117 std::map<std::string, std::vector<ldmx::SimCalorimeterHit>>
119 std::map<std::string, std::vector<ldmx::SimTrackerHit>>
120 tracker_collection_map;
121 std::map<std::string, std::map<int, ldmx::SimParticle>>
122 particle_collection_map;
123 std::map<std::string, std::map<int, ldmx::SimCalorimeterHit>> hit_map;
145 if (!needs_contribs_added) {
151 [
this](
int id,
unsigned enc,
unsigned idx) {
158 ldmx_log(debug) <<
"in loop: start of collection " << coll_name
159 <<
"in loop: printing current sim event: ";
160 ldmx_log(debug) <<
"in loop: size of sim hits_ vector " << coll_name
161 <<
" is " << simhits_calo.size();
165 if (needs_contribs_added) {
166 ldmx_log(trace) <<
"Collection " << coll_name <<
" needs contribs added";
168 ldmx_log(trace) << simhit;
173 [
this](
int id,
unsigned enc,
unsigned idx) {
187 auto simhits_tracker =
192 int encoded_track_id =
194 simhit.setTrackID(encoded_track_id);
198 ldmx_log(debug) <<
"in loop: size of sim hits_ vector " << coll_name
199 <<
" is " << simhits_tracker.size();
201 ldmx_log(debug) <<
"in loop: start of collection " << coll_name
202 <<
"in loop: printing current sim event: ";
205 ldmx_log(trace) << simhit;
218 ldmx_log(debug) <<
"in loop: size of sim particles map " << coll_name
219 <<
" is " << sim_particles.size();
221 ldmx_log(debug) <<
"in loop: start of collection " << coll_name
222 <<
"in loop: printing current sim event: ";
226 for (
auto& [track_id, particle] : sim_particles) {
227 int encoded_track_id =
229 output_map[encoded_track_id] = particle;
230 output_map[encoded_track_id].encodeTracks(
231 [
this](
int id,
unsigned enc,
unsigned idx) {
235 ldmx_log(trace) << particle;
253 for (
int bunch_offset{start_bunch}; bunch_offset <= end_bunch;
262 if (bunch_offset == 0) {
272 event.getEventHeader().setIntParameter(
"in_time_pu", n_events_overlay);
276 n_events_overlay -= 1;
281 ldmx_log(debug) <<
"Will overlay " << n_events_overlay
282 <<
" events on the simulated one";
284 for (
int i_ev = 0; i_ev < n_events_overlay; i_ev++) {
292 ldmx_log(error) <<
"Couldn't read next overlay event!";
296 ldmx_log(error) <<
"Too many overlay events! Maximum events that can "
297 "be overlayed is 7.";
303 time_offset += bunchtime_offset;
305 ldmx_log(trace) <<
"in overlay loop: overlaying event " <<
"which is "
306 << i_ev + 1 <<
" out of " << n_events_overlay
307 <<
"\n\thit time offset is " << time_offset <<
" ns"
308 <<
"\n\tbunch position offset is " << bunch_offset
309 <<
", leading to a total time offset of "
310 << bunchtime_offset <<
" ns";
318 bool needs_contribs_added{
324 std::vector<ldmx::SimCalorimeterHit> overlay_hits =
328 ldmx_log(debug) <<
"in loop: size of overlay hits_ vector is "
329 << overlay_hits.size();
331 std::string out_coll_name =
334 ldmx_log(trace) <<
"in loop: printing overlay event: ";
337 ldmx_log(trace) << overlay_hit;
340 overlay_hit.setTime(overlay_hit.getTime() + time_offset);
341 overlay_hit.setPreStepTime(overlay_hit.getPreStepTime() +
343 overlay_hit.setPostStepTime(overlay_hit.getPostStepTime() +
345 overlay_hit.encodeTracks(
346 [
this](
int id,
unsigned enc,
unsigned idx) {
351 if (needs_contribs_added) {
353 auto& this_coll_hit_map{
355 int overlay_hit_id = overlay_hit.getID();
356 if (this_coll_hit_map.find(overlay_hit_id) ==
360 <<
"No existing simhit found for ID " << overlay_hit_id
361 <<
"; copying overlay hit to output collection";
362 auto& output_hit = this_coll_hit_map[overlay_hit_id];
363 output_hit = overlay_hit;
366 auto id = output_hit.getID();
367 auto pos = output_hit.getPosition();
368 auto time = output_hit.getTime();
371 output_hit.setID(
id);
372 output_hit.setPosition(pos[0], pos[1], pos[2]);
373 output_hit.setTime(time);
378 int n_contribs = overlay_hit.getNumberOfContribs();
380 <<
"Copying and reindexing " << n_contribs
381 <<
" contributors to the sim hit for ID " << overlay_hit_id;
382 for (
int i = 0; i < n_contribs; i++) {
384 overlay_hit.getContrib(i)};
387 this_coll_hit_map[overlay_hit_id].addContrib(
388 contrib.incident_id_, contrib.track_id_, contrib.pdg_code_,
389 contrib.edep_, contrib.time_ + time_offset,
390 contrib.origin_id_ + i_ev + 1);
394 << this_coll_hit_map[overlay_hit_id].getNumberOfContribs()
395 <<
" total contributors in the output collection";
399 calo_collection_map[out_coll_name].push_back(overlay_hit);
401 ldmx_log(trace) <<
"Adding non-Ecal overlay hit to outhit vector "
406 if (!needs_contribs_added)
407 ldmx_log(debug) <<
"Nhits in overlay collection " << out_coll_name
408 <<
": " << calo_collection_map[out_coll_name].size();
416 auto overlay_tracker_hits{
420 ldmx_log(debug) <<
"in loop: size of overlay hits_ vector is "
421 << overlay_tracker_hits.size();
425 ldmx_log(trace) <<
"in loop: printing overlay event: ";
427 for (
auto& overlay_hit : overlay_tracker_hits) {
428 auto overlay_time{overlay_hit.getTime() + time_offset};
429 overlay_hit.setTime(overlay_time);
430 auto overlay_track_id{
encodeTrack(overlay_hit.getTrackID(),
432 overlay_hit.setTrackID(overlay_track_id);
434 ldmx_log(trace) << overlay_hit;
435 ldmx_log(trace) <<
"Adding tracker overlay hit to outhit vector "
436 << out_coll_name_tracker;
438 tracker_collection_map[out_coll_name_tracker].push_back(overlay_hit);
441 ldmx_log(debug) <<
"Nhits in overlay collection "
442 << out_coll_name_tracker <<
": "
443 << tracker_collection_map[out_coll_name_tracker].size();
452 ldmx_log(debug) <<
"in loop: size of overlay particles map is "
453 << overlay_particles.size();
456 auto& output_map = particle_collection_map[out_coll_name_particles];
458 ldmx_log(trace) <<
"in loop: printing overlay event: ";
460 for (
auto& [track_id, particle] : overlay_particles) {
464 output_map[new_track_id] = particle;
465 output_map[new_track_id].encodeTracks(
466 [
this](
int id,
unsigned enc,
unsigned idx) {
470 output_map[new_track_id].setTime(particle.getTime() + time_offset);
472 ldmx_log(trace) <<
"Track ID: " << new_track_id <<
" --- "
473 << output_map[new_track_id];
474 ldmx_log(trace) <<
"Adding sim particle to output map "
475 << out_coll_name_particles;
486 ldmx_log(trace) <<
"Hits in hit_map after overlay of "
491 ldmx_log(trace) << map_hit.second;
495 calo_collection_map.end()) {
496 ldmx_log(debug) <<
"Adding first hit from hit map as first outhit "
497 "vector to calo_collection_map";
502 .push_back(map_hit.second);
511 for (
auto& [name, coll] : calo_collection_map) {
512 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] : tracker_collection_map) {
523 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
524 ldmx_log(trace) <<
"List of hits_ added: ";
525 for (
auto& hit : coll) {
526 ldmx_log(trace) << hit;
528 event.add(name, coll);
532 for (
auto& [name, coll] : particle_collection_map) {
533 ldmx_log(debug) <<
"Writing " << name <<
" to event bus.";
534 ldmx_log(trace) <<
"List of particles added: ";
535 for (
auto& [track_id, particle] : coll) {
536 ldmx_log(trace) <<
"Track ID: " << track_id <<
" --- " << particle;
538 event.add(name, coll);