Fix for neg. crossing angles.
[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"
4c00c36c 15#include "AliITSsegmentationSPD.h"
f5826889 16#include "AliVertexerTracks.h"
17#include "AliCDBManager.h"
18#include "AliGeomManager.h"
332910f8 19#include "AliGRPManager.h"
fdc48e5f 20#include "AliITSDetTypeRec.h"
f5826889 21#include "AliITSVertexer3D.h"
22#include "AliITSVertexerZ.h"
23#include "AliESDVertex.h"
7d766abb 24#include "AliESDEvent.h"
f5826889 25#include "AliRun.h"
26#include "AliRunLoader.h"
27#include "AliGenEventHeader.h"
28#include "AliStack.h"
29#endif
30
31/* $Id$ */
32
5951029f 33Bool_t DoVerticesSPD(Int_t pileupalgo=1, Int_t optdebug=0){
792b611a 34
f5826889 35 TFile *fint = new TFile("VertexSPD.root","recreate");
7d766abb 36 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:is3D:isTriggered");
f5826889 37
38 if (gClassTable->GetID("AliRun") < 0) {
39 gInterpreter->ExecuteMacro("loadlibs.C");
40 }
41 // Set OCDB if needed
42 AliCDBManager* man = AliCDBManager::Instance();
43 if (!man->IsDefaultStorageSet()) {
44 printf("Setting a local default storage and run number 0\n");
162637e4 45 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
4c00c36c 46 // man->SetSpecificStorage("GRP/GRP/Data",Form("local://%s",gSystem->pwd()));
f5826889 47 man->SetRun(0);
48 }
49 else {
50 printf("Using deafult storage \n");
51 }
52
53 // retrives geometry
54 if(!gGeoManager){
55 AliGeomManager::LoadGeometry("geometry.root");
56 }
3714ff25 57 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
f5826889 58
59 AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
60 if (!runLoader) {
61 Error("DoVertices", "getting run loader from file %s failed",
62 "galice.root");
63 return kFALSE;
64 }
65 runLoader->LoadgAlice();
66 gAlice = runLoader->GetAliRun();
67 if (!gAlice) {
68 Error("DoVertices", "no galice object found");
69 return kFALSE;
70 }
71 runLoader->LoadKinematics();
72 runLoader->LoadHeader();
73 AliITSLoader* ITSloader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
74 ITSloader->LoadRecPoints("read");
75
3714ff25 76 Int_t totev=runLoader->GetNumberOfEvents();
f5826889 77 if(optdebug) printf("Number of events= %d\n",totev);
78
5951029f 79 TFile* esdFile = TFile::Open("AliESDs.root");
80 if (!esdFile || !esdFile->IsOpen()) {
81 printf("Error in opening ESD file");
82 return kFALSE;
83 }
84
85 AliESDEvent * esd = new AliESDEvent;
86 TTree* tree = (TTree*) esdFile->Get("esdTree");
87 if (!tree) {
88 printf("Error: no ESD tree found");
89 return kFALSE;
90 }
91 esd->ReadFromTree(tree);
332910f8 92 AliGRPManager * grpMan=new AliGRPManager();
93 grpMan->ReadGRPEntry();
94 grpMan->SetMagField();
95 printf("Magnetic field set to %f T\n",AliTracker::GetBz()/10.);
5951029f 96
97 AliITSDetTypeRec* detTypeRec = new AliITSDetTypeRec();
4c00c36c 98 AliITSsegmentation* seg = new AliITSsegmentationSPD();
99 detTypeRec->SetSegmentationModel(0,seg);
100
f5826889 101 Double_t xnom=0.,ynom=0.;
308c2f7c 102 AliITSVertexerZ *vertz = new AliITSVertexerZ(xnom,ynom);
103 vertz->Init("default");
104 AliITSVertexer3D *vert3d = new AliITSVertexer3D();
105 vert3d->Init("default");
792b611a 106 vert3d->SetWideFiducialRegion(40.,1.);
7d766abb 107 vert3d->SetPileupAlgo(pileupalgo);
792b611a 108 vert3d->PrintStatus();
fdc48e5f 109 vertz->SetDetTypeRec(detTypeRec);
110 vert3d->SetDetTypeRec(detTypeRec);
ecce5370 111
112 /* uncomment these lines to use diamond constrain */
113// Double_t posdiam[3]={0.03,0.1,0.};
114// Double_t sigdiam[3]={0.01,0.01,10.0};
115// AliESDVertex* diam=new AliESDVertex(posdiam,sigdiam);
116// vertz->SetVtxStart(diam);
117// vert3d->SetVtxStart(diam);
118 /* end lines to be uncommented to use diamond constrain */
f5826889 119
120 Int_t goodz=0,good3d=0;
7d766abb 121 // Trigger mask
122 ULong64_t spdFO = (1 << 14);
123 ULong64_t v0left = (1 << 11);
124 ULong64_t v0right = (1 << 12);
f5826889 125
126 for (Int_t iEvent = 0; iEvent < totev; iEvent++) {
127 TArrayF mcVertex(3);
128 runLoader->GetEvent(iEvent);
129 runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
130 AliGenPythiaEventHeader *evh=(AliGenPythiaEventHeader*)runLoader->GetHeader()->GenEventHeader();
131 Int_t ptype = evh->ProcessType();
132 if(optdebug){
133 printf("==============================================================\n");
134 printf("\nEvent: %d ---- Process Type = %d \n",iEvent,ptype);
135 }
136
137 AliStack* stack = runLoader->Stack();
138 TTree *treek=(TTree*)runLoader->TreeK();
139 Int_t npart = (Int_t)treek->GetEntries();
140 if(optdebug) printf("particles %d\n",npart);
141
142 Double_t dNchdy = 0.;
143
ecce5370 144 // loop on particles to get generated dN/dy
145 for(Int_t iPart=0; iPart<npart; iPart++) {
146 if(!stack->IsPhysicalPrimary(iPart)) continue;
147 TParticle* part = (TParticle*)stack->Particle(iPart);
148 if(part->GetPDG()->Charge() == 0) continue;
149 Double_t eta=part->Eta();
f5826889 150
ecce5370 151 if(TMath::Abs(eta)<1.5) dNchdy+=1.;
f5826889 152 }
153 if(optdebug) printf(" dNch/dy = %f\n",dNchdy);
154
7d766abb 155 tree->GetEvent(iEvent);
308c2f7c 156
7d766abb 157 TTree* cltree = ITSloader->TreeR();
158 ULong64_t triggerMask=esd->GetTriggerMask();
159 // MB1: SPDFO || V0L || V0R
160 Bool_t eventTriggered = (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)));
308c2f7c 161 AliESDVertex* vtxz = vertz->FindVertexForCurrentEvent(cltree);
ecce5370 162 AliESDVertex* vtx3d = vert3d->FindVertexForCurrentEvent(cltree);
ecce5370 163 AliMultiplicity *alimult = vert3d->GetMultiplicity();
792b611a 164 Int_t ntrklets=0;
165 Int_t nrecp1=0;
166 if(alimult){
167 ntrklets=alimult->GetNumberOfTracklets() ;
168 nrecp1=ntrklets+alimult->GetNumberOfSingleClusters();
f5826889 169 }
792b611a 170
ecce5370 171
f5826889 172
173 TDirectory *current = gDirectory;
174 fint->cd();
7d766abb 175 Float_t xnt[23];
f5826889 176
177 Double_t zz = 0.;
178 Double_t zresz = 0.;
179 Double_t zdiffz = 0.;
180
181 Int_t ntrkz = 0;
182 if(vtxz){
183
184 ntrkz = vtxz->GetNContributors();
185 if(ntrkz>0)goodz++;
186 zz=vtxz->GetZv();
187 zresz =vtxz->GetZRes(); // microns
188 zdiffz = 10000.*(zz-mcVertex[2]); // microns
189 }
190
191 Double_t x3d = 0.;
192 Double_t xerr3d = 0.;
193 Double_t xdiff3d = 0.;
194
195 Double_t y3d = 0.;
196 Double_t yerr3d = 0.;
197 Double_t ydiff3d = 0.;
198
199 Double_t z3d = 0.;
200 Double_t zerr3d = 0.;
201 Double_t zdiff3d = 0.;
202
203 Int_t ntrk3d = 0;
6b4d9537 204 Bool_t is3d=kFALSE;
f5826889 205 if(vtx3d){
7d766abb 206
6b4d9537 207 if(vtx3d->IsFromVertexer3D()) is3d=kTRUE;
f5826889 208 ntrk3d = vtx3d->GetNContributors();
792b611a 209 if(is3d && ntrk3d>0)good3d++;
f5826889 210 x3d = vtx3d->GetXv();
211 xerr3d=vtx3d->GetXRes();
212 xdiff3d = 10000.*(x3d-mcVertex[0]); // microns
213
214 y3d = vtx3d->GetYv();
215 yerr3d=vtx3d->GetYRes();
216 ydiff3d = 10000.*(y3d-mcVertex[1]); // microns
217
218 z3d = vtx3d->GetZv();
219 zerr3d=vtx3d->GetZRes();
220 zdiff3d = 10000.*(z3d-mcVertex[2]); // microns
221
222 }
223
224 xnt[0]=mcVertex[0];//x
225 xnt[1]=mcVertex[1];//y
226 xnt[2]=mcVertex[2];//z
227
228 xnt[3]=zz;
229 xnt[4]=zdiffz;
230 xnt[5]=zresz;
231 xnt[6]=ntrkz;
232
233 xnt[7]=x3d;
234 xnt[8]=xdiff3d;
235 xnt[9]=xerr3d;
8686a665 236 xnt[10]=y3d;
f5826889 237 xnt[11]=ydiff3d;
238 xnt[12]=yerr3d;
239 xnt[13]=z3d;
240 xnt[14]=zdiff3d;
241 xnt[15]=zerr3d;
242 xnt[16]=ntrk3d;
243
244 xnt[17]=dNchdy;
245 xnt[18]=float(ntrklets);
246 xnt[19]=float(nrecp1);
247 xnt[20]=float(ptype);
792b611a 248 xnt[21]=float(is3d);
7d766abb 249 xnt[22]=float(eventTriggered);
f5826889 250 nt->Fill(xnt);
251 current->cd();
252
253 if(optdebug){
254 printf("\nVertexerZ: \tz(cm)=%9.5f \tTracklets=%d \tztrue(cm)=%9.5f \tzdiff(um)=%8.2f\n",zz,ntrkz,mcVertex[2],zdiffz);
255 printf("Vertexer3D: \tz(cm)=%9.5f \tTracklets=%d \tztrue(cm)=%9.5f \tzdiff(um)=%8.2f\n",z3d,ntrk3d,mcVertex[2],zdiff3d);
256 }
257
258 }
259 fint->cd();
260 nt->Write();
261 fint->Close();
262 delete fint;
263 if(optdebug){
264 printf("***********************************************\n");
265 printf("Number of Z vertices found= %d\n",goodz);
266 printf("efficiency=%f\n",float(goodz)/float(totev));
267 printf("Number of 3D vertices found= %d\n",good3d);
268 printf("efficiency=%f\n",float(good3d)/float(totev));
269 }
270 return kTRUE;
271}