CMS 3D CMS Logo

EgHLTOffHelper.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/EgHLTOffHelper.h"
00002 
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00006 #include "DataFormats/DetId/interface/DetId.h"
00007 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00008 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00009 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00011 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00012 
00013 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"
00014 
00015 void EgHLTOffHelper::setup(const edm::ParameterSet& conf)
00016 {
00017   // barrelShapeAssocProd_ = conf.getParameter<edm::InputTag>("barrelClusterShapeAssociation");
00018   //barrelShapeAssocProd_ = conf.getParameter<edm::InputTag>("barrelClusterShapeAssociation");
00019   //endcapShapeAssocProd_ = conf.getParameter<edm::InputTag>("endcapClusterShapeAssociation");
00020 
00021 
00022   ecalRecHitsEBTag_ = conf.getParameter<edm::InputTag>("BarrelRecHitCollection");
00023   ecalRecHitsEETag_ = conf.getParameter<edm::InputTag>("EndcapRecHitCollection");
00024   
00025   caloJetsTag_ = conf.getParameter<edm::InputTag>("CaloJetCollection");
00026  
00027 
00028   cuts_.setHighNrgy();
00029   tagCuts_.setHighNrgy();
00030   probeCuts_.setPreSel();
00031 }
00032 
00033 
00034 //this function coverts GsfElectrons to a format which is actually useful to me
00035 void EgHLTOffHelper::fillEgHLTOffEleVec(edm::Handle<reco::GsfElectronCollection> gsfElectrons,std::vector<EgHLTOffEle>& egHLTOffEles)
00036 {
00037   egHLTOffEles.clear();
00038   egHLTOffEles.reserve(gsfElectrons->size());
00039   for(reco::PixelMatchGsfElectronCollection::const_iterator gsfIter=gsfElectrons->begin(); gsfIter!=gsfElectrons->end();++gsfIter){
00040     //for now use dummy isolation data
00041     EgHLTOffEle::IsolData isolData;
00042     isolData.nrTrks=1;
00043     isolData.ptTrks=1.;
00044     isolData.em= 0.42;
00045     isolData.had=0.42;
00046     
00047     //get cluster shape and we're done construction 
00048     //edm::LogInfo("EgHLTOffHelper") << "getting clus shape "<<std::endl;
00049     //const reco::ClusterShape* clusShape = getClusterShape(&*gsfIter);
00050     //edm::LogInfo("EgHLTOffHelper") << "clus shape "<<clusShape<<std::endl;
00051     EgHLTOffEle::ClusShapeData clusShapeData;
00052     clusShapeData.sigmaEtaEta=999.;
00053     //    clusShapeData.sigmaIEtaIEta=999.;
00054     //clusShapeData.e2x5MaxOver5x5=-1.; //not defined in endcap yet
00055     //need to figure out if its in the barrel or endcap
00056     //classification variable is unrelyable so get the first hit of the cluster and figure out if its barrel or endcap
00057     const reco::BasicCluster& seedClus = *(gsfIter->superCluster()->seed());
00058     const DetId seedDetId = seedClus.getHitsByDetId()[0]; //note this may not actually be the seed hit but it doesnt matter because all hits will be in the barrel OR endcap (it is also incredably inefficient as it getHitsByDetId passes the vector by value not reference
00059     if(seedDetId.subdetId()==EcalBarrel){
00060       std::vector<float> stdCov = EcalClusterTools::covariances(seedClus,ebRecHits_,caloTopology_,caloGeom_);
00061       // std::vector<float> crysCov = EcalClusterTools::crystalCovariances(seedClus,ebRecHits_,caloTopology_,caloGeom_);
00062       clusShapeData.sigmaEtaEta = sqrt(stdCov[0]);
00063       //  clusShapeData.sigmaIEtaIEta =  sqrt(crysCov[0]);
00064       clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
00065       //clusShapeData.sigmaIPhiIPhi =  sqrt(crysCov[2]);
00066        
00067       
00068      
00069     }else{
00070      std::vector<float> stdCov = EcalClusterTools::covariances(seedClus,eeRecHits_,caloTopology_,caloGeom_);
00071      clusShapeData.sigmaEtaEta = sqrt(stdCov[0]);  
00072      clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
00073      
00074     }
00075 
00076     egHLTOffEles.push_back(EgHLTOffEle(*gsfIter,clusShapeData,isolData));
00077     
00078     //now we would like to set the cut results
00079     EgHLTOffEle& ele =  egHLTOffEles.back();
00080     ele.setTagCutCode(tagCuts_.getCutCode(ele));
00081     ele.setProbeCutCode(probeCuts_.getCutCode(ele));
00082     ele.setCutCode(cuts_.getCutCode(ele));
00083       
00084 
00085   }//end loop over gsf electron collection
00086 
00087 }
00088 
00089 void EgHLTOffHelper::getHandles(const edm::Event& event,const edm::EventSetup& setup)
00090 {
00091   // try{
00092 //     event.getByLabel(barrelShapeAssocProd_, clusterShapeHandleBarrel_) ;
00093 //   }catch(...){} //the worlds most pointless try, catch pair, damn you CMSSW framework,  DAMN you
00094   
00095 //   try{
00096 //     event.getByLabel(endcapShapeAssocProd_, clusterShapeHandleEndcap_) ;
00097 //   }catch(...){}
00098 
00099 //   if (!clusterShapeHandleBarrel_.isValid()) {
00100 //     edm::LogError ("EgHLTOffHelper") << "Can't get ECAL barrel Cluster Shape Collection" ; 
00101 //   }
00102 //   if (!clusterShapeHandleEndcap_.isValid()) {
00103 //     edm::LogError ("EgHLTOffHelper") << "Can't get ECAL endcap Cluster Shape Collection" ; 
00104 //   }
00105 
00106   //yay, now in 2_1 we dont have to program by exception
00107   edm::Handle<EcalRecHitCollection> ecalBarrelRecHitsHandle;
00108   event.getByLabel(ecalRecHitsEBTag_,ecalBarrelRecHitsHandle);
00109   ebRecHits_ = ecalBarrelRecHitsHandle.product();
00110 
00111   edm::Handle<EcalRecHitCollection> ecalEndcapRecHitsHandle;
00112   event.getByLabel(ecalRecHitsEETag_,ecalEndcapRecHitsHandle);
00113   eeRecHits_ = ecalEndcapRecHitsHandle.product();
00114 
00115   edm::Handle<reco::CaloJetCollection> caloJetsHandle;
00116   event.getByLabel(caloJetsTag_,caloJetsHandle);
00117   jets_ = caloJetsHandle.product();
00118   
00119   edm::ESHandle<CaloGeometry> geomHandle;
00120   setup.get<CaloGeometryRecord>().get(geomHandle);
00121   caloGeom_ = geomHandle.product();
00122 
00123   edm::ESHandle<CaloTopology> topologyHandle;
00124   setup.get<CaloTopologyRecord>().get(topologyHandle);
00125   caloTopology_ = topologyHandle.product();
00126 }
00127 
00128 
00129 
00130 // //ripped of from the electronIDAlgo (there must be a better way, I *cannot* believe that there isnt a better way)
00131 // //I've made some minor mods for speed and robustness (it could still be faster though)
00132 // //I'm sorry for the pain you are about to go through
00133 // //in summary it determines where the electron is barrel or endcap and if the clusterShape association map handle is valid for it
00134 // //it then looks in the map for the electrons seed cluster and if found, returns a pointer to the shape
00135 // //a complication arrises as electrons which are endcap may be classified as in the barrel-endcap gap and therefore have classification 40
00136 // //and therefore be labeled barrel someplaces (like here) and endcap others
00137 // const reco::ClusterShape* EgHLTOffHelper::getClusterShape(const reco::GsfElectron* electron)
00138 // {
00139 //   // Find entry in map corresponding to seed BasicCluster of SuperCluster
00140 //   reco::BasicClusterShapeAssociationCollection::const_iterator seedShpItr;
00141  
00142 //   if ( electron->classification() < 100 && clusterShapeHandleBarrel_.isValid() ) {
00143 //     const reco::BasicClusterShapeAssociationCollection& barrelClShpMap = *clusterShapeHandleBarrel_;
00144 //     reco::SuperClusterRef sclusRef = electron->get<reco::SuperClusterRef> () ;
00145 //     seedShpItr = barrelClShpMap.find ( sclusRef->seed () ) ;
00146 //     if (seedShpItr!=barrelClShpMap.end()) return &*(seedShpItr->val);
00147 //     else if (clusterShapeHandleEndcap_.isValid()){
00148 //       const reco::BasicClusterShapeAssociationCollection& endcapClShpMap = *clusterShapeHandleEndcap_;
00149 //       seedShpItr = endcapClShpMap.find ( sclusRef->seed ()) ;
00150 //       if(seedShpItr!=endcapClShpMap.end()) return &*(seedShpItr->val);
00151 //     }//end check of valid endcap cluster shape in barrel section
00152 //   } else if(electron->classification()>=100 && clusterShapeHandleEndcap_.isValid()) {
00153 //     const reco::BasicClusterShapeAssociationCollection& endcapClShpMap = *clusterShapeHandleEndcap_;
00154 //     reco::SuperClusterRef sclusRef = electron->get<reco::SuperClusterRef> () ;
00155 //     seedShpItr = endcapClShpMap.find ( sclusRef->seed () ) ;
00156 //     if(seedShpItr!=endcapClShpMap.end()) return &*(seedShpItr->val); 
00157 //   }//end check of endcap electron with valid shape map
00158   
00159 //   return NULL;
00160 // }
00161 

Generated on Tue Jun 9 17:34:09 2009 for CMSSW by  doxygen 1.5.4