HiggsAnalysis/HiggsAnalysis-00-01-00/src/JetTrackSelectorTool.cxx

00001 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00002 // 17.07.2007, AUTHOR: OLIVER KORTNER
00003 // Modified: 29.07.2007 by O. Kortner, options for a special treatment of
00004 //                                     multivertex events.
00005 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00006 
00007 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 //:: IMPLEMENTATION OF METHODS DEFINED IN THE CLASS JetTrackSelectorTool ::
00009 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00010 
00011 //::::::::::::::::::
00012 //:: HEADER FILES ::
00013 //::::::::::::::::::
00014 
00015 // standard C++ //
00016 #include <iostream>
00017 #include <fstream>
00018 
00019 // Gaudi //
00020 #include "GaudiKernel/Service.h"
00021 #include "GaudiKernel/MsgStream.h"
00022 
00023 // track particles //
00024 #include "Particle/TrackParticleContainer.h"
00025 #include "ElectronPhotonIDEvent/ElectronContainer.h"
00026 #include "MuonIDEvent/MuonContainer.h"
00027 
00028 // jet reconstruction //
00029 #include "JetUtils/JetCollectionHelper.h"
00030 #include "JetEvent/Jet.h"
00031 #include "JetEvent/JetCollection.h"
00032 #include "JetRec/JetAlgToolBase.h"
00033 
00034 //#include "JetRecTools/JetTrackSelectorTool.h"
00035 #include "HiggsAnalysis/JetTrackSelectorTool.h"
00036 //#include "TrkEventPrimitives/FitQuality.h"
00037 
00038 //::::::::::::::::::::::::
00039 //:: NAMESPACE SETTINGS ::
00040 //::::::::::::::::::::::::
00041 
00042 using namespace std;
00043 using namespace Rec;
00044 
00045 //*****************************************************************************
00046 
00047 //:::::::::::::::::
00048 //:: CONSTRUCTOR ::
00049 //:::::::::::::::::
00050 
00051 JetTrackSelectorTool::JetTrackSelectorTool(const std::string & name,
00052         const std::string & type,
00053         const IInterface * parent) : JetAlgToolBase(name, type, parent) {
00054 
00056 // JOB OPTIONS //
00058 
00059         m_pt_min = 0.0; // no cut on the transverse momentum of a track by
00060                         // default
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 // RESET POINTERS //
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 //:: DESTRUCTOR ::
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 //:: METHOD initialize ::
00140 //:::::::::::::::::::::::
00141 
00142 StatusCode JetTrackSelectorTool::initialize(void) {
00143 
00145 // VARIABLES //
00147 
00148         m_log = new MsgStream(msgSvc(), name()); // message service
00149 
00151 // MESSAGE //
00153 
00154         *m_log << MSG::INFO << "Initializing tool..." << endreq;
00155 
00157 // SET POINTERS //
00159 
00160 // store gate //
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 // VertexCollectionSvc //
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 //:: METHOD execute ::
00195 //::::::::::::::::::::
00196 
00197 StatusCode JetTrackSelectorTool::execute(
00198                                 JetAlgToolBase::jetcollection_t * theJets) {
00199 
00201 // VARIABLES //
00203 
00204     //static std::ofstream out_e("et_dR_trkjets_e.txt");
00205     //static std::ofstream out_mu("et_dR_trkjets_mu.txt");
00206 
00207         const TrackParticleContainer *track_particle_container(0);
00208                                         // pointer to the track particles
00209 
00210         const ElectronContainer *electron_container(0); 
00211                                         // container with reconstructed electrons
00212 
00213         const MuonContainer *muon_container(0); 
00214                                         // container with reconstructed muons
00215 
00216         jetcollection_t* writeCollection(0); // output jet collection
00217         Hep3Vector primary_vertex(0.0, 0.0, 0.0); // primary vertex of highest
00218                                                   // momentum
00219 
00220 
00222 // GET THE PRIMARY VERTEX OF HIGHEST TRANSVERSE MOMENTUM, IF REQUESTED //
00224 
00225         if (!m_ignore_multivertices) {
00226                 primary_vertex = highest_pt_vertex();
00227         }
00228 
00229 
00231 // GET THE POINTER TO THE PARTICLE CONTAINER //
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 // CREATE A NEW JET COLLECTION (TO BE USED AS THE INPUT OF THE JET RECO.) //
00272 
00273         writeCollection = new jetcollection_t();
00274                                
00275         // build vectors containing the isolated leptons                         //
00276         // isolation is done by cutting on the et sum of the tracks in the cone  //
00277 
00278         //ElectronContainer *isol_electron_container = new ElectronContainer(); 
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             //electrons
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                 // if ((*electron_container)[iE]->isEM()!=0 ){
00297 //                   continue;
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                 //out_e << etcone << endl;
00330                 //Electron *electron = const_cast<Electron*>((*electron_container)[iE]);
00331             
00332                 if( etcone < m_electron_et_cut ){
00333                     //isol_electron_vector.push_back(electron);
00334                     isol_electron_vector.push_back((*electron_container)[iE]);
00335                 }
00336                 
00337             }
00338 
00339             //muons
00340             for (unsigned int iM=0; iM<muon_container->size(); iM++) {
00341 
00342                 // if (!(*muon_container)[iM]->hasCombinedMuonTrackParticle() || !(*muon_container)[iM]->isHighPt() 
00343 //                     || !(*muon_container)[iM]->bestMatch()) {
00344 //                     continue;
00345 //                 }
00346 
00347                 if( (*muon_container)[iM]->track()->reconstructedVertex()==NULL ){
00348                     continue;
00349                 } 
00350 
00351                 if (!m_ignore_multivertices){
00352                 
00353                   //   if( (*muon_container)[iM]->track()->reconstructedVertex()==NULL ){
00354 //                         continue;
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                 //out_mu << etcone << endl;
00373                 //Analysis::Muon *muon = const_cast<Analysis::Muon*>((*muon_container)[iM]);
00374             
00375                 if( etcone < m_muon_et_cut ){
00376                     //isol_muon_vector.push_back(muon);
00377                     isol_muon_vector.push_back((*muon_container)[iM]);
00378                 }
00379                 
00380             }
00381 
00382         }
00383 
00384         // loop over track particles and add them to the jet collection //
00385         // if they pass all the cuts                                       //
00386        
00387         //static std::ofstream out("eta_trkjets.txt");
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             //const Trk::FitQuality *fq = (*track_particle_container)[k]->fitQuality();
00396             
00397             //out << p.eta() << "\t\t" <<  p.et() << endl;
00398                 //<< fq->chiSquared() << "\t\t" << fq->numberDoF()  << endl;
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             //const Trk::MeasuredPerigee* perigee = (*track_particle_container)[k]->measuredPerigee();
00404             //double d0 = perigee->parameters()[Trk::d0]; 
00405             //double z0 = perigee->parameters()[Trk::z0];
00406             //double sinTh = perigee->sinTheta();
00407             
00408             m_cut_start++;
00409             
00410             //check pt
00411             if (p.perp()<m_pt_min) {
00412                 continue;
00413             }
00414             m_cut_p++;
00415  
00416             //check vertex
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             //if(fabs(d0)>2){
00433             //  continue;
00434             //}
00435             //m_cut_d0++;
00436             
00437             //if(fabs(z0*sinTh)>10){
00438             //  continue;
00439             //}
00440             //m_cut_z0++;
00441             
00442             //cout << (*track_particle_container)[k]->reconstructedVertex()->position() << endl;
00443             //cout << trk_num_SCTHit << ", " << trk_num_PHit << ", " 
00444             //   << fabs(d0) << ", " << fabs(z0*sinTh) << endl;
00445                        
00446             //check overlap with isol leptons
00447             if ( m_remove_isol_leptons ){
00448                 
00449                 bool overlap(false);
00450                 
00451                 //electrons
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                 //muons
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             } //m_remove_isol_leptons
00484             
00485             
00486             writeCollection->push_back(new Jet(p));
00487 
00488         } //for track_particle_container 
00489 
00490 
00491 // record the collection in the store gate //
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 // free memory //
00501         JetCollectionHelper::remove_object(writeCollection,
00502                                                 writeCollection->begin(),
00503                                                 writeCollection->end());
00504         delete writeCollection;
00505 
00506 // retrieve collection from StoreGate to satisfy Jet constructor //
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 // build intermediate jet list //
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 //:: METHOD highest_pt_vertex ::
00531 //::::::::::::::::::::::::::::::
00532 
00533 Hep3Vector JetTrackSelectorTool::highest_pt_vertex(void) const {
00534 
00535     
00536     //for (unsigned int k=0; k<m_vert_coll->getVertices().size(); k++){
00537     //  cout << m_vert_coll->getVertices()[k].Et() << endl;
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 //:: METHOD get_energy_in_cone ::
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 // VARIABLES --
00560 //-------------
00561 
00562     double ET(0.);   // transverse energy in the cone
00563 
00564 //-------------------------------------------------------------
00565 // LOOP OVER THE TRACKS AND CALCULATE THE ENERGY IN THE CONE --
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 

Generated on Tue Oct 21 11:50:43 2008 for NtupleAnalysis by  doxygen 1.5.1