CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMET/METAlgorithms/src/HcalHaloAlgo.cc

Go to the documentation of this file.
00001 #include "RecoMET/METAlgorithms/interface/HcalHaloAlgo.h"
00002 
00003 /*
00004   [class]:  HcalHaloAlgo
00005   [authors]: R. Remington, The University of Florida
00006   [description]: See HcalHaloAlgo.h
00007   [date]: October 15, 2009
00008 */
00009 
00010 using namespace std;
00011 using namespace edm;
00012 using namespace reco;
00013 
00014 #include <iomanip>
00015 bool CompareTime(const HBHERecHit* x, const HBHERecHit* y ){ return x->time() < y->time() ;}
00016 
00017 HcalHaloAlgo::HcalHaloAlgo()
00018 {
00019   HBRecHitEnergyThreshold = 0.;
00020   HERecHitEnergyThreshold = 0.;
00021   SumEnergyThreshold = 0.;
00022   NHitsThreshold = 0;
00023 }
00024 
00025 HcalHaloData HcalHaloAlgo::Calculate(const CaloGeometry& TheCaloGeometry, edm::Handle<HBHERecHitCollection>& TheHBHERecHits)
00026 {
00027   HcalHaloData TheHcalHaloData;
00028   
00029   // Store Energy sum of rechits as a function of iPhi (iPhi goes from 1 to 72)
00030   float SumE[73];
00031   // Store Number of rechits as a function of iPhi 
00032   int NumHits[73];
00033   // Store minimum time of rechit as a function of iPhi
00034   float MinTimeHits[73];
00035   // Store maximum time of rechit as a function of iPhi
00036   float MaxTimeHits[73];
00037   for(unsigned int i = 0 ; i < 73 ; i++ ) 
00038     {
00039       SumE[i] = 0;
00040       NumHits[i]= 0;
00041       MinTimeHits[i] = 0.;
00042       MaxTimeHits[i] = 0.;
00043     }
00044   
00045   for( HBHERecHitCollection::const_iterator hit = TheHBHERecHits->begin() ; hit != TheHBHERecHits->end() ; hit++ )
00046     {
00047       HcalDetId id = HcalDetId(hit->id());                                                                                                    
00048       switch ( id.subdet() )                                                                                         
00049         {      
00050         case HcalBarrel:                                                                           
00051           if(hit->energy() < HBRecHitEnergyThreshold )continue;
00052           break;                                                                                                                  
00053         case HcalEndcap:                                                                                          
00054           if(hit->energy() < HERecHitEnergyThreshold ) continue;
00055           break;
00056         default:
00057           continue;
00058         }
00059       
00060       int iEta = id.ieta();
00061       int iPhi = id.iphi();
00062       if(iPhi < 73 && TMath::Abs(iEta) < 23 )
00063         { 
00064           SumE[iPhi]+= hit->energy();
00065           NumHits[iPhi] ++;
00066           
00067           float time = hit->time();
00068           MinTimeHits[iPhi] = time < MinTimeHits[iPhi] ? time : MinTimeHits[iPhi];
00069           MaxTimeHits[iPhi] = time > MaxTimeHits[iPhi] ? time : MaxTimeHits[iPhi];
00070         }
00071     }
00072   
00073   for( int iPhi = 1 ; iPhi < 73 ; iPhi++ )
00074     {
00075       if( SumE[iPhi] >= SumEnergyThreshold && NumHits[iPhi] > NHitsThreshold )
00076         {
00077           // Build PhiWedge and store to HcalHaloData if energy or #hits pass thresholds
00078           PhiWedge wedge(SumE[iPhi], iPhi, NumHits[iPhi], MinTimeHits[iPhi], MaxTimeHits[iPhi]);
00079           
00080           // Loop over rechits again to calculate direction based on timing info
00081           std::vector<const HBHERecHit*> Hits;
00082           for( HBHERecHitCollection::const_iterator hit = TheHBHERecHits->begin() ; hit != TheHBHERecHits->end() ; hit++ )
00083             {
00084 
00085               HcalDetId id = HcalDetId(hit->id());
00086               if( id.iphi() != iPhi ) continue;
00087               if( TMath::Abs(id.ieta() ) > 22 ) continue;  // has to overlap geometrically w/ HB
00088               switch ( id.subdet() )
00089                 {
00090                 case HcalBarrel:
00091                   if(hit->energy() < HBRecHitEnergyThreshold )continue;
00092                   break;
00093                 case HcalEndcap:
00094                   if(hit->energy() < HERecHitEnergyThreshold ) continue;
00095                   break;
00096                 default:
00097                   continue;
00098                 }
00099               Hits.push_back(&(*hit));
00100             }
00101               
00102           std::sort( Hits.begin() , Hits.end() , CompareTime);
00103           float MinusToPlus = 0.;
00104           float PlusToMinus = 0.;
00105           for( unsigned int i = 0 ; i < Hits.size() ; i++ )
00106             {
00107               HcalDetId id_i = HcalDetId(Hits[i]->id() );
00108               int ieta_i = id_i.ieta();
00109               for( unsigned int j = (i+1) ; j < Hits.size() ; j++ )
00110                 {
00111                   HcalDetId id_j = HcalDetId(Hits[j]->id() );
00112                   int ieta_j = id_j.ieta();
00113                   if( ieta_i > ieta_j ) PlusToMinus += TMath::Abs(ieta_i - ieta_j ) ;
00114                   else MinusToPlus += TMath::Abs(ieta_i - ieta_j);
00115                 }
00116             }
00117           float PlusZOriginConfidence = (PlusToMinus + MinusToPlus )? PlusToMinus / ( PlusToMinus + MinusToPlus ) : -1. ;
00118           wedge.SetPlusZOriginConfidence( PlusZOriginConfidence );
00119           TheHcalHaloData.GetPhiWedges().push_back( wedge );
00120         }
00121     }
00122   return TheHcalHaloData;
00123   
00124 }
00125 
00126