10#include <ecl/variables/ECLCalibrationVariables.h>
13#include <analysis/dataobjects/Particle.h>
14#include <analysis/dataobjects/ECLEnergyCloseToTrack.h>
15#include <analysis/dataobjects/ECLTRGInformation.h>
16#include <analysis/dataobjects/ECLTriggerCell.h>
17#include <analysis/VariableManager/Utility.h>
18#include <framework/logging/Logger.h>
19#include <framework/datastore/StoreArray.h>
20#include <mdst/dataobjects/ECLCluster.h>
21#include <mdst/dataobjects/Track.h>
33 double eclEnergy3FWDBarrel(
const Particle* particle)
36 const Track* track = particle->getTrack();
39 auto* eclinfo = track->getRelatedTo<ECLEnergyCloseToTrack>();
42 return eclinfo->getEnergy3FWDBarrel();
44 B2WARNING(
"Relation to ECLEnergyCloseToTrack not found, did you forget to run ECLTrackCalDigitMatchModule?");
45 return std::numeric_limits<float>::quiet_NaN();
49 return std::numeric_limits<float>::quiet_NaN();
52 double eclEnergy3FWDEndcap(
const Particle* particle)
55 const Track* track = particle->getTrack();
58 auto* eclinfo = track->getRelatedTo<ECLEnergyCloseToTrack>();
61 return eclinfo->getEnergy3FWDEndcap();
63 B2WARNING(
"Relation to ECLEnergyCloseToTrack not found, did you forget to run ECLTrackCalDigitMatchModule?");
64 return std::numeric_limits<float>::quiet_NaN();
68 return std::numeric_limits<float>::quiet_NaN();
71 double eclEnergy3BWDBarrel(
const Particle* particle)
74 const Track* track = particle->getTrack();
77 auto* eclinfo = track->getRelatedTo<ECLEnergyCloseToTrack>();
80 return eclinfo->getEnergy3BWDBarrel();
82 B2WARNING(
"Relation to ECLEnergyCloseToTrack not found, did you forget to run ECLTrackCalDigitMatchModule?");
83 return std::numeric_limits<float>::quiet_NaN();
87 return std::numeric_limits<float>::quiet_NaN();
90 double eclEnergy3BWDEndcap(
const Particle* particle)
92 const Track* track = particle->getTrack();
95 auto* eclinfo = track->getRelatedTo<ECLEnergyCloseToTrack>();
98 return eclinfo->getEnergy3BWDEndcap();
100 B2WARNING(
"Relation to ECLEnergyCloseToTrack not found, did you forget to run ECLTrackCalDigitMatchModule?");
101 return std::numeric_limits<float>::quiet_NaN();
105 return std::numeric_limits<float>::quiet_NaN();
108 double eclNumberOfTCsForCluster(
const Particle* particle,
const std::vector<double>& vars)
110 if (vars.size() != 4) {
111 B2FATAL(
"Need exactly four parameters (minthetaid, maxthetaid, minhitwindow, maxhitwindow).");
115 StoreArray<ECLTriggerCell> ecltc;
116 if (!ecltc)
return std::numeric_limits<double>::quiet_NaN();
119 const int minTheta = int(std::lround(vars[0]));
120 const int maxTheta = int(std::lround(vars[1]));
121 if (maxTheta < minTheta) {
122 B2WARNING(
"minTheta i (vars[0]) must be equal or less than maxTheta j (vars[1]).");
123 return std::numeric_limits<double>::quiet_NaN();
126 const int minHitWin = int(std::lround(vars[2]));
127 const int maxHitWin = int(std::lround(vars[3]));
128 if (maxHitWin < minHitWin) {
129 B2WARNING(
"minHitWin k (vars[2]) must be equal or less than maxHitWin l (vars[3]).");
130 return std::numeric_limits<double>::quiet_NaN();
134 const ECLCluster* cluster = particle->getECLCluster();
138 auto relationsTCs = cluster->getRelationsWith<ECLTriggerCell>();
139 for (
unsigned int idxTC = 0; idxTC < relationsTCs.size(); ++idxTC) {
140 const auto tc = relationsTCs.object(idxTC);
141 if (tc->getThetaId() >= minTheta and tc->getThetaId() <= maxTheta
142 and tc->getHitWin() >= minHitWin and tc->getHitWin() <= maxHitWin) result += 1.0;
148 double eclTCFADCForCluster(
const Particle* particle,
const std::vector<double>& vars)
150 if (vars.size() != 4) {
151 B2FATAL(
"Need exactly four parameters (minthetaid, maxthetaid, minhitwindow, maxhitwindow).");
155 StoreArray<ECLTriggerCell> ecltc;
156 if (!ecltc)
return std::numeric_limits<double>::quiet_NaN();
159 const int minTheta = int(std::lround(vars[0]));
160 const int maxTheta = int(std::lround(vars[1]));
161 if (maxTheta < minTheta) {
162 B2WARNING(
"minTheta i (vars[0]) must be equal or less than maxTheta j (vars[1]).");
163 return std::numeric_limits<double>::quiet_NaN();
167 const int minHitWin = int(std::lround(vars[2]));
168 const int maxHitWin = int(std::lround(vars[3]));
169 if (maxHitWin < minHitWin) {
170 B2WARNING(
"minHitWin k (vars[2]) must be equal or less than maxHitWin l (vars[3]).");
171 return std::numeric_limits<double>::quiet_NaN();
175 const ECLCluster* cluster = particle->getECLCluster();
179 auto relationsTCs = cluster->getRelationsTo<ECLTriggerCell>();
180 for (
unsigned int idxTC = 0; idxTC < relationsTCs.size(); ++idxTC) {
181 const auto tc = relationsTCs.object(idxTC);
182 if (tc->getThetaId() >= minTheta and tc->getThetaId() <= maxTheta
183 and tc->getHitWin() >= minHitWin and tc->getHitWin() <= maxHitWin) result += tc->getFADC();
189 double eclTCIsMaximumForCluster(
const Particle* particle)
193 StoreArray<ECLTriggerCell> ecltc;
194 if (!ecltc)
return std::numeric_limits<double>::quiet_NaN();
197 const ECLCluster* cluster = particle->getECLCluster();
201 auto relationsTCs = cluster->getRelationsTo<ECLTriggerCell>();
202 for (
unsigned int idxTC = 0; idxTC < relationsTCs.size(); ++idxTC) {
203 const auto tc = relationsTCs.object(idxTC);
204 if (tc->isHighestFADC()) result = 1.0;
210 double eclClusterTrigger(
const Particle* particle)
212 const ECLCluster* cluster = particle->getECLCluster();
214 const bool matcher = cluster->hasTriggerClusterMatching();
217 return cluster->isTriggerCluster();
219 B2WARNING(
"Particle has an associated ECLCluster but the ECLTriggerClusterMatcher module has not been run!");
220 return std::numeric_limits<float>::quiet_NaN();
223 return std::numeric_limits<float>::quiet_NaN();
226 double getEnergyTC(
const Particle*,
const std::vector<double>& vars)
228 if (vars.size() != 1) {
229 B2FATAL(
"Need exactly one parameter (tcid).");
232 StoreObjPtr<ECLTRGInformation> tce;
233 const int tcid = int(std::lround(vars[0]));
235 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
236 return tce->getEnergyTC(tcid);
239 double getEnergyTCECLCalDigit(
const Particle*,
const std::vector<double>& vars)
241 if (vars.size() != 1) {
242 B2FATAL(
"Need exactly one parameter (tcid).");
245 StoreObjPtr<ECLTRGInformation> tce;
246 const int tcid = int(std::lround(vars[0]));
248 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
249 return tce->getEnergyTCECLCalDigit(tcid);
252 double getTimingTC(
const Particle*,
const std::vector<double>& vars)
254 if (vars.size() != 1) {
255 B2FATAL(
"Need exactly one parameter (tcid).");
258 StoreObjPtr<ECLTRGInformation> tce;
259 const int tcid = int(std::lround(vars[0]));
261 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
262 return tce->getTimingTC(tcid);
265 double eclHitWindowTC(
const Particle*,
const std::vector<double>& vars)
267 if (vars.size() != 1) {
268 B2FATAL(
"Need exactly one parameter (tcid).");
271 StoreObjPtr<ECLTRGInformation> tce;
272 const int tcid = int(std::lround(vars[0]));
274 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
275 return tce->getHitWinTC(tcid);
278 double getEvtTimingTC(
const Particle*)
280 StoreObjPtr<ECLTRGInformation> tce;
281 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
282 return tce->getEvtTiming();
285 double getMaximumTCId(
const Particle*)
287 StoreObjPtr<ECLTRGInformation> tce;
288 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
289 return tce->getMaximumTCId();
292 double getTimingTCECLCalDigit(
const Particle*,
const std::vector<double>& vars)
294 if (vars.size() != 1) {
295 B2FATAL(
"Need exactly one parameter (tcid).");
298 StoreObjPtr<ECLTRGInformation> tce;
299 const int tcid = int(std::lround(vars[0]));
301 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
302 return tce->getTimingTCECLCalDigit(tcid);
305 double getNumberOfTCs(
const Particle*,
const std::vector<double>& vars)
307 if (vars.size() != 3) {
308 B2FATAL(
"Need exactly three parameters (fadccut, minthetaid, maxthetaid).");
311 StoreArray<ECLTriggerCell> ecltcs;
312 const int fadccut = int(std::lround(vars[0]));
314 if (!ecltcs)
return std::numeric_limits<double>::quiet_NaN();
315 if (fadccut == 0)
return ecltcs.getEntries();
317 int minTheta = int(std::lround(vars[1]));
318 int maxTheta = int(std::lround(vars[2]));
321 for (
const auto& tc : ecltcs) {
322 if (tc.getFADC() >= fadccut and
323 tc.getThetaId() >= minTheta and
324 tc.getThetaId() <= maxTheta) nTCs++;
331 double eclEnergySumTC(
const Particle*,
const std::vector<double>& vars)
333 if (vars.size() != 3) {
334 B2FATAL(
"Need exactly three parameters (fadccut, minthetaid, maxthetaid).");
337 StoreObjPtr<ECLTRGInformation> tce;
338 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
340 const int fadccut = int(std::lround(vars[0]));
341 const int minTheta = int(std::lround(vars[1]));
342 const int maxTheta = int(std::lround(vars[2]));
344 if (maxTheta < minTheta) {
345 B2WARNING(
"minTheta i (vars[1]) must be equal or less than maxTheta j (vars[2]).");
346 return std::numeric_limits<double>::quiet_NaN();
349 double energySum = 0.;
350 for (
unsigned idx = 1; idx <= 576; idx++) {
351 if (tce->getThetaIdTC(idx) >= minTheta and tce->getThetaIdTC(idx) <= maxTheta and tce->getEnergyTC(idx) >= fadccut) {
352 energySum += tce->getEnergyTC(idx);
359 double eclEnergySumTCECLCalDigit(
const Particle*,
const std::vector<double>& vars)
361 if (vars.size() != 3) {
362 B2FATAL(
"Need exactly three parameters (minthetaid, maxthetaid, option).");
365 StoreObjPtr<ECLTRGInformation> tce;
366 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
368 int minTheta = int(std::lround(vars[0]));
369 int maxTheta = int(std::lround(vars[1]));
370 int option = int(std::lround(vars[2]));
371 double par = vars[3];
373 if (maxTheta < minTheta) {
374 B2WARNING(
"minTheta i (vars[0]) must be equal or less than maxTheta j (vars[1]).");
375 return std::numeric_limits<double>::quiet_NaN();
377 if (option < 0 or option > 2) {
378 B2WARNING(
"Third parameters k (vars[2]) must be >=0 and <=2.");
379 return std::numeric_limits<double>::quiet_NaN();
382 double energySum = 0.;
383 for (
unsigned idx = 1; idx <= 576; idx++) {
384 if (tce->getThetaIdTC(idx) >= minTheta and
385 tce->getThetaIdTC(idx) <= maxTheta) {
388 energySum += tce->getEnergyTCECLCalDigit(idx);
389 }
else if (option == 1 and tce->getEnergyTC(idx)) {
390 energySum += tce->getEnergyTCECLCalDigit(idx);
391 }
else if (option == 2 and tce->getEnergyTCECLCalDigit(idx) > par) {
392 energySum += tce->getEnergyTCECLCalDigit(idx);
400 double eclEnergySumTCECLCalDigitInECLCluster(
const Particle*)
402 StoreObjPtr<ECLTRGInformation> tce;
403 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
404 return tce->getSumEnergyTCECLCalDigitInECLCluster();
407 double eclEnergySumECLCalDigitInECLCluster(
const Particle*)
409 StoreObjPtr<ECLTRGInformation> tce;
410 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
411 return tce->getSumEnergyECLCalDigitInECLCluster();
414 double eclEnergySumTCECLCalDigitInECLClusterThreshold(
const Particle*)
416 StoreObjPtr<ECLTRGInformation> tce;
417 if (!tce)
return std::numeric_limits<double>::quiet_NaN();
418 return tce->getClusterEnergyThreshold();
422 VARIABLE_GROUP(
"ECL calibration");
424 REGISTER_VARIABLE(
"eclEnergy3FWDBarrel", eclEnergy3FWDBarrel, R
"DOC(
425[Calibration] Returns energy sum of three crystals in forward barrel.
428 REGISTER_VARIABLE("eclEnergy3FWDEndcap", eclEnergy3FWDEndcap, R
"DOC(
429[Calibration] Returns energy sum of three crystals in forward endcap.
432 REGISTER_VARIABLE("eclEnergy3BWDBarrel", eclEnergy3BWDBarrel, R
"DOC(
433[Calibration] Returns energy sum of three crystals in backward barrel.
436 REGISTER_VARIABLE("eclEnergy3BWDEndcap", eclEnergy3BWDEndcap, R
"DOC(
437[Calibration] Returns energy sum of three crystals in backward endcap.
441 VARIABLE_GROUP(
"ECL trigger calibration");
443 REGISTER_VARIABLE(
"clusterNumberOfTCs(i, j, k, l)", eclNumberOfTCsForCluster, R
"DOC(
444[Calibration] Returns the number of TCs for this ECL cluster for a given TC theta ID range
445:math:`(i, j)` and hit window :math:`(k, l)`.
447 REGISTER_VARIABLE("clusterTCFADC(i, j, k, l)", eclTCFADCForCluster, R
"DOC(
448[Calibration] Returns the total FADC sum related to this ECL cluster for a given TC theta ID
449range :math:`(i, j)` and hit window :math:`(k, l)`.
451 REGISTER_VARIABLE("clusterTCIsMaximum", eclTCIsMaximumForCluster, R
"DOC(
452[Calibration] Returns True if cluster is related to maximum TC.
454 REGISTER_VARIABLE("clusterTrigger", eclClusterTrigger, R
"DOC(
455[Calibration] Returns 1.0 if ECL cluster is matched to a trigger cluster (requires to run eclTriggerClusterMatcher
456(which requires TRGECLClusters in the input file)) and 0 otherwise. Returns -1 if the matching code was not run.
459 REGISTER_VARIABLE("eclEnergyTC(i)", getEnergyTC, R
"DOC(
460[Eventbased][Calibration] Returns the energy (in FADC counts) for the :math:`i`-th trigger cell (TC), 1 based (1..576).
462 REGISTER_VARIABLE("eclEnergyTCECLCalDigit(i)", getEnergyTCECLCalDigit, R
"DOC(
463[Eventbased][Calibration] Returns the energy (in GeV) for the :math:`i`-th trigger cell (TC)
464based on ECLCalDigits, 1 based (1..576).
466 REGISTER_VARIABLE("eclTimingTC(i)", getTimingTC, R
"DOC(
467[Eventbased][Calibration] Returns the time (in ns) for the :math:`i`-th trigger cell (TC), 1 based (1..576).
469 REGISTER_VARIABLE("eclHitWindowTC(i)", eclHitWindowTC, R
"DOC(
470[Eventbased][Calibration] Returns the hit window for the :math:`i`-th trigger cell (TC), 1 based (1..576).
472 REGISTER_VARIABLE("eclEventTimingTC", getEvtTimingTC, R
"DOC(
473[Eventbased][Calibration] Returns the ECL TC event time (in ns).
475 REGISTER_VARIABLE("eclMaximumTCId", getMaximumTCId, R
"DOC(
476[Eventbased][Calibration] Returns the TC ID with maximum FADC value.
479 REGISTER_VARIABLE("eclTimingTCECLCalDigit(i)", getTimingTCECLCalDigit, R
"DOC(
480[Eventbased][Calibration] Returns the time (in ns) for the :math:`i`-th trigger cell (TC) based
481on ECLCalDigits, 1 based (1..576)
484 REGISTER_VARIABLE("eclNumberOfTCs(i, j, k)", getNumberOfTCs, R
"DOC(
485[Eventbased][Calibration] Returns the number of TCs above threshold (i=FADC counts) for this event
486for a given theta range (j-k)
488 REGISTER_VARIABLE("eclEnergySumTC(i, j)", eclEnergySumTC, R
"DOC(
489[Eventbased][Calibration] Returns energy sum (in FADC counts) of all TC cells between two
490theta ids i<=thetaid<=j, 1 based (1..17)
492 REGISTER_VARIABLE("eclEnergySumTCECLCalDigit(i, j, k, l)", eclEnergySumTCECLCalDigit, R
"DOC(
493[Eventbased][Calibration] Returns energy sum (in GeV) of all TC cells between two theta ids i<=thetaid<=j,
4941 based (1..17). k is the sum option: 0 (all), 1 (those with actual TC entries), 2 (sum of ECLCalDigit energy
495in this TC above threshold). l is the threshold parameter for the option k 2.
497 REGISTER_VARIABLE("eclEnergySumTCECLCalDigitInECLCluster", eclEnergySumTCECLCalDigitInECLCluster, R
"DOC(
498[Eventbased][Calibration] Returns energy sum (in GeV) of all ECLCalDigits if TC is above threshold
499that are part of an ECLCluster above eclEnergySumTCECLCalDigitInECLClusterThreshold within TC thetaid 2-15.
501 REGISTER_VARIABLE("eclEnergySumECLCalDigitInECLCluster", eclEnergySumECLCalDigitInECLCluster, R
"DOC(
502[Eventbased][Calibration] Returns energy sum (in GeV) of all ECLCalDigits that are part of an ECL cluster
503above eclEnergySumTCECLCalDigitInECLClusterThreshold within TC thetaid 2-15.
505 REGISTER_VARIABLE("eclEnergySumTCECLCalDigitInECLClusterThreshold", eclEnergySumTCECLCalDigitInECLClusterThreshold, R
"DOC(
506[Eventbased][Calibration] Returns threshold used to calculate eclEnergySumTCECLCalDigitInECLCluster.
Abstract base class for different kinds of events.