Skip to content

Commit

Permalink
Adding New ZDC Hit Reconstructor for Run3
Browse files Browse the repository at this point in the history
ZDC Hit Reconstructor that works with QIE10 digis
  • Loading branch information
matt2275 committed Jun 6, 2024
1 parent 105a40c commit 5eb6cf3
Show file tree
Hide file tree
Showing 2 changed files with 248 additions and 0 deletions.
157 changes: 157 additions & 0 deletions RecoLocalCalo/HcalRecProducers/src/ZdcHitReconstructorRunThree.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include "ZdcHitReconstructorRunThree.h"
#include "DataFormats/Common/interface/EDCollection.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
#include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"

#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"

#include <iostream>

#include "CalibFormats/HcalObjects/interface/HcalCalibrationWidths.h"
#include "CondFormats/HcalObjects/interface/HcalPedestal.h"

/* Zdc Hit reconstructor allows for CaloRecHits with status words */
ZdcHitReconstructorRunThree::ZdcHitReconstructorRunThree(edm::ParameterSet const& conf)

: reco_(conf.getParameter<bool>("correctForTimeslew"),
conf.getParameter<bool>("correctForPhaseContainment"),
conf.getParameter<double>("correctionPhaseNS"),
conf.getParameter<int>("recoMethod"),
conf.getParameter<int>("lowGainOffset"),
conf.getParameter<double>("lowGainFrac")),
saturationFlagSetter_(nullptr),
det_(DetId::Hcal),
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")),
dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
ignoreRPD_(conf.getParameter<bool>("ignoreRPD")),
matchTrigger_(conf.getParameter<bool>("matchTrigger")),
AuxTSvec_(conf.getParameter<std::vector<int> >("AuxTSvec")) {

// commented out hcal and castor digis since not used in RunThree ZDC
// tok_input_hcal = consumes<ZDCDigiCollection>(conf.getParameter<edm::InputTag>("digiLabelhcal"));
// tok_input_castor = consumes<ZDCDigiCollection>(conf.getParameter<edm::InputTag>("digiLabelcastor"));
tok_input_QIE10 = consumes<QIE10DigiCollection>(conf.getParameter<edm::InputTag>("digiLabelQIE10ZDC"));

std::sort(AuxTSvec_.begin(), AuxTSvec_.end()); // sort vector in ascending TS order
std::string subd = conf.getParameter<std::string>("Subdetector");

if (setSaturationFlags_) {
const edm::ParameterSet& pssat = conf.getParameter<edm::ParameterSet>("saturationParameters");
saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
}
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 << "ZdcHitReconstructorRunThree is not associated with a specific subdetector!" << std::endl;
}

// ES tokens
htopoToken_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();
paramsToken_ = esConsumes<HcalLongRecoParams, HcalLongRecoParamsRcd, edm::Transition::BeginRun>();
conditionsToken_ = esConsumes<HcalDbService, HcalDbRecord>();
qualToken_ = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"));
sevToken_ = esConsumes<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd>();
}

ZdcHitReconstructorRunThree::~ZdcHitReconstructorRunThree() { delete saturationFlagSetter_; }

void ZdcHitReconstructorRunThree::beginRun(edm::Run const& r, edm::EventSetup const& es) {
const HcalTopology& htopo = es.getData(htopoToken_);
const HcalLongRecoParams& p = es.getData(paramsToken_);
longRecoParams_ = std::make_unique<HcalLongRecoParams>(p);
longRecoParams_->setTopo(&htopo);
}

void ZdcHitReconstructorRunThree::endRun(edm::Run const& r, edm::EventSetup const& es) {}

void ZdcHitReconstructorRunThree::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
// get conditions
const HcalDbService* conditions = &eventSetup.getData(conditionsToken_);
const HcalChannelQuality* myqual = &eventSetup.getData(qualToken_);
const HcalSeverityLevelComputer* mySeverity = &eventSetup.getData(sevToken_);

// define vectors to pass noiseTS and signalTS
std::vector<unsigned int> mySignalTS;
std::vector<unsigned int> myNoiseTS;

if (det_ == DetId::Calo && subdet_ == HcalZDCDetId::SubdetectorId) {
edm::Handle<QIE10DigiCollection> digi;
e.getByToken(tok_input_QIE10, digi);



// create empty output
auto rec = std::make_unique<ZDCRecHitCollection>();
rec->reserve(digi->size());


// testing QEI10 conditions
for (auto it = digi->begin(); it != digi->end(); it++) {
QIE10DataFrame QIE10_i = static_cast<QIE10DataFrame>(*it);
HcalZDCDetId cell = QIE10_i.id();
if(cell.section() != 1 && cell.section()!= 2 && ignoreRPD_) continue;
if(cell.section() == 1 && cell.channel()> 5) continue; // ignore extra EM channels

DetId detcell = (DetId)cell; // temporarly removed to avoid issue with RPD

// 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 (QIE10_i.zsMarkAndPass())
continue;

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



const HcalLongRecoParam* myParams = longRecoParams_->getValues(detcell);
mySignalTS.clear();
myNoiseTS.clear();
mySignalTS = myParams->signalTS();
myNoiseTS = myParams->noiseTS();

if(matchTrigger_){
const HcalPedestal* Peds = conditions->getPedestal(cell);
const HcalPedestal* effPeds = conditions->getEffectivePedestal(cell);
// for(int capid =0; capid<4; capid++) std::cout<<calibWidths.pedestal(capid)<<std::endl;
rec->push_back(reco_.reconstruct(QIE10_i, myNoiseTS, mySignalTS, coder, calibrations,*effPeds));
}

else rec->push_back(reco_.reconstruct(QIE10_i, myNoiseTS, mySignalTS, coder, calibrations));


//// saturationFlagSetter_ doesn't work with QIE10 so saturation is set in ZDCRecAlgo
// (rec->back()).setFlags(0);
// if (setSaturationFlags_)
// saturationFlagSetter_->setSaturationFlag(rec->back(), QIE10_i);

}
// return result
e.put(std::move(rec));
} // else if (det_==DetId::Calo...)

} // void HcalHitReconstructor::produce(...)

//define this as a plug-in
DEFINE_FWK_MODULE(ZdcHitReconstructorRunThree);
91 changes: 91 additions & 0 deletions RecoLocalCalo/HcalRecProducers/src/ZdcHitReconstructorRunThree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#ifndef ZDCHITRECONSTRUCTORRUNTHREE_H
#define ZDCHITRECONSTRUCTORRUNTHREE_H 1

#include <memory>

#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

#include "RecoLocalCalo/HcalRecAlgos/interface/ZdcSimpleRecAlgo_Run3.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HcalHFStatusBitFromRecHits.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HcalHFStatusBitFromDigis.h"
#include "DataFormats/METReco/interface/HcalCaloFlagLabels.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
#include "CondFormats/HcalObjects/interface/HcalLongRecoParams.h"
#include "CondFormats/HcalObjects/interface/HcalLongRecoParam.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HcalTimingCorrector.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HBHETimeProfileStatusBitSetter.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HBHETimingShapedFlag.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HcalADCSaturationFlag.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HFTimingTrustFlag.h"

#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"

class HcalTopology;
class HcalRecNumberingRecord;
class HcalLongRecoParamsRcd;
class HcalDbService;
class HcalDbRecord;
class HcalChannelQuality;
class HcalChannelQualityRcd;
class HcalSeverityLevelComputer;
class HcalSeverityLevelComputerRcd;

/** \class ZdcHitReconstructorRunThree
\author E. Garcia - CSU
** Based on HcalSimpleReconstructor.h by J. Mans
*/
class ZdcHitReconstructorRunThree : public edm::stream::EDProducer<> {
public:
explicit ZdcHitReconstructorRunThree(const edm::ParameterSet& ps);
~ZdcHitReconstructorRunThree() override;
void beginRun(edm::Run const& r, edm::EventSetup const& es) final;
void endRun(edm::Run const& r, edm::EventSetup const& es) final;
void produce(edm::Event& e, const edm::EventSetup& c) final;

private:
ZdcSimpleRecAlgo_Run3 reco_;
HcalADCSaturationFlag* saturationFlagSetter_;

DetId::Detector det_;
int subdet_;
HcalOtherSubdetector subdetOther_;
// edm::EDGetTokenT<ZDCDigiCollection> tok_input_hcal;
// edm::EDGetTokenT<ZDCDigiCollection> tok_input_castor;
edm::EDGetTokenT<QIE10DigiCollection> tok_input_QIE10;


bool correctTiming_; // turn on/off Ken Rossato's algorithm to fix timing
bool setNoiseFlags_; // turn on/off basic noise flags
bool setHSCPFlags_; // turn on/off HSCP noise flags
bool setSaturationFlags_; // turn on/off flag indicating ADC saturation
bool setTimingTrustFlags_; // turn on/off HF timing uncertainty flag

bool dropZSmarkedPassed_; // turn on/off dropping of zero suppression marked and passed digis
bool ignoreRPD_; // ignore all channels but EM and HCAL if true
bool matchTrigger_; // match trigger method used in 2023 HI datataking using pedestal widths
std::vector<int> AuxTSvec_;

// new lowGainEnergy variables
int lowGainOffset_;
double lowGainFrac_;

std::unique_ptr<HcalLongRecoParams> longRecoParams_; //noiseTS and signalTS from db

// ES tokens
edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> htopoToken_;
edm::ESGetToken<HcalLongRecoParams, HcalLongRecoParamsRcd> paramsToken_;
edm::ESGetToken<HcalDbService, HcalDbRecord> conditionsToken_;
edm::ESGetToken<HcalChannelQuality, HcalChannelQualityRcd> qualToken_;
edm::ESGetToken<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd> sevToken_;
};

#endif

0 comments on commit 5eb6cf3

Please sign in to comment.