00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <iostream>
00017 #include <fstream>
00018
00019
00020 #include "GaudiKernel/Service.h"
00021 #include "GaudiKernel/MsgStream.h"
00022
00023
00024 #include "Particle/TrackParticleContainer.h"
00025 #include "egammaEvent/ElectronContainer.h"
00026 #include "egammaEvent/egammaParamDefs.h"
00027 #include "muonEvent/MuonContainer.h"
00028
00029
00030 #include "JetUtils/JetCollectionHelper.h"
00031 #include "JetEvent/Jet.h"
00032 #include "JetEvent/JetCollection.h"
00033 #include "JetRec/JetAlgToolBase.h"
00034
00035
00036 #include "NtupleWriter14/JetTrackSelectorTool.h"
00037
00038
00039
00040
00041
00042
00043 using namespace std;
00044 using namespace Rec;
00045
00046
00047
00048
00049
00050
00051
00052 JetTrackSelectorTool::JetTrackSelectorTool(const std::string & name,
00053 const std::string & type,
00054 const IInterface * parent) : JetAlgToolBase(name, type, parent) {
00055
00057
00059
00060 m_pt_min = 0.0;
00061
00062 declareProperty("pTMin", m_pt_min);
00063
00064 m_output_collection_name = string("TrackParticlesForJets");
00065 declareProperty("outputCollectionName", m_output_collection_name);
00066
00067 m_track_particle_container_name = string("TrackParticleCandidate");
00068 declareProperty("TrackParticleContainer",
00069 m_track_particle_container_name);
00070
00071 m_ignore_multivertices = false;
00072 declareProperty("ignoreMultivertices", m_ignore_multivertices);
00073
00074 m_primary_vertex_container = string("VxPrimaryCandidate");
00075 declareProperty("vertexContainer", m_primary_vertex_container);
00076
00077 m_vert_coll_svc_name = string("MPIHiggsAnalysis::VertexCollectionSvc");
00078 declareProperty("VertexCollectionSvc", m_vert_coll_svc_name);
00079
00080 m_electron_container = string("ElectronCollection");
00081 declareProperty("electronContainer", m_electron_container);
00082
00083 m_muon_container = string("StacoMuonCollection");
00084 declareProperty("muonContainer", m_muon_container);
00085
00086 m_remove_isol_leptons = false;
00087 declareProperty("removeIsolLeptons", m_remove_isol_leptons);
00088
00089 m_electron_cone = 0.;
00090 m_electron_et_cut = 0.;
00091 m_muon_cone = 0.;
00092 m_muon_et_cut = 0.;
00093 m_inner_cone = 0.01;
00094
00095 declareProperty("electronCone", m_electron_cone);
00096 declareProperty("electronEtCut", m_electron_et_cut);
00097 declareProperty("muonCone", m_muon_cone);
00098 declareProperty("muonEtCut", m_muon_et_cut);
00099 declareProperty("innerCone", m_inner_cone);
00100
00101
00103
00105
00106 m_storeGate = 0;
00107 m_log = 0;
00108 m_vert_coll = 0;
00109
00110 }
00111
00112
00113
00114
00115
00116
00117
00118 JetTrackSelectorTool::~JetTrackSelectorTool(void) {}
00119
00120
00121
00122
00123
00124
00125
00126 StatusCode JetTrackSelectorTool::initialize(void) {
00127
00129
00131
00132 m_log = new MsgStream(msgSvc(), name());
00133
00135
00137
00138 *m_log << MSG::INFO << "Initializing tool..." << endreq;
00139
00141
00143
00144
00145 StatusCode sc(service("StoreGateSvc", m_storeGate));
00146 if (!sc.isSuccess()) {
00147 *m_log << MSG::FATAL << "Cannot retrieve StoreGateSvc!"
00148 << endreq;
00149 return sc;
00150 }
00151
00152
00153 sc = service(m_vert_coll_svc_name, m_vert_coll);
00154 if (!sc.isSuccess()) {
00155 *m_log << MSG::FATAL << "Cannot retrieve "
00156 << m_vert_coll_svc_name << "!" << endreq;
00157 return sc;
00158 }
00159
00160 if(m_remove_isol_leptons){
00161 *m_log << MSG::INFO
00162 << "Ignore tracks wich overlap with an isolated lepton"
00163 << endreq
00164 << "Isolation: " << endreq
00165 << " electron: etcone(" << m_electron_cone << ") < "
00166 << m_electron_et_cut << endreq
00167 << " muon: etcone(" << m_muon_cone << ") < "
00168 << m_muon_et_cut << endreq;
00169 }
00170
00171 return StatusCode::SUCCESS;
00172
00173 }
00174
00175
00176
00177
00178
00179
00180
00181 StatusCode JetTrackSelectorTool::execute(
00182 JetAlgToolBase::jetcollection_t * theJets) {
00183
00185
00187
00188
00189
00190
00191 const TrackParticleContainer *track_particle_container(0);
00192
00193
00194 const ElectronContainer *electron_container(0);
00195
00196
00197 const Analysis::MuonContainer *muon_container(0);
00198
00199
00200 jetcollection_t* writeCollection(0);
00201 Hep3Vector primary_vertex(0.0, 0.0, 0.0);
00202
00203
00204
00206
00208
00209 if (!m_ignore_multivertices) {
00210 primary_vertex = highest_pt_vertex();
00211 }
00212
00213
00215
00217
00218 StatusCode sc(m_storeGate->retrieve(track_particle_container,
00219 m_track_particle_container_name));
00220 if (sc.isFailure() || track_particle_container==0) {
00221 *m_log << MSG::WARNING
00222 << "No track particle container found in store gate!"
00223 << endreq;
00224 return sc;
00225 }
00226 *m_log << MSG::DEBUG
00227 << "Track particle container retrieved successfully!"
00228 << endreq;
00229
00230
00231 sc = m_storeGate->retrieve(electron_container, m_electron_container);
00232 if(sc.isFailure() || electron_container==0) {
00233 *m_log << MSG::WARNING
00234 << "No electron container found in the store gate!"
00235 << endreq;
00236 return false;
00237 }
00238 *m_log << MSG::DEBUG << "Electron container retrieved successfully!"
00239 << endreq;
00240
00241
00242 sc = m_storeGate->retrieve(muon_container, m_muon_container);
00243 if(sc.isFailure() || muon_container==0) {
00244 *m_log << MSG::WARNING
00245 << "No muon container found in the store gate!"
00246 << endreq;
00247 return false;
00248 }
00249 *m_log << MSG::DEBUG << "Muon container retrieved successfully!"
00250 << endreq;
00251
00252
00254
00256
00257 writeCollection = new jetcollection_t();
00258
00259
00260
00261
00262
00263 vector<const Analysis::Electron*> isol_electron_vector(0);
00264 vector<const Analysis::Muon*> isol_muon_vector(0);
00265
00266 if ( m_remove_isol_leptons ){
00267
00268
00269 for (unsigned int iE=0; iE<electron_container->size(); iE++) {
00270
00271 if ((*electron_container)[iE]
00272 ->trackParticle()->reconstructedVertex() == NULL){
00273 continue;
00274 }
00275
00276 if (((*electron_container)[iE]->isem(egammaPID::ElectronLoose))!=0 ){
00277 continue;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 if ((*electron_container)[iE]->author()!=
00290 egammaParameters::AuthorElectron &&
00291 (*electron_container)[iE]->author()!=
00292 egammaParameters::AuthorSofte) {
00293 continue;
00294 }
00295
00296
00297 if ((*electron_container)[iE]->trackParticle()==0) {
00298 continue;
00299 }
00300
00301 if (!m_ignore_multivertices){
00302
00303 if ((*electron_container)[iE]
00304 ->trackParticle()->reconstructedVertex()->recVertex().position() != primary_vertex){
00305
00306 continue;
00307 }
00308 }
00309
00310 HepLorentzVector p((*electron_container)[iE]->hlv());
00311
00312 double etcone = get_energy_in_cone( m_electron_cone, p,
00313 (*electron_container)[iE]->trackParticle()
00314 ->reconstructedVertex()->recVertex().position(),
00315 track_particle_container
00316 );
00317
00318
00319
00320 if( etcone < m_electron_et_cut ){
00321
00322 isol_electron_vector.push_back((*electron_container)[iE]);
00323 }
00324
00325 }
00326
00327
00328 for (unsigned int iM=0; iM<muon_container->size(); iM++) {
00329
00330
00331
00332
00333
00334
00335 if( (*muon_container)[iM]->track()->reconstructedVertex()==NULL ){
00336 continue;
00337 }
00338
00339 if (!m_ignore_multivertices){
00340
00341
00342
00343
00344
00345 if ((*muon_container)[iM]
00346 ->track()->reconstructedVertex()->recVertex().position() != primary_vertex){
00347
00348 continue;
00349 }
00350 }
00351
00352 HepLorentzVector p((*muon_container)[iM]->hlv());
00353
00354 double etcone = get_energy_in_cone( m_muon_cone, p,
00355 (*muon_container)[iM]->track()
00356 ->reconstructedVertex()->recVertex().position(),
00357 track_particle_container
00358 );
00359
00360
00361
00362
00363 if( etcone < m_muon_et_cut ){
00364
00365 isol_muon_vector.push_back((*muon_container)[iM]);
00366 }
00367
00368 }
00369
00370 }
00371
00372
00373
00374
00375
00376 for (unsigned int k=0; k<track_particle_container->size(); k++) {
00377
00378 if((*track_particle_container)[k]->reconstructedVertex() == NULL){
00379 continue;
00380 }
00381
00382 HepLorentzVector p((*track_particle_container)[k]->hlv());
00383
00384
00385
00386
00387
00388
00389
00390 if (p.perp()<m_pt_min) {
00391 continue;
00392 }
00393
00394
00395 if (!m_ignore_multivertices){
00396
00397 if ((*track_particle_container)[k]
00398 ->reconstructedVertex()->recVertex().position() != primary_vertex){
00399
00400 continue;
00401 }
00402 }
00403
00404
00405
00406 if ( m_remove_isol_leptons ){
00407
00408 bool overlap(false);
00409
00410
00411 for (unsigned int iE=0; iE<isol_electron_vector.size(); iE++) {
00412
00413 if( (*track_particle_container)[k]
00414 == isol_electron_vector[iE]->trackParticle() ){
00415
00416 overlap = true;
00417 break;
00418 }
00419 }
00420
00421 if(overlap){
00422 continue;
00423 }
00424
00425 overlap = false;
00426
00427
00428 for (unsigned int iM=0; iM<isol_muon_vector.size(); iM++) {
00429
00430 if( (*track_particle_container)[k]
00431 == isol_muon_vector[iM]->inDetTrackParticle() ){
00432
00433 overlap = true;
00434 break;
00435 }
00436 }
00437
00438 if(overlap){
00439 continue;
00440 }
00441
00442 }
00443
00444
00445 writeCollection->push_back(new Jet(p));
00446
00447 }
00448
00449
00450
00451 if (!JetCollectionHelper::record_jets(m_storeGate, writeCollection,
00452 m_output_collection_name)) {
00453 *m_log << MSG::ERROR
00454 << "Cannot convert initial list to JetCollection!"
00455 << endreq;
00456 return StatusCode::FAILURE;
00457 }
00458
00459
00460 JetCollectionHelper::remove_object(writeCollection,
00461 writeCollection->begin(),
00462 writeCollection->end());
00463 delete writeCollection;
00464
00465
00466 const INavigable4MomentumCollection *readCollection;
00467 sc = m_storeGate->retrieve(readCollection, m_output_collection_name);
00468 if (sc.isFailure()) {
00469 *m_log << MSG::ERROR
00470 << "Cannot read back initial jet collection!"
00471 << endreq;
00472 return sc;
00473 }
00474
00475
00476 for (Jet::index_type theIndex=0; theIndex < readCollection->size();
00477 theIndex++) {
00478 theJets->push_back(new Jet(readCollection, theIndex));
00479 }
00480
00481
00482 return StatusCode::SUCCESS;
00483
00484 }
00485
00486
00487
00488
00489
00490
00491
00492 Hep3Vector JetTrackSelectorTool::highest_pt_vertex(void) const {
00493
00494 return m_vert_coll->getVertices()[
00495 m_vert_coll->getVertices().size()-1].position();
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 }
00600
00601
00602
00603
00604
00605
00606
00607 double
00608 JetTrackSelectorTool::get_energy_in_cone(const double & cone,
00609 const HepLorentzVector & p,
00610 const Hep3Vector & vertex,
00611 const TrackParticleContainer *track_particle_container) {
00612
00613
00614
00615
00616 double ET(0.);
00617
00618
00619
00620
00621
00622 for (unsigned int k=0; k<track_particle_container->size(); k++) {
00623
00624 if (!m_ignore_multivertices){
00625
00626 if ( (*track_particle_container)[k]
00627 ->reconstructedVertex()->recVertex().position()!=vertex) {
00628
00629 continue;
00630 }
00631 }
00632
00633 if ( p.deltaR((*track_particle_container)[k]->hlv()) < cone &&
00634 p.deltaR((*track_particle_container)[k]->hlv()) > m_inner_cone) {
00635
00636 ET = ET+(*track_particle_container)[k]->hlv().et();
00637 }
00638
00639 }
00640
00641
00642 return ET;
00643
00644 }
00645
00646