star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AgUStep.cxx
Go to the documentation of this file.
1 #include <functional>
2 
3 #include "TGeoManager.h"
4 #include "St_geant_Maker/St_geant_Maker.h"
5 #include "GeaRootIO/AgUStep.h"
6 
7 
9 
10 
11 extern "C" {
12 
13  void agustep_() {
14  if ( AgUStep::Instance() ) {
15  (*AgUStep::Instance())();
16  }
17  }
18 
19  struct Agcstep_t {
20 
21  Float_t vect0[7];
22  Float_t vloc0[7];
23  Float_t vloc[7];
24  Float_t xloc[7];
25  Float_t astep;
26  Float_t adestep;
27 
28  } agcstep_;
29 
30 }
31 
32 
33 #define agcstep agcstep_
34 
35 
36 Float_t AgUStep::rmin = 0.0;
37 Float_t AgUStep::rmax = 50.0;
38 
39 TGiant3 *AgUStep::geant3; // G3 VMC
40 Quest_t *AgUStep::cquest; // G3 Commons ...
41 Gclink_t *AgUStep::clink;
42 Gcflag_t *AgUStep::cflag;
43 Gcvolu_t *AgUStep::cvolu;
44 Gcnum_t *AgUStep::cnum;
45 Gcsets_t *AgUStep::csets;
46 Gckine_t *AgUStep::ckine;
47 Gcking_t *AgUStep::cking;
48 Gctrak_t *AgUStep::ctrak;
49 Gcmate_t *AgUStep::cmate;
50 Gccuts_t *AgUStep::ccuts;
51 Gcphys_t *AgUStep::cphys;
52 Int_t AgUStep::nlev;
53 
55 
57 {
58  if ( 0 == sInstance ) sInstance = new AgUStep();
59  return sInstance;
60 }
61 
62 
63 AgUStep::AgUStep() : TObject(),
64  mTree(0),
65  mFile(0),
66  mEvent( new TGeaEvent() ),
67  mTrack(0),
68  idEvent(-1)
69 {
70  geant3 = St_geant_Maker::instance()->Geant3();
72 
73  cquest = (Quest_t *) geant3->Quest();
74  clink = (Gclink_t *) geant3->Gclink();
75  cflag = (Gcflag_t *) geant3->Gcflag();
76  cvolu = (Gcvolu_t *) geant3->Gcvolu();
77  cnum = (Gcnum_t *) geant3->Gcnum();
78  csets = (Gcsets_t *) geant3->Gcsets();
79  ckine = (Gckine_t *) geant3->Gckine();
80  cking = (Gcking_t *) geant3->Gcking();
81  ctrak = (Gctrak_t *) geant3->Gctrak();
82  cmate = (Gcmate_t *) geant3->Gcmate();
83  ccuts = (Gccuts_t *) geant3->Gccuts();
84  cphys = (Gcphys_t *) geant3->Gcphys();
85 
86  oldEvent = -999;
87 
88 }
89 
90 
91 // Take a step through the G3 geometry
93 {
94  Double_t x = ctrak->vect[0];
95  Double_t y = ctrak->vect[1];
96 //Double_t z = ctrak->vect[2];
97 
98  Double_t r = TMath::Sqrt(x*x+y*y);
99  if (r > rmax) return; // track is exiting region of interest
100 
101  // Get current event
102  idEvent = geant3->CurrentEvent();
103 
104  // Detect new event and reset sums, clear event, etc...
105  if ( oldEvent != idEvent )
106  {
107 
108  if (mTree && idEvent>1) mTree->Fill(); // last event should be filled on finish
109 
110  mEvent->Clear("C"); // clear old event
111  aDeStep = 0; // clear sums etc...
112  aStep = 0;
113  idTruth = 0;
114  // LOG_INFO << "New Event " << idEvent << endm;
115  mEvent->idEvent = idEvent; // and set the event number
116  oldEvent = idEvent;
117  }
118 
119  // Detect a new track
120  if ( 0 == ctrak->sleng )
121  {
122  aDeStep = 0;
123  aStep = 0;
124  idTruth++;
125  // LOG_INFO << " New Track " << idTruth << endm;
126 
127  // Add track to this event
128  mTrack = mEvent->AddTrack();
130 
131  }
132 
133  aDeStep += ctrak->destep;
134  aStep += ctrak->step;
135 
136  // Add a new step to the track
137  assert(mTrack);
138 
139  if ( r < rmin ) return; // track has not entered region of interest
140 
141  TGeaStep *mStep = mTrack -> AddStep();
142 
143  mStep->adEstep = aDeStep;
144  mStep->dEstep = ctrak -> destep;
145  mStep->step = ctrak -> step;
146  mStep->state = ctrak->inwvol;
147  mStep->dens = cmate->dens;
148  mStep->relRadLength = ctrak->step / cmate->radl * 100.;
149 
150  if (!gGeoManager) return; // step through before complete init?
151 
152  // Print out current path...
153  //LOG_INFO << "N level = " << cvolu->nlevel << endm;
154  TString path = "";
155  for ( Int_t i=0;i<cvolu->nlevel;i++ )
156  {
157  path += "/";
158  Char_t buff[16];
159  memcpy( buff, &cvolu->names[i], sizeof(cvolu->names[i]) );
160 
161  TString volume; for ( Int_t ii=0;ii<4;ii++ ) volume += buff[ii];
162 
163  path += volume; path += "_";
164  path += cvolu->number[i];
165  }
166  // LOG_INFO << path.Data() << endm;
167 
168  std::hash<std::string> hash_fn;
169  mStep->volNameHash = hash_fn(std::string(path.Data()));
170 }
171 
172 
173 void AgUStep::Init( const Char_t *filename )
174 {
175  // LOG_INFO << "Initialize stepper with filename= " << filename << endm;
176  mFile = TFile::Open( filename, "recreate" );
177  mTree = new TTree( "stepping", "custom stepping tree" );
178  mTree->Branch("TGeaEvent", &mEvent, 32000, 99); // Add the event to the ttree
179 }
180 
181 
183 {
184  if (mTree&&mFile) {
185  mTree->Fill();
186 
187  mFile->cd();
188  mTree->Write();
189  // mFile->Write();
190  delete mFile;
191  }
192 }
static Quest_t * cquest
Definition: AgUStep.h:39
static Gcsets_t * csets
Definition: AgUStep.h:44
Int_t idEvent
Definition: TGeaEvent.h:27
Float_t dEstep
Definition: TGeaEvent.h:78
TGeaTrack * AddTrack()
Definition: TGeaEvent.cxx:31
ClassImp(AgUStep) extern"C"
Definition: AgUStep.cxx:8
void operator()()
Definition: AgUStep.cxx:92
Float_t adEstep
Definition: TGeaEvent.h:79
Float_t aDeStep
Definition: AgUStep.h:56
void Clear(const Option_t *opts="")
Definition: TGeaEvent.cxx:65
size_t volNameHash
Definition: TGeaEvent.h:83
static Gcphys_t * cphys
Definition: AgUStep.h:50
TGeaEvent * mEvent
Definition: AgUStep.h:35
static Float_t rmin
Definition: AgUStep.h:25
AgUStep()
Definition: AgUStep.cxx:63
void Init(const Char_t *filename="")
Initialize stepping routine. Opens TFile and creates TTree.
Definition: AgUStep.cxx:173
static TGiant3 * geant3
Pointer to all geant3 structures.
Definition: TGeaEvent.h:25
static Gcking_t * cking
Definition: AgUStep.h:46
Float_t dens
Definition: TGeaEvent.h:81
Int_t oldEvent
Definition: AgUStep.h:61
Int_t idTruth
Definition: AgUStep.h:55
Float_t step
Definition: TGeaEvent.h:80
static Gckine_t * ckine
Definition: AgUStep.h:45
static Int_t nlev
Definition: AgUStep.h:51
TGeaTrack * mTrack
Definition: AgUStep.h:36
Float_t relRadLength
Definition: TGeaEvent.h:82
static Gcflag_t * cflag
Definition: AgUStep.h:41
static AgUStep * Instance()
Definition: AgUStep.cxx:56
static Gccuts_t * ccuts
Definition: AgUStep.h:49
static Float_t rmax
Definition: AgUStep.h:26
void Finish()
Definition: AgUStep.cxx:182
static Gcvolu_t * cvolu
Definition: AgUStep.h:42
static Gcnum_t * cnum
Definition: AgUStep.h:43
static Gctrak_t * ctrak
Definition: AgUStep.h:47
TGeoManager * gGeoManager
Definition: stiscan.cc:18
Int_t idTruth
Definition: TGeaEvent.h:48
Int_t idEvent
Definition: AgUStep.h:54
static TGiant3 * geant3
Definition: AgUStep.h:38
static AgUStep * sInstance
Definition: AgUStep.h:30
static Gcmate_t * cmate
Definition: AgUStep.h:48
Float_t aStep
Definition: AgUStep.h:57
TTree * mTree
Definition: AgUStep.h:31
Int_t state
Definition: TGeaEvent.h:77
TFile * mFile
Definition: AgUStep.h:32
static Gclink_t * clink
Definition: AgUStep.h:40