00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "AtlfastAlgs/Isolator.h"
00011 #include "AtlfastAlgs/ClusterIsAssoc.h"
00012 #include "AtlfastAlgs/GlobalEventData.h"
00013
00014 #include "AtlfastEvent/Phi.h"
00015 #include "AtlfastEvent/Cluster.h"
00016
00017 #include "AtlfastUtils/FunctionObjects.h"
00018 #include "AtlfastUtils/HeaderPrinter.h"
00019 #include "AtlfastUtils/HepMC_helper/IMCselector.h"
00020
00021 #include <cmath>
00022 #include <algorithm>
00023
00024
00025 #include "GaudiKernel/DataSvc.h"
00026 #include "StoreGate/DataHandle.h"
00027 #include "AtlfastEvent/MsgStreamDefs.h"
00028
00029 namespace Atlfast {
00030 using std::partial_sort;
00031
00032
00033
00034
00035
00036
00037 Isolator::Isolator
00038 ( const std::string& name, ISvcLocator* pSvcLocator )
00039 : Algorithm( name, pSvcLocator ){
00040
00041
00042 m_rClusterMatch = 0.150;
00043 m_rClusterIsolation = 0.400;
00044 m_eClusterIsolation = 0.0;
00045 m_rCellIsolation = 0.200;
00046 m_eCellIsolation = 10.0;
00047
00048
00049 m_inputLocation = "Unknown";
00050 m_cellLocation = "/Event/AtlfastCell";
00051 m_clusterLocation = "/Event/AtlfastCluster";
00052 m_isolatedOutputLocation = "Unknown";
00053 m_nonIsolatedOutputLocation = "Unknown";
00054
00055
00056
00057
00058 declareProperty( "RClusterMatch", m_rClusterMatch ) ;
00059 declareProperty( "RClusterIsolation", m_rClusterIsolation ) ;
00060 declareProperty( "EClusterIsolation", m_eClusterIsolation ) ;
00061 declareProperty( "RCellIsolation", m_rCellIsolation ) ;
00062 declareProperty( "ECellIsolation", m_eCellIsolation ) ;
00063
00064 declareProperty( "InputLocation", m_inputLocation ) ;
00065 declareProperty( "CellLocation", m_cellLocation ) ;
00066 declareProperty( "ClusterLocation", m_clusterLocation ) ;
00067 declareProperty( "IsolatedOutputLocation", m_isolatedOutputLocation ) ;
00068 declareProperty( "NonIsolatedOutputLocation", m_nonIsolatedOutputLocation ) ;
00069
00070 }
00071
00072
00073 Isolator::~Isolator() {
00074 MsgStream log( messageService(), name() ) ;
00075 log << MSG::INFO << "destructor" << endreq;
00076 if (m_tesIO) {
00077 delete m_tesIO;
00078 }
00079 }
00080
00081
00082
00083
00084
00085
00086 StatusCode Isolator::initialize(){
00087 MsgStream log( messageService(), name() ) ;
00088 log << MSG::DEBUG << "Initialising" << endreq;
00089
00090
00091
00092 m_tesIO = new TesIO();
00093
00094 GlobalEventData* ged = GlobalEventData::Instance();
00095 m_visibleToCal = ged -> visibleToCal();
00096
00097 HeaderPrinter hp("Atlfast Isolator:", log);
00098
00099 hp.add("TES Locations: ");
00100 hp.add(" Particles from ", m_inputLocation);
00101 hp.add(" Cells from ", m_cellLocation);
00102 hp.add(" Clusters from ", m_clusterLocation);
00103 hp.add(" Isolated Particles to ", m_isolatedOutputLocation);
00104 hp.add(" Non-Isolated Particles to ", m_nonIsolatedOutputLocation);
00105 hp.add("Cluster match DeltaR ", m_rClusterMatch);
00106 hp.add("Cluster isolation DeltaR ", m_rClusterIsolation);
00107 hp.add("Cluster isolation E thresh ", m_eClusterIsolation);
00108 hp.add("Cell isolation DeltaR ", m_rCellIsolation);
00109 hp.add("Cell isolation E thresh ", m_eCellIsolation);
00110 hp.print();
00111
00112
00113 return StatusCode::SUCCESS ;
00114 }
00115
00116
00117
00118
00119
00120 StatusCode Isolator::finalize(){
00121 MsgStream log( messageService(), name() ) ;
00122 log << MSG::INFO << "finalizing" << endreq;
00123 return StatusCode::SUCCESS ;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 StatusCode Isolator::execute( ){
00142
00143
00144
00145
00146 MsgStream log( messageService(), name() ) ;
00147 std::string mess;
00148
00149
00150
00151
00152 const DataHandle<ReconstructedParticleCollection> particles;
00153 if(!m_tesIO->getDH(particles, m_inputLocation)){
00154 log << MSG::DEBUG
00155 << "No reconstructed particles in TES to treat"
00156 << endreq ;
00157 return StatusCode::SUCCESS ;
00158 }
00159
00160 log << MSG::DEBUG
00161 << "Found "
00162 << particles->size()
00163 << " particles in TES "
00164 << endreq ;
00165
00166
00167
00168
00169
00170
00171
00172 std::vector<ITwoCptCell*> cells;
00173 if(!m_tesIO->copy<ITwoCptCellCollection> (cells, m_cellLocation)){
00174
00175 log << MSG::DEBUG
00176 << "No Cells found in TES at "
00177 << m_cellLocation
00178 << endreq ;
00179 }
00180
00181
00182 std::vector<Cluster*> clusters;
00183 if(!m_tesIO->copy<ClusterCollection>(clusters, m_clusterLocation)){
00184 log << MSG::DEBUG
00185 << "No Clusters found in TES at "
00186 << m_clusterLocation
00187 << endreq ;
00188 }
00189
00190
00191
00192
00193
00194
00195 ReconstructedParticleCollection* isolatedParticles =
00196 new ReconstructedParticleCollection ;
00197
00198 ReconstructedParticleCollection* nonIsolatedParticles =
00199 new ReconstructedParticleCollection ;
00200
00201
00202
00203
00204
00205
00206 ReconstructedParticleCollection::iterator particle ;
00207
00208 for( particle = particles->begin();
00209 particle != particles->end();
00210 ++particle)
00211 {
00212 if( this->isIsolated( log, particle, cells, clusters ) )
00213 isolatedParticles->push_back
00214 ( new ReconstructedParticle( *particle ) );
00215 else
00216 nonIsolatedParticles->push_back
00217 ( new ReconstructedParticle( *particle ) );
00218 }
00219
00220
00221
00222
00223
00224 TesIoStat sc;
00225 sc = m_tesIO->store(isolatedParticles, m_isolatedOutputLocation );
00226
00227 if( !sc ) {
00228 log << MSG::ERROR << "Failed to register output in TES at "
00229 << m_isolatedOutputLocation << endreq ;
00230 return sc;
00231 } else{
00232 log << MSG::DEBUG << "Written " << isolatedParticles->size()
00233 << " isolated particles to TES " << endreq;
00234 }
00235
00236 sc = m_tesIO->store(nonIsolatedParticles, m_nonIsolatedOutputLocation );
00237
00238 if( !sc ) {
00239 log << MSG::ERROR << "Failed to register output in TES at "
00240 << m_nonIsolatedOutputLocation << endreq ;
00241 }
00242 else {
00243 log << MSG::DEBUG << "Written " << nonIsolatedParticles->size()
00244 << " NON-isolated particles to TES " << endreq;
00245 }
00246
00247 return sc ;
00248
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 bool Isolator::isIsolated
00260 ( MsgStream& log,
00261 ReconstructedParticleCollection::iterator particle,
00262 std::vector<ITwoCptCell*>& storedCells,
00263 std::vector<Cluster*>& storedClusters
00264
00265 ){
00266
00267 log << MSG::DEBUG << "\n\t Treating particle: " << *particle ;
00268
00269
00270
00271
00272 bool associated = false ;
00273 Cluster* associatedCluster = NULL ;
00274
00275
00276
00277
00278
00279
00280 if( storedClusters.begin() ) {
00281
00282 if( storedClusters.size() > 0 ) {
00283
00284
00285 std::vector<Cluster*> clusters(
00286 storedClusters.begin(),
00287 storedClusters.end()
00288 );
00289
00290
00291 std::vector<Cluster*>::iterator firstNonAssociatedCluster ;
00292 firstNonAssociatedCluster = std::partition(
00293 clusters.begin(),
00294 clusters.end(),
00295 ClusterIsAssoc()
00296 );
00297 if(firstNonAssociatedCluster != clusters.begin()){
00298 log<<MSG::DEBUG<<"First "
00299 <<firstNonAssociatedCluster-clusters.begin()
00300 <<" clusters are associated to ReconstructedParticles "
00301 <<clusters.end()-firstNonAssociatedCluster
00302 <<" cluster(s) remain"
00303 <<endreq;
00304 }else{
00305 log<<MSG::DEBUG
00306 <<"No clusters are associated to ReconstructedParticles"
00307 <<endreq;
00308 }
00309 if(clusters.end()!=firstNonAssociatedCluster){
00310
00311
00312
00313
00314
00315 partial_sort(
00316 firstNonAssociatedCluster,
00317 firstNonAssociatedCluster+1,
00318 clusters.end(),
00319 SortAttribute::DeltaR( *particle )
00320 );
00321
00322 log<<MSG::DEBUG<<"Sorted clusters "<<endreq;
00323
00324 associated =
00325 (m_kinehelp.deltaR(*particle, *firstNonAssociatedCluster) <
00326 m_rClusterMatch);
00327
00328 if( associated )
00329 {
00330 log << "\n\t -->Found associated cluster: "
00331 << *clusters.begin() ;
00332
00333
00334 associatedCluster = *firstNonAssociatedCluster ;
00335
00336
00337 ++firstNonAssociatedCluster;
00338
00339 }
00340
00341
00342
00343
00344
00345
00346
00347 double eClusterSum = m_kinehelp.sumETInCone(
00348 firstNonAssociatedCluster,
00349 clusters.end(),
00350 *particle,
00351 m_rClusterIsolation
00352 );
00353
00354
00355
00356 if( eClusterSum > m_eClusterIsolation )
00357 log << "\n\t -->Excess Cluster energy in cone = " << eClusterSum
00358 << " => NOT-ISOLATED " << endreq;
00359 else
00360 log << "\n\t -->Excess Cluster energy in cone = " << eClusterSum
00361 << " => ISOLATED " ;
00362
00363 if( eClusterSum > m_eClusterIsolation ) return false ;
00364
00365 }
00366
00367 }
00368 }
00369
00370
00371
00372
00373
00374 if( storedCells.begin() ) {
00375
00376
00377
00378
00379
00380 double eCellSum = m_kinehelp.sumETInCone(
00381 storedCells.begin(),
00382 storedCells.end(),
00383 *particle,
00384 m_rCellIsolation
00385 );
00386
00387
00388
00389
00390
00391
00392 bool itDeposits = m_visibleToCal->operator()( (*particle)->truth() );
00393
00394 if(itDeposits) eCellSum -= (*particle)->eT() ;
00395
00396
00397
00398
00399 if( eCellSum > m_eCellIsolation )
00400 log
00401 << "\n\t -->Excess Cell energy in cone = " << eCellSum
00402 << " => NOT-ISOLATED " << endreq ;
00403 else
00404 log
00405 << "\n\t -->Excess Cell energy in cone = " << eCellSum
00406 << " => ISOLATED " ;
00407
00408 if( eCellSum > m_eCellIsolation ) return false ;
00409
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419 if( associated ) {
00420
00421
00422 IAssociationManager* iamp = *particle;
00423 iamp->associate( associatedCluster ) ;
00424
00425
00426 IAssociationManager* iamc = associatedCluster;
00427 iamc->associate( *particle ) ;
00428
00429 }
00430
00431 log << endreq ;
00432
00433 return true ;
00434 }
00435
00436 }