Skip to content

Commit 53682cc

Browse files
jolopezlsawenzel
authored andcommitted
TRD: Fixed ADC spectrum (#2776)
* improving trd digitizer * changed the signal type to float instead of int * removed map to vector conversion (buggy part) - output correct ADC spectrum * comment out ccdb failing method
1 parent f39aac2 commit 53682cc

6 files changed

Lines changed: 161 additions & 121 deletions

File tree

Detectors/TRD/base/include/TRDBase/Digit.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ constexpr int KEY_MIN = 0;
2929
constexpr int KEY_MAX = 2211727;
3030

3131
typedef std::uint16_t ADC_t; // the ADC value type
32-
typedef std::array<ADC_t, kTB> ArrayADC_t; // the array ADC
33-
typedef std::array<ADC_t, kTB + 1> ArrayADCext_t; // the array ADC + label index
34-
typedef std::vector<Digit> DigitContainer_t; // the digit container type
35-
typedef std::unordered_map<int, ArrayADCext_t> SignalContainer_t; // a map container type for signal handling during digitization
32+
typedef float Signal_t; // the signal value type
33+
typedef std::array<ADC_t, kTB> ArrayADC_t; // the array ADC - the main member of the Digit class
34+
typedef std::array<Signal_t, kTB + 1> ArraySignal_t; // the signal array + 1 element for mc label indexing - for the digitization process only
35+
typedef std::vector<Digit> DigitContainer_t; // the digit container type to send the digits to the DPL
36+
typedef std::unordered_map<int, ArraySignal_t> SignalContainer_t; // a map container type for signal handling during digitization
3637

3738
class Digit
3839
{
@@ -91,11 +92,11 @@ class Digit
9192
const int key = calculateKey(element.getDetector(),
9293
element.getRow(),
9394
element.getPad());
94-
ArrayADCext_t adcsext{};
95+
ArraySignal_t adcs{};
9596
for (int i = 0; i < kTB; ++i) {
96-
adcsext[i] = element.getADC()[i];
97+
adcs[i] = element.getADC()[i];
9798
}
98-
adcMapCont[key] = adcsext;
99+
adcMapCont[key] = adcs;
99100
}
100101
}
101102

Detectors/TRD/macros/CheckDigits.C

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,32 @@
1919

2020
#include "FairLogger.h"
2121
#include "TRDBase/Digit.h"
22+
#include "TRDBase/TRDSimParam.h"
23+
#include "TRDBase/TRDCommonParam.h"
2224
#endif
2325

26+
using namespace o2::trd;
27+
28+
constexpr int kMINENTRIES = 1000;
29+
2430
void CheckDigits(std::string digifile = "trddigits.root",
2531
std::string hitfile = "o2sim.root",
2632
std::string inputGeom = "O2geometry.root",
2733
std::string paramfile = "o2sim_par.root")
2834
{
29-
using o2::trd::Digit;
3035
TFile* fin = TFile::Open(digifile.data());
3136
TTree* digitTree = (TTree*)fin->Get("o2sim");
32-
std::vector<o2::trd::Digit>* digitCont = nullptr;
37+
std::vector<Digit>* digitCont = nullptr;
3338
digitTree->SetBranchAddress("TRDDigit", &digitCont);
3439
int nev = digitTree->GetEntries();
3540

3641
TH1F* hDet = new TH1F("hDet", ";Detector number;Counts", 504, 0, 539);
3742
TH1F* hRow = new TH1F("hRow", ";Row number;Counts", 16, 0, 15);
3843
TH1F* hPad = new TH1F("hPad", ";Pad number;Counts", 144, 0, 143);
39-
TH1* hADC = new TH1F("hADC", ";ADC value;Counts", 300, 0, 300);
44+
TH1* hADC[540];
45+
for (int d = 0; d < 540; ++d) {
46+
hADC[d] = new TH1F(Form("hADC_%d", d), ";ADC value;Counts", 1024, 0, 1023);
47+
}
4048

4149
LOG(INFO) << nev << " entries found";
4250
for (int iev = 0; iev < nev; ++iev) {
@@ -50,11 +58,13 @@ void CheckDigits(std::string digifile = "trddigits.root",
5058
hDet->Fill(det);
5159
hRow->Fill(row);
5260
hPad->Fill(pad);
53-
int tb = 0;
54-
for (const auto& adc : adcs) {
55-
if (++tb > 30)
56-
break;
57-
hADC->Fill(adc);
61+
for (int tb = 0; tb < kTimeBins; ++tb) {
62+
ADC_t adc = adcs[tb];
63+
if (adc == (ADC_t)TRDSimParam::Instance()->GetADCoutRange()) {
64+
// LOG(INFO) << "Out of range ADC " << adc;
65+
continue;
66+
}
67+
hADC[det]->Fill(adc);
5868
}
5969
}
6070
}
@@ -68,6 +78,63 @@ void CheckDigits(std::string digifile = "trddigits.root",
6878
hPad->Draw();
6979
c->cd(4);
7080
c->cd(4)->SetLogy();
71-
hADC->Draw();
81+
int first = 0;
82+
int count = 0;
83+
int max = 0;
84+
for (int d = 1; d < 540; ++d) {
85+
if (hADC[d]->GetEntries() < kMINENTRIES) {
86+
continue;
87+
}
88+
if (count > 6) {
89+
break;
90+
}
91+
hADC[d]->SetLineColor(count + 1);
92+
if (count == 0) {
93+
hADC[d]->Draw();
94+
first = d;
95+
if (max < hADC[d]->GetMaximum()) {
96+
max = hADC[d]->GetMaximum();
97+
}
98+
count++;
99+
} else {
100+
hADC[d]->Draw("SAME");
101+
if (max < hADC[d]->GetMaximum()) {
102+
max = hADC[d]->GetMaximum();
103+
}
104+
count++;
105+
}
106+
}
107+
hADC[first]->GetYaxis()->SetLimits(1.1, max + 100);
72108
c->SaveAs("testCheckDigits.pdf");
73-
}
109+
110+
TCanvas* c1 = new TCanvas("c1", "trd digits analysis", 600, 600);
111+
first = 0;
112+
count = 0;
113+
max = 0;
114+
for (int d = 1; d < 540; ++d) {
115+
if (hADC[d]->GetEntries() < kMINENTRIES) {
116+
continue;
117+
}
118+
if (count > 6) {
119+
break;
120+
}
121+
hADC[d]->SetLineColor(count + 1);
122+
if (count == 0) {
123+
hADC[d]->Draw();
124+
first = d;
125+
if (max < hADC[d]->GetMaximum()) {
126+
max = hADC[d]->GetMaximum();
127+
}
128+
count++;
129+
} else {
130+
hADC[d]->Draw("SAME");
131+
if (max < hADC[d]->GetMaximum()) {
132+
max = hADC[d]->GetMaximum();
133+
}
134+
count++;
135+
}
136+
}
137+
hADC[first]->GetYaxis()->SetLimits(1.1, max + 100);
138+
c1->SetLogy();
139+
c1->SaveAs("testCheckDigits_ADCs.pdf");
140+
}

Detectors/TRD/macros/CheckHits.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void CheckHits(const int detector = 50, // 354, 14, 242, 50
4242
TH1F* hlocC = new TH1F("hlocC", ";locC (cm);Counts", 100, -60, 60);
4343
TH1F* hlocR = new TH1F("hlocR", ";locR (cm);Counts", 100, -80, 80);
4444
TH1F* hlocT = new TH1F("hlocT", ";locT (cm);Counts", 100, -3.5, 0.5);
45-
TH1F* hnEl = new TH1F("hnEl", ";locT (cm);Counts", 100, 0, 5000);
45+
TH1F* hnEl = new TH1F("hnEl", ";Number of Electrons;Counts", 100, 0, 5000);
4646
TH1F* hnElPhoton = new TH1F("hnElPhoton", ";Number of Electrons;Counts", 100, 0, 1000);
4747

4848
TH2F* h2locClocT = new TH2F("h2locClocT", ";locC (cm);locT(cm)", 100, -60, 60, 100, -3.5, 0.5);

Detectors/TRD/simulation/include/TRDSimulation/Digitizer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ class Digitizer
7171
void getHitContainerPerDetector(const std::vector<HitType>&, std::array<std::vector<HitType>, kNdet>&);
7272
// Digitization chaing methods
7373
bool convertHits(const int, const std::vector<HitType>&, SignalContainer_t&, o2::dataformats::MCTruthContainer<MCLabel>&, int thread = 0); // True if hit-to-signal conversion is successful
74-
bool convertSignalsToDigits(const int, SignalContainer_t&, int thread = 0); // True if signal-to-digit conversion is successful
75-
bool convertSignalsToSDigits(const int, SignalContainer_t&, int thread = 0); // True if signal-to-sdigit conversion is successful
76-
bool convertSignalsToADC(const int, SignalContainer_t&, int thread = 0); // True if signal-to-ADC conversion is successful
74+
bool convertSignalsToADC(const int, SignalContainer_t&, DigitContainer_t&, int thread = 0); // True if signal-to-ADC conversion is successful
7775

7876
bool diffusion(float, float, float, float, float, float, double&, double&, double&, int thread = 0); // True if diffusion is applied successfully
7977
};

Detectors/TRD/simulation/src/Detector.cxx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ bool Detector::ProcessHits(FairVolume* v)
144144
// Update track status
145145
trkStat = 1;
146146
// Create the hits from TR photons if electron/positron is entering the drift volume
147-
const bool ele = (TMath::Abs(fMC->TrackPid()) == 11); // electron PDG code.
147+
const bool ele = (std::fabs(fMC->TrackPid()) == 11); // electron PDG code.
148148
if (mTRon && ele) {
149149
createTRhit(det);
150150
}
@@ -164,8 +164,8 @@ bool Detector::ProcessHits(FairVolume* v)
164164

165165
// Calculate the charge according to GEANT Edep
166166
// Create a new dEdx hit
167-
const float enDep = TMath::Max(fMC->Edep(), 0.0) * 1e9; // Energy in eV
168-
const int totalChargeDep = (int)(enDep / mWion); // Total charge
167+
const float enDep = std::max(fMC->Edep(), 0.0) * 1e9; // Energy in eV
168+
const int totalChargeDep = (int)(enDep / mWion); // Total charge
169169

170170
// Store those hits with enDep bigger than the ionization potential of the gas mixture for in-flight tracks
171171
// or store hits of tracks that are entering or exiting
@@ -176,7 +176,10 @@ bool Detector::ProcessHits(FairVolume* v)
176176
double pos[3] = {xp, yp, zp};
177177
double loc[3] = {-99, -99, -99};
178178
gGeoManager->MasterToLocal(pos, loc); // Go to the local coordinate system (locR, locC, locT)
179-
const float locC = loc[0], locR = loc[1], locT = loc[2];
179+
float locC = loc[0], locR = loc[1], locT = loc[2];
180+
if (drRegion) {
181+
locT = locT - 0.5 * (TRDGeometry::drThick() + TRDGeometry::amThick()); // Relative to middle of amplification region
182+
}
180183
addHit(xp, yp, zp, locC, locR, locT, tof, totalChargeDep, trackID, det, drRegion);
181184
stack->addHit(GetDetId());
182185
return true;
@@ -199,7 +202,7 @@ void Detector::createTRhit(int det)
199202

200203
float px, py, pz, etot;
201204
fMC->TrackMomentum(px, py, pz, etot);
202-
float pTot = TMath::Sqrt(px * px + py * py + pz * pz);
205+
float pTot = std::sqrt(px * px + py * py + pz * pz);
203206
std::vector<float> photonEnergyContainer; // energy in keV
204207
mTR->createPhotons(11, pTot, photonEnergyContainer); // Create TR photons
205208
if (photonEnergyContainer.size() > mMaxNumberOfTRPhotons) {
@@ -264,7 +267,8 @@ void Detector::createTRhit(int det)
264267
double pos[3] = {x, y, z};
265268
double loc[3] = {-99, -99, -99};
266269
gGeoManager->MasterToLocal(pos, loc); // Go to the local coordinate system (locR, locC, locT)
267-
const float locC = loc[0], locR = loc[1], locT = loc[2];
270+
float locC = loc[0], locR = loc[1], locT = loc[2];
271+
locT = locT - 0.5 * (TRDGeometry::drThick() + TRDGeometry::amThick()); // Relative to middle of amplification region
268272
addHit(x, y, z, locC, locR, locT, tof, totalChargeDep, trackID, det, true); // All TR hits are in drift region
269273
stack->addHit(GetDetId());
270274
}

0 commit comments

Comments
 (0)