Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ struct DPLDigitizerParam : public o2::conf::ConfigurableParamHelper<DPLDigitizer
float tdcBin = 0.010f; ///< TDC time bin (10 ps default)
float efficiency = 0.98f; ///< detection efficiency

// Optional map paths. Prefix with "ccdb://" to fetch from CCDB, otherwise the path is opened with TFile::Open
// (local file, alien://, root://, ...). An empty path disables the map.
std::string efficiencyMapPath{}; ///< optional efficiency map path.
///< e.g. ccdb://Users/g/glucia/tmp/ALICE3/IOTOF/pixelEfficiency
///< or alien:///alice/cern.ch/user/g/glucia/ALICE3/IOTOF/pixelEfficiency/PixelEfficiencyMap_TH2.root
std::string resolutionMapPath{}; ///< optional resolution map path.
///< e.g. alien:///alice/cern.ch/user/g/glucia/ALICE3/IOTOF/pixelEfficiency/PixelResolutionMap_TH2.root
std::string timeOfArrivalMapPath{}; ///< optional time of arrival map path.

int chargeThreshold = 100; ///< charge threshold in Nelectrons
int minChargeToAccount = 7; ///< minimum charge contribution to account
int nSimSteps = 10; ///< number of steps in response simulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class Digitizer : public TObject
// Provide the common iotof::GeometryTGeo to access matrices and segmentation
void setGeometry(const o2::iotof::GeometryTGeo* gm) { mGeometry = gm; }

void loadEfficiencyMap(TH2D* map) { mEfficiencyMap = map; }
void loadResolutionMap(TH2D* map) { mResolutionMap = map; }
void loadTimeOfArrivalMap(TH2D* map) { mTimeOfArrivalMap = map; }

void prepareScaledResolutionMap();

private:
/// Process a single hit
void processHit(const o2::itsmft::Hit& hit, int evID, int srcID);
Expand All @@ -91,12 +97,6 @@ class Digitizer : public TObject
/// Convert energy loss to charge
int energyToCharge(float energyLoss) const;

/// Load a map from CCDB (path prefixed with "ccdb://") or from a ROOT file (any other path)
/// \param mapName Name of the histogram inside the ROOT file (ignored for CCDB)
void loadMap(TH2D*& map, const std::string& path, const char* mapName);

void prepareScaledResolutionMap();

/// Check if the hit passes efficiency cut
/// \param x Detector local coordinate x in cm with respect to the center of the sensitive volume.
/// \param z Detector local coordinate z in cm with respect to the center of the sensitive volume.
Expand Down
71 changes: 0 additions & 71 deletions Detectors/Upgrades/ALICE3/IOTOF/simulation/src/Digitizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,6 @@ void Digitizer::init()
LOG(info) << " Charge threshold: " << digitizerParams.chargeThreshold << " electrons";
LOG(info) << " Continuous mode: " << (mContinuous ? "ON" : "OFF");

loadMap(mEfficiencyMap, digitizerParams.efficiencyMapPath, "hEfficiencyMap");
if (!mEfficiencyMap) {
LOG(info) << "No efficiency map loaded, using uniform efficiency: " << digitizerParams.efficiency * 100 << " %";
}

loadMap(mResolutionMap, digitizerParams.resolutionMapPath, "hSigmaPixel");
prepareScaledResolutionMap();
if (!mResolutionMap) {
LOG(info) << "No resolution map loaded, using uniform time resolution: " << digitizerParams.timeResolution * 1e3 << " ps";
}

loadMap(mTimeOfArrivalMap, digitizerParams.timeOfArrivalMapPath, "toa_pixel");
if (!mTimeOfArrivalMap) {
LOG(info) << "No time of arrival map loaded";
}

sSegmentation = o2::iotof::Segmentation::Instance();
}

Expand Down Expand Up @@ -374,61 +358,6 @@ int Digitizer::energyToCharge(float energyLoss) const
}

//_______________________________________________________________________

void Digitizer::loadMap(TH2D*& map, const std::string& path, const char* mapName)
{
// Load a map either from CCDB (path prefixed with "ccdb://") or from a ROOT file
// (anything TFile::Open understands: local path, alien://, root://, http://, ...)
static constexpr std::string_view ccdbPrefix = "ccdb://";

if (path.empty()) {
return;
}

TH2D* rawMap = nullptr;
TFile* file = nullptr;

if (path.rfind(ccdbPrefix, 0) == 0) {
const std::string ccdbPath = path.substr(ccdbPrefix.size());
LOG(info) << "Loading " << mapName << " from CCDB: " << ccdbPath;
rawMap = o2::ccdb::BasicCCDBManager::instance().get<TH2D>(ccdbPath); // owned by the CCDB manager
if (!rawMap) {
LOG(error) << "Failed to retrieve " << mapName << " from CCDB path: " << ccdbPath;
return;
}
} else {
LOG(info) << "Loading " << mapName << " from file: " << path;
file = TFile::Open(path.c_str());
if (!file || !file->IsOpen()) {
LOG(error) << "Failed to open file: " << path;
delete file;
return;
}
rawMap = dynamic_cast<TH2D*>(file->Get(mapName));
if (!rawMap) {
LOG(error) << "Failed to retrieve " << mapName << " from file: " << path;
LOG(error) << "Available keys in the file:";
TIter next(file->GetListOfKeys());
TKey* key;
while ((key = dynamic_cast<TKey*>(next()))) {
LOG(error) << " " << key->GetName() << " (" << key->GetClassName() << ")";
}
file->Close();
delete file;
return;
}
}

map = dynamic_cast<TH2D*>(rawMap->Clone());
map->SetDirectory(nullptr); // Detach from file to avoid deletion when file is closed
LOG(info) << "Loaded " << mapName << " (" << map->GetNbinsX() << " x " << map->GetNbinsY() << " bins)";

if (file) {
file->Close();
delete file;
}
}

void Digitizer::prepareScaledResolutionMap()
{
if (!mResolutionMap) {
Expand Down
69 changes: 67 additions & 2 deletions Steer/DigitizerWorkflow/src/IOTOFDigitizerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
void initDigitizerTask(framework::InitContext& ic) override
{
mDisableQED = ic.options().get<bool>("disable-qed");
mEnableResponseFiles = ic.options().get<bool>("enable-response-files");
mLocalEfficiencyFile = ic.options().get<std::string>("local-efficiency-file");
mLocalTimeResoFile = ic.options().get<std::string>("local-timereso-file");
mLocalToAFile = ic.options().get<std::string>("local-toa-file");

auto geom = GeometryTGeo::Instance();
geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G)); // make sure L2G matrices are loaded
Expand All @@ -69,6 +73,13 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
if (mFinished) {
return;
}

if (mEnableResponseFiles) {
pc.inputs().get<TH2D*>("madpixeff");
pc.inputs().get<TH2D*>("madpixreso");
pc.inputs().get<TH2D*>("madpixtoa");
}

mFirstOrbitTF = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
const o2::InteractionRecord firstIR(0, mFirstOrbitTF);

Expand Down Expand Up @@ -163,10 +174,59 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer
mFinished = true;
}

void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
if (matcher == ConcreteDataMatcher(mOrigin, "MADPIXEFF", 0)) {
if (mLocalEfficiencyFile.empty()) {
LOG(info) << "Using CCDB/MADPIX efficiency file";
mDigitizer.loadEfficiencyMap((TH2D*)obj);
} else {
LOG(info) << "Response function will be loaded from local file: " << mLocalEfficiencyFile;
std::unique_ptr<TFile> file(TFile::Open(mLocalEfficiencyFile.data(), "READ"));
if (!file) {
LOG(fatal) << "Cannot open response file " << mLocalEfficiencyFile.data();
}
mDigitizer.loadEfficiencyMap((TH2D*)file->Get("efficiency_pixel"));
}
return;
}
if (matcher == ConcreteDataMatcher(mOrigin, "MADPIXRESO", 0)) {
if (mLocalTimeResoFile.empty()) {
LOG(info) << "Using CCDB/MADPIX time resolution file";
mDigitizer.loadResolutionMap((TH2D*)obj);
} else {
LOG(info) << "Response function will be loaded from local file: " << mLocalTimeResoFile;
std::unique_ptr<TFile> file(TFile::Open(mLocalTimeResoFile.data(), "READ"));
if (!file) {
LOG(fatal) << "Cannot open response file " << mLocalTimeResoFile.data();
}
mDigitizer.loadResolutionMap((TH2D*)file->Get("sigma_pixel"));
}
return;
}
if (matcher == ConcreteDataMatcher(mOrigin, "MADPIXTOA", 0)) {
if (mLocalToAFile.empty()) {
LOG(info) << "Using CCDB/MADPIX time-of-arrival file";
mDigitizer.loadTimeOfArrivalMap((TH2D*)obj);
} else {
LOG(info) << "Response function will be loaded from local file: " << mLocalToAFile;
std::unique_ptr<TFile> file(TFile::Open(mLocalToAFile.data(), "READ"));
if (!file) {
LOG(fatal) << "Cannot open response file " << mLocalToAFile.data();
}
mDigitizer.loadTimeOfArrivalMap((TH2D*)file->Get("toa_pixel"));
}
}
}

private:
bool mDisableQED = false;
bool mEnableResponseFiles = false;
bool mWithMCTruth{true};
bool mFinished{false};
std::string mLocalEfficiencyFile{""};
std::string mLocalTimeResoFile{""};
std::string mLocalToAFile{""};
unsigned long mFirstOrbitTF = 0x0;
const o2::detectors::DetID mID{o2::detectors::DetID::TF3};
const o2::header::DataOrigin mOrigin{o2::header::gDataOriginTF3};
Expand Down Expand Up @@ -197,7 +257,9 @@ o2::framework::DataProcessorSpec getIOTOFDigitizerSpec(int channel, bool mctruth
{
std::vector<o2::framework::InputSpec> inputs;
inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<o2::header::DataHeader::SubSpecificationType>(channel), o2::framework::Lifetime::Timeframe);
inputs.emplace_back("IOTOF_aptsresp", "TF3", "APTSRESP", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("IT3/Calib/APTSResponse"));
inputs.emplace_back("madpixeff", "TF3", "MADPIXEFF", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelEfficiency"));
inputs.emplace_back("madpixreso", "TF3", "MADPIXRESO", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelResolution"));
inputs.emplace_back("madpixtoa", "TF3", "MADPIXTOA", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("Users/g/glucia/tmp/ALICE3/IOTOF/pixelTimeOfArrival"));

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

} // namespace o2::iotof
Loading