00001
00002 #include "GaudiKernel/Service.h"
00003 #include "GaudiKernel/MsgStream.h"
00004
00005 #include "StoreGate/StoreGateSvc.h"
00006
00007 #include "NavFourMom/INavigable4MomentumCollection.h"
00008
00009 #include "HepMC/GenParticle.h"
00010
00011 #include "TruthHelper/IsGenInteracting.h"
00012 #include "TruthHelper/GenAccessIO.h"
00013
00014 #include "CLHEP/Vector/LorentzVector.h"
00015 #include "CLHEP/Units/SystemOfUnits.h"
00016 #include "CLHEP/HepPDT/ParticleID.hh"
00017 #include "CLHEP/Vector/ThreeVector.h"
00018
00019 #include "JetUtils/JetCollectionHelper.h"
00020
00021 #include "JetEvent/Jet.h"
00022 #include "JetEvent/JetCollection.h"
00023
00024 #include "JetRec/JetAlgToolBase.h"
00025
00026
00027 #include "HiggsAnalysis/JetTruthTrackSelectorTool.h"
00028 #include "HiggsAnalysis/MyTruthTrackJetInfoContainer.h"
00029 #include "HiggsAnalysis/Vertex.h"
00030
00031
00032 #include "Particle/TrackParticleContainer.h"
00033
00034 #include <string>
00035 #include <vector>
00036 #include <cmath>
00037 #include <fstream>
00038
00039 using namespace Rec;
00040 using namespace std;
00041 using namespace MPIHiggsAnalysis;
00042
00043 JetTruthTrackSelectorTool::JetTruthTrackSelectorTool(const std::string& name,
00044 const std::string& type,
00045 const IInterface* parent)
00046 : JetAlgToolBase(name,type,parent)
00047 , m_ptMin(0.*MeV)
00048 , m_etaMax(5.)
00049 , m_includeMuons(true)
00050 {
00051 declareProperty("MinPt", m_ptMin);
00052 declareProperty("MaxEta", m_etaMax);
00053 declareProperty("IncludeMuons", m_includeMuons);
00054 declareProperty("OutputCollectionName",m_outputCollectionName);
00055
00056 m_ignore_multivertices = false;
00057 declareProperty("ignoreMultivertices", m_ignore_multivertices);
00058
00059 m_Et_min_vert = 1000*MeV;
00060 declareProperty("MinEtVertex", m_Et_min_vert);
00061
00062 m_vertex_cut = 0.1*mm;
00063 declareProperty("VertexCut", m_vertex_cut);
00064
00065 m_remove_isol_leptons = false;
00066 declareProperty("removeIsolLeptons", m_remove_isol_leptons);
00067
00068 m_electron_cone = 0.;
00069 m_electron_et_cut = 0.;
00070 m_muon_cone = 0.;
00071 m_muon_et_cut = 0.;
00072 m_inner_cone = 0.01;
00073
00074 declareProperty("electronCone", m_electron_cone);
00075 declareProperty("electronEtCut", m_electron_et_cut);
00076 declareProperty("muonCone", m_muon_cone);
00077 declareProperty("muonEtCut", m_muon_et_cut);
00078 declareProperty("innerCone", m_inner_cone);
00079
00080 }
00081
00082 JetTruthTrackSelectorTool::~JetTruthTrackSelectorTool()
00083 { }
00084
00085
00086 StatusCode JetTruthTrackSelectorTool::initialize()
00087 {
00088 MsgStream report(msgSvc(),name());
00089
00090
00091 StatusCode checkOut = service("StoreGateSvc",m_storeGate);
00092 if ( checkOut.isFailure() )
00093 {
00094 report << MSG::ERROR
00095 << "cannot allocate StoreGate service"
00096 << endreq;
00097 return checkOut;
00098 }
00099
00100
00101 m_truthAccess = new GenAccessIO();
00102
00103
00104 if ( m_truthAccess == 0 )
00105 {
00106 report << MSG::ERROR
00107 << "cannot allocate GenAccessIO service."
00108 << endreq;
00109 return StatusCode::FAILURE;
00110 }
00111
00112 return checkOut;
00113 }
00114
00115
00116 StatusCode JetTruthTrackSelectorTool::execute(JetAlgToolBase::jetcollection_t*
00117 theJets)
00118 {
00119
00120 MsgStream report(msgSvc(),name());
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 Hep3Vector primary_vertex(0.0, 0.0, 0.0);
00136
00137
00138
00139 std::vector<const HepMC::GenParticle*> theParticles;
00140 IsGenInteracting theGenInteracting ;
00141 StatusCode checkOut =
00142 m_truthAccess->getMC(theParticles, &theGenInteracting );
00143
00144
00145 if ( theParticles.size() == 0 || checkOut.isFailure() )
00146 {
00147 report << MSG::WARNING
00148 << "no truth particles found in this event"
00149 << endreq;
00150 return StatusCode::SUCCESS;
00151 }
00152
00153
00154
00155 primary_vertex = highest_Et_vertex(theParticles);
00156
00157
00158
00159 jetcollection_t* writeCollection = new jetcollection_t();
00160
00161
00162 std::vector<const HepMC::GenParticle*>::iterator
00163 firstParticle = theParticles.begin();
00164 std::vector<const HepMC::GenParticle*>::iterator
00165 lastParticle = theParticles.end();
00166
00167
00168 for( ; firstParticle != lastParticle; firstParticle++ )
00169 {
00170
00171 HepLorentzVector particleKine = (*firstParticle)->momentum();
00172 HepPDT::ParticleID IDEN((*firstParticle)->pdg_id());
00173
00174 if ( particleKine.perp() > m_ptMin &&
00175 fabs(particleKine.pseudoRapidity()) < m_etaMax &&
00176 ( abs((*firstParticle)->pdg_id()) != 13 || m_includeMuons ) &&
00177 IDEN.threeCharge()!=0 && (*firstParticle)->production_vertex()!=0)
00178 {
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 if ( m_remove_isol_leptons ){
00204
00205 double etcone(0);
00206
00207
00208 if(abs((*firstParticle)->pdg_id()) == 11){
00209 etcone = get_energy_in_cone( m_electron_cone, particleKine,
00210 (*firstParticle)->production_vertex()->position().vect(),
00211 theParticles
00212 );
00213
00214
00215 if( etcone < m_electron_et_cut ){
00216 continue;
00217 }
00218
00219 }
00220 else if(abs((*firstParticle)->pdg_id()) == 13){
00221 etcone = get_energy_in_cone( m_muon_cone, particleKine,
00222 (*firstParticle)->production_vertex()->position().vect(),
00223 theParticles
00224 );
00225
00226 if( etcone < m_muon_et_cut ){
00227 continue;
00228 }
00229
00230 }
00231 }
00232
00233
00234
00235 if (m_ignore_multivertices) {
00236 writeCollection->push_back(new Jet(particleKine));
00237 } else {
00238 Hep3Vector delta((*firstParticle)->production_vertex(
00239 )->position().vect()-primary_vertex);
00240 if ((*firstParticle)->production_vertex()!=0 &&
00241
00242
00243 delta.mag()<m_vertex_cut) {
00244 writeCollection->push_back(new Jet(particleKine));
00245 }
00246 }
00247 }
00248 }
00249
00250
00251 if ( ! JetCollectionHelper::record_jets(m_storeGate,writeCollection,
00252 m_outputCollectionName) )
00253 {
00254 report << MSG::ERROR
00255 << "cannot convert initial jet list to JetCollection"
00256 << endreq;
00257 return StatusCode::FAILURE;
00258 }
00259
00260
00261 JetCollectionHelper::remove_object(writeCollection,
00262 writeCollection->begin(),
00263 writeCollection->end());
00264 delete writeCollection;
00265
00266
00267 const INavigable4MomentumCollection* readCollection;
00268 checkOut = m_storeGate->retrieve(readCollection,m_outputCollectionName);
00269 if ( checkOut.isFailure() )
00270 {
00271 report << MSG::ERROR
00272 << "cannot read back initial JetCollection"
00273 << endreq;
00274 return checkOut;
00275 }
00276
00277
00278 for ( Jet::index_type theIndex=0; theIndex < readCollection->size();
00279 theIndex++ )
00280 {
00281
00282 theJets->push_back(new Jet(readCollection,theIndex));
00283 }
00284
00285
00286
00287 return checkOut;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296 Hep3Vector JetTruthTrackSelectorTool::highest_Et_vertex(
00297 std::vector<const HepMC::GenParticle*> theParticles) {
00298
00300
00302
00303 std::vector<Hep3Vector> vertex;
00304 bool vertex_flag;
00305 double max_Et;
00306 Hep3Vector primary_vertex(0.0, 0.0, 0.0);
00307 std::vector<double> Et_vert;
00308 std::vector<unsigned> nb_part;
00309 std::vector<MPIHiggsAnalysis::Vertex> vertices;
00310
00311 MyTruthTrackJetInfoContainer
00312 *container(MyTruthTrackJetInfoContainer::getTruthTrackJetInfoContainer());
00313
00314 container->clear();
00315 container->setVertexCut(m_vertex_cut);
00316
00317
00319
00321
00322
00323 std::vector<const HepMC::GenParticle*>::iterator
00324 firstParticle(theParticles.begin());
00325 std::vector<const HepMC::GenParticle*>::iterator
00326 lastParticle(theParticles.end());
00327
00328 for ( ; firstParticle != lastParticle; firstParticle++) {
00329
00330 HepLorentzVector particleKine = (*firstParticle)->momentum();
00331 HepPDT::ParticleID IDEN((*firstParticle)->pdg_id());
00332
00333 if (particleKine.perp()>m_Et_min_vert &&
00334 fabs(particleKine.pseudoRapidity())<m_etaMax &&
00335 (abs((*firstParticle)->pdg_id())!=13 || m_includeMuons)
00336 && IDEN.threeCharge()!=0
00337 && (*firstParticle)->production_vertex()!=0) {
00338
00339
00340 vertex_flag = false;
00341
00342 for (unsigned int l=0; l<vertex.size(); l++) {
00343
00344 Hep3Vector delta( (*firstParticle)->production_vertex()
00345 ->position().vect()-vertex[l] );
00346 if (delta.mag()<m_vertex_cut) {
00347 Et_vert[l] += particleKine.et();
00348 nb_part[l]++;
00349 vertices[l].setEt( vertices[l].Et()+particleKine.et() );
00350 vertices[l].setNumberOfTracks( vertices[l].numberOfTracks()+1 );
00351 vertex_flag = true;
00352 break;
00353 }
00354 }
00355 if (!vertex_flag) {
00356 vertex.push_back(
00357 (*firstParticle)->production_vertex(
00358 )->position().vect());
00359 Et_vert.push_back(particleKine.et());
00360 nb_part.push_back(1);
00361
00362 vertices.push_back(
00363 MPIHiggsAnalysis::Vertex( (*firstParticle)->production_vertex()
00364 ->position().vect(),
00365 Hep3Vector(0.,0.,0.), 0., 0,
00366 particleKine.et(), 1) );
00367
00368 }
00369 }
00370 }
00371
00372 if (vertex.size()==0) {
00373 return primary_vertex;
00374 }
00375
00377
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00390
00392
00393
00394
00395
00396
00397 max_Et = Et_vert[0];
00398 primary_vertex = vertex[0];
00399 for (unsigned int k=1; k<vertex.size(); k++) {
00400 if (Et_vert[k]>max_Et) {
00401 max_Et = Et_vert[k];
00402 primary_vertex = vertex[k];
00403 }
00404 }
00405
00406 container->setVertex(vertex);
00407 container->setEt(Et_vert);
00408 container->setNumberOfTracks(nb_part);
00409
00410 container->setVertices(vertices);
00411 container->sortVerticesAscendingInEt();
00412
00413 return primary_vertex;
00414
00415 }
00416
00417
00418
00419
00420
00421
00422 double
00423 JetTruthTrackSelectorTool::get_energy_in_cone(const double & cone,
00424 const HepLorentzVector & p,
00425 const Hep3Vector & vertex,
00426 vector<const HepMC::GenParticle*> theParticles) {
00427
00428
00429
00430
00431
00432 double ET(0.);
00433
00434
00435
00436
00437
00438 for (unsigned int k=0; k<theParticles.size(); k++ ) {
00439
00440 if(theParticles[k]->production_vertex()==NULL){
00441 continue;
00442 }
00443
00444 if(theParticles[k]->momentum().eta()>m_etaMax){
00445 continue;
00446 }
00447
00448 if (!m_ignore_multivertices){
00449
00450 Hep3Vector delta = theParticles[k]
00451 ->production_vertex()->position().vect()-vertex;
00452
00453
00454
00455 if (delta.mag()>m_vertex_cut){
00456 continue;
00457 }
00458 }
00459
00460 if ( p.deltaR(theParticles[k]->momentum()) < cone &&
00461 p.deltaR(theParticles[k]->momentum()) > m_inner_cone) {
00462
00463 ET = ET+theParticles[k]->momentum().et();
00464 }
00465
00466 }
00467
00468
00469 return ET;
00470
00471 }
00472
00473