R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandOnlineReconstruction.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
15#include "FairRunOnline.h"
16#include "R3BEventHeader.h"
17#include "TCanvas.h"
18#include "TF1.h"
19#include "TFile.h"
20#include "TH1D.h"
21#include "TH2D.h"
22#include "TH3D.h"
23#include "THttpServer.h"
24#include "TStyle.h"
25#include <FairRootManager.h>
26#include <numeric>
27
28/* This function is required to suppress boxes for empty bins - make them transparent.*/
29static Double_t gEmptyBinSupressor(const Double_t* x, const Double_t*)
30{
31 if (x)
32 {
33 return *x > 0 ? 1. : 0.;
34 }
35 return 0.;
36}
37
39 : FairTask("R3BNeulandOnlineReconstruction", 0)
40 , fEventHeader(nullptr)
41 , fNeulandHits("NeulandHits")
42 , fNeulandClusters("NeulandClusters")
43{
44}
45
47{
48 auto run = FairRunOnline::Instance();
49 if (run)
50 {
51 run->GetHttpServer()->Register("/Tasks", this);
52 run->GetHttpServer()->RegisterCommand("Reset_Neuland_Reco", Form("/Tasks/%s/->ResetHistos()", GetName()));
53 }
54
55 auto ioman = FairRootManager::Instance();
56 if (ioman == nullptr)
57 {
58 throw std::runtime_error("R3BNeulandOnlineReconstruction: No FairRootManager");
59 }
60
61 fEventHeader = dynamic_cast<R3BEventHeader*>(ioman->GetObject("EventHeader."));
62 if (fEventHeader == nullptr)
63 {
64 throw std::runtime_error("R3BNeulandOnlineReconstruction: No R3BEventHeader");
65 }
66
67 fNeulandHits.Init();
68 fNeulandClusters.Init();
69
70 gStyle->SetCanvasPreferGL(kTRUE);
71 gStyle->SetPalette(kViridis);
72 gStyle->SetOptStat(0);
73
74 auto canvasHits = new TCanvas("canvasHits", "Neuland Hits", 10, 10, 850, 850);
75 canvasHits->Divide(3, 2);
76 canvasHits->cd(1);
77 hHitX = new TH1D("hHitX", "Hit X", 300, -150, 150);
78 hHitX->Draw();
79 canvasHits->cd(2);
80 hHitY = new TH1D("hHitY", "Hit Y", 300, -150, 150);
81 hHitY->Draw();
82 canvasHits->cd(3);
83 hHitZ = new TH1D("hHitZ", "Hit Z", 16, fDistanceToTarget, fDistanceToTarget + 16 * 5);
84 hHitZ->Draw();
85 canvasHits->cd(4);
86 hHitT = new TH1D("hHitT", "Hit T", 100000, -10000, 10000);
87 hHitTadj = new TH1D("hHitTadj", "Hit Tadj", 100000, -10000, 10000);
88 hHitT->Draw();
89 hHitTadj->Draw("same");
90 canvasHits->cd(5);
91 gPad->SetLogy();
92 hHitE = new TH1D("hHitE", "Hit E", 1000, 0, 100);
93 hHitE->Draw();
94 canvasHits->cd(6);
95 gPad->SetLogy();
96 hHitMult = new TH1D("hHitMult", "Hit Multiplicity", 100, 0, 100);
97 hHitMult->Draw();
98 canvasHits->cd(0);
99 if (run)
100 {
101 run->AddObject(canvasHits);
102 }
103
104 auto canvas3D = new TCanvas("canvas3D", "Neuland 3D Hits & Clusters", 10, 10, 850, 850);
105 canvas3D->Divide(2, 2);
106 canvas3D->cd(1);
107 hHits3D = new TH3D("hHits3D", "Hits3D, nHits > 10", 16, 0, 16 * 5, 50, -125, 125, 50, -125, 125);
108 hHits3D->GetXaxis()->SetTitle("Z");
109 hHits3D->GetYaxis()->SetTitle("X");
110 hHits3D->GetZaxis()->SetTitle("Y");
111 auto lofH = hHits3D->GetListOfFunctions();
112 lofH->Add(new TF1("TransferFunction", gEmptyBinSupressor, 0., 1000., 0));
113 hHits3D->Draw("glcolz");
114 canvas3D->cd(2);
115 gPad->SetLogy();
116 hClusterSize = new TH1D("hClusterSize", "Cluster Size", 100, 0, 100);
117 hClusterSize->Draw();
118 canvas3D->cd(3);
119 hClusters3D = new TH3D("hClusters3D", "Hits 3D, nHits > 10", 16, 0, 16 * 5, 50, -125, 125, 50, -125, 125);
120 hClusters3D->GetXaxis()->SetTitle("Z");
121 hClusters3D->GetYaxis()->SetTitle("X");
122 hClusters3D->GetZaxis()->SetTitle("Y");
123 auto lofC = hClusters3D->GetListOfFunctions();
124 lofC->Add(new TF1("TransferFunction", gEmptyBinSupressor, 0., 1000., 0));
125 hClusters3D->Draw("glcolz");
126 canvas3D->cd(4);
127 gPad->SetLogy();
128 hClusterMult = new TH1D("hClusterMult", "Cluster Multiplicity", 50, 0, 50);
129 hClusterMult->Draw();
130 canvas3D->cd(0);
131 if (run)
132 {
133 run->AddObject(canvas3D);
134 }
135
136 auto canvasCalibr = new TCanvas("canvasCalibr", "canvasCalibr", 10, 10, 850, 850);
137 canvasCalibr->Divide(2, 2);
138 canvasCalibr->cd(1);
139 hEtotVSNClusters = new TH2D("hEtotVSNClusters", "Calibr", 300, 0, 3000, 50, 0, 50);
140 hEtotVSNClusters->GetXaxis()->SetTitle("Total Energy [MeV]");
141 hEtotVSNClusters->GetYaxis()->SetTitle("Number of Clusters");
142 hEtotVSNClusters->Draw("colz");
143 canvasCalibr->cd(2);
144 hEtot = new TH1D("hEtot", "Etot", 300, 0, 3000);
145 hEtot->Draw();
146 canvasCalibr->cd(0);
147 if (run)
148 {
149 run->AddObject(canvasCalibr);
150 }
151
152 return kSUCCESS;
153}
154
156{
157 if (std::isnan(fEventHeader->GetTStart()))
158 {
159 return;
160 }
161
162 const auto hits = fNeulandHits.Retrieve();
163 const auto nHits = hits.size();
164 if (hits.empty())
165 {
166 return;
167 }
168 hHitMult->Fill(nHits);
169
170 for (const auto& hit : hits)
171 {
172 hHitX->Fill(hit->GetPosition().X());
173 hHitY->Fill(hit->GetPosition().Y());
174 hHitZ->Fill(hit->GetPosition().Z());
175 hHitT->Fill(hit->GetT());
176 hHitTadj->Fill(fDistanceToTarget / hit->GetPosition().Mag() * hit->GetT());
177 hHitE->Fill(hit->GetE());
178 }
179
180 const auto clusters = fNeulandClusters.Retrieve();
181 const auto nClusters = clusters.size();
182 hClusterMult->Fill(nClusters);
183 for (const auto& cluster : clusters)
184 {
185 hClusterSize->Fill(cluster->GetSize());
186 }
187
188 if (hits.size() > 10)
189 {
190 hHits3D->Reset("ICES");
191 for (const auto& hit : hits)
192 {
193 hHits3D->Fill(hit->GetPosition().Z() - fDistanceToTarget,
194 hit->GetPosition().X(),
195 hit->GetPosition().Y(),
196 hit->GetE());
197 }
198 hClusters3D->Reset("ICES");
199 for (const auto& cluster : clusters)
200 {
201 hClusters3D->Fill(cluster->GetPosition().Z() - fDistanceToTarget,
202 cluster->GetPosition().X(),
203 cluster->GetPosition().Y(),
204 cluster->GetE());
205 }
206 }
207
208 const double etot = std::accumulate(clusters.begin(),
209 clusters.end(),
210 0.,
211 [](const double sum, const R3BNeulandCluster* c) { return sum + c->GetE(); });
212 if (etot > 10)
213 {
214 hEtotVSNClusters->Fill(etot, nClusters);
215 }
216}
217
219{
220 TDirectory* tmp = gDirectory;
221 FairRootManager::Instance()->GetOutFile()->cd();
222
223 gDirectory->mkdir("R3BNeulandOnlineReconstruction");
224 gDirectory->cd("R3BNeulandOnlineReconstruction");
225
226 hHitX->Write();
227 hHitY->Write();
228 hHitZ->Write();
229 hHitT->Write();
230 hHitTadj->Write();
231 hHitE->Write();
232
233 hHitMult->Write();
234 hClusterMult->Write();
235 hClusterSize->Write();
236 hEtot->Write();
237 hEtotVSNClusters->Write();
238
239 gDirectory = tmp;
240}
241
243{
244 hHitX->Reset();
245 hHitY->Reset();
246 hHitZ->Reset();
247 hHitT->Reset();
248 hHitTadj->Reset();
249 hHitE->Reset();
250
251 hHitMult->Reset();
252 hClusterMult->Reset();
253 hClusterSize->Reset();
254 hEtot->Reset();
255 hEtotVSNClusters->Reset();
256}
257
ClassImp(R3B::Neuland::Cal2HitPar)
static const Double_t c
static Double_t gEmptyBinSupressor(const Double_t *x, const Double_t *)