Macro to produce SPD vertices with Z and 3D vertexers
[u/mrichter/AliRoot.git] / ITS / DoVerticesSPD.C
CommitLineData
f5826889 1#if !defined(__CINT__) || defined(__MAKECINT__)
2#include "TFile.h"
3#include "TGeoManager.h"
4#include "TInterpreter.h"
5#include "TClassTable.h"
6#include "TNtuple.h"
7#include "TTree.h"
8#include "TArrayF.h"
9#include "TParticle.h"
10#include "AliESD.h"
11#include "AliGenPythiaEventHeader.h"
12#include "AliTracker.h"
13#include "AliHeader.h"
14#include "AliITSLoader.h"
15#include "AliVertexerTracks.h"
16#include "AliCDBManager.h"
17#include "AliGeomManager.h"
18#include "AliITSVertexer3D.h"
19#include "AliITSVertexerZ.h"
20#include "AliESDVertex.h"
21#include "AliRun.h"
22#include "AliRunLoader.h"
23#include "AliGenEventHeader.h"
24#include "AliStack.h"
25#endif
26
27/* $Id$ */
28
29Bool_t DoVerticesSPD(Int_t optdebug=1){
30 TFile *fint = new TFile("VertexSPD.root","recreate");
31 TNtuple *nt = new TNtuple("ntvert","vertices","xtrue:ytrue:ztrue:zZ:zdiffZ:zerrZ:ntrksZ:x3D:xdiff3D:xerr3D:y3D:ydiff3D:yerr3D:z3D:zdiff3D:zerr3D:ntrks3D:dndy:ntrklets:nrp1:ptyp");
32
33 if (gClassTable->GetID("AliRun") < 0) {
34 gInterpreter->ExecuteMacro("loadlibs.C");
35 }
36 // Set OCDB if needed
37 AliCDBManager* man = AliCDBManager::Instance();
38 if (!man->IsDefaultStorageSet()) {
39 printf("Setting a local default storage and run number 0\n");
40 man->SetDefaultStorage("local://$ALICE_ROOT");
41 man->SetRun(0);
42 }
43 else {
44 printf("Using deafult storage \n");
45 }
46
47 // retrives geometry
48 if(!gGeoManager){
49 AliGeomManager::LoadGeometry("geometry.root");
50 }
51
52 AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
53 if (!runLoader) {
54 Error("DoVertices", "getting run loader from file %s failed",
55 "galice.root");
56 return kFALSE;
57 }
58 runLoader->LoadgAlice();
59 gAlice = runLoader->GetAliRun();
60 if (!gAlice) {
61 Error("DoVertices", "no galice object found");
62 return kFALSE;
63 }
64 runLoader->LoadKinematics();
65 runLoader->LoadHeader();
66 AliITSLoader* ITSloader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
67 ITSloader->LoadRecPoints("read");
68
69 AliMagF * magf = gAlice->Field();
70 AliTracker::SetFieldMap(magf,kTRUE);
71 if(optdebug) printf("MagneticField=%f\n",AliTracker::GetBz());
72
73 Int_t totev=runLoader->GetNumberOfEvents();
74 if(optdebug) printf("Number of events= %d\n",totev);
75
76
77// TFile* esdFile = TFile::Open("AliESDs.root");
78// if (!esdFile || !esdFile->IsOpen()) {
79// Error("DoVertices", "opening ESD file %s failed", "AliESDs.root");
80// return kFALSE;
81// }
82// AliESD* esd = new AliESD;
83// TTree* tree = (TTree*) esdFile->Get("esdTree");
84// if (!tree) {
85// Error("DoVertices", "no ESD tree found");
86// return kFALSE;
87// }
88// tree->SetBranchAddress("ESD", &esd);
89
90 Double_t xnom=0.,ynom=0.;
91 AliITSVertexerZ *vertz = new AliITSVertexerZ("default",xnom,ynom);
92 AliITSVertexer3D *vert3d = new AliITSVertexer3D("default");
93 // vert3d->SetDebug(10);
94 // vertz->ConfigIterations(5);
95
96 Int_t goodz=0,good3d=0;
97
98 for (Int_t iEvent = 0; iEvent < totev; iEvent++) {
99 TArrayF mcVertex(3);
100 runLoader->GetEvent(iEvent);
101 runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
102 AliGenPythiaEventHeader *evh=(AliGenPythiaEventHeader*)runLoader->GetHeader()->GenEventHeader();
103 Int_t ptype = evh->ProcessType();
104 if(optdebug){
105 printf("==============================================================\n");
106 printf("\nEvent: %d ---- Process Type = %d \n",iEvent,ptype);
107 }
108
109 AliStack* stack = runLoader->Stack();
110 TTree *treek=(TTree*)runLoader->TreeK();
111 Int_t npart = (Int_t)treek->GetEntries();
112 if(optdebug) printf("particles %d\n",npart);
113
114 Double_t dNchdy = 0.;
115
116 // loop on particles
117 for(Int_t pa=0; pa<npart; pa++) {
118 TParticle* part = (TParticle*)stack->Particle(pa);
119 Int_t pdg = part->GetPdgCode();
120 Int_t apdg = TMath::Abs(pdg);
121 Double_t energy = part->Energy();
122 if(energy>6900.) continue; // reject incoming protons
123 Double_t pz = part->Pz();
124 Double_t y = 0.5*TMath::Log((energy+pz+1.e-13)/(energy-pz+1.e-13));
125
126
127 if(apdg!=11 && apdg!=13 && apdg!=211 && apdg!=321 && apdg!=2212) continue; // reject secondaries
128 if(TMath::Sqrt((part->Vx()-mcVertex[0])*(part->Vx()-mcVertex[0])+(part->Vy()-mcVertex[1])*(part->Vy()-mcVertex[1]))>0.0010) continue;
129 if(TMath::Abs(y)<1.0) dNchdy += 0.5; // count 1/2 of particles in |y|<1
130 }
131 if(optdebug) printf(" dNch/dy = %f\n",dNchdy);
132
133 AliESDVertex* vtxz = vertz->FindVertexForCurrentEvent(iEvent);
134 AliMultiplicity *alimult = vertz->GetMultiplicity();
135 Int_t ntrklets=0,nrecp1=0;
136 if(alimult) {
137 nrecp1=alimult->GetNumberOfTracklets() ;
138 ntrklets = alimult->GetNumberOfTracklets();
139 for(Int_t l=0;l<alimult->GetNumberOfTracklets();l++){
140 if(alimult->GetDeltaPhi(l)<-9998.) ntrklets--;
141 }
142 }
143
144 AliESDVertex* vtx3d = vert3d->FindVertexForCurrentEvent(iEvent);
145
146 TDirectory *current = gDirectory;
147 fint->cd();
148 Float_t xnt[21];
149
150 Double_t zz = 0.;
151 Double_t zresz = 0.;
152 Double_t zdiffz = 0.;
153
154 Int_t ntrkz = 0;
155 if(vtxz){
156
157 ntrkz = vtxz->GetNContributors();
158 if(ntrkz>0)goodz++;
159 zz=vtxz->GetZv();
160 zresz =vtxz->GetZRes(); // microns
161 zdiffz = 10000.*(zz-mcVertex[2]); // microns
162 }
163
164 Double_t x3d = 0.;
165 Double_t xerr3d = 0.;
166 Double_t xdiff3d = 0.;
167
168 Double_t y3d = 0.;
169 Double_t yerr3d = 0.;
170 Double_t ydiff3d = 0.;
171
172 Double_t z3d = 0.;
173 Double_t zerr3d = 0.;
174 Double_t zdiff3d = 0.;
175
176 Int_t ntrk3d = 0;
177 if(vtx3d){
178
179 ntrk3d = vtx3d->GetNContributors();
180 if(ntrk3d>0)good3d++;
181 x3d = vtx3d->GetXv();
182 xerr3d=vtx3d->GetXRes();
183 xdiff3d = 10000.*(x3d-mcVertex[0]); // microns
184
185 y3d = vtx3d->GetYv();
186 yerr3d=vtx3d->GetYRes();
187 ydiff3d = 10000.*(y3d-mcVertex[1]); // microns
188
189 z3d = vtx3d->GetZv();
190 zerr3d=vtx3d->GetZRes();
191 zdiff3d = 10000.*(z3d-mcVertex[2]); // microns
192
193 }
194
195 xnt[0]=mcVertex[0];//x
196 xnt[1]=mcVertex[1];//y
197 xnt[2]=mcVertex[2];//z
198
199 xnt[3]=zz;
200 xnt[4]=zdiffz;
201 xnt[5]=zresz;
202 xnt[6]=ntrkz;
203
204 xnt[7]=x3d;
205 xnt[8]=xdiff3d;
206 xnt[9]=xerr3d;
207 xnt[11]=y3d;
208 xnt[11]=ydiff3d;
209 xnt[12]=yerr3d;
210 xnt[13]=z3d;
211 xnt[14]=zdiff3d;
212 xnt[15]=zerr3d;
213 xnt[16]=ntrk3d;
214
215 xnt[17]=dNchdy;
216 xnt[18]=float(ntrklets);
217 xnt[19]=float(nrecp1);
218 xnt[20]=float(ptype);
219 nt->Fill(xnt);
220 current->cd();
221
222 if(optdebug){
223 printf("\nVertexerZ: \tz(cm)=%9.5f \tTracklets=%d \tztrue(cm)=%9.5f \tzdiff(um)=%8.2f\n",zz,ntrkz,mcVertex[2],zdiffz);
224 printf("Vertexer3D: \tz(cm)=%9.5f \tTracklets=%d \tztrue(cm)=%9.5f \tzdiff(um)=%8.2f\n",z3d,ntrk3d,mcVertex[2],zdiff3d);
225 }
226
227 }
228 fint->cd();
229 nt->Write();
230 fint->Close();
231 delete fint;
232 if(optdebug){
233 printf("***********************************************\n");
234 printf("Number of Z vertices found= %d\n",goodz);
235 printf("efficiency=%f\n",float(goodz)/float(totev));
236 printf("Number of 3D vertices found= %d\n",good3d);
237 printf("efficiency=%f\n",float(good3d)/float(totev));
238 }
239 return kTRUE;
240}