CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFTauElecRejectionBenchmark.cc
Go to the documentation of this file.
2 
3 // preprocessor macro for booking 1d histos with DQMStore -or- bare Root
4 #define BOOK1D(name,title,nbinsx,lowx,highx) \
5  h##name = db_ ? db_->book1D(#name,title,nbinsx,lowx,highx)->getTH1F() \
6  : new TH1F(#name,title,nbinsx,lowx,highx)
7 
8 // preprocessor macro for booking 2d histos with DQMStore -or- bare Root
9 #define BOOK2D(name,title,nbinsx,lowx,highx,nbinsy,lowy,highy) \
10  h##name = db_ ? db_->book2D(#name,title,nbinsx,lowx,highx,nbinsy,lowy,highy)->getTH2F() \
11  : new TH2F(#name,title,nbinsx,lowx,highx,nbinsy,lowy,highy)
12 
13 // all versions OK
14 // preprocesor macro for setting axis titles
15 #define SETAXES(name,xtitle,ytitle) \
16  h##name->GetXaxis()->SetTitle(xtitle); h##name->GetYaxis()->SetTitle(ytitle)
17 
18 
19 using namespace reco;
20 using namespace std;
21 
22 class MonitorElement;
23 
25 
27  if(file_) file_->Close();
28 }
29 
31  // Store the DAQ Histograms
32  if (outputFile_.size() != 0) {
33  if (db_)
34  db_->save(outputFile_.c_str());
35  // use bare Root if no DQM (FWLite applications)
36  else if (file_) {
37  file_->Write(outputFile_.c_str());
38  cout << "Benchmark output written to file " << outputFile_.c_str() << endl;
39  file_->Close();
40  }
41  }
42  else
43  cout << "No output file specified ("<<outputFile_<<"). Results will not be saved!" << endl;
44 
45 }
46 
48  string Filename,
49  string benchmarkLabel,
50  double maxDeltaR,
51  double minRecoPt,
52  double maxRecoAbsEta,
53  double minMCPt,
54  double maxMCAbsEta,
55  string sGenMatchObjectLabel,
56  bool applyEcalCrackCut,
57  DQMStore * db_store) {
58  maxDeltaR_ = maxDeltaR;
59  benchmarkLabel_ = benchmarkLabel;
60  outputFile_=Filename;
61  minRecoPt_ = minRecoPt;
62  maxRecoAbsEta_= maxRecoAbsEta;
63  minMCPt_ = minMCPt;
64  maxMCAbsEta_= maxMCAbsEta;
65  sGenMatchObjectLabel_ = sGenMatchObjectLabel;
66  applyEcalCrackCut_= applyEcalCrackCut;
67 
68  file_ = NULL;
69  db_ = db_store;
70 
71  // print parameters
72  cout<< "PFTauElecRejectionBenchmark Setup parameters =============================================="<<endl;
73  cout << "Filename to write histograms " << Filename<<endl;
74  cout << "Benchmark label name " << benchmarkLabel_<<endl;
75  cout << "maxDeltaRMax " << maxDeltaR << endl;
76  cout << "minRecoPt " << minRecoPt_ << endl;
77  cout << "maxRecoAbsEta " << maxRecoAbsEta_ << endl;
78  cout << "minMCPt " << minMCPt_ << endl;
79  cout << "maxMCAbsEta " << maxMCAbsEta_ << endl;
80  cout << "applyEcalCrackCut " << applyEcalCrackCut_ << endl;
81  cout << "sGenMatchObjectLabel " << sGenMatchObjectLabel_ << endl;
82 
83  // Book histogram
84 
85  // Establish DQM Store
86  string path = "PFTask/Benchmarks/"+ benchmarkLabel_ + "/";
87  path += "Gen";
88  if (db_) {
89  db_->setCurrentFolder(path.c_str());
90  }
91  else {
92  file_ = new TFile(outputFile_.c_str(), "recreate");
93  cout << "Info: DQM is not available to provide data storage service. Using TFile to save histograms. "<<endl;
94  }
95 
96  // E/p
97  BOOK1D(EoverP,"E/p",100, 0., 4.);
98  SETAXES(EoverP, "E/p", "Entries");
99 
100  BOOK1D(EoverP_barrel,"E/p barrel",100, 0., 4.);
101  SETAXES(EoverP_barrel, "E/p barrel", "Entries");
102 
103  BOOK1D(EoverP_endcap,"E/p endcap",100, 0., 4.);
104  SETAXES(EoverP_endcap, "E/p endcap", "Entries");
105 
106  BOOK1D(EoverP_preid0,"E/p (preid=0)",100, 0., 4.);
107  SETAXES(EoverP_preid0, "E/p", "Entries");
108 
109  BOOK1D(EoverP_preid1,"E/p (preid=1)",100, 0., 4.);
110  SETAXES(EoverP_preid1, "E/p", "Entries");
111 
112  // H/p
113  BOOK1D(HoverP,"H/p",100, 0., 2.);
114  SETAXES(HoverP, "H/p", "Entries");
115 
116  BOOK1D(HoverP_barrel,"H/p barrel",100, 0., 2.);
117  SETAXES(HoverP_barrel, "H/p barrel", "Entries");
118 
119  BOOK1D(HoverP_endcap,"H/p endcap",100, 0., 2.);
120  SETAXES(HoverP_endcap, "H/p endcap", "Entries");
121 
122  BOOK1D(HoverP_preid0,"H/p (preid=0)",100, 0., 2.);
123  SETAXES(HoverP_preid0, "H/p", "Entries");
124 
125  BOOK1D(HoverP_preid1,"H/p (preid=1)",100, 0., 2.);
126  SETAXES(HoverP_preid1, "H/p", "Entries");
127 
128  // emfrac
129  BOOK1D(Emfrac,"EM fraction",100, 0., 1.01);
130  SETAXES(Emfrac, "em fraction", "Entries");
131 
132  BOOK1D(Emfrac_barrel,"EM fraction barrel",100, 0., 1.01);
133  SETAXES(Emfrac_barrel, "em fraction barrel", "Entries");
134 
135  BOOK1D(Emfrac_endcap,"EM fraction endcap",100, 0., 1.01);
136  SETAXES(Emfrac_endcap, "em fraction endcap", "Entries");
137 
138  BOOK1D(Emfrac_preid0,"EM fraction (preid=0)",100, 0., 1.01);
139  SETAXES(Emfrac_preid0, "em fraction", "Entries");
140 
141  BOOK1D(Emfrac_preid1,"EM fraction (preid=1)",100, 0., 1.01);
142  SETAXES(Emfrac_preid1, "em fraction", "Entries");
143 
144  // PreID
145  BOOK1D(ElecPreID,"PFElectron PreID decision",6, 0., 1.01);
146  SETAXES(ElecPreID, "PFElectron PreID decision", "Entries");
147 
148  // MVA
149  BOOK1D(ElecMVA,"PFElectron MVA",100, -1.01, 1.01);
150  SETAXES(ElecMVA, "PFElectron MVA", "Entries");
151 
152  // Discriminant
153  BOOK1D(TauElecDiscriminant,"PFTau-Electron Discriminant",6, 0., 1.01);
154  SETAXES(TauElecDiscriminant, "PFTau-Electron Discriminant", "Entries");
155 
156 
157  // PFCand clusters
158  BOOK1D(pfcand_deltaEta,"PFCand cluster dEta",100, 0., 0.8);
159  SETAXES(pfcand_deltaEta, "PFCand cluster #Delta(#eta)", "Entries");
160 
161  BOOK1D(pfcand_deltaEta_weightE,"PFCand cluster dEta, energy weighted",100, 0., 0.8);
162  SETAXES(pfcand_deltaEta_weightE, "PFCand cluster #Delta(#eta)", "Entries");
163 
164  BOOK1D(pfcand_deltaPhiOverQ,"PFCand cluster dPhi/q",100, -0.8, 0.8);
165  SETAXES(pfcand_deltaPhiOverQ, "PFCand cluster #Delta(#phi)/q", "Entries");
166 
167  BOOK1D(pfcand_deltaPhiOverQ_weightE,"PFCand cluster dEta/q, energy weighted",100, -0.8, 0.8);
168  SETAXES(pfcand_deltaPhiOverQ_weightE, "PFCand cluster #Delta(#phi)/q", "Entries");
169 
170 
171  // Leading KF track
172  BOOK1D(leadTk_pt,"leading KF track pt",100, 0., 80.);
173  SETAXES(leadTk_pt, "leading KF track p_{T} (GeV)", "Entries");
174 
175  BOOK1D(leadTk_eta,"leading KF track eta",100, -4., 4.);
176  SETAXES(leadTk_eta, "leading KF track #eta", "Entries");
177 
178  BOOK1D(leadTk_phi,"leading KF track phi",100, -3.2, 3.2);
179  SETAXES(leadTk_phi, "leading KF track #phi", "Entries");
180 
181  // Leading Gsf track
182  BOOK1D(leadGsfTk_pt,"leading Gsf track pt",100, 0., 80.);
183  SETAXES(leadGsfTk_pt, "leading Gsf track p_{T} (GeV)", "Entries");
184 
185  BOOK1D(leadGsfTk_eta,"leading Gsf track eta",100, -4., 4.);
186  SETAXES(leadGsfTk_eta, "leading Gsf track #eta", "Entries");
187 
188  BOOK1D(leadGsfTk_phi,"leading Gsf track phi",100, -3.2, 3.2);
189  SETAXES(leadGsfTk_phi, "leading Gsf track #phi", "Entries");
190 
191 
192  // H/p vs E/p
193  BOOK2D(HoPvsEoP,"H/p vs. E/p",100, 0., 2., 100, 0., 2.);
194  SETAXES(HoPvsEoP, "E/p", "H/p");
195 
196  BOOK2D(HoPvsEoP_preid0,"H/p vs. E/p (preid=0)",100, 0., 2., 100, 0., 2.);
197  SETAXES(HoPvsEoP_preid0, "E/p", "H/p");
198 
199  BOOK2D(HoPvsEoP_preid1,"H/p vs. E/p (preid=0)",100, 0., 2., 100, 0., 2.);
200  SETAXES(HoPvsEoP_preid1, "E/p", "H/p");
201 
202  // em fraction vs E/p
203  BOOK2D(EmfracvsEoP,"emfrac vs. E/p",100, 0., 2., 100, 0., 1.01);
204  SETAXES(EmfracvsEoP, "E/p", "em fraction");
205 
206  BOOK2D(EmfracvsEoP_preid0,"emfrac vs. E/p (preid=0)",100, 0., 2., 100, 0., 1.01);
207  SETAXES(EmfracvsEoP_preid0, "E/p", "em fraction");
208 
209  BOOK2D(EmfracvsEoP_preid1,"emfrac vs. E/p (preid=0)",100, 0., 2., 100, 0., 1.01);
210  SETAXES(EmfracvsEoP_preid1, "E/p", "em fraction");
211 
212 
213 }
214 
215 
218  edm::Handle<reco::PFTauDiscriminator> pfTauElecDiscr) {
219 
220 
221  // Find Gen Objects to be matched with
222  HepMC::GenEvent * generated_event = new HepMC::GenEvent(*(mcevt->GetEvent()));
223  _GenObjects.clear();
224 
225  TLorentzVector taunet;
226  HepMC::GenEvent::particle_iterator p;
227  for (p = generated_event->particles_begin(); p != generated_event->particles_end(); p++) {
228  if(std::abs((*p)->pdg_id()) == 15&&(*p)->status()==2) {
229  bool lept_decay = false;
230  TLorentzVector tau((*p)->momentum().px(),(*p)->momentum().py(),(*p)->momentum().pz(),(*p)->momentum().e());
231  HepMC::GenVertex::particle_iterator z = (*p)->end_vertex()->particles_begin(HepMC::descendants);
232  for(; z != (*p)->end_vertex()->particles_end(HepMC::descendants); z++) {
233  if(std::abs((*z)->pdg_id()) == 11 || std::abs((*z)->pdg_id()) == 13) lept_decay=true;
234  if(std::abs((*z)->pdg_id()) == 16)
235  taunet.SetPxPyPzE((*z)->momentum().px(),(*z)->momentum().py(),(*z)->momentum().pz(),(*z)->momentum().e());
236 
237  }
238  if(lept_decay==false) {
239  TLorentzVector jetMom=tau-taunet;
240  if (sGenMatchObjectLabel_=="tau") _GenObjects.push_back(jetMom);
241  }
242  } else if(std::abs((*p)->pdg_id()) == 11&&(*p)->status()==1) {
243  TLorentzVector elec((*p)->momentum().px(),(*p)->momentum().py(),(*p)->momentum().pz(),(*p)->momentum().e());
244  if (sGenMatchObjectLabel_=="e") _GenObjects.push_back(elec);
245  }
246  }
247 
249 
250 
251  // Loop over all PFTaus
252  math::XYZPointF myleadTkEcalPos;
253  for (PFTauCollection::size_type iPFTau=0;iPFTau<pfTaus->size();iPFTau++) {
254  PFTauRef thePFTau(pfTaus,iPFTau);
255  if ((*pfTauIsoDiscr)[thePFTau] == 1) {
256  if ((*thePFTau).et() > minRecoPt_ && std::abs((*thePFTau).eta()) < maxRecoAbsEta_) {
257 
258  // Check if track goes to Ecal crack
259  TrackRef myleadTk;
260  if(thePFTau->leadPFChargedHadrCand().isNonnull()){
261  myleadTk=thePFTau->leadPFChargedHadrCand()->trackRef();
262  myleadTkEcalPos = thePFTau->leadPFChargedHadrCand()->positionAtECALEntrance();
263 
264  if(myleadTk.isNonnull()){
265  if (applyEcalCrackCut_ && isInEcalCrack(std::abs((double)myleadTkEcalPos.eta()))) {
266  continue; // do nothing
267  } else {
268 
269  // Match with gen object
270  for (unsigned int i = 0; i<_GenObjects.size();i++) {
271  if (_GenObjects[i].Et() >= minMCPt_ && std::abs(_GenObjects[i].Eta()) < maxMCAbsEta_ ) {
272  TLorentzVector pftau((*thePFTau).px(),(*thePFTau).py(),(*thePFTau).pz(),(*thePFTau).energy());
273  double GenDeltaR = pftau.DeltaR(_GenObjects[i]);
274  if (GenDeltaR<maxDeltaR_) {
275 
276  hleadTk_pt->Fill((float)myleadTk->pt());
277  hleadTk_eta->Fill((float)myleadTk->eta());
278  hleadTk_phi->Fill((float)myleadTk->phi());
279 
280  hEoverP->Fill((*thePFTau).ecalStripSumEOverPLead());
281  hHoverP->Fill((*thePFTau).hcal3x3OverPLead());
282  hEmfrac->Fill((*thePFTau).emFraction());
283 
284  if (std::abs(myleadTk->eta())<1.5) {
285  hEoverP_barrel->Fill((*thePFTau).ecalStripSumEOverPLead());
286  hHoverP_barrel->Fill((*thePFTau).hcal3x3OverPLead());
287  hEmfrac_barrel->Fill((*thePFTau).emFraction());
288  } else if (std::abs(myleadTk->eta())>1.5 && std::abs(myleadTk->eta())<2.5) {
289  hEoverP_endcap->Fill((*thePFTau).ecalStripSumEOverPLead());
290  hHoverP_endcap->Fill((*thePFTau).hcal3x3OverPLead());
291  hEmfrac_endcap->Fill((*thePFTau).emFraction());
292  }
293 
294  // if -999 fill in -1 bin!
295  if ((*thePFTau).electronPreIDOutput()<-1)
296  hElecMVA->Fill(-1);
297  else
298  hElecMVA->Fill((*thePFTau).electronPreIDOutput());
299 
300  hTauElecDiscriminant->Fill((*pfTauElecDiscr)[thePFTau]);
301 
302  hHoPvsEoP->Fill((*thePFTau).ecalStripSumEOverPLead(),(*thePFTau).hcal3x3OverPLead());
303  hEmfracvsEoP->Fill((*thePFTau).emFraction(),(*thePFTau).hcal3x3OverPLead());
304 
305  if ((*thePFTau).electronPreIDDecision()==1) {
306  hEoverP_preid1->Fill((*thePFTau).ecalStripSumEOverPLead());
307  hHoverP_preid1->Fill((*thePFTau).hcal3x3OverPLead());
308  hEmfrac_preid1->Fill((*thePFTau).emFraction());
309  hHoPvsEoP_preid1->Fill((*thePFTau).ecalStripSumEOverPLead(),(*thePFTau).hcal3x3OverPLead());
310  hEmfracvsEoP_preid1->Fill((*thePFTau).emFraction(),(*thePFTau).hcal3x3OverPLead());
311  } else {
312  hEoverP_preid0->Fill((*thePFTau).ecalStripSumEOverPLead());
313  hHoverP_preid0->Fill((*thePFTau).hcal3x3OverPLead());
314  hEmfrac_preid0->Fill((*thePFTau).emFraction());
315  hHoPvsEoP_preid0->Fill((*thePFTau).ecalStripSumEOverPLead(),(*thePFTau).hcal3x3OverPLead());
316  hEmfracvsEoP_preid0->Fill((*thePFTau).emFraction(),(*thePFTau).hcal3x3OverPLead());
317  }
318 
319 
320  }
321  }
322 
323  // Loop over all PFCands for cluster plots
324  std::vector<PFCandidatePtr> myPFCands=(*thePFTau).pfTauTagInfoRef()->PFCands();
325  for(int i=0;i<(int)myPFCands.size();i++){
326 
327  math::XYZPointF candPos;
328  if (myPFCands[i]->particleId()==1 || myPFCands[i]->particleId()==2) // if charged hadron or electron
329  candPos = myPFCands[i]->positionAtECALEntrance();
330  else
331  candPos = math::XYZPointF(myPFCands[i]->px(),myPFCands[i]->py(),myPFCands[i]->pz());
332 
333  //double deltaR = ROOT::Math::VectorUtil::DeltaR(myleadTkEcalPos,candPos);
334  double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(myleadTkEcalPos,candPos);
335  double deltaEta = std::abs(myleadTkEcalPos.eta()-myPFCands[i]->eta());
336  double deltaPhiOverQ = deltaPhi/(double)myleadTk->charge();
337 
338  hpfcand_deltaEta->Fill(deltaEta);
339  hpfcand_deltaEta_weightE->Fill(deltaEta*myPFCands[i]->ecalEnergy());
340  hpfcand_deltaPhiOverQ->Fill(deltaPhiOverQ);
341  hpfcand_deltaPhiOverQ_weightE->Fill(deltaPhiOverQ*myPFCands[i]->ecalEnergy());
342 
343  }
344 
345  }
346 
347  }
348  }
349  }
350 
351  }
352  }
353  }
354 }
355 
356 // Ecal crack map from Egamma POG
358  return (eta < 0.018 ||
359  (eta>0.423 && eta<0.461) ||
360  (eta>0.770 && eta<0.806) ||
361  (eta>1.127 && eta<1.163) ||
362  (eta>1.460 && eta<1.558));
363 }
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
tuple pfTaus
Definition: pfTaus_cff.py:136
#define NULL
Definition: scimark2.h:8
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
uint16_t size_type
#define BOOK1D(name, title, nbinsx, lowx, highx)
static const double deltaEta
Definition: CaloConstants.h:8
std::vector< TLorentzVector > _GenObjects
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define BOOK2D(name, title, nbinsx, lowx, highx, nbinsy, lowy, highy)
#define SETAXES(name, xtitle, ytitle)
tuple cout
Definition: gather_cfg.py:145
void process(edm::Handle< edm::HepMCProduct > mcevt, edm::Handle< reco::PFTauCollection > pfTaus, edm::Handle< reco::PFTauDiscriminator > pfTauIsoDiscr, edm::Handle< reco::PFTauDiscriminator > pfTauElecDiscr)
void setup(std::string Filename, std::string benchmarkLabel, double maxDeltaR, double minRecoPt, double maxRecoAbsEta, double minMCPt, double maxMCAbsEta, std::string sGenMatchObjectLabel, bool applyEcalCrackCut, DQMStore *db_store)