1#include "Recon/OverlayProducer.h"
12 ldmx_log(debug) <<
"Running configure() ";
18 "overlayCaloHitCollections");
20 "overlayTrackerHitCollections");
36 ldmx_log(info) <<
"Got parameters \n \t overlayFileName = "
40 <<
"\n\t overlayCaloHitCollections = ";
43 ldmx_log(info) <<
"\n\t overlayTrackerHitCollections = ";
45 ldmx_log(info) << coll <<
"; ";
47 ldmx_log(info) <<
"\n\t numberOverlaidInteractions = " <<
poissonMu_
48 <<
"\n\t nEarlierBunchesToSample = " <<
nEarlier_
49 <<
"\n\t nLaterBunchesToSample = " <<
nLater_
62 if (
rndm_.get() ==
nullptr) {
64 const auto &rnss = getCondition<framework::RandomNumberSeedService>(
66 rndm_ = std::make_unique<TRandom2>(rnss.getSeed(
"OverlayProducer::rndm"));
69 int start_event =
rndm_->Uniform(20., 1e4);
73 EXCEPTION_RAISE(
"BadRead",
"Couldn't read to starting offset.");
76 ldmx_log(info) <<
"Starting overlay process with pileup event number " << evNb
77 <<
" (random event number picked was " << start_event <<
").";
84 ldmx_log(info) <<
"produce() starts on simulation event "
85 <<
event.getEventHeader().getEventNumber();
90 const auto &rnss = getCondition<framework::RandomNumberSeedService>(
93 std::make_unique<TRandom2>(rnss.getSeed(
"OverlayProducer::rndmTime"));
100 std::map<std::string, std::vector<ldmx::SimCalorimeterHit>> caloCollectionMap;
101 std::map<std::string, std::vector<ldmx::SimTrackerHit>> trackerCollectionMap;
102 std::map<int, ldmx::SimCalorimeterHit> hitMap;
113 auto needsContribsAdded{collName.find(
"Ecal") != std::string::npos ? true
121 if (!needsContribsAdded) {
122 caloCollectionMap[collName +
"Overlay"] = simHitsCalo;
126 ldmx_log(debug) <<
"in loop: start of collection " << collName
127 <<
"in loop: printing current sim event: ";
129 ldmx_log(debug) <<
"in loop: size of sim hits vector " << collName <<
" is "
130 << simHitsCalo.size();
138 if (needsContribsAdded) {
140 hitMap[simHit.getID()] = simHit;
153 auto simHitsTracker =
155 trackerCollectionMap[collName +
"Overlay"] = simHitsTracker;
158 ldmx_log(debug) <<
"in loop: size of sim hits vector " << collName <<
" is "
159 << simHitsTracker.size();
162 ldmx_log(debug) <<
"in loop: start of collection " << collName
163 <<
"in loop: printing current sim event: ";
183 for (
int bunchOffset{startBunch}; bunchOffset <= endBunch; bunchOffset++) {
190 if (bunchOffset == 0) {
197 event.getEventHeader().setIntParameter(
"inTimePU", nEvsOverlay);
202 ldmx_log(debug) <<
"will overlay " << nEvsOverlay
203 <<
" events on the simulated one";
209 ldmx_log(error) <<
"No overlay event!";
215 for (
int iEv = 0; iEv < nEvsOverlay; iEv++) {
223 ldmx_log(error) <<
"At sim event "
224 <<
event.getEventHeader().getEventNumber()
225 <<
": couldn't read next overlay event!";
231 timeOffset += bunchTimeOffset;
234 ldmx_log(debug) <<
"in overlay loop: overlaying event "
236 <<
"which is " << iEv + 1 <<
" out of " << nEvsOverlay
237 <<
"\n\thit time offset is " << timeOffset <<
" ns"
238 <<
"\n\tbunch position offset is " << bunchOffset
239 <<
", leading to a total time offset of "
240 << bunchTimeOffset <<
" ns";
248 bool needsContribsAdded =
false;
250 needsContribsAdded =
true;
252 std::vector<ldmx::SimCalorimeterHit> overlayHits =
256 ldmx_log(debug) <<
"in loop: size of overlay hits vector is "
257 << overlayHits.size();
262 ldmx_log(debug) <<
"in loop: printing overlay event: ";
268 const float overlayTime = overlayHit.getTime() + timeOffset;
269 overlayHit.setTime(overlayTime);
271 if (needsContribsAdded) {
273 int overlayHitID = overlayHit.getID();
274 if (hitMap.find(overlayHitID) ==
277 hitMap[overlayHitID].setID(overlayHitID);
278 std::vector<float> hitPos = overlayHit.getPosition();
279 hitMap[overlayHitID].setPosition(hitPos[0], hitPos[1], hitPos[2]);
286 overlayHit.getEdep(), overlayTime);
289 caloCollectionMap[outCollName].push_back(overlayHit);
291 ldmx_log(debug) <<
"Adding non-Ecal overlay hit to outhit vector "
296 if (!needsContribsAdded)
297 ldmx_log(debug) <<
"Nhits in overlay collection " << outCollName
298 <<
": " << caloCollectionMap[outCollName].size();
306 auto overlayTrackerHits{
310 ldmx_log(debug) <<
"in loop: size of overlay hits vector is "
311 << overlayTrackerHits.size();
313 auto outCollName{coll +
"Overlay"};
316 ldmx_log(debug) <<
"in loop: printing overlay event: ";
319 for (
auto &overlayHit : overlayTrackerHits) {
320 auto overlayTime{overlayHit.getTime() + timeOffset};
321 overlayHit.setTime(overlayTime);
322 trackerCollectionMap[outCollName].push_back(overlayHit);
326 ldmx_log(debug) <<
"Adding tracker overlay hit to outhit vector "
331 ldmx_log(debug) <<
"Nhits in overlay collection " << outCollName <<
": "
332 << trackerCollectionMap[outCollName].size();
347 ldmx_log(debug) <<
"Hits in hitmap after overlay of "
350 for (
auto &mapHit : hitMap) {
354 caloCollectionMap.end()) {
355 ldmx_log(debug) <<
"Adding first hit from hit map as first outhit "
356 "vector to caloCollectionMap";
372 for (
auto &[name, coll] : caloCollectionMap) {
373 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
375 ldmx_log(debug) <<
"List of hits added: ";
376 for (
auto &hit : coll) hit.Print();
378 event.add(name, coll);
380 for (
auto &[name, coll] : trackerCollectionMap) {
381 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
383 ldmx_log(debug) <<
"List of hits added: ";
384 for (
auto &hit : coll) hit.Print();
386 event.add(name, coll);
393 ldmx_log(debug) <<
"onProcessStart() ";
404 ldmx_log(debug) <<
"onProcessStart () successful. Used input file: "
406 ldmx_log(debug) <<
"onProcessStart () successful. Got event info: ";
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Conditions object for random number seeds.
Class which stores simulated calorimeter hit information.
Class which encapsulates information from a hit in a simulated tracking detector.
Implements an event buffer system for storing event data.
const std::vector< ContentType > & getCollection(const std::string &collectionName, const std::string &passName="") const
Get a collection (std::vector) of objects from the event bus.
ldmx::EventHeader & getEventHeader()
Get the event header.
static const std::string CONDITIONS_OBJECT_NAME
Conditions object name.
Class encapsulating parameters for configuring a processor.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Stores simulated calorimeter hit information.
void Print() const
Print out the object.
Represents a simulated tracker hit in the simulation.
void Print() const
Print a description of this object.
std::string simPassName_
To use for finding the sim event bus passengers, mostly a disambiguation.
std::unique_ptr< framework::EventFile > overlayFile_
Pileup overlay events input file.
std::string overlayPassName_
Pileup overlay events input pass name.
std::string overlayFileName_
Pileup overlay events input file name.
std::vector< std::string > caloCollections_
List of SimCalorimeterHit collection(s) to loop over and add hits from, combining sim and pileup.
int verbosity_
Local control of processor verbosity.
int overlayIncidentID_
For Ecal, overlay hits should be added as contribs.
std::unique_ptr< TRandom2 > rndmTime_
Random number generator for pileup event time offset.
int nEarlier_
Number of bunches before the sim event to pull pileup events from.
void onNewRun(const ldmx::RunHeader &) override
At the start of the run, the pileup overlay file is set up, and the starting event number is chosen,...
double bunchSpacing_
Spacing in time (in [ns]) between electron bunches.
double timeMean_
Average position in time (in [ns]) of pileup bunches, relative to the sim event.
framework::config::Parameters params_
The parameters used to configure this producer.
double poissonMu_
(average) total number of events
framework::Event overlayEvent_
The overlay ldmx event bus.
int nLater_
Number of bunches after the sim event to pull pileup events from.
bool doPoissonIT_
Let the total number of in-time events be poisson distributed, or fix at the chosen value,...
std::unique_ptr< TRandom2 > rndm_
Random number generator for number of overlaid events.
void produce(framework::Event &event) override
Based on the list of collections to overlay, and the desired number of events, loop through all relev...
double timeSigma_
Width of pileup bunch spread in time (in [ns]), specified as a sigma of a Gaussian distribution.
void configure(framework::config::Parameters ¶meters) override
Configure the processor with input parameters from the python cofig.
bool doPoissonOOT_
Let the total number of out-of-time events be poisson distributed, or fix at the chosen value,...
void onProcessStart() override
At the start of processing, the pileup overlay file is set up.
std::vector< std::string > trackerCollections_
List of SimTrackerHit collection(s) to loop over and add hits from, combining sim and pileup.