BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnEcalDigitizer.cxx
Go to the documentation of this file.
1/*
2 * File: BmnEcalDigitizer.cxx
3 * Author: Petr Alekseev
4 *
5 * Created on 05.08.2020, 19:31
6 */
7
8#include "BmnEcalDigitizer.h"
9
10#include "BmnEcalPoint.h"
11#include "FairLogger.h"
12#include "FairRootManager.h"
13#include "TGeoManager.h"
14
15#include <iostream>
16
18
20
22{
23
24 FairRootManager* ioman = FairRootManager::Instance();
25 fArrayOfEcalPoints = (TClonesArray*)ioman->GetObject("EcalPoint");
26 if (fArrayOfEcalPoints == nullptr) {
27 LOG(error) << "BmnEcalDigitizer::Init() branch 'EcalPoint' not found! Task will be deactivated";
28 SetActive(kFALSE);
29 return kERROR;
30 }
31
32 fArrayOfEcalDigits = new TClonesArray("BmnECALDigit");
33 ioman->Register("EcalDigit", "Ecal", fArrayOfEcalDigits, kTRUE);
34
35 if (LoadGeometry() != 0) {
36 SetActive(kFALSE);
37 return kERROR;
38 }
39
40 Info(__func__, "ECAL digitizer ready");
41 return kSUCCESS;
42}
43
45{
46 if (!IsActive())
47 return;
48
49 // Initialize
50 fArrayOfEcalDigits->Delete();
51
52 for (Int_t i = 0; i < fCellsSize; i++) {
53 fCells[i].SetAmp(0.);
54 fCells[i].SetStartTime(0.);
55 }
56
57 // Collect points
58 Int_t N = fArrayOfEcalPoints->GetEntries();
59 for (Int_t i = 0; i < N; i++) {
61
62 Int_t ch = p->GetCopyMother();
63 if (ch < fCellsSize) {
64 if (fCells[ch].GetChannel() == ch) {
65 Float_t energyLoss = p->GetEnergyLoss();
66 if (energyLoss > 0) {
67 Float_t pointTime = p->GetTime();
68 if (fMaxPointTime > 0 && pointTime > fMaxPointTime)
69 continue;
70 if (fFiberSOL > 0.) {
71 pointTime += (fFiberLength - fLayerThickness * (p->GetCopy() + 1)) / fFiberSOL;
72 }
73 fCells[ch].SetAmp(fCells[ch].GetAmp() + energyLoss);
74 fCells[ch].SetStartTime(fCells[ch].GetStartTime() + pointTime * energyLoss);
75 }
76 } else {
77 Error(__func__, "ECAL ch %d was not initialized", ch);
78 }
79 } else {
80 Error(__func__, "ECAL ch %d ignored", ch);
81 }
82 }
83
84 // Store digits
85 for (Int_t i = 0; i < fCellsSize; i++) {
86 if (fCells[i].GetChannel() != i)
87 continue;
88
89 Float_t amp = fCells[i].GetAmp() * 1000.;
90
91 if (amp == 0.)
92 continue;
93 if (amp < fThreshold)
94 continue;
95
96 Float_t time = fCells[i].GetStartTime() / fCells[i].GetAmp();
97
98 BmnECALDigit* p = new ((*fArrayOfEcalDigits)[fArrayOfEcalDigits->GetEntriesFast()]) BmnECALDigit();
99 *p = fCells[i];
100 p->SetAmp(amp);
101 p->SetPeakAmp(amp);
102 p->SetStartTime(time);
103 p->SetPeakTime(time + fPeakTimeDelay);
104 }
105}
106
108{
109
110 printf("\n"
111 "\e[1;92m");
112 printf("BMN ECAL Digitizer\n");
113 printf("ECAL geometry fileN: %s\n", fEcalGeometryFileName);
114 printf("ECAL interaction depth shift: %f\n", fDepthShift);
115 printf("ECAL cells coords (((\n");
116 Float_t x, y, z;
117 for (Int_t i = 1; i < fCellsSize; i++) {
118 if (fCells[i].GetChannel() == i) {
119 fCells[i].GetLabCoords(x, y, z);
120 printf(" % 4d [%3.0f,%3.0f] -> [%7.2f,%7.2f,%7.2f]\n", i, fCells[i].GetX(), fCells[i].GetY(), x, y, z);
121 } else {
122 // printf(" % 04d - Not initialized\n", i);
123 }
124 }
125 printf("))) ECAL cells coords\n");
126 printf("\e[0m"
127 "\n");
128}
129
131{
132 Bool_t loadFromFile = fEcalGeometryFileName != nullptr;
133 TGeoNode *ecal1 = 0, *ecal2 = 0;
134 if (gGeoManager) {
135 TGeoVolume* ecal = gGeoManager->FindVolumeFast("ecal");
136 if (ecal) {
137 if (ecal->GetNdaughters() > 0)
138 ecal1 = ecal->GetNode(0);
139 if (ecal->GetNdaughters() > 1)
140 ecal2 = ecal->GetNode(1);
141 loadFromFile = kFALSE;
142 } else {
143 Info(__func__, "Ecal geometry not found by TGeoManager\n");
144 }
145 }
146
147 if (loadFromFile) {
148 Info(__func__, "Loading coordinates of ECAL cells from %s\n", fEcalGeometryFileName);
150
151 if (!top) {
152 LOG(error) << "<BmnEcalDigitizer::LoadGeometry>: Volume TOP not found in "
153 << (fEcalGeometryFileName == nullptr ? "(null)" : fEcalGeometryFileName);
154 // Fatal(__func__, "Volume TOP not found in %s\n", fEcalGeometryFileName);
155 return -1;
156 }
157
158 TGeoNode* ecal = top->GetNode(0);
159
160 if (!ecal /*|| ecal->GetNdaughters() < 2*/) {
161 LOG(error) << "<BmnEcalDigitizer::LoadGeometry>: Unexpected geometry structure "
162 << (fEcalGeometryFileName == nullptr ? "(null)" : fEcalGeometryFileName);
163 // Fatal(__func__, "Unexpected geometry structure %s\n",fEcalGeometryFileName);
164 return -1;
165 }
166 ecal1 = ecal->GetDaughter(0);
167 ecal2 = ecal->GetDaughter(1);
168 }
169
170 if (ecal1 == 0 && ecal2 == 0) {
171 Info(__func__, "BmnEcalDigitizer was set in inactive state, because ECAL geometry was not found");
172 return -1;
173 }
174
175 for (Int_t i = 0; i < fCellsSize; i++) {
176 fCells[i].SetChannel(0);
177 }
178
179 Double_t coords[] = {0., 0., 0.};
180 Double_t ecalCoords[3];
181 Double_t labCoords[3];
182
183 coords[2] = fDepthShift;
184
185 if (ecal1) {
186 Int_t n = ecal1->GetNdaughters();
187 if (n > 504) {
188 LOG(error) << "<BmnEcalDigitizer::LoadGeometry>: Expected ecal node 1 with 504 daughters or less in "
189 << (fEcalGeometryFileName == nullptr ? "(null)" : fEcalGeometryFileName);
190 return -1;
191 }
192 for (Int_t i = 0; i < n; i++) {
193 Int_t ch = ecal1->GetDaughter(i)->GetNumber();
194 if (ch < 1 || ch > 504) {
195 LOG(error) << "<BmnEcalDigitizer::LoadGeometry>: Unexpected chan " << ch << " at ecal node 1 in "
196 << (fEcalGeometryFileName == nullptr ? "(null)" : fEcalGeometryFileName);
197 return -1;
198 }
199 ecal1->GetDaughter(i)->LocalToMaster(coords, ecalCoords);
200 ecal1->LocalToMaster(ecalCoords, labCoords);
201 fCells[ch].SetChannel(ch);
202 fCells[ch].SetX(ecalCoords[0]);
203 fCells[ch].SetY(ecalCoords[1]);
204 fCells[ch].SetLabCoords(labCoords[0], labCoords[1], labCoords[2]);
205 }
206 }
207
208 if (ecal2) {
209 Int_t n = ecal2->GetNdaughters();
210 if (n > 504) {
211 LOG(error) << "<BmnEcalDigitizer::LoadGeometry>: Expected ecal node 2 with 504 daughters or less in "
212 << (fEcalGeometryFileName == nullptr ? "(null)" : fEcalGeometryFileName);
213 return -1;
214 }
215 for (Int_t i = 0; i < n; i++) {
216 Int_t ch = ecal2->GetDaughter(i)->GetNumber();
217 if (ch < 505 || ch > 1008) {
218 LOG(error) << "<BmnEcalDigitizer::LoadGeometry>: Unexpected chan=" << ch << " at ecal node 2 in "
219 << (fEcalGeometryFileName == nullptr ? "(null)" : fEcalGeometryFileName);
220 return -1;
221 }
222 ecal2->GetDaughter(i)->LocalToMaster(coords, ecalCoords);
223 ecal2->LocalToMaster(ecalCoords, labCoords);
224 fCells[ch].SetChannel(ch);
225 fCells[ch].SetX(ecalCoords[0]);
226 fCells[ch].SetY(ecalCoords[1]);
227 fCells[ch].SetLabCoords(labCoords[0], labCoords[1], labCoords[2]);
228 }
229 }
230
231 return 0;
232}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Info(const char *location, const char *msgfmt,...)
void Error(const char *location, const char *msgfmt,...)
R__EXTERN TGeoManager * gGeoManager
void SetAmp(Float_t amp)
void SetPeakAmp(Float_t amp)
void SetPeakTime(Float_t ns)
void SetStartTime(Float_t ns)
const char * fEcalGeometryFileName
virtual void Exec(Option_t *opt)
TClonesArray * fArrayOfEcalPoints
virtual InitStatus Init()
virtual void Print(Option_t *option="") const
TClonesArray * fArrayOfEcalDigits
const Int_t fCellsSize
BmnECALDigit fCells[1024]
Short_t GetCopy() const
Accessors.
Short_t GetCopyMother() const
Int_t GetNdaughters() const
TGeoNode * GetDaughter(Int_t ind) const
virtual void LocalToMaster(const Double_t *local, Double_t *master) const
Int_t GetNumber() const
Int_t GetNdaughters() const
TGeoNode * GetNode(const char *name) const
static TGeoVolume * Import(const char *filename, const char *name="", Option_t *option="")
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362