CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoLocalCalo/HcalRecAlgos/src/HBHETimeProfileStatusBitSetter.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/HcalRecAlgos/interface/HBHETimeProfileStatusBitSetter.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalCaloFlagLabels.h"
00004 
00005 #include <algorithm> // for "max"
00006 #include <math.h>
00007 #include <TH1.h>
00008 #include <TF1.h>
00009 
00010 
00011 HBHETimeProfileStatusBitSetter::HBHETimeProfileStatusBitSetter()
00012 {
00013   // use simple values in default constructor
00014   R1Min_ = 0.1;
00015   R1Max_ = 0.7;
00016   R2Min_ = 0.2;
00017   R2Max_ = 0.5;
00018   FracLeaderMin_ = 0.4;
00019   FracLeaderMax_ = 0.7;
00020   SlopeMin_ = -1.5;
00021   SlopeMax_ = -0.6;
00022   OuterMin_ = 0.9;
00023   OuterMax_ = 1.0;
00024   EnergyThreshold_=30;
00025 }
00026 
00027 HBHETimeProfileStatusBitSetter::HBHETimeProfileStatusBitSetter(double R1Min, double R1Max, 
00028                                                                double R2Min, double R2Max, 
00029                                                                double FracLeaderMin, double FracLeaderMax, 
00030                                                                double SlopeMin, double SlopeMax, 
00031                                                                double OuterMin, double OuterMax, 
00032                                                                double EnergyThreshold)
00033 {
00034   R1Min_ = R1Min;
00035   R1Max_ = R1Max;
00036   R2Min_ = R2Min;
00037   R2Max_ = R2Max;
00038   FracLeaderMin_ = FracLeaderMin;
00039   FracLeaderMax_ = FracLeaderMax;
00040   SlopeMin_ = SlopeMin;
00041   SlopeMax_ = SlopeMax;
00042   OuterMin_ = OuterMin;
00043   OuterMax_ = OuterMax;
00044   EnergyThreshold_ = EnergyThreshold;
00045 }
00046 
00047 HBHETimeProfileStatusBitSetter::~HBHETimeProfileStatusBitSetter(){}
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 void HBHETimeProfileStatusBitSetter::hbheSetTimeFlagsFromDigi(HBHERecHitCollection * hbhe, std::vector<HBHEDataFrame> digi, std::vector<int> RecHitIndex)
00058 {
00059   
00060   bool Bits[4]={false, false, false, false};
00061   std::sort(digi.begin(), digi.end(), compare_digi_energy()); // sort digis according to energies
00062   std::vector<double> PulseShape; // store fC values for each time slice
00063   int DigiSize=0;
00064   //  int LeadingEta=0;
00065   int LeadingPhi=0;
00066   bool FoundLeadingChannel=false;
00067   for(std::vector<HBHEDataFrame>::const_iterator itDigi = digi.begin(); itDigi!=digi.end(); itDigi++)
00068     {
00069       if(!FoundLeadingChannel)
00070         {
00071           //      LeadingEta = itDigi->id().ieta();
00072           LeadingPhi = itDigi->id().iphi();
00073           DigiSize=(*itDigi).size();
00074           PulseShape.clear();
00075           PulseShape.resize(DigiSize,0); 
00076           FoundLeadingChannel=true;
00077         }
00078       if(abs(LeadingPhi - itDigi->id().iphi())<2)
00079         for(int i=0; i!=DigiSize; i++)
00080           PulseShape[i]+=itDigi->sample(i).nominal_fC();
00081             
00082     }
00083 
00084 
00085     
00086   if(RecHitIndex.size()>0)
00087     {
00088       double FracInLeader=-1;
00089       //double Slope=0; // not currently used
00090       double R1=-1;
00091       double R2=-1;
00092       double OuterEnergy=-1;
00093       double TotalEnergy=0;
00094       int PeakPosition=0;
00095       
00096       for(int i=0; i!=DigiSize; i++)
00097         {
00098           if(PulseShape[i]>PulseShape[PeakPosition]) 
00099             PeakPosition=i;
00100           TotalEnergy+=PulseShape[i];
00101         }
00102      
00103      
00104       if(PeakPosition < (DigiSize-2))
00105         {
00106           R1 = PulseShape[PeakPosition+1]/PulseShape[PeakPosition];
00107           R2 = PulseShape[PeakPosition+2]/PulseShape[PeakPosition+1];
00108         }
00109       
00110       FracInLeader = PulseShape[PeakPosition]/TotalEnergy;
00111       
00112       if((PeakPosition > 0) && (PeakPosition < (DigiSize-2)))
00113       {
00114         OuterEnergy = 1. -((PulseShape[PeakPosition - 1] +
00115                            PulseShape[PeakPosition]     +
00116                            PulseShape[PeakPosition + 1] +
00117                            PulseShape[PeakPosition + 2] )
00118                            / TotalEnergy);
00119 
00120       }
00121            
00122       /*      TH1D * HistForFit = new TH1D("HistForFit","HistForFit",DigiSize,0,DigiSize);
00123       for(int i=0; i!=DigiSize; i++)
00124         {
00125           HistForFit->Fill(i,PulseShape[i]);
00126           HistForFit->Fit("expo","WWQ","",PeakPosition, DigiSize-1);
00127           TF1 * Fit = HistForFit->GetFunction("expo");
00128           Slope = Fit->GetParameter("Slope");
00129         }
00130       delete HistForFit;
00131       */
00132       if (R1!=-1 && R2!=-1)
00133         Bits[0] = (R1Min_ > R1) || (R1Max_ < R1) || (R2Min_ > R2) || (R2Max_ < R2);
00134       if (FracInLeader!=-1)
00135         Bits[1] = (FracInLeader < FracLeaderMin_) || (FracInLeader > FracLeaderMax_);
00136       if (OuterEnergy!=-1)
00137         Bits[2] = (OuterEnergy < OuterMin_) || (OuterEnergy > OuterMax_);
00138       //  Bits[3] = (SlopeMin_ > Slope) || (SlopeMax_ < Slope);
00139       Bits[3] = false;
00140 
00141     } // if (RecHitIndex.size()>0)
00142   else 
00143     {
00144       
00145       Bits[0]=false;
00146       Bits[1]=false;
00147       Bits[2]=false;
00148       Bits[3]=true;
00149   
00150     } // (RecHitIndex.size()==0; no need to set Bit3 true?)
00151   
00152   for(unsigned int i=0; i!=RecHitIndex.size(); i++)
00153     {
00154 
00155       // Write calculated bit values starting from position FirstBit
00156       (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[0],HcalCaloFlagLabels::HSCP_R1R2);
00157       (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[1],HcalCaloFlagLabels::HSCP_FracLeader);
00158       (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[2],HcalCaloFlagLabels::HSCP_OuterEnergy);
00159       (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[3],HcalCaloFlagLabels::HSCP_ExpFit);
00160  
00161    }
00162  
00163   
00164 
00165 }
00166