ATLAS Offline Software
Loading...
Searching...
No Matches
ZDCFitWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <numeric>
6#include <memory>
8
9const std::map<std::string, std::vector<ZDCFitWrapper::FitParameter>> ZDCFitExpFermiVariableTausInduct::s_ConfigParamMap =
10 {
11 {"default",
12 {{{"A", 1000, false, 2, 5000, 50, false, 0}},
13 {{"T0", 40, false, 0, 100, 2, false, 0}},
14 {{"tau1", 0, false, 0.5, 3, 0.05, false, 0}}, // default value set via JSON
15 {{"tau2", 0, false, 3.5, 8, 0.25, false, 0}}, // default value set via JSON
16 {{"C", 0, false, -50, 50, 1, true, 0}},
17 {{"period", 13.5, true, 10, 30, 0, false, 0}},
18 {{"IndA", 0.2, false, -2, 2, 0.1, false, 0}},
19 {{"IndB", 0.2, false, -2, 2, 0.1, false, 0}},
20 {{"bI", 0.18, false, -1, 1, 0.025, false, 0}},
21 {{"delta", 0.015, true, 0, 0, 0, false, 0}}}
22 },
23 {"PbPb2026",
24 {{{"period", 16, true, 0, 0, 0, false, 0}},
25 {{"IndA", 0.25, false, 0, 2, 0.1, false, 0}},
26 {{"IndB", 0.8, false, 0, 2, 0.1, false, 0}},
27 {{"bI", 0.18, false, -1, 1, 0.025, false, 0}},
28 {{"delta", 0.015, true, 0, 0, 0, false, 0}},
29 {{"C", 0, false, -50, 50, 1, true, 0}},
30 }
31 },
32 {"PbPb2025",
33 {{{"tau2", 0, false, 4, 7.5, 0.25, false, 0}}, // adjust the range
34 {{"period", 13, true, 0, 0, 0, false, 0}},
35 {{"IndA", -0.07, false, -0.1, 0.4, 0.025, true, 0.}},
36 {{"IndB", 0.1, false, -0.1, 0.4, 0.025, false, 0}},
37 {{"bI", -0.025, false, -0.15, 0.05, 0.025, true, -0.03}},
38 {{"C", 0, false, -50, 50, 1, false, 0}}, }
39 },
40 {"PbPb2025LG",
41 {{{"tau2", 6, false, 5, 8, 0.25, false, 0}}, // adjust the range
42 {{"period", 14, true, 10, 16, 1, false, 0}},
43 {{"IndA", 0.1, false, -0.1, 0.75, 0.1, true, 0}},
44 {{"IndB", 0.1, false, -0.25, 0.75, 0.1, false, 0}},
45 {{"bI", -0.02, false, -0.2, 0.2, 0.025, false, 0}},
46 }
47 },
48 {"PbPb2025FreeInduct",
49 {{{"period", 13, false, 11, 20, 1, true, 13}},
50 {{"IndA", 0.25, false, -0.05, 0.5, 0.1, true, 0}},
51 {{"IndB", 0.2, false, -0.2, 0.5, 0.1, false, 0}},
52 {{"bI", -0.025, false, -0.3, 0.3, 0, false, 0}},
53 }
54 },
55 {"PbPb2024",
56 {{{"period", 16, true, 0, 0, 0, false, 0}},
57 {{"IndA", 0.25, false, 0, 2, 0.1, false, 0}},
58 {{"IndB", 0.8, false, 0, 2, 0.1, false, 0}},
59 {{"bI", 0.018, true, 0, -0.5, 0.5, false, 0}},
60 {{"delta", 0.015, true, 0, 0, 0, false, 0}},
61 }
62 },
63 };
64
65const std::map<std::string, std::vector<ZDCFitWrapper::FitParameter>> ZDCFitExpFermiInductPreExp::s_ConfigParamMap =
66 {
67 {"default",
68 {{{"A", 1000, false, 2, 5000, 50, false, 0}},
69 {{"T0", 40, false, 0, 100, 1, false, 0}},
70 {{"Aexp", 0, false, 0, 4000, 0.05, false, 0}},
71 {{"tauexp", 0, false, 3.5, 8, 0.25, false, 0}},
72 {{"bsqrtexp", 0, false, -0.001, 0.001, 0.0001, true, 0}},
73 {{"C", 0, false, -50, 50, 1, true, 0}},
74 {{"period", 13.5, true, 0, 0, 0, false, 0}},
75 {{"IndA", 0.2, false, -2, 2, 0.1, false, 0}},
76 {{"IndB", 0.2, false, -2, 2, 0.1, false, 0}},
77 {{"bI", -0.02, true, -0.5, 0.5, 0.025, true, -0.02}}
78 }
79 },
80 {"PbPb2025",
81 {{{"period", 13, true, 0, 0, 0, false, 0}},
82 {{"IndA", 0.1, false, -0.1, 0.4, 0.05, true, 0}},
83 {{"IndB", 0.2, false, -0.1, 0.4, 0.05, false, 0}},
84 {{"bI", -0.05, true, -0.15, 0.15, 0.025, false, 0}},
85 {{"C", 0, false, -200, 200, 1, false, 0}},
86 }
87 },
88 {"PbPb2025LG",
89 {{{"period", 13, true, 0, 0, 0, false, 0}},
90 {{"IndA", 0.1, false, -0.1, 2, 0.1, true, 0}},
91 {{"IndB", 0.2, false, -0.1, 2, 0.1, false, 0}},
92 {{"bI", -0.04, true, -0.1, 0., 0.025, true, -0.02}},
93 {{"C", 0, false, -200, 200, 1, false, 0}},
94 }
95 },
96 {"PbPb2025FreeInduct",
97 {{{"period", 13, false, 10, 30, 1, true, 13}},
98 {{"IndA", 0., false, -0.1, 0.25, 0.1, true, 0}},
99 {{"IndB", 0.1, false, -0.1, 0.5, 0.1, false, 0}},
100 {{"bI", -0.025, false, -0.5, 0.5, 0, false, 0}},
101 {{"C", 0, false, -200, 200, 1, false, 0}},
102 }
103 }
104 };
105
106const std::map<std::string, std::vector<ZDCFitWrapper::FitParameter>> ZDCFitExpFermiInductPrePulse::s_ConfigParamMap =
107 {
108 {"default",
109 {{{"A", 1000, false, 2, 5000, 50, false, 0}},
110 {{"T0", 40, false, 0, 100, 1, false, 0}},
111 {{"Apre", 0, false, 0, 4000, 0.05, false, 0}},
112 {{"T0pre", 0, false, 3.5, 8, 0.25, false, 0}},
113 {{"C", 0, false, -50, 50, 1, true, 0}},
114 {{"period", 13.5, true, 0, 0, 0, false, 0}},
115 {{"IndA", 0.2, false, -2, 2, 0.1, false, 0}},
116 {{"IndB", 0.2, false, -2, 2, 0.1, false, 0}},
117 {{"bI", -0.02, true, -0.5, 0.5, 0.025, true, -0.02}}
118 }
119 },
120 {"PbPb2025",
121 {{{"period", 13, true, 0, 0, 0, false, 0}},
122 {{"IndA", 0.1, false, -0.25, 0.25, 0.1, true, 0}},
123 {{"IndB", 0.2, false, -0.25, 0.25, 0.1, false, 0}},
124 {{"bI", -0.05, true, -0.5, 0.5, 0.025, true, -0.02}},
125 }
126 },
127 {"PbPb2025LG",
128 {{{"period", 13, true, 0, 0, 0, false, 0}},
129 {{"IndA", 0.1, false, -0.25, 0.5, 0.1, true, 0}},
130 {{"IndB", 0.2, false, -0.25, 0.5, 0.1, false, 0}},
131 {{"bI", -0.04, false, -0.5, 0.5, 0.025, true, -0.02}},
132 }
133 },
134 {"PbPb2025FreeInduct",
135 {{{"period", 13, false, 10, 30, 1, true, 13}},
136 {{"IndA", 0.1, false, -0.25, 0.5, 0.1, true, 0}},
137 {{"IndB", 0.2, false, -0.25, 0.1, 0.1, false, 0}},
138 {{"bI", -0.025, false, -0.5, 0.5, 0, false, 0}},
139 }
140 }
141 };
142
144{
145 auto iter = std::find_if(m_parameterSet.begin(), m_parameterSet.end(),
146 [name](const FitParameter& parDesc){return parDesc.name() == name;});
147 if (iter == m_parameterSet.end()) throw std::logic_error("ZDCFitWrapper::GetParameterDescr: invalid parameter name: " + name );
148 return *iter;
149}
150
151void ZDCFitWrapper::LoadDefaultParameterSet(const std::vector<FitParameter>& parameterSet)
152{
153 // First step is to check consistency with number of parameters in TF1
154 //
155 if (int(parameterSet.size()) != m_wrapperTF1->GetNpar()) throw std::logic_error("ZDCFitWrapper::LoadDefaultParameterSet:: Incorrect number of parameters in default parameter set");
156
157 m_parameterSet = parameterSet;
158 m_haveParameterSet = true;
159
160 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
161
162 // Loop over passed descriptors
163 //
164 unsigned parIndex = 0;
165 for (const auto & parDescr : parameterSet) {
166 //
167 // Load the settings for this parameter in the TF1
168 //
169 std::string name = parDescr.name();
170 theTF1->SetParName(parIndex, name.c_str());
171
172 bool fixed = parDescr.fixed();
173
174 if (fixed) {
175 float fixedValue = parDescr.defaultValue();
176 theTF1->FixParameter(parIndex, fixedValue);
177 }
178 else {
179 float lowerLimit = parDescr.lowerLimit();
180 float upperLimit = parDescr.upperLimit();
181 theTF1->SetParLimits(parIndex, lowerLimit, upperLimit);
182 }
183
184 parIndex++;
185 }
186}
187
188void ZDCFitWrapper::OverrideParameterSet(const std::vector<FitParameter>& overParamSet)
189{
190 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
191
192 // Loop over the provided parameter descriptors
193 //
194 for (const auto & parDescr : overParamSet) {
195 std::string inputName = parDescr.name();
196
197 // Fit the parameter name in the current list
198 //
199 auto iter = std::find_if(m_parameterSet.begin(), m_parameterSet.end(),
200 [inputName](const FitParameter& parDesc){return parDesc.name() == inputName;});
201 if (iter == m_parameterSet.end()) throw std::logic_error("ZDCFitWrapper::OverrideParameterSet: invalid parameter name: " +inputName );
202
203 // Update the descriptor for this parameter
204 //
205 (*iter) = parDescr;
206
207 // Update the settings in the TF!
208 //
209 unsigned int parIndex = std::distance(m_parameterSet.begin(), iter);
210 bool fixed = parDescr.fixed();
211
212 if (fixed) {
213 float fixedValue = parDescr.defaultValue();
214 theTF1->FixParameter(parIndex, fixedValue);
215 }
216 else {
217 float lowerLimit = parDescr.lowerLimit();
218 float upperLimit = parDescr.upperLimit();
219 theTF1->SetParLimits(parIndex, lowerLimit, upperLimit);
220 }
221 }
222}
223
224void ZDCFitWrapper::Initialize(float initialAmp, float initialT0, float ampMin, float ampMax)
225{
226 // Clear the errors on the TF1 because retaining the errors seems to affect
227 // the convergence of fits
228 //
229 auto tf1_p = GetWrapperTF1();
230 unsigned int npar = tf1_p->GetNpar();
231 std::vector<double> zeroVec(npar, 0.0);
232 GetWrapperTF1()->SetParErrors(&zeroVec[0]);
233
234 // If we adjusted the time range on the previous event, restore to default
235 //
236 if (m_adjTLimitsEvent) {
238
239 m_adjTLimitsEvent = false;
240 m_tminAdjust = 0;
241 }
242
243 SetAmpMinMax(ampMin, ampMax);
244
245 //
246 // Do we have parameter sets?
247 //
248 if (m_haveParameterSet) {
249 for (unsigned int ipar = 0; ipar < m_parameterSet.size(); ipar++) {
250 //
251 // Yes, use parameter descriptors to initialize the TF1
252 //
253 const auto & fitparDescr = m_parameterSet[ipar];
254
255 if (!fitparDescr.fixed()) {
256 tf1_p->SetParameter(ipar, fitparDescr.defaultValue());
257 tf1_p->SetParError(ipar, fitparDescr.stepSize());
258 }
259 }
260
261 tf1_p->SetParameter(0, initialAmp);
262 tf1_p->SetParameter(1, initialT0);
263 }
264 else {
265 //
266 // No, perform the wrapper-implemented initialize
267 //
268 DoInitialize(initialAmp, initialT0, ampMin, ampMax);
269
270 // Clear the errors on the TF1 because retaining the errors seems to affect
271 // the convergence of fits
272 //
273 unsigned int npar = GetWrapperTF1()->GetNpar();
274 std::vector<double> zeroVec(npar, 0.0);
275 tf1_p->SetParErrors(&zeroVec[0]);
276
277 }
278}
279
280void ZDCFitWrapper::Initialize(float initialAmp, float initialT0, float ampMin, float ampMax, float fitTmin, float fitTmax, float fitTRef)
281{
282
283 // First do the nominal initializatioon
284 //
285 Initialize(initialAmp, initialT0, ampMin, ampMax);
286
287 // Now account for the modified time range
288 //
289 m_adjTLimitsEvent = true;
290
291 // Handle the specific limits on T0
292 //
293 m_tminAdjust = fitTRef; // Note: this is the time corresponding to the sample used for presample subtraction
294
295 m_tempTmin = std::max(m_t0Min, fitTmin);
296 m_tempTmax = std::min(m_t0Max, fitTmax);
297
298 SetAmpMinMax(ampMin, ampMax);
300}
301
303{
304 if (m_haveParameterSet) {
305 auto tf1_p = GetWrapperTF1();
306
307 for (unsigned int ipar = 2; ipar < m_parameterSet.size(); ipar++) {
308 const auto & fitparDescr = m_parameterSet[ipar];
309
310 if (!fitparDescr.fixed() && fitparDescr.constrainFixed()) {
311 tf1_p->FixParameter(ipar, fitparDescr.constrainValue());
312 }
313 }
314 }
315 else doConstrainFit();
316}
317
319{
320 if (m_haveParameterSet) {
321 auto tf1_p = GetWrapperTF1();
322
323 for (unsigned int ipar = 2; ipar < m_parameterSet.size(); ipar++) {
324 const auto & fitparDescr = m_parameterSet[ipar];
325
326 if (!fitparDescr.fixed() && fitparDescr.constrainFixed()) {
327 tf1_p->ReleaseParameter(ipar);
328 tf1_p->SetParameter(ipar, fitparDescr.defaultValue());
329
330 float lowerLimit = fitparDescr.lowerLimit();
331 float upperLimit = fitparDescr.upperLimit();
332 tf1_p->SetParLimits(ipar, lowerLimit, upperLimit);
333
334 tf1_p->SetParError(ipar, fitparDescr.stepSize());
335 }
336 }
337 }
338 else doUnconstrainFit();
339}
340
341ZDCFitExpFermiVariableTaus::ZDCFitExpFermiVariableTaus(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2) :
342 ZDCFitWrapper(std::make_shared<TF1>(("ExpFermiVariableTaus" + tag).c_str(), ZDCFermiExpFit, tmin, tmax, 5)),
343 m_fixTau1(fixTau1), m_fixTau2(fixTau2), m_tau1(tau1), m_tau2(tau2)
344{
345 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
346
347 theTF1->SetParName(0, "Amp");
348 theTF1->SetParName(1, "T0");
349 theTF1->SetParName(2, "tau1");
350 theTF1->SetParName(3, "tau2");
351 theTF1->SetParName(4, "C");
352
353 // BAC, parameter 0 limits now is set in DoInitialize
354 theTF1->SetParLimits(1, tmin, tmax);
355 theTF1->SetParLimits(2, 3, 6);
356 theTF1->SetParLimits(3, 10, 40);
357
358 if (m_fixTau1) theTF1->FixParameter(2, m_tau1);
359 if (m_fixTau2) theTF1->FixParameter(3, m_tau2);
360}
361
362void ZDCFitExpFermiVariableTaus::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
363{
364 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
365
366 theTF1->SetParameter(0, initialAmp);
367 theTF1->SetParameter(1, initialT0);
368 theTF1->SetParameter(4, 0);
369
370 theTF1->SetParLimits(0, ampMin, ampMax);
371
372 if (!m_fixTau1) theTF1->SetParameter(2, m_tau1);
373 if (!m_fixTau2) theTF1->SetParameter(3, m_tau2);
374}
375
376void ZDCFitExpFermiVariableTaus::SetT0FitLimits(float t0Min, float t0Max)
377{
378 // Set the parameter limits accordingly on the TF1
379 //
380 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
381 theTF1->SetParLimits(1, t0Min, t0Max);
382}
383
385{
386 // We force the constant terms to zero
387 //
388 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
389
390 theTF1->FixParameter(4, 0);
391}
393{
394 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
395 theTF1->ReleaseParameter(4);
396}
397
398ZDCFitExpFermiVariableTausRun3::ZDCFitExpFermiVariableTausRun3(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2) :
399 ZDCFitExpFermiVariableTaus(tag, tmin, tmax, fixTau1, fixTau2, tau1, tau2)
400{
401 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
402 theTF1->SetParLimits(2, 0.5, 3);
403 theTF1->SetParLimits(3, 4, 10);
404
405 // Since we st parameter ranges, we have to redo the fixing (or not) again here
406 //
407 if (m_fixTau1) theTF1->FixParameter(2, m_tau1);
408 if (m_fixTau2) theTF1->FixParameter(3, m_tau2);
409}
410
411
412ZDCFitExpFermiVariableTausLHCf::ZDCFitExpFermiVariableTausLHCf(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2) :
413 ZDCFitWrapper(std::make_shared<TF1>(("ExpFermiVariableTausLHCf" + tag).c_str(), ZDCFermiExpFitRefl, tmin, tmax, 9)),
414 m_fixTau1(fixTau1), m_fixTau2(fixTau2), m_tau1(tau1), m_tau2(tau2)
415{
416 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
417
418 theTF1->SetParName(0, "Amp");
419 theTF1->SetParName(1, "T0");
420 theTF1->SetParName(2, "tau1");
421 theTF1->SetParName(3, "tau2");
422 theTF1->SetParName(4, "C");
423 theTF1->SetParName(5, "refdelay");
424 theTF1->SetParName(6, "reflAmpFrac");
425 theTF1->SetParName(7, "reflWidth");
426 theTF1->SetParName(8, "delta");
427
428 theTF1->SetParLimits(1, tmin, tmax);
429 theTF1->SetParLimits(4, -100, 100);
430 theTF1->SetParLimits(6, -1e-4, 0.35);
431
432 theTF1->FixParameter(5, 6.5);
433 theTF1->FixParameter(7, 1.5);
434 theTF1->FixParameter(8, 0.01);
435
436 if (m_fixTau1) theTF1->FixParameter(2, m_tau1);
437 else theTF1->SetParLimits(2, 1, 2);
438
439 if (m_fixTau2) theTF1->FixParameter(3, m_tau2);
440 else theTF1->SetParLimits(3, 3.5, 6);
441}
442
443void ZDCFitExpFermiVariableTausLHCf::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
444{
445 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
446
447 theTF1->SetParameter(0, initialAmp);
448
449 float t0 = initialT0;
450 if (t0 < GetT0Min()) t0 = GetT0Min()*1.1;
451 if (t0 > GetT0Max()) t0 = GetT0Max()/1.1;
452 theTF1->SetParameter(1, t0);
453
454 theTF1->SetParameter(1, initialT0);
455 theTF1->SetParameter(4, 0);
456 theTF1->SetParameter(6, 0.1);
457
458 theTF1->SetParLimits(0, ampMin, ampMax);
459
460 if (!m_fixTau1) theTF1->SetParameter(2, m_tau1);
461 if (!m_fixTau2) theTF1->SetParameter(3, m_tau2);
462
463 // Set the parameter errors which ROOT now uses <<<to set the initial step sizes>>>
464 //
465 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
466
467 theTF1->SetParError(0, ampStep);
468 theTF1->SetParError(1, 1.0);
469
470 if (!m_fixTau1) theTF1->SetParError(2, 0.05);
471 if (!m_fixTau2) theTF1->SetParError(3, 0.25);
472
473 theTF1->SetParError(4, 2);
474 theTF1->SetParError(5, 0.25);
475 theTF1->SetParError(6, 0.05);
476}
477
479{
480 // Set the parameter limits accordingly on the TF1
481 //
482 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
483 theTF1->SetParLimits(1, t0Min, t0Max);
484}
485
487{
488 // We force the constant and reflection terms to zero
489 //
490 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
491
492 theTF1->FixParameter(4, 0);
493 theTF1->FixParameter(6, 0);
494}
496{
497 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
498 theTF1->ReleaseParameter(4);
499 theTF1->SetParameter(4, 0);
500
501 theTF1->ReleaseParameter(6);
502 theTF1->SetParLimits(6, -1e-4, 0.35);
503 theTF1->SetParameter(6, 0.1);
504}
505
506ZDCFitExpFermiVariableTausInduct::ZDCFitExpFermiVariableTausInduct(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2) :
507 ZDCFitWrapper(std::make_shared<TF1>(("ExpFermiVariableTausInduct" + tag).c_str(), ZDCFermiExpFitInduct, tmin, tmax, 10)),
508 m_fixTau1(fixTau1), m_fixTau2(fixTau2), m_tau1(tau1), m_tau2(tau2)
509{
510 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
511
512 theTF1->SetParName(0, "Amp");
513 theTF1->SetParName(1, "T0");
514 theTF1->SetParName(2, "tau1");
515 theTF1->SetParName(3, "tau2");
516 theTF1->SetParName(4, "C");
517 theTF1->SetParName(5, "period");
518 theTF1->SetParName(6, "IndA");
519 theTF1->SetParName(7, "IndB");
520 theTF1->SetParName(8, "tauI");
521 theTF1->SetParName(9, "delta");
522
523 theTF1->SetParLimits(1, tmin, tmax);
524 theTF1->SetParLimits(4, -50, 50);
525 theTF1->SetParLimits(5, 10, 50);
526 theTF1->SetParLimits(6, 0, 2);
527 theTF1->SetParLimits(7, 0, 2);
528 // theTF1->SetParLimits(8, 1, 6);
529 theTF1->FixParameter(8, 5.5);
530 theTF1->FixParameter(5, 16);
531 // theTF1->SetParLimits(9, 0, 0.05);
532
533 theTF1->SetNpx(1000);
534 FixDelta(0.015);
535
536 if (m_fixTau1) theTF1->FixParameter(2, m_tau1);
537 else theTF1->SetParLimits(2, 0.5, 3);
538
539 if (m_fixTau2) theTF1->FixParameter(3, m_tau2);
540 else theTF1->SetParLimits(3, 3.5, 8);
541}
542
543
544ZDCFitExpFermiVariableTausInduct::ZDCFitExpFermiVariableTausInduct(const std::string& tag, const std::string& paramSet, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2, float period = 0, float bI = -1) :
545 ZDCFitWrapper(std::make_shared<TF1>(("ExpFermiVariableTausInduct" + tag).c_str(), ZDCFermiExpFitInduct, tmin, tmax, 10),
546 s_ConfigParamMap.at("default"))
547{
548
549 auto iter = s_ConfigParamMap.find(paramSet);
550 if (iter == s_ConfigParamMap.end()) throw std::runtime_error("ZDCFitExpFermiVariableTausInduct:: invalid parameter set identifier: " + paramSet);
551
552 std::vector<ZDCFitWrapper::FitParameter> overRideParams = iter->second;
553
554 // Handle the JSON-based tau settings (this is ugly and temporary until we get the more general parameter overriding implemented)
555 //
556 auto tau1Iter = std::find_if(overRideParams.begin(), overRideParams.end(), [](const FitParameter& parDesc){return parDesc.name() == "tau1";});
557 if (tau1Iter != overRideParams.end()) {
558 if (fixTau1) tau1Iter->setFixed(tau1);
559 else tau1Iter->setDefaultValue(tau1);
560 }
561 else {
562 FitParameter tau1Descr = GetParameterDescr("tau1");
563 if (fixTau1) tau1Descr.setFixed(tau1);
564 else tau1Descr.setDefaultValue(tau1);
565 overRideParams.push_back(std::move(tau1Descr));
566 }
567
568 auto tau2Iter = std::find_if(overRideParams.begin(), overRideParams.end(), [](const FitParameter& parDesc){return parDesc.name() == "tau2";});
569 if (tau2Iter != overRideParams.end()) {
570 if (fixTau2) tau2Iter->setFixed(tau2);
571 else tau2Iter->setDefaultValue(tau2);
572 }
573 else {
574 FitParameter tau2Descr = GetParameterDescr("tau2");
575 if (fixTau2) tau2Descr.setFixed(tau2);
576 else tau2Descr.setDefaultValue(std::move(tau2));
577 overRideParams.push_back(std::move(tau2Descr));
578 }
579
580 if (period > 0) {
581 auto periodIter = std::find_if(overRideParams.begin(), overRideParams.end(), [](const FitParameter& parDesc){return parDesc.name() == "period";});
582 if (periodIter != overRideParams.end()) {
583 periodIter->setFixed(period);
584 }
585 else {
586 FitParameter periodDescr = GetParameterDescr("period");
587 periodDescr.setFixed(period);
588 overRideParams.push_back(std::move(periodDescr));
589 }
590 }
591
592 if (bI > -1) {
593 auto bIIter = std::find_if(overRideParams.begin(), overRideParams.end(), [](const FitParameter& parDesc){return parDesc.name() == "bI";});
594 if (bIIter != overRideParams.end()) {
595 bIIter->setFixed(bI);
596 }
597 else {
598 FitParameter bIDescr = GetParameterDescr("bI");
599 bIDescr.setFixed(bI);
600 overRideParams.push_back(std::move(bIDescr));
601 }
602 }
603
604 OverrideParameterSet(overRideParams);
605}
606
607void ZDCFitExpFermiVariableTausInduct::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
608{
609 // Note: if we use parameter sets, this code never gets called as the base class executes the initialize
610 //
611 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
612
613 theTF1->SetParameter(0, initialAmp);
614 theTF1->SetParLimits(0, ampMin, ampMax);
615
616 float t0 = initialT0;
617 if (t0 < GetT0Min()) t0 = GetT0Min()*1.1;
618 if (t0 > GetT0Max()) t0 = GetT0Max()/1.1;
619 theTF1->SetParameter(1, t0);
620
621 theTF1->SetParameter(6, 0.25);
622 theTF1->SetParameter(7, 0.8);
623 if (!m_fixDelta) theTF1->SetParameter(9, 0.);
624
625 if (!m_fixTau1) theTF1->SetParameter(2, m_tau1);
626 if (!m_fixTau2) theTF1->SetParameter(3, m_tau2);
627
628 // Set the parameter errors which ROOT now uses <<<to set the initial step sizes>>>
629 //
630 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
631
632 theTF1->SetParError(0, ampStep);
633 theTF1->SetParError(1, 1.0);
634
635 if (!m_fixTau1) theTF1->SetParError(2, 0.05);
636 if (!m_fixTau2) theTF1->SetParError(3, 0.25);
637
638 theTF1->SetParError(4, 1);
639 theTF1->SetParError(5, 5);
640 theTF1->SetParError(6, 0.1);
641 theTF1->SetParError(7, 0.1);
642}
643
645{
646 // Set the parameter limits accordingly on the TF1
647 //
648 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
649 theTF1->SetParLimits(1, t0Min, t0Max);
650}
651
653{
654 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
655 theTF1->FixParameter(6, 0.25);
656 theTF1->FixParameter(4, 0);
657 // theTF1->FixParameter(7, 0.1);
658}
659
661{
662 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
663 theTF1->ReleaseParameter(6);
664 theTF1->ReleaseParameter(4);
665 theTF1->SetParLimits(6, 0, 2);
666 theTF1->SetParLimits(4, -50, 50);
667
668}
669
670ZDCFitExpFermiFixedTaus::ZDCFitExpFermiFixedTaus(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
671 ZDCFitWrapper(std::make_shared<TF1>(("ExpFermiFixedTaus" + tag).c_str(), this, tmin, tmax, 3)),
672 m_tau1(tau1), m_tau2(tau2)
673{
674 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
675
676 // BAC, parameter 0 limits now is set in DoInitialize
677 theTF1->SetParLimits(1, tmin, tmax);
678
679 theTF1->SetParName(0, "Amp");
680 theTF1->SetParName(1, "T0");
681 theTF1->SetParName(2, "C");
682
683 // Now create the reference function that we use to evaluate ExpFermiFit more efficiently
684 //
685 std::string funcNameRefFunc = "ExpFermiFixedTausRefFunc" + tag;
686 m_expFermiFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFit, -50, 100, 5);
687
688 m_expFermiFunc->SetParameter(0, 1);
689 m_expFermiFunc->SetParameter(1, 0);
690 m_expFermiFunc->SetParameter(2, m_tau1);
691 m_expFermiFunc->SetParameter(3, m_tau2);
692 m_expFermiFunc->SetParameter(4, 0);
693
694 m_norm = 1. / m_expFermiFunc->GetMaximum();
695 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
696}
697
698void ZDCFitExpFermiFixedTaus::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
699{
700 GetWrapperTF1()->SetParameter(0, initialAmp);
701 GetWrapperTF1()->SetParameter(1, initialT0);
702
703 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
704}
706{
707 // We force the constant tersm to zero
708 //
709 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
710
711 theTF1->FixParameter(2, 0);
712}
714{
715 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
716 theTF1->ReleaseParameter(2);
717}
718
719void ZDCFitExpFermiFixedTaus::SetT0FitLimits(float t0Min, float t0Max)
720{
721 GetWrapperTF1()->SetParLimits(1, t0Min, t0Max);
722}
723
724ZDCFitExpFermiPrePulse::ZDCFitExpFermiPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
725 ZDCPrePulseFitWrapper(std::make_shared<TF1>(("ExpFermiPrePulse" + tag).c_str(), this, tmin, tmax, 5)),
726 m_tau1(tau1), m_tau2(tau2)
727{
728 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
729 //
730 std::string funcNameRefFunc = "ExpFermiPrePulseRefFunc" + tag;
731
732 m_expFermiFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFit, -50, 100, 5);
733
734 m_expFermiFunc->SetParameter(0, 1);
735 m_expFermiFunc->SetParameter(1, 0);
736 m_expFermiFunc->SetParameter(2, m_tau1);
737 m_expFermiFunc->SetParameter(3, m_tau2);
738 m_expFermiFunc->SetParameter(4, 0);
739
740 m_norm = 1. / m_expFermiFunc->GetMaximum();
741 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
742
743 // Now set up the actual TF1
744 //
745 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
746
747 // BAC, parameter 0 limits now is set in DoInitialize
748 theTF1->SetParLimits(1, tmin, tmax);
749 theTF1->SetParLimits(2, 1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
750 theTF1->SetParLimits(3, -20, 10);
751
752 theTF1->SetParName(0, "Amp");
753 theTF1->SetParName(1, "T0");
754 theTF1->SetParName(2, "Amp_{pre}");
755 theTF1->SetParName(3, "T0_{pre}");
756 theTF1->SetParName(4, "C");
757}
758
760{
761 // We force the constant term and per-pulse amplitude to zero
762 //
763 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
764
765 theTF1->FixParameter(2, 0);
766 theTF1->FixParameter(4, 0);
767}
769{
770 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
771 theTF1->ReleaseParameter(2);
772 theTF1->ReleaseParameter(4);
773
774 theTF1->SetParLimits(2, 1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
775}
776
778{
779 if (tmin > GetTMin()) {
780 m_preT0Min = tmin;
781 GetWrapperTF1()->ReleaseParameter(3);
782 GetWrapperTF1()->SetParLimits(3, tmin, tmax);
783 }
784 else {
785 m_preT0Min = -25;
786 GetWrapperTF1()->SetParLimits(3, -25, tmax);
787 }
788 m_preT0Max = tmax;
789}
790
791void ZDCFitExpFermiPrePulse::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
792{
793 GetWrapperTF1()->SetParameter(0, initialAmp);
794 GetWrapperTF1()->SetParameter(1, initialT0);
795 GetWrapperTF1()->SetParameter(2, 5);
796 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
797
798 // Set parameter errors for fit step size
799 //
800 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
801 GetWrapperTF1()->SetParError(0, ampStep);
802 GetWrapperTF1()->SetParError(1, 1.0);
803 GetWrapperTF1()->SetParError(2, 2);
804 GetWrapperTF1()->SetParError(3, 1.0);
805 GetWrapperTF1()->SetParError(4, 1.0);
806}
807
808void ZDCFitExpFermiPrePulse::SetT0FitLimits(float t0Min, float t0Max)
809{
810 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
811 theTF1->SetParLimits(1, t0Min, t0Max);
812}
813
814ZDCFitExpFermiPreExp::ZDCFitExpFermiPreExp(const std::string& tag, float tmin, float tmax, float tau1, float tau2,
815 float defExpTau, float fixExpTau) :
816 ZDCPreExpFitWrapper(std::make_shared<TF1>(("ExpFermiPreExp" + tag).c_str(), this, tmin, tmax, 6), defExpTau, fixExpTau),
817 m_tau1(tau1), m_tau2(tau2)
818{
819 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
820 //
821 std::string funcNameRefFunc = "ExpFermiPreExpRefFunc" + tag;
822
823 m_expFermiFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFit, tmin, tmax, 8);
824
825 // The parameters for the FermiExp
826 //
827 m_expFermiFunc->SetParameter(0, 1);
828 m_expFermiFunc->SetParameter(1, 0);
829 m_expFermiFunc->SetParameter(2, m_tau1);
830 m_expFermiFunc->SetParameter(3, m_tau2);
831 m_expFermiFunc->SetParameter(4, 0);
832
833 m_norm = 1. / m_expFermiFunc->GetMaximum();
834 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
835
836 // Now set up the actual TF1
837 //
838 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
839 theTF1->SetParName(0, "Amp");
840 theTF1->SetParName(1, "T0");
841 theTF1->SetParName(2, "Amp_{pre}");
842 theTF1->SetParName(3, "tau_{pre}");
843 theTF1->SetParName(4, "tausqrt_{pre}");
844 theTF1->SetParName(5, "C");
845
846 theTF1->SetParLimits(1, tmin, tmax);
847 theTF1->SetParLimits(2, -1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
848 theTF1->SetParLimits(3, 6, 30);
849 theTF1->SetParLimits(4, -0.2, 0.2);
850 theTF1->SetParLimits(5, -50, 50);
851}
852
854{
855 // We force the constant term and per-pulse amplitude to zero
856 //
857 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
858
859 theTF1->FixParameter(2, 0);
860 theTF1->FixParameter(3, getDefaultExpTau());
861 theTF1->FixParameter(5, 0);
862}
864{
865 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
866
867 theTF1->ReleaseParameter(2);
868 theTF1->SetParLimits(2, -1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
869
870 theTF1->ReleaseParameter(3);
871 theTF1->SetParLimits(3, 6, 30);
872 theTF1->SetParameter(3, getDefaultExpTau());
873
874 theTF1->ReleaseParameter(5);
875 theTF1->SetParLimits(5, -50, 50);
876 theTF1->SetParameter(5, 0);
877}
878
879void ZDCFitExpFermiPreExp::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
880{
881 GetWrapperTF1()->SetParameter(0, initialAmp);
882 GetWrapperTF1()->SetParameter(1, initialT0);
883 GetWrapperTF1()->SetParameter(2, 0);
884 GetWrapperTF1()->SetParameter(3, getDefaultExpTau());
885 GetWrapperTF1()->SetParameter(4, 0.);
886 GetWrapperTF1()->SetParameter(5, 0);
887
888 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
889
890 // Set parameter errors for fit step size
891 //
892 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
893 GetWrapperTF1()->SetParError(0, ampStep);
894 GetWrapperTF1()->SetParError(1, 1.0);
895 GetWrapperTF1()->SetParError(2, ampStep/2);
896 GetWrapperTF1()->SetParError(3, 1.0);
897 GetWrapperTF1()->SetParError(4, 0.025);
898 GetWrapperTF1()->SetParError(5, 1.0);
899}
900
901void ZDCFitExpFermiPreExp::SetT0FitLimits(float t0Min, float t0Max)
902{
903 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
904 theTF1->SetParLimits(1, t0Min, t0Max);
905}
906
907ZDCFitExpFermiLHCfPreExp::ZDCFitExpFermiLHCfPreExp(const std::string& tag, float tmin, float tmax, float tau1, float tau2,
908 float defExpTau, float fixExpTau) :
909 ZDCPreExpFitWrapper(std::make_shared<TF1>(("ExpFermiLHCfPreExp" + tag).c_str(), this, tmin, tmax, 8), defExpTau, fixExpTau),
910 m_tau1(tau1), m_tau2(tau2)
911{
912 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
913 //
914 std::string funcNameRefFunc = "ExpFermiLHCfPreExpRefFunc" + tag;
915
916 m_expFermiLHCfFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFitRefl, tmin, tmax, 9);
917
918 // The parameters for the FermiExpRefl
919 //
920 m_expFermiLHCfFunc->SetParameter(0, 1);
921 m_expFermiLHCfFunc->SetParameter(1, 0);
922 m_expFermiLHCfFunc->SetParameter(2, m_tau1);
923 m_expFermiLHCfFunc->SetParameter(3, m_tau2);
924 m_expFermiLHCfFunc->SetParameter(4, 0);
925 m_expFermiLHCfFunc->SetParameter(5, 6.5);
926 m_expFermiLHCfFunc->SetParameter(6, 0.1);
927 m_expFermiLHCfFunc->SetParameter(7, 1.5);
928 m_expFermiLHCfFunc->SetParameter(8, 0.01);
929
930 // Now set up the actual TF1
931 //
932 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
933 theTF1->SetParName(0, "Amp");
934 theTF1->SetParName(1, "T0");
935 theTF1->SetParName(2, "Tau1");
936 theTF1->SetParName(3, "Tau2");
937 theTF1->SetParName(4, "Amp_{pre}");
938 theTF1->SetParName(5, "tau_{pre}");
939 theTF1->SetParName(6, "bsqrt_{pre}");
940 theTF1->SetParName(7, "ReflFrac");
941
942 theTF1->SetParLimits(1, tmin, tmax);
943 theTF1->SetParLimits(2, 1.0, 2);
944 theTF1->SetParLimits(3, 3.5, 5.5);
945 theTF1->SetParLimits(4, -1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
946 theTF1->SetParLimits(5, 4, 12);
947 theTF1->SetParLimits(6, -0.001, 0.001);
948 theTF1->SetParLimits(7, -1.0e-4, 0.3);
949}
950
951void ZDCFitExpFermiLHCfPreExp::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
952{
953 GetWrapperTF1()->SetParameter(0, std::max(initialAmp, ampMin));
954
955 float t0 = initialT0;
956 if (t0 < GetT0Min()) t0 = GetT0Min()*1.1;
957 if (t0 > GetT0Max()) t0 = GetT0Max()/1.1;
958 GetWrapperTF1()->SetParameter(1, t0);
959
960 GetWrapperTF1()->SetParameter(2, std::max(m_tau1, (float) 1.01));
961 GetWrapperTF1()->SetParameter(3, m_tau2);
962 GetWrapperTF1()->SetParameter(4, 0.);
963 GetWrapperTF1()->SetParameter(5, std::max(getDefaultExpTau(), (float) 6.01));
964 GetWrapperTF1()->SetParameter(6, 0);
965 GetWrapperTF1()->SetParameter(7, 0.2);
966
967 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
968
969 // Set parameter errors for fit step size
970 //
971 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
972 GetWrapperTF1()->SetParError(0, ampStep);
973 GetWrapperTF1()->SetParError(1, 1.0);
974 GetWrapperTF1()->SetParError(2, 0.1);
975 GetWrapperTF1()->SetParError(3, 0.1);
976 GetWrapperTF1()->SetParError(4, 1.0);
977 GetWrapperTF1()->SetParError(5, 0.5);
978 GetWrapperTF1()->SetParError(6, 0.001);
979 GetWrapperTF1()->SetParError(7, 0.01);
980}
981
983{
984 // We force the constant term and per-pulse amplitude to zero
985 //
986 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
987
988 theTF1->FixParameter(5, std::max(getDefaultExpTau(), (float) 6.01));
989 theTF1->FixParameter(6, 0);
990 theTF1->FixParameter(7, 0.20);
991}
993{
994 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
995
996 theTF1->ReleaseParameter(5);
997 theTF1->SetParLimits(5, 6, 12);
998
999 theTF1->ReleaseParameter(6);
1000 theTF1->SetParLimits(6, -0.001, 0.001);
1001 GetWrapperTF1()->SetParameter(6, 0);
1002
1003 theTF1->ReleaseParameter(7);
1004 theTF1->SetParLimits(7, -1.0e-4, 0.3);
1005 GetWrapperTF1()->SetParameter(7, 0.2);
1006
1007}
1008
1009void ZDCFitExpFermiLHCfPreExp::SetT0FitLimits(float t0Min, float t0Max)
1010{
1011 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1012 theTF1->SetParLimits(1, t0Min, t0Max);
1013}
1014
1015ZDCFitExpFermiLHCfPrePulse::ZDCFitExpFermiLHCfPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
1016 ZDCPrePulseFitWrapper(std::make_shared<TF1>(("ExpFermiLHCfPrePulse" + tag).c_str(), this, tmin, tmax, 7)),
1017 m_tau1(tau1), m_tau2(tau2)
1018{
1019 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1020 //
1021 std::string funcNameRefFunc = "ExpFermiLHCfPrePulseRefFunc" + tag;
1022 std::string funcNamePreFunc = "ExpFermiLHCfPrePulsePreFunc" + tag;
1023
1024 m_expFermiLHCfFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFitRefl, tmin, tmax, 9);
1025 m_expFermiLHCfFunc->SetParameter(0, 1);
1026 m_expFermiLHCfFunc->SetParameter(1, 0);
1027 m_expFermiLHCfFunc->SetParameter(2, m_tau1);
1028 m_expFermiLHCfFunc->SetParameter(3, m_tau2);
1029 m_expFermiLHCfFunc->SetParameter(4, 0);
1030 m_expFermiLHCfFunc->SetParameter(5, 6.5);
1031 m_expFermiLHCfFunc->SetParameter(6, 0.2);
1032 m_expFermiLHCfFunc->SetParameter(7, 1.5);
1033 m_expFermiLHCfFunc->SetParameter(8, 0.01);
1034
1035 m_expFermiPreFunc = std::make_shared<TF1>(funcNamePreFunc.c_str(), ZDCFermiExpFit, tmin, tmax, 9);
1036
1037 m_expFermiPreFunc->SetParameter(0, 1);
1038 m_expFermiPreFunc->SetParameter(1, 0);
1039 m_expFermiPreFunc->SetParameter(2, m_tau1);
1040 m_expFermiPreFunc->SetParameter(3, m_tau2);
1041 m_expFermiPreFunc->SetParameter(4, 0);
1042 m_preNorm = 1. / m_expFermiPreFunc->GetMaximum();
1043
1044 // Now set up the actual TF1
1045 //
1046 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
1047
1048 // The actual paerameters we fit
1049 //
1050 theTF1->SetParName(0, "Amp");
1051 theTF1->SetParName(1, "T0");
1052 theTF1->SetParName(2, "tau1");
1053 theTF1->SetParName(3, "tau2");
1054 theTF1->SetParName(4, "Amp_{pre}");
1055 theTF1->SetParName(5, "T0_{pre}");
1056 theTF1->SetParName(6, "C");
1057
1058 // BAC, parameter 0 limits now is set in DoInitialize
1059 theTF1->SetParLimits(1, tmin, tmax);
1060 theTF1->SetParLimits(2, 1.0, 2);
1061 theTF1->SetParLimits(3, 3.5, 5.5);
1062 theTF1->SetParLimits(4, 1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
1063 theTF1->SetParLimits(5, -20, 10);
1064 theTF1->SetParLimits(6, -50, 50);
1065
1066}
1067
1069{
1070 // We force the constant term and per-pulse amplitude to zero
1071 //
1072 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1073
1074 theTF1->FixParameter(4, 0);
1075 theTF1->FixParameter(6, 0);
1076}
1078{
1079 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1080 theTF1->ReleaseParameter(4);
1081 theTF1->ReleaseParameter(6);
1082
1083 theTF1->SetParLimits(4, 1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
1084 theTF1->SetParLimits(6, -50, 50);
1085}
1086
1088{
1089 if (tmin > GetTMin()) {
1090 m_preT0Min = tmin;
1091 GetWrapperTF1()->ReleaseParameter(5);
1092 GetWrapperTF1()->SetParLimits(5, tmin, tmax);
1093 }
1094 else {
1095 m_preT0Min = -25;
1096 GetWrapperTF1()->SetParLimits(5, -25, tmax);
1097 }
1098 m_preT0Max = tmax;
1099}
1100
1101void ZDCFitExpFermiLHCfPrePulse::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
1102{
1103 GetWrapperTF1()->SetParameter(0, initialAmp);
1104 GetWrapperTF1()->SetParameter(1, initialT0);
1105 GetWrapperTF1()->SetParameter(2, m_tau1);
1106 GetWrapperTF1()->SetParameter(3, m_tau2);
1107 GetWrapperTF1()->SetParameter(4, 5);
1108 GetWrapperTF1()->SetParameter(5, -10);
1109 GetWrapperTF1()->SetParameter(6, 0);
1110
1111 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
1112 // Set parameter errors for fit step size
1113 //
1114 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
1115 GetWrapperTF1()->SetParError(0, ampStep);
1116 GetWrapperTF1()->SetParError(1, 1.0);
1117 GetWrapperTF1()->SetParError(2, 0.05);
1118 GetWrapperTF1()->SetParError(3, 1);
1119 GetWrapperTF1()->SetParError(4, 5.0);
1120 GetWrapperTF1()->SetParError(5, 1.0);
1121 GetWrapperTF1()->SetParError(6, 2.0);
1122}
1123
1125{
1126 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1127 theTF1->SetParLimits(1, t0Min, t0Max);
1128}
1129
1130ZDCFitExpFermiInductPreExp::ZDCFitExpFermiInductPreExp(const std::string& tag, float tmin, float tmax, float tau1, float tau2,
1131 float defExpTau, float fixExpTau) :
1132 ZDCPreExpFitWrapper(std::make_shared<TF1>(("ExpFermiInductPreExp" + tag).c_str(), this, tmin, tmax, 10), defExpTau, fixExpTau),
1133 m_tau1(tau1), m_tau2(tau2)
1134{
1135 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1136 //
1137 std::string funcNameRefFunc = "ExpFermiInductPreExpRefFunc" + tag;
1138
1139 m_expFermiInductFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFitInduct, tmin, tmax, 10);
1140
1141 // The parameters for the FermiExpInduct
1142 //
1143 m_expFermiInductFunc->SetParameter(0, 1);
1144 m_expFermiInductFunc->SetParameter(1, 0);
1145 m_expFermiInductFunc->SetParameter(2, m_tau1); // tau1 is fixed
1146 m_expFermiInductFunc->SetParameter(3, m_tau2); // tau2 is fixed
1147 m_expFermiInductFunc->SetParameter(4, 0); // the constant term will be handled directly not here
1148 m_expFermiInductFunc->SetParameter(5, 14); // the period will be fixed
1149 m_expFermiInductFunc->SetParameter(6, 0.25); // A will be varied as part of the fit
1150 m_expFermiInductFunc->SetParameter(7, 0.5); // B will be varied as part of the fit
1151 m_expFermiInductFunc->SetParameter(8, 0.18);
1152 m_expFermiInductFunc->SetParameter(9, 0.015);
1153
1154 // Now set up the actual TF1
1155 //
1156 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
1157 theTF1->SetParName(0, "Amp");
1158 theTF1->SetParName(1, "T0");
1159 theTF1->SetParName(2, "Aexp");
1160 theTF1->SetParName(3, "tauexp");
1161 theTF1->SetParName(4, "bsqrtexp");
1162 theTF1->SetParName(5, "C");
1163 theTF1->SetParName(6, "Period");
1164 theTF1->SetParName(7, "IndA");
1165 theTF1->SetParName(8, "IndB");
1166 theTF1->SetParName(9, "bI");
1167
1168 theTF1->SetParLimits(1, tmin, tmax);
1169 theTF1->SetParLimits(2, -1, 8196); // Increase the upper range to 2 times of ADC range to deal with large exponential tail case of pre-pulse.
1170 theTF1->SetParLimits(3, 4, 12);
1171 theTF1->SetParLimits(4, -0.001, 0.001);
1172 theTF1->SetParLimits(5, -10, 10);
1173 theTF1->FixParameter(6, 13);
1174 theTF1->SetParLimits(7, -0.1, 2);
1175 theTF1->SetParLimits(8, -0.1, 2);
1176 theTF1->SetParLimits(9, -0.05, 0.5);
1177
1178}
1179
1180ZDCFitExpFermiInductPreExp::ZDCFitExpFermiInductPreExp(const std::string& tag, const std::string& paramSet, float tmin, float tmax, float tau1, float tau2, float period, float bI) :
1181 ZDCPreExpFitWrapper(std::make_shared<TF1>(("ExpFermiInductPreExp" + tag).c_str(), this, tmin, tmax, 10), s_ConfigParamMap.at("default")),
1182 m_tau1(tau1), m_tau2(tau2)
1183{
1184 auto iter = s_ConfigParamMap.find(paramSet);
1185 if (iter == s_ConfigParamMap.end()) throw std::runtime_error("ZDCFitExpFermiVariableTausInduct:: invalid parameter set identifier: " + paramSet);
1186
1187 std::vector<ZDCFitWrapper::FitParameter> overRideParams = iter->second;
1188
1189 // Handle the JSON-based tau settings (this is ugly and temporary until we get the more general parameter overriding implemented)
1190 //
1191
1192 if (period > 0) {
1193 auto periodIter = std::find_if(overRideParams.begin(), overRideParams.end(), [](const FitParameter& parDesc){return parDesc.name() == "period";});
1194 if (periodIter != overRideParams.end()) {
1195 periodIter->setFixed(period);
1196 }
1197 else {
1198 FitParameter periodDescr = GetParameterDescr("period");
1199 periodDescr.setFixed(period);
1200 overRideParams.push_back(std::move(periodDescr));
1201 }
1202 }
1203
1204 if (bI > 0) {
1205 auto bIIter = std::find_if(overRideParams.begin(), overRideParams.end(), [](const FitParameter& parDesc){return parDesc.name() == "bI";});
1206 if (bIIter != overRideParams.end()) {
1207 bIIter->setFixed(bI);
1208 }
1209 else {
1210 FitParameter bIDescr = GetParameterDescr("bI");
1211 bIDescr.setFixed(bI);
1212 overRideParams.push_back(std::move(bIDescr));
1213 }
1214 }
1215
1216 OverrideParameterSet(overRideParams);
1217
1218 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1219 //
1220 std::string funcNameRefFunc = "ExpFermiInductPreExpRefFunc" + tag;
1221
1222 m_expFermiInductFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFitInduct, tmin, tmax, 10);
1223
1224 // The parameters for the FermiExpInduct
1225 //
1226 m_expFermiInductFunc->SetParameter(0, 1);
1227 m_expFermiInductFunc->SetParameter(1, 0);
1228 m_expFermiInductFunc->SetParameter(2, m_tau1); // tau1 is fixed
1229 m_expFermiInductFunc->SetParameter(3, m_tau2); // tau2 is fixed
1230 m_expFermiInductFunc->SetParameter(4, 0); // the constant term will be handled directly not here
1231 m_expFermiInductFunc->SetParameter(5, 14);
1232 m_expFermiInductFunc->SetParameter(6, 0.25); // A will be varied as part of the fit
1233 m_expFermiInductFunc->SetParameter(7, 0.5); // B will be varied as part of the fit
1234 m_expFermiInductFunc->SetParameter(8, 0.18);
1235 m_expFermiInductFunc->SetParameter(9, 0.015);
1236}
1237
1238void ZDCFitExpFermiInductPreExp::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
1239{
1240 GetWrapperTF1()->SetParameter(0, std::max(initialAmp, ampMin));
1241
1242 float t0 = initialT0;
1243 if (t0 < GetT0Min()) t0 = GetT0Min()*1.1;
1244 if (t0 > GetT0Max()) t0 = GetT0Max()/1.1;
1245 GetWrapperTF1()->SetParameter(1, t0);
1246
1247 GetWrapperTF1()->SetParameter(2, 1);
1248 GetWrapperTF1()->SetParameter(3, std::max(getDefaultExpTau(), (float) 6.01));
1249 GetWrapperTF1()->SetParameter(6, 14);
1250 GetWrapperTF1()->SetParameter(7, 0.2);
1251 GetWrapperTF1()->SetParameter(8, 0.2);
1252 GetWrapperTF1()->SetParameter(9, 0.01);
1253
1254 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
1255
1256 // Set parameter errors for fit step size
1257 //
1258 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
1259 GetWrapperTF1()->SetParError(0, ampStep);
1260 GetWrapperTF1()->SetParError(1, 1.0);
1261 GetWrapperTF1()->SetParError(2, 5.0);
1262 GetWrapperTF1()->SetParError(3, 0.5);
1263 GetWrapperTF1()->SetParError(4, 0.01);
1264 GetWrapperTF1()->SetParError(5, 1);
1265 GetWrapperTF1()->SetParError(6, 1);
1266 GetWrapperTF1()->SetParError(7, 0.05);
1267 GetWrapperTF1()->SetParError(8, 0.05);
1268 GetWrapperTF1()->SetParError(9, 0.01);
1269}
1270
1277
1279{
1280 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1281 theTF1->SetParLimits(1, t0Min, t0Max);
1282}
1283
1284ZDCFitExpFermiInductPrePulse::ZDCFitExpFermiInductPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
1285 ZDCPrePulseFitWrapper(std::make_shared<TF1>(("ExpFermiInductPrePulse" + tag).c_str(), this, tmin, tmax, 9)),
1286 m_tau1(tau1), m_tau2(tau2)
1287{
1288 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1289 //
1290 std::string funcNameRefFunc = "ExpFermiInductPrePulseRefFunc" + tag;
1291 std::string funcNamePreFunc = "ExpFermiInductPrePulsePreFunc" + tag;
1292
1293 m_expFermiInductFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFitInduct, tmin, tmax, 10);
1294 m_expFermiInductFunc->SetParameter(0, 1);
1295 m_expFermiInductFunc->SetParameter(1, 0);
1296 m_expFermiInductFunc->SetParameter(2, m_tau1);
1297 m_expFermiInductFunc->SetParameter(3, m_tau2);
1298 m_expFermiInductFunc->SetParameter(4, 0);
1299 m_expFermiInductFunc->SetParameter(5, 14);
1300 m_expFermiInductFunc->SetParameter(6, 0.25);
1301 m_expFermiInductFunc->SetParameter(7, 0.15);
1302 m_expFermiInductFunc->SetParameter(8, 0.18);
1303 m_expFermiInductFunc->SetParameter(9, 0.015);
1304
1305 m_expFermiPreFunc = std::make_shared<TF1>(funcNamePreFunc.c_str(), ZDCFermiExpFit, tmin, tmax, 5);
1306
1307 m_expFermiPreFunc->SetParameter(0, 1);
1308 m_expFermiPreFunc->SetParameter(1, 0);
1309 m_expFermiPreFunc->SetParameter(2, m_tau1);
1310 m_expFermiPreFunc->SetParameter(3, m_tau2);
1311 m_expFermiPreFunc->SetParameter(4, 0);
1312 m_preNorm = 1. / m_expFermiPreFunc->GetMaximum();
1313
1314 // Now set up the actual TF1
1315 //
1316 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
1317
1318 // The actual paerameters we fit
1319 //
1320 theTF1->SetParName(0, "Amp");
1321 theTF1->SetParName(1, "T0");
1322 theTF1->SetParName(2, "Apre");
1323 theTF1->SetParName(3, "T0pre");
1324 theTF1->SetParName(4, "C");
1325 theTF1->SetParName(5, "Period");
1326 theTF1->SetParName(6, "IndA");
1327 theTF1->SetParName(7, "IndB");
1328 theTF1->SetParName(8, "bI");
1329
1330 // BAC, parameter 0 limits now is set in DoInitialize
1331 theTF1->SetParLimits(1, tmin, tmax);
1332 theTF1->SetParLimits(2, 0, 5000);
1333 theTF1->SetParLimits(3, 0, 30);
1334 theTF1->SetParLimits(4, 0, 2);
1335 theTF1->SetParLimits(3, 4, 12);
1336 theTF1->SetParLimits(4, -50, 50);
1337 theTF1->SetParLimits(5, 10, 20);
1338 theTF1->SetParLimits(6, -0.1, 1);
1339 theTF1->SetParLimits(7, -0.1, 1);
1340 theTF1->SetParLimits(9, -0.2, 0.2);
1341
1342 GetWrapperTF1()->FixParameter(5, 14);
1343 GetWrapperTF1()->FixParameter(8, 0.02);
1344}
1345
1346ZDCFitExpFermiInductPrePulse::ZDCFitExpFermiInductPrePulse(const std::string& tag, const std::string & paramSet, float tmin, float tmax, float tau1, float tau2) :
1347 ZDCPrePulseFitWrapper(std::make_shared<TF1>(("ExpFermiInductPrePulse" + tag).c_str(), this, tmin, tmax, 9), s_ConfigParamMap.at("default")),
1348 m_tau1(tau1), m_tau2(tau2)
1349{
1350 auto iter = s_ConfigParamMap.find(paramSet);
1351 if (iter == s_ConfigParamMap.end()) throw std::runtime_error("ZDCFitExpFermiVariableTausInduct:: invalid parameter set identifier: " + paramSet);
1352
1353 std::vector<ZDCFitWrapper::FitParameter> overRideParams = iter->second;
1354
1355 OverrideParameterSet(overRideParams);
1356
1357 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1358 //
1359 std::string funcNameRefFunc = "ExpFermiInductPrePulseRefFunc" + tag;
1360 std::string funcNamePreFunc = "ExpFermiInductPrePulsePreFunc" + tag;
1361
1362 m_expFermiPreFunc = std::make_shared<TF1>(funcNamePreFunc.c_str(), ZDCFermiExpFit, tmin, tmax, 5);
1363
1364 m_expFermiPreFunc->SetParameter(0, 1);
1365 m_expFermiPreFunc->SetParameter(1, 0);
1366 m_expFermiPreFunc->SetParameter(2, m_tau1);
1367 m_expFermiPreFunc->SetParameter(3, m_tau2);
1368 m_expFermiPreFunc->SetParameter(4, 0);
1369
1370 // Make the base function that we use
1371 //
1372 m_expFermiInductFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFitInduct, tmin, tmax, 10);
1373 m_expFermiInductFunc->SetParameter(0, 1);
1374 m_expFermiInductFunc->SetParameter(1, 0);
1375 m_expFermiInductFunc->SetParameter(2, m_tau1);
1376 m_expFermiInductFunc->SetParameter(3, m_tau2);
1377 m_expFermiInductFunc->SetParameter(4, 0);
1378 m_expFermiInductFunc->SetParameter(5, 14);
1379 m_expFermiInductFunc->SetParameter(6, 0.25);
1380 m_expFermiInductFunc->SetParameter(7, 0.15);
1381 m_expFermiInductFunc->SetParameter(8, 0.18);
1382 m_expFermiInductFunc->SetParameter(9, 0.015);
1383
1384}
1385
1387{
1388 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1389 theTF1->FixParameter(4, 0);
1390 theTF1->FixParameter(5, 0);
1391 theTF1->FixParameter(7, 0);
1392}
1394{
1395 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1396 theTF1->ReleaseParameter(5);
1397 theTF1->ReleaseParameter(7);
1398 theTF1->SetParLimits(4, -0.001, 0.001);
1399 theTF1->SetParLimits(5, -10, 10);
1400 theTF1->SetParLimits(7, -0.1, 2);
1401}
1402
1404{
1405 if (tmin > GetTMin()) {
1406 m_preT0Min = tmin;
1407 GetWrapperTF1()->ReleaseParameter(3);
1408 GetWrapperTF1()->SetParLimits(3, tmin, tmax);
1409 }
1410 else {
1411 m_preT0Min = -25;
1412 GetWrapperTF1()->SetParLimits(3, -25, tmax);
1413 }
1414 m_preT0Max = tmax;
1415}
1416
1417void ZDCFitExpFermiInductPrePulse::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
1418{
1419 GetWrapperTF1()->SetParameter(0, initialAmp);
1420 GetWrapperTF1()->SetParameter(1, initialT0);
1421 GetWrapperTF1()->SetParameter(2, 5);
1422 GetWrapperTF1()->SetParameter(3, 10);
1423 GetWrapperTF1()->SetParameter(4, 0);
1424 GetWrapperTF1()->SetParameter(5, 0);
1425 GetWrapperTF1()->SetParameter(6, 0.1);
1426 GetWrapperTF1()->SetParameter(7, 0.1);
1427
1428 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
1429 // Set parameter errors for fit step size
1430 //
1431 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
1432 GetWrapperTF1()->SetParError(0, ampStep);
1433 GetWrapperTF1()->SetParError(1, 1.0);
1434 GetWrapperTF1()->SetParError(2, 0.05);
1435 GetWrapperTF1()->SetParError(3, 1);
1436 GetWrapperTF1()->SetParError(4, 5.0);
1437 GetWrapperTF1()->SetParError(5, 5);
1438 GetWrapperTF1()->SetParError(6, 0.05);
1439 GetWrapperTF1()->SetParError(7, 0.05);
1440}
1441
1443{
1444 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1445 theTF1->SetParLimits(1, t0Min, t0Max);
1446}
1447
1448
1449// --------------------------------------------------------------------------------------------------------------------------------------------
1450//
1451ZDCFitExpFermiLinearFixedTaus::ZDCFitExpFermiLinearFixedTaus(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
1452 ZDCFitWrapper(std::make_shared<TF1>(("ExpFermiFixedTaus" + tag).c_str(), this, tmin, tmax, 4)),
1453 m_tau1(tau1), m_tau2(tau2)
1454{
1455 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1456
1457 // BAC, parameter 0 limits now is set in DoInitialize
1458 theTF1->SetParLimits(1, tmin, tmax);
1459
1460 theTF1->SetParName(0, "Amp");
1461 theTF1->SetParName(1, "T0");
1462 theTF1->SetParName(2, "s_{b}");
1463 theTF1->SetParName(3, "c_{b}");
1464
1465 // Now create the reference function that we use to evaluate ExpFermiFit more efficiently
1466 //
1467 std::string funcNameRefFunc = "ExpFermiFixedTausRefFunc" + tag;
1468
1469 m_expFermiFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFit, -50, 100, 5);
1470
1471 m_expFermiFunc->SetParameter(0, 1);
1472 m_expFermiFunc->SetParameter(1, 0);
1473 m_expFermiFunc->SetParameter(2, m_tau1);
1474 m_expFermiFunc->SetParameter(3, m_tau2);
1475 m_expFermiFunc->FixParameter(4, 0);
1476
1477 m_norm = 1. / m_expFermiFunc->GetMaximum();
1478 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
1479}
1480
1482{
1483 // We force the linear terms to zero
1484 //
1485 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1486
1487 theTF1->FixParameter(2, 0);
1488 theTF1->FixParameter(3, 0);
1489}
1490
1492{
1493 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1494 theTF1->ReleaseParameter(2);
1495 theTF1->ReleaseParameter(3);
1496}
1497
1498void ZDCFitExpFermiLinearFixedTaus::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
1499{
1500 float slope = std::abs(0.1 * initialAmp / initialT0);
1501 float intercept = std::abs(0.1 * initialAmp);
1502 GetWrapperTF1()->SetParLimits(2, -slope , slope );
1503 GetWrapperTF1()->SetParLimits(3, -intercept, intercept);
1504
1505 GetWrapperTF1()->SetParameter(0, initialAmp);
1506 GetWrapperTF1()->SetParameter(1, initialT0);
1507 GetWrapperTF1()->SetParameter(2, 0);
1508 GetWrapperTF1()->SetParameter(3, 0);
1509
1510 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
1511
1512 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
1513
1514 GetWrapperTF1()->SetParError(0, ampStep);
1515 GetWrapperTF1()->SetParError(1, 1);
1516 GetWrapperTF1()->SetParError(2, 1);
1517 GetWrapperTF1()->SetParError(3, 0.5);
1518}
1519
1521{
1522 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1523 theTF1->SetParLimits(1, t0Min, t0Max);
1524}
1525
1526// --------------------------------------------------------------------------------------------------------------------------------------------
1527//
1528ZDCFitExpFermiLinearPrePulse::ZDCFitExpFermiLinearPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
1529 ZDCPrePulseFitWrapper(std::make_shared<TF1>(("ExpFermiLinearPrePulse" + tag).c_str(), this, tmin, tmax, 6)),
1530 m_tau1(tau1), m_tau2(tau2)
1531{
1532 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1533 //
1534 std::string funcNameRefFunc = "ExpFermiPerPulseRefFunc" + tag;
1535
1536 m_expFermiFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFit, -50, 100, 5);
1537
1538 m_expFermiFunc->SetParameter(0, 1);
1539 m_expFermiFunc->SetParameter(1, 0);
1540 m_expFermiFunc->SetParameter(2, m_tau1);
1541 m_expFermiFunc->SetParameter(3, m_tau2);
1542 m_expFermiFunc->FixParameter(4, 0);
1543
1544 m_norm = 1. / m_expFermiFunc->GetMaximum();
1545 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
1546
1547 // Now set up the actual TF1
1548 //
1549 std::shared_ptr<TF1> theTF1 = ZDCFitWrapper::GetWrapperTF1();
1550
1551 theTF1->SetParName(0, "Amp");
1552 theTF1->SetParName(1, "T0");
1553 theTF1->SetParName(2, "Amp_{pre}");
1554 theTF1->SetParName(3, "T0_{pre}");
1555 theTF1->SetParName(4, "s_{b}");
1556 theTF1->SetParName(5, "c_{b}");
1557
1558 // BAC, parameter 0 limits now is set in DoInitialize
1559 theTF1->SetParLimits(1, tmin, tmax);
1560 theTF1->SetParLimits(2, 1, 4096); // Increase the upper range to 4 times of ADC range to deal with large exponential tail case of pre-pulse.
1561 theTF1->SetParLimits(3, -20, 10);
1562}
1563
1565{
1566 // We force the linear terms and prepulse terms to zero
1567 //
1568 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1569
1570 theTF1->FixParameter(4, 0);
1571 theTF1->FixParameter(5, 0);
1572}
1574{
1575 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1576
1577 theTF1->ReleaseParameter(4);
1578 theTF1->ReleaseParameter(5);
1579}
1580
1582{
1583 GetWrapperTF1()->SetParLimits(3, tmin, tmax);
1584}
1585
1586void ZDCFitExpFermiLinearPrePulse::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
1587{
1588 float slope = std::abs(initialAmp / initialT0); // to be studied more ??? limit 0.1 0.05
1589 float intercept = std::abs(0.5 * initialAmp);
1590 GetWrapperTF1()->SetParLimits(4, -slope , slope );
1591 GetWrapperTF1()->SetParLimits(5, -intercept, intercept);
1592
1593 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
1594
1595 GetWrapperTF1()->SetParameter(0, initialAmp);
1596 GetWrapperTF1()->SetParameter(1, initialT0);
1597 GetWrapperTF1()->SetParameter(2, 5);
1598 GetWrapperTF1()->SetParameter(5, 0);
1599
1600 double ampStep = std::min(0.05*initialAmp, std::abs(ampMax - initialAmp)/2.);
1601
1602 GetWrapperTF1()->SetParError(0, ampStep);
1603 GetWrapperTF1()->SetParError(1, 1.0);
1604 GetWrapperTF1()->SetParError(2, 1);
1605 GetWrapperTF1()->SetParError(3, 1);
1606 GetWrapperTF1()->SetParError(4, 0.1);
1607 GetWrapperTF1()->SetParError(5, 1);
1608}
1609
1611{
1612 GetWrapperTF1()->SetParLimits(1, t0Min, t0Max);
1613}
1614
1615
1616// --------------------------------------------------------------------------------------------------------------------------------------------
1617//
1618ZDCFitComplexPrePulse::ZDCFitComplexPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
1619 ZDCPrePulseFitWrapper(std::make_shared<TF1>(("ExpFermiPrePulse" + tag).c_str(), this, tmin, tmax, 7)),
1620 m_tau1(tau1), m_tau2(tau2)
1621{
1622 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1623 //
1624 std::string funcNameRefFunc = "ExpFermiPerPulseRefFunc" + tag;
1625
1626 m_expFermiFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFit, -50, 100, 4);
1627
1628 m_expFermiFunc->SetParameter(0, 1);
1629 m_expFermiFunc->SetParameter(1, 0);
1630 m_expFermiFunc->SetParameter(2, m_tau1);
1631 m_expFermiFunc->SetParameter(3, m_tau2);
1632
1633 m_norm = 1. / m_expFermiFunc->GetMaximum();
1634 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
1635
1636 // Now set up the actual TF1
1637 //
1638 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1639
1640 // BAC, parameter 0 limits now is set in DoInitialize
1641 theTF1->SetParLimits(1, tmin, tmax);
1642 theTF1->SetParLimits(2, 0, 2048); // Pre-pulse upper bound should not be greater 2 times of ADC range with overflow constrains.
1643 theTF1->SetParLimits(3, 0, 40);
1644 theTF1->SetParLimits(6, 0, 4096); // Increase the upper range to 4 times of ADC range to deal with large exponential tail case of pre-pulse.
1645
1646 theTF1->SetParName(0, "Amp");
1647 theTF1->SetParName(1, "T0");
1648 theTF1->SetParName(2, "Amp_{pre}");
1649 theTF1->SetParName(3, "T0_{pre}");
1650 theTF1->SetParName(4, "s_{b}");
1651 theTF1->SetParName(5, "c_{b}");
1652 theTF1->SetParName(6, "Amp_{exp}");
1653}
1654
1656{
1657 // We force the linear terms and prepulse terms to zero
1658 //
1659 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1660
1661 theTF1->FixParameter(2, 0);
1662 theTF1->FixParameter(4, 0);
1663 theTF1->FixParameter(5, 0);
1664}
1666{
1667 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1668 theTF1->ReleaseParameter(2);
1669 theTF1->ReleaseParameter(4);
1670 theTF1->ReleaseParameter(5);
1671}
1672
1674{
1675 if (tmin > GetTMin()) {
1676 GetWrapperTF1()->ReleaseParameter(3);
1677 GetWrapperTF1()->SetParLimits(3, tmin, tmax);
1678 }
1679 else {
1680 GetWrapperTF1()->SetParLimits(3, 0, tmax);
1681 }
1682}
1683
1684void ZDCFitComplexPrePulse::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
1685{
1686 float slope = std::abs(initialAmp / initialT0); // to be studied more ??? limit 0.1 0.05
1687 float intercept = std::abs(0.1 * initialAmp); // reduce from 0.25 to 0.1 fix some fail issue
1688 GetWrapperTF1()->SetParLimits(4, -slope , slope ); // if the lower limit is set to 0, there will be some fit fail issue...
1689 GetWrapperTF1()->SetParLimits(5, -intercept, intercept);
1690
1691 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
1692
1693 GetWrapperTF1()->SetParameter(0, initialAmp);
1694 GetWrapperTF1()->SetParameter(1, initialT0);
1695 GetWrapperTF1()->SetParameter(2, 5);
1696 GetWrapperTF1()->SetParameter(3, 10);
1697 GetWrapperTF1()->SetParameter(4, 0);
1698 GetWrapperTF1()->SetParameter(5, 0);
1699 GetWrapperTF1()->SetParameter(6, 1);
1700}
1701
1702void ZDCFitComplexPrePulse::SetT0FitLimits(float t0Min, float t0Max)
1703{
1704 GetWrapperTF1()->SetParLimits(1, t0Min, t0Max);
1705}
1706
1707
1708
1709// --------------------------------------------------------------------------------------------------------------------------------------------
1710//
1711ZDCFitGeneralPulse::ZDCFitGeneralPulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2) :
1712 ZDCPrePulseFitWrapper(std::make_shared<TF1>(("ExpFermiPrePulse" + tag).c_str(), this, tmin, tmax, 9)),
1713 m_tau1(tau1), m_tau2(tau2)
1714{
1715 // Create the reference function that we use to evaluate ExpFermiFit more efficiently
1716 //
1717 std::string funcNameRefFunc = "ExpFermiPerPulseRefFunc" + tag;
1718
1719 m_expFermiFunc = std::make_shared<TF1>(funcNameRefFunc.c_str(), ZDCFermiExpFit, -50, 100, 4);
1720
1721 m_expFermiFunc->SetParameter(0, 1);
1722 m_expFermiFunc->SetParameter(1, 0);
1723 m_expFermiFunc->SetParameter(2, m_tau1);
1724 m_expFermiFunc->SetParameter(3, m_tau2);
1725
1726 m_norm = 1. / m_expFermiFunc->GetMaximum();
1727 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
1728
1729 // Now set up the actual TF1
1730 //
1731 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1732
1733 // BAC, parameter 0 limits now is set in DoInitialize
1734 theTF1->SetParLimits(1, tmin, tmax);
1735 theTF1->SetParLimits(2, 0, 2048); // Pre-pulse upper bound should not be greater 2 times of ADC range with overflow constrains.
1736 theTF1->SetParLimits(3, 0, 40);
1737 theTF1->SetParLimits(6, 0, 4096); // Increase the upper range to 4 times of ADC range to deal with large exponential tail case of pre-pulse.
1738 theTF1->SetParLimits(7, 0, 2048); // Post-pulse upper bound should not be greater 2 times of ADC range with overflow constrains.
1739 theTF1->SetParLimits(8, 100, 163);
1740
1741 theTF1->SetParName(0, "Amp");
1742 theTF1->SetParName(1, "T0");
1743 theTF1->SetParName(2, "Amp_{pre}");
1744 theTF1->SetParName(3, "T0_{pre}");
1745 theTF1->SetParName(4, "s_{b}");
1746 theTF1->SetParName(5, "c_{b}");
1747 theTF1->SetParName(6, "Amp_{exp}");
1748 theTF1->SetParName(7, "Amp_{post}");
1749 theTF1->SetParName(8, "T0_{post}");
1750}
1751
1753{
1754 // We force the linear terms and prepulse terms to zero
1755 //
1756 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1757
1758 theTF1->FixParameter(2, 0);
1759 theTF1->FixParameter(4, 0);
1760 theTF1->FixParameter(5, 0);
1761}
1763{
1764 std::shared_ptr<TF1> theTF1 = GetWrapperTF1();
1765 theTF1->ReleaseParameter(2);
1766 theTF1->ReleaseParameter(4);
1767 theTF1->ReleaseParameter(5);
1768}
1769
1770void ZDCFitGeneralPulse::SetPrePulseT0Range(float tmin, float tmax)
1771{
1772 if (tmin > GetTMin()) {
1773 if (tmin < 0) tmin = 0;
1774 GetWrapperTF1()->SetParLimits(3, tmin, tmax);
1775 }
1776 else {
1777 GetWrapperTF1()->SetParLimits(3, 0, tmax);
1778 }
1779}
1780
1781void ZDCFitGeneralPulse::SetPostPulseT0Range(float tmin, float tmax, float initialPostT0)
1782{
1783 GetWrapperTF1()->SetParLimits(8, tmin, tmax);
1784 float iniPostT0 = initialPostT0;
1785 GetWrapperTF1()->SetParameter(8, iniPostT0);
1786}
1787
1788void ZDCFitGeneralPulse::DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)
1789{
1790 float slope = std::abs(initialAmp / initialT0); // to be studied more ??? limit 0.1 0.05
1791 float intercept = std::abs(0.1 * initialAmp); // reduce from 0.25 to 0.1 fix some fail issue
1792 GetWrapperTF1()->SetParLimits(4, -slope , slope ); // if the lower limit is set to 0, there will be some fit fail issue...
1793 GetWrapperTF1()->SetParLimits(5, -intercept, intercept);
1794
1795 GetWrapperTF1()->SetParLimits(0, ampMin, ampMax);
1796
1797 GetWrapperTF1()->SetParameter(0, initialAmp);
1798 GetWrapperTF1()->SetParameter(1, initialT0);
1799 GetWrapperTF1()->SetParameter(4, 0);
1800 GetWrapperTF1()->SetParameter(5, 0);
1801 GetWrapperTF1()->SetParameter(7, 5);
1802}
1803
1804void ZDCFitGeneralPulse::SetT0FitLimits(float t0Min, float t0Max)
1805{
1806 GetWrapperTF1()->SetParLimits(1, t0Min, t0Max);
1807}
static Double_t t0
if(pathvar)
double ZDCFermiExpFit(const double *xvec, const double *pvec)
double ZDCFermiExpFitRefl(const double *xvec, const double *pvec)
double ZDCFermiExpFitInduct(const double *xvec, const double *pvec)
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
virtual void SetPrePulseT0Range(float tmin, float tmax) override
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doConstrainFit() override
ZDCFitComplexPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
std::shared_ptr< TF1 > m_expFermiFunc
virtual void doUnconstrainFit() override
ZDCFitExpFermiFixedTaus(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual void doUnconstrainFit() override
virtual void doConstrainFit() override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
std::shared_ptr< TF1 > m_expFermiFunc
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doUnconstrainFit() override
std::shared_ptr< TF1 > m_expFermiInductFunc
virtual void doConstrainFit() override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
static const std::map< std::string, std::vector< ZDCFitWrapper::FitParameter > > s_ConfigParamMap
ZDCFitExpFermiInductPreExp(const std::string &tag, float tmin, float tmax, float tau1, float tau2, float defExpTau, float fixExpTau)
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doConstrainFit() override
static const std::map< std::string, std::vector< ZDCFitWrapper::FitParameter > > s_ConfigParamMap
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doUnconstrainFit() override
ZDCFitExpFermiInductPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
std::shared_ptr< TF1 > m_expFermiPreFunc
std::shared_ptr< TF1 > m_expFermiInductFunc
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
virtual void SetPrePulseT0Range(float tmin, float tmax) override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
virtual void SetT0FitLimits(float tMin, float tMax) override
std::shared_ptr< TF1 > m_expFermiLHCfFunc
virtual void doConstrainFit() override
virtual void doUnconstrainFit() override
ZDCFitExpFermiLHCfPreExp(const std::string &tag, float tmin, float tmax, float tau1, float tau2, float defExpTau, float fixExpTau)
std::shared_ptr< TF1 > m_expFermiPreFunc
std::shared_ptr< TF1 > m_expFermiLHCfFunc
virtual void SetPrePulseT0Range(float tmin, float tmax) override
virtual void doConstrainFit() override
virtual void doUnconstrainFit() override
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
ZDCFitExpFermiLHCfPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
std::shared_ptr< TF1 > m_expFermiFunc
virtual void doUnconstrainFit() override
virtual void doConstrainFit() override
virtual void SetT0FitLimits(float tMin, float tMax) override
ZDCFitExpFermiLinearFixedTaus(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
virtual void doUnconstrainFit() override
virtual void SetPrePulseT0Range(float tmin, float tmax) override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
ZDCFitExpFermiLinearPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
std::shared_ptr< TF1 > m_expFermiFunc
virtual void doConstrainFit() override
virtual void SetT0FitLimits(float tMin, float tMax) override
std::shared_ptr< TF1 > m_expFermiFunc
virtual void doUnconstrainFit() override
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doConstrainFit() override
ZDCFitExpFermiPreExp(const std::string &tag, float tmin, float tmax, float tau1, float tau2, float defExpTau, float fixExpTau)
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
virtual void doUnconstrainFit() override
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doConstrainFit() override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
std::shared_ptr< TF1 > m_expFermiFunc
virtual void SetPrePulseT0Range(float tmin, float tmax) override
ZDCFitExpFermiPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
static const std::map< std::string, std::vector< ZDCFitWrapper::FitParameter > > s_ConfigParamMap
virtual void doConstrainFit() override
ZDCFitExpFermiVariableTausInduct(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual void doUnconstrainFit() override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
virtual void doUnconstrainFit() override
ZDCFitExpFermiVariableTausLHCf(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual void doConstrainFit() override
virtual void SetT0FitLimits(float tMin, float tMax) override
ZDCFitExpFermiVariableTausRun3(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
ZDCFitExpFermiVariableTaus(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual void doConstrainFit() override
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doUnconstrainFit() override
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override
std::shared_ptr< TF1 > m_expFermiFunc
virtual void SetT0FitLimits(float tMin, float tMax) override
virtual void doUnconstrainFit() override
virtual void SetPostPulseT0Range(float tmin, float tmax, float initialPostT0) override
ZDCFitGeneralPulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual void doConstrainFit() override
virtual void SetPrePulseT0Range(float tmin, float tmax) override
void setFixed(float fixedValue)
void Initialize(float initialAmp, float initialT0, float ampMin, float ampMax)
float GetTMin() const
void OverrideParameterSet(const std::vector< FitParameter > &parameterSet)
virtual void doUnconstrainFit()=0
virtual std::shared_ptr< TF1 > GetWrapperTF1()
ZDCFitWrapper()=delete
float GetT0Max() const
std::vector< FitParameter > m_parameterSet
void LoadDefaultParameterSet(const std::vector< FitParameter > &parameterSet)
bool m_haveParameterSet
float GetT0Min() const
virtual void SetT0FitLimits(float tMin, float tMax)=0
void SetAmpMinMax(float minAmp, float maxAmp)
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)=0
virtual void doConstrainFit()=0
const FitParameter & GetParameterDescr(const std::string &name)
std::shared_ptr< TF1 > m_wrapperTF1
float getDefaultExpTau() const
ZDCPreExpFitWrapper(std::shared_ptr< TF1 > wrapperTF1, float defaultExpTau, bool fixTau)
bool fixExpTau() const
ZDCPrePulseFitWrapper(std::shared_ptr< TF1 > wrapperTF1)
STL namespace.