CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Validation/RecoTau/src/TauTagValidation.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TauTagValidation
00004 // Class:      TauTagValidation
00005 // 
00015 //
00016 // Original Author:  Ricardo Vasquez Sierra
00017 //         Created:  October 8, 2008
00018 // $Id: TauTagValidation.cc,v 1.20 2011/01/24 13:29:22 mverzett Exp $
00019 //
00020 //
00021 // user include files
00022 
00023 #include "Validation/RecoTau/interface/TauTagValidation.h"
00024 #include "FWCore/Version/interface/GetReleaseVersion.h"
00025 
00026 using namespace edm;
00027 using namespace std;
00028 using namespace reco;
00029 
00030 TauTagValidation::TauTagValidation(const edm::ParameterSet& iConfig)
00031 {
00032   // What do we want to use as source Leptons or Jets (the only difference is the matching criteria)
00033   dataType_ = iConfig.getParameter<string>("DataType");
00034 
00035   // We need different matching criteria if we talk about leptons or jets
00036   matchDeltaR_Leptons_ = iConfig.getParameter<double>("MatchDeltaR_Leptons");
00037   matchDeltaR_Jets_    = iConfig.getParameter<double>("MatchDeltaR_Jets");
00038 
00039   // The output histograms can be stored or not
00040   saveoutputhistograms_ = iConfig.getParameter<bool>("SaveOutputHistograms");
00041 
00042   // Here it can be pretty much anything either a lepton or a jet 
00043   refCollectionInputTag_ = iConfig.getParameter<InputTag>("RefCollection");
00044   refCollection_ = refCollectionInputTag_.label();
00045   
00046   // The extension name has information about the Reference collection used
00047   extensionName_ = iConfig.getParameter<string>("ExtensionName");
00048   
00049   // Here is the reconstructed product of interest.
00050   TauProducerInputTag_ = iConfig.getParameter<InputTag>("TauProducer");
00051   TauProducer_ = TauProducerInputTag_.label();
00052 
00053   // The vector of Tau Discriminators to be monitored
00054   // TauProducerDiscriminators_ = iConfig.getUntrackedParameter<std::vector<string> >("TauProducerDiscriminators");
00055   
00056   // The cut on the Discriminators
00057   //  TauDiscriminatorCuts_ = iConfig.getUntrackedParameter<std::vector<double> > ("TauDiscriminatorCuts");
00058 
00059   // Get the discriminators and their cuts
00060   discriminators_ = iConfig.getParameter< std::vector<edm::ParameterSet> >( "discriminators" ); 
00061 
00062   //  cout << " RefCollection: " << refCollection_.label() << " "<< refCollection_ << endl;
00063 
00064   tversion = edm::getReleaseVersion();
00065   //    cout<<endl<<"-----------------------*******************************Version: " << tversion<<endl;
00066   
00067   if (!saveoutputhistograms_) {
00068     LogInfo("OutputInfo") << " TauVisible histograms will NOT be saved";
00069   } else {
00070     outPutFile_ = TauProducer_;
00071     outPutFile_.append("_");    
00072     tversion.erase(0,1);
00073     tversion.erase(tversion.size()-1,1);
00074     outPutFile_.append(tversion);
00075     outPutFile_.append("_"+ refCollection_);
00076     if ( ! extensionName_.empty()){
00077       outPutFile_.append("_"+ extensionName_);
00078     }
00079     outPutFile_.append(".root");
00080     
00081     //    cout<<endl<< outPutFile_<<endl;
00082     LogInfo("OutputInfo") << " TauVisiblehistograms will be saved to file:" << outPutFile_;
00083   }
00084 
00085   //---- book-keeping information ---
00086   numEvents_ = 0 ;
00087 
00088 }
00089 
00090 // ------------ method called once each job just before starting event loop  ------------
00091 void TauTagValidation::beginJob()
00092 { 
00093 
00094   dbeTau = &*edm::Service<DQMStore>();
00095 
00096   if(dbeTau) {
00097 
00098     MonitorElement * ptTemp,* etaTemp,* phiTemp, *energyTemp;
00099     
00100     dbeTau->setCurrentFolder("RecoTauV/" + TauProducer_ + extensionName_ + "_ReferenceCollection" );
00101 
00102     // What kind of Taus do we originally have!
00103     
00104     ptTemp    =  dbeTau->book1D("nRef_Taus_vs_ptTauVisible", "nRef_Taus_vs_ptTauVisible", 75, 0., 150.);
00105     etaTemp   =  dbeTau->book1D("nRef_Taus_vs_etaTauVisible", "nRef_Taus_vs_etaTauVisible", 60, -3.0, 3.0 );
00106     phiTemp   =  dbeTau->book1D("nRef_Taus_vs_phiTauVisible", "nRef_Taus_vs_phiTauVisible", 36, -180., 180.);
00107     energyTemp =  dbeTau->book1D("nRef_Taus_vs_energyTauVisible", "nRef_Taus_vs_energyTauVisible", 45, 0., 450.0);
00108 
00109     ptTauVisibleMap.insert( std::make_pair( refCollection_,ptTemp));
00110     etaTauVisibleMap.insert( std::make_pair(refCollection_,etaTemp));
00111     phiTauVisibleMap.insert( std::make_pair(refCollection_,phiTemp));
00112     energyTauVisibleMap.insert( std::make_pair(refCollection_,energyTemp));
00113 
00114     // Number of Tau Candidates matched to MC Taus    
00115 
00116     dbeTau->setCurrentFolder("RecoTauV/"+ TauProducer_ + extensionName_ + "_Matched");
00117 
00118     ptTemp    =  dbeTau->book1D(TauProducer_ +"Matched_vs_ptTauVisible", TauProducer_ +"Matched_vs_ptTauVisible", 75, 0., 150.);
00119     etaTemp   =  dbeTau->book1D(TauProducer_ +"Matched_vs_etaTauVisible", TauProducer_ +"Matched_vs_etaTauVisible", 60, -3.0, 3.0 );
00120     phiTemp   =  dbeTau->book1D(TauProducer_ +"Matched_vs_phiTauVisible", TauProducer_ +"Matched_vs_phiTauVisible", 36, -180., 180.);
00121     energyTemp =  dbeTau->book1D(TauProducer_ +"Matched_vs_energyTauVisible", TauProducer_ +"Matched_vs_energyTauVisible", 45, 0., 450.0);
00122 
00123     ptTauVisibleMap.insert( std::make_pair( TauProducer_+"Matched" ,ptTemp));
00124     etaTauVisibleMap.insert( std::make_pair(TauProducer_+"Matched" ,etaTemp));
00125     phiTauVisibleMap.insert( std::make_pair(TauProducer_+"Matched" ,phiTemp));
00126     energyTauVisibleMap.insert( std::make_pair(TauProducer_+"Matched" ,energyTemp));  
00127 
00128     for ( std::vector< edm::ParameterSet >::iterator it = discriminators_.begin(); it!= discriminators_.end();  it++)
00129       {
00130         string DiscriminatorLabel = it->getParameter<string>("discriminator");
00131 
00132         dbeTau->setCurrentFolder("RecoTauV/" +  TauProducer_ + extensionName_ + "_" +  DiscriminatorLabel );
00133         
00134         ptTemp    =  dbeTau->book1D(DiscriminatorLabel + "_vs_ptTauVisible", DiscriminatorLabel +"_vs_ptTauVisible", 75, 0., 150.);
00135         etaTemp   =  dbeTau->book1D(DiscriminatorLabel + "_vs_etaTauVisible", DiscriminatorLabel + "_vs_etaTauVisible", 60, -3.0, 3.0 );
00136         phiTemp   =  dbeTau->book1D(DiscriminatorLabel + "_vs_phiTauVisible", DiscriminatorLabel + "_vs_phiTauVisible", 36, -180., 180.);
00137         energyTemp =  dbeTau->book1D(DiscriminatorLabel + "_vs_energyTauVisible", DiscriminatorLabel + "_vs_energyTauVisible", 45, 0., 450.0);
00138                 
00139         ptTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,ptTemp));
00140         etaTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,etaTemp));
00141         phiTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,phiTemp));
00142         energyTauVisibleMap.insert( std::make_pair(DiscriminatorLabel,energyTemp));
00143 
00144         //      if ( TauProducer_.find("PFTau") != string::npos) 
00145         // {
00146         
00147         if ( DiscriminatorLabel.find("LeadingTrackPtCut") != string::npos){
00148           if ( TauProducer_.find("PFTau") != string::npos)
00149             {
00150               nPFJet_LeadingChargedHadron_ChargedHadronsSignal_         =dbeTau->book1D(DiscriminatorLabel + "_ChargedHadronsSignal",DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);              
00151               nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_    =dbeTau->book1D(DiscriminatorLabel + "_ChargedHadronsIsolAnnulus",DiscriminatorLabel + "_ChargedHadronsIsolAnnulus", 21, -0.5, 20.5);    
00152               nPFJet_LeadingChargedHadron_GammasSignal_                 =dbeTau->book1D(DiscriminatorLabel + "_GammasSignal",DiscriminatorLabel + "_GammasSignal",21, -0.5, 20.5);                               
00153               nPFJet_LeadingChargedHadron_GammasIsolAnnulus_            =dbeTau->book1D(DiscriminatorLabel + "_GammasIsolAnnulus",DiscriminatorLabel + "_GammasIsolAnnulus",21, -0.5, 20.5);             
00154               nPFJet_LeadingChargedHadron_NeutralHadronsSignal_         =dbeTau->book1D(DiscriminatorLabel + "_NeutralHadronsSignal",DiscriminatorLabel + "_NeutralHadronsSignal",21, -0.5, 20.5);               
00155               nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_    =dbeTau->book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",21, -0.5, 20.5);          
00156             }
00157           else if (TauProducer_.find("caloRecoTau") != string::npos)
00158             {
00159               nCaloJet_LeadingTrack_signalTracksInvariantMass_   =dbeTau->book1D(DiscriminatorLabel + "_signalTracksInvariantMass",DiscriminatorLabel + "_signalTracksInvariantMass",  75, 0., 150.); 
00160               nCaloJet_LeadingTrack_signalTracks_                =dbeTau->book1D(DiscriminatorLabel + "_signalTracks", DiscriminatorLabel + "_signalTracks" , 15, -0.5, 14.5);               
00161               nCaloJet_LeadingTrack_isolationTracks_             =dbeTau->book1D(DiscriminatorLabel + "_isolationTracks", DiscriminatorLabel + "_isolationTracks",  15, -0.5, 14.5);                     
00162               nCaloJet_LeadingTrack_isolationECALhitsEtSum_      =dbeTau->book1D(DiscriminatorLabel + "_isolationECALhitsEtSum", DiscriminatorLabel + "_isolationECALhitsEtSum", 75, 0., 75.);       
00163             }
00164         }
00165         
00166         if ( DiscriminatorLabel.find("ByIsolationLater") != string::npos ){
00167           if ( TauProducer_.find("PFTau") != string::npos)
00168             {
00169               nIsolated_NoChargedHadrons_ChargedHadronsSignal_        =dbeTau->book1D(DiscriminatorLabel + "_ChargedHadronsSignal",DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);                     
00170               nIsolated_NoChargedHadrons_GammasSignal_                =dbeTau->book1D(DiscriminatorLabel + "_GammasSignal",DiscriminatorLabel + "_GammasSignal",21, -0.5, 20.5);                           
00171               nIsolated_NoChargedHadrons_GammasIsolAnnulus_           =dbeTau->book1D(DiscriminatorLabel + "_GammasIsolAnnulus",DiscriminatorLabel + "_GammasIsolAnnulus",21, -0.5, 20.5);                 
00172               nIsolated_NoChargedHadrons_NeutralHadronsSignal_        =dbeTau->book1D(DiscriminatorLabel + "_NeutralHadronsSignal",DiscriminatorLabel + "_NeutralHadronsSignal",21, -0.5, 20.5);           
00173               nIsolated_NoChargedHadrons_NeutralHadronsIsolAnnulus_   =dbeTau->book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",21, -0.5, 20.5); 
00174             }
00175           else if (TauProducer_.find("caloRecoTau") != string::npos)
00176             {
00177               nTrackIsolated_isolationECALhitsEtSum_      =dbeTau->book1D(DiscriminatorLabel + "_isolationECALhitsEtSum", DiscriminatorLabel + "_isolationECALhitsEtSum", 75, 0., 75.);   
00178               nTrackIsolated_signalTracksInvariantMass_   =dbeTau->book1D(DiscriminatorLabel + "_signalTracksInvariantMass",DiscriminatorLabel + "_signalTracksInvariantMass", 75, 0., 150.);
00179               nTrackIsolated_signalTracks_                =dbeTau->book1D(DiscriminatorLabel + "_signalTracks",DiscriminatorLabel + "_signalTracks", 15, -0.5, 14.5);                        
00180             }
00181         }
00182 
00183         if ( DiscriminatorLabel.find("ByIsolation") != string::npos ){
00184           if ( TauProducer_.find("PFTau") != string::npos)
00185             {
00186               nIsolated_NoChargedNoGammas_ChargedHadronsSignal_        =dbeTau->book1D(DiscriminatorLabel + "_ChargedHadronsSignal",DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);        
00187               nIsolated_NoChargedNoGammas_GammasSignal_                =dbeTau->book1D(DiscriminatorLabel + "_GammasSignal",DiscriminatorLabel + "_GammasSignal",21, -0.5, 20.5);        
00188               nIsolated_NoChargedNoGammas_NeutralHadronsSignal_        =dbeTau->book1D(DiscriminatorLabel + "_NeutralHadronsSignal",DiscriminatorLabel + "_NeutralHadronsSignal",21, -0.5, 20.5);                
00189               nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_   =dbeTau->book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",21, -0.5, 20.5); 
00190 
00191             }
00192           else if (TauProducer_.find("caloRecoTau") != string::npos)
00193             {
00194               nEMIsolated_signalTracksInvariantMass_  =dbeTau->book1D(DiscriminatorLabel+"_signalTracksInvariantMass",DiscriminatorLabel+"_signalTracksInvariantMass", 75, 0., 150.);
00195               nEMIsolated_signalTracks_               =dbeTau->book1D(DiscriminatorLabel+"_signalTracks",DiscriminatorLabel+"_signalTracks", 15, -0.5, 14.5);    
00196             }
00197         }
00198 
00199       }
00200   }
00201 
00202   for ( std::vector< edm::ParameterSet >::iterator it = discriminators_.begin(); it!= discriminators_.end();  it++) 
00203     {
00204       cerr<< " "<< it->getParameter<string>("discriminator") << " "<< it->getParameter<double>("selectionCut") << endl;
00205       
00206     }
00207 }
00208 
00209 // -- method called to produce fill all the histograms --------------------
00210 void TauTagValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00211 {
00212   
00213   numEvents_++;
00214   double matching_criteria = -1.0;
00215 
00216   typedef edm::View<reco::Candidate> genCandidateCollection;
00217   //  typedef edm::Vector<reco::PFTau> pfCandidateCollection;
00218   //  typedef edm::Vector<reco::CaloTau> caloCandidateCollection;
00219 
00220   //  std::cout << "--------------------------------------------------------------"<<endl;
00221   //std::cout << " RunNumber: " << iEvent.id().run() << ", EventNumber: " << iEvent.id().event() << std:: endl;
00222   //std::cout << "Event number: " << ++numEvents_ << endl;
00223   //std::cout << "--------------------------------------------------------------"<<endl;
00224 
00225   // ----------------------- Reference product -----------------------------------------------------------------------
00226 
00227   Handle<genCandidateCollection> ReferenceCollection;
00228   bool isGen = iEvent.getByLabel(refCollectionInputTag_, ReferenceCollection);    // get the product from the event
00229 
00230   if (!isGen) {
00231     std::cerr << " Reference collection: " << refCollection_ << " not found while running TauTagValidation.cc " << std::endl;
00232     return;
00233   }
00234 
00235   if(dataType_ == "Leptons"){
00236     matching_criteria = matchDeltaR_Leptons_;
00237   }
00238   else
00239   {
00240     matching_criteria = matchDeltaR_Jets_;
00241   }
00242 
00243   // ------------------------------ PFTauCollection Matched and other discriminators ---------------------------------------------------------
00244 
00245   if ( TauProducer_.find("PFTau") != string::npos)
00246     {
00247       Handle<PFTauCollection> thePFTauHandle;
00248       iEvent.getByLabel(TauProducerInputTag_,thePFTauHandle);
00249       
00250       const PFTauCollection  *pfTauProduct;
00251       pfTauProduct = thePFTauHandle.product();
00252 
00253       PFTauCollection::size_type thePFTauClosest;      
00254 
00255       for (genCandidateCollection::const_iterator RefJet= ReferenceCollection->begin() ; RefJet != ReferenceCollection->end(); RefJet++ ){ 
00256 
00257         
00258         ptTauVisibleMap.find(refCollection_)->second->Fill(RefJet->pt());
00259         etaTauVisibleMap.find(refCollection_)->second->Fill(RefJet->eta());
00260         phiTauVisibleMap.find(refCollection_)->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00261         energyTauVisibleMap.find(refCollection_)->second->Fill(RefJet->energy());
00262         
00263         const reco::Candidate *gen_particle = &(*RefJet);
00264         
00265         double delta=TMath::Pi();
00266 
00267         thePFTauClosest = pfTauProduct->size();
00268 
00269         for (PFTauCollection::size_type iPFTau=0 ; iPFTau <  pfTauProduct->size() ; iPFTau++) 
00270           {                 
00271             if (algo_->deltaR(gen_particle, & pfTauProduct->at(iPFTau)) < delta){
00272               delta = algo_->deltaR(gen_particle, & pfTauProduct->at(iPFTau));
00273               thePFTauClosest = iPFTau;
00274             }
00275           }
00276         
00277         // Skip if there is no reconstructed Tau matching the Reference 
00278         if (thePFTauClosest == pfTauProduct->size()) continue;
00279         
00280         double deltaR = algo_->deltaR(gen_particle, & pfTauProduct->at(thePFTauClosest));
00281 
00282         // Skip if the delta R difference is larger than the required criteria
00283         if (deltaR > matching_criteria && matching_criteria != -1.0) continue;
00284         
00285         ptTauVisibleMap.find( TauProducer_+"Matched")->second->Fill(RefJet->pt());
00286         etaTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->eta());
00287         phiTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00288         energyTauVisibleMap.find(  TauProducer_+"Matched")->second->Fill(RefJet->energy());
00289         
00290         PFTauRef thePFTau(thePFTauHandle, thePFTauClosest);
00291         Handle<PFTauDiscriminator> currentDiscriminator;
00292         
00293         for ( std::vector< edm::ParameterSet >::iterator it = discriminators_.begin(); it!= discriminators_.end();  it++) 
00294           {
00295             string currentDiscriminatorLabel = it->getParameter<string>("discriminator");             
00296             iEvent.getByLabel(currentDiscriminatorLabel, currentDiscriminator);
00297             
00298             if ((*currentDiscriminator)[thePFTau] >= it->getParameter<double>("selectionCut")){
00299               ptTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->pt());
00300               etaTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->eta());
00301               phiTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00302               energyTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->energy());
00303               
00304               if ( currentDiscriminatorLabel.find("LeadingTrackPtCut") != string::npos){
00305                 nPFJet_LeadingChargedHadron_ChargedHadronsSignal_->Fill((*thePFTau).signalPFChargedHadrCands().size());
00306                 nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFChargedHadrCands().size());
00307                 nPFJet_LeadingChargedHadron_GammasSignal_->Fill((*thePFTau).signalPFGammaCands().size());                
00308                 nPFJet_LeadingChargedHadron_GammasIsolAnnulus_->Fill((*thePFTau).isolationPFGammaCands().size()); 
00309                 nPFJet_LeadingChargedHadron_NeutralHadronsSignal_->Fill((*thePFTau).signalPFNeutrHadrCands().size());    
00310                 nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFNeutrHadrCands().size());
00311               }       
00312               else if ( currentDiscriminatorLabel.find("ByIsolation") != string::npos ){
00313                 nIsolated_NoChargedNoGammas_ChargedHadronsSignal_->Fill((*thePFTau).signalPFChargedHadrCands().size());  
00314                 nIsolated_NoChargedNoGammas_GammasSignal_->Fill((*thePFTau).signalPFGammaCands().size());                
00315                 nIsolated_NoChargedNoGammas_NeutralHadronsSignal_->Fill((*thePFTau).signalPFNeutrHadrCands().size());    
00316                 nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFNeutrHadrCands().size());             
00317               }
00318             }
00319             else {
00320               break; 
00321             }
00322           }
00323       }
00324     }
00325   // ------------------------------ CaloTauCollection Matched and other discriminators ---------------------------------------------------------
00326   else if (TauProducer_.find("caloRecoTau") != string::npos)
00327     {
00328       
00329       Handle<CaloTauCollection> theCaloTauHandle;
00330       iEvent.getByLabel(TauProducer_,theCaloTauHandle);
00331       
00332       const CaloTauCollection *caloTauProduct;
00333       caloTauProduct = theCaloTauHandle.product();
00334       
00335       for (genCandidateCollection::const_iterator RefJet= ReferenceCollection->begin() ; RefJet != ReferenceCollection->end(); RefJet++ ){ 
00336         
00337         ptTauVisibleMap.find(refCollection_)->second->Fill(RefJet->pt());
00338         etaTauVisibleMap.find(refCollection_)->second->Fill(RefJet->eta());
00339         phiTauVisibleMap.find(refCollection_)->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00340         energyTauVisibleMap.find(refCollection_)->second->Fill(RefJet->energy());
00341 
00342         const reco::Candidate *gen_particle = &(*RefJet);
00343 
00344         bool trueCaloTau = false;
00345         double delta=TMath::Pi();
00346         CaloTauCollection::size_type  theCaloTauClosest=caloTauProduct->size();
00347         
00348         for (CaloTauCollection::size_type iCaloTau=0 ; iCaloTau <  caloTauProduct->size() ; iCaloTau++) 
00349           {     
00350             
00351             if (algo_->deltaR(gen_particle, & caloTauProduct->at(iCaloTau)) < delta){
00352               delta = algo_->deltaR(gen_particle, & caloTauProduct->at(iCaloTau));
00353               theCaloTauClosest = iCaloTau;
00354             }
00355             if ( delta <  matching_criteria ) {
00356               trueCaloTau=true;
00357             }
00358           }
00359 
00360         // Skip if there is no reconstructed Tau matching the Reference 
00361         if (theCaloTauClosest == caloTauProduct->size()) continue;
00362         
00363         double deltaR = algo_->deltaR(gen_particle, & caloTauProduct->at(theCaloTauClosest));
00364         
00365         // Skip if the delta R difference is larger than the required criteria
00366         if (deltaR > matching_criteria && matching_criteria != -1.0) continue;
00367         
00368         ptTauVisibleMap.find( TauProducer_+"Matched")->second->Fill(RefJet->pt());
00369         etaTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->eta());
00370         phiTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00371         energyTauVisibleMap.find(  TauProducer_+"Matched")->second->Fill(RefJet->energy());
00372         
00373         CaloTauRef theCaloTau(theCaloTauHandle,theCaloTauClosest);
00374         Handle<CaloTauDiscriminator> currentDiscriminator;
00375         
00376         for (  std::vector< edm::ParameterSet >::iterator it = discriminators_.begin(); it!= discriminators_.end();  it++)
00377           {
00378             
00379             string currentDiscriminatorLabel = it->getParameter<string>("discriminator");
00380             iEvent.getByLabel(currentDiscriminatorLabel, currentDiscriminator);       
00381             
00382             if((*currentDiscriminator)[theCaloTau] >= it->getParameter<double>("selectionCut") )
00383               {
00384                 ptTauVisibleMap.find( currentDiscriminatorLabel)->second->Fill(RefJet->pt());
00385                 etaTauVisibleMap.find( currentDiscriminatorLabel )->second->Fill(RefJet->eta());
00386                 phiTauVisibleMap.find( currentDiscriminatorLabel )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00387                 energyTauVisibleMap.find( currentDiscriminatorLabel )->second->Fill(RefJet->energy());
00388                 
00389                 if ( currentDiscriminatorLabel.find("LeadingTrackPtCut") != string::npos){
00390                   nCaloJet_LeadingTrack_signalTracksInvariantMass_->Fill((*theCaloTau).signalTracksInvariantMass());
00391                   nCaloJet_LeadingTrack_signalTracks_->Fill((*theCaloTau).signalTracks().size()); 
00392                   nCaloJet_LeadingTrack_isolationTracks_->Fill((*theCaloTau).isolationTracks().size());
00393                   nCaloJet_LeadingTrack_isolationECALhitsEtSum_->Fill((*theCaloTau).isolationECALhitsEtSum());
00394                 }
00395                 
00396                 else if ( currentDiscriminatorLabel.find("ByIsolation") != string::npos ){
00397                   nEMIsolated_signalTracksInvariantMass_->Fill((*theCaloTau).signalTracksInvariantMass());
00398                   nEMIsolated_signalTracks_->Fill((*theCaloTau).signalTracks().size());     
00399                 }
00400               }
00401             else {
00402               break; 
00403             }
00404           }     
00405       }
00406     }
00407   //------------------------------- hpsTanc (why do I need this? I don't know, the program is made this way) -----------------------------------
00408   else if ( TauProducer_.find("hpsTancTaus") != string::npos)
00409     {
00410       //cout<<"entering the hpsTancTaus section\n"<<endl;
00411       Handle<PFTauCollection> thePFTauHandle;
00412       iEvent.getByLabel(TauProducerInputTag_,thePFTauHandle);
00413       
00414       const PFTauCollection  *pfTauProduct;
00415       pfTauProduct = thePFTauHandle.product();
00416 
00417       PFTauCollection::size_type thePFTauClosest;      
00418 
00419       for (genCandidateCollection::const_iterator RefJet= ReferenceCollection->begin() ; RefJet != ReferenceCollection->end(); RefJet++ ){ 
00420 
00421         
00422         ptTauVisibleMap.find(refCollection_)->second->Fill(RefJet->pt());
00423         etaTauVisibleMap.find(refCollection_)->second->Fill(RefJet->eta());
00424         phiTauVisibleMap.find(refCollection_)->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00425         energyTauVisibleMap.find(refCollection_)->second->Fill(RefJet->energy());
00426         
00427         const reco::Candidate *gen_particle = &(*RefJet);
00428         
00429         double delta=TMath::Pi();
00430 
00431         thePFTauClosest = pfTauProduct->size();
00432 
00433         for (PFTauCollection::size_type iPFTau=0 ; iPFTau <  pfTauProduct->size() ; iPFTau++) 
00434           {                 
00435             if (algo_->deltaR(gen_particle, & pfTauProduct->at(iPFTau)) < delta){
00436               delta = algo_->deltaR(gen_particle, & pfTauProduct->at(iPFTau));
00437               thePFTauClosest = iPFTau;
00438             }
00439           }
00440         
00441         // Skip if there is no reconstructed Tau matching the Reference 
00442         if (thePFTauClosest == pfTauProduct->size()) continue;
00443         
00444         double deltaR = algo_->deltaR(gen_particle, & pfTauProduct->at(thePFTauClosest));
00445 
00446         // Skip if the delta R difference is larger than the required criteria
00447         if (deltaR > matching_criteria && matching_criteria != -1.0) continue;
00448         
00449         ptTauVisibleMap.find( TauProducer_+"Matched")->second->Fill(RefJet->pt());
00450         etaTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->eta());
00451         phiTauVisibleMap.find( TauProducer_+"Matched" )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00452         energyTauVisibleMap.find(  TauProducer_+"Matched")->second->Fill(RefJet->energy());
00453         
00454         PFTauRef thePFTau(thePFTauHandle, thePFTauClosest);
00455         Handle<PFTauDiscriminator> currentDiscriminator;
00456         
00457         for ( std::vector< edm::ParameterSet >::iterator it = discriminators_.begin(); it!= discriminators_.end();  it++) 
00458           {
00459             string currentDiscriminatorLabel = it->getParameter<string>("discriminator");             
00460             iEvent.getByLabel(currentDiscriminatorLabel, currentDiscriminator);
00461             
00462             if ((*currentDiscriminator)[thePFTau] >= it->getParameter<double>("selectionCut")){
00463               ptTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->pt());
00464               etaTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->eta());
00465               phiTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->phi()*180.0/TMath::Pi());
00466               energyTauVisibleMap.find(  currentDiscriminatorLabel )->second->Fill(RefJet->energy());
00467               
00468             }
00469             else {
00470               break; 
00471             }
00472           }
00473       }
00474     }    
00475 }
00476 
00477 
00478  
00479 
00480 // ---------------------------------------------------------------------------  endJob -----------------------------------------------------------------------
00481 
00482 void TauTagValidation::endJob(){
00483 
00484   if(saveoutputhistograms_) //USED for debugging. I keep it here in case of need ;)
00485     {
00486       cout << "dumping entries for hpsTanc"<<endl;
00487       for(std::map<std::string,MonitorElement*>::iterator mapEntry = ptTauVisibleMap.begin(); mapEntry != ptTauVisibleMap.end(); mapEntry++)
00488         if( mapEntry->first.find("hpsTancTaus") !=string::npos)    
00489           cout << mapEntry->first << "      entries:   " <<  mapEntry->second->getTH1()->GetEntries() << endl;
00490     }
00491 
00492   // just fill the denominator histograms for the changing cone sizes
00493   /*  
00494   double Denominator_Taus = nRefTaus_etaTauVisible_->getEntries();
00495   double First_Taus = nPFJet_etaTauVisible_->getEntries();
00496   double Second_Taus = nPFJet_LeadingChargedHadron_etaTauVisible_->getEntries();
00497   double Third_Taus = nIsolated_NoChargedHadrons_etaTauVisible_->getEntries();
00498   double Forth_Taus = nIsolated_NoChargedNoGammas_etaTauVisible_->getEntries();
00499    
00500   std::streamsize prec = cout.precision();
00501  
00502   cout<<setfill('-')<<setw(110)<<"-"<<endl;
00503   
00504   cout<<setfill('-')<<setw(55)<<" TAU TAG VALIDATION SUMMARY "<<setw(55)<<"-"<<endl;
00505   
00506   cout<<setfill('-')<<setw(92)<<"-"<<setfill(' ')<<setw(9)<<"Rel.Eff."<<setw(9)<<"Tot.Eff."<<endl;
00507   cout<<setfill('-')<<setw(85)<<left<<" TOTAL NUMBER OF REF OBJECTS LEVEL: ";
00508   
00509   cout<<setfill(' ')<<setw(7) <<right<< Denominator_Taus <<setw(9)<<"--"<<setw(9)<<"--"<< endl;
00510   
00511   cout<<setfill('-')<<setw(85)<<left<<" Step 1. TOTAL NUMBER OF PFJETS MATCHED TO REF COLLECTION: ";
00512   cout<<setfill(' ')<<setw(7) <<right<< First_Taus <<setw(9)<<"--";
00513   if (Denominator_Taus > 0) 
00514     cout<<setw(9)<<setprecision(3)<< First_Taus/Denominator_Taus  << setprecision(prec)<<endl;
00515   else 
00516     cout<<setw(9)<<"--"<<endl;
00517   
00518   cout<<setfill('-')<<setw(85)<<left<<" Step 2. PLUS LEADING CHARGED HADRON= 5.0 GeV: ";
00519   cout<<setfill(' ')<<setw(7)<<right<<Second_Taus;
00520   if (First_Taus > 0) 
00521     cout<<setw(9)<<setprecision(3)<< Second_Taus/First_Taus <<setprecision(prec);
00522   else
00523     cout<<setw(9)<<"--"<<endl;
00524   
00525   if (Denominator_Taus > 0)
00526     cout<<setw(9)<<setprecision(3)<< Second_Taus/Denominator_Taus  << setprecision(prec)<<endl;
00527   else 
00528     cout<<setw(9)<<"--"<<endl;
00529 
00530   
00531  
00532   cout<<setfill('-')<<setw(85)<<left<<" Step 3. PLUS CHARGED HADRON ISOLATION: ";
00533   cout<<setfill(' ')<<setw(7) <<right<<Third_Taus;
00534   if (Second_Taus > 0) 
00535     cout<<setw(9)<<setprecision(3)<< Third_Taus/Second_Taus <<setprecision(prec);
00536   else
00537     cout<<setw(9)<<"--"<<endl;
00538   
00539   if (Denominator_Taus > 0)
00540     cout<<setw(9)<<setprecision(3)<< Third_Taus/Denominator_Taus  << setprecision(prec)<<endl;
00541   else 
00542     cout<<setw(9)<<"--"<<endl;
00543 
00544   //  cout<<setfill('-')<<setw(110)<<"-"<<endl;
00545 
00546   cout<<setfill('-')<<setw(85)<<left<<" Step 4. PLUS GAMMA ISOLATION: ";
00547   cout<<setfill(' ')<<setw(7) <<right<<Forth_Taus;
00548   if (Third_Taus > 0) 
00549     cout<<setw(9)<<setprecision(3)<< Forth_Taus/Third_Taus <<setprecision(prec);
00550   else
00551     cout<<setw(9)<<"--"<<endl;
00552   
00553   if (Denominator_Taus > 0)
00554     cout<<setw(9)<<setprecision(3)<< Forth_Taus/Denominator_Taus  << setprecision(prec)<<endl;
00555   else 
00556     cout<<setw(9)<<"--"<<endl;
00557 
00558     cout<<setfill('-')<<setw(110)<<"-"<<endl; 
00559   */
00560 
00561   if (!outPutFile_.empty() && &*edm::Service<DQMStore>() && saveoutputhistograms_) dbeTau->save (outPutFile_);
00562   
00563 }
00564 
00565