LDMX Software
PropagationMapWriter.cxx
1#include "Trigger/PropagationMapWriter.h"
2
4// #include "Trigger/Event/TrigParticle.h"
5// #include "Trigger/Event/TrigEnergySum.h"
6
7namespace trigger {
8PropagationMapWriter::PropagationMapWriter(const std::string& name,
9 framework::Process& process)
10 : Producer(name, process) {}
11
12void PropagationMapWriter::configure(framework::config::Parameters& ps) {
13 out_path_ = ps.get<std::string>("outPath");
14 ecal_scoring_plane_passname_ =
15 ps.get<std::string>("ecal_scoring_plane_passname");
16 target_scoring_plane_passname_ =
17 ps.get<std::string>("target_scoring_plane_passname");
18 target_sp_hits_events_passname_ =
19 ps.get<std::string>("target_sp_hits_events_passname");
20 ecal_sp_hits_events_passname_ =
21 ps.get<std::string>("ecal_sp_hits_events_passname");
22}
23
24void PropagationMapWriter::produce(framework::Event& event) {
25 std::string in_tag;
26 in_tag = "TargetScoringPlaneHits";
27 if (!event.exists(in_tag, target_sp_hits_events_passname_)) return;
28 const std::vector<ldmx::SimTrackerHit> hits_targ =
29 event.getCollection<ldmx::SimTrackerHit>(in_tag,
30 target_scoring_plane_passname_);
31
32 in_tag = "EcalScoringPlaneHits";
33 if (!event.exists(in_tag, ecal_sp_hits_events_passname_)) return;
34 const std::vector<ldmx::SimTrackerHit> hits_ecal =
35 event.getCollection<ldmx::SimTrackerHit>(in_tag,
36 ecal_scoring_plane_passname_);
37
38 ldmx::SimTrackerHit h1, h2; // the desired truth hits
39 for (const auto& hit : hits_targ) {
40 if (!(hit.getTrackID() == 1)) continue;
41 if (!(hit.getPdgID() == 11)) continue;
42 auto xyz = hit.getPosition();
43 if (xyz[2] < 0 || xyz[2] > 1) continue; // select one sp
44 h1 = hit;
45 }
46 for (const auto& hit : hits_ecal) {
47 if (!(hit.getTrackID() == 1)) continue;
48 if (!(hit.getPdgID() == 11)) continue;
49 auto xyz = hit.getPosition();
50 if (xyz[2] < 239.99 || xyz[2] > 240.01) continue;
51 h2 = hit;
52 }
53
54 // std::cout << h1.getPdgID() << " and " << h2.getPdgID() << std::endl;
55
56 if (h1.getPdgID() && h2.getPdgID()) {
57 // as a function of the Ecal face electron (but this should make a minimal
58 // difference)
59 profx_->Fill(h2.getEnergy(), h1.getMomentum()[0] / h1.getEnergy(),
60 h2.getPosition()[0] - h1.getPosition()[0]);
61 profy_->Fill(h2.getEnergy(), h1.getMomentum()[1] / h1.getEnergy(),
62 h2.getPosition()[1] - h1.getPosition()[1]);
63 // profx_->Fill(h1.getEnergy(), h1.getMomentum()[0]/h1.getEnergy(),
64 // h2.getPosition()[0]-h1.getPosition()[0]); profy_->Fill(h1.getEnergy(),
65 // h1.getMomentum()[1]/h1.getEnergy(),
66 // h2.getPosition()[1]-h1.getPosition()[1]);
67 }
68}
69
70void PropagationMapWriter::onProcessStart() {
71 // auto hdir = getHistoDirectory();
72 out_file_ = new TFile(out_path_.c_str(), "recreate");
73 out_file_->SetCompressionSettings(209);
74 // 100*alg+level
75 // 2=LZMA, 9 = max compression
76 profx_ = new TProfile2D("profx", ";energy;px/e", 40, 0, 4000, 40, -1, 1, -200,
77 200);
78 profy_ = new TProfile2D("profy", ";energy;py/e", 40, 0, 4000, 40, -1, 1, -200,
79 200);
80}
81
82void PropagationMapWriter::onProcessEnd() {
83 out_file_->Write();
84 out_file_->Close();
85}
86
87} // namespace trigger
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class which encapsulates information from a hit in a simulated tracking detector.
Implements an event buffer system for storing event data.
Definition Event.h:42
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:92
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Represents a simulated tracker hit in the simulation.