ATLAS Offline Software
Loading...
Searching...
No Matches
ZDCFitWrapper.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ZDCANALYSIS_ZDCFITWRAPPER_H
6#define ZDCANALYSIS_ZDCFITWRAPPER_H
7
9
10// Base class that defines the interface
11//
12#include <TF1.h>
13#include <memory>
14#include <cmath>
15#include <stdexcept>
16#include <algorithm> //std::max
17
18inline double ZDCFermiExpFit(const double* xvec, const double* pvec);
19inline double ZDCFermiExpFitRefl(const double* xvec, const double* pvec);
20inline double ZDCFermiExpFitInduct(const double* xvec, const double* pvec);
21
23{
24private:
25 std::shared_ptr<TF1> m_wrapperTF1{};
26
27 float m_tmin{0};
28 float m_tmax{0};
29
30 float m_ampMin{0};
31 float m_ampMax{0};
32
33 float m_t0Min{0};
34 float m_t0Max{0};
35
36 bool m_adjTLimitsEvent{false};
37 float m_tminAdjust{0};
38 float m_tempTmin{0};
39 float m_tempTmax{0};
40
41protected:
42 // Actually sets the t0 parameter limits in the fit function
43 //
44 virtual void SetT0FitLimits(float tMin, float tMax) = 0;
45
46public:
47 ZDCFitWrapper(const std::shared_ptr<TF1>& wrapperTF1) : m_wrapperTF1(wrapperTF1),
48 m_ampMin(0),
49 m_adjTLimitsEvent(true) // true here forces a setting of T0 par limits on first event
50 {
51 m_tmin = m_wrapperTF1->GetXmin();
52 m_tmax = m_wrapperTF1->GetXmax();
53
56 }
57
58 virtual ~ZDCFitWrapper() {}
59
60 void Initialize(float initialAmp, float initialT0, float ampMin, float ampMax);
61 void Initialize(float initialAmp, float initialT0, float ampMin, float ampMax, float fitTmin, float fitTmax, float fitTRef);
62
63 // Performs the class-specific event initialization
64 //
65 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) = 0;
66
67 void SetAmpMinMax(float minAmp, float maxAmp)
68 {
69 m_ampMin = minAmp;
70 m_ampMax = maxAmp;
71 }
72
73 void SetT0Range(float t0Min, float t0Max)
74 {
75 m_t0Min = t0Min;
76 m_t0Max = t0Max;
77
78 SetT0FitLimits(t0Min, t0Max);
79 }
80
81 virtual void ConstrainFit() = 0;
82 virtual void UnconstrainFit() = 0;
83
84 virtual float GetAmplitude() const = 0;
85 virtual float GetAmpError() const = 0;
86 virtual float GetTime() const = 0;
87 virtual float GetTau1() const = 0;
88 virtual float GetTau2() const = 0;
89
90 float GetMinAmp() const {return m_ampMin;}
91 float GetMaxAmp() const {return m_ampMax;}
92
93 float GetTMin() const {return m_tmin;}
94 float GetTMax() const {return m_tmax;}
95
96 float GetT0Min() const {
97 if (m_adjTLimitsEvent) return m_tempTmin;
98 else return m_t0Min;
99 }
100
101 float GetT0Max() const {
102 if (m_adjTLimitsEvent) return m_tempTmax;
103 else return m_t0Max;
104 }
105
106 float GetTMinAdjust() const {return m_tminAdjust;}
107
108 virtual float GetBkgdMaxFraction() const = 0;
109
110 virtual unsigned int GetNumShapeParameters() const = 0;
111 virtual float GetShapeParameter(size_t index) const = 0;
112
113 virtual double operator()(const double *x, const double *p) = 0;
114
115 virtual std::shared_ptr<TF1> GetWrapperTF1() {return m_wrapperTF1;}
116 virtual const TF1* GetWrapperTF1() const {return m_wrapperTF1.get();}
117 virtual TF1* GetWrapperTF1RawPtr() const {return m_wrapperTF1.get();}
118};
119
121{
122protected:
125public:
126 ZDCPrePulseFitWrapper(std::shared_ptr<TF1> wrapperTF1) : ZDCFitWrapper(wrapperTF1)
127 {
130 }
131
132 virtual void SetInitialPrePulse(float amp, float t0, float expamp, bool fixPrePulseToZero) = 0;
133
134 virtual void SetPrePulseT0Range(float tmin, float tmax) = 0;
135 virtual void SetPostPulseT0Range(float tmin, float tmax, float initialPostT0) = 0;
136
137 virtual unsigned int GetPreT0ParIndex() const = 0;
138
139 virtual float GetPreT0() const = 0;
140 virtual float GetPreAmp() const = 0;
141
142 virtual float GetPostT0() const = 0;
143 virtual float GetPostAmp() const = 0;
144
145 virtual float GetExpAmp() const = 0;
146};
147
149{
150protected:
153
154public:
155 ZDCPreExpFitWrapper(std::shared_ptr<TF1> wrapperTF1, float defaultExpTau, bool fixTau) :
156 ZDCFitWrapper(wrapperTF1), m_defaultTau(defaultExpTau), m_fixTau(fixTau)
157 {}
158
159 virtual void SetInitialExpPulse(float expamp) = 0;
160
161 bool fixExpTau() const {return m_fixTau;}
162 float getDefaultExpTau() const {return m_defaultTau;}
163
164 virtual float GetExpAmp() const = 0;
165 virtual float GetExpTau() const = 0;
166};
167
169{
170protected:
171 bool m_fixTau1{false};
172 bool m_fixTau2{false};
173
174 float m_tau1{0};
175 float m_tau2{0};
176
177public:
178
179 ZDCFitExpFermiVariableTaus(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2);
180
181 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
182 virtual void SetT0FitLimits(float tMin, float tMax) override;
183
184 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
185 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
186
187 virtual float GetTau1() const override {return GetWrapperTF1()->GetParameter(2);}
188 virtual float GetTau2() const override {return GetWrapperTF1()->GetParameter(3);}
189
190 virtual float GetTime() const override {
191 const TF1* theTF1 = GetWrapperTF1();
192
193 float fitT0 = theTF1->GetParameter(1);
194
195 float tau1 = theTF1->GetParameter(2);
196 float tau2 = theTF1->GetParameter(3);
197
198 // Correct the time to the maximum
199 //
200 if (tau2 > tau1) fitT0 += tau1 * std::log(tau2 / tau1 - 1.0);
201 return fitT0;
202 }
203
204 virtual unsigned int GetNumShapeParameters() const override {return 1;}
205
206 virtual float GetShapeParameter(size_t index) const override
207 {
208 if (index == 0) return GetWrapperTF1()->GetParameter(4);
209 else throw std::runtime_error("Fit parameter does not exist.");
210 }
211
212 virtual float GetBkgdMaxFraction() const override
213 {
214 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
215 double amp = theTF1->GetParameter(0);
216 double constant = theTF1->GetParameter(4);
217
218 if (amp > 0) return constant / amp;
219 else return -1;
220 }
221
222 virtual double operator()(const double *x, const double *p) override{
223 return ZDCFermiExpFit(x, p);
224 }
225
226 virtual void ConstrainFit() override;
227 virtual void UnconstrainFit() override;
228};
229
230//
231// A special version of the fermi*negative exponential function that includes a term to describe
232// the "reflection" effects we see in the ZDC+LHCf joint run due to the splitting of the ZDC
233// signals to send a copy to LHCf DAQ. It's not really a reflection but an artifact introduced
234// by the bandwidth limit of the linear fan-in/fan-out module that we used.
235//
237{
238protected:
239 bool m_fixTau1{false};
240 bool m_fixTau2{false};
241
242 float m_tau1{0};
243 float m_tau2{0};
244
245public:
246
247 ZDCFitExpFermiVariableTausLHCf(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2);
248
249 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
250 virtual void SetT0FitLimits(float tMin, float tMax) override;
251
252 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
253 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
254
255 virtual float GetTau1() const override {return GetWrapperTF1()->GetParameter(2);}
256 virtual float GetTau2() const override {return GetWrapperTF1()->GetParameter(3);}
257
258 virtual float GetTime() const override {
259 const TF1* theTF1 = GetWrapperTF1();
260
261 float fitT0 = theTF1->GetParameter(1);
262
263 float tau1 = theTF1->GetParameter(2);
264 float tau2 = theTF1->GetParameter(3);
265
266 // Correct the time to the maximum
267 //
268 if (tau2 > tau1) fitT0 += tau1 * std::log(tau2 / tau1 - 1.0);
269 return fitT0;
270 }
271
272 virtual unsigned int GetNumShapeParameters() const override {return 5;}
273
274 virtual float GetShapeParameter(size_t index) const override
275 {
276 if (index < 5) return GetWrapperTF1()->GetParameter(5+index);
277 else throw std::runtime_error("Fit parameter does not exist.");
278 }
279
280 virtual float GetBkgdMaxFraction() const override
281 {
282 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
283 double amp = theTF1->GetParameter(0);
284 double constant = theTF1->GetParameter(4);
285
286 if (amp > 0) return constant / amp;
287 else return 1;
288 }
289
290 virtual double operator()(const double *x, const double *p) override{
291 return ZDCFermiExpFitRefl(x, p);
292 }
293
294 virtual void ConstrainFit() override;
295 virtual void UnconstrainFit() override;
296};
297
299{
300protected:
301 bool m_fixTau1{false};
302 bool m_fixTau2{false};
303
304 float m_tau1{0};
305 float m_tau2{0};
306
307public:
308
309 ZDCFitExpFermiVariableTausInduct(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2);
310
311 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
312 virtual void SetT0FitLimits(float tMin, float tMax) override;
313
314 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
315 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
316
317 virtual float GetTau1() const override {return GetWrapperTF1()->GetParameter(2);}
318 virtual float GetTau2() const override {return GetWrapperTF1()->GetParameter(3);}
319
320 virtual float GetTime() const override {
321 const TF1* theTF1 = GetWrapperTF1();
322
323 float fitT0 = theTF1->GetParameter(1);
324
325 float tau1 = theTF1->GetParameter(2);
326 float tau2 = theTF1->GetParameter(3);
327
328 // Correct the time to the maximum
329 //
330 if (tau2 > tau1) fitT0 += tau1 * std::log(tau2 / tau1 - 1.0);
331 return fitT0;
332 }
333
334 virtual unsigned int GetNumShapeParameters() const override {return 5;}
335
336 virtual float GetShapeParameter(size_t index) const override
337 {
338 if (index < 5) return GetWrapperTF1()->GetParameter(4+index);
339 else throw std::runtime_error("Fit parameter does not exist.");
340 }
341
342 virtual float GetBkgdMaxFraction() const override
343 {
344 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
345 double amp = theTF1->GetParameter(0);
346 double constant = theTF1->GetParameter(4);
347
348 if (amp > 1e-6) return constant / amp;
349 else return 1;
350 }
351
352 virtual double operator()(const double *x, const double *p) override{
353 return ZDCFermiExpFitInduct(x, p);
354 }
355
356 virtual void ConstrainFit() override;
357 virtual void UnconstrainFit() override;
358};
359
361{
362public:
363 ZDCFitExpFermiVariableTausRun3(const std::string& tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2);
364};
365
367{
368private:
369 float m_tau1{0};
370 float m_tau2{0};
371
372 float m_norm{0};
373 float m_timeCorr{0};
374
375 std::shared_ptr<TF1> m_expFermiFunc{};
376
377public:
378
379 ZDCFitExpFermiFixedTaus(const std::string& tag, float tmin, float tmax, float tau1, float tau2);
380
382
383 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
384 virtual void SetT0FitLimits(float tMin, float tMax) override;
385
386 virtual void ConstrainFit() override;
387 virtual void UnconstrainFit() override;
388
389 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
390 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
391
392 virtual float GetTau1() const override {return m_tau1;}
393 virtual float GetTau2() const override {return m_tau2;}
394
395 virtual float GetTime() const override {
396 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
397 }
398
399 virtual unsigned int GetNumShapeParameters() const override {return 2;}
400
401 virtual float GetShapeParameter(size_t index) const override
402 {
403 if (index == 0) return m_tau1;
404 else if (index == 1) return m_tau2;
405 else throw std::runtime_error("Fit parameter does not exist.");
406 }
407
408 virtual float GetBkgdMaxFraction() const override
409 {
410 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
411 double amp = theTF1->GetParameter(0);
412 if (amp <= 0) return -1;
413
414 double C = theTF1->GetParameter(2);
415 return C / amp;
416 }
417
418 virtual double operator() (const double *x, const double *p) override
419 {
420 double amp = p[0];
421 double t0 = p[1];
422 double C = p[2];
423
424 double deltaT = x[0] - t0;
425
426 double expFermi = amp * m_norm * m_expFermiFunc->operator()(deltaT);
427
428 return expFermi + C; // + bckgd;
429 }
430};
431
433{
434private:
435 float m_tau1{0};
436 float m_tau2{0};
437 float m_norm{0};
438 float m_timeCorr{0};
439
440 std::shared_ptr<TF1> m_expFermiFunc = 0;
441 std::shared_ptr<TF1> m_expFermiPreFunc = 0;
442
443public:
444 ZDCFitExpFermiPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2);
446
447 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
448 virtual void SetT0FitLimits(float tMin, float tMax) override;
449
450
451 virtual void SetInitialPrePulse(float amp, float t0, float /*expamp = 0*/, bool /*fixPrePulseToZero = false*/) override {
452 GetWrapperTF1()->SetParameter(2, std::max(amp, (float) 1.5)); //1.5 here ensures that we're above lower limit
453 GetWrapperTF1()->SetParameter(3, t0);
454 }
455
456 virtual void SetPrePulseT0Range(float tmin, float tmax) override;
457 virtual void SetPostPulseT0Range(float /*tmin*/, float /*tmax*/, float /*initialPostT0*/) override {return;}
458
459 virtual void ConstrainFit() override;
460 virtual void UnconstrainFit() override;
461
462 virtual unsigned int GetPreT0ParIndex() const override {return 3;}
463
464 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
465 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
466
467 virtual float GetTau1() const override {return m_tau1;}
468 virtual float GetTau2() const override {return m_tau2;}
469
470 virtual float GetPreT0() const override {return 0;}
471 virtual float GetPreAmp() const override {return 0;}
472
473 virtual float GetPostT0() const override {return 0;}
474 virtual float GetPostAmp() const override {return 0;}
475
476 virtual float GetExpAmp() const override {return 0;}
477
478 virtual float GetTime() const override {
479 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
480 }
481
482 virtual unsigned int GetNumShapeParameters() const override {return 1;}
483
484 virtual float GetShapeParameter(size_t index) const override
485 {
486 if (index < 1) return GetWrapperTF1()->GetParameter(4);
487 else throw std::runtime_error("Fit parameter does not exist.");
488 }
489
490 virtual float GetBkgdMaxFraction() const override
491 {
492 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
493
494 double maxTime = GetTime();
495
496 double amp = theTF1->GetParameter(0);
497 if (amp <= 0) return -1;
498
499 double preAmp = theTF1->GetParameter(2);
500 double preT0 = theTF1->GetParameter(3);
501
502 double deltaTPre = maxTime - preT0;
503 double background = preAmp * m_norm * m_expFermiFunc->operator()(deltaTPre);
504
505 return background / (amp + background);
506 }
507
508 virtual double operator() (const double *x, const double *p) override
509 {
510 double t = x[0];
511
512 double amp = p[0];
513 double t0 = p[1];
514 double preAmp = p[2];
515 double preT0 = p[3];
516 double C = p[4];
517
518 double deltaT = t - t0;
519 double deltaTPre = t - preT0;
520
521 // We subtract off the value of the pre-pulse at the minimum time (nominally 0,
522 // but can change if we exclude early samples) to account for the subtraction of the pre-sample
523 //
524 double deltaPresamp = GetTMinAdjust() - preT0;
525
526 // double bckgd = linSlope*t;
527
528 double pulse1 = amp*m_norm*m_expFermiFunc->operator()(deltaT);
529 double pulse2 = preAmp * m_norm * (m_expFermiFunc->operator()(deltaTPre) -
530 m_expFermiFunc->operator()(deltaPresamp));
531
532 return C + pulse1 + pulse2;// + bckgd;
533 }
534};
535
537{
538private:
539 float m_tau1{0};
540 float m_tau2{0};
541 float m_timeCorr{0};
542
543 double m_preNorm{1.};
544
545 std::shared_ptr<TF1> m_expFermiLHCfFunc = 0;
546 std::shared_ptr<TF1> m_expFermiPreFunc = 0;
547
548public:
549 ZDCFitExpFermiLHCfPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2);
551
552 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
553 virtual void SetT0FitLimits(float tMin, float tMax) override;
554
555
556 virtual void SetInitialPrePulse(float amp, float t0, float /*expamp = 0*/, bool /*fixPrePulseToZero = false*/) override
557 {
558 double ampMin, ampMax;
559
560 GetWrapperTF1()->GetParLimits(2, ampMin, ampMax);
561 double initialAmp = std::min<double>(std::max<double>(amp, ampMin), ampMax);
562
563 GetWrapperTF1()->SetParameter(4, initialAmp);
564 GetWrapperTF1()->SetParameter(5, t0);
565 }
566
567 virtual void SetPrePulseT0Range(float tmin, float tmax) override;
568 virtual void SetPostPulseT0Range(float /*tmin*/, float /*tmax*/, float /*initialPostT0*/) override {return;}
569
570 virtual void ConstrainFit() override;
571 virtual void UnconstrainFit() override;
572
573 virtual unsigned int GetPreT0ParIndex() const override {return 3;}
574
575 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
576 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
577
578 virtual float GetTau1() const override {return m_tau1;}
579 virtual float GetTau2() const override {return m_tau2;}
580
581 virtual float GetPreT0() const override {return GetWrapperTF1()->GetParameter(3);}
582 virtual float GetPreAmp() const override {return GetWrapperTF1()->GetParameter(3);}
583
584 virtual float GetPostT0() const override {return 0;}
585 virtual float GetPostAmp() const override {return 0;}
586
587 virtual float GetExpAmp() const override {return 0;}
588
589 virtual float GetTime() const override {
590 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
591 }
592
593 virtual unsigned int GetNumShapeParameters() const override {return 1;}
594
595 virtual float GetShapeParameter(size_t index) const override
596 {
597 if (index < 1) return GetWrapperTF1()->GetParameter(6);
598 else throw std::runtime_error("Fit parameter does not exist.");
599 }
600
601 virtual float GetBkgdMaxFraction() const override
602 {
603 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
604
605 double maxTime = GetTime();
606
607 double amp = theTF1->GetParameter(0);
608 if (amp <= 0) return -1;
609
610 double preAmp = theTF1->GetParameter(2);
611 double preT0 = theTF1->GetParameter(3);
612
613 double deltaTPre = maxTime - preT0;
614 double background = preAmp * m_preNorm * m_expFermiLHCfFunc->operator()(deltaTPre);
615
616 return background / (amp + background);
617 }
618
619 virtual double operator() (const double *x, const double *p) override
620 {
621 double t = x[0];
622
623 double amp = p[0];
624 double t0 = p[1];
625 double tau1 = p[2];
626 double tau2 = p[3];
627 double preAmp = p[4];
628 double preT0 = p[5];
629 double C = p[6];
630
631 m_expFermiLHCfFunc->SetParameter(0, amp);
632 m_expFermiLHCfFunc->SetParameter(2, tau1);
633 m_expFermiLHCfFunc->SetParameter(3, tau2);
634 m_expFermiLHCfFunc->SetParameter(4, tau2);
635
636 double deltaT = t - t0;
637 double deltaTPre = t - preT0;
638
639 // We subtract off the value of the pre-pulse at the minimum time (nominally 0,
640 // but can change if we exclude early samples) to account for the subtraction of the pre-sample
641 //
642 double deltaPresamp = GetTMinAdjust() - preT0;
643
644 double pulse1 = m_expFermiLHCfFunc->operator()(deltaT);
645 double pulse2 = preAmp * m_preNorm * (m_expFermiPreFunc->operator()(deltaTPre) -
646 m_expFermiPreFunc->operator()(deltaPresamp));
647
648 return C + pulse1 + pulse2;
649 }
650};
651
653{
654private:
655 float m_tau1{0};
656 float m_tau2{0};
657 float m_timeCorr{0};
658 double m_norm{};
659
660 std::shared_ptr<TF1> m_expFermiFunc{0};
661 std::shared_ptr<TF1> m_expFermiPreFunc{0};
662
663public:
664 ZDCFitExpFermiPreExp(const std::string& tag, float tmin, float tmax, float tau1, float tau2,
665 float defExpTau, float fixExpTau);
667
668 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
669 virtual void SetT0FitLimits(float tMin, float tMax) override;
670
671 virtual void SetInitialExpPulse(float amp) override
672 {
673 GetWrapperTF1()->SetParameter(2, std::max(amp, (float) 0.5)); //0.5 here ensures that we're above lower limit (0)
674 }
675
676 virtual void ConstrainFit() override;
677 virtual void UnconstrainFit() override;
678
679 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
680 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
681
682 virtual float GetTau1() const override {return m_tau1;}
683 virtual float GetTau2() const override {return m_tau2;}
684
685 virtual float GetTime() const override {
686 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
687 }
688
689 virtual float GetExpAmp() const override {return GetWrapperTF1()->GetParameter(2);}
690 virtual float GetExpTau() const override {return GetWrapperTF1()->GetParameter(3);}
691
692 virtual unsigned int GetNumShapeParameters() const override {return 2;}
693
694 virtual float GetShapeParameter(size_t index) const override
695 {
696 if (index < 2) return GetWrapperTF1()->GetParameter(index + 4);
697 else throw std::runtime_error("Fit parameter does not exist.");
698 }
699
700 virtual float GetBkgdMaxFraction() const override
701 {
702 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
703 double maxTime = GetTime();
704
705 double amp = theTF1->GetParameter(0);
706 if (amp <= 0) return -1;
707
708 double preAmp = theTF1->GetParameter(2);
709 double preT0 = theTF1->GetParameter(3);
710
711 double deltaTPre = maxTime - preT0;
712 double background = preAmp * m_norm * m_expFermiFunc->operator()(deltaTPre);
713
714 return background / (amp + background);
715 }
716
717 virtual double operator() (const double *x, const double *p) override
718 {
719 double t = x[0];
720
721 double amp = p[0];
722 double t0 = p[1];
723 double expAmp = p[2];
724 double expTau = p[3];
725 double expSqrtTau = p[4];
726 double C = p[5];
727
728 double deltaT = t - t0;
729 double pulse = amp * m_norm * m_expFermiFunc->operator()(deltaT);
730
731 // We subtract off the value of the exponential pulse at the minimum time (nominally 0),
732 // because it would have been included in the baseline subtraction
733 //
734 double tRef = GetTMinAdjust();
735 double expPre = 0;
736 if (t > 0 && std::abs(expSqrtTau)>1e-6) expPre = expAmp * (std::exp(-t/expTau-expSqrtTau*std::sqrt(t)) - std::exp(-tRef/expTau));
737 else expPre = expAmp * (std::exp(-t/expTau) - std::exp(-tRef/expTau));
738
739 return C + pulse + expPre;
740 }
741};
742
744{
745private:
746 float m_tau1{0};
747 float m_tau2{0};
748 float m_timeCorr{0};
749
750 std::shared_ptr<TF1> m_expFermiLHCfFunc{};
751 std::shared_ptr<TF1> m_expFermiLHCfPreFunc{};
752
753public:
754 ZDCFitExpFermiLHCfPreExp(const std::string& tag, float tmin, float tmax, float tau1, float tau2,
755 float defExpTau, float fixExpTau);
757
758 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
759 virtual void SetT0FitLimits(float tMin, float tMax) override;
760
761 virtual void SetInitialExpPulse(float amp) override
762 {
763 GetWrapperTF1()->SetParameter(4, std::max(amp, (float) 0.5)); //0.5 here ensures that we're above lower limit (0)
764 }
765
766 virtual void ConstrainFit() override;
767 virtual void UnconstrainFit() override;
768
769 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
770 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
771
772 virtual float GetTau1() const override {return m_tau1;}
773 virtual float GetTau2() const override {return m_tau2;}
774
775 virtual float GetTime() const override {
776 const TF1* theTF1 = GetWrapperTF1();
777
778 float fitT0 = theTF1->GetParameter(1);
779
780 float tau1 = theTF1->GetParameter(2);
781 float tau2 = theTF1->GetParameter(3);
782
783 // Correct the time to the maximum
784 //
785 if (tau2 > tau1) fitT0 += tau1 * std::log(tau2 / tau1 - 1.0);
786 return fitT0;
787 }
788
789 virtual float GetExpAmp() const override {return GetWrapperTF1()->GetParameter(4);}
790 virtual float GetExpTau() const override {return GetWrapperTF1()->GetParameter(5);}
791
792 virtual unsigned int GetNumShapeParameters() const override {return 1;}
793 virtual float GetShapeParameter(size_t index) const override
794 {
795 if (index < 1) return GetWrapperTF1()->GetParameter(5);
796 else throw std::runtime_error("Fit parameter does not exist.");
797 }
798
799 virtual float GetBkgdMaxFraction() const override
800 {
801 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
802 double amp = theTF1->GetParameter(0);
803 if (amp <= 0) return -1;
804
805 double maxTime = GetTime();
806
807 double expAmp = theTF1->GetParameter(4);
808 double expTau = theTF1->GetParameter(5);
809 double bexpSqrt = theTF1->GetParameter(6);
810
811 double tRef = GetTMinAdjust();
812 double expPre = expAmp * (std::exp(-maxTime/expTau - bexpSqrt*maxTime*maxTime) - std::exp(-tRef/expTau - bexpSqrt*tRef*tRef));
813
814 return expPre / (amp + expPre);
815 }
816
817 virtual double operator() (const double *x, const double *p) override
818 {
819 double t = x[0];
820
821 double amp = p[0];
822 double t0 = p[1];
823
824 double tau1 = p[2];
825 double tau2 = p[3];
826
827 double expAmp = p[4];
828 double expTau = p[5];
829 double bexpSqrt = p[6];
830 double reflFrac = p[7];
831
832 m_expFermiLHCfFunc->SetParameter(0, amp);
833 m_expFermiLHCfFunc->SetParameter(2, tau1);
834 m_expFermiLHCfFunc->SetParameter(3, tau2);
835 m_expFermiLHCfFunc->SetParameter(6, reflFrac);
836
837 m_timeCorr = m_tau1 * std::log(m_tau2 / m_tau1 - 1.0);
838
839 double deltaT = t - t0;
840 double pulse = m_expFermiLHCfFunc->operator()(deltaT);
841
842 // We subtract off the value of the exponential pulse at the minimum time (nominally 0),
843 // because it would have been included in the baseline subtraction
844 //
845 double tRef = GetTMinAdjust();
846 double expPre = 0;
847
848 expPre = expAmp * (std::exp(-t/expTau - bexpSqrt*t*t) - std::exp(-tRef/expTau - bexpSqrt*tRef*tRef));
849
850 return pulse + expPre;
851 }
852};
853
855{
856private:
857 float m_tau1{0};
858 float m_tau2{0};
859 float m_timeCorr{0};
860
861 std::shared_ptr<TF1> m_expFermiInductFunc{0};
862 std::shared_ptr<TF1> m_expFermiPreFunc{0};
863
864public:
865 ZDCFitExpFermiInductPreExp(const std::string& tag, float tmin, float tmax, float tau1, float tau2,
866 float defExpTau, float fixExpTau);
868
869 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
870 virtual void SetT0FitLimits(float tMin, float tMax) override;
871
872 virtual void SetInitialExpPulse(float amp) override
873 {
874 GetWrapperTF1()->SetParameter(2, std::max(amp, (float) 0.5)); //0.5 here ensures that we're above lower limit (0)
875 }
876
877 virtual void ConstrainFit() override;
878 virtual void UnconstrainFit() override;
879
880 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
881 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
882
883 virtual float GetTau1() const override {return m_tau1;}
884 virtual float GetTau2() const override {return m_tau2;}
885
886 virtual float GetTime() const override {
887 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
888 }
889
890 virtual float GetExpAmp() const override {return GetWrapperTF1()->GetParameter(2);}
891 virtual float GetExpTau() const override {return GetWrapperTF1()->GetParameter(3);}
892
893 virtual unsigned int GetNumShapeParameters() const override {return 3;}
894
895 virtual float GetShapeParameter(size_t index) const override
896 {
897 if (index < 3) {
898 if (index == 0) return GetWrapperTF1()->GetParameter(4);
899 if (index == 1) return GetWrapperTF1()->GetParameter(6);
900 if (index == 2) return GetWrapperTF1()->GetParameter(7);
901 }
902 throw std::runtime_error("Fit parameter does not exist.");
903 }
904
905 virtual float GetBkgdMaxFraction() const override
906 {
907 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
908 double amp = theTF1->GetParameter(0);
909 if (amp <= 0) return -1;
910
911 double maxTime = GetTime();
912
913 double expAmp = theTF1->GetParameter(2);
914 double expTau = theTF1->GetParameter(3);
915 double bexpSqrt = theTF1->GetParameter(4);
916
917 double tRef = GetTMinAdjust();
918 double expPre = expAmp * (std::exp(-maxTime/expTau - bexpSqrt*maxTime*maxTime) - std::exp(-tRef/expTau - bexpSqrt*tRef*tRef));
919
920 return expPre / (amp + expPre);
921 }
922
923 virtual double operator() (const double *x, const double *p) override
924 {
925 double t = x[0];
926
927 double amp = p[0];
928 double t0 = p[1];
929
930 double expAmp = p[2];
931 double expTau = p[3];
932 double bexpSqrt = p[4];
933 double C = p[5];
934 double inductA = p[6];
935 double inductB = p[7];
936
937 m_expFermiInductFunc->SetParameter(0, amp);
938 m_expFermiInductFunc->SetParameter(6, inductA);
939 m_expFermiInductFunc->SetParameter(7, inductB);
940
941 double deltaT = t - t0;
942 double pulse = m_expFermiInductFunc->operator()(deltaT);
943
944 // We subtract off the value of the exponential pulse at the minimum time (nominally 0),
945 // because it would have been included in the baseline subtraction
946 //
947 double tRef = GetTMinAdjust();
948 double expPre = 0;
949
950 expPre = expAmp * (std::exp(-t/expTau - bexpSqrt*t*t) - std::exp(-tRef/expTau - bexpSqrt*tRef*tRef));
951
952 return pulse + C + expPre;
953 }
954};
955
956
957// ----------------------------------------------------------------------
959{
960private:
961 float m_tau1{};
962 float m_tau2{};
963
964 float m_norm{};
965 float m_timeCorr{};
966
967 std::shared_ptr<TF1> m_expFermiFunc;
968
969public:
970
971 ZDCFitExpFermiLinearFixedTaus(const std::string& tag, float tmin, float tmax, float tau1, float tau2);
972
974
975 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
976 virtual void SetT0FitLimits(float tMin, float tMax) override;
977
978 virtual void ConstrainFit() override;
979 virtual void UnconstrainFit() override;
980
981 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
982 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
983
984 virtual float GetTau1() const override {return m_tau1;}
985 virtual float GetTau2() const override {return m_tau2;}
986
987 virtual float GetTime() const override {
988 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
989 }
990
991 virtual unsigned int GetNumShapeParameters() const override {return 2;}
992 virtual float GetShapeParameter(size_t index) const override
993 {
994 if (index < 2) return GetWrapperTF1()->GetParameter(index + 2);
995 else throw std::runtime_error("Fit parameter does not exist.");
996 }
997
998 virtual float GetBkgdMaxFraction() const override
999 {
1000 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
1001 double amp = theTF1->GetParameter(0);
1002 if (amp <= 0) return -1;
1003
1004 double slope = theTF1->GetParameter(2);
1005
1006 double background = slope * GetTime();
1007 return background / amp;
1008 }
1009
1010 virtual double operator() (const double *x, const double *p) override
1011 {
1012 double amp = p[0];
1013 double t0 = p[1];
1014 double deltaT = x[0] - t0;
1015
1016 double bckgd = p[2] * x[0] + p[3];
1017
1018 double expFermi = amp * m_norm * m_expFermiFunc->operator()(deltaT);
1019
1020 return expFermi + bckgd;
1021 }
1022};
1023
1024// ----------------------------------------------------------------------
1026{
1027private:
1028 float m_tau1{};
1029 float m_tau2{};
1030 float m_norm{};
1031 float m_timeCorr{};
1032 std::shared_ptr<TF1> m_expFermiFunc;
1033
1034public:
1035 ZDCFitExpFermiLinearPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2);
1037
1038 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
1039 virtual void SetT0FitLimits(float tMin, float tMax) override;
1040
1041 virtual void ConstrainFit() override;
1042 virtual void UnconstrainFit() override;
1043
1044 virtual void SetInitialPrePulse(float amp, float t0, float /*expamp = 0*/, bool /*fixPrePulseToZero = false*/) override {
1045 GetWrapperTF1()->SetParameter(2, std::max(amp, (float) 1.5)); //1.5 here ensures that we're above lower limit
1046 GetWrapperTF1()->SetParameter(3, t0);
1047 }
1048
1049 virtual void SetPrePulseT0Range(float tmin, float tmax) override;
1050 virtual void SetPostPulseT0Range(float /*tmin*/, float /*tmax*/, float /*initialPostT0*/) override {return;}
1051
1052 unsigned int GetPreT0ParIndex() const override {return 3;}
1053
1054 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
1055 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
1056
1057 virtual float GetTau1() const override {return m_tau1;}
1058 virtual float GetTau2() const override {return m_tau2;}
1059
1060 virtual float GetPreT0() const override {
1061 float fitPreT0 = GetWrapperTF1()->GetParameter(3);
1062
1063 // Correct the time to the maximum
1064 //
1065 fitPreT0 += m_timeCorr;
1066
1067 return fitPreT0;
1068 }
1069 virtual float GetPreAmp() const override {return GetWrapperTF1()->GetParameter(2);}
1070
1071 virtual float GetPostT0() const override {return 0;}
1072 virtual float GetPostAmp() const override {return 0;}
1073
1074 virtual float GetExpAmp() const override {return 0;}
1075
1076 virtual float GetTime() const override {
1077 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
1078 }
1079
1080 virtual unsigned int GetNumShapeParameters() const override {return 1;}
1081
1082 virtual float GetShapeParameter(size_t index) const override
1083 {
1084 if (index < 1) return GetWrapperTF1()->GetParameter(index + 4);
1085 else throw std::runtime_error("Fit parameter does not exist.");
1086 }
1087
1088 virtual float GetBkgdMaxFraction() const override
1089 {
1090 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
1091
1092 double maxTime = GetTime();
1093
1094 double amp = theTF1->GetParameter(0);
1095 if (amp <= 0) return -1;
1096
1097 double preAmp = theTF1->GetParameter(2);
1098 double preT0 = theTF1->GetParameter(3);
1099 double slope = theTF1->GetParameter(4);
1100
1101 double deltaTPre = maxTime - preT0;
1102
1103 double background = slope * maxTime + preAmp * m_norm * (m_expFermiFunc->operator()(deltaTPre) -
1104 m_expFermiFunc->operator()(-preT0));
1105
1106 return background / amp;
1107 }
1108
1109 virtual double operator() (const double *x, const double *p) override
1110 {
1111 double t = x[0];
1112
1113 double amp = p[0];
1114 double t0 = p[1];
1115 double preAmp = p[2];
1116 double preT0 = p[3];
1117 double linSlope = p[4];
1118
1119 double deltaT = t - t0;
1120 double deltaTPre = t - preT0;
1121
1122 // We subtract off the value of the pre-pulse at the minimum time (nominally 0,
1123 // but can change if we exclude early samples) to account for the subtraction of the pre-sample
1124 //
1125 double deltaPresamp = GetTMinAdjust() - preT0;
1126
1127 double pulse1 = amp * m_norm * m_expFermiFunc->operator()(deltaT);
1128 double pulse2 = preAmp * m_norm * (m_expFermiFunc->operator()(deltaTPre) -
1129 m_expFermiFunc->operator()(deltaPresamp));
1130
1131 double bckgd = linSlope * (t - deltaPresamp) + p[5];
1132
1133 return pulse1 + pulse2 + bckgd;
1134 }
1135};
1136
1137
1138
1139// ----------------------------------------------------------------------
1141{
1142private:
1143 float m_tau1{};
1144 float m_tau2{};
1145 float m_norm{};
1146 float m_timeCorr{};
1147 std::shared_ptr<TF1> m_expFermiFunc;
1148
1149public:
1150 ZDCFitComplexPrePulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2);
1152
1153 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
1154 virtual void SetT0FitLimits(float tMin, float tMax) override;
1155
1156 virtual void SetInitialPrePulse(float amp, float t0, float expamp, bool /*fixPrePulseToZero = false*/) override {
1157 GetWrapperTF1()->SetParameter(2, std::max(amp, (float) 1.5)); //1.5 here ensures that we're above lower limit
1158 GetWrapperTF1()->SetParameter(3, t0);
1159 GetWrapperTF1()->SetParameter(6, std::max(std::abs(expamp), (float) 1.5));
1160 }
1161
1162 virtual void ConstrainFit() override;
1163 virtual void UnconstrainFit() override;
1164
1165 virtual void SetPrePulseT0Range(float tmin, float tmax) override;
1166 virtual void SetPostPulseT0Range(float /*tmin*/, float /*tmax*/, float /*initialPostT0*/) override {return;}
1167
1168 unsigned int GetPreT0ParIndex() const override {return 3;}
1169
1170 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
1171 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
1172
1173 virtual float GetTau1() const override {return m_tau1;}
1174 virtual float GetTau2() const override {return m_tau2;}
1175
1176 virtual float GetPreT0() const override {
1177 float fitPreT0 = GetWrapperTF1()->GetParameter(3);
1178
1179 // Correct the time to the maximum
1180 //
1181 fitPreT0 += m_timeCorr;
1182
1183 return fitPreT0;
1184 }
1185 virtual float GetPreAmp() const override {return GetWrapperTF1()->GetParameter(2);}
1186
1187 virtual float GetPostT0() const override {return 0;}
1188 virtual float GetPostAmp() const override {return 0;}
1189
1190 virtual float GetExpAmp() const override {return GetWrapperTF1()->GetParameter(6);}
1191
1192 virtual float GetTime() const override {
1193 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
1194 }
1195
1196 virtual unsigned int GetNumShapeParameters() const override {return 3;}
1197
1198 virtual float GetShapeParameter(size_t index) const override
1199 {
1200 if (index < 3) return GetWrapperTF1()->GetParameter(4 + index);
1201 else throw std::runtime_error("Fit parameter does not exist.");
1202 }
1203
1204 virtual float GetBkgdMaxFraction() const override
1205 {
1206 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
1207
1208 double maxTime = GetTime();
1209
1210 double amp = theTF1->GetParameter(0);
1211 if (amp <= 0) return -1;
1212
1213 double preAmp = theTF1->GetParameter(2);
1214 double preT0 = theTF1->GetParameter(3);
1215 double slope = theTF1->GetParameter(4);
1216
1217 double deltaTPre = maxTime - preT0;
1218
1219 double background = slope * maxTime + preAmp * m_norm * (m_expFermiFunc->operator()(deltaTPre) -
1220 m_expFermiFunc->operator()(-preT0));
1221
1222 return background / amp;
1223 }
1224
1225 virtual double operator() (const double *x, const double *p) override
1226 {
1227 double t = x[0];
1228
1229 double amp = p[0];
1230 double t0 = p[1];
1231 double preAmp = p[2];
1232 double preT0 = p[3];
1233 double linSlope = p[4];
1234 double linConst = p[5];
1235 double expamp = p[6];
1236
1237 double deltaT = t - t0;
1238 double deltaTPre = t - preT0;
1239
1240 // We subtract off the value of the pre-pulse at the minimum time (nominally 0,
1241 // but can change if we exclude early samples) to account for the subtraction of the pre-sample
1242 //
1243 double deltaPresamp = GetTMinAdjust() - preT0;
1244
1245 double pulse1 = amp * m_norm * m_expFermiFunc->operator()(deltaT);
1246 double pulse2 = preAmp * m_norm * (m_expFermiFunc->operator()(deltaTPre) - m_expFermiFunc->operator()(deltaPresamp));
1247
1248 double linBG = linSlope * (t - deltaPresamp) + linConst;
1249 double expBG = expamp * std::exp(-(t) / m_tau2) - expamp; // deltaPresamp
1250
1251 return pulse1 + pulse2 + linBG + expBG;
1252 }
1253};
1254
1255
1256// ----------------------------------------------------------------------
1258{
1259private:
1260 float m_tau1{};
1261 float m_tau2{};
1262 float m_norm{};
1263 float m_timeCorr{};
1264 std::shared_ptr<TF1> m_expFermiFunc;
1265
1266public:
1267 ZDCFitGeneralPulse(const std::string& tag, float tmin, float tmax, float tau1, float tau2);
1269
1270 virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax) override;
1271 virtual void SetT0FitLimits(float tMin, float tMax) override;
1272
1273 virtual void SetInitialPrePulse(float amp, float t0, float expamp, bool fixPrePulseToZero) override {
1274 GetWrapperTF1()->ReleaseParameter(2);
1275 GetWrapperTF1()->ReleaseParameter(3);
1276 GetWrapperTF1()->SetParameter(2, std::max(amp, (float) 1.5)); //1.5 here ensures that we're above lower limit
1277 GetWrapperTF1()->SetParameter(3, std::max(t0, (float) 20.0));
1278 GetWrapperTF1()->SetParameter(6, std::max(std::abs(expamp), (float) 1.5));
1279
1280 if (fixPrePulseToZero) {
1281 GetWrapperTF1()->FixParameter(2, 0. );
1282 GetWrapperTF1()->FixParameter(3, 20.);
1283 }
1284 }
1285
1286 virtual void ConstrainFit() override;
1287 virtual void UnconstrainFit() override;
1288
1289 virtual void SetPrePulseT0Range(float tmin, float tmax) override;
1290 virtual void SetPostPulseT0Range(float tmin, float tmax, float initialPostT0) override;
1291
1292 unsigned int GetPreT0ParIndex() const override {return 3;}
1293
1294 virtual float GetAmplitude() const override {return GetWrapperTF1()->GetParameter(0); }
1295 virtual float GetAmpError() const override {return GetWrapperTF1()->GetParError(0); }
1296
1297 virtual float GetTau1() const override {return m_tau1;}
1298 virtual float GetTau2() const override {return m_tau2;}
1299
1300 virtual float GetPreT0() const override {
1301 float fitPreT0 = GetWrapperTF1()->GetParameter(3);
1302
1303 // Correct the time to the maximum
1304 //
1305 fitPreT0 += m_timeCorr;
1306
1307 return fitPreT0;
1308 }
1309 virtual float GetPreAmp() const override {return GetWrapperTF1()->GetParameter(2);}
1310
1311 virtual float GetPostT0() const override {
1312 float fitPostT0 = GetWrapperTF1()->GetParameter(8);
1313
1314 // Correct the time to the maximum
1315 //
1316 fitPostT0 += m_timeCorr;
1317
1318 return fitPostT0;
1319 }
1320 virtual float GetPostAmp() const override {return GetWrapperTF1()->GetParameter(7);}
1321
1322 virtual float GetExpAmp() const override {return GetWrapperTF1()->GetParameter(6);}
1323
1324 virtual float GetTime() const override {
1325 return GetWrapperTF1()->GetParameter(1) + m_timeCorr; // Correct the time to the maximum
1326 }
1327
1328 virtual unsigned int GetNumShapeParameters() const override {return 5;}
1329
1330 virtual float GetShapeParameter(size_t index) const override
1331 {
1332 if (index < 5) return GetWrapperTF1()->GetParameter(index + 4);
1333 else throw std::runtime_error("Fit parameter does not exist.");
1334 }
1335
1336 virtual float GetBkgdMaxFraction() const override
1337 {
1338 const TF1* theTF1 = ZDCFitWrapper::GetWrapperTF1();
1339
1340 double maxTime = GetTime();
1341
1342 double amp = theTF1->GetParameter(0);
1343 if (amp <= 0) return -1;
1344 double preAmp = theTF1->GetParameter(2);
1345 double preT0 = theTF1->GetParameter(3);
1346 double slope = theTF1->GetParameter(4);
1347
1348 double deltaTPre = maxTime - preT0;
1349
1350 double background = slope * maxTime + preAmp * m_norm * (m_expFermiFunc->operator()(deltaTPre) -
1351 m_expFermiFunc->operator()(-preT0));
1352
1353 return background / amp;
1354 }
1355
1356 virtual double operator() (const double *x, const double *p) override
1357 {
1358 double t = x[0];
1359
1360 double amp = p[0];
1361 double t0 = p[1];
1362 double preAmp = p[2];
1363 double preT0 = p[3];
1364 double linSlope = p[4];
1365 double linConst = p[5];
1366 double expamp = p[6];
1367 double postAmp = p[7];
1368 double postT0 = p[8];
1369
1370 double deltaT = t - t0;
1371 double deltaTPre = t - preT0;
1372 double deltaTPost = t - postT0;
1373
1374 // We subtract off the value of the pre-pulse at the minimum time (nominally 0,
1375 // but can change if we exclude early samples) to account for the subtraction of the pre-sample
1376 //
1377 double deltaPresamp = GetTMinAdjust() - preT0;
1378
1379 double pulse1 = amp * m_norm * m_expFermiFunc->operator()(deltaT);
1380 double pulse2 = preAmp * m_norm * (m_expFermiFunc->operator()(deltaTPre) - m_expFermiFunc->operator()(deltaPresamp));
1381 double pulse3 = postAmp * m_norm * m_expFermiFunc->operator()(deltaTPost);
1382
1383 double linBG = linSlope * t + linConst;
1384 double expBG = expamp * std::exp(-(t) / m_tau2) - expamp * std::exp(-(GetTMinAdjust()) / m_tau2); // deltaPresamp
1385
1386 return pulse1 + pulse2 + pulse3 + linBG + expBG;
1387 }
1388};
1389
1390double ZDCFermiExpFit(const double* xvec, const double* pvec)
1391{
1392 double t = xvec[0];
1393
1394 double amp = pvec[0];
1395 double t0 = pvec[1];
1396 double tau1 = pvec[2];
1397 double tau2 = pvec[3];
1398 double C = pvec[4];
1399
1400 double tauRatio = tau2 / tau1;
1401 double tauRatioMinunsOne = tauRatio - 1;
1402
1403 double norm = (std::pow(1. / tauRatioMinunsOne, 1. / (1 + tauRatio)) /
1404 ( 1 + std::pow(1. / tauRatioMinunsOne, 1. / (1 + 1 / tauRatio))));
1405
1406 double deltaT = t - t0;
1407 if (deltaT < 0) deltaT = 0;
1408
1409 double expTerm = std::exp(-deltaT / tau2);
1410 double fermiTerm = 1. / (1. + std::exp(-(t - t0) / tau1));
1411
1412 return amp * expTerm * fermiTerm / norm + C;
1413}
1414
1415double ZDCFermiExpFitRefl(const double* xvec, const double* pvec)
1416{
1417 double t = xvec[0];
1418
1419 double amp = pvec[0];
1420 double t0 = pvec[1];
1421 double tau1 = pvec[2];
1422 double tau2 = pvec[3];
1423 double C = pvec[4];
1424
1425 double refldelay = pvec[5];
1426 double reflFrac = pvec[6];
1427 double reflwidth = pvec[7];
1428 double delta = pvec[8];
1429
1430 double tauRatio = tau2 / tau1;
1431 double tauRatioMinunsOne = tauRatio - 1;
1432
1433 double norm = std::pow(1. / tauRatioMinunsOne, 1. / (1 + tauRatio)) /
1434 ( 1 + std::pow(1. / tauRatioMinunsOne, 1. / (1 + 1 / tauRatio))) ;
1435
1436 double deltaT = t - t0;
1437 if (deltaT < 0) deltaT = 0;
1438
1439 // Note: the small constant added here accounts for the very long tail on the pulse
1440 // which doesn't go to zero over the time range that we sample
1441 //
1442 double expTerm = delta + std::exp(-deltaT / tau2);
1443 double fermiTerm = 1. / (1. + std::exp(-(t - t0) / tau1));
1444
1445 double deltaTRefl = deltaT - refldelay;
1446 double reflTerm = -reflFrac*amp*std::exp(-0.5*deltaTRefl*deltaTRefl/reflwidth/reflwidth);
1447
1448 return amp * expTerm * fermiTerm / norm + C + reflTerm;
1449}
1450
1451double ZDCFermiExpFitInduct(const double* xvec, const double* pvec)
1452{
1453 double t = xvec[0];
1454
1455 double amp = pvec[0];
1456 double t0 = pvec[1];
1457 double tau1 = pvec[2];
1458 double tau2 = pvec[3];
1459 double C = pvec[4];
1460
1461 double period = pvec[5];
1462 double Acos = pvec[6];
1463 double Bsin = pvec[7];
1464 double delta = pvec[8];
1465
1466 double tauRatio = tau2 / tau1;
1467 double tauRatioMinunsOne = tauRatio - 1;
1468
1469 double norm = std::pow(1. / tauRatioMinunsOne, 1. / (1.0 + tauRatio)) /
1470 ( 1.0 + std::pow(1. / tauRatioMinunsOne, 1. / (1.0 + 1.0 / tauRatio))) ;
1471
1472 double deltaT = t - t0;
1473 double deltaTInduct = deltaT - tau1 * std::log(tauRatioMinunsOne);
1474
1475 if (deltaT < 0) deltaT = 0;
1476 if (deltaTInduct < 0) deltaTInduct = 0;
1477
1478 // Note: the small constant added here accounts for the very long tail on the pulse
1479 // which doesn't go to zero over the time range that we sample
1480
1481 double twoPiOverPeriod = 2.0*M_PI/period;
1482 double inductTerm = (1.0 + Acos*std::cos(deltaTInduct*twoPiOverPeriod) +
1483 Bsin*std::sin(deltaTInduct*twoPiOverPeriod))/(1+Acos);
1484 double expTerm = delta + std::exp(-deltaT / tau2)*inductTerm;
1485 double fermiTerm = 1. / (1. + std::exp(-(t - t0) / tau1));
1486
1487 return amp * expTerm * fermiTerm / norm + C;
1488}
1489
1490#endif
#define M_PI
std::array< fp_t, 2 > pvec
static Double_t t0
#define x
double ZDCFermiExpFit(const double *xvec, const double *pvec)
double ZDCFermiExpFitRefl(const double *xvec, const double *pvec)
double ZDCFermiExpFitInduct(const double *xvec, const double *pvec)
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
virtual float GetPreAmp() const override
virtual float GetTau1() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetBkgdMaxFraction() const override
virtual float GetPostAmp() const override
virtual float GetExpAmp() const override
virtual float GetTime() const override
virtual void SetPostPulseT0Range(float, float, float) override
virtual float GetAmpError() const override
virtual float GetPreT0() const override
virtual float GetTau2() const override
virtual float GetPostT0() const override
ZDCFitComplexPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual void SetInitialPrePulse(float amp, float t0, float expamp, bool) override
unsigned int GetPreT0ParIndex() const override
std::shared_ptr< TF1 > m_expFermiFunc
virtual float GetAmplitude() const override
virtual unsigned int GetNumShapeParameters() const override
ZDCFitExpFermiFixedTaus(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual float GetAmplitude() const override
virtual float GetBkgdMaxFraction() const override
virtual float GetTau1() const override
virtual float GetTime() const override
virtual float GetAmpError() const override
virtual unsigned int GetNumShapeParameters() const override
virtual float GetShapeParameter(size_t index) const override
std::shared_ptr< TF1 > m_expFermiFunc
virtual float GetTau2() const override
virtual float GetExpTau() const override
virtual unsigned int GetNumShapeParameters() const override
std::shared_ptr< TF1 > m_expFermiInductFunc
virtual float GetTime() const override
virtual float GetTau1() const override
virtual float GetTau2() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetExpAmp() const override
virtual void SetInitialExpPulse(float amp) override
virtual float GetAmpError() const override
std::shared_ptr< TF1 > m_expFermiPreFunc
ZDCFitExpFermiInductPreExp(const std::string &tag, float tmin, float tmax, float tau1, float tau2, float defExpTau, float fixExpTau)
virtual float GetAmplitude() const override
virtual float GetBkgdMaxFraction() const override
virtual float GetTau1() const override
virtual float GetExpTau() const override
virtual float GetTau2() const override
virtual unsigned int GetNumShapeParameters() const override
std::shared_ptr< TF1 > m_expFermiLHCfFunc
std::shared_ptr< TF1 > m_expFermiLHCfPreFunc
virtual float GetShapeParameter(size_t index) const override
virtual float GetTime() const override
virtual float GetBkgdMaxFraction() const override
virtual float GetExpAmp() const override
ZDCFitExpFermiLHCfPreExp(const std::string &tag, float tmin, float tmax, float tau1, float tau2, float defExpTau, float fixExpTau)
virtual float GetAmplitude() const override
virtual float GetAmpError() const override
virtual void SetInitialExpPulse(float amp) override
virtual unsigned int GetPreT0ParIndex() const override
std::shared_ptr< TF1 > m_expFermiPreFunc
virtual float GetBkgdMaxFraction() const override
virtual float GetAmpError() const override
virtual unsigned int GetNumShapeParameters() const override
virtual float GetExpAmp() const override
virtual float GetTau2() const override
std::shared_ptr< TF1 > m_expFermiLHCfFunc
virtual float GetPreT0() const override
virtual void SetPostPulseT0Range(float, float, float) override
virtual float GetPostT0() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetTime() const override
virtual float GetPreAmp() const override
ZDCFitExpFermiLHCfPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual float GetTau1() const override
virtual float GetPostAmp() const override
virtual float GetAmplitude() const override
virtual void SetInitialPrePulse(float amp, float t0, float, bool) override
std::shared_ptr< TF1 > m_expFermiFunc
virtual float GetBkgdMaxFraction() const override
virtual float GetAmpError() const override
virtual float GetTime() const override
virtual unsigned int GetNumShapeParameters() const override
ZDCFitExpFermiLinearFixedTaus(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual float GetTau1() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetTau2() const override
virtual float GetAmplitude() const override
virtual unsigned int GetNumShapeParameters() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetPreT0() const override
virtual float GetPostAmp() const override
virtual float GetBkgdMaxFraction() const override
virtual float GetAmplitude() const override
virtual void SetInitialPrePulse(float amp, float t0, float, bool) override
virtual float GetPostT0() const override
virtual float GetPreAmp() const override
virtual float GetTau1() const override
unsigned int GetPreT0ParIndex() const override
virtual float GetExpAmp() const override
virtual float GetTime() const override
virtual void SetPostPulseT0Range(float, float, float) override
virtual float GetAmpError() const override
virtual float GetTau2() const override
ZDCFitExpFermiLinearPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
std::shared_ptr< TF1 > m_expFermiFunc
virtual float GetExpAmp() const override
virtual unsigned int GetNumShapeParameters() const override
virtual float GetTau1() const override
virtual float GetAmpError() const override
std::shared_ptr< TF1 > m_expFermiFunc
virtual float GetShapeParameter(size_t index) const override
std::shared_ptr< TF1 > m_expFermiPreFunc
virtual float GetBkgdMaxFraction() const override
virtual float GetAmplitude() const override
virtual void SetInitialExpPulse(float amp) override
virtual float GetExpTau() const override
ZDCFitExpFermiPreExp(const std::string &tag, float tmin, float tmax, float tau1, float tau2, float defExpTau, float fixExpTau)
virtual float GetTime() const override
virtual float GetTau2() const override
std::shared_ptr< TF1 > m_expFermiPreFunc
virtual float GetPostT0() const override
virtual float GetExpAmp() const override
virtual float GetTau1() const override
virtual float GetAmplitude() const override
virtual float GetAmpError() const override
virtual float GetBkgdMaxFraction() const override
virtual unsigned int GetNumShapeParameters() const override
std::shared_ptr< TF1 > m_expFermiFunc
virtual void SetInitialPrePulse(float amp, float t0, float, bool) override
virtual void SetPostPulseT0Range(float, float, float) override
virtual float GetPreT0() const override
virtual float GetPostAmp() const override
virtual unsigned int GetPreT0ParIndex() const override
ZDCFitExpFermiPrePulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual float GetTime() const override
virtual float GetPreAmp() const override
virtual float GetTau2() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetTime() const override
virtual float GetTau1() const override
ZDCFitExpFermiVariableTausInduct(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual double operator()(const double *x, const double *p) override
virtual float GetTau2() const override
virtual float GetShapeParameter(size_t index) const override
virtual unsigned int GetNumShapeParameters() const override
virtual float GetAmplitude() const override
virtual float GetAmpError() const override
virtual float GetBkgdMaxFraction() const override
virtual float GetTime() const override
virtual double operator()(const double *x, const double *p) override
virtual float GetAmplitude() const override
ZDCFitExpFermiVariableTausLHCf(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual float GetShapeParameter(size_t index) const override
virtual float GetBkgdMaxFraction() const override
virtual float GetTau1() const override
virtual float GetAmpError() const override
virtual float GetTau2() const override
virtual unsigned int GetNumShapeParameters() const override
ZDCFitExpFermiVariableTausRun3(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual float GetTime() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetTau2() const override
virtual float GetAmplitude() const override
virtual double operator()(const double *x, const double *p) override
virtual float GetTau1() const override
ZDCFitExpFermiVariableTaus(const std::string &tag, float tmin, float tmax, bool fixTau1, bool fixTau2, float tau1, float tau2)
virtual float GetBkgdMaxFraction() const override
virtual unsigned int GetNumShapeParameters() const override
virtual float GetAmpError() const override
virtual float GetPreAmp() const override
virtual float GetAmpError() const override
virtual float GetPostT0() const override
virtual float GetPreT0() const override
virtual float GetAmplitude() const override
virtual float GetTau2() const override
unsigned int GetPreT0ParIndex() const override
virtual float GetPostAmp() const override
std::shared_ptr< TF1 > m_expFermiFunc
virtual unsigned int GetNumShapeParameters() const override
virtual float GetShapeParameter(size_t index) const override
virtual float GetExpAmp() const override
virtual float GetTime() const override
virtual void SetInitialPrePulse(float amp, float t0, float expamp, bool fixPrePulseToZero) override
virtual float GetBkgdMaxFraction() const override
virtual float GetTau1() const override
ZDCFitGeneralPulse(const std::string &tag, float tmin, float tmax, float tau1, float tau2)
virtual float GetTau1() const =0
void Initialize(float initialAmp, float initialT0, float ampMin, float ampMax)
float GetTMin() const
virtual float GetBkgdMaxFraction() const =0
virtual void ConstrainFit()=0
virtual TF1 * GetWrapperTF1RawPtr() const
virtual std::shared_ptr< TF1 > GetWrapperTF1()
virtual float GetAmpError() const =0
virtual void UnconstrainFit()=0
float GetT0Max() const
virtual float GetTime() const =0
virtual float GetShapeParameter(size_t index) const =0
virtual ~ZDCFitWrapper()
float GetMinAmp() const
virtual float GetTau2() const =0
float GetMaxAmp() const
virtual const TF1 * GetWrapperTF1() const
float GetT0Min() const
virtual void SetT0FitLimits(float tMin, float tMax)=0
ZDCFitWrapper(const std::shared_ptr< TF1 > &wrapperTF1)
virtual float GetAmplitude() const =0
void SetAmpMinMax(float minAmp, float maxAmp)
virtual unsigned int GetNumShapeParameters() const =0
virtual void DoInitialize(float initialAmp, float initialT0, float ampMin, float ampMax)=0
virtual double operator()(const double *x, const double *p)=0
float GetTMinAdjust() const
void SetT0Range(float t0Min, float t0Max)
float GetTMax() const
std::shared_ptr< TF1 > m_wrapperTF1
virtual float GetExpAmp() const =0
virtual float GetExpTau() const =0
virtual void SetInitialExpPulse(float expamp)=0
float getDefaultExpTau() const
ZDCPreExpFitWrapper(std::shared_ptr< TF1 > wrapperTF1, float defaultExpTau, bool fixTau)
bool fixExpTau() const
virtual float GetPreAmp() const =0
virtual void SetPostPulseT0Range(float tmin, float tmax, float initialPostT0)=0
virtual unsigned int GetPreT0ParIndex() const =0
virtual float GetPreT0() const =0
virtual float GetPostT0() const =0
virtual float GetExpAmp() const =0
virtual void SetPrePulseT0Range(float tmin, float tmax)=0
virtual void SetInitialPrePulse(float amp, float t0, float expamp, bool fixPrePulseToZero)=0
ZDCPrePulseFitWrapper(std::shared_ptr< TF1 > wrapperTF1)
virtual float GetPostAmp() const =0
struct color C
Definition index.py:1