ATLAS Offline Software
TFCSParametrizationBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
52 void 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  for (unsigned int i = 0; i < size(); ++i)
93  if ((*this)[i]) {
94  TFCSParametrizationBase *param = (*this)[i];
95  FindDuplicates_t &dup = dupclasses[param->GetName()];
96  // If param is already in the duplication list, skip over
97  auto checkexist = dup.find(param);
98  if (checkexist != dup.end()) {
99  ATH_MSG_DEBUG("Found duplicate pointer for: " << param << "="
100  << param->GetName());
101  if (checkexist->second.replace) {
102  TFCSParametrizationBase *refparam = checkexist->second.replace;
103  ATH_MSG_DEBUG("Found duplicate pointer: "
104  << refparam << "=" << refparam->GetName()
105  << ", duplicate is " << param << "=" << param->GetName()
106  << " index " << i << " of " << this);
107  dup[refparam].mother.push_back(this);
108  dup[refparam].index.push_back(i);
109  }
110  continue;
111  }
112  // Add param to duplication list
113  dup[param] = Duplicate_t();
114  for (auto &ref : dup) {
115  TFCSParametrizationBase *refparam = ref.first;
116  // skip itself, as this just added above
117  if (param == refparam)
118  continue;
119  // skip nullptr reference
120  if (refparam == nullptr)
121  continue;
122  // skip reference that is itself going to get replaced
123  if (ref.second.replace)
124  continue;
125  // Check for objects with identical content
126  if (*param == *refparam) {
127  ATH_MSG_DEBUG("Found duplicate: "
128  << refparam << "=" << refparam->GetName()
129  << ", duplicate is " << param << "=" << param->GetName()
130  << " index " << i << " of " << this);
131  dup[param].replace = refparam;
132  dup[refparam].mother.push_back(this);
133  dup[refparam].index.push_back(i);
134  break;
135  }
136  }
137  // Continue for child objects in param
138  param->FindDuplicates(dupclasses);
139  }
140 }
141 
143  FindDuplicateClasses_t dupclasses;
144  FindDuplicates(dupclasses);
145 
146  std::set<TFCSParametrizationBase *> dellist;
147  for (auto &dupiter : dupclasses) {
148  FindDuplicates_t &dup = dupiter.second;
149  for (auto onedup : dup) {
150  if (onedup.second.mother.empty())
151  continue;
152  TFCSParametrizationBase *ref = onedup.first;
153  ATH_MSG_DEBUG("Main object " << ref << "=" << ref->GetName());
154  for (unsigned int i = 0; i < onedup.second.mother.size(); ++i) {
155  int index = onedup.second.index[i];
156  TFCSParametrizationBase *mother = onedup.second.mother[i];
157  TFCSParametrizationBase *delparam = mother->operator[](index);
158  unsigned int delcount = dup[delparam].mother.size();
159  if (delcount == 0) {
160  ATH_MSG_DEBUG(" - Delete object "
161  << delparam << "=" << delparam->GetName() << " index "
162  << index << " of " << mother << ", has " << delcount
163  << " other replacements attached. Deleting");
164  mother->set_daughter(index, ref);
165  dellist.insert(delparam);
166  } else {
167  ATH_MSG_WARNING(" - Delete object "
168  << delparam << "=" << delparam->GetName() << " index "
169  << index << " of " << mother << ", has " << delcount
170  << " other replacements attached. Skipping");
171  }
172  }
173  }
174  }
175 
176  ATH_MSG_INFO("RERUNNING DUPLICATE FINDING");
177  FindDuplicateClasses_t dupclasses2;
178  FindDuplicates(dupclasses2);
179 
180  std::map<std::string, int> ndel;
181  for (auto *delparam : dellist) {
182  FindDuplicates_t &dup2 = dupclasses2[delparam->GetName()];
183  bool present = dup2.find(delparam) != dup2.end();
184  if (present) {
185  ATH_MSG_WARNING("- Delete object " << delparam << "="
186  << delparam->GetName()
187  << " still referenced somewhere!");
188  } else {
189  ATH_MSG_DEBUG("- Delete object " << delparam << "="
190  << delparam->GetName());
191  ++ndel[delparam->ClassName()];
192  delete delparam;
193  }
194  }
195  for (auto &del : ndel)
196  ATH_MSG_INFO("Deleted " << del.second << " duplicate objects of class "
197  << del.first);
198 }
199 
201  for (unsigned int i = 0; i < size(); ++i)
202  if ((*this)[i]) {
203  TFCSParametrizationBase *param = (*this)[i];
204  param->SetName("");
205  param->SetTitle("");
206 
207  // Continue for child objects in param
208  param->RemoveNameTitle();
209  }
210 }
211 
212 #ifdef USE_GPU
213 void TFCSParametrizationBase::Copy2GPU() {
214  for (unsigned int i = 0; i < size(); ++i) {
215  if (!((*this)[i]))
216  continue;
217  TFCSParametrizationBase *param = (*this)[i];
218  TString name = param->ClassName();
219  if (name.EqualTo("TFCSLateralShapeParametrizationHitChain")) {
220  auto size = ((TFCSLateralShapeParametrizationHitChain *)param)->size();
221  for (size_t ichain = 0; ichain < size; ++ichain) {
222  TFCSParametrizationBase *hitsim =
223  (*((TFCSLateralShapeParametrizationHitChain *)param))[ichain];
224  TString hitsimname = hitsim->ClassName();
225  if (hitsimname.EqualTo("TFCSHistoLateralShapeParametrization")) {
226  ((TFCSHistoLateralShapeParametrization *)hitsim)->LoadHistFuncs();
227  } else if (hitsimname.EqualTo("TFCSHitCellMappingWiggle")) {
228  ((TFCSHitCellMappingWiggle *)hitsim)->LoadHistFuncs();
229  } else if (hitsimname.EqualTo("TFCSHistoLateralShapeGausLogWeight")) {
230  ((TFCSHistoLateralShapeGausLogWeight *)hitsim)->LoadHist();
231  }
232  }
233  }
234  param->Copy2GPU();
235  }
236 }
237 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TFCSParametrizationBase::set_daughter
virtual void set_daughter(unsigned int, TFCSParametrizationBase *)
Some derived classes have daughter instances of TFCSParametrizationBase objects The set_daughter meth...
Definition: TFCSParametrizationBase.h:113
TFCSHitCellMappingWiggle
Definition: TFCSHitCellMappingWiggle.h:20
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
TFCSParametrizationBase::compare
bool compare(const TFCSParametrizationBase &ref) const
Do not persistify!
Definition: TFCSParametrizationBase.cxx:42
TFCSLateralShapeParametrizationHitChain
Definition: TFCSLateralShapeParametrizationHitChain.h:15
ATH_MSG
#define ATH_MSG(lvl)
Definition: AthMsgStreamMacros.h:38
TFCSHistoLateralShapeParametrization
Definition: TFCSHistoLateralShapeParametrization.h:20
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TFCSParametrizationBase::is_match_all_pdgid
virtual bool is_match_all_pdgid() const
Definition: TFCSParametrizationBase.h:66
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
TFCSParametrizationBase::eta_nominal
virtual double eta_nominal() const
Definition: TFCSParametrizationBase.h:79
index
Definition: index.py:1
TFCSHistoLateralShapeGausLogWeight
Definition: TFCSHistoLateralShapeGausLogWeight.h:16
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TFCSParametrizationBase::FindDuplicates
void FindDuplicates(FindDuplicateClasses_t &dup)
Definition: TFCSParametrizationBase.cxx:90
TFCSParametrizationBase::Ekin_nominal
virtual double Ekin_nominal() const
Definition: TFCSParametrizationBase.h:76
TFCSParametrizationBase::simulate
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
Method in all derived classes to do some simulation.
Definition: TFCSParametrizationBase.cxx:32
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
TFCSParametrizationBase::is_match_all_Ekin
virtual bool is_match_all_Ekin() const
Definition: TFCSParametrizationBase.h:67
TFCSHistoLateralShapeGausLogWeight.h
FCSRetry
@ FCSRetry
Definition: TFCSParametrizationBase.h:41
TFCSParametrizationBase.h
TFCSParametrizationBase
Definition: TFCSParametrizationBase.h:46
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TFCSParametrizationBase::Ekin_max
virtual double Ekin_max() const
Definition: TFCSParametrizationBase.h:78
lumiFormat.i
int i
Definition: lumiFormat.py:85
TFCSLateralShapeParametrizationHitChain.h
TFCSParametrizationBase::pdgid
virtual const std::set< int > & pdgid() const
Definition: TFCSParametrizationBase.h:72
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TFCSHistoLateralShapeParametrization.h
ICaloGeometry
Definition: ICaloGeometry.h:14
TFCSParametrizationBase::eta_min
virtual double eta_min() const
Definition: TFCSParametrizationBase.h:80
TFCSParametrizationBase::FindDuplicateClasses_t
std::map< std::string, FindDuplicates_t > FindDuplicateClasses_t
Definition: TFCSParametrizationBase.h:142
TFCSParametrizationBase::eta_max
virtual double eta_max() const
Definition: TFCSParametrizationBase.h:81
covarianceTool.title
title
Definition: covarianceTool.py:542
TFCSParametrizationBase::set_geometry
virtual void set_geometry(ICaloGeometry *geo)
Method to set the geometry access pointer.
Definition: TFCSParametrizationBase.cxx:24
TFCSParametrizationBase::Duplicate_t
Definition: TFCSParametrizationBase.h:136
TFCSParametrizationBase::Print
void Print(Option_t *option="") const
Print object information.
Definition: TFCSParametrizationBase.cxx:52
TFCSParametrizationBase::FindDuplicates_t
std::map< TFCSParametrizationBase *, Duplicate_t > FindDuplicates_t
Definition: TFCSParametrizationBase.h:141
TFCSParametrizationBase::RemoveNameTitle
void RemoveNameTitle()
Definition: TFCSParametrizationBase.cxx:200
TFCSParametrizationBase::Ekin_min
virtual double Ekin_min() const
Definition: TFCSParametrizationBase.h:77
TFCSParametrizationBase::RemoveDuplicates
void RemoveDuplicates()
Definition: TFCSParametrizationBase.cxx:142
TFCSParametrizationBase::is_match_all_eta
virtual bool is_match_all_eta() const
Definition: TFCSParametrizationBase.h:68
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DeMoScan.index
string index
Definition: DeMoScan.py:364
END_MSG
#define END_MSG(lvl)
Definition: MLogging.h:171
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:16
ref
const boost::regex ref(r_ef)
LArCellConditions.geo
bool geo
Definition: LArCellConditions.py:46
DEBUG
#define DEBUG
Definition: page_access.h:11
TFCSHitCellMappingWiggle.h
TFCSParametrizationBase::TFCSParametrizationBase
TFCSParametrizationBase(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSParametrizationBase.cxx:20
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSParametrizationBase::size
virtual unsigned int size() const
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
Definition: TFCSParametrizationBase.h:93
TFCSSimulationState
Definition: TFCSSimulationState.h:32
ISF_FCS::MLogging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition: MLogging.h:222