LDMX Software
trigger::TrigElectronProducer Class Reference

Public Member Functions

 TrigElectronProducer (const std::string &name, framework::Process &process)
 
virtual void configure (framework::config::Parameters &ps)
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
virtual void produce (framework::Event &event)
 Process the event and put new data products into it.
 
virtual void onProcessStart ()
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
void setupMaps (bool isX)
 
float getP (bool isX, float e, float d)
 
float getPx (float e, float d)
 
float getPy (float e, float d)
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onNewRun (const ldmx::RunHeader &run_header)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module_.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Member Functions

std::optional< float > tsTargetY (const framework::Event &event)
 

Private Attributes

std::string ts_track_coll_name_
 
std::string ts_passname_
 
float ts_y0_ {0}
 
float ts_channel_pitch_ {0}
 
bool warned_missing_ts_ {false}
 
std::string cluster_coll_name_
 
std::string ele_coll_name_
 
std::string cluster_coll_passname_
 
std::string cluster_collname_events_passname_
 
std::string prop_map_name_
 
double ecal_front_z_ {0}
 
TProfile2D * prop_mapx_ {nullptr}
 
TProfile2D * prop_mapy_ {nullptr}
 
std::vector< TF1 * > fits_x_ {}
 
std::vector< TF1 * > fits_y_ {}
 

Additional Inherited Members

- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManager & ntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 28 of file TrigElectronProducer.h.

Constructor & Destructor Documentation

◆ TrigElectronProducer()

trigger::TrigElectronProducer::TrigElectronProducer ( const std::string & name,
framework::Process & process )
inline

Definition at line 30 of file TrigElectronProducer.h.

Base class for a module which produces a data product.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

Member Function Documentation

◆ configure()

void trigger::TrigElectronProducer::configure ( framework::config::Parameters & parameters)
virtual

Callback for the EventProcessor to configure itself from the given set of parameters.

The parameters a processor has access to are the member variables of the python class in the sequence that has class_name equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 13 of file TrigElectronProducer.cxx.

13 {
14 cluster_coll_name_ = ps.get<std::string>("cluster_coll_name");
15 ele_coll_name_ = ps.get<std::string>("ele_coll_name");
16 prop_map_name_ = ps.get<std::string>("prop_map_name");
17 ecal_front_z_ = ps.get<double>("ecal_front_z");
18 cluster_coll_passname_ = ps.get<std::string>("cluster_coll_passname");
19 cluster_collname_events_passname_ =
20 ps.get<std::string>("cluster_collname_events_passname");
21 ts_track_coll_name_ = ps.get<std::string>("ts_track_coll_name");
22 ts_passname_ = ps.get<std::string>("ts_passname");
23 ts_y0_ = static_cast<float>(ps.get<double>("ts_y0"));
24 ts_channel_pitch_ = static_cast<float>(ps.get<double>("ts_channel_pitch"));
25}

References framework::config::Parameters::get().

◆ getP()

float trigger::TrigElectronProducer::getP ( bool isX,
float e,
float d )

Definition at line 125 of file TrigElectronProducer.cxx.

125 {
126 if (fabs(d) > 300) return 0; // something has gone very wrong
127 const bool debug = false;
128 TProfile2D* prof = isX ? prop_mapx_ : prop_mapy_;
129 if (!prof) {
130 if (debug) std::cout << "null pointer" << std::endl;
131 return 0;
132 }
133 int bin1{-9999}, bin2{-9999};
134 bin1 = prof->GetXaxis()->FindBin(e);
135 float frac = e - prof->GetXaxis()->GetBinCenter(bin1);
136 float diff = fabs(prof->GetXaxis()->GetBinCenter(bin1) -
137 prof->GetXaxis()->GetBinCenter(bin2));
138 bin2 = diff > 0 ? bin1 + 1 : bin1 - 1;
139 bin1 = std::max(1, std::min(bin1, prof->GetXaxis()->GetNbins()));
140 bin2 = std::max(1, std::min(bin2, prof->GetXaxis()->GetNbins()));
141 float res1, res2;
142 if (isX) {
143 res1 = fits_x_[bin1 - 1]->GetX(d);
144 res2 = fits_x_[bin2 - 1]->GetX(d);
145 } else {
146 res1 = fits_y_[bin1 - 1]->GetX(d);
147 res2 = fits_y_[bin2 - 1]->GetX(d);
148 }
149
150 if (debug)
151 printf("%f %f %f %f :: %f %f %f \n", d, e,
152 prof->GetXaxis()->GetBinCenter(bin1),
153 prof->GetXaxis()->GetBinCenter(bin2), res1, res2,
154 std::abs(frac / diff) * res2 + (1 - std::abs(frac / diff)) * res1);
155 return e *
156 (std::abs(frac / diff) * res2 + (1 - std::abs(frac / diff)) * res1);
157}

◆ getPx()

float trigger::TrigElectronProducer::getPx ( float e,
float d )
inline

Definition at line 43 of file TrigElectronProducer.h.

43{ return getP(true, e, d); }

◆ getPy()

float trigger::TrigElectronProducer::getPy ( float e,
float d )
inline

Definition at line 44 of file TrigElectronProducer.h.

44{ return getP(false, e, d); }

◆ onProcessEnd()

void trigger::TrigElectronProducer::onProcessEnd ( )
virtual

Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.

Reimplemented from framework::EventProcessor.

Definition at line 175 of file TrigElectronProducer.cxx.

175 {
176 ldmx_log(debug) << "Process ends!";
177
178 // free maps
179 for (int i = 0; i < fits_x_.size(); i++) delete fits_x_[i];
180 for (int i = 0; i < fits_y_.size(); i++) delete fits_y_[i];
181
182 return;
183}

◆ onProcessStart()

void trigger::TrigElectronProducer::onProcessStart ( )
virtual

Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.

Reimplemented from framework::EventProcessor.

Definition at line 159 of file TrigElectronProducer.cxx.

159 {
160 ldmx_log(debug) << "Process starts!";
161
162 TFile* f = new TFile(prop_map_name_.c_str(), "read");
163 prop_mapx_ = (TProfile2D*)f->Get("profx");
164 prop_mapx_->SetDirectory(0);
165 prop_mapy_ = (TProfile2D*)f->Get("profy");
166 prop_mapy_->SetDirectory(0);
167 f->Close();
168
169 setupMaps(0); // X
170 setupMaps(1); // Y
171
172 return;
173}

◆ produce()

void trigger::TrigElectronProducer::produce ( framework::Event & event)
virtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Implements framework::Producer.

Definition at line 27 of file TrigElectronProducer.cxx.

27 {
28 if (!event.exists(cluster_coll_name_, cluster_collname_events_passname_))
29 return;
30 auto ecal_clusters{event.getObject<TrigCaloClusterCollection>(
31 cluster_coll_name_, cluster_coll_passname_)};
32
33 // target y from the trigger scintillator
34 const auto y_t{tsTargetY(event)};
35
36 // std::vector<ldmx::SimParticle> eles;
37 TrigParticleCollection eles;
38 for (const auto& clus : ecal_clusters) {
39 TrigParticle el;
40 // ldmx::SimParticle el;
41
42 // We fit for the response in an eGun sample like this:
43 // Events->Draw("Electron_e[0]/Truth_e[0]:Truth_e[0]","Truth_e[0]>500 &&
44 // Truth_e[0]<3500","prof")
45 // --> update fit to use the electron energy at the ecal face (not target)
46 // -->
47 // Events->Draw("Electron_eClus[0]/TruthEcal_e[0]:TruthEcal_e[0]","TruthEcal_e[0]>500
48 // && TruthEcal_e[0]<3500","prof") TF1* func = new
49 // TF1("func","[0]/x+[1]",500,3500); htemp->Fit(func) float calib_e =
50 // clus.e() / (98.099700/clus.e() + 0.77202700);
51 float calib_e =
52 clus.e() / (184.103 / clus.e() + 0.753756); // divide by response
53
54 // const float dX = clus.x() - xT;
55 // float R = calib_e*(11500/4000.); // convert 11.5m/4GeV (in mm/MeV)
56 // float zd = 240.; // 240mm z detector
57 // float a = dX/zd;
58 // float b = (dX*dX+zd*zd)/(2*R*zd);
59 // float pred_px = clus.e() * (-b+a*sqrt(1+a*a-b*b))/(1+a*a);
60 // float pred_py = clus.e()/4e3 * (clus.y() - yT) * 13.3; //mev/mm
61
62 // Events->Draw("TruthEcal_y-Truth_y -
63 // Electron_dy*240/Electron_zClus","TruthEcal_e>1e3")
64
65 // the TS measures only y, so px is not predicted
66 const float pred_px = 0;
67 // y deflection, tracing back to the ECal face
68 const float pred_py =
69 y_t && clus.z() > 0
70 ? getPy(calib_e, (ecal_front_z_ / clus.z()) * (clus.y() - *y_t))
71 : 0;
72
73 // std::cout << "expectX " << pred_px << " versus " << fit_px << std::endl;
74 // std::cout << "expectY " << pred_py << " versus " << fit_py << std::endl;
75 float pred_pz = sqrt(
76 std::max(pow(calib_e, 2) - (pow(pred_px, 2) + pow(pred_py, 2)), 0.));
77
78 // produce el
79 Point targ(0, y_t.value_or(0), 0);
80 LorentzVector p4(pred_px, pred_py, pred_pz, calib_e);
81 eles.emplace_back(p4, targ, 11);
82 Point calo(clus.x(), clus.y(),
83 clus.z()); // n.b. "Z" is not at the ECal Face!
84 eles.back().setEndPoint(
85 calo); // clus.x(), clus.y(), clus.z()); how to handle?
86 eles.back().setClusEnergy(clus.e());
87 eles.back().setClusTP(clus.nTP());
88 eles.back().setClusDepth(clus.depth());
89
90 // el.setEnergy(clus.e());
91 // el.setPdgID(11);
92 // el.setCharge(-1);
93 // el.setMass(0.000511);
94 // el.setVertex(0, xT, yT);
95 // el.setMomentum(pred_px, pred_py, pred_pz);
96 // eles.push_back(el);
97 }
98 event.add(ele_coll_name_, eles);
99}
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:107

References framework::Event::exists().

◆ setupMaps()

void trigger::TrigElectronProducer::setupMaps ( bool isX)

Definition at line 101 of file TrigElectronProducer.cxx.

101 {
102 TProfile2D* prof = isX ? prop_mapx_ : prop_mapy_;
103 const int n = prof->GetXaxis()->GetNbins();
104 for (int i = 1; i <= n; i++) {
105 TF1* func = new TF1("func", "pol1", -20, 20); // going to fit for px/e
106 TProfile* proj = prof->ProfileY("h", i, i);
107 proj->Fit("func", "q", "", -1, 1);
108 bool debug = false;
109 if (debug) {
110 TCanvas c("c", "");
111 proj->Draw();
112 func->Draw("same");
113 c.SaveAs(TString::Format("debug_fit_%d_%d.pdf", int(isX), i));
114 }
115 delete proj;
116 if (isX) {
117 fits_x_.push_back(func);
118 } else {
119 fits_y_.push_back(func);
120 }
121 }
122 return;
123}

◆ tsTargetY()

std::optional< float > trigger::TrigElectronProducer::tsTargetY ( const framework::Event & event)
private

Definition at line 185 of file TrigElectronProducer.cxx.

186 {
187 const auto& coll{ts_track_coll_name_};
188 if (!event.exists(coll, ts_passname_)) {
189 if (!warned_missing_ts_) {
190 ldmx_log(warn) << "No " << coll << " (pass '" << ts_passname_
191 << "') in the event: trigger electrons get py = 0.";
192 warned_missing_ts_ = true;
193 }
194 return std::nullopt;
195 }
196 // lowest residual with ties going to the highest PE
197 std::optional<float> centroid;
198 float residual{0};
199 float pe{0};
200 for (const auto& track :
201 event.getCollection<ldmx::TrigScintTrack>(coll, ts_passname_)) {
202 if (centroid &&
203 (track.getResidual() > residual ||
204 (track.getResidual() == residual && track.getPE() <= pe))) {
205 continue;
206 }
207 centroid = track.getCentroid();
208 residual = track.getResidual();
209 pe = track.getPE();
210 }
211 if (!centroid) return std::nullopt;
212 return ts_y0_ + ts_channel_pitch_ * (*centroid);
213}
const std::vector< ContentType > & getCollection(const std::string &collectionName, const std::string &passName) const
Get a collection (std::vector) of objects from the event bus.
Definition Event.h:409
Represents a track of trigger scintillator clusters.

Member Data Documentation

◆ cluster_coll_name_

std::string trigger::TrigElectronProducer::cluster_coll_name_
private

Definition at line 59 of file TrigElectronProducer.h.

◆ cluster_coll_passname_

std::string trigger::TrigElectronProducer::cluster_coll_passname_
private

Definition at line 63 of file TrigElectronProducer.h.

◆ cluster_collname_events_passname_

std::string trigger::TrigElectronProducer::cluster_collname_events_passname_
private

Definition at line 64 of file TrigElectronProducer.h.

◆ ecal_front_z_

double trigger::TrigElectronProducer::ecal_front_z_ {0}
private

Definition at line 68 of file TrigElectronProducer.h.

68{0};

◆ ele_coll_name_

std::string trigger::TrigElectronProducer::ele_coll_name_
private

Definition at line 61 of file TrigElectronProducer.h.

◆ fits_x_

std::vector<TF1*> trigger::TrigElectronProducer::fits_x_ {}
private

Definition at line 71 of file TrigElectronProducer.h.

71{};

◆ fits_y_

std::vector<TF1*> trigger::TrigElectronProducer::fits_y_ {}
private

Definition at line 72 of file TrigElectronProducer.h.

72{};

◆ prop_map_name_

std::string trigger::TrigElectronProducer::prop_map_name_
private

Definition at line 66 of file TrigElectronProducer.h.

◆ prop_mapx_

TProfile2D* trigger::TrigElectronProducer::prop_mapx_ {nullptr}
private

Definition at line 69 of file TrigElectronProducer.h.

69{nullptr};

◆ prop_mapy_

TProfile2D* trigger::TrigElectronProducer::prop_mapy_ {nullptr}
private

Definition at line 70 of file TrigElectronProducer.h.

70{nullptr};

◆ ts_channel_pitch_

float trigger::TrigElectronProducer::ts_channel_pitch_ {0}
private

Definition at line 55 of file TrigElectronProducer.h.

55{0};

◆ ts_passname_

std::string trigger::TrigElectronProducer::ts_passname_
private

Definition at line 52 of file TrigElectronProducer.h.

◆ ts_track_coll_name_

std::string trigger::TrigElectronProducer::ts_track_coll_name_
private

Definition at line 51 of file TrigElectronProducer.h.

◆ ts_y0_

float trigger::TrigElectronProducer::ts_y0_ {0}
private

Definition at line 54 of file TrigElectronProducer.h.

54{0};

◆ warned_missing_ts_

bool trigger::TrigElectronProducer::warned_missing_ts_ {false}
private

Definition at line 56 of file TrigElectronProducer.h.

56{false};

The documentation for this class was generated from the following files: