6 #include "GaudiKernel/EventIDRange.h"
10 #include "CLHEP/Random/RandomEngine.h"
12 #include "CLHEP/Random/RandGaussZiggurat.h"
14 #include "CLHEP/Units/SystemOfUnits.h"
37 return StatusCode::SUCCESS;
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);
78 ATH_MSG_ERROR(
"Distortion filename is empty not found! No pixel distortion will be applied.");
79 return StatusCode::FAILURE;
91 return StatusCode::FAILURE;
98 while (!
input.eof()) {
100 unsigned int hashID {};
107 return StatusCode::FAILURE;
111 input >> std::hex >> idmod >> std::dec;
119 for (
int i = 0;
i < distosize; ++
i) {
122 distortionMap[hashID].push_back(
data);
133 rngWrapper->
setSeed(
name(),Gaudi::Hive::currentContext());
134 CLHEP::HepRandomEngine *rndmEngine = *rngWrapper;
137 constexpr
double distortionRMSR{0.08};
138 constexpr
double distortionMeanTwist{-0.0005};
140 for (
int i=0;
i<nmodule_max;
i++) {
141 float r1 = CLHEP::RandGaussZiggurat::shoot(rndmEngine,distortionMeanR,distortionRMSR);
142 float r2 = CLHEP::RandGaussZiggurat::shoot(rndmEngine,r1,distortionRMSR/10.);
143 float twist = CLHEP::RandGaussZiggurat::shoot(rndmEngine,distortionMeanTwist,distortionMeanTwist);
153 if (readCdo==
nullptr) {
155 return StatusCode::FAILURE;
161 if (readCdo->
tag()==
"/Indet/PixelDist") {
163 ATH_MSG_INFO(
"Detected old version of pixel distortions data.");
166 bool gotVersion =
false;
169 std::string baseStr =
"/Indet/PixelDist_v";
170 if (readCdo->
tag().compare(0,baseStr.size(),baseStr)==0) {
171 std::istringstream istr(readCdo->
tag().substr(baseStr.size()));
180 ATH_MSG_WARNING(
"Unable to determine version number of pixel distortions data. Version string: " << readCdo->
tag());
183 writeCdo -> setVersion(
version);
186 int distosize = readCdo->
size();
188 for (
int i=0;
i<nmodule_max;
i++) {
191 const float *disto = readCdo->
find(modId);
196 for (
int j = 0; j < distosize; ++j) {
197 distortionMap[
i].push_back(disto[j]);
198 s << disto[j] <<
" ";
204 writeCdo -> setDistortionMap(distortionMap);
205 writeCdo -> setIds(
ids);
208 std::ofstream*
outfile =
new std::ofstream(
"output_distortion.txt");
209 for (
int i=0;
i<nmodule_max;
i++) {
210 if (!distortionMap[
i].empty()) {
215 *
outfile <<
i <<
" " << distortionMap[
i].at(0) <<
" " << distortionMap[
i].at(1) <<
" " << distortionMap[
i].at(2) << std::endl;
223 const EventIDBase
start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
224 const EventIDBase
stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
227 if (writeHandle.
record(rangeW, std::move(writeCdo)).isFailure()) {
228 ATH_MSG_FATAL(
"Could not record PixelDistortionData " << writeHandle.
key() <<
" with EventRange " << rangeW <<
" into Conditions Store");
229 return StatusCode::FAILURE;
231 ATH_MSG_DEBUG(
"recorded new CDO " << writeHandle.
key() <<
" with range " << rangeW <<
" into Conditions Store");
233 return StatusCode::SUCCESS;