GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GammaTracker.cpp
Go to the documentation of this file.
1 
2 #ifndef ROOT_TClass
3 #include <TClass.h>
4 #endif
5 
6 #ifndef ROOT_TROOT
7 #include <TROOT.h>
8 #endif
9 
10 #ifndef ROOT_TSystem
11 #include <TSystem.h>
12 #endif
13 
14 #ifndef GW_GAMMATRACKER_H
15 #include "GammaTracker.h"
16 #endif
17 
18 #include <iostream>
19 
20 #define MAXIMPACTS 1000
21 
22 using namespace Gw;
23 using namespace std;
24 
26 
27 GammaTracker::GammaTracker(const char *name,const char *title) : TNamed(name,title)
28 {
29 // fDoPacking = fDoSmearing = kTRUE;
30  MaxImpacts = MAXIMPACTS;
31 
32  InputN = 0;
33  InputE = new Double_t[MaxImpacts]; ::memset(InputE,0,sizeof(Double_t)*MaxImpacts);
34  InputDE = new Double_t[MaxImpacts]; ::memset(InputDE,0,sizeof(Double_t)*MaxImpacts);
35 
36  InputX = new Double_t[MaxImpacts]; ::memset(InputX,0,sizeof(Double_t)*MaxImpacts);
37  InputY = new Double_t[MaxImpacts]; ::memset(InputY,0,sizeof(Double_t)*MaxImpacts);
38  InputZ = new Double_t[MaxImpacts]; ::memset(InputZ,0,sizeof(Double_t)*MaxImpacts);
39  InputDX = new Double_t[MaxImpacts]; ::memset(InputDX,0,sizeof(Double_t)*MaxImpacts);
40  InputDY = new Double_t[MaxImpacts]; ::memset(InputDY,0,sizeof(Double_t)*MaxImpacts);
41  InputDZ = new Double_t[MaxImpacts]; ::memset(InputDZ,0,sizeof(Double_t)*MaxImpacts);
42 
43  OutputN = 0;
44  OutputE = new Double_t[MaxImpacts]; ::memset(OutputE,0,sizeof(Double_t)*MaxImpacts);
45  OutputTheta1 = new Double_t[MaxImpacts]; ::memset(OutputTheta1,0,sizeof(Double_t)*MaxImpacts);
46  OutputPhi1 = new Double_t[MaxImpacts]; ::memset(OutputPhi1,0,sizeof(Double_t)*MaxImpacts);
47  OutputTheta2 = new Double_t[MaxImpacts]; ::memset(OutputTheta2,0,sizeof(Double_t)*MaxImpacts);
48  OutputPhi2 = new Double_t[MaxImpacts]; ::memset(OutputPhi2,0,sizeof(Double_t)*MaxImpacts);
49 }
50 
52 {
53  if ( InputE ) { delete [] InputE; InputE = NULL; }
54  if ( InputX ) { delete [] InputX; InputX = NULL; }
55  if ( InputY ) { delete [] InputY; InputY = NULL; }
56  if ( InputZ ) { delete [] InputZ; InputZ = NULL; }
57  if ( InputDX ) { delete [] InputDX; InputDX = NULL; }
58  if ( InputDY ) { delete [] InputDY; InputDY = NULL; }
59  if ( InputDZ ) { delete [] InputDZ; InputDZ = NULL; }
60 
61  if ( InputDE ) { delete [] InputDE; InputDE = NULL; }
62 
63  if ( OutputE ) { delete [] OutputE; OutputE = NULL; }
64  if ( OutputTheta1 ){ delete [] OutputTheta1;OutputTheta1 = NULL; }
65  if ( OutputPhi1 ) { delete [] OutputPhi1; OutputPhi1 = NULL; }
66  if ( OutputTheta2) { delete [] OutputTheta2;OutputTheta2 = NULL; }
67  if ( OutputPhi2 ) { delete [] OutputPhi2; OutputPhi2 = NULL; }
68 }
69 
70 bool GammaTracker::Load(const char *classname, const char *pathtopackage, const char *libraryname)
71 {
72  if ( GammaTracker::IsTracker(classname) ) return true;
73 
74  TString name = classname, path = pathtopackage, libname = libraryname, tmp;
75 
76  if ( path.EndsWith("/") == kFALSE ) path += "/";
77 
78  // load the dynamic library
79  tmp = path + libname;
80  if ( gSystem->Load(tmp.Data()) < 0 ) {
81  cout << "Cannot find library " << libname << " in " << path << endl; return false;
82  }
83 
84  // add path to includes to compile the wrapper
85  tmp = ".include " + path ; gROOT->ProcessLine(tmp.Data());
86 
87  // try to compile the wrapper class
88  tmp = ".L "; tmp += classname; tmp += "Adapter.C+";
89  cout << " Trying to compile the Adapter: " << tmp << endl; gROOT->ProcessLine(tmp);
90 
91  // test if the class is now available
92  if ( GammaTracker::IsTracker(classname) ) {
93  cout << " " << classname << " is now available though GammaTracker::GetTracker " << endl; return true;
94  }
95  else {
96  cout << " " << classname << " is NOT available though GammaTracker::GetTracker " << endl; return false;
97  }
98 }
99 
100 
101 GammaTracker *GammaTracker::GetTracker(const char *classname)
102 {
103  GammaTracker *tracker = NULL;
104 
105  // known by the ROOT dictionnary
106  TClass *cl = gROOT->GetClass(classname);
107  if ( cl ) { tracker = (GammaTracker *)cl->New(); }
108 
109  return tracker;
110 }
111 
112 
113 UInt_t GammaTracker::SetEvent(UInt_t n, const Double_t *e, const Double_t *x, const Double_t *y, const Double_t *z, Double_t efactor, Double_t pfactor)
114 {
115  UInt_t i;
116  if ( n > (MaxImpacts-1) ) { InputN = 0; return InputN; } // to protect against too large input
117 
118  InputN = n;
119  if ( efactor == 1.0 ) { // no multiplication factor required
120  ::memcpy(InputE,e,sizeof(Double_t)*InputN); // no multiplication factor required
121  }
122  else {
123  for (i = 0; i < InputN; i++ ) { InputE[i] = e[i] * efactor; }
124  }
125 
126  if ( pfactor == 1.0 ) { // no multiplication factor required
127  ::memcpy(InputX,x,sizeof(Double_t)*n);
128  ::memcpy(InputY,y,sizeof(Double_t)*n);
129  ::memcpy(InputZ,z,sizeof(Double_t)*n);
130  }
131  else {
132  for (i = 0; i < InputN; i++ ) {
133  InputX[i] = x[i] * pfactor;
134  InputY[i] = y[i] * pfactor;
135  InputZ[i] = z[i] * pfactor;
136  }
137  }
138  ::memset(InputDE,0,sizeof(Double_t)*MaxImpacts);
139  ::memset(InputDX,0,sizeof(Double_t)*MaxImpacts);
140  ::memset(InputDY,0,sizeof(Double_t)*MaxImpacts);
141  ::memset(InputDZ,0,sizeof(Double_t)*MaxImpacts);
142 
143  return InputN;
144 }
146 {
147  cout << " list of inputs for GammaTracker " << endl;
148  for (UInt_t i = 0; i < InputN; i++ ) {
149  cout << " " << InputE[i] << endl;
150  cout << " " << InputX[i] << " " << InputY[i] << " " << InputZ[i] << endl;
151 
152  }
153  cout << " list of outputs for GammaTracker " << endl;
154  for (UInt_t i = 0; i < OutputN; i++ ) {
155  cout << " " << OutputE[i] << endl;
156  cout << " " << OutputTheta1[i] << " " << OutputPhi1[i] << " " << OutputTheta2[i] << " " << OutputPhi2[i] <<endl;
157  }
158 
159 }
160 
162 {
163  if ( InputN == 0 ) { OutputN = 0; return OutputN; }
164 
165  OutputN = 1; OutputE[0] = 0.0;
166  for (UInt_t i = 0; i < InputN; i++) { OutputE[0] += InputE[i]; }
167 
168  return OutputN;
169 }
170 
171 
172 
UInt_t OutputN
DZ positions.
Definition: GammaTracker.h:49
Base class to build tracker families.
Definition: GammaTracker.h:29
Double_t * InputZ
Y positions.
Definition: GammaTracker.h:44
virtual Int_t DoTracking()
to track the gamma-rays
Double_t * OutputPhi2
direction (theta) of the first scattered gamma-ray for polarisation
Definition: GammaTracker.h:54
GammaTracker(const char *name="GammaTracker", const char *title="Base to track gamma-rays")
direction (phi) of the first scattered gamma-ray for polarisation
static GammaTracker * GetTracker(const char *classname)
Interface to get a new tracker.
#define MAXIMPACTS
Double_t * InputDY
DX positions.
Definition: GammaTracker.h:46
Double_t * OutputPhi1
incoming direction (theta) of the reconstructed gamma-rays
Definition: GammaTracker.h:52
static bool IsTracker(const char *classname)
To know if a tracker is already loaded.
Definition: GammaTracker.h:70
UInt_t InputN
Units for energies.
Definition: GammaTracker.h:38
virtual UInt_t SetEvent(UInt_t n, const Double_t *e, const Double_t *x, const Double_t *y, const Double_t *z, Double_t efactor=1.0, Double_t pfactor=1.0)
Double_t * OutputTheta1
energies of the reconstructed gamma-rays
Definition: GammaTracker.h:51
ClassImp(GammaTracker)
Double_t * InputY
X positions.
Definition: GammaTracker.h:43
static bool Load(const char *classname, const char *pathtopackage, const char *libraryname)
To load an interface to a particular tracker.
Double_t * OutputE
of reconstructed gamma-rays
Definition: GammaTracker.h:50
Double_t * InputDE
energies
Definition: GammaTracker.h:40
Double_t * InputE
of impacts
Definition: GammaTracker.h:39
Double_t * InputDZ
DY positions.
Definition: GammaTracker.h:47
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual ~GammaTracker()
Double_t * InputX
errors on energies
Definition: GammaTracker.h:42
Double_t * InputDX
Z positions.
Definition: GammaTracker.h:45
Double_t * OutputTheta2
incoming direction (phi) of the reconstructed gamma-rays
Definition: GammaTracker.h:53