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