CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  * $Date: 2011/01/24 17:41:34 $
6  * $Revision: 1.3 $
7  */
8 
11 #include "TLorentzVector.h"
12 
13 #include "CLHEP/Units/defs.h"
14 #include "CLHEP/Units/PhysicalConstants.h"
15 
17 
18 using namespace edm;
19 
21  hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
22  _flavor(iPSet.getParameter<int>("decaysTo")),
23  _name(iPSet.getParameter<std::string>("name"))
24 {
25  dbe = 0;
27 }
28 
30 
32 {
33  if(dbe){
35  std::string folderName = "Generator/DrellYan";
36  folderName+=_name;
37  dbe->setCurrentFolder(folderName.c_str());
38 
39  // Number of analyzed events
40  nEvt = dbe->book1D("nEvt", "n analyzed Events", 1, 0., 1.);
41 
42  //Kinematics
43  Zmass = dbe->book1D("Zmass","inv. Mass Z", 70 ,0,140);
44  ZmassPeak = dbe->book1D("ZmassPeak","inv. Mass Z", 80 ,80 ,100);
45  Zpt = dbe->book1D("Zpt","Z pt",100,0,200);
46  ZptLog = dbe->book1D("ZptLog","log(Z pt)",100,0.,5.);
47  Zrap = dbe->book1D("Zrap", "Z y", 100, -5, 5);
48  Zdaughters = dbe->book1D("Zdaughters", "Z daughters", 60, -30, 30);
49 
50  dilep_mass = dbe->book1D("dilep_mass","inv. Mass dilepton", 70 ,0,140);
51  dilep_massPeak = dbe->book1D("dilep_massPeak","inv. Mass dilepton", 80 ,80 ,100);
52  dilep_pt = dbe->book1D("dilep_pt","dilepton pt",100,0,200);
53  dilep_ptLog = dbe->book1D("dilep_ptLog","log(dilepton pt)",100,0.,5.);
54  dilep_rap = dbe->book1D("dilep_rap", "dilepton y", 100, -5, 5);
55 
56  gamma_energy = dbe->book1D("gamma_energy", "photon energy in Z rest frame", 200, 0., 100.);
57  cos_theta_gamma_lepton = dbe->book1D("cos_theta_gamma_lepton", "cos_theta_gamma_lepton in Z rest frame", 200, -1, 1);
58 
59  leadpt = dbe->book1D("leadpt","leading lepton pt", 200, 0., 200.);
60  secpt = dbe->book1D("secpt","second lepton pt", 200, 0., 200.);
61  leadeta = dbe->book1D("leadeta","leading lepton eta", 100, -5., 5.);
62  seceta = dbe->book1D("seceta","second lepton eta", 100, -5., 5.);
63 
64  }
65  return;
66 }
67 
69 void DrellYanValidation::beginRun(const edm::Run& iRun,const edm::EventSetup& iSetup)
70 {
72  iSetup.getData( fPDGTable );
73  return;
74 }
75 void DrellYanValidation::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){return;}
77 {
78 
79  // we *DO NOT* rely on a Z entry in the particle listings!
80 
83  iEvent.getByLabel(hepmcCollection_, evt);
84 
85  //Get EVENT
86  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
87 
88  nEvt->Fill(0.5);
89 
90  std::vector<const HepMC::GenParticle*> allproducts;
91 
92  //requires status 1 for leptons and neutrinos (except tau)
93  int requiredstatus = (abs(_flavor) == 11 || abs(_flavor) == 12 || abs(_flavor) ==13 || abs(_flavor) ==14 || abs(_flavor) ==16) ? 1 : 3;
94 
95  bool vetotau = true; //(abs(_flavor) == 11 || abs(_flavor) == 12 || abs(_flavor) ==13 || abs(_flavor) ==14 || abs(_flavor) ==16) ? true : false;
96 
97  for(HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin(); iter != myGenEvent->particles_end(); ++iter) {
98  if (vetotau) {
99  if ((*iter)->status()==3 && abs((*iter)->pdg_id() == 15) ) return;
100  }
101  if((*iter)->status()==requiredstatus) {
102  if(abs((*iter)->pdg_id())==_flavor)
103  allproducts.push_back(*iter);
104  }
105  }
106 
107  //nothing to do if we don't have 2 particles
108  if (allproducts.size() < 2) return;
109 
110  //sort them in pt
111  std::sort(allproducts.begin(), allproducts.end(), HepMCValidationHelper::sortByPt);
112 
113  //get the first element and the first following element with opposite charge
114  std::vector<const HepMC::GenParticle*> products;
115  products.push_back(allproducts.front());
116  const HepPDT::ParticleData* PData1 = fPDGTable->particle(HepPDT::ParticleID(allproducts.front()->pdg_id()));
117  double charge1 = PData1->charge();
118  for (unsigned int i = 1; i < allproducts.size(); ++i ){
119  const HepPDT::ParticleData* PData2 = fPDGTable->particle(HepPDT::ParticleID(allproducts[i]->pdg_id()));
120  double charge2 = PData2->charge();
121  if (charge1*charge2 < 0) products.push_back(allproducts[i]);
122  }
123 
124  //if we did not find any opposite charge pair there is nothing to do
125  if (products.size() < 2) return;
126 
127  assert(products[0]->momentum().perp() > products[1]->momentum().perp());
128 
129  //leading lepton with pt > 20.
130  if (products[0]->momentum().perp() < 20.) return;
131 
132  //assemble FourMomenta
133  TLorentzVector lep1(products[0]->momentum().x(), products[0]->momentum().y(), products[0]->momentum().z(), products[0]->momentum().t());
134  TLorentzVector lep2(products[1]->momentum().x(), products[1]->momentum().y(), products[1]->momentum().z(), products[1]->momentum().t());
135  TLorentzVector dilepton_mom = lep1 + lep2;
136  TLorentzVector dilepton_andphoton_mom = dilepton_mom;
137 
138  //mass > 60.
139  if (dilepton_mom.M() < 60.) return;
140 
141  //find possible qed fsr photons
142  std::vector<const HepMC::GenParticle*> fsrphotons;
143  HepMCValidationHelper::findFSRPhotons(products, myGenEvent, 0.1, fsrphotons);
144 
145  Zdaughters->Fill(products[0]->pdg_id());
146  Zdaughters->Fill(products[1]->pdg_id());
147 
148  std::vector<TLorentzVector> gammasMomenta;
149  for (unsigned int ipho = 0; ipho < fsrphotons.size(); ++ipho){
150  TLorentzVector phomom(fsrphotons[ipho]->momentum().x(), fsrphotons[ipho]->momentum().y(), fsrphotons[ipho]->momentum().z(), fsrphotons[ipho]->momentum().t());
151  dilepton_andphoton_mom += phomom;
152  Zdaughters->Fill(fsrphotons[ipho]->pdg_id());
153  gammasMomenta.push_back(phomom);
154  }
155  //Fill Z histograms
156  Zmass->Fill(dilepton_andphoton_mom.M());
157  ZmassPeak->Fill(dilepton_andphoton_mom.M());
158  Zpt->Fill(dilepton_andphoton_mom.Pt());
159  ZptLog->Fill(log10(dilepton_andphoton_mom.Pt()));
160  Zrap->Fill(dilepton_andphoton_mom.Rapidity());
161 
162  //Fill dilepton histograms
163  dilep_mass->Fill(dilepton_mom.M());
164  dilep_massPeak->Fill(dilepton_mom.M());
165  dilep_pt->Fill(dilepton_mom.Pt());
166  dilep_ptLog->Fill(log10(dilepton_mom.Pt()));
167  dilep_rap->Fill(dilepton_mom.Rapidity());
168 
169  //Fill lepton histograms
170  leadpt->Fill(lep1.Pt());
171  secpt->Fill(lep2.Pt());
172  leadeta->Fill(lep1.Eta());
173  seceta->Fill(lep2.Eta());
174 
175  //boost everything in the Z frame
176  TVector3 boost = dilepton_andphoton_mom.BoostVector();
177  boost*=-1.;
178  lep1.Boost(boost);
179  lep2.Boost(boost);
180  for (unsigned int ipho = 0; ipho < gammasMomenta.size(); ++ipho){
181  gammasMomenta[ipho].Boost(boost);
182  }
183  std::sort(gammasMomenta.begin(), gammasMomenta.end(), HepMCValidationHelper::GreaterByE<TLorentzVector>);
184 
185  //fill gamma histograms
186  if (gammasMomenta.size() != 0 && dilepton_andphoton_mom.M() > 50.) {
187  gamma_energy->Fill(gammasMomenta.front().E());
188  double dphi = lep1.DeltaR(gammasMomenta.front()) < lep2.DeltaR(gammasMomenta.front()) ?
189  lep1.DeltaPhi(gammasMomenta.front()) : lep2.DeltaPhi(gammasMomenta.front());
191  }
192 
193 }//analyze
MonitorElement * secpt
MonitorElement * gamma_energy
int i
Definition: DBlmapReader.cc:9
MonitorElement * dilep_rap
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void findFSRPhotons(const std::vector< const HepMC::GenParticle * > &leptons, const std::vector< const HepMC::GenParticle * > &all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
MonitorElement * Zmass
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
edm::InputTag hepmcCollection_
MonitorElement * cos_theta_gamma_lepton
MonitorElement * nEvt
MonitorElement * leadeta
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
virtual void endRun(const edm::Run &, const edm::EventSetup &)
#define abs(x)
Definition: mlp_lapack.h:159
MonitorElement * Zrap
MonitorElement * leadpt
double double double z
void getData(T &iHolder) const
Definition: EventSetup.h:67
void Fill(long long x)
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
int _flavor
decay flavor
int iEvent
Definition: GenABIO.cc:243
MonitorElement * dilep_massPeak
ESProducts< T, S > products(const T &i1, const S &i2)
Definition: ESProducts.h:189
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DQMStore * dbe
ME&#39;s &quot;container&quot;.
MonitorElement * Zdaughters
MonitorElement * dilep_pt
HepPDT::ParticleData ParticleData
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
MonitorElement * ZptLog
virtual void beginJob()
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
std::string _name
decay flavor name
MonitorElement * seceta
T perp() const
Magnitude of transverse component.
MonitorElement * dilep_mass
MonitorElement * ZmassPeak
MonitorElement * dilep_ptLog
Definition: DDAxes.h:10
DrellYanValidation(const edm::ParameterSet &)
MonitorElement * Zpt
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32