EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairRadMapManager.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairRadMapManager.cxx
1 // -------------------------------------------------------------------------
2 // ----- FairRadMapManager source file -----
3 // -------------------------------------------------------------------------
4 
5 #include <iostream>
6 #include "FairRadMapPoint.h"
7 #include "FairRadMapManager.h"
8 #include "FairRootManager.h"
9 #include "TLorentzVector.h"
10 #include "TParticle.h"
11 #include "TVirtualMC.h"
12 #include "TROOT.h"
13 #include "TGeoManager.h"
14 #include "TGeoVolume.h"
15 #include "TVectorD.h"
16 
17 using namespace std;
18 
19 
21 
22 FairRadMapManager* FairRadMapManager::fgInstance = NULL;
23 
25 {
27  return fgInstance;
28 }
29 
31  : fPointCollection(new TClonesArray("FairRadMapPoint")),
32  fTrackID(0),
33  fVolumeID(0),
34  fPdg(0),
35  fPosIn(TLorentzVector(0,0,0,0)),
36  fPosOut(TLorentzVector(0,0,0,0)),
37  fMomIn(TLorentzVector(0,0,0,0)),
38  fMomOut(TLorentzVector(0,0,0,0)),
39  fTime(0),
40  fLength(0),
41  fStep(0),
42  fELoss(0),
43  fDose(0),
44  fDoseSL(0),
45  fA(0),
46  fZmat(0),
47  fRadl(0),
48  fDensity(0),
49  fAbsl(0),
50  fActVol(0),
51  fActMass(0),
52  fMassMap(NULL)
53 {
55  if(NULL == fgInstance) {
56  fgInstance = this;
57  // fPointCollection=new TClonesArray("FairRadMapPoint");
58  }
59 
60 }
61 
62 
64 {
66  fgInstance = NULL;
67  fPointCollection->Delete();
68  delete fPointCollection;
69  delete fMassMap;
70 }
71 
73 {
75  FairRootManager::Instance()->Register("RadMap","RadMapPoint", fPointCollection, kTRUE);
76  cout << "RadMapMan initialized" << endl;
77 
78  // compute once the masses of the volumes in this simulation and store them in a TMap object
79 
80  Int_t volumeiterator=0,lastvolume=0;
81  Double_t vmass;
82  TObjArray* volumelist;
83  TGeoVolume* myvolume;
84  const char* volumename;
85  fMassMap = new TMap(lastvolume+1,0);
86 
87  volumelist = gGeoManager->GetListOfVolumes();
88 
89  lastvolume = volumelist->GetLast();
90 
91  volumeiterator=0;
92 
93  cout << "RadMapMan: calculating the masses for " << lastvolume << " volumes in this simulation" << endl;
94 
95  while ( volumeiterator<=lastvolume ) {
96  volumename = volumelist->At(volumeiterator)->GetName();
97  myvolume = gGeoManager->GetVolume(volumename);
98  vmass = myvolume->WeightA(); // calculate weight analytically
99  TVectorD* vomass= new TVectorD(1,1,vmass,"END"); // 1-dim vector
100 
101  fMassMap->Add(myvolume,vomass);
102 
103  cout << myvolume->GetName() << " has " << vmass << " kg" << endl;
104 
105  volumeiterator++;
106  }
107 
108 }
109 
111 {
113  fPointCollection->Delete();
114  printf(" FairRadMapManager::Reset() ------------------------------------------------\n");
115 }
116 
117 void FairRadMapManager::AddPoint(Int_t& ModuleId)
118 {
120  if ( gMC->IsTrackEntering() ) {
121  fELoss = 0.;
122  fStep = 0.;
123  fDose = 0.;
124  fDoseSL = 0.;
125  fPdg = 0;
126  fActVol = 0.;
127  fActMass = 0.;
128  Int_t copyNo;
129  fVolumeID = gMC->CurrentVolID(copyNo);
130  fTime = gMC->TrackTime() * 1.0e09;
131  fLength = gMC->TrackLength();
132  gMC->TrackPosition(fPosIn);
133  gMC->TrackMomentum(fMomIn);
134  // Int_t MatId= gMC->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl);
135  gMC->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl);
136 
137  // if (!gGeoManager) { GetGeoManager(); }
138  // TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
139  TGeoVolume* actVolume = gGeoManager->GetVolume(fVolumeID);
140 
141  TVectorD* ActMass = (TVectorD*)fMassMap->GetValue(actVolume);
142 
143  fActMass = ActMass->Min(); // read from TVectorD
144 
145  // cout << actVolume->GetName() << " has " << fActMass << " kg" << endl;
146 
147  }
149  fELoss += gMC->Edep();
150  fStep += gMC->TrackStep();
151 
152  fPdg = gMC->TrackPid();
153 
154  // calculate the energy dose
155  // exclude fragments with PDG code >= 10000
156 
157  if (fPdg<10000 && fStep>0 && fActMass>0 ) {
158  // fDose = fELoss*1.602e-10/(fDensity*actvol*0.001); // per mass/kg
159  fDose = fELoss*1.602e-10/(fActMass); // per mass/kg
160  } else {
161  fDose = -.00001;
162  }
163 
164  // exclude very high, probably wrong, energy doses
165  if ( fDose>0.02 ) {
166  fDose = -.00001;
167  }
168 
170  if ( gMC->IsTrackExiting() ||
171  gMC->IsTrackStop() ||
172  gMC->IsTrackDisappeared() ) {
173 
174  FairRadMapPoint* p=0;
175  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
176  Int_t copyNo;
177  Int_t fVolID = gMC->CurrentVolID(copyNo); // CAVEAT: fVolID is NOT an unique identifier!!
178  gMC->TrackPosition(fPosOut);
179  gMC->TrackMomentum(fMomOut);
180 
181  TClonesArray& clref = *fPointCollection;
182  Int_t tsize = clref.GetEntriesFast();
183 
184  p=new(clref[tsize]) FairRadMapPoint(fTrackID, fVolID,
185  TVector3(fPosIn.X(),fPosIn.Y(),fPosIn.Z()),
186  TVector3(fMomIn.X(),fMomIn.Y(),fMomIn.Z()),
187  fTime, fLength, fELoss,
188  TVector3(fPosOut.X(),fPosOut.Y(),fPosOut.Z()),
189  TVector3(fMomOut.X(),fMomOut.Y(),fMomOut.Z()),
191 
192  }
193 
194 }
195 
196