GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FirstTracking.C
Go to the documentation of this file.
1 
20 #ifndef __CINT__
21 
22 #ifndef ROOT_TH1
23 #include "TH1.h"
24 #endif
25 #ifndef ROOT_TH2
26 #include "TH2.h"
27 #endif
28 #ifndef ROOT_TGeoManager
29 #include "TGeoManager.h"
30 #endif
31 #ifndef ROOT_TGeoTrack
32 #include "TGeoTrack.h"
33 #endif
34 
35 #endif
36 
37 #include "GeantLMOF.h"
38 #include "GammaTracker.h"
39 #include "XtermProgressBar.h"
40 
41 using namespace Gw;
42 
43 const char TRACKERNAME[] = "OFT"; // Tracker you would like to use for in these functions
44 
50 void EPTracking(const char *input, UInt_t mult = 1, UInt_t MaxEvents = 1000000)
51 {
52  const Int_t window = 2; // window to integrate peaks in the output spectrum
53 
54 // load the tacker you would like to use
56  if ( tracker == NULL ) {
57  cout << " Cannot run, unknown GammaTracker " << TRACKERNAME << endl; return;
58  }
59 
60 // input file(s) decoded by GeantLMOF reader
61  GeantLMOF reader; reader << fastout; reader.AddFile(input);
62 
63 // spectra definitions
64  const int BINRANGE = 2000; const Stat_t MINX = 0.; const Stat_t MAXX = 2000.;
65 
66  TH1F *hinput = new TH1F("Input","From Geant",BINRANGE,MINX,MAXX);
67  TH1F *houtput = new TH1F("Output","After Tracking",BINRANGE,MINX,MAXX);
68 
69  TH1F *ep = new TH1F("PhotopeakEfficiency","PhotopeakEfficiency",BINRANGE,MINX,MAXX);
70 
71 // start reading
72  XtermProgressBar progress(0,MaxEvents);
73 
74  while( reader.NextEvent(mult) ) { // loop on events
75 
76  progress++;
77 
78  // fill the tracker with the current event
79  reader >> tracker;
80  for (UInt_t i = 0; i < reader.NbEmitted(); i++ ) { // fill input
81  hinput->Fill(reader.GetEnerFactor()*reader.GetEnergy()[i]);
82  }
83 
84  // do the tracking
85  tracker->DoTracking();
86  for (UInt_t i = 0; i < tracker->GetOutputN(); i++ ) { // fill output
87  houtput->Fill(tracker->GetEnerFactor()*tracker->GetOutputE()[i]);
88  }
89 
90  if ( progress.IsFinished() ) break;
91 
92  } // while reader
93  cout << endl; reader.ShowCurrentConditions();
94 
95 // now compute photopeak efficiency
96  for(Int_t i = 0 ; i < BINRANGE ; i++ ){
97  if ( hinput->GetBinContent(i+1) > 1 ) {
98  Stat_t peak = houtput->Integral(i+1-window,i+1+window) -
99  0.5*(houtput->Integral(i-2*window,i-window)+houtput->Integral(i+window,i+2*window));
100 
101  ep->SetBinContent(i+1,peak/hinput->GetBinContent(i+1));
102  }
103  }
104 
105  delete tracker;
106 }
107 
115 void GGTracking(const char *input, UInt_t mult = 1, UInt_t MaxEvents = 1000000)
116 {
117 // load the tacker you would like to use
119  if ( tracker == NULL ) {
120  cout << " Cannot run, unknown GammaTracker " << TRACKERNAME << endl; return;
121  }
122 
123 // input file(s) decoded by GeantLMOF reader
124 // be carefull, fastout is called, remove this call is your GEANT file contains other particles that gammas
125  GeantLMOF reader; reader << fastout; reader.AddFile(input);
126 
127 // matrix definition
128  const int BINRANGE = 2000; const Stat_t MINX = 0.; const Stat_t MAXX = 2000.;
129  TH2F *matrix = new TH2F("GxG","Gamma-Gamma Matrix",BINRANGE, MINX, MAXX, BINRANGE, MINX, MAXX);
130 
131 // start reading
132  XtermProgressBar progress(0,MaxEvents);
133 
134  while( reader.NextEvent(mult) ) { // loop on events
135 
136  progress++;
137 
138  // fill the tracker with the current event
139  reader >> tracker;
140 
141  // do the tracking
142  tracker->DoTracking(); if ( tracker->GetOutputN() < 2 ) continue;
143 
144  for (UInt_t i = 0; i < tracker->GetOutputN(); i++ ) {
145  Float_t ecos1 = TMath::Cos(tracker->GetOutputTheta1()[i]);
146  Float_t edop1 = (tracker->GetEnerFactor()*tracker->GetOutputE()[i])
147  / ( 1 + reader.GetRecoilBeta() * ecos1 ) ;
148 
149  for (UInt_t j = i+1; j < tracker->GetOutputN(); j++ ) {
150 
151  Float_t ecos2 = TMath::Cos(tracker->GetOutputTheta1()[j]);
152  Float_t edop2 = (tracker->GetEnerFactor()*tracker->GetOutputE()[j])
153  / ( 1 + reader.GetRecoilBeta() * ecos2 ) ;
154 
155  matrix->Fill(edop1,edop2); matrix->Fill(edop2,edop1);
156  } // j
157  } // i
158 
159  if ( progress.IsFinished() ) break;
160  } // while reader
161  reader.ShowCurrentConditions();
162 
163  delete tracker;
164 }
165 
167 {
168  // the world is created first
169  TGeoManager *geom = new TGeoManager("Agata","AGATA");
170  TGeoMaterial *mat = new TGeoMaterial("Vacuum",0,0,0); TGeoMedium *med = new TGeoMedium("Vacuum",1,mat);
171 
172  TGeoVolume *top = gGeoManager->MakeBox("World",med,100,100,100); gGeoManager->SetTopVolume(top);
173 
174  // agata is added to the world
176 
177  // the geometry MUST be closed once defined !
178  geom->CloseGeometry();
179 }
180 
186 void VisuTrack(const char *input, UInt_t mult = 1, UInt_t MaxEvents = 10)
187 {
188 // the world is created first
189  TGeoManager *geom = new TGeoManager("Agata","AGATA");
190  TGeoMaterial *mat = new TGeoMaterial("Vacuum",0,0,0); TGeoMedium *med = new TGeoMedium("Vacuum",1,mat);
191 
192  TGeoVolume *top = gGeoManager->MakeBox("World",med,100,100,100); gGeoManager->SetTopVolume(top);
193 
194  // agata is added to the World
196 
197  // the geometry MUST be closed once defined !
198  geom->CloseGeometry();
199 
200 // input file(s) decoded by GeantLMOF reader
201  GeantLMOF reader; reader << fastout; reader.AddFile(input);
202 
203 // start reading
204  XtermProgressBar progress(0,MaxEvents);
205 
206  while( reader.NextEvent(mult) ) { // loop on events
207 
208  progress++; if ( reader.NbImpacts() < 1 ) continue;
209 
210  Int_t trackid = geom->AddTrack(Int_t(progress.GetCurrentPosition()),22); TVirtualGeoTrack *primary = geom->GetTrack(trackid);
211 
212  primary->AddPoint(0,0,0,0);
213  for( UInt_t i = 0; i < reader.NbImpacts() ; i++ ){
214  primary->AddPoint(reader.GetPx()[i]/10,reader.GetPy()[i]/10,reader.GetPz()[i]/10,0);
215 
216  }
217  if ( progress.IsFinished() ) break;
218  }
219  geom->GetTopVolume()->Draw("ogl");
220 }
221 
Base class to build tracker families.
Definition: GammaTracker.h:29
void AddFile(const char *fname)
to add an input file
Definition: GeantLMOF.h:178
virtual Double_t GetCurrentPosition() const
to get the current event number
GeantLMOF & fastout(GeantLMOF &reader)
Definition: GeantLMOF.h:208
virtual Int_t DoTracking()
to track the gamma-rays
Bool_t NextEvent(UInt_t mult=kMaxUInt)
To load the next event.
Definition: GeantLMOF.cpp:205
void VisuTrack(const char *input, UInt_t mult=1, UInt_t MaxEvents=10)
void TestImportAgata()
static GammaTracker * GetTracker(const char *classname)
Interface to get a new tracker.
Double_t GetEnerFactor() const
Definition: GeantLMOF.h:138
virtual bool IsFinished() const
to get the current event number
void GGTracking(const char *input, UInt_t mult=1, UInt_t MaxEvents=1000000)
This function built a gamma gamma matrix.
const char TRACKERNAME[]
Definition: FirstTracking.C:43
void ShowCurrentConditions()
The current status is shown on the standard ouptut.
Definition: GeantLMOF.cpp:58
static TGeoVolume * ImportAgataG4(const char *asolid="asolid", const char *aclust="aclust", const char *aeuler="aeuler", const char *top="World")
to import the agata geometry from the Agata-Geant4 world
Definition: GeantLMOF.cpp:53
const std::vector< Double_t > & GetPz()
Definition: GeantLMOF.h:154
const std::vector< Double_t > & GetPx()
Definition: GeantLMOF.h:152
const std::vector< Double_t > & GetEnergy()
Definition: GeantLMOF.h:146
void EPTracking(const char *input, UInt_t mult=1, UInt_t MaxEvents=1000000)
This function computes the photopeak efficiency for a given multipliciy.
Definition: FirstTracking.C:50
Class to display a progress bar on the command line.
Class to read/decode Geant List Mode Output Files.
Definition: GeantLMOF.h:59
UInt_t NbEmitted() const
Definition: GeantLMOF.h:143
ADF::LogMessage & endl(ADF::LogMessage &log)
const std::vector< Double_t > & GetPy()
Definition: GeantLMOF.h:153
UInt_t NbImpacts() const
Definition: GeantLMOF.h:144