CbmRoot
Loading...
Searching...
No Matches
CbmTrdRawToDigiLookUpCorrR.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
6
7#include "CbmTrdSpadic.h"
8
9#include <Logger.h>
10
11#include <RtypesCore.h>
12#include <TFile.h>
13#include <TH2.h>
14
15#include <algorithm>
16#include <iostream>
17#include <map>
18#include <memory>
19#include <stdexcept>
20#include <utility>
21
22//---- CbmTrdRawToDigiLookUpCorrR ----
25 , fLookUpMode(mode)
26 , fLookUpFilename(infile)
27{
28 prepareLookUpTables(infile);
29}
30
31// ---- Init ----
32bool CbmTrdRawToDigiLookUpCorrR::Init(std::string infile)
33{
34 bool initOk = true;
35
36 fLookUpFilename = infile.empty() ? fLookUpFilename : infile;
37
38 fMaxAdcLookUpMap.clear();
39 fTimeshiftLookUpMap.clear();
40
42
43 // Could be used for checks within prepareLookUpTables
44 return initOk;
45}
46
47
48// ---- GetBinTimeShift ----
49ULong64_t CbmTrdRawToDigiLookUpCorrR::GetBinTimeShift(const std::vector<std::int16_t>* samples)
50{
51 Int_t baseline = GetBaseline(samples);
52 fcorrFirstSample = samples->at(fFirstLookUpSamplePos) - baseline;
53 fcorrFirstSample = fcorrFirstSample > fSpadic->GetClippingStart() ? fSpadic->GetClippingStart() : fcorrFirstSample;
55
56 fcorrSecondSample = samples->at(fSecondLookUpSamplePos) - baseline;
57 fcorrSecondSample = fcorrSecondSample > fSpadic->GetClippingStart() ? fSpadic->GetClippingStart() : fcorrSecondSample;
59
61
62 return timeshift;
63}
64
65// --- GetCharge ----
66Float_t CbmTrdRawToDigiLookUpCorrR::GetMaxAdcValue(const std::vector<std::int16_t>* /* samples*/)
67{
68 Double_t charge = 0.0;
69
71
72
73 // Remark: Due to the fact, that we store the charge UInt_t in the Digi values below 0 are not allowed.
74 // In this case the above only appears if the baseline fluctuated above all values in the applied peaking range. This can only happen for forced neighbor triggers with a deposited charged that can not be separated from the baseline.
75 return charge;
76}
77
78// ---- prepareLookUpTables ----
80{
81 switch (fLookUpMode) {
84 if (infile.empty())
85 LOG(fatal) << "CbmTrdRawToDigiLookUpCorrR::prepareLookUpTables: Look up mode that reqiures an input file "
86 "requested with empty infile name string!";
87 loadLookUpTables(infile);
88 break;
89 }
90}
91
92// ---- loadLookUpTables ----
94{
95 auto oldFile = gFile;
96
97 TFile file(infile.data(), "READ");
98 if (file.IsOpen()) {
99 std::string hname = Form("Timeshift_Map_Fst%d_Snd%d", fFirstLookUpSamplePos, fSecondLookUpSamplePos);
100 TH2* hTimeshiftMap = file.Get<TH2>(hname.data());
101 LOG_IF(fatal, !hTimeshiftMap)
102 << "CbmTrdRawToDigiLookUpCorrR::loadLookUpTables: Look up mode that reqiures Timeshift Map "
103 "histogram requested, but the map "
104 << hname << " was not found in the given file(" << infile << ")!";
105 hname = Form("MaxAdc_Map_Fst%d_Snd%d", fFirstLookUpSamplePos, fSecondLookUpSamplePos);
106 TH2* hMaxAdcMap = file.Get<TH2>(hname.data());
107 LOG_IF(fatal, !hMaxAdcMap) << "CbmTrdRawToDigiLookUpCorrR::loadLookUpTables: Look up mode that reqiures MaxAdc Map "
108 "histogram requested, but the map "
109 << hname << " was not found in the given file(" << infile << ")!";
110
111 // TH2* hMaxAdcMap = file.Get<TH2>("MAX ADC");
112 // TH2* hAsymMap = file.Get<TH2>("ASYM MAP");
113
114 if (hMaxAdcMap && hTimeshiftMap) {
115 auto h = hMaxAdcMap;
116 for (Int_t ibinx = 1; ibinx <= h->GetNbinsX(); ibinx++) {
117 for (Int_t ibiny = 1; ibiny <= h->GetNbinsY(); ibiny++) {
118 fMaxAdcLookUpMap[h->GetXaxis()->GetBinCenter(ibinx)][h->GetYaxis()->GetBinCenter(ibiny)] =
119 h->GetBinContent(ibinx, ibiny);
120 }
121 }
122
123 h = hTimeshiftMap;
124 for (Int_t ibinx = 1; ibinx <= h->GetNbinsX(); ibinx++) {
125 for (Int_t ibiny = 1; ibiny <= h->GetNbinsY(); ibiny++) {
126 fTimeshiftLookUpMap[h->GetXaxis()->GetBinCenter(ibinx)][h->GetYaxis()->GetBinCenter(ibiny)] =
127 h->GetBinContent(ibinx, ibiny);
128 }
129 }
130 }
131 file.Close();
132 }
133 else {
134 LOG(fatal) << "CbmTrdRawToDigiLookUpCorrR::loadLookUpTables: Look up mode that reqiures an input file "
135 "requested with a wrong file path! Filepath = "
136 << infile;
137 }
138 gFile = oldFile;
139}
140
141// ---- loadLookUpTables ----
143{
144 UInt_t chargeFirstSample = 0;
145 UInt_t chargeSecondSample = 0;
146
147 for (Int_t timeshift = 0; timeshift < fSpadic->GetClockCycle(); timeshift += 1) {
148 fSpadic->SetParameter(CbmTrdSpadic::eResponsePars::kBinTimeshift, timeshift);
149 for (UInt_t maxAdc = 1; maxAdc < fSpadic->GetDynamicRange() * 2; maxAdc++) {
150 // Set the max adc related input charge for the spadic response
152 // Get the response for the sample positions
153 chargeFirstSample = fSpadic->Response(fFirstLookUpSamplePos);
154 // second sample position
155 chargeSecondSample = fSpadic->Response(fSecondLookUpSamplePos);
156 auto innerpair = std::make_pair(chargeSecondSample, timeshift);
157 auto innermap = fTimeshiftLookUpMap.find(chargeFirstSample);
158 if (innermap != fTimeshiftLookUpMap.end()) {
159 innermap->second.emplace(innerpair);
160 }
161 else {
162 std::map<UInt_t, ULong64_t> newinnermap = {};
163 newinnermap.emplace(innerpair);
164 auto outerpair = std::make_pair(chargeFirstSample, newinnermap);
165 fTimeshiftLookUpMap.emplace(outerpair);
166 }
167
168
169 // fTimeshiftLookUpMap[chargeFirstSample][chargeSecondSample] = timeshift;
170 fMaxAdcLookUpMap[timeshift][chargeSecondSample] = maxAdc;
171 }
172 }
173 ULong64_t timeshift = 0;
174 std::vector<ULong64_t> timeshiftsvec = {};
175 std::vector<UInt_t> emptyChargeVec = {};
176
177 // Fill up empty bins in the look up. Due to several effects, e.g. noise, real signals can produce other combinations of first and second sample charges than the pure analytical approach. Hence, we the look up also to deliver values for those combinations.
178 // Fill up the map, we assume here that the shift does behave steadily, i.e. empty bins after a 62 ns bin will be filled with 62 ns and vise versa empty bins after 0 ns bin will be filled with 0 ns.
179 for (auto& innermap : fTimeshiftLookUpMap) {
180 for (UInt_t secondsampleCharge = 0; secondsampleCharge < fSpadic->GetDynamicRange(); secondsampleCharge++) {
181 if (innermap.second.find(secondsampleCharge) == innermap.second.end())
182 emptyChargeVec.emplace_back(secondsampleCharge);
183 else {
184 timeshift = innermap.second.find(secondsampleCharge)->second;
185 for (auto emptycharge : emptyChargeVec) {
186 auto pair = std::make_pair(emptycharge, timeshift);
187 innermap.second.emplace(pair);
188 }
189 emptyChargeVec.clear();
190 }
191 }
192 for (auto emptycharge : emptyChargeVec) {
193 auto pair = std::make_pair(emptycharge, timeshift);
194 innermap.second.emplace(pair);
195 }
196 emptyChargeVec.clear();
197 }
198}
199
ClassImp(CbmConverterManager)
Class for extracting information from raw signals to digi level.
Software representation of the SPADIC v2.2+.
Data class with information on a STS local track.
std::shared_ptr< CbmTrdSpadic > fSpadic
Float_t GetBaseline(const std::vector< std::int16_t > *samples)
Get the Baseline value.
ULong64_t fCurrentTimeshift
Bin timeshift for the current sample set in [ns].
CbmTrdRawToDigiLookUpCorrR(std::string infile="", eLookUpModes mode=eLookUpModes::kTwoSamplesFileInput)
Construct a new CbmTrdRawToDigiLookUpCorrR.
std::string fLookUpFilename
File name where the look up histos are stored.
UInt_t fFirstLookUpSamplePos
Position of the first sample used in the look up tables Default corresponds to the value used in the ...
eLookUpModes fLookUpMode
Used look up mode.
bool Init(std::string infile="")
Initialise the method after all settings have been passed.
ULong64_t GetBinTimeShift(const std::vector< std::int16_t > *samples)
Get the Bin Time Shift value.
Float_t GetMaxAdcValue(const std::vector< std::int16_t > *samples)
Get the MaxAdc value.
void loadLookUpTables(std::string infile)
Load the look up tables from the given file.
Int_t fcorrFirstSample
Baseline corrected sample value of the first used sample.
std::map< Int_t, std::map< Int_t, Float_t > > fMaxAdcLookUpMap
Look up map for the max adc values for Keys correspond to charge[fCurrentTimeshift],...
std::map< UInt_t, std::map< UInt_t, ULong64_t > > fTimeshiftLookUpMap
Look up map for the bin time shift value Keys correspond to charge[fFirstLookUpSamplePos],...
UInt_t fSecondLookUpSamplePos
Position of the second sample used in the look up tables Default corresponds to the value used in the...
Int_t fcorrSecondSample
Baseline corrected sample value of the second used sample.
void prepareLookUpTables(std::string infile)
Prepare the look up tables for the used look up mode.
void createAnalyticLookUpTables()
Create a Analytical Look Up Tables.
@ kTwoSamplesFileInput
Look up mode based on two samples and statistical filling. Look up mode based on two samples with map...
@ kTwoSamplesDynamicAnalytic
Look up mode based on two samples and analytical on the fly filling. Look up mode based on two sample...