CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoLocalCalo/HcalRecProducers/src/ZdcHitReconstructor.cc

Go to the documentation of this file.
00001 #include "ZdcHitReconstructor.h"
00002 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00003 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00004 #include "DataFormats/Common/interface/EDCollection.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "FWCore/Framework/interface/Selector.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
00010 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00011 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00012 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00013 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
00014 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
00015 
00016 #include <iostream>
00017 
00018 /*  Zdc Hit reconstructor allows for CaloRecHits with status words */
00019 
00020 ZdcHitReconstructor::ZdcHitReconstructor(edm::ParameterSet const& conf):
00021   reco_(conf.getParameter<bool>("correctForTimeslew"),
00022         conf.getParameter<bool>("correctForPhaseContainment"),
00023         conf.getParameter<double>("correctionPhaseNS"),
00024         conf.getParameter<int>("recoMethod"),
00025         conf.getParameter<int>("lowGainOffset"),
00026         conf.getParameter<double>("lowGainFrac")),
00027   det_(DetId::Hcal),
00028   inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
00029   correctTiming_(conf.getParameter<bool>("correctTiming")),
00030   setNoiseFlags_(conf.getParameter<bool>("setNoiseFlags")),
00031   setHSCPFlags_(conf.getParameter<bool>("setHSCPFlags")),
00032   setSaturationFlags_(conf.getParameter<bool>("setSaturationFlags")),
00033   setTimingTrustFlags_(conf.getParameter<bool>("setTimingTrustFlags")),
00034   dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
00035   AuxTSvec_(conf.getParameter<std::vector<int> >("AuxTSvec"))
00036   
00037 { 
00038   std::sort(AuxTSvec_.begin(),AuxTSvec_.end()); // sort vector in ascending TS order
00039   std::string subd=conf.getParameter<std::string>("Subdetector");
00040  
00041  if (setSaturationFlags_)
00042     {
00043       const edm::ParameterSet& pssat      = conf.getParameter<edm::ParameterSet>("saturationParameters");
00044       saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
00045     }
00046   if (!strcasecmp(subd.c_str(),"ZDC")) {
00047     det_=DetId::Calo;
00048     subdet_=HcalZDCDetId::SubdetectorId;
00049     produces<ZDCRecHitCollection>();
00050   } else if (!strcasecmp(subd.c_str(),"CALIB")) {
00051     subdet_=HcalOther;
00052     subdetOther_=HcalCalibration;
00053     produces<HcalCalibRecHitCollection>();
00054   } else {
00055     std::cout << "ZdcHitReconstructor is not associated with a specific subdetector!" << std::endl;
00056   }       
00057   
00058 }
00059 
00060 ZdcHitReconstructor::~ZdcHitReconstructor() {;
00061 }
00062 void ZdcHitReconstructor::beginRun(edm::Run&r, edm::EventSetup const & es){
00063 
00064    edm::ESHandle<HcalLongRecoParams> p;
00065    es.get<HcalLongRecoParamsRcd>().get(p);
00066    myobject = new HcalLongRecoParams(*p.product());
00067 }
00068 
00069 void ZdcHitReconstructor::endRun(edm::Run&r, edm::EventSetup const & es){
00070   if (myobject) delete myobject;
00071 }
00072 void ZdcHitReconstructor::produce(edm::Event& e, const edm::EventSetup& eventSetup)
00073 {
00074   // get conditions
00075   edm::ESHandle<HcalDbService> conditions;
00076   eventSetup.get<HcalDbRecord>().get(conditions);
00077   const HcalQIEShape* shape = conditions->getHcalShape (); // this one is generic
00078   
00079   edm::ESHandle<HcalChannelQuality> p;
00080   eventSetup.get<HcalChannelQualityRcd>().get(p);
00081   HcalChannelQuality* myqual = new HcalChannelQuality(*p.product());
00082 
00083   edm::ESHandle<HcalSeverityLevelComputer> mycomputer;
00084   eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
00085   const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
00086   
00087   // define vectors to pass noiseTS and signalTS
00088   std::vector<unsigned int> mySignalTS;
00089   std::vector<unsigned int> myNoiseTS;
00090   
00091    if (det_==DetId::Calo && subdet_==HcalZDCDetId::SubdetectorId) {
00092      edm::Handle<ZDCDigiCollection> digi;
00093      e.getByLabel(inputLabel_,digi);
00094      
00095      // create empty output
00096      std::auto_ptr<ZDCRecHitCollection> rec(new ZDCRecHitCollection);
00097      rec->reserve(digi->size());
00098      // run the algorithm
00099      ZDCDigiCollection::const_iterator i;
00100      for (i=digi->begin(); i!=digi->end(); i++) {
00101        HcalZDCDetId cell = i->id();
00102       DetId detcell=(DetId)cell;
00103       // check on cells to be ignored and dropped: (rof,20.Feb.09)
00104       const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
00105       if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
00106         if (dropZSmarkedPassed_)
00107           if (i->zsMarkAndPass()) continue;
00108         const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00109         const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
00110         HcalCoderDb coder (*channelCoder, *shape);
00111 
00112 // get db values for signalTSs and noiseTSs
00113    const HcalLongRecoParam* myParams = myobject->getValues(detcell);
00114    mySignalTS.clear();
00115    myNoiseTS.clear();
00116    mySignalTS = myParams->signalTS();
00117    myNoiseTS = myParams->noiseTS(); 
00118 
00119         rec->push_back(reco_.reconstruct(*i,myNoiseTS,mySignalTS,coder,calibrations));
00120         (rec->back()).setFlags(0);
00121         if (setSaturationFlags_)
00122           saturationFlagSetter_->setSaturationFlag(rec->back(),*i);     
00123 
00124         // Set auxiliary flag with subset of digi information
00125         // ZDC aux flag can store non-contiguous set of values
00126         int auxflag=0;
00127         for (unsigned int xx=0; xx<AuxTSvec_.size() && xx<4;++xx)
00128           {
00129             if (AuxTSvec_[xx]<0 || AuxTSvec_[xx]>9) continue; // don't allow 
00130             auxflag+=(i->sample(AuxTSvec_[xx]).adc())<<(7*xx); // store the time slices in the first 28 bits of aux, a set of 4 7-bit a dc values
00131           }
00132         // bits 28 and 29 are reserved for capid of the first time slice saved in aux
00133         if (AuxTSvec_.size()>0)
00134           auxflag+=((i->sample(AuxTSvec_[0]).capid())<<28);
00135         (rec->back()).setAux(auxflag);
00136      }
00137      // return result
00138      e.put(rec);     
00139    } // else if (det_==DetId::Calo...)
00140 
00141    delete myqual;
00142 } // void HcalHitReconstructor::produce(...)