er  dev
ERDetector.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 "ERDetector.h"
10 
11 #include "TGeoMatrix.h"
12 #include "TVirtualMC.h"
13 
14 #include "FairRun.h"
15 #include "FairRuntimeDb.h"
16 #include "FairRootManager.h"
17 #include "FairLogger.h"
18 
19 #include "ERDetectorGeoPar.h"
20 //-------------------------------------------------------------------------------------------------
22 : FairDetector("ERDetector", kTRUE, -1)
23 {
24  flGeoPar = new TList();
25  flGeoPar->SetName( GetName());
26  fVerboseLevel = 1;
27 }
28 //-------------------------------------------------------------------------------------------------
29 ERDetector::ERDetector(const char* Name, Bool_t Active, Int_t DetId/*=0*/)
30 : FairDetector(Name, Active, DetId)
31 {
32  flGeoPar = new TList();
33  flGeoPar->SetName( GetName());
34  fVerboseLevel = 1;
35 }
36 //-------------------------------------------------------------------------------------------------
38  TString fileName = GetGeometryFileName();
39  if(fileName.EndsWith(".root")) {
40  LOG(INFO) << "Constructing geometry from ROOT file " << fileName.Data() << FairLogger::endl;
41  ConstructRootGeometry();
42  }
43  else if (fileName.EndsWith(".gdml")) {
44  LOG(INFO) << "Constructing geometry from GDML file " << fileName.Data() << FairLogger::endl;
45  TGeoRotation *zeroRotation = new TGeoRotation();
46  zeroRotation->RotateX(0.);
47  zeroRotation->RotateY(0.);
48  zeroRotation->RotateZ(0.);
49  ConstructGDMLGeometry(new TGeoCombiTrans(.0,.0,.0, zeroRotation));
50  }
51  else {
52  LOG(FATAL) << "Geometry file name is not set" << FairLogger::endl;
53  }
54 }
55 //-------------------------------------------------------------------------------------------------
56 void ERDetector::AddSensetive(TString name){
57  fSenNames.push_back(name);
58 }
59 //-------------------------------------------------------------------------------------------------
60 TClonesArray* ERDetector::GetCollection(Int_t iColl) const {
61  if (fSenVolumes.size() > iColl){
62  auto it = fSenVolumes.begin();
63  for (Int_t i = 0; i<iColl; i++){it++;}
64  return it->second;
65  }
66  else {
67  return NULL;
68  }
69 }
70 //-------------------------------------------------------------------------------------------------
72  FairDetector::Initialize();
73  FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
74  ERDetectorGeoPar* par=(ERDetectorGeoPar*)(rtdb->getContainer("ERDetectorGeoPar"));
75 }
76 //-------------------------------------------------------------------------------------------------
78  FairRootManager* ioman = FairRootManager::Instance();
79  if (!ioman)
80  LOG(FATAL) << "IO manager is not set" << FairLogger::endl;
81 
82  for(const auto &itSen: fSenVolumes){
83  ioman->Register(fName+itSen.first+TString("Point"),fName, itSen.second, kTRUE);
84  }
85 }
86 //-------------------------------------------------------------------------------------------------
87 Bool_t ERDetector::ProcessHits(FairVolume* vol) {
88  // Set constants for Birk's Law implentation
89  static const Double_t dP = 1.032 ;
90  static const Double_t BirkC1 = 0.013/dP;
91  static const Double_t BirkC2 = 9.6e-6/(dP * dP);
92 
96  if (gMC->IsTrackEntering()) { // Return true if this is the first step of the track in the current volume
97  StartNewPoint();
98  }
99 
100  fELoss += gMC->Edep(); // GeV //Return the energy lost in the current step
101 
102  Double_t curLightYield = 0.;
103  // Apply Birk's law ( Adapted from G3BIRK/Geant3)
104  // Correction for all charge states
105  if (gMC->TrackCharge()!=0) { // Return the charge of the track currently transported
106  Double_t BirkC1Mod = 0;
107  // Apply correction for higher charge states
108  if (TMath::Abs(gMC->TrackCharge())>=2)
109  BirkC1Mod=BirkC1*7.2/12.6;
110  else
111  BirkC1Mod=BirkC1;
112 
113  if (gMC->TrackStep()>0){
114  Double_t dedxcm=gMC->Edep()*1000./gMC->TrackStep(); //[MeV/cm]
115  curLightYield=gMC->Edep()*1000./(1.+BirkC1Mod*dedxcm+BirkC2*dedxcm*dedxcm); //[MeV]
116  curLightYield /= 1000.; //[GeV]
117  fLightYield+=curLightYield;
118  }
119  }
120 
121  if (gMC->IsTrackExiting() || //true if this is the last step of the track in the current volume
122  gMC->IsTrackStop() || //true if the track energy has fallen below the threshold
123  gMC->IsTrackDisappeared()) {
124  FinishNewPoint();
125  }
126 
127  return kTRUE;
128 }
129 //-------------------------------------------------------------------------------------------------
131  if (fVerbose > 1){
132  Print();
133  }
134  Reset();
135 }
136 //-------------------------------------------------------------------------------------------------
137 void ERDetector::Print(Option_t *option) const {
138  for(const auto &itSen: fSenVolumes){
139  TClonesArray* points = itSen.second;
140  for (Int_t i_point = 0; i_point < points->GetEntriesFast(); i_point++) {
141  ERPoint* point = (ERPoint*)points->At(i_point);
142  point->Print();
143  }
144  }
145 }
146 //-------------------------------------------------------------------------------------------------
148  for(const auto &itSen: fSenVolumes){
149  TClonesArray* points = itSen.second;
150  points->Clear();
151  }
152  fFullEnergy = 0.;
153  fFullLY = 0.;
154 }
155 //-------------------------------------------------------------------------------------------------
156 void ERDetector::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
157 
158  Int_t nEntries = cl1->GetEntriesFast();
159  LOG(DEBUG) << "ERDetector: " << nEntries << " entries to add" << FairLogger::endl;
160  TClonesArray& clref = *cl2;
161  ERPoint* oldpoint = NULL;
162  for (Int_t i=0; i<nEntries; i++) {
163  oldpoint = (ERPoint*) cl1->At(i);
164  Int_t index = oldpoint->GetTrackID() + offset;
165  oldpoint->SetTrackID(index);
166  new (clref[cl2->GetEntriesFast()]) ERPoint(*oldpoint);
167  }
168  LOG(DEBUG) << "ERDetector: " << cl2->GetEntriesFast() << " merged entries" << FairLogger::endl;
169 
170 }
171 //-------------------------------------------------------------------------------------------------
172 Bool_t ERDetector::CheckIfSensitive(std::string name) {
173  TString curVolName = name;
174  for(const auto &volNameSubsting: fSenNames){
175  if(curVolName.Contains(volNameSubsting)){
176  fSenVolumes[curVolName] = new TClonesArray("ERPoint");
177  return kTRUE;
178  }
179  }
180  return kFALSE;
181 }
182 //-------------------------------------------------------------------------------------------------
184  fELoss = 0.;
185  fLightYield = 0.;
186  fEventID = gMC->CurrentEvent();
187  gMC->TrackPosition(fPosIn);
188  gMC->TrackMomentum(fMomIn);
189  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
190  fTimeIn = gMC->TrackTime() * 1.0e09; //current time of flight of the track being transported
191  fTrackLength = gMC->TrackLength(); //length of the current track from its origin (in cm)
192  fMot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
193  fMass = gMC->ParticleMass(gMC->TrackPid()); // GeV/c2
194  Int_t curVolId, corOffVolId;
195  curVolId = gMC->CurrentVolID(fVolNb);
196  TGeoHMatrix matrix;
197  gMC->GetTransformation(gMC->CurrentVolPath(), matrix);
198  Double_t globalPos[3],localPos[3];
199  fPosIn.Vect().GetXYZ(globalPos);
200  matrix.MasterToLocal(globalPos,localPos);
201  fPosInLocal.SetXYZ(localPos[0],localPos[1],localPos[2]);
202 }
203 //-------------------------------------------------------------------------------------------------
205  gMC->TrackPosition(fPosOut);
206  gMC->TrackMomentum(fMomOut);
207  fTimeOut = gMC->TrackTime() * 1.0e09;
208 
209  if (fELoss > 0.) {
210  TClonesArray* points = fSenVolumes[gMC->CurrentVolName()];
211  AddPoint(points);
214 
215  }
216 }
217 //-------------------------------------------------------------------------------------------------
218 ERPoint* ERDetector::AddPoint(TClonesArray* points) {
219  TClonesArray& clref = *points;
220  Int_t size = clref.GetEntriesFast();
221  return new(clref[size]) ERPoint(fEventID, fTrackID, fMot0TrackID, fVolNb,
222  fMass, fPosIn.Vect(),fPosInLocal,fPosOut.Vect(),fMomIn.Vect(),fMomOut.Vect(),fTimeIn,
223  fTimeOut,fTrackLength, fELoss, fLightYield,gMC->TrackPid(), gMC->TrackCharge());
224 }
225 
226 ClassImp(ERDetector)
TLorentzVector fMomOut
point start momentum
Definition: ERDetector.h:152
TLorentzVector fMomIn
point start momentum
Definition: ERDetector.h:151
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Copies the points collection with a given track index offset.
Definition: ERDetector.cxx:156
Int_t fTrackID
track index
Definition: ERDetector.h:144
virtual void Reset()
Clears the point and steps collections Virtual from FairDetector.
Definition: ERDetector.cxx:147
Float_t fFullLY
Sum Light Yield in event in sensetive volume.
Definition: ERDetector.h:140
virtual void Print(Option_t *option="") const
Screen log Prints NeuRadPoint information Virtual from TObject.
Definition: ERDetector.cxx:137
Double_t fLightYield
light yield
Definition: ERDetector.h:158
Double_t fMass
mass
Definition: ERDetector.h:146
virtual TClonesArray * GetCollection(Int_t iColl) const
Get array of ERNeuRadPoint.
Definition: ERDetector.cxx:60
void StartNewPoint()
Start new point creation. Reinit current point data.
Definition: ERDetector.cxx:183
virtual void Print(const Option_t *opt=0) const
Definition: ERPoint.cxx:69
Float_t fFullEnergy
Sum Edep in event in sensetive volume.
Definition: ERDetector.h:139
void FinishNewPoint()
Finish point creation. Call AddPoint()
Definition: ERDetector.cxx:204
virtual void EndOfEvent()
Action at end of event Short status log and Reset(). Virtual from FairDetector.
Definition: ERDetector.cxx:130
ERDetector()
Default constructor.
Definition: ERDetector.cxx:21
virtual void Initialize()
Initialisation class method FairDetector::Initialize() is called. NeuRadGeoPar init from RuntimeDB Vi...
Definition: ERDetector.cxx:71
TVector3 fPosInLocal
point position in sensetive volume CS
Definition: ERDetector.h:150
Int_t fMot0TrackID
0th mother track index
Definition: ERDetector.h:145
std::vector< TString > fSenNames
Sensetive volumes sustring, that user set.
Definition: ERDetector.h:135
Int_t fEventID
event index
Definition: ERDetector.h:143
Int_t fVerbose
Verbosity level.
Definition: ERDetector.h:137
virtual Bool_t CheckIfSensitive(std::string name)
Check whether a volume is sensitive.
Definition: ERDetector.cxx:172
virtual Bool_t ProcessHits(FairVolume *vol=0)
Virtual method Defines the action to be taken when a step is inside the active volume. Creates a ERNeuRadPoint and adds it to the collection.
Definition: ERDetector.cxx:87
Int_t fVolNb
number of fiber in pixel
Definition: ERDetector.h:159
The data class for storing pieces of charged tracks in sensitive volumes in NeuRad.
Definition: ERPoint.h:23
virtual void ConstructGeometry()
Definition: ERDetector.cxx:37
ERPoint * AddPoint(TClonesArray *points)
Adds a Point to the Point Collection.
Definition: ERDetector.cxx:218
TLorentzVector fPosIn
point start position
Definition: ERDetector.h:147
virtual void Register()
Register output array (NeuRadPoint) to the I/O manager Abstract from FairDetector.
Definition: ERDetector.cxx:77
void AddSensetive(TString name)
Add sensetive volume name. Create new points collection.
Definition: ERDetector.cxx:56
Double32_t fTimeOut
point finish time
Definition: ERDetector.h:155
Double32_t fTimeIn
point start time
Definition: ERDetector.h:154
The base class for detector simulation in er sim.
Definition: ERDetector.h:32
Double32_t fELoss
energy loss
Definition: ERDetector.h:157
Double32_t fTrackLength
track length from his origin
Definition: ERDetector.h:156
TLorentzVector fPosOut
point finish position
Definition: ERDetector.h:148