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 
50 
52  public:
53  ParticleMonitor(std::string name_, int pdgid_, DQMStore::IBooker &i, bool nlog_ = false)
54  : name(name_), pdgid(pdgid_), count(0), nlog(nlog_) {
55  DQMHelper dqm(&i);
56  // Number of analyzed events
57  if (!nlog) {
58  numberPerEvent = dqm.book1dHisto(
59  name + "Number", "Number of " + name + "'s per event", 20, 0, 20, "No. of " + name, "Number of Events");
60  } else {
61  numberPerEvent = dqm.book1dHisto(name + "Number",
62  "Number of " + name + "'s per event",
63  20,
64  0,
65  20,
66  "log_{10}(No. of " + name + ")",
67  "Number of Events");
68  }
69  p_init = dqm.book1dHisto(name + "Momentum",
70  "log_{10}(P) of the " + name + "s",
71  60,
72  -2,
73  4,
74  "log_{10}(P) (log_{10}(GeV))",
75  "Number of " + name);
76 
77  eta_init = dqm.book1dHisto(name + "Eta", "#eta of the " + name + "s", 100, -5., 5., "#eta", "Number of " + name);
78 
79  lifetime_init = dqm.book1dHisto(name + "LifeTime",
80  "#phi of the " + name + "s",
81  100,
82  -15,
83  -5,
84  "Log_{10}(life-time^{final}) (log_{10}(s))",
85  "Number of " + name);
86 
87  p_final = dqm.book1dHisto(name + "MomentumFinal",
88  "log_{10}(P^{final}) of " + name + "s at end of decay chain",
89  60,
90  -2,
91  4,
92  "log_{10}(P^{final}) (log_{10}(GeV))",
93  "Number of " + name);
94 
95  lifetime_final = dqm.book1dHisto(name + "LifeTimeFinal",
96  "Log_{10}(life-time^{final}) of " + name + "s at end of decay chain",
97  100,
98  -15,
99  -5,
100  "Log_{10}(life-time^{final}) (log_{10}(s))",
101  "Number of " + name);
102  }
103 
105 
106  bool Fill(const HepMC::GenParticle *p, double weight) {
107  if (p->pdg_id() == pdgid) {
108  if (isFirst(p)) {
109  p_init->Fill(log10(p->momentum().rho()), weight);
110  eta_init->Fill(p->momentum().eta(), weight);
111  const HepMC::GenParticle *pf = GetFinal(p); // inlcude mixing
112  p_final->Fill(log10(pf->momentum().rho()), weight);
113  // compute lifetime...
114  if (p->production_vertex() && p->end_vertex()) {
115  TVector3 PV(p->production_vertex()->point3d().x(),
116  p->production_vertex()->point3d().y(),
117  p->production_vertex()->point3d().z());
118  TVector3 SV(p->end_vertex()->point3d().x(), p->end_vertex()->point3d().y(), p->end_vertex()->point3d().z());
119  TVector3 DL = SV - PV;
120  double c(2.99792458E8), Ltau(DL.Mag() / 100) /*cm->m*/, beta(p->momentum().rho() / p->momentum().m());
121  double lt = Ltau / (c * beta);
122  if (lt > 1E-16)
123  lifetime_init->Fill(log10(lt), weight);
124  if (pf->end_vertex()) {
125  TVector3 SVf(
126  pf->end_vertex()->point3d().x(), pf->end_vertex()->point3d().y(), pf->end_vertex()->point3d().z());
127  DL = SVf - PV;
128  Ltau = DL.Mag() / 100;
129  lt = Ltau / (c * beta);
130  if (lt > 1E-16)
131  lifetime_final->Fill(log10(lt), weight);
132  }
133  }
134  count++;
135  }
136  return true;
137  }
138  return false;
139  }
140 
141  void FillCount(double weight) {
142  if (nlog)
143  numberPerEvent->Fill(log10(count), weight);
144  else
146  count = 0;
147  }
148 
149  int PDGID() { return pdgid; }
150 
151  private:
152  bool isFirst(const HepMC::GenParticle *p) {
153  if (p->production_vertex()) {
154  for (HepMC::GenVertex::particles_in_const_iterator m = p->production_vertex()->particles_in_const_begin();
155  m != p->production_vertex()->particles_in_const_end();
156  m++) {
157  if (abs((*m)->pdg_id()) == abs(p->pdg_id()))
158  return false;
159  }
160  }
161  return true;
162  }
163 
164  // includes mixing (assuming mixing is not occurring more than 5 times back and forth)
166  const HepMC::GenParticle *aPart = p;
167  for (unsigned int iMix = 0; iMix < 10; iMix++) {
168  bool foundSimilar = false;
169  if (aPart->end_vertex()) {
170  if (aPart->end_vertex()->particles_out_size() != 0) {
171  for (HepMC::GenVertex::particles_out_const_iterator d = aPart->end_vertex()->particles_out_const_begin();
172  d != aPart->end_vertex()->particles_out_const_end();
173  d++) {
174  if (abs((*d)->pdg_id()) == abs(aPart->pdg_id())) {
175  aPart = *d;
176  foundSimilar = true;
177  break;
178  }
179  }
180  }
181  if (!foundSimilar)
182  break;
183  }
184  }
185  return aPart;
186  }
187 
189  int pdgid;
190  unsigned int count;
191  bool nlog;
193  };
194 
196  std::vector<ParticleMonitor> particles;
197 
206  //
217  //
220  //
233 
235 
241 
243 };
244 
245 #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
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)
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > fPDGTableToken
MonitorElement * genPtclNumber
edm::InputTag hepmcCollection_
MonitorElement * outVrtxStablePtclNumber
Definition: DQMStore.h:18
std::vector< ParticleMonitor > particles
MonitorElement * pdf_ssbar
Definition: Run.h:45
MonitorElement * parton1Id