CMS 3D CMS Logo

BasicHepMCValidation.h
Go to the documentation of this file.
1 #ifndef BASICHEPMCVALIDATION_H
2 #define BASICHEPMCVALIDATION_H
3 
4 /*class BasicHepMCValidation
5  *
6  * Class to fill Event Generator dqm monitor elements; works on HepMCProduct
7  *
8  *
9  */
10 
11 // framework & common header files
15 
20 
21 //DQM services
26 
28 
30 
32 #include "TVector3.h"
33 
35 public:
36  explicit BasicHepMCValidation(const edm::ParameterSet &);
37  ~BasicHepMCValidation() override;
38 
39  void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override;
40  void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override;
41  void analyze(edm::Event const &, edm::EventSetup const &) override;
42 
43 private:
46 
49 
51  public:
52  ParticleMonitor(std::string name_, int pdgid_, DQMStore::IBooker &i, bool nlog_ = false)
53  : name(name_), pdgid(pdgid_), count(0), nlog(nlog_) {
54  DQMHelper dqm(&i);
55  // Number of analyzed events
56  if (!nlog) {
58  name + "Number", "Number of " + name + "'s per event", 20, 0, 20, "No. of " + name, "Number of Events");
59  } else {
60  numberPerEvent = dqm.book1dHisto(name + "Number",
61  "Number of " + name + "'s per event",
62  20,
63  0,
64  20,
65  "log_{10}(No. of " + name + ")",
66  "Number of Events");
67  }
68  p_init = dqm.book1dHisto(name + "Momentum",
69  "log_{10}(P) of the " + name + "s",
70  60,
71  -2,
72  4,
73  "log_{10}(P) (log_{10}(GeV))",
74  "Number of " + name);
75 
76  eta_init = dqm.book1dHisto(name + "Eta", "#eta of the " + name + "s", 100, -5., 5., "#eta", "Number of " + name);
77 
78  lifetime_init = dqm.book1dHisto(name + "LifeTime",
79  "#phi of the " + name + "s",
80  100,
81  -15,
82  -5,
83  "Log_{10}(life-time^{final}) (log_{10}(s))",
84  "Number of " + name);
85 
86  p_final = dqm.book1dHisto(name + "MomentumFinal",
87  "log_{10}(P^{final}) of " + name + "s at end of decay chain",
88  60,
89  -2,
90  4,
91  "log_{10}(P^{final}) (log_{10}(GeV))",
92  "Number of " + name);
93 
94  lifetime_final = dqm.book1dHisto(name + "LifeTimeFinal",
95  "Log_{10}(life-time^{final}) of " + name + "s at end of decay chain",
96  100,
97  -15,
98  -5,
99  "Log_{10}(life-time^{final}) (log_{10}(s))",
100  "Number of " + name);
101  }
102 
104 
105  bool Fill(const HepMC::GenParticle *p, double weight) {
106  if (p->pdg_id() == pdgid) {
107  if (isFirst(p)) {
108  p_init->Fill(log10(p->momentum().rho()), weight);
109  eta_init->Fill(p->momentum().eta(), weight);
110  const HepMC::GenParticle *pf = GetFinal(p); // inlcude mixing
111  p_final->Fill(log10(pf->momentum().rho()), weight);
112  // compute lifetime...
113  if (p->production_vertex() && p->end_vertex()) {
114  TVector3 PV(p->production_vertex()->point3d().x(),
115  p->production_vertex()->point3d().y(),
116  p->production_vertex()->point3d().z());
117  TVector3 SV(p->end_vertex()->point3d().x(), p->end_vertex()->point3d().y(), p->end_vertex()->point3d().z());
118  TVector3 DL = SV - PV;
119  double c(2.99792458E8), Ltau(DL.Mag() / 100) /*cm->m*/, beta(p->momentum().rho() / p->momentum().m());
120  double lt = Ltau / (c * beta);
121  if (lt > 1E-16)
122  lifetime_init->Fill(log10(lt), weight);
123  if (pf->end_vertex()) {
124  TVector3 SVf(
125  pf->end_vertex()->point3d().x(), pf->end_vertex()->point3d().y(), pf->end_vertex()->point3d().z());
126  DL = SVf - PV;
127  Ltau = DL.Mag() / 100;
128  lt = Ltau / (c * beta);
129  if (lt > 1E-16)
130  lifetime_final->Fill(log10(lt), weight);
131  }
132  }
133  count++;
134  }
135  return true;
136  }
137  return false;
138  }
139 
140  void FillCount(double weight) {
141  if (nlog)
142  numberPerEvent->Fill(log10(count), weight);
143  else
144  numberPerEvent->Fill(count, weight);
145  count = 0;
146  }
147 
148  int PDGID() { return pdgid; }
149 
150  private:
151  bool isFirst(const HepMC::GenParticle *p) {
152  if (p->production_vertex()) {
153  for (HepMC::GenVertex::particles_in_const_iterator m = p->production_vertex()->particles_in_const_begin();
154  m != p->production_vertex()->particles_in_const_end();
155  m++) {
156  if (abs((*m)->pdg_id()) == abs(p->pdg_id()))
157  return false;
158  }
159  }
160  return true;
161  }
162 
163  // includes mixing (assuming mixing is not occurring more than 5 times back and forth)
165  const HepMC::GenParticle *aPart = p;
166  for (unsigned int iMix = 0; iMix < 10; iMix++) {
167  bool foundSimilar = false;
168  if (aPart->end_vertex()) {
169  if (aPart->end_vertex()->particles_out_size() != 0) {
170  for (HepMC::GenVertex::particles_out_const_iterator d = aPart->end_vertex()->particles_out_const_begin();
171  d != aPart->end_vertex()->particles_out_const_end();
172  d++) {
173  if (abs((*d)->pdg_id()) == abs(aPart->pdg_id())) {
174  aPart = *d;
175  foundSimilar = true;
176  break;
177  }
178  }
179  }
180  if (!foundSimilar)
181  break;
182  }
183  }
184  return aPart;
185  }
186 
188  int pdgid;
189  unsigned int count;
190  bool nlog;
192  };
193 
195  std::vector<ParticleMonitor> particles;
196 
205  //
216  //
219  //
232 
234 
240 
242 };
243 
244 #endif
MonitorElement * genPtclStatus
MonitorElement * DeltaEcms
MonitorElement * genVrtxNumber
MonitorElement * unknownPDTNumber
MonitorElement * pdf_bbbar
MonitorElement * outVrtxPtclNumber
MonitorElement * pdf_ccbar
bool isFirst(const HepMC::GenParticle *p)
MonitorElement * Bjorken_x
MonitorElement * otherPtclNumber
other ME&#39;s
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
BasicHepMCValidation(const edm::ParameterSet &)
MonitorElement * parton2Id
MonitorElement * otherPtclMomentum
MonitorElement * stablePtclCharge
Definition: weight.py:1
MonitorElement * partonNumber
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
void Fill(long long x)
MonitorElement * vrtxRadius
MonitorElement * book1dHisto(std::string name, std::string title, int n, double xmin, double xmax, std::string xaxis, std::string yaxis)
Definition: DQMHelper.cc:7
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * log10DeltaEcms
MonitorElement * stablePtclPhi
MonitorElement * stablePtclEta
d
Definition: ztail.py:151
const HepMC::GenParticle * GetFinal(const HepMC::GenParticle *p)
void analyze(edm::Event const &, edm::EventSetup const &) override
MonitorElement * stablePtclp
MonitorElement * status1ShortLived
MonitorElement * stablePtclpT
MonitorElement * stableChaNumber
ParticleMonitor(std::string name_, int pdgid_, DQMStore::IBooker &i, bool nlog_=false)
MonitorElement * stablePtclNumber
bool Fill(const HepMC::GenParticle *p, double weight)
MonitorElement * genPtclNumber
edm::InputTag hepmcCollection_
MonitorElement * outVrtxStablePtclNumber
std::vector< ParticleMonitor > particles
MonitorElement * pdf_ssbar
Definition: Run.h:45
MonitorElement * parton1Id