ATLAS Offline Software
TFCSParametrizationChain.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include <algorithm>
12 #include <iterator>
13 #include "TBuffer.h"
14 #include "TDirectory.h"
15 
16 //=============================================
17 //======= TFCSParametrizationChain =========
18 //=============================================
19 
21  set_pdgid(m_chain[0]->pdgid());
22 
23  for (const auto &param : m_chain) {
24  std::set<int> tmp;
25 
27  param->pdgid().begin(), param->pdgid().end(),
28  std::inserter(tmp, tmp.begin()));
29  set_pdgid(tmp);
30  }
31 }
32 
34  set_pdgid(chain()[0]->pdgid());
35 
36  for (const auto &param : chain()) {
37  std::set<int> tmp;
38 
39  std::set_union(pdgid().begin(), pdgid().end(), param->pdgid().begin(),
40  param->pdgid().end(), std::inserter(tmp, tmp.begin()));
41  set_pdgid(tmp);
42  }
43 }
44 
46  set_Ekin(*m_chain[0]);
47 
48  for (const auto &param : m_chain) {
49  if (param->Ekin_min() > Ekin_min())
50  set_Ekin_min(param->Ekin_min());
51  if (param->Ekin_max() < Ekin_max())
52  set_Ekin_max(param->Ekin_max());
53  if (Ekin_nominal() < Ekin_min() || Ekin_nominal() > Ekin_max())
54  set_Ekin_nominal(param->Ekin_nominal());
55  }
56 
57  if (Ekin_nominal() < Ekin_min() || Ekin_nominal() > Ekin_max())
58  set_Ekin_nominal(0.5 * (Ekin_min() + Ekin_max()));
59 }
60 
62  set_eta(*m_chain[0]);
63 
64  for (const auto &param : m_chain) {
65  if (param->eta_min() > eta_min())
66  set_eta_min(param->eta_min());
67  if (param->eta_max() < eta_max())
68  set_eta_max(param->eta_max());
69  if (eta_nominal() < eta_min() || eta_nominal() > eta_max())
70  set_eta_nominal(param->eta_nominal());
71  }
72 
73  if (eta_nominal() < eta_min() || eta_nominal() > eta_max())
74  set_eta_nominal(0.5 * (eta_min() + eta_max()));
75 }
76 
80 }
81 
83  set_Ekin(*m_chain[0]);
84 
85  for (const auto &param : m_chain) {
86  if (param->Ekin_min() < Ekin_min())
87  set_Ekin_min(param->Ekin_min());
88  if (param->Ekin_max() > Ekin_max())
89  set_Ekin_max(param->Ekin_max());
90  if (Ekin_nominal() < Ekin_min() || Ekin_nominal() > Ekin_max())
91  set_Ekin_nominal(param->Ekin_nominal());
92  }
93 
94  if (Ekin_nominal() < Ekin_min() || Ekin_nominal() > Ekin_max())
95  set_Ekin_nominal(0.5 * (Ekin_min() + Ekin_max()));
96 }
97 
99  set_eta(*m_chain[0]);
100 
101  for (const auto &param : m_chain) {
102  if (param->eta_min() < eta_min())
103  set_eta_min(param->eta_min());
104  if (param->eta_max() > eta_max())
105  set_eta_max(param->eta_max());
106  if (eta_nominal() < eta_min() || eta_nominal() > eta_max())
107  set_eta_nominal(param->eta_nominal());
108  }
109 
110  if (eta_nominal() < eta_min() || eta_nominal() > eta_max())
111  set_eta_nominal(0.5 * (eta_min() + eta_max()));
112 }
113 
117 }
118 
120  clear();
121  if (m_chain.empty())
122  return;
123 
126 
127  m_chain.shrink_to_fit();
128 }
129 
131  for (const auto &param : m_chain)
132  if (!param->is_match_Ekin_bin(Ekin_bin))
133  return false;
134  return true;
135 }
136 
138  for (const auto &param : m_chain)
139  if (!param->is_match_calosample(calosample))
140  return false;
141  return true;
142 }
143 
145  TFCSSimulationState &simulstate, const TFCSTruthState *truth,
146  const TFCSExtrapolationState *extrapol) const {
147  Int_t retry = 0;
148  Int_t retry_warning = 1;
149 
151  for (int i = 0; i <= retry; i++) {
152  if (i >= retry_warning)
154  "TFCSParametrizationChain::simulate(): Retry simulate call "
155  << i << "/" << retry);
156  for (const auto &param : m_chain) {
157  status = simulate_and_retry(param, simulstate, truth, extrapol);
158 
159  if (status >= FCSRetry) {
160  retry = status - FCSRetry;
161  retry_warning = retry >> 1;
162  if (retry_warning < 1)
163  retry_warning = 1;
164  break;
165  }
166  if (status == FCSFatal)
167  return FCSFatal;
168  }
169 
170  if (status == FCSSuccess)
171  break;
172  }
173 
174  if (status != FCSSuccess) {
176  "TFCSParametrizationChain::simulate(): Simulate call failed after "
177  << retry << " retries");
178  return FCSFatal;
179  }
180 
181  return FCSSuccess;
182 }
183 
184 void TFCSParametrizationChain::Print(Option_t *option) const {
186  TString opt(option);
187  // bool shortprint=opt.Index("short")>=0;
188  // bool longprint=msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
189 
190  char count = 'A';
191  for (const auto &param : m_chain) {
192  param->Print(opt + count + ' ');
193  count++;
194  }
195 }
196 
197 void TFCSParametrizationChain::Streamer(TBuffer &R__b) {
198  // Stream an object of class TFCSParametrizationChain.
199 
200  UInt_t R__s, R__c;
201  TDirectory *dir = nullptr;
202 
203  if (R__b.IsReading()) {
204  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
205  if (R__v == 1) {
206  R__b.SetBufferOffset(R__s);
207  R__b.ReadClassBuffer(TFCSParametrizationChain::Class(), this);
208  } else {
209  TFCSParametrization::Streamer(R__b);
210 
211  TObject *parent = R__b.GetParent();
212  if (R__b.GetParent()) {
213  if (parent->InheritsFrom(TDirectory::Class())) {
214  dir = (TDirectory *)parent;
215  }
216  }
217 
219  R__stl.clear();
220  TClass *R__tcl1 = TFCSParametrizationBase::Class();
221  if (R__tcl1 == nullptr) {
222  Error("m_chain streamer",
223  "Missing the TClass object for class TFCSParametrizationBase *!");
224  return;
225  }
226  int R__i, R__n;
227  R__b >> R__n;
228  R__stl.reserve(R__n);
229  for (R__i = 0; R__i < R__n; R__i++) {
230  std::unique_ptr<TFCSParametrizationBase> R__t;
231  R__t.reset((TFCSParametrizationBase *)R__b.ReadObjectAny(R__tcl1));
232  if (R__t != nullptr) {
233  if (R__t->InheritsFrom(TFCSParametrizationPlaceholder::Class())) {
234  std::unique_ptr<TFCSParametrizationBase> new_R__t = nullptr;
235 
236  if (dir) {
237  new_R__t.reset(
238  (TFCSParametrizationBase *)dir->Get(R__t->GetName()));
239  }
240 
241  if (new_R__t) {
242  R__t = std::move(new_R__t);
243  } else {
244  Error("TFCSParametrizationChain::Streamer",
245  "Found placeholder object in the parametrization chain, "
246  "but could not read the real object from the file!");
247  }
248  }
249  }
250  R__stl.emplace_back(R__t.release());
251  }
252 
253  R__b.CheckByteCount(R__s, R__c, TFCSParametrizationChain::IsA());
254  }
255  } else {
256  R__c = R__b.WriteVersion(TFCSParametrizationChain::IsA(), kTRUE);
257  TFCSParametrization::Streamer(R__b);
258 
259  if (SplitChainObjects()) {
260  TObject *parent = R__b.GetParent();
261  if (R__b.GetParent()) {
262  if (parent->InheritsFrom(TDirectory::Class())) {
263  dir = (TDirectory *)parent;
264  }
265  }
266  }
267 
269  int R__n = int(R__stl.size());
270  R__b << R__n;
271  if (R__n) {
273  for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
274  TFCSParametrizationBase *R__t = *R__k; // Ownership stays with m_chain
275  if (dir && R__t != nullptr) {
276  dir->WriteTObject(R__t);
277  TFCSParametrizationPlaceholder tmp( R__t->GetName(), TString("Placeholder for: ") + R__t->GetTitle());
278  R__b.WriteObject( &tmp, false ); // tell R__b object with same address are actually different
279  } else {
280  R__b.WriteObject( R__t );
281  }
282  }
283  }
284  R__b.SetByteCount(R__c, kTRUE);
285  }
286 }
287 
289  TFCSSimulationState *simulstate, const TFCSTruthState *truth,
292  if (!simulstate)
293  simulstate = new TFCSSimulationState();
294  if (!truth)
295  truth = new TFCSTruthState();
296  if (!extrapol)
298 
299  TFCSParametrizationChain chain("chain", "chain");
300  chain.setLevel(MSG::DEBUG);
301 
302  ATH_MSG_NOCLASS(logger, "==== Chain setup ====");
303  chain.Print();
304  ATH_MSG_NOCLASS(logger, "==== Simulate with empty chain ====");
305  chain.simulate(*simulstate, truth, extrapol);
306  ATH_MSG_NOCLASS(logger, "===================================" << std::endl);
307 
309  param = new TFCSInvisibleParametrization("A begin all", "A begin all");
310  param->setLevel(MSG::VERBOSE);
311  chain.push_back(param);
312  param = new TFCSParametrization("A end all", "A end all");
313  param->setLevel(MSG::DEBUG);
314  chain.push_back(param);
315 
316  ATH_MSG_NOCLASS(logger, "==== Chain setup ====");
317  chain.Print();
318  ATH_MSG_NOCLASS(logger, "==== Simulate only begin/end all ====");
319  chain.simulate(*simulstate, truth, extrapol);
321  "==== Simulate only begin/end all with chain retry====");
322  chain.set_RetryChainFromStart();
323  chain.simulate(*simulstate, truth, extrapol);
324  chain.reset_RetryChainFromStart();
325  ATH_MSG_NOCLASS(logger, "===================================" << std::endl);
326 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TFCSParametrizationChain
Definition: TFCSParametrizationChain.h:10
TFCSParametrization::set_Ekin_nominal
virtual void set_Ekin_nominal(double min)
Definition: TFCSParametrization.cxx:39
TFCSParametrizationChain::recalc
virtual void recalc()
Default is to call recalc_pdgid_intersect() and recalc_Ekin_eta_intersect()
Definition: TFCSParametrizationChain.cxx:119
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
TFCSParametrization::pdgid
const std::set< int > & pdgid() const override
Definition: TFCSParametrization.h:34
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TFCSParametrizationChain::is_match_Ekin_bin
virtual bool is_match_Ekin_bin(int Ekin_bin) const override
Definition: TFCSParametrizationChain.cxx:130
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
TFCSParametrizationChain::Chain_t
std::vector< TFCSParametrizationBase * > Chain_t
Definition: TFCSParametrizationChain.h:38
TFCSParametrizationChain::Print
void Print(Option_t *option="") const override
Definition: TFCSParametrizationChain.cxx:184
TFCSParametrization::Ekin_max
double Ekin_max() const override
Definition: TFCSParametrization.h:37
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
TFCSParametrizationChain::recalc_eta_intersect
void recalc_eta_intersect()
Definition: TFCSParametrizationChain.cxx:61
TFCSParametrizationChain::recalc_Ekin_union
void recalc_Ekin_union()
Definition: TFCSParametrizationChain.cxx:82
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TFCSParametrization::set_Ekin_max
virtual void set_Ekin_max(double max)
Definition: TFCSParametrization.cxx:45
TFCSParametrizationChain.h
TFCSParametrization::eta_nominal
double eta_nominal() const override
Definition: TFCSParametrization.h:38
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
RunActsMaterialValidation.extrapol
extrapol
Definition: RunActsMaterialValidation.py:91
TFCSParametrization::set_Ekin
virtual void set_Ekin(const TFCSParametrizationBase &ref)
Definition: TFCSParametrization.cxx:55
TFCSParametrization::set_eta
virtual void set_eta(const TFCSParametrizationBase &ref)
Definition: TFCSParametrization.cxx:61
TFCSParametrizationChain::recalc_eta_union
void recalc_eta_union()
Definition: TFCSParametrizationChain.cxx:98
TFCSParametrization::set_eta_max
virtual void set_eta_max(double max)
Definition: TFCSParametrization.cxx:53
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
FCSRetry
@ FCSRetry
Definition: TFCSParametrizationBase.h:41
TFCSParametrizationChain::simulate
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
Definition: TFCSParametrizationChain.cxx:144
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TFCSParametrization::set_pdgid
virtual void set_pdgid(int id)
Definition: TFCSParametrization.cxx:28
TFCSParametrizationBase
Definition: TFCSParametrizationBase.h:46
set_union
Set * set_union(Set *set1, Set *set2)
Perform a union of two sets.
TFCSParametrization::set_Ekin_min
virtual void set_Ekin_min(double min)
Definition: TFCSParametrization.cxx:43
TFCSParametrizationPlaceholder
Definition: TFCSParametrizationPlaceholder.h:10
lumiFormat.i
int i
Definition: lumiFormat.py:85
TFCSParametrizationChain::chain
const Chain_t & chain() const
Definition: TFCSParametrizationChain.h:53
TFCSParametrization::TFCSParametrization
TFCSParametrization(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSParametrization.cxx:12
TFCSParametrizationChain::is_match_calosample
virtual bool is_match_calosample(int calosample) const override
Definition: TFCSParametrizationChain.cxx:137
TFCSParametrizationChain::recalc_pdgid_intersect
void recalc_pdgid_intersect()
Definition: TFCSParametrizationChain.cxx:20
TFCSParametrizationChain::recalc_Ekin_intersect
void recalc_Ekin_intersect()
Definition: TFCSParametrizationChain.cxx:45
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TFCSParametrization::Ekin_min
double Ekin_min() const override
Definition: TFCSParametrization.h:36
TFCSParametrizationBase::Print
void Print(Option_t *option="") const
Print object information.
Definition: TFCSParametrizationBase.cxx:52
FCSFatal
@ FCSFatal
Definition: TFCSParametrizationBase.h:41
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
FCSSuccess
@ FCSSuccess
Definition: TFCSParametrizationBase.h:41
TFCSParametrization::eta_max
double eta_max() const override
Definition: TFCSParametrization.h:40
beamspotman.dir
string dir
Definition: beamspotman.py:623
TFCSParametrization::eta_min
double eta_min() const override
Definition: TFCSParametrization.h:39
TFCSParametrization::set_eta_nominal
virtual void set_eta_nominal(double min)
Definition: TFCSParametrization.cxx:47
ISF_FCS::MLogging::setLevel
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
Definition: MLogging.cxx:105
TFCSParametrization::clear
void clear()
Definition: TFCSParametrization.cxx:18
TFCSInvisibleParametrization
Definition: TFCSInvisibleParametrization.h:10
TFCSParametrizationPlaceholder.h
TFCSParametrizationChain::recalc_pdgid_union
void recalc_pdgid_union()
Definition: TFCSParametrizationChain.cxx:33
TFCSTruthState.h
ATH_MSG_NOCLASS
#define ATH_MSG_NOCLASS(logger_name, x)
Definition: MLogging.h:52
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TFCSExtrapolationState.h
TFCSParametrizationChain::SplitChainObjects
bool SplitChainObjects() const
Definition: TFCSParametrizationChain.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
TFCSParametrizationChain::simulate_and_retry
FCSReturnCode simulate_and_retry(TFCSParametrizationBase *parametrization, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
TFCSInvisibleParametrization.h
TFCSParametrizationChain::m_chain
Chain_t m_chain
Definition: TFCSParametrizationChain.h:99
TFCSParametrization::Ekin_nominal
double Ekin_nominal() const override
Definition: TFCSParametrization.h:35
TFCSParametrizationChain::recalc_Ekin_eta_intersect
void recalc_Ekin_eta_intersect()
Definition: TFCSParametrizationChain.cxx:77
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
TFCSParametrization::set_eta_min
virtual void set_eta_min(double min)
Definition: TFCSParametrization.cxx:51
merge.status
status
Definition: merge.py:17
TFCSSimulationState.h
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TFCSParametrizationChain::unit_test
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
Definition: TFCSParametrizationChain.cxx:288
set_intersection
Set * set_intersection(Set *set1, Set *set2)
Perform an intersection of two sets.
TFCSParametrizationChain::recalc_Ekin_eta_union
void recalc_Ekin_eta_union()
Definition: TFCSParametrizationChain.cxx:114
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14