CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTauTag/HLTProducers/src/L2TauNarrowConeIsolationProducer.cc

Go to the documentation of this file.
00001 #include "RecoTauTag/HLTProducers/interface/L2TauNarrowConeIsolationProducer.h"
00002 #include "RecoTauTag/HLTProducers/interface/L2TauIsolationAlgs.h"
00003 #include "RecoTauTag/HLTProducers/interface/L2TauSimpleClustering.h"
00004 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00005 
00006 using namespace reco;
00007 
00008 L2TauNarrowConeIsolationProducer::L2TauNarrowConeIsolationProducer(const edm::ParameterSet& iConfig):
00009   l2CaloJets_(iConfig.getParameter<edm::InputTag>("L2TauJetCollection")),
00010   EBRecHits_(iConfig.getParameter<edm::InputTag>("EBRecHits")),
00011   EERecHits_(iConfig.getParameter<edm::InputTag>("EERecHits")),
00012   CaloTowers_(iConfig.getParameter<edm::InputTag>("CaloTowers")),
00013   associationRadius_(iConfig.getParameter<double>("associationRadius")),
00014   crystalThresholdE_(iConfig.getParameter<double>("crystalThresholdEE")),
00015   crystalThresholdB_(iConfig.getParameter<double>("crystalThresholdEB")),
00016   towerThreshold_(iConfig.getParameter<double>("towerThreshold"))
00017  {
00018         
00019   //ECAL Isolation
00020   edm::ParameterSet ECALIsolParams = iConfig.getParameter<edm::ParameterSet>("ECALIsolation") ;
00021   ECALIsolation_innerCone_ =  ECALIsolParams.getParameter<double>( "innerCone" );
00022   ECALIsolation_outerCone_ =  ECALIsolParams.getParameter<double>( "outerCone" );
00023   ECALIsolation_run_       =  ECALIsolParams.getParameter<bool>( "runAlgorithm" );
00024 
00025   //ECAL Clustering
00026   edm::ParameterSet ECALClusterParams = iConfig.getParameter<edm::ParameterSet>("ECALClustering") ;
00027   ECALClustering_run_                 =  ECALClusterParams.getParameter<bool>( "runAlgorithm" );
00028   ECALClustering_clusterRadius_       =  ECALClusterParams.getParameter<double>( "clusterRadius" );
00029     
00030   //Tower Isolation
00031   edm::ParameterSet TowerIsolParams = iConfig.getParameter<edm::ParameterSet>("TowerIsolation") ;
00032   TowerIsolation_innerCone_         =  TowerIsolParams.getParameter<double>( "innerCone" );
00033   TowerIsolation_outerCone_         =  TowerIsolParams.getParameter<double>( "outerCone" );
00034   TowerIsolation_run_               =  TowerIsolParams.getParameter<bool>( "runAlgorithm" );
00035  
00036 
00037   //Add the products
00038   produces<L2TauInfoAssociation>();
00039 
00040 }
00041 
00042 
00043 L2TauNarrowConeIsolationProducer::~L2TauNarrowConeIsolationProducer()
00044 {
00045   //Destruction
00046 
00047 }
00048 
00049 
00050 
00051 void
00052 L2TauNarrowConeIsolationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00053 {
00054 
00055 
00056    edm::Handle<CaloJetCollection> l2CaloJets; //Handle to the input (L2TauCaloJets);
00057    iEvent.getByLabel(l2CaloJets_ ,l2CaloJets);//get the handle
00058 
00059    //Create the Association
00060    std::auto_ptr<L2TauInfoAssociation> l2InfoAssoc( new L2TauInfoAssociation);
00061 
00062    //If the JetCrystalsAssociation exists -> RUN The Producer
00063    if(l2CaloJets->size()>0)
00064      {
00065       CaloJetCollection::const_iterator jcStart = l2CaloJets->begin();
00066        //Loop on Jets
00067        for(CaloJetCollection::const_iterator jc = jcStart ;jc!=l2CaloJets->end();++jc)
00068          {
00069            //Create Algorithm Object
00070            L2TauIsolationAlgs alg;
00071            
00072            //Create Info Object
00073            L2TauIsolationInfo info; 
00074 
00075            //get Hits
00076            math::PtEtaPhiELorentzVectorCollection hitsECAL = getECALHits(*jc,iEvent,iSetup);
00077            math::PtEtaPhiELorentzVectorCollection hitsHCAL = getHCALHits(*jc,iEvent);
00078 
00079 
00080 
00081            //Run ECALIsolation 
00082            if(ECALIsolation_run_)
00083              {
00084                info.setEcalIsolEt( alg.isolatedEt(hitsECAL , jc->p4().Vect(), ECALIsolation_innerCone_,ECALIsolation_outerCone_) );
00085                if(hitsECAL.size()>0)
00086                  info.setSeedEcalHitEt(hitsECAL[0].pt());
00087              }
00088 
00089            //Run ECALClustering 
00090            if(ECALClustering_run_)
00091              {
00092                //load simple clustering algorithm
00093                L2TauSimpleClustering clustering(ECALClustering_clusterRadius_);
00094                math::PtEtaPhiELorentzVectorCollection clusters = clustering.clusterize(hitsECAL);
00095                info.setEcalClusterShape(alg.clusterShape(clusters,jc->p4().Vect(),0,0.5) );
00096                info.setNEcalHits(clusters.size());
00097              }
00098 
00099            //Run CaloTower Isolation
00100            if(TowerIsolation_run_)
00101              {
00102                info.setHcalIsolEt( alg.isolatedEt(hitsHCAL , jc->p4().Vect(), TowerIsolation_innerCone_,TowerIsolation_outerCone_) );
00103                if(hitsHCAL.size()>0)
00104                  info.setSeedHcalHitEt(hitsHCAL[0].pt());
00105              }
00106 
00107            //Store the info Class
00108            edm::Ref<CaloJetCollection> jcRef(l2CaloJets,jc-jcStart);
00109            l2InfoAssoc->insert(jcRef, info);
00110          }
00111 
00112      } //end of if(*jetCrystalsObj)
00113 
00114     iEvent.put(l2InfoAssoc);
00115 }
00116 
00117 
00118 void 
00119 L2TauNarrowConeIsolationProducer::beginJob()
00120 {
00121 }
00122 
00123 
00124 void 
00125 L2TauNarrowConeIsolationProducer::endJob() {
00126 }
00127 
00128 
00129 
00130 math::PtEtaPhiELorentzVectorCollection 
00131 L2TauNarrowConeIsolationProducer::getHCALHits(const CaloJet& jet,const edm::Event& iEvent)
00132 {
00133   edm::Handle<CaloTowerCollection> towers;
00134   math::PtEtaPhiELorentzVectorCollection towers2;
00135 
00136   if(iEvent.getByLabel(CaloTowers_,towers))
00137     for(size_t i=0;i<towers->size();++i)
00138       {
00139         math::PtEtaPhiELorentzVector tower((*towers)[i].et(),(*towers)[i].eta(),(*towers)[i].phi(),(*towers)[i].energy());
00140         if(ROOT::Math::VectorUtil::DeltaR(tower,jet.p4()) <associationRadius_)
00141           {
00142             if(tower.energy()>towerThreshold_)
00143               towers2.push_back(tower);
00144 
00145           }       
00146 
00147       }
00148 
00149  std::sort(towers2.begin(),towers2.end(),comparePt);
00150 
00151   return towers2;
00152 }
00153 
00154 
00155 math::PtEtaPhiELorentzVectorCollection 
00156 L2TauNarrowConeIsolationProducer::getECALHits(const CaloJet& jet,const edm::Event& iEvent,const edm::EventSetup& iSetup)
00157 {
00158   //Init Geometry
00159   edm::ESHandle<CaloGeometry> geometry;
00160   iSetup.get<CaloGeometryRecord>().get(geometry);
00161 
00162   //Create ECAL Geometry
00163   const CaloSubdetectorGeometry* EB = geometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
00164   const CaloSubdetectorGeometry* EE = geometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
00165 
00166   //Handle To the ECAL
00167   edm::Handle<EBRecHitCollection> EBRecHits;
00168   edm::Handle<EERecHitCollection> EERecHits;
00169 
00170   //Create a container for the hits
00171   math::PtEtaPhiELorentzVectorCollection jetRecHits;
00172 
00173   //Loop on the barrel hits
00174   if(iEvent.getByLabel( EBRecHits_, EBRecHits))
00175      for(EBRecHitCollection::const_iterator hit = EBRecHits->begin();hit!=EBRecHits->end();++hit)
00176        {
00177          //get Detector Geometry
00178          const CaloCellGeometry* this_cell = EB->getGeometry(hit->detid());
00179          GlobalPoint posi = this_cell->getPosition();
00180          double energy = hit->energy();
00181          double eta = posi.eta();
00182          double phi = posi.phi();
00183          double theta = posi.theta();
00184          if(theta > M_PI) theta = 2 * M_PI- theta;
00185          double et = energy * sin(theta);
00186          math::PtEtaPhiELorentzVector p(et, eta, phi, energy);
00187          if(ROOT::Math::VectorUtil::DeltaR(p,jet.p4()) <associationRadius_)
00188            if(p.energy()>crystalThresholdB_)
00189              jetRecHits.push_back(p);
00190        }
00191 
00192  if(iEvent.getByLabel( EERecHits_, EERecHits))
00193      for(EERecHitCollection::const_iterator hit = EERecHits->begin();hit!=EERecHits->end();++hit)
00194        {
00195          //get Detector Geometry
00196          const CaloCellGeometry* this_cell = EE->getGeometry(hit->detid());
00197          GlobalPoint posi = this_cell->getPosition();
00198          double energy = hit->energy();
00199          double eta = posi.eta();
00200          double phi = posi.phi();
00201          double theta = posi.theta();
00202          if(theta > M_PI) theta = 2 * M_PI- theta;
00203          double et = energy * sin(theta);
00204          math::PtEtaPhiELorentzVector p(et, eta, phi, energy);
00205          if(ROOT::Math::VectorUtil::DeltaR(p,jet.p4()) < associationRadius_)
00206            if(p.energy()>crystalThresholdE_)
00207              jetRecHits.push_back(p);
00208        }
00209 
00210 
00211  std::sort(jetRecHits.begin(),jetRecHits.end(),comparePt);
00212 
00213  return jetRecHits;
00214 }
00215 
00216 
00217