ATLAS Offline Software
TFCSParametrizationEkinSelectChain.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CLHEP/Random/RandFlat.h"
6 
12 
13 #include <iostream>
14 
15 //=============================================
16 //======= TFCSParametrizationEkinSelectChain =========
17 //=============================================
18 
20  clear();
21  if (size() == 0)
22  return;
23 
27 
28  chain().shrink_to_fit();
29 }
30 
32  TFCSParametrizationBase *param) {
33  push_back_in_bin(param, param->Ekin_min(), param->Ekin_max());
34 }
35 
37  TFCSSimulationState &simulstate, const TFCSTruthState *truth,
38  const TFCSExtrapolationState *) const {
39  if (!simulstate.randomEngine()) {
40  return -1;
41  }
42 
43  float Ekin = truth->Ekin();
44  int bin = val_to_bin(Ekin);
45 
46  if (!DoRandomInterpolation())
47  return bin;
48  float rnd = CLHEP::RandFlat::shoot(simulstate.randomEngine());
49  if (bin < 0)
50  return bin;
51  if (bin >= (int)get_number_of_bins())
52  return bin;
53 
54  // if no parametrizations for this bin, return
55  if (m_bin_start[bin + 1] == m_bin_start[bin])
56  return bin;
57 
58  TFCSParametrizationBase *first_in_bin = chain()[m_bin_start[bin]];
59  if (!first_in_bin)
60  return bin;
61 
62  if (Ekin < first_in_bin->Ekin_nominal()) {
63  if (bin == 0)
64  return bin;
65  int prevbin = bin - 1;
66  // if no parametrizations for previous bin, return
67  if (m_bin_start[prevbin + 1] == m_bin_start[prevbin])
68  return bin;
69 
70  TFCSParametrizationBase *first_in_prevbin = chain()[m_bin_start[prevbin]];
71  if (!first_in_prevbin)
72  return bin;
73 
74  float logEkin = TMath::Log(Ekin);
75  float logEkin_nominal = TMath::Log(first_in_bin->Ekin_nominal());
76  float logEkin_previous = TMath::Log(first_in_prevbin->Ekin_nominal());
77  float numerator = logEkin - logEkin_previous;
78  float denominator = logEkin_nominal - logEkin_previous;
79  if (denominator <= 0)
80  return bin;
81 
82  if (numerator / denominator < rnd)
83  bin = prevbin;
84  ATH_MSG_DEBUG("logEkin="
85  << logEkin << " logEkin_previous=" << logEkin_previous
86  << " logEkin_nominal=" << logEkin_nominal
87  << " (rnd=" << 1 - rnd
88  << " < p(previous)=" << (1 - numerator / denominator)
89  << ")? => orgbin=" << prevbin + 1 << " selbin=" << bin);
90  } else {
91  if (bin == (int)get_number_of_bins() - 1)
92  return bin;
93  int nextbin = bin + 1;
94  // if no parametrizations for previous bin, return
95  if (m_bin_start[nextbin + 1] == m_bin_start[nextbin])
96  return bin;
97 
98  TFCSParametrizationBase *first_in_nextbin = chain()[m_bin_start[nextbin]];
99  if (!first_in_nextbin)
100  return bin;
101 
102  float logEkin = TMath::Log(Ekin);
103  float logEkin_nominal = TMath::Log(first_in_bin->Ekin_nominal());
104  float logEkin_next = TMath::Log(first_in_nextbin->Ekin_nominal());
105  float numerator = logEkin - logEkin_nominal;
106  float denominator = logEkin_next - logEkin_nominal;
107  if (denominator <= 0)
108  return bin;
109 
110  if (rnd < numerator / denominator)
111  bin = nextbin;
112  ATH_MSG_DEBUG("logEkin="
113  << logEkin << " logEkin_nominal=" << logEkin_nominal
114  << " logEkin_next=" << logEkin_next << " (rnd=" << rnd
115  << " < p(next)=" << numerator / denominator
116  << ")? => orgbin=" << nextbin - 1 << " selbin=" << bin);
117  }
118 
119  return bin;
120 }
121 
123  TFCSSimulationState &, const TFCSTruthState *truth,
124  const TFCSExtrapolationState *) const {
125  return std::string(Form("Ekin=%1.1f", truth->Ekin()));
126 }
127 
128 const std::string
130  if (bin == -1 || bin >= (int)get_number_of_bins()) {
131  return std::string(Form("bin=%d not in [%1.1f<=Ekin<%1.1f)", bin,
132  m_bin_low_edge[0],
134  }
135  if (DoRandomInterpolation()) {
136  return std::string(Form("bin=%d, %1.1f<=Ekin(+random)<%1.1f", bin,
138  }
139  return std::string(Form("bin=%d, %1.1f<=Ekin<%1.1f", bin, m_bin_low_edge[bin],
140  m_bin_low_edge[bin + 1]));
141 }
142 
144  TFCSSimulationState *simulstate, TFCSTruthState *truth,
147  if (!simulstate)
148  simulstate = new TFCSSimulationState();
149  if (!truth)
150  truth = new TFCSTruthState();
151  if (!extrapol)
153 
154  TFCSParametrizationEkinSelectChain chain("chain", "chain");
155  chain.setLevel(MSG::DEBUG);
156 
157  TFCSParametrization *param;
158  param = new TFCSInvisibleParametrization("A begin all", "A begin all");
159  param->setLevel(MSG::DEBUG);
160  param->set_Ekin_nominal(2);
161  param->set_Ekin_min(2);
162  param->set_Ekin_max(5);
163  chain.push_before_first_bin(param);
164  param = new TFCSInvisibleParametrization("A end all", "A end all");
165  param->setLevel(MSG::DEBUG);
166  param->set_Ekin_nominal(2);
167  param->set_Ekin_min(2);
168  param->set_Ekin_max(5);
169  chain.push_back(param);
170 
171  const int n_params = 5;
172  for (int i = 2; i < n_params; ++i) {
173  param = new TFCSInvisibleParametrization(Form("A%d", i), Form("A %d", i));
174  param->setLevel(MSG::DEBUG);
175  param->set_Ekin_nominal(TMath::Power(2.0, i));
176  param->set_Ekin_min(TMath::Power(2.0, i - 0.5));
177  param->set_Ekin_max(TMath::Power(2.0, i + 0.5));
178  chain.push_back_in_bin(param);
179  }
180  for (int i = n_params; i >= 1; --i) {
181  param = new TFCSInvisibleParametrization(Form("B%d", i), Form("B %d", i));
182  param->setLevel(MSG::DEBUG);
183  param->set_Ekin_nominal(TMath::Power(2.0, i));
184  param->set_Ekin_min(TMath::Power(2.0, i - 0.5));
185  param->set_Ekin_max(TMath::Power(2.0, i + 0.5));
186  chain.push_back_in_bin(param);
187  }
188 
189  ATH_MSG_NOCLASS(logger, "==== Chain setup ====");
190  chain.Print();
191 
192  param = new TFCSInvisibleParametrization("B end all", "B end all");
193  param->setLevel(MSG::DEBUG);
194  chain.push_back(param);
195  param = new TFCSInvisibleParametrization("B begin all", "B begin all");
196  param->setLevel(MSG::DEBUG);
197  chain.push_before_first_bin(param);
198 
199  ATH_MSG_NOCLASS(logger, "==== Chain setup ====");
200  chain.Print();
201  ATH_MSG_NOCLASS(logger, "==== Simulate with E=0.3 ====");
202  truth->SetPtEtaPhiM(0.3, 0, 0, 0);
203  chain.simulate(*simulstate, truth, extrapol);
204  for (double E = 1; E < 10.1; E += 1) {
205  ATH_MSG_NOCLASS(logger, "==== Simulate with E=" << E << " ====");
206  truth->SetPtEtaPhiM(E, 0, 0, 0);
207  chain.simulate(*simulstate, truth, extrapol);
208  }
209  ATH_MSG_NOCLASS(logger, "==== Simulate with E=100 ====");
210  truth->SetPtEtaPhiM(100, 0, 0, 0);
211  chain.simulate(*simulstate, truth, extrapol);
212  ATH_MSG_NOCLASS(logger, "===================================" << std::endl);
213  ATH_MSG_NOCLASS(logger, "====== now with random bin ========" << std::endl);
214  chain.set_DoRandomInterpolation();
215  for (double E = 15; E < 35.1; E += 4) {
216  ATH_MSG_NOCLASS(logger, "==== Simulate with E=" << E << " ====");
217  truth->SetPtEtaPhiM(E, 0, 0, 0);
218  for (int i = 0; i < 10; ++i)
219  chain.simulate(*simulstate, truth, extrapol);
220  }
221  ATH_MSG_NOCLASS(logger, "===================================" << std::endl);
222 }
TFCSParametrization::set_Ekin_nominal
virtual void set_Ekin_nominal(double min)
Definition: TFCSParametrization.cxx:39
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
TFCSParametrizationEkinSelectChain::recalc
virtual void recalc() override
Default is to call recalc_pdgid_intersect() and recalc_Ekin_eta_intersect()
Definition: TFCSParametrizationEkinSelectChain.cxx:19
TFCSParametrizationEkinSelectChain::push_back_in_bin
virtual void push_back_in_bin(TFCSParametrizationBase *param)
Definition: TFCSParametrizationEkinSelectChain.cxx:31
TFCSParametrizationChain::recalc_eta_intersect
void recalc_eta_intersect()
Definition: TFCSParametrizationChain.cxx:61
TFCSParametrizationEkinSelectChain::unit_test
static void unit_test(TFCSSimulationState *simulstate=nullptr, TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
Definition: TFCSParametrizationEkinSelectChain.cxx:143
TFCSParametrizationChain::recalc_Ekin_union
void recalc_Ekin_union()
Definition: TFCSParametrizationChain.cxx:82
bin
Definition: BinsDiffFromStripMedian.h:43
TFCSParametrization::set_Ekin_max
virtual void set_Ekin_max(double max)
Definition: TFCSParametrization.cxx:45
TFCSParametrizationBase::Ekin_nominal
virtual double Ekin_nominal() const
Definition: TFCSParametrizationBase.h:76
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
TFCSSimulationState::randomEngine
CLHEP::HepRandomEngine * randomEngine()
Definition: TFCSSimulationState.h:36
RunActsMaterialValidation.extrapol
extrapol
Definition: RunActsMaterialValidation.py:90
TFCSParametrizationEkinSelectChain::DoRandomInterpolation
bool DoRandomInterpolation() const
Definition: TFCSParametrizationEkinSelectChain.h:32
TFCSParametrizationEkinSelectChain::get_variable_text
virtual const std::string get_variable_text(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
Definition: TFCSParametrizationEkinSelectChain.cxx:122
TFCSParametrizationBase
Definition: TFCSParametrizationBase.h:46
TFCSParametrizationBinnedChain::get_number_of_bins
virtual unsigned int get_number_of_bins() const
Definition: TFCSParametrizationBinnedChain.h:22
TFCSParametrization::set_Ekin_min
virtual void set_Ekin_min(double min)
Definition: TFCSParametrization.cxx:43
TFCSParametrizationBase::Ekin_max
virtual double Ekin_max() const
Definition: TFCSParametrizationBase.h:78
lumiFormat.i
int i
Definition: lumiFormat.py:85
TFCSParametrizationChain::chain
const Chain_t & chain() const
Definition: TFCSParametrizationChain.h:53
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TFCSTruthState::Ekin
double Ekin() const
Definition: TFCSTruthState.h:26
TFCSParametrizationChain::recalc_pdgid_intersect
void recalc_pdgid_intersect()
Definition: TFCSParametrizationChain.cxx:20
TFCSParametrizationEkinSelectChain.h
TFCSParametrizationEkinSelectChain
Definition: TFCSParametrizationEkinSelectChain.h:12
ReadTripsProbsFromCool.denominator
denominator
Definition: ReadTripsProbsFromCool.py:96
TFCSParametrizationBase::Ekin_min
virtual double Ekin_min() const
Definition: TFCSParametrizationBase.h:77
TFCSParametrization
Definition: TFCSParametrization.h:10
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
ISF_FCS::MLogging::setLevel
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
Definition: MLogging.cxx:105
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
TFCSParametrization::clear
void clear()
Definition: TFCSParametrization.cxx:18
TFCSParametrizationFloatSelectChain::val_to_bin
int val_to_bin(float val) const
Definition: TFCSParametrizationFloatSelectChain.cxx:92
TFCSInvisibleParametrization
Definition: TFCSInvisibleParametrization.h:10
TFCSTruthState.h
ATH_MSG_NOCLASS
#define ATH_MSG_NOCLASS(logger_name, x)
Definition: MLogging.h:52
TFCSExtrapolationState.h
DEBUG
#define DEBUG
Definition: page_access.h:11
TFCSInvisibleParametrization.h
TFCSParametrizationEkinSelectChain::get_bin
virtual int get_bin(TFCSSimulationState &, const TFCSTruthState *truth, const TFCSExtrapolationState *) const override
this method should determine in derived classes which bin to simulate, so that the simulate method ca...
Definition: TFCSParametrizationEkinSelectChain.cxx:36
TFCSParametrization::Ekin_nominal
double Ekin_nominal() const override
Definition: TFCSParametrization.h:35
TFCSParametrizationEkinSelectChain::get_bin_text
virtual const std::string get_bin_text(int bin) const override
print the range of a bin; for bin -1, print the allowed range
Definition: TFCSParametrizationEkinSelectChain.cxx:129
TFCSSimulationState.h
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32
TFCSParametrizationFloatSelectChain::m_bin_low_edge
std::vector< float > m_bin_low_edge
Definition: TFCSParametrizationFloatSelectChain.h:41
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
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