CMS 3D CMS Logo

Public Member Functions | Private Attributes

HcalHitReconstructor Class Reference

#include <HcalHitReconstructor.h>

Inheritance diagram for HcalHitReconstructor:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual void beginRun (edm::Run &r, edm::EventSetup const &es)
virtual void endRun (edm::Run &r, edm::EventSetup const &es)
 HcalHitReconstructor (const edm::ParameterSet &ps)
virtual void produce (edm::Event &e, const edm::EventSetup &c)
virtual ~HcalHitReconstructor ()

Private Attributes

bool correctTiming_
DetId::Detector det_
bool dropZSmarkedPassed_
int firstAuxTS_
int firstSample_
HBHEStatusBitSetterhbheFlagSetter_
HBHETimeProfileStatusBitSetterhbheHSCPFlagSetter_
HBHEPulseShapeFlagSetterhbhePulseShapeFlagSetter_
HBHETimingShapedFlagSetterhbheTimingShapedFlagSetter_
HcalHFStatusBitFromDigishfdigibit_
HcalHF_PETalgorithmhfPET_
HcalHF_S9S1algorithmhfS8S1_
HcalHF_S9S1algorithmhfS9S1_
HFTimingTrustFlagHFTimingTrustFlagSetter_
edm::InputTag inputLabel_
HcalRecoParamsparamTS
HcalSimpleRecAlgo reco_
int samplesToAdd_
HcalADCSaturationFlagsaturationFlagSetter_
bool setHSCPFlags_
bool setNoiseFlags_
bool setPulseShapeFlags_
bool setSaturationFlags_
bool setTimingTrustFlags_
int subdet_
HcalOtherSubdetector subdetOther_
bool tsFromDB_

Detailed Description

Date:
2011/05/11 16:46:24
Revision:
1.13.10.2
Author:
J. Temple & E. Yazgan Based on HcalSimpleReconstructor.h by J. Mans

Definition at line 37 of file HcalHitReconstructor.h.


Constructor & Destructor Documentation

HcalHitReconstructor::HcalHitReconstructor ( const edm::ParameterSet ps) [explicit]

Definition at line 20 of file HcalHitReconstructor.cc.

References DetId::Calo, gather_cfg::cout, det_, edm::ParameterSet::getParameter(), hbheFlagSetter_, hbheHSCPFlagSetter_, hbhePulseShapeFlagSetter_, hbheTimingShapedFlagSetter_, HcalBarrel, HcalCalibration, HcalForward, HcalOther, HcalOuter, hfdigibit_, hfPET_, hfS8S1_, hfS9S1_, HFTimingTrustFlagSetter_, saturationFlagSetter_, setHSCPFlags_, setNoiseFlags_, setPulseShapeFlags_, setSaturationFlags_, setTimingTrustFlags_, subdet_, HcalZDCDetId::SubdetectorId, and subdetOther_.

                                                                     :
  reco_(conf.getParameter<bool>("correctForTimeslew"),
        conf.getParameter<bool>("correctForPhaseContainment"),
        conf.getParameter<double>("correctionPhaseNS")),
  det_(DetId::Hcal),
  inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
  correctTiming_(conf.getParameter<bool>("correctTiming")),
  setNoiseFlags_(conf.getParameter<bool>("setNoiseFlags")),
  setHSCPFlags_(conf.getParameter<bool>("setHSCPFlags")),
  setSaturationFlags_(conf.getParameter<bool>("setSaturationFlags")),
  setTimingTrustFlags_(conf.getParameter<bool>("setTimingTrustFlags")),
  setPulseShapeFlags_(conf.getParameter<bool>("setPulseShapeFlags")),
  dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
  firstAuxTS_(conf.getParameter<int>("firstAuxTS")),
  firstSample_(conf.getParameter<int>("firstSample")),
  samplesToAdd_(conf.getParameter<int>("samplesToAdd")),
  tsFromDB_(conf.getParameter<bool>("tsFromDB"))
{

  std::string subd=conf.getParameter<std::string>("Subdetector");
  //Set all FlagSetters to 0
  /* Important to do this!  Otherwise, if the setters are turned off,
     the "if (XSetter_) delete XSetter_;" commands can crash
  */
  hbheFlagSetter_             = 0;
  hbheHSCPFlagSetter_         = 0;
  hbhePulseShapeFlagSetter_   = 0;
  hbheTimingShapedFlagSetter_ = 0;
  hfdigibit_                  = 0;

  hfS9S1_                     = 0;
  hfS8S1_                     = 0;
  hfPET_                      = 0;
  saturationFlagSetter_       = 0;
  HFTimingTrustFlagSetter_    = 0;

  if (setSaturationFlags_)
    {
      const edm::ParameterSet& pssat      = conf.getParameter<edm::ParameterSet>("saturationParameters");
      saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
    }

  if (!strcasecmp(subd.c_str(),"HBHE")) {
    subdet_=HcalBarrel;
    bool timingShapedCutsFlags = conf.getParameter<bool>("setTimingShapedCutsFlags");
    if (timingShapedCutsFlags)
      {
        const edm::ParameterSet& psTshaped = conf.getParameter<edm::ParameterSet>("timingshapedcutsParameters");
        hbheTimingShapedFlagSetter_ = new HBHETimingShapedFlagSetter(psTshaped.getParameter<std::vector<double> >("tfilterEnvelope"),
                                                                     psTshaped.getParameter<bool>("ignorelowest"),
                                                                     psTshaped.getParameter<bool>("ignorehighest"),
                                                                     psTshaped.getParameter<double>("win_offset"),
                                                                     psTshaped.getParameter<double>("win_gain"));
      }
      
    if (setNoiseFlags_)
      {
        const edm::ParameterSet& psdigi    =conf.getParameter<edm::ParameterSet>("flagParameters");
        hbheFlagSetter_=new HBHEStatusBitSetter(psdigi.getParameter<double>("nominalPedestal"),
                                                psdigi.getParameter<double>("hitEnergyMinimum"),
                                                psdigi.getParameter<int>("hitMultiplicityThreshold"),
                                                psdigi.getParameter<std::vector<edm::ParameterSet> >("pulseShapeParameterSets")
         );
      } // if (setNoiseFlags_)
    if (setHSCPFlags_)
      {
        const edm::ParameterSet& psHSCP = conf.getParameter<edm::ParameterSet>("hscpParameters");
        hbheHSCPFlagSetter_ = new HBHETimeProfileStatusBitSetter(psHSCP.getParameter<double>("r1Min"),
                                                                 psHSCP.getParameter<double>("r1Max"),
                                                                 psHSCP.getParameter<double>("r2Min"),
                                                                 psHSCP.getParameter<double>("r2Max"),
                                                                 psHSCP.getParameter<double>("fracLeaderMin"),
                                                                 psHSCP.getParameter<double>("fracLeaderMax"),
                                                                 psHSCP.getParameter<double>("slopeMin"),
                                                                 psHSCP.getParameter<double>("slopeMax"),
                                                                 psHSCP.getParameter<double>("outerMin"),
                                                                 psHSCP.getParameter<double>("outerMax"),
                                                                 psHSCP.getParameter<double>("TimingEnergyThreshold"));
      } // if (setHSCPFlags_) 
    if (setPulseShapeFlags_)
      {
        const edm::ParameterSet &psPulseShape = conf.getParameter<edm::ParameterSet>("pulseShapeParameters");
        hbhePulseShapeFlagSetter_ = new HBHEPulseShapeFlagSetter(
                                                                 psPulseShape.getParameter<double>("MinimumChargeThreshold"),
                                                                 psPulseShape.getParameter<double>("TS4TS5ChargeThreshold"),
                                                                 psPulseShape.getParameter<unsigned int>("TrianglePeakTS"),
                                                                 psPulseShape.getParameter<std::vector<double> >("LinearThreshold"),
                                                                 psPulseShape.getParameter<std::vector<double> >("LinearCut"),
                                                                 psPulseShape.getParameter<std::vector<double> >("RMS8MaxThreshold"),
                                                                 psPulseShape.getParameter<std::vector<double> >("RMS8MaxCut"),
                                                                 psPulseShape.getParameter<std::vector<double> >("LeftSlopeThreshold"),
                                                                 psPulseShape.getParameter<std::vector<double> >("LeftSlopeCut"),
                                                                 psPulseShape.getParameter<std::vector<double> >("RightSlopeThreshold"),
                                                                 psPulseShape.getParameter<std::vector<double> >("RightSlopeCut"),
                                                                 psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallThreshold"),
                                                                 psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallCut"),
                                                                 psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerThreshold"),
                                                                 psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerCut"),
                                                                 psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperThreshold"),
                                                                 psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperCut"),
                                                                 psPulseShape.getParameter<bool>("UseDualFit"),
                         psPulseShape.getParameter<bool>("TriangleIgnoreSlow"));
      }  // if (setPulseShapeFlags_)

    produces<HBHERecHitCollection>();
  } else if (!strcasecmp(subd.c_str(),"HO")) {
    subdet_=HcalOuter;
    produces<HORecHitCollection>();
  } else if (!strcasecmp(subd.c_str(),"HF")) {
    subdet_=HcalForward;

    if (setTimingTrustFlags_) {
      
      const edm::ParameterSet& pstrust      = conf.getParameter<edm::ParameterSet>("hfTimingTrustParameters");
      HFTimingTrustFlagSetter_=new HFTimingTrustFlag(pstrust.getParameter<int>("hfTimingTrustLevel1"),
                                                     pstrust.getParameter<int>("hfTimingTrustLevel2"));
    }

    if (setNoiseFlags_)
      {
        const edm::ParameterSet& psdigi    =conf.getParameter<edm::ParameterSet>("digistat");
        const edm::ParameterSet& psTimeWin =conf.getParameter<edm::ParameterSet>("HFInWindowStat");
        hfdigibit_=new HcalHFStatusBitFromDigis(psdigi,psTimeWin);

        const edm::ParameterSet& psS9S1   = conf.getParameter<edm::ParameterSet>("S9S1stat");
        hfS9S1_   = new HcalHF_S9S1algorithm(psS9S1.getParameter<std::vector<double> >("short_optimumSlope"),
                                             psS9S1.getParameter<std::vector<double> >("shortEnergyParams"),
                                             psS9S1.getParameter<std::vector<double> >("shortETParams"),
                                             psS9S1.getParameter<std::vector<double> >("long_optimumSlope"),
                                             psS9S1.getParameter<std::vector<double> >("longEnergyParams"),
                                             psS9S1.getParameter<std::vector<double> >("longETParams"),
                                             psS9S1.getParameter<int>("flagsToSkip"),
                                             psS9S1.getParameter<bool>("isS8S1")
                                             );

        const edm::ParameterSet& psS8S1   = conf.getParameter<edm::ParameterSet>("S8S1stat");
        hfS8S1_   = new HcalHF_S9S1algorithm(psS8S1.getParameter<std::vector<double> >("short_optimumSlope"),
                                             psS8S1.getParameter<std::vector<double> >("shortEnergyParams"),
                                             psS8S1.getParameter<std::vector<double> >("shortETParams"),
                                             psS8S1.getParameter<std::vector<double> >("long_optimumSlope"),
                                             psS8S1.getParameter<std::vector<double> >("longEnergyParams"),
                                             psS8S1.getParameter<std::vector<double> >("longETParams"),
                                             psS8S1.getParameter<int>("flagsToSkip"),
                                             psS8S1.getParameter<bool>("isS8S1")
                                             );

        const edm::ParameterSet& psPET    = conf.getParameter<edm::ParameterSet>("PETstat");
        hfPET_    = new HcalHF_PETalgorithm(psPET.getParameter<std::vector<double> >("short_R"),
                                            psPET.getParameter<std::vector<double> >("shortEnergyParams"),
                                            psPET.getParameter<std::vector<double> >("shortETParams"),
                                            psPET.getParameter<std::vector<double> >("long_R"),
                                            psPET.getParameter<std::vector<double> >("longEnergyParams"),
                                            psPET.getParameter<std::vector<double> >("longETParams"),
                                            psPET.getParameter<int>("flagsToSkip"),
                                            psPET.getParameter<std::vector<double> >("short_R_29"),
                                            psPET.getParameter<std::vector<double> >("long_R_29")
                                            );
      }
    produces<HFRecHitCollection>();
  } else if (!strcasecmp(subd.c_str(),"ZDC")) {
    det_=DetId::Calo;
    subdet_=HcalZDCDetId::SubdetectorId;
    produces<ZDCRecHitCollection>();
  } else if (!strcasecmp(subd.c_str(),"CALIB")) {
    subdet_=HcalOther;
    subdetOther_=HcalCalibration;
    produces<HcalCalibRecHitCollection>();
  } else {
     std::cout << "HcalHitReconstructor is not associated with a specific subdetector!" << std::endl;
  }       
  
}
HcalHitReconstructor::~HcalHitReconstructor ( ) [virtual]

Member Function Documentation

void HcalHitReconstructor::beginRun ( edm::Run r,
edm::EventSetup const &  es 
) [virtual]
void HcalHitReconstructor::endRun ( edm::Run r,
edm::EventSetup const &  es 
) [virtual]

Reimplemented from edm::EDProducer.

Definition at line 211 of file HcalHitReconstructor.cc.

References paramTS, and tsFromDB_.

                                                                   {
  if (tsFromDB_==true)
    {
      if (paramTS) delete paramTS;
    }
}
void HcalHitReconstructor::produce ( edm::Event e,
const edm::EventSetup c 
) [virtual]

Implements edm::EDProducer.

Definition at line 219 of file HcalHitReconstructor.cc.

References abs, HBHEStatusBitSetter::Clear(), HcalTimingCorrector::Correct(), correctTiming_, det_, HcalSeverityLevelComputer::dropChannel(), dropZSmarkedPassed_, HBHETimeProfileStatusBitSetter::EnergyThreshold(), first, firstAuxTS_, HcalRecoParam::firstSample(), firstSample_, edm::EventSetup::get(), edm::Event::getByLabel(), HcalChannelStatus::getValue(), HcalCondObjectContainer< Item >::getValues(), hbheFlagSetter_, hbheHSCPFlagSetter_, hbhePulseShapeFlagSetter_, HBHETimeProfileStatusBitSetter::hbheSetTimeFlagsFromDigi(), hbheTimingShapedFlagSetter_, DetId::Hcal, HcalBarrel, HcalCalibration, HcalEndcap, HcalForward, HcalOther, HcalOuter, hfdigibit_, hfPET_, hfS8S1_, hfS9S1_, HcalHFStatusBitFromDigis::hfSetFlagFromDigi(), HcalHF_PETalgorithm::HFSetFlagFromPET(), HcalHF_S9S1algorithm::HFSetFlagFromS9S1(), HFTimingTrustFlagSetter_, i, HcalSimpleRecAlgo::initPulseCorr(), inputLabel_, edm::EventBase::isRealData(), j, gen::k, L1TEmulatorMonitor_cff::p, paramTS, HcalCaloFlagLabels::PresampleADC, edm::ESHandle< T >::product(), edm::Event::put(), DetId::rawId(), reco_, HcalSimpleRecAlgo::reconstruct(), HcalHFStatusBitFromDigis::resetFlagTimeSamples(), HcalRecoParam::samplesToAdd(), samplesToAdd_, saturationFlagSetter_, HBHEStatusBitSetter::SetFlagsFromDigi(), HBHEStatusBitSetter::SetFlagsFromRecHits(), HcalSimpleRecAlgo::setForData(), HFTimingTrustFlag::setHFTimingTrustFlag(), setHSCPFlags_, setNoiseFlags_, HBHEPulseShapeFlagSetter::SetPulseShapeFlags(), setPulseShapeFlags_, HcalADCSaturationFlag::setSaturationFlag(), setSaturationFlags_, HBHETimingShapedFlagSetter::SetTimingShapedFlags(), setTimingTrustFlags_, subdet_, subdetOther_, and tsFromDB_.

{

  // get conditions
  edm::ESHandle<HcalDbService> conditions;
  eventSetup.get<HcalDbRecord>().get(conditions);
  const HcalQIEShape* shape = conditions->getHcalShape (); // this one is generic
  // HACK related to HB- corrections
  if(e.isRealData()) reco_.setForData();
    
  edm::ESHandle<HcalChannelQuality> p;
  eventSetup.get<HcalChannelQualityRcd>().get(p);
  HcalChannelQuality* myqual = new HcalChannelQuality(*p.product());

  edm::ESHandle<HcalSeverityLevelComputer> mycomputer;
  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
  
  if (det_==DetId::Hcal) {

    // HBHE -------------------------------------------------------------------
    if (subdet_==HcalBarrel || subdet_==HcalEndcap) {
      edm::Handle<HBHEDigiCollection> digi;
      
      e.getByLabel(inputLabel_,digi);
      
      // create empty output
      std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
      rec->reserve(digi->size());
      // run the algorithm
      if (setNoiseFlags_) hbheFlagSetter_->Clear();
      HBHEDigiCollection::const_iterator i;
      std::vector<HBHEDataFrame> HBDigis;
      std::vector<int> RecHitIndex;

      // Vote on majority TS0 CapId
      int favorite_capid = 0; 
      if (correctTiming_) {
        long capid_votes[4] = {0,0,0,0};
        for (i=digi->begin(); i!=digi->end(); i++) {
          capid_votes[(*i)[0].capid()]++;
        }
        for (int k = 0; k < 4; k++)
          if (capid_votes[k] > capid_votes[favorite_capid])
            favorite_capid = k;
      }

      int toaddMem = 0;
      int first = firstSample_;
      int toadd = samplesToAdd_;

      for (i=digi->begin(); i!=digi->end(); i++) {
        HcalDetId cell = i->id();
        DetId detcell=(DetId)cell;

        // check on cells to be ignored and dropped: (rof,20.Feb.09)
        const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
        if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
        if (dropZSmarkedPassed_)
          if (i->zsMarkAndPass()) continue;

        const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
        const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
        HcalCoderDb coder (*channelCoder, *shape);

        // firstSample & samplesToAdd
        if(tsFromDB_) {
          const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
          first = param_ts->firstSample();    
          toadd = param_ts->samplesToAdd(); 
        }
        if(toaddMem != toadd) {
          reco_.initPulseCorr(toadd);
          toaddMem = toadd;
        }

        rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));

        // Set auxiliary flag
        int auxflag=0;
        int fTS = firstAuxTS_;
        if (fTS<0) fTS=0; // silly protection against time slice <0
        for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
          auxflag+=(i->sample(xx).adc())<<(7*(xx-fTS)); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
        // bits 28 and 29 are reserved for capid of the first time slice saved in aux
        auxflag+=((i->sample(fTS).capid())<<28);
        (rec->back()).setAux(auxflag);

        (rec->back()).setFlags(0);  // this sets all flag bits to 0
        // Set presample flag
        if (fTS>0)
          (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);

        if (hbheTimingShapedFlagSetter_!=0)
          hbheTimingShapedFlagSetter_->SetTimingShapedFlags(rec->back());
        if (setNoiseFlags_)
          hbheFlagSetter_->SetFlagsFromDigi(rec->back(),*i,coder,calibrations,first,toadd);
        if (setPulseShapeFlags_ == true)
          hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
        if (setSaturationFlags_)
          saturationFlagSetter_->setSaturationFlag(rec->back(),*i);
        if (correctTiming_)
          HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
        if (setHSCPFlags_ && i->id().ietaAbs()<16)
          {
            double DigiEnergy=0;
            for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
            if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
              {
                HBDigis.push_back(*i);
                RecHitIndex.push_back(rec->size()-1);
              }
            
          } // if (set HSCPFlags_ && |ieta|<16)
      } // loop over HBHE digis


      if (setNoiseFlags_) hbheFlagSetter_->SetFlagsFromRecHits(*rec);
      if (setHSCPFlags_)  hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
      // return result
      e.put(rec);

      //  HO ------------------------------------------------------------------
    } else if (subdet_==HcalOuter) {
      edm::Handle<HODigiCollection> digi;
      e.getByLabel(inputLabel_,digi);
      
      // create empty output
      std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
      rec->reserve(digi->size());
      // run the algorithm
      HODigiCollection::const_iterator i;

      // Vote on majority TS0 CapId
      int favorite_capid = 0; 
      if (correctTiming_) {
        long capid_votes[4] = {0,0,0,0};
        for (i=digi->begin(); i!=digi->end(); i++) {
          capid_votes[(*i)[0].capid()]++;
        }
        for (int k = 0; k < 4; k++)
          if (capid_votes[k] > capid_votes[favorite_capid])
            favorite_capid = k;
      }

      int toaddMem = 0;
      int first = firstSample_;
      int toadd = samplesToAdd_;

      for (i=digi->begin(); i!=digi->end(); i++) {
        HcalDetId cell = i->id();
        DetId detcell=(DetId)cell;
        // check on cells to be ignored and dropped: (rof,20.Feb.09)
        const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
        if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
        if (dropZSmarkedPassed_)
          if (i->zsMarkAndPass()) continue;

        const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
        const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
        HcalCoderDb coder (*channelCoder, *shape);

        // firstSample & samplesToAdd
        if(tsFromDB_) {
          const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
          first = param_ts->firstSample();    
          toadd = param_ts->samplesToAdd();    
        }
        if(toaddMem != toadd) {
          reco_.initPulseCorr(toadd);
          toaddMem = toadd;
        }
        rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));

        // Set auxiliary flag
        int auxflag=0;
        int fTS = firstAuxTS_;
        if (fTS<0) fTS=0; //silly protection against negative time slice values
        for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
          auxflag+=(i->sample(xx).adc())<<(7*(xx-fTS)); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
        // bits 28 and 29 are reserved for capid of the first time slice saved in aux
        auxflag+=((i->sample(fTS).capid())<<28);
        (rec->back()).setAux(auxflag);

        (rec->back()).setFlags(0);
        // Fill Presample ADC flag
        if (fTS>0)
          (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);

        if (setSaturationFlags_)
          saturationFlagSetter_->setSaturationFlag(rec->back(),*i);
        if (correctTiming_)
          HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
      }
      // return result
      e.put(rec);    

      // HF -------------------------------------------------------------------
    } else if (subdet_==HcalForward) {
      edm::Handle<HFDigiCollection> digi;
      e.getByLabel(inputLabel_,digi);


      // create empty output
      std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
      rec->reserve(digi->size());
      // run the algorithm
      HFDigiCollection::const_iterator i;

      // Vote on majority TS0 CapId
      int favorite_capid = 0; 
      if (correctTiming_) {
        long capid_votes[4] = {0,0,0,0};
        for (i=digi->begin(); i!=digi->end(); i++) {
          capid_votes[(*i)[0].capid()]++;
        }
        for (int k = 0; k < 4; k++)
          if (capid_votes[k] > capid_votes[favorite_capid])
            favorite_capid = k;
      }

      int toaddMem = 0;
      int first = firstSample_;
      int toadd = samplesToAdd_;

      for (i=digi->begin(); i!=digi->end(); i++) {
        HcalDetId cell = i->id();
        DetId detcell=(DetId)cell;
        // check on cells to be ignored and dropped: (rof,20.Feb.09)
        const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
        if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
        if (dropZSmarkedPassed_)
          if (i->zsMarkAndPass()) continue;

        const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
        const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
        HcalCoderDb coder (*channelCoder, *shape);

        // firstSample & samplesToAdd
        if(tsFromDB_) {
          const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
          first = param_ts->firstSample();    
          toadd = param_ts->samplesToAdd();    
        }
        if(toaddMem != toadd) {
          reco_.initPulseCorr(toadd);
          toaddMem = toadd;
        }

        // Digi parameters depending on Reco ones from DB
        if (first ==3 && toadd == 4)  { // 2010 data cfgs
          firstAuxTS_=3;
          // Provide firstSample, samplesToAdd, expected peak for digi flag
          // (This can be different from rechit value!)
          if (hfdigibit_!=0)
            hfdigibit_->resetFlagTimeSamples(3,4,4);
        } // 2010 data; firstSample = 3; samplesToAdd =4 
        else if (first == 4 && toadd == 2)  // 2011 data cfgs, 10-TS digis
          {
            firstAuxTS_=3;
            if (hfdigibit_!=0)
              hfdigibit_->resetFlagTimeSamples(3,3,4);
          } // 2010 data; firstSample = 4; samplesToAdd =2 
        else if (first == 2 && toadd == 2)  // 2011 data cfgs; 6-TS digis
          {
            firstAuxTS_=1;
            if (hfdigibit_!=0)
              hfdigibit_->resetFlagTimeSamples(1,3,2);
          } // 2010 data; firstSample = 2; samplesToAdd =2 

      
        rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));

        // Set auxiliary flag
        int auxflag=0;
        int fTS = firstAuxTS_;
        if (fTS<0) fTS=0; // silly protection against negative time slice values
        for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
          auxflag+=(i->sample(xx).adc())<<(7*(xx-fTS)); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
        // bits 28 and 29 are reserved for capid of the first time slice saved in aux
        auxflag+=((i->sample(fTS).capid())<<28);
        (rec->back()).setAux(auxflag);

        // Clear flags
        (rec->back()).setFlags(0);

        // Fill Presample ADC flag
        if (fTS>0)
          (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);

        // This calls the code for setting the HF noise bit determined from digi shape
        if (setNoiseFlags_) 
          hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
        if (setSaturationFlags_)
          saturationFlagSetter_->setSaturationFlag(rec->back(),*i);
        if (setTimingTrustFlags_)
          HFTimingTrustFlagSetter_->setHFTimingTrustFlag(rec->back(),*i);
        if (correctTiming_)
          HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
      } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis

      // The following flags require the full set of rechits
      // These need to be set consecutively, so an energy check should be the first 
      // test performed on these hits (to minimize the loop time)
      if (setNoiseFlags_) 
        {
          // Step 1:  Set PET flag  (short fibers of |ieta|==29)
          // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
          // won't be considered in these calculations
          for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
            {
              int depth=i->id().depth();
              int ieta=i->id().ieta();
              // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
              if (depth==2 || abs(ieta)==29 ) 
                hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
            }

          // Step 2:  Set S8S1 flag (short fibers or |ieta|==29)
          for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
            {
              int depth=i->id().depth();
              int ieta=i->id().ieta();
              // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
              if (depth==2 || abs(ieta)==29 ) 
                hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
            }

          // Set 3:  Set S9S1 flag (long fibers)
          for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
            {
              int depth=i->id().depth();
              int ieta=i->id().ieta();
              // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
              if (depth==1 && abs(ieta)!=29 ) 
                hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
            }
        }

      // return result
      e.put(rec);     
    } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
      edm::Handle<HcalCalibDigiCollection> digi;
      e.getByLabel(inputLabel_,digi);
      
      // create empty output
      std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
      rec->reserve(digi->size());
      // run the algorithm
      int toaddMem = 0;
      int first = firstSample_;
      int toadd = samplesToAdd_;

      HcalCalibDigiCollection::const_iterator i;
      for (i=digi->begin(); i!=digi->end(); i++) {
        HcalCalibDetId cell = i->id();
        //      HcalDetId cellh = i->id();
        DetId detcell=(DetId)cell;
        // check on cells to be ignored and dropped: (rof,20.Feb.09)
        const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
        if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
        if (dropZSmarkedPassed_)
          if (i->zsMarkAndPass()) continue;

        const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
        const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
        HcalCoderDb coder (*channelCoder, *shape);

        // firstSample & samplesToAdd
        if(tsFromDB_) {
          const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
          first = param_ts->firstSample();    
          toadd = param_ts->samplesToAdd();    
        }
        if(toaddMem != toadd) {
          reco_.initPulseCorr(toadd);
          toaddMem = toadd;
        }
        rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));

        /*
          // Flag setting not available for calibration rechits
        // Set auxiliary flag
        int auxflag=0;
        int fTS = firstAuxTS_;
        for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
          auxflag+=(i->sample(xx).adc())<<(7*(xx-fTS)); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
        // bits 28 and 29 are reserved for capid of the first time slice saved in aux
        auxflag+=((i->sample(fTS).capid())<<28);
        (rec->back()).setAux(auxflag);

        (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
        */
      }
      // return result
      e.put(rec);     
    }
  } 

  delete myqual;
} // void HcalHitReconstructor::produce(...)

Member Data Documentation

Definition at line 62 of file HcalHitReconstructor.h.

Referenced by produce().

Definition at line 57 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 68 of file HcalHitReconstructor.h.

Referenced by produce().

Definition at line 70 of file HcalHitReconstructor.h.

Referenced by produce().

Definition at line 74 of file HcalHitReconstructor.h.

Referenced by produce().

Definition at line 48 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), produce(), and ~HcalHitReconstructor().

Definition at line 49 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), produce(), and ~HcalHitReconstructor().

Definition at line 51 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), produce(), and ~HcalHitReconstructor().

Definition at line 50 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 52 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), produce(), and ~HcalHitReconstructor().

Definition at line 55 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), produce(), and ~HcalHitReconstructor().

Definition at line 54 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 53 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), produce(), and ~HcalHitReconstructor().

Definition at line 47 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 60 of file HcalHitReconstructor.h.

Referenced by produce().

Definition at line 78 of file HcalHitReconstructor.h.

Referenced by beginRun(), endRun(), and produce().

Definition at line 45 of file HcalHitReconstructor.h.

Referenced by produce().

Definition at line 75 of file HcalHitReconstructor.h.

Referenced by produce().

Definition at line 46 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 64 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 63 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 67 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 65 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 66 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 58 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 59 of file HcalHitReconstructor.h.

Referenced by HcalHitReconstructor(), and produce().

Definition at line 76 of file HcalHitReconstructor.h.

Referenced by beginRun(), endRun(), and produce().