14 #include <top/reconstruction/TOPreco.h>
15 #include <top/reconstruction/TOPf77fun.h>
16 #include <top/geometry/TOPGeometryPar.h>
18 #include <framework/gearbox/Const.h>
19 #include <framework/logging/Logger.h>
22 void set_beta_rq_(
float*);
23 void set_time_window_(
float*,
float*);
24 void get_time_window_(
float*,
float*);
25 void set_pdf_opt_(
int*,
int*,
int*);
26 void set_store_opt_(
int*);
27 float get_logl_(
float*,
float*,
float*,
float*);
28 void get_logl_ch_(
float*,
float*,
float*,
float*,
float*);
30 void set_channel_mask_(
int*,
int*,
int*);
31 void set_channel_off_(
int*,
int*);
32 void print_channel_mask_();
33 void set_channel_effi_(
int*,
int*,
float*);
34 void redo_pdf_(
float*,
int*);
35 int get_num_peaks_(
int*);
36 void get_peak_(
int*,
int*,
float*,
float*,
float*);
38 int get_pik_typ_(
int*,
int*);
39 float get_pik_fic_(
int*,
int*);
40 float get_pik_e_(
int*,
int*);
41 float get_pik_sige_(
int*,
int*);
42 int get_pik_nx_(
int*,
int*);
43 int get_pik_ny_(
int*,
int*);
44 int get_pik_nxm_(
int*,
int*);
45 int get_pik_nym_(
int*,
int*);
46 int get_pik_nxe_(
int*,
int*);
47 int get_pik_nye_(
int*,
int*);
48 float get_pik_xd_(
int*,
int*);
49 float get_pik_yd_(
int*,
int*);
50 float get_pik_kxe_(
int*,
int*);
51 float get_pik_kye_(
int*,
int*);
52 float get_pik_kze_(
int*,
int*);
53 float get_pik_kxd_(
int*,
int*);
54 float get_pik_kyd_(
int*,
int*);
55 float get_pik_kzd_(
int*,
int*);
66 double BkgPerModule,
double ScaleN0)
71 std::vector<float> masses;
72 for (
int i = 0; i < Num; i++) {
73 masses.push_back((
float) Masses[i]);
75 rtra_set_hypo_(&Num, masses.data());
76 rtra_set_hypid_(&Num, pdgCodes);
78 float b = (float) BkgPerModule;
79 float s = (float) ScaleN0;
93 int numModules = geo->getNumModules();
94 for (
int moduleID = 1; moduleID <= numModules; moduleID++) {
95 unsigned numPixels = geo->getModule(moduleID).getPMTArray().getNumPixels();
96 for (
unsigned channel = 0; channel < numPixels; channel++) {
97 int mdn = moduleID - 1;
98 int ich = mapper.getPixelID(channel) - 1;
99 int flag = mask->isActive(moduleID, channel) and asicMask.
isActive(moduleID, channel);
100 set_channel_mask_(&mdn, &ich, &flag);
103 B2INFO(
"TOPreco: new channel masks have been passed to reconstruction");
111 int numModules = geo->getNumModules();
112 for (
int moduleID = 1; moduleID <= numModules; moduleID++) {
113 unsigned numPixels = geo->getModule(moduleID).getPMTArray().getNumPixels();
114 for (
unsigned channel = 0; channel < numPixels; channel++) {
115 if (channelT0->isCalibrated(moduleID, channel))
continue;
116 int mdn = moduleID - 1;
117 int ich = mapper.getPixelID(channel) - 1;
118 set_channel_off_(&mdn, &ich);
121 B2INFO(
"TOPreco: channelT0-uncalibrated channels have been masked off");
130 int numModules = geo->getNumModules();
131 for (
int moduleID = 1; moduleID <= numModules; moduleID++) {
132 unsigned numPixels = geo->getModule(moduleID).getPMTArray().getNumPixels();
133 for (
unsigned channel = 0; channel < numPixels; channel++) {
134 const auto* fe = fe_mapper.getMap(moduleID, channel / 128);
136 B2ERROR(
"TOPreco::setUncalibratedChannelsOff no front-end map found");
139 auto scrodID = fe->getScrodID();
140 const auto* sampleTimes = timebase->getSampleTimes(scrodID, channel);
141 if (sampleTimes->isCalibrated())
continue;
142 int mdn = moduleID - 1;
143 int ich = ch_mapper.getPixelID(channel) - 1;
144 set_channel_off_(&mdn, &ich);
147 B2INFO(
"TOPreco: timebase-uncalibrated channels have been masked off");
152 print_channel_mask_();
158 const auto* geo = topgp->getGeometry();
159 int numModules = geo->getNumModules();
160 for (
int moduleID = 1; moduleID <= numModules; moduleID++) {
161 int numPixels = geo->getModule(moduleID).getPMTArray().getNumPixels();
162 for (
int pixelID = 1; pixelID <= numPixels; pixelID++) {
163 int mdn = moduleID - 1;
164 int ich = pixelID - 1;
165 float effi = topgp->getRelativePixelEfficiency(moduleID, pixelID);
166 set_channel_effi_(&mdn, &ich, &effi);
169 B2INFO(
"TOPreco: new relative pixel efficiencies have been passed to reconstruction");
175 float mass = (float) Mass;
176 rtra_set_hypo_(&Num, &mass);
177 rtra_set_hypid_(&Num, &pdg);
182 float tmin = (float) Tmin;
183 float tmax = (float) Tmax;
184 set_time_window_(&tmin, &tmax);
191 get_time_window_(&tmin, &tmax);
199 set_pdf_opt_(&iopt, &NP, &NC);
205 set_store_opt_(&iopt);
219 float t = (float) time;
220 float terr = (float) timeError;
221 data_put_(&moduleID, &pixelID, &t, &terr, &status);
222 if (status > 0)
return status;
225 B2WARNING(
"TOPReco::addData: no space available in /TOP_DATA/");
228 B2ERROR(
"TOPReco::addData: invalid module ID."
229 <<
LogVar(
"moduleID", moduleID + 1));
232 B2ERROR(
"TOPReco::addData: invalid pixel ID."
233 <<
LogVar(
"pixelID", pixelID + 1));
236 B2DEBUG(100,
"TOPReco::addData: digit should already be masked-out (different masks used?)");
239 B2ERROR(
"TOPReco::addData: unknown return status."
240 <<
LogVar(
"status", status));
247 return data_getnum_();
251 double Px,
double Py,
double Pz,
int Q,
252 int HYP,
int moduleID)
258 float px = (float) Px;
259 float py = (float) Py;
260 float pz = (float) Pz;
264 rtra_put_(&x, &y, &z, &t, &px, &py, &pz, &Q, &HYP, &REF, &moduleID);
281 return rtra_get_flag_(&K);
288 return rtra_get_sfot_(&K, &i);
294 return rtra_get_bfot_(&K);
300 return rtra_get_nfot_(&K);
307 return rtra_get_plkh_(&K, &i);
313 std::vector<float> logl(Size), sfot(Size);
315 rtra_get_(&K, logl.data(), sfot.data(), &Size, &Nphot, &Flag, &MTRA, &REF);
316 for (
int i = 0; i < Size; i++) {
318 ExpNphot[i] = sfot[i];
325 float t0 = (float) timeShift;
326 float tmin = (float) timeMin;
327 float tmax = (float) timeMax;
328 float sigt = (float) sigma;
329 return get_logl_(&t0, &tmin, &tmax, &sigt);
335 float t0 = (float) timeShift;
336 float tmin = (float) timeMin;
337 float tmax = (float) timeMax;
338 float sigt = (float) sigma;
339 get_logl_ch_(&t0, &tmin, &tmax, &sigt, logL);
343 double& Tlen,
double& Mom,
int& moduleID)
346 float r[3], dir[3], len, tof, p;
347 rtra_gethit_(&K, &LocGlob, r, dir, &len, &tof, &p, &moduleID);
349 for (
int i = 0; i < 3; i++) {
358 std::vector<double> logl(Size), sfot(Size);
359 std::vector<int> hypid(Size);
361 getLogL(Size, logl.data(), sfot.data(), Nphot);
362 rtra_get_hypid_(&Size, hypid.data());
365 double logl_max = logl[0];
366 for (
int i = 1; i < Size; i++) {
367 if (logl[i] > logl_max) {logl_max = logl[i]; i_max = i;}
371 cout <<
"TOPreco::dumpLogL: Flag=" <<
getFlag();
372 cout <<
" Detected Photons=" << Nphot << endl;
373 cout <<
" i HypID LogL ExpPhot" << endl;
374 cout << showpoint << fixed << right;
375 for (
int i = 0; i < Size; i++) {
376 cout << setw(2) << i;
377 cout << setw(12) << hypid[i];
378 cout << setw(10) << setprecision(2) << logl[i];
379 cout << setw(8) << setprecision(2) << sfot[i];
380 if (i == i_max) cout <<
" <";
381 if (hypid[i] ==
m_hypID) cout <<
" <-- truth";
388 double r[3], dir[3], len, Tlen, p;
390 getTrackHit(LocGlob, r, dir, len, Tlen, p, moduleID);
393 cout << showpoint << fixed << right;
394 cout <<
"TOPreco::dumpTrackHit: moduleID=" << moduleID;
395 cout <<
" Len=" << setprecision(2) << len;
396 cout <<
"cm Tlen=" << setprecision(1) << Tlen;
397 cout <<
"cm p=" << setprecision(2) << p <<
"GeV/c" << endl;
398 cout <<
"position [cm]: ";
399 for (
int i = 0; i < 3; i++) {
400 cout << setw(10) << setprecision(2) << r[i];
402 if (LocGlob == c_Local) {cout <<
" (local)" << endl;}
403 else {cout <<
" (global)" << endl;}
405 cout <<
"direction: ";
406 for (
int i = 0; i < 3; i++) {
407 cout << setw(10) << setprecision(4) << dir[i];
409 if (LocGlob == c_Local) {cout <<
" (local)" << endl;}
410 else {cout <<
" (global)" << endl;}
421 float& fic,
float& wt)
424 get_pulls_(&K, &t, &t0, &wid, &fic, &wt, &ich);
432 float terr = (float) Terr;
433 float mass = (float) Mass;
434 return get_pdf_(&pixelID, &t, &terr, &mass, &PDG);
453 return get_num_peaks_(&pixelID);
457 float& position,
float& width,
float& numPhotons)
const
461 get_peak_(&pixelID, &k, &position, &width, &numPhotons);
467 return get_bgr_(&pixelID);
474 return get_pik_typ_(&pixelID, &k);
481 return get_pik_fic_(&pixelID, &k);
488 return get_pik_e_(&pixelID, &k);
495 return get_pik_sige_(&pixelID, &k);
502 return abs(get_pik_nx_(&pixelID, &k));
509 return abs(get_pik_ny_(&pixelID, &k));
516 return abs(get_pik_nxm_(&pixelID, &k));
523 return abs(get_pik_nym_(&pixelID, &k));
530 return abs(get_pik_nxe_(&pixelID, &k));
537 return abs(get_pik_nye_(&pixelID, &k));
544 return get_pik_xd_(&pixelID, &k);
551 return get_pik_yd_(&pixelID, &k);
558 return get_pik_kxe_(&pixelID, &k);
565 return get_pik_kye_(&pixelID, &k);
572 return get_pik_kze_(&pixelID, &k);
579 return get_pik_kxd_(&pixelID, &k);
586 return get_pik_kyd_(&pixelID, &k);
593 return get_pik_kzd_(&pixelID, &k);