CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoLocalCalo/HcalRecAlgos/src/HBHEStatusBitSetter.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/HcalRecAlgos/interface/HBHEStatusBitSetter.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "CalibCalorimetry/HcalAlgos/interface/HcalLogicalMapGenerator.h"
00004 #include "CondFormats/HcalObjects/interface/HcalLogicalMap.h"
00005 
00006 HBHEStatusBitSetter::HBHEStatusBitSetter()
00007 {
00008   HcalLogicalMapGenerator gen;
00009   logicalMap_=new HcalLogicalMap(gen.createMap());
00010 
00011   for (int iRm=0;iRm<HcalFrontEndId::maxRmIndex;iRm++) {
00012     hpdMultiplicity_.push_back(0);
00013   }
00014 
00015   nominalPedestal_=3.0;
00016   hitEnergyMinimum_=2.0;
00017   hitMultiplicityThreshold_=17;
00018 }
00019 
00020 HBHEStatusBitSetter::HBHEStatusBitSetter(double nominalPedestal,
00021                                          double hitEnergyMinimum,
00022                                          int hitMultiplicityThreshold,
00023                                          std::vector<edm::ParameterSet> pulseShapeParameterSets
00024                                          )
00025 {
00026   HcalLogicalMapGenerator gen;
00027   logicalMap_=new HcalLogicalMap(gen.createMap());
00028   
00029   for (int iRm=0;iRm<HcalFrontEndId::maxRmIndex;iRm++) {
00030     hpdMultiplicity_.push_back(0);
00031   }
00032 
00033   nominalPedestal_=nominalPedestal;
00034   hitEnergyMinimum_=hitEnergyMinimum;
00035   hitMultiplicityThreshold_=hitMultiplicityThreshold;
00036 
00037   for (unsigned int iPSet=0;iPSet<pulseShapeParameterSets.size();iPSet++) {
00038     edm::ParameterSet pset=pulseShapeParameterSets.at(iPSet);
00039     std::vector<double> params=pset.getParameter<std::vector<double> >("pulseShapeParameters");
00040     pulseShapeParameters_.push_back(params);
00041   }
00042 
00043 }
00044 
00045 HBHEStatusBitSetter::~HBHEStatusBitSetter() {
00046   delete logicalMap_;
00047 }
00048 
00049 void HBHEStatusBitSetter::Clear()
00050 {
00051   for (unsigned int i=0;i<hpdMultiplicity_.size();i++) hpdMultiplicity_[i]=0;
00052 }
00053 
00054 void HBHEStatusBitSetter::SetFlagsFromDigi(HBHERecHit& hbhe, 
00055                                            const HBHEDataFrame& digi,
00056                                            const HcalCoder& coder,
00057                                            const HcalCalibrations& calib,
00058                                            int firstSample,
00059                                            int samplesToAdd
00060                                            )
00061 {
00062   // get firstSample, samplesToAdd from database for each hit
00063   firstSample_ = firstSample;
00064   samplesToAdd_ = samplesToAdd;
00065 
00066   //increment hit multiplicity
00067   if (hbhe.energy()>hitEnergyMinimum_) {
00068     int index=logicalMap_->getHcalFrontEndId(hbhe.detid()).rmIndex();
00069     hpdMultiplicity_.at(index)++;
00070   }
00071 
00072   //set pulse shape bits
00073   // Shuichi's algorithm uses the "correct" charge & pedestals, while Ted's uses "nominal" values.
00074   // Perhaps we should correct Ted's algorithm in the future, though that will mean re-tuning thresholds for his cuts. -- Jeff, 28 May 2010
00075   //double shuichi_charge_total=0.0;
00076   double nominal_charge_total=0.0;  
00077   double charge_max3=-100.0;
00078   double charge_late3=-100.0;
00079   unsigned int slice_max3=0;
00080   unsigned int size=digi.size();
00081  
00082   CaloSamples tool;
00083   coder.adc2fC(digi,tool);
00084 
00085   //  int capid=-1;
00086   for (unsigned int iSlice=0;iSlice<size;iSlice++) 
00087     {
00088       //      capid  = digi.sample(iSlice).capid();
00089       //shuichi_charge_total+=tool[iSlice]-calib.pedestal(capid);
00090       nominal_charge_total+=digi[iSlice].nominal_fC()-nominalPedestal_;
00091 
00092       if (iSlice<2) continue;
00093       // digi[i].nominal_fC() could be replaced by tool[iSlice], I think...  -- Jeff, 11 April 2011
00094       double qsum3=digi[iSlice].nominal_fC() + digi[iSlice-1].nominal_fC() + digi[iSlice-2].nominal_fC() - 3*nominalPedestal_;
00095       if (qsum3>charge_max3) {
00096         charge_max3=qsum3;
00097         slice_max3=iSlice;
00098       }
00099     }
00100 
00101   if ((4+slice_max3)>size) return;
00102   charge_late3=digi[slice_max3+1].nominal_fC() + digi[slice_max3+2].nominal_fC() + digi[slice_max3+3].nominal_fC() - 3*nominalPedestal_;
00103 
00104   for (unsigned int iCut=0;iCut<pulseShapeParameters_.size();iCut++) {
00105     if (pulseShapeParameters_[iCut].size()!=6) continue;
00106     if (nominal_charge_total<pulseShapeParameters_[iCut].at(0) || nominal_charge_total>=pulseShapeParameters_[iCut].at(1)) continue;
00107     if ( charge_late3< (pulseShapeParameters_[iCut].at(2)+nominal_charge_total*pulseShapeParameters_[iCut].at(3)) ) continue;
00108     if ( charge_late3>=(pulseShapeParameters_[iCut].at(4)+nominal_charge_total*pulseShapeParameters_[iCut].at(5)) ) continue;
00109     hbhe.setFlagField(1,HcalCaloFlagLabels::HBHEPulseShape);
00110     return;
00111   }
00112   
00113 }
00114 
00115 void HBHEStatusBitSetter::SetFlagsFromRecHits(HBHERecHitCollection& rec) {
00116   for (HBHERecHitCollection::iterator iHBHE=rec.begin();iHBHE!=rec.end();++iHBHE) {
00117     int index=logicalMap_->getHcalFrontEndId(iHBHE->detid()).rmIndex();
00118     if (hpdMultiplicity_.at(index)<hitMultiplicityThreshold_) continue;
00119     iHBHE->setFlagField(1,HcalCaloFlagLabels::HBHEHpdHitMultiplicity);
00120   }
00121 }