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 
70  gamma_energy = dqm.book1dHisto(
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 
87 void WValidation::dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) { c.getData(fPDGTable); }
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());
211  }
212 
213 } //analyze
RazorAnalyzer.lep1
lep1
print 'MRbb(1b)',event.mr_bb
Definition: RazorAnalyzer.py:261
HiggsValidation_cfi.pdg_id
pdg_id
Definition: HiggsValidation_cfi.py:6
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:355
WValidation::Wdaughters
MonitorElement * Wdaughters
Definition: WValidation.h:49
WValidation::hepmcCollection_
edm::InputTag hepmcCollection_
Definition: WValidation.h:43
WValidation::Wmass
MonitorElement * Wmass
Definition: WValidation.h:49
WValidation::wmanager_
WeightManager wmanager_
Definition: WValidation.h:42
WValidation::cos_theta_gamma_lepton
MonitorElement * cos_theta_gamma_lepton
Definition: WValidation.h:52
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
WValidation::_flavor
int _flavor
decay flavor
Definition: WValidation.h:55
mps_merge.weight
weight
Definition: mps_merge.py:88
HepMCValidationHelper::findFSRPhotons
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: HepMCValidationHelper.cc:20
WValidation::lepmet_pt
MonitorElement * lepmet_pt
Definition: WValidation.h:50
WValidation::~WValidation
~WValidation() override
Definition: WValidation.cc:26
DDAxes::x
boost
Definition: CLHEP.h:16
edm::Handle
Definition: AssociativeIterator.h:50
WValidation::nEvt
MonitorElement * nEvt
Definition: WValidation.h:48
edm::es::products
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
WValidation::_name
std::string _name
decay flavor name
Definition: WValidation.h:57
WValidation::lepeta
MonitorElement * lepeta
Definition: WValidation.h:51
DQMHelper.h
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
DDAxes::z
WValidation::fPDGTable
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
Definition: WValidation.h:46
WValidation::hepmcCollectionToken_
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WValidation.h:59
OrderedSet.t
t
Definition: OrderedSet.py:90
WValidation::lepmet_mT
MonitorElement * lepmet_mT
Definition: WValidation.h:50
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:36
LorentzVector.h
WValidation::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: WValidation.cc:89
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
WValidation::WptLog
MonitorElement * WptLog
Definition: WValidation.h:49
edm::EventSetup
Definition: EventSetup.h:57
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
WeightManager::weight
double weight(const edm::Event &)
Definition: WeightManager.cc:24
WValidation::dqmBeginRun
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: WValidation.cc:87
ALCARECODTCalibSynchCosmicsDQM_cff.folderName
folderName
Definition: ALCARECODTCalibSynchCosmicsDQM_cff.py:9
WValidation::gamma_energy
MonitorElement * gamma_energy
Definition: WValidation.h:52
HepMCValidationHelper::genMet
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
Definition: HepMCValidationHelper.cc:278
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DQMHelper
Definition: DQMHelper.h:15
WValidation::bookHistograms
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
Definition: WValidation.cc:28
WValidation::lepmet_ptLog
MonitorElement * lepmet_ptLog
Definition: WValidation.h:50
HepMCValidationHelper.h
WValidation::Wpt
MonitorElement * Wpt
Definition: WValidation.h:49
std
Definition: JetResolutionObject.h:76
dqm::implementation::IBooker
Definition: DQMStore.h:43
WValidation::WValidation
WValidation(const edm::ParameterSet &)
Definition: WValidation.cc:18
WValidation::lepmet_mTPeak
MonitorElement * lepmet_mTPeak
Definition: WValidation.h:50
dqm
Definition: DQMStore.h:18
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
WValidation::leppt
MonitorElement * leppt
Definition: WValidation.h:51
WValidation::WmassPeak
MonitorElement * WmassPeak
Definition: WValidation.h:49
edm::Event
Definition: Event.h:73
RazorAnalyzer.lep2
lep2
Definition: RazorAnalyzer.py:262
WValidation::met
MonitorElement * met
Definition: WValidation.h:51
edm::InputTag
Definition: InputTag.h:15
HepMCValidationHelper::sortByPt
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
Definition: HepMCValidationHelper.h:15
weight
Definition: weight.py:1
WValidation.h
WValidation::Wrap
MonitorElement * Wrap
Definition: WValidation.h:49