10#include <ecl/modules/eclDigitCalibration/ECLDigitCalibratorModule.h>
13#include <ecl/dataobjects/ECLCalDigit.h>
14#include <ecl/dataobjects/ECLDigit.h>
15#include <ecl/dataobjects/ECLDsp.h>
16#include <ecl/dataobjects/ECLPureCsIInfo.h>
17#include <ecl/dbobjects/ECLCrystalCalib.h>
18#include <ecl/digitization/EclConfiguration.h>
19#include <ecl/utility/utilityFunctions.h>
20#include <ecl/dataobjects/ECLElementNumbers.h>
23#include <framework/core/Environment.h>
24#include <framework/gearbox/Unit.h>
25#include <framework/geometry/B2Vector3.h>
26#include <framework/logging/Logger.h>
27#include <framework/utilities/FileSystem.h>
28#include <mdst/dataobjects/EventLevelClusteringInfo.h>
29#include <framework/datastore/RelationArray.h>
36#include <unordered_map>
64 setDescription(
"Applies digit energy, time and time-resolution calibration to each ECL digit. Counts number of out-of-time background digits to determine the event-by-event background level.");
105 std::vector<float>& constantsUnc)
107 constants = cal->getCalibVector();
108 constantsUnc = cal->getCalibUncVector();
137 B2FATAL(
"Could not find m_th1fBackground");
160 B2ERROR(
"ECLDigitCalibratorModule::beginRun - Couldn't find m_calibrationCrystalElectronics for current run!");
167 B2ERROR(
"ECLDigitCalibratorModule::beginRun - Couldn't find m_calibrationCrystalEnergy for current run!");
175 B2ERROR(
"ECLDigitCalibratorModule::beginRun - Couldn't find m_calibrationCrystalElectronicsTime for current run!");
182 B2ERROR(
"ECLDigitCalibratorModule::beginRun - Couldn't find m_calibrationCrystalTimeOffset for current run!");
189 B2ERROR(
"ECLDigitCalibratorModule::beginRun - Couldn't find m_calibrationCrateTimeOffset for current run!");
196 B2ERROR(
"ECLDigitCalibratorModule::beginRun - Couldn't find m_calibrationCrystalFlightTime for current run!");
209 std::array < const ECLDsp*, ECLElementNumbers::c_NCrystals + 1 > dspFromCellId{};
211 int cellId = eclDsp.getCellId();
212 dspFromCellId[cellId] = &eclDsp;
216 for (
int index = 0; index <
m_eclDigits.getEntries(); ++index) {
219 bool is_pure_csi = 0;
225 calDigitsToDigits.
add(index, index);
228 const int cellid = aECLDigit.
getCellId();
232 B2FATAL(
"ECLDigitCalibrationModule::event():" << cellid <<
" out of range!");
236 const int amplitude = aECLDigit.
getAmp();
237 double calibratedEnergy = 0;
251 if (calibratedEnergy < 0.0)
252 calibratedEnergy = 0.0;
259 aECLCalDigit->addStatus(ECLCalDigit::c_IsFailedFit);
275 B2DEBUG(35,
"cellid = " << cellid <<
", m_isMC = " <<
m_isMC);
280 B2DEBUG(35,
"cellid = " << cellid <<
", amplitude = " << amplitude <<
", corrected amplitude = " << amplitude*
282 energyTimeShift <<
" ns");
283 calibratedTime -= energyTimeShift;
287 B2DEBUG(35,
"cellid = " << cellid <<
", amplitude = " << amplitude <<
", calibrated energy = " << calibratedEnergy);
288 B2DEBUG(35,
"cellid = " << cellid <<
", time = " << time <<
", calibratedTime = " << calibratedTime);
291 const ECLDsp* aECLDsp = dspFromCellId[cellid];
296 aECLCalDigit->setTwoComponentTotalEnergy(-1);
297 aECLCalDigit->setTwoComponentHadronEnergy(-1);
298 aECLCalDigit->setTwoComponentDiodeEnergy(-1);
300 const int online_quality = aECLDigit.
getQuality();
301 if (online_quality == 1) {
302 aECLCalDigit->addStatus(ECLCalDigit::c_OnlineFitQuality1);
303 }
else if (online_quality == 2) {
304 aECLCalDigit->addStatus(ECLCalDigit::c_OnlineFitQuality2);
305 }
else if (online_quality == 3) {
306 aECLCalDigit->addStatus(ECLCalDigit::c_OnlineFitQuality3);
307 }
else if (online_quality == 0) {
308 aECLCalDigit->addStatus(ECLCalDigit::c_OnlineFitQuality0);
326 aECLCalDigit->setTwoComponentTotalEnergy(calibratedTwoComponentTotalEnergy);
327 aECLCalDigit->setTwoComponentHadronEnergy(calibratedTwoComponentHadronEnergy);
328 aECLCalDigit->setTwoComponentDiodeEnergy(calibratedTwoComponentDiodeEnergy);
329 aECLCalDigit->setTwoComponentChi2(twoComponentChi2);
334 aECLCalDigit->setTwoComponentFitType(twoComponentFitType);
339 aECLCalDigit->setCellId(cellid);
341 aECLCalDigit->setEnergy(calibratedEnergy);
342 aECLCalDigit->addStatus(ECLCalDigit::c_IsEnergyCalibrated);
344 aECLCalDigit->setTime(calibratedTime);
345 aECLCalDigit->addStatus(ECLCalDigit::c_IsTimeCalibrated);
355 const double t99 =
getT99(aECLCalDigit.getCellId(),
356 aECLCalDigit.getEnergy(),
357 aECLCalDigit.hasStatus(ECLCalDigit::c_IsFailedFit),
359 aECLCalDigit.setTimeResolution(t99);
362 aECLCalDigit.addStatus(ECLCalDigit::c_IsFailedTimeResolution);
365 aECLCalDigit.addStatus(ECLCalDigit::c_IsTimeResolutionCalibrated);
400 double t99 = p1 * einv;
406 B2DEBUG(35,
"ECLDigitCalibratorModule::getCalibratedTimeResolution: dose = " <<
m_th1fBackground->GetBinContent(
408 <<
", bglevel = " << bglevel <<
", cellid = " << cellid <<
", t99 = " << t99 <<
", energy = " << energy /
Belle2::Unit::MeV);
417 using regionCounter = std::unordered_map<ECL::DetectorRegion, uint>;
419 regionCounter outOfTimeCount{{ECL::DetectorRegion::FWD, 0},
420 {ECL::DetectorRegion::BRL, 0},
421 {ECL::DetectorRegion::BWD, 0}};
429 const int cellId = aECLCalDigit.getCellId();
430 const ECL::DetectorRegion detectorRegion =
433 ECL::DetectorRegion::FWD);
436 ++outOfTimeCount.at(detectorRegion);
449 B2DEBUG(35,
"ECLDigitCalibratorModule::determineBackgroundECL found " << outOfTimeCount.at(ECL::DetectorRegion::FWD) <<
", " <<
450 outOfTimeCount.at(ECL::DetectorRegion::BRL) <<
", " << outOfTimeCount.at(ECL::DetectorRegion::BWD) <<
451 " out of time digits in FWD, BRL, BWD");
Class for accessing objects in the database.
double m_pureCsITimeCalib
conversion factor from eclPureCsIDigitizer to ns.
const double c_pol2Var2
2-order fit for p1.
virtual const char * eventLevelClusteringInfoName() const
Name of the EventLevelClusteringInfo.
StoreArray< ECLDsp > m_eclDsps
storearray ECLDsp
~ECLDigitCalibratorModule()
Destructor.
virtual const char * eclPureCsIInfoArrayName() const
Name of the ECL pure CsI Information.
DBObjPtr< ECLCrystalCalib > m_calibrationCrateTimeOffset
single crate time calibration offset (per crystal)
double m_pureCsITimeOffset
ad-hoc offset correction for pureCsI timing/
TH1F * m_th1fBackground
Background histogram.
DBObjPtr< ECLCrystalCalib > m_calibrationCrystalElectronics
single crystal electronics calibration
const double c_minT99
The minimum t99.
virtual void initialize() override
Initialize variables.
std::vector< float > v_calibrationCrystalElectronicsUnc
single crystal electronics calibration as vector uncertainty
std::string m_fileBackgroundName
Background filename.
std::vector< float > v_calibrationCrateTimeOffsetUnc
single crate time calibration offset as vector uncertainty (per crystal)
std::vector< float > v_calibrationCrystalElectronicsTimeUnc
single crystal time calibration offset electronics as vector uncertainty
virtual void event() override
event per event.
DBObjPtr< ECLCrystalCalib > m_calibrationCrystalEnergy
single crystal energy calibration
bool m_isMC
Flag to keep track if we run on MC or not.
virtual void endRun() override
end run.
double getT99(const int cellid, const double energy, const bool fitfailed, const int bgcount) const
t99%.
virtual void terminate() override
terminate.
const double c_pol2Var1
2-order fit for p1 Var1 + Var2*bg + Var3*bg^2.
StoreArray< ECLDigit > m_eclDigits
storearray ECLDigit
virtual const char * eclDspArrayName() const
Name of the ECLDsp.
const double c_timeResolutionForFitFailed
Time resolution for failed fits".
std::vector< float > v_calibrationCrystalElectronicsTime
single crystal time calibration offset electronics as vector
std::vector< float > v_calibrationCrystalFlightTime
single crystal time calibration TOF as vector
void callbackCalibration(DBObjPtr< ECLCrystalCalib > &cal, std::vector< float > &constants, std::vector< float > &constantsUnc)
reads calibration constants
std::unique_ptr< Belle2::ECL::ECLTimingUtilities > ECLTimeUtil
ECL timing tools.
void initializeCalibration()
reads calibration constants, performs checks, put them into a vector
std::vector< float > v_calibrationCrystalEnergy
single crystal energy calibration as vector
std::vector< float > v_calibrationCrystalEnergyUnc
single crystal energy calibration as vector uncertainty
virtual void beginRun() override
begin run.
const double c_pol2Var3
2-order fit for p1.
std::vector< float > v_calibrationCrateTimeOffset
single crate time calibration offset as vector (per crystal)
const double c_timeForFitFailed
Time for failed fits".
int determineBackgroundECL()
count out of time digits to determine baclground levels
double m_timeInverseSlope
Time calibration inverse slope "a".
DBObjPtr< ECLCrystalCalib > m_calibrationCrystalTimeOffset
single crystal time calibration offset
double m_backgroundTimingCut
Timing window for background level counting.
std::vector< float > v_calibrationCrystalElectronics
single crystal electronics calibration as vector
DBObjPtr< ECLCrystalCalib > m_calibrationCrystalElectronicsTime
single crystal time calibration offset electronics
double m_pureCsIEnergyCalib
conversion factor from ADC counts to GeV.
const int c_nCrystals
Number of ECL crystals.
std::vector< float > v_calibrationCrystalTimeOffset
single crystal time calibration offset as vector
virtual const char * eclDigitArrayName() const
Name of the ECLDigit.
DBObjPtr< ECLCrystalCalib > m_calibrationCrystalFlightTime
single crystal time calibration TOF
double m_averageBG
Average dose per crystal calculated from m_th1dBackground.
double m_pol2Max
Maximum of p1 2-order fit to limit values.
std::vector< float > v_calibrationCrystalFlightTimeUnc
single crystal time calibration TOF as vector uncertainty
virtual const char * eclCalDigitArrayName() const
Name of the ECLCalDigit.
ECLDigitCalibratorModule()
Constructor.
double m_backgroundEnergyCut
Energy cut for background level counting.
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
event level clustering info
StoreArray< ECLCalDigit > m_eclCalDigits
storearray ECLCalDigit
TFile * m_fileBackground
Background file.
const int c_nominalBG
Number of out of time digits at BGx1.0.
std::vector< float > v_calibrationCrystalTimeOffsetUnc
single crystal time calibration offset as vector uncertainty
bool m_simulatePure
Flag to set pure CsI simulation option.
Class to store ECL digitized hits (output of ECLDigi) relation to ECLHit filled in ecl/modules/eclDig...
int getAmp() const
Get Fitting Amplitude.
int getQuality() const
Get Fitting Quality.
int getCellId() const
Get Cell ID.
int getTimeFit() const
Get Fitting Time.
Class to store ECL ShaperDSP waveform ADC data.
double getTwoComponentHadronAmp() const
get two comp hadron amp
double getTwoComponentSavedChi2(TwoComponentFitType FitTypeIn) const
get two comp chi2 for a fit type see enum TwoComponentFitType in ECLDsp.h for description of fit type...
TwoComponentFitType
Offline two component fit type.
@ photonHadronBackgroundPhoton
photon + hadron template + pile-up photon fit
@ photonDiodeCrossing
photon + diode template fit
@ photonHadron
photon + hadron template fit
double getTwoComponentTotalAmp() const
get two comp total amp
double getTwoComponentChi2() const
get two comp chi2
TwoComponentFitType getTwoComponentFitType() const
get two comp fit type
double getTwoComponentDiodeAmp() const
get two comp diode amp
void setTwoComponentChi2(double input)
Set two comp chi2.
Class to store ECL crystal type relation to ECLDigit for the simulation pure CsI upgrade option fille...
static double getRF()
See m_rf.
bool isMC() const
Do we have generated, not real data?
static Environment & Instance()
Static method to get a reference to the Environment instance.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Low-level class to create/modify relations between StoreArrays.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
static const double MeV
[megaelectronvolt]
static const double ns
Standard of [time].
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
bool isBarrel(int cellId)
Check whether the crystal is in barrel ECL.
bool isBackward(int cellId)
Check whether the crystal is in backward ECL.
Abstract base class for different kinds of events.