LDMX Software
hcal::HcalSimpleDigiAndRecProducer Class Reference

Public Member Functions

 HcalSimpleDigiAndRecProducer (const std::string &name, framework::Process &process)
 
void onNewRun (const ldmx::RunHeader &runHeader) override
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
void configure (framework::config::Parameters &ps) override
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
void produce (framework::Event &event) override
 Process the event and put new data products into it.
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void beforeNewRun (ldmx::RunHeader &header)
 Handle allowing producers to modify run headers before the run begins.
 
- Public Member Functions inherited from framework::EventProcessor
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()
 Class destructor.
 
virtual void onFileOpen (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
virtual void onProcessStart ()
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Attributes

std::string input_coll_name_ {}
 
std::string input_pass_name_ {}
 
std::string output_coll_name_ {}
 
double mev_per_mip_ {}
 
double pe_per_mip_ {}
 
double attenuation_length_ {}
 
double mean_noise_ {}
 
std::mt19937 rng_ {}
 
std::unique_ptr< std::normal_distribution< double > > position_resolution_smear_
 
std::unique_ptr< ldmx::NoiseGeneratornoiseGenerator_ {nullptr}
 
int readout_threshold_ {2}
 

Additional Inherited Members

- Static Public Member Functions inherited from framework::EventProcessor
static void declare (const std::string &classname, int classtype, EventProcessorMaker *)
 Internal function which is part of the PluginFactory machinery.
 
- Static Public Attributes inherited from framework::Producer
static const int CLASSTYPE {1}
 Constant used to track EventProcessor types by the PluginFactory.
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramHelper histograms_
 Interface class for making and filling histograms.
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger theLog_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 14 of file HcalSimpleDigiAndRecProducer.h.

Constructor & Destructor Documentation

◆ HcalSimpleDigiAndRecProducer()

hcal::HcalSimpleDigiAndRecProducer::HcalSimpleDigiAndRecProducer ( const std::string & name,
framework::Process & process )
inline

Definition at line 16 of file HcalSimpleDigiAndRecProducer.h.

18 : framework::Producer{name, process} {}
Base class for a module which produces a data product.

Member Function Documentation

◆ configure()

void hcal::HcalSimpleDigiAndRecProducer::configure ( framework::config::Parameters & parameters)
overridevirtual

Callback for the EventProcessor to configure itself from the given set of parameters.

The parameters a processor has access to are the member variables of the python class in the sequence that has className equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 8 of file HcalSimpleDigiAndRecProducer.cxx.

9 {
10 input_coll_name_ = ps.getParameter<std::string>("input_coll_name");
11 input_pass_name_ = ps.getParameter<std::string>("input_pass_name");
12 output_coll_name_ = ps.getParameter<std::string>("output_coll_name");
13 mev_per_mip_ = ps.getParameter<double>("mev_per_mip");
14 pe_per_mip_ = ps.getParameter<double>("pe_per_mip");
15 attenuation_length_ = ps.getParameter<double>("attenuation_length");
16 readout_threshold_ = ps.getParameter<int>("readout_threshold");
17 mean_noise_ = ps.getParameter<double>("mean_noise");
18 position_resolution_smear_ =
19 std::make_unique<std::normal_distribution<double>>(
20 0.0, ps.getParameter<double>("position_resolution"));
21}

◆ onNewRun()

void hcal::HcalSimpleDigiAndRecProducer::onNewRun ( const ldmx::RunHeader & runHeader)
overridevirtual

Callback for the EventProcessor to take any necessary action when the run being processed changes.

Parameters
runHeaderThe RunHeader containing run information.

Reimplemented from framework::EventProcessor.

Definition at line 23 of file HcalSimpleDigiAndRecProducer.cxx.

23 {
24 noiseGenerator_ = std::make_unique<ldmx::NoiseGenerator>(mean_noise_, false);
25 // hard-code this number, create noise hits for non-zero PEs!
26 noiseGenerator_->setNoiseThreshold(1);
30 noiseGenerator_->seedGenerator(
31 rseed.getSeed("HcalSimpleDigiAndRecProducer::NoiseGenerator"));
32 rng_.seed(rseed.getSeed("HcalSimpleDigiAndRecProducer"));
33}
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
System for consistent seeding of random number generators.
static const std::string CONDITIONS_OBJECT_NAME
Conditions object name.
uint64_t getSeed(const std::string &name) const
Access a given seed by name.

References framework::RandomNumberSeedService::CONDITIONS_OBJECT_NAME, framework::EventProcessor::getCondition(), and framework::RandomNumberSeedService::getSeed().

◆ produce()

void hcal::HcalSimpleDigiAndRecProducer::produce ( framework::Event & event)
overridevirtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Implements framework::Producer.

Definition at line 35 of file HcalSimpleDigiAndRecProducer.cxx.

35 {
36 const auto& hcalGeometry = getCondition<ldmx::HcalGeometry>(
38
39 std::vector<ldmx::HcalHit> hcalRecHits;
40
41 auto simHits{event.getCollection<ldmx::SimCalorimeterHit>(input_coll_name_,
42 input_pass_name_)};
43 std::unordered_map<unsigned int, std::vector<const ldmx::SimCalorimeterHit*>>
44 hits_by_id{};
45 // Important, has to be a reference so that we don't take the address of a
46 // variable that goes out of scope!
47 for (const auto& hit : simHits) {
48 auto id{hit.getID()};
49 auto found{hits_by_id.find(id)};
50 if (found == hits_by_id.end()) {
51 hits_by_id[id] = std::vector<const ldmx::SimCalorimeterHit*>{&hit};
52 } else {
53 hits_by_id[id].push_back(&hit);
54 }
55 }
56 for (const auto& [barID, simhits_in_bar] : hits_by_id) {
57 ldmx::HcalHit& recHit = hcalRecHits.emplace_back();
58 double edep{};
59 double time{};
60 std::vector<double> pos{0, 0, 0};
61 for (auto hit : simhits_in_bar) {
62 edep += hit->getEdep();
63 double edep_hit = hit->getEdep();
64 time += hit->getTime() * edep_hit;
65 auto hitPos{hit->getPosition()};
66 pos[0] += hitPos[0] * edep_hit;
67 pos[1] += hitPos[1] * edep_hit;
68 pos[2] += hitPos[2] * edep_hit;
69 }
70 ldmx::HcalID hitID{barID};
71
72 // Position smearing
73 double mean_pe{(edep / mev_per_mip_) * pe_per_mip_};
74 double xpos{pos[0] / edep};
75 double ypos{pos[1] / edep};
76 double zpos{pos[2] / edep};
77 time /= edep;
78
79 auto orientation{hcalGeometry.getScintillatorOrientation(barID)};
80 double half_total_width{
81 hcalGeometry.getHalfTotalWidth(hitID.section(), hitID.layer())};
82 double scint_bar_length{hcalGeometry.getScintillatorLength(hitID)};
83
84 auto stripCenter{hcalGeometry.getStripCenterPosition(hitID)};
85 if (hitID.section() == ldmx::HcalID::HcalSection::BACK) {
86 double distance_along_bar =
87 (orientation ==
88 ldmx::HcalGeometry::ScintillatorOrientation::horizontal)
89 ? xpos
90 : ypos;
91 if (orientation ==
92 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
93 ypos = stripCenter.y();
94 xpos += (*position_resolution_smear_)(rng_);
95 } else {
96 xpos = stripCenter.x();
97 ypos += (*position_resolution_smear_)(rng_);
98 }
99 zpos = stripCenter.z();
100 // Attenuation
101 mean_pe *= exp(1. / attenuation_length_);
102 double mean_pe_close =
103 mean_pe * exp(-1. *
104 ((half_total_width - distance_along_bar) /
105 (scint_bar_length * 0.5)) /
106 attenuation_length_);
107 double mean_pe_far =
108 mean_pe * exp(-1. *
109 ((half_total_width + distance_along_bar) /
110 (scint_bar_length * 0.5)) /
111 attenuation_length_);
112 int PE_close{
113 std::poisson_distribution<int>(mean_pe_close + mean_noise_)(rng_)};
114 int PE_far{
115 std::poisson_distribution<int>(mean_pe_far + mean_noise_)(rng_)};
116 recHit.setPE(PE_close + PE_far);
117 recHit.setMinPE(std::min(PE_close, PE_far));
118 } else {
119 // Side HCAL, no attenuation business since single ended readout
120 int PE{std::poisson_distribution<int>(mean_pe + mean_noise_)(rng_)};
121 recHit.setPE(PE);
122 recHit.setMinPE(PE);
123
124 // Checks orientation of side Hcal bars, sets center positions and add
125 // smearing along bar orientation axis
126 if (orientation ==
127 ldmx::HcalGeometry::ScintillatorOrientation::horizontal) {
128 xpos += (*position_resolution_smear_)(rng_);
129 ypos = stripCenter.y();
130 zpos = stripCenter.z();
131 } else if (orientation ==
132 ldmx::HcalGeometry::ScintillatorOrientation::vertical) {
133 xpos = stripCenter.x();
134 ypos += (*position_resolution_smear_)(rng_);
135 zpos = stripCenter.z();
136 } else if (orientation ==
137 ldmx::HcalGeometry::ScintillatorOrientation::depth) {
138 xpos = stripCenter.x();
139 ypos = stripCenter.y();
140 zpos += (*position_resolution_smear_)(rng_);
141 } else {
142 xpos = stripCenter.x();
143 ypos = stripCenter.y();
144 zpos = stripCenter.z();
145 ldmx_log(warn) << "Bar orientation not found. Hit" << hitID.raw()
146 << "positioned at bar center.";
147 }
148 }
149
150 recHit.setID(hitID.raw());
151 recHit.setXPos(xpos);
152 recHit.setNoise(false);
153 recHit.setYPos(ypos);
154 recHit.setZPos(zpos);
155 recHit.setTime(time);
156 recHit.setSection(hitID.section());
157 recHit.setStrip(hitID.strip());
158 recHit.setLayer(hitID.layer());
159 recHit.setEnergy(edep);
160 recHit.setOrientation(static_cast<int>(orientation));
161 }
162 event.add(output_coll_name_, hcalRecHits);
163}
void setYPos(float ypos)
Set the Y position of the hit [mm].
void setID(int id)
Set the detector ID.
void setZPos(float zpos)
Set the Z position of the hit [mm].
void setXPos(float xpos)
Set the X position of the hit [mm].
void setTime(float time)
Set the time of the hit [ns].
void setEnergy(float energy)
Set the calorimetric energy of the hit, corrected for sampling factors [MeV].
void setNoise(bool yes)
Set if this hit is a noise hit.
static constexpr const char * CONDITIONS_OBJECT_NAME
Conditions object: The name of the python configuration calling this class (Hcal/python/HcalGeometry....
Stores reconstructed hit information from the HCAL.
Definition HcalHit.h:24
void setSection(int section)
Set the section for this hit.
Definition HcalHit.h:166
void setMinPE(float minpe)
Set the minimum number of photoelectrons estimated for this hit.
Definition HcalHit.h:160
void setOrientation(int orientation)
Set if the bar is orientied in X / Y / Z meanig 0 / 1 / 2, respectively.
Definition HcalHit.h:234
void setStrip(int strip)
Set the strip for this hit.
Definition HcalHit.h:178
void setLayer(int layer)
Set the layer for this hit.
Definition HcalHit.h:172
void setPE(float pe)
Set the number of photoelectrons estimated for this hit.
Definition HcalHit.h:153
Implements detector ids for HCal subdetector.
Definition HcalID.h:19
Stores simulated calorimeter hit information.

References ldmx::HcalGeometry::CONDITIONS_OBJECT_NAME, framework::EventProcessor::getCondition(), ldmx::CalorimeterHit::setEnergy(), ldmx::CalorimeterHit::setID(), ldmx::HcalHit::setLayer(), ldmx::HcalHit::setMinPE(), ldmx::CalorimeterHit::setNoise(), ldmx::HcalHit::setOrientation(), ldmx::HcalHit::setPE(), ldmx::HcalHit::setSection(), ldmx::HcalHit::setStrip(), ldmx::CalorimeterHit::setTime(), ldmx::CalorimeterHit::setXPos(), ldmx::CalorimeterHit::setYPos(), and ldmx::CalorimeterHit::setZPos().

Member Data Documentation

◆ attenuation_length_

double hcal::HcalSimpleDigiAndRecProducer::attenuation_length_ {}
private

Definition at line 30 of file HcalSimpleDigiAndRecProducer.h.

30{};

◆ input_coll_name_

std::string hcal::HcalSimpleDigiAndRecProducer::input_coll_name_ {}
private

Definition at line 25 of file HcalSimpleDigiAndRecProducer.h.

25{};

◆ input_pass_name_

std::string hcal::HcalSimpleDigiAndRecProducer::input_pass_name_ {}
private

Definition at line 26 of file HcalSimpleDigiAndRecProducer.h.

26{};

◆ mean_noise_

double hcal::HcalSimpleDigiAndRecProducer::mean_noise_ {}
private

Definition at line 31 of file HcalSimpleDigiAndRecProducer.h.

31{};

◆ mev_per_mip_

double hcal::HcalSimpleDigiAndRecProducer::mev_per_mip_ {}
private

Definition at line 28 of file HcalSimpleDigiAndRecProducer.h.

28{};

◆ noiseGenerator_

std::unique_ptr<ldmx::NoiseGenerator> hcal::HcalSimpleDigiAndRecProducer::noiseGenerator_ {nullptr}
private

Definition at line 35 of file HcalSimpleDigiAndRecProducer.h.

35{nullptr};

◆ output_coll_name_

std::string hcal::HcalSimpleDigiAndRecProducer::output_coll_name_ {}
private

Definition at line 27 of file HcalSimpleDigiAndRecProducer.h.

27{};

◆ pe_per_mip_

double hcal::HcalSimpleDigiAndRecProducer::pe_per_mip_ {}
private

Definition at line 29 of file HcalSimpleDigiAndRecProducer.h.

29{};

◆ position_resolution_smear_

std::unique_ptr<std::normal_distribution<double> > hcal::HcalSimpleDigiAndRecProducer::position_resolution_smear_
private
Initial value:
{
nullptr}

Definition at line 33 of file HcalSimpleDigiAndRecProducer.h.

33 {
34 nullptr};

◆ readout_threshold_

int hcal::HcalSimpleDigiAndRecProducer::readout_threshold_ {2}
private

Definition at line 36 of file HcalSimpleDigiAndRecProducer.h.

36{2};

◆ rng_

std::mt19937 hcal::HcalSimpleDigiAndRecProducer::rng_ {}
private

Definition at line 32 of file HcalSimpleDigiAndRecProducer.h.

32{};

The documentation for this class was generated from the following files: