o add epsilon 20 precalculated map
[u/mrichter/AliRoot.git] / TPC / Upgrade / AliToyMCEventGeneratorSimple.cxx
CommitLineData
526ddf0e 1#include <iostream>
a1a695e5 2
526ddf0e 3#include <TDatabasePDG.h>
4#include <TRandom.h>
5#include <TF1.h>
32438f4e 6#include <TStopwatch.h>
a1a695e5 7
de0014b7 8#include "AliToyMCEvent.h"
526ddf0e 9
a1a695e5 10#include "AliToyMCEventGeneratorSimple.h"
11
de0014b7 12ClassImp(AliToyMCEventGeneratorSimple);
526ddf0e 13
14
de0014b7 15AliToyMCEventGeneratorSimple::AliToyMCEventGeneratorSimple()
16 :AliToyMCEventGenerator()
526ddf0e 17 ,fVertexMean(0.)
18 ,fVertexSigma(7.)
32438f4e 19 ,fNtracks(20)
526ddf0e 20{
21 //
22
23}
24//________________________________________________________________
de0014b7 25AliToyMCEventGeneratorSimple::AliToyMCEventGeneratorSimple(const AliToyMCEventGeneratorSimple &gen)
26 :AliToyMCEventGenerator(gen)
526ddf0e 27 ,fVertexMean(gen.fVertexMean)
28 ,fVertexSigma(gen.fVertexSigma)
32438f4e 29 ,fNtracks(gen.fNtracks)
526ddf0e 30{
31}
32//________________________________________________________________
de0014b7 33AliToyMCEventGeneratorSimple::~AliToyMCEventGeneratorSimple()
526ddf0e 34{
35}
36 //________________________________________________________________
de0014b7 37AliToyMCEventGeneratorSimple& AliToyMCEventGeneratorSimple::operator = (const AliToyMCEventGeneratorSimple &gen)
526ddf0e 38{
39 //assignment operator
40 if (&gen == this) return *this;
de0014b7 41 new (this) AliToyMCEventGeneratorSimple(gen);
526ddf0e 42
43 return *this;
44}
45//________________________________________________________________
de0014b7 46void AliToyMCEventGeneratorSimple::SetParameters(Double_t vertexMean, Double_t vertexSigma) {
526ddf0e 47 fVertexMean = vertexMean;
48 fVertexSigma = vertexSigma;
49}
50//________________________________________________________________
de0014b7 51AliToyMCEvent* AliToyMCEventGeneratorSimple::Generate(Double_t time) {
526ddf0e 52
de0014b7 53 AliToyMCEvent *retEvent = new AliToyMCEvent();
526ddf0e 54 retEvent->SetT0(time);
55 retEvent->SetX(0);
56 retEvent->SetX(0);
57 retEvent->SetZ(gRandom->Gaus(fVertexMean,fVertexSigma));
58
59 Double_t etaCuts=.9;
60 Double_t mass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
61 TF1 fpt("fpt",Form("x*(1+(sqrt(x*x+%f^2)-%f)/([0]*[1]))^(-[0])",mass,mass),0.4,10);
62 fpt.SetParameters(7.24,0.120);
63 fpt.SetNpx(10000);
32438f4e 64// Int_t nTracks = 400; //TODO: draw from experim dist
65// Int_t nTracks = 20; //TODO: draw from experim dist
526ddf0e 66
32438f4e 67 for(Int_t iTrack=0; iTrack<fNtracks; iTrack++){
526ddf0e 68 Double_t phi = gRandom->Uniform(0.0, 2*TMath::Pi());
69 Double_t eta = gRandom->Uniform(-etaCuts, etaCuts);
70 Double_t pt = fpt.GetRandom(); // momentum for f1
71 Short_t sign=1;
72 if(gRandom->Rndm() < 0.5){
73 sign =1;
74 }else{
75 sign=-1;
76 }
77
78 Double_t theta = 2*TMath::ATan(TMath::Exp(-eta))-TMath::Pi()/2.;
79 Double_t pxyz[3];
80 pxyz[0]=pt*TMath::Cos(phi);
81 pxyz[1]=pt*TMath::Sin(phi);
82 pxyz[2]=pt*TMath::Tan(theta);
83 Double_t vertex[3]={0,0,retEvent->GetZ()};
84 Double_t cv[21]={0};
de0014b7 85 AliToyMCTrack *tempTrack = new AliToyMCTrack(vertex,pxyz,cv,sign);
526ddf0e 86
87 Bool_t trackDist = DistortTrack(*tempTrack, time);
88 if(trackDist) retEvent->AddTrack(*tempTrack);
89 delete tempTrack;
90 }
91
92 return retEvent;
93}
94
a1a695e5 95//________________________________________________________________
32438f4e 96void AliToyMCEventGeneratorSimple::RunSimulation(const Int_t nevents/*=10*/, const Int_t ntracks/*=400*/)
a1a695e5 97{
98 //
99 // run simple simulation with equal event spacing
100 //
101
102 if (!ConnectOutputFile()) return;
103
32438f4e 104 fNtracks=ntracks;
a1a695e5 105 Double_t eventTime=0.;
106 const Double_t eventSpacing=1./50e3; //50kHz equally spaced
32438f4e 107 TStopwatch s;
a1a695e5 108 for (Int_t ievent=0; ievent<nevents; ++ievent){
32438f4e 109 printf("Generating event %3d (%.3g)\n",ievent,eventTime);
a1a695e5 110 fEvent = Generate(eventTime);
111 FillTree();
112 delete fEvent;
113 fEvent=0x0;
114 eventTime+=eventSpacing;
115 }
32438f4e 116 s.Stop();
117 s.Print();
118
a1a695e5 119 CloseOutputFile();
120}
526ddf0e 121