8#include "Trigger/Event/TrigCaloCluster.h"
9#include "Trigger/Event/TrigParticle.h"
14 sp_coll_name_ = ps.
get<std::string>(
"scoringPlaneCollName");
15 cluster_coll_name_ = ps.
get<std::string>(
"clusterCollName");
16 ele_coll_name_ = ps.
get<std::string>(
"eleCollName");
17 prop_map_name_ = ps.
get<std::string>(
"propMapName");
18 target_sp_passname_ = ps.
get<std::string>(
"target_sp_passname");
19 cluster_coll_passname_ = ps.
get<std::string>(
"cluster_coll_passname");
20 cluster_collname_events_passname_ =
21 ps.
get<std::string>(
"cluster_collname_events_passname");
22 sp_collname_events_passname_ =
23 ps.
get<std::string>(
"sp_collname_events_passname_");
27 if (!event.
exists(cluster_coll_name_, cluster_collname_events_passname_))
29 auto ecal_clusters{
event.getObject<TrigCaloClusterCollection>(
30 cluster_coll_name_, cluster_coll_passname_)};
32 if (!event.
exists(sp_coll_name_, sp_collname_events_passname_))
return;
33 const std::vector<ldmx::SimTrackerHit> target_sp_hit =
38 float x_t = 0, y_t = 0;
39 for (
const auto& hit : target_sp_hit) {
40 if (hit.getTrackID() != 1)
continue;
41 if (!(abs(hit.getPdgID()) == 11))
continue;
42 auto xyz = hit.getPosition();
43 if (xyz[2] < 0 || xyz[2] > 1)
continue;
51 TrigParticleCollection eles;
52 for (
const auto& clus : ecal_clusters) {
66 clus.e() / (184.103 / clus.e() + 0.753756);
79 float pred_px = clus.z() > 0
80 ? getPx(calib_e, (240. / clus.z()) * (clus.x() - x_t))
83 clus.z() > 0 ? getPy(calib_e, (240. / clus.z()) * (clus.y() - y_t)) : 0;
88 std::max(pow(calib_e, 2) - (pow(pred_px, 2) + pow(pred_py, 2)), 0.));
91 Point targ(x_t, y_t, 0);
92 LorentzVector p4(pred_px, pred_py, pred_pz, calib_e);
93 eles.emplace_back(p4, targ, 11);
94 Point calo(clus.x(), clus.y(),
96 eles.back().setEndPoint(
98 eles.back().setClusEnergy(clus.e());
99 eles.back().setClusTP(clus.nTP());
100 eles.back().setClusDepth(clus.depth());
110 event.add(ele_coll_name_, eles);
113void TrigElectronProducer::setupMaps(
bool isX) {
114 TProfile2D* prof = isX ? prop_mapx_ : prop_mapy_;
115 const int n = prof->GetXaxis()->GetNbins();
116 for (
int i = 1; i <= n; i++) {
117 TF1* func =
new TF1(
"func",
"pol1", -20, 20);
118 TProfile* proj = prof->ProfileY(
"h", i, i);
119 proj->Fit(
"func",
"q",
"", -1, 1);
125 c.SaveAs(TString::Format(
"debug_fit_%d_%d.pdf",
int(isX), i));
129 fits_x_.push_back(func);
131 fits_y_.push_back(func);
137float TrigElectronProducer::getP(
bool isX,
float e,
float d) {
138 if (fabs(d) > 300)
return 0;
139 const bool debug =
false;
140 TProfile2D* prof = isX ? prop_mapx_ : prop_mapy_;
142 if (debug) std::cout <<
"null pointer" << std::endl;
145 int bin1{-9999}, bin2{-9999};
146 bin1 = prof->GetXaxis()->FindBin(e);
147 float frac = e - prof->GetXaxis()->GetBinCenter(bin1);
148 float diff = fabs(prof->GetXaxis()->GetBinCenter(bin1) -
149 prof->GetXaxis()->GetBinCenter(bin2));
150 bin2 = diff > 0 ? bin1 + 1 : bin1 - 1;
151 bin1 = std::max(1, std::min(bin1, prof->GetXaxis()->GetNbins()));
152 bin2 = std::max(1, std::min(bin2, prof->GetXaxis()->GetNbins()));
155 res1 = fits_x_[bin1 - 1]->GetX(d);
156 res2 = fits_x_[bin2 - 1]->GetX(d);
158 res1 = fits_y_[bin1 - 1]->GetX(d);
159 res2 = fits_y_[bin2 - 1]->GetX(d);
163 printf(
"%f %f %f %f :: %f %f %f \n", d, e,
164 prof->GetXaxis()->GetBinCenter(bin1),
165 prof->GetXaxis()->GetBinCenter(bin2), res1, res2,
166 std::abs(frac / diff) * res2 + (1 - std::abs(frac / diff)) * res1);
168 (std::abs(frac / diff) * res2 + (1 - std::abs(frac / diff)) * res1);
172 ldmx_log(debug) <<
"Process starts!";
174 TFile* f =
new TFile(prop_map_name_.c_str(),
"read");
175 prop_mapx_ = (TProfile2D*)f->Get(
"profx");
176 prop_mapx_->SetDirectory(0);
177 prop_mapy_ = (TProfile2D*)f->Get(
"profy");
178 prop_mapy_->SetDirectory(0);
188 ldmx_log(debug) <<
"Process ends!";
191 for (
int i = 0; i < fits_x_.size(); i++)
delete fits_x_[i];
192 for (
int i = 0; i < fits_y_.size(); i++)
delete fits_y_[i];
Class that translates raw positions of ECal module hits into cells in a hexagonal readout.
#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.
Trigger electron reconstruction algorithm.
Implements an event buffer system for storing event data.
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.
Class encapsulating parameters for configuring a processor.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Represents a simulated tracker hit in the simulation.
virtual void onProcessStart()
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
virtual void produce(framework::Event &event)
Process the event and put new data products into it.
virtual void onProcessEnd()
Callback for the EventProcessor to take any necessary action when the processing of events finishes,...
virtual void configure(framework::config::Parameters &ps)
Callback for the EventProcessor to configure itself from the given set of parameters.
Class for particles reconstructed by the trigger system.