ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSParametrizationBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "TClass.h"
7#ifdef USE_GPU
8// for purpose of copying all parameterization files to GPU in initialization
13#include "TString.h"
14#endif
15
16//=============================================
17//======= TFCSParametrizationBase =========
18//=============================================
19
21 const char *title)
22 : TNamed(name, title) {}
23
25 for (unsigned int i = 0; i < size(); ++i)
26 (*this)[i]->set_geometry(geo);
27}
28
33 TFCSSimulationState & /*simulstate*/, const TFCSTruthState * /*truth*/,
34 const TFCSExtrapolationState * /*extrapol*/) const {
35 ATH_MSG_ERROR("now in TFCSParametrizationBase::simulate(). This should "
36 "normally not happen");
37 // Force one retry to issue a printout from the chain causing the call to this
38 // method
39 return (FCSReturnCode)(FCSRetry + 1);
40}
41
43 const TFCSParametrizationBase &ref) const {
44 if (this == &ref) {
45 ATH_MSG_DEBUG("compare(): identical instances " << this << " == " << &ref);
46 return true;
47 }
48 return false;
49}
50
52void TFCSParametrizationBase::Print(Option_t *option) const {
53 TString opt(option);
54 bool shortprint = opt.Index("short") >= 0;
55 bool longprint = msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
56 TString optprint = opt;
57 optprint.ReplaceAll("short", "");
58
59 if (longprint) {
60 ATH_MSG_INFO(optprint << GetTitle() << " " << IsA()->GetName() );
61 ATH_MSG(INFO) << optprint << " PDGID: ";
62 if (is_match_all_pdgid()) {
63 ATH_MSG(INFO) << "all";
64 } else {
65 for (std::set<int>::iterator it = pdgid().begin(); it != pdgid().end();
66 ++it) {
67 if (it != pdgid().begin())
68 ATH_MSG(INFO) << ", ";
69 ATH_MSG(INFO) << *it;
70 }
71 }
72 if (is_match_all_Ekin()) {
73 ATH_MSG(INFO) << " ; Ekin=all";
74 } else {
75 ATH_MSG(INFO) << " ; Ekin=" << Ekin_nominal() << " [" << Ekin_min()
76 << " , " << Ekin_max() << ") MeV";
77 }
78 if (is_match_all_eta()) {
79 ATH_MSG(INFO) << " ; eta=all";
80 } else {
81 ATH_MSG(INFO) << " ; eta=" << eta_nominal() << " [" << eta_min() << " , "
82 << eta_max() << ")";
83 }
84 ATH_MSG(INFO) << END_MSG(INFO);
85 } else {
86 ATH_MSG_INFO(optprint << GetTitle());
87 }
88}
89
91 FindDuplicateClasses_t &dupclasses) {
92
93 for (unsigned int i = 0; i < size(); ++i)
94 if ((*this)[i]) {
95 TFCSParametrizationBase *param = (*this)[i];
96 FindDuplicates_t &dup = dupclasses[param->GetName()];
97 // If param is already in the duplication list, skip over
98 auto checkexist = dup.find(param);
99 if (checkexist != dup.end()) {
100 ATH_MSG_WARNING(" [TFCSParametrizationBase::FindDuplicates] "
101 "DUPLICATE POINTER DETECTED");
102
103 ATH_MSG_WARNING(" - Pointer : " << param);
104 ATH_MSG_WARNING(" - Name : " << param->GetName());
105 ATH_MSG_WARNING(" - Class : " << param->ClassName());
106 ATH_MSG_WARNING(" - Occurs in parent : " << this
107 << " (" << this->ClassName() << ")"
108 << " index=" << i);
109
110 if (checkexist->second.replace) {
111 TFCSParametrizationBase *refparam = checkexist->second.replace;
112 ATH_MSG_DEBUG("Found duplicate pointer: "
113 << refparam << "=" << refparam->GetName()
114 << ", duplicate is " << param << "=" << param->GetName()
115 << " index " << i << " of " << this);
116 dup[refparam].mother.push_back(this);
117 dup[refparam].index.push_back(i);
118 }
119 continue;
120 }
121 // Add param to duplication list
122 dup[param] = Duplicate_t();
123 for (auto &ref : dup) {
124 TFCSParametrizationBase *refparam = ref.first;
125 // skip itself, as this just added above
126 if (param == refparam)
127 continue;
128 // skip nullptr reference
129 if (refparam == nullptr)
130 continue;
131 // skip reference that is itself going to get replaced
132 if (ref.second.replace)
133 continue;
134 // Check for objects with identical content
135 if (*param == *refparam) {
136 ATH_MSG_DEBUG("Found duplicate: "
137 << refparam << "=" << refparam->GetName()
138 << ", duplicate is " << param << "=" << param->GetName()
139 << " index " << i << " of " << this);
140
141 dup[param].replace = refparam;
142 dup[refparam].mother.push_back(this);
143 dup[refparam].index.push_back(i);
144 break;
145 }
146 }
147 // Continue for child objects in param
148 param->FindDuplicates(dupclasses);
149 }
150}
151
153 FindDuplicateClasses_t dupclasses;
154 FindDuplicates(dupclasses);
155
156 std::set<TFCSParametrizationBase *> dellist;
157 for (auto &dupiter : dupclasses) {
158 FindDuplicates_t &dup = dupiter.second;
159 for (auto onedup : dup) {
160 if (onedup.second.mother.empty())
161 continue;
162 TFCSParametrizationBase *ref = onedup.first;
163 ATH_MSG_DEBUG("Main object " << ref << "=" << ref->GetName());
164 for (unsigned int i = 0; i < onedup.second.mother.size(); ++i) {
165 int index = onedup.second.index[i];
166 TFCSParametrizationBase *mother = onedup.second.mother[i];
167 TFCSParametrizationBase *delparam = mother->operator[](index);
168 unsigned int delcount = dup[delparam].mother.size();
169 if (delcount == 0) {
170 ATH_MSG_DEBUG(" - Delete object "
171 << delparam << "=" << delparam->GetName() << " index "
172 << index << " of " << mother << ", has " << delcount
173 << " other replacements attached. Deleting");
174 mother->set_daughter(index, ref);
175 dellist.insert(delparam);
176 } else {
177 ATH_MSG_WARNING(" - Delete object "
178 << delparam << "=" << delparam->GetName() << " index "
179 << index << " of " << mother << ", has " << delcount
180 << " other replacements attached. Skipping");
181 }
182 }
183 }
184 }
185
186 ATH_MSG_INFO("RERUNNING DUPLICATE FINDING");
187 FindDuplicateClasses_t dupclasses2;
188 FindDuplicates(dupclasses2);
189
190 std::map<std::string, int> ndel;
191 for (auto *delparam : dellist) {
192 FindDuplicates_t &dup2 = dupclasses2[delparam->GetName()];
193 bool present = dup2.find(delparam) != dup2.end();
194 if (present) {
195 ATH_MSG_WARNING("- Delete object " << delparam << "="
196 << delparam->GetName()
197 << " still referenced somewhere!");
198 } else {
199 ATH_MSG_DEBUG("- Delete object " << delparam << "="
200 << delparam->GetName());
201 ++ndel[delparam->ClassName()];
202 delete delparam;
203 }
204 }
205 for (auto &del : ndel)
206 ATH_MSG_INFO("Deleted " << del.second << " duplicate objects of class "
207 << del.first);
208}
209
211 for (unsigned int i = 0; i < size(); ++i)
212 if ((*this)[i]) {
213 TFCSParametrizationBase *param = (*this)[i];
214 param->SetName("");
215 param->SetTitle("");
216
217 // Continue for child objects in param
218 param->RemoveNameTitle();
219 }
220}
221
222#ifdef USE_GPU
223void TFCSParametrizationBase::Copy2GPU() {
224 for (unsigned int i = 0; i < size(); ++i) {
225 if (!((*this)[i]))
226 continue;
227 TFCSParametrizationBase *param = (*this)[i];
228 TString name = param->ClassName();
229 if (name.EqualTo("TFCSLateralShapeParametrizationHitChain")) {
230 auto size = (static_cast<TFCSLateralShapeParametrizationHitChain *>(param))->size();
231 for (size_t ichain = 0; ichain < size; ++ichain) {
233 *(static_cast<TFCSLateralShapeParametrizationHitChain *>(param))[ichain];
234 TString hitsimname = hitsim->ClassName();
235 if (hitsimname.EqualTo("TFCSHistoLateralShapeParametrization")) {
236 (static_cast<TFCSHistoLateralShapeParametrization *>(hitsim))->LoadHistFuncs();
237 } else if (hitsimname.EqualTo("TFCSHitCellMappingWiggle")) {
238 (static_cast<TFCSHitCellMappingWiggle *>(hitsim))->LoadHistFuncs();
239 } else if (hitsimname.EqualTo("TFCSHistoLateralShapeGausLogWeight")) {
240 (static_cast<TFCSHistoLateralShapeGausLogWeight *>(hitsim))->LoadHist();
241 }
242 }
243 }
244 param->Copy2GPU();
245 }
246}
247#endif
const boost::regex ref(r_ef)
#define ATH_MSG_ERROR(x)
#define ATH_MSG(lvl)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define END_MSG(lvl)
Definition MLogging.h:171
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
An interface for getting the name of a class as a string.
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition MLogging.h:222
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
Method in all derived classes to do some simulation.
void FindDuplicates(FindDuplicateClasses_t &dup)
virtual const std::set< int > & pdgid() const
virtual bool is_match_all_eta() const
virtual bool is_match_all_Ekin() const
virtual double Ekin_min() const
virtual void set_geometry(ICaloGeometry *geo)
Method to set the geometry access pointer.
virtual double eta_max() const
virtual void set_daughter(unsigned int, TFCSParametrizationBase *)
Some derived classes have daughter instances of TFCSParametrizationBase objects The set_daughter meth...
std::map< TFCSParametrizationBase *, Duplicate_t > FindDuplicates_t
virtual unsigned int size() const
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
virtual double eta_min() const
std::map< std::string, FindDuplicates_t > FindDuplicateClasses_t
virtual double Ekin_max() const
void Print(Option_t *option="") const
Print object information.
virtual bool is_match_all_pdgid() const
bool compare(const TFCSParametrizationBase &ref) const
Do not persistify!
virtual double eta_nominal() const
TFCSParametrizationBase(const char *name=nullptr, const char *title=nullptr)
virtual double Ekin_nominal() const
Definition index.py:1
#define IsA
Declare the TObject style functions.