CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MC_Efficiency_Analyzer.cc
Go to the documentation of this file.
1 /* \class MCEfficiencyAnalyzer
2  *
3  * Muon reconstruction efficiency from MC truth,
4  * for global muons, tracks and standalone. Take as input the output of the
5  * standard EWK skim: zToMuMu
6  *
7  * Produces in output the efficency number
8  *
9  * \author Michele de Gruttola, INFN Naples
10 */
11 
23 #include <iostream>
24 #include <iterator>
25 using namespace edm;
26 using namespace std;
27 using namespace reco;
28 
30 {
31 public:
33  zMuMu_( pset.getParameter<InputTag>( "zMuMu" ) ),
34  Muons_( pset.getParameter<InputTag>( "Muons" ) ),
35  MuonsMap_( pset.getParameter<InputTag>( "MuonsMap" ) ),
36  Tracks_( pset.getParameter<InputTag>( "Tracks" ) ),
37  TracksMap_( pset.getParameter<InputTag>( "TracksMap" ) ),
38  genParticles_( pset.getParameter<InputTag>( "genParticles" ) ),
39  StandAlone_( pset.getParameter<InputTag>( "StandAlone" ) ),
40  StandAloneMap_( pset.getParameter<InputTag>( "StandAloneMap" ) ),
41  etacut_( pset.getParameter<double>( "etacut" ) ),
42  ptcut_( pset.getParameter<double>( "ptcut" ) ),
43  deltaRStacut_( pset.getParameter<double>( "deltaRStacut" ) )
44 
45  {
46  nMuMC =0; nMureco =0; nTrk=0; nSta=0; nNotMuMatching =0 ;
47  }
48 
49  virtual void analyze(const edm::Event& event, const edm::EventSetup& setup)
50  {
51 
53  event.getByLabel(zMuMu_, zMuMu);
54 
55 
57  event.getByLabel(Muons_, Muons);
58 
60  event.getByLabel(Tracks_, Tracks);
61 
62  Handle<CandidateCollection> StandAlone;
63  event.getByLabel(StandAlone_, StandAlone);
64 
65  Handle<CandMatchMap> MuonsMap;
66  event.getByLabel(MuonsMap_, MuonsMap);
67 
68  Handle<CandMatchMap> TracksMap;
69  event.getByLabel(TracksMap_, TracksMap);
70 
71  Handle<CandMatchMap> StandAloneMap;
72  event.getByLabel(StandAloneMap_, StandAloneMap);
73 
75  event.getByLabel(genParticles_, genParticles);
76 
77  //Getting muons from Z MC
78  for( unsigned int k = 0; k < genParticles->size(); k++ )
79  {
80  const Candidate & ZCand = (*genParticles)[ k ];
81  int status = ZCand.status();
82 
83  if (ZCand.pdgId()==23&& status==3 )
84  {
85  // positive muons
86  const Candidate * muCand1 = ZCand.daughter(0);
87  if (muCand1->status()==3)
88  {
89  for (unsigned int d =0 ; d< muCand1->numberOfDaughters(); d++)
90  {
91  const Candidate * muCandidate = muCand1->daughter(d);
92  if (muCandidate->pdgId() == muCand1->pdgId() )
93  {
94  muCand1 = muCand1->daughter(d);
95  }
96  }
97  }
98  // negative muons
99  const Candidate * muCand2 = ZCand.daughter(1);
100  if (muCand2->status()==3)
101  {
102  for (unsigned int e =0 ; e< muCand2->numberOfDaughters(); e++)
103  {
104  const Candidate * muCandidate = muCand2->daughter(e);
105  if (muCandidate->pdgId() == muCand2->pdgId() )
106  {
107  muCand2 = muCand2->daughter(e);
108  }
109  }
110  }
111 
112  double deltaR_Mu_Sta =0;
113  int nMurecoTemp = nMureco;
114  // getting mu matched
116  for(i = MuonsMap->begin(); i != MuonsMap->end(); i++ )
117  {
118  const Candidate/* & reco = * i -> key,*/ & mc = * i -> val;
119  if ((muCand1 == &mc) && (mc.pt()>ptcut_) && (abs(mc.eta()<etacut_)))
120  {
121  nMuMC++;
122  nMureco++;
123  break;
124  }
125  }
126  if (nMureco == nMurecoTemp ) // I.E. MU RECO NOT FOUND!!!!
127  {
128  int nTrkTemp = nTrk;
129  int nStaTemp = nSta;
130 
131  // getting tracks matched and doing the same, CONTROLLING IF MU IS RECONSTRUCTED AS A TRACK AND NOT AS A MU
133  for(l = TracksMap->begin(); l != TracksMap->end(); l++ )
134  {
135  const Candidate /* & Trkreco = * l -> key, */ & Trkmc = * l -> val;
136  if (( muCand1 == & Trkmc) && (Trkmc.pt()>ptcut_) && (abs(Trkmc.eta()<etacut_)))
137  {
138  nMuMC++;
139  nTrk++;
140  break;
141  }
142  }
143  // the same for standalone
145  for(n = StandAloneMap->begin(); n != StandAloneMap->end(); n++ )
146  {
147  const Candidate & Stareco = * n -> key, & Stamc = * n -> val;
148  if ((muCand1 == &Stamc ) && (Stamc.pt()>ptcut_) && (abs(Stamc.eta()<etacut_)))
149  {
150  nMuMC++;
151  nSta++;
152  deltaR_Mu_Sta = deltaR(Stareco, *muCand1);
153 
154  // cout<<"Ho trovato un sta reco "<<endl;
155  break;
156  }
157  }
158  // controlling if sta and trk are reconstrucetd both, and if so the get the deltaR beetween muon MC and reco sta, to controll correlation to this happening
159  if ((nSta == nStaTemp + 1) && (nTrk == nTrkTemp + 1 ) )
160  {
161  nNotMuMatching ++;
162  if ((deltaR_Mu_Sta< deltaRStacut_))
163  {
164  v_.push_back(deltaR_Mu_Sta) ;
165  cout << "Not matching from trk and sta matched to MC mu, to reconstruct a recoMU" << endl;
166  }
167  }
168  }
169  }
170  }
171  }
172 
173 
174  virtual void endJob()
175  {
176 
177 
178  cout <<"--- nMuMC == "<<nMuMC<<endl;
179  cout <<"--- nMureco == "<<nMureco<<endl;
180  cout <<"--- nSta == "<<nSta<<endl;
181  cout <<"--- nTrk == "<<nTrk<<endl;
182  cout <<"--- nNotMuMatching from a trk and sta matched to a Mu MC == "<<nNotMuMatching<<endl;
183  if (nMuMC!=0 )
184  {
185  cout<<" effMu == "<<(double) nMureco/nMuMC<<endl;
186  cout<<" effTrk == "<< (double)(nTrk + nMureco) /nMuMC<<endl;
187  cout<<" effSta == "<< (double)(nSta + nMureco) / nMuMC<<endl;
188  }
189 
190 vector< int >::const_iterator p2;
191  for (unsigned int i =0 ; i < v_.size(); ++i )
192  {
193  cout<<" delta R Mu Sta == "<< v_[i]<<endl;
194  }
195  }
196 
197 
198 
199 
200 
201 private:
202 
203  InputTag zMuMu_, Muons_, MuonsMap_, Tracks_, TracksMap_, genParticles_, StandAlone_,StandAloneMap_;
204  double etacut_, ptcut_, deltaRStacut_;
205  int nMuMC, nMureco, nTrk, nSta, nNotMuMatching;
206  vector<double> v_;
207 };
208 
209 
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
MCEfficiencyAnalyzer(const edm::ParameterSet &pset)
virtual int status() const =0
status word
#define abs(x)
Definition: mlp_lapack.h:159
virtual size_type numberOfDaughters() const =0
number of daughters
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 void analyze(const edm::Event &event, const edm::EventSetup &setup)
double p2[4]
Definition: TauolaWrapper.h:90
int k[5][pyjets_maxn]
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
virtual int pdgId() const =0
PDG identifier.
list key
Definition: combine.py:13
tuple cout
Definition: gather_cfg.py:121
tuple status
Definition: ntuplemaker.py:245
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple zMuMu
zMuMu vector of PSet is common to all categories except zMuTrk category
virtual double eta() const =0
momentum pseudorapidity