Skip to content

Commit b399aae

Browse files
committed
move initialization of maps to digitizer workflow
(TODO: load also reso + toa map + scale resolutio nmap to center)
1 parent 8f4271a commit b399aae

4 files changed

Lines changed: 56 additions & 82 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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ 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(const TH2D* map);
79+
80+
void loadResolutionMap(const TH2D* map);
81+
82+
void loadTimeOfArrivalMap(const TH2D* map);
83+
84+
void prepareScaledResolutionMap();
85+
7886
private:
7987
/// Process a single hit
8088
void processHit(const o2::itsmft::Hit& hit, int evID, int srcID);
@@ -91,12 +99,6 @@ class Digitizer : public TObject
9199
/// Convert energy loss to charge
92100
int energyToCharge(float energyLoss) const;
93101

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-
100102
/// Check if the hit passes efficiency cut
101103
/// \param x Detector local coordinate x in cm with respect to the center of the sensitive volume.
102104
/// \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: 13 additions & 65 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

@@ -375,58 +359,22 @@ int Digitizer::energyToCharge(float energyLoss) const
375359

376360
//_______________________________________________________________________
377361

378-
void Digitizer::loadMap(TH2D*& map, const std::string& path, const char* mapName)
362+
void Digitizer::loadEfficiencyMap(const TH2D* map)
379363
{
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-
}
364+
mEfficiencyMap = dynamic_cast<TH2D*>(map->Clone());
365+
mEfficiencyMap->SetDirectory(nullptr);
366+
}
421367

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)";
368+
void Digitizer::loadResolutionMap(const TH2D* map)
369+
{
370+
mResolutionMap = dynamic_cast<TH2D*>(map->Clone());
371+
mResolutionMap->SetDirectory(nullptr);
372+
}
425373

426-
if (file) {
427-
file->Close();
428-
delete file;
429-
}
374+
void Digitizer::loadTimeOfArrivalMap(const TH2D* map)
375+
{
376+
mTimeOfArrivalMap = dynamic_cast<TH2D*>(map->Clone());
377+
mTimeOfArrivalMap->SetDirectory(nullptr);
430378
}
431379

432380
void Digitizer::prepareScaledResolutionMap()

‎Steer/DigitizerWorkflow/src/IOTOFDigitizerSpec.cxx‎

Lines changed: 35 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
@@ -163,10 +167,34 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
163167
mFinished = true;
164168
}
165169

170+
void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
171+
{
172+
if (!mEnableResponseFiles) {
173+
return;
174+
}
175+
if (matcher == ConcreteDataMatcher(mOrigin, "MADPIXEFF", 0)) {
176+
if (mLocalEfficiencyFile.empty()) {
177+
LOG(info) << "Using CCDB/MADPIX efficiency file";
178+
mDigitizer.loadEfficiencyMap((const TH2D*)obj);
179+
} else {
180+
LOG(info) << "Response function will be loaded from local file: " << mLocalEfficiencyFile;
181+
std::unique_ptr<TFile> file(TFile::Open(mLocalEfficiencyFile.data(), "READ"));
182+
if (!file) {
183+
LOG(fatal) << "Cannot open response file " << mLocalEfficiencyFile.data();
184+
}
185+
mDigitizer.loadEfficiencyMap((const TH2D*)file->Get("hEfficiencyMap"));
186+
}
187+
}
188+
}
189+
166190
private:
167191
bool mDisableQED = false;
192+
bool mEnableResponseFiles = false;
168193
bool mWithMCTruth{true};
169194
bool mFinished{false};
195+
std::string mLocalEfficiencyFile{""};
196+
std::string mLocalTimeResoFile{""};
197+
std::string mLocalToAFile{""};
170198
unsigned long mFirstOrbitTF = 0x0;
171199
const o2::detectors::DetID mID{o2::detectors::DetID::TF3};
172200
const o2::header::DataOrigin mOrigin{o2::header::gDataOriginTF3};
@@ -197,7 +225,9 @@ o2::framework::DataProcessorSpec getIOTOFDigitizerSpec(int channel, bool mctruth
197225
{
198226
std::vector<o2::framework::InputSpec> inputs;
199227
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"));
228+
inputs.emplace_back("madpixeff", "TF3", "MADPIXEFF", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelEfficiency"));
229+
inputs.emplace_back("madpixreso", "TF3", "MADPIXRESO", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelResolution"));
230+
inputs.emplace_back("madpixtoa", "TF3", "MADPIXTOA", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelTimeOfArrival"));
201231

202232
const std::string detStr = o2::detectors::DetID::getName(o2::detectors::DetID::TF3);
203233
return o2::framework::DataProcessorSpec{detStr + "Digitizer",
@@ -206,7 +236,10 @@ o2::framework::DataProcessorSpec getIOTOFDigitizerSpec(int channel, bool mctruth
206236
o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<IOTOFDPLDigitizerTask>(mctruth)},
207237
o2::framework::Options{
208238
{"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"}}}};
239+
{"enable-response-files", o2::framework::VariantType::Bool, false, {"enable in-pixel response maps from data"}},
240+
{"local-efficiency-file", o2::framework::VariantType::String, "", {"use efficiency map saved locally at this path/filename"}},
241+
{"local-timereso-file", o2::framework::VariantType::String, "", {"use time resolution map saved locally at this path/filename"}},
242+
{"local-toa-file", o2::framework::VariantType::String, "", {"use ToA map saved locally at this path/filename"}}}};
210243
}
211244

212245
} // namespace o2::iotof

0 commit comments

Comments
 (0)