107 std::map<std::string, std::vector<ldmx::SimCalorimeterHit>>
109 std::map<std::string, std::vector<ldmx::SimTrackerHit>>
110 tracker_collection_map;
111 std::map<std::string, std::map<int, ldmx::SimParticle>>
112 particle_collection_map;
113 std::map<std::string, std::map<int, ldmx::SimCalorimeterHit>> hit_map;
135 if (!needs_contribs_added) {
141 [
this](
int id,
unsigned enc,
unsigned idx) {
148 ldmx_log(debug) <<
"in loop: start of collection " << coll_name
149 <<
"in loop: printing current sim event: ";
150 ldmx_log(debug) <<
"in loop: size of sim hits_ vector " << coll_name
151 <<
" is " << simhits_calo.size();
155 if (needs_contribs_added) {
156 ldmx_log(trace) <<
"Collection " << coll_name <<
" needs contribs added";
158 ldmx_log(trace) << simhit;
163 [
this](
int id,
unsigned enc,
unsigned idx) {
177 auto simhits_tracker =
182 int encoded_track_id =
184 simhit.setTrackID(encoded_track_id);
188 ldmx_log(debug) <<
"in loop: size of sim hits_ vector " << coll_name
189 <<
" is " << simhits_tracker.size();
191 ldmx_log(debug) <<
"in loop: start of collection " << coll_name
192 <<
"in loop: printing current sim event: ";
195 ldmx_log(trace) << simhit;
208 ldmx_log(debug) <<
"in loop: size of sim particles map " << coll_name
209 <<
" is " << sim_particles.size();
211 ldmx_log(debug) <<
"in loop: start of collection " << coll_name
212 <<
"in loop: printing current sim event: ";
216 for (
auto &[track_id, particle] : sim_particles) {
217 int encoded_track_id =
219 output_map[encoded_track_id] = particle;
220 output_map[encoded_track_id].encodeTracks(
221 [
this](
int id,
unsigned enc,
unsigned idx) {
225 ldmx_log(trace) << particle;
242 unsigned overlay_event_index = 1;
247 for (
int bunch_offset{start_bunch}; bunch_offset <= end_bunch;
256 if (bunch_offset == 0) {
266 event.getEventHeader().setIntParameter(
"in_time_pu", n_events_overlay);
270 n_events_overlay -= 1;
275 ldmx_log(debug) <<
"Will overlay " << n_events_overlay
276 <<
" events on the simulated one";
278 for (
int i_ev = 0; i_ev < n_events_overlay; i_ev++) {
286 ldmx_log(error) <<
"Couldn't read next overlay event!";
292 time_offset += bunchtime_offset;
294 ldmx_log(trace) <<
"in overlay loop: overlaying event " <<
"which is "
295 << i_ev + 1 <<
" out of " << n_events_overlay
296 <<
"\n\thit time offset is " << time_offset <<
" ns"
297 <<
"\n\tbunch position offset is " << bunch_offset
298 <<
", leading to a total time offset of "
299 << bunchtime_offset <<
" ns";
307 bool needs_contribs_added{
313 std::vector<ldmx::SimCalorimeterHit> overlay_hits =
317 ldmx_log(debug) <<
"in loop: size of overlay hits_ vector is "
318 << overlay_hits.size();
320 std::string out_coll_name =
323 ldmx_log(trace) <<
"in loop: printing overlay event: ";
326 ldmx_log(trace) << overlay_hit;
329 overlay_hit.setTime(overlay_hit.getTime() + time_offset);
330 overlay_hit.setPreStepTime(overlay_hit.getPreStepTime() +
332 overlay_hit.setPostStepTime(overlay_hit.getPostStepTime() +
334 overlay_hit.encodeTracks(
335 [
this](
int id,
unsigned enc,
unsigned idx) {
340 if (needs_contribs_added) {
342 auto &this_coll_hit_map{
344 int overlay_hit_id = overlay_hit.getID();
345 if (this_coll_hit_map.find(overlay_hit_id) ==
349 <<
"No existing simhit found for ID " << overlay_hit_id
350 <<
"; copying overlay hit to output collection";
351 auto &output_hit = this_coll_hit_map[overlay_hit_id];
352 output_hit = overlay_hit;
355 auto id = output_hit.getID();
356 auto pos = output_hit.getPosition();
357 auto time = output_hit.getTime();
360 output_hit.setID(
id);
361 output_hit.setPosition(pos[0], pos[1], pos[2]);
362 output_hit.setTime(time);
367 int n_contribs = overlay_hit.getNumberOfContribs();
369 <<
"Copying and reindexing " << n_contribs
370 <<
" contributors to the sim hit for ID " << overlay_hit_id;
371 for (
int i = 0; i < n_contribs; i++) {
373 overlay_hit.getContrib(i)};
376 this_coll_hit_map[overlay_hit_id].addContrib(
377 contrib.incident_id_, contrib.track_id_, contrib.pdg_code_,
378 contrib.edep_, contrib.time_ + time_offset);
382 << this_coll_hit_map[overlay_hit_id].getNumberOfContribs()
383 <<
" total contributors in the output collection";
387 calo_collection_map[out_coll_name].push_back(overlay_hit);
389 ldmx_log(trace) <<
"Adding non-Ecal overlay hit to outhit vector "
394 if (!needs_contribs_added)
395 ldmx_log(debug) <<
"Nhits in overlay collection " << out_coll_name
396 <<
": " << calo_collection_map[out_coll_name].size();
404 auto overlay_tracker_hits{
408 ldmx_log(debug) <<
"in loop: size of overlay hits_ vector is "
409 << overlay_tracker_hits.size();
413 ldmx_log(trace) <<
"in loop: printing overlay event: ";
415 for (
auto &overlay_hit : overlay_tracker_hits) {
416 auto overlay_time{overlay_hit.getTime() + time_offset};
417 overlay_hit.setTime(overlay_time);
418 auto overlay_track_id{
encodeTrack(overlay_hit.getTrackID(),
420 overlay_event_index)};
421 overlay_hit.setTrackID(overlay_track_id);
423 ldmx_log(trace) << overlay_hit;
424 ldmx_log(trace) <<
"Adding tracker overlay hit to outhit vector "
425 << out_coll_name_tracker;
427 tracker_collection_map[out_coll_name_tracker].push_back(overlay_hit);
430 ldmx_log(debug) <<
"Nhits in overlay collection "
431 << out_coll_name_tracker <<
": "
432 << tracker_collection_map[out_coll_name_tracker].size();
441 ldmx_log(debug) <<
"in loop: size of overlay particles map is "
442 << overlay_particles.size();
445 auto &output_map = particle_collection_map[out_coll_name_particles];
447 ldmx_log(trace) <<
"in loop: printing overlay event: ";
449 for (
auto &[track_id, particle] : overlay_particles) {
453 output_map[new_track_id] = particle;
454 output_map[new_track_id].encodeTracks(
455 [
this](
int id,
unsigned enc,
unsigned idx) {
459 output_map[new_track_id].setTime(particle.getTime() + time_offset);
461 ldmx_log(trace) <<
"Track ID: " << new_track_id <<
" --- "
462 << output_map[new_track_id];
463 ldmx_log(trace) <<
"Adding sim particle to output map "
464 << out_coll_name_particles;
476 ldmx_log(trace) <<
"Hits in hit_map after overlay of "
481 ldmx_log(trace) << map_hit.second;
485 calo_collection_map.end()) {
486 ldmx_log(debug) <<
"Adding first hit from hit map as first outhit "
487 "vector to calo_collection_map";
492 .push_back(map_hit.second);
501 for (
auto &[name, coll] : calo_collection_map) {
502 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
504 ldmx_log(trace) <<
"List of hits_ added: ";
505 for (
auto &hit : coll) {
506 ldmx_log(trace) << hit;
508 event.add(name, coll);
512 for (
auto &[name, coll] : tracker_collection_map) {
513 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
514 ldmx_log(trace) <<
"List of hits_ added: ";
515 for (
auto &hit : coll) {
516 ldmx_log(trace) << hit;
518 event.add(name, coll);
522 for (
auto &[name, coll] : particle_collection_map) {
523 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
524 ldmx_log(trace) <<
"List of particles added: ";
525 for (
auto &[track_id, particle] : coll) {
526 ldmx_log(trace) <<
"Track ID: " << track_id <<
" --- " << particle;
528 event.add(name, coll);