CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/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   coef_.push_back(0.93);
00020   coef_.push_back(-0.38275);
00021   coef_.push_back(-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   coef_              = HFDigiTimeParams.getParameter<std::vector<double> >("HFdigiflagCoef");
00044 
00045   // Specify parameters used in forming HFInTimeWindow flag
00046   HFlongwindowMinTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMinWindowTime");
00047   HFlongwindowMaxTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMaxWindowTime");
00048   HFlongwindowEthresh_    = HFTimeInWindowParams.getParameter<double>("hflongEthresh");
00049   HFshortwindowMinTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMinWindowTime");
00050   HFshortwindowMaxTime_    = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMaxWindowTime");
00051   HFshortwindowEthresh_    = HFTimeInWindowParams.getParameter<double>("hfshortEthresh");
00052 }
00053 
00054 HcalHFStatusBitFromDigis::~HcalHFStatusBitFromDigis(){}
00055 
00056 void HcalHFStatusBitFromDigis::resetParamsFromDB(int firstSample, int samplesToAdd, int expectedPeak, double minthreshold, std::vector<double> coef)
00057 {
00058   // Resets values based on values in database.
00059   firstSample_  = firstSample;
00060   samplesToAdd_ = samplesToAdd;
00061   expectedPeak_ = expectedPeak;
00062   minthreshold_ = minthreshold;
00063   coef_         = coef;
00064 }
00065 
00066 
00067 void HcalHFStatusBitFromDigis::resetFlagTimeSamples(int firstSample, int samplesToAdd, int expectedPeak)
00068 {
00069   // This resets the time samples used in the HF flag.  These samples are not necessarily the same 
00070   // as the flags used by the energy reconstruction
00071   firstSample_  = firstSample;
00072   samplesToAdd_ = samplesToAdd;
00073   expectedPeak_ = expectedPeak;
00074 } // void HcalHFStatusBitFromDigis
00075 
00076 void HcalHFStatusBitFromDigis::hfSetFlagFromDigi(HFRecHit& hf, 
00077                                                  const HFDataFrame& digi,
00078                                                  const HcalCoder& coder,
00079                                                  const HcalCalibrations& calib)
00080 {
00081   // The following 3 values are computed by Igor's algorithm 
00082   //only in the window [firstSample_, firstSample_ + samplesToAdd_), 
00083   //which may not be the same as the default reco window.
00084  
00085   double totalCharge=0;
00086   double peakCharge=0;
00087   double RecomputedEnergy=0;
00088 
00089   CaloSamples tool;
00090   coder.adc2fC(digi,tool);
00091 
00092   // Compute quantities needed for HFDigiTime, Fraction2TS FLAGS
00093   for (int i=0;i<digi.size();++i)
00094     {
00095       int capid=digi.sample(i).capid();
00096       double value = tool[i]-calib.pedestal(capid);
00097 
00098 
00099       // Sum all charge within flagging window, find charge in expected peak time slice
00100       if (i >=firstSample_ && i < firstSample_+samplesToAdd_)
00101         {
00102           totalCharge+=value;
00103           RecomputedEnergy+=value*calib.respcorrgain(capid);
00104           if (i==expectedPeak_) peakCharge=value;
00105         }
00106     } // for (int i=0;i<digi.size();++i)
00107 
00108   // FLAG:  HcalCaloLabels::HFDigiTime
00109   // Igor's algorithm:  compare charge in peak to total charge in window
00110   if (RecomputedEnergy>=minthreshold_)  // don't set noise flags for cells below a given threshold
00111     {
00112       // Calculate allowed minimum value of (TS4/TS3+4+5+6):
00113       double cutoff=0; // no arguments specified; no cutoff applied
00114       if (coef_.size()>0)
00115         cutoff=coef_[0];
00116       // default cutoff takes the form:
00117       // cutoff = coef_[0] - exp(coef_[1]+coef_[2]*E+coef_[3]*E^2+...)
00118       double powRE=1;
00119       double expo_arg=0;
00120       for (unsigned int zz=1;zz<coef_.size();++zz)
00121         {
00122           expo_arg+=coef_[zz]*powRE;
00123           powRE*=RecomputedEnergy;
00124         }
00125       cutoff-=exp(expo_arg);
00126       
00127       if (peakCharge/totalCharge<cutoff)
00128         hf.setFlagField(1,HcalCaloFlagLabels::HFDigiTime);
00129     }
00130 
00131   // FLAG:  HcalCaloLabels:: HFInTimeWindow
00132   // Timing algorithm
00133   if (hf.id().depth()==1)
00134     {
00135       if (hf.energy()>=HFlongwindowEthresh_)
00136         {
00137           float mult=1./hf.energy();
00138           float enPow=1.;
00139           float mintime=0;
00140           float maxtime=0;
00141           for (unsigned int i=0;i<HFlongwindowMinTime_.size();++i)
00142             {
00143               mintime+=HFlongwindowMinTime_[i]*enPow;
00144               maxtime+=HFlongwindowMaxTime_[i]*enPow;
00145               enPow*=mult;
00146             }
00147           if (hf.time()<mintime || hf.time()>maxtime)
00148             hf.setFlagField(1,HcalCaloFlagLabels::HFInTimeWindow);
00149         }
00150     }
00151   else if (hf.id().depth()==2)
00152     {
00153       if (hf.energy()>=HFshortwindowEthresh_)
00154         {
00155           float mult=1./hf.energy();
00156           float enPow=1.;
00157           float mintime=0;
00158           float maxtime=0;
00159           for (unsigned int i=0;i<HFshortwindowMinTime_.size();++i)
00160             {
00161               mintime+=HFshortwindowMinTime_[i]*enPow;
00162               maxtime+=HFshortwindowMaxTime_[i]*enPow;
00163               enPow*=mult;
00164             }
00165           if (hf.time()<mintime || hf.time()>maxtime)
00166             hf.setFlagField(1,HcalCaloFlagLabels::HFInTimeWindow);
00167         }
00168     }
00169 
00170   return;
00171 }
00172