CbmRoot
CbmTrdSPADIC.cxx
Go to the documentation of this file.
1 #include "CbmTrdSPADIC.h"
2 
3 #include "CbmTrdAddress.h" // for CbmTrdAddress
4 #include "CbmTrdDigi.h" // for CbmTrdDigi
5 #include "CbmTrdGeoHandler.h" // for CbmTrdGeoHandler
6 #include "CbmTrdParModDigi.h" // for CbmTrdParModDigi
7 #include "CbmTrdParSetDigi.h" // for CbmTrdParSetDigi
8 
9 #include <FairLogger.h> // for LOG, Logger
10 #include <FairRootManager.h> // for FairRootManager
11 #include <FairRunAna.h> // for FairRunAna
12 #include <FairRuntimeDb.h> // for FairRuntimeDb
13 #include <FairTask.h> // for FairTask, InitStatus, kSUCCESS
14 
15 #include <TAxis.h> // for TAxis
16 #include <TCanvas.h> // for TCanvas
17 #include <TClonesArray.h> // for TClonesArray
18 #include <TGenericClassInfo.h> // for TGenericClassInfo
19 #include <TH1.h> // for TH1D
20 
21 #include <cmath> // for pow, exp
22 #include <list> // for list, list<>::iterator, operator!=
23 #include <map> // for map, operator!=, map<>::iterator, __m...
24 #include <stdio.h> // for printf
25 #include <utility> // for pair, make_pair
26 
28  : FairTask("TrdSPADIC", 1)
29  , fSpadicResponse(nullptr)
30  , fShaperOrder(2)
31  , fShapingTime(0.09)
32  , fPeakBin(2)
33  , fBitResolution(8)
34  , fmaxdEdx(0.0001)
35  , fAdcBit(fmaxdEdx / pow(2, fBitResolution))
36  , fPulseShape(false)
37  , fSelectionMask()
38  , fDigis(nullptr)
39  , fDigiPar(nullptr)
40  , fModuleInfo(nullptr)
41  , fGeoHandler(nullptr)
42  , fMinimumChargeTH(1.0e-06) {}
44  fDigis->Delete();
45  delete fDigis;
46 }
48  fDigiPar =
49  (CbmTrdParSetDigi*) (FairRunAna::Instance()->GetRuntimeDb()->getContainer(
50  "CbmTrdParSetDigi"));
51 }
52 
53 InitStatus CbmTrdSPADIC::Init() {
54  FairRootManager* ioman = FairRootManager::Instance();
55 
56  fDigis = (TClonesArray*) ioman->GetObject("TrdDigi");
57  if (fDigis == nullptr) LOG(fatal) << "CbmTrdSPADIC::Init No TrdDigi array";
58 
60  fGeoHandler->Init();
61 
63 
64  return kSUCCESS;
65 }
66 
67 
68 // --------------------------------------------------------------------
69 void CbmTrdSPADIC::SetBitResolution(Int_t bit) { fBitResolution = pow(2, bit); }
70 // --------------------------------------------------------------------
71 void CbmTrdSPADIC::SetMaxRange(Double_t maxRange) {
72  fmaxdEdx = maxRange;
74 }
75 // --------------------------------------------------------------------
76 void CbmTrdSPADIC::SetPulseShapeSim(Bool_t pulseShape) {
77  fPulseShape = pulseShape;
78 }
79 // --------------------------------------------------------------------
80 void CbmTrdSPADIC::SetTriggerThreshold(Double_t minCharge) {
81  fMinimumChargeTH = minCharge; // To be used for test beam data processing
82 }
83 // --------------------------------------------------------------------
84 Bool_t CbmDigiSorter(std::pair<Int_t, Int_t /*CbmTrdDigi**/> a,
85  std::pair<Int_t, Int_t /*CbmTrdDigi**/> b) {
86  return (a.first < b.first);
87 }
88 // --------------------------------------------------------------------
90  fSpadicResponse = new TH1D(
91  "SpadicResponseFunction",
92  "SpadicResponseFunction",
93  fnBins,
94  0 - (1.8 / fnBins),
95  1.8 - (1.8 / fnBins)); // 1/25MHz * 45Timebins = 1.8µs200000,0,20);
96  Double_t t = 0; //[µs]
97  Double_t h = 0;
98  // Double_t T = 0.09; //[µs]
99  // Double_t t_peak = fSpadicResponse->GetBinCenter(fPeakBin);
100  for (Int_t k = 1; k <= fSpadicResponse->GetNbinsX(); k++) {
101  t = fSpadicResponse->GetBinCenter(k);
102  //t = fSpadicResponse->GetBinCenter(k) * t_peak;
103  //h = t/pow(fShapingTime,fShaperOrder) * exp(-1. * t / fShapingTime); // Tim thesis p.42
104  h = (pow(t / fShapingTime, fShaperOrder)
105  * exp(-1. * t / fShapingTime)); // with time compesation
106  fSpadicResponse->SetBinContent(k, h);
107  }
108  fSpadicResponse->Scale(1. / fSpadicResponse->Integral());
109 }
110 // --------------------------------------------------------------------
111 void CbmTrdSPADIC::SetSelectionMask(Bool_t mask[fnBins]) {
112  for (Int_t iBin = 0; iBin < fnBins; iBin++) {
113  fSelectionMask[iBin] = mask[iBin];
114  }
115 }
116 // --------------------------------------------------------------------
117 void CbmTrdSPADIC::ADC(TH1D* spadicPulse) {
118  for (Int_t k = 1; k <= spadicPulse->GetNbinsX(); k++) {
119  if (spadicPulse->GetBinContent(k) > fmaxdEdx)
120  spadicPulse->SetBinContent(k, fmaxdEdx);
121  else
122  spadicPulse->SetBinContent(
123  k, Int_t(spadicPulse->GetBinContent(k) / fAdcBit) * fAdcBit);
124  if (!fSelectionMask[k - 1]) { spadicPulse->SetBinContent(k, 0); }
125  }
126 }
127 // --------------------------------------------------------------------
129  if (digi->GetCharge() > fmaxdEdx)
130  digi->SetCharge(fmaxdEdx);
131  else
132  digi->SetCharge(Int_t(digi->GetCharge() / fAdcBit) * fAdcBit);
133 }
134 // --------------------------------------------------------------------
135 void CbmTrdSPADIC::CR_RC_Shaper(CbmTrdDigi* digi, TH1D* spadicPulse) {
136  Double_t amplitude = digi->GetCharge();
137  if (amplitude <= 0.0) return;
138  TH1D* event =
139  new TH1D("deltaPulse",
140  "deltaPulse",
141  fnBins,
142  0 - (1.8 / fnBins),
143  1.8 - (1.8 / fnBins)); // 1/25MHz * 45Timebins = 1.8µs
144  event->SetBinContent(1, 0);
145  for (Int_t k = fPeakBin; k <= event->GetNbinsX(); k++) {
146  event->SetBinContent(k, amplitude * exp(-0.65 * (k - fPeakBin)));
147  }
148  spadicPulse->Reset();
149  // Double_t t = 0; //[µs]
150  Double_t x = 0;
151  Double_t h = 0;
152  // Double_t T_0 = event->GetBinWidth(1); //[µs]
153  // Double_t t_peak = event->GetBinCenter(event->GetMaximumBin());
154  // Double_t max_ampl = event->GetBinContent(event->GetMaximumBin());
155 
156  for (Int_t k = 1; k <= event->GetNbinsX(); k++) {
157  Double_t y = 0;
158  for (Int_t i = 1; i <= event->GetNbinsX(); i++) {
159  //t = event->GetBinCenter(i);// * t_peak;
160  //h = (pow(t / fShapingTime,fShaperOrder) * exp(-1. * t / fShapingTime)); // with time compesation
161  h = fSpadicResponse->GetBinContent(i);
162  x = event->GetBinContent(k - i);
163  y += x * h;
164  }
165  spadicPulse->SetBinContent(k, y); // * T_0 / max_ampl);
166  //spadicPulse->SetBinContent(k, event->GetBinContent(k));
167  }
168  spadicPulse->Scale(
169  amplitude
170  / spadicPulse->GetBinContent(
171  spadicPulse->GetMaximumBin()) /*spadicPulse->Integral()*/);
172  ADC(spadicPulse);
173  delete event;
174 }
175 
176 
177 // ---- Exec ----------------------------------------------------------
178 void CbmTrdSPADIC::Exec(Option_t*) {
179  LOG(info) << "================CbmTrdSPADIC===============";
180  LOG(info) << "CbmTrdSPADIC::Exec : fPulseShape: " << (Bool_t) fPulseShape;
181  LOG(info) << "CbmTrdSPADIC::Exec : fBitResolution: " << fBitResolution;
182  LOG(info) << "CbmTrdSPADIC::Exec : fShaperOrder: " << fShaperOrder;
183  LOG(info) << "CbmTrdSPADIC::Exec : fShapingTime: " << fShapingTime << " µs";
184  LOG(info) << "CbmTrdSPADIC::Exec : fmaxdEdx: " << fmaxdEdx << " GeV";
185  LOG(info) << "CbmTrdSPADIC::Exec : fAdcBit: " << fAdcBit
186  << " (GeV/bit)";
187  LOG(info) << "CbmTrdSPADIC::Exec : fSelectionMask:";
188  for (Int_t iBin = 0; iBin < fnBins; iBin++) {
189  LOG(info) << " " << (Bool_t) fSelectionMask[iBin];
190  if ((1 + iBin) % 5 == 0 && iBin > 0 && (1 + iBin) < fnBins) {
191  LOG(info) << " ";
192  }
193  }
194  LOG(info) << "";
195  Bool_t debug = false;
196  std::map<Int_t, std::map<Int_t, Int_t>>
197  moduleDigiNotTriggerMap; //<ModuleAddress, <combiId, digiId> >
198  std::map<Int_t, std::list<std::pair<Int_t, Int_t>>>
199  moduleDigiTriggerMap; //<ModuleAddress, <combiId, digiId> >
200  Int_t nDigis = fDigis->GetEntries();
201 
202  TH1D* spadicPulse =
203  new TH1D("spadicPulse",
204  "spadicPulse",
205  fnBins,
206  0 - (1.8 / fnBins),
207  1.8 - (1.8 / fnBins)); // 1/25MHz * 45Timebins = 1.8µs
208  TCanvas* c = nullptr;
209  if (debug) c = new TCanvas("c", "c", 800, 600);
210  for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
211  CbmTrdDigi* digi = (CbmTrdDigi*) fDigis->At(iDigi);
212 
213 
214  Int_t digiAddress = digi->GetAddress();
215  Int_t layerId = CbmTrdAddress::GetLayerId(digiAddress);
216  Int_t moduleId = CbmTrdAddress::GetModuleId(digiAddress);
217  Int_t moduleAddress = CbmTrdAddress::GetModuleAddress(digiAddress);
219  CbmTrdAddress::GetModuleAddress(digiAddress));
220  if (!fModuleInfo) {
221  printf("digi %3i digiAddress %i layer %i and modId %i Sec%i Row:%i "
222  "Col%i not found\n",
223  iDigi,
224  digiAddress,
225  layerId,
226  moduleId,
230  continue;
231  }
232  Int_t secRow = CbmTrdAddress::GetRowId(digi->GetAddress());
233  Int_t iSector = CbmTrdAddress::GetSectorId(digi->GetAddress());
234  Int_t globalRow = 0;
235  globalRow = fModuleInfo->GetModuleRow(iSector, secRow);
236  Int_t iCol = CbmTrdAddress::GetColumnId(digi->GetAddress());
237 
238  Int_t combiId = globalRow * (fModuleInfo->GetNofColumns() + 1) + iCol;
239 
240  if (digi->GetCharge() >= fMinimumChargeTH) {
241  digi->SetTriggerType(1);
242  digi->SetStopType(0);
243  moduleDigiTriggerMap[moduleAddress].push_back(
244  std::make_pair(combiId, iDigi));
245  } else {
246  moduleDigiNotTriggerMap[moduleAddress][combiId] = iDigi;
247  }
248  }
249  CbmTrdDigi* digi = nullptr;
250  for (std::map<Int_t, std::list<std::pair<Int_t, Int_t>>>::iterator iModule =
251  moduleDigiTriggerMap.begin();
252  iModule != moduleDigiTriggerMap.end();
253  ++iModule) {
254  (*iModule).second.sort(CbmDigiSorter);
255  Int_t moduleAddress = (*iModule).first;
256  for (std::list<std::pair<Int_t, Int_t>>::iterator iDigi =
257  (*iModule).second.begin();
258  iDigi != (*iModule).second.end();
259  iDigi++) {
260  Int_t combiId = (*iDigi).first;
261  Int_t digiId = (*iDigi).second;
262  digi = (CbmTrdDigi*) fDigis->At(digiId);
263  if (fPulseShape) {
264  CR_RC_Shaper(digi, spadicPulse);
265  Float_t pulse[fnBins] = {0.0};
266  for (Int_t k = 1; k <= spadicPulse->GetNbinsX(); k++) {
267  pulse[k - 1] = spadicPulse->GetBinContent(k);
268  }
269  digi->SetPulseShape(pulse);
270  if (debug) {
271  //printf("%.6E - %.6E => %.1f%% \n", digi->GetCharge(), spadicPulse->GetBinContent(spadicPulse->GetMaximumBin()), 100.*(digi->GetCharge() - spadicPulse->GetBinContent(spadicPulse->GetMaximumBin())) / digi->GetCharge());
272  c->cd();
273  spadicPulse->GetYaxis()->SetRangeUser(0 - 0.01 * fmaxdEdx,
274  fmaxdEdx + 0.01 * fmaxdEdx);
275  spadicPulse->DrawCopy();
276  }
277  } else {
278  ADC(digi);
279  }
280  if (moduleDigiNotTriggerMap[moduleAddress].find(combiId - 1)
281  != moduleDigiNotTriggerMap[moduleAddress].end()) {
282  digi = (CbmTrdDigi*) fDigis->At(
283  moduleDigiNotTriggerMap[moduleAddress][combiId - 1]);
284  if (fPulseShape) {
285  CR_RC_Shaper(digi, spadicPulse);
286  Float_t pulse[fnBins] = {0.0};
287  for (Int_t k = 1; k <= spadicPulse->GetNbinsX(); k++) {
288  pulse[k - 1] = spadicPulse->GetBinContent(k);
289  }
290  digi->SetPulseShape(pulse);
291  if (debug) {
292  c->cd();
293  spadicPulse->SetLineColor(kRed);
294  spadicPulse->GetYaxis()->SetRangeUser(0 - 0.01 * fmaxdEdx,
295  fmaxdEdx + 0.01 * fmaxdEdx);
296  spadicPulse->DrawCopy("same");
297  }
298  } else {
299  ADC(digi);
300  }
301  digi->SetStopType(0);
302  digi->SetTriggerType(2);
303  }
304  if (moduleDigiNotTriggerMap[moduleAddress].find(combiId + 1)
305  != moduleDigiNotTriggerMap[moduleAddress].end()) {
306  digi = (CbmTrdDigi*) fDigis->At(
307  moduleDigiNotTriggerMap[moduleAddress][combiId + 1]);
308  if (fPulseShape) {
309  CR_RC_Shaper(digi, spadicPulse);
310  Float_t pulse[fnBins] = {0.0};
311  for (Int_t k = 1; k <= spadicPulse->GetNbinsX(); k++) {
312  pulse[k - 1] = spadicPulse->GetBinContent(k);
313  }
314  digi->SetPulseShape(pulse);
315  if (debug) {
316  c->cd();
317  spadicPulse->SetLineColor(kGreen);
318  spadicPulse->GetYaxis()->SetRangeUser(0 - 0.01 * fmaxdEdx,
319  fmaxdEdx + 0.01 * fmaxdEdx);
320  spadicPulse->DrawCopy("same");
321  }
322  } else {
323  ADC(digi);
324  }
325  digi->SetStopType(0);
326  digi->SetTriggerType(2);
327  }
328  if (fPulseShape)
329  if (debug) c->Update();
330  }
331  }
332 }
exp
friend F32vec4 exp(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:134
CbmTrdAddress::GetModuleAddress
static UInt_t GetModuleAddress(UInt_t address)
Return unique module ID from address.
Definition: CbmTrdAddress.h:117
CbmTrdSPADIC::fSpadicResponse
TH1D * fSpadicResponse
Definition: CbmTrdSPADIC.h:62
CbmTrdDigi::GetAddress
Int_t GetAddress() const
Address getter for module in the format defined by CbmTrdDigi (format of CbmTrdAddress can be accesse...
Definition: CbmTrdDigi.h:92
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
CbmTrdSPADIC::fShapingTime
Double_t fShapingTime
Definition: CbmTrdSPADIC.h:64
CbmTrdSPADIC::SetBitResolution
void SetBitResolution(Int_t bit)
Definition: CbmTrdSPADIC.cxx:69
CbmTrdSPADIC::fDigis
TClonesArray * fDigis
Definition: CbmTrdSPADIC.h:75
CbmTrdDigi::SetCharge
void SetCharge(Float_t c)
Charge setter for SPADIC ASIC.
Definition: CbmTrdDigi.cxx:206
CbmTrdSPADIC::CR_RC_Shaper
void CR_RC_Shaper(CbmTrdDigi *digi, TH1D *spadicPulse)
Definition: CbmTrdSPADIC.cxx:135
CbmTrdAddress::GetSectorId
static UInt_t GetSectorId(UInt_t address)
Return sector ID from address.
Definition: CbmTrdAddress.h:88
CbmTrdSPADIC::SetSelectionMask
void SetSelectionMask(Bool_t mask[45])
Definition: CbmTrdSPADIC.cxx:111
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmTrdSPADIC::fPeakBin
Int_t fPeakBin
Definition: CbmTrdSPADIC.h:65
CbmTrdSPADIC::fAdcBit
Double_t fAdcBit
Definition: CbmTrdSPADIC.h:69
CbmTrdSPADIC::SetPulseShapeSim
void SetPulseShapeSim(Bool_t pulseShape)
Definition: CbmTrdSPADIC.cxx:76
CbmTrdSPADIC::Exec
virtual void Exec(Option_t *option)
Definition: CbmTrdSPADIC.cxx:178
CbmTrdAddress::GetLayerId
static UInt_t GetLayerId(UInt_t address)
Return layer ID from address.
Definition: CbmTrdAddress.h:69
CbmTrdAddress::GetModuleId
static UInt_t GetModuleId(UInt_t address)
Return module ID from address.
Definition: CbmTrdAddress.h:78
CbmTrdSPADIC::Init
virtual InitStatus Init()
Inherited from FairTask.
Definition: CbmTrdSPADIC.cxx:53
CbmDigiSorter
Bool_t CbmDigiSorter(std::pair< Int_t, Int_t > a, std::pair< Int_t, Int_t > b)
Definition: CbmTrdSPADIC.cxx:84
CbmTrdSPADIC::~CbmTrdSPADIC
virtual ~CbmTrdSPADIC()
Destructor.
Definition: CbmTrdSPADIC.cxx:43
CbmTrdSPADIC::CbmTrdSPADIC
CbmTrdSPADIC()
Definition: CbmTrdSPADIC.cxx:27
CbmTrdSPADIC::fShaperOrder
Int_t fShaperOrder
Definition: CbmTrdSPADIC.h:63
CbmTrdSPADIC::fPulseShape
Bool_t fPulseShape
Definition: CbmTrdSPADIC.h:70
CbmTrdSPADIC
Definition: CbmTrdSPADIC.h:22
CbmTrdGeoHandler
Definition: CbmTrdGeoHandler.h:29
CbmTrdDigi.h
CbmTrdDigi::SetPulseShape
void SetPulseShape(Float_t[45])
Definition: CbmTrdDigi.h:198
h
Data class with information on a STS local track.
CbmTrdSPADIC::fDigiPar
CbmTrdParSetDigi * fDigiPar
Definition: CbmTrdSPADIC.h:77
CbmTrdGeoHandler.h
Helper class to extract information from the GeoManager.
CbmTrdParModDigi
Definition of chamber gain conversion for one TRD module.
Definition: CbmTrdParModDigi.h:14
CbmTrdGeoHandler::Init
void Init(Bool_t isSimulation=kFALSE)
Definition: CbmTrdGeoHandler.cxx:45
CbmTrdParModDigi.h
CbmTrdSPADIC::SetMaxRange
void SetMaxRange(Double_t maxRange)
Definition: CbmTrdSPADIC.cxx:71
CbmTrdParSet::GetModulePar
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
Definition: CbmTrdParSet.cxx:45
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmTrdSPADIC::fGeoHandler
CbmTrdGeoHandler * fGeoHandler
Definition: CbmTrdSPADIC.h:80
CbmTrdParSetDigi.h
CbmTrdSPADIC::fBitResolution
Int_t fBitResolution
Definition: CbmTrdSPADIC.h:66
CbmTrdSPADIC::fmaxdEdx
Double_t fmaxdEdx
Definition: CbmTrdSPADIC.h:68
CbmTrdSPADIC::fMinimumChargeTH
Double_t fMinimumChargeTH
Definition: CbmTrdSPADIC.h:82
CbmTrdDigi::SetTriggerType
void SetTriggerType(const Int_t ttype)
Set digi trigger type (SPADIC only)
Definition: CbmTrdDigi.cxx:237
CbmTrdSPADIC::fnBins
static const Int_t fnBins
Definition: CbmTrdSPADIC.h:67
CbmTrdDigi::SetStopType
void SetStopType(Int_t)
Definition: CbmTrdDigi.h:196
CbmTrdSPADIC::ADC
void ADC(TH1D *spadicPulse)
Definition: CbmTrdSPADIC.cxx:117
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdSPADIC::fSelectionMask
Bool_t fSelectionMask[fnBins]
Definition: CbmTrdSPADIC.h:71
CbmTrdSPADIC::SetTriggerThreshold
void SetTriggerThreshold(Double_t triggerthreshold)
Definition: CbmTrdSPADIC.cxx:80
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdDigi
Definition: CbmTrdDigi.h:14
CbmTrdParSetDigi
Definition: CbmTrdParSetDigi.h:15
CbmTrdSPADIC::fModuleInfo
CbmTrdParModDigi * fModuleInfo
Definition: CbmTrdSPADIC.h:78
CbmTrdSPADIC::SetParContainers
virtual void SetParContainers()
Definition: CbmTrdSPADIC.cxx:47
CbmTrdParModDigi::GetModuleRow
Int_t GetModuleRow(Int_t &sectorId, Int_t &rowId) const
Definition: CbmTrdParModDigi.cxx:373
CbmTrdSPADIC.h
CbmTrdDigi::GetCharge
Double_t GetCharge() const
Charge getter for SPADIC.
Definition: CbmTrdDigi.cxx:133
CbmTrdSPADIC::InitSpadicResponseFunction
void InitSpadicResponseFunction()
Definition: CbmTrdSPADIC.cxx:89
CbmTrdParModDigi::GetNofColumns
Int_t GetNofColumns() const
Definition: CbmTrdParModDigi.cxx:321
CbmTrdAddress::GetRowId
static UInt_t GetRowId(UInt_t address)
Return row ID from address.
Definition: CbmTrdAddress.h:98
CbmTrdAddress::GetColumnId
static UInt_t GetColumnId(UInt_t address)
Return column ID from address.
Definition: CbmTrdAddress.h:107