HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TpcSimIonisationChamber.cxx
Go to the documentation of this file.
1 #include "TMath.h"
2 #include "TRandom.h"
3 
4 #include "HarpoConfig.h"
5 #include "HarpoDebug.h"
6 #include "TpcSimMCEvent.h"
9 
10 
11 #ifdef HARPO_G4
12 #include "DetectorConstruction.hh"
13 #include "PhysicsList.hh"
14 #include "PrimaryGeneratorAction.hh"
15 #include "RunAction.hh"
16 #include "EventAction.hh"
17 #endif
18 
19 #include <iostream>
20 #include <fstream>
21 
22 //using namespace std;
23 
25 
27 {
28 
29  fGeom = new TpcSimGeometry();
30 
31  fIpot = 15;
32  fW = 25;
33  fFano = 0;
34 
35  fMfp = 1./3.641661E+01; // MFP [1/cm]
36 
37  Double_t ipot;
38  if ( ! gHConfig->Lookup("Sim.Ipot",ipot) )
39  Info("Constructor","Use default Ipot %g",fIpot);
40  else
41  fIpot = ipot;
42 
43  Double_t w;
44  if ( ! gHConfig->Lookup("Sim.W",w) )
45  Info("Constructor","Use default W %g",fW);
46  else
47  fW = w;
48 
49  Double_t fano;
50  if ( ! gHConfig->Lookup("Sim.Fano",fano) )
51  Info("Constructor","Use default Fano %g",fFano);
52  else
53  fFano = fano;
54 
55  Double_t mfp;
56  if ( ! gHConfig->Lookup("Sim.Mfp",mfp) )
57  Info("Constructor","Use default Mfp %g",fMfp);
58  else
59  fMfp = mfp;
60 
61  fModuleX = 0;
62  fModuleY = 0;
63  fModuleZ = 0;
64 
65  Long64_t cx;
66  if ( ! gHConfig->Lookup("Sim.ModuleX",cx) )
67  Info("Constructor","Use default ModuleX %d",fModuleX);
68  else
69  fModuleX = cx;
70  Long64_t cy;
71 
72  if ( ! gHConfig->Lookup("Sim.ModuleY",cy) )
73  Info("Constructor","Use default ModuleY %d",fModuleY);
74  else
75  fModuleY = cy;
76 
77  Long64_t cz;
78  if ( ! gHConfig->Lookup("Sim.ModuleZ",cz) )
79  Info("Constructor","Use default ModuleZ %d",fModuleZ);
80  else
81  fModuleZ = cz;
82 
83 
84 }
85 
87 {
88  if(gHarpoDebug>0)
89  Info("~TpcSimIonisationChamber","Deleting");
90  fGeom->Delete();
91 }
92 
93 
95 {
96  if(gHarpoDebug>1)
97  Info("GenerateTrack","start");
98 
100 
101  Double_t x = tr->GetX0(), y = tr->GetY0(), z = tr->GetZ0(), t = tr->GetT0();
102  Double_t px = tr->GetPx(), py = tr->GetPy(), pz = tr->GetPz();
103  Double_t p = TMath::Sqrt(px*px+py*py+pz*pz);
104  Double_t d = 0;
105  Double_t dMax = 10000;
106  if(gHarpoDebug>1)
107  Info("GenerateTrack","%f %f %f %f %f %f %f",x,y,z,t,px,py,pz);
108  Bool_t notyet = kTRUE;
109  Int_t isin = 0;
110  while((notyet || isin==1) && d<dMax){
111  isin = fGeom->GetVolume(x,y,z);
112  if(isin==1) notyet = kFALSE;
113 
114  Double_t l = fMfp*gRandom->Exp(1); // *
115  Double_t dx = l*px/p;
116  Double_t dy = l*py/p;
117  Double_t dz = l*pz/p;
118 
119  x += dx; y += dy; z += dz; d += l;
120 
121  Double_t eloss = GetEloss();
122  Int_t Ne = GetNe(eloss);
123 
124  TpcSimIonisationPoint* point = new TpcSimIonisationPoint(Ne,x,y,z,t,eloss,0);
125  trackout->AddPoint(point);
126  }
127 
128  if(gHarpoDebug>1)
129  Info("GenerateTrack","End track %d %d %f",notyet,isin,d);
130 
131  return trackout;
132 
133 }
134 
135 //TpcSimIonisationTrack* TpcSimIonisationChamber::GenerateTrackFromText(ifstream *str, TpcSimMCEvent* mcevent)
137 {
138  if(gHarpoDebug>1)
139  Info("GenerateTrackFromText","start");
140 
141 
142  if(!str->good())
143  return 0;
144  Char_t line[256];
145  str->getline(line,256);
146  if(strstr(line,"NEW TRACK") == NULL)
147  return 0;
148 
149  Float_t x0 = 0, y0 = 0, z0 = 0, t0 = 0;
150  Float_t px = 0, py = 0, pz = 0, e = 0;
151  Int_t pid = 0, trackId = 0;
152  /* Int_t test = */ sscanf(line," NEW TRACK %f %f %f %f %f %f %f %f %d %d",
153  &x0, &y0, &z0, &t0,
154  &px, &py, &pz, &e,
155  &pid, &trackId);
156 
157  if(gHarpoDebug>1) Info("GenerateTrackFromText"," %s",line);
158  // Info("GenerateTrackFromText","%d",test);
159  // Info("GenerateTrackFromText","%g %g %g %g %g %g %g %g %d %d",x0, y0, z0, t0, px, py, pz, e,pid, trackId);
160 
161  // TpcSimMCTrack* mctrack
162  // = new TpcSimMCTrack(Double_t(x0), Double_t(y0), Double_t(z0), Double_t(t0),
163  // Double_t(px), Double_t(py), Double_t(pz),
164  // pid);
165  // mcevent->AddTrack(mctrack);
166 
167  TpcSimIonisationTrack* trackout
168  = new TpcSimIonisationTrack(Double_t(x0), Double_t(y0), Double_t(z0), Double_t(t0),
169  Double_t(px), Double_t(py), Double_t(pz),
170  pid,
171  0, 0, trackId);
172  // TpcSimIonisationTrack* trackout = new TpcSimIonisationTrack();
173 
174  Double_t t = 2;
175 
176  while(str->good()){
177  str->getline(line,256);
178  if(strstr(line,"END TRACK") != NULL)
179  break;
180  // if(strstr(line,"BEGINNING OF EVENT") != NULL){
181  // Float_t x0, y0, z0, t0;
182  // Float_t px, py, pz, e;
183  // Int_t pid, trackId;
184  // sscanf(line,"BEGINNING OF EVENT %f %f %f %f %f %f %f %f %d %d",
185  // &x0, &y0, &z0, &t0,
186  // &px, &py, &pz, &e,
187  // &pid, &trackId);
188  // continue;
189  // }
190  Float_t x = 10, y = 10, z = 10;
191  Int_t Ne;
192  // Int_t test = sscanf(line,"%f %f %f %d",&x, &y, &z, &Ne);
193  Int_t cx = -1, cy = -1, cz = -1, trk = -1;
194  Float_t time;
195  Int_t test = sscanf(line,"%f %f %f %d %d %d %d %d %f",&x, &y, &z, &Ne, &cx, &cy, &cz, &trk, &time);
196  z += fGeom->GetGasSizeZ()*0.5;
197  if(test < 4) continue;
198 
199  // std::cout << cx << " " << cy << " " << cz << std::endl;
200  // std::cout << "#" << fModuleX << " " << fModuleY << " " << fModuleZ << std::endl;
201 
202  if(cx != -1 && cx != fModuleX) continue;
203  if(cy != -1 && cy != fModuleY) continue;
204  if(cz != -1 && cz != fModuleZ) continue;
205  // std::cout << "***" << cx << " " << cy << " " << cz << std::endl;
206 
207  Double_t eloss = Ne;
208 
209  if(gHarpoDebug>3)
210  Info("GenerateTrackFromText","%f %f %f %d",x,y,z,Ne);
211 
212  TpcSimIonisationPoint* point = new TpcSimIonisationPoint(Ne,x,y,z,t,eloss,0);
213  trackout->AddPoint(point);
214  point->Delete();
215  }
216 
217  if(gHarpoDebug>1)
218  Info("GenerateTrackFromText","End track %s",line);
219 
220  return trackout;
221 
222 }
223 
224 
225 
226 Int_t TpcSimIonisationChamber::GetNe(Double_t Eloss)
227 {
228 
229  Int_t Ne;
230 
231  // ****** Number of electrons (primary + secondary) *****
232  if(fFano <= 0){
233  Ne = Int_t((Eloss - fIpot)/fW) + 1; // *
234  } else{
235  Double_t netmp = (Eloss - fIpot)/fW;
236  while(1){
237  if(netmp<=0){ Ne = 0; break;}
238  Double_t elosstmp = gRandom->Gaus(netmp, TMath::Sqrt(fFano*netmp));
239  if(elosstmp<0) continue;
240  Ne = Int_t(elosstmp);
241  break;
242  }
243  }
244  if(Ne>1000) Ne = 1000; // Delta electron cut *
245  // ******************************************************
246 
247 
248  return Ne;
249 }
250 
251 
252 
254 {
255 
256  Double_t tmprndm = gRandom->Rndm();
257  Double_t Eloss;
258 
259  // switch(fEdist){
260  // case 0: // ALICE power law
261  Eloss = fIpot*TMath::Power(tmprndm+6e-04,-5./6.);
262  // break;
263  // default: // from file
264  // Eloss = fStraggleFunc->Eval(tmprndm);
265  // break;
266  // }
267 
268  // if(Eloss < 0){
269  // Debug(1,Form("%f | %f",tmprndm,Eloss));
270  // Eloss = 1000000;
271  // }
272 
273  return Eloss;
274 
275 }
Double_t GetY0()
Definition: TpcSimMCEvent.h:24
Double_t GetPz()
Definition: TpcSimMCEvent.h:32
Double_t GetZ0()
Definition: TpcSimMCEvent.h:25
Int_t GetVolume(Double_t x, Double_t y, Double_t z)
Double_t GetT0()
Definition: TpcSimMCEvent.h:26
void AddPoint(TpcSimIonisationPoint *point)
Double_t GetPy()
Definition: TpcSimMCEvent.h:31
TpcSimIonisationTrack * GenerateTrack(TpcSimMCTrack *tr)
Double_t GetX0()
Definition: TpcSimMCEvent.h:23
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
Double_t GetGasSizeZ()
Bool_t Lookup(const char *path, Bool_t &val)
Lookup function for scalar values.
TpcSimIonisationTrack * GenerateTrackFromText(std::ifstream *str)
HarpoConfig * gHConfig
Double_t GetPx()
Definition: TpcSimMCEvent.h:30