CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/SimCalorimetry/HcalZeroSuppressionAlgos/src/HcalZSAlgoEnergy.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/HcalZeroSuppressionAlgos/interface/HcalZSAlgoEnergy.h"
00002 #include "CondFormats/HcalObjects/interface/HcalPedestal.h"
00003 #include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
00004 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
00005 #include <iostream>
00006 
00007 HcalZSAlgoEnergy::HcalZSAlgoEnergy(bool mp,int level, int start, int samples, bool twosided) : 
00008   HcalZeroSuppressionAlgo(mp),
00009   threshold_(level),
00010   firstsample_(start),
00011   samplecount_(samples),
00012   twosided_(twosided)
00013 {
00014 }
00015 
00016 namespace ZSEnergy_impl {
00017   
00018   template <class DIGI> 
00019   bool keepMe(const HcalDbService& db, const DIGI& inp, int threshold, int firstSample, int samples, bool twosided) {
00020     bool keepIt=false;
00021     const HcalQIEShape* shape = db.getHcalShape (); // this one is generic
00022     const HcalQIECoder* channelCoder = db.getHcalCoder (inp.id());
00023 
00024     // determine average pedestal for channel
00025     float pedsum=0, pedave=0, offset=0, slope=0;
00026     const HcalPedestal* ped=db.getPedestal(inp.id());
00027     for (int j=0; j<4; j++) {
00028       pedave+=ped->getValue(j)/4.0;
00029       offset+=channelCoder->charge(*shape,0,j)/4.0;
00030       slope+=channelCoder->charge(*shape,1,j)/4.0;
00031     }
00032     slope-=offset;
00033     pedave-=offset;
00034     pedave/=slope;
00035       
00036     int sum=0;
00037 
00038     for (int j=0; j<samples && j+firstSample < inp.size(); j++) {
00039       sum+=inp[j+firstSample].adc();
00040       pedsum+=pedave;
00041     }
00042     //    int presum=sum;
00043     sum-=(int)(pedsum);
00044 
00045     if (sum>=threshold) keepIt=true;
00046     else if (sum<=(-threshold) && twosided) keepIt=true;
00047     /*
00048       else
00049      std::cout << inp.id() << " " << sum << ":" << presum << " " << threshold 
00050       << " " << pedsum << " " << pedave
00051       << " " << offset << " " << slope 
00052       << std::endl;
00053     */
00054     return keepIt;
00055   }
00056 }
00057 
00058 bool HcalZSAlgoEnergy::shouldKeep(const HBHEDataFrame& digi) const {
00059   return ZSEnergy_impl::keepMe<HBHEDataFrame>(*db_,digi,threshold_,firstsample_,samplecount_,twosided_);
00060 }
00061 bool HcalZSAlgoEnergy::shouldKeep(const HODataFrame& digi) const {
00062   return ZSEnergy_impl::keepMe<HODataFrame>(*db_,digi,threshold_,firstsample_,samplecount_,twosided_);
00063 }
00064 bool HcalZSAlgoEnergy::shouldKeep(const HFDataFrame& digi) const {
00065   return ZSEnergy_impl::keepMe<HFDataFrame>(*db_,digi,threshold_,firstsample_,samplecount_,twosided_);
00066 }
00067 
00068 void HcalZSAlgoEnergy::prepare(const HcalDbService* db) { db_=db; }
00069 void HcalZSAlgoEnergy::done() { db_=0; }