]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/DoVerticesSPD.C
Update of the QA code of the SDD: 1) SDD Checker: added protection in case only a...
[u/mrichter/AliRoot.git] / ITS / DoVerticesSPD.C
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 "AliITSsegmentationSPD.h"
16 #include "AliVertexerTracks.h"
17 #include "AliCDBManager.h"
18 #include "AliGeomManager.h"
19 #include "AliGRPManager.h"
20 #include "AliITSDetTypeRec.h"
21 #include "AliITSVertexer3D.h"
22 #include "AliITSVertexerZ.h"
23 #include "AliESDVertex.h"
24 #include "AliESDEvent.h"
25 #include "AliRun.h"
26 #include "AliRunLoader.h"
27 #include "AliGenEventHeader.h"
28 #include "AliStack.h"
29 #endif
30
31 /*  $Id$    */
32
33 Bool_t DoVerticesSPD(Int_t pileupalgo=1, Int_t optdebug=0){
34
35   TFile *fint = new TFile("VertexSPD.root","recreate");
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");
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");
45     man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
46     //    man->SetSpecificStorage("GRP/GRP/Data",Form("local://%s",gSystem->pwd()));
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   }
57   AliGeomManager::ApplyAlignObjsFromCDB("ITS");
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
76   Int_t totev=runLoader->GetNumberOfEvents();
77   if(optdebug)  printf("Number of events= %d\n",totev);
78
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);
92   AliGRPManager * grpMan=new AliGRPManager();
93   grpMan->ReadGRPEntry();
94   grpMan->SetMagField();
95   printf("Magnetic field set to %f T\n",AliTracker::GetBz()/10.);
96
97   AliITSDetTypeRec* detTypeRec = new AliITSDetTypeRec();
98   AliITSsegmentation* seg = new AliITSsegmentationSPD();  
99   detTypeRec->SetSegmentationModel(0,seg);
100
101   Double_t xnom=0.,ynom=0.;
102   AliITSVertexerZ *vertz = new AliITSVertexerZ(xnom,ynom);
103   vertz->Init("default");
104   AliITSVertexer3D *vert3d = new AliITSVertexer3D();
105   vert3d->Init("default");
106   vert3d->SetWideFiducialRegion(40.,1.);
107   vert3d->SetPileupAlgo(pileupalgo);
108   vert3d->PrintStatus();
109   vertz->SetDetTypeRec(detTypeRec);
110   vert3d->SetDetTypeRec(detTypeRec);
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 */
119
120   Int_t goodz=0,good3d=0;
121   // Trigger mask
122   ULong64_t spdFO = (1 << 14);
123   ULong64_t v0left = (1 << 11);
124   ULong64_t v0right = (1 << 12);
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
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();
150
151       if(TMath::Abs(eta)<1.5) dNchdy+=1.; 
152     }
153     if(optdebug) printf(" dNch/dy = %f\n",dNchdy);
154  
155     tree->GetEvent(iEvent);
156
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)));
161     AliESDVertex* vtxz = vertz->FindVertexForCurrentEvent(cltree);
162     AliESDVertex* vtx3d = vert3d->FindVertexForCurrentEvent(cltree);
163     AliMultiplicity *alimult = vert3d->GetMultiplicity();
164     Int_t  ntrklets=0;
165     Int_t nrecp1=0;
166     if(alimult){
167       ntrklets=alimult->GetNumberOfTracklets() ;
168       nrecp1=ntrklets+alimult->GetNumberOfSingleClusters();
169     }
170        
171
172
173     TDirectory *current = gDirectory;
174     fint->cd();
175     Float_t xnt[23];
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;
204     Bool_t is3d=kFALSE;
205     if(vtx3d){
206
207       if(vtx3d->IsFromVertexer3D()) is3d=kTRUE;
208       ntrk3d = vtx3d->GetNContributors();
209       if(is3d && ntrk3d>0)good3d++;
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;
236     xnt[10]=y3d;
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);
248     xnt[21]=float(is3d);
249     xnt[22]=float(eventTriggered);
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 }