CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/Calibration/Tools/plugins/SingleEleCalibSelector.cc

Go to the documentation of this file.
00001 // my includes
00002 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 
00006 // Geometry
00007 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00008 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00009 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00010 
00011 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00013 
00014 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00015 #include "DataFormats/DetId/interface/DetId.h"
00016 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00017 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00018 
00019 
00020 #include "Calibration/Tools/plugins/SingleEleCalibSelector.h"
00021 
00022 //CLHEP
00023 #include <CLHEP/Vector/LorentzVector.h>
00024 
00025 #include <iostream>
00026 
00027 SingleEleCalibSelector::SingleEleCalibSelector (const edm::ParameterSet& iConfig)
00028  {
00029    ESCOPinMin_      = iConfig.getParameter<double>("ESCOPinMin");
00030    ESCOPinMax_      = iConfig.getParameter<double>("ESCOPinMax");
00031    ESeedOPoutMin_   = iConfig.getParameter<double>("ESeedOPoutMin");
00032    ESeedOPoutMax_   = iConfig.getParameter<double>("ESeedOPoutMax");  
00033    PinMPoutOPinMin_ = iConfig.getParameter<double>("PinMPoutOPinMin");
00034    PinMPoutOPinMax_ = iConfig.getParameter<double>("PinMPoutOPinMax");   
00035    E5x5OPoutMin_    = iConfig.getParameter<double>("E5x5OPoutMin");
00036    E5x5OPoutMax_    = iConfig.getParameter<double>("E5x5OPoutMax");
00037    E3x3OPinMin_     = iConfig.getParameter<double>("E3x3OPinMin");
00038    E3x3OPinMax_     = iConfig.getParameter<double>("E3x3OPinMax");
00039    E3x3OE5x5Min_    = iConfig.getParameter<double>("E3x3OE5x5Min");
00040    E3x3OE5x5Max_    = iConfig.getParameter<double>("E3x3OE5x5Max"); 
00041    EBrecHitLabel_   = iConfig.getParameter<edm::InputTag> ("alcaBarrelHitCollection"); 
00042    EErecHitLabel_   = iConfig.getParameter<edm::InputTag> ("alcaEndcapHitCollection"); 
00043  }
00044 
00045 
00046 // ------------------------------------------------------------
00047 
00048 
00049 void 
00050 
00051 SingleEleCalibSelector::select (edm::Handle<collection> inputHandle, 
00052                         const edm::Event& iEvent , const edm::EventSetup& iSetup) 
00053 {
00054   selected_.clear();
00055 
00056   //Get the EB rechit collection
00057   edm::Handle<EBRecHitCollection> barrelRecHitsHandle ;
00058   iEvent.getByLabel (EBrecHitLabel_, barrelRecHitsHandle) ;
00059   const EBRecHitCollection* EBHitsColl = barrelRecHitsHandle.product () ; 
00060 
00061   //Get the EE rechit collection
00062   edm::Handle<EERecHitCollection> endcapRecHitsHandle ;
00063   iEvent.getByLabel (EErecHitLabel_, endcapRecHitsHandle) ;
00064   const EERecHitCollection* EEHitsColl = endcapRecHitsHandle.product () ; 
00065   
00066   //To deal with Geometry
00067   iSetup.get<CaloTopologyRecord>().get(theCaloTopology); 
00068 
00069   //Loop over electrons
00070   for( collection::const_iterator ele = (*inputHandle).begin(); ele != (*inputHandle).end(); ++ ele ){
00071      
00072     //Find DetID max hit
00073     DetId maxHitId = findMaxHit((*ele).superCluster()->hitsAndFractions(),EBHitsColl,EEHitsColl);
00074     
00075     if(maxHitId.null()){std::cout<<" Null Id"<<std::endl; continue;}
00076 
00077     // Find 3x3 and 5x5 windows around xtal max and compute E3x3,E5x5
00078     double E5x5 = 0.; 
00079     double E3x3 = 0.; 
00080   
00081     const CaloSubdetectorTopology* topology = theCaloTopology->getSubdetectorTopology(DetId::Ecal,maxHitId.subdetId()); 
00082     int WindowSize = 5;
00083     std::vector<DetId> m5x5aroundMax = topology->getWindow(maxHitId,WindowSize,WindowSize); 
00084     E5x5 = EnergyNxN(m5x5aroundMax,EBHitsColl,EEHitsColl);
00085     WindowSize = 3;
00086     std::vector<DetId> m3x3aroundMax = topology->getWindow(maxHitId,WindowSize,WindowSize); 
00087     E3x3 = EnergyNxN(m3x3aroundMax,EBHitsColl,EEHitsColl);
00088 
00089     double pin = ele->trackMomentumAtVtx ().R () ;
00090     double piMpoOpi = (pin - ele->trackMomentumOut ().R ()) / pin ;
00091     double E5x5OPout = E5x5/ele->trackMomentumOut ().R () ;
00092     double E3x3OPin = E3x3/pin;
00093     double E3x3OE5x5 = E3x3/E5x5;
00094     double EseedOPout = ele->eSeedClusterOverPout () ;
00095     double EoPin = ele->eSuperClusterOverP () ;      
00096   
00097     if ( piMpoOpi > PinMPoutOPinMin_ && piMpoOpi < PinMPoutOPinMax_ && 
00098          EseedOPout > ESeedOPoutMin_ && EseedOPout < ESeedOPoutMax_ &&
00099          EoPin > ESCOPinMin_ && EoPin < ESCOPinMax_ &&
00100          E5x5OPout > E5x5OPoutMin_ && E5x5OPout < E5x5OPoutMax_ && 
00101          E3x3OPin > E3x3OPinMin_ && E3x3OPin < E3x3OPinMax_ &&
00102          E3x3OE5x5 > E3x3OE5x5Min_ && E3x3OE5x5 < E3x3OE5x5Max_)
00103       {
00104         selected_.push_back( & (*ele) );
00105       }
00106   }
00107    
00108   return ;
00109 }       
00110 
00111 
00112 // ------------------------------------------------------------
00113 
00114 
00115 SingleEleCalibSelector::~SingleEleCalibSelector()
00116 {}
00117 
00118 
00119 // ------------------------------------------------------------
00120 
00121 
00122 // To find Max Hit
00123 DetId SingleEleCalibSelector::findMaxHit(const std::vector<std::pair<DetId,float> > & v1,
00124                                 const EBRecHitCollection* EBhits,
00125                                 const EERecHitCollection* EEhits) 
00126 {
00127   double currEnergy = 0. ;
00128   DetId maxHit ;
00129   for (std::vector<std::pair<DetId,float> >::const_iterator idsIt = v1.begin () ; 
00130        idsIt != v1.end () ; ++idsIt)
00131     {
00132       if (idsIt->first.subdetId () == EcalBarrel) 
00133         {              
00134           EBRecHitCollection::const_iterator itrechit ;
00135           itrechit = EBhits->find ((*idsIt).first) ;
00136           if (itrechit == EBhits->end () )
00137             {
00138               edm::LogInfo ("reading") << "[findMaxHit] rechit not found! " ;
00139               continue ;
00140             }
00141 //FIXME: use fraction ??
00142           if (itrechit->energy () > currEnergy)
00143             {
00144               currEnergy = itrechit->energy () ;
00145               maxHit= (*idsIt).first ;
00146             }
00147         }
00148       else 
00149         {     
00150           EERecHitCollection::const_iterator itrechit ;
00151           itrechit = EEhits->find ((*idsIt).first) ;
00152           if (itrechit == EEhits->end () )
00153             {
00154               edm::LogInfo ("reading")<< "[findMaxHit] rechit not found! " ;
00155               continue ;
00156             }
00157           
00158           if (itrechit->energy () > currEnergy)
00159             {
00160               currEnergy=itrechit->energy () ;
00161               maxHit= (*idsIt).first ;
00162             }
00163         }
00164     }
00165   return maxHit ;
00166 }
00167 
00168 
00169 // Energy in a window NxN
00170 double SingleEleCalibSelector::EnergyNxN(const std::vector<DetId> & vNxN, 
00171                                    const EBRecHitCollection* EBhits,
00172                                    const EERecHitCollection* EEhits)
00173 {
00174   double dummy = 0.;
00175   int window_size = vNxN.size(); 
00176   for (int ixtal = 0; ixtal < window_size; ixtal++){ 
00177     if (vNxN[ixtal].subdetId() == EcalBarrel) 
00178       { 
00179         EBRecHitCollection::const_iterator it_rechit; 
00180         it_rechit = EBhits->find(vNxN[ixtal]);
00181         dummy+= it_rechit->energy(); 
00182       } 
00183     else 
00184       { 
00185         EERecHitCollection::const_iterator it_rechit;
00186         it_rechit = EEhits->find(vNxN[ixtal]); 
00187         dummy+= it_rechit->energy(); 
00188       } 
00189   }
00190   
00191   return dummy;
00192 }
00193