CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoTauTag/HLTProducers/src/L2TauIsolationProducer.cc

Go to the documentation of this file.
00001 #include "RecoTauTag/HLTProducers/interface/L2TauIsolationProducer.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 L2TauIsolationProducer::L2TauIsolationProducer(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   crystalThreshold_(iConfig.getParameter<double>("crystalThreshold")),
00013   towerThreshold_(iConfig.getParameter<double>("towerThreshold"))
00014  {
00015         
00016   //ECAL Isolation
00017   edm::ParameterSet ECALIsolParams = iConfig.getParameter<edm::ParameterSet>("ECALIsolation") ;
00018     
00019   ECALIsolation_innerCone_ =  ECALIsolParams.getParameter<double>( "innerCone" );
00020   ECALIsolation_outerCone_ =  ECALIsolParams.getParameter<double>( "outerCone" );
00021   ECALIsolation_run_       =  ECALIsolParams.getParameter<bool>( "runAlgorithm" );
00022   
00023 
00024   //ECAL Clustering
00025   edm::ParameterSet ECALClusterParams = iConfig.getParameter<edm::ParameterSet>("ECALClustering") ;
00026 
00027   ECALClustering_run_                 =  ECALClusterParams.getParameter<bool>( "runAlgorithm" );
00028   ECALClustering_clusterRadius_       =  ECALClusterParams.getParameter<double>( "clusterRadius" );
00029     
00030 
00031   //Tower Isolation
00032   edm::ParameterSet TowerIsolParams = iConfig.getParameter<edm::ParameterSet>("TowerIsolation") ;
00033   TowerIsolation_innerCone_         =  TowerIsolParams.getParameter<double>( "innerCone" );
00034   TowerIsolation_outerCone_         =  TowerIsolParams.getParameter<double>( "outerCone" );
00035   TowerIsolation_run_               =  TowerIsolParams.getParameter<bool>( "runAlgorithm" );
00036  
00037 
00038   //Add the products
00039   produces<L2TauInfoAssociation>();
00040 
00041 }
00042 
00043 
00044 L2TauIsolationProducer::~L2TauIsolationProducer()
00045 {
00046   //Destruction
00047 
00048 }
00049 
00050 
00051 
00052 void
00053 L2TauIsolationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00054 {
00055 
00056 
00057    edm::Handle<CaloJetCollection> l2CaloJets; //Handle to the input (L2TauCaloJets);
00058    iEvent.getByLabel(l2CaloJets_ ,l2CaloJets);//get the handle
00059 
00060    //Create the Association
00061    std::auto_ptr<L2TauInfoAssociation> l2InfoAssoc( new L2TauInfoAssociation);
00062 
00063    //If the JetCrystalsAssociation exists -> RUN The Producer
00064    if(l2CaloJets->size()>0)
00065      {
00066       CaloJetCollection::const_iterator jcStart = l2CaloJets->begin();
00067 
00068        //Loop on Jets
00069        for(CaloJetCollection::const_iterator jc = jcStart ;jc!=l2CaloJets->end();++jc)
00070          {
00071 
00072            //Create Algorithm Object
00073            L2TauIsolationAlgs alg;
00074            
00075            //Create Info Object
00076            L2TauIsolationInfo info; 
00077 
00078            //get Hits
00079            math::PtEtaPhiELorentzVectorCollection hitsECAL = getECALHits(*jc,iEvent,iSetup);
00080            math::PtEtaPhiELorentzVectorCollection hitsHCAL = getHCALHits(*jc);
00081 
00082 
00083            //Run ECALIsolation 
00084            if(ECALIsolation_run_)
00085              {
00086                info.setEcalIsolEt( alg.isolatedEt(hitsECAL , jc->p4().Vect(), ECALIsolation_innerCone_,ECALIsolation_outerCone_) );
00087                if(hitsECAL.size()>0)
00088                  info.setSeedEcalHitEt(hitsECAL[0].pt());
00089              }
00090 
00091            //Run ECALClustering 
00092            if(ECALClustering_run_)
00093              {
00094                //load simple clustering algorithm
00095                L2TauSimpleClustering clustering(ECALClustering_clusterRadius_);
00096                math::PtEtaPhiELorentzVectorCollection clusters = clustering.clusterize(hitsECAL);
00097                info.setEcalClusterShape(alg.clusterShape(clusters,jc->p4().Vect(),0,0.5) );
00098                info.setNEcalHits(clusters.size());
00099              }
00100 
00101            //Run CaloTower Isolation
00102            if(TowerIsolation_run_)
00103              {
00104                info.setHcalIsolEt( alg.isolatedEt(hitsHCAL , jc->p4().Vect(), TowerIsolation_innerCone_,TowerIsolation_outerCone_) );
00105                if(hitsHCAL.size()>0)
00106                  info.setSeedHcalHitEt(hitsHCAL[0].pt());
00107              }
00108 
00109            //Store the info Class
00110            edm::Ref<CaloJetCollection> jcRef(l2CaloJets,jc-jcStart);
00111            l2InfoAssoc->insert(jcRef, info);
00112          }
00113 
00114      
00115      } //end of if(*jetCrystalsObj)
00116 
00117     iEvent.put(l2InfoAssoc);
00118 }
00119 
00120 
00121 void 
00122 L2TauIsolationProducer::beginJob()
00123 {
00124 }
00125 
00126 
00127 void 
00128 L2TauIsolationProducer::endJob() {
00129 }
00130 
00131 
00132 
00133 math::PtEtaPhiELorentzVectorCollection 
00134 L2TauIsolationProducer::getHCALHits(const CaloJet& jet)
00135 {
00136 
00137 
00138   std::vector<CaloTowerPtr> towers = jet.getCaloConstituents();
00139 
00140   math::PtEtaPhiELorentzVectorCollection towers2;
00141 
00142   for(size_t i=0;i<towers.size();++i)
00143     if(towers[i]->energy()>towerThreshold_)
00144       towers2.push_back(math::PtEtaPhiELorentzVector(towers[i]->et(),towers[i]->eta(),towers[i]->phi(),towers[i]->energy()));
00145 
00146   return towers2;
00147 }
00148 
00149 
00150 
00151 
00152 
00153 math::PtEtaPhiELorentzVectorCollection 
00154 L2TauIsolationProducer::getECALHits(const CaloJet& jet,const edm::Event& iEvent,const edm::EventSetup& iSetup)
00155 {
00156 
00157   //Init Geometry
00158   edm::ESHandle<CaloGeometry> geometry;
00159   iSetup.get<CaloGeometryRecord>().get(geometry);
00160 
00161   //Create ECAL Geometry
00162   const CaloSubdetectorGeometry* EB = geometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
00163   const CaloSubdetectorGeometry* EE = geometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
00164 
00165   //Handle To the ECAL
00166   edm::Handle<EBRecHitCollection> EBRecHits;
00167   edm::Handle<EERecHitCollection> EERecHits;
00168 
00169   //Read From File
00170  
00171   iEvent.getByLabel( EBRecHits_, EBRecHits );
00172   iEvent.getByLabel( EERecHits_, EERecHits );
00173   
00174  
00175 
00176   //Create a container for the hits
00177   math::PtEtaPhiELorentzVectorCollection jetRecHits;
00178 
00179 
00180   //Create the Machinery to put the highest et crystal at the begining
00181   double ref_pt = 0.;//max et
00182   int ref_id=0; //id of the max element
00183   int count=0; //counter
00184 
00185   //Code Copied from JetCrystalsAssociator    
00186       const std::vector<CaloTowerPtr>  myTowers=jet.getCaloConstituents();
00187         for (unsigned int iTower = 0; iTower < myTowers.size(); iTower++)
00188         {
00189           CaloTowerPtr theTower = myTowers[iTower];
00190           size_t numRecHits = theTower->constituentsSize();
00191           // access CaloRecHits
00192           for (size_t j = 0; j < numRecHits; j++) {
00193             DetId RecHitDetID=theTower->constituent(j);
00194             DetId::Detector DetNum=RecHitDetID.det();
00195             if( DetNum == DetId::Ecal ){
00196               int EcalNum =  RecHitDetID.subdetId();
00197               if( EcalNum == 1 ){
00198                 EBDetId EcalID = RecHitDetID;
00199                 EBRecHitCollection::const_iterator theRecHit=EBRecHits->find(EcalID);
00200                 if(theRecHit != EBRecHits->end()){
00201                   DetId id = theRecHit->detid();
00202                   const CaloCellGeometry* this_cell = EB->getGeometry(id);
00203                   if (this_cell) {
00204                     GlobalPoint posi = this_cell->getPosition();
00205                     double energy = theRecHit->energy();
00206                     double eta = posi.eta();
00207                     double phi = posi.phi();
00208                     double theta = posi.theta();
00209                     if(theta > M_PI) theta = 2 * M_PI- theta;
00210                     double et = energy * sin(theta);
00211                     //Apply Thresholds Here
00212                     math::PtEtaPhiELorentzVector p(et, eta, phi, energy);
00213                      if(p.pt()>crystalThreshold_)
00214                       { 
00215                         if(p.pt()>ref_pt)
00216                          {
00217                            ref_id=count;
00218                            ref_pt = p.pt();
00219                          }
00220                         jetRecHits.push_back(p);
00221                         count++;
00222                       }
00223                     
00224                   }
00225                 }
00226               } else if ( EcalNum == 2 ) {
00227                 EEDetId EcalID = RecHitDetID;
00228                 EERecHitCollection::const_iterator theRecHit=EERecHits->find(EcalID);    
00229                 if(theRecHit != EBRecHits->end()){
00230                   DetId id = theRecHit->detid();
00231                   const CaloCellGeometry* this_cell = EE->getGeometry(id);
00232                   if (this_cell) {
00233                     GlobalPoint posi = this_cell->getPosition();
00234                     double energy = theRecHit->energy();
00235                     double eta = posi.eta();
00236                     double phi = posi.phi();
00237                     double theta = posi.theta();
00238                     if (theta > M_PI) theta = 2 * M_PI - theta;
00239                     double et = energy * sin(theta);
00240                     // std::cout <<"Et "<<et<<std::endl;
00241                     math::PtEtaPhiELorentzVector p(et, eta, phi, energy);
00242                      if(p.pt()>crystalThreshold_)
00243                       { 
00244                         if(p.pt()>ref_pt)
00245                          {
00246                            ref_id=count;
00247                            ref_pt = p.pt();
00248                          }
00249                         jetRecHits.push_back(p);
00250                         count++;
00251                       }
00252                   }
00253                 }
00254               }
00255             }
00256           }
00257         }
00258 
00259         //bring it to the front
00260         if(jetRecHits.size()>0)
00261           std::swap(jetRecHits[ref_id],jetRecHits[0]);
00262 
00263         return jetRecHits;
00264 }
00265      
00266 
00267 
00268