CbmRoot
Loading...
Searching...
No Matches
CbmTrdSpadic.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pascal Raisig [committer] */
4
5#include "CbmTrdSpadic.h"
6
7#include <RtypesCore.h>
8#include <TH1.h>
9#include <TMath.h> // for SpadicResponse function
10#include <TRandom.h>
11
12#include <cstddef>
13#include <cstdint>
14#include <limits>
15#include <vector>
16
17
19
20// const Double_t CbmTrdSpadic::fgShapingTime = 142.0;
21const Double_t CbmTrdSpadic::fgShapingTime = 120.0;
22const Double_t CbmTrdSpadic::fgChargeToMaxAdcCal = 2.73;
23
26
27// ---- GetResponseFunc ----
28std::shared_ptr<TF1> CbmTrdSpadic::GetResponseFunc()
29{
30 auto funcSpadicResponse = std::make_shared<TF1>(TF1("funcSpadicResponse", Response, 0, (fgNrOfAdcSamples - 1), 6));
31 funcSpadicResponse->SetParNames("Shaping time", "Shaping order", "Input charge", "Bin timeshift", "Nr of presamples",
32 "Charge Calibration");
33
34 // Set the default parameters
35 std::vector<Double_t> parvec = {fgShapingTime, fgShapingOrder, 0.0,
37 funcSpadicResponse->SetParameters(parvec.data());
38
39 return funcSpadicResponse;
40}
41
42// ---- Response ----
43Double_t CbmTrdSpadic::Response(Double_t* samplenr, Double_t* par)
44{
45
46 // par[0] = shaping time of the first shaping station
47 // par[1] = shaping order
48 // par[2] = input charge
49 // par[3] = timeshift inside the 62.5 ns bin of a CC
50 // par[4] = number of presamples
51 // par[5] = charge calibration factor
52
53 // histo comes in cc but spadicResponse is in ns
54 Double_t t = (samplenr[0] - par[4]) * fgClockCycleLength + par[3];
55
56 Double_t response =
57 t >= 0 ? ((par[2] * par[5]) * TMath::Power((t / par[0]), ((Int_t) par[1])) * TMath::Exp(-(t / par[0]))) : 0;
58
59 return response;
60}
61
62// ---- Response ----
63Double_t CbmTrdSpadic::Response(UInt_t samplenr)
64{
65 Double_t samplepos = samplenr;
66
67 return Response(&samplepos, fvecResponsePars.data());
68}
69
70// ---- GetAnalogResponse ----
71std::vector<std::int16_t> CbmTrdSpadic::GetAnalogResponsePulse(Double_t inputCharge, Double_t binTimeshift)
72{
73 // If a timeshift should be taken into account, it has to be set before calling this function via SetParameter(eResponsePars::kBinTimeShift, yourTimeShiftHere);
74 std::vector<std::int16_t> pulse(CbmTrdSpadic::GetNrOfAdcSamples(), 0.0);
76
78
79 for (UInt_t isample = fvecResponsePars.at(static_cast<size_t>(eResponsePars::kNrPresamples)); isample < pulse.size();
80 isample++) {
81
82 auto response = Response(isample) / fMaxAdcToMipCal;
83 // calibrate response to MIP
84
85 // Add baseline lvl to the response
86 response += fBaselineLvl;
87
88 // Add noise if requested (protect 0 against real numbers)
89 if (fNoiseLvl > 1e-20) response += GetNoise(fNoiseLvl);
90
91 // Check the sample for potential clipping. Since, we also have analog clipping in the same region as the digital clipping we also check for it here.
92 // To deactivate simply set to an unreasonable high value
93 if (response > fClippingStart) response = fClippingStart;
94 pulse.at(isample) = response;
95 }
96 return pulse;
97}
98
99// ---- GetNoise ----
100Int_t CbmTrdSpadic::GetNoise(Double_t sigmaNoise)
101{
102 Int_t noise = gRandom->Gaus(0, sigmaNoise);
103 return noise;
104}
105
106// ---- GetAnalyticTimeshift ----
107Double_t CbmTrdSpadic::GetAnalyticTimeshift(Double_t absolutetime)
108{
109 Double_t timeshift = (static_cast<Int_t>(absolutetime * 10) % static_cast<Int_t>(GetClockCycle() * 10)) / 10.0;
110
111 timeshift = timeshift >= 0 ? timeshift - (GetClockCycle() / 2) : 0;
112
113 return timeshift;
114}
115
116// ---- GetPeakingSamplePos ----
118{
119 UInt_t peakbin =
120 static_cast<UInt_t>(fvecResponsePars.at(static_cast<size_t>(eResponsePars::kShapingTime)) / fgClockCycleLength
121 + static_cast<UInt_t>(fvecResponsePars.at(static_cast<size_t>(eResponsePars::kNrPresamples))));
122 return peakbin;
123}
124
125// ---- MaxAdcToEnergyCal ----
126Float_t CbmTrdSpadic::MaxAdcToEnergyCal(Float_t maxadc)
127{
128 Float_t energy = maxadc * fMaxAdcToEnergyCal;
129
130 return energy;
131}
132
ClassImp(CbmConverterManager)
Software representation of the SPADIC v2.2+.
static float Clk(eCbmTrdAsicType ty)
DAQ clock accessor for each ASIC.
Definition CbmTrdDigi.h:109
static Double_t GetClockCycle()
Get the Clock Cycle.
UInt_t GetPeakingSamplePos()
Get the Peaking Sample Pos.
static constexpr UInt_t fgNrOfAdcSamples
Number of ADC samples.
Float_t fMaxAdcToMipCal
Calibration for MIP to 7% of MaxAdc dynamic range. 0.65 = charge from PRF broad distribution on centr...
virtual ~CbmTrdSpadic()
Destroy the Cbm Trd Spadic object.
static constexpr UInt_t GetNrOfAdcSamples()
Get the Nr Of Adc Samples (Spadic default)
Double_t GetAnalyticTimeshift(Double_t absolutetime)
Get the Analytic Timeshift value ns precision Calculate the timeshift within the spadic response base...
static const Double_t fgClockCycleLength
Clockcycle length of SPADIC v2.2.
static const Double_t fgChargeToMaxAdcCal
Calibration factor for input charges.
static std::shared_ptr< TF1 > GetResponseFunc()
Get a TF1 response function object.
std::vector< std::int16_t > GetAnalogResponsePulse(Double_t inputCharge, Double_t binTimeshift=0.0)
Get the Analog Response to a given input charge per adc time bin.
Float_t fMaxAdcToEnergyCal
Calibration value to calculate energy in keV based on the max adc value. Default = Simulation calibra...
Int_t fClippingStart
Value where a analog and or digital clipping appears By default it is set to the dynamic range of Spa...
Int_t GetNoise(Double_t sigmaNoise)
Get a Noise value based on the width of the noise distribution in sigmas.
std::vector< Double_t > fvecResponsePars
Vector for the response parameters. Order based on eResponsePars. The given values here correspond to...
static const Double_t fgShapingTime
Spadic shaping time.
void SetParameter(eResponsePars ipar, Double_t value)
static constexpr UInt_t fgNrOfPresamples
Number of presamples in the ADC signal in front of the actual signal.
static Double_t Response(Double_t *samplenr, Double_t *par)
Response of the SPADIC v2.2 to an input charge, for a given timesample.
CbmTrdSpadic()
Construct a new CbmTrdSpadic object Default and standard c'tor for a CbmTrdSpadic object.
UInt_t fBaselineLvl
Baseline level of the current Spadic Used for MaxAdcToMip calibration and baseline placement in Analo...
Float_t MaxAdcToEnergyCal(Float_t maxadc)
Return energy [keV (MC input GeV)] for a given max adc value, based on max adc to energy calibration.
static constexpr UInt_t fgShapingOrder
Spadic Shaping order.
Float_t fNoiseLvl
Noise level for signal response simulation [gaus sigmas].