ATLAS Offline Software
TFCSParametrizationBinnedChain.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include <algorithm>
11 #include <iterator>
12 #include <iostream>
13 
14 //=============================================
15 //======= TFCSParametrizationBinnedChain =========
16 //=============================================
17 
19  TFCSParametrizationBase *param) {
20  if (m_bin_start[0] == size()) {
21  chain().push_back(param);
22  } else {
24  chain().insert(it, param);
25  }
26  for (auto &ele : m_bin_start)
27  ele++;
28  recalc();
29 }
30 
32  TFCSParametrizationBase *param, unsigned int bin) {
33  if (m_bin_start.size() <= bin + 1) {
34  m_bin_start.resize(bin + 2, m_bin_start.back());
35  m_bin_start.shrink_to_fit();
36  }
37  if (m_bin_start[bin + 1] == size()) {
38  chain().push_back(param);
39  } else {
41  chain().insert(it, param);
42  }
43  for (unsigned int ibin = bin + 1; ibin < m_bin_start.size(); ++ibin)
44  m_bin_start[ibin]++;
45  recalc();
46 }
47 
50  const TFCSExtrapolationState *) const {
51  return 0;
52 }
53 
56  const TFCSExtrapolationState *) const {
57  return std::string("NO VARIABLE DEFINED");
58 }
59 
60 const std::string TFCSParametrizationBinnedChain::get_bin_text(int bin) const {
61  return std::string(Form("bin %d", bin));
62 }
63 
65  TFCSSimulationState &simulstate, const TFCSTruthState *truth,
66  const TFCSExtrapolationState *extrapol) const {
67  Int_t retry = 0;
68  Int_t retry_warning = 1;
69 
71  for (int i = 0; i <= retry; i++) {
72  if (i >= retry_warning)
74  "TFCSParametrizationBinnedChain::simulate(): Retry simulate call "
75  << i << "/" << retry);
76 
77  for (unsigned int ichain = 0; ichain < m_bin_start[0]; ++ichain) {
78  ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
79  status = simulate_and_retry(chain()[ichain], simulstate, truth, extrapol);
80  if (status >= FCSRetry) {
81  retry = status - FCSRetry;
82  retry_warning = retry >> 1;
83  if (retry_warning < 1)
84  retry_warning = 1;
85  break;
86  }
87  if (status == FCSFatal)
88  return FCSFatal;
89  }
90  if (status >= FCSRetry)
91  continue;
92 
93  if (get_number_of_bins() > 0) {
94  const int bin = get_bin(simulstate, truth, extrapol);
95  if (bin >= 0 && bin < (int)get_number_of_bins()) {
96  for (unsigned int ichain = m_bin_start[bin];
97  ichain < m_bin_start[bin + 1]; ++ichain) {
98  ATH_MSG_DEBUG("for " << get_variable_text(simulstate, truth, extrapol)
99  << " run " << get_bin_text(bin) << ": "
100  << chain()[ichain]->GetName());
101  status =
102  simulate_and_retry(chain()[ichain], simulstate, truth, extrapol);
103  if (status >= FCSRetry) {
104  retry = status - FCSRetry;
105  retry_warning = retry >> 1;
106  if (retry_warning < 1)
107  retry_warning = 1;
108  break;
109  }
110  if (status == FCSFatal)
111  return FCSFatal;
112  }
113  } else {
114  ATH_MSG_WARNING("for " << get_variable_text(simulstate, truth, extrapol)
115  << ": " << get_bin_text(bin));
116  }
117  } else {
118  ATH_MSG_WARNING("no bins defined, is this intended?");
119  }
120  if (status >= FCSRetry)
121  continue;
122 
123  for (unsigned int ichain = m_bin_start.back(); ichain < size(); ++ichain) {
124  ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
125  status = simulate_and_retry(chain()[ichain], simulstate, truth, extrapol);
126  if (status >= FCSRetry) {
127  retry = status - FCSRetry;
128  retry_warning = retry >> 1;
129  if (retry_warning < 1)
130  retry_warning = 1;
131  break;
132  }
133  if (status == FCSFatal)
134  return FCSFatal;
135  }
136 
137  if (status == FCSSuccess)
138  break;
139  }
140 
141  if (status != FCSSuccess) {
142  ATH_MSG_FATAL("TFCSParametrizationBinnedChain::simulate(): Simulate call "
143  "failed after "
144  << retry << " retries");
145  return FCSFatal;
146  }
147 
148  return FCSSuccess;
149 }
150 
151 void TFCSParametrizationBinnedChain::Print(Option_t *option) const {
153  TString opt(option);
154  bool shortprint = opt.Index("short") >= 0;
155  bool longprint = msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
156  TString optprint = opt;
157  optprint.ReplaceAll("short", "");
158 
159  TString prefix = "- ";
160  for (unsigned int ichain = 0; ichain < size(); ++ichain) {
161  if (ichain == 0 && ichain != m_bin_start.front()) {
162  prefix = "> ";
163  if (longprint)
164  ATH_MSG_INFO(optprint << prefix << "Run for all bins");
165  }
166  for (unsigned int ibin = 0; ibin < get_number_of_bins(); ++ibin) {
167  if (ichain == m_bin_start[ibin]) {
168  if (ibin < get_number_of_bins() - 1)
169  if (ichain == m_bin_start[ibin + 1])
170  continue;
171  prefix = Form("%-2d", ibin);
172  if (longprint)
173  ATH_MSG_INFO(optprint << prefix << "Run for " << get_bin_text(ibin));
174  }
175  }
176  if (ichain == m_bin_start.back()) {
177  prefix = "< ";
178  if (longprint)
179  ATH_MSG_INFO(optprint << prefix << "Run for all bins");
180  }
181  chain()[ichain]->Print(opt + prefix);
182  }
183 }
184 
186  TFCSSimulationState *simulstate, const TFCSTruthState *truth,
189  if (!simulstate)
190  simulstate = new TFCSSimulationState();
191  if (!truth)
192  truth = new TFCSTruthState();
193  if (!extrapol)
195 
196  TFCSParametrizationBinnedChain chain("chain", "chain");
197  chain.setLevel(MSG::DEBUG);
198 
199  ATH_MSG_NOCLASS(logger, "==== Chain setup ====");
200  chain.Print();
201  ATH_MSG_NOCLASS(logger, "==== Simulate with empty chain ====");
202  chain.simulate(*simulstate, truth, extrapol);
203  ATH_MSG_NOCLASS(logger, "===================================" << std::endl);
204 
206  param = new TFCSInvisibleParametrization("A begin all", "A begin all");
207  param->setLevel(MSG::VERBOSE);
208  chain.push_before_first_bin(param);
209  param = new TFCSParametrization("A end all", "A end all");
210  param->setLevel(MSG::DEBUG);
211  chain.push_back(param);
212 
213  ATH_MSG_NOCLASS(logger, "==== Chain setup ====");
214  chain.Print();
215  ATH_MSG_NOCLASS(logger, "==== Simulate only begin/end all ====");
216  chain.simulate(*simulstate, truth, extrapol);
218  "==== Simulate only begin/end all with chain retry====");
219  chain.set_RetryChainFromStart();
220  chain.simulate(*simulstate, truth, extrapol);
221  chain.reset_RetryChainFromStart();
222  ATH_MSG_NOCLASS(logger, "===================================" << std::endl);
223 
224  for (int i = 0; i < 3; ++i) {
225  TFCSParametrizationBase *param =
226  new TFCSInvisibleParametrization(Form("A%d", i), Form("A %d", i));
227  param->setLevel(MSG::DEBUG);
228  chain.push_back_in_bin(param, i);
229  }
230 
231  for (int i = 3; i > 0; --i) {
232  TFCSParametrizationBase *param =
233  new TFCSInvisibleParametrization(Form("B%d", i), Form("B %d", i));
234  param->setLevel(MSG::DEBUG);
235  chain.push_back_in_bin(param, i);
236  }
237  param = new TFCSParametrization("B end all", "B end all");
238  param->setLevel(MSG::DEBUG);
239  chain.push_back(param);
240  param = new TFCSInvisibleParametrization("B begin all", "B begin all");
241  param->setLevel(MSG::VERBOSE);
242  chain.push_before_first_bin(param);
243 
244  ATH_MSG_NOCLASS(logger, "==== Chain setup ====");
245  chain.Print();
246  ATH_MSG_NOCLASS(logger, "==== Simulate with full chain ====");
247  chain.simulate(*simulstate, truth, extrapol);
249  "==== Simulate with full chain with chain retry ====");
250  chain.set_RetryChainFromStart();
251  chain.simulate(*simulstate, truth, extrapol);
252  chain.reset_RetryChainFromStart();
253  ATH_MSG_NOCLASS(logger, "===================================" << std::endl);
254 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
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
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
TFCSParametrizationBinnedChain::get_bin_text
virtual const std::string get_bin_text(int bin) const
print the range of a bin; for bin -1, print the allowed range
Definition: TFCSParametrizationBinnedChain.cxx:60
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
TFCSParametrizationBinnedChain::Print
void Print(Option_t *option="") const override
Definition: TFCSParametrizationBinnedChain.cxx:151
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TFCSParametrizationBinnedChain::push_back_in_bin
virtual void push_back_in_bin(TFCSParametrizationBase *param, unsigned int bin)
Definition: TFCSParametrizationBinnedChain.cxx:31
bin
Definition: BinsDiffFromStripMedian.h:43
TFCSParametrizationBinnedChain::push_before_first_bin
virtual void push_before_first_bin(TFCSParametrizationBase *param)
Definition: TFCSParametrizationBinnedChain.cxx:18
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
RunActsMaterialValidation.extrapol
extrapol
Definition: RunActsMaterialValidation.py:91
FCSRetry
@ FCSRetry
Definition: TFCSParametrizationBase.h:41
TFCSParametrizationBinnedChain::get_variable_text
virtual const std::string get_variable_text(TFCSSimulationState &, const TFCSTruthState *, const TFCSExtrapolationState *) const
Definition: TFCSParametrizationBinnedChain.cxx:54
TFCSParametrizationBinnedChain::get_bin
virtual int get_bin(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const
this method should determine in derived classes which bin to simulate, so that the simulate method ca...
Definition: TFCSParametrizationBinnedChain.cxx:48
TFCSParametrizationBinnedChain::unit_test
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
Definition: TFCSParametrizationBinnedChain.cxx:185
TFCSParametrizationBase
Definition: TFCSParametrizationBase.h:46
TFCSParametrizationBinnedChain::get_number_of_bins
virtual unsigned int get_number_of_bins() const
Definition: TFCSParametrizationBinnedChain.h:22
TFCSParametrizationBinnedChain
Definition: TFCSParametrizationBinnedChain.h:10
TFCSParametrizationBinnedChain.h
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
TFCSParametrizationBase::Print
void Print(Option_t *option="") const
Print object information.
Definition: TFCSParametrizationBase.cxx:52
FCSFatal
@ FCSFatal
Definition: TFCSParametrizationBase.h:41
FCSSuccess
@ FCSSuccess
Definition: TFCSParametrizationBase.h:41
ISF_FCS::MLogging::setLevel
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
Definition: MLogging.cxx:105
TFCSInvisibleParametrization
Definition: TFCSInvisibleParametrization.h:10
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
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
TFCSParametrizationBinnedChain::simulate
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
Definition: TFCSParametrizationBinnedChain.cxx:64
merge.status
status
Definition: merge.py:17
TFCSSimulationState.h
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
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
TFCSParametrizationBinnedChain::m_bin_start
std::vector< unsigned int > m_bin_start
Contains the index where the TFCSParametrizationBase* instances to run for a given bin start.
Definition: TFCSParametrizationBinnedChain.h:53
TFCSParametrizationChain::size
virtual unsigned int size() const override
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
Definition: TFCSParametrizationChain.h:41