CMS 3D CMS Logo

HiggsValidation.cc
Go to the documentation of this file.
1 /*class HiggsValidation
2  *
3  * Class to fill dqm monitor elements from existing EDM file
4  *
5  */
6 
8 
10 
11 #include "CLHEP/Units/defs.h"
12 #include "CLHEP/Units/PhysicalConstants.h"
13 
15 
19 using namespace edm;
20 
22  : wmanager_(iPSet, consumesCollector()),
23  hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
24  particle_id(iPSet.getParameter<int>("pdg_id")),
25  particle_name(iPSet.getParameter<std::string>("particleName")) {
26  monitoredDecays = new MonitoredDecays(iPSet);
27  hepmcCollectionToken_ = consumes<HepMCProduct>(hepmcCollection_);
28  fPDGTableToken = esConsumes<edm::Transition::BeginRun>();
29 }
30 
32 
34  fPDGTable = c.getHandle(fPDGTableToken);
35 }
36 
39  std::string dir = "Generator/";
40  dir += particle_name;
41  DQMHelper dqm(&i);
42  i.setCurrentFolder(dir);
43 
44  // Number of analyzed events
45  nEvt = dqm.book1dHisto("nEvt", "n analyzed Events", 1, 0., 1., "bin", "Number of Events");
46 
47  //decay type
48 
49  std::string channel = particle_name + "_DecayChannels";
50  HiggsDecayChannels = dqm.book1dHisto(channel,
51  particle_name + " decay channels",
53  0,
55  "Decay Channels",
56  "Number of Events");
57 
58  for (size_t j = 0; j < monitoredDecays->size(); ++j) {
60  }
61 
62  //Kinematics
63  Higgs_pt = dqm.book1dHisto((particle_name + "_pt"),
64  (particle_name + " p_{t}"),
65  50,
66  0,
67  250,
68  "P_{t}^{" + particle_name + "} (GeV)",
69  "Number of Events");
70  Higgs_eta = dqm.book1dHisto((particle_name + "_eta"),
71  (particle_name + " #eta"),
72  50,
73  -5,
74  5,
75  "#eta^{" + particle_name + "}",
76  "Number of Events");
77  Higgs_mass = dqm.book1dHisto(
78  (particle_name + "_m"), (particle_name + " M"), 500, 0, 500, "M^{" + particle_name + "}", "Number of Events");
79 
80  int idx = 0;
81  for (unsigned int j = 0; j < monitoredDecays->NDecayParticles(); j++) {
82  HiggsDecayProd_pt.push_back(dqm.book1dHisto((monitoredDecays->ConvertIndex(idx) + "_pt"),
83  (monitoredDecays->ConvertIndex(idx) + " p_{t}"),
84  50,
85  0,
86  250,
87  "P_{t}^{" + monitoredDecays->ConvertIndex(idx) + "} (GeV)",
88  "Number of Events"));
89  HiggsDecayProd_eta.push_back(dqm.book1dHisto((monitoredDecays->ConvertIndex(idx) + "_eta"),
90  (monitoredDecays->ConvertIndex(idx) + " #eta"),
91  50,
92  -5,
93  5,
94  "#eta^{" + monitoredDecays->ConvertIndex(idx) + "}",
95  "Number of Events"));
96  idx++;
97  }
98 
99  return;
100 }
101 
103  double weight = wmanager_.weight(iEvent);
104  nEvt->Fill(0.5, weight);
105 
106  //Gathering the HepMCProduct information
108  iEvent.getByToken(hepmcCollectionToken_, evt);
109 
110  //Get EVENT
111  HepMC::GenEvent* myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
112 
113  // loop over all particles
114  bool filled = false;
115  for (HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin();
116  iter != myGenEvent->particles_end() && !filled;
117  ++iter) {
118  if (particle_id == std::abs((*iter)->pdg_id())) {
119  std::vector<HepMC::GenParticle*> decayprod;
120  int channel = findHiggsDecayChannel(*iter, decayprod);
121  HiggsDecayChannels->Fill(channel, weight);
122  Higgs_pt->Fill((*iter)->momentum().perp(), weight);
123  Higgs_eta->Fill((*iter)->momentum().eta(), weight);
124  Higgs_mass->Fill((*iter)->momentum().m(), weight);
125  for (unsigned int i = 0; i < decayprod.size(); i++) {
126  int idx = monitoredDecays->isDecayParticle(decayprod.at(i)->pdg_id());
127  if (0 <= idx && idx <= (int)HiggsDecayProd_pt.size()) {
128  HiggsDecayProd_pt.at(idx)->Fill(decayprod.at(i)->momentum().perp(), weight);
129  HiggsDecayProd_eta.at(idx)->Fill(decayprod.at(i)->momentum().eta(), weight);
130  }
131  }
132  filled = true;
133  }
134  }
135 
136  delete myGenEvent;
137 
138 } //analyze
139 
141  std::vector<HepMC::GenParticle*>& decayprod) {
142  if (genParticle->status() == 1)
143  return monitoredDecays->stable();
144  std::vector<int> children;
145  if (genParticle->end_vertex()) {
146  HepMC::GenVertex::particle_iterator des;
147  for (des = genParticle->end_vertex()->particles_begin(HepMC::descendants);
148  des != genParticle->end_vertex()->particles_end(HepMC::descendants);
149  ++des) {
150  if ((*des)->pdg_id() == genParticle->pdg_id())
151  continue;
152 
153  HepMC::GenVertex::particle_iterator mother = (*des)->production_vertex()->particles_begin(HepMC::parents);
154  if ((*mother)->pdg_id() == genParticle->pdg_id()) {
155  children.push_back((*des)->pdg_id());
156  decayprod.push_back((*des));
157  }
158  }
159  }
160 
161  if (children.size() == 2 && children.at(0) != 0 && children.at(1) != 0) {
162  return monitoredDecays->position(children.at(0), children.at(1));
163  }
164  return monitoredDecays->undetermined();
165 }
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
std::vector< MonitorElement * > HiggsDecayProd_pt
TPRegexp parents
Definition: eve_filter.cc:21
MonitorElement * Higgs_eta
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
std::vector< MonitorElement * > HiggsDecayProd_eta
Definition: weight.py:1
MonitorElement * nEvt
size_t position(int pid1, int pid2)
MonitoredDecays * monitoredDecays
int findHiggsDecayChannel(const HepMC::GenParticle *, std::vector< HepMC::GenParticle *> &decayprod)
HiggsValidation(const edm::ParameterSet &)
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:224
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * Higgs_pt
virtual 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)
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
MonitorElement * HiggsDecayChannels
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > fPDGTableToken
void analyze(edm::Event const &, edm::EventSetup const &) override
edm::InputTag hepmcCollection_
~HiggsValidation() override
std::string ConvertIndex(int index)
WeightManager wmanager_
HLT enums.
std::string channel(size_t i)
std::string particle_name
double weight(const edm::Event &)
Definition: DQMStore.h:18
Definition: Run.h:45
MonitorElement * Higgs_mass