41 ATH_MSG_DEBUG(
"PixelDistortionAlg::execute(const EventContext& ctx) const");
45 ATH_MSG_DEBUG(
"CondHandle " << writeHandle.
fullKey() <<
" is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
46 return StatusCode::SUCCESS;
50 std::unique_ptr<PixelDistortionData> writeCdo(std::make_unique<PixelDistortionData>());
54 constexpr int nmodule_max = 2048;
55 std::unordered_map<uint32_t,std::vector<float>> distortionMap;
56 std::unordered_map<uint32_t,unsigned long long> ids;
60 for (
int i=0; i<nmodule_max; i++) {
61 distortionMap[i].push_back(0.0);
62 distortionMap[i].push_back(0.0);
63 distortionMap[i].push_back(0.0);
69 for (
int i=0; i<nmodule_max; i++) {
70 distortionMap[i].push_back(0.1);
71 distortionMap[i].push_back(0.1);
72 distortionMap[i].push_back(2.0*std::atan(0.0005)/CLHEP::degree);
77 if (file_name.empty()) {
78 ATH_MSG_ERROR(
"Distortion filename is empty not found! No pixel distortion will be applied.");
79 return StatusCode::FAILURE;
82 ATH_MSG_DEBUG(
"Reading pixel distortions from file: " << file_name);
85 if (file_name[0] !=
'/') {
88 std::ifstream input(file_name);
91 return StatusCode::FAILURE;
98 while (!input.eof()) {
100 unsigned int hashID {};
107 input >> std::hex >> idmod >> std::dec;
115 ATH_MSG_DEBUG(
"Identifier = 0x" << std::hex << ids[hashID] << std::dec);
118 for (
int i = 0; i < distosize; ++i) {
121 distortionMap[hashID].push_back(
data);
132 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
134 constexpr double distortionMeanR{0.12/CLHEP::meter};
135 constexpr double distortionRMSR{0.08};
136 constexpr double distortionMeanTwist{-0.0005};
138 for (
int i=0; i<nmodule_max; i++) {
139 float r1 = CLHEP::RandGaussZiggurat::shoot(rndmEngine,distortionMeanR,distortionRMSR);
140 float r2 = CLHEP::RandGaussZiggurat::shoot(rndmEngine,r1,distortionRMSR/10.);
141 float twist = CLHEP::RandGaussZiggurat::shoot(rndmEngine,distortionMeanTwist,distortionMeanTwist);
142 distortionMap[i].push_back(r1*CLHEP::meter);
143 distortionMap[i].push_back(r2*CLHEP::meter);
144 distortionMap[i].push_back(2.0*std::atan(twist)/CLHEP::degree);
151 if (readCdo==
nullptr) {
153 return StatusCode::FAILURE;
159 if (readCdo->
tag()==
"/Indet/PixelDist") {
161 ATH_MSG_INFO(
"Detected old version of pixel distortions data.");
164 bool gotVersion =
false;
167 std::string baseStr =
"/Indet/PixelDist_v";
168 if (readCdo->
tag().compare(0,baseStr.size(),baseStr)==0) {
169 std::istringstream istr(readCdo->
tag().substr(baseStr.size()));
173 version = version_tmp;
178 ATH_MSG_WARNING(
"Unable to determine version number of pixel distortions data. Version string: " << readCdo->
tag());
181 writeCdo -> setVersion(version);
184 int distosize = readCdo->
size();
186 for (
int i=0; i<nmodule_max; i++) {
189 const float *disto = readCdo->
find(modId);
192 ATH_MSG_DEBUG(
"Identifier = 0x" << std::hex << ids[i] << std::dec);
194 for (
int j = 0; j < distosize; ++j) {
195 distortionMap[i].push_back(disto[j]);
196 s << disto[j] <<
" ";
202 writeCdo -> setDistortionMap(distortionMap);
203 writeCdo -> setIds(ids);
206 std::ofstream* outfile =
new std::ofstream(
"output_distortion.txt");
207 for (
int i=0; i<nmodule_max; i++) {
208 if (!distortionMap[i].
empty()) {
210 *outfile <<
m_pixelID->wafer_id(
IdentifierHash(i)) <<
" " << distortionMap[i].at(0) <<
" " << distortionMap[i].at(1) <<
" " << distortionMap[i].at(2) << std::endl;
213 *outfile << i <<
" " << distortionMap[i].at(0) <<
" " << distortionMap[i].at(1) <<
" " << distortionMap[i].at(2) << std::endl;
221 const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
222 const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
223 const EventIDRange rangeW{start, stop};
225 if (writeHandle.
record(rangeW, std::move(writeCdo)).isFailure()) {
226 ATH_MSG_FATAL(
"Could not record PixelDistortionData " << writeHandle.
key() <<
" with EventRange " << rangeW <<
" into Conditions Store");
227 return StatusCode::FAILURE;
229 ATH_MSG_DEBUG(
"recorded new CDO " << writeHandle.
key() <<
" with range " << rangeW <<
" into Conditions Store");
231 return StatusCode::SUCCESS;