FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairRadMapManager.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairRadMapManager source file -----
10 // -------------------------------------------------------------------------
11 
12 #include "FairRadMapManager.h"
13 
14 #include "FairRadMapPoint.h" // for FairRadMapPoint
15 #include "FairRootManager.h" // for FairRootManager
16 
17 #include <TClonesArray.h> // for TClonesArray
18 #include <TGeoManager.h> // for TGeoManager, gGeoManager
19 #include <TGeoVolume.h> // for TGeoVolume
20 #include <TMap.h> // for TMap
21 #include <TObjArray.h> // for TObjArray
22 #include <TObject.h> // for TObject
23 #include <TVector3.h> // for TVector3
24 #include <TVectorDfwd.h> // for TVectorD
25 #include <TVectorT.h> // for TVectorT
26 #include <TVirtualMC.h> // for TVirtualMC
27 #include <TVirtualMCStack.h> // for TVirtualMCStack
28 #include <iostream> // for operator<<, basic_ostream, etc
29 
30 using namespace std;
31 
33 
34 FairRadMapManager* FairRadMapManager::fgInstance = nullptr;
35 
37 {
39  return fgInstance;
40 }
41 
43  : fPointCollection(new TClonesArray("FairRadMapPoint"))
44  , fTrackID(0)
45  , fVolumeID(0)
46  , fPdg(0)
47  , fPosIn(TLorentzVector(0, 0, 0, 0))
48  , fPosOut(TLorentzVector(0, 0, 0, 0))
49  , fMomIn(TLorentzVector(0, 0, 0, 0))
50  , fMomOut(TLorentzVector(0, 0, 0, 0))
51  , fTime(0)
52  , fLength(0)
53  , fStep(0)
54  , fELoss(0)
55  , fDose(0)
56  , fDoseSL(0)
57  , fA(0)
58  , fZmat(0)
59  , fRadl(0)
60  , fDensity(0)
61  , fAbsl(0)
62  , fActVol(0)
63  , fActMass(0)
64  , fMassMap(nullptr)
65 {
67  if (nullptr == fgInstance) {
68  fgInstance = this;
69  // fPointCollection=new TClonesArray("FairRadMapPoint");
70  }
71 }
72 
74 {
76  fgInstance = nullptr;
77  fPointCollection->Delete();
78  delete fPointCollection;
79  delete fMassMap;
80 }
81 
83 {
85  FairRootManager::Instance()->Register("RadMap", "RadMapPoint", fPointCollection, kTRUE);
86  cout << "RadMapMan initialized" << endl;
87 
88  // compute once the masses of the volumes in this simulation and store them in a TMap object
89 
90  Int_t volumeiterator = 0, lastvolume = 0;
91  Double_t vmass;
92  TObjArray* volumelist;
93  TGeoVolume* myvolume;
94  const char* volumename;
95  fMassMap = new TMap(lastvolume + 1, 0);
96 
97  volumelist = gGeoManager->GetListOfVolumes();
98 
99  lastvolume = volumelist->GetLast();
100 
101  volumeiterator = 0;
102 
103  cout << "RadMapMan: calculating the masses for " << lastvolume << " volumes in this simulation" << endl;
104 
105  while (volumeiterator <= lastvolume) {
106  volumename = volumelist->At(volumeiterator)->GetName();
107  myvolume = gGeoManager->GetVolume(volumename);
108  vmass = myvolume->WeightA(); // calculate weight analytically
109  TVectorD* vomass = new TVectorD(1, 1, vmass, "END"); // 1-dim vector
110 
111  fMassMap->Add(myvolume, vomass);
112 
113  cout << myvolume->GetName() << " has " << vmass << " kg" << endl;
114 
115  volumeiterator++;
116  }
117 }
118 
120 {
122  fPointCollection->Delete();
123  cout << " FairRadMapManager::Reset() ------------------------------------------------\n" << endl;
124 }
125 
127 {
129  if (TVirtualMC::GetMC()->IsTrackEntering()) {
130  fELoss = 0.;
131  fStep = 0.;
132  fDose = 0.;
133  fDoseSL = 0.;
134  fPdg = 0;
135  fActVol = 0.;
136  fActMass = 0.;
137  Int_t copyNo;
138  fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo);
139  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
140  fLength = TVirtualMC::GetMC()->TrackLength();
141  TVirtualMC::GetMC()->TrackPosition(fPosIn);
142  TVirtualMC::GetMC()->TrackMomentum(fMomIn);
143  // Int_t MatId= TVirtualMC::GetMC()->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl);
144  TVirtualMC::GetMC()->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl);
145 
146  // if (!gGeoManager) { GetGeoManager(); }
147  // TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
148  TGeoVolume* actVolume = gGeoManager->GetVolume(fVolumeID);
149 
150  TVectorD* ActMass = static_cast<TVectorD*>(fMassMap->GetValue(actVolume));
151 
152  fActMass = ActMass->Min(); // read from TVectorD
153 
154  // cout << actVolume->GetName() << " has " << fActMass << " kg" << endl;
155  }
157  fELoss += TVirtualMC::GetMC()->Edep();
158  fStep += TVirtualMC::GetMC()->TrackStep();
159 
160  fPdg = TVirtualMC::GetMC()->TrackPid();
161 
162  // calculate the energy dose
163  // exclude fragments with PDG code >= 10000
164 
165  if (fPdg < 10000 && fStep > 0 && fActMass > 0) {
166  // fDose = fELoss*1.602e-10/(fDensity*actvol*0.001); // per mass/kg
167  fDose = fELoss * 1.602e-10 / (fActMass); // per mass/kg
168  } else {
169  fDose = -.00001;
170  }
171 
172  // exclude very high, probably wrong, energy doses
173  if (fDose > 0.02) {
174  fDose = -.00001;
175  }
176 
178  if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
179  || TVirtualMC::GetMC()->IsTrackDisappeared()) {
180 
181  // FairRadMapPoint* p=0;
182  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
183  Int_t copyNo;
184  Int_t fVolID = TVirtualMC::GetMC()->CurrentVolID(copyNo); // CAVEAT: fVolID is NOT an unique identifier!!
185  TVirtualMC::GetMC()->TrackPosition(fPosOut);
186  TVirtualMC::GetMC()->TrackMomentum(fMomOut);
187 
188  TClonesArray& clref = *fPointCollection;
189  Int_t tsize = clref.GetEntriesFast();
190 
191  // p=new(clref[tsize]) FairRadMapPoint(fTrackID, fVolID,
192  new (clref[tsize]) FairRadMapPoint(fTrackID,
193  fVolID,
194  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
195  TVector3(fMomIn.X(), fMomIn.Y(), fMomIn.Z()),
196  fTime,
197  fLength,
198  fELoss,
199  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
200  TVector3(fMomOut.X(), fMomOut.Y(), fMomOut.Z()),
201  fA,
202  fZmat,
203  fDensity,
204  fActMass,
205  fStep,
206  fDose,
207  fDoseSL,
208  fPdg);
209  }
210 }
static FairRadMapManager * Instance()
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
void AddPoint(Int_t &ModuleId)