CMS 3D CMS Logo

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