er  dev
ERNeuRad.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 "ERNeuRad.h"
10 
11 #include "TClonesArray.h"
12 #include "TParticle.h"
13 #include "TVirtualMC.h"
14 #include "TGeoMatrix.h"
15 #include "TString.h"
16 
17 #include "FairRootManager.h"
18 #include "FairRun.h"
19 #include "FairRunSim.h"
20 #include "FairRuntimeDb.h"
21 #include "FairLogger.h"
22 
23 #include "ERNeuRadGeoPar.h"
24 #include "ERMCEventHeader.h"
25 #include "ERNeuRadPoint.h"
26 #include "ERNeuRadStep.h"
27 
28 //-------------------------------------------------------------------------------------------------
30  ERDetector("ERNeuRad", kTRUE),
31  fStorePrimarySteps(kFALSE),
32  fStoreAllSteps(kFALSE),
33  fNeuRadPoints(NULL),
34  fNeuRadFirstStep(NULL),
35  fNeuRadSteps(NULL),
36  fStep(0.1)
37 {
38  fNeuRadPoints = new TClonesArray("ERNeuRadPoint");
39  fNeuRadFirstStep = new TClonesArray("ERNeuRadStep");
40  fNeuRadSteps = new TClonesArray("ERNeuRadStep");
41  flGeoPar = new TList();
42  flGeoPar->SetName( GetName());
43  fVerboseLevel = 1;
44 }
45 
46 //-------------------------------------------------------------------------------------------------
47 ERNeuRad::ERNeuRad(const char* name, Bool_t active, Int_t verbose):
48  ERDetector(name, active),
49  fVerbose(verbose),
50  fStorePrimarySteps(kFALSE),
51  fStoreAllSteps(kFALSE),
52  fStep(0.1)
53 {
54  fNeuRadPoints = new TClonesArray("ERNeuRadPoint");
55  fNeuRadFirstStep = new TClonesArray("ERNeuRadStep");
56  fNeuRadSteps = new TClonesArray("ERNeuRadStep");
57  flGeoPar = new TList();
58  flGeoPar->SetName( GetName());
59 }
60 
61 //-------------------------------------------------------------------------------------------------
63  if (fNeuRadPoints) {
64  fNeuRadPoints->Delete();
65  delete fNeuRadPoints;
66  }
67 }
68 
69 //-------------------------------------------------------------------------------------------------
70 TClonesArray* ERNeuRad::GetCollection(Int_t iColl) const {
71  if (iColl == 0)
72  return fNeuRadPoints;
73  else
74  return NULL;
75 }
76 
77 //-------------------------------------------------------------------------------------------------
79  FairDetector::Initialize();
80  FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
81  ERNeuRadGeoPar* par=(ERNeuRadGeoPar*)(rtdb->getContainer("ERNeuRadGeoPar"));
82 }
83 
84 //-------------------------------------------------------------------------------------------------
86  FairRootManager* ioman = FairRootManager::Instance();
87  if (!ioman)
88  LOG(FATAL) << "IO manager is not set" << FairLogger::endl;
89 
90  ioman->Register("NeuRadPoint","NeuRad", fNeuRadPoints, kTRUE);
91  ioman->Register("NeuRadFirstStep","NeuRad", fNeuRadFirstStep, kTRUE);
92  ioman->Register("NeuRadStep","NeuRad", fNeuRadSteps, kTRUE);
93 }
94 
95 //-------------------------------------------------------------------------------------------------
96 Bool_t ERNeuRad::ProcessHits(FairVolume* vol) {
97  // Set constants for Birk's Law implentation
98  static const Double_t dP = 1.032 ;
99  static const Double_t BirkC1 = 0.013/dP;
100  static const Double_t BirkC2 = 9.6e-6/(dP * dP);
101 
102  gMC->SetMaxStep(fStep);
103 
107  if (gMC->IsTrackEntering()) { // Return true if this is the first step of the track in the current volume
108  StartNewPoint();
109  if (fNeuRadFirstStep->GetEntriesFast() == 0)
110  AddFirstStep();
111  }
112 
113  if (fStorePrimarySteps && fMot0TrackID == -1 && fNeuRadSteps->GetEntriesFast() == 0){
114  ERNeuRadStep* step = AddStep();
115  if (fVerbose > 2)
116  step->Print();
117  }
118 
119  fELoss += gMC->Edep(); // GeV //Return the energy lost in the current step
120  fStepNb++;
121 
122  if (fStoreAllSteps) {
123  ERNeuRadStep* step = AddStep();
124  if (fVerbose > 2)
125  step->Print();
126  }
127  Double_t curLightYield = 0.;
128  // Apply Birk's law ( Adapted from G3BIRK/Geant3)
129  // Correction for all charge states
130  if (gMC->TrackCharge()!=0) { // Return the charge of the track currently transported
131  Double_t BirkC1Mod = 0;
132  // Apply correction for higher charge states
133  if (TMath::Abs(gMC->TrackCharge())>=2)
134  BirkC1Mod=BirkC1*7.2/12.6;
135  else
136  BirkC1Mod=BirkC1;
137 
138  if (gMC->TrackStep()>0){
139  Double_t dedxcm=gMC->Edep()*1000./gMC->TrackStep(); //[MeV/cm]
140  curLightYield=gMC->Edep()*1000./(1.+BirkC1Mod*dedxcm+BirkC2*dedxcm*dedxcm); //[MeV]
141  curLightYield /= 1000.; //[GeV]
142  fLightYield+=curLightYield;
143  }
144  }
145 
146  if (gMC->IsTrackExiting() || //true if this is the last step of the track in the current volume
147  gMC->IsTrackStop() || //true if the track energy has fallen below the threshold
148  gMC->IsTrackDisappeared()) {
149  FinishNewPoint();
150  }
151 
152  if (CurPointLen(fPosIn) > 4.) {
153  FinishNewPoint();
154  StartNewPoint();
155  }
156 
157  return kTRUE;
158 }
159 
160 //-------------------------------------------------------------------------------------------------
162  if (fVerbose > 1){
163  Print();
164  }
165 
166  FairRunSim* run = FairRunSim::Instance();
167  ERMCEventHeader* header = (ERMCEventHeader*)run->GetMCEventHeader();
168  header->SetNeuRadEloss(fFullEnergy);
169  header->SetNeuRadLY(fFullLY);
170 
171  Reset();
172 }
173 
174 //-------------------------------------------------------------------------------------------------
175 void ERNeuRad::Print(Option_t *option) const {
176  for (Int_t i_point = 0; i_point < fNeuRadPoints->GetEntriesFast(); i_point++) {
177  ERNeuRadPoint* point = (ERNeuRadPoint*)fNeuRadPoints->At(i_point);
178  point->Print();
179  }
180 }
181 
182 //-------------------------------------------------------------------------------------------------
184  fNeuRadPoints->Clear();
185  fNeuRadSteps->Clear();
186  fNeuRadFirstStep->Clear();
187  fFullEnergy = 0.;
188  fFullLY = 0.;
189 }
190 
191 //-------------------------------------------------------------------------------------------------
192 void ERNeuRad::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
193  Int_t nEntries = cl1->GetEntriesFast();
194  LOG(DEBUG) << "NeuRad: " << nEntries << " entries to add" << FairLogger::endl;
195  TClonesArray& clref = *cl2;
196  ERNeuRadPoint* oldpoint = NULL;
197  for (Int_t i=0; i<nEntries; i++) {
198  oldpoint = (ERNeuRadPoint*) cl1->At(i);
199  Int_t index = oldpoint->GetTrackID() + offset;
200  oldpoint->SetTrackID(index);
201  new (clref[cl2->GetEntriesFast()]) ERNeuRadPoint(*oldpoint);
202  }
203  LOG(DEBUG) << "NeuRad: " << cl2->GetEntriesFast() << " merged entries" << FairLogger::endl;
204 }
205 
206 //-------------------------------------------------------------------------------------------------
207 Bool_t ERNeuRad::CheckIfSensitive(std::string name) {
208  TString volName = name;
209  if(volName.Contains("fiber") /*&& !volName.Contains("dead") */) {
210  return kTRUE;
211  }
212  return kFALSE;
213 }
214 
215 //-------------------------------------------------------------------------------------------------
217  fELoss = 0.;
218  fLightYield = 0.;
219  fStepNb = 0;
220  fEventID = gMC->CurrentEvent();
221  gMC->TrackPosition(fPosIn);
222  gMC->TrackMomentum(fMomIn);
223  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
224  fTimeIn = gMC->TrackTime() * 1.0e09; //current time of flight of the track being transported
225  fTrackLength = gMC->TrackLength(); //length of the current track from its origin (in cm)
226  fMot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
227  fMass = gMC->ParticleMass(gMC->TrackPid()); // GeV/c2
228  Int_t curVolId, corOffVolId;
229  if(!(TString(gMC->CurrentVolOffName(1)).Contains("dead") &&
230  TString(gMC->CurrentVolOffName(2)).Contains("pixel"))) {
231  LOG(FATAL) << "Old version of geometry structure is used" << FairLogger::endl;
232  }
233 
234  curVolId = gMC->CurrentVolOffID(1,fFiberNb);
235  corOffVolId = gMC->CurrentVolOffID(2, fPixelNb);
236  corOffVolId = gMC->CurrentVolOffID(3, fModuleNb);
237 
238  //Пересчитываем номер пикселя если введены субмодули
239  if (TString(gMC->CurrentVolOffName(3)).Contains("submodul")){
240  Int_t pixel_in_submodule_X = 4;
241  Int_t pixel_in_submodule_Y = 4;
242  Int_t submodule_in_module_X = 2;
243  Int_t submodule_in_module_Y = 2;
244  Int_t pixel_row = fPixelNb/pixel_in_submodule_X;
245  Int_t pixel_col = fPixelNb%pixel_in_submodule_X;
246  Int_t subm_row = fModuleNb/submodule_in_module_X;
247  Int_t subm_col = fModuleNb%submodule_in_module_X;
248  fPixelNb = subm_row*submodule_in_module_X*pixel_in_submodule_X*pixel_in_submodule_Y
249  +pixel_row*submodule_in_module_X*pixel_in_submodule_X
250  +subm_col*pixel_in_submodule_X+pixel_col;
251  corOffVolId = gMC->CurrentVolOffID(4, fModuleNb);
252  }
253 
254  TGeoHMatrix matrix;
255  gMC->GetTransformation(gMC->CurrentVolPath(), matrix);
256  Double_t globalPos[3],localPos[3];
257  fPosIn.Vect().GetXYZ(globalPos);
258  matrix.MasterToLocal(globalPos,localPos);
259  fPosInLocal.SetXYZ(localPos[0],localPos[1],localPos[2]);
260 }
261 
262 //-------------------------------------------------------------------------------------------------
264  gMC->TrackPosition(fPosOut);
265  gMC->TrackMomentum(fMomOut);
266  fTimeOut = gMC->TrackTime() * 1.0e09;
267 
268  if (fELoss > 0.) {
269  AddPoint();
272  }
273 }
274 
275 //-------------------------------------------------------------------------------------------------
277  TClonesArray& clref = *fNeuRadPoints;
278  Int_t size = clref.GetEntriesFast();
279  return new(clref[size]) ERNeuRadPoint(fEventID, fTrackID, fMot0TrackID, fFiberNb,fPixelNb,
280  fModuleNb,fMass, fPosIn.Vect(),fPosInLocal,fPosOut.Vect(),fMomIn.Vect(),fMomOut.Vect(),fTimeIn,
281  fTimeOut,fTrackLength, fELoss, fLightYield,gMC->TrackPid(), gMC->TrackCharge());
282 }
283 
284 //-------------------------------------------------------------------------------------------------
286  TClonesArray& clref = *fNeuRadFirstStep;
287  fTrackStatus = ERNeuRadStep::GetTrackStatus();
288  gMC->StepProcesses(fProcessesID);
289  gMC->TrackPosition(fCurPosIn);
290  gMC->TrackMomentum(fCurMomIn);
292  fModuleNb,fCurPosIn.Vect(), fCurMomIn.Vect(), gMC->TrackTime() * 1.0e09, gMC->TrackStep(),
293  gMC->TrackPid(), gMC->TrackMass(), fTrackStatus, gMC->Edep(), gMC->TrackCharge(), fProcessesID);
294 }
295 
296 // ----- Private method AddStep --------------------------------------------
298  TClonesArray& clref = *fNeuRadSteps;
299  fTrackStatus = ERNeuRadStep::GetTrackStatus();
300  gMC->StepProcesses(fProcessesID);
301  gMC->TrackPosition(fCurPosIn);
302  gMC->TrackMomentum(fCurMomIn);
303  return new(clref[fNeuRadSteps->GetEntriesFast()])ERNeuRadStep(fEventID,fStepNb, fTrackID,
305  gMC->TrackTime() * 1.0e09, gMC->TrackStep(), gMC->TrackPid(), gMC->TrackMass(),fTrackStatus,
306  gMC->Edep(), gMC->TrackCharge(), fProcessesID);
307 }
308 
309 //-------------------------------------------------------------------------------------------------
310 Double_t ERNeuRad::CurPointLen(TLorentzVector& posIn) {
311  TLorentzVector posOut;
312  gMC->TrackPosition(posOut);
313  return TMath::Sqrt((posIn.X() - posOut.X())*(posIn.X() - posOut.X()) +
314  (posIn.Y() - posOut.Y())*(posIn.X() - posOut.X()) +
315  (posIn.Z() - posOut.Z())*(posIn.Z() - posOut.Z()));
316 }
317 
318 //-------------------------------------------------------------------------------------------------
319 ClassImp(ERNeuRad)
ExpertTrackingStatus fTrackStatus
curren track stutus (transport, stop, disappeared, ...)
Definition: ERNeuRad.h:198
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Copies the points collection with a given track index offset.
Definition: ERNeuRad.cxx:192
ERNeuRadStep * AddStep()
Adds a NeuRadStep to the Steps Collection.
Definition: ERNeuRad.cxx:297
TLorentzVector fMomOut
point start momentum
Definition: ERNeuRad.h:187
Float_t fFullEnergy
Sum Edep in event in sensetive volume.
Definition: ERNeuRad.h:171
Double_t fLightYield
light yield
Definition: ERNeuRad.h:193
Double_t fMass
mass
Definition: ERNeuRad.h:181
Double_t CurPointLen(TLorentzVector &posIn)
return current point length
Definition: ERNeuRad.cxx:310
void FinishNewPoint()
Finish point creation. Call AddPoint()
Definition: ERNeuRad.cxx:263
Int_t fMot0TrackID
0th mother track index
Definition: ERNeuRad.h:180
virtual void Register()
Register output array (NeuRadPoint) to the I/O manager Abstract from FairDetector.
Definition: ERNeuRad.cxx:85
TClonesArray * fNeuRadPoints
The point collection.
Definition: ERNeuRad.h:163
Int_t fFiberNb
number of fiber in pixel
Definition: ERNeuRad.h:194
virtual void EndOfEvent()
Action at end of event Short status log and Reset(). Virtual from FairDetector.
Definition: ERNeuRad.cxx:161
Int_t fPixelNb
number of pixel in module
Definition: ERNeuRad.h:195
TClonesArray * fNeuRadSteps
The steps collection.
Definition: ERNeuRad.h:165
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: ERNeuRad.cxx:96
virtual void Print(const Option_t *opt=0) const
TLorentzVector fPosOut
point finish position
Definition: ERNeuRad.h:183
virtual Bool_t CheckIfSensitive(std::string name)
Check whether a volume is sensitive.
Definition: ERNeuRad.cxx:207
ERNeuRadStep * AddFirstStep()
Adds a NeuRadStep to the PrimaryStep Collection.
Definition: ERNeuRad.cxx:285
Bool_t fStoreAllSteps
Flag to storing all steps in sensetive volume.
Definition: ERNeuRad.h:168
ERNeuRadPoint * AddPoint()
Adds a NeuRadPoint to the Point Collection.
Definition: ERNeuRad.cxx:276
virtual void Print(Option_t *option="") const
Screen log Prints NeuRadPoint information Virtual from TObject.
Definition: ERNeuRad.cxx:175
virtual void Initialize()
Initialisation class method FairDetector::Initialize() is called. NeuRadGeoPar init from RuntimeDB Vi...
Definition: ERNeuRad.cxx:78
Double32_t fTrackLength
track length from his origin
Definition: ERNeuRad.h:191
TLorentzVector fMomIn
point start momentum
Definition: ERNeuRad.h:186
Double32_t fTimeIn
point start time
Definition: ERNeuRad.h:189
virtual TClonesArray * GetCollection(Int_t iColl) const
Get array of ERNeuRadPoint.
Definition: ERNeuRad.cxx:70
virtual ~ERNeuRad()
Destructor.
Definition: ERNeuRad.cxx:62
Double32_t fELoss
energy loss
Definition: ERNeuRad.h:192
virtual void Reset()
Clears the point and steps collections Virtual from FairDetector.
Definition: ERNeuRad.cxx:183
Float_t fStep
Step length in sensetive volumes.
Definition: ERNeuRad.h:174
ERNeuRad()
Default constructor.
Definition: ERNeuRad.cxx:29
Int_t fStepNb
current step numb in this active volumes
Definition: ERNeuRad.h:197
Float_t fFullLY
Sum Light Yield in event in sensetive volume.
Definition: ERNeuRad.h:172
Class for the MC transport of the NeuRad.
Definition: ERNeuRad.h:39
TLorentzVector fPosIn
point start position
Definition: ERNeuRad.h:182
TArrayI fProcessesID
VMC prcess IDs in step.
Definition: ERNeuRad.h:199
TLorentzVector fCurMomIn
current step momentum
Definition: ERNeuRad.h:188
The data class for storing pieces of charged tracks in sensitive volumes in NeuRad.
Definition: ERNeuRadPoint.h:22
TVector3 fPosInLocal
point position in sensetive volume CS
Definition: ERNeuRad.h:185
void StartNewPoint()
Start new point creation. Reinit current point data.
Definition: ERNeuRad.cxx:216
Int_t fModuleNb
number of module in NeuRad
Definition: ERNeuRad.h:196
TClonesArray * fNeuRadFirstStep
The first step collection.
Definition: ERNeuRad.h:164
Bool_t fStorePrimarySteps
Flag to storing firs step in sensetive volume.
Definition: ERNeuRad.h:167
Int_t fTrackID
track index
Definition: ERNeuRad.h:179
Int_t fEventID
event index
Definition: ERNeuRad.h:178
Double32_t fTimeOut
point finish time
Definition: ERNeuRad.h:190
The base class for detector simulation in er sim.
Definition: ERDetector.h:32
Int_t fVerbose
Verbosity level.
Definition: ERNeuRad.h:169
TLorentzVector fCurPosIn
current step position
Definition: ERNeuRad.h:184