1 #if !defined(__CINT__) || defined(__MAKECINT__)
3 #include "TGeoManager.h"
4 #include "TInterpreter.h"
5 #include "TClassTable.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"
26 #include "AliRunLoader.h"
27 #include "AliGenEventHeader.h"
33 Bool_t DoVerticesSPD(Bool_t isMC=kFALSE, Int_t pileupalgo=1, Int_t optdebug=0){
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");
38 if (gClassTable->GetID("AliRun") < 0) {
39 gInterpreter->ExecuteMacro("loadlibs.C");
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()));
50 printf("Using deafult storage \n");
55 AliGeomManager::LoadGeometry("geometry.root");
57 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
59 AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
61 Error("DoVertices", "getting run loader from file %s failed",
67 runLoader->LoadgAlice();
68 gAlice = runLoader->GetAliRun();
70 Error("DoVertices", "no galice object found");
73 runLoader->LoadKinematics();
74 runLoader->LoadHeader();
76 AliITSLoader* ITSloader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
77 ITSloader->LoadRecPoints("read");
79 Int_t totev=runLoader->GetNumberOfEvents();
80 if(optdebug) printf("Number of events= %d\n",totev);
82 TFile* esdFile = TFile::Open("AliESDs.root");
83 if (!esdFile || !esdFile->IsOpen()) {
84 printf("Error in opening ESD file");
88 AliESDEvent * esd = new AliESDEvent;
89 TTree* tree = (TTree*) esdFile->Get("esdTree");
91 printf("Error: no ESD tree found");
94 esd->ReadFromTree(tree);
95 AliGRPManager * grpMan=new AliGRPManager();
96 grpMan->ReadGRPEntry();
97 grpMan->SetMagField();
98 printf("Magnetic field set to %f T\n",AliTracker::GetBz()/10.);
100 AliITSDetTypeRec* detTypeRec = new AliITSDetTypeRec();
101 AliITSsegmentation* seg = new AliITSsegmentationSPD();
102 detTypeRec->SetSegmentationModel(0,seg);
104 Double_t xnom=0.,ynom=0.;
105 AliITSVertexerZ *vertz = new AliITSVertexerZ(xnom,ynom);
106 vertz->Init("default");
107 AliITSVertexer3D *vert3d = new AliITSVertexer3D();
108 vert3d->Init("default");
109 vert3d->SetWideFiducialRegion(40.,1.);
110 vert3d->SetPileupAlgo(pileupalgo);
111 vert3d->PrintStatus();
112 vertz->SetDetTypeRec(detTypeRec);
113 vert3d->SetDetTypeRec(detTypeRec);
114 vert3d->SetComputeMultiplicity(kTRUE);
115 /* uncomment these lines to use diamond constrain */
116 // Double_t posdiam[3]={0.03,0.1,0.};
117 // Double_t sigdiam[3]={0.01,0.01,10.0};
118 // AliESDVertex* diam=new AliESDVertex(posdiam,sigdiam);
119 // vertz->SetVtxStart(diam);
120 // vert3d->SetVtxStart(diam);
121 /* end lines to be uncommented to use diamond constrain */
123 Int_t goodz=0,good3d=0;
125 ULong64_t spdFO = (1 << 14);
126 ULong64_t v0left = (1 << 11);
127 ULong64_t v0right = (1 << 12);
129 for (Int_t iEvent = 0; iEvent < totev; iEvent++) {
131 runLoader->GetEvent(iEvent);
132 Double_t dNchdy = 0.;
135 printf("==============================================================\n");
136 printf("Event: %d \n",iEvent);
139 runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
140 AliGenPythiaEventHeader *evh=(AliGenPythiaEventHeader*)runLoader->GetHeader()->GenEventHeader();
141 ptype = evh->ProcessType();
143 AliStack* stack = runLoader->Stack();
144 TTree *treek=(TTree*)runLoader->TreeK();
145 Int_t npart = (Int_t)treek->GetEntries();
146 if(optdebug) printf("Process Type = %d --- Particles %d\n",ptype,npart);
148 // loop on particles to get generated dN/dy
149 for(Int_t iPart=0; iPart<npart; iPart++) {
150 if(!stack->IsPhysicalPrimary(iPart)) continue;
151 TParticle* part = (TParticle*)stack->Particle(iPart);
152 if(part->GetPDG()->Charge() == 0) continue;
153 Double_t eta=part->Eta();
155 if(TMath::Abs(eta)<1.5) dNchdy+=1.;
157 if(optdebug) printf(" dNch/dy = %f\n",dNchdy);
159 tree->GetEvent(iEvent);
161 TTree* cltree = ITSloader->TreeR();
162 ULong64_t triggerMask=esd->GetTriggerMask();
163 // MB1: SPDFO || V0L || V0R
164 Bool_t eventTriggered = (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)));
165 AliESDVertex* vtxz = vertz->FindVertexForCurrentEvent(cltree);
166 AliESDVertex* vtx3d = vert3d->FindVertexForCurrentEvent(cltree);
167 AliMultiplicity *alimult = vert3d->GetMultiplicity();
171 ntrklets=alimult->GetNumberOfTracklets() ;
172 nrecp1=ntrklets+alimult->GetNumberOfSingleClusters();
176 TDirectory *current = gDirectory;
182 Double_t zdiffz = 0.;
187 ntrkz = vtxz->GetNContributors();
190 zresz =vtxz->GetZRes(); // microns
191 zdiffz = 10000.*(zz-mcVertex[2]); // microns
195 Double_t xerr3d = 0.;
196 Double_t xdiff3d = 0.;
199 Double_t yerr3d = 0.;
200 Double_t ydiff3d = 0.;
203 Double_t zerr3d = 0.;
204 Double_t zdiff3d = 0.;
210 if(vtx3d->IsFromVertexer3D()) is3d=kTRUE;
211 ntrk3d = vtx3d->GetNContributors();
212 if(is3d && ntrk3d>0)good3d++;
213 x3d = vtx3d->GetXv();
214 xerr3d=vtx3d->GetXRes();
215 xdiff3d = 10000.*(x3d-mcVertex[0]); // microns
217 y3d = vtx3d->GetYv();
218 yerr3d=vtx3d->GetYRes();
219 ydiff3d = 10000.*(y3d-mcVertex[1]); // microns
221 z3d = vtx3d->GetZv();
222 zerr3d=vtx3d->GetZRes();
223 zdiff3d = 10000.*(z3d-mcVertex[2]); // microns
227 xnt[0]=mcVertex[0];//x
228 xnt[1]=mcVertex[1];//y
229 xnt[2]=mcVertex[2];//z
248 xnt[18]=float(ntrklets);
249 xnt[19]=float(nrecp1);
250 xnt[20]=float(ptype);
252 xnt[22]=float(eventTriggered);
257 printf("Vertexer3D: \tx=%.5f \ty=%.5f \tz(cm)=%.5f \tContributors=%d \n",x3d,y3d,z3d,ntrk3d);
258 printf("VertexerZ: \tx=%.5f \ty=%.5f \tz(cm)=%.5f \tContributors=%d \n",0.,0.,zz,ntrkz);
259 if(isMC) printf("True Pos.: \tx=%.5f \ty=%.5f \tz(cm)=%.5f \tdN/dy=%.1f\n",mcVertex[0],mcVertex[1],mcVertex[2],dNchdy);
260 printf("Multiplicity: Tracklets=%d ClustersLay1=%d\n",ntrklets,nrecp1);
269 printf("***********************************************\n");
270 printf("Number of Z vertices found= %d\n",goodz);
271 printf("efficiency=%f\n",float(goodz)/float(totev));
272 printf("Number of 3D vertices found= %d\n",good3d);
273 printf("efficiency=%f\n",float(good3d)/float(totev));