Skip to content

Commit 387a6af

Browse files
committed
feat(actaf):Update online histograms and added more conditions to the cal and hit data levels
Changed the filling condition for hit histograms Changed the filling condition for hit histograms Changed the filling condition for hit histograms Changed the filling condition for hit histograms Changed the filling condition for hit histograms
1 parent 332ed26 commit 387a6af

5 files changed

Lines changed: 77 additions & 82 deletions

File tree

actaf/calibration/R3BActafCal2Hit.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void R3BActafCal2Hit::Exec(Option_t*)
110110
auto ring = fActafGeo->GetRingId(pad);
111111
auto zpos = calData->GetZpos();
112112
auto energy = calData->GetEnergy();
113-
TVector3 track = fActafGeo->GetPosition(pad, false);
113+
TVector3 track = fActafGeo->GetPosition(pad);
114114
AddHitData(pad, (pad < 65 ? 1 : 2), ring, track.X(), track.Y(), zpos, energy, track);
115115
}
116116
return;

actaf/calibration/R3BActafMapped2Cal.cxx

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
// ROOT headers
2020
#include <TClonesArray.h>
2121
#include <TMath.h>
22+
#include <array>
23+
#include <iostream>
24+
#include <numeric>
25+
#include <utility>
26+
#include <vector>
2227

2328
// FAIR headers
2429
#include <FairLogger.h>
@@ -29,9 +34,23 @@
2934
#include "R3BActafCalData.h"
3035
#include "R3BActafCalPar.h"
3136
#include "R3BActafMapped2Cal.h"
32-
#include "R3BActafMappedData.h"
3337
#include "R3BLogger.h"
3438

39+
template <class Cont>
40+
double IntegratePulse(const Cont& signal, int maxIdx, double baseline = 0.)
41+
{
42+
int left = maxIdx, right = maxIdx;
43+
const int size = static_cast<int>(signal.size());
44+
45+
while (left > 0 && signal[left] > baseline)
46+
--left;
47+
48+
while (right < size - 1 && signal[right] > baseline)
49+
++right;
50+
51+
return std::accumulate(signal.begin() + left, signal.begin() + right, 0.0) - (right - left) * baseline;
52+
}
53+
3554
// R3BActafMapped2Cal::Default Constructor --------------------------
3655
R3BActafMapped2Cal::R3BActafMapped2Cal()
3756
: R3BActafMapped2Cal("R3BActafMapped2Cal", 1)
@@ -135,7 +154,7 @@ InitStatus R3BActafMapped2Cal::ReInit()
135154
return kSUCCESS;
136155
}
137156

138-
inline void ApplySGFilter(std::array<double, ACTAF_BINS>& signal, std::vector<double> coeffs)
157+
void R3BActafMapped2Cal::ApplySGFilter(std::array<double, ACTAF_BINS>& signal, std::vector<double> coeffs)
139158
{
140159
auto n = signal.size(), m = coeffs.size();
141160
int half = m / 2;
@@ -183,27 +202,28 @@ void R3BActafMapped2Cal::Exec(Option_t*)
183202
synTagTime = mappedData->GetLeadingEdgeTime() * fConversionCh2ns; // in ns
184203
}
185204

186-
// Apply the SG filter to the trace
187205
for (size_t index = 0; index < nHits; ++index)
188206
{
189207
auto mappedData = dynamic_cast<R3BActafMappedData const*>(fActafMappedData->At(index));
190208
auto pad = mappedData->GetPad();
191-
if (pad >= 129)
192-
continue; // syn-time
209+
if (pad >= 129 || pad == fPulserCh) // syn-time or pulser channel
210+
continue;
193211

194-
std::array<double, ACTAF_BINS> trace = mappedData->GetTrace();
195-
ApplySGFilter(trace, fSgCoeffs);
212+
std::array<double, ACTAF_BINS> waveform = mappedData->GetTrace();
213+
// Apply the SG filter to the waveform
214+
if (fApplySGFilter)
215+
ApplySGFilter(waveform, fSgCoeffs);
196216

197-
auto energy = mappedData->GetE() * fEGain[pad - 1];
217+
auto integral = IntegratePulse(waveform, mappedData->GetMaxpos());
218+
auto energy = integral * fEGain[pad - 1];
198219
auto energyMaxAmpl = mappedData->GetMaxampl() * fEGain[pad - 1];
220+
199221
auto drift = mappedData->GetLeadingEdgeTime() * fConversionCh2ns; // in ns
200222
auto zpos = drift * fVelocity; // in cm
201223
auto syntime = drift - synTagTime; // in ns
202224

203-
if (energy >= fEThr[pad - 1])
204-
AddCalData(pad, energy, energyMaxAmpl, drift, zpos, syntime, trace);
205-
else if (energy < fEThr[pad - 1] && fDisplayTrace)
206-
AddCalData(pad, 0, 0, 0, 0, 0, trace);
225+
if (energyMaxAmpl >= fEThr[pad - 1] && energy < fMaxE)
226+
AddCalData(pad, energy, energyMaxAmpl, drift, zpos, syntime, waveform);
207227
}
208228
return;
209229
}

actaf/calibration/R3BActafMapped2Cal.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <FairTask.h>
2222

2323
#include "R3BActafCalData.h"
24+
#include "R3BActafMappedData.h"
2425

2526
#include <Rtypes.h>
26-
2727
#include <vector>
2828

2929
class TClonesArray;
@@ -64,15 +64,24 @@ class R3BActafMapped2Cal : public FairTask
6464
// Method to define the velocity
6565
inline void SetVelocity(double opt) { fVelocity = opt; }
6666

67-
// Method to force all traces to be stored
68-
void SetDisplayTraces(bool use = true) { fDisplayTrace = use; }
67+
// Method to apply SG filter
68+
void SetSGFilter(bool use = true) { fApplySGFilter = use; }
69+
70+
// Method to set pulser channel/pad
71+
void SetPulserChannel(int chn) { fPulserCh = chn; }
72+
73+
// Method to set max integral
74+
void SetMaxEIntegral(int max) { fMaxE = max; }
6975

7076
private:
7177
void SetParameter();
78+
void ApplySGFilter(std::array<double, ACTAF_BINS>& signal, std::vector<double> coeffs);
7279

7380
static constexpr int fPad = 128;
74-
75-
bool fOnline = false; // Don't store data for online
81+
bool fOnline = false; // Don't store data for online
82+
bool fApplySGFilter = false;
83+
int fPulserCh = 62;
84+
int fMaxE = 300000;
7685
double fConversionCh2ns = 51.44; // in ns/bin
7786
double fVelocity = 0.02888; // in cm/ns
7887

@@ -97,5 +106,5 @@ class R3BActafMapped2Cal : public FairTask
97106

98107
public:
99108
// Class definition
100-
ClassDefOverride(R3BActafMapped2Cal, 1);
109+
ClassDefOverride(R3BActafMapped2Cal, 2);
101110
};

actaf/online/R3BActafOnlineSpectra.cxx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ InitStatus R3BActafOnlineSpectra::Init()
281281
cMap_perRing[sideNb][ringNb - 1][0]->cd(++countsPerRing[sideNb][ringNb - 1]);
282282
fh2_RawTraces[index]->Draw("colz");
283283

284-
std::string nameHistC = "fh2_Pad_" + std::to_string(index) + "corrected_trace";
284+
std::string nameHistC = "fh2_Pad_" + std::to_string(index + 1) + "corrected_trace";
285285

286286
fh2_CorrectedTraces[index] = R3B::root_owned<TH2F>(
287287
nameHistC.c_str(), titleHist.c_str(), nBinsSample, 1, nBinsSample, nBinsTrace, nTraceMin, nTraceMax);
@@ -299,7 +299,7 @@ InitStatus R3BActafOnlineSpectra::Init()
299299
fh2_CorrectedTraces[index]->Draw("colz");
300300

301301
// Filtered traces (CAL LEVEL!)
302-
std::string nameFiltHist = "fh2_Pad_" + std::to_string(index) + "filtered_trace";
302+
std::string nameFiltHist = "fh2_Pad_" + std::to_string(index + 1) + "filtered_trace";
303303
fh2_FilteredTraces[index] = R3B::root_owned<TH2F>(
304304
nameFiltHist.c_str(), titleHist.c_str(), nBinsSample, 1, nBinsSample, nBinsTrace, nTraceMin, nTraceMax);
305305
fh2_FilteredTraces[index]->GetXaxis()->SetTitle("Time [Chn]");
@@ -310,7 +310,7 @@ InitStatus R3BActafOnlineSpectra::Init()
310310
cCalFilt->cd(chn);
311311
fh2_FilteredTraces[index]->Draw("colz");
312312

313-
std::string nameHistE = "fh1_Pad_" + std::to_string(index) + "_Eraw";
313+
std::string nameHistE = "fh1_Pad_" + std::to_string(index + 1) + "_Eraw";
314314
std::string titleHistE = "ERaw: Pad " + std::to_string(index + 1) + " (Mod " + std::to_string(FADCnum) +
315315
" Chn " + std::to_string(FADCchn) + ")";
316316
fh1_RawE[index] = R3B::root_owned<TH1F>(nameHistE.c_str(), titleHistE.c_str(), 100, 0, 300000);
@@ -327,7 +327,7 @@ InitStatus R3BActafOnlineSpectra::Init()
327327
cMap_perRing[sideNb][ringNb - 1][2]->cd(countsPerRing[sideNb][ringNb - 1]);
328328
fh1_RawE[index]->Draw("colz");
329329

330-
std::string nameHistB = "fh1_Pad_" + std::to_string(index) + "_Baseline";
330+
std::string nameHistB = "fh1_Pad_" + std::to_string(index + 1) + "_Baseline";
331331
std::string titleHistB = "Baseline: Pad " + std::to_string(index + 1) + " (Mod " + std::to_string(FADCnum) +
332332
" Chn " + std::to_string(FADCchn) + ")";
333333
fh1_Baseline[index] = R3B::root_owned<TH1F>(nameHistB.c_str(), titleHistB.c_str(), 300, 7000, 10000);
@@ -553,7 +553,7 @@ InitStatus R3BActafOnlineSpectra::Init()
553553
{
554554

555555
TString tit;
556-
i == 0 ? tit = "Counts per ring (upstream side)" : tit = "Counts per ring (downstream side)";
556+
i == 0 ? tit = "Counts per ring (upstream)" : tit = "Counts per ring (downstream)";
557557

558558
cCounts->cd(i + 2);
559559
fh1_RingCounts[i] = R3B::root_owned<TH1F>(Form("fh1_RingCounts_side%d", i + 1), tit, 8, 0.5, 8.5);
@@ -575,11 +575,11 @@ InitStatus R3BActafOnlineSpectra::Init()
575575
for (auto i = 0; i < fh2_XYPos.size(); i++)
576576
{
577577
TString tit;
578-
i == 0 ? tit = "XY (upstream)" : tit = "XY (downstream)";
578+
i == 0 ? tit = "Pad plane (upstream)" : tit = "Pad plane (downstream)";
579579

580580
cXY->cd(i + 1);
581581

582-
fh2_XYPos[i] = new TH2Poly();
582+
fh2_XYPos[i] = R3B::root_owned<TH2Poly>();
583583

584584
for (int iPad = 1 + 64 * i; iPad <= 65 + 64 * i; iPad++)
585585
{
@@ -662,15 +662,15 @@ InitStatus R3BActafOnlineSpectra::Init()
662662
hitfol->Add(cXY);
663663

664664
// Canvas with XY positions (one per ring) storing the tracks of three events (updated each 3000 events)
665-
auto* cXY_nevents = new TCanvas("X_Y_events", Form("XY positions (%d events)", nbEventsFilled), 10, 10, 500, 500);
665+
auto* cXY_nevents = new TCanvas("X_Y_events", "XY positions per event", 10, 10, 500, 500);
666666
cXY_nevents->Divide(2, 1);
667667

668668
for (int i = 0; i < fh2_XYPos_Evts.size(); i++)
669669
{
670670
cXY_nevents->cd(i + 1);
671671
fh2_XYPos_Evts[i] =
672672
static_cast<TH2Poly*>(fh2_XYPos[i]->Clone((fh2_XYPos[i]->GetTitle() + TString("_events")).Data()));
673-
fh2_XYPos_Evts[i]->SetTitle(fh2_XYPos[i]->GetTitle() + TString(Form(" %d Events", nbEventsFilled)));
673+
fh2_XYPos_Evts[i]->SetTitle(fh2_XYPos[i]->GetTitle() + TString(" per event"));
674674
fh2_XYPos_Evts[i]->SetLineColor(kBlack);
675675
fh2_XYPos_Evts[i]->SetLineWidth(1);
676676
fh2_XYPos_Evts[i]->Draw("colz ]");
@@ -963,7 +963,8 @@ void R3BActafOnlineSpectra::Exec(Option_t* /*option*/)
963963
if (value == 0)
964964
continue;
965965

966-
fh2_timetag_signal->Fill(index++, value + hit->GetBaseline());
966+
if (hit->GetBaseline() > 0)
967+
fh2_timetag_signal->Fill(index++, value + hit->GetBaseline());
967968
}
968969
}
969970
}
@@ -1011,8 +1012,6 @@ void R3BActafOnlineSpectra::Exec(Option_t* /*option*/)
10111012
if (value == 0)
10121013
continue;
10131014

1014-
// if (value < -hit->GetBaseline())
1015-
// continue;
10161015
if (hit->GetBaseline() > 0)
10171016
{
10181017
fh2_CorrectedTraces[pad]->Fill(index, value /*- hit->GetBaseline()*/);
@@ -1077,39 +1076,40 @@ void R3BActafOnlineSpectra::Exec(Option_t* /*option*/)
10771076
}
10781077

10791078
// Fill hit data
1080-
// In principle each events has 128 hits
1079+
if (fNEvents % updateRate == 0)
1080+
{
1081+
for (auto& hist : fh2_XYPos_Evts)
1082+
hist->Reset("");
1083+
}
1084+
10811085
if (fHitItems && fHitItems->GetEntriesFast() > 0)
10821086
{
10831087
auto nHits = fHitItems->GetEntriesFast();
1084-
for (int ihit = 0; ihit < nHits; ihit++)
1088+
for (size_t ihit = 0; ihit < nHits; ihit++)
10851089
{
10861090
auto* hit = dynamic_cast<R3BActafHitData*>(fHitItems->At(ihit));
10871091
if (!hit)
10881092
continue;
10891093

1090-
int pad = hit->GetPad();
1094+
auto pad = hit->GetPad();
10911095

10921096
if (pad > fPads)
10931097
continue;
10941098

1095-
int side = hit->GetSide() - 1;
1096-
int ring = hit->GetRing();
1097-
double x = hit->GetXpos();
1098-
double y = hit->GetYpos();
1099-
// double z = hit->GetZpos();
1099+
auto side = hit->GetSide() - 1;
1100+
auto ring = hit->GetRing();
1101+
auto x = hit->GetXpos();
1102+
auto y = hit->GetYpos();
1103+
auto energy = hit->GetEnergy();
11001104

1101-
TVector3 track = hit->GetTrack();
1102-
double phi = track.Phi() * TMath::RadToDeg();
1105+
auto track = hit->GetTrack();
1106+
auto phi = track.Phi() * TMath::RadToDeg();
11031107

11041108
fh1_RingCounts[side]->Fill(ring);
11051109
fh2_XYPos[side]->Fill(x, y);
11061110

1107-
if (fNEvents % updateRate == 0)
1108-
fh2_XYPos_Evts[side]->Reset("");
1109-
1110-
for (int iEventFilled = 1; iEventFilled <= nbEventsFilled; iEventFilled++)
1111-
if ((fNEvents - iEventFilled) % updateRate == 0)
1112-
fh2_XYPos_Evts[side]->Fill(x, y);
1111+
auto bin = fh2_XYPos_Evts[side]->FindBin(x, y);
1112+
fh2_XYPos_Evts[side]->SetBinContent(bin, energy);
11131113

11141114
fh1_PhiCounts[side]->Fill(phi);
11151115
fh1_CountsPerSide->Fill(side + 1);

actaf/online/R3BActafOnlineSpectra.h

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,6 @@ namespace r3b::util
4040
if (ptr)
4141
ptr->Clear();
4242
}
43-
44-
/*
45-
inline TH1F* MakeH1F(TString name,
46-
TString title,
47-
int nbx,
48-
double xlow,
49-
double xup,
50-
TString xtitle,
51-
TString ytitle,
52-
TCanvas* where,
53-
TString drawopt = "")
54-
{
55-
auto* h = R3B::root_owned<TH1F>(name, title, nbx, xlow, xup);
56-
57-
h->SetTitle(title);
58-
h->CenterTitle(true);
59-
60-
h->GetXaxis()->SetTitle(xtitle);
61-
h->GetXaxis()->CenterTitle(true);
62-
63-
h->GetYaxis()->SetTitle(ytitle);
64-
h->GetYaxis()->SetTitleOffset(1.1);
65-
h->GetYaxis()->CenterTitle(true);
66-
67-
if (where)
68-
{
69-
where->cd();
70-
h->Draw(drawopt);
71-
}
72-
}
73-
*/
7443
} // namespace r3b::util
7544

7645
class R3BActafOnlineSpectra : public FairTask
@@ -174,8 +143,6 @@ class R3BActafOnlineSpectra : public FairTask
174143

175144
void SetUpdateRate(int num) { updateRate = num; }
176145

177-
void SetNbEventsFilled(int num) { nbEventsFilled = num; }
178-
179146
private:
180147
void SetParameter();
181148

@@ -261,8 +228,7 @@ class R3BActafOnlineSpectra : public FairTask
261228
int max_second_for_rate = 600;
262229
int max_rate = 1000;
263230

264-
int nbEventsFilled = 3;
265-
int updateRate = 500;
231+
int updateRate = 1;
266232

267233
std::vector<uint64_t> pre_timestamp{ 0, 0, 0, 0, 0, 0, 0, 0, 0 };
268234

0 commit comments

Comments
 (0)