er  dev
ERTelescope.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERTelescope.h"
10 
11 #include "TClonesArray.h"
12 #include "TParticle.h"
13 #include "TVirtualMC.h"
14 #include "TString.h"
15 
16 #include "FairRootManager.h"
17 #include "FairRun.h"
18 #include "FairRunSim.h"
19 #include "FairRuntimeDb.h"
20 #include "FairLogger.h"
21 
22 #include "ERTelescopeGeoComponentSensetive.h"
23 #include "ERPoint.h"
24 //-------------------------------------------------------------------------------------------------
26  ERDetector("ERTelescope", kTRUE)
27 {
29  flGeoPar = new TList();
30  flGeoPar->SetName( GetName());
31  fQTelescopeSetup = ERTelescopeSetup::Instance();
32  fVerboseLevel = 1;
33  fVersion = 1;
34 }
35 //-------------------------------------------------------------------------------------------------
36 ERTelescope::ERTelescope(const char* name, Bool_t active, Int_t verbose)
37  : ERDetector(name, active,1)
38 {
40  flGeoPar = new TList();
41  flGeoPar->SetName( GetName());
42  fQTelescopeSetup = ERTelescopeSetup::Instance();
43  fVersion = 1;
44  fVerboseLevel = verbose;
45 }
46 //-------------------------------------------------------------------------------------------------
48 /* if (fSiPoint) {
49  fSiPoint->Delete();
50  delete fSiPoint;
51  }
52  if (fCsIPoint) {
53  fCsIPoint->Delete();
54  delete fCsIPoint;
55  }
56  */
57 }
58 //-------------------------------------------------------------------------------------------------
60  FairDetector::Initialize();
61 }
62 //-------------------------------------------------------------------------------------------------
63 void ERTelescope::AddPoint(TClonesArray& clref) {
64  TGeoHMatrix matrix;
65  gMC->GetTransformation(gMC->CurrentVolPath(), matrix);
66  Double_t globalPos[3],localPos[3];
67  fPosIn.Vect().GetXYZ(globalPos);
68  matrix.MasterToLocal(globalPos,localPos);
69  TVector3 pos_in_local_cs;
70  pos_in_local_cs.SetXYZ(localPos[0],localPos[1],localPos[2]);
71  new(clref[clref.GetEntriesFast()]) ERPoint(
73  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
74  pos_in_local_cs,
75  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
76  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
77  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
78  fTime, fTime, fLength, fEloss, -1 /*light yield*/,fPDG, -1 /*charge*/);
79 }
80 //-------------------------------------------------------------------------------------------------
82  fQTelescopeSetup->ConstructGeometry();
83  SetGeometryFileName(fQTelescopeSetup->GetGeoFileName());
84  ConstructRootGeometry();
85 }
86 //-------------------------------------------------------------------------------------------------
87 Bool_t ERTelescope::ProcessHits(FairVolume* vol) {
88  if ( gMC->IsTrackEntering() ) { // Return true if this is the first step of the track in the current volume
89  fEloss = 0.;
90  fEventID = gMC->CurrentEvent();
91  gMC->TrackPosition(fPosIn);
92  gMC->TrackMomentum(fMomIn);
93  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
94  fTime = gMC->TrackTime() * 1.0e09; // Return the current time of flight of the track being transported
95  fLength = gMC->TrackLength(); // Return the length of the current track from its origin (in cm)
96  fMot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
97  fMass = gMC->ParticleMass(gMC->TrackPid()) * 1000; // MeV
98  fPDG = gMC->TrackPid();
99  }
100  fEloss += gMC->Edep() * 1000.; // MeV //Return the energy lost in the current step
101  if ((gMC->IsTrackExiting() || //Return true if this is the last step of the track in the current volume
102  gMC->IsTrackStop() || //Return true if the track energy has fallen below the threshold
103  gMC->IsTrackDisappeared()) && fEloss > 0.) {
104  gMC->TrackPosition(fPosOut);
105  gMC->TrackMomentum(fMomOut);
106  const TString path = gMC->CurrentVolPath();
107  const auto* component = dynamic_cast<ERTelescopeGeoComponentSensetive*>(fQTelescopeSetup->GetComponent(path));
108  if (!component)
109  LOG(FATAL) << "[ERTelescope] Not found setup component for sensetive volume path"
110  << path << FairLogger::endl;
111  for (const auto orientation : component->GetOrientationsAroundZ()) {
112  for (const auto channelSide : component->GetChannelSides()) {
113  fChannel = component->GetChannelFromSensetiveNodePath(path, orientation);
114  auto* pointCollection =
115  fPoints[component->GetVolumeName()][component->GetBranchName(ERDataObjectType::Point, orientation, channelSide)];
116  AddPoint(*pointCollection);
117  }
118  }
119  }
120  return kTRUE;
121 }
122 //-------------------------------------------------------------------------------------------------
124 }
125 //-------------------------------------------------------------------------------------------------
127  if (fVerboseLevel > 1) {
128  Print();
129  }
130  Reset();
131 }
132 //-------------------------------------------------------------------------------------------------
134  FairRootManager* ioman = FairRootManager::Instance();
135  if (!ioman)
136  Fatal("Init", "IO manager is not set");
137  for (const auto* component : fQTelescopeSetup->GetAllComponents()) {
138  if (!dynamic_cast<const ERTelescopeGeoComponentSensetive*>(component))
139  continue;
140  for (const auto branchName : component->GetBranchNames(ERDataObjectType::Point)) {
141  LOG(DEBUG) << "[ERTelescope] Register branch " << branchName
142  << " for component " << component->GetVolumeName() << FairLogger::endl;
143  fPoints[component->GetVolumeName()][branchName] =
144  new TClonesArray("ERPoint", consts::approx_telescope_point_number);
145  ioman->Register(branchName, "Telescope", fPoints[component->GetVolumeName()][branchName], kTRUE);
146  }
147  }
148 }
149 //-------------------------------------------------------------------------------------------------
150 TClonesArray* ERTelescope::GetCollection(Int_t iColl) const {
151  /* if (iColl == 0)
152  return fSiPoint;
153  if (iColl == 0)
154  return fCsIPoint;
155 */
156  return NULL;
157 }
158 //-------------------------------------------------------------------------------------------------
159 void ERTelescope::Print(Option_t *option) const {
160 /* if(fSiPoint->GetEntriesFast() > 0) {
161  LOG(DEBUG) << "======== Si Points ==================" << FairLogger::endl;
162  for (Int_t iPoint = 0; iPoint < fSiPoint->GetEntriesFast(); iPoint++){
163  ERTelescopeSiPoint* point = (ERTelescopeSiPoint*)fSiPoint->At(iPoint);
164  point->Print();
165  }
166  }
167  if(fCsIPoint->GetEntriesFast() > 0) {
168  LOG(DEBUG) << "======== CsI Points ==================" << FairLogger::endl;
169  for (Int_t iPoint = 0; iPoint < fCsIPoint->GetEntriesFast(); iPoint++){
170  ERTelescopeCsIPoint* point = (ERTelescopeCsIPoint*)fCsIPoint->At(iPoint);
171  point->Print();
172  }
173  }
174 */
175 }
176 //-------------------------------------------------------------------------------------------------
178  for(auto& componentPoints : fPoints) {
179  for (auto& branchPoints : componentPoints.second) {
180  branchPoints.second->Clear();
181  }
182  }
183  ResetParameters();
184 }
185 //-------------------------------------------------------------------------------------------------
186 void ERTelescope::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
187 /* LOG(INFO) << " ERTelescope::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)"
188  << FairLogger::endl;
189  Int_t nEntries = cl1->GetEntriesFast();
190  LOG(INFO) << "QTelescope: " << nEntries << " entries to add" << FairLogger::endl;
191  TClonesArray& clref = *cl2;
192  ERTelescopeSiPoint* oldpoint = NULL;
193  for (Int_t i=0; i<nEntries; i++) {
194  oldpoint = (ERTelescopeSiPoint*) cl1->At(i);
195  Int_t index = oldpoint->GetTrackID() + offset;
196  oldpoint->SetTrackID(index);
197  new (clref[cl2->GetEntriesFast()]) ERTelescopeSiPoint(*oldpoint);
198  }
199  LOG(INFO) << "decector: " << cl2->GetEntriesFast() << " merged entries" << FairLogger::endl;
200 */
201 }
202 //-------------------------------------------------------------------------------------------------
203 Bool_t ERTelescope::CheckIfSensitive(std::string name) {
204  TString volName = name;
205  if(volName.BeginsWith("Sensitive")) {
206  return kTRUE;
207  }
208  return kFALSE;
209 }
210 //-------------------------------------------------------------------------------------------------
212 };
213 //-------------------------------------------------------------------------------------------------
214 ClassImp(ERTelescope)
215 
Int_t fMot0TrackID
track index
Definition: ERTelescope.h:107
Int_t fChannel
energy loss
Definition: ERTelescope.h:114
virtual void Print(Option_t *option="") const
virtual void ConstructGeometry()
Builds geometry and writes it to temporary file trough parameters from ERBeamDetSetup class object...
Definition: ERTelescope.cxx:81
TLorentzVector fMomIn
position
Definition: ERTelescope.h:110
virtual void Register()
TLorentzVector fPosIn
mass
Definition: ERTelescope.h:109
virtual void BeginEvent()
Double32_t fEloss
length
Definition: ERTelescope.h:113
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: ERTelescope.cxx:87
Int_t fEventID
geometry version
Definition: ERTelescope.h:105
Double32_t fTime
momentum
Definition: ERTelescope.h:111
virtual void Reset()
Int_t fTrackID
event index
Definition: ERTelescope.h:106
virtual TClonesArray * GetCollection(Int_t iColl) const
void ResetParameters()
void AddPoint(TClonesArray &clref)
Definition: ERTelescope.cxx:63
virtual void Initialize()
Definition: ERTelescope.cxx:59
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Double32_t fLength
time
Definition: ERTelescope.h:112
virtual ~ERTelescope()
Definition: ERTelescope.cxx:47
virtual void EndOfEvent()
The data class for storing pieces of charged tracks in sensitive volumes in NeuRad.
Definition: ERPoint.h:23
Double_t fMass
0th mother track index
Definition: ERTelescope.h:108
virtual Bool_t CheckIfSensitive(std::string name)
The base class for detector simulation in er sim.
Definition: ERDetector.h:32