CMS 3D CMS Logo

DrellYanValidation.cc
Go to the documentation of this file.
1 /*class DrellYanValidation
2  *
3  * Class to fill dqm monitor elements from existing EDM file
4  *
5  */
6 
10 #include "TLorentzVector.h"
11 
12 #include "CLHEP/Units/defs.h"
13 #include "CLHEP/Units/PhysicalConstants.h"
14 
17 using namespace edm;
18 
20  : wmanager_(iPSet, consumesCollector()),
21  hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
22  _flavor(iPSet.getParameter<int>("decaysTo")),
23  _name(iPSet.getParameter<std::string>("name")) {
24  hepmcCollectionToken_ = consumes<HepMCProduct>(hepmcCollection_);
25 }
26 
28 
30 
33  std::string folderName = "Generator/DrellYan";
34  folderName += _name;
35  DQMHelper dqm(&i);
36  i.setCurrentFolder(folderName);
37 
38  // Number of analyzed events
39  nEvt = dqm.book1dHisto("nEvt", "n analyzed Events", 1, 0., 1., "bin", "Number of Events");
40 
41  //Kinematics
42  Zmass = dqm.book1dHisto("Zmass", "inv. Mass Z", 70, 0, 140, "M_{Z} (GeV)", "Number of Events");
43  ZmassPeak = dqm.book1dHisto("ZmassPeak", "inv. Mass Z", 80, 80, 100, "M_{Z} (GeV)", "Number of Events");
44  Zpt = dqm.book1dHisto("Zpt", "Z pt", 100, 0, 200, "P_{t}^{Z} (GeV)", "Number of Events");
45  ZptLog =
46  dqm.book1dHisto("ZptLog", "log(Z pt)", 100, 0., 5., "log_{10}(P_{t}^{Z}) (log_{10}(GeV))", "Number of Events");
47  Zrap = dqm.book1dHisto("Zrap", "Z y", 100, -5, 5, "Y_{Z}", "Number of Events");
48  Zdaughters = dqm.book1dHisto("Zdaughters", "Z daughters", 60, -30, 30, "Z daughters (PDG ID)", "Number of Events");
49 
50  dilep_mass = dqm.book1dHisto("dilep_mass", "inv. Mass dilepton", 70, 0, 140, "M_{ll} (GeV)", "Number of Events");
52  dqm.book1dHisto("dilep_massPeak", "inv. Mass dilepton", 80, 80, 100, "M_{ll} (GeV)", "Number of Events");
53  dilep_pt = dqm.book1dHisto("dilep_pt", "dilepton pt", 100, 0, 200, "P_{t}^{ll} (GeV)", "Number of Events");
54  dilep_ptLog = dqm.book1dHisto(
55  "dilep_ptLog", "log(dilepton pt)", 100, 0., 5., "log_{10}(P_{t}^{ll}) (log_{10}(GeV))", "Number of Events");
56  dilep_rap = dqm.book1dHisto("dilep_rap", "dilepton y", 100, -5, 5, "Y_{ll}", "Number of Events");
57 
58  gamma_energy = dqm.book1dHisto("gamma_energy",
59  "photon energy in Z rest frame",
60  200,
61  0.,
62  100.,
63  "E_{#gamma}^{Z rest-frame} (GeV)",
64  "Number of Events");
65  cos_theta_gamma_lepton = dqm.book1dHisto("cos_theta_gamma_lepton",
66  "cos_theta_gamma_lepton in Z rest frame",
67  200,
68  -1,
69  1,
70  "cos(#theta_{#gamma-lepton}^{Z rest-frame})",
71  "Number of Events");
72 
73  leadpt = dqm.book1dHisto("leadpt", "leading lepton pt", 200, 0., 200., "P_{t}^{1st-lepton}", "Number of Events");
74  secpt = dqm.book1dHisto("secpt", "second lepton pt", 200, 0., 200., "P_{t}^{2nd-lepton}", "Number of Events");
75  leadeta = dqm.book1dHisto("leadeta", "leading lepton eta", 100, -5., 5., "#eta^{1st-lepton}", "Number of Events");
76  seceta = dqm.book1dHisto("seceta", "second lepton eta", 100, -5., 5., "#eta^{2nd-lepton}", "Number of Events");
77 
78  return;
79 }
80 
82  // we *DO NOT* rely on a Z entry in the particle listings!
83 
86  iEvent.getByToken(hepmcCollectionToken_, evt);
87 
88  //Get EVENT
89  const HepMC::GenEvent* myGenEvent = evt->GetEvent();
90 
91  double weight = wmanager_.weight(iEvent);
92 
93  //std::cout << "weight: " << weight << std::endl;
94 
95  nEvt->Fill(0.5, weight);
96 
97  std::vector<const HepMC::GenParticle*> allproducts;
98 
99  //requires status 1 for leptons and neutrinos (except tau)
100  int requiredstatus = (std::abs(_flavor) == 11 || std::abs(_flavor) == 12 || std::abs(_flavor) == 13 ||
101  std::abs(_flavor) == 14 || std::abs(_flavor) == 16)
102  ? 1
103  : 3;
104 
105  bool vetotau =
106  true; //(std::abs(_flavor) == 11 || std::abs(_flavor) == 12 || std::abs(_flavor) ==13 || std::abs(_flavor) ==14 || std::abs(_flavor) ==16) ? true : false;
107 
108  for (HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin();
109  iter != myGenEvent->particles_end();
110  ++iter) {
111  if (vetotau) {
112  if ((*iter)->status() == 3 && std::abs((*iter)->pdg_id()) == 15)
113  return;
114  }
115  if ((*iter)->status() == requiredstatus) {
116  if (std::abs((*iter)->pdg_id()) == _flavor)
117  allproducts.push_back(*iter);
118  }
119  }
120 
121  //nothing to do if we don't have 2 particles
122  if (allproducts.size() < 2)
123  return;
124 
125  //sort them in pt
126  std::sort(allproducts.begin(), allproducts.end(), HepMCValidationHelper::sortByPt);
127 
128  //get the first element and the first following element with opposite charge
129  std::vector<const HepMC::GenParticle*> products;
130  products.push_back(allproducts.front());
131  const HepPDT::ParticleData* PData1 = fPDGTable->particle(HepPDT::ParticleID(allproducts.front()->pdg_id()));
132  double charge1 = PData1->charge();
133  for (unsigned int i = 1; i < allproducts.size(); ++i) {
134  const HepPDT::ParticleData* PData2 = fPDGTable->particle(HepPDT::ParticleID(allproducts[i]->pdg_id()));
135  double charge2 = PData2->charge();
136  if (charge1 * charge2 < 0)
137  products.push_back(allproducts[i]);
138  }
139 
140  //if we did not find any opposite charge pair there is nothing to do
141  if (products.size() < 2)
142  return;
143 
144  assert(products[0]->momentum().perp() >= products[1]->momentum().perp());
145 
146  //leading lepton with pt > 20.
147  if (products[0]->momentum().perp() < 20.)
148  return;
149 
150  //assemble FourMomenta
151  TLorentzVector lep1(products[0]->momentum().x(),
152  products[0]->momentum().y(),
153  products[0]->momentum().z(),
154  products[0]->momentum().t());
155  TLorentzVector lep2(products[1]->momentum().x(),
156  products[1]->momentum().y(),
157  products[1]->momentum().z(),
158  products[1]->momentum().t());
159  TLorentzVector dilepton_mom = lep1 + lep2;
160  TLorentzVector dilepton_andphoton_mom = dilepton_mom;
161 
162  //mass > 60.
163  if (dilepton_mom.M() < 60.)
164  return;
165 
166  //find possible qed fsr photons
167  std::vector<const HepMC::GenParticle*> fsrphotons;
168  HepMCValidationHelper::findFSRPhotons(products, myGenEvent, 0.1, fsrphotons);
169 
172 
173  std::vector<TLorentzVector> gammasMomenta;
174  for (unsigned int ipho = 0; ipho < fsrphotons.size(); ++ipho) {
175  TLorentzVector phomom(fsrphotons[ipho]->momentum().x(),
176  fsrphotons[ipho]->momentum().y(),
177  fsrphotons[ipho]->momentum().z(),
178  fsrphotons[ipho]->momentum().t());
179  dilepton_andphoton_mom += phomom;
180  Zdaughters->Fill(fsrphotons[ipho]->pdg_id(), weight);
181  gammasMomenta.push_back(phomom);
182  }
183  //Fill Z histograms
184  Zmass->Fill(dilepton_andphoton_mom.M(), weight);
185  ZmassPeak->Fill(dilepton_andphoton_mom.M(), weight);
186  Zpt->Fill(dilepton_andphoton_mom.Pt(), weight);
187  ZptLog->Fill(log10(dilepton_andphoton_mom.Pt()), weight);
188  Zrap->Fill(dilepton_andphoton_mom.Rapidity(), weight);
189 
190  //Fill dilepton histograms
191  dilep_mass->Fill(dilepton_mom.M(), weight);
192  dilep_massPeak->Fill(dilepton_mom.M(), weight);
193  dilep_pt->Fill(dilepton_mom.Pt(), weight);
194  dilep_ptLog->Fill(log10(dilepton_mom.Pt()), weight);
195  dilep_rap->Fill(dilepton_mom.Rapidity(), weight);
196 
197  //Fill lepton histograms
198  leadpt->Fill(lep1.Pt(), weight);
199  secpt->Fill(lep2.Pt(), weight);
200  leadeta->Fill(lep1.Eta(), weight);
201  seceta->Fill(lep2.Eta(), weight);
202 
203  //boost everything in the Z frame
204  TVector3 boost = dilepton_andphoton_mom.BoostVector();
205  boost *= -1.;
206  lep1.Boost(boost);
207  lep2.Boost(boost);
208  for (unsigned int ipho = 0; ipho < gammasMomenta.size(); ++ipho) {
209  gammasMomenta[ipho].Boost(boost);
210  }
211  std::sort(gammasMomenta.begin(), gammasMomenta.end(), HepMCValidationHelper::GreaterByE<TLorentzVector>);
212 
213  //fill gamma histograms
214  if (!gammasMomenta.empty() && dilepton_andphoton_mom.M() > 50.) {
215  gamma_energy->Fill(gammasMomenta.front().E(), weight);
216  double dphi = lep1.DeltaR(gammasMomenta.front()) < lep2.DeltaR(gammasMomenta.front())
217  ? lep1.DeltaPhi(gammasMomenta.front())
218  : lep2.DeltaPhi(gammasMomenta.front());
220  }
221 
222 } //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
DrellYanValidation::Zpt
MonitorElement * Zpt
Definition: DrellYanValidation.h:49
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
DrellYanValidation::dilep_rap
MonitorElement * dilep_rap
Definition: DrellYanValidation.h:50
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
DrellYanValidation::dilep_pt
MonitorElement * dilep_pt
Definition: DrellYanValidation.h:50
mps_merge.weight
weight
Definition: mps_merge.py:88
DrellYanValidation::Zmass
MonitorElement * Zmass
Definition: DrellYanValidation.h:49
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
DrellYanValidation.h
DrellYanValidation::nEvt
MonitorElement * nEvt
Definition: DrellYanValidation.h:48
cms::cuda::assert
assert(be >=bs)
DrellYanValidation::wmanager_
WeightManager wmanager_
Definition: DrellYanValidation.h:42
DrellYanValidation::_name
std::string _name
decay flavor name
Definition: DrellYanValidation.h:57
DrellYanValidation::ZmassPeak
MonitorElement * ZmassPeak
Definition: DrellYanValidation.h:49
DDAxes::x
DrellYanValidation::ZptLog
MonitorElement * ZptLog
Definition: DrellYanValidation.h:49
perp
T perp() const
Magnitude of transverse component.
Definition: Basic3DVectorLD.h:133
boost
Definition: CLHEP.h:16
edm::Handle
Definition: AssociativeIterator.h:50
edm::es::products
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
DrellYanValidation::fPDGTable
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
Definition: DrellYanValidation.h:46
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
DrellYanValidation::dilep_massPeak
MonitorElement * dilep_massPeak
Definition: DrellYanValidation.h:50
DQMHelper.h
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DrellYanValidation::hepmcCollectionToken_
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: DrellYanValidation.h:59
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
DrellYanValidation::leadpt
MonitorElement * leadpt
Definition: DrellYanValidation.h:51
DDAxes::z
DrellYanValidation::secpt
MonitorElement * secpt
Definition: DrellYanValidation.h:51
DrellYanValidation::_flavor
int _flavor
decay flavor
Definition: DrellYanValidation.h:55
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DrellYanValidation::dqmBeginRun
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: DrellYanValidation.cc:29
edm::ParameterSet
Definition: ParameterSet.h:47
DrellYanValidation::hepmcCollection_
edm::InputTag hepmcCollection_
Definition: DrellYanValidation.h:43
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
DrellYanValidation::cos_theta_gamma_lepton
MonitorElement * cos_theta_gamma_lepton
Definition: DrellYanValidation.h:52
DrellYanValidation::DrellYanValidation
DrellYanValidation(const edm::ParameterSet &)
Definition: DrellYanValidation.cc:19
DrellYanValidation::Zrap
MonitorElement * Zrap
Definition: DrellYanValidation.h:49
LorentzVector.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
DrellYanValidation::dilep_ptLog
MonitorElement * dilep_ptLog
Definition: DrellYanValidation.h:50
edm::EventSetup
Definition: EventSetup.h:58
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
DrellYanValidation::leadeta
MonitorElement * leadeta
Definition: DrellYanValidation.h:51
WeightManager::weight
double weight(const edm::Event &)
Definition: WeightManager.cc:24
DrellYanValidation::bookHistograms
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
Definition: DrellYanValidation.cc:31
ALCARECODTCalibSynchCosmicsDQM_cff.folderName
folderName
Definition: ALCARECODTCalibSynchCosmicsDQM_cff.py:9
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DQMHelper
Definition: DQMHelper.h:15
DrellYanValidation::analyze
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: DrellYanValidation.cc:81
DrellYanValidation::gamma_energy
MonitorElement * gamma_energy
Definition: DrellYanValidation.h:52
DrellYanValidation::dilep_mass
MonitorElement * dilep_mass
Definition: DrellYanValidation.h:50
HepMCValidationHelper.h
DrellYanValidation::~DrellYanValidation
~DrellYanValidation() override
Definition: DrellYanValidation.cc:27
std
Definition: JetResolutionObject.h:76
DrellYanValidation::seceta
MonitorElement * seceta
Definition: DrellYanValidation.h:51
dqm::implementation::IBooker
Definition: DQMStore.h:43
ConsumesCollector.h
dqm
Definition: DQMStore.h:18
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::Event
Definition: Event.h:73
RazorAnalyzer.lep2
lep2
Definition: RazorAnalyzer.py:262
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
LHEGenericFilter_cfi.ParticleID
ParticleID
Definition: LHEGenericFilter_cfi.py:6
edm::InputTag
Definition: InputTag.h:15
DrellYanValidation::Zdaughters
MonitorElement * Zdaughters
Definition: DrellYanValidation.h:49
HepMCValidationHelper::sortByPt
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
Definition: HepMCValidationHelper.h:15
weight
Definition: weight.py:1