CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauTagValidation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TauTagValidation
4 // Class: TauTagValidation
5 //
15 //
16 // Original Author: Ricardo Vasquez Sierra
17 // Created: October 8, 2008
18 //
19 //
20 // user include files
21 
27 
31 
33 
34 using namespace edm;
35 using namespace std;
36 using namespace reco;
37 
39  moduleLabel_(iConfig.getParameter<std::string>("@module_label")),
40  // What do we want to use as source Leptons or Jets (the only difference is the matching criteria)
41  dataType_( iConfig.getParameter<string>("DataType") ),
42  // We need different matching criteria if we talk about leptons or jets
43  matchDeltaR_Leptons_( iConfig.getParameter<double>("MatchDeltaR_Leptons")),
44  matchDeltaR_Jets_( iConfig.getParameter<double>("MatchDeltaR_Jets")),
45  TauPtCut_( iConfig.getParameter<double>("TauPtCut")),
46  //flexible cut interface to filter reco and gen collection. use an empty string to select all.
47  recoCuts_( iConfig.getParameter<std::string>( "recoCuts" )),
48  genCuts_( iConfig.getParameter<std::string>( "genCuts" )),
49  // The output histograms can be stored or not
50  saveoutputhistograms_( iConfig.getParameter<bool>("SaveOutputHistograms")),
51  // Here it can be pretty much anything either a lepton or a jet
52  refCollectionInputTag_( iConfig.getParameter<InputTag>("RefCollection")),
53  // The extension name has information about the Reference collection used
54  extensionName_( iConfig.getParameter<string>("ExtensionName")),
55  // Here is the reconstructed product of interest.
56  TauProducerInputTag_( iConfig.getParameter<InputTag>("TauProducer")),
57  // Get the discriminators and their cuts
58  discriminators_( iConfig.getParameter< std::vector<edm::ParameterSet> >( "discriminators" ))
59 {
60 
61  turnOnTrigger_ = iConfig.exists("turnOnTrigger") && iConfig.getParameter<bool>("turnOnTrigger");
62  genericTriggerEventFlag_ = (iConfig.exists("GenericTriggerSelection") && turnOnTrigger_) ? new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("GenericTriggerSelection"), consumesCollector(), *this) : NULL;
63  if(genericTriggerEventFlag_ != NULL) LogDebug(moduleLabel_) <<"--> GenericTriggerSelection parameters found in "<<moduleLabel_<<"."<<std::endl;//move to LogDebug
64  else LogDebug(moduleLabel_) <<"--> GenericTriggerSelection not found in "<<moduleLabel_<<"."<<std::endl;//move to LogDebug to keep track of modules that fail and pass
65 
66  //InputTag to strings
69 
70  histoSettings_= (iConfig.exists("histoSettings")) ? iConfig.getParameter<edm::ParameterSet>("histoSettings") : edm::ParameterSet();
71  edm::InputTag PrimaryVertexCollection_ = (iConfig.exists("PrimaryVertexCollection")) ? iConfig.getParameter<InputTag>("PrimaryVertexCollection") : edm::InputTag("offlinePrimaryVertices"); //TO-DO
72 
73  refCollectionInputTagToken_ = consumes<edm::View<reco::Candidate> >(iConfig.getParameter<InputTag>("RefCollection"));
74  primaryVertexCollectionToken_ = consumes<VertexCollection>(PrimaryVertexCollection_); //TO-DO
75  tauProducerInputTagToken_ = consumes<reco::PFTauCollection>(iConfig.getParameter<InputTag>("TauProducer"));
76  int j = 0;
77  for ( std::vector<edm::ParameterSet>::iterator it = discriminators_.begin(); it != discriminators_.end(); ++j, ++it ) {
78  currentDiscriminatorToken_.push_back( consumes<reco::PFTauDiscriminator>(edm::InputTag(it->getParameter<string>("discriminator"))) );
79  }
80 
82 
83  if (!saveoutputhistograms_) {
84  LogInfo("OutputInfo") << " TauVisible histograms will NOT be saved";
85  } else {
87  outPutFile_.append("_");
88  tversion.erase(0,1);
89  tversion.erase(tversion.size()-1,1);
90  outPutFile_.append(tversion);
91  outPutFile_.append("_"+ refCollection_);
92  if ( ! extensionName_.empty()){
93  outPutFile_.append("_"+ extensionName_);
94  }
95  outPutFile_.append(".root");
96 
97  LogInfo("OutputInfo") << " TauVisiblehistograms will be saved to file:" << outPutFile_;
98  }
99 
100  //---- book-keeping information ---
101  numEvents_ = 0 ;
102 
103  // Check if we want to "chain" the discriminator requirements (i.e. all
104  // prveious discriminators must pass)
105  chainCuts_ = iConfig.exists("chainCuts") ?
106  iConfig.getParameter<bool>("chainCuts") : true;
107 
108 }
109 
112 }
113 
114 void TauTagValidation::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & iRun, edm::EventSetup const & /* iSetup */)
115 {
116  MonitorElement * ptTemp,* etaTemp,* phiTemp, *pileupTemp, *tmpME;
117 
118  ibooker.setCurrentFolder("RecoTauV/" + TauProducer_ + extensionName_ + "_ReferenceCollection" );
119 
120  //Histograms settings
121  hinfo ptHinfo = (histoSettings_.exists("pt")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("pt")) : hinfo(500, 0., 1000.);
122  hinfo etaHinfo = (histoSettings_.exists("eta")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("eta")) : hinfo(60, -3.0, 3.0);
123  hinfo phiHinfo = (histoSettings_.exists("phi")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("phi")) : hinfo(40, -200., 200.);
124  hinfo pileupHinfo = (histoSettings_.exists("pileup")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("pileup")) : hinfo(100, 0., 100.);
125  //hinfo dRHinfo = (histoSettings_.exists("deltaR")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("deltaR")) : hinfo(10, 0., 0.5);
126 
127  // What kind of Taus do we originally have!
128 
129  ptTemp = ibooker.book1D("nRef_Taus_vs_ptTauVisible", "nRef_Taus_vs_ptTauVisible", ptHinfo.nbins, ptHinfo.min, ptHinfo.max);
130  etaTemp = ibooker.book1D("nRef_Taus_vs_etaTauVisible", "nRef_Taus_vs_etaTauVisible", etaHinfo.nbins, etaHinfo.min, etaHinfo.max );
131  phiTemp = ibooker.book1D("nRef_Taus_vs_phiTauVisible", "nRef_Taus_vs_phiTauVisible", phiHinfo.nbins, phiHinfo.min, phiHinfo.max);
132  pileupTemp = ibooker.book1D("nRef_Taus_vs_pileupTauVisible", "nRef_Taus_vs_pileupTauVisible", pileupHinfo.nbins, pileupHinfo.min, pileupHinfo.max);
133 
134  ptTauVisibleMap.insert( std::make_pair( refCollection_,ptTemp));
135  etaTauVisibleMap.insert( std::make_pair(refCollection_,etaTemp));
136  phiTauVisibleMap.insert( std::make_pair(refCollection_,phiTemp));
137  pileupTauVisibleMap.insert( std::make_pair(refCollection_,pileupTemp));
138 
139  // Number of Tau Candidates matched to MC Taus
140 
141  ibooker.setCurrentFolder("RecoTauV/"+ TauProducer_ + extensionName_ + "_Matched");
142 
143  ptTemp = ibooker.book1D(TauProducer_ +"Matched_vs_ptTauVisible", TauProducer_ +"Matched_vs_ptTauVisible", ptHinfo.nbins, ptHinfo.min, ptHinfo.max);
144  etaTemp = ibooker.book1D(TauProducer_ +"Matched_vs_etaTauVisible", TauProducer_ +"Matched_vs_etaTauVisible", etaHinfo.nbins, etaHinfo.min, etaHinfo.max );
145  phiTemp = ibooker.book1D(TauProducer_ +"Matched_vs_phiTauVisible", TauProducer_ +"Matched_vs_phiTauVisible", phiHinfo.nbins, phiHinfo.min, phiHinfo.max );
146  pileupTemp = ibooker.book1D(TauProducer_ +"Matched_vs_pileupTauVisible", TauProducer_ +"Matched_vs_pileupTauVisible", pileupHinfo.nbins, pileupHinfo.min, pileupHinfo.max);
147 
148  ptTauVisibleMap.insert( std::make_pair( TauProducer_+"Matched" ,ptTemp));
149  etaTauVisibleMap.insert( std::make_pair(TauProducer_+"Matched" ,etaTemp));
150  phiTauVisibleMap.insert( std::make_pair(TauProducer_+"Matched" ,phiTemp));
151  pileupTauVisibleMap.insert( std::make_pair(TauProducer_+"Matched" ,pileupTemp));
152 
153  for ( std::vector< edm::ParameterSet >::iterator it = discriminators_.begin(); it!= discriminators_.end(); it++)
154  {
155  string DiscriminatorLabel = it->getParameter<string>("discriminator");
156  std::string histogramName;
157  stripDiscriminatorLabel(DiscriminatorLabel, histogramName);
158 
159  ibooker.setCurrentFolder("RecoTauV/" + TauProducer_ + extensionName_ + "_" + DiscriminatorLabel );
160 
161  ptTemp = ibooker.book1D(DiscriminatorLabel + "_vs_ptTauVisible", histogramName +"_vs_ptTauVisible", ptHinfo.nbins, ptHinfo.min, ptHinfo.max);
162  etaTemp = ibooker.book1D(DiscriminatorLabel + "_vs_etaTauVisible", histogramName + "_vs_etaTauVisible", etaHinfo.nbins, etaHinfo.min, etaHinfo.max );
163  phiTemp = ibooker.book1D(DiscriminatorLabel + "_vs_phiTauVisible", histogramName + "_vs_phiTauVisible", phiHinfo.nbins, phiHinfo.min, phiHinfo.max);
164  pileupTemp = ibooker.book1D(DiscriminatorLabel + "_vs_pileupTauVisible", histogramName + "_vs_pileupTauVisible", pileupHinfo.nbins, pileupHinfo.min, pileupHinfo.max);
165 
166  ptTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,ptTemp));
167  etaTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,etaTemp));
168  phiTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,phiTemp));
169  pileupTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,pileupTemp));
170 
171  // momentum resolution for several decay modes
172 
173  std::string plotType = "_pTRatio_";//use underscores (this allows to parse plot type in later stages)
174  std::string xaxisLabel = ";p_{T}^{reco}/p_{T}^{gen}";
175  std::string yaxislabel = ";Frequency";
176  std::string plotName = plotType + "allHadronic";
177  int bins = 40;
178  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
179  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
180  plotName = plotType + "oneProng0Pi0";
181  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
182  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
183  plotName = plotType + "oneProng1Pi0";
184  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
185  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
186  plotName = plotType + "oneProng2Pi0";
187  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
188  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
189  plotName = plotType + "threeProng0Pi0";
190  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
191  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
192  plotName = plotType + "threeProng1Pi0";
193  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
194  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
195 
196  //size and sumPt within tau isolation
197 
198  plotType = "_Size_";
199  xaxisLabel = ";size";
200  yaxislabel = ";Frequency";
201  bins = 20;
202  plotName = plotType + "signalPFCands";
203  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5);
204  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
205  plotName = plotType + "signalPFChargedHadrCands";
206  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5);
207  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
208  plotName = plotType + "signalPFNeutrHadrCands";
209  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5);
210  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
211 
212  plotName = plotType + "isolationPFCands";
213  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5);
214  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
215  plotName = plotType + "isolationPFChargedHadrCands";
216  bins = 10;
217  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5);
218  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
219  plotName = plotType + "isolationPFNeutrHadrCands";
220  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5);
221  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
222  plotName = plotType + "isolationPFGammaCands";
223  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5);
224  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
225 
226  plotType = "_SumPt_";
227  xaxisLabel = ";p_{T}^{sum}/ GeV";
228  yaxislabel = ";Frequency";
229  bins = 20;
230  plotName = plotType + "signalPFCands";
231  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
232  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
233  plotName = plotType + "signalPFChargedHadrCands";
234  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
235  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
236  plotName = plotType + "signalPFNeutrHadrCands";
237  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
238  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
239  plotName = plotType + "isolationPFCands";
240  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
241  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
242  plotName = plotType + "isolationPFChargedHadrCands";
243  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 10.);
244  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
245  plotName = plotType + "isolationPFNeutrHadrCands";
246  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 30.);
247  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
248  plotName = plotType + "isolationPFGammaCands";
249  tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 20.);
250  plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) );
251 
252  //deprecated!
253 
254  if ( DiscriminatorLabel.find("LeadingTrackPtCut") != string::npos){
255  if ( TauProducer_.find("PFTau") != string::npos)
256  {
257  nPFJet_LeadingChargedHadron_ChargedHadronsSignal_ =ibooker.book1D(DiscriminatorLabel + "_ChargedHadronsSignal",DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
258  nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_ =ibooker.book1D(DiscriminatorLabel + "_ChargedHadronsIsolAnnulus",DiscriminatorLabel + "_ChargedHadronsIsolAnnulus", 21, -0.5, 20.5);
259  nPFJet_LeadingChargedHadron_GammasSignal_ =ibooker.book1D(DiscriminatorLabel + "_GammasSignal",DiscriminatorLabel + "_GammasSignal",21, -0.5, 20.5);
260  nPFJet_LeadingChargedHadron_GammasIsolAnnulus_ =ibooker.book1D(DiscriminatorLabel + "_GammasIsolAnnulus",DiscriminatorLabel + "_GammasIsolAnnulus",21, -0.5, 20.5);
261  nPFJet_LeadingChargedHadron_NeutralHadronsSignal_ =ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsSignal",DiscriminatorLabel + "_NeutralHadronsSignal",21, -0.5, 20.5);
262  nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_ =ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",21, -0.5, 20.5);
263  }
264  }
265 
266  if ( DiscriminatorLabel.find("ByIsolationLater") != string::npos ){
267  if ( TauProducer_.find("PFTau") != string::npos)
268  {
269  nIsolated_NoChargedHadrons_ChargedHadronsSignal_ =ibooker.book1D(DiscriminatorLabel + "_ChargedHadronsSignal",DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
270  nIsolated_NoChargedHadrons_GammasSignal_ =ibooker.book1D(DiscriminatorLabel + "_GammasSignal",DiscriminatorLabel + "_GammasSignal",21, -0.5, 20.5);
271  nIsolated_NoChargedHadrons_GammasIsolAnnulus_ =ibooker.book1D(DiscriminatorLabel + "_GammasIsolAnnulus",DiscriminatorLabel + "_GammasIsolAnnulus",21, -0.5, 20.5);
272  nIsolated_NoChargedHadrons_NeutralHadronsSignal_ =ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsSignal",DiscriminatorLabel + "_NeutralHadronsSignal",21, -0.5, 20.5);
273  nIsolated_NoChargedHadrons_NeutralHadronsIsolAnnulus_ =ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",21, -0.5, 20.5);
274  }
275  }
276 
277  if ( DiscriminatorLabel.find("ByIsolation") != string::npos ){
278  if ( TauProducer_.find("PFTau") != string::npos)
279  {
280  nIsolated_NoChargedNoGammas_ChargedHadronsSignal_ =ibooker.book1D(DiscriminatorLabel + "_ChargedHadronsSignal",DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
281  nIsolated_NoChargedNoGammas_GammasSignal_ =ibooker.book1D(DiscriminatorLabel + "_GammasSignal",DiscriminatorLabel + "_GammasSignal",21, -0.5, 20.5);
282  nIsolated_NoChargedNoGammas_NeutralHadronsSignal_ =ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsSignal",DiscriminatorLabel + "_NeutralHadronsSignal",21, -0.5, 20.5);
283  nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_ =ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",21, -0.5, 20.5);
284  }
285  }
286  }
287 }
288 
289 void TauTagValidation::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
291  if (genericTriggerEventFlag_->on()) {
292  genericTriggerEventFlag_->initRun(iRun, iSetup);
293  }
294  }
295 }
296 
299  if (!genericTriggerEventFlag_->on()) std::cout<<"TauTagValidation::analyze: No working genericTriggerEventFlag. Did you specify a valid globaltag?"<<std::endl;//move to LogDebug?
300  }
301 
302  numEvents_++;
303  double matching_criteria = -1.0;
304 
305  typedef edm::View<reco::Candidate> genCandidateCollection;
306 
307  // ----------------------- Reference product -----------------------------------------------------------------------
308 
309  Handle<genCandidateCollection> ReferenceCollection;
310  bool isGen = iEvent.getByToken( refCollectionInputTagToken_, ReferenceCollection );
311 
312  Handle<VertexCollection> pvHandle;
313  iEvent.getByToken( primaryVertexCollectionToken_, pvHandle ); //TO-DO
314 
315  if (!isGen) {
316  std::cerr << " Reference collection: " << refCollection_ << " not found while running TauTagValidation.cc " << std::endl;
317  return;
318  }
319 
320  if(dataType_ == "Leptons"){
321  matching_criteria = matchDeltaR_Leptons_;
322  }
323  else
324  {
325  matching_criteria = matchDeltaR_Jets_;
326  }
327 
328  // ------------------------------ PFTauCollection Matched and other discriminators ---------------------------------------------------------
329 
330  if ( TauProducer_.find("PFTau") != string::npos || TauProducer_.find("hpsTancTaus") != string::npos )
331  {
332  Handle<PFTauCollection> thePFTauHandle;
333  iEvent.getByToken( tauProducerInputTagToken_, thePFTauHandle );
334 
335  const PFTauCollection *pfTauProduct;
336  pfTauProduct = thePFTauHandle.product();
337 
338  PFTauCollection::size_type thePFTauClosest;
339 
340  std::map<std::string, MonitorElement *>::const_iterator element = plotMap_.end();
341 
342  for (genCandidateCollection::const_iterator RefJet= ReferenceCollection->begin() ; RefJet != ReferenceCollection->end(); RefJet++ ){
343 
344  ptTauVisibleMap.find(refCollection_)->second->Fill(RefJet->pt());
345  etaTauVisibleMap.find(refCollection_)->second->Fill(RefJet->eta());
346  phiTauVisibleMap.find(refCollection_)->second->Fill(RefJet->phi()*180.0/TMath::Pi());
347  pileupTauVisibleMap.find(refCollection_)->second->Fill(pvHandle->size());
348 
349  const reco::Candidate *gen_particle = &(*RefJet);
350 
351  double delta=TMath::Pi();
352 
353  thePFTauClosest = pfTauProduct->size();
354 
355  for (PFTauCollection::size_type iPFTau=0 ; iPFTau < pfTauProduct->size() ; iPFTau++)
356  {
357  if (algo_->deltaR(gen_particle, & pfTauProduct->at(iPFTau)) < delta){
358  delta = algo_->deltaR(gen_particle, & pfTauProduct->at(iPFTau));
359  thePFTauClosest = iPFTau;
360  }
361  }
362 
363  // Skip if there is no reconstructed Tau matching the Reference
364  if (thePFTauClosest == pfTauProduct->size()) continue;
365 
366  double deltaR = algo_->deltaR(gen_particle, & pfTauProduct->at(thePFTauClosest));
367 
368  // Skip if the delta R difference is larger than the required criteria
369  if (deltaR > matching_criteria && matching_criteria != -1.0) continue;
370 
371  ptTauVisibleMap.find( TauProducer_+"Matched")->second->Fill(RefJet->pt());
372  etaTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->eta());
373  phiTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
374  pileupTauVisibleMap.find( TauProducer_+"Matched")->second->Fill(pvHandle->size());
375 
376  PFTauRef thePFTau(thePFTauHandle, thePFTauClosest);
377 
378  Handle<PFTauDiscriminator> currentDiscriminator;
379 
380  //filter the candidates
381  if(thePFTau->pt() < TauPtCut_ ) continue;//almost deprecated, since recoCuts_ provides more flexibility
382  //reco
384  bool pass = selectReco( thePFTau );
385  if( !pass ) continue;
386  //gen
388  pass = selectGen( *gen_particle );
389  if( !pass ) continue;
390 
391  int j = 0;
392  for ( std::vector< edm::ParameterSet >::iterator it = discriminators_.begin(); it!= discriminators_.end(); it++, j++)
393  {
394  string currentDiscriminatorLabel = it->getParameter<string>("discriminator");
395  iEvent.getByToken( currentDiscriminatorToken_[j], currentDiscriminator );
396 
397  if ((*currentDiscriminator)[thePFTau] >= it->getParameter<double>("selectionCut")){
398  ptTauVisibleMap.find( currentDiscriminatorLabel )->second->Fill(RefJet->pt());
399  etaTauVisibleMap.find( currentDiscriminatorLabel )->second->Fill(RefJet->eta());
400  phiTauVisibleMap.find( currentDiscriminatorLabel )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
401  pileupTauVisibleMap.find( currentDiscriminatorLabel )->second->Fill(pvHandle->size());
402 
403  //fill the momentum resolution plots
404  double tauPtRes = thePFTau->pt()/gen_particle->pt();//WARNING: use only the visible parts!
405  plotMap_.find( currentDiscriminatorLabel + "_pTRatio_allHadronic" )->second->Fill(tauPtRes);
406 
407  //is there a better way than casting the candidate?
408  const reco::GenJet *tauGenJet = dynamic_cast<const reco::GenJet*>(gen_particle);
409  if(tauGenJet!=0){
410  std::string genTauDecayMode = JetMCTagUtils::genTauDecayMode(*tauGenJet); // gen_particle is the tauGenJet matched to the reconstructed tau
411  element = plotMap_.find( currentDiscriminatorLabel + "_pTRatio_" + genTauDecayMode );
412  if( element != plotMap_.end() ) element->second->Fill(tauPtRes);
413  }else{
414  LogInfo("TauTagValidation") << " Failed to cast the MC candidate.";
415  }
416 
417  //fill: size and sumPt within tau isolation
418  std::string plotType = "_Size_";
419  element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFCands" );
420  if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalPFCands().size() );
421  element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFChargedHadrCands" );
422  if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalPFChargedHadrCands().size() );
423  element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFNeutrHadrCands" );
424  if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalPFNeutrHadrCands().size() );
425  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFCands" );
426  if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFCands().size() );
427  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFChargedHadrCands" );
428  if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFChargedHadrCands().size() );
429  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFNeutrHadrCands" );
430  if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFNeutrHadrCands().size() );
431  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFGammaCands" );
432  if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFGammaCands().size() );
433 
434  plotType = "_SumPt_";
435  element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFCands" );
436  if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalPFCands() ) );
437  element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFChargedHadrCands" );
438  if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalPFChargedHadrCands() ) );
439  element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFNeutrHadrCands" );
440  if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalPFNeutrHadrCands() ) );
441  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFCands" );
442  if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFCands() ) );
443  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFChargedHadrCands" );
444  if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFChargedHadrCands() ) );
445  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFNeutrHadrCands" );
446  if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFNeutrHadrCands() ) );
447  element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFGammaCands" );
448  if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFGammaCands() ) );
449 
450  //deprecated
451 
452  if( TauProducer_.find("PFTau") != string::npos ){
453  if ( currentDiscriminatorLabel.find("LeadingTrackPtCut") != string::npos){
454  nPFJet_LeadingChargedHadron_ChargedHadronsSignal_->Fill((*thePFTau).signalPFChargedHadrCands().size());
455  nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFChargedHadrCands().size());
456  nPFJet_LeadingChargedHadron_GammasSignal_->Fill((*thePFTau).signalPFGammaCands().size());
457  nPFJet_LeadingChargedHadron_GammasIsolAnnulus_->Fill((*thePFTau).isolationPFGammaCands().size());
458  nPFJet_LeadingChargedHadron_NeutralHadronsSignal_->Fill((*thePFTau).signalPFNeutrHadrCands().size());
459  nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFNeutrHadrCands().size());
460  }
461  else if ( currentDiscriminatorLabel.find("ByIsolation") != string::npos ){
462  nIsolated_NoChargedNoGammas_ChargedHadronsSignal_->Fill((*thePFTau).signalPFChargedHadrCands().size());
463  nIsolated_NoChargedNoGammas_GammasSignal_->Fill((*thePFTau).signalPFGammaCands().size());
464  nIsolated_NoChargedNoGammas_NeutralHadronsSignal_->Fill((*thePFTau).signalPFNeutrHadrCands().size());
465  nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFNeutrHadrCands().size());
466  }
467  }
468  }
469  else {
470  if (chainCuts_)
471  break;
472  }
473  }
474  }
475  }
476 }
477 
479  double sumPt = 0.;
480  for (std::vector<edm::Ptr<reco::PFCandidate> >::const_iterator candidate = candidates.begin(); candidate!=candidates.end(); ++candidate) {
481  sumPt += (*candidate)->pt();
482  }
483  return sumPt;
484 }
485 
486 bool TauTagValidation::stripDiscriminatorLabel(const std::string& discriminatorLabel, std::string & newLabel) {
487  std::string separatorString = "DiscriminationBy";
488  std::string::size_type separator = discriminatorLabel.find(separatorString);
489  if(separator==std::string::npos){
490  separatorString = "Discrimination";//DiscriminationAgainst, keep the 'against' here
491  separator = discriminatorLabel.find(separatorString);
492  if(separator==std::string::npos){
493  return false;
494  }
495  }
496  std::string prefix = discriminatorLabel.substr(0,separator);
497  std::string postfix = discriminatorLabel.substr(separator+separatorString.size());
498  newLabel = prefix+postfix;
499  return true;
500 }
#define LogDebug(id)
std::map< std::string, MonitorElement * > ptTauVisibleMap
dbl * delta
Definition: mlp_gen.cc:36
const double Pi
T getParameter(std::string const &) const
std::string genTauDecayMode(const reco::CompositePtrCandidate &c)
Definition: JetMCTag.cc:81
MonitorElement * nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_
std::map< std::string, MonitorElement * > plotMap_
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
double max
MonitorElement * nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
virtual double pt() const =0
transverse momentum
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::PFTauCollection > tauProducerInputTagToken_
#define NULL
Definition: scimark2.h:8
edm::InputTag TauProducerInputTag_
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
std::string refCollection_
uint16_t size_type
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > currentDiscriminatorToken_
void Fill(long long x)
std::string outPutFile_
MonitorElement * nPFJet_LeadingChargedHadron_GammasSignal_
std::vector< edm::ParameterSet > discriminators_
MonitorElement * nPFJet_LeadingChargedHadron_ChargedHadronsSignal_
int iEvent
Definition: GenABIO.cc:230
std::string tversion
GenericTriggerEventFlag * genericTriggerEventFlag_
generic access to dynamic trigger table
MonitorElement * nIsolated_NoChargedNoGammas_ChargedHadronsSignal_
std::string dataType_
What&#39;s the reference for the Validation Leptons or Jets.
std::string TauProducer_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
static double deltaR(const T *, const U *)
double getSumPt(const std::vector< edm::Ptr< reco::PFCandidate > > &candidates)
sum the transversal momentum of all candidates
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int j
Definition: DBlmapReader.cc:9
Jets made from MC generator particles.
Definition: GenJet.h:24
MonitorElement * nIsolated_NoChargedHadrons_GammasSignal_
MonitorElement * nIsolated_NoChargedHadrons_GammasIsolAnnulus_
std::string genCuts_
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
std::map< std::string, MonitorElement * > etaTauVisibleMap
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::string getReleaseVersion()
MonitorElement * nIsolated_NoChargedNoGammas_NeutralHadronsSignal_
double min
MonitorElement * nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
T const * product() const
Definition: Handle.h:81
MonitorElement * nIsolated_NoChargedHadrons_NeutralHadronsSignal_
edm::EDGetTokenT< edm::View< reco::Candidate > > refCollectionInputTagToken_
std::string extensionName_
std::string const & label() const
Definition: InputTag.h:43
MonitorElement * nIsolated_NoChargedHadrons_NeutralHadronsIsolAnnulus_
std::string moduleLabel_
label of the current module
edm::InputTag refCollectionInputTag_
bool stripDiscriminatorLabel(const std::string &discriminatorLabel, std::string &newLabel)
get rid of redundant parts to shorten the label
edm::InputTag PrimaryVertexCollection_
tuple cout
Definition: gather_cfg.py:121
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
MonitorElement * nIsolated_NoChargedHadrons_ChargedHadronsSignal_
std::map< std::string, MonitorElement * > phiTauVisibleMap
MonitorElement * nPFJet_LeadingChargedHadron_NeutralHadronsSignal_
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
TauTagValidation(const edm::ParameterSet &)
edm::ParameterSet histoSettings_
MonitorElement * nPFJet_LeadingChargedHadron_GammasIsolAnnulus_
std::string recoCuts_
moduleLabel_(iConfig.getParameter< string >("@module_label"))
std::map< std::string, MonitorElement * > pileupTauVisibleMap
MonitorElement * nIsolated_NoChargedNoGammas_GammasSignal_
PFBenchmarkAlgo * algo_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::VertexCollection > primaryVertexCollectionToken_
Definition: Run.h:43