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