ATLAS Offline Software
Loading...
Searching...
No Matches
ITkPixFieldMapsAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "GaudiKernel/EventIDRange.h"
9#include "TFile.h"
10#include "TH3F.h"
11#include "TH2F.h"
12#include <memory>
13
14namespace {
15 template <class T>
16 std::unique_ptr<T>
17 readRootObject(TFile& file, const char* name){
18 auto* object = file.Get<T>(name);
19 if (!object) {
20 return nullptr;
21 }
22 auto result = std::unique_ptr<T>(object);
23 result->SetDirectory(nullptr);
24 return result;
25 }
26 //from EventIDBase
27 typedef unsigned int number_type;
29}
30
31ITkPixFieldMapsAlg::ITkPixFieldMapsAlg(const std::string& name, ISvcLocator* pSvcLocator):
32 ::AthCondAlgorithm(name, pSvcLocator)
33{
34}
35
37 ATH_MSG_DEBUG("ITkPixFieldMapsAlg::initialize()");
38 ATH_CHECK(m_writeFieldMapKey.initialize());
39 EventContext ctx;
40 //we need a context eventually, and the following will all be in 'execute'
41 //right now, this section is redundant; however by doing it in initialize, we only open
42 //the file and read the data once for all events
43 number_type runNumber(1);
44 event_number_t eventNumber(0);
45 number_type timeStamp(0);
46 EventIDBase eidRun1 (runNumber, eventNumber, timeStamp);
47 ctx.setEventID (eidRun1);
48 //
50 if (writeFieldMapHandle.isValid()) {
51 ATH_MSG_DEBUG("CondHandle " << writeFieldMapHandle.fullKey() << " is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
52 return StatusCode::SUCCESS;
53 }
54
55
56 // Construct the output Cond Object and fill it in
57 auto writeFieldsCdo(std::make_unique<ITkPixFieldMaps>());
58
59 const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0,
60 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
61 const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1,
62 EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
63
64 EventIDRange rangeW{start, stop};
65
66 // Create mapping file for radiation damage simulation
67 std::vector<PixelHistoConverter> ramoPotentialMap;
68 std::vector<PixelHistoConverter> lorentzMap_e;
69 std::vector<PixelHistoConverter> lorentzMap_h;
70 std::vector<PixelHistoConverter> distanceMap_e;
71 std::vector<PixelHistoConverter> distanceMap_h;
72 //returns /cvmfs/atlas.cern.ch/repo/sw/database/GroupData/PixelDigitization/maps_IBL_PL_80V_fl0e14.root
73 const std::string fullPath = PathResolverFindCalibFile(m_efieldFilePath.value());
74 ATH_MSG_INFO("Using map located at: "<<fullPath);
75 std::unique_ptr<TFile> mapsFile(TFile::Open(fullPath.c_str(), "READ")); //this is the ramo potential
76 if (!mapsFile) {
77 ATH_MSG_FATAL("Cannot open file: " << m_efieldFilePath.value());
78 return StatusCode::FAILURE;
79 }
80
81 //Setup ramo weighting field map
82 auto ramoPotentialMap_hold = readRootObject<TH3F>(*mapsFile, "hramomap1");
83 if (!ramoPotentialMap_hold) {
84 ramoPotentialMap_hold = readRootObject<TH3F>(*mapsFile, "ramo3d");
85 }
86 if (!ramoPotentialMap_hold) {
87 ATH_MSG_FATAL("Did not find a Ramo potential map and an approximate form is available yet. Exit...");
88 return StatusCode::FAILURE;
89 }
90
91 ramoPotentialMap_hold->SetDirectory(nullptr);
92 auto lorentzMap_e_hold = readRootObject<TH2F>(*mapsFile, "lorentz_map_e");
93 auto lorentzMap_h_hold = readRootObject<TH2F>(*mapsFile, "lorentz_map_h");
94 auto distanceMap_e_hold = readRootObject<TH2F>(*mapsFile, "edistance");
95 auto distanceMap_h_hold = readRootObject<TH2F>(*mapsFile, "hdistance");
96
97 if (!lorentzMap_e_hold || !lorentzMap_h_hold || !distanceMap_e_hold || !distanceMap_h_hold) {
98 ATH_MSG_FATAL("Cannot read one of the histograms needed");
99 return StatusCode::FAILURE;
100 }
101
102
103 ramoPotentialMap.emplace_back();
104 ATH_CHECK(ramoPotentialMap.back().setHisto3D(ramoPotentialMap_hold.get()));
105 lorentzMap_e.emplace_back();
106 lorentzMap_h.emplace_back();
107 distanceMap_e.emplace_back();
108 distanceMap_h.emplace_back();
109 ATH_CHECK(lorentzMap_e.back().setHisto2D(lorentzMap_e_hold.get()));
110 ATH_CHECK(lorentzMap_h.back().setHisto2D(lorentzMap_h_hold.get()));
111 ATH_CHECK(distanceMap_e.back().setHisto2D(distanceMap_e_hold.get()));
112 ATH_CHECK(distanceMap_h.back().setHisto2D(distanceMap_h_hold.get()));
113
114 mapsFile->Close();
115
116 writeFieldsCdo -> setLorentzMap_e(std::move(lorentzMap_e));
117 writeFieldsCdo -> setLorentzMap_h(std::move(lorentzMap_h));
118 writeFieldsCdo -> setDistanceMap_e(std::move(distanceMap_e));
119 writeFieldsCdo -> setDistanceMap_h(std::move(distanceMap_h));
120 writeFieldsCdo -> setRamoPotentialMap(std::move(ramoPotentialMap));
121
122 if (rangeW.stop().isValid() && rangeW.start()>rangeW.stop()) {
123 ATH_MSG_FATAL("Invalid intersection rangeW: " << rangeW);
124 return StatusCode::FAILURE;
125 }
126 if (writeFieldMapHandle.record(rangeW, std::move(writeFieldsCdo)).isFailure()) {
127 ATH_MSG_FATAL("Could not record ITkPixFieldMaps " << writeFieldMapHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
128 return StatusCode::FAILURE;
129 }
130 ATH_MSG_INFO("recorded new CDO " << writeFieldMapHandle.key() << " with range " << rangeW << " into Conditions Store");
131
132 return StatusCode::SUCCESS;
133
134}
135
136StatusCode ITkPixFieldMapsAlg::execute(const EventContext& /*ctx*/) const {
137 ATH_MSG_DEBUG("ITkPixFieldMapsAlg::execute()");
138
139
140 return StatusCode::SUCCESS;
141}
142
143
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
EventIDBase::event_number_t event_number_t
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Base class for conditions algorithms.
Gaudi::Property< std::string > m_efieldFilePath
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteCondHandleKey< ITkPixFieldMaps > m_writeFieldMapKey
ITkPixFieldMapsAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
unsigned int number_type
TFile * file