BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnCaloTowerDraw.cxx
Go to the documentation of this file.
1/**
2 * @file BmnCaloTowerDraw.cxx
3 * @author
4 * @brief BmnCaloTowerDraw source file
5 * @date 2021-09-09
6 *
7 */
8
9#include "BmnCaloTowerDraw.h"
10
11#include "BmnCaloDigit.h"
12#include "BmnDetectorList.h"
13#include "FairLogger.h"
14#include "MpdEventManagerEditor.h"
15#include "TEveManager.h"
16#include "TEveViewer.h"
17#include "TGeoBBox.h"
18#include "TGeoManager.h"
19#include "nlohmann/json.hpp"
20
21#include <iostream>
22
23using json = nlohmann::json;
24
25// file containing the characteristics of calorimeters
26const char* caloDataFile = gSystem->ExpandPathName("$VMCWORKDIR/config/eventdisplay.json");
27
29 : FairTask("BmnCaloTowerDraw", 0)
30 , fEventManager(nullptr)
31 , fDigitList(nullptr)
32 , fq(nullptr)
33 , fCaloName("unknown")
35 , fEneArr(nullptr)
36 , fMaxE(0)
37 , fNumModules(0)
38 , fModuleZLen(nullptr)
40 , fGeoPath("")
43{}
44
45BmnCaloTowerDraw::BmnCaloTowerDraw(const char* name, Int_t caloType, Float_t caloMinEnergyThreshold, Int_t iVerbose)
46 : FairTask(name, iVerbose)
47 , fEventManager(nullptr)
48 , fDigitList(nullptr)
49 , fq(nullptr)
50 , fCaloName("unknown")
51 , fCaloMinEnergyThreshold(caloMinEnergyThreshold)
52 , fEneArr(nullptr)
53 , fMaxE(0)
54 , fNumModules(0)
55 , fModuleZLen(nullptr)
57 , fGeoPath("")
60{
62}
63
65{
66 if (fVerbose > 0)
67 cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | " << endl;
68 //----------------------------------------
69 if (fCaloName == "unknown") {
70 LOG(error) << "BmnCaloTowerDraw::Init() calorimeter type not defined! Task will be deactivated!";
71 SetActive(kFALSE);
72 return kERROR;
73 }
74 //----------------------------------------
75 ifstream file(caloDataFile);
76 if (!file.is_open()) {
77 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | file " << caloDataFile
78 << " not found! Task will be deactivated!";
79 SetActive(kFALSE);
80 file.close();
81 return kERROR;
82 }
83
84 json caloData;
85 file >> caloData;
86 file.close();
87 try {
88 fNumModules = caloData["calorimeters"][fCaloName.Data()]["numberOfModules"];
89 fGeoPath = caloData["calorimeters"][fCaloName.Data()]["pathToGeometry"];
90 } catch (const json::type_error& e) {
91 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | file " << caloDataFile
92 << " doesn't contain the required data or the calorimeter type is incorrectly set! Task will be "
93 "deactivated!";
94 SetActive(kFALSE);
95 return kERROR;
96 }
97 //----------------------------------------
99 if (fVerbose > 1)
100 cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | get instance of EventManager: " << fEventManager
101 << endl;
102
103 fEventManager->fgRedrawRecoPointsReqired = kTRUE;
104
105 FairRootManager* fManager = FairRootManager::Instance();
106 if (fVerbose > 1)
107 cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | get instance of FairRootManager: " << fManager
108 << endl;
109
110 fDigitList = (TClonesArray*)fManager->GetObject(GetName());
111 if (fDigitList == 0) {
112 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | branch " << GetName()
113 << " not found! Task will be deactivated!";
114 SetActive(kFALSE);
115 return kERROR;
116 }
117 if (fVerbose > 1)
118 cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | get digit list " << fDigitList << endl;
119
120 if (gGeoManager->cd(fGeoPath.c_str()) == false) {
121 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | Path to geometry '" << fGeoPath
122 << "' not found" << endl;
123 SetActive(kFALSE);
124 return kERROR;
125 }
126 //----------------------------------------
128 fMaxModuleZLen = 0;
129
130 fEneArr = new Float_t[fNumModules + 1];
131 fMaxE = 1;
132 for (UInt_t i = 0; i < fNumModules + 1; i++)
133 fEneArr[i] = 1;
134 DrawTowers();
137
138 fq = 0;
139
140 return kSUCCESS;
141}
142
144{
145 if (!IsActive())
146 return;
147 Reset();
148
149 if (fVerbose > 1)
150 cout << "-----[ BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | ]-----------------------------------"
151 << endl;
152
153 fMaxE = 0;
154 for (UInt_t i = 0; i < fNumModules + 1; i++)
155 fEneArr[i] = 0;
156
157 if (fEventManager->fgShowShowMCPoints || fEventManager->fgShowShowRecoPoints || fEventManager->fgShowShowRecoTracks)
158 {
159 Int_t nDigits = fDigitList->GetEntriesFast();
160 if (fVerbose > 2)
161 cout << "BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | Number of Calo digits = " << nDigits
162 << endl;
163
164 for (int i = 0; i < nDigits; i++) {
166
167 UShort_t channel = dgt->GetChannel();
168 if (channel < 1 || channel > fNumModules)
169 continue;
170 Float_t energy = dgt->GetAmp() * 1e-3; // MeV to GeV
171
172 if (fVerbose > 3)
173 cout << "BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | Channel = " << channel
174 << ", Energy = " << energy << " GeV" << endl;
175
176 fEneArr[channel] = energy;
177 }
178
179 for (UInt_t i = 1; i < fNumModules + 1; i++)
180 if (fEneArr[i] > fMaxE)
181 fMaxE = fEneArr[i];
182
183 if (fVerbose > 2)
184 cout << "BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | Max energy = " << fMaxE << " GeV" << endl;
185
186 DrawTowers();
187 } else {
188 if (fResetRequiredFlag) {
189 fMaxE = 1;
190 for (UInt_t i = 0; i < fNumModules + 1; i++)
191 fEneArr[i] = 1;
192
193 DrawTowers();
194
196 }
197 }
198
199 TEvePointSet* q = new TEvePointSet(GetName(), fDigitList->GetEntriesFast(), TEvePointSelectorConsumer::kTVT_XYZ);
200 q->SetOwnIds(kTRUE);
201
202 fEventManager->AddEventElement(q, RecoPointList);
203
204 fq = q;
205
206 gEve->FullRedraw3D(kFALSE);
207}
208
210{
211 gGeoManager->cd(fGeoPath.c_str());
212
213 auto rootNode = gGeoManager->GetCurrentNode();
214 auto rootArr = rootNode->GetVolume()->GetNodes();
215
216 for (Int_t iModule = 0; iModule < rootArr->GetEntriesFast(); iModule++) {
217 auto caloNode = (TGeoNode*)rootArr->UncheckedAt(iModule);
218 auto caloArr = caloNode->GetVolume()->GetNodes();
219
220 for (Int_t iTower = 0; iTower < caloArr->GetEntriesFast(); iTower++) {
221 auto moduleNode = (TGeoNode*)caloArr->UncheckedAt(iTower);
222 TGeoVolume* moduleVolumeCopy;
223
224 /**
225 * the internal structure of modules does not allow changing their shape
226 * (all modules have the same TGeoVolume), so during initialization we
227 * delete and create a new TGeoVolume for each module.
228 */
229
230 if (fInitDrawFlag) {
231 moduleVolumeCopy = (TGeoVolume*)moduleNode->GetVolume()->Clone();
232 fModuleZLen[iTower] = ((TGeoBBox*)moduleVolumeCopy->GetShape())->GetDZ();
233 if (fMaxModuleZLen < fModuleZLen[iTower])
234 fMaxModuleZLen = fModuleZLen[iTower];
235 } else {
236 moduleVolumeCopy = (TGeoVolume*)moduleNode->GetVolume();
237
238 auto box = (TGeoBBox*)moduleVolumeCopy->GetShape();
239 auto mat = moduleNode->GetMatrix();
240
241 if (fEneArr[iTower + 1] != 0) {
242 box->SetBoxDimensions(box->GetDX(), box->GetDY(),
243 fModuleZLen[iTower] * fEneArr[iTower + 1] / fMaxE);
244 ((TGeoTranslation*)mat)->SetDz(fModuleZLen[iTower] * fEneArr[iTower + 1] / fMaxE - fMaxModuleZLen);
245
246 moduleNode->SetVisibility(kTRUE);
247 } else
248 moduleNode->SetVisibility(kFALSE);
249 }
250
251 moduleNode->SetVolume(moduleVolumeCopy);
252 }
253 }
254
256}
257
259{
260 if (fq != 0) {
261 fq->Reset();
262 gEve->RemoveElement(fq, fEventManager->EveRecoPoints);
263 }
264}
265
267
269{
270 fDigitList->Delete();
271 delete[] fModuleZLen;
272 delete[] fEneArr;
273}
const char * caloDataFile
int i
Definition P4_F32vec4.h:22
unsigned short UShort_t
int Int_t
unsigned int UInt_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
R__EXTERN TEveManager * gEve
R__EXTERN TGeoManager * gGeoManager
R__EXTERN TSystem * gSystem
UShort_t GetChannel() const
Float_t GetAmp() const
Double_t fMaxModuleZLen
z length of calorimeter modules, cm
Bool_t fResetRequiredFlag
path to calorimeter geometry
MpdEventManager * fEventManager
virtual InitStatus Init()
BmnCaloTowerDraw()
Default constructor.
TEvePointSet * fq
Float_t fCaloMinEnergyThreshold
virtual void Finish()
TClonesArray * fDigitList
virtual ~BmnCaloTowerDraw()
Destructor.
Float_t fMaxE
array of energies in each module of calorimeter, GeV
virtual void Exec(Option_t *option)
static void GetSystemNameCaps(DetectorId det, TString &name)
Get system name in capitals.
static MpdEventManager * Instance()
TGeoShape * GetShape() const
TObject * Clone(const char *newname="") const override
void SetOwnIds(Bool_t o)
@ RecoPointList
BmnCaloTowerDraw header file.
basic_json<> json
default specialization
Definition json.hpp:3365