BmnRoot
Loading...
Searching...
No Matches
BmnCaloTowerDraw.cxx
Go to the documentation of this file.
1
9#include "BmnCaloTowerDraw.h"
10#include "BmnCaloDigit.h"
11#include "BmnDetectorList.h"
12
13#include "MpdEventManagerEditor.h"
14#include "FairLogger.h"
15
16#include "TEveManager.h"
17#include "TGeoManager.h"
18#include "TEveViewer.h"
19#include "TGeoBBox.h"
20
21#include "nlohmann/json.hpp"
22
23#include <iostream>
24
26
27// file containing the characteristics of calorimeters
28const char* caloDataFile = gSystem->ExpandPathName("$VMCWORKDIR/config/eventdisplay.json");
29
31: FairTask("BmnCaloTowerDraw", 0),
32 fEventManager(nullptr),
33 fDigitList(nullptr),
34 fq(nullptr),
35 fCaloName("unknown"),
36 fCaloMinEnergyThreshold(0),
37 fEneArr(nullptr),
38 fMaxE(0),
39 fNumModules(0),
40 fModuleZLen(nullptr),
41 fMaxModuleZLen(0),
42 fGeoPath(""),
43 fResetRequiredFlag(kFALSE),
44 fInitDrawFlag(kTRUE)
45{}
46
47BmnCaloTowerDraw::BmnCaloTowerDraw(const char* name, Int_t caloType, Float_t caloMinEnergyThreshold, Int_t iVerbose)
48: FairTask(name, iVerbose),
49 fEventManager(nullptr),
50 fDigitList(nullptr),
51 fq(nullptr),
52 fCaloName("unknown"),
53 fCaloMinEnergyThreshold(caloMinEnergyThreshold),
54 fEneArr(nullptr),
55 fMaxE(0),
56 fNumModules(0),
57 fModuleZLen(nullptr),
58 fMaxModuleZLen(0),
59 fGeoPath(""),
60 fResetRequiredFlag(kFALSE),
61 fInitDrawFlag(kTRUE)
62{
63 BmnDetectorList::GetSystemNameCaps(caloType, fCaloName);
64}
65
67{
68 if (fVerbose > 0) cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | " << endl;
69 //----------------------------------------
70 if (fCaloName == "unknown")
71 {
72 LOG(error) << "BmnCaloTowerDraw::Init() calorimeter type not defined! Task will be deactivated!";
73 SetActive(kFALSE);
74 return kERROR;
75 }
76 //----------------------------------------
77 ifstream file(caloDataFile);
78 if (!file.is_open())
79 {
80 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | file " << caloDataFile << " not found! Task will be deactivated!";
81 SetActive(kFALSE);
82 file.close();
83 return kERROR;
84 }
85
86 json caloData;
87 file >> caloData;
88 file.close();
89 try
90 {
91 fNumModules = caloData["calorimeters"][fCaloName.Data()]["numberOfModules"];
92 fGeoPath = caloData["calorimeters"][fCaloName.Data()]["pathToGeometry"];
93 }
94 catch(const json::type_error& e)
95 {
96 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | file " << caloDataFile << " doesn't contain the required data or the calorimeter type is incorrectly set! Task will be deactivated!";
97 SetActive(kFALSE);
98 return kERROR;
99 }
100 //----------------------------------------
102 if (fVerbose > 1) cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | get instance of EventManager: " << fEventManager << endl;
103
105
106 FairRootManager *fManager = FairRootManager::Instance();
107 if (fVerbose > 1) cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | get instance of FairRootManager: " << fManager << endl;
108
109 fDigitList = (TClonesArray *) fManager->GetObject(GetName());
110 if (fDigitList == 0)
111 {
112 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | branch " << GetName() << " not found! Task will be deactivated!";
113 SetActive(kFALSE);
114 return kERROR;
115 }
116 if (fVerbose > 1) cout << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | get digit list " << fDigitList << endl;
117
118 if (gGeoManager->cd(fGeoPath.c_str()) == false)
119 {
120 LOG(error) << "BmnCaloTowerDraw::Init() | Type: " << fCaloName << " | Path to geometry '" << fGeoPath << "' not found" << endl;
121 SetActive(kFALSE);
122 return kERROR;
123 }
124 //----------------------------------------
125 fModuleZLen = new Double_t[fNumModules+1];
126 fMaxModuleZLen = 0;
127
128 fEneArr = new Float_t[fNumModules+1];
129 fMaxE = 1;
130 for (UInt_t i = 0; i < fNumModules+1; i++)
131 fEneArr[i] = 1;
132 DrawTowers();
133 fInitDrawFlag = kFALSE;
134 fResetRequiredFlag = kFALSE;
135
136 fq = 0;
137
138 return kSUCCESS;
139}
140
141void BmnCaloTowerDraw::Exec(Option_t* option)
142{
143 if (!IsActive()) return;
144 Reset();
145
146 if (fVerbose > 1) cout << "-----[ BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | ]-----------------------------------" << endl;
147
148 fMaxE = 0;
149 for (UInt_t i = 0; i < fNumModules+1; i++)
150 fEneArr[i] = 0;
151
153 {
154 Int_t nDigits = fDigitList->GetEntriesFast();
155 if (fVerbose > 2) cout << "BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | Number of Calo digits = " << nDigits << endl;
156
157 for (int i = 0; i < nDigits; i++)
158 {
159 BmnCaloDigit *dgt = (BmnCaloDigit *) fDigitList->At(i);
160
161 UShort_t channel = dgt->GetChannel();
162 if (channel < 1 || channel > fNumModules) continue;
163 Float_t energy = dgt->GetAmp() * 1e-3; // MeV to GeV
164
165 if (fVerbose > 3) cout << "BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | Channel = " << channel << ", Energy = " << energy << " GeV" << endl;
166
167 fEneArr[channel] = energy;
168 }
169
170 for (UInt_t i = 1; i < fNumModules+1; i++)
171 if (fEneArr[i] > fMaxE) fMaxE = fEneArr[i];
172
173 if (fVerbose > 2) cout << "BmnCaloTowerDraw::Exec() | Type: " << fCaloName << " | Max energy = " << fMaxE << " GeV" << endl;
174
175 DrawTowers();
176 }
177 else
178 {
179 if (fResetRequiredFlag)
180 {
181 fMaxE = 1;
182 for (UInt_t i = 0; i < fNumModules+1; i++)
183 fEneArr[i] = 1;
184
185 DrawTowers();
186
187 fResetRequiredFlag = kFALSE;
188 }
189 }
190
191 TEvePointSet *q = new TEvePointSet(GetName(), fDigitList->GetEntriesFast(), TEvePointSelectorConsumer::kTVT_XYZ);
192 q->SetOwnIds(kTRUE);
193
195
196 fq = q;
197
198 gEve->FullRedraw3D(kFALSE);
199}
200
202{
203 gGeoManager->cd(fGeoPath.c_str());
204
205 auto rootNode = gGeoManager->GetCurrentNode();
206 auto rootArr = rootNode->GetVolume()->GetNodes();
207
208 for (Int_t iModule = 0; iModule < rootArr->GetEntriesFast(); iModule++)
209 {
210 auto caloNode = (TGeoNode *) rootArr->UncheckedAt(iModule);
211 auto caloArr = caloNode->GetVolume()->GetNodes();
212
213 for (Int_t iTower = 0; iTower < caloArr->GetEntriesFast(); iTower++)
214 {
215 auto moduleNode = (TGeoNode *) caloArr->UncheckedAt(iTower);
216 TGeoVolume *moduleVolumeCopy;
217
224 if (fInitDrawFlag)
225 {
226 moduleVolumeCopy = (TGeoVolume *) moduleNode->GetVolume()->Clone();
227 fModuleZLen[iTower] = ((TGeoBBox *) moduleVolumeCopy->GetShape())->GetDZ();
228 if (fMaxModuleZLen < fModuleZLen[iTower])
229 fMaxModuleZLen = fModuleZLen[iTower];
230 }
231 else
232 {
233 moduleVolumeCopy = (TGeoVolume *) moduleNode->GetVolume();
234
235 auto box = (TGeoBBox *) moduleVolumeCopy->GetShape();
236 auto mat = moduleNode->GetMatrix();
237
238 if (fEneArr[iTower+1] != 0)
239 {
240 box->SetBoxDimensions(box->GetDX(), box->GetDY(), fModuleZLen[iTower] * fEneArr[iTower+1] / fMaxE);
241 ((TGeoTranslation *) mat)->SetDz(fModuleZLen[iTower] * fEneArr[iTower+1] / fMaxE - fMaxModuleZLen);
242
243 moduleNode->SetVisibility(kTRUE);
244 }
245 else
246 moduleNode->SetVisibility(kFALSE);
247 }
248
249 moduleNode->SetVolume(moduleVolumeCopy);
250 }
251 }
252
253 fResetRequiredFlag = kTRUE;
254}
255
257{
258 if (fq != 0)
259 {
260 fq->Reset();
261 gEve->RemoveElement(fq, fEventManager->EveRecoPoints);
262 }
263}
264
266
268{
269 fDigitList->Delete();
270 delete[] fModuleZLen;
271 delete[] fEneArr;
272}
const char * caloDataFile
int i
Definition P4_F32vec4.h:22
UShort_t GetChannel() const
Float_t GetAmp() const
MpdEventManager * fEventManager
virtual InitStatus Init()
TEvePointSet * fq
virtual void Finish()
TClonesArray * fDigitList
virtual void Exec(Option_t *option)
static void GetSystemNameCaps(DetectorId det, TString &name)
TEveElementList * EveRecoPoints
static MpdEventManager * Instance()
void AddEventElement(TEveElement *element, ElementList element_list)
a class to store JSON values
Definition json.hpp:17282
exception indicating executing a member function with a wrong type
Definition json.hpp:2972
@ RecoPointList
BmnCaloTowerDraw header file.
basic_json<> json
default specialization
Definition json.hpp:3337