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