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 outPath_ = ps.getParameter<std::string>("outPath");
14}
15
16void PropagationMapWriter::produce(framework::Event& event) {
17 std::string inTag;
18 inTag = "TargetScoringPlaneHits";
19 if (!event.exists(inTag)) return;
20 const std::vector<ldmx::SimTrackerHit> hitsTarg =
21 event.getCollection<ldmx::SimTrackerHit>(inTag);
22
23 inTag = "EcalScoringPlaneHits";
24 if (!event.exists(inTag)) return;
25 const std::vector<ldmx::SimTrackerHit> hitsEcal =
26 event.getCollection<ldmx::SimTrackerHit>(inTag);
27
28 ldmx::SimTrackerHit h1, h2; // the desired truth hits
29 for (const auto& hit : hitsTarg) {
30 if (!(hit.getTrackID() == 1)) continue;
31 if (!(hit.getPdgID() == 11)) continue;
32 auto xyz = hit.getPosition();
33 if (xyz[2] < 0 || xyz[2] > 1) continue; // select one sp
34 h1 = hit;
35 }
36 for (const auto& hit : hitsEcal) {
37 if (!(hit.getTrackID() == 1)) continue;
38 if (!(hit.getPdgID() == 11)) continue;
39 auto xyz = hit.getPosition();
40 if (xyz[2] < 239.99 || xyz[2] > 240.01) continue;
41 h2 = hit;
42 }
43
44 // std::cout << h1.getPdgID() << " and " << h2.getPdgID() << std::endl;
45
46 if (h1.getPdgID() && h2.getPdgID()) {
47 // as a function of the Ecal face electron (but this should make a minimal
48 // difference)
49 profx_->Fill(h2.getEnergy(), h1.getMomentum()[0] / h1.getEnergy(),
50 h2.getPosition()[0] - h1.getPosition()[0]);
51 profy_->Fill(h2.getEnergy(), h1.getMomentum()[1] / h1.getEnergy(),
52 h2.getPosition()[1] - h1.getPosition()[1]);
53 // profx_->Fill(h1.getEnergy(), h1.getMomentum()[0]/h1.getEnergy(),
54 // h2.getPosition()[0]-h1.getPosition()[0]); profy_->Fill(h1.getEnergy(),
55 // h1.getMomentum()[1]/h1.getEnergy(),
56 // h2.getPosition()[1]-h1.getPosition()[1]);
57 }
58}
59
60void PropagationMapWriter::onProcessStart() {
61 // auto hdir = getHistoDirectory();
62 outFile_ = new TFile(outPath_.c_str(), "recreate");
63 outFile_->SetCompressionSettings(209);
64 // 100*alg+level
65 // 2=LZMA, 9 = max compression
66 profx_ = new TProfile2D("profx", ";energy;px/e", 40, 0, 4000, 40, -1, 1, -200,
67 200);
68 profy_ = new TProfile2D("profy", ";energy;py/e", 40, 0, 4000, 40, -1, 1, -200,
69 200);
70}
71
72void PropagationMapWriter::onProcessEnd() {
73 outFile_->Write();
74 outFile_->Close();
75}
76
77} // namespace trigger
78DECLARE_PRODUCER_NS(trigger, PropagationMapWriter);
#define DECLARE_PRODUCER_NS(NS, 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:41
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:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Represents a simulated tracker hit in the simulation.
std::vector< float > getPosition() const
Get the XYZ position of the hit [mm].