CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTriggerOffline/Tau/src/L2TauAnalyzer.cc

Go to the documentation of this file.
00001 #include "HLTriggerOffline/Tau/interface/L2TauAnalyzer.h"
00002 #include "Math/GenVector/VectorUtil.h"
00003 #include <iostream>
00004 #include <iomanip>
00005 #include <fstream>
00006 
00007 L2TauAnalyzer::L2TauAnalyzer(const edm::ParameterSet& iConfig):
00008  l2TauInfoAssoc_(iConfig.getParameter<edm::InputTag>("L2InfoAssociationInput")),
00009  l1Taus_(iConfig.getParameter<edm::InputTag>("L1TauCollection")),
00010  l1Jets_(iConfig.getParameter<edm::InputTag>("L1JetCollection")),
00011  rootFile_(iConfig.getParameter<std::string>("outputFileName")),
00012  IsSignal_(iConfig.getParameter<bool>("IsSignal")),
00013  mcColl_(iConfig.getParameter<edm::InputTag>("MatchedCollection"))
00014 {
00015   //File Setup
00016   l2file = new TFile(rootFile_.c_str(),"recreate");
00017   //Tree Setup
00018   l2tree = new TTree("l2tree","Level 2 Tau Tree");
00019 
00020 
00021   //Initialize the vars
00022   ecalIsol_Et=0.;
00023   towerIsol_Et=0.;
00024   cl_etaRMS=0.;
00025   cl_phiRMS=0.;
00026   cl_drRMS=0.;
00027   MCeta=0.;
00028   MCet=0.;
00029   cl_Nclusters=0;
00030   seedTowerEt = 0.;
00031   JetEt=0.;
00032   JetEta=0.;
00033   L1et=0.;
00034   L1eta=0.;
00035   jetEMF = 0.;
00036 
00037   //Setup Branches
00038   l2tree->Branch("ecalIsolEt",&ecalIsol_Et,"ecalIsolEt/F");
00039   l2tree->Branch("jetEMF",&jetEMF,"jetEMF/F");
00040   l2tree->Branch("towerIsolEt",&towerIsol_Et,"towerIsolEt/F");
00041   l2tree->Branch("clEtaRMS",&cl_etaRMS,"clEtaRMS/F");
00042   l2tree->Branch("clPhiRMS",&cl_phiRMS,"clPhiRMS/F");
00043   l2tree->Branch("clDrRMS",&cl_drRMS,"clDrRMS/F");
00044   l2tree->Branch("mcEta",&MCeta,"mcEta/F");
00045   l2tree->Branch("mcEt",&MCet,"mcEt/F");
00046   l2tree->Branch("clNclusters",&cl_Nclusters,"clNclusters/I");
00047   l2tree->Branch("seedTowerEt",&seedTowerEt,"seedTowerEt/F");
00048   l2tree->Branch("jetEt",&JetEt,"jetEt/F");
00049   l2tree->Branch("jetEta",&JetEta,"jetEta/F");
00050   l2tree->Branch("L1Et",&L1et,"L1Et/F");
00051   l2tree->Branch("L1Eta",&L1eta,"L1Eta/F");
00052  
00053 }
00054 
00055 
00056 L2TauAnalyzer::~L2TauAnalyzer()
00057 {
00058 }
00059 
00060 
00061 
00062 void
00063 L2TauAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00064 {
00065    using namespace edm;
00066    using namespace reco;
00067 
00068    Handle<L2TauInfoAssociation> l2TauInfoAssoc; //Handle to the input (L2 Tau Info Association)
00069    Handle<LVColl> McInfo; //Handle To The Truth!!!!
00070    Handle<l1extra::L1JetParticleCollection> L1Taus; //Handle To The L1 Taus
00071    Handle<l1extra::L1JetParticleCollection> L1Jets; //Handle To The L1 jets
00072 
00073         if(iEvent.getByLabel(l2TauInfoAssoc_,l2TauInfoAssoc))//get the handle
00074           {
00075             if(l2TauInfoAssoc->size()>0)
00076               for(L2TauInfoAssociation::const_iterator p = l2TauInfoAssoc->begin();p!=l2TauInfoAssoc->end();++p)
00077                 {
00078                   const L2TauIsolationInfo l2info = p->val;
00079                   const CaloJet& jet =*(p->key);
00080        
00081                   MatchElementL2 mcMatch;
00082                   mcMatch.matched=false;
00083                   mcMatch.mcEt=0;
00084                   mcMatch.mcEta=0;
00085                   mcMatch.deltar=0;
00086 
00087                   if(IsSignal_) //Get Collection and match it
00088                     {
00089                       if(iEvent.getByLabel(mcColl_,McInfo))
00090                           mcMatch=match(jet,*McInfo);
00091                     }
00092 
00093                   if((mcMatch.matched&&IsSignal_)||(!IsSignal_))
00094                     {
00095                       //Fill variables
00096                       jetEMF = jet.emEnergyFraction();
00097                       ecalIsol_Et=l2info.ecalIsolEt();
00098                       towerIsol_Et=l2info.hcalIsolEt();
00099                       cl_Nclusters=l2info.nEcalHits();
00100                       cl_etaRMS=l2info.ecalClusterShape()[0];
00101                       cl_phiRMS=l2info.ecalClusterShape()[1];
00102                       cl_drRMS=l2info.ecalClusterShape()[2];
00103                       seedTowerEt = l2info.seedHcalHitEt();
00104                       MCeta =mcMatch.mcEta;
00105                       MCet=mcMatch.mcEt;
00106                       JetEt = jet.et();
00107                       JetEta = jet.eta();
00108 
00109                       //Match with L1 and fill
00110                       L1et=0;
00111                       L1eta=0;
00112                       if(iEvent.getByLabel(l1Taus_,L1Taus))
00113                         {
00114                             MatchElementL2 l1Match;
00115                             l1Match.matched=false;
00116                             l1Match.mcEt=0;
00117                             l1Match.mcEta=0;
00118                             l1Match.deltar=0;
00119                             l1Match=match(jet,*L1Taus);
00120                             if(l1Match.matched)
00121                               {
00122                                 L1et=l1Match.mcEt;
00123                                 L1eta=l1Match.mcEta;
00124                               }
00125                             //If not matched look at the jet collection
00126                             else
00127                               {
00128                                 if(iEvent.getByLabel(l1Jets_,L1Jets))
00129                                   {
00130                                     l1Match=match(jet,*L1Taus);
00131                                     if(l1Match.matched)
00132                                       {
00133                                         L1et=l1Match.mcEt;
00134                                         L1eta=l1Match.mcEta;
00135                                       }
00136 
00137                                   }
00138                               }
00139 
00140                         }
00141                       //Fill Tree
00142                       l2tree->Fill();
00143                     }
00144            
00145                 }
00146           } 
00147 }
00148 
00149 
00150 
00151 void 
00152 L2TauAnalyzer::beginJob()
00153 {
00154 
00155 }
00156 
00157 
00158 void 
00159 L2TauAnalyzer::endJob() {
00160   l2file->Write();
00161 
00162 }
00163 
00164 MatchElementL2 
00165 L2TauAnalyzer::match(const reco::Jet& jet,const LVColl& McInfo)
00166 {
00167 
00168   //Loop On the Collection and see if your tau jet is matched to one there
00169  //Also find the nearest Matched MC Particle to your Jet (to be complete)
00170  
00171  bool matched=false;
00172  double delta_min=100.;
00173  double mceta=0;
00174  double mcet=0;
00175  
00176  double matchingDR=0.3;
00177 
00178 
00179 
00180 
00181  if(McInfo.size()>0)
00182   for(std::vector<LV>::const_iterator it = McInfo.begin();it!=McInfo.end();++it)
00183    {
00184           double delta = ROOT::Math::VectorUtil::DeltaR(jet.p4().Vect(),*it);
00185           if(delta<matchingDR)
00186             {
00187               matched=true;
00188               if(delta<delta_min)
00189                 {
00190                   delta_min=delta;
00191                   mceta=it->eta();
00192                   mcet=it->Et();
00193                 }
00194             }
00195    }
00196 
00197   //Create Struct and send it out!
00198   MatchElementL2 match;
00199   match.matched=matched;
00200   match.deltar=delta_min;
00201   match.mcEta = mceta;
00202   match.mcEt = mcet;
00203 
00204 
00205  return match;
00206 }
00207 
00208 MatchElementL2 
00209 L2TauAnalyzer::match(const reco::Jet& jet,const l1extra::L1JetParticleCollection& McInfo)
00210 {
00211 
00212   //Loop On the Collection and see if your tau jet is matched to one there
00213  //Also find the nearest Matched MC Particle to your Jet (to be complete)
00214  
00215  bool matched=false;
00216  double delta_min=100.;
00217  double mceta=0;
00218  double mcet=0;
00219  
00220  double matchingDR=0.5;
00221 
00222 
00223 
00224 
00225  if(McInfo.size()>0)
00226   for(l1extra::L1JetParticleCollection::const_iterator it = McInfo.begin();it!=McInfo.end();++it)
00227    {
00228           double delta = ROOT::Math::VectorUtil::DeltaR(jet.p4().Vect(),it->p4().Vect());
00229           if(delta<matchingDR)
00230             {
00231               matched=true;
00232               if(delta<delta_min)
00233                 {
00234                   delta_min=delta;
00235                   mceta=it->eta();
00236                   mcet=it->et();
00237                 }
00238             }
00239    }
00240 
00241   //Create Struct and send it out!
00242   MatchElementL2 match;
00243   match.matched=matched;
00244   match.deltar=delta_min;
00245   match.mcEta = mceta;
00246   match.mcEt = mcet;
00247 
00248 
00249  return match;
00250 }
00251 
00252 
00253 
00254 
00255