CMS 3D CMS Logo

TrackingTruthValid.cc
Go to the documentation of this file.
2 
4 
12 
15 
20 
21 #include <cmath>
22 
24 
30 
31 
33  : runStandalone( conf.getParameter<bool>("runStandalone") )
34  , outputFile( conf.getParameter<std::string>( "outputFile" ) )
35  , dbe_( nullptr )
36  , vec_TrackingParticle_Token_( consumes<TrackingParticleCollection>( conf.getParameter<edm::InputTag>( "src" ) ) ) {}
37 
40  ibooker.setCurrentFolder("Tracking/TrackingMCTruth/TrackingParticle");
41 
42 
43  meTPMass = ibooker.book1D("TPMass","Tracking Particle Mass",100, -1,+5.);
44  meTPCharge = ibooker.book1D("TPCharge","Tracking Particle Charge",10, -5, 5);
45  meTPId = ibooker.book1D("TPId","Tracking Particle Id",500, -5000, 5000);
46  meTPProc = ibooker.book1D("TPProc","Tracking Particle Proc",20, -0.5, 19.5);
47  meTPAllHits = ibooker.book1D("TPAllHits", "Tracking Particle All Hits", 200, -0.5, 199.5);
48  meTPMatchedHits = ibooker.book1D("TPMatchedHits", "Tracking Particle Matched Hits", 100, -0.5, 99.5);
49  meTPPt = ibooker.book1D("TPPt", "Tracking Particle Pt",100, 0, 100.);
50  meTPEta = ibooker.book1D("TPEta", "Tracking Particle Eta",100, -7., 7.);
51  meTPPhi = ibooker.book1D("TPPhi", "Tracking Particle Phi",100, -4., 4);
52  meTPVtxX = ibooker.book1D("TPVtxX", "Tracking Particle VtxX",100, -100, 100.);
53  meTPVtxY = ibooker.book1D("TPVtxY", "Tracking Particle VtxY",100, -100, 100.);
54  meTPVtxZ = ibooker.book1D("TPVtxZ", "Tracking Particle VtxZ",100, -100, 100.);
55  meTPtip = ibooker.book1D("TPtip", "Tracking Particle tip",100, 0, 1000.);
56  meTPlip = ibooker.book1D("TPlip", "Tracking Particle lip",100, 0, 100.);
57 
58 
59  // Prepare Axes Labels for Processes
60  meTPProc->setBinLabel( 1,"Undefined"); // value = 0
61  meTPProc->setBinLabel( 2,"Unknown"); // value = 1
62  meTPProc->setBinLabel( 3,"Primary"); // value = 2
63  meTPProc->setBinLabel( 4,"Hadronic"); // value = 3
64  meTPProc->setBinLabel( 5,"Decay"); // value = 4
65  meTPProc->setBinLabel( 6,"Compton"); // value = 5
66  meTPProc->setBinLabel( 7,"Annihilation"); // value = 6
67  meTPProc->setBinLabel( 8,"EIoni"); // value = 7
68  meTPProc->setBinLabel( 9,"HIoni"); // value = 8
69  meTPProc->setBinLabel(10,"MuIoni"); // value = 9
70  meTPProc->setBinLabel(11,"Photon"); // value = 10
71  meTPProc->setBinLabel(12,"MuPairProd"); // value = 11
72  meTPProc->setBinLabel(13,"Conversions"); // value = 12
73  meTPProc->setBinLabel(14,"EBrem"); // value = 13
74  meTPProc->setBinLabel(15,"SynchrotronRadiation"); // value = 14
75  meTPProc->setBinLabel(16,"MuBrem"); // value = 15
76  meTPProc->setBinLabel(17,"MuNucl"); // value = 16
77  meTPProc->setBinLabel(18,"");
78  meTPProc->setBinLabel(19,"");
79  meTPProc->setBinLabel(20,"");
80 }
81 
83 
84  edm::Handle<TrackingParticleCollection> TruthTrackContainer ;
85  // edm::Handle<TrackingVertexCollection> TruthVertexContainer;
86 
87  event.getByToken( vec_TrackingParticle_Token_, TruthTrackContainer );
88 
89  const TrackingParticleCollection *tPC = TruthTrackContainer.product();
90 
91  // Loop over TrackingParticle's
92  for (TrackingParticleCollection::const_iterator t = tPC -> begin(); t != tPC -> end(); ++t) {
93  //if(t -> trackerPSimHit().size() ==0) cout << " Track with 0 SimHit " << endl;
94 
95  meTPMass->Fill(t->mass());
96  meTPCharge->Fill(t->charge() );
97  meTPId->Fill(t->pdgId());
98  meTPPt->Fill(sqrt(t->momentum().perp2()));
99  meTPEta->Fill(t->momentum().eta());
100  meTPPhi->Fill(t->momentum().Phi());
101  //#warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
102  //#ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
103  // std::vector<PSimHit> trackerPSimHit( t->trackPSimHit(DetId::Tracker) );
104  //#endif
105  meTPAllHits->Fill(t->numberOfTrackerHits());
106  //get the process of the first hit
107  //#warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
108  //#ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
109  // if(trackerPSimHit.size() !=0) meTPProc->Fill( trackerPSimHit.front().processType());
110  //#endif
111 
112  // there is no more the PSimHits collection !!! how to deal w/ the processType ?
113  // if(t->numberOfTrackerHits() !=0) meTPProc->Fill( trackerPSimHit.front().processType());
114 
115  meTPMatchedHits->Fill(t->numberOfTrackerLayers());
116  meTPVtxX->Fill(t->vx());
117  meTPVtxY->Fill(t->vy());
118  meTPVtxZ->Fill(t->vz());
119  meTPtip->Fill(sqrt(t->vertex().perp2()));
120  meTPlip->Fill(t->vz());
121 
122  /*
123  // Compare momenta from sources
124  cout << "T.P. Track mass, Momentum, q , ID, & Event # "
125  << t -> mass() << " "
126  << t -> p4() << " " << t -> charge() << " "
127  << t -> pdgId() << " "
128  << t -> eventId().bunchCrossing() << "." << t -> eventId().event() << endl;
129 
130  if(t->mass() < 0) cout << "======= WARNING, this particle has negative mass: " << t->mass()
131  << " and pdgId: " << t->pdgId() << endl;
132  if(t->pdgId() == 0) cout << "======= WARNING, this particle has pdgId = 0: " << t->pdgId() << endl;
133  cout << " Hits for this track: " << t -> trackerPSimHit().size() << endl;
134  */
135 
136  /*
137  std::cout << std::endl << "### Tracking Particle ###" << std::endl;
138  std::cout << (*t) << std::endl;
139  std::cout << "\t Tracker: " << t->trackerPSimHit().size() << std::endl;
140  std::cout << "\t Muon: " << t->muonPSimHit().size() << std::endl;
141  std::cout << (*t) << std::endl;
142  */
143  } // End loop over TrackingParticle
144 
145  // Loop over TrackingVertex's
146  /*
147  cout << "Dumping sample vertex info" << endl;
148  for (TrackingVertexCollection::const_iterator v = tVC -> begin(); v != tVC -> end(); ++v) {
149  cout << " Vertex Position & Event #" << v -> position() << " " << v -> eventId().bunchCrossing() << "." << v -> eventId().event() << endl;
150  cout << " Associated with " << v -> daughterTracks().size() << " tracks" << endl;
151  // Get Geant and HepMC positions
152  for (genv_iterator genV = v -> genVertices_begin(); genV != v -> genVertices_end(); ++genV) {
153  cout << " HepMC vertex position " << (*(*genV)).position() << endl;
154  }
155  for (g4v_iterator g4V = v -> g4Vertices_begin(); g4V != v -> g4Vertices_end(); ++g4V) {
156  cout << " Geant vertex position " << (*g4V).position() << endl;
157  // Probably empty all the time, currently
158  }
159 
160  // Loop over daughter track(s)
161  for (tp_iterator iTP = v -> daughterTracks_begin(); iTP != v -> daughterTracks_end(); ++iTP) {
162  cout << " Daughter starts: " << (*(*iTP)).vertex();
163  for (g4t_iterator g4T = (*(*iTP)).g4Track_begin(); g4T != (*(*iTP)).g4Track_end(); ++g4T) {
164  cout << " p " << g4T->momentum();
165  }
166  cout << endl;
167  }
168 
169  // Loop over source track(s) (can be multiple since vertices are collapsed)
170  for (tp_iterator iTP = v -> sourceTracks_begin(); iTP != v -> sourceTracks_end(); ++iTP) {
171  cout << " Source starts: " << (*(*iTP)).vertex();
172  for (g4t_iterator g4T = (*iTP)->g4Track_begin(); g4T != (*iTP)->g4Track_end(); ++g4T) {
173  cout << ", p " << g4T ->momentum();
174  }
175  cout << endl;
176  }
177  } // End loop over TrackingVertex
178  */
179 
180 
181 }
182 
184  //Only in standalone mode save local root file
185  if (runStandalone && !outputFile.empty() && dbe_ ){dbe_->save(outputFile);}
186 
187 }
MonitorElement * meTPAllHits
edm::RefVector< std::vector< TrackingParticle > > TrackingParticleContainer
MonitorElement * meTPVtxX
TrackingVertex::g4v_iterator g4v_iterator
std::vector< SimVertex >::const_iterator g4v_iterator
MonitorElement * meTPtip
MonitorElement * meTPPhi
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
MonitorElement * meTPVtxZ
MonitorElement * meTPVtxY
#define nullptr
TrackingParticle::genp_iterator genp_iterator
void Fill(long long x)
MonitorElement * meTPEta
edm::EDGetTokenT< TrackingParticleCollection > vec_TrackingParticle_Token_
TrackingVertex::genv_iterator genv_iterator
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
T sqrt(T t)
Definition: SSEVec.h:18
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &run, const edm::EventSetup &es) override
std::vector< TrackingParticle > TrackingParticleCollection
MonitorElement * meTPProc
#define end
Definition: vmac.h:39
DQMStore * dbe_
std::vector< SimTrack >::const_iterator g4t_iterator
T const * product() const
Definition: Handle.h:81
void analyze(const edm::Event &, const edm::EventSetup &) override
void endJob() override
MonitorElement * meTPMatchedHits
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2443
MonitorElement * meTPCharge
#define begin
Definition: vmac.h:32
HLT enums.
TrackingParticleRefVector::iterator tp_iterator
MonitorElement * meTPMass
MonitorElement * meTPlip
MonitorElement * meTPPt
Definition: event.py:1
Definition: Run.h:44
TrackingTruthValid(const edm::ParameterSet &conf)
MonitorElement * meTPId
TrackingParticle::g4t_iterator g4t_iterator