CbmRoot
Loading...
Searching...
No Matches
CbmLitTrackingGeometryConstructor.cxx
Go to the documentation of this file.
1/* Copyright (C) 2008-2020 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
12
13#include "CbmHistManager.h"
14#include "CbmUtils.h"
15#include "FairRunAna.h"
16#include "FairRuntimeDb.h"
17#include "TDirectory.h"
18#include "TFile.h"
19#include "TGeoArb8.h"
20#include "TGeoBBox.h"
21#include "TGeoCone.h"
22#include "TGeoManager.h"
23#include "TGeoMatrix.h"
24#include "TGeoMedium.h"
25#include "TGeoPgon.h"
26#include "TGeoShape.h"
27#include "TGeoSphere.h"
28#include "TGeoVolume.h"
29#include "TProfile2D.h"
30#include "TRegexp.h"
32
33#include <algorithm>
34#include <iostream>
35#include <limits>
36#include <map>
37#include <set>
38#include <sstream>
39
40using std::cout;
41using std::map;
42using std::set;
43
45 : fGeo(NULL)
46 , fNofTrdStations(-1)
47 , fNofMuchStations(-1)
48 , fNofMvdStations(-1)
49 , fNofStsStations(-1)
50 , fDet()
51{
52 fGeo = gGeoManager;
54}
55
57
63
68
73
74template<class T>
76{
77 cout << "Getting MUCH layout for parallel version of tracking...\n";
78
79 // Read file with TProfile2D containing silicon equivalent of the material
80 TString parDir = TString(gSystem->Getenv("VMCWORKDIR")) + TString("/parameters");
81 TString matBudgetFile = parDir + "/littrack/much_v12b.silicon.root";
82 TFile* oldFile = gFile;
83 TDirectory* oldDirectory = gDirectory;
84 TFile* file = new TFile(matBudgetFile, "READ");
86 hm.ReadFromFile(file);
87
88 CbmLitFieldGridCreator gridCreator;
89
90 TGeoNode* much = nullptr;
91 TObjArray* nodes = gGeoManager->GetTopVolume()->GetNodes();
92 for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
93 TGeoNode* node = (TGeoNode*) nodes->At(iNode);
94 if (TString(node->GetName()).Contains("much", TString::kIgnoreCase)) { // Top MUCH node
95 much = node;
96 break;
97 }
98 }
99 assert(much);
100 TObjArray* muchNodes = much->GetNodes();
101 Int_t currentStation = 0;
102 Int_t currentLayer = 0;
103 for (Int_t iMuchNode = 0; iMuchNode < muchNodes->GetEntriesFast(); iMuchNode++) {
104 const TGeoNode* muchNode = static_cast<const TGeoNode*>(muchNodes->At(iMuchNode));
105
106 if (TString(muchNode->GetName()).Contains("station")) {
107 TObjArray* layerNodes = muchNode->GetNodes();
108
109 for (Int_t iLayerNode = 0; iLayerNode < layerNodes->GetEntriesFast(); iLayerNode++) {
110 const TGeoNode* layer = static_cast<const TGeoNode*>(layerNodes->At(iLayerNode));
111
112 Double_t z = much->GetMatrix()->GetTranslation()[2] + muchNode->GetMatrix()->GetTranslation()[2]
113 + layer->GetMatrix()->GetTranslation()[2];
114
115 // Convert material for this station
116 TProfile2D* profile =
117 (iLayerNode == 0) ? hm.P2("hrl_ThicknessSilicon_MuchAbsorber_" + Cbm::ToString<Int_t>(currentStation) + "_P2")
118 : hm.P2("hrl_ThicknessSilicon_Much_" + Cbm::ToString<Int_t>(currentLayer) + "_P2");
119 //profile->Rebin2D(200, 200);
121 ConvertTProfile2DToLitMaterialGrid(profile, &material);
122
124 vs.SetMaterial(material);
125
127 station.AddVirtualStation(vs);
128
129 layout.AddStation(station);
130
131
132 currentLayer++;
133 }
134 currentStation++;
135 }
136 }
137
138 gFile = oldFile;
139 gDirectory = oldDirectory;
140 file->Close();
141 delete file;
142
143 cout << layout;
144 cout << "Finish getting MUCH layout for parallel version of tracking\n";
145}
146
151
156
157template<class T>
159{
160 cout << "Getting TRD layout for parallel version of tracking...\n";
161
162 // Read file with TProfile2D containing silicon equivalent of the material
163 TString parDir = TString(gSystem->Getenv("VMCWORKDIR")) + TString("/parameters");
164 TString matBudgetFile = parDir + "/littrack/trd_v13p_3e.silicon.root";
165 TFile* oldFile = gFile;
166 TDirectory* oldDirectory = gDirectory;
167 TFile* file = new TFile(matBudgetFile, "READ");
169 hm.ReadFromFile(file);
170
171 CbmLitFieldGridCreator gridCreator;
172
173 Double_t startZPosition = 100.; // Last STS station
174 // Double_t detectorZPosition = 400.; // We want to extrapolate up to here using virtual stations
175 Double_t dZ = 10.; // Distance between neighboring virtual stations
176
178 GetRichMaterial(&richMaterial);
179
180 // Virtual stations
181 Int_t nofVirtualStations = 31;
182 for (Int_t iStation = 0; iStation < nofVirtualStations; iStation++) {
183 Double_t z = startZPosition + iStation * dZ;
185 gridCreator.CreateGrid(z, fieldGrid);
186
188 station.SetZ(z);
189 station.SetField(fieldGrid);
190 if (iStation == 10) station.SetMaterial(richMaterial);
191
192 layout.AddVirtualStation(station);
193 }
194
195 // Stations
196 Int_t nofStations = GetNofTrdStations();
197 for (Int_t iStation = 0; iStation < nofStations; iStation++) {
198 // Convert material for this station
199 TProfile2D* profile = hm.P2("hrl_ThicknessSilicon_Trd_" + Cbm::ToString<Int_t>(iStation) + "_P2");
200 //profile->Rebin2D(200, 200);
202 ConvertTProfile2DToLitMaterialGrid(profile, &material);
203
205 vs.SetMaterial(material);
206
208 station.AddVirtualStation(vs);
209
210 layout.AddStation(station);
211 }
212
213 gFile = oldFile;
214 gDirectory = oldDirectory;
215 file->Close();
216 delete file;
217
218 cout << layout;
219 cout << "Finish getting TRD layout for parallel version of tracking\n";
220}
221
223{
224 if (!fDet.GetDet(ECbmModuleId::kRich)) return;
225 // Read file with TProfile2D containing silicon equivalent of the material
226 TString parDir = TString(gSystem->Getenv("VMCWORKDIR")) + TString("/parameters");
227 TString matBudgetFile = parDir + "/littrack/rich_v08a.silicon.root";
228 TFile* oldFile = gFile;
229 TDirectory* oldDirectory = gDirectory;
230 TFile* file = new TFile(matBudgetFile, "READ");
232 hm.ReadFromFile(file);
233
234 TProfile2D* profile = hm.P2("hrl_ThicknessSilicon_Rich_P2");
235 // profile->Rebin2D(200, 200);
236 ConvertTProfile2DToLitMaterialGrid(profile, material, 3.);
237
238 gFile = oldFile;
239 gDirectory = oldDirectory;
240 file->Close();
241 delete file;
242}
243
246 Double_t maximumValue)
247{
248 // Int_t nofBinsX = profile->GetNbinsX();
249 // Int_t nofBinsY = profile->GetNbinsY();
250 // vector<vector<fscal> >material(nofBinsX);
251 // for (Int_t i = 0; i < nofBinsX; i++) material[i].resize(nofBinsY);
252 // for (Int_t iX = 1; iX <= nofBinsX; iX++) {
253 // for (Int_t iY = 1; iY <= nofBinsY; iY++) {
254 // Double_t content = profile->GetBinContent(iX, iY);
255 // if (maximumValue > 0 && content > maximumValue) content = maximumValue;
256 // material[iX - 1][iY - 1] = content;
257 // }
258 // }
259 // Double_t xmin = profile->GetXaxis()->GetXmin();
260 // Double_t xmax = profile->GetXaxis()->GetXmax();
261 // Double_t ymin = profile->GetYaxis()->GetXmin();
262 // Double_t ymax = profile->GetYaxis()->GetXmax();
263 // grid->SetMaterial(material, xmin, xmax, ymin, ymax, nofBinsX, nofBinsY);
264
265 Int_t nofBinsX = profile->GetNbinsX();
266 Int_t nofBinsY = profile->GetNbinsY();
267 Int_t minShrinkBinX = std::numeric_limits<Double_t>::max();
268 Int_t maxShrinkBinX = std::numeric_limits<Double_t>::min();
269 Int_t minShrinkBinY = std::numeric_limits<Double_t>::max();
270 Int_t maxShrinkBinY = std::numeric_limits<Double_t>::min();
271 Bool_t isSet = false;
272 for (Int_t iBinX = 1; iBinX <= nofBinsX; iBinX++) {
273 for (Int_t iBinY = 1; iBinY <= nofBinsY; iBinY++) {
274 Double_t content = profile->GetBinContent(iBinX, iBinY);
275 if (content != 0.) {
276 minShrinkBinX = std::min(iBinX, minShrinkBinX);
277 maxShrinkBinX = std::max(iBinX, maxShrinkBinX);
278 minShrinkBinY = std::min(iBinY, minShrinkBinY);
279 maxShrinkBinY = std::max(iBinY, maxShrinkBinY);
280 isSet = true;
281 }
282 }
283 }
284
285 Int_t nofShrinkBinsX = maxShrinkBinX - minShrinkBinX + 1;
286 Int_t nofShrinkBinsY = maxShrinkBinY - minShrinkBinY + 1;
287 vector<vector<fscal>> material(nofShrinkBinsX);
288 for (Int_t i = 0; i < nofShrinkBinsX; i++)
289 material[i].resize(nofShrinkBinsY);
290
291 for (Int_t iX = minShrinkBinX; iX <= maxShrinkBinX; iX++) {
292 for (Int_t iY = minShrinkBinY; iY <= maxShrinkBinY; iY++) {
293 Double_t content = profile->GetBinContent(iX, iY);
294 if (maximumValue > 0 && content > maximumValue) content = maximumValue;
295 material[iX - minShrinkBinX][iY - minShrinkBinY] = content;
296 }
297 }
298 Double_t xmin = profile->GetXaxis()->GetBinLowEdge(minShrinkBinX);
299 Double_t xmax = profile->GetXaxis()->GetBinUpEdge(maxShrinkBinX);
300 Double_t ymin = profile->GetYaxis()->GetBinLowEdge(minShrinkBinY);
301 Double_t ymax = profile->GetYaxis()->GetBinUpEdge(maxShrinkBinY);
302 grid->SetMaterial(material, xmin, xmax, ymin, ymax, nofShrinkBinsX, nofShrinkBinsY);
303}
304
306{
307 static Bool_t firstTime = true;
308 if (firstTime) {
309 Int_t layerCounter = 0;
310 TObjArray* topNodes = fGeo->GetTopNode()->GetNodes();
311 for (Int_t iTopNode = 0; iTopNode < topNodes->GetEntriesFast(); iTopNode++) {
312 TGeoNode* topNode = static_cast<TGeoNode*>(topNodes->At(iTopNode));
313 if (TString(topNode->GetName()).Contains("trd")) {
314 TObjArray* layers = topNode->GetNodes();
315 for (Int_t iLayer = 0; iLayer < layers->GetEntriesFast(); iLayer++) {
316 TGeoNode* layer = static_cast<TGeoNode*>(layers->At(iLayer));
317 if (TString(layer->GetName()).Contains("layer")) {
318 layerCounter++;
319 }
320 }
321 }
322 }
323 fNofTrdStations = layerCounter;
324 firstTime = false;
325 }
326 return fNofTrdStations;
327}
328
330{
331 static Bool_t firstTime = true;
332 if (firstTime) {
334 TGeoNode* much = nullptr;
335 TObjArray* nodes = gGeoManager->GetTopVolume()->GetNodes();
336 for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
337 TGeoNode* node = (TGeoNode*) nodes->At(iNode);
338 if (TString(node->GetName()).Contains("much", TString::kIgnoreCase)) { // Top MUCH node
339 much = node;
340 break;
341 }
342 }
343 if (NULL == much) { // No MUCH detector return 0 stations
344 firstTime = false;
345 return fNofMuchStations;
346 }
347 TObjArray* muchNodes = much->GetNodes();
348 for (Int_t iMuchNode = 0; iMuchNode < muchNodes->GetEntriesFast(); iMuchNode++) {
349 const TGeoNode* muchNode = static_cast<const TGeoNode*>(muchNodes->At(iMuchNode));
350 if (TString(muchNode->GetName()).Contains("station")) {
351 // old structure defined in ASCII geometry
352 if (TString(muchNode->GetName()).Contains("muchstation")) {
353 TObjArray* layerNodes = muchNode->GetNodes();
354 fNofMuchStations += layerNodes->GetEntriesFast();
355 }
356 else {
357 // New structure defined in ROOT geometry files
358 TObjArray* muchSubNodes = muchNode->GetNodes();
359 for (Int_t iMuchSubNode = 0; iMuchSubNode < muchSubNodes->GetEntriesFast(); iMuchSubNode++) {
360 const TGeoNode* muchSubNode = static_cast<const TGeoNode*>(muchSubNodes->At(iMuchSubNode));
361 TObjArray* layerNodes = muchSubNode->GetNodes();
362 fNofMuchStations += layerNodes->GetEntriesFast();
363 }
364 }
365 }
366 }
367 firstTime = false;
368 }
369 return fNofMuchStations;
370}
371
373{
374 static Bool_t firstTime = true;
375 if (firstTime) {
377 const TGeoNode* much = static_cast<const TGeoNode*>(fGeo->GetTopNode()->GetNodes()->FindObject("much_0"));
378 if (NULL == much) { // No MUCH detector return 0 stations
379 firstTime = false;
380 return fNofMuchAbsorbers;
381 }
382 TObjArray* muchNodes = much->GetNodes();
383 for (Int_t iMuchNode = 0; iMuchNode < muchNodes->GetEntriesFast(); iMuchNode++) {
384 const TGeoNode* muchNode = static_cast<const TGeoNode*>(muchNodes->At(iMuchNode));
385 if (TString(muchNode->GetName()).Contains("absorber")) {
386 // old structure defined in ASCII geometry
387 if (TString(muchNode->GetName()).Contains("muchabsorber")) {
389 }
390 else {
391 // New structure defined in ROOT geometry files
392 TObjArray* muchSubNodes = muchNode->GetNodes();
393 fNofMuchAbsorbers += muchSubNodes->GetEntriesFast();
394 }
395 }
396 }
397 firstTime = false;
398 }
399 return fNofMuchAbsorbers;
400}
401
403
405{
406 static Bool_t firstTime = true;
407 if (firstTime) {
408 fNofMvdStations = 0;
409 TGeoNode* topNode = gGeoManager->GetTopVolume()->FindNode("pipevac1_0");
410 if (topNode) {
411 TObjArray* nodes = topNode->GetNodes();
412 for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
413 TGeoNode* node = (TGeoNode*) nodes->At(iNode);
414 if (TString(node->GetName()).Contains("mvdstation")) {
416 }
417 }
418 }
419 else {
420 TObjArray* nodes = gGeoManager->GetTopNode()->GetNodes();
421 for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
422 TGeoNode* node = (TGeoNode*) nodes->At(iNode);
423 TString nodeName = node->GetName();
424 nodeName.ToLower();
425 if (nodeName.Contains("pipe")) {
426 TObjArray* nodes2 = node->GetNodes();
427 for (Int_t iiNode = 0; iiNode < nodes2->GetEntriesFast(); iiNode++) {
428 TGeoNode* node2 = (TGeoNode*) nodes2->At(iiNode);
429 TString nodeName2 = node2->GetName();
430 nodeName2.ToLower();
431 if (nodeName2.Contains("pipevac1")) {
432 // check if there is a mvd in the pipevac
433 TObjArray* nodes3 = node2->GetNodes();
434 for (Int_t iiiNode = 0; iiiNode < nodes3->GetEntriesFast(); iiiNode++) {
435 TGeoNode* node3 = (TGeoNode*) nodes3->At(iiiNode);
436 TString nodeName3 = node3->GetName();
437 nodeName3.ToLower();
438 if (nodeName3.Contains("mvd")) {
439 //fNofMvdStations = node3->GetNodes()->GetEntriesFast();
440 //break;
441 // Fix for mvd_v14a.
442 // Count number of daughter nodes which contain MVDDo
443 TObjArray* nodes4 = node3->GetNodes();
444 for (Int_t iiiiNode = 0; iiiiNode < nodes4->GetEntriesFast(); iiiiNode++) {
445 TGeoNode* node4 = (TGeoNode*) nodes4->At(iiiiNode);
446 TString nodeName4 = node4->GetName();
447 nodeName4.ToLower();
448 if (nodeName4.Contains("mvd")) {
450 }
451 }
452 }
453 }
454 break;
455 }
456 }
457 break;
458 }
459 }
460 }
461 firstTime = false;
462 }
463 cout << "Number of MVD station: " << fNofMvdStations << std::endl;
464 return fNofMvdStations;
465}
466
468{
469 static Bool_t firstTime = true;
470 if (firstTime) {
471 fNofStsStations = 0;
472 TObjArray* nodes = gGeoManager->GetTopVolume()->GetNodes();
473 for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
474 TGeoNode* node = (TGeoNode*) nodes->At(iNode);
475 if (TString(node->GetName()).Contains("STS_")) { // Top STS node
476 fNofStsStations = node->GetNodes()->GetEntriesFast();
477 break;
478 }
479 }
480 firstTime = false;
481 }
482 return fNofStsStations;
483}
484
486{
487 static Bool_t firstTime = true;
488 static vector<Int_t> sumOfLayers;
489 if (firstTime) {
491 const TGeoNode* much = static_cast<const TGeoNode*>(fGeo->GetTopNode()->GetNodes()->FindObject("much_0"));
492 if (NULL == much) { // No MUCH detector return 0
493 firstTime = false;
494 return 0;
495 }
496 map<Int_t, Int_t> nofLayersPerStation;
497 TObjArray* muchNodes = much->GetNodes();
498 for (Int_t iMuchNode = 0; iMuchNode < muchNodes->GetEntriesFast(); iMuchNode++) {
499 const TGeoNode* muchNode = static_cast<const TGeoNode*>(muchNodes->At(iMuchNode));
500 if (TString(muchNode->GetName()).Contains("station")) {
501 // old structure defined in ASCII geometry
502 if (TString(muchNode->GetName()).Contains("muchstation")) {
503 Int_t station = std::atoi(string(muchNode->GetName() + 11, 2).c_str()) - 1;
504 TObjArray* layerNodes = muchNode->GetNodes();
505 nofLayersPerStation[station] = layerNodes->GetEntriesFast();
506 }
507 else {
508 // New structure defined in ROOT geometry files
509 TObjArray* muchSubNodes = muchNode->GetNodes();
510 for (Int_t iMuchSubNode = 0; iMuchSubNode < muchSubNodes->GetEntriesFast(); iMuchSubNode++) {
511 const TGeoNode* muchSubNode = static_cast<const TGeoNode*>(muchSubNodes->At(iMuchSubNode));
512 Int_t station = std::atoi(string(muchSubNode->GetName() + 11, 2).c_str()) - 1;
513 TObjArray* layerNodes = muchSubNode->GetNodes();
514 nofLayersPerStation[station] += layerNodes->GetEntriesFast();
515 }
516 }
517 }
518 }
519 map<Int_t, Int_t>::const_iterator it;
520 Int_t sum = 0;
521 sumOfLayers.push_back(0);
522 for (it = nofLayersPerStation.begin(); it != nofLayersPerStation.end(); it++) {
523 sum += (*it).second;
524 sumOfLayers.push_back(sum);
525 }
526 firstTime = false;
527 }
528 return sumOfLayers[station] + layer;
529}
@ kRich
Ring-Imaging Cherenkov Detector.
Histogram manager.
Class creates grid with magnetic field values at a certain Z position.
Tracking geometry constructor.
Histogram manager.
TProfile2D * P2(const std::string &name) const
Return pointer to TProfile2D.
void ReadFromFile(TFile *file)
Read histograms from file.
void DetermineSetup()
Determines detector presence using TGeoManager.
bool GetDet(ECbmModuleId detId) const
Return detector presence in setup.
void CreateGrid(fscal Z, lit::parallel::LitFieldGrid &grid)
Main function which creates grid with magnetic field values in (X, Y) slice.
Int_t GetNofStsStations()
Return number of stations in STS.
void GetMuchLayoutVec(lit::parallel::LitDetectorLayoutVec &layout)
Return MUCH detector layout for parallel MUCH tracking in SIMD format.
static CbmLitTrackingGeometryConstructor * Instance()
Return pointer to singleton object.
Int_t GetNofMuchTrdStations()
Return number of stations in MUCH + TRD.
Int_t ConvertMuchToAbsoluteStationNr(Int_t station, Int_t layer)
void GetMuchLayoutScal(lit::parallel::LitDetectorLayoutScal &layout)
Return MUCH detector layout for parallel MUCH tracking in scalar format.
void GetRichMaterial(lit::parallel::LitMaterialGrid *material)
void GetMuchLayout(lit::parallel::LitDetectorLayout< T > &layout)
Return MUCH detector layout for parallel MUCH tracking.
Int_t GetNofMvdStations()
Return number of stations in MVD.
void GetTrdLayoutVec(lit::parallel::LitDetectorLayoutVec &layout)
Return TRD detector layout for TRD parallel tracking in SIMD format.
void GetTrdLayoutScal(lit::parallel::LitDetectorLayoutScal &layout)
Return TRD detector layout for TRD parallel tracking in scalar format.
Int_t GetNofMuchStations()
Return number of stations in MUCH.
void GetTrdLayout(lit::parallel::LitDetectorLayout< T > &layout)
Return TRD detector layout for TRD parallel tracking.
Int_t GetNofMuchAbsorbers()
Return number of MUCH absorbers.
void ConvertTProfile2DToLitMaterialGrid(const TProfile2D *profile, lit::parallel::LitMaterialGrid *grid, Double_t maximumValue=0)
Int_t GetNofTrdStations()
Return number of stations in TRD.
CbmLitTrackingGeometryConstructor()
Constructor. Constructor is protected since singleton pattern is used. Pointer to object is returned ...
Represents detector layout.
void AddVirtualStation(const LitVirtualStation< T > &virtualStation)
Add virtual station to detector layout.
void AddStation(const LitStation< T > &station)
Add station to detector layout.
Class stores a grid of magnetic field values in XY slice at Z position.
Class stores a grid of material thickness in silicon equivalent.
void SetMaterial(const vector< vector< fscal > > &material, fscal xmin, fscal xmax, fscal ymin, fscal ymax, int nofBinsX, int nofBinsY)
Returns Z position of the grid.
Detector station.
Definition LitStation.h:38
void AddVirtualStation(const LitVirtualStation< T > &virtualStation)
Add virtual station to detector layout.
Definition LitStation.h:54
Virtual detector station which stores information needed for track propagation.
void SetMaterial(const LitMaterialGrid &material)
void SetField(const LitFieldGrid &field)
std::string ToString(const T &value)
Definition CbmUtils.h:26