er  dev
ERND.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 "ERND.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 "FairLogger.h"
18 //--------------------------------------------------------------------------------------------------
20  : FairDetector("ERND", kTRUE)
21 {
22  LOG(INFO) << " ERND::ERND()" << FairLogger::endl;
23  fNDPoints = new TClonesArray("ERNDPoint");
24  flGeoPar = new TList();
25  flGeoPar->SetName( GetName());
26  fVerboseLevel = 1;
27 }
28 //--------------------------------------------------------------------------------------------------
29 ERND::ERND(const char* name, Bool_t active, Int_t verbose)
30  : FairDetector(name, active,verbose)
31 {
32  fNDPoints = new TClonesArray("ERNDPoint");
33  flGeoPar = new TList();
34  flGeoPar->SetName( GetName());
35 }
36 //--------------------------------------------------------------------------------------------------
38  if (fNDPoints) {
39  fNDPoints->Delete();
40  delete fNDPoints;
41  }
42 }
43 //--------------------------------------------------------------------------------------------------
45 {
46  FairDetector::Initialize();
47 }
48 //--------------------------------------------------------------------------------------------------
49 Bool_t ERND::ProcessHits(FairVolume* vol) {
50  // Set constants for Birk's Law implentation (Geant 4parametrization)
51  /*
52  static const Double_t dP = 1.032 ;
53  static const Double_t BirkC1 = 0.013/dP;
54  static const Double_t BirkC2 = 9.6e-6/(dP * dP);
55  */
56  //Birks constants from Craun, R. L.; Smith, D. L. NIM 80,2, p. 239, 1970
57  /*
58  static const Double_t dP = 0.97;
59  static const Double_t BirkC1 = 0.00856/dP;
60  static const Double_t BirkC2 = 4.99e-6/(dP * dP);
61  */
62  // Bircks constant from experiment. S. Belogurov, E. Gazeeva
63  static const Double_t dP = 1.16;
64  static const Double_t BirkC1 = 0.027/dP;
65  static const Double_t BirkC2 = 0.0/(dP * dP);
66 
67  static Int_t eventID;
68  static Int_t trackID;
69  static Int_t mot0TrackID;
70  static Int_t pdg;
71  static TLorentzVector posIn, posOut;
72  static TLorentzVector momIn, momOut;
73  static Double32_t time;
74  static Double32_t length;
75  static Double32_t eLoss;
76  static Int_t stilbenNr;
77  static Double_t lightYield;
78 
79  gMC->SetMaxStep(fStep);
80 
81  if ( gMC->IsTrackEntering() ) { // Return true if this is the first step of the track in the current volume
82  eLoss = 0.;
83  lightYield = 0.;
84  eventID = gMC->CurrentEvent();
85  gMC->TrackPosition(posIn);
86  gMC->TrackMomentum(momIn);
87  trackID = gMC->GetStack()->GetCurrentTrackNumber();
88  time = gMC->TrackTime() * 1.0e09; // Return the current time of flight of the track being transported
89  length = gMC->TrackLength(); // Return the length of the current track from its origin (in cm)
90  mot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
91  pdg = gMC->TrackPid();
92  gMC->CurrentVolOffID(3,stilbenNr);
93  }
94  const Double_t stepEloss = gMC->Edep() * 1000; // MeV //Return the energy lost in the current step
95  eLoss += stepEloss;
96  Double_t curLightYield = 0.;
97  // Apply Birk's law ( Adapted from G3BIRK/Geant3)
98  // Correction for all charge states
99  if (gMC->TrackCharge()!=0) { // Return the charge of the track currently transported
100  Double_t BirkC1Mod = 0;
101  // Apply correction for higher charge states
102  if (TMath::Abs(gMC->TrackCharge())>=2)
103  BirkC1Mod=BirkC1*7.2/12.6;
104  else
105  BirkC1Mod=BirkC1;
106 
107  if (gMC->TrackStep()>0)
108  {
109  Double_t dedxcm = stepEloss/gMC->TrackStep(); //[MeV/cm]
110  curLightYield = stepEloss /(1.+BirkC1Mod*dedxcm+BirkC2*dedxcm*dedxcm); //[MeV]
111  lightYield+=curLightYield;
112  }
113  }
114 
115  if (gMC->IsTrackExiting() || //Return true if this is the last step of the track in the current volume
116  gMC->IsTrackStop() || //Return true if the track energy has fallen below the threshold
117  gMC->IsTrackDisappeared())
118  {
119  gMC->TrackPosition(posOut);
120  gMC->TrackMomentum(momOut);
121 
122  if (eLoss > 0. && gMC->TrackCharge()!=0){
123  AddPoint( eventID, trackID, mot0TrackID, pdg,
124  TVector3(posIn.X(), posIn.Y(), posIn.Z()),
125  TVector3(posOut.X(), posOut.Y(), posOut.Z()),
126  TVector3(momIn.Px(), momIn.Py(), momIn.Pz()),
127  TVector3(momOut.Px(), momOut.Py(), momOut.Pz()),
128  time, length, eLoss, stilbenNr, lightYield);
129  }
130  }
131  return kTRUE;
132 }
133 //--------------------------------------------------------------------------------------------------
135  LOG(DEBUG) << "ND Points Count: " << fNDPoints->GetEntriesFast() << FairLogger::endl;
136  Print();
137  Reset();
138 }
139 //--------------------------------------------------------------------------------------------------
141  FairRootManager* ioman = FairRootManager::Instance();
142  if (!ioman)
143  Fatal("Init", "IO manager is not set");
144  ioman->Register("NDPoint","ND", fNDPoints, kTRUE);
145 }
146 //--------------------------------------------------------------------------------------------------
147 TClonesArray* ERND::GetCollection(Int_t iColl) const {
148  if (iColl == 0)
149  return fNDPoints;
150  else
151  return NULL;
152 }
153 //--------------------------------------------------------------------------------------------------
154 void ERND::Print(Option_t *option) const {
155  for (Int_t i_point = 0; i_point < fNDPoints->GetEntriesFast(); i_point++){
156  ERNDPoint* point = (ERNDPoint*)fNDPoints->At(i_point);
157  point->Print();
158  }
159 }
160 //--------------------------------------------------------------------------------------------------
161 void ERND::Reset() {
162  fNDPoints->Clear();
163 }
164 //--------------------------------------------------------------------------------------------------
165 void ERND::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
166  LOG(DEBUG) << " ERND::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)"
167  << FairLogger::endl;
168  Int_t nEntries = cl1->GetEntriesFast();
169  LOG(DEBUG) << "decector: " << nEntries << " entries to add" << FairLogger::endl;
170  TClonesArray& clref = *cl2;
171  ERNDPoint* oldpoint = NULL;
172  for (Int_t i=0; i<nEntries; i++) {
173  oldpoint = (ERNDPoint*) cl1->At(i);
174  Int_t index = oldpoint->GetTrackID() + offset;
175  oldpoint->SetTrackID(index);
176  new (clref[cl2->GetEntriesFast()]) ERNDPoint(*oldpoint);
177  }
178  LOG(DEBUG) << "decector: " << cl2->GetEntriesFast() << " merged entries" << FairLogger::endl;
179 }
180 //--------------------------------------------------------------------------------------------------
181 ERNDPoint* ERND::AddPoint(Int_t eventID, Int_t trackID,
182  Int_t mot0trackID,
183  Int_t pdg,
184  TVector3 posIn,
185  TVector3 posOut, TVector3 momIn,
186  TVector3 momOut, Double_t time,
187  Double_t length, Double_t eLoss, Int_t stilbenNr, Float_t lightYield) {
188  TClonesArray& clref = *fNDPoints;
189  Int_t size = clref.GetEntriesFast();
190  return new(clref[size]) ERNDPoint(eventID, trackID, mot0trackID, pdg,
191  posIn, posOut, momIn, momOut, time, length, eLoss,stilbenNr,lightYield);
192 
193 }
194 //--------------------------------------------------------------------------------------------------
196  TString fileName = GetGeometryFileName();
197  if(fileName.EndsWith(".root")) {
198  LOG(DEBUG) << "Constructing ERND geometry from ROOT file " << fileName.Data() << FairLogger::endl;
199  ConstructRootGeometry();
200  } else {
201  LOG(DEBUG) << "Geometry file name is not set" << FairLogger::endl;
202  }
203 
204 }
205 //--------------------------------------------------------------------------------------------------
206 Bool_t ERND::CheckIfSensitive(std::string name)
207 {
208  TString volName = name;
209  if(volName.Contains("crystal")) {
210  return kTRUE;
211  }
212 
213  return kFALSE;
214 }
215 //--------------------------------------------------------------------------------------------------
216 ClassImp(ERND)
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: ERND.cxx:49
virtual Bool_t CheckIfSensitive(std::string name)
Definition: ERND.cxx:206
virtual ~ERND()
Definition: ERND.cxx:37
virtual void EndOfEvent()
Definition: ERND.cxx:134
ERNDPoint * AddPoint(Int_t eventID, Int_t trackID, Int_t mot0trackID, Int_t pdg, TVector3 posIn, TVector3 pos_out, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Int_t stilbenNr, Float_t lightYield)
Max lengt of step of track propagetion in sensetive volume.
Definition: ERND.cxx:181
ERND()
Definition: ERND.cxx:19
Definition: ERND.h:21
virtual void Print(const Option_t *opt=0) const
Definition: ERNDPoint.cxx:61
virtual void Initialize()
Initialize ERND data.
Definition: ERND.cxx:44
virtual void Register()
Registers the point collection in the ROOT manager.
Definition: ERND.cxx:140
Double_t fStep
The point collection.
Definition: ERND.h:71
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition: ERND.cxx:165
virtual TClonesArray * GetCollection(Int_t iColl) const
Accessor to the point collection.
Definition: ERND.cxx:147
virtual void Reset()
Clears the point collection.
Definition: ERND.cxx:161
virtual void Print(Option_t *option="") const
Screen output of hit collection.
Definition: ERND.cxx:154
virtual void ConstructGeometry()
Constructs the ERND geometry.
Definition: ERND.cxx:195