er  dev
ERNDSetup.cxx
1 #include "ERNDSetup.h"
2 
3 #include <iostream>
4 
5 #include "TGeoManager.h"
6 
7 #include "FairLogger.h"
8 
9 ERNDSetup* ERNDSetup::fInstance = NULL;
10 TGeoNode* ERNDSetup::fNDnode = NULL;
11 
12 ERNDSetup::ERNDSetup(){
13  // --- Catch absence of TGeoManager
14  if ( ! gGeoManager ) {
15  std::cerr << "ERNDSetup: cannot initialise without TGeoManager!"<< std::endl;
16  }
17  gGeoManager->CdTop();
18  TGeoNode* cave = gGeoManager->GetCurrentNode();
19  fNDnode = NULL;
20  for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
21  TString name = cave->GetDaughter(iNode)->GetName();
22  if ( name.Contains("ND", TString::kIgnoreCase) ) {
23  fNDnode = cave->GetDaughter(iNode);
24  }
25  }
26 }
27 
28 ERNDSetup* ERNDSetup::Instance(){
29  if (fInstance == NULL)
30  return new ERNDSetup();
31  else
32  return fInstance;
33 }
34 
35 void ERNDSetup::ReadGeoParamsFromParContainer() {
36  if (fInited)
37  return;
38  if (! gGeoManager)
39  LOG(FATAL) << "ERNDSetup: cannot initialise without TGeoManager!"<< FairLogger::endl;
40  gGeoManager->CdTop();
41  TGeoNode* cave = gGeoManager->GetCurrentNode();
42  for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) { // cycle by volumes in TOP
43  TString detectorName = cave->GetDaughter(iNode)->GetName();
44  if (!detectorName.Contains("ND", TString::kIgnoreCase))
45  continue;
46  const auto* nd = cave->GetDaughter(iNode);
47  if (nd->GetNdaughters() != 1)
48  LOG(FATAL) << "Wrong ND geometry structure" << FairLogger::endl;
49  const auto* airBox = nd->GetDaughter(0);
50  for (Int_t iStilben = 0; iStilben < airBox->GetNdaughters(); iStilben++) {
51  const auto* node = airBox->GetDaughter(iStilben);
52  const auto* translation = node->GetMatrix()->GetTranslation();
53  fChannel2Node[node->GetNumber()] = node;
54  }
55  }
56  fInited = true;
57 }
58 
59 void ERNDSetup::PMTPos(TVector3 pos, TVector3& pmtPos){
60  //@TODO пока что высчитывается координата центра стилбена.
61  TGeoNode* stilben = gGeoManager->FindNode(pos.X(), pos.Y(), pos.Z());
62 
63  TGeoMatrix* stilbenMatrix = stilben->GetMatrix();
64  pmtPos.SetXYZ(stilbenMatrix->GetTranslation()[0],
65  stilbenMatrix->GetTranslation()[1],
66  stilbenMatrix->GetTranslation()[2]);
67 }
68 
69 TVector3 ERNDSetup::Pos(Int_t channel) {
70  if (fChannel2Node.find(channel) == fChannel2Node.end()) {
71  LOG(FATAL) << "ERNDSetup: Node for channel " << channel << " not found in geometry."
72  << FairLogger::endl;
73  }
74  const auto* translation = fChannel2Node[channel]->GetMatrix()->GetTranslation();
75  return TVector3(translation[0], translation[1], translation[2]);
76 }