CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZMCHistogrammer.cc
Go to the documentation of this file.
3 #include "TH1.h"
4 
6 public:
8 private:
9  virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
14  TH1F *h_invmMuMu_;
17  //TH1F *h_mZ2vs3MC_, *h_ptZ2vs3MC_, *h_phiZ2vs3MC_, *h_thetaZ2vs3MC_, *h_etaZ2vs3MC_, *h_rapidityZ2vs3MC_;
21  bool isMCatNLO_;
22 };
23 
30 
31 #include "HepMC/WeightContainer.h"
32 #include "HepMC/GenEvent.h"
38 #include <cmath>
39 #include <iostream>
40 
41 using namespace std;
42 using namespace reco;
43 using namespace edm;
44 
46  z_(pset.getParameter<InputTag>("z")),
47  gen_(pset.getParameter<InputTag>("gen")),
48  match_(pset.getParameter<InputTag>("match")),
49  nbinsMass_(pset.getUntrackedParameter<unsigned int>("nbinsMass")),
50  nbinsPt_(pset.getUntrackedParameter<unsigned int>("nbinsPt")),
51  nbinsAng_(pset.getUntrackedParameter<unsigned int>("nbinsAng")),
52  nbinsMassRes_(pset.getUntrackedParameter<unsigned int>("nbinsMassRes")),
53  massMax_(pset.getUntrackedParameter<double>("massMax")),
54  ptMax_(pset.getUntrackedParameter<double>("ptMax")),
55  angMax_(pset.getUntrackedParameter<double>("angMax")),
56  massResMax_(pset.getUntrackedParameter<double>("massResMax")),
57  isMCatNLO_(pset.getUntrackedParameter<bool>("isMCatNLO")) {
58  cout << ">>> Z Histogrammer constructor" << endl;
60  TFileDirectory ZHisto = fs->mkdir( "ZRecoHisto" );
61  TFileDirectory ZMCHisto = fs->mkdir( "ZMCHisto" );
62  TFileDirectory ZResHisto = fs->mkdir( "ZResolutionHisto" );
63  //TFileDirectory Z2vs3MCHisto = fs->mkdir( "Z2vs3MCHisto" );
64  h_nZ_ = ZHisto.make<TH1F>("ZNumber", "number of Z particles", 11, -0.5, 10.5);
65  h_mZ_ = ZHisto.make<TH1F>("ZMass", "Z mass (GeV/c^{2})", nbinsMass_, 0, massMax_);
66  h_ptZ_ = ZHisto.make<TH1F>("ZPt", "Z p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
67  h_phiZ_ = ZHisto.make<TH1F>("ZPhi", "Z #phi", nbinsAng_, -angMax_, angMax_);
68  h_thetaZ_ = ZHisto.make<TH1F>("Ztheta", "Z #theta", nbinsAng_, 0, angMax_);
69  h_etaZ_ = ZHisto.make<TH1F>("ZEta", "Z #eta", nbinsAng_, -angMax_, angMax_);
70  h_rapidityZ_ = ZHisto.make<TH1F>("ZRapidity", "Z rapidity", nbinsAng_, -angMax_, angMax_);
71  h_invmMuMu_ = ZHisto.make<TH1F>("MuMuMass", "#mu #mu invariant mass",nbinsMass_, 0, massMax_);
72  h_weight_histo = ZHisto.make<TH1F>("weight_histo","weight_histo",20,-10,10);
73  h_nZMC_ = ZMCHisto.make<TH1F>("ZMCNumber", "number of Z MC particles", 11, -0.5, 10.5);
74  h_mZMC_ = ZMCHisto.make<TH1F>("ZMCMass", "Z MC mass (GeV/c^{2})", nbinsMass_, 0, massMax_);
75  h_ptZMC_ = ZMCHisto.make<TH1F>("ZMCPt", "Z MC p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
76  h_phiZMC_ = ZMCHisto.make<TH1F>("ZMCPhi", "Z MC #phi", nbinsAng_, -angMax_, angMax_);
77  h_thetaZMC_ = ZMCHisto.make<TH1F>("ZMCTheta", "Z MC #theta", nbinsAng_, 0, angMax_);
78  h_etaZMC_ = ZMCHisto.make<TH1F>("ZMCEta", "Z MC #eta", nbinsAng_, -angMax_, angMax_);
79  h_rapidityZMC_ = ZMCHisto.make<TH1F>("ZMCRapidity", "Z MC rapidity", nbinsAng_, -angMax_, angMax_);
80  h_invmMuMuMC_ = ZMCHisto.make<TH1F>("MuMuMCMass", "#mu #mu MC invariant mass",
81  nbinsMass_, 0, massMax_);
82  /*
83  h_mZ2vs3MC_ = Z2vs3MCHisto.make<TH1F>("Z2vs3MCMass", "Z MC st 2 vs st 3 mass (GeV/c^{2})",
84  nbinsMassRes_, -massResMax_, massResMax_);
85  h_ptZ2vs3MC_ = Z2vs3MCHisto.make<TH1F>("Z2vs3MCPt", "Z MC st 2 vs st 3 p_{t} (GeV/c)",
86  nbinsPt_, -ptMax_, ptMax_);
87  h_phiZ2vs3MC_ = Z2vs3MCHisto.make<TH1F>("Z2vs3MCPhi", "Z MC st 2 vs st 3 #phi",
88  nbinsAng_, -angMax_, angMax_);
89  h_thetaZ2vs3MC_ = Z2vs3MCHisto.make<TH1F>("Z2vs3MCTheta", "Z MC st 2 vs st 3 #theta",
90  nbinsAng_, -angMax_, angMax_);
91  h_etaZ2vs3MC_ = Z2vs3MCHisto.make<TH1F>("Z2vs3MCEta", "Z MC st 2 vs st 3 #eta",
92  nbinsAng_, -angMax_, angMax_);
93  h_rapidityZ2vs3MC_ = Z2vs3MCHisto.make<TH1F>("Z2vs3MCRapidity", "Z MC st 2 vs st 3 rapidity",
94  nbinsAng_, -angMax_, angMax_);
95  */
96  h_mResZ_ = ZResHisto.make<TH1F>("ZMassResolution", "Z mass Resolution (GeV/c^{2})",
98  h_ptResZ_ = ZResHisto.make<TH1F>("ZPtResolution", "Z p_{t} Resolution (GeV/c)",
100  h_phiResZ_ = ZResHisto.make<TH1F>("ZPhiResolution", "Z #phi Resolution",
102  h_thetaResZ_ = ZResHisto.make<TH1F>("ZThetaResolution", "Z #theta Resolution",
104  h_etaResZ_ = ZResHisto.make<TH1F>("ZEtaResolution", "Z #eta Resolution",
106  h_rapidityResZ_ = ZResHisto.make<TH1F>("ZRapidityResolution", "Z rapidity Resolution",
108  h_mResZMuMu_ = ZResHisto.make<TH1F>("ZToMuMuRecoMassResolution",
109  "Z Reco vs matched final state #mu #mu mass Difference (GeV/c^{2})",
111  h_mRatioZMuMu_ = ZResHisto.make<TH1F>("ZToMuMuRecoMassRatio",
112  "Z Reco vs matched final state #mu #mu mass Ratio",
113  4000, 0, 2);
114  h_mResZMuMuMC_ = ZResHisto.make<TH1F>("ZToMuMuMCMassResolution",
115  "Z vs final state #mu #mu MC mass Difference (GeV/c^{2})",
116  nbinsMassRes_/2 + 1, -2*massResMax_/nbinsMassRes_, massResMax_);
117  h_mRatioZMuMuMC_ = ZResHisto.make<TH1F>("ZToMuMuMCMassRatio",
118  "Z vs final state #mu #mu MC mass Ratio",
119  2002, 0.999, 2);
120 }
121 
123  cout << ">>> Z Histogrammer analyze" << endl;
127  event.getByLabel(z_, z);
128  event.getByLabel(gen_, gen);
129  event.getByLabel(match_, match);
130  h_nZ_->Fill(z->size());
131 
132 // get HepMC::GenEvent ...
133  Handle<HepMCProduct> evt_h;
134  event.getByType(evt_h);
135  HepMC::GenEvent* evt = new HepMC::GenEvent(*(evt_h->GetEvent()));
136 
137 
138  // get weight and fill it to histogram
139  HepMC::WeightContainer weights = evt->weights();
140  double weight = weights.front();
141  if(!weight) weight=1.;
142  h_weight_histo->Fill(weight);
143 
144  if(isMCatNLO_) {
145  weight > 0 ? weight=1. : weight=-1.;
146  }
147 
148  for(unsigned int i = 0; i < z->size(); ++i) {
149  const Candidate &zCand = (*z)[i];
150  h_mZ_->Fill(zCand.mass(),weight );
151  h_ptZ_->Fill(zCand.pt(),weight);
152  h_phiZ_->Fill(zCand.phi(),weight);
153  h_thetaZ_->Fill(zCand.theta(),weight);
154  h_etaZ_->Fill(zCand.eta(),weight);
155  h_rapidityZ_->Fill(zCand.rapidity(),weight);
156  CandidateBaseRef zCandRef = z->refAt(i);
157 
158  GenParticleRef zMCMatch = (*match)[i];
159  if(zMCMatch.isNonnull() && zMCMatch->pdgId()==23) {
160  h_mResZ_->Fill(zCandRef->mass() - zMCMatch->mass());
161  h_ptResZ_->Fill(zCandRef->pt() - zMCMatch->pt());
162  h_phiResZ_->Fill(zCandRef->phi() - zMCMatch->phi());
163  h_thetaResZ_->Fill(zCandRef->theta() - zMCMatch->theta());
164  h_etaResZ_->Fill(zCandRef->eta() - zMCMatch->eta());
165  h_rapidityResZ_->Fill(zCandRef->rapidity() - zMCMatch->rapidity());
166  const Candidate * dau0 = zMCMatch->daughter(0);
167  const Candidate * dau1 = zMCMatch->daughter(1);
168  for(unsigned int i0 = 0; i0 < dau0->numberOfDaughters(); ++i0) {
169  const Candidate * ddau0 = dau0->daughter(i0);
170  if(abs(ddau0->pdgId())==13 && ddau0->status()==1) {
171  dau0 = ddau0; break;
172  }
173  }
174  for(unsigned int i1 = 0; i1 < dau1->numberOfDaughters(); ++i1) {
175  const Candidate * ddau1 = dau1->daughter(i1);
176  if(abs(ddau1->pdgId())==13 && ddau1->status()==1) {
177  dau1 = ddau1; break;
178  }
179  }
180  assert(abs(dau0->pdgId())==13 && dau0->status()==1);
181  assert(abs(dau1->pdgId())==13 && dau1->status()==1);
182  double invMass = (dau0->p4()+dau1->p4()).mass();
183  h_invmMuMu_->Fill(invMass,weight);
184  h_mResZMuMu_->Fill(zCand.mass() - invMass);
185  h_mRatioZMuMu_->Fill(zCand.mass()/invMass);
186  }
187  }
188  h_nZMC_->Fill(gen->size());
189  for(unsigned int i = 0; i < gen->size(); ++i) {
190  const Candidate &genCand = (*gen)[i];
191  if((genCand.pdgId() == 23) && (genCand.status() == 2)) //this is an intermediate Z0
192  cout << ">>> intermediate Z0 found, with " << genCand.numberOfDaughters()
193  << " daughters" << endl;
194  if((genCand.pdgId() == 23)&&(genCand.status() == 3)) { //this is a Z0
195  cout << ">>> Z0 found, with " << genCand.numberOfDaughters()
196  << " daughters" << endl;
197  h_mZMC_->Fill(genCand.mass(),weight);
198  h_ptZMC_->Fill(genCand.pt(),weight);
199  h_phiZMC_->Fill(genCand.phi(),weight);
200  h_thetaZMC_->Fill(genCand.theta(),weight);
201  h_etaZMC_->Fill(genCand.eta(),weight);
202  h_rapidityZMC_->Fill(genCand.rapidity(),weight);
203  Particle::LorentzVector pZ(0, 0, 0, 0);
204  int nMu = 0;
205  for(unsigned int j = 0; j < genCand.numberOfDaughters(); ++j) {
206  const Candidate *dauGen = genCand.daughter(j);
207  /*
208  if((dauGen->pdgId() == 23) && (dauGen->status() == 2)) {
209  h_mZ2vs3MC_->Fill(genCand.mass() - dauGen->mass());
210  h_ptZ2vs3MC_->Fill(genCand.pt() - dauGen->pt());
211  h_phiZ2vs3MC_->Fill(genCand.phi() - dauGen->phi());
212  h_thetaZ2vs3MC_->Fill(genCand.theta() - dauGen->theta());
213  h_etaZ2vs3MC_->Fill(genCand.eta() - dauGen->eta());
214  h_rapidityZ2vs3MC_->Fill(genCand.rapidity() - dauGen->rapidity());
215  }
216  */
217  if((abs(dauGen->pdgId()) == 13) && (dauGen->numberOfDaughters() != 0)) {
218  //we are looking for photons of final state radiation
219  cout << ">>> The muon " << j
220  << " has " << dauGen->numberOfDaughters() << " daughters" <<endl;
221  for(unsigned int k = 0; k < dauGen->numberOfDaughters(); ++k) {
222  const Candidate * dauMuGen = dauGen->daughter(k);
223  cout << ">>> Mu " << j
224  << " daughter MC " << k
225  << " PDG Id " << dauMuGen->pdgId()
226  << ", status " << dauMuGen->status()
227  << ", charge " << dauMuGen->charge()
228  << endl;
229  if(abs(dauMuGen->pdgId()) == 13 && dauMuGen->status() ==1) {
230  pZ += dauMuGen->p4();
231  nMu ++;
232  }
233  }
234  }
235  }
236  assert(nMu == 2);
237  double mZ = pZ.mass();
238  h_invmMuMuMC_->Fill(mZ,weight);
239  h_mResZMuMuMC_->Fill(genCand.mass() - mZ);
240  h_mRatioZMuMuMC_->Fill(genCand.mass()/mZ);
241  }
242  }
243 }
244 
246 
248 
int i
Definition: DBlmapReader.cc:9
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
edm::InputTag z_
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
ZMCHistogrammer(const edm::ParameterSet &pset)
virtual double mass() const =0
mass
virtual int status() const =0
status word
#define abs(x)
Definition: mlp_lapack.h:159
virtual double rapidity() const =0
rapidity
double double double z
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
virtual size_type numberOfDaughters() const =0
number of daughters
unsigned int nbinsAng_
virtual double theta() const =0
momentum polar angle
edm::InputTag gen_
int j
Definition: DBlmapReader.cc:9
edm::InputTag match_
virtual int charge() const =0
electric charge
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int k[5][pyjets_maxn]
virtual int pdgId() const =0
PDG identifier.
unsigned int nbinsMass_
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup)
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
tuple mass
Definition: scaleCards.py:27
T * make() const
make new ROOT object
tuple cout
Definition: gather_cfg.py:121
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
unsigned int nbinsPt_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
unsigned int nbinsMassRes_