BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnZdcDigiScheme.cxx
Go to the documentation of this file.
1/*************************************************************************************
2 *
3 * Class BmnZdcDigiScheme
4 *
5 * Author: Elena Litvinenko
6 * e-mail: litvin@nf.jinr.ru
7 * Version: 18-11-2015
8 *
9 ************************************************************************************/
10
11#include "BmnZdcDigiScheme.h"
12
13#include "TGeoBBox.h"
14#include "TGeoManager.h"
15#include "TGeoNode.h"
16
17#include <iostream>
18
19using std::cout;
20using std::endl;
21
25
26static Int_t kZDC = 1; // // hard-coded basic ZDC detector number
27
28// -------------------------------------------------------------------------
29
31 : Nx(0)
32 , Ny(0)
33 , Nz(0)
34{
35 fZdcDigiPar = 0;
36}
37
38// -------------------------------------------------------------------------
39
41{
42 fRefcount--;
43 if (!fRefcount) {
44 delete this;
45 fInstance = NULL;
46 }
47}
48// -------------------------------------------------------------------------
49
57
58// -------------------------------------------------------------------------
59
61{
62 if (!fInitialized) {
63
64 if (!geoPar) {
65 cout << "-W- BmnZdcDigiScheme::Init: "
66 << "No geometry parameters available!" << endl;
67 return kFALSE;
68 }
69 if (!digiPar) {
70 cout << "-W- BmnZdcDigiScheme::Init: "
71 << "No digitization parameters available!" << endl;
72 // return kFALSE;
73 }
74 fZdcDigiPar = digiPar;
75
76 TObjArray* sensNodes = geoPar->GetGeoSensitiveNodes();
77 if (!sensNodes) {
78 cout << "-W- BmnZdcDigiScheme::Init: "
79 << "No sensitive nodes available!" << endl;
80 return kFALSE;
81 }
82
83 fPasNodes = geoPar->GetGeoPassiveNodes();
84 if (!fPasNodes) {
85 cout << "-W- BmnZdcDigiScheme::Init: "
86 << "No passive nodes available!" << endl;
87 return kFALSE;
88 }
89
91
92 AddNodes(sensNodes, pVerbose);
94
95 if (pVerbose)
96 cout << endl << "-W- BmnZdcDigiScheme::Init: finished." << endl;
97 }
98 return kTRUE;
99}
100
101// -------------------------------------------------------------------------
102
104{
105 if (!nod)
106 return NULL;
107
108 static TString root_name_copy1 = "";
109 static Double_t volData[6] = {0, 0, 0, 0, 0, 0};
110 Int_t i;
111
112 TString shape_name = nod->getShapePointer()->GetName();
113 TString root_name = nod->getRootVolume()->GetName();
114 TString tmp = " ";
115 TGeoBBox* shape = 0;
116
117 FairGeoVector pos = nod->getLabTransform()->getTranslation();
118
119 for (i = 0; i < 3; i++)
120 volData[i] = pos.getValues(i); // [cm]
121
122 if (root_name != root_name_copy1) {
123
124 root_name_copy1 = root_name;
125
126 shape = (TGeoBBox*)nod->getRootVolume()->GetShape();
127
128 if (shape_name.Contains("BOX")) {
129 volData[3] = shape->GetDX(); // [cm]
130 volData[4] = shape->GetDY(); // [cm]
131 volData[5] = shape->GetDZ(); // [cm]
132 } else {
133 if (shape_name.Contains("PGON")) {
134 volData[3] = nod->getPoint(2)->getZ() / 10.; // [cm]
135 volData[4] = volData[3];
136 volData[5] = shape->GetDZ(); // [cm]
137 }
138 }
139 }
140
141 BmnZdcVolInfo_t* volInfo = new BmnZdcVolInfo_t;
142 for (i = 0; i < 6; i++)
143 volInfo->push_back(volData[i]);
144
145 if (pVerbose > 1) {
146 if (pVerbose > 2)
147 tmp = " root: " + root_name + ", shape: " + shape_name;
148 tmp += "X,Y,Z, Dx,Dy,Dz: ";
149 cout << tmp << volData[0] << "," << volData[1] << "," << volData[2] << ", " << volData[3] << "," << volData[4]
150 << "," << volData[5] << endl;
151 }
152 return volInfo;
153}
154
155// -------------------------------------------------------------------------
156
158 Int_t nodeNumber,
159 BmnZdcDigiId_t* right,
160 Int_t pVerbose)
161{
162 if (!nod)
163 return NULL;
164
165 // FairGeoNode *nod0, *nod1;
166 TString mother_name, tmp;
167
168 // FairGeoTransform *center;
169
170 TString nod_name = nod->GetName();
171 mother_name = nod->getMother();
172
173 // if (nod_name.Contains("boxs") {
174 if (1) {
175
176 // (*right).push_back(nod->getRootVolume()->GetNumber()); // GroupID(now=box volume ID)
177 if (nod_name.Contains("boxs"))
178 (*right).push_back(1); // GroupID ("size" of small ZDC module)
179 else
180 (*right).push_back(2); // GroupID ("size" of big ZDC module)
181 (*right).push_back(nod->getCopyNo()); // ModuleID inside group
182 // center = nod->getLabTransform();
183 (*right).push_back(nodeNumber); // ChannelID
184
185 BmnZdcVolId_t* left = new BmnZdcVolId_t;
186 (*left).push_back(nod->getRootVolume()->GetNumber() + 3); // sensitive volume ID
187 (*left).push_back(nod->getCopyNo()); // MotherMotherCopyNo
188
189 if (pVerbose > 1) {
190 tmp = " mother: " + mother_name + ", me: " + (nod->getName()) + " ";
191 cout << tmp << (*left)[0] << "," << (*left)[1] << " : " << (*right)[0] << "," << (*right)[1] << ","
192 << (*right)[2] << endl;
193 }
194
195 return left;
196
197 } else {
198 cout << "-E- BmnZdcDigiScheme::CreateVolInfoElement: Strange for me node: " << nod->GetName()
199 << " Node number:" << nodeNumber << " Mother:" << mother_name << endl;
200 return NULL;
201 }
202}
203
204// -------------------------------------------------------------------------
205
207{
208 // Int_t nNodes = sensNodes->GetEntriesFast();
209 Int_t nPasNodes = fPasNodes->GetEntriesFast();
210 FairGeoNode* nod = 0;
211 Int_t nodeNumber, /*nodeCopyNo,nodeVolumeId, chanId2=0, chanId1=0, */ zdc_channel = 0;
212 BmnZdcVolId_t* left1 /*,*left2*/;
213 BmnZdcDigiId_t* right1 /*,*right2*/;
214
215 // if (pVerbose) {
216 // cout << "-W- BmnZdcDigiScheme::AddNodes: started. nNodes:" << nNodes << endl;
217 // }
218
219 // for (nodeNumber=0;nodeNumber<nNodes;nodeNumber++) {
220
221 if (pVerbose) {
222 // cout << "-W- BmnZdcDigiScheme::AddNodes: started. nNodes:" << nNodes << endl;
223 cout << "-W- BmnZdcDigiScheme::AddNodes: started. nNodes:" << nPasNodes << endl;
224 }
225
226 TString nod_name;
227
228 for (nodeNumber = 1; nodeNumber < nPasNodes; nodeNumber++) {
229 // nod = (FairGeoNode*)sensNodes->At(nodeNumber);
230 nod = (FairGeoNode*)fPasNodes->At(nodeNumber); // we will use boxes, not layers
231 if (nod) {
232
233 nod_name = nod->getName();
234 if (nod_name.Contains("box")) {
235
236 zdc_channel++;
237
238 right1 = new BmnZdcDigiId_t;
239 // left1 = CreateVolElement(nod, nodeNumber, right1, pVerbose);
240 left1 = CreateVolElement(nod, zdc_channel, right1, pVerbose);
241
242 fVolToDigiIdMap[*left1] = *right1;
243
244 CreateVolInfoElement(nod, 1);
245 // left2 = new BmnZdcVolId_t ((*left1).begin(),(*left1).end());
246 // (*left2)[0]=(*left1)[0]+1;
247 // right2 = new BmnZdcDigiId_t (right1->begin(),right1->end());
248 // (*right2)[0] = (*right1)[0]+1;
249
250 // fVolToDigiIdMap[*left2]=*right2;
251
252 // CreateVolCopyElements (left1, right1);
253 }
254
255 } else {
256 cout << "-W- BmnZdcDigiScheme::AddNodes: "
257 // << "Node number "<< nodeNumber << " from " << nNodes << " not found!" << endl;
258 << "Node number " << nodeNumber << " from " << nPasNodes << " not found!" << endl;
259 return kFALSE;
260 }
261 }
262 return kTRUE;
263}
264
265// -------------------------------------------------------------------------
266
268{
269 BmnZdcVolId_t* left1 /*,*left2*/;
270 BmnZdcDigiId_t* right1 /*,*right2*/;
271
272 if (!fPasNodes)
273 return kFALSE;
274
275 FairGeoNode* nod1 = (FairGeoNode*)fPasNodes->At(fPasNodes->GetEntries() - 2);
276
277 if (!nod1)
278 return kFALSE;
279
280 Int_t moduleID, nModules; // {MotherMotherCopyNo, MotherCopyNo, VolumeId, CopyNo},{GroupID, ModuleID, ChannelID}
281
282 TString lm_name = nod1->getName();
283 TString last_module_number(&(lm_name[lm_name.Last('#') + 1]));
284 nModules = last_module_number.Atoi();
285
286 for (moduleID = 1; moduleID < nModules; moduleID++) {
287
288 left1 = new BmnZdcVolId_t((*left).begin(), (*left).end());
289 (*left1)[1] = (*left)[1] + moduleID;
290 right1 = new BmnZdcDigiId_t(right->begin(), right->end());
291 (*right1)[1] = (*right)[1] + moduleID;
292
293 fVolToDigiIdMap[*left1] = *right1;
294 }
295
296 return kTRUE;
297}
298
299// -------------------------------------------------------------------------
300
302{
303
304 if (!fPasNodes)
305 return kFALSE;
306
307 FairGeoNode* nod1 = (FairGeoNode*)fPasNodes->At(fPasNodes->GetEntries() - 2);
308
309 if (!nod1)
310 return kFALSE;
311
312 Int_t moduleID, nModules;
313
314 TString lm_name = nod1->getName();
315 TString last_module_number(&(lm_name[lm_name.Last('#') + 1]));
316 nModules = last_module_number.Atoi();
317
318 for (moduleID = 1; moduleID < nModules; moduleID++) {
319
320 nod1 = (FairGeoNode*)fPasNodes->At(fPasNodes->GetEntries() - 2 - nModules + moduleID);
321
322 FairGeoVector pos = nod1->getLabTransform()->getTranslation();
323
324 BmnZdcVolInfo_t* volInfo1 = new BmnZdcVolInfo_t((*volInfo).begin(), (*volInfo).end());
325 (*volInfo1)[0] = pos.getValues(0); // X [cm]
326 (*volInfo1)[1] = pos.getValues(1); // Y [cm]
327
328 BmnZdcDigiId_t* right1 = new BmnZdcDigiId_t(right->begin(), right->end());
329 (*right1)[1] = (*right)[1] + moduleID;
330
331 BmnZdcDigiId_t* right2 = new BmnZdcDigiId_t(right1->begin(), right1->end());
332 (*right2)[0] = (*right1)[0] + 1;
333
334 BmnZdcVolInfo_t* volInfo2 = new BmnZdcVolInfo_t(*volInfo1);
335 (*volInfo2)[2] = -(*volInfo2)[2]; // Z [cm]
336
337 fDigiToVolInfoMap[*right1] = volInfo1;
338 fDigiToVolInfoMap[*right2] = volInfo2;
339 }
340
341 return kTRUE;
342}
343
344// -------------------------------------------------------------------------
345
347{
348 if (!pDigiID)
349 return kFALSE;
350 if (fDigiToVolInfoMap.find(*pDigiID) == fDigiToVolInfoMap.end())
351 return kFALSE;
352 else {
353 BmnZdcVolInfo_t* volInfo = fDigiToVolInfoMap[*pDigiID];
354 if (volInfo) {
355 x = (*volInfo)[0];
356 y = (*volInfo)[1];
357 z = (*volInfo)[2];
358 return kTRUE;
359 } else
360 return kFALSE;
361 }
362}
363
364// -------------------------------------------------------------------------
365
367{
368 if (!pDigiID)
369 return kFALSE;
370 if (fDigiToVolInfoMap.find(*pDigiID) == fDigiToVolInfoMap.end())
371 return kFALSE;
372 else {
373 BmnZdcVolInfo_t* volInfo = fDigiToVolInfoMap[*pDigiID];
374 if (volInfo) {
375 Dx = (*volInfo)[3];
376 Dy = (*volInfo)[4];
377 Dz = (*volInfo)[5];
378 return kTRUE;
379 } else
380 return kFALSE;
381 }
382}
383
384// -------------------------------------------------------------------------
385
387{
388 if (!pVolId)
389 return kFALSE;
390 else
391 return (!(fVolToDigiIdMap.find(*pVolId) == fVolToDigiIdMap.end()));
392}
393
394// -------------------------------------------------------------------------
395
397{
398 static const BmnZdcDigiId_t not_found(4, -1);
399
400 if (IsVolumeExist(pVolId))
401 return fVolToDigiIdMap[*pVolId];
402 else
403 return not_found;
404}
405
406// -------------------------------------------------------------------------
407
409{
410 BmnZdcDigiId_t digiID = GetDigiId(pVolId);
411 // return digiID.first;
412 return digiID[0];
413}
414
415// -------------------------------------------------------------------------
416
418{
419 BmnZdcDigiId_t digiID = GetDigiId(pVolId);
420 // return digiID.second;
421 return digiID[2];
422}
423
424// -------------------------------------------------------------------------
425
427{
428 if (IsVolumeExist(pVolId)) {
429
430 BmnZdcDigiId_t pDigiID = GetDigiId(pVolId);
431
432 if (fDigiToVolInfoMap.find(pDigiID) == fDigiToVolInfoMap.end())
433 return NULL;
434 else
435 return fDigiToVolInfoMap[pDigiID];
436 } else
437 return NULL;
438}
439
440// -------------------------------------------------------------------------
441
442void BmnZdcDigiScheme::PrintVolume(Int_t volID, Int_t copyNoMotherMother)
443{
444 Int_t content[] = {volID, copyNoMotherMother};
445 BmnZdcVolId_t pVolId(content, content + sizeof(content) / sizeof(Int_t));
446
447 BmnZdcDigiId_t pDigiID = GetDigiId(&pVolId);
448
449 cout << " BmnZdc Volume: " << volID << "," << copyNoMotherMother << " DigiID: " << pDigiID[0] << "," << pDigiID[1]
450 << "," << pDigiID[2];
451
452 if (IsVolumeExist(&pVolId))
453 cout << " found ";
454
455 BmnZdcVolInfo_t* pVolInfo = GetVolInfo(&pVolId);
456
457 if (pVolInfo)
458 cout << " X,Y,Z [cm]: " << (*pVolInfo)[0] << "," << (*pVolInfo)[1] << "," << (*pVolInfo)[2]
459 << " Dx,Dy,Dz [cm]: " << (*pVolInfo)[3] << "," << (*pVolInfo)[4] << "," << (*pVolInfo)[5];
460 else
461 cout << " (no VolInfo) ";
462
463 cout << endl;
464}
465
466// -------------------------------------------------------------------------
467
468Bool_t BmnZdcDigiScheme::CalcDimensions(Int_t pGlobalDetectorNumber, Int_t& nx, Int_t& ny, Int_t& nz)
469{
470
471 if (fDigiToVolInfoMap.empty())
472 return kFALSE;
473
474 Bool_t result = kFALSE;
475 std::map<BmnZdcDigiId_t, BmnZdcVolInfo_t*>::iterator it;
476 std::map<Double_t, Int_t> xmap, ymap, zmap;
477 Double_t x, y, z;
478 nx = ny = nz = 0;
479
480 for (it = fDigiToVolInfoMap.begin(); it != fDigiToVolInfoMap.end(); ++it) {
481
482 // cout << ". ";
483
484 // if ((*it).first.first==pGlobalDetectorNumber) {
485 // if ((*it).first[0]==1) {
486 if (1) {
487
488 result = kTRUE;
489
490 x = (*((*it).second))[0];
491 if (xmap.count(x))
492 xmap[x] = xmap[x] + 1;
493 else
494 xmap[x] = 1;
495
496 y = (*((*it).second))[1];
497 if (ymap.count(y))
498 ymap[y] = ymap[y] + 1;
499 else
500 ymap[y] = 1;
501
502 z = (*((*it).second))[2];
503 if (zmap.count(z))
504 zmap[z] = zmap[z] + 1;
505 else
506 zmap[z] = 1;
507 }
508 }
509
510 nx = xmap.size();
511 ny = ymap.size();
512 nz = zmap.size();
513
514 return result;
515}
516
517// -------------------------------------------------------------------------
518
520{
521 nx = Nx;
522 ny = Ny;
523 nz = Nz;
524}
525
526// -------------------------------------------------------------------------
527
529{
530 Int_t content[] = {-1, -1};
531 BmnZdcVolId_t resultmc(content, content + sizeof(content) / sizeof(Int_t));
532
533 BmnZdcDigiId_t result(-1, -1);
534 if (gGeoManager) {
535 TGeoNode* tgn = gGeoManager->FindNode(x, y, z);
536 if (tgn) {
537 resultmc[0] = (gGeoManager->GetMother(2))->GetNumber();
538 resultmc[1] = (gGeoManager->GetMother(1))->GetMotherVolume()->GetNumber();
539 resultmc[2] = tgn->GetVolume()->GetNumber();
540 resultmc[3] = tgn->GetNumber();
541 if (fVolToDigiIdMap.find(resultmc) != fVolToDigiIdMap.end())
542 result = fVolToDigiIdMap[resultmc];
543 }
544 }
545 return result;
546}
547
548// -------------------------------------------------------------------------
549
551{
552 Int_t content[] = {pMcVolumeNumber, pMotherMotherCopyNumber};
553 BmnZdcVolId_t pVolId(content, content + sizeof(content) / sizeof(Int_t));
554 BmnZdcDigiId_t digiID = GetDigiId(&pVolId);
555 return digiID;
556}
557
558// -------------------------------------------------------------------------
559
560void BmnZdcDigiScheme::SplitDigiID(BmnZdcDigiId_t digiID, Int_t& module_groupID, Int_t& modID, Int_t& chanID)
561{
562 module_groupID = digiID[0];
563 modID = digiID[1];
564 chanID = digiID[2];
565}
566
567// -------------------------------------------------------------------------
568
570{
571 cout << "*********************************************" << endl;
572
573 cout << "*** BmnZdcDigiScheme:" << endl;
574 cout << " BmnZdc Nx,Ny,Nz: " << Nx << "," << Ny << "," << Nz;
575
576 std::map<BmnZdcVolId_t, BmnZdcDigiId_t>::iterator it;
577
578 for (it = fVolToDigiIdMap.begin(); it != fVolToDigiIdMap.end(); ++it)
579 PrintVolume((*it).first[0], (*it).first[1]);
580
581 cout << "*********************************************" << endl;
582}
583
584// -------------------------------------------------------------------------
585
587 Int_t pMcCopyNumber,
588 Int_t pMotherCopyNumber,
589 Int_t pMotherMotherCopyNumber,
590 Int_t& pGroupId,
591 Int_t& pChanId,
592 Int_t& pModId)
593{
594 Int_t content[] = {pMotherMotherCopyNumber, pMotherCopyNumber, pMcVolumeNumber, pMcCopyNumber};
595 BmnZdcVolId_t pVolId(content, content + sizeof(content) / sizeof(Int_t));
596 BmnZdcDigiId_t digiID = GetDigiId(&pVolId);
597 pGroupId = digiID[0];
598 pModId = digiID[1];
599 pChanId = digiID[2];
600
601 return kTRUE;
602}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
R__EXTERN TGeoManager * gGeoManager
@ kZDC
BmnZdcDigiPar * fZdcDigiPar
Bool_t CreateVolCopyElements(BmnZdcVolId_t *left, BmnZdcDigiId_t *right)
static Int_t fRefcount
BmnZdcVolInfo_t * GetVolInfo(BmnZdcVolId_t *pVolId)
Bool_t GetVolCenterXYZ(BmnZdcDigiId_t *pDigiId, Double_t &x, Double_t &y, Double_t &z)
Bool_t AddNodes(TObjArray *sensNodes, Int_t pVerbose=0)
Bool_t Init(BmnZdcGeoPar *geoPar, BmnZdcDigiPar *digiPar, Int_t pVerbose=0)
void PrintVolume(Int_t volID, Int_t copyNoMotherMother=1)
void SplitDigiID(BmnZdcDigiId_t digiID, Int_t &module_groupID, Int_t &modID, Int_t &chanID)
static BmnZdcDigiScheme * fInstance
BmnZdcDigiId_t GetDigiId(BmnZdcVolId_t *pVolId)
std::map< BmnZdcDigiId_t, BmnZdcVolInfo_t * > fDigiToVolInfoMap
correspondence for all active volumes (Zdc+ZdcPsd)
Bool_t CreateVolInfoCopyElements(BmnZdcDigiId_t *right, BmnZdcVolInfo_t *volInfo)
Bool_t CalcDimensions(Int_t pGlobalDetectorNumber, Int_t &nx, Int_t &ny, Int_t &nz)
Bool_t GetVolDxDyDz(BmnZdcDigiId_t *pDigiId, Double_t &Dx, Double_t &Dy, Double_t &Dz)
BmnZdcDigiId_t GetDigiIdFromVolumeData(Int_t pMcVolumeNumber, Int_t pMotherMotherCopyNumber)
BmnZdcDigiId_t GetDigiIdFromCoords(Double_t x, Double_t y, Double_t z)
Bool_t IsVolumeExist(BmnZdcVolId_t *pVolId)
Int_t GetChannelID(BmnZdcVolId_t *pVolId)
BmnZdcVolInfo_t * CreateVolInfoElement(FairGeoNode *nod, Int_t pVerbose)
Int_t GetGroupID(BmnZdcVolId_t *pVolId)
Bool_t GetGroupIdModIdChanId(Int_t pMcVolumeNumber, Int_t pMcCopyNumber, Int_t pMotherCopyNumber, Int_t pMotherMotherCopyNumber, Int_t &pGroupId, Int_t &pChanId, Int_t &pModId)
void GetZdcDimensions(Int_t &nx, Int_t &ny, Int_t &nz)
TObjArray * fPasNodes
std::map< BmnZdcVolId_t, BmnZdcDigiId_t > fVolToDigiIdMap
static Bool_t fInitialized
Int_t Nx
correspondence for active volumes
BmnZdcVolId_t * CreateVolElement(FairGeoNode *nod, Int_t nodeNumber, BmnZdcDigiId_t *right, Int_t pVerbose)
static BmnZdcDigiScheme * Instance()
TObjArray * GetGeoPassiveNodes()
TObjArray * GetGeoSensitiveNodes()
virtual Double_t GetDX() const
virtual Double_t GetDZ() const
virtual Double_t GetDY() const
TGeoVolume * GetVolume() const
Int_t GetNumber() const
Int_t GetNumber() const
Int_t Atoi() const
Ssiz_t Last(char c) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
std::vector< Double_t > BmnZdcVolInfo_t
std::vector< Int_t > BmnZdcVolId_t
std::vector< Int_t > BmnZdcDigiId_t