CMS 3D CMS Logo

ZLONLOHistogrammer.cc
Go to the documentation of this file.
5 #include "TH1.h"
6 
8 public:
10 
11 private:
12  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
13  void endJob() override;
16  unsigned int nbinsMass_, nbinsPt_, nbinsAng_;
23  bool isMCatNLO_;
25 };
26 
31 
32 #include "HepMC/WeightContainer.h"
33 #include "HepMC/GenEvent.h"
39 #include <cmath>
40 #include <iostream>
41 
42 using namespace std;
43 using namespace reco;
44 using namespace edm;
45 
47  : genToken_(consumes<GenParticleCollection>(pset.getParameter<InputTag>("genParticles"))),
48  weightsToken_(consumes<double>(pset.getParameter<InputTag>("weights"))),
49  nbinsMass_(pset.getUntrackedParameter<unsigned int>("nbinsMass")),
50  nbinsPt_(pset.getUntrackedParameter<unsigned int>("nbinsPt")),
51  nbinsAng_(pset.getUntrackedParameter<unsigned int>("nbinsAng")),
52  massMax_(pset.getUntrackedParameter<double>("massMax")),
53  ptMax_(pset.getUntrackedParameter<double>("ptMax")),
54  angMax_(pset.getUntrackedParameter<double>("angMax")),
55  accPtMin_(pset.getUntrackedParameter<double>("accPtMin")),
56  accMassMin_(pset.getUntrackedParameter<double>("accMassMin")),
57  accMassMax_(pset.getUntrackedParameter<double>("accMassMax")),
58  accEtaMin_(pset.getUntrackedParameter<double>("accEtaMin")),
59  accEtaMax_(pset.getUntrackedParameter<double>("accEtaMax")),
60  isMCatNLO_(pset.getUntrackedParameter<bool>("isMCatNLO")) {
61  cout << ">>> Z Histogrammer constructor" << endl;
63  TFileDirectory ZHisto = fs->mkdir("ZRecHisto");
64  TFileDirectory ZMCHisto = fs->mkdir("ZMCHisto");
65  h_nZ_ = ZHisto.make<TH1F>("ZNumber", "number of Z particles", 11, -0.5, 10.5);
66  h_mZ_ = ZHisto.make<TH1F>("ZMass", "Z mass (GeV/c^{2})", nbinsMass_, 0, massMax_);
67  h_ptZ_ = ZHisto.make<TH1F>("ZPt", "Z p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
68  h_phiZ_ = ZHisto.make<TH1F>("ZPhi", "Z #phi", nbinsAng_, -angMax_, angMax_);
69  h_thetaZ_ = ZHisto.make<TH1F>("Ztheta", "Z #theta", nbinsAng_, 0, angMax_);
70  h_etaZ_ = ZHisto.make<TH1F>("ZEta", "Z #eta", nbinsAng_, -angMax_, angMax_);
71  h_rapidityZ_ = ZHisto.make<TH1F>("ZRapidity", "Z rapidity", nbinsAng_, -angMax_, angMax_);
72  h_weight_histo = ZMCHisto.make<TH1F>("weight_histo", "weight_histo", 20, -10, 10);
73 
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  hardpt = ZMCHisto.make<TH1F>("hardpt", "hard muon p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
77  softpt = ZMCHisto.make<TH1F>("softpt", "soft muon p_{t} (GeV/c)", nbinsPt_, 0, ptMax_);
78 
79  h_phiZMC_ = ZMCHisto.make<TH1F>("ZMCPhi", "Z MC #phi", nbinsAng_, -angMax_, angMax_);
80  h_thetaZMC_ = ZMCHisto.make<TH1F>("ZMCTheta", "Z MC #theta", nbinsAng_, 0, angMax_);
81  h_etaZMC_ = ZMCHisto.make<TH1F>("ZMCEta", "Z MC #eta", nbinsAng_, -angMax_, angMax_);
82  h_rapidityZMC_ = ZMCHisto.make<TH1F>("ZMCRapidity", "Z MC y", nbinsAng_, -angMax_, angMax_);
83 
84  hardeta = ZMCHisto.make<TH1F>("hard muon eta", "hard muon #eta", nbinsAng_, -angMax_, angMax_);
85  softeta = ZMCHisto.make<TH1F>("soft muon eta", "soft muon #eta", nbinsAng_, -angMax_, angMax_);
86  nAcc_ = 0;
88 }
89 
91  cout << ">>> Z Histogrammer analyze" << endl;
92 
95 
96  event.getByToken(genToken_, gen);
97  event.getByToken(weightsToken_, weights);
98 
99  // get weight and fill it to histogram
100 
101  double weight = *weights;
102  if (!weight)
103  weight = 1.;
104  h_weight_histo->Fill(weight);
105 
106  if (isMCatNLO_) {
107  weight > 0 ? weight = 1. : weight = -1.;
108  }
109 
110  std::vector<GenParticle> muons;
111  if (!isMCatNLO_) {
112  // LO....
113  for (unsigned int i = 0; i < gen->size(); ++i) {
114  const GenParticle& muMC = (*gen)[i];
115  // filling only muons coming form Z
116  if (abs(muMC.pdgId()) == 13 && muMC.status() == 1 && muMC.numberOfMothers() > 0) {
117  if (muMC.mother()->numberOfMothers() > 0) {
118  cout << "I'm getting a muon \n"
119  << "with "
120  << "muMC.numberOfMothers() " << muMC.numberOfMothers() << "\n the first mother has pdgId "
121  << muMC.mother()->pdgId() << "with "
122  << "muMC.mother()->numberOfMothers() " << muMC.mother()->numberOfMothers()
123  << "\n the first grandma has pdgId " << muMC.mother()->mother()->pdgId() << endl;
124  if (muMC.mother()->mother()->pdgId() == 23)
125  muons.push_back(muMC);
126  }
127  }
128  }
129  } else {
130  // NLO
131  for (unsigned int i = 0; i < gen->size(); ++i) {
132  const GenParticle& muMC = (*gen)[i];
133  if (abs(muMC.pdgId()) == 13 && muMC.status() == 1 && muMC.numberOfMothers() > 0) {
134  if (muMC.mother()->numberOfMothers() > 0) {
135  cout << "I'm getting a muon \n"
136  << "with "
137  << "muMC.numberOfMothers() " << muMC.numberOfMothers() << "\n the first mother has pdgId "
138  << muMC.mother()->pdgId() << "with "
139  << "muMC.mother()->numberOfMothers() " << muMC.mother()->numberOfMothers()
140  << "\n the first grandma has pdgId " << muMC.mother()->mother()->pdgId() << endl;
141  // 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....
142  muons.push_back(muMC);
143  }
144  }
145  }
146  }
147 
148  cout << "finally I selected " << muons.size() << " muons" << endl;
149 
150  // if there are at least two muons,
151  // calculate invarant mass of first two and fill it into histogram
152 
153  //if isMCatNLO_......
154 
155  double inv_mass = 0.0;
156  double Zpt_ = 0.0;
157  double Zeta_ = 0.0;
158  double Ztheta_ = 0.0;
159  double Zphi_ = 0.0;
160  double Zrapidity_ = 0.0;
161 
162  if (muons.size() > 1) {
163  if (muons[0].mother()->mother()->pdgId() == 23 && muons[1].mother()->mother()->pdgId() == 23)
165  math::XYZTLorentzVector tot_momentum(muons[0].p4());
166  math::XYZTLorentzVector mom2(muons[1].p4());
167  tot_momentum += mom2;
168  inv_mass = sqrt(tot_momentum.mass2());
169  Zpt_ = tot_momentum.pt();
170  Zeta_ = tot_momentum.eta();
171  Ztheta_ = tot_momentum.theta();
172  Zphi_ = tot_momentum.phi();
173  Zrapidity_ = tot_momentum.Rapidity();
174 
175  // IMPORTANT: use the weight of the event ...
176 
177  double weight_sign = (weight > 0) ? 1. : -1.;
178  //double weight_sign = 1. ;
179  h_mZMC_->Fill(inv_mass, weight_sign);
180  h_ptZMC_->Fill(Zpt_, weight_sign);
181  h_etaZMC_->Fill(Zeta_, weight_sign);
182  h_thetaZMC_->Fill(Ztheta_, weight_sign);
183  h_phiZMC_->Fill(Zphi_, weight_sign);
184  h_rapidityZMC_->Fill(Zrapidity_, weight_sign);
185 
186  double pt1 = muons[0].pt();
187  double pt2 = muons[1].pt();
188  double eta1 = muons[0].eta();
189  double eta2 = muons[1].eta();
190 
191  if (pt1 > pt2) {
192  hardpt->Fill(pt1, weight_sign);
193  softpt->Fill(pt2, weight_sign);
194  hardeta->Fill(eta1, weight_sign);
195  softeta->Fill(eta2, weight_sign);
196  } else {
197  hardpt->Fill(pt2, weight_sign);
198  softpt->Fill(pt1, weight_sign);
199  hardeta->Fill(eta2, weight_sign);
200  softeta->Fill(eta1, weight_sign);
201  }
202 
203  //evaluating the geometric acceptance
204  if (pt1 >= accPtMin_ && pt2 >= accPtMin_ && fabs(eta1) >= accEtaMin_ && fabs(eta2) >= accEtaMin_ &&
205  fabs(eta1) <= accEtaMax_ && fabs(eta2) <= accEtaMax_ && inv_mass >= accMassMin_ && inv_mass <= accMassMax_)
206  nAcc_++;
207  }
208 }
209 
211  cout << " number of events accepted :" << nAcc_ << endl;
212  cout << " number of total events :" << h_mZMC_->GetEntries() << endl;
213  cout << " number of cases in which BothMuHasZHasGrandMa :" << nBothMuHasZHasGrandMa_ << endl;
214  double eff = (double)nAcc_ / (double)h_mZMC_->GetEntries();
215  double err = sqrt(eff * (1. - eff) / (double)h_mZMC_->GetEntries());
216  cout << " geometric acceptance: " << eff << "+/-" << err << endl;
217 }
219 
ZLONLOHistogrammer::h_etaZMC_
TH1F * h_etaZMC_
Definition: ZLONLOHistogrammer.cc:20
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
ZLONLOHistogrammer::ZLONLOHistogrammer
ZLONLOHistogrammer(const edm::ParameterSet &pset)
Definition: ZLONLOHistogrammer.cc:46
Handle.h
ZLONLOHistogrammer::h_phiZ_
TH1F * h_phiZ_
Definition: ZLONLOHistogrammer.cc:19
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
reco::LeafCandidate::status
int status() const final
status word
Definition: LeafCandidate.h:180
ZLONLOHistogrammer::nbinsPt_
unsigned int nbinsPt_
Definition: ZLONLOHistogrammer.cc:16
ZLONLOHistogrammer::h_rapidityZ_
TH1F * h_rapidityZ_
Definition: ZLONLOHistogrammer.cc:19
edm::EDGetTokenT< reco::GenParticleCollection >
reco::CompositeRefCandidateT::mother
const Candidate * mother(size_type=0) const override
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode)
TFileDirectory::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileDirectory.h:53
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
ZLONLOHistogrammer::softeta
TH1F * softeta
Definition: ZLONLOHistogrammer.cc:21
ZLONLOHistogrammer::angMax_
double angMax_
Definition: ZLONLOHistogrammer.cc:17
ZLONLOHistogrammer::softpt
TH1F * softpt
Definition: ZLONLOHistogrammer.cc:21
reco::CompositeRefCandidateT::numberOfMothers
size_t numberOfMothers() const override
number of mothers
ZLONLOHistogrammer::accEtaMax_
double accEtaMax_
Definition: ZLONLOHistogrammer.cc:18
EDAnalyzer.h
TFileDirectory
Definition: TFileDirectory.h:24
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ZLONLOHistogrammer::nBothMuHasZHasGrandMa_
unsigned int nBothMuHasZHasGrandMa_
Definition: ZLONLOHistogrammer.cc:24
reco::Candidate::mother
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
edm::Handle
Definition: AssociativeIterator.h:50
GenParticle
Definition: GenParticle.py:1
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
CandMatchMap.h
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
GenParticle.h
CandidateFwd.h
MakerMacros.h
ZLONLOHistogrammer::massMax_
double massMax_
Definition: ZLONLOHistogrammer.cc:17
reco::Candidate::numberOfMothers
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
ZLONLOHistogrammer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
Definition: ZLONLOHistogrammer.cc:90
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ZLONLOHistogrammer::genToken_
edm::EDGetTokenT< reco::GenParticleCollection > genToken_
Definition: ZLONLOHistogrammer.cc:14
ZLONLOHistogrammer::h_mZ_
TH1F * h_mZ_
Definition: ZLONLOHistogrammer.cc:19
Service.h
HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:99178
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ZLONLOHistogrammer
Definition: ZLONLOHistogrammer.cc:7
HLT_FULL_cff.eta2
eta2
Definition: HLT_FULL_cff.py:9542
GenParticleFwd.h
ZLONLOHistogrammer::h_nZ_
TH1F * h_nZ_
Definition: ZLONLOHistogrammer.cc:19
HLT_FULL_cff.pt1
pt1
Definition: HLT_FULL_cff.py:9870
ZLONLOHistogrammer::accEtaMin_
double accEtaMin_
Definition: ZLONLOHistogrammer.cc:18
gen
Definition: PythiaDecays.h:13
ZLONLOHistogrammer::h_rapidityZMC_
TH1F * h_rapidityZMC_
Definition: ZLONLOHistogrammer.cc:20
TFileService.h
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9541
ZLONLOHistogrammer::h_thetaZ_
TH1F * h_thetaZ_
Definition: ZLONLOHistogrammer.cc:19
TFileService::mkdir
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
edm::ParameterSet
Definition: ParameterSet.h:47
ZLONLOHistogrammer::weightsToken_
edm::EDGetTokenT< double > weightsToken_
Definition: ZLONLOHistogrammer.cc:15
Event.h
ZLONLOHistogrammer::h_weight_histo
TH1F * h_weight_histo
Definition: ZLONLOHistogrammer.cc:22
ZLONLOHistogrammer::h_phiZMC_
TH1F * h_phiZMC_
Definition: ZLONLOHistogrammer.cc:20
reco::LeafCandidate::pdgId
int pdgId() const final
PDG identifier.
Definition: LeafCandidate.h:176
ZLONLOHistogrammer::hardpt
TH1F * hardpt
Definition: ZLONLOHistogrammer.cc:21
ZLONLOHistogrammer::endJob
void endJob() override
Definition: ZLONLOHistogrammer.cc:210
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
ZLONLOHistogrammer::h_etaZ_
TH1F * h_etaZ_
Definition: ZLONLOHistogrammer.cc:19
p4
double p4[4]
Definition: TauolaWrapper.h:92
ZLONLOHistogrammer::h_mZMC_
TH1F * h_mZMC_
Definition: ZLONLOHistogrammer.cc:20
edm::EventSetup
Definition: EventSetup.h:57
HLT_FULL_cff.pt2
pt2
Definition: HLT_FULL_cff.py:9872
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
ZLONLOHistogrammer::accPtMin_
double accPtMin_
Definition: ZLONLOHistogrammer.cc:18
reco::Candidate::pdgId
virtual int pdgId() const =0
PDG identifier.
ZLONLOHistogrammer::hardeta
TH1F * hardeta
Definition: ZLONLOHistogrammer.cc:21
InputTag.h
ZLONLOHistogrammer::h_ptZ_
TH1F * h_ptZ_
Definition: ZLONLOHistogrammer.cc:19
ZLONLOHistogrammer::isMCatNLO_
bool isMCatNLO_
Definition: ZLONLOHistogrammer.cc:23
std
Definition: JetResolutionObject.h:76
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
relval_steps.gen
def gen(fragment, howMuch)
Production test section ####.
Definition: relval_steps.py:509
ZLONLOHistogrammer::h_ptZMC_
TH1F * h_ptZMC_
Definition: ZLONLOHistogrammer.cc:20
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ZLONLOHistogrammer::h_thetaZMC_
TH1F * h_thetaZMC_
Definition: ZLONLOHistogrammer.cc:20
ZLONLOHistogrammer::nbinsMass_
unsigned int nbinsMass_
Definition: ZLONLOHistogrammer.cc:16
ParameterSet.h
HepMCProduct.h
ZLONLOHistogrammer::accMassMax_
double accMassMax_
Definition: ZLONLOHistogrammer.cc:18
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
ZLONLOHistogrammer::accMassMin_
double accMassMin_
Definition: ZLONLOHistogrammer.cc:18
ZLONLOHistogrammer::ptMax_
double ptMax_
Definition: ZLONLOHistogrammer.cc:17
edm::InputTag
Definition: InputTag.h:15
weight
Definition: weight.py:1
ZLONLOHistogrammer::nAcc_
unsigned int nAcc_
Definition: ZLONLOHistogrammer.cc:24
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
ZLONLOHistogrammer::nbinsAng_
unsigned int nbinsAng_
Definition: ZLONLOHistogrammer.cc:16