CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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  * $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/W";
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  Wmass = dbe->book1D("Wmass","inv. Mass W", 70 ,0,140);
44  WmassPeak = dbe->book1D("WmassPeak","inv. Mass W", 80 ,80 ,100);
45  Wpt = dbe->book1D("Wpt","W pt",100,0,200);
46  WptLog = dbe->book1D("WptLog","log(W pt)",100,0.,5.);
47  Wrap = dbe->book1D("Wrap", "W y", 100, -5, 5);
48  Wdaughters = dbe->book1D("Wdaughters", "W daughters", 60, -30, 30);
49 
50  lepmet_mT = dbe->book1D("lepmet_mT","lepton-met transverse mass", 70 ,0,140);
51  lepmet_mTPeak = dbe->book1D("lepmet_mTPeak","lepton-met transverse mass", 80 ,80 ,100);
52  lepmet_pt = dbe->book1D("lepmet_pt","lepton-met",100,0,200);
53  lepmet_ptLog = dbe->book1D("lepmet_ptLog","log(lepton-met pt)",100,0.,5.);
54 
55  gamma_energy = dbe->book1D("gamma_energy", "photon energy in W rest frame", 200, 0., 100.);
56  cos_theta_gamma_lepton = dbe->book1D("cos_theta_gamma_lepton", "cos_theta_gamma_lepton in W rest frame", 200, -1, 1);
57 
58  leppt = dbe->book1D("leadpt","lepton pt", 200, 0., 200.);
59  met = dbe->book1D("met","met", 200, 0., 200.);
60  lepeta = dbe->book1D("leadeta","leading lepton eta", 100, -5., 5.);
61 
62  }
63  return;
64 }
65 
66 void WValidation::endJob(){return;}
67 void WValidation::beginRun(const edm::Run& iRun,const edm::EventSetup& iSetup)
68 {
70  iSetup.getData( fPDGTable );
71  return;
72 }
73 void WValidation::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){return;}
75 {
76 
77  // we *DO NOT* rely on a Z entry in the particle listings!
78 
81  iEvent.getByLabel(hepmcCollection_, evt);
82 
83  //Get EVENT
84  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
85 
86  nEvt->Fill(0.5);
87 
88  std::vector<const HepMC::GenParticle*> allleptons;
89  std::vector<const HepMC::GenParticle*> allneutrinos;
90 
91  //requires status 1 for leptons and neutrinos (except tau)
92  int requiredstatus = (abs(_flavor) == 11 || abs(_flavor) ==13 ) ? 1 : 3;
93 
94  bool vetotau = true; //(abs(_flavor) == 11 || abs(_flavor) == 12 || abs(_flavor) ==13 || abs(_flavor) ==14 || abs(_flavor) ==16) ? true : false;
95 
96  for(HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin(); iter != myGenEvent->particles_end(); ++iter) {
97  if (vetotau) {
98  if ((*iter)->status()==3 && abs((*iter)->pdg_id() == 15) ) return;
99  }
100  if((*iter)->status()==requiredstatus) {
101  //@todo: improve this selection
102  if((*iter)->pdg_id()==_flavor)
103  allleptons.push_back(*iter);
104  else if (abs((*iter)->pdg_id()) == abs(_flavor)+1)
105  allneutrinos.push_back(*iter);
106  }
107  }
108 
109  //nothing to do if we don't have 2 particles
110  if (allleptons.empty() || allneutrinos.empty()) return;
111 
112  //sort them in pt
113  std::sort(allleptons.begin(), allleptons.end(), HepMCValidationHelper::sortByPt);
114  std::sort(allneutrinos.begin(), allneutrinos.end(), HepMCValidationHelper::sortByPt);
115 
116  //get the first lepton and the first neutrino, and check that one is particle one is antiparticle (product of pdgids < 0)
117  std::vector<const HepMC::GenParticle*> products;
118  if (allleptons.front()->pdg_id() * allneutrinos.front()->pdg_id() > 0) return;
119 
120  //require at least 20 GeV on the lepton
121  if (allleptons.front()->momentum().perp() < 20. || allneutrinos.front()->momentum().perp() < 20. ) return;
122 
123  //find possible qed fsr photons
124  std::vector<const HepMC::GenParticle*> selectedLepton;
125  selectedLepton.push_back(allleptons.front());
126  std::vector<const HepMC::GenParticle*> fsrphotons;
127  HepMCValidationHelper::findFSRPhotons(selectedLepton, myGenEvent, 0.1, fsrphotons);
128 
129  Wdaughters->Fill(allleptons.front()->pdg_id());
130  Wdaughters->Fill(allneutrinos.front()->pdg_id());
131 
132  //assemble FourMomenta
133  TLorentzVector lep1(allleptons[0]->momentum().x(), allleptons[0]->momentum().y(), allleptons[0]->momentum().z(), allleptons[0]->momentum().t());
134  TLorentzVector lep2(allneutrinos[0]->momentum().x(), allneutrinos[0]->momentum().y(), allneutrinos[0]->momentum().z(), allneutrinos[0]->momentum().t());
135  TLorentzVector dilepton_mom = lep1 + lep2;
136  TLorentzVector dilepton_andphoton_mom = dilepton_mom;
137  std::vector<TLorentzVector> gammasMomenta;
138  for (unsigned int ipho = 0; ipho < fsrphotons.size(); ++ipho){
139  TLorentzVector phomom(fsrphotons[ipho]->momentum().x(), fsrphotons[ipho]->momentum().y(), fsrphotons[ipho]->momentum().z(), fsrphotons[ipho]->momentum().t());
140  dilepton_andphoton_mom += phomom;
141  Wdaughters->Fill(fsrphotons[ipho]->pdg_id());
142  gammasMomenta.push_back(phomom);
143  }
144  //Fill "true" W histograms
145  Wmass->Fill(dilepton_andphoton_mom.M());
146  WmassPeak->Fill(dilepton_andphoton_mom.M());
147  Wpt->Fill(dilepton_andphoton_mom.Pt());
148  WptLog->Fill(log10(dilepton_andphoton_mom.Pt()));
149  Wrap->Fill(dilepton_andphoton_mom.Rapidity());
150 
151  TLorentzVector met_mom = HepMCValidationHelper::genMet(myGenEvent, -3., 3.);
152  TLorentzVector lep1T(lep1.Px(), lep1.Py(), 0., lep1.Et());
153  TLorentzVector lepmet_mom = lep1T + met_mom;
154  //Fill lepmet histograms
155  lepmet_mT->Fill(lepmet_mom.M());
156  lepmet_mTPeak->Fill(lepmet_mom.M());
157  lepmet_pt->Fill(lepmet_mom.Pt());
158  lepmet_ptLog->Fill(log10(lepmet_mom.Pt()));
159 
160  //Fill lepton histograms
161  leppt->Fill(lep1.Pt());
162  lepeta->Fill(lep1.Eta());
163  met->Fill(met_mom.Pt());
164 
165  //boost everything in the W frame
166  TVector3 boost = dilepton_andphoton_mom.BoostVector();
167  boost*=-1.;
168  lep1.Boost(boost);
169  lep2.Boost(boost);
170  for (unsigned int ipho = 0; ipho < gammasMomenta.size(); ++ipho){
171  gammasMomenta[ipho].Boost(boost);
172  }
173  std::sort(gammasMomenta.begin(), gammasMomenta.end(), HepMCValidationHelper::GreaterByE<TLorentzVector>);
174 
175  //fill gamma histograms
176  if (gammasMomenta.size() != 0 && dilepton_andphoton_mom.M() > 50.) {
177  gamma_energy->Fill(gammasMomenta.front().E());
178  double dphi = lep1.DeltaR(gammasMomenta.front());
180  }
181 
182 
183 }//analyze
WValidation(const edm::ParameterSet &)
Definition: WValidation.cc:20
edm::InputTag hepmcCollection_
Definition: WValidation.h:47
MonitorElement * leppt
Definition: WValidation.h:58
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 * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
MonitorElement * Wrap
Definition: WValidation.h:56
MonitorElement * nEvt
Definition: WValidation.h:55
std::string _name
decay flavor name
Definition: WValidation.h:64
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: WValidation.cc:67
DQMStore * dbe
ME&#39;s &quot;container&quot;.
Definition: WValidation.h:53
bool sortByPt(const HepMC::GenParticle *a, const HepMC::GenParticle *b)
virtual void endJob()
Definition: WValidation.cc:66
#define abs(x)
Definition: mlp_lapack.h:159
MonitorElement * lepeta
Definition: WValidation.h:58
virtual void endRun(const edm::Run &, const edm::EventSetup &)
Definition: WValidation.cc:73
virtual ~WValidation()
Definition: WValidation.cc:29
double double double z
void getData(T &iHolder) const
Definition: EventSetup.h:67
MonitorElement * lepmet_mT
Definition: WValidation.h:57
void Fill(long long x)
MonitorElement * lepmet_pt
Definition: WValidation.h:57
int iEvent
Definition: GenABIO.cc:243
ESProducts< T, S > products(const T &i1, const S &i2)
Definition: ESProducts.h:189
virtual void beginJob()
Definition: WValidation.cc:31
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MonitorElement * gamma_energy
Definition: WValidation.h:59
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
Definition: WValidation.h:50
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
MonitorElement * WptLog
Definition: WValidation.h:56
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
MonitorElement * lepmet_mTPeak
Definition: WValidation.h:57
MonitorElement * WmassPeak
Definition: WValidation.h:56
MonitorElement * met
Definition: WValidation.h:58
MonitorElement * Wpt
Definition: WValidation.h:56
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: WValidation.cc:74
MonitorElement * lepmet_ptLog
Definition: WValidation.h:57
Definition: DDAxes.h:10
MonitorElement * Wdaughters
Definition: WValidation.h:56
MonitorElement * Wmass
Definition: WValidation.h:56
MonitorElement * cos_theta_gamma_lepton
Definition: WValidation.h:59
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32
int _flavor
decay flavor
Definition: WValidation.h:62