Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HGCAL: Change ToA to global time in DIGI #39720

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,6 +9,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(60),
tdcSaturation = cms.double(10000),
tofDelay = cms.double(-9),
toaLSB_ns = cms.double(0.0244)
),
HGCEEdigiCollection = cms.InputTag("hgcalDigisL1Seeded","EE"),
Expand All @@ -21,6 +22,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(55),
tdcSaturation = cms.double(1000),
tofDelay = cms.double(-14),
toaLSB_ns = cms.double(0.0244)
),
HGCHEBdigiCollection = cms.InputTag("hgcalDigisL1Seeded","HEback"),
Expand All @@ -33,6 +35,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(60),
tdcSaturation = cms.double(10000),
tofDelay = cms.double(-11),
toaLSB_ns = cms.double(0.0244)
),
HGCHEFdigiCollection = cms.InputTag("hgcalDigisL1Seeded","HEfront"),
Expand All @@ -45,6 +48,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(60),
tdcSaturation = cms.double(10000),
tofDelay = cms.double(-33),
toaLSB_ns = cms.double(0.0244)
),
HGCHFNosedigiCollection = cms.InputTag("hfnoseDigis","HFNose"),
Expand Down
Expand Up @@ -9,6 +9,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(60),
tdcSaturation = cms.double(10000),
tofDelay = cms.double(-9),
toaLSB_ns = cms.double(0.0244)
),
HGCEEdigiCollection = cms.InputTag("hgcalDigis","EE"),
Expand All @@ -21,6 +22,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(55),
tdcSaturation = cms.double(1000),
tofDelay = cms.double(-14),
toaLSB_ns = cms.double(0.0244)
),
HGCHEBdigiCollection = cms.InputTag("hgcalDigis","HEback"),
Expand All @@ -33,6 +35,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(60),
tdcSaturation = cms.double(10000),
tofDelay = cms.double(-11),
toaLSB_ns = cms.double(0.0244)
),
HGCHEFdigiCollection = cms.InputTag("hgcalDigis","HEfront"),
Expand All @@ -45,6 +48,7 @@
tdcNbits = cms.uint32(12),
tdcOnset = cms.double(60),
tdcSaturation = cms.double(10000),
tofDelay = cms.double(-33),
toaLSB_ns = cms.double(0.0244)
),
HGCHFNosedigiCollection = cms.InputTag("hfnoseDigis","HFNose"),
Expand Down
Expand Up @@ -33,23 +33,26 @@ class HGCalUncalibRecHitRecWeightsAlgo {

void set_tdcOnsetfC(const double tdcOnset) { tdcOnsetfC_ = tdcOnset; }

void set_tofDelay(const double tofDelay) { tofDelay_ = tofDelay; }

void set_fCPerMIP(const std::vector<double>& fCPerMIP) {
if (std::any_of(fCPerMIP.cbegin(), fCPerMIP.cend(), [](double conv) { return conv <= 0.0; })) {
throw cms::Exception("BadConversionFactor") << "At least one of fCPerMIP is zero!" << std::endl;
}
fCPerMIP_ = fCPerMIP;
}

void setGeometry(const HGCalGeometry* geom) {
if (geom)
ddd_ = &(geom->topology().dddConstants());
void setGeometry(const edm::ESHandle<HGCalGeometry>& geom) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: you could use bool setGeometry (instead of void), returning geom_ != nullptr (or similar), to give the user a handle to know if geom_ was set or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. Implemented in commit.

geom_ = geom.isValid() ? geom.product() : nullptr;
if (isSiFESim_ && geom_)
ddd_ = &(geom_->topology().dddConstants());
else
ddd_ = nullptr;
}

/// Compute HGCUncalibratedRecHit from DataFrame
virtual HGCUncalibratedRecHit makeRecHit(const C& dataFrame) {
double amplitude_(-1.), pedestal_(-1.), jitter_(-1.), chi2_(-1.);
double amplitude_(-1.), pedestal_(-1.), jitter_(-99.), chi2_(-1.);
uint32_t flag = 0;

constexpr int iSample = 2; //only in-time sample
Expand All @@ -68,23 +71,21 @@ class HGCalUncalibRecHitRecWeightsAlgo {
// LG (11/04/2016):
// offset the TDC upwards to reflect the bin center
amplitude_ = (std::floor(tdcOnsetfC_ / adcLSB_) + 1.0) * adcLSB_ + (double(sample.data()) + 0.5) * tdcLSB_;

if (sample.getToAValid()) {
jitter_ = double(sample.toa()) * toaLSBToNS_;
}
} else {
amplitude_ = double(sample.data()) * adcLSB_; // why do we not have +0.5 here ?
if (sample.getToAValid()) {
jitter_ = double(sample.toa()) * toaLSBToNS_;
}
} //isSiFESim_
} //mode()
} //isSiFESim_
} //mode()

// trivial digitization, i.e. no signal shape
else {
amplitude_ = double(sample.data()) * adcLSB_;
}

if (sample.getToAValid()) {
const auto& dist2center = geom_ ? geom_->getPosition(dataFrame.id()).mag() : 0;
jitter_ = double(sample.toa()) * toaLSBToNS_ - dist2center / c_cm_ns - tofDelay_;
}

int thickness = (ddd_ != nullptr) ? ddd_->waferType(dataFrame.id()) : 0;
amplitude_ = amplitude_ / fCPerMIP_[thickness];

Expand All @@ -100,9 +101,11 @@ class HGCalUncalibRecHitRecWeightsAlgo {
}

private:
double adcLSB_, tdcLSB_, toaLSBToNS_, tdcOnsetfC_;
static constexpr float c_cm_ns = CLHEP::c_light * CLHEP::ns / CLHEP::cm;
double adcLSB_, tdcLSB_, toaLSBToNS_, tdcOnsetfC_, tofDelay_;
bool isSiFESim_;
std::vector<double> fCPerMIP_;
const HGCalDDDConstants* ddd_;
const HGCalGeometry* geom_;
};
#endif
Expand Up @@ -4,6 +4,7 @@
#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
#include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"

namespace edm {
class Event;
Expand All @@ -18,22 +19,24 @@ class HGCalUncalibRecHitWorkerBaseClass {
HGCalUncalibRecHitWorkerBaseClass(const edm::ParameterSet& ps, edm::ConsumesCollector iC) {}
virtual ~HGCalUncalibRecHitWorkerBaseClass() {}

// do event setup things
virtual void set(const edm::EventSetup& es) = 0;

// run HGC-EE things
virtual bool runHGCEE(const HGCalDigiCollection::const_iterator& digi, HGCeeUncalibratedRecHitCollection& result) = 0;
virtual bool runHGCEE(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGCeeUncalibratedRecHitCollection& result) = 0;

// run HGC-FH things
virtual bool runHGCHEsil(const HGCalDigiCollection::const_iterator& digi,
virtual bool runHGCHEsil(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGChefUncalibratedRecHitCollection& result) = 0;

// run HGC-BH things
virtual bool runHGCHEscint(const HGCalDigiCollection::const_iterator& digi,
virtual bool runHGCHEscint(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGChebUncalibratedRecHitCollection& result) = 0;

// run HFNose things
virtual bool runHGCHFNose(const HGCalDigiCollection::const_iterator& digi,
virtual bool runHGCHFNose(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGChfnoseUncalibratedRecHitCollection& result) = 0;
};

Expand Down
Expand Up @@ -221,7 +221,7 @@ void HGCalLayerClusterProducer::produce(edm::Event& evt, const edm::EventSetup&
//check on timeError to exclude scintillator
if (rhTimeE < 0.)
continue;
timeClhits.push_back(rechit->time() - timeOffset);
timeClhits.push_back(rechit->time());
timeErrorClhits.push_back(1. / (rhTimeE * rhTimeE));
}
hgcalsimclustertime::ComputeClusterTime timeEstimator;
Expand Down
Expand Up @@ -219,7 +219,7 @@ bool HGCalRecHitWorkerSimple::run(const edm::Event& evt,
float SoN = new_E / sigmaNoiseGeV;
myrechit.setSignalOverSigmaNoise(SoN);

if (detid.det() == DetId::HGCalHSc || myrechit.time() < 0.) {
if (detid.det() == DetId::HGCalHSc || myrechit.time() == -99.) {
myrechit.setTimeError(-1.);
} else {
float timeError = timeEstimatorSi_.getTimeError("recHit", SoN);
Expand Down
Expand Up @@ -14,6 +14,10 @@ HGCalUncalibRecHitProducer::HGCalUncalibRecHitProducer(const edm::ParameterSet&
hefDigiCollection_(consumes<HGCalDigiCollection>(ps.getParameter<edm::InputTag>("HGCHEFdigiCollection"))),
hebDigiCollection_(consumes<HGCalDigiCollection>(ps.getParameter<edm::InputTag>("HGCHEBdigiCollection"))),
hfnoseDigiCollection_(consumes<HGCalDigiCollection>(ps.getParameter<edm::InputTag>("HGCHFNosedigiCollection"))),
ee_geometry_token_(esConsumes(edm::ESInputTag("", "HGCalEESensitive"))),
hef_geometry_token_(esConsumes(edm::ESInputTag("", "HGCalHESiliconSensitive"))),
heb_geometry_token_(esConsumes(edm::ESInputTag("", "HGCalHEScintillatorSensitive"))),
hfnose_geometry_token_(esConsumes(edm::ESInputTag("", "HGCalHFNoseSensitive"))),
eeHitCollection_(ps.getParameter<std::string>("HGCEEhitCollection")),
hefHitCollection_(ps.getParameter<std::string>("HGCHEFhitCollection")),
hebHitCollection_(ps.getParameter<std::string>("HGCHEBhitCollection")),
Expand All @@ -31,53 +35,31 @@ HGCalUncalibRecHitProducer::~HGCalUncalibRecHitProducer() {}
void HGCalUncalibRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
using namespace edm;

// tranparently get things from event setup
worker_->set(es);

// prepare output
auto eeUncalibRechits = std::make_unique<HGCeeUncalibratedRecHitCollection>();
auto hefUncalibRechits = std::make_unique<HGChefUncalibratedRecHitCollection>();
auto hebUncalibRechits = std::make_unique<HGChebUncalibratedRecHitCollection>();
auto hfnoseUncalibRechits = std::make_unique<HGChfnoseUncalibratedRecHitCollection>();

// loop over HGCEE digis
edm::Handle<HGCalDigiCollection> pHGCEEDigis;
evt.getByToken(eeDigiCollection_, pHGCEEDigis);
const HGCalDigiCollection* eeDigis = pHGCEEDigis.product();
eeUncalibRechits->reserve(eeDigis->size());
for (auto itdg = eeDigis->begin(); itdg != eeDigis->end(); ++itdg) {
worker_->runHGCEE(itdg, *eeUncalibRechits);
}
const auto& pHGCEEDigis = evt.getHandle(eeDigiCollection_);
if (pHGCEEDigis.isValid())
worker_->runHGCEE(es.getHandle(ee_geometry_token_), *pHGCEEDigis, *eeUncalibRechits);

// loop over HGCHEsil digis
edm::Handle<HGCalDigiCollection> pHGCHEFDigis;
evt.getByToken(hefDigiCollection_, pHGCHEFDigis);
const HGCalDigiCollection* hefDigis = pHGCHEFDigis.product();
hefUncalibRechits->reserve(hefDigis->size());
for (auto itdg = hefDigis->begin(); itdg != hefDigis->end(); ++itdg) {
worker_->runHGCHEsil(itdg, *hefUncalibRechits);
}
const auto& pHGCHEFDigis = evt.getHandle(hefDigiCollection_);
if (pHGCHEFDigis.isValid())
worker_->runHGCHEsil(es.getHandle(hef_geometry_token_), *pHGCHEFDigis, *hefUncalibRechits);

// loop over HGCHEscint digis
edm::Handle<HGCalDigiCollection> pHGCHEBDigis;
evt.getByToken(hebDigiCollection_, pHGCHEBDigis);
const HGCalDigiCollection* hebDigis = pHGCHEBDigis.product();
hebUncalibRechits->reserve(hebDigis->size());
for (auto itdg = hebDigis->begin(); itdg != hebDigis->end(); ++itdg) {
worker_->runHGCHEscint(itdg, *hebUncalibRechits);
}
const auto& pHGCHEBDigis = evt.getHandle(hebDigiCollection_);
if (pHGCHEBDigis.isValid())
worker_->runHGCHEscint(es.getHandle(heb_geometry_token_), *pHGCHEBDigis, *hebUncalibRechits);

// loop over HFNose digis
edm::Handle<HGCalDigiCollection> pHGCHFNoseDigis;
evt.getByToken(hfnoseDigiCollection_, pHGCHFNoseDigis);
if (pHGCHFNoseDigis.isValid()) {
const HGCalDigiCollection* hfnoseDigis = pHGCHFNoseDigis.product();
if (!(hfnoseDigis->empty())) {
hfnoseUncalibRechits->reserve(hfnoseDigis->size());
for (auto itdg = hfnoseDigis->begin(); itdg != hfnoseDigis->end(); ++itdg)
worker_->runHGCHFNose(itdg, *hfnoseUncalibRechits);
}
}
const auto& pHGCHFNoseDigis = evt.getHandle(hfnoseDigiCollection_);
if (pHGCHFNoseDigis.isValid())
worker_->runHGCHFNose(es.getHandle(hfnose_geometry_token_), *pHGCHFNoseDigis, *hfnoseUncalibRechits);

// put the collection of recunstructed hits in the event
evt.put(std::move(eeUncalibRechits), eeHitCollection_);
Expand Down
Expand Up @@ -17,10 +17,15 @@ class HGCalUncalibRecHitProducer : public edm::stream::EDProducer<> {
void produce(edm::Event& evt, const edm::EventSetup& es) override;

private:
const edm::EDGetTokenT<HGCalDigiCollection> eeDigiCollection_; // collection of HGCEE digis
const edm::EDGetTokenT<HGCalDigiCollection> hefDigiCollection_; // collection of HGCHEF digis
edm::EDGetTokenT<HGCalDigiCollection> hebDigiCollection_; // collection of HGCHEB digis
edm::EDGetTokenT<HGCalDigiCollection> hfnoseDigiCollection_; // collection of HGCHFNose digis
const edm::EDGetTokenT<HGCalDigiCollection> eeDigiCollection_; // collection of HGCEE digis
const edm::EDGetTokenT<HGCalDigiCollection> hefDigiCollection_; // collection of HGCHEF digis
const edm::EDGetTokenT<HGCalDigiCollection> hebDigiCollection_; // collection of HGCHEB digis
const edm::EDGetTokenT<HGCalDigiCollection> hfnoseDigiCollection_; // collection of HGCHFNose digis

const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> ee_geometry_token_;
const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> hef_geometry_token_;
const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> heb_geometry_token_;
const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> hfnose_geometry_token_;

const std::string eeHitCollection_; // instance name of HGCEE collection of hits
const std::string hefHitCollection_; // instance name of HGCHEF collection of hits
Expand Down
Expand Up @@ -55,13 +55,12 @@ void configureIt(const edm::ParameterSet& conf, HGCalUncalibRecHitRecWeightsAlgo
} else {
maker.set_fCPerMIP(std::vector<double>({1.0}));
}

maker.set_tofDelay(conf.getParameter<double>("tofDelay"));
}

HGCalUncalibRecHitWorkerWeights::HGCalUncalibRecHitWorkerWeights(const edm::ParameterSet& ps, edm::ConsumesCollector iC)
: HGCalUncalibRecHitWorkerBaseClass(ps, iC),
ee_geometry_token_(iC.esConsumes(edm::ESInputTag("", "HGCalEESensitive"))),
hef_geometry_token_(iC.esConsumes(edm::ESInputTag("", "HGCalHESiliconSensitive"))),
hfnose_geometry_token_(iC.esConsumes(edm::ESInputTag("", "HGCalHFNoseSensitive"))) {
: HGCalUncalibRecHitWorkerBaseClass(ps, iC) {
const edm::ParameterSet& ee_cfg = ps.getParameterSet("HGCEEConfig");
const edm::ParameterSet& hef_cfg = ps.getParameterSet("HGCHEFConfig");
const edm::ParameterSet& heb_cfg = ps.getParameterSet("HGCHEBConfig");
Expand All @@ -72,41 +71,39 @@ HGCalUncalibRecHitWorkerWeights::HGCalUncalibRecHitWorkerWeights(const edm::Para
configureIt(hfnose_cfg, uncalibMaker_hfnose_);
}

void HGCalUncalibRecHitWorkerWeights::set(const edm::EventSetup& es) {
if (uncalibMaker_ee_.isSiFESim()) {
uncalibMaker_ee_.setGeometry(&es.getData(ee_geometry_token_));
}
if (uncalibMaker_hef_.isSiFESim()) {
uncalibMaker_hef_.setGeometry(&es.getData(hef_geometry_token_));
}
uncalibMaker_heb_.setGeometry(nullptr);
if (uncalibMaker_hfnose_.isSiFESim()) {
uncalibMaker_hfnose_.setGeometry(&es.getData(hfnose_geometry_token_));
}
bool HGCalUncalibRecHitWorkerWeights::run(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGCalUncalibRecHitRecWeightsAlgo<HGCalDataFrame>& uncalibMaker,
edm::SortedCollection<HGCUncalibratedRecHit>& result) {
uncalibMaker.setGeometry(geom);
result.reserve(digis.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected

-  result.reserve(digis.size());
+  result.reserve(result.size() + digis.size());

or is the idea to clear the vector before filling it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result collection is created on each event ( link ), and is then introduced (empty) in HGCalUncalibRecHitWorkerWeights::run .

So the result.reserve is used to reserve the same size as the digis collection, to speed up the push_back (by avoiding buffer resizing).

But you are right that using result.reserve(result.size() + digis.size()) is safer if in the future the same result collection is used across the runHGCEE , runHGCHEsil , runHGCHEscint , runHGCHFNose , so I changed it in the commit.

for (const auto& digi : digis)
result.push_back(uncalibMaker.makeRecHit(digi));
return true;
}

bool HGCalUncalibRecHitWorkerWeights::runHGCEE(const HGCalDigiCollection::const_iterator& itdg,
bool HGCalUncalibRecHitWorkerWeights::runHGCEE(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGCeeUncalibratedRecHitCollection& result) {
result.push_back(uncalibMaker_ee_.makeRecHit(*itdg));
return true;
return run(geom, digis, uncalibMaker_ee_, result);
}

bool HGCalUncalibRecHitWorkerWeights::runHGCHEsil(const HGCalDigiCollection::const_iterator& itdg,
bool HGCalUncalibRecHitWorkerWeights::runHGCHEsil(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGChefUncalibratedRecHitCollection& result) {
result.push_back(uncalibMaker_hef_.makeRecHit(*itdg));
return true;
return run(geom, digis, uncalibMaker_hef_, result);
}

bool HGCalUncalibRecHitWorkerWeights::runHGCHEscint(const HGCalDigiCollection::const_iterator& itdg,
bool HGCalUncalibRecHitWorkerWeights::runHGCHEscint(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGChebUncalibratedRecHitCollection& result) {
result.push_back(uncalibMaker_heb_.makeRecHit(*itdg));
return true;
return run(geom, digis, uncalibMaker_heb_, result);
}

bool HGCalUncalibRecHitWorkerWeights::runHGCHFNose(const HGCalDigiCollection::const_iterator& itdg,
bool HGCalUncalibRecHitWorkerWeights::runHGCHFNose(const edm::ESHandle<HGCalGeometry>& geom,
const HGCalDigiCollection& digis,
HGChfnoseUncalibratedRecHitCollection& result) {
result.push_back(uncalibMaker_hfnose_.makeRecHit(*itdg));
return true;
return run(geom, digis, uncalibMaker_hfnose_, result);
}

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down