er  dev
ERGadastSetup.cxx
1 #include "ERGadastSetup.h"
2 
3 #include "TMath.h"
4 #include "TGeoManager.h"
5 #include "TGeoMatrix.h"
6 #include "TGeoNode.h"
7 #include <iostream>
8 
9 #include "FairRun.h"
10 #include "FairRuntimeDb.h"
11 
12 #include "ERDetectorList.h"
13 
14 using namespace std;
15 
16 ERGadastSetup* ERGadastSetup::fInstance = NULL;
17 ERGadastDigiPar* ERGadastSetup::fDigiPar;
18 TGeoPhysicalNode* ERGadastSetup::fGadastNode;
19 //----------------------------------------------------------------------------
20 ERGadastSetup* ERGadastSetup::Instance(){
21  if (fInstance == NULL)
22  return new ERGadastSetup();
23  else
24  return fInstance;
25 }
26 //----------------------------------------------------------------------------
27 ERGadastSetup::ERGadastSetup()
28 {
29 
30  FairRun* run = FairRun::Instance();
31  if ( ! run ) Fatal("ERGadastSetup", "No analysis run");
32 
33  FairRuntimeDb* rtdb = run->GetRuntimeDb();
34  if ( ! rtdb ) Fatal("ERGadastSetup", "No runtime database");
35 
36  fDigiPar = (ERGadastDigiPar*)(rtdb->getContainer("ERGadastDigiPar"));
37  if ( ! fDigiPar ) Fatal("ERGadastSetup`", "No ERNeuRadDigiPar in runtime");
38 }
39 //----------------------------------------------------------------------------
40 int ERGadastSetup::GetMeshElement(TVector3* pos, SensetiveType detType){
41  TGeoNode* node = gGeoManager->FindNode(pos->X(), pos->Y(), pos->Z());
42  TGeoMatrix* gm = node->GetMatrix();
43 
44  Double_t posMaster[3];
45  posMaster[0] = pos->X(); posMaster[1] = pos->Y(); posMaster[2] = pos->Z();
46  Double_t posLocal[3];
47  gm->MasterToLocal(posMaster,posLocal);
48  if(detType == CsI){
49  Int_t xCount=4,yCount=4,zCount=4;
50  Double_t dX = 72.8/(double)xCount;
51  Double_t dY = 41.5/(double)yCount;
52  Double_t dZ = 150.1/(double)zCount; // 4 ячейки длина криистала 150.1
53  posLocal[0] += 72.8/2;
54  posLocal[1] += 41.5/2;
55  posLocal[2] += 30.; //так как начало координат в начале координат первого trd. сдвигаем ее на поверхность второго trd
56 
57  Int_t x = (Int_t)(posLocal[0]/dX);
58  Int_t y = (Int_t)(posLocal[1]/dY);
59  Int_t z = (Int_t)(posLocal[2]/dZ);
60 
61  Int_t MeshElement = z*xCount*yCount + y*xCount + x;
62  return MeshElement;
63  }
64  if (detType == LaBr){
65  Int_t zCount=4;
66  Double_t dZ = 50.8/(double)zCount; // 4 ячейки длина криистала 150.1
67  posLocal[2] += 50.8/2; //так как начало координат в центре tube
68 
69  Int_t z = (Int_t)(posLocal[2]/dZ);
70  return z;
71  }
72 }
73 //----------------------------------------------------------------------------
74 Bool_t ERGadastSetup::Init(){
75  // --- Get cave (top node)
76  TGeoManager* geo = gGeoManager;
77  if (!gGeoManager){
78  Fatal("ERGadastSetup","Can`t find gGeoManager!");
79  return kFALSE;
80  }
81  cout << "Reading geometry from TGeoManager " << geo->GetName() << endl;
82  geo->CdTop();
83  TGeoNode* cave = geo->GetCurrentNode();
84  // --- Get top Gaadast node
85  TGeoNode* gadast = NULL;
86  for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
87  TString name = cave->GetDaughter(iNode)->GetName();
88  if ( name.Contains("Gadast", TString::kIgnoreCase) ) {
89  gadast = cave->GetDaughter(iNode);
90  geo->CdDown(iNode);
91  cout << "Gadast top node is " << gadast->GetName() << endl;
92  break;
93  }
94  }
95 
96  if ( ! gadast ) {
97  cout << "No top Gadast node found in geometry!" << endl;
98  return kFALSE;
99  }
100 
101  // --- Create physical node for sts
102  TString path = cave->GetName();
103  path = path + "/" + gadast->GetName();
104  fGadastNode = new TGeoPhysicalNode(path);
105 
106  return kTRUE;
107 }
108 
109 //----------------------------------------------------------------------------
110 Float_t ERGadastSetup::CsILC(TVector3* pos){
111  return fDigiPar->CsILC(fInstance->GetMeshElement(pos, CsI));
112 }
113 //----------------------------------------------------------------------------
114 Float_t ERGadastSetup::LaBrLC(TVector3* pos){
115  return fDigiPar->LaBrLC(fInstance->GetMeshElement(pos, LaBr));
116 }
117 //----------------------------------------------------------------------------
118 Float_t ERGadastSetup::CsIDispA(TVector3* pos){
119  return fDigiPar->CsIDispA(fInstance->GetMeshElement(pos, CsI));
120 }
121 //----------------------------------------------------------------------------
122 Float_t ERGadastSetup::LaBrDispA(TVector3* pos){
123  return fDigiPar->LaBrDispA(fInstance->GetMeshElement(pos, LaBr));
124 }
125 //----------------------------------------------------------------------------
126 Float_t ERGadastSetup::CsIDispB(TVector3* pos){
127  return fDigiPar->CsIDispB(fInstance->GetMeshElement(pos, CsI));
128 }
129 //----------------------------------------------------------------------------
130 Float_t ERGadastSetup::LaBrDispB(TVector3* pos){
131  return fDigiPar->LaBrDispB(fInstance->GetMeshElement(pos, LaBr));
132 }
133 //----------------------------------------------------------------------------