CMS 3D CMS Logo

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