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 = 0;
107 input >> std::hex >> idmod >> std::dec;
115 for (
int i = 0;
i < distosize; ++
i) {
118 distortionMap[hashID].push_back(
data);
129 rngWrapper->
setSeed(
name(),Gaudi::Hive::currentContext());
130 CLHEP::HepRandomEngine *rndmEngine = *rngWrapper;
133 constexpr
double distortionRMSR{0.08};
134 constexpr
double distortionMeanTwist{-0.0005};
136 for (
int i=0;
i<nmodule_max;
i++) {
137 float r1 = CLHEP::RandGaussZiggurat::shoot(rndmEngine,distortionMeanR,distortionRMSR);
138 float r2 = CLHEP::RandGaussZiggurat::shoot(rndmEngine,r1,distortionRMSR/10.);
139 float twist = CLHEP::RandGaussZiggurat::shoot(rndmEngine,distortionMeanTwist,distortionMeanTwist);
149 if (readCdo==
nullptr) {
151 return StatusCode::FAILURE;
157 if (readCdo->
tag()==
"/Indet/PixelDist") {
159 ATH_MSG_INFO(
"Detected old version of pixel distortions data.");
162 bool gotVersion =
false;
165 std::string baseStr =
"/Indet/PixelDist_v";
166 if (readCdo->
tag().compare(0,baseStr.size(),baseStr)==0) {
167 std::istringstream istr(readCdo->
tag().substr(baseStr.size()));
176 ATH_MSG_WARNING(
"Unable to determine version number of pixel distortions data. Version string: " << readCdo->
tag());
179 writeCdo -> setVersion(
version);
182 int distosize = readCdo->
size();
184 for (
int i=0;
i<nmodule_max;
i++) {
187 const float *disto = readCdo->
find(modId);
192 for (
int j = 0; j < distosize; ++j) {
193 distortionMap[
i].push_back(disto[j]);
194 s << disto[j] <<
" ";
200 writeCdo -> setDistortionMap(distortionMap);
201 writeCdo -> setIds(
ids);
204 std::ofstream*
outfile =
new std::ofstream(
"output_distortion.txt");
205 for (
int i=0;
i<nmodule_max;
i++) {
206 if (!distortionMap[
i].
empty()) {
211 *
outfile <<
i <<
" " << distortionMap[
i].at(0) <<
" " << distortionMap[
i].at(1) <<
" " << distortionMap[
i].at(2) << std::endl;
219 const EventIDBase
start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
220 const EventIDBase
stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
223 if (writeHandle.
record(rangeW, std::move(writeCdo)).isFailure()) {
224 ATH_MSG_FATAL(
"Could not record PixelDistortionData " << writeHandle.
key() <<
" with EventRange " << rangeW <<
" into Conditions Store");
225 return StatusCode::FAILURE;
227 ATH_MSG_DEBUG(
"recorded new CDO " << writeHandle.
key() <<
" with range " << rangeW <<
" into Conditions Store");
229 return StatusCode::SUCCESS;