CMS 3D CMS Logo

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