Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:32

0001 #include "ZdcHitReconstructor.h"
0002 #include "DataFormats/Common/interface/EDCollection.h"
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
0006 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
0007 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0008 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0009 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
0010 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
0011 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0012 
0013 #include <iostream>
0014 
0015 /*  Zdc Hit reconstructor allows for CaloRecHits with status words */
0016 
0017 ZdcHitReconstructor::ZdcHitReconstructor(edm::ParameterSet const& conf)
0018     : reco_(conf.getParameter<bool>("correctForTimeslew"),
0019             conf.getParameter<bool>("correctForPhaseContainment"),
0020             conf.getParameter<double>("correctionPhaseNS"),
0021             conf.getParameter<int>("recoMethod"),
0022             conf.getParameter<int>("lowGainOffset"),
0023             conf.getParameter<double>("lowGainFrac")),
0024       saturationFlagSetter_(nullptr),
0025       det_(DetId::Hcal),
0026       correctTiming_(conf.getParameter<bool>("correctTiming")),
0027       setNoiseFlags_(conf.getParameter<bool>("setNoiseFlags")),
0028       setHSCPFlags_(conf.getParameter<bool>("setHSCPFlags")),
0029       setSaturationFlags_(conf.getParameter<bool>("setSaturationFlags")),
0030       setTimingTrustFlags_(conf.getParameter<bool>("setTimingTrustFlags")),
0031       dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
0032       AuxTSvec_(conf.getParameter<std::vector<int> >("AuxTSvec")) {
0033   tok_input_hcal = consumes<ZDCDigiCollection>(conf.getParameter<edm::InputTag>("digiLabelhcal"));
0034   tok_input_castor = consumes<ZDCDigiCollection>(conf.getParameter<edm::InputTag>("digiLabelcastor"));
0035 
0036   std::sort(AuxTSvec_.begin(), AuxTSvec_.end());  // sort vector in ascending TS order
0037   std::string subd = conf.getParameter<std::string>("Subdetector");
0038 
0039   if (setSaturationFlags_) {
0040     const edm::ParameterSet& pssat = conf.getParameter<edm::ParameterSet>("saturationParameters");
0041     saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
0042   }
0043   if (!strcasecmp(subd.c_str(), "ZDC")) {
0044     det_ = DetId::Calo;
0045     subdet_ = HcalZDCDetId::SubdetectorId;
0046     produces<ZDCRecHitCollection>();
0047   } else if (!strcasecmp(subd.c_str(), "CALIB")) {
0048     subdet_ = HcalOther;
0049     subdetOther_ = HcalCalibration;
0050     produces<HcalCalibRecHitCollection>();
0051   } else {
0052     std::cout << "ZdcHitReconstructor is not associated with a specific subdetector!" << std::endl;
0053   }
0054 
0055   // ES tokens
0056   htopoToken_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();
0057   paramsToken_ = esConsumes<HcalLongRecoParams, HcalLongRecoParamsRcd, edm::Transition::BeginRun>();
0058   conditionsToken_ = esConsumes<HcalDbService, HcalDbRecord>();
0059   qualToken_ = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"));
0060   sevToken_ = esConsumes<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd>();
0061 }
0062 
0063 ZdcHitReconstructor::~ZdcHitReconstructor() { delete saturationFlagSetter_; }
0064 
0065 void ZdcHitReconstructor::beginRun(edm::Run const& r, edm::EventSetup const& es) {
0066   const HcalTopology& htopo = es.getData(htopoToken_);
0067   const HcalLongRecoParams& p = es.getData(paramsToken_);
0068   longRecoParams_ = std::make_unique<HcalLongRecoParams>(p);
0069   longRecoParams_->setTopo(&htopo);
0070 }
0071 
0072 void ZdcHitReconstructor::endRun(edm::Run const& r, edm::EventSetup const& es) {}
0073 
0074 void ZdcHitReconstructor::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0075   // get conditions
0076   const HcalDbService* conditions = &eventSetup.getData(conditionsToken_);
0077   const HcalChannelQuality* myqual = &eventSetup.getData(qualToken_);
0078   const HcalSeverityLevelComputer* mySeverity = &eventSetup.getData(sevToken_);
0079 
0080   // define vectors to pass noiseTS and signalTS
0081   std::vector<unsigned int> mySignalTS;
0082   std::vector<unsigned int> myNoiseTS;
0083 
0084   if (det_ == DetId::Calo && subdet_ == HcalZDCDetId::SubdetectorId) {
0085     edm::Handle<ZDCDigiCollection> digi;
0086     e.getByToken(tok_input_hcal, digi);
0087 
0088     if (digi->empty()) {
0089       edm::Handle<ZDCDigiCollection> digi_castor;
0090       e.getByToken(tok_input_castor, digi_castor);
0091       if (!digi_castor.isValid() || digi_castor->empty())
0092         edm::LogInfo("ZdcHitReconstructor") << "No ZDC info found in either castorDigis or hcalDigis." << std::endl;
0093       if (digi_castor.isValid())
0094         e.getByToken(tok_input_castor, digi);
0095     }
0096 
0097     // create empty output
0098     auto rec = std::make_unique<ZDCRecHitCollection>();
0099     rec->reserve(digi->size());
0100     // run the algorithm
0101     ZDCDigiCollection::const_iterator i;
0102     for (i = digi->begin(); i != digi->end(); i++) {
0103       HcalZDCDetId cell = i->id();
0104       DetId detcell = (DetId)cell;
0105       // check on cells to be ignored and dropped: (rof,20.Feb.09)
0106       const HcalChannelStatus* mydigistatus = myqual->getValues(detcell.rawId());
0107       if (mySeverity->dropChannel(mydigistatus->getValue()))
0108         continue;
0109       if (dropZSmarkedPassed_)
0110         if (i->zsMarkAndPass())
0111           continue;
0112       const HcalCalibrations& calibrations = conditions->getHcalCalibrations(cell);
0113       const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
0114       const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
0115       HcalCoderDb coder(*channelCoder, *shape);
0116 
0117       // get db values for signalTSs and noiseTSs
0118       const HcalLongRecoParam* myParams = longRecoParams_->getValues(detcell);
0119       mySignalTS.clear();
0120       myNoiseTS.clear();
0121       mySignalTS = myParams->signalTS();
0122       myNoiseTS = myParams->noiseTS();
0123 
0124       rec->push_back(reco_.reconstruct(*i, myNoiseTS, mySignalTS, coder, calibrations));
0125       (rec->back()).setFlags(0);
0126       if (setSaturationFlags_)
0127         saturationFlagSetter_->setSaturationFlag(rec->back(), *i);
0128 
0129       // Set auxiliary flag with subset of digi information
0130       // ZDC aux flag can store non-contiguous set of values
0131       int auxflag = 0;
0132       for (unsigned int xx = 0; xx < AuxTSvec_.size() && xx < 4; ++xx) {
0133         if (AuxTSvec_[xx] < 0 || AuxTSvec_[xx] > 9)
0134           continue;  // don't allow
0135         auxflag += (i->sample(AuxTSvec_[xx]).adc())
0136                    << (7 * xx);  // store the time slices in the first 28 bits of aux, a set of 4 7-bit a dc values
0137       }
0138       // bits 28 and 29 are reserved for capid of the first time slice saved in aux
0139       if (!AuxTSvec_.empty())
0140         auxflag += ((i->sample(AuxTSvec_[0]).capid()) << 28);
0141       (rec->back()).setAux(auxflag);
0142     }
0143     // return result
0144     e.put(std::move(rec));
0145   }  // else if (det_==DetId::Calo...)
0146 
0147 }  // void HcalHitReconstructor::produce(...)