1#include "Recon/OverlayProducer.h"
12 ldmx_log(debug) <<
"Running configure() ";
18 "overlayCaloHitCollections");
20 "overlayTrackerHitCollections");
21 simPassName_ = parameters.getParameter<std::string>(
"passName");
24 poissonMu_ = parameters.getParameter<
double>(
"totalNumberOfInteractions");
25 doPoissonIT_ = parameters.getParameter<
bool>(
"doPoissonIntime");
26 doPoissonOOT_ = parameters.getParameter<
bool>(
"doPoissonOutoftime");
27 timeSigma_ = parameters.getParameter<
double>(
"timeSpread");
28 timeMean_ = parameters.getParameter<
double>(
"timeMean");
29 nEarlier_ = parameters.getParameter<
int>(
"nEarlierBunchesToSample");
30 nLater_ = parameters.getParameter<
int>(
"nLaterBunchesToSample");
31 bunchSpacing_ = parameters.getParameter<
double>(
"bunchSpacing");
32 verbosity_ = parameters.getParameter<
int>(
"verbosity");
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) {
66 rndm_ = std::make_unique<TRandom2>(rnss.getSeed(
"OverlayProducer::rndm"));
69 int start_event =
rndm_->Uniform(20., 4570);
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();
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
122 if (!needsContribsAdded) {
123 caloCollectionMap[collName +
"Overlay"] = simHitsCalo;
127 ldmx_log(debug) <<
"in loop: start of collection " << collName
128 <<
"in loop: printing current sim event: ";
130 ldmx_log(debug) <<
"in loop: size of sim hits vector " << collName <<
" is "
131 << simHitsCalo.size();
139 if (needsContribsAdded) {
141 hitMap[simHit.getID()] = simHit;
154 auto simHitsTracker =
156 trackerCollectionMap[collName +
"Overlay"] = simHitsTracker;
159 ldmx_log(debug) <<
"in loop: size of sim hits vector " << collName <<
" is "
160 << simHitsTracker.size();
163 ldmx_log(debug) <<
"in loop: start of collection " << collName
164 <<
"in loop: printing current sim event: ";
184 for (
int bunchOffset{startBunch}; bunchOffset <= endBunch; bunchOffset++) {
191 if (bunchOffset == 0) {
198 event.getEventHeader().setIntParameter(
"inTimePU", nEvsOverlay);
203 ldmx_log(debug) <<
"will overlay " << nEvsOverlay
204 <<
" events on the simulated one";
210 for (
int iEv = 0; iEv < nEvsOverlay; iEv++) {
218 ldmx_log(error) <<
"At sim event "
219 <<
event.getEventHeader().getEventNumber()
220 <<
": couldn't read next overlay event!";
226 timeOffset += bunchTimeOffset;
229 ldmx_log(debug) <<
"in overlay loop: overlaying event "
231 <<
"which is " << iEv + 1 <<
" out of " << nEvsOverlay
232 <<
"\n\thit time offset is " << timeOffset <<
" ns"
233 <<
"\n\tbunch position offset is " << bunchOffset
234 <<
", leading to a total time offset of "
235 << bunchTimeOffset <<
" ns";
243 bool needsContribsAdded =
false;
245 needsContribsAdded =
true;
247 std::vector<ldmx::SimCalorimeterHit> overlayHits =
251 ldmx_log(debug) <<
"in loop: size of overlay hits vector is "
252 << overlayHits.size();
257 ldmx_log(debug) <<
"in loop: printing overlay event: ";
263 const float overlayTime = overlayHit.getTime() + timeOffset;
264 overlayHit.setTime(overlayTime);
266 if (needsContribsAdded) {
268 int overlayHitID = overlayHit.getID();
269 if (hitMap.find(overlayHitID) ==
272 hitMap[overlayHitID].setID(overlayHitID);
273 std::vector<float> hitPos = overlayHit.getPosition();
274 hitMap[overlayHitID].setPosition(hitPos[0], hitPos[1], hitPos[2]);
281 overlayHit.getEdep(), overlayTime);
284 caloCollectionMap[outCollName].push_back(overlayHit);
286 ldmx_log(debug) <<
"Adding non-Ecal overlay hit to outhit vector "
291 if (!needsContribsAdded)
292 ldmx_log(debug) <<
"Nhits in overlay collection " << outCollName
293 <<
": " << caloCollectionMap[outCollName].size();
301 auto overlayTrackerHits{
305 ldmx_log(debug) <<
"in loop: size of overlay hits vector is "
306 << overlayTrackerHits.size();
308 auto outCollName{coll +
"Overlay"};
311 ldmx_log(debug) <<
"in loop: printing overlay event: ";
314 for (
auto &overlayHit : overlayTrackerHits) {
315 auto overlayTime{overlayHit.getTime() + timeOffset};
316 overlayHit.setTime(overlayTime);
317 trackerCollectionMap[outCollName].push_back(overlayHit);
321 ldmx_log(debug) <<
"Adding tracker overlay hit to outhit vector "
326 ldmx_log(debug) <<
"Nhits in overlay collection " << outCollName <<
": "
327 << trackerCollectionMap[outCollName].size();
342 ldmx_log(debug) <<
"Hits in hitmap after overlay of "
345 for (
auto &mapHit : hitMap) {
349 caloCollectionMap.end()) {
350 ldmx_log(debug) <<
"Adding first hit from hit map as first outhit "
351 "vector to caloCollectionMap";
367 for (
auto &[name, coll] : caloCollectionMap) {
368 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
370 ldmx_log(debug) <<
"List of hits added: ";
371 for (
auto &hit : coll) hit.Print();
373 event.add(name, coll);
375 for (
auto &[name, coll] : trackerCollectionMap) {
376 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
378 ldmx_log(debug) <<
"List of hits added: ";
379 for (
auto &hit : coll) hit.Print();
381 event.add(name, coll);
388 ldmx_log(debug) <<
"onProcessStart() ";
399 ldmx_log(debug) <<
"onProcessStart () successful. Used input file: "
401 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.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
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.
Stores simulated calorimeter hit information.
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.