ATLAS Offline Software
Loading...
Searching...
No Matches
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
20 if (m_bin_start[0] == size()) {
21 chain().push_back(param);
22 } else {
23 Chain_t::iterator it(&chain()[m_bin_start[0]]);
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 {
40 Chain_t::iterator it(&chain()[m_bin_start[bin + 1]]);
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
53
56 const TFCSExtrapolationState *) const {
57 return std::string("NO VARIABLE DEFINED");
58}
59
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
151void 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,
187 const TFCSExtrapolationState *extrapol) {
189 if (!simulstate)
190 simulstate = new TFCSSimulationState();
191 if (!truth)
192 truth = new TFCSTruthState();
193 if (!extrapol)
194 extrapol = new TFCSExtrapolationState();
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) {
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) {
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}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define ATH_MSG_NOCLASS(logger_name, x)
Definition MLogging.h:52
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Cut down AthMessaging.
Definition MLogging.h:176
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition MLogging.h:222
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
Definition MLogging.cxx:105
void Print(Option_t *option="") const
Print object information.
TFCSParametrizationBase(const char *name=nullptr, const char *title=nullptr)
virtual void push_before_first_bin(TFCSParametrizationBase *param)
virtual unsigned int get_number_of_bins() const
TFCSParametrizationBinnedChain(const char *name=nullptr, const char *title=nullptr)
std::vector< unsigned int > m_bin_start
Contains the index where the TFCSParametrizationBase* instances to run for a given bin start.
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
virtual void push_back_in_bin(TFCSParametrizationBase *param, unsigned int bin)
virtual const std::string get_variable_text(TFCSSimulationState &, const TFCSTruthState *, const TFCSExtrapolationState *) const
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
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...
virtual const std::string get_bin_text(int bin) const
print the range of a bin; for bin -1, print the allowed range
void Print(Option_t *option="") const override
FCSReturnCode simulate_and_retry(TFCSParametrizationBase *parametrization, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
const Chain_t & chain() const
virtual void recalc()
Default is to call recalc_pdgid_intersect() and recalc_Ekin_eta_intersect()
virtual unsigned int size() const override
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
TFCSParametrization(const char *name=nullptr, const char *title=nullptr)
static Root::TMsgLogger logger("iLumiCalc")