Skip to content

Commit 06081e0

Browse files
authored
[ALICE3] TF3: fetch pixel maps inside digitizer workflow (#16002)
1 parent 6409c6a commit 06081e0

4 files changed

Lines changed: 73 additions & 88 deletions

File tree

‎Detectors/Upgrades/ALICE3/IOTOF/simulation/include/IOTOFSimulation/DPLDigitizerParam.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ struct DPLDigitizerParam : public o2::conf::ConfigurableParamHelper<DPLDigitizer
3131
float tdcBin = 0.010f; ///< TDC time bin (10 ps default)
3232
float efficiency = 0.98f; ///< detection efficiency
3333

34-
// Optional map paths. Prefix with "ccdb://" to fetch from CCDB, otherwise the path is opened with TFile::Open
35-
// (local file, alien://, root://, ...). An empty path disables the map.
36-
std::string efficiencyMapPath{}; ///< optional efficiency map path.
37-
///< e.g. ccdb://Users/g/glucia/tmp/ALICE3/IOTOF/pixelEfficiency
38-
///< or alien:///alice/cern.ch/user/g/glucia/ALICE3/IOTOF/pixelEfficiency/PixelEfficiencyMap_TH2.root
39-
std::string resolutionMapPath{}; ///< optional resolution map path.
40-
///< e.g. alien:///alice/cern.ch/user/g/glucia/ALICE3/IOTOF/pixelEfficiency/PixelResolutionMap_TH2.root
41-
std::string timeOfArrivalMapPath{}; ///< optional time of arrival map path.
42-
4334
int chargeThreshold = 100; ///< charge threshold in Nelectrons
4435
int minChargeToAccount = 7; ///< minimum charge contribution to account
4536
int nSimSteps = 10; ///< number of steps in response simulation

‎Detectors/Upgrades/ALICE3/IOTOF/simulation/include/IOTOFSimulation/Digitizer.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class Digitizer : public TObject
7575
// Provide the common iotof::GeometryTGeo to access matrices and segmentation
7676
void setGeometry(const o2::iotof::GeometryTGeo* gm) { mGeometry = gm; }
7777

78+
void loadEfficiencyMap(TH2D* map) { mEfficiencyMap = map; }
79+
void loadResolutionMap(TH2D* map) { mResolutionMap = map; }
80+
void loadTimeOfArrivalMap(TH2D* map) { mTimeOfArrivalMap = map; }
81+
82+
void prepareScaledResolutionMap();
83+
7884
private:
7985
/// Process a single hit
8086
void processHit(const o2::itsmft::Hit& hit, int evID, int srcID);
@@ -91,12 +97,6 @@ class Digitizer : public TObject
9197
/// Convert energy loss to charge
9298
int energyToCharge(float energyLoss) const;
9399

94-
/// Load a map from CCDB (path prefixed with "ccdb://") or from a ROOT file (any other path)
95-
/// \param mapName Name of the histogram inside the ROOT file (ignored for CCDB)
96-
void loadMap(TH2D*& map, const std::string& path, const char* mapName);
97-
98-
void prepareScaledResolutionMap();
99-
100100
/// Check if the hit passes efficiency cut
101101
/// \param x Detector local coordinate x in cm with respect to the center of the sensitive volume.
102102
/// \param z Detector local coordinate z in cm with respect to the center of the sensitive volume.

‎Detectors/Upgrades/ALICE3/IOTOF/simulation/src/Digitizer.cxx‎

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,6 @@ void Digitizer::init()
7373
LOG(info) << " Charge threshold: " << digitizerParams.chargeThreshold << " electrons";
7474
LOG(info) << " Continuous mode: " << (mContinuous ? "ON" : "OFF");
7575

76-
loadMap(mEfficiencyMap, digitizerParams.efficiencyMapPath, "hEfficiencyMap");
77-
if (!mEfficiencyMap) {
78-
LOG(info) << "No efficiency map loaded, using uniform efficiency: " << digitizerParams.efficiency * 100 << " %";
79-
}
80-
81-
loadMap(mResolutionMap, digitizerParams.resolutionMapPath, "hSigmaPixel");
82-
prepareScaledResolutionMap();
83-
if (!mResolutionMap) {
84-
LOG(info) << "No resolution map loaded, using uniform time resolution: " << digitizerParams.timeResolution * 1e3 << " ps";
85-
}
86-
87-
loadMap(mTimeOfArrivalMap, digitizerParams.timeOfArrivalMapPath, "toa_pixel");
88-
if (!mTimeOfArrivalMap) {
89-
LOG(info) << "No time of arrival map loaded";
90-
}
91-
9276
sSegmentation = o2::iotof::Segmentation::Instance();
9377
}
9478

@@ -374,61 +358,6 @@ int Digitizer::energyToCharge(float energyLoss) const
374358
}
375359

376360
//_______________________________________________________________________
377-
378-
void Digitizer::loadMap(TH2D*& map, const std::string& path, const char* mapName)
379-
{
380-
// Load a map either from CCDB (path prefixed with "ccdb://") or from a ROOT file
381-
// (anything TFile::Open understands: local path, alien://, root://, http://, ...)
382-
static constexpr std::string_view ccdbPrefix = "ccdb://";
383-
384-
if (path.empty()) {
385-
return;
386-
}
387-
388-
TH2D* rawMap = nullptr;
389-
TFile* file = nullptr;
390-
391-
if (path.rfind(ccdbPrefix, 0) == 0) {
392-
const std::string ccdbPath = path.substr(ccdbPrefix.size());
393-
LOG(info) << "Loading " << mapName << " from CCDB: " << ccdbPath;
394-
rawMap = o2::ccdb::BasicCCDBManager::instance().get<TH2D>(ccdbPath); // owned by the CCDB manager
395-
if (!rawMap) {
396-
LOG(error) << "Failed to retrieve " << mapName << " from CCDB path: " << ccdbPath;
397-
return;
398-
}
399-
} else {
400-
LOG(info) << "Loading " << mapName << " from file: " << path;
401-
file = TFile::Open(path.c_str());
402-
if (!file || !file->IsOpen()) {
403-
LOG(error) << "Failed to open file: " << path;
404-
delete file;
405-
return;
406-
}
407-
rawMap = dynamic_cast<TH2D*>(file->Get(mapName));
408-
if (!rawMap) {
409-
LOG(error) << "Failed to retrieve " << mapName << " from file: " << path;
410-
LOG(error) << "Available keys in the file:";
411-
TIter next(file->GetListOfKeys());
412-
TKey* key;
413-
while ((key = dynamic_cast<TKey*>(next()))) {
414-
LOG(error) << " " << key->GetName() << " (" << key->GetClassName() << ")";
415-
}
416-
file->Close();
417-
delete file;
418-
return;
419-
}
420-
}
421-
422-
map = dynamic_cast<TH2D*>(rawMap->Clone());
423-
map->SetDirectory(nullptr); // Detach from file to avoid deletion when file is closed
424-
LOG(info) << "Loaded " << mapName << " (" << map->GetNbinsX() << " x " << map->GetNbinsY() << " bins)";
425-
426-
if (file) {
427-
file->Close();
428-
delete file;
429-
}
430-
}
431-
432361
void Digitizer::prepareScaledResolutionMap()
433362
{
434363
if (!mResolutionMap) {

‎Steer/DigitizerWorkflow/src/IOTOFDigitizerSpec.cxx‎

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
5454
void initDigitizerTask(framework::InitContext& ic) override
5555
{
5656
mDisableQED = ic.options().get<bool>("disable-qed");
57+
mEnableResponseFiles = ic.options().get<bool>("enable-response-files");
58+
mLocalEfficiencyFile = ic.options().get<std::string>("local-efficiency-file");
59+
mLocalTimeResoFile = ic.options().get<std::string>("local-timereso-file");
60+
mLocalToAFile = ic.options().get<std::string>("local-toa-file");
5761

5862
auto geom = GeometryTGeo::Instance();
5963
geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G)); // make sure L2G matrices are loaded
@@ -69,6 +73,13 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
6973
if (mFinished) {
7074
return;
7175
}
76+
77+
if (mEnableResponseFiles) {
78+
pc.inputs().get<TH2D*>("madpixeff");
79+
pc.inputs().get<TH2D*>("madpixreso");
80+
pc.inputs().get<TH2D*>("madpixtoa");
81+
}
82+
7283
mFirstOrbitTF = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
7384
const o2::InteractionRecord firstIR(0, mFirstOrbitTF);
7485

@@ -163,10 +174,59 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
163174
mFinished = true;
164175
}
165176

177+
void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
178+
{
179+
if (matcher == ConcreteDataMatcher(mOrigin, "MADPIXEFF", 0)) {
180+
if (mLocalEfficiencyFile.empty()) {
181+
LOG(info) << "Using CCDB/MADPIX efficiency file";
182+
mDigitizer.loadEfficiencyMap((TH2D*)obj);
183+
} else {
184+
LOG(info) << "Response function will be loaded from local file: " << mLocalEfficiencyFile;
185+
std::unique_ptr<TFile> file(TFile::Open(mLocalEfficiencyFile.data(), "READ"));
186+
if (!file) {
187+
LOG(fatal) << "Cannot open response file " << mLocalEfficiencyFile.data();
188+
}
189+
mDigitizer.loadEfficiencyMap((TH2D*)file->Get("efficiency_pixel"));
190+
}
191+
return;
192+
}
193+
if (matcher == ConcreteDataMatcher(mOrigin, "MADPIXRESO", 0)) {
194+
if (mLocalTimeResoFile.empty()) {
195+
LOG(info) << "Using CCDB/MADPIX time resolution file";
196+
mDigitizer.loadResolutionMap((TH2D*)obj);
197+
} else {
198+
LOG(info) << "Response function will be loaded from local file: " << mLocalTimeResoFile;
199+
std::unique_ptr<TFile> file(TFile::Open(mLocalTimeResoFile.data(), "READ"));
200+
if (!file) {
201+
LOG(fatal) << "Cannot open response file " << mLocalTimeResoFile.data();
202+
}
203+
mDigitizer.loadResolutionMap((TH2D*)file->Get("sigma_pixel"));
204+
}
205+
return;
206+
}
207+
if (matcher == ConcreteDataMatcher(mOrigin, "MADPIXTOA", 0)) {
208+
if (mLocalToAFile.empty()) {
209+
LOG(info) << "Using CCDB/MADPIX time-of-arrival file";
210+
mDigitizer.loadTimeOfArrivalMap((TH2D*)obj);
211+
} else {
212+
LOG(info) << "Response function will be loaded from local file: " << mLocalToAFile;
213+
std::unique_ptr<TFile> file(TFile::Open(mLocalToAFile.data(), "READ"));
214+
if (!file) {
215+
LOG(fatal) << "Cannot open response file " << mLocalToAFile.data();
216+
}
217+
mDigitizer.loadTimeOfArrivalMap((TH2D*)file->Get("toa_pixel"));
218+
}
219+
}
220+
}
221+
166222
private:
167223
bool mDisableQED = false;
224+
bool mEnableResponseFiles = false;
168225
bool mWithMCTruth{true};
169226
bool mFinished{false};
227+
std::string mLocalEfficiencyFile{""};
228+
std::string mLocalTimeResoFile{""};
229+
std::string mLocalToAFile{""};
170230
unsigned long mFirstOrbitTF = 0x0;
171231
const o2::detectors::DetID mID{o2::detectors::DetID::TF3};
172232
const o2::header::DataOrigin mOrigin{o2::header::gDataOriginTF3};
@@ -197,7 +257,9 @@ o2::framework::DataProcessorSpec getIOTOFDigitizerSpec(int channel, bool mctruth
197257
{
198258
std::vector<o2::framework::InputSpec> inputs;
199259
inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<o2::header::DataHeader::SubSpecificationType>(channel), o2::framework::Lifetime::Timeframe);
200-
inputs.emplace_back("IOTOF_aptsresp", "TF3", "APTSRESP", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("IT3/Calib/APTSResponse"));
260+
inputs.emplace_back("madpixeff", "TF3", "MADPIXEFF", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelEfficiency"));
261+
inputs.emplace_back("madpixreso", "TF3", "MADPIXRESO", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelResolution"));
262+
inputs.emplace_back("madpixtoa", "TF3", "MADPIXTOA", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelTimeOfArrival"));
201263

202264
const std::string detStr = o2::detectors::DetID::getName(o2::detectors::DetID::TF3);
203265
return o2::framework::DataProcessorSpec{detStr + "Digitizer",
@@ -206,7 +268,10 @@ o2::framework::DataProcessorSpec getIOTOFDigitizerSpec(int channel, bool mctruth
206268
o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<IOTOFDPLDigitizerTask>(mctruth)},
207269
o2::framework::Options{
208270
{"disable-qed", o2::framework::VariantType::Bool, false, {"disable QED handling"}},
209-
{"local-response-file", o2::framework::VariantType::String, "", {"use response file saved locally at this path/filename"}}}};
271+
{"enable-response-files", o2::framework::VariantType::Bool, false, {"enable in-pixel response maps from data"}},
272+
{"local-efficiency-file", o2::framework::VariantType::String, "", {"use efficiency map saved locally at this path/filename"}},
273+
{"local-timereso-file", o2::framework::VariantType::String, "", {"use time resolution map saved locally at this path/filename"}},
274+
{"local-toa-file", o2::framework::VariantType::String, "", {"use ToA map saved locally at this path/filename"}}}};
210275
}
211276

212277
} // namespace o2::iotof

0 commit comments

Comments
 (0)