CbmRoot
Loading...
Searching...
No Matches
CbmMuchGeoScheme.cxx
Go to the documentation of this file.
1/* Copyright (C) 2008-2021 St. Petersburg Polytechnic University, St. Petersburg
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Vikas Singhal, Mikhail Ryzhinskiy [committer], Florian Uhlig, Evgeny Kryshen */
4// -------------------------------------------------------------------------
5// ----- CbmMuchGeoScheme source file -----
6//------ Modilfied 21/06/2019 by Ekata Nandy(Detector type for GEM & RPC included) -----
7//------ Modilfied 18/10/2017 by Omveer Singh -----
8// ----- Created 18/02/08 by E. Kryshen
9// -------------------------------------------------------------------------
10#include "CbmMuchGeoScheme.h"
11
12#include "CbmMuchAddress.h" // for CbmMuchAddress
13#include "CbmMuchLayer.h" // for CbmMuchLayer
14#include "CbmMuchLayerSide.h" // for CbmMuchLayerSide
15#include "CbmMuchModule.h" // for CbmMuchModule
16#include "CbmMuchModuleGem.h" // for CbmMuchModuleGem
17#include "CbmMuchModuleGemRadial.h" // for CbmMuchModuleGemRadial
18#include "CbmMuchStation.h" // for CbmMuchStation
19
20#include <Logger.h> // for LOG
21
22#include <TArrayD.h> // for TArrayD
23#include <TArrayI.h> // for TArrayI
24#include <TClonesArray.h> // for TClonesArray
25#include <TFile.h> // for TFile, gFile
26#include <TGeoArb8.h> // for TGeoTrap
27#include <TGeoBBox.h> // for TGeoBBox
28#include <TGeoManager.h> // for TGeoManager, gGeoManager
29#include <TGeoNode.h> // for TGeoNode
30#include <TGeoVolume.h> // for TGeoVolume
31#include <TMath.h> // for Cos, Sqrt
32#include <TObjArray.h> // for TObjArray
33#include <TObject.h> // for TObject
34#include <TVector3.h> // for TVector3
35
36#include <cassert> // for assert
37#include <stdexcept> // for out_of_range
38#include <utility> // for pair
39#include <vector>
40
41#include <math.h> // for sqrt
42
43using std::vector;
44
46Bool_t CbmMuchGeoScheme::fInitialized = kFALSE;
48
49// -------------------------------------------------------------------------
51 : TObject()
52 , fGeoPathHash(0)
53 , fCurrentVolume(nullptr)
54 , fVolumeBoxShape(nullptr)
55 , fVolumeTrapShape(nullptr)
56 , fGlobal()
57 , fGlobalTrap()
58 , fGlobalMatrix(nullptr)
59 , fStation(0)
60 , fLayer(0)
61 , fActive(0)
62 , fGeoID(0)
63 ,
64 //fIsSimulation(kFALSE),
65 fModules()
66 , fSides()
67 , fMapSides()
68 , fStations(nullptr)
69 , fAbsorbers(new TObjArray())
70 , fMuchCave(nullptr)
71 , fMuchZ1(0.)
72 , fAcceptanceTanMin(0.)
73 , fAcceptanceTanMax(0.)
74 , fNabs(0)
75 , fNst(0)
76 , fActiveLx(0.)
77 , fActiveLy(0.)
78 , fActiveLz(0.)
79 , fSpacerLx(0.)
80 , fSpacerLy(0.)
81 , fOverlapY(0.)
82 , fStrawLz(0.)
83 , fNSectorsPerLayer(0)
84 , fActiveLzSector(0.)
85 , fSpacerR(0.)
86 , fSpacerPhi(0)
87 , fOverlapR(0.)
88 , fAbsorberZ1(0)
89 , fAbsorberLz(0)
90 , fAbsorberMat(0)
91 , fStationZ0(0)
92 , fNlayers(0)
93 , fDetType(0)
94 , fLayersDz(0)
95 , fSupportLz(0)
96 , fModuleDesign(0)
97 , muchSt(nullptr)
98 , muchLy(nullptr)
99 , muchLySd(nullptr)
100 , Rmin(-1.)
101 , Rmax(-1.)
102 , Dx2(-1.)
103{
104 LOG(debug) << "CbmMuchGeoScheme created";
105}
106// -------------------------------------------------------------------------
107
108// -------------------------------------------------------------------------
110{
111
112 if (fInstance != nullptr) delete fInstance;
113}
114// -------------------------------------------------------------------------
115
116
117// -------------------------------------------------------------------------
124// -------------------------------------------------------------------------
125
126// -------------------------------------------------------------------------
127void CbmMuchGeoScheme::Init(TObjArray* stations, Int_t flag)
128{
129
130 if (!fInitialized) {
131 fStations = stations;
132 //LOG(info) <<" enter ini loop check"<<fStations->GetEntriesFast()<<" "<<stations->GetEntriesFast();
133 fGeoID = flag;
134 fInitialized = kTRUE;
135 }
136 LOG(debug) << "CbmMuchGeoScheme init successful";
137 InitModules();
138}
139// -------------------------------------------------------------------------
140
141
142// -------------------------------------------------------------------------
143void CbmMuchGeoScheme::Init(TString digiFileName, Int_t flag)
144{
145
147 TFile* oldFile = gFile;
148 TDirectory* oldDir = gDirectory;
149
150 TFile* file = new TFile(digiFileName);
151 LOG_IF(fatal, !file) << "File " << digiFileName << " does not exist";
152 TObjArray* stations = file->Get<TObjArray>("stations");
153 LOG_IF(fatal, !stations) << "No TObjArray stations found in file " << digiFileName;
154 file->Close();
155 file->Delete();
156
158 gFile = oldFile;
159 gDirectory = oldDir;
160
161 Init(stations, flag);
162}
163// -------------------------------------------------------------------------
164
165
166// -------------------------------------------------------------------------
168{
169
170 if (!fModulesInitialized) {
171
172
173 if (!fStations) Fatal("InitModules", "No input array of stations.");
174 Int_t incSides = 0;
175 fMapSides.clear();
176 fSides.clear();
177 fModules.clear();
178
179 //LOG(info) <<"Total No. of Stations "<<" "<<GetNStations()<<" absorbers "<<GetNAbsorbers();
180 for (Int_t iStation = 0; iStation < GetNStations(); iStation++) {
181
182 const CbmMuchStation* station = GetStation(iStation);
183 if (!station) continue;
184
185 assert(iStation == CbmMuchAddress::GetStationIndex(station->GetDetectorId()));
186 vector<CbmMuchLayerSide*> sides;
187 vector<CbmMuchModule*> modules;
188
189 for (Int_t iLayer = 0; iLayer < station->GetNLayers(); iLayer++) {
190 CbmMuchLayer* layer = station->GetLayer(iLayer);
191 if (!layer) continue;
192
193 assert(iLayer == CbmMuchAddress::GetLayerIndex(layer->GetDetectorId()));
194 for (Int_t iSide = 0; iSide < 2; iSide++) {
195 CbmMuchLayerSide* side = (CbmMuchLayerSide*) layer->GetSide(iSide);
196 if (!side) continue;
197 assert(iSide == CbmMuchAddress::GetLayerSideIndex(side->GetDetectorId()));
198 if (side->GetNModules() != 0) fMapSides[side->GetDetectorId()] = incSides++;
199 sides.push_back(side);
200
201 for (Int_t iModule = 0; iModule < side->GetNModules(); iModule++) {
202 CbmMuchModule* mod = side->GetModule(iModule);
203 if (!mod) continue;
204
205 assert(iModule == CbmMuchAddress::GetModuleIndex(mod->GetDetectorId()));
206 assert(iStation == CbmMuchAddress::GetStationIndex(mod->GetDetectorId()));
207 if (!mod->InitModule()) continue;
208 modules.push_back(mod);
209 } // Modules
210 } // Sides
211 } // Layers
212 fSides.push_back(sides);
213 fModules.push_back(modules);
214 } // Stations
215
216 fModulesInitialized = kTRUE;
217 }
218}
219// -------------------------------------------------------------------------
220
221// -------------------------------------------------------------------------
223{
224
225 if (!fStations) return nullptr;
226 Bool_t result = (iStation >= 0) || (iStation < fStations->GetEntriesFast());
227
228 return result ? (CbmMuchStation*) fStations->At(iStation) : nullptr;
229}
230// -------------------------------------------------------------------------
231
232
233// -------------------------------------------------------------------------
234CbmMuchLayer* CbmMuchGeoScheme::GetLayer(Int_t iStation, Int_t iLayer) const
235{
236
237 CbmMuchStation* station = GetStation(iStation);
238 return station ? station->GetLayer(iLayer) : nullptr;
239}
240// -------------------------------------------------------------------------
241
242// -------------------------------------------------------------------------
243CbmMuchLayerSide* CbmMuchGeoScheme::GetLayerSide(Int_t iStation, Int_t iLayer, Bool_t iSide) const
244{
245
246 CbmMuchLayer* layer = GetLayer(iStation, iLayer);
247 return layer ? layer->GetSide(iSide) : nullptr;
248}
249// -------------------------------------------------------------------------
250
251// -------------------------------------------------------------------------
252CbmMuchModule* CbmMuchGeoScheme::GetModule(Int_t iStation, Int_t iLayer, Bool_t iSide, Int_t iModule) const
253{
254
255 CbmMuchLayerSide* side = GetLayerSide(iStation, iLayer, iSide);
256 return side ? side->GetModule(iModule) : nullptr;
257}
258// -------------------------------------------------------------------------
259
260// -------------------------------------------------------------------------
262{
263
264 Int_t iStation = CbmMuchAddress::GetStationIndex(detId);
265 assert(iStation < GetNStations());
266 return GetStation(iStation);
267}
268// -------------------------------------------------------------------------
269
270// -------------------------------------------------------------------------
272{
273
274 CbmMuchStation* station = GetStationByDetId(detId);
275 Int_t iLayer = CbmMuchAddress::GetLayerIndex(detId);
276 assert(iLayer < station->GetNLayers());
277 return station ? station->GetLayer(iLayer) : nullptr;
278}
279// -------------------------------------------------------------------------
280
281// -------------------------------------------------------------------------
283{
284
285 CbmMuchLayer* layer = GetLayerByDetId(detId);
286 Int_t iSide = CbmMuchAddress::GetLayerSideIndex(detId);
287 assert(iSide < 2);
288 return layer ? layer->GetSide(iSide) : nullptr;
289}
290// -------------------------------------------------------------------------
291
292// -------------------------------------------------------------------------
294{
295
297 Int_t iModule = CbmMuchAddress::GetModuleIndex(detId);
298 assert(iModule < side->GetNModules());
299 return side ? side->GetModule(iModule) : nullptr;
300}
301// -------------------------------------------------------------------------
302
303// -------------------------------------------------------------------------
305{
306
307 vector<CbmMuchModule*> modules = GetModules();
308 for (vector<CbmMuchModule*>::iterator it = modules.begin(); it != modules.end(); it++) {
309 CbmMuchModule* module = (*it);
310 module->SetPoints(new TClonesArray("CbmVisPoint", 1));
311 }
312}
313// -------------------------------------------------------------------------
314
315// -------------------------------------------------------------------------
317{
318
319 vector<CbmMuchModule*> modules = GetModules();
320 for (vector<CbmMuchModule*>::iterator it = modules.begin(); it != modules.end(); it++) {
321 CbmMuchModule* module = (*it);
322 if (module->GetDetectorType() == 1) {
323 CbmMuchModuleGem* mod = (CbmMuchModuleGem*) module;
324 mod->SetHits(new TClonesArray("CbmVisPixelHit", 1));
325 /*
326 } else if (module->GetDetectorType()==2) {
327 CbmMuchModuleStraws* mod = (CbmMuchModuleStraws*)module;
328 mod->SetHits(new TClonesArray("CbmVisStripHit",1));
329*/
330 }
331 }
332}
333// -------------------------------------------------------------------------
334
335// -------------------------------------------------------------------------
337{
338
339 vector<CbmMuchModule*> modules = GetModules();
340 for (vector<CbmMuchModule*>::iterator it = modules.begin(); it != modules.end(); it++) {
341 CbmMuchModule* module = (*it);
342 if (module->GetDetectorType() != 1) continue;
343 CbmMuchModuleGem* mod = (CbmMuchModuleGem*) module;
344 mod->SetClusters(new TClonesArray("CbmVisMuchCluster", 1));
345 }
346}
347// -------------------------------------------------------------------------
348
349// -------------------------------------------------------------------------
351{
352
353 vector<CbmMuchModule*> modules = GetModules();
354 for (vector<CbmMuchModule*>::iterator it = modules.begin(); it != modules.end(); it++) {
355 (*it)->GetPoints()->Clear();
356 }
357}
358// -------------------------------------------------------------------------
359
360
361// -------------------------------------------------------------------------
363{
364
365 vector<CbmMuchModule*> modules = GetModules();
366 for (vector<CbmMuchModule*>::iterator it = modules.begin(); it != modules.end(); it++) {
367 (*it)->GetHits()->Clear();
368 }
369}
370// -------------------------------------------------------------------------
371
372// -------------------------------------------------------------------------
374{
375
376 vector<CbmMuchModule*> modules = GetModules();
377 for (vector<CbmMuchModule*>::iterator it = modules.begin(); it != modules.end(); it++) {
378 CbmMuchModule* module = (*it);
379 if (module->GetDetectorType() != 1) continue;
380 CbmMuchModuleGem* mod = (CbmMuchModuleGem*) module;
381 mod->GetClusters()->Clear();
382 }
383}
384// -------------------------------------------------------------------------
385
386// -------------------------------------------------------------------------
387vector<CbmMuchLayerSide*> CbmMuchGeoScheme::GetLayerSides(Int_t iStation) const
388{
389
390 try {
391 return fSides.at(iStation);
392 }
393 catch (const std::out_of_range& exc) {
394 Fatal("GetLayerSides", "No input array of stations.");
395 }
396 return vector<CbmMuchLayerSide*>();
397}
398
399//Int_t CbmMuchGeoScheme::GetLayerSideNr(Int_t detId){
400// int i = 0;
401// Int_t sideId = GetLayerSideByDetId(detId)->GetDetectorId();
402// Int_t iStation = GetStationIndex(detId);
403// for(Int_t iSt=0; iSt<=iStation; iSt++){
404// vector<CbmMuchLayerSide*> sides = GetLayerSides(iSt);
405// for(Int_t iSide=0; iSide<sides.size(); iSide++){
406// i++;
407// }
408// }
409// printf("%i, %i\n",fMapSides[sideId] + 1, i);
410// assert(fMapSides[sideId] + 1 == i);
411// return i;
412//}
413
414Int_t CbmMuchGeoScheme::GetLayerSideNr(Int_t detId) const
415{
416 Int_t sideId = GetLayerSideByDetId(detId)->GetDetectorId();
417 if (fMapSides.find(sideId) == fMapSides.end())
418 Fatal("GetLayerSideNr", "Wrong side id or no modules in the layer side");
419 return fMapSides.find(sideId)->second + 1;
420}
421
422// -------------------------------------------------------------------------
423void CbmMuchGeoScheme::NavigateTo(const TString& path)
424{
425
426 gGeoManager->cd(path.Data());
427 // fGeoPathHash;
428 fGeoPathHash = path.Hash();
429 fCurrentVolume = gGeoManager->GetCurrentVolume();
430 fVolumeBoxShape = (TGeoBBox*) fCurrentVolume->GetShape();
431 Double_t local[3] = {0., 0., 0.};
432 gGeoManager->LocalToMaster(local, fGlobal);
433}
434
435//------------------------------------------------------
436Double_t CbmMuchGeoScheme::GetSizeX(const TString& path)
437{
438
439 if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
440 return fVolumeBoxShape->GetDX();
441}
442
443
444Double_t CbmMuchGeoScheme::GetSizeY(const TString& path)
445{
446
447 if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
448 return fVolumeBoxShape->GetDY();
449}
450
451
452Double_t CbmMuchGeoScheme::GetSizeZ(const TString& path)
453{
454 if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
455 return fVolumeBoxShape->GetDZ();
456}
457
458
459Double_t CbmMuchGeoScheme::GetZ(const TString& path)
460{
461
462 if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
463 return fGlobal[2];
464}
465
466
467Double_t CbmMuchGeoScheme::GetY(const TString& path)
468{
469
470 if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
471 return fGlobal[1];
472}
473
474
475Double_t CbmMuchGeoScheme::GetX(const TString& path)
476{
477
478 if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
479 return fGlobal[0];
480}
481//-----------------------------------------------------------------------------------------------------
482void CbmMuchGeoScheme::ExtractGeoParameter(TGeoNode* ncave, const char* volumeName)
483{
484
485 TObjArray* caveArr = ncave->GetNodes();
486
487 for (int iSystem = 0; iSystem < caveArr->GetEntriesFast(); iSystem++) {
488 TGeoNode* SystemNode = static_cast<TGeoNode*>(caveArr->At(iSystem));
489
490 if (!TString(SystemNode->GetName()).Contains(volumeName)) continue;
491 TObjArray* MuchObj = SystemNode->GetNodes();
492
493 for (Int_t iMuchObj = 0; iMuchObj < MuchObj->GetEntriesFast(); iMuchObj++) {
494
495 TGeoNode* MuchObjNode = static_cast<TGeoNode*>(MuchObj->At(iMuchObj));
496
497 // if (!TString(MuchObjNode->GetName()).Contains("Station")) continue;
498 if (!TString(MuchObjNode->GetName()).Contains("station")) continue;
499 TString MuchObjPath =
500 TString("/") + ncave->GetName() + "/" + SystemNode->GetName() + "/" + MuchObjNode->GetName();
501
502 StationNode(MuchObjNode, MuchObjPath); //StationNode
503 } //iMuchObj
504
505 } //iSystem
506} //SetParameters
507
508//---------------------------------------------------------------------------------------------
509void CbmMuchGeoScheme::StationNode(TGeoNode* fSNode, TString Path)
510{
511
512 TObjArray* stations = fSNode->GetNodes();
513 //fStations=stations; // by PPB 1/11/2017
514 fNst = stations->GetEntriesFast();
515 // LOG(info) <<"check stations "<<fNst;
516 fStationZ0.Set(fNst); // Station Zceneter [cm]
517 fNlayers.Set(fNst); // Number of layers
518 fDetType.Set(fNst); // Detector type
519 fLayersDz.Set(fNst); // Distance between layers [cm]
520 fSupportLz.Set(fNst); // Support thickness [cm]
521 fLayersDz.Set(fNst); //
522 fModuleDesign.Set(fNst); // Module design (0/1)
523 fNSectorsPerLayer.Set(fNst); // Number of sectors per layer in sector GEM geometry
524
525
526 for (Int_t iStation = 0; iStation < fNst; iStation++) {
527 TGeoNode* station = static_cast<TGeoNode*>(stations->At(iStation));
528 TString StationPath = Path + "/" + station->GetName();
529 TObjArray* layers = station->GetNodes();
530 fNlayers[iStation] = layers->GetEntriesFast();
531
532
533 // fDetType[iStation]=3;
534 // fLayersDz[iStation]=10.0;
535
536 //-----------------------------Layer1-------------------------------------------------------
537 TGeoNode* layer1 = static_cast<TGeoNode*>(layers->At(0)); //first layer position of station
538 TString Layer1Path = StationPath + "/" + layer1->GetName();
539 TObjArray* Supportlayer1 = layer1->GetNodes();
540 TGeoNode* Supportlayer1Node = static_cast<TGeoNode*>(Supportlayer1->At(0));
541
542 TString Supportlayer1Path = Layer1Path + "/" + Supportlayer1Node->GetName();
543 Double_t fLayer1Z0;
544 //if(Supportlayer2Path.Contains("mcbm")) fLayer2Z0=GetModuleZ(Supportlayer2Path);
545 if (fGeoID == 1) fLayer1Z0 = GetModuleZ(Supportlayer1Path);
546 else
547 fLayer1Z0 = GetZ(Supportlayer1Path);
548
549
550 //-----------------------------Layer2-------------------------------------------------------
551 TGeoNode* layer2 = static_cast<TGeoNode*>(layers->At(1)); //second layer position of station
552 TString Layer2Path = StationPath + "/" + layer2->GetName();
553
554 TObjArray* Supportlayer2 = layer2->GetNodes();
555 TGeoNode* Supportlayer2Node = static_cast<TGeoNode*>(Supportlayer2->At(0));
556
557 TString Supportlayer2Path = Layer2Path + "/" + Supportlayer2Node->GetName();
558
559 Double_t fLayer2Z0;
560 //if(Supportlayer2Path.Contains("mcbm")) fLayer2Z0=GetModuleZ(Supportlayer2Path);
561 if (fGeoID == 1) fLayer2Z0 = GetModuleZ(Supportlayer2Path);
562 else
563 fLayer2Z0 = GetZ(Supportlayer2Path);
564 //
565
566
567 fLayersDz[iStation] = fLayer2Z0 - fLayer1Z0;
568
569 //if(Supportlayer3Path.Contains("mcbm")) fSupportLz[iStation]=2.0*GetModuleDZ(Supportlayer3Path);
570 if (fGeoID == 1) fSupportLz[iStation] = 2.0 * GetModuleDZ(Supportlayer1Path);
571 else
572 fSupportLz[iStation] = 2.0 * GetSizeZ(Supportlayer1Path);
573 //LOG(info) <<fSupportLz[iStation]<<" "<<fLayersDz[iStation];
574
575
576 Double_t PosY = 0., Phi = 0., Dy = 0.;
577
578 if (fNlayers[iStation] == 3) {
579 //------------------------------Layer3-----------------------------------------------------------
580 TGeoNode* layer3 = static_cast<TGeoNode*>(layers->At(2));
581 TString Layer3Path = StationPath + "/" + layer3->GetName();
582
583 TObjArray* Supportlayer3 = layer3->GetNodes();
584 TGeoNode* Supportlayer3Node = static_cast<TGeoNode*>(Supportlayer3->At(0));
585 TString Supportlayer3Path = Layer3Path + "/" + Supportlayer3Node->GetName();
586
587 // Double_t fLayer3Z0;
588 //if(Supportlayer3Path.Contains("mcbm")) fLayer3Z0=GetModuleZ(Supportlayer3Path);
589 // if(fGeoID==1) fLayer3Z0=GetModuleZ(Supportlayer3Path);
590 // else fLayer3Z0 = GetZ(Supportlayer3Path);
591 TGeoNode* Activelayer3Node = static_cast<TGeoNode*>(Supportlayer3->At(1));
592 TString Activelayer3Path = Layer3Path + "/" + Activelayer3Node->GetName();
593
594 PosY = GetModuleY(Activelayer3Path);
595 // Double_t PosX=GetModuleX(Activelayer3Path);
596 Phi = GetModulePhi(Activelayer3Path);
597 Dy = GetModuleH1(Activelayer3Path);
598 fActiveLzSector = 2.0 * GetModuleDZ(Activelayer3Path);
599 fStationZ0[iStation] = fLayer2Z0;
600 }
601 else {
602 TGeoNode* Activelayer2Node = static_cast<TGeoNode*>(Supportlayer2->At(1));
603 TString Activelayer2Path = Layer2Path + "/" + Activelayer2Node->GetName();
604
605 PosY = GetModuleY(Activelayer2Path);
606 // Double_t PosX=GetModuleX(Activelayer3Path);
607 Phi = GetModulePhi(Activelayer2Path);
608 Dy = GetModuleH1(Activelayer2Path);
609 fActiveLzSector = 2.0 * GetModuleDZ(Activelayer2Path);
610 fStationZ0[iStation] = (fLayer2Z0 - fLayer1Z0) / 2.;
611 }
612
613
614 //chaned by PPB on 16.11.2017
615 //Double_t yMin = -(PosX/TMath::Sin(Phi))-Dy;
616 Double_t yMin = (PosY / TMath::Cos(Phi)) - Dy;
617 Double_t yMax = 2 * Dy + yMin;
618 LOG(info) << " Geo Scheme "
619 << " posY " << PosY << " phi " << Phi << " Dy " << Dy;
620 Rmax = yMax;
621 Rmin = yMin; //-2.0; // Spacer width[cm] = 2.0
622
623
624 muchSt = new CbmMuchStation(iStation, fStationZ0[iStation]);
627
628 if (Supportlayer1->GetEntriesFast() > 0) fModuleDesign[iStation] = 1;
630
631
632 LayerNode(station, iStation, StationPath);
633
634
635 muchLy = muchSt->GetLayer(0);
636 Double_t supDx = muchLy->GetSupportDx();
637 Double_t supDy = muchLy->GetSupportDy();
638 // Double_t supDz = muchLy->GetSupportDz();
640 muchSt->SetTubeRmax(TMath::Sqrt(supDx * supDx + supDy * supDy) + 10);
641 //LOG(info) <<" fill fStations array "<<iStation<<" z cent "<<fStationZ0[iStation];
642 fStations->Add(muchSt);
643
644 } //Station
645} //StationNode
646//---------------------------------------------------------------------------------------------------------
647
648void CbmMuchGeoScheme::LayerNode(TGeoNode* StNode, Int_t iStation, TString StPath)
649{
650
651 TObjArray* layerArray = StNode->GetNodes();
652 for (Int_t iLayer = 0; iLayer < layerArray->GetEntriesFast(); iLayer++) {
653 TGeoNode* layerNode = static_cast<TGeoNode*>(layerArray->At(iLayer));
654 TString layerPath = StPath + "/" + layerNode->GetName();
655
656 ModuleNode(layerNode, iStation, iLayer, layerPath);
657
658 //Set support shape
661 muchLy->SetSupportDz(fSupportLz[iStation] / 2.);
662
664
665 } //iLayer
666}
667//---------------------------------------------------------------------------------------------------------------------------------
668
669void CbmMuchGeoScheme::ModuleNode(TGeoNode* layerNode, Int_t iStation, Int_t iLayer, TString layerPath)
670{
671
672
673 TObjArray* moduleArray = layerNode->GetNodes();
674 for (Int_t iModule = 0; iModule < moduleArray->GetEntriesFast(); iModule++) {
675 TGeoNode* moduleNode = static_cast<TGeoNode*>(moduleArray->At(iModule));
676
677 TString modulePath = layerPath + "/" + moduleNode->GetName();
678
679 ActiveModuleNode(moduleNode, iStation, iLayer, iModule, modulePath);
680
681
682 } //iModule
683}
684
685//----------------------------------------------------------------------------------------------------------------------------------------------------------------
686
687void CbmMuchGeoScheme::ActiveModuleNode(TGeoNode* moduleNode, Int_t iStation, Int_t iLayer, Int_t /*iModule*/,
688 TString modulePath)
689{
690
691 TString modName = moduleNode->GetName();
692
693
694 if (modName.Contains("support")) {
695
696
697 Double_t layerGlobalZ0;
698 // if(modulePath.Contains("mcbm")) layerGlobalZ0=GetModuleZ(modulePath);
699 if (fGeoID == 1) layerGlobalZ0 = GetModuleZ(modulePath);
700 else
701 layerGlobalZ0 = GetZ(modulePath);
702
703 Double_t layerZ0 = (iLayer - (fNlayers[iStation] - 1) / 2.) * fLayersDz[iStation];
704 Double_t sideDz = fSupportLz[iStation] / 2. + fActiveLzSector / 2.;
705
706 muchLy = new CbmMuchLayer(iStation, iLayer, layerGlobalZ0, layerZ0); //CbmMuchLayer Class
707 muchLy->GetSideB()->SetZ(layerGlobalZ0 + sideDz);
708 muchLy->GetSideF()->SetZ(layerGlobalZ0 - sideDz);
709 }
710
711
712 if (modName.Contains("active")) {
713
714 gGeoManager->cd(modulePath.Data());
715 // TGeoNode* moduleNode = gGeoManager->GetMother(0);
716 moduleNode = gGeoManager->GetMother(0);
717 // Int_t nModule=moduleNode->GetNumber();
718
719 Bool_t iSide;
720 if (modName.Contains("factive")) iSide = 0;
721 if (modName.Contains("bactive")) iSide = 1;
722 TVector3 pos;
723 pos[0] = GetModuleX(modulePath);
724 pos[1] = GetModuleY(modulePath);
725 pos[2] = GetModuleZ(modulePath);
726 // LOG(info) <<" positions "<<pos[0]<<" "<<pos[1]<<" "<<pos[2];
727 Double_t Dz = GetModuleDZ(modulePath);
728 // Double_t Phi = GetModulePhi(modulePath);
729 Double_t Dy = GetModuleH1(modulePath);
730 Double_t Dx1 = GetModuleBl1(modulePath);
731 Dx2 = GetModuleTl1(modulePath);
732 //LOG(info) <<" positions "<<pos[0]<<" "<<pos[1]<<" "<<pos[2]<<" phi "<<Phi;
733
734 // Is this formula correct? Check Omveer (PPB 16.11.2017)
735 // Double_t yMin = (pos[1]/TMath::Cos(Phi))-Dy;
736 // Double_t yMax = 2*Dy + yMin;
737 // Double_t Rmin = yMin-2.0; // Spacer width[cm] = 2.0
738 // Why is R0 required?
739 // Double_t R0 = yMax-Dy;
740 // Double_t Rmax = yMax;
741
742
743 Int_t DetType = -1;
744 if (modName.Contains("gasArgon")) DetType = 3; // Detector type 3 for GEM
745 if (modName.Contains("rpcgas")) DetType = 4; // Detector type 4 for RPC
746 // LOG(info) <<" detector type "<<DetType;
747
748 muchLySd = muchLy->GetSide(iSide);
750 new CbmMuchModuleGemRadial(DetType, iStation, iLayer, iSide, muchLySd->GetNModules(), pos, Dx1, Dx2, Dy, Dz,
751 Rmin)); // Detector type variable added in the class constructor on 03-07-2019
752
753
754 } //activeLayer
755
756
757} //ActiveModuleNode
758//----------------------------------------------------------------------------------------------------------
759void CbmMuchGeoScheme::NavigateModule(const TString& path)
760{
761 gGeoManager->cd(path.Data());
762 // fGeoPathHash;
763 fGeoPathHash = path.Hash();
764 fCurrentVolume = gGeoManager->GetCurrentVolume();
765 fVolumeTrapShape = (TGeoTrap*) fCurrentVolume->GetShape();
766 Double_t local[3] = {0., 0., 0.};
767 gGeoManager->LocalToMaster(local, fGlobalTrap);
768
769} //NavigateModule
770
771//----------------------------------------------------------------------------------------------------------
772
773Double_t CbmMuchGeoScheme::GetModuleDZ(const TString& path)
774{
775
776 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
777 return fVolumeTrapShape->GetDZ();
778}
779
780
781Double_t CbmMuchGeoScheme::GetModuleZ(const TString& path)
782{
783
784 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
785 return fGlobalTrap[2];
786}
787
788
789Double_t CbmMuchGeoScheme::GetModuleY(const TString& path)
790{
791
792 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
793 return fGlobalTrap[1];
794}
795
796
797Double_t CbmMuchGeoScheme::GetModuleX(const TString& path)
798{
799
800 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
801 return fGlobalTrap[0];
802}
803
804Double_t CbmMuchGeoScheme::GetModulePhi(const TString& path)
805{
806
807 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
808 return fVolumeTrapShape->GetPhi();
809}
810
811Double_t CbmMuchGeoScheme::GetModuleH1(const TString& path)
812{
813
814 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
815 return fVolumeTrapShape->GetH1();
816}
817
818Double_t CbmMuchGeoScheme::GetModuleBl1(const TString& path)
819{
820
821 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
822 return fVolumeTrapShape->GetBl1();
823}
824
825Double_t CbmMuchGeoScheme::GetModuleTl1(const TString& path)
826{
827
828 if (fGeoPathHash != path.Hash()) { NavigateModule(path); }
829 return fVolumeTrapShape->GetTl1();
830}
831
832// -------------------------------------------------------------------------
833Int_t CbmMuchGeoScheme::Intersect(Float_t x, Float_t y, Float_t dx, Float_t dy, Float_t r)
834{
835
836 Float_t x1 = x - dx;
837 Float_t x2 = x + dx;
838 Float_t y1 = y - dy;
839 Float_t y2 = y + dy;
840 Int_t nCornersInside = 0;
841 if (x1 * x1 + y1 * y1 < r * r) nCornersInside++;
842 if (x2 * x2 + y1 * y1 < r * r) nCornersInside++;
843 if (x1 * x1 + y2 * y2 < r * r) nCornersInside++;
844 if (x2 * x2 + y2 * y2 < r * r) nCornersInside++;
845 if (nCornersInside == 4) return 2;
846 if (nCornersInside) return 1;
847 if (!nCornersInside && x1 < r && y1 < 0 && y2 > 0) return 1;
848 return 0;
849}
850// -------------------------------------------------------------------------
851
852// -------------------------------------------------------------------------
853vector<CbmMuchModule*> CbmMuchGeoScheme::GetModules() const
854{
855
856 vector<CbmMuchModule*> modules;
857 for (Int_t iStation = 0; iStation < GetNStations(); ++iStation) {
858 vector<CbmMuchModule*> stationModules = GetModules(iStation);
859 for (vector<CbmMuchModule*>::iterator it = stationModules.begin(); it != stationModules.end(); it++) {
860 CbmMuchModule* module = (*it);
861 modules.push_back(module);
862 assert(CbmMuchAddress::GetStationIndex(module->GetDetectorId()) == iStation);
863 }
864 }
865 return modules;
866}
867// -------------------------------------------------------------------------
868
869
870// -------------------------------------------------------------------------
871vector<CbmMuchModuleGem*> CbmMuchGeoScheme::GetGemModules() const
872{
873
874 vector<CbmMuchModuleGem*> modules;
875 for (Int_t iStation = 0; iStation < GetNStations(); ++iStation) {
876 vector<CbmMuchModule*> stationModules = GetModules(iStation);
877 for (vector<CbmMuchModule*>::iterator it = stationModules.begin(); it != stationModules.end(); it++) {
878 CbmMuchModule* module = (*it);
879 if (module->GetDetectorType() != 3 && module->GetDetectorType() != 4) continue; //Detector type 3:GEM, 4:RPC
880 modules.push_back((CbmMuchModuleGem*) module);
881 assert(CbmMuchAddress::GetStationIndex(module->GetDetectorId()) == iStation);
882 }
883 }
884 return modules;
885}
886// -------------------------------------------------------------------------
887
888
889// -------------------------------------------------------------------------
890vector<CbmMuchModule*> CbmMuchGeoScheme::GetModules(Int_t iStation) const
891{
892
893 try {
894 return fModules.at(iStation);
895 }
896 catch (const std::out_of_range& exc) {
897 Fatal("GetModules", "No input array of stations.");
898 }
899 return vector<CbmMuchModule*>();
900}
901// -------------------------------------------------------------------------
902
ClassImp(CbmConverterManager)
friend fvec sqrt(const fvec &a)
static int32_t GetModuleIndex(int32_t address)
static int32_t GetLayerIndex(int32_t address)
static int32_t GetLayerSideIndex(int32_t address)
static int32_t GetStationIndex(int32_t address)
Int_t GetLayerSideNr(Int_t detId) const
std::vector< CbmMuchLayerSide * > GetLayerSides(Int_t iStation) const
std::vector< CbmMuchModuleGem * > GetGemModules() const
Double_t GetModuleY(const TString &path)
void ExtractGeoParameter(TGeoNode *muchNode, const char *volumeName)
CbmMuchLayer * GetLayerByDetId(Int_t detId) const
Double_t GetZ(const TString &path)
std::map< Int_t, Int_t > fMapSides
Double_t fGlobalTrap[3]
Double_t GetModuleBl1(const TString &path)
Double_t GetModuleH1(const TString &path)
std::vector< std::vector< CbmMuchModule * > > fModules
void StationNode(TGeoNode *MuchObjNode, TString MuchObjPath)
CbmMuchStation * GetStationByDetId(Int_t detId) const
std::vector< std::vector< CbmMuchLayerSide * > > fSides
void ActiveModuleNode(TGeoNode *moduleNode, Int_t iStation, Int_t iLayer, Int_t iModule, TString modulePath)
Double_t GetSizeY(const TString &path)
Double_t GetModuleTl1(const TString &path)
CbmMuchStation * GetStation(Int_t iStation) const
std::vector< CbmMuchModule * > GetModules() const
static CbmMuchGeoScheme * Instance()
void Init(TObjArray *stations, Int_t flag)
static CbmMuchGeoScheme * fInstance
TGeoVolume * fCurrentVolume
void NavigateModule(const TString &path)
Double_t GetY(const TString &path)
Double_t GetModulePhi(const TString &path)
void ModuleNode(TGeoNode *layerNode, Int_t iStation, Int_t iLayer, TString layerPath)
static Bool_t fModulesInitialized
CbmMuchLayerSide * GetLayerSideByDetId(Int_t detId) const
CbmMuchLayerSide * GetLayerSide(Int_t iStation, Int_t iLayer, Bool_t iSide) const
CbmMuchLayer * GetLayer(Int_t iStation, Int_t iLayer) const
Double_t GetModuleX(const TString &path)
Double_t GetSizeX(const TString &path)
CbmMuchStation * muchSt
Int_t GetNStations() const
CbmMuchLayer * muchLy
void NavigateTo(const TString &path)
CbmMuchLayerSide * muchLySd
Double_t GetModuleDZ(const TString &path)
static Bool_t fInitialized
Double_t GetX(const TString &path)
Int_t fGeoID
ModuleCopyID with module type.
CbmMuchModule * GetModuleByDetId(Int_t detId) const
Double_t GetSizeZ(const TString &path)
CbmMuchModule * GetModule(Int_t iStation, Int_t iLayer, Bool_t iSide, Int_t iModule) const
TGeoBBox * fVolumeBoxShape
void LayerNode(TGeoNode *StNode, Int_t iStation, TString StPath)
Double_t GetModuleZ(const TString &path)
TGeoTrap * fVolumeTrapShape
Int_t Intersect(Float_t x, Float_t y, Float_t dx, Float_t dy, Float_t r)
Int_t GetNModules() const
void AddModule(CbmMuchModule *module)
CbmMuchModule * GetModule(Int_t iModule) const
void SetZ(Double_t z)
Int_t GetDetectorId() const
Double_t GetSupportDx() const
void SetSupportDx(Double_t supDx)
CbmMuchLayerSide * GetSide(Bool_t side)
CbmMuchLayerSide * GetSideF()
CbmMuchLayerSide * GetSideB()
Double_t GetSupportDy() const
Int_t GetDetectorId() const
void SetSupportDy(Double_t supDy)
void SetSupportDz(Double_t supDz)
Int_t GetDetectorId() const
void SetClusters(TClonesArray *clusters)
void SetHits(TClonesArray *hits)
virtual Bool_t InitModule()
TClonesArray * GetClusters() const
Int_t GetDetectorType() const
void SetRmin(Double_t rMin)
Double_t GetRmin() const
CbmMuchLayer * GetLayer(Int_t iLayer) const
void SetTubeRmin(Double_t rMin)
void AddLayer(CbmMuchLayer *layer)
void SetTubeRmax(Double_t rMax)
void SetModuleDesign(Bool_t on)
void SetRmax(Double_t rMax)
Int_t GetNLayers() const
Int_t GetDetectorId() const