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;
243 for (
int bunch_offset{start_bunch}; bunch_offset <= end_bunch;
252 if (bunch_offset == 0) {
262 event.getEventHeader().setIntParameter(
"in_time_pu", n_events_overlay);
266 n_events_overlay -= 1;
271 ldmx_log(debug) <<
"Will overlay " << n_events_overlay
272 <<
" events on the simulated one";
274 for (
int i_ev = 0; i_ev < n_events_overlay; i_ev++) {
282 ldmx_log(error) <<
"Couldn't read next overlay event!";
286 ldmx_log(error) <<
"Too many overlay events! Maximum events that can "
287 "be overlayed is 7.";
293 time_offset += bunchtime_offset;
295 ldmx_log(trace) <<
"in overlay loop: overlaying event " <<
"which is "
296 << i_ev + 1 <<
" out of " << n_events_overlay
297 <<
"\n\thit time offset is " << time_offset <<
" ns"
298 <<
"\n\tbunch position offset is " << bunch_offset
299 <<
", leading to a total time offset of "
300 << bunchtime_offset <<
" ns";
308 bool needs_contribs_added{
314 std::vector<ldmx::SimCalorimeterHit> overlay_hits =
318 ldmx_log(debug) <<
"in loop: size of overlay hits_ vector is "
319 << overlay_hits.size();
321 std::string out_coll_name =
324 ldmx_log(trace) <<
"in loop: printing overlay event: ";
327 ldmx_log(trace) << overlay_hit;
330 overlay_hit.setTime(overlay_hit.getTime() + time_offset);
331 overlay_hit.setPreStepTime(overlay_hit.getPreStepTime() +
333 overlay_hit.setPostStepTime(overlay_hit.getPostStepTime() +
335 overlay_hit.encodeTracks(
336 [
this](
int id,
unsigned enc,
unsigned idx) {
341 if (needs_contribs_added) {
343 auto &this_coll_hit_map{
345 int overlay_hit_id = overlay_hit.getID();
346 if (this_coll_hit_map.find(overlay_hit_id) ==
350 <<
"No existing simhit found for ID " << overlay_hit_id
351 <<
"; copying overlay hit to output collection";
352 auto &output_hit = this_coll_hit_map[overlay_hit_id];
353 output_hit = overlay_hit;
356 auto id = output_hit.getID();
357 auto pos = output_hit.getPosition();
358 auto time = output_hit.getTime();
361 output_hit.setID(
id);
362 output_hit.setPosition(pos[0], pos[1], pos[2]);
363 output_hit.setTime(time);
368 int n_contribs = overlay_hit.getNumberOfContribs();
370 <<
"Copying and reindexing " << n_contribs
371 <<
" contributors to the sim hit for ID " << overlay_hit_id;
372 for (
int i = 0; i < n_contribs; i++) {
374 overlay_hit.getContrib(i)};
377 this_coll_hit_map[overlay_hit_id].addContrib(
378 contrib.incident_id_, contrib.track_id_, contrib.pdg_code_,
379 contrib.edep_, contrib.time_ + time_offset,
380 contrib.origin_id_ + i_ev + 1);
384 << this_coll_hit_map[overlay_hit_id].getNumberOfContribs()
385 <<
" total contributors in the output collection";
389 calo_collection_map[out_coll_name].push_back(overlay_hit);
391 ldmx_log(trace) <<
"Adding non-Ecal overlay hit to outhit vector "
396 if (!needs_contribs_added)
397 ldmx_log(debug) <<
"Nhits in overlay collection " << out_coll_name
398 <<
": " << calo_collection_map[out_coll_name].size();
406 auto overlay_tracker_hits{
410 ldmx_log(debug) <<
"in loop: size of overlay hits_ vector is "
411 << overlay_tracker_hits.size();
415 ldmx_log(trace) <<
"in loop: printing overlay event: ";
417 for (
auto &overlay_hit : overlay_tracker_hits) {
418 auto overlay_time{overlay_hit.getTime() + time_offset};
419 overlay_hit.setTime(overlay_time);
420 auto overlay_track_id{
encodeTrack(overlay_hit.getTrackID(),
422 overlay_hit.setTrackID(overlay_track_id);
424 ldmx_log(trace) << overlay_hit;
425 ldmx_log(trace) <<
"Adding tracker overlay hit to outhit vector "
426 << out_coll_name_tracker;
428 tracker_collection_map[out_coll_name_tracker].push_back(overlay_hit);
431 ldmx_log(debug) <<
"Nhits in overlay collection "
432 << out_coll_name_tracker <<
": "
433 << tracker_collection_map[out_coll_name_tracker].size();
442 ldmx_log(debug) <<
"in loop: size of overlay particles map is "
443 << overlay_particles.size();
446 auto &output_map = particle_collection_map[out_coll_name_particles];
448 ldmx_log(trace) <<
"in loop: printing overlay event: ";
450 for (
auto &[track_id, particle] : overlay_particles) {
454 output_map[new_track_id] = particle;
455 output_map[new_track_id].encodeTracks(
456 [
this](
int id,
unsigned enc,
unsigned idx) {
460 output_map[new_track_id].setTime(particle.getTime() + time_offset);
462 ldmx_log(trace) <<
"Track ID: " << new_track_id <<
" --- "
463 << output_map[new_track_id];
464 ldmx_log(trace) <<
"Adding sim particle to output map "
465 << 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);