CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
14 const Candidate * mcMuDaughter(const Candidate * c) {
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) return d;
19  }
20  return 0;
21 }
22 
23 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)
24  ZSelector(double ptMin, double etaDau0Min, double etaDau0Max,double etaDau1Min, double etaDau1Max, double massMin, double massMax, double massMinZMC, double massMaxZMC) :
25  ptMin_(ptMin), etaDau0Min_(etaDau0Min),etaDau0Max_(etaDau0Max), etaDau1Min_(etaDau1Min),etaDau1Max_(etaDau1Max),
26  massMin_(massMin), massMax_(massMax), massMinZMC_(massMinZMC), massMaxZMC_(massMaxZMC) { }
27  int operator()(const Candidate& c) const {
28  // std::cout << "c.numberOfDaughters(): " << c.numberOfDaughters()<< std::endl;
29  if (c.numberOfDaughters()<2) return 0;
30  if (c.numberOfDaughters()>=6) return 0;
31  const Candidate * d0 = c.daughter(0);
32  const Candidate * d1 = c.daughter(1);
33  if(c.numberOfDaughters()>2) {
34  if (d0->numberOfDaughters()>0) d0 = mcMuDaughter(d0);
35  if (d1->numberOfDaughters()>0) d1 = mcMuDaughter(d1);
36  }
37  int temp_cut= 0;
39  if( ( fabs(d0->eta()) > etaDau0Min_ && fabs(d1->eta())>etaDau1Min_ && fabs(d0->eta()) < etaDau0Max_ && fabs(d1->eta()) <etaDau1Max_ ) || ( fabs(d0->eta()) > etaDau1Min_ && fabs(d1->eta())>etaDau0Min_ && fabs(d0->eta()) < etaDau1Max_ && fabs(d1->eta()) <etaDau0Max_ ) ) {
40  temp_cut=1;
41  if(d0->pt() > ptMin_ && d1->pt() > ptMin_) {
42  temp_cut=2;
43  double m = (d0->p4() + d1->p4()).mass();
44  if(m > massMin_ && m < massMax_) temp_cut=3;
45  if (c.mass()> massMinZMC_ && c.mass() < massMaxZMC_) temp_cut =4;
46  }
47  }
48 
49  return temp_cut;
50  }
51  double ptMin_, etaDau0Min_, etaDau0Max_, etaDau1Min_, etaDau1Max_, massMin_, massMax_, massMinZMC_, massMaxZMC_;
52 };
53 
55 public:
57 private:
58  void analyze(const Event&, const EventSetup&);
59  void endJob();
60  InputTag zToMuMu_, zToMuMuMC_, zToMuMuMatched_;
61  long nZToMuMu_, selZToMuMu_, nZToMuMuMC_, selZToMuMuMC_, nZToMuMuMCMatched_, selZToMuMuMCMatched_, nZToMuMuMCDen_;
63 };
64 
66  zToMuMu_(cfg.getParameter<InputTag>("zToMuMu")),
67  zToMuMuMC_(cfg.getParameter<InputTag>("zToMuMuMC")),
68  zToMuMuMatched_(cfg.getParameter<InputTag>("zToMuMuMatched")),
69  nZToMuMu_(0), selZToMuMu_(0),
70  nZToMuMuMC_(0), selZToMuMuMC_(0),
71  nZToMuMuMCMatched_(0), selZToMuMuMCMatched_(0), nZToMuMuMCDen_(0),
72  select_(cfg.getParameter<double>("ptMin"), cfg.getParameter<double>("etaDau0Min"), cfg.getParameter<double>("etaDau0Max"), cfg.getParameter<double>("etaDau1Min"), cfg.getParameter<double>("etaDau1Max"),cfg.getParameter<double>("massMin"), cfg.getParameter<double>("massMax"), cfg.getParameter<double>("massMinZMC"), cfg.getParameter<double>("massMaxZMC") ),
73  select_OnlyMassCut_(-1, -9999,9999 , -9999, 9999,0, 0, cfg.getParameter<double>("massMinZMC"), cfg.getParameter<double>("massMaxZMC") )
74 {
75 }
76 
78  Handle<CandidateView> zToMuMu;
79  evt.getByLabel(zToMuMu_, zToMuMu);
80  Handle<CandidateView> zToMuMuMC;
81  evt.getByLabel(zToMuMuMC_, zToMuMuMC);
82  Handle<GenParticleMatch > zToMuMuMatched;
83  evt.getByLabel(zToMuMuMatched_, zToMuMuMatched);
84  // long nZToMuMu = zToMuMu->size();
85  long nZToMuMuMC = zToMuMuMC->size();
86  long nZToMuMuMatched = zToMuMuMatched->size();
87 
88 
89  // cout << ">>> " << zToMuMu_ << " has " << nZToMuMu << " entries" << endl;
90  //cout << ">>> " << zToMuMuMC_ << " has " << nZToMuMuMC << " entries" << endl;
91  //cout << ">>> " << zToMuMuMatched_ << " has " << nZToMuMuMatched << " entries" << endl;
92 
93 
94 
95  nZToMuMuMC_ += nZToMuMuMC;
96  for(long i = 0; i < nZToMuMuMC; ++i) {
97  const Candidate & z = (*zToMuMuMC)[i];
98  if(select_(z)==4) ++selZToMuMuMC_;
100 
101  }
102 
103 
104  for(long i = 0; i < nZToMuMuMatched; ++i) {
105 
106  const Candidate & z = (*zToMuMu)[i];
107  CandidateBaseRef zRef = zToMuMu->refAt(i);
108  GenParticleRef mcRef = (*zToMuMuMatched)[zRef];
109 
110 
111  if(mcRef.isNonnull()) { // z candidate matched to Z MC
112  ++nZToMuMu_;
114 
115  int selectZ = select_(z);
116  if(selectZ==4) ++selZToMuMu_;
117 
118 
119 
120  int selectMC = select_(*mcRef);
121 
122  if(selectMC==4) ++selZToMuMuMCMatched_;
123 
124  if(selectZ != selectMC) {
125  cout << ">>> select reco: " << selectZ << ", select mc: " << selectMC << endl;
126  if ((selectZ * selectMC) ==0 ) break;
127  if (z.numberOfDaughters()> 1){
128  const Candidate * d0 = z.daughter(0), * d1 = z.daughter(1);
129  if (mcRef->numberOfDaughters()>1){
130  const Candidate * mcd0 = mcMuDaughter(mcRef->daughter(0)),
131  * mcd1 = mcMuDaughter(mcRef->daughter(1));
132  double m = z.mass(), mcm = (mcd0->p4()+mcd1->p4()).mass();
133  cout << ">>> reco pt1, eta1: " << d0->pt() <<", " << d0->eta()
134  << ", 2: " << d1->pt() << ", " << d1->eta()
135  << ", mass = " << m << endl;
136  cout << ">>> mc pt1, eta1: " << mcd0->pt() <<", " << mcd0->eta()
137  << ", 2: " << mcd1->pt() << ", " << mcd1->eta()
138  << ", mass = " << mcm << endl;
139  }
140  }
141 
142  }
143  // to avoid double counting
144  if ((selectZ==3) && (selectMC==3)) break;
145  }
146  }
147 
148 }
149 
151  double effZToMuMu = double(selZToMuMu_)/double(nZToMuMu_);
152  double errZToMuMu = sqrt(effZToMuMu*(1. - effZToMuMu)/nZToMuMu_);
153  double effZToMuMuMC = double(selZToMuMuMC_)/double(nZToMuMuMC_);
154  double errZToMuMuMC = sqrt(effZToMuMuMC*(1. - effZToMuMuMC)/nZToMuMuMC_);
155  double effZToMuMuMCDen = double(selZToMuMuMC_)/double(nZToMuMuMCDen_);
156  double errZToMuMuMCDen = sqrt(effZToMuMuMCDen*(1. - effZToMuMuMCDen)/nZToMuMuMCDen_);
157  double effZToMuMuMCMatched = double(selZToMuMuMCMatched_)/double(nZToMuMuMCMatched_);
158  double errZToMuMuMCMatched = sqrt(effZToMuMuMCMatched*(1. - effZToMuMuMCMatched)/nZToMuMuMCMatched_);
159  cout << ">>> " << zToMuMu_ << ": " << selZToMuMu_ << "/" << nZToMuMu_
160  << " = " << effZToMuMu << " +/- " << errZToMuMu << endl;
161  cout << ">>> " << zToMuMuMC_ << " - matched: " << selZToMuMuMCMatched_ << "/" << nZToMuMuMCMatched_
162  << " = " << effZToMuMuMCMatched << " +/- " << errZToMuMuMCMatched << endl;
163  cout << " if the two numbers above are the same we can neglete resolution effect and quote the acceptance as the number below.... " << endl;
164  cout << "********* acceptance m>sampleMCMassCut (usually 20 or 40) ******** " << endl;
165  cout << ">>> " << zToMuMuMC_ << ": " << selZToMuMuMC_ << "/" << nZToMuMuMC_
166  << " = " << effZToMuMuMC << " +/- " << errZToMuMuMC << endl;
167  cout << "********* acceptance in the given mass range ******** " << endl;
168  cout << ">>> " << zToMuMuMC_ << ": " << selZToMuMuMC_ << "/" << nZToMuMuMCDen_
169  << " = " << effZToMuMuMCDen << " +/- " << errZToMuMuMCDen << endl;
170 
171 }
172 
174 
176 
void analyze(const Event &, const EventSetup &)
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) ...
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual double mass() const =0
mass
double double double z
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
virtual size_type numberOfDaughters() const =0
number of daughters
T sqrt(T t)
Definition: SSEVec.h:46
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const Candidate * mcMuDaughter(const Candidate *c)
virtual int pdgId() const =0
PDG identifier.
int operator()(const Candidate &c) const
tuple mass
Definition: scaleCards.py:27
tuple cout
Definition: gather_cfg.py:121
MCAcceptanceAnalyzer(const ParameterSet &cfg)
virtual double eta() const =0
momentum pseudorapidity
ZSelector(double ptMin, double etaDau0Min, double etaDau0Max, double etaDau1Min, double etaDau1Max, double massMin, double massMax, double massMinZMC, double massMaxZMC)
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector