7#include "TrigScint/Event/TrigScintTrack.h"
8#include "Trigger/Event/TrigCaloCluster.h"
9#include "Trigger/Event/TrigParticle.h"
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"));
28 if (!event.
exists(cluster_coll_name_, cluster_collname_events_passname_))
30 auto ecal_clusters{
event.getObject<TrigCaloClusterCollection>(
31 cluster_coll_name_, cluster_coll_passname_)};
34 const auto y_t{tsTargetY(event)};
37 TrigParticleCollection eles;
38 for (
const auto& clus : ecal_clusters) {
52 clus.e() / (184.103 / clus.e() + 0.753756);
66 const float pred_px = 0;
70 ? getPy(calib_e, (ecal_front_z_ / clus.z()) * (clus.y() - *y_t))
76 std::max(pow(calib_e, 2) - (pow(pred_px, 2) + pow(pred_py, 2)), 0.));
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(),
84 eles.back().setEndPoint(
86 eles.back().setClusEnergy(clus.e());
87 eles.back().setClusTP(clus.nTP());
88 eles.back().setClusDepth(clus.depth());
98 event.add(ele_coll_name_, eles);
101void TrigElectronProducer::setupMaps(
bool isX) {
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);
106 TProfile* proj = prof->ProfileY(
"h", i, i);
107 proj->Fit(
"func",
"q",
"", -1, 1);
113 c.SaveAs(TString::Format(
"debug_fit_%d_%d.pdf",
int(isX), i));
117 fits_x_.push_back(func);
119 fits_y_.push_back(func);
125float TrigElectronProducer::getP(
bool isX,
float e,
float d) {
126 if (fabs(d) > 300)
return 0;
127 const bool debug =
false;
128 TProfile2D* prof = isX ? prop_mapx_ : prop_mapy_;
130 if (debug) std::cout <<
"null pointer" << std::endl;
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()));
143 res1 = fits_x_[bin1 - 1]->GetX(d);
144 res2 = fits_x_[bin2 - 1]->GetX(d);
146 res1 = fits_y_[bin1 - 1]->GetX(d);
147 res2 = fits_y_[bin2 - 1]->GetX(d);
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);
156 (std::abs(frac / diff) * res2 + (1 - std::abs(frac / diff)) * res1);
160 ldmx_log(debug) <<
"Process starts!";
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);
176 ldmx_log(debug) <<
"Process ends!";
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];
185std::optional<float> TrigElectronProducer::tsTargetY(
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;
197 std::optional<float> centroid;
200 for (
const auto& track :
203 (track.getResidual() > residual ||
204 (track.getResidual() == residual && track.getPE() <= pe))) {
207 centroid = track.getCentroid();
208 residual = track.getResidual();
211 if (!centroid)
return std::nullopt;
212 return ts_y0_ + ts_channel_pitch_ * (*centroid);
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
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.
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.
Class encapsulating parameters for configuring a processor.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Represents a track of trigger scintillator clusters.
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.