Example macro to define the 1/pt resouttion
[u/mrichter/AliRoot.git] / TPC / Upgrade / AliToyMCEventGenerator.cxx
CommitLineData
526ddf0e 1#include <iostream>
a1a695e5 2
526ddf0e 3#include <TDatabasePDG.h>
4#include <TRandom.h>
5#include <TH2F.h>
a1a695e5 6#include <TGeoGlobalMagField.h>
32438f4e 7#include <TSpline.h>
cd8ed0ac 8#include <TObjString.h>
0403120d 9#include <TROOT.h>
a1a695e5 10
b0c26b55 11#include <AliLog.h>
a1a695e5 12#include <AliTPCROC.h>
13#include <AliTrackPointArray.h>
526ddf0e 14#include <AliTrackerBase.h>
15#include <AliCDBManager.h>
16#include <AliTPCParam.h>
17#include <AliGeomManager.h>
18#include <AliTPCcalibDB.h>
526ddf0e 19#include <AliTPCclusterMI.h>
a1a695e5 20#include <AliTPCSpaceCharge3D.h>
32438f4e 21#include <AliTPCROC.h>
0403120d 22#include <AliExternalTrackParam.h>
a1a695e5 23
24#include "AliToyMCEvent.h"
25#include "AliToyMCTrack.h"
26
27#include "AliToyMCEventGenerator.h"
28
de0014b7 29ClassImp(AliToyMCEventGenerator);
526ddf0e 30
31
de0014b7 32AliToyMCEventGenerator::AliToyMCEventGenerator()
526ddf0e 33 :TObject()
34 ,fTPCParam(0x0)
a1a695e5 35 ,fEvent(0x0)
223d9e38 36 ,fCurrentTrack(0)
37 ,fTPCCorrection(0x0)
38 ,fCorrectionFile("$ALICE_ROOT/TPC/Calib/maps/SC_NeCO2_eps5_50kHz_precal.lookup.root")
a1a695e5 39 ,fOutputFileName("toyMC.root")
40 ,fOutFile(0x0)
41 ,fOutTree(0x0)
d92b8630 42 ,fUseStepCorrection(kFALSE)
d1cf83f5 43 ,fUseMaterialBudget(kFALSE)
0403120d 44 ,fIsLaser(kTRUE)
526ddf0e 45{
526ddf0e 46 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
47 fTPCParam->ReadGeoMatrices();
223d9e38 48 gRandom->SetSeed();
526ddf0e 49}
50//________________________________________________________________
de0014b7 51AliToyMCEventGenerator::AliToyMCEventGenerator(const AliToyMCEventGenerator &gen)
526ddf0e 52 :TObject(gen)
a1a695e5 53 ,fTPCParam(gen.fTPCParam)
54 ,fEvent(0x0)
223d9e38 55 ,fCurrentTrack(0)
56 ,fTPCCorrection(gen.fTPCCorrection)
57 ,fCorrectionFile(gen.fCorrectionFile)
a1a695e5 58 ,fOutputFileName(gen.fOutputFileName)
59 ,fOutFile(0x0)
60 ,fOutTree(0x0)
d92b8630 61 ,fUseStepCorrection(gen.fUseStepCorrection)
d1cf83f5 62 ,fUseMaterialBudget(gen.fUseMaterialBudget)
0403120d 63 ,fIsLaser(gen.fIsLaser)
526ddf0e 64{
65 //
223d9e38 66 gRandom->SetSeed();
526ddf0e 67}
68//________________________________________________________________
de0014b7 69AliToyMCEventGenerator::~AliToyMCEventGenerator()
526ddf0e 70{
223d9e38 71 delete fTPCCorrection;
526ddf0e 72}
32438f4e 73
526ddf0e 74//________________________________________________________________
a1a695e5 75Bool_t AliToyMCEventGenerator::DistortTrack(AliToyMCTrack &trackIn, Double_t t0)
76{
77 //
78 //
79 //
80
526ddf0e 81 if(!fTPCParam) {
82 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
83 fTPCParam->ReadGeoMatrices();
526ddf0e 84 }
32438f4e 85
1e62e876 86 MakeITSClusters(trackIn/*,t0*/);
87 MakeTPCClusters(trackIn, t0);
88 MakeTRDClusters(trackIn/*,t0*/);
89
0403120d 90 return kTRUE;
1e62e876 91}
92//________________________________________________________________
93void AliToyMCEventGenerator::MakeITSClusters(AliToyMCTrack &trackIn/*, Double_t t0*/)
94{
95 //Upgrade ITS parameters
96 const Int_t nITSLayers = 7;
97 const Double_t ITSRadii[nITSLayers] = {2.2, 2.8, 3.6, 20.0, 22.0, 41.0, 43.0};
98 const Double_t lengthITS[nITSLayers] = {22.4, 24.2, 26.8, 78.0, 83.6, 142.4, 148.6};
99
100 const Double_t kMaxSnp = 0.85;
101 const Double_t kMaxZ0 = fTPCParam->GetZLength();
102 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
103
0403120d 104 AliExternalTrackParam track(trackIn);
1e62e876 105 Double_t xyz[3] = {0.,0.,0.};
106
107 if (!AliTrackerBase::PropagateTrackTo(&track,ITSRadii[0],kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterialBudget)) {
108 AliError(Form("Propagation to %.2f failed\n",ITSRadii[0]));
109 return;
110 }
111
112 for(Int_t iLayer = 0; iLayer<nITSLayers; iLayer++){
113
114 if (!AliTrackerBase::PropagateTrackTo(&track,ITSRadii[iLayer],kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterialBudget)) {
115 AliError(Form("Propagation to %.2f failed\n",ITSRadii[iLayer]));
116 continue;
117 }
118 track.GetXYZ(xyz);
119
120 if (TMath::Abs(track.GetZ())>kMaxZ0) continue;
121 if (TMath::Abs(track.GetZ())>lengthITS[iLayer]/2) continue;
122
0403120d 123 const Double_t sigmaY = 0.0004;
124 const Double_t sigmaZ = 0.0004;
125 AliCluster* tempCl = trackIn.AddITSPoint(AliCluster(1000,xyz[0],xyz[1],xyz[2],sigmaY*sigmaY,sigmaZ*sigmaZ,0));
126 tempCl->SetLabel(trackIn.GetUniqueID(), 0);
1e62e876 127 }
128
129}
130//________________________________________________________________
131void AliToyMCEventGenerator::MakeTRDClusters(AliToyMCTrack &trackIn/*, Double_t t0*/)
132
133{
134 //Uses current TRD parameters
135 const Int_t nTRDLayers = 6;
136 const Double_t distToMid = 3.2 + 30./2; //dist to middle of drift region (radiator + half drift region)
137 const Double_t TRDRadii[nTRDLayers] = {294.5 + distToMid, 307.1 + distToMid, 319.7 + distToMid, 332.3 + distToMid, 344.9 + distToMid, 357.5 + distToMid};
138 const Double_t lengthTRD[nTRDLayers] = {604.0, 634.0, 656.0, 686.0, 700.0, 700.0};
139
140
141 const Double_t kMaxSnp = 0.85;
142 const Double_t kMaxZ0 = fTPCParam->GetZLength();
143 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
144
0403120d 145 AliExternalTrackParam track(trackIn);
1e62e876 146 Double_t xyz[3] = {0.,0.,0.};
147
148 if (!AliTrackerBase::PropagateTrackTo(&track,TRDRadii[0],kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterialBudget)) {
149 AliError(Form("Propagation to %.2f failed\n",TRDRadii[0]));
150 return;
151 }
152
153 for(Int_t iLayer = 0; iLayer<nTRDLayers; iLayer++){
154
155 if (!AliTrackerBase::PropagateTrackTo(&track,TRDRadii[iLayer],kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterialBudget)) {
156 AliError(Form("Propagation to %.2f failed\n",TRDRadii[iLayer]));
157 continue;
158 }
159 track.GetXYZ(xyz);
160
161 if (TMath::Abs(track.GetZ())>kMaxZ0) continue;
162 if (TMath::Abs(track.GetZ())>lengthTRD[iLayer]/2) continue;
163
0403120d 164 const Double_t sigmaY = 0.06;
165 const Double_t sigmaZ = 0.2;
166 AliCluster* tempCl = trackIn.AddTRDPoint(AliCluster(1000,xyz[0],xyz[1],xyz[2],sigmaY*sigmaY,sigmaZ*sigmaZ,0));
167 tempCl->SetLabel(trackIn.GetUniqueID(), 0);
1e62e876 168 }
169
170}
171//________________________________________________________________
172void AliToyMCEventGenerator::MakeTPCClusters(AliToyMCTrack &trackIn, Double_t t0)
173{
174
32438f4e 175 // make it big enough to hold all points
176 // store real number of generated points in the unique id
177 const Int_t nMaxPoints=3000;
0403120d 178 static AliTrackPointArray pointArray0(nMaxPoints); //undistorted
179 static AliTrackPointArray pointArray1(nMaxPoints); //distorted
1e62e876 180
32438f4e 181 //Create space point of undistorted and distorted clusters along the propagated track trajectory
182 CreateSpacePoints(trackIn,pointArray0,pointArray1);
183 //Convert the space points into clusters in the local frame
184 //for undistorted and distorted clusters using the same function
185 ConvertTrackPointsToLocalClusters(pointArray0,trackIn,t0,0);
186 ConvertTrackPointsToLocalClusters(pointArray1,trackIn,t0,1);
526ddf0e 187
526ddf0e 188
1e62e876 189}
32438f4e 190//________________________________________________________________
191void AliToyMCEventGenerator::CreateSpacePoints(AliToyMCTrack &trackIn,
192 AliTrackPointArray &arrUdist,
193 AliTrackPointArray &arrDist)
194{
195 //
196 // sample the track from the inner to the outer wall of the TPC
197 // a graph is filled in local coordinates for later
198 //
199
0403120d 200 Double_t kMaxSnp = 0.85;
201 if (fIsLaser) kMaxSnp=0.99;
32438f4e 202 const Double_t kMaxZ0 = fTPCParam->GetZLength();
203 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
204
205 const Double_t iFCRadius = 83.5; //radius constants found in AliTPCCorrection.cxx
206 const Double_t oFCRadius = 254.5;
207
0403120d 208 AliExternalTrackParam track(trackIn);
32438f4e 209 //!!! TODO: make this adjustable perhaps
210 const Double_t stepSize=0.1;
211 Double_t xyz[3] = {0.,0.,0.};
212 Float_t xyzf[3] = {0.,0.,0.};
213
a1a695e5 214 //!!! when does the propagation not work, how often does it happen?
0403120d 215 if (!AliTrackerBase::PropagateTrackTo(&track,iFCRadius,kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterialBudget) && !fIsLaser) {
b0c26b55 216 AliError(Form("Propagation to IFC: %.2f failed\n",iFCRadius));
32438f4e 217 return;
b0c26b55 218 }
32438f4e 219
526ddf0e 220 Int_t npoints=0;
b0c26b55 221
32438f4e 222 for (Double_t radius=iFCRadius; radius<oFCRadius; radius+=stepSize){
b0c26b55 223 //!!! changed from return 0 to continue -> Please check
d1cf83f5 224 if (!AliTrackerBase::PropagateTrackTo(&track,radius,kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterialBudget)) {
0403120d 225 AliError(Form("Propagation to r=%.2f (snp=%.2f) failed\n",radius,track.GetSnp()));
b0c26b55 226 continue;
227 }
526ddf0e 228 track.GetXYZ(xyz);
32438f4e 229
b0c26b55 230 //!!! Why is this smeared
05da1b4e 231// xyz[0]+=gRandom->Gaus(0,0.000005);
232// xyz[1]+=gRandom->Gaus(0,0.000005);
233// xyz[2]+=gRandom->Gaus(0,0.000005);
32438f4e 234
235 xyzf[0]=Float_t(xyz[0]);
236 xyzf[1]=Float_t(xyz[1]);
237 xyzf[2]=Float_t(xyz[2]);
238
526ddf0e 239 if (TMath::Abs(track.GetZ())>kMaxZ0) continue;
32438f4e 240 // if (TMath::Abs(track.GetX())<iFCRadius) continue;
241 // if (TMath::Abs(track.GetX())>oFCRadius) continue;
242
243
244 AliTrackPoint pUdist; // undistorted space point
245 AliTrackPoint pDist; // distorted space point
246 // Set undistorted point
247 SetPoint(xyzf,pUdist);
248 arrUdist.AddPoint(npoints, &pUdist);
249 Int_t sector=pUdist.GetVolumeID();
32438f4e 250
251 // set distorted point
526ddf0e 252 Float_t distPoint[3]={xyz[0],xyz[1],xyz[2]};
d92b8630 253 Float_t dxyz[3]={0.,0.,0.};
254 if (!fUseStepCorrection){
223d9e38 255 fTPCCorrection->DistortPoint(distPoint, sector);
d92b8630 256 } else {
223d9e38 257 fTPCCorrection->GetCorrectionIntegralDz(distPoint,sector,dxyz,5);
d92b8630 258 distPoint[0]-=dxyz[0];
259 distPoint[1]-=dxyz[1];
260 distPoint[2]-=dxyz[2];
261 }
32438f4e 262 SetPoint(distPoint, pDist);
263 arrDist.AddPoint(npoints, &pDist);
32438f4e 264
265 ++npoints;
526ddf0e 266 }
32438f4e 267
268 arrUdist.SetUniqueID(npoints);
269 arrDist.SetUniqueID(npoints);
270}
526ddf0e 271
32438f4e 272//________________________________________________________________
273void AliToyMCEventGenerator::SetPoint(Float_t xyz[3], AliTrackPoint &point)
274{
275 //
276 // make AliTrackPoint out of AliTPCclusterMI
277 //
278
279 //covariance at the local frame
280 //assume 1mm distortion in y and z
281 Int_t i[3]={0,0,0};
282 const Double_t kSigmaY=0.1;
283 const Double_t kSigmaZ=0.1;
284 Float_t cov[6]={0,0,0, kSigmaY*kSigmaY,0,kSigmaZ*kSigmaZ};
285
286 const Float_t alpha = -TMath::ATan2(xyz[1],xyz[0]);
287 const Float_t sin = TMath::Sin(alpha), cos = TMath::Cos(alpha);
288
289 Float_t newcov[6];
290 newcov[0] = cov[0]*cos*cos + 2*cov[1]*sin*cos + cov[3]*sin*sin;
291 newcov[1] = cov[1]*(cos*cos-sin*sin) + (cov[3]-cov[0])*sin*cos;
292 newcov[2] = cov[2]*cos + cov[4]*sin;
293 newcov[3] = cov[0]*sin*sin - 2*cov[1]*sin*cos + cov[3]*cos*cos;
294 newcov[4] = cov[4]*cos - cov[2]*sin;
295 newcov[5] = cov[5];
296
297 // voluem ID to add later ....
298 point.SetXYZ(xyz);
299 point.SetCov(newcov);
d92b8630 300 // abuse volume ID for the sector number
32438f4e 301 point.SetVolumeID(fTPCParam->Transform0to1(xyz,i));
b0c26b55 302
32438f4e 303 // TODO: Add sampled dE/dx (use SetCharge)
304}
b0c26b55 305
32438f4e 306//________________________________________________________________
307void AliToyMCEventGenerator::ConvertTrackPointsToLocalClusters(AliTrackPointArray &arrPoints,
308 AliToyMCTrack &tr, Double_t t0, Int_t type)
309{
310 //
311 //
312 //
526ddf0e 313
32438f4e 314 const Int_t npoints=Int_t(arrPoints.GetUniqueID());
315 Int_t secOld=-1;
316
317 // create an array for graphs which are used for local interpolation
318 // we need a new graph if the sector changed since then the local frame will also change
319 TObjArray arrGraphsXY(72);
320 arrGraphsXY.SetOwner();
321 TObjArray arrGraphsXZ(72);
322 arrGraphsXZ.SetOwner();
323 AliTrackPoint p;
324 //create initial graph
325 TGraph *grXY=0x0;
326 TGraph *grXZ=0x0;
327 //row -> sector mapping
328 Int_t rowMap[159];
329 for (Int_t irow=0; irow<159; ++irow) rowMap[irow]=-1;
330
331 // 1. Step
332 // Make from the list of global space points graphs in the local frame
333 // one graph per sector is needed
334 for (Int_t ipoint=0; ipoint<npoints; ++ipoint){
335 arrPoints.GetPoint(p,ipoint);
336 Float_t xyz[3] = {p.GetX(),p.GetY(),p.GetZ()};
337 Int_t index[3] = {0,0,0};
338 Int_t row = fTPCParam->GetPadRow(xyz,index);
339 // rotate space point to local frame
340 // the angle is given by the VolumeID which was set in CrateSpacePoints
341 const Int_t sec=p.GetVolumeID();
342 if (row<0 || (sec<36 && row>62) || row>95 ) continue;
343 Double_t angle=((sec%18)*20.+10.)/TMath::RadToDeg();
344 AliTrackPoint pRot=p.Rotate(angle);
345 const Int_t secrow=row+(sec>35)*63;
346 if (rowMap[secrow]==-1) rowMap[secrow]=sec;
347 // check if we need a new graph (sector change)
348 if (secOld!=sec){
349 grXY=new TGraph;
350 grXZ=new TGraph;
351 arrGraphsXY.AddAt(grXY,sec);
352 arrGraphsXZ.AddAt(grXZ,sec);
353 }
b0c26b55 354
32438f4e 355 //add coordinates in local frame for later interpolation
356 grXY->SetPoint(grXY->GetN(), pRot.GetX(), pRot.GetY());
357 grXZ->SetPoint(grXZ->GetN(), pRot.GetX(), pRot.GetZ());
358 secOld=sec;
359 }
b0c26b55 360
32438f4e 361 // 2. Step
362 // create in the center of each row a space point by using the graph to interpolate
363 // the the center of the row. This is done in xy and xz
364 TSpline3 *splXY=0x0;
365 TSpline3 *splXZ=0x0;
366 AliTPCclusterMI tempCl;
367 secOld=-1;
368 for (Int_t irow=0; irow<159; ++irow ){
369 const Int_t sec = rowMap[irow];
370 if (sec==-1) continue;
371 const Int_t secrow = irow<63?irow:irow-63;
372 Double_t localX = fTPCParam->GetPadRowRadii(sec,secrow);
373 // get graph for the current row
374 if (sec!=secOld){
375 delete splXY;
376 splXY=0x0;
377 delete splXZ;
378 splXZ=0x0;
379
380 grXY=(TGraph*)arrGraphsXY.At(sec);
381 grXZ=(TGraph*)arrGraphsXZ.At(sec);
382 if (!grXY) continue;
b0c26b55 383
05da1b4e 384// if(grXY->GetN()>1 && grXZ->GetN()>1) { //causes segmentation violation if N==1
385// splXY=new TSpline3("splXY",grXY);
386// splXZ=new TSpline3("splXZ",grXZ);
387// }
388// else {
544076ea 389 //TODO: make a cluster also in the sector w only one space point?
05da1b4e 390// continue;
544076ea 391 // Double_t tempX=0., tempY = 0., tempZ = 0.;
392
393 // grXY->GetPoint(0,tempX,localY);
394 // grXZ->GetPoint(0,tempX,localZ);
05da1b4e 395// }
544076ea 396
32438f4e 397 }
398 secOld=sec;
b0c26b55 399
32438f4e 400 // check we are in an active area
05da1b4e 401// if (splXY->FindX(localX)<1 || splXZ->FindX(localX)<1) continue;
402 if ( localX<grXY->GetX()[0] || localX>grXY->GetX()[grXY->GetN()-1] || localX<grXZ->GetX()[0] || localX>grXZ->GetX()[grXZ->GetN()-1]) continue;
b0c26b55 403
32438f4e 404 //get interpolated value at the center for the pad row
405 // using splines
05da1b4e 406// const Double_t localY=splXY->Eval(localX/*,0x0,"S"*/);
407// const Double_t localZ=splXZ->Eval(localX/*,0x0,"S"*/);
408 const Double_t localY=grXY->Eval(localX/*,0x0,"S"*/);
409 const Double_t localZ=grXZ->Eval(localX/*,0x0,"S"*/);
32438f4e 410 Float_t xyz[3]={localX,localY,localZ};
526ddf0e 411
32438f4e 412 if (!SetupCluster(tempCl,xyz,sec,t0)) continue;
d1cf83f5 413 tempCl.SetLabel(tr.GetUniqueID(), 0);
0403120d 414
32438f4e 415 if (type==0) tr.AddSpacePoint(tempCl);
416 else tr.AddDistortedSpacePoint(tempCl);
417// printf("SetupCluster %3d: (%.2f, %.2f, %.2f), %d, %.2f\n",irow,xyz[0],xyz[1],xyz[2],sec,t0);
418 }
526ddf0e 419
32438f4e 420 delete splXY;
421 splXY=0x0;
422 delete splXZ;
423 splXZ=0x0;
424
425}
526ddf0e 426
32438f4e 427//________________________________________________________________
428Bool_t AliToyMCEventGenerator::SetupCluster(AliTPCclusterMI &tempCl, Float_t xyz[3], Int_t sec, Double_t t0)
429{
430 //
431 //
432 //
526ddf0e 433
32438f4e 434 const Double_t kSigmaY = 0.1;
435 const Double_t kSigmaZ = 0.1;
436 const Double_t kMaxZ0 = fTPCParam->GetZLength();
437 //TODO: Get this from the OCDB at some point?
438 const Double_t kDriftVel = fTPCParam->GetDriftV();
526ddf0e 439
32438f4e 440 tempCl.SetX(xyz[0]);
441 tempCl.SetY(xyz[1]);
442 tempCl.SetZ(xyz[2]);
526ddf0e 443
32438f4e 444 tempCl.SetSigmaY2(kSigmaY*kSigmaY);
445 tempCl.SetSigmaZ2(kSigmaZ*kSigmaZ);
446
447 // transform from the local coordinates to the coordinates expressed in pad coordinates
448 Int_t index[3] = {0,sec,0};
449 fTPCParam->Transform2to3(xyz,index);
450 fTPCParam->Transform3to4(xyz,index);
451 fTPCParam->Transform4to8(xyz,index);
452
453 const Int_t row = index[2];
454 const Int_t nPads = fTPCParam->GetNPads(sec, row);
455 // pad is fractional, but it needs to be shifted from the center
456 // to the edge of the row
457 const Float_t pad = xyz[1] + nPads/2;
458
459 tempCl.SetRow(row);
460 tempCl.SetPad(pad);
461 Float_t timeBin=Float_t(t0 + (kMaxZ0-TMath::Abs(tempCl.GetZ()))/kDriftVel);
462 tempCl.SetTimeBin(timeBin); // set time as t0 + drift time from dist z
463 tempCl.SetDetector(sec);
464
465 //check if we are in the active area
466 if (pad<0 || pad>=nPads) return kFALSE;
467
468 return kTRUE;
526ddf0e 469}
32438f4e 470
a1a695e5 471//________________________________________________________________
472Bool_t AliToyMCEventGenerator::ConnectOutputFile()
473{
474 //
475 // Create the output file name and tree and connect the event
476 //
477
478 fOutFile = new TFile(fOutputFileName.Data(),"recreate");
479
480 if (!fOutFile || !fOutFile->IsOpen()){
481 delete fOutFile;
482 fOutFile=0x0;
483 return kFALSE;
484 }
485
486 fOutTree = new TTree("toyMCtree","Tree with toyMC simulation");
487 fOutTree->Branch("event","AliToyMCEvent",&fEvent);
488
0403120d 489 gROOT->cd();
490
a1a695e5 491 return kTRUE;
492}
493
494//________________________________________________________________
495Bool_t AliToyMCEventGenerator::CloseOutputFile()
496{
497 //
498 // close the output file
499 //
500 if (!fOutFile) return kFALSE;
501 fOutFile->Write();
502 fOutFile->Close();
503 delete fOutFile;
504 fOutFile=0x0;
505
506 return kTRUE;
507}
508
509//________________________________________________________________
510void AliToyMCEventGenerator::FillTree()
511{
512 // fill the tree
0403120d 513 if (fOutTree&&fEvent) fOutTree->Fill();
a1a695e5 514}
515
cd8ed0ac 516//________________________________________________________________
223d9e38 517void AliToyMCEventGenerator::SetSpaceCharge(EEpsilon epsilon, EGasType gasType/*=kNeCO2_9010*/,
518 ECollRate collRate/*=k50kHz*/, ECorrection corrType/*=kLookup*/)
cd8ed0ac 519{
520 //
521 // Set the space charge conditions
522 //
223d9e38 523 fCorrectionFile="$ALICE_ROOT/TPC/Calib/maps/SC";
cd8ed0ac 524 switch (gasType) {
525 case kNeCO2_9010:
223d9e38 526 fCorrectionFile.Append("_NeCO2");
cd8ed0ac 527 break;
528 }
529 switch (epsilon) {
530 case kEps5:
223d9e38 531 fCorrectionFile.Append("_eps5");
cd8ed0ac 532 break;
533 case kEps10:
223d9e38 534 fCorrectionFile.Append("_eps10");
cd8ed0ac 535 break;
536 case kEps20:
223d9e38 537 fCorrectionFile.Append("_eps20");
cd8ed0ac 538 break;
539 }
540 switch (collRate) {
541 case k50kHz:
223d9e38 542 fCorrectionFile.Append("_50kHz");
543 break;
544 }
545 switch (corrType) {
546 case kLookup:
547 fCorrectionFile.Append("_precal.lookup.root");
548 break;
549 case kSpaceChargeFile:
550 fCorrectionFile.Append("_precal.root");
cd8ed0ac 551 break;
552 }
cd8ed0ac 553}
554
555//________________________________________________________________
556void AliToyMCEventGenerator::InitSpaceCharge()
557{
558 //
559 // init the space charge conditions
560 // this should be called after the tree was connected
561 //
562
223d9e38 563 AliInfo(Form("Using space charge map file: '%s'",fCorrectionFile.Data()));
564
565 TString corrName("map");
566
567 // allow for specifying an object name for the AliTPCCorrection in the file name
568 // separated by a ':'
569 TObjArray *arr=fCorrectionFile.Tokenize(":");
570 if (arr->GetEntriesFast()>1) {
571 fCorrectionFile=arr->At(0)->GetName();
572 corrName=arr->At(1)->GetName();
573 }
574 delete arr;
575
cd8ed0ac 576
223d9e38 577 TFile f(fCorrectionFile.Data());
578 fTPCCorrection=(AliTPCSpaceCharge3D*)f.Get("map");
cd8ed0ac 579
580 if (fOutTree){
581 AliInfo("Attaching space charge map file name to the tree");
223d9e38 582 fOutTree->GetUserInfo()->Add(new TObjString(fCorrectionFile.Data()));
cd8ed0ac 583 }
584}