CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/special/src/HLTEcalResonanceFilter.cc

Go to the documentation of this file.
00001 #include "HLTrigger/special/interface/HLTEcalResonanceFilter.h"
00002 
00003 using namespace std;
00004 using namespace edm;
00005 
00006 
00007 HLTEcalResonanceFilter::HLTEcalResonanceFilter(const edm::ParameterSet& iConfig)
00008 {
00009   
00010   
00011   barrelHits_ = iConfig.getParameter< edm::InputTag > ("barrelHits");
00012   barrelClusters_ = iConfig.getParameter< edm::InputTag > ("barrelClusters");
00013   
00014   endcapHits_ = iConfig.getParameter< edm::InputTag > ("endcapHits");
00015   endcapClusters_ = iConfig.getParameter< edm::InputTag > ("endcapClusters");
00016   
00017   doSelBarrel_ = iConfig.getParameter<bool>("doSelBarrel");  
00018   if(doSelBarrel_){
00019     edm::ParameterSet barrelSelection = iConfig.getParameter<edm::ParameterSet>( "barrelSelection" );
00020     
00022     selePtGamma_ = barrelSelection.getParameter<double> ("selePtGamma");  
00023     selePtPair_ = barrelSelection.getParameter<double> ("selePtPair");   
00024     seleS4S9Gamma_ = barrelSelection.getParameter<double> ("seleS4S9Gamma");  
00025     seleS9S25Gamma_ = barrelSelection.getParameter<double> ("seleS9S25Gamma");  
00026     seleMinvMaxBarrel_ = barrelSelection.getParameter<double> ("seleMinvMaxBarrel");  
00027     seleMinvMinBarrel_ = barrelSelection.getParameter<double> ("seleMinvMinBarrel");  
00028     ptMinForIsolation_ = barrelSelection.getParameter<double> ("ptMinForIsolation");
00029     removePi0CandidatesForEta_ = barrelSelection.getParameter<bool>("removePi0CandidatesForEta");
00030     if(removePi0CandidatesForEta_){
00031       massLowPi0Cand_ = barrelSelection.getParameter<double>("massLowPi0Cand");
00032       massHighPi0Cand_ = barrelSelection.getParameter<double>("massHighPi0Cand");
00033     }
00034     seleIso_ = barrelSelection.getParameter<double> ("seleIso");  
00035     ptMinForIsolation_ = barrelSelection.getParameter<double> ("ptMinForIsolation");
00036     seleBeltDR_ = barrelSelection.getParameter<double> ("seleBeltDR");  
00037     seleBeltDeta_ = barrelSelection.getParameter<double> ("seleBeltDeta");  
00038     
00039     store5x5RecHitEB_ = barrelSelection.getParameter<bool> ("store5x5RecHitEB");
00040     BarrelHits_ = barrelSelection.getParameter<string > ("barrelHitCollection");
00041     
00042     produces< EBRecHitCollection >(BarrelHits_);
00043     
00044   }
00045   
00046   
00047   doSelEndcap_ = iConfig.getParameter<bool>("doSelEndcap");  
00048   if(doSelEndcap_){
00049     edm::ParameterSet endcapSelection = iConfig.getParameter<edm::ParameterSet>( "endcapSelection" );
00050     
00052     seleMinvMaxEndCap_ = endcapSelection.getParameter<double> ("seleMinvMaxEndCap");  
00053     seleMinvMinEndCap_ = endcapSelection.getParameter<double> ("seleMinvMinEndCap");
00054     
00055     region1_EndCap_ = endcapSelection.getParameter<double> ("region1_EndCap");
00056     selePtGammaEndCap_region1_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region1");  
00057     selePtPairEndCap_region1_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region1");   
00058     
00059     region2_EndCap_ = endcapSelection.getParameter<double> ("region2_EndCap");
00060     selePtGammaEndCap_region2_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region2");  
00061     selePtPairEndCap_region2_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region2");   
00062     
00063     selePtGammaEndCap_region3_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region3");  
00064     selePtPairEndCap_region3_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region3");
00065     selePtPairMaxEndCap_region3_ = endcapSelection.getParameter<double> ("selePtPairMaxEndCap_region3");
00066     
00067 
00068     seleS4S9GammaEndCap_ = endcapSelection.getParameter<double> ("seleS4S9GammaEndCap");  
00069     seleS9S25GammaEndCap_ = endcapSelection.getParameter<double> ("seleS9S25GammaEndCap");  
00070     ptMinForIsolationEndCap_ = endcapSelection.getParameter<double> ("ptMinForIsolationEndCap");
00071     seleBeltDREndCap_ = endcapSelection.getParameter<double> ("seleBeltDREndCap");  
00072     seleBeltDetaEndCap_ = endcapSelection.getParameter<double> ("seleBeltDetaEndCap");  
00073     seleIsoEndCap_ = endcapSelection.getParameter<double> ("seleIsoEndCap");  
00074     
00075     store5x5RecHitEE_ = endcapSelection.getParameter<bool> ("store5x5RecHitEE");
00076     EndcapHits_ = endcapSelection.getParameter<string > ("endcapHitCollection");
00077     produces< EERecHitCollection >(EndcapHits_);
00078     
00079     
00080   }
00081   
00082   
00083   useRecoFlag_ = iConfig.getParameter<bool>("useRecoFlag");
00084   flagLevelRecHitsToUse_ = iConfig.getParameter<int>("flagLevelRecHitsToUse"); 
00085   
00086   useDBStatus_ = iConfig.getParameter<bool>("useDBStatus");
00087   statusLevelRecHitsToUse_ = iConfig.getParameter<int>("statusLevelRecHitsToUse"); 
00088   
00089   
00090   preshHitProducer_   = iConfig.getParameter<edm::InputTag>("preshRecHitProducer");
00092   storeRecHitES_ = iConfig.getParameter<bool>("storeRecHitES");  
00093   if(storeRecHitES_){
00094 
00095     edm::ParameterSet preshowerSelection = iConfig.getParameter<edm::ParameterSet>( "preshowerSelection" );
00096     
00097     // maximum number of matched ES clusters (in each ES layer) to each BC
00098     preshNclust_             = preshowerSelection.getParameter<int>("preshNclust");
00099     // min energy of ES clusters
00100     preshClustECut = preshowerSelection.getParameter<double>("preshClusterEnergyCut");
00101     // algo params
00102     float preshStripECut = preshowerSelection.getParameter<double>("preshStripEnergyCut");
00103     int preshSeededNst = preshowerSelection.getParameter<int>("preshSeededNstrip");
00104     // calibration parameters:
00105     calib_planeX_ = preshowerSelection.getParameter<double>("preshCalibPlaneX");
00106     calib_planeY_ = preshowerSelection.getParameter<double>("preshCalibPlaneY");
00107     gamma_        = preshowerSelection.getParameter<double>("preshCalibGamma");
00108     mip_          = preshowerSelection.getParameter<double>("preshCalibMIP");
00109 
00110     PreshowerClusterAlgo::DebugLevel debugL;  
00111     // The debug level
00112     std::string debugString = preshowerSelection.getParameter<std::string>("debugLevelES");
00113     if      (debugString == "DEBUG")   debugL = PreshowerClusterAlgo::pDEBUG;
00114     else if (debugString == "INFO")    debugL = PreshowerClusterAlgo::pINFO;
00115     else                               debugL = PreshowerClusterAlgo::pERROR;
00116     // ES algo constructor:
00117     presh_algo_ = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst,debugL);
00118 
00119     ESHits_ = preshowerSelection.getParameter< std::string > ("ESCollection");
00120     produces< ESRecHitCollection >(ESHits_);
00121   }
00122   
00123   debug_ = iConfig.getParameter<int> ("debugLevel");
00124   
00125 }
00126 
00127 
00128 HLTEcalResonanceFilter::~HLTEcalResonanceFilter()
00129 {
00130   if(storeRecHitES_){
00131     delete presh_algo_;
00132   }
00133 }
00134 
00135 
00136 
00137 // ------------ method called to produce the data  ------------
00138 bool
00139 HLTEcalResonanceFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00140 {
00141    
00142   //Create empty output collections
00143   std::auto_ptr< EBRecHitCollection > selEBRecHitCollection( new EBRecHitCollection );
00144   //Create empty output collections
00145   std::auto_ptr< EERecHitCollection > selEERecHitCollection( new EERecHitCollection );
00146   
00147   
00149   vector<DetId> selectedEBDetIds;
00150   vector<DetId> selectedEEDetIds; 
00151   
00152   
00153   edm::ESHandle<CaloTopology> pTopology;
00154   iSetup.get<CaloTopologyRecord>().get(pTopology);
00155   const CaloSubdetectorTopology *topology_eb = pTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel);
00156   const CaloSubdetectorTopology *topology_ee = pTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap);
00157   
00158   
00159   edm::ESHandle<CaloGeometry> geoHandle;
00160   iSetup.get<CaloGeometryRecord>().get(geoHandle); 
00161   const CaloSubdetectorGeometry *geometry_es = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00162   CaloSubdetectorTopology *topology_es=0;
00163   if (geometry_es) {
00164     topology_es  = new EcalPreshowerTopology(geoHandle);
00165   }else{
00166     storeRecHitES_ = false; 
00167   }
00168 
00169   
00171   edm::ESHandle<EcalChannelStatus> csHandle;
00172   if ( useDBStatus_ ) iSetup.get<EcalChannelStatusRcd>().get(csHandle);
00173   const EcalChannelStatus &channelStatus = *csHandle; 
00174   
00176     
00177   Handle<EBRecHitCollection> barrelRecHitsHandle;
00178   
00179   iEvent.getByLabel(barrelHits_,barrelRecHitsHandle);
00180   if (!barrelRecHitsHandle.isValid()) {
00181     LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product barrel hits!" << std::endl;
00182   }
00183   
00184   const EcalRecHitCollection *hitCollection_eb = barrelRecHitsHandle.product();
00185     
00186   
00187   Handle<reco::BasicClusterCollection> barrelClustersHandle;
00188   iEvent.getByLabel(barrelClusters_,barrelClustersHandle);
00189   if (!barrelClustersHandle.isValid()) {
00190     LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product barrel clusters!" << std::endl;
00191   }
00192   const reco::BasicClusterCollection *clusterCollection_eb = barrelClustersHandle.product();
00193   if(debug_>=1) LogDebug("")<<" barrel_input_size:  run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nhitEB:  "<<hitCollection_eb->size()<<" nCluster: "<< clusterCollection_eb->size() <<endl;
00194   
00195   
00196   if(doSelBarrel_){
00197     
00198     map<int, vector<EcalRecHit> > RecHits5x5_clus;  
00199     vector<int> indIsoClus; 
00200     vector<int> indCandClus; 
00201     vector<int> indClusSelected;  
00202     
00203     doSelection( EcalBarrel,clusterCollection_eb, hitCollection_eb, channelStatus,topology_eb,
00204                  RecHits5x5_clus,
00205                  indCandClus,indIsoClus, indClusSelected);
00206     
00207     
00209     for(int i = 0; i < int(indClusSelected.size()); i++){
00210       int ind = indClusSelected[i];
00211       reco::BasicClusterCollection::const_iterator it_bc3 = clusterCollection_eb->begin() + ind; 
00212       const std::vector< std::pair<DetId, float> > &vid =  it_bc3->hitsAndFractions(); 
00213       for (std::vector<std::pair<DetId,float> >::const_iterator idItr = vid.begin();idItr != vid.end ();++idItr){
00214         EcalRecHitCollection::const_iterator hit  = hitCollection_eb->find(idItr->first);
00215         if( hit == hitCollection_eb->end()) continue;  //this should not happen.
00216         selEBRecHitCollection->push_back(*hit); 
00217         selectedEBDetIds.push_back(idItr->first);
00218       }
00219     }
00220     
00221     
00222     if( store5x5RecHitEB_ ){
00224       for(int i = 0; i < int( indCandClus.size()); i++){
00225         int ind = indCandClus[i];
00226         vector<EcalRecHit> v5x5 =  RecHits5x5_clus[ind]; 
00227         for(int n=0; n< int(v5x5.size()); n++){
00228           DetId ed = v5x5[n].id(); 
00229           std::vector<DetId>::iterator itdet = find(selectedEBDetIds.begin(),selectedEBDetIds.end(),ed); 
00230           if( itdet == selectedEBDetIds.end()){
00231             selectedEBDetIds.push_back(ed); 
00232             selEBRecHitCollection->push_back(v5x5[n]);
00233           }
00234         }
00235       }
00236       
00237       
00239       for(int i = 0; i < int( indIsoClus.size()); i++){
00240         int ind = indIsoClus[i];
00241         
00242         std::vector<int>::iterator  it = find(indCandClus.begin(),indCandClus.end(), ind);  
00243         if( it != indCandClus.end()) continue; 
00244         
00245         reco::BasicClusterCollection::const_iterator it_bc3 = clusterCollection_eb->begin() + ind;
00246         DetId seedId = it_bc3->seed();
00247         std::vector<DetId> clus_v5x5 = topology_eb->getWindow(seedId,5,5);
00248         for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
00249           DetId ed = *idItr;
00250           EcalRecHitCollection::const_iterator rit = hitCollection_eb->find( ed );
00251           if ( rit == hitCollection_eb->end() ) continue;
00252           if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue; 
00253           std::vector<DetId>::iterator itdet = find(selectedEBDetIds.begin(),selectedEBDetIds.end(),ed);
00254           if( itdet == selectedEBDetIds.end()){
00255             selectedEBDetIds.push_back(ed);
00256             selEBRecHitCollection->push_back(*rit);
00257           }
00258         }      
00259       }
00260     }
00261     
00262     
00263   }// end of selection for eta/pi0->gg in the barrel 
00264     
00265   int eb_collsize = selEBRecHitCollection->size();
00266   
00267   if(debug_>=1) LogDebug("")<<" barrel_output_size_run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nEBSaved "<<selEBRecHitCollection->size()<<std::endl;
00269   
00270   
00271   
00272   //===============Start of Endcap =================/////
00274   Handle<ESRecHitCollection> esRecHitsHandle;
00275   iEvent.getByLabel(preshHitProducer_,esRecHitsHandle);
00276   if( !esRecHitsHandle.isValid()){
00277     LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product esRecHit!" << std::endl;
00278   }
00279   const EcalRecHitCollection* hitCollection_es = esRecHitsHandle.product();
00280   // make a map of rechits:
00281   m_esrechit_map.clear();
00282   EcalRecHitCollection::const_iterator iter;
00283   for (iter = esRecHitsHandle->begin(); iter != esRecHitsHandle->end(); iter++) {
00284     //Make the map of DetID, EcalRecHit pairs
00285     m_esrechit_map.insert(std::make_pair(iter->id(), *iter));   
00286   }
00287   // The set of used DetID's for a given event:
00288   m_used_strips.clear();
00289   std::auto_ptr<ESRecHitCollection> selESRecHitCollection(new ESRecHitCollection );
00290 
00291   Handle<EERecHitCollection> endcapRecHitsHandle;
00292   iEvent.getByLabel(endcapHits_,endcapRecHitsHandle);
00293   if (!endcapRecHitsHandle.isValid()) {
00294     LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product endcap hits!" << std::endl;
00295   }
00296   const EcalRecHitCollection *hitCollection_ee = endcapRecHitsHandle.product();
00297   Handle<reco::BasicClusterCollection> endcapClustersHandle;
00298   iEvent.getByLabel(endcapClusters_,endcapClustersHandle);
00299   if (!endcapClustersHandle.isValid()) {
00300     LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product endcap clusters!" << std::endl;
00301   }
00302   const reco::BasicClusterCollection *clusterCollection_ee = endcapClustersHandle.product();
00303   if(debug_>=1) LogDebug("")<<" endcap_input_size:  run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nhitEE:  "<<hitCollection_ee->size()<<" nhitES: "<<hitCollection_es->size()<<" nCluster: "<< clusterCollection_ee->size() <<endl;
00304   
00305   
00306   if(doSelEndcap_){
00307     
00308     map<int, vector<EcalRecHit> > RecHits5x5_clus;  
00309     vector<int> indIsoClus; 
00310     vector<int> indCandClus; 
00311     vector<int> indClusSelected;  
00312 
00313     doSelection( EcalEndcap,clusterCollection_ee, hitCollection_ee, channelStatus,topology_ee,
00314                  RecHits5x5_clus,
00315                  indCandClus,indIsoClus, indClusSelected);
00316     
00318     for(int i = 0; i < int(indClusSelected.size()); i++){
00319       int ind = indClusSelected[i];
00320       reco::BasicClusterCollection::const_iterator it_bc3 = clusterCollection_ee->begin() + ind; 
00321       const std::vector< std::pair<DetId, float> > &vid =  it_bc3->hitsAndFractions(); 
00322       for (std::vector<std::pair<DetId,float> >::const_iterator idItr = vid.begin();idItr != vid.end ();++idItr){
00323         EcalRecHitCollection::const_iterator hit  = hitCollection_ee->find(idItr->first);
00324         if( hit == hitCollection_ee->end()) continue;  //this should not happen.
00325         selEERecHitCollection->push_back(*hit); 
00326         selectedEEDetIds.push_back(idItr->first);
00327       }
00329       if(storeRecHitES_){
00330         std::set<DetId> used_strips_before = m_used_strips;  
00331         makeClusterES(it_bc3->x(),it_bc3->y(),it_bc3->z(),geometry_es,topology_es);
00332         std::set<DetId>::const_iterator ites = m_used_strips.begin();
00333         for(; ites != m_used_strips.end(); ++ ites ){
00334           ESDetId d1 = ESDetId(*ites);
00335           std::set<DetId>::const_iterator ites2 = find(used_strips_before.begin(),used_strips_before.end(),d1);
00336           if( (ites2 == used_strips_before.end())){
00337             std::map<DetId, EcalRecHit>::iterator itmap = m_esrechit_map.find(d1);
00338             selESRecHitCollection->push_back(itmap->second);
00339           }
00340         }
00341       }
00342     }
00343 
00344 
00345     if( store5x5RecHitEE_ ){
00347       for(int i = 0; i < int( indCandClus.size()); i++){
00348         int ind = indCandClus[i];
00349         vector<EcalRecHit> v5x5 =  RecHits5x5_clus[ind]; 
00350         for(int n=0; n< int(v5x5.size()); n++){
00351           DetId ed = v5x5[n].id(); 
00352           std::vector<DetId>::iterator itdet = find(selectedEEDetIds.begin(),selectedEEDetIds.end(),ed); 
00353           if( itdet == selectedEEDetIds.end()){
00354             selectedEEDetIds.push_back(ed); 
00355             selEERecHitCollection->push_back(v5x5[n]);
00356           }
00357         }
00358       }
00359       
00360       
00362       for(int i = 0; i < int( indIsoClus.size()); i++){
00363         int ind = indIsoClus[i];
00364         
00365         std::vector<int>::iterator  it = find(indCandClus.begin(),indCandClus.end(), ind);  
00366         if( it != indCandClus.end()) continue; 
00367         
00368         reco::BasicClusterCollection::const_iterator    it_bc3 = clusterCollection_ee->begin() + ind;
00369         DetId seedId = it_bc3->seed();
00370         std::vector<DetId> clus_v5x5 = topology_ee->getWindow(seedId,5,5);
00371         for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
00372           DetId ed = *idItr;
00373           EcalRecHitCollection::const_iterator rit = hitCollection_ee->find( ed );
00374           if ( rit == hitCollection_ee->end() ) continue;
00375           if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue; 
00376           std::vector<DetId>::iterator itdet = find(selectedEEDetIds.begin(),selectedEEDetIds.end(),ed);
00377           if( itdet == selectedEEDetIds.end()){
00378             selectedEEDetIds.push_back(ed);
00379             selEERecHitCollection->push_back(*rit);
00380           }
00381         }      
00382       }
00383     }
00384     
00385   }// end of selection for eta/pi0->gg in the endcap
00386     
00387  
00388   
00389   delete topology_es;
00390   
00392   
00393   if(debug_>=1) LogDebug("")<<" endcap_output_size run "<<iEvent.id().run()<<"_"<<iEvent.id().event()<<" nEESaved "<<selEERecHitCollection->size()<<" nESSaved: " << selESRecHitCollection->size() <<endl;
00394   
00395   
00396   //Put selected information in the event
00397   int ee_collsize = selEERecHitCollection->size();
00398   
00399   if( eb_collsize < 2 && ee_collsize <2) return false; 
00400   
00402   if(doSelBarrel_){
00403     iEvent.put( selEBRecHitCollection, BarrelHits_);
00404   }  
00405   if(doSelEndcap_){
00406     iEvent.put( selEERecHitCollection, EndcapHits_);
00407     if(storeRecHitES_){
00408       iEvent.put( selESRecHitCollection, ESHits_);
00409     }
00410   }
00411   
00412   return true; 
00413     
00414   
00415 }
00416 
00417 
00418 
00419 void HLTEcalResonanceFilter::doSelection(int detector, const reco::BasicClusterCollection *clusterCollection,
00420                                          const EcalRecHitCollection *hitCollection,
00421                                          const EcalChannelStatus &channelStatus,
00422                                          const CaloSubdetectorTopology *topology_p,
00423                                          map<int, vector<EcalRecHit> > &RecHits5x5_clus,
00424                                          vector<int> &indCandClus, 
00425                                          vector<int> &indIsoClus, 
00426                                          vector<int> &indClusSelected  
00427                                          ){
00428   
00429   
00430   vector<int> indClusPi0Candidates;  
00431   if( detector ==EcalBarrel && removePi0CandidatesForEta_){
00432     for( reco::BasicClusterCollection::const_iterator it_bc = clusterCollection->begin(); it_bc != clusterCollection->end();it_bc++){
00433       for( reco::BasicClusterCollection::const_iterator it_bc2 = it_bc + 1 ; it_bc2 != clusterCollection->end();it_bc2++){
00434         float m_pair,pt_pair,eta_pair, phi_pair; 
00435         calcPaircluster(*it_bc,*it_bc2, m_pair, pt_pair,eta_pair,phi_pair); 
00436         if(m_pair > massLowPi0Cand_ && m_pair < massHighPi0Cand_){
00437           int indtmp[2]={ int( it_bc - clusterCollection->begin()), int( it_bc2 - clusterCollection->begin())};
00438           for( int k=0;k<2; k++){
00439             std::vector<int>::iterator it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),indtmp[k]);
00440             if( it == indClusPi0Candidates.end()) indClusPi0Candidates.push_back(indtmp[k]);
00441           }
00442         }
00443       }
00444     }//end of loop over finding pi0's clusters
00445   }
00446   
00447   
00448   
00449   
00450   
00451   double m_minCut = seleMinvMinBarrel_; 
00452   double m_maxCut = seleMinvMaxBarrel_; 
00453   double ptminforIso = ptMinForIsolation_; 
00454   double isoCut = seleIso_; 
00455   double isoBeltdrCut = seleBeltDR_ ; 
00456   double isoBeltdetaCut =  seleBeltDeta_; 
00457   double s4s9Cut = seleS4S9Gamma_; 
00458   double s9s25Cut = seleS9S25Gamma_; 
00459   bool store5x5 = store5x5RecHitEB_; 
00460   
00461   if( detector ==EcalEndcap){
00462     m_minCut = seleMinvMinEndCap_;
00463     m_maxCut = seleMinvMaxEndCap_; 
00464     ptminforIso = ptMinForIsolationEndCap_; 
00465     isoCut = seleIsoEndCap_; 
00466     isoBeltdrCut =  seleBeltDREndCap_; 
00467     isoBeltdetaCut =  seleBeltDetaEndCap_; 
00468     s4s9Cut = seleS4S9GammaEndCap_; 
00469     s9s25Cut = seleS9S25GammaEndCap_ ; 
00470     store5x5 = store5x5RecHitEE_; 
00471     
00472   }
00473   
00474   
00475   
00476 
00477   map<int,bool> passShowerShape_clus;  //if this cluster passed showershape cut, so no need to compute the quantity again for each loop
00478   
00479   for( reco::BasicClusterCollection::const_iterator it_bc = clusterCollection->begin(); it_bc != clusterCollection->end();it_bc++){
00480     
00481     if( detector ==EcalBarrel && removePi0CandidatesForEta_){
00482       std::vector<int>::iterator it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),int(it_bc - clusterCollection->begin()) );
00483       if( it != indClusPi0Candidates.end()) continue; 
00484     }
00485     
00486     float en1 = it_bc->energy();
00487     float theta1 = 2. * atan(exp(-it_bc->position().eta()));
00488     float pt1 = en1*sin(theta1);
00489  
00490     int ind1 = int( it_bc - clusterCollection->begin() );
00491     std::map<int,bool>::iterator  itmap = passShowerShape_clus.find(ind1);
00492     if( itmap != passShowerShape_clus.end()){
00493       if( itmap->second == false){
00494         continue; 
00495       }
00496     }
00497     
00498     for( reco::BasicClusterCollection::const_iterator it_bc2 = it_bc + 1 ; it_bc2 != clusterCollection->end();it_bc2++){
00499       if( detector ==EcalBarrel && removePi0CandidatesForEta_){
00500         std::vector<int>::iterator it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),int(it_bc2 - clusterCollection->begin()) );
00501         if( it != indClusPi0Candidates.end()) continue; 
00502       }
00503       float en2 = it_bc2 ->energy();
00504       float theta2 = 2. * atan(exp(-it_bc2->position().eta()));
00505       float pt2 = en2*sin(theta2);
00506       
00507       int ind2 = int( it_bc2 - clusterCollection->begin() );
00508       std::map<int,bool>::iterator  itmap = passShowerShape_clus.find(ind2);
00509       if( itmap != passShowerShape_clus.end()){
00510         if( itmap->second == false){
00511           continue; 
00512         }
00513       }
00514       
00515       float m_pair,pt_pair,eta_pair, phi_pair; 
00516       calcPaircluster(*it_bc,*it_bc2, m_pair, pt_pair,eta_pair,phi_pair);  
00518       float ptmin = pt1< pt2 ? pt1:pt2; 
00519       if(  detector ==EcalBarrel ){
00520         if( ptmin < selePtGamma_ ) continue; 
00521         if (pt_pair < selePtPair_ )continue;
00522       }else{
00523         float etapair = fabs(eta_pair);
00524         if(etapair <= region1_EndCap_){
00525           if(ptmin < selePtGammaEndCap_region1_ || pt_pair < selePtPairEndCap_region1_) continue; 
00526         }else if( etapair <= region2_EndCap_){
00527           if(ptmin < selePtGammaEndCap_region2_ || pt_pair < selePtPairEndCap_region2_) continue;
00528         }else{
00529           if(ptmin < selePtGammaEndCap_region3_ || pt_pair < selePtPairEndCap_region3_) continue;
00530           if(pt_pair > selePtPairMaxEndCap_region3_ ) continue; 
00531         }
00532       }
00533       
00534 
00535       
00537       if( m_pair < m_minCut || m_pair > m_maxCut) continue; 
00538       
00539       
00540       
00541       
00543       vector<int> IsoClus;
00544       IsoClus.push_back(ind1);  //first two are good clusters
00545       IsoClus.push_back(ind2); 
00546       
00547       float Iso = 0;
00548       for( reco::BasicClusterCollection::const_iterator it_bc3 = clusterCollection->begin(); it_bc3 != clusterCollection->end();it_bc3++){
00549         if( it_bc3->seed() == it_bc->seed() || it_bc3->seed() == it_bc2->seed()) continue; 
00550         float drcl = GetDeltaR(eta_pair,it_bc3->eta(),phi_pair,it_bc3->phi()); 
00551         float dretacl = fabs( eta_pair - it_bc3->eta()); 
00552         if( drcl > isoBeltdrCut ||  dretacl > isoBeltdetaCut ) continue; 
00553         float pt3 = it_bc3->energy()*sin(it_bc3->position().theta()) ; 
00554         if( pt3 < ptminforIso) continue; 
00555         Iso += pt3; 
00556         int ind3 = int(it_bc3 - clusterCollection->begin());  
00557         IsoClus.push_back( ind3);
00558       }
00560       if(Iso/pt_pair > isoCut) continue; 
00561       
00562       
00563       bool failShowerShape = false;
00564       for(int n=0; n<2; n++){
00565         int ind = IsoClus[n];
00566         reco::BasicClusterCollection::const_iterator it_bc3 = clusterCollection->begin() + ind; 
00567         std::map<int,bool>::iterator  itmap = passShowerShape_clus.find(ind);
00568         if( itmap != passShowerShape_clus.end()){
00569           if( itmap->second == false){
00570             failShowerShape = true; 
00571             n=2; //exit the loop 
00572           }
00573         }else{
00574           vector<EcalRecHit> RecHitsCluster_5x5;
00575           float res[3];
00576           calcShowerShape(*it_bc3, channelStatus,hitCollection, topology_p,store5x5, RecHitsCluster_5x5, res);
00577           float s4s9 = res[1] >0 ? res[0]/ res[1] : -1; 
00578           float s9s25 = res[2] >0 ? res[1] / res[2] : -1; 
00579           bool passed = s4s9 > s4s9Cut && s9s25 > s9s25Cut; 
00580           passShowerShape_clus.insert(pair<int, bool>(ind,passed));
00581           if( !passed ){
00582             failShowerShape = true; 
00583             n=2; //exit the loop 
00584           }else{
00585             RecHits5x5_clus.insert(pair<int, vector<EcalRecHit> >(ind,RecHitsCluster_5x5) );
00586           }
00587         }
00588       }
00589       
00590       if( failShowerShape == true) continue;  //if any of the two clusters fail shower shape
00591       
00592       
00594       for(unsigned int iii=0 ; iii<IsoClus.size() ; iii++){   
00595         int ind = IsoClus[iii];
00596         
00597         if( iii < 2){
00598           std::vector<int>::iterator it = find(indCandClus.begin(),indCandClus.end(), ind);  
00599           if( it == indCandClus.end()) indCandClus.push_back(ind);
00600           else continue; 
00601         }else{
00602           std::vector<int>::iterator it = find(indIsoClus.begin(),indIsoClus.end(), ind);  //iso cluster 
00603           if( it == indIsoClus.end()) indIsoClus.push_back(ind);
00604           else continue; 
00605         }
00606         
00607         std::vector<int>::iterator it = find(indClusSelected.begin(),indClusSelected.end(),ind); 
00608         if( it != indClusSelected.end()) continue; 
00609         indClusSelected.push_back(ind);
00610       }
00611       
00612     }
00613   }
00614   
00615   
00616   
00617   
00618 }
00619 
00620 
00621 
00622 
00623 
00624 
00625 
00626 void HLTEcalResonanceFilter::convxtalid(Int_t &nphi,Int_t &neta)
00627 {
00628   // Barrel only
00629   // Output nphi 0...359; neta 0...84; nside=+1 (for eta>0), or 0 (for eta<0).
00630   // neta will be [-85,-1] , or [0,84], the minus sign indicates the z<0 side.
00631   
00632   if(neta > 0) neta -= 1;
00633   if(nphi > 359) nphi=nphi-360;
00634   
00635   // final check
00636   if(nphi >359 || nphi <0 || neta< -85 || neta > 84)
00637     {
00638       LogError("") <<" unexpected fatal error in HLTEcalResonanceFilter::convxtalid "<<  nphi <<  " " << neta <<  " " <<std::endl;
00639     }
00640 } //end of convxtalid
00641 
00642 
00643 
00644 
00645 int HLTEcalResonanceFilter::diff_neta_s(Int_t neta1, Int_t neta2){
00646   Int_t mdiff;
00647   mdiff=(neta1-neta2);
00648   return mdiff;
00649 }
00650 
00651 // Calculate the distance in xtals taking into account the periodicity of the Barrel
00652 int HLTEcalResonanceFilter::diff_nphi_s(Int_t nphi1,Int_t nphi2) {
00653    Int_t mdiff;
00654    if(std::abs(nphi1-nphi2) < (360-std::abs(nphi1-nphi2))) {
00655      mdiff=nphi1-nphi2;
00656    }
00657    else {
00658    mdiff=360-std::abs(nphi1-nphi2);
00659    if(nphi1>nphi2) mdiff=-mdiff;
00660    }
00661    return mdiff;
00662 }
00663 
00664 
00665 void HLTEcalResonanceFilter::calcShowerShape(const reco::BasicCluster &bc,   const EcalChannelStatus &channelStatus, const EcalRecHitCollection *recHits, const CaloSubdetectorTopology *topology_p, bool calc5x5, vector<EcalRecHit> &rechit5x5, float res[]){
00666   
00667   
00668   const std::vector< std::pair<DetId, float> > &vid =  bc.hitsAndFractions(); 
00669   
00670   
00671   float e2x2[4]={0};
00672   float e3x3 =0 ; 
00673   float e5x5 =0; 
00674   int seedx ;
00675   int seedy; 
00676   DetId seedId = bc.seed(); 
00677   
00678   bool InBarrel = true; 
00679   if( seedId.subdetId() == EcalBarrel){
00680     EBDetId ebd = EBDetId(seedId);
00681     seedx = ebd.ieta();
00682     seedy = ebd.iphi();
00683     convxtalid(seedy,seedx);
00684   }else{
00685     InBarrel = false; 
00686     EEDetId eed = EEDetId(seedId);
00687     seedx = eed.ix();
00688     seedy = eed.iy();
00689   }
00690   int x,y, dx, dy; 
00691   
00692   
00693 
00694   if( calc5x5 ){
00695     rechit5x5.clear();
00696     std::vector<DetId> clus_v5x5; 
00697     clus_v5x5 = topology_p->getWindow(seedId,5,5);
00698     
00699     for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
00700       DetId ed = *idItr; 
00701       if( InBarrel == true){
00702         EBDetId ebd = EBDetId(ed); 
00703         x = ebd.ieta();
00704         y = ebd.iphi();
00705         convxtalid(y,x);
00706         dx = diff_neta_s(x,seedx);
00707         dy = diff_nphi_s(y,seedy);
00708       }else{
00709         EEDetId eed = EEDetId(ed); 
00710         x = eed.ix();
00711         y = eed.iy();
00712         dx = x-seedx;
00713         dy = y-seedy; 
00714       }
00715       EcalRecHitCollection::const_iterator rit = recHits->find( ed );
00716       if ( rit == recHits->end() ) continue; 
00717       if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue; 
00718       
00719       float energy = (*rit).energy();
00720       e5x5 += energy; 
00721       
00722       std::vector<std::pair<DetId,float> >::const_iterator idItr = std::find( vid.begin(),vid.end(), std::make_pair(ed,1.0f));  
00723       if( idItr == vid.end()){ 
00724         rechit5x5.push_back(*rit);
00725       }else{ 
00726         if(std::abs(dx)<=1 && std::abs(dy)<=1) {
00727           if(dx <= 0 && dy <=0) e2x2[0] += energy; 
00728           if(dx >= 0 && dy <=0) e2x2[1] += energy; 
00729           if(dx <= 0 && dy >=0) e2x2[2] += energy; 
00730           if(dx >= 0 && dy >=0) e2x2[3] += energy; 
00731           e3x3 += energy; 
00732         }
00733       }
00734     }
00735     
00736     
00737   }else{
00738     
00739     for (std::vector<std::pair<DetId,float> >::const_iterator idItr = vid.begin();idItr != vid.end ();++idItr){
00740       DetId ed = idItr->first; 
00741       if( InBarrel == true){
00742         EBDetId ebd = EBDetId(ed); 
00743         x = ebd.ieta();
00744         y = ebd.iphi();
00745         convxtalid(y,x);
00746         dx = diff_neta_s(x,seedx);
00747         dy = diff_nphi_s(y,seedy);
00748       }else{
00749         EEDetId eed = EEDetId(ed); 
00750         x = eed.ix();
00751         y = eed.iy();
00752         dx = x-seedx;
00753         dy = y-seedy; 
00754       }
00755       EcalRecHitCollection::const_iterator rit = recHits->find( ed );
00756       if ( rit == recHits->end() ) {
00757         continue; 
00758       }
00759       
00760       float energy = (*rit).energy();
00761       if(std::abs(dx)<=1 && std::abs(dy)<=1){
00762         if(dx <= 0 && dy <=0) e2x2[0] += energy; 
00763         if(dx >= 0 && dy <=0) e2x2[1] += energy; 
00764         if(dx <= 0 && dy >=0) e2x2[2] += energy; 
00765         if(dx >= 0 && dy >=0) e2x2[3] += energy; 
00766         e3x3 += energy; 
00767       }
00768       
00769     }
00770     e5x5 = e3x3; 
00771   }
00772   
00773   
00774   
00776   res[0] = *max_element( e2x2,e2x2+4); 
00777   res[1] = e3x3; 
00778   res[2] = e5x5; 
00779   
00780   
00781 }
00782 
00783 
00784 
00785 
00786 void HLTEcalResonanceFilter::calcPaircluster(const reco::BasicCluster &bc1, const reco::BasicCluster &bc2,float &m_pair,float &pt_pair,float &eta_pair, float &phi_pair){
00787     
00788   
00789   float theta1 = 2. * atan(exp(-bc1.eta())); 
00790   float en1 = bc1.energy();
00791   float pt1 = en1 * sin(theta1); 
00792   TLorentzVector v1( pt1 *cos(bc1.phi()),pt1 * sin(bc1.phi()),en1*cos(theta1),en1);
00793   
00794   float theta2 = 2. * atan(exp(-bc2.eta())); 
00795   float en2 = bc2.energy();
00796   float pt2 = en2 * sin(theta2); 
00797   TLorentzVector v2( pt2 *cos(bc2.phi()),pt2 * sin(bc2.phi()),en2*cos(theta2),en2);
00798   
00799   TLorentzVector v = v1 + v2; 
00800   
00801   m_pair = v.M();
00802   pt_pair = v.Pt();
00803   eta_pair = v.Eta();
00804   phi_pair = v.Phi();
00805   
00806   
00807 }
00808 
00809 
00810 
00811 
00812 
00813 bool HLTEcalResonanceFilter::checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus,const EcalRecHit &rh){
00814   
00815   if(useRecoFlag_ ){ 
00816     int flag = rh.recoFlag();
00817     if( flagLevelRecHitsToUse_ ==0){ 
00818       if( flag != 0) return false; 
00819     }
00820     else if( flagLevelRecHitsToUse_ ==1){ 
00821       if( flag !=0 && flag != 4 ) return false; 
00822     }
00823     else if( flagLevelRecHitsToUse_ ==2){ 
00824       if( flag !=0 && flag != 4 && flag != 6 && flag != 7) return false; 
00825     }
00826   }
00827   if ( useDBStatus_){ 
00828     int status =  int(channelStatus[rh.id().rawId()].getStatusCode()); 
00829     if ( status > statusLevelRecHitsToUse_ ) return false; 
00830   }
00831   
00832   return true; 
00833 }
00834 
00835 
00836 float HLTEcalResonanceFilter::DeltaPhi(float phi1, float phi2){
00837 
00838   float diff = fabs(phi2 - phi1);
00839   
00840   while (diff >acos(-1)) diff -= 2*acos(-1);
00841   while (diff <= -acos(-1)) diff += 2*acos(-1);
00842   
00843   return diff; 
00844 
00845 }
00846 
00847 
00848 float HLTEcalResonanceFilter::GetDeltaR(float eta1, float eta2, float phi1, float phi2){
00849   
00850   return sqrt( (eta1-eta2)*(eta1-eta2) 
00851                + DeltaPhi(phi1, phi2)*DeltaPhi(phi1, phi2) );
00852   
00853 }
00854 
00855 
00856 void HLTEcalResonanceFilter::makeClusterES(float x, float y, float z,const CaloSubdetectorGeometry*& geometry_es,
00857                                         CaloSubdetectorTopology*& topology_es
00858                                         ){
00859   
00860   
00862   const GlobalPoint point(x,y,z);
00863   DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 1);
00864   DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 2);
00865   ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
00866   ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);     
00867   
00868   // Get ES clusters (found by the PreshSeeded algorithm) associated with a given EE cluster.           
00869   for (int i2=0; i2<preshNclust_; i2++) {
00870     reco::PreshowerCluster cl1 = presh_algo_->makeOneCluster(strip1,&m_used_strips,&m_esrechit_map,geometry_es,topology_es);   
00871     reco::PreshowerCluster cl2 = presh_algo_->makeOneCluster(strip2,&m_used_strips,&m_esrechit_map,geometry_es,topology_es); 
00872   } // end of cycle over ES clusters
00873   
00874   
00875 }