11#include "FairLogger.h"
12#include "FairRootManager.h"
14#include "TGeoManager.h"
26 FairRootManager* ioman = FairRootManager::Instance();
27 fArrayOfEcalPoints = (TClonesArray*) ioman->GetObject(
"EcalPoint");
28 if (fArrayOfEcalPoints ==
nullptr)
30 LOG(error)<<
"BmnEcalDigitizer::Init() branch 'EcalPoint' not found! Task will be deactivated";
35 fArrayOfEcalDigits =
new TClonesArray(
"BmnECALDigit");
36 ioman->Register(
"EcalDigit",
"Ecal", fArrayOfEcalDigits, kTRUE);
38 if (LoadGeometry() != 0)
44 Info(__func__,
"ECAL digitizer ready");
51 if (!IsActive())
return;
54 fArrayOfEcalDigits->Delete();
56 for (Int_t
i = 0;
i < fCellsSize;
i++) {
62 Int_t N = fArrayOfEcalPoints->GetEntries();
63 for (Int_t
i = 0;
i < N;
i++) {
67 if (ch < fCellsSize) {
68 if (fCells[ch].GetChannel() == ch) {
69 Float_t energyLoss = p->GetEnergyLoss();
71 Float_t pointTime = p->GetTime();
72 if (fMaxPointTime > 0 && pointTime > fMaxPointTime)
continue;
74 pointTime += (fFiberLength - fLayerThickness * (p->
GetCopy()+1))/fFiberSOL;
76 fCells[ch].
SetAmp(fCells[ch].GetAmp() + energyLoss);
77 fCells[ch].
SetStartTime(fCells[ch].GetStartTime() + pointTime * energyLoss);
80 Error(__func__,
"ECAL ch %d was not initialized",ch);
83 Error(__func__,
"ECAL ch %d ignored",ch);
88 for (Int_t
i = 0;
i < fCellsSize;
i++) {
89 if (fCells[
i].GetChannel() !=
i)
continue;
91 Float_t amp = fCells[
i].
GetAmp() * 1000.;
93 if (amp == 0.)
continue;
94 if (amp < fThreshold)
continue;
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");
116 for (Int_t
i = 1;
i < fCellsSize;
i++) {
117 if (fCells[
i].GetChannel() ==
i) {
119 printf(
" % 4d [%3.0f,%3.0f] -> [%7.2f,%7.2f,%7.2f]\n",
i, fCells[
i].GetX(), fCells[
i].GetY(), x, y, z);
124 printf(
"))) ECAL cells coords\n");
125 printf(
"\e[0m" "\n");
129int BmnEcalDigitizer::LoadGeometry()
131 Bool_t loadFromFile = fEcalGeometryFileName !=
nullptr;
132 TGeoNode *ecal1 = 0, *ecal2 = 0;
134 TGeoVolume * ecal = gGeoManager->FindVolumeFast(
"ecal");
136 if (ecal->GetNdaughters() > 0) ecal1 = ecal->GetNode(0);
137 if (ecal->GetNdaughters() > 1) ecal2 = ecal->GetNode(1);
138 loadFromFile = kFALSE;
140 Info(__func__,
"Ecal geometry not found by TGeoManager\n");
145 Info(__func__,
"Loading coordinates of ECAL cells from %s\n", fEcalGeometryFileName);
146 TGeoVolume * top = TGeoVolume::Import(fEcalGeometryFileName,
"TOP");
149 LOG(error)<<
"<BmnEcalDigitizer::LoadGeometry>: Volume TOP not found in "<<(fEcalGeometryFileName ==
nullptr?
"(null)" : fEcalGeometryFileName);
154 TGeoNode * ecal = top->GetNode(0);
157 LOG(error)<<
"<BmnEcalDigitizer::LoadGeometry>: Unexpected geometry structure "<<(fEcalGeometryFileName ==
nullptr?
"(null)" : fEcalGeometryFileName);
161 ecal1 = ecal->GetDaughter(0);
162 ecal2 = ecal->GetDaughter(1);
165 if (ecal1 == 0 && ecal2 == 0) {
166 Info(__func__,
"BmnEcalDigitizer was set in inactive state, because ECAL geometry was not found");
170 for (Int_t
i = 0;
i < fCellsSize;
i++) {
174 Double_t coords[] = {0.,0.,0.};
175 Double_t ecalCoords[3];
176 Double_t labCoords[3];
178 coords[2] = fDepthShift;
181 Int_t n = ecal1->GetNdaughters();
183 LOG(error)<<
"<BmnEcalDigitizer::LoadGeometry>: Expected ecal node 1 with 504 daughters or less in "<<(fEcalGeometryFileName ==
nullptr?
"(null)" : fEcalGeometryFileName);
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);
192 ecal1->GetDaughter(
i)->LocalToMaster(coords, ecalCoords);
193 ecal1->LocalToMaster(ecalCoords,labCoords);
195 fCells[ch].
SetX(ecalCoords[0]);
196 fCells[ch].
SetY(ecalCoords[1]);
197 fCells[ch].
SetLabCoords(labCoords[0],labCoords[1],labCoords[2]);
202 Int_t n = ecal2->GetNdaughters();
204 LOG(error)<<
"<BmnEcalDigitizer::LoadGeometry>: Expected ecal node 2 with 504 daughters or less in "<<(fEcalGeometryFileName ==
nullptr?
"(null)" : fEcalGeometryFileName);
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);
213 ecal2->GetDaughter(
i)->LocalToMaster(coords, ecalCoords);
214 ecal2->LocalToMaster(ecalCoords,labCoords);
216 fCells[ch].
SetX(ecalCoords[0]);
217 fCells[ch].
SetY(ecalCoords[1]);
218 fCells[ch].
SetLabCoords(labCoords[0],labCoords[1],labCoords[2]);
void SetChannel(UShort_t ch)
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
virtual ~BmnEcalDigitizer()
Short_t GetCopyMother() const