|
ATLAS Offline Software
|
Go to the documentation of this file.
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;
def retrieve(aClass, aKey=None)
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
DetCondCFloat is a class to hold sets of Identifiers and arrays of floats for detector element specif...
char data[hepevt_bytes_allocation_ATLAS]
const DataObjID & fullKey() const
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Gaudi::Property< int > m_distortionVersion
value_type get_compact() const
Get the compact id.
virtual StatusCode execute() override
SG::WriteCondHandleKey< PixelDistortionData > m_writeKey
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Gaudi::Property< bool > m_writeToFile
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
SG::ReadCondHandleKey< DetCondCFloat > m_readKey
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
const DataObjID & fullKey() const
virtual StatusCode initialize() override
::StatusCode StatusCode
StatusCode definition for legacy code.
PixelDistortionAlg(const std::string &name, ISvcLocator *pSvcLocator)
A wrapper class for event-slot-local random engines.
const std::string & key() const
StatusCode initialize(bool used=true)
#define ATH_MSG_WARNING(x)
Gaudi::Property< std::string > m_inputFileName
const std::string & tag() const
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
const float * find(const Identifier &ident) const
Gaudi::Property< int > m_distortionInputSource
ServiceHandle< IAthRNGSvc > m_rndmSvc
Random number service.
const PixelID * m_pixelID