CMS 3D CMS Logo

MCAcceptanceAnalyzer.cc
Go to the documentation of this file.
8 #include <iostream>
9 
10 using namespace edm;
11 using namespace reco;
12 using namespace std;
13 
15  unsigned int n = c->numberOfDaughters();
16  for (unsigned int i = 0; i < n; ++i) {
17  const Candidate* d = c->daughter(i);
18  if (fabs(d->pdgId()) == 13)
19  return d;
20  }
21  return nullptr;
22 }
23 
24 struct ZSelector { // modify this selector in order to return an integer (0: no eta cut, 1: eta cut only, 2 eta && pt cut, 3: eta, pt and Mass cut, 4: mass cut on the denominator Z MC)
25  ZSelector(double ptMin,
26  double etaDau0Min,
27  double etaDau0Max,
28  double etaDau1Min,
29  double etaDau1Max,
30  double massMin,
31  double massMax,
32  double massMinZMC,
33  double massMaxZMC)
34  : ptMin_(ptMin),
35  etaDau0Min_(etaDau0Min),
36  etaDau0Max_(etaDau0Max),
37  etaDau1Min_(etaDau1Min),
38  etaDau1Max_(etaDau1Max),
39  massMin_(massMin),
40  massMax_(massMax),
41  massMinZMC_(massMinZMC),
42  massMaxZMC_(massMaxZMC) {}
43  int operator()(const Candidate& c) const {
44  // std::cout << "c.numberOfDaughters(): " << c.numberOfDaughters()<< std::endl;
45  if (c.numberOfDaughters() < 2)
46  return 0;
47  if (c.numberOfDaughters() >= 6)
48  return 0;
49  const Candidate* d0 = c.daughter(0);
50  const Candidate* d1 = c.daughter(1);
51  if (c.numberOfDaughters() > 2) {
52  if (d0->numberOfDaughters() > 0)
53  d0 = mcMuDaughter(d0);
54  if (d1->numberOfDaughters() > 0)
55  d1 = mcMuDaughter(d1);
56  }
57  int temp_cut = 0;
59  if ((fabs(d0->eta()) > etaDau0Min_ && fabs(d1->eta()) > etaDau1Min_ && fabs(d0->eta()) < etaDau0Max_ &&
60  fabs(d1->eta()) < etaDau1Max_) ||
61  (fabs(d0->eta()) > etaDau1Min_ && fabs(d1->eta()) > etaDau0Min_ && fabs(d0->eta()) < etaDau1Max_ &&
62  fabs(d1->eta()) < etaDau0Max_)) {
63  temp_cut = 1;
64  if (d0->pt() > ptMin_ && d1->pt() > ptMin_) {
65  temp_cut = 2;
66  double m = (d0->p4() + d1->p4()).mass();
67  if (m > massMin_ && m < massMax_)
68  temp_cut = 3;
69  if (c.mass() > massMinZMC_ && c.mass() < massMaxZMC_)
70  temp_cut = 4;
71  }
72  }
73 
74  return temp_cut;
75  }
76  double ptMin_, etaDau0Min_, etaDau0Max_, etaDau1Min_, etaDau1Max_, massMin_, massMax_, massMinZMC_, massMaxZMC_;
77 };
78 
80 public:
82 
83 private:
84  void analyze(const Event&, const EventSetup&) override;
85  void endJob() override;
86  InputTag zToMuMu_, zToMuMuMC_, zToMuMuMatched_;
90  long nZToMuMu_, selZToMuMu_, nZToMuMuMC_, selZToMuMuMC_, nZToMuMuMCMatched_, selZToMuMuMCMatched_, nZToMuMuMCDen_;
92 };
93 
95  : zToMuMu_(cfg.getParameter<InputTag>("zToMuMu")),
96  zToMuMuMC_(cfg.getParameter<InputTag>("zToMuMuMC")),
97  zToMuMuMatched_(cfg.getParameter<InputTag>("zToMuMuMatched")),
98  zToMuMuToken_(consumes<CandidateView>(zToMuMu_)),
99  zToMuMuMCToken_(consumes<CandidateView>(zToMuMuMC_)),
100  zToMuMuMatchedToken_(consumes<GenParticleMatch>(zToMuMuMatched_)),
101  nZToMuMu_(0),
102  selZToMuMu_(0),
103  nZToMuMuMC_(0),
104  selZToMuMuMC_(0),
105  nZToMuMuMCMatched_(0),
106  selZToMuMuMCMatched_(0),
107  nZToMuMuMCDen_(0),
108  select_(cfg.getParameter<double>("ptMin"),
109  cfg.getParameter<double>("etaDau0Min"),
110  cfg.getParameter<double>("etaDau0Max"),
111  cfg.getParameter<double>("etaDau1Min"),
112  cfg.getParameter<double>("etaDau1Max"),
113  cfg.getParameter<double>("massMin"),
114  cfg.getParameter<double>("massMax"),
115  cfg.getParameter<double>("massMinZMC"),
116  cfg.getParameter<double>("massMaxZMC")),
117  select_OnlyMassCut_(-1,
118  -9999,
119  9999,
120  -9999,
121  9999,
122  0,
123  0,
124  cfg.getParameter<double>("massMinZMC"),
125  cfg.getParameter<double>("massMaxZMC")) {}
126 
128  Handle<CandidateView> zToMuMu;
129  evt.getByToken(zToMuMuToken_, zToMuMu);
130  Handle<CandidateView> zToMuMuMC;
131  evt.getByToken(zToMuMuMCToken_, zToMuMuMC);
132  Handle<GenParticleMatch> zToMuMuMatched;
133  evt.getByToken(zToMuMuMatchedToken_, zToMuMuMatched);
134  // long nZToMuMu = zToMuMu->size();
135  long nZToMuMuMC = zToMuMuMC->size();
136  long nZToMuMuMatched = zToMuMuMatched->size();
137 
138  // cout << ">>> " << zToMuMu_ << " has " << nZToMuMu << " entries" << endl;
139  //cout << ">>> " << zToMuMuMC_ << " has " << nZToMuMuMC << " entries" << endl;
140  //cout << ">>> " << zToMuMuMatched_ << " has " << nZToMuMuMatched << " entries" << endl;
141 
142  nZToMuMuMC_ += nZToMuMuMC;
143  for (long i = 0; i < nZToMuMuMC; ++i) {
144  const Candidate& z = (*zToMuMuMC)[i];
145  if (select_(z) == 4)
146  ++selZToMuMuMC_;
147  if (select_OnlyMassCut_(z) == 4)
148  ++nZToMuMuMCDen_;
149  }
150 
151  for (long i = 0; i < nZToMuMuMatched; ++i) {
152  const Candidate& z = (*zToMuMu)[i];
153  CandidateBaseRef zRef = zToMuMu->refAt(i);
154  GenParticleRef mcRef = (*zToMuMuMatched)[zRef];
155 
156  if (mcRef.isNonnull()) { // z candidate matched to Z MC
157  ++nZToMuMu_;
159 
160  int selectZ = select_(z);
161  if (selectZ == 4)
162  ++selZToMuMu_;
163 
164  int selectMC = select_(*mcRef);
165 
166  if (selectMC == 4)
168 
169  if (selectZ != selectMC) {
170  cout << ">>> select reco: " << selectZ << ", select mc: " << selectMC << endl;
171  if ((selectZ * selectMC) == 0)
172  break;
173  if (z.numberOfDaughters() > 1) {
174  const Candidate *d0 = z.daughter(0), *d1 = z.daughter(1);
175  if (mcRef->numberOfDaughters() > 1) {
176  const Candidate *mcd0 = mcMuDaughter(mcRef->daughter(0)), *mcd1 = mcMuDaughter(mcRef->daughter(1));
177  double m = z.mass(), mcm = (mcd0->p4() + mcd1->p4()).mass();
178  cout << ">>> reco pt1, eta1: " << d0->pt() << ", " << d0->eta() << ", 2: " << d1->pt() << ", " << d1->eta()
179  << ", mass = " << m << endl;
180  cout << ">>> mc pt1, eta1: " << mcd0->pt() << ", " << mcd0->eta() << ", 2: " << mcd1->pt() << ", "
181  << mcd1->eta() << ", mass = " << mcm << endl;
182  }
183  }
184  }
185  // to avoid double counting
186  if ((selectZ == 3) && (selectMC == 3))
187  break;
188  }
189  }
190 }
191 
193  double effZToMuMu = double(selZToMuMu_) / double(nZToMuMu_);
194  double errZToMuMu = sqrt(effZToMuMu * (1. - effZToMuMu) / nZToMuMu_);
195  double effZToMuMuMC = double(selZToMuMuMC_) / double(nZToMuMuMC_);
196  double errZToMuMuMC = sqrt(effZToMuMuMC * (1. - effZToMuMuMC) / nZToMuMuMC_);
197  double effZToMuMuMCDen = double(selZToMuMuMC_) / double(nZToMuMuMCDen_);
198  double errZToMuMuMCDen = sqrt(effZToMuMuMCDen * (1. - effZToMuMuMCDen) / nZToMuMuMCDen_);
199  double effZToMuMuMCMatched = double(selZToMuMuMCMatched_) / double(nZToMuMuMCMatched_);
200  double errZToMuMuMCMatched = sqrt(effZToMuMuMCMatched * (1. - effZToMuMuMCMatched) / nZToMuMuMCMatched_);
201  cout << ">>> " << zToMuMu_ << ": " << selZToMuMu_ << "/" << nZToMuMu_ << " = " << effZToMuMu << " +/- " << errZToMuMu
202  << endl;
203  cout << ">>> " << zToMuMuMC_ << " - matched: " << selZToMuMuMCMatched_ << "/" << nZToMuMuMCMatched_ << " = "
204  << effZToMuMuMCMatched << " +/- " << errZToMuMuMCMatched << endl;
205  cout << " if the two numbers above are the same we can neglete resolution effect and quote the acceptance as the "
206  "number below.... "
207  << endl;
208  cout << "********* acceptance m>sampleMCMassCut (usually 20 or 40) ******** " << endl;
209  cout << ">>> " << zToMuMuMC_ << ": " << selZToMuMuMC_ << "/" << nZToMuMuMC_ << " = " << effZToMuMuMC << " +/- "
210  << errZToMuMuMC << endl;
211  cout << "********* acceptance in the given mass range ******** " << endl;
212  cout << ">>> " << zToMuMuMC_ << ": " << selZToMuMuMC_ << "/" << nZToMuMuMCDen_ << " = " << effZToMuMuMCDen << " +/- "
213  << errZToMuMuMCDen << endl;
214 }
215 
217 
Handle.h
MCAcceptanceAnalyzer::analyze
void analyze(const Event &, const EventSetup &) override
Definition: MCAcceptanceAnalyzer.cc:127
mps_fire.i
i
Definition: mps_fire.py:428
MCAcceptanceAnalyzer::selZToMuMuMC_
long selZToMuMuMC_
Definition: MCAcceptanceAnalyzer.cc:90
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::View::refAt
RefToBase< value_type > refAt(size_type i) const
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
edm::EDGetTokenT< CandidateView >
edm
HLT enums.
Definition: AlignableModifier.h:19
MCAcceptanceAnalyzer::zToMuMu_
InputTag zToMuMu_
Definition: MCAcceptanceAnalyzer.cc:86
MCAcceptanceAnalyzer::zToMuMuMCToken_
EDGetTokenT< CandidateView > zToMuMuMCToken_
Definition: MCAcceptanceAnalyzer.cc:88
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ZSelector
Definition: MCAcceptanceAnalyzer.cc:24
ptMin
constexpr float ptMin
Definition: PhotonIDValueMapProducer.cc:155
reco::Candidate::pt
virtual double pt() const =0
transverse momentum
ZSelector::operator()
int operator()(const Candidate &c) const
Definition: MCAcceptanceAnalyzer.cc:43
ZMuMuCategoriesSequences_cff.massMin
massMin
Definition: ZMuMuCategoriesSequences_cff.py:136
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
MCAcceptanceAnalyzer::nZToMuMu_
long nZToMuMu_
Definition: MCAcceptanceAnalyzer.cc:90
edm::Handle
Definition: AssociativeIterator.h:50
MCAcceptanceAnalyzer
Definition: MCAcceptanceAnalyzer.cc:79
edm::Ref< GenParticleCollection >
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
GenParticle.h
MCAcceptanceAnalyzer::selZToMuMu_
long selZToMuMu_
Definition: MCAcceptanceAnalyzer.cc:90
MCAcceptanceAnalyzer::endJob
void endJob() override
Definition: MCAcceptanceAnalyzer.cc:192
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MCAcceptanceAnalyzer::nZToMuMuMC_
long nZToMuMuMC_
Definition: MCAcceptanceAnalyzer.cc:90
mcMuDaughter
const Candidate * mcMuDaughter(const Candidate *c)
Definition: MCAcceptanceAnalyzer.cc:14
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
MCAcceptanceAnalyzer::nZToMuMuMCMatched_
long nZToMuMuMCMatched_
Definition: MCAcceptanceAnalyzer.cc:90
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
ZSelector::ZSelector
ZSelector(double ptMin, double etaDau0Min, double etaDau0Max, double etaDau1Min, double etaDau1Max, double massMin, double massMax, double massMinZMC, double massMaxZMC)
Definition: MCAcceptanceAnalyzer.cc:25
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
MCAcceptanceAnalyzer::zToMuMuMatchedToken_
EDGetTokenT< GenParticleMatch > zToMuMuMatchedToken_
Definition: MCAcceptanceAnalyzer.cc:89
edm::View::size
size_type size() const
edm::View
Definition: CaloClusterFwd.h:14
MCAcceptanceAnalyzer::selZToMuMuMCMatched_
long selZToMuMuMCMatched_
Definition: MCAcceptanceAnalyzer.cc:90
MCAcceptanceAnalyzer::select_
ZSelector select_
Definition: MCAcceptanceAnalyzer.cc:91
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
MCAcceptanceAnalyzer::nZToMuMuMCDen_
long nZToMuMuMCDen_
Definition: MCAcceptanceAnalyzer.cc:90
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:57
MCAcceptanceAnalyzer::zToMuMuToken_
EDGetTokenT< CandidateView > zToMuMuToken_
Definition: MCAcceptanceAnalyzer.cc:87
ZMuMuCategoriesSequences_cff.massMax
massMax
Definition: ZMuMuCategoriesSequences_cff.py:137
edm::Association::size
size_t size() const
Definition: Association.h:64
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
reco::Candidate
Definition: Candidate.h:27
ZSelector::ptMin_
double ptMin_
Definition: MCAcceptanceAnalyzer.cc:76
std
Definition: JetResolutionObject.h:76
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
edm::RefToBase< Candidate >
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
ztail.d
d
Definition: ztail.py:151
Candidate.h
ParameterSet.h
MCAcceptanceAnalyzer::zToMuMuMC_
InputTag zToMuMuMC_
Definition: MCAcceptanceAnalyzer.cc:86
edm::Event
Definition: Event.h:73
d0
static constexpr float d0
Definition: L1EGammaCrystalsEmulatorProducer.cc:84
MCAcceptanceAnalyzer::select_OnlyMassCut_
ZSelector select_OnlyMassCut_
Definition: MCAcceptanceAnalyzer.cc:91
edm::InputTag
Definition: InputTag.h:15
d1
static constexpr float d1
Definition: L1EGammaCrystalsEmulatorProducer.cc:84
MCAcceptanceAnalyzer::MCAcceptanceAnalyzer
MCAcceptanceAnalyzer(const ParameterSet &cfg)
Definition: MCAcceptanceAnalyzer.cc:94