CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLocalCalo/HcalRecAlgos/src/HcalHFStatusBitFromDigis.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalHFStatusBitFromDigis.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 #include <algorithm> // for "max"
00005 #include <math.h>
00006 #include <iostream>
00007 
00008 HcalHFStatusBitFromDigis::HcalHFStatusBitFromDigis()
00009 {
00010   // use simple values in default constructor
00011   minthreshold_=40; // minimum energy threshold (in GeV)
00012 
00013   firstSample_=1; // these are the firstSample, samplesToAdd value of Igor's algorithm -- not necessarily the same as the reco first, toadd values (which are supplied individually for each hit)
00014   samplesToAdd_=3;
00015   expectedPeak_=2;
00016 
00017   // Based on Igor V's algorithm:
00018   //TS4/(TS3+TS4+TS5+TS6) > 0.93 - exp(-0.38275-0.012667*E)
00019   coef0_= 0.93;
00020   coef1_ = -0.38275;
00021   coef2_ = -0.012667;
00022   // Minimum energy of 10 GeV required
00023   HFlongwindowEthresh_=40;
00024   HFlongwindowMinTime_.clear();
00025   HFlongwindowMinTime_.push_back(-10);
00026   HFlongwindowMaxTime_.clear();
00027   HFlongwindowMaxTime_.push_back(8);
00028   HFshortwindowEthresh_=40;
00029   HFshortwindowMinTime_.clear();
00030   HFshortwindowMinTime_.push_back(-10);
00031   HFshortwindowMaxTime_.clear();
00032   HFshortwindowMaxTime_.push_back(8);
00033 }
00034 
00035 HcalHFStatusBitFromDigis::HcalHFStatusBitFromDigis(const edm::ParameterSet& HFDigiTimeParams,
00036                                                    const edm::ParameterSet& HFTimeInWindowParams)
00037 {
00038   // Specify parameters used in forming the HFDigiTime flag
00039   firstSample_        = HFDigiTimeParams.getParameter<int>("HFdigiflagFirstSample");
00040   samplesToAdd_       = HFDigiTimeParams.getParameter<int>("HFdigiflagSamplesToAdd");
00041   expectedPeak_       = HFDigiTimeParams.getParameter<int>("HFdigiflagExpectedPeak");
00042   minthreshold_       = HFDigiTimeParams.getParameter<double>("HFdigiflagMinEthreshold");
00043   coef0_              = HFDigiTimeParams.getParameter<double>("HFdigiflagCoef0");
00044   coef1_              = HFDigiTimeParams.getParameter<double>("HFdigiflagCoef1");
00045   coef2_              = HFDigiTimeParams.getParameter<double>("HFdigiflagCoef2");
00046 
00047   // Specify parameters used in forming HFInTimeWindow flag
00048   HFlongwindowMinTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMinWindowTime");
00049   HFlongwindowMaxTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMaxWindowTime");
00050   HFlongwindowEthresh_    = HFTimeInWindowParams.getParameter<double>("hflongEthresh");
00051   HFshortwindowMinTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMinWindowTime");
00052   HFshortwindowMaxTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMaxWindowTime");
00053   HFshortwindowEthresh_    = HFTimeInWindowParams.getParameter<double>("hfshortEthresh");
00054 }
00055 
00056 HcalHFStatusBitFromDigis::~HcalHFStatusBitFromDigis(){}
00057 
00058 void HcalHFStatusBitFromDigis::resetFlagTimeSamples(int firstSample, int samplesToAdd, int expectedPeak)
00059 {
00060   // This resets the time samples used in the HF flag.  These samples are not necessarily the same 
00061   // as the flags used by the energy reconstruction
00062   firstSample_  = firstSample;
00063   samplesToAdd_ = samplesToAdd;
00064   expectedPeak_ = expectedPeak;
00065 } // void HcalHFStatusBitFromDigis
00066 
00067 void HcalHFStatusBitFromDigis::hfSetFlagFromDigi(HFRecHit& hf, 
00068                                                  const HFDataFrame& digi,
00069                                                  const HcalCoder& coder,
00070                                                  const HcalCalibrations& calib)
00071 {
00072   // The following 3 values are computed by Igor's algorithm 
00073   //only in the window [firstSample_, firstSample_ + samplesToAdd_), 
00074   //which may not be the same as the default reco window.
00075   
00076   double totalCharge=0;
00077   double peakCharge=0;
00078   double RecomputedEnergy=0;
00079 
00080   CaloSamples tool;
00081   coder.adc2fC(digi,tool);
00082 
00083   // Compute quantities needed for HFDigiTime, Fraction2TS FLAGS
00084   for (int i=0;i<digi.size();++i)
00085     {
00086       int capid=digi.sample(i).capid();
00087       double value = tool[i]-calib.pedestal(capid);
00088 
00089 
00090       // Sum all charge within flagging window, find charge in expected peak time slice
00091       if (i >=firstSample_ && i < firstSample_+samplesToAdd_)
00092         {
00093           totalCharge+=value;
00094           RecomputedEnergy+=value*calib.respcorrgain(capid);
00095           if (i==expectedPeak_) peakCharge=value;
00096         }
00097     } // for (int i=0;i<digi.size();++i)
00098   
00099 
00100   // FLAG:  HcalCaloLabels::HFDigiTime
00101   // Igor's algorithm:  compare charge in peak to total charge in window
00102   if (RecomputedEnergy>=minthreshold_)  // don't set noise flags for cells below a given threshold
00103     {
00104       // Calculate allowed minimum value of (TS4/TS3+4+5+6):
00105       double cutoff=coef0_-exp(coef1_+coef2_*RecomputedEnergy);
00106       
00107       if (peakCharge/totalCharge<cutoff)
00108         hf.setFlagField(1,HcalCaloFlagLabels::HFDigiTime);
00109     }
00110 
00111   // FLAG:  HcalCaloLabels:: HFInTimeWindow
00112   // Timing algorithm
00113   if (hf.id().depth()==1)
00114     {
00115       if (hf.energy()>=HFlongwindowEthresh_)
00116         {
00117           float mult=1./hf.energy();
00118           float enPow=1.;
00119           float mintime=0;
00120           float maxtime=0;
00121           for (unsigned int i=0;i<HFlongwindowMinTime_.size();++i)
00122             {
00123               mintime+=HFlongwindowMinTime_[i]*enPow;
00124               maxtime+=HFlongwindowMaxTime_[i]*enPow;
00125               enPow*=mult;
00126             }
00127           if (hf.time()<mintime || hf.time()>maxtime)
00128             hf.setFlagField(1,HcalCaloFlagLabels::HFInTimeWindow);
00129         }
00130     }
00131   else if (hf.id().depth()==2)
00132     {
00133       if (hf.energy()>=HFshortwindowEthresh_)
00134         {
00135           float mult=1./hf.energy();
00136           float enPow=1.;
00137           float mintime=0;
00138           float maxtime=0;
00139           for (unsigned int i=0;i<HFshortwindowMinTime_.size();++i)
00140             {
00141               mintime+=HFshortwindowMinTime_[i]*enPow;
00142               maxtime+=HFshortwindowMaxTime_[i]*enPow;
00143               enPow*=mult;
00144             }
00145           if (hf.time()<mintime || hf.time()>maxtime)
00146             hf.setFlagField(1,HcalCaloFlagLabels::HFInTimeWindow);
00147         }
00148     }
00149 
00150   return;
00151 }
00152