er  dev
ERGadast.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 "ERGadast.h"
10 
11 #include "TClonesArray.h"
12 #include "TVirtualMC.h"
13 #include "TString.h"
14 #include "TLorentzVector.h"
15 
16 #include "FairRootManager.h"
17 #include "FairRun.h"
18 #include "FairRuntimeDb.h"
19 #include "FairLogger.h"
20 
21 #include "ERGadastGeoPar.h"
22 
23 //--------------------------------------------------------------------------------------------------
25  ERDetector("ERGadast", kTRUE),
26  fCsIPoints(new TClonesArray("ERGadastCsIPoint")),
27  fLaBrPoints(new TClonesArray("ERGadastLaBrPoint")),
28  fGadastSteps(new TClonesArray("ERGadastStep")),
29  fStoreSteps(kFALSE)
30 {
31  flGeoPar->SetName( GetName());
32  flGeoPar = new TList();
33  fVerboseLevel = 1;
34 }
35 
36 //--------------------------------------------------------------------------------------------------
37 ERGadast::ERGadast(const char* name, Bool_t active, Int_t verbose):
38  ERDetector(name, active),
39  fCsIPoints(new TClonesArray("ERGadastCsIPoint")),
40  fLaBrPoints(new TClonesArray("ERGadastLaBrPoint")),
41  fGadastSteps(new TClonesArray("ERGadastStep")),
42  fStoreSteps(kFALSE)
43 {
44  flGeoPar->SetName( GetName());
45  flGeoPar = new TList();
46  fVerboseLevel = verbose;
47 }
48 
49 //--------------------------------------------------------------------------------------------------
51  if (fCsIPoints) {
52  fCsIPoints->Delete();
53  delete fCsIPoints;
54  }
55  if (fLaBrPoints) {
56  fLaBrPoints->Delete();
57  delete fLaBrPoints;
58  }
59  if (fGadastSteps){
60  fGadastSteps->Delete();
61  delete fGadastSteps;
62  }
63 }
64 
65 //--------------------------------------------------------------------------------------------------
67  FairDetector::Initialize();
68  FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
69  ERGadastGeoPar* par=(ERGadastGeoPar*)(rtdb->getContainer("ERGadastGeoPar"));
70 }
71 
72 //--------------------------------------------------------------------------------------------------
73 Bool_t ERGadast::ProcessHits(FairVolume* vol) {
74  //Start point
75  if ( gMC->IsTrackEntering() ) { // Return true if this is the first step of the track in sen. vol.
76  StartPoint();
77  }
78 
79  if (fStoreSteps) {
80  AddStep();
81  return kTRUE;
82  }
83  fELoss += gMC->Edep() * 1e3; // MeV //Return the energy lost in the current step
84 
85  //finish point
86  if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
87  FinishPoint();
88  }
89  fStepNr++;
90 }
91 
92 //--------------------------------------------------------------------------------------------------
94  fELoss = 0.;
95  fEventID = gMC->CurrentEvent();
96 
97  TLorentzVector pos, mom;
98 
99  gMC->TrackPosition(pos);
100  gMC->TrackMomentum(mom);
101  fPosIn = pos.Vect();
102  fMomIn = mom.Vect();
103 
104  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
105  fTime = gMC->TrackTime() * 1.0e09;// Return the current time track being transported
106  fLength = gMC->TrackLength(); // Return the length of the current track from its origin (in cm)
107  fMot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
108  fMass = gMC->ParticleMass(gMC->TrackPid()); // GeV/c2
109 
110  if (TString(gMC->CurrentVolName()).Contains("LaBrcell_cell"))
111  fDetectorType = LaBr;
112  else
113  fDetectorType = CsI;
114 
115  fPDG = gMC->TrackPid();
116  fStepNr = 0;
117  if(fDetectorType == CsI){
118  gMC->CurrentVolOffID(1, fCsICell);
119  gMC->CurrentVolOffID(2, fCsIBlock);
120  gMC->CurrentVolOffID(3, fCsIWall);
121  }
122  else{
123  gMC->CurrentVolID(fLaBrCell);
124  }
125 }
126 
127 //--------------------------------------------------------------------------------------------------
129  TLorentzVector pos, mom;
130 
131  gMC->TrackPosition(pos);
132  gMC->TrackMomentum(mom);
133  fPosOut = pos.Vect();
134  fMomOut = mom.Vect();
135 
136  if (fELoss > 0.){
137  if(fDetectorType == 0)
138  AddCsIPoint();
139  if(fDetectorType == 1)
140  AddLaBrPoint();
141  }
142 }
143 
144 //--------------------------------------------------------------------------------------------------
146  if (fVerboseLevel > 1) {
147  Print();
148  }
149 
150  Reset();
151 }
152 
153 //--------------------------------------------------------------------------------------------------
155  FairRootManager* ioman = FairRootManager::Instance();
156  if (!ioman)
157  LOG(FATAL) << "IO manager is not set" << FairLogger::endl;
158  ioman->Register("GadastCsIPoint","ERGadast", fCsIPoints, kTRUE);
159  ioman->Register("GadastLaBrPoint","ERGadast", fLaBrPoints, kTRUE);
160  ioman->Register("GadastStep","ERGadast", fGadastSteps, kTRUE);
161 }
162 
163 //--------------------------------------------------------------------------------------------------
164 TClonesArray* ERGadast::GetCollection(Int_t iColl) const {
165  if (iColl == 0)
166  return fCsIPoints;
167  if (iColl == 1)
168  return fLaBrPoints;
169  return NULL;
170 }
171 
172 //--------------------------------------------------------------------------------------------------
173 void ERGadast::Print(Option_t *option) const {
174  if (fCsIPoints->GetEntriesFast() > 0){
175  LOG(INFO) << "======== CsI Points ==================" << FairLogger::endl;
176  for (Int_t i_point = 0; i_point < fCsIPoints->GetEntriesFast(); i_point++){
177  ERGadastCsIPoint* point = (ERGadastCsIPoint*)fCsIPoints->At(i_point);
178  point->Print();
179  }
180  }
181 
182  if (fLaBrPoints->GetEntriesFast() > 0){
183  LOG(INFO) << "======== LaBr Points =================" << FairLogger::endl;
184  for (Int_t i_point = 0; i_point < fLaBrPoints->GetEntriesFast(); i_point++){
185  ERGadastLaBrPoint* point = (ERGadastLaBrPoint*)fLaBrPoints->At(i_point);
186  point->Print();
187  }
188  }
189 }
190 
191 //--------------------------------------------------------------------------------------------------
193  fCsIPoints->Clear();
194  fLaBrPoints->Clear();
195  fGadastSteps->Clear();
196 }
197 
198 //--------------------------------------------------------------------------------------------------
199 void ERGadast::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
200  Int_t nEntries = cl1->GetEntriesFast();
201  LOG(DEBUG) << "ERGadast: " << nEntries << " entries to add" << FairLogger::endl;
202  TClonesArray& clref = *cl2;
203  ERGadastCsIPoint* oldpoint = NULL;
204  for (Int_t i=0; i<nEntries; i++) {
205  oldpoint = (ERGadastCsIPoint*) cl1->At(i);
206  Int_t index = oldpoint->GetTrackID() + offset;
207  oldpoint->SetTrackID(index);
208  new (clref[cl2->GetEntriesFast()]) ERGadastCsIPoint(*oldpoint);
209  }
210  LOG(DEBUG) << "ERGadast: " << cl2->GetEntriesFast() << " merged entries" << FairLogger::endl;
211 }
212 
213 //--------------------------------------------------------------------------------------------------
215  TClonesArray& clref = *fCsIPoints;
216  Int_t size = clref.GetEntriesFast();
217  return new(clref[size]) ERGadastCsIPoint(fEventID, fTrackID, fMot0TrackID, fMass,
218  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
219  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
220  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
221  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
223 
224 }
225 
226 //--------------------------------------------------------------------------------------------------
228  TClonesArray& clref = *fLaBrPoints;
229  Int_t size = clref.GetEntriesFast();
230  return new(clref[size]) ERGadastLaBrPoint(fEventID, fTrackID, fMot0TrackID, fMass,
231  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
232  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
233  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
234  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
236 
237 
238 }
239 
240 //--------------------------------------------------------------------------------------------------
242 
243  TClonesArray& clref = *fGadastSteps;
244  //Fill step info
245  ExpertTrackingStatus trackStatus = ERGadastStep::GetTrackStatus();
246  TArrayI processesID;
247  gMC->StepProcesses(processesID);
248  TLorentzVector curPosIn;
249  TLorentzVector curMomIn;
250  gMC->TrackPosition(curPosIn);
251  gMC->TrackMomentum(curMomIn);
252 
253 
254  return new(clref[fGadastSteps->GetEntriesFast()])
256  TVector3(curPosIn.X(), curPosIn.Y(), curPosIn.Z()),
257  TVector3(curMomIn.X(), curMomIn.Y(), curMomIn.Z()),
258  gMC->TrackTime() * 1.0e09, gMC->TrackStep(), gMC->TrackPid(),
259  fMass,trackStatus,gMC->Edep(),gMC->TrackCharge(),processesID);
260 }
261 
262 //--------------------------------------------------------------------------------------------------
263 Bool_t ERGadast::CheckIfSensitive(std::string name) {
264  TString volName = name;
265  if(volName.Contains("LaBrcell_cell")) {
266  return kTRUE;
267  }
268  if(volName.Contains("onecell_cell")) { //CsI
269  return kTRUE;
270  }
271  return kFALSE;
272 }
273 
274 //--------------------------------------------------------------------------------------------------
275 ClassImp(ERGadast)
void FinishPoint()
Finish point creation. Call AddCsIPoint() or AddLaBrPoint()
Definition: ERGadast.cxx:128
virtual void Print(const Option_t *opt=0) const
Print point information to screen.
Class for the MC transport of the Gadast.
Definition: ERGadast.h:33
Int_t fStepNr
current step numb in this active volumes
Definition: ERGadast.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 ERGadastPoint and adds it to the collection.
Definition: ERGadast.cxx:73
Int_t fCsIBlock
CsI Block number.
Definition: ERGadast.h:168
Int_t fCsICell
CsI Cell number.
Definition: ERGadast.h:169
TClonesArray * fLaBrPoints
The LaBr point collection.
Definition: ERGadast.h:146
virtual void EndOfEvent()
Action at end of event Short status log and Reset(). Virtual from FairDetector.
Definition: ERGadast.cxx:145
void StartPoint()
Start new point creation. Reinit current point data.
Definition: ERGadast.cxx:93
virtual void Initialize()
Initialisation class method FairDetector::Initialize() is called. GadastGeoPar init from RuntimeDB Vi...
Definition: ERGadast.cxx:66
TClonesArray * fGadastSteps
The all steps collection.
Definition: ERGadast.h:147
virtual void Print(Option_t *option="") const
Screen log Prints GadastPoint information Virtual from TObject.
Definition: ERGadast.cxx:173
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Copies the points collection with a given track index offset.
Definition: ERGadast.cxx:199
virtual void Print(const Option_t *opt=0) const
SensetiveType fDetectorType
CsI or LaBr point.
Definition: ERGadast.h:166
Double32_t fLength
track length from his origin
Definition: ERGadast.h:162
Int_t fTrackID
track index
Definition: ERGadast.h:154
The data class for storing pieces of charged tracks in sensitive volumes in CsI crystall.
virtual Bool_t CheckIfSensitive(std::string name)
Check whether a volume is sensitive.
Definition: ERGadast.cxx:263
Int_t fLaBrCell
laBr Cell number
Definition: ERGadast.h:170
virtual void Reset()
Clears the point and steps collections Virtual from FairDetector.
Definition: ERGadast.cxx:192
ERGadastStep * AddStep()
Adds a GadastStep to the Step Collection.
Definition: ERGadast.cxx:241
Int_t fEventID
event index
Definition: ERGadast.h:153
Int_t fPDG
particle PDG
Definition: ERGadast.h:164
TClonesArray * fCsIPoints
The CsI point collection.
Definition: ERGadast.h:145
Double_t fMass
mass
Definition: ERGadast.h:156
TVector3 fPosIn
point start position
Definition: ERGadast.h:157
Bool_t fStoreSteps
Flag to storing all steps in sensetive volume.
Definition: ERGadast.h:149
TVector3 fMomOut
point finish momentum
Definition: ERGadast.h:160
Int_t fMot0TrackID
0th mother track index
Definition: ERGadast.h:155
virtual ~ERGadast()
Destructor.
Definition: ERGadast.cxx:50
Double32_t fELoss
energy loss
Definition: ERGadast.h:163
ERGadastLaBrPoint * AddLaBrPoint()
Adds a GadastLaBrPoint to the Point Collection.
Definition: ERGadast.cxx:227
ERGadastCsIPoint * AddCsIPoint()
Adds a GadastCsIPoint to the Point Collection.
Definition: ERGadast.cxx:214
TVector3 fPosOut
point finish position
Definition: ERGadast.h:158
virtual TClonesArray * GetCollection(Int_t iColl) const
Get array of ERGadastPoint.
Definition: ERGadast.cxx:164
TVector3 fMomIn
point start momentum
Definition: ERGadast.h:159
ERGadast()
Default constructor.
Definition: ERGadast.cxx:24
The base class for detector simulation in er sim.
Definition: ERDetector.h:32
virtual void Register()
Register output array (NeuRadPoint) to the I/O manager Abstract from FairDetector.
Definition: ERGadast.cxx:154
Double32_t fTime
point start time
Definition: ERGadast.h:161
Int_t fCsIWall
CsI Wall number.
Definition: ERGadast.h:167