CMS 3D CMS Logo

WValidation.cc
Go to the documentation of this file.
1 /*class WValidation
2  *
3  * Class to fill dqm monitor elements from existing EDM file
4  *
5  */
6 
9 #include "TLorentzVector.h"
10 
11 #include "CLHEP/Units/defs.h"
12 #include "CLHEP/Units/PhysicalConstants.h"
13 
16 using namespace edm;
17 
19  : wmanager_(iPSet, consumesCollector()),
20  hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
21  _flavor(iPSet.getParameter<int>("decaysTo")),
22  _name(iPSet.getParameter<std::string>("name")) {
23  hepmcCollectionToken_ = consumes<HepMCProduct>(hepmcCollection_);
24 }
25 
27 
30  std::string folderName = "Generator/W";
31  folderName += _name;
32  DQMHelper dqm(&i);
33  i.setCurrentFolder(folderName);
34 
35  // Number of analyzed events
36  nEvt = dqm.book1dHisto("nEvt", "n analyzed Events", 1, 0., 1., "bin", "Number of Events");
37 
38  //Kinematics
39  Wmass = dqm.book1dHisto("Wmass", "inv. Mass W", 70, 0, 140, "M_{T}^{W} (GeV)", "Number of Events");
40  WmassPeak = dqm.book1dHisto("WmassPeak", "inv. Mass W", 80, 80, 100, "M_{T}^{W} (GeV)", "Number of Events");
41  Wpt = dqm.book1dHisto("Wpt", "W pt", 100, 0, 200, "P_{T}^{W} (GeV)", "Number of Events");
42  WptLog = dqm.book1dHisto("WptLog", "log(W pt)", 100, 0., 5., "Log_{10}(P_{T}^{W}) (GeV)", "Number of Events");
43  Wrap = dqm.book1dHisto("Wrap", "W y", 100, -5, 5, "Y^{W}", "Number of Events");
44  Wdaughters = dqm.book1dHisto("Wdaughters", "W daughters", 60, -30, 30, "W daughters (PDG ID)", "Number of Events");
45 
46  lepmet_mT = dqm.book1dHisto("lepmet_mT",
47  "lepton-met transverse mass",
48  70,
49  0,
50  140,
51  "M_{T}^{Lepton_{T}+E_{T}^{Miss}} (GeV)",
52  "Number of Events");
53  lepmet_mTPeak = dqm.book1dHisto("lepmet_mTPeak",
54  "lepton-met transverse mass",
55  80,
56  80,
57  100,
58  "M_{T}^{Lepton_{T}+E_{T}^{Miss}} (GeV)",
59  "Number of Events");
60  lepmet_pt = dqm.book1dHisto(
61  "lepmet_pt", "lepton-met", 100, 0, 200, "P_{T}^{Lepton_{T}+E_{T}^{Miss}} (GeV)", "Number of Events");
62  lepmet_ptLog = dqm.book1dHisto("lepmet_ptLog",
63  "log(lepton-met pt)",
64  100,
65  0.,
66  5.,
67  "log_{10}(P_{T}^{Lepton_{T}+E_{T}^{Miss}}) (Log_{10}(GeV))",
68  "Number of Events");
69 
71  "gamma_energy", "photon energy in W rest frame", 200, 0., 100., "E_{#gamma}^{W rest-frame}", "Number of Events");
72  cos_theta_gamma_lepton = dqm.book1dHisto("cos_theta_gamma_lepton",
73  "cos_theta_gamma_lepton in W rest frame",
74  200,
75  -1,
76  1,
77  "cos(#theta_{#gamma-lepton}^{W rest-frame})",
78  "Number of Events");
79 
80  leppt = dqm.book1dHisto("leadpt", "lepton pt", 200, 0., 200., "P_{t}^{Lead-Lepton} (GeV)", "Number of Events");
81  met = dqm.book1dHisto("met", "met", 200, 0., 200., "E_{T}^{Miss} (GeV)", "Number of Events");
82  lepeta = dqm.book1dHisto("leadeta", "leading lepton eta", 100, -5., 5., "#eta^{Lead-Lepton}", "Number of Events");
83 
84  return;
85 }
86 
88 
90  // we *DO NOT* rely on a Z entry in the particle listings!
91 
94  iEvent.getByToken(hepmcCollectionToken_, evt);
95 
96  //Get EVENT
97  const HepMC::GenEvent* myGenEvent = evt->GetEvent();
98 
99  double weight = wmanager_.weight(iEvent);
100 
101  nEvt->Fill(0.5, weight);
102 
103  std::vector<const HepMC::GenParticle*> allleptons;
104  std::vector<const HepMC::GenParticle*> allneutrinos;
105 
106  //requires status 1 for leptons and neutrinos (except tau)
107  int requiredstatus = (std::abs(_flavor) == 11 || std::abs(_flavor) == 13) ? 1 : 3;
108 
109  bool vetotau = true;
110  // alternatively (std::abs(_flavor) == 11 || std::abs(_flavor) == 12 || std::abs(_flavor) ==13 || std::abs(_flavor) ==14 || std::abs(_flavor) ==16) ? true : false;
111 
112  for (HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin();
113  iter != myGenEvent->particles_end();
114  ++iter) {
115  if (vetotau) {
116  if ((*iter)->status() == 3 && std::abs((*iter)->pdg_id()) == 15)
117  return;
118  }
119  if ((*iter)->status() == requiredstatus) {
120  //@todo: improve this selection
121  if ((*iter)->pdg_id() == _flavor)
122  allleptons.push_back(*iter);
123  else if (std::abs((*iter)->pdg_id()) == std::abs(_flavor) + 1)
124  allneutrinos.push_back(*iter);
125  }
126  }
127 
128  //nothing to do if we don't have 2 particles
129  if (allleptons.empty() || allneutrinos.empty())
130  return;
131 
132  //sort them in pt
133  std::sort(allleptons.begin(), allleptons.end(), HepMCValidationHelper::sortByPt);
134  std::sort(allneutrinos.begin(), allneutrinos.end(), HepMCValidationHelper::sortByPt);
135 
136  //get the first lepton and the first neutrino, and check that one is particle one is antiparticle (product of pdgids < 0)
137  std::vector<const HepMC::GenParticle*> products;
138  if (allleptons.front()->pdg_id() * allneutrinos.front()->pdg_id() > 0)
139  return;
140 
141  //require at least 20 GeV on the lepton
142  if (allleptons.front()->momentum().perp() < 20. || allneutrinos.front()->momentum().perp() < 20.)
143  return;
144 
145  //find possible qed fsr photons
146  std::vector<const HepMC::GenParticle*> selectedLepton;
147  selectedLepton.push_back(allleptons.front());
148  std::vector<const HepMC::GenParticle*> fsrphotons;
149  HepMCValidationHelper::findFSRPhotons(selectedLepton, myGenEvent, 0.1, fsrphotons);
150 
151  Wdaughters->Fill(allleptons.front()->pdg_id(), weight);
152  Wdaughters->Fill(allneutrinos.front()->pdg_id(), weight);
153 
154  //assemble FourMomenta
155  TLorentzVector lep1(allleptons[0]->momentum().x(),
156  allleptons[0]->momentum().y(),
157  allleptons[0]->momentum().z(),
158  allleptons[0]->momentum().t());
159  TLorentzVector lep2(allneutrinos[0]->momentum().x(),
160  allneutrinos[0]->momentum().y(),
161  allneutrinos[0]->momentum().z(),
162  allneutrinos[0]->momentum().t());
163  TLorentzVector dilepton_mom = lep1 + lep2;
164  TLorentzVector dilepton_andphoton_mom = dilepton_mom;
165  std::vector<TLorentzVector> gammasMomenta;
166  for (unsigned int ipho = 0; ipho < fsrphotons.size(); ++ipho) {
167  TLorentzVector phomom(fsrphotons[ipho]->momentum().x(),
168  fsrphotons[ipho]->momentum().y(),
169  fsrphotons[ipho]->momentum().z(),
170  fsrphotons[ipho]->momentum().t());
171  dilepton_andphoton_mom += phomom;
172  Wdaughters->Fill(fsrphotons[ipho]->pdg_id(), weight);
173  gammasMomenta.push_back(phomom);
174  }
175  //Fill "true" W histograms
176  Wmass->Fill(dilepton_andphoton_mom.M(), weight);
177  WmassPeak->Fill(dilepton_andphoton_mom.M(), weight);
178  Wpt->Fill(dilepton_andphoton_mom.Pt(), weight);
179  WptLog->Fill(log10(dilepton_andphoton_mom.Pt()), weight);
180  Wrap->Fill(dilepton_andphoton_mom.Rapidity(), weight);
181 
182  TLorentzVector met_mom = HepMCValidationHelper::genMet(myGenEvent, -3., 3.);
183  TLorentzVector lep1T(lep1.Px(), lep1.Py(), 0., lep1.Et());
184  TLorentzVector lepmet_mom = lep1T + met_mom;
185  //Fill lepmet histograms
186  lepmet_mT->Fill(lepmet_mom.M(), weight);
187  lepmet_mTPeak->Fill(lepmet_mom.M(), weight);
188  lepmet_pt->Fill(lepmet_mom.Pt(), weight);
189  lepmet_ptLog->Fill(log10(lepmet_mom.Pt()), weight);
190 
191  //Fill lepton histograms
192  leppt->Fill(lep1.Pt(), weight);
193  lepeta->Fill(lep1.Eta(), weight);
194  met->Fill(met_mom.Pt(), weight);
195 
196  //boost everything in the W frame
197  TVector3 boost = dilepton_andphoton_mom.BoostVector();
198  boost *= -1.;
199  lep1.Boost(boost);
200  lep2.Boost(boost);
201  for (unsigned int ipho = 0; ipho < gammasMomenta.size(); ++ipho) {
202  gammasMomenta[ipho].Boost(boost);
203  }
204  std::sort(gammasMomenta.begin(), gammasMomenta.end(), HepMCValidationHelper::GreaterByE<TLorentzVector>);
205 
206  //fill gamma histograms
207  if (!gammasMomenta.empty() && dilepton_andphoton_mom.M() > 50.) {
208  gamma_energy->Fill(gammasMomenta.front().E(), weight);
209  double dphi = lep1.DeltaR(gammasMomenta.front());
210  cos_theta_gamma_lepton->Fill(cos(dphi), weight);
211  }
212 
213 } //analyze
WValidation(const edm::ParameterSet &)
Definition: WValidation.cc:18
edm::InputTag hepmcCollection_
Definition: WValidation.h:43
MonitorElement * leppt
Definition: WValidation.h:51
void findFSRPhotons(const std::vector< const HepMC::GenParticle * > &leptons, const std::vector< const HepMC::GenParticle * > &all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
Definition: CLHEP.h:16
MonitorElement * Wrap
Definition: WValidation.h:49
MonitorElement * nEvt
Definition: WValidation.h:48
WeightManager wmanager_
Definition: WValidation.h:42
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::string _name
decay flavor name
Definition: WValidation.h:57
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
~WValidation() override
Definition: WValidation.cc:26
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
Definition: weight.py:1
MonitorElement * lepeta
Definition: WValidation.h:51
MonitorElement * lepmet_mT
Definition: WValidation.h:50
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&...args)
Definition: ESProducts.h:128
MonitorElement * lepmet_pt
Definition: WValidation.h:50
void Fill(long long x)
bool getData(T &iHolder) const
Definition: EventSetup.h:113
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WValidation.h:59
MonitorElement * book1dHisto(std::string name, std::string title, int n, double xmin, double xmax, std::string xaxis, std::string yaxis)
Definition: DQMHelper.cc:7
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * gamma_energy
Definition: WValidation.h:52
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
Definition: WValidation.cc:28
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
Definition: WValidation.h:46
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: WValidation.cc:87
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
MonitorElement * WptLog
Definition: WValidation.h:49
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
MonitorElement * lepmet_mTPeak
Definition: WValidation.h:50
MonitorElement * WmassPeak
Definition: WValidation.h:49
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: WValidation.cc:89
MonitorElement * met
Definition: WValidation.h:51
HLT enums.
MonitorElement * Wpt
Definition: WValidation.h:49
lep1
print &#39;MRbb(1b)&#39;,event.mr_bb
MonitorElement * lepmet_ptLog
Definition: WValidation.h:50
MonitorElement * Wdaughters
Definition: WValidation.h:49
double weight(const edm::Event &)
MonitorElement * Wmass
Definition: WValidation.h:49
MonitorElement * cos_theta_gamma_lepton
Definition: WValidation.h:52
Definition: Run.h:45
int _flavor
decay flavor
Definition: WValidation.h:55