CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZLONLOHistogrammer.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);
10  virtual void endJob();
12  unsigned int nbinsMass_, nbinsPt_, nbinsAng_;
17  TH1F *hardpt, *softpt, * hardeta, *softeta;
18  TH1F * h_weight_histo;
19  bool isMCatNLO_;
21 };
22 
29 
30 #include "HepMC/WeightContainer.h"
31 #include "HepMC/GenEvent.h"
37 #include <cmath>
38 #include <iostream>
39 
40 using namespace std;
41 using namespace reco;
42 using namespace edm;
43 
45  gen_(pset.getParameter<InputTag>("genParticles")),
46  weights_(pset.getParameter<InputTag>("weights")),
47  nbinsMass_(pset.getUntrackedParameter<unsigned int>("nbinsMass")),
48  nbinsPt_(pset.getUntrackedParameter<unsigned int>("nbinsPt")),
49  nbinsAng_(pset.getUntrackedParameter<unsigned int>("nbinsAng")),
50  massMax_(pset.getUntrackedParameter<double>("massMax")),
51  ptMax_(pset.getUntrackedParameter<double>("ptMax")),
52  angMax_(pset.getUntrackedParameter<double>("angMax")),
53  accPtMin_(pset.getUntrackedParameter<double>("accPtMin")),
54  accMassMin_(pset.getUntrackedParameter<double>("accMassMin")),
55  accMassMax_(pset.getUntrackedParameter<double>("accMassMax")),
56  accEtaMin_(pset.getUntrackedParameter<double>("accEtaMin")),
57  accEtaMax_(pset.getUntrackedParameter<double>("accEtaMax")),
58  isMCatNLO_(pset.getUntrackedParameter<bool>("isMCatNLO")) {
59  cout << ">>> Z Histogrammer constructor" << endl;
61  TFileDirectory ZHisto = fs->mkdir( "ZRecHisto" );
62  TFileDirectory ZMCHisto = fs->mkdir( "ZMCHisto" );
63  h_nZ_ = ZHisto.make<TH1F>("ZNumber", "number of Z particles", 11, -0.5, 10.5);
64  h_mZ_ = ZHisto.make<TH1F>("ZMass", "Z mass (GeV/c^{2})", nbinsMass_, 0, massMax_);
65  h_ptZ_ = ZHisto.make<TH1F>("ZPt", "Z p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
66  h_phiZ_ = ZHisto.make<TH1F>("ZPhi", "Z #phi", nbinsAng_, -angMax_, angMax_);
67  h_thetaZ_ = ZHisto.make<TH1F>("Ztheta", "Z #theta", nbinsAng_, 0, angMax_);
68  h_etaZ_ = ZHisto.make<TH1F>("ZEta", "Z #eta", nbinsAng_, -angMax_, angMax_);
69  h_rapidityZ_ = ZHisto.make<TH1F>("ZRapidity", "Z rapidity", nbinsAng_, -angMax_, angMax_);
70  h_weight_histo = ZMCHisto.make<TH1F>("weight_histo","weight_histo",20,-10,10);
71 
72  h_mZMC_ = ZMCHisto.make<TH1F>("ZMCMass", "Z MC mass (GeV/c^{2})", nbinsMass_, 0, massMax_);
73  h_ptZMC_ = ZMCHisto.make<TH1F>("ZMCPt", "Z MC p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
74  hardpt = ZMCHisto.make<TH1F>("hardpt", "hard muon p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
75  softpt = ZMCHisto.make<TH1F>("softpt", "soft muon p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
76 
77 
78  h_phiZMC_ = ZMCHisto.make<TH1F>("ZMCPhi", "Z MC #phi", nbinsAng_, -angMax_, angMax_);
79  h_thetaZMC_ = ZMCHisto.make<TH1F>("ZMCTheta", "Z MC #theta", nbinsAng_, 0, angMax_);
80  h_etaZMC_ = ZMCHisto.make<TH1F>("ZMCEta", "Z MC #eta", nbinsAng_, -angMax_, angMax_);
81  h_rapidityZMC_ = ZMCHisto.make<TH1F>("ZMCRapidity", "Z MC y", nbinsAng_, -angMax_, angMax_);
82 
83  hardeta = ZMCHisto.make<TH1F>("hard muon eta", "hard muon #eta", nbinsAng_, -angMax_, angMax_);
84  softeta = ZMCHisto.make<TH1F>("soft muon eta", "soft muon #eta", nbinsAng_, -angMax_, angMax_);
85  nAcc_=0;
87 
88 }
89 
91  cout << ">>> Z Histogrammer analyze" << endl;
92 
94  Handle<double> weights;
95 
96  event.getByLabel(gen_, gen);
97  event.getByLabel(weights_, weights );
98 
99 
100 
101  // get weight and fill it to histogram
102 
103  double weight = * weights;
104  if(!weight) weight=1.;
105  h_weight_histo->Fill(weight);
106 
107  if(isMCatNLO_) {
108  weight > 0 ? weight=1. : weight=-1.;
109  }
110 
111 
112 
113  std::vector<GenParticle> muons;
114  if (!isMCatNLO_){
115  // LO....
116  for(unsigned int i = 0; i < gen->size(); ++i){
117  const GenParticle & muMC = (*gen)[i];
118  // filling only muons coming form Z
119  if (abs(muMC.pdgId())==13 && muMC.status()==1 && muMC.numberOfMothers()>0) {
120  if (muMC.mother()->numberOfMothers()> 0 ){
121  cout << "I'm getting a muon \n"
122  << "with " << "muMC.numberOfMothers() " << muMC.numberOfMothers() << "\n the first mother has pdgId " << muMC.mother()->pdgId()
123  << "with " << "muMC.mother()->numberOfMothers() " << muMC.mother()->numberOfMothers()<< "\n the first grandma has pdgId " << muMC.mother()->mother()->pdgId()<<endl;
124  if (muMC.mother()->mother()->pdgId() ==23 ) muons.push_back(muMC);
125  }
126  }
127  }
128  } else {
129  // NLO
130  for(unsigned int i = 0; i < gen->size(); ++i){
131  const GenParticle & muMC = (*gen)[i];
132  if (abs(muMC.pdgId())==13 && muMC.status()==1 && muMC.numberOfMothers()>0) { if (muMC.mother()->numberOfMothers()> 0 ){
133  cout << "I'm getting a muon \n"
134  << "with " << "muMC.numberOfMothers() " << muMC.numberOfMothers() << "\n the first mother has pdgId " << muMC.mother()->pdgId()
135  << "with " << "muMC.mother()->numberOfMothers() " << muMC.mother()->numberOfMothers()<< "\n the first grandma has pdgId " << muMC.mother()->mother()->pdgId()<<endl;
136  // filling withoput requiring that the grandma is a Z...... sometimes the grandma are still muons, otherwise those are fake muons, but the first two are always the desired muons....
137  muons.push_back(muMC);
138  }
139  }
140  }
141  }
142 
143  cout << "finally I selected " << muons.size() << " muons" << endl;
144 
145 
146 
147 
148 
149 // if there are at least two muons,
150  // calculate invarant mass of first two and fill it into histogram
151 
152  //if isMCatNLO_......
153 
154 
155 
156 
157  double inv_mass = 0.0;
158  double Zpt_ = 0.0;
159  double Zeta_ = 0.0;
160  double Ztheta_ = 0.0;
161  double Zphi_ = 0.0;
162  double Zrapidity_ = 0.0;
163 
164  if(muons.size()>1) {
165  if (muons[0].mother()->mother()->pdgId()==23 && muons[1].mother()->mother()->pdgId()==23) nBothMuHasZHasGrandMa_ ++;
166  math::XYZTLorentzVector tot_momentum(muons[0].p4());
167  math::XYZTLorentzVector mom2(muons[1].p4());
168  tot_momentum += mom2;
169  inv_mass = sqrt(tot_momentum.mass2());
170  Zpt_=tot_momentum.pt();
171  Zeta_ = tot_momentum.eta();
172  Ztheta_ = tot_momentum.theta();
173  Zphi_ = tot_momentum.phi();
174  Zrapidity_ = tot_momentum.Rapidity();
175 
176 
177 
178  // IMPORTANT: use the weight of the event ...
179 
180  double weight_sign = (weight > 0) ? 1. : -1.;
181  //double weight_sign = 1. ;
182  h_mZMC_->Fill(inv_mass,weight_sign);
183  h_ptZMC_->Fill(Zpt_,weight_sign);
184  h_etaZMC_->Fill(Zeta_,weight_sign);
185  h_thetaZMC_->Fill(Ztheta_,weight_sign);
186  h_phiZMC_->Fill(Zphi_,weight_sign);
187  h_rapidityZMC_-> Fill (Zrapidity_,weight_sign );
188 
189  double pt1 = muons[0].pt();
190  double pt2 = muons[1].pt();
191  double eta1 = muons[0].eta();
192  double eta2 = muons[1].eta();
193 
194 
195 
196  if(pt1>pt2) {
197  hardpt->Fill(pt1,weight_sign);
198  softpt->Fill(pt2,weight_sign);
199  hardeta->Fill(eta1,weight_sign);
200  softeta->Fill(eta2,weight_sign);
201  } else {
202  hardpt->Fill(pt2,weight_sign);
203  softpt->Fill(pt1,weight_sign);
204  hardeta->Fill(eta2,weight_sign);
205  softeta->Fill(eta1,weight_sign);
206  }
207 
208 
209  //evaluating the geometric acceptance
210  if ( pt1 >= accPtMin_ && pt2 >= accPtMin_ && fabs(eta1)>= accEtaMin_ && fabs(eta2) >= accEtaMin_ && fabs(eta1)<= accEtaMax_ && fabs(eta2) <= accEtaMax_ && inv_mass>= accMassMin_ && inv_mass<= accMassMax_) nAcc_++;
211 
212 
213  }
214 
215 }
216 
217 
219  cout << " number of events accepted :" << nAcc_ << endl;
220  cout << " number of total events :" << h_mZMC_->GetEntries() << endl;
221  cout << " number of cases in which BothMuHasZHasGrandMa :" << nBothMuHasZHasGrandMa_ << endl;
222  double eff = (double)nAcc_ / (double) h_mZMC_->GetEntries();
223  double err = sqrt( eff * (1. - eff) / (double) h_mZMC_->GetEntries() );
224  cout << " geometric acceptance: " << eff << "+/-" << err << endl;
225 }
227 
229 
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual int status() const
status word
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
#define abs(x)
Definition: mlp_lapack.h:159
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual size_t numberOfMothers() const
number of mothers
T sqrt(T t)
Definition: SSEVec.h:28
double p4[4]
Definition: TauolaWrapper.h:92
ZLONLOHistogrammer(const edm::ParameterSet &pset)
unsigned int nBothMuHasZHasGrandMa_
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
virtual int pdgId() const =0
PDG identifier.
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
tuple muons
Definition: patZpeak.py:38
T * make() const
make new ROOT object
tuple cout
Definition: gather_cfg.py:41
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")