]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG1/global/AliAnalysisTaskVertexESD.cxx
Correct conversion from Int_t to UShort_t
[u/mrichter/AliRoot.git] / PWG1 / global / AliAnalysisTaskVertexESD.cxx
CommitLineData
388ca814 1/**************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//*************************************************************************
17// Class AliAnalysisTaskVertexESD
18// AliAnalysisTask to extract from ESD the information for the analysis
19// of the primary vertex reconstruction efficiency and resolution
20// (for MC events) and distributions (for real data). Three vertices:
21// - SPD tracklets
22// - ITS+TPC tracks
23// - TPC-only tracks
24//
25// Author: A.Dainese, andrea.dainese@pd.infn.it
26//*************************************************************************
27
28#include <TChain.h>
29#include <TTree.h>
30#include <TNtuple.h>
31#include <TBranch.h>
32#include <TClonesArray.h>
33#include <TObjArray.h>
34#include <TH1F.h>
35#include <TH2F.h>
36#include <TCanvas.h>
37
38#include "AliAnalysisTask.h"
39#include "AliAnalysisManager.h"
40
41#include "AliMultiplicity.h"
42#include "AliVertexerTracks.h"
43#include "AliESDtrack.h"
44#include "AliExternalTrackParam.h"
45#include "AliESDVertex.h"
46#include "AliESDEvent.h"
388ca814 47#include "AliESDInputHandler.h"
388ca814 48#include "AliTrackReference.h"
38d12819 49//#include "AliTriggerAnalysis.h"
388ca814 50
51#include "AliMCEventHandler.h"
52#include "AliMCEvent.h"
53#include "AliStack.h"
54#include "AliLog.h"
55
56#include "AliGenEventHeader.h"
57#include "AliAnalysisTaskVertexESD.h"
58
59
60ClassImp(AliAnalysisTaskVertexESD)
61
62//________________________________________________________________________
63AliAnalysisTaskVertexESD::AliAnalysisTaskVertexESD(const char *name) :
74917c1f 64AliAnalysisTaskSE(name),
4148ee5b 65fCheckEventType(kTRUE),
388ca814 66fReadMC(kFALSE),
94f15f9b 67fRecoVtxTPC(kFALSE),
68fRecoVtxITSTPC(kFALSE),
4d95fd6c 69fRecoVtxITSTPCHalfEvent(kFALSE),
cb393b39 70fOnlyITSTPCTracks(kFALSE),
71fOnlyITSSATracks(kFALSE),
b588553c 72fFillNtuple(kFALSE),
4f0574ad 73fFillTreeBeamSpot(kFALSE),
388ca814 74fESD(0),
388ca814 75fOutput(0),
76fNtupleVertexESD(0),
b588553c 77fhSPDVertexX(0),
78fhSPDVertexY(0),
79fhSPDVertexZ(0),
80fhTRKVertexX(0),
81fhTRKVertexY(0),
82fhTRKVertexZ(0),
83fhTPCVertexX(0),
84fhTPCVertexY(0),
85fhTPCVertexZ(0),
30b05a14 86fhTrackRefs(0),
4f0574ad 87fTreeBeamSpot(0)
388ca814 88{
89 // Constructor
90
91 // Define input and output slots here
388ca814 92 // Output slot #0 writes into a TList container
41deb8e3 93 DefineOutput(1, TList::Class()); //My private output
388ca814 94}
95//________________________________________________________________________
96AliAnalysisTaskVertexESD::~AliAnalysisTaskVertexESD()
97{
98 // Destructor
99
100 // histograms are in the output list and deleted when the output
101 // list is deleted by the TSelector dtor
102
103 if (fOutput) {
104 delete fOutput;
105 fOutput = 0;
106 }
107}
108
388ca814 109
110//________________________________________________________________________
74917c1f 111void AliAnalysisTaskVertexESD::UserCreateOutputObjects()
388ca814 112{
113 // Create histograms
114 // Called once
115
116 // Several histograms are more conveniently managed in a TList
117 fOutput = new TList;
118 fOutput->SetOwner();
119
19076e2d 120 fNtupleVertexESD = new TNtuple("fNtupleVertexESD","vertices","run:tstamp:bunchcross:triggered:dndygen:xtrue:ytrue:ztrue:xSPD:xerrSPD:ySPD:yerrSPD:zSPD:zerrSPD:ntrksSPD:SPD3D:dphiSPD:xTPC:xerrTPC:yTPC:yerrTPC:zTPC:zerrTPC:ntrksTPC:constrTPC:xTRK:xerrTRK:yTRK:yerrTRK:zTRK:zerrTRK:ntrksTRK:constrTRK:ntrklets:nESDtracks:nITSrefit5or6:nTPCin:nTPCinEta09:SPD0cls:xSPDp:xerrSPDp:ySPDp:yerrSPDp:zSPDp:zerrSPDp:ntrksSPDp:xTPCnc:xerrTPCnc:yTPCnc:yerrTPCnc:zTPCnc:zerrTPCnc:ntrksTPCnc:xTPCc:xerrTPCc:yTPCc:yerrTPCc:zTPCc:zerrTPCc:ntrksTPCc:xTRKnc:xerrTRKnc:yTRKnc:yerrTRKnc:zTRKnc:zerrTRKnc:ntrksTRKnc:xTRKc:xerrTRKc:yTRKc:yerrTRKc:zTRKc:zerrTRKc:ntrksTRKc:deltaxTRKnc:deltayTRKnc:deltazTRKnc:deltaxerrTRKnc:deltayerrTRKnc:deltazerrTRKnc:ntrksEvenTRKnc:ntrksOddTRKnc");
388ca814 121
122 fOutput->Add(fNtupleVertexESD);
123
b588553c 124 fhSPDVertexX = new TH1F("fhSPDVertexX","SPDVertex x; x vertex [cm]; events",200,-1,1);
125 fOutput->Add(fhSPDVertexX);
126 fhSPDVertexY = new TH1F("fhSPDVertexY","SPDVertex y; y vertex [cm]; events",200,-1,1);
127 fOutput->Add(fhSPDVertexY);
128 fhSPDVertexZ = new TH1F("fhSPDVertexZ","SPDVertex z; z vertex [cm]; events",200,-20,20);
129 fOutput->Add(fhSPDVertexZ);
130 fhTRKVertexX = new TH1F("fhTRKVertexX","TRKVertex x; x vertex [cm]; events",200,-1,1);
131 fOutput->Add(fhTRKVertexX);
132 fhTRKVertexY = new TH1F("fhTRKVertexY","TRKVertex y; y vertex [cm]; events",200,-1,1);
133 fOutput->Add(fhTRKVertexY);
134 fhTRKVertexZ = new TH1F("fhTRKVertexZ","TRKVertex z; z vertex [cm]; events",200,-20,20);
135 fOutput->Add(fhTRKVertexZ);
136 fhTPCVertexX = new TH1F("fhTPCVertexX","TPCVertex x; x vertex [cm]; events",200,-3,3);
137 fOutput->Add(fhTPCVertexX);
138 fhTPCVertexY = new TH1F("fhTPCVertexY","TPCVertex y; y vertex [cm]; events",200,-3,3);
139 fOutput->Add(fhTPCVertexY);
140 fhTPCVertexZ = new TH1F("fhTPCVertexZ","TPCVertex z; z vertex [cm]; events",200,-20,20);
141 fOutput->Add(fhTPCVertexZ);
142
388ca814 143 fhTrackRefs = new TH2F("fhTrackRefs","Track references; x; y",1000,-4,4,1000,-4,4);
144 fOutput->Add(fhTrackRefs);
145
4f0574ad 146 fTreeBeamSpot = new TTree("fTreeBeamSpot", "BeamSpotTree");
147 UShort_t triggered, ntrkletsS, ntrksTRKnc;
148 UInt_t run, bx;
149 Float_t cetTimeLHC,xTRKnc, yTRKnc, zTRKnc;
150 fTreeBeamSpot->Branch("run", &run, "run/i");
151 fTreeBeamSpot->Branch("cetTimeLHC", &cetTimeLHC, "cetTimeLHC/F");
152 fTreeBeamSpot->Branch("bx", &bx, "bx/i");
153 fTreeBeamSpot->Branch("triggered", &triggered, "triggered/s");
154 fTreeBeamSpot->Branch("ntrkletsS", &ntrkletsS, "ntrkletsS/s");
155 fTreeBeamSpot->Branch("xTRKnc", &xTRKnc, "xTRKnc/F");
156 fTreeBeamSpot->Branch("yTRKnc", &yTRKnc, "yTRKnc/F");
157 fTreeBeamSpot->Branch("zTRKnc", &zTRKnc, "zTRKnc/F");
158 fTreeBeamSpot->Branch("ntrksTRKnc", &ntrksTRKnc, "ntrksTRKnc/s");
159 fOutput->Add(fTreeBeamSpot);
aea5af08 160
997f86cb 161 PostData(1, fOutput);
30b05a14 162
f6232e6e 163 return;
388ca814 164}
165
166//________________________________________________________________________
74917c1f 167void AliAnalysisTaskVertexESD::UserExec(Option_t *)
388ca814 168{
169 // Main loop
170 // Called for each event
171
74917c1f 172 if (!InputEvent()) {
388ca814 173 Printf("ERROR: fESD not available");
174 return;
175 }
74917c1f 176 AliESDEvent* esdE = (AliESDEvent*) InputEvent();
177
178 if(fCheckEventType && (esdE->GetEventType())!=7) return;
38d12819 179
180
388ca814 181 TArrayF mcVertex(3);
182 mcVertex[0]=9999.; mcVertex[1]=9999.; mcVertex[2]=9999.;
183 Float_t dNchdy=-999.;
388ca814 184 // *********** MC info ***************
185 if (fReadMC) {
186 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
187 if (!eventHandler) {
188 Printf("ERROR: Could not retrieve MC event handler");
189 return;
190 }
191
192 AliMCEvent* mcEvent = eventHandler->MCEvent();
193 if (!mcEvent) {
194 Printf("ERROR: Could not retrieve MC event");
195 return;
196 }
197
198 AliStack* stack = mcEvent->Stack();
199 if (!stack) {
200 AliDebug(AliLog::kError, "Stack not available");
201 return;
202 }
203
204 AliHeader* header = mcEvent->Header();
205 if (!header) {
206 AliDebug(AliLog::kError, "Header not available");
207 return;
208 }
209 AliGenEventHeader* genHeader = header->GenEventHeader();
210 genHeader->PrimaryVertex(mcVertex);
211
212 Int_t ngenpart = (Int_t)stack->GetNtrack();
213 //printf("# generated particles = %d\n",ngenpart);
214 dNchdy=0;
215 for(Int_t ip=0; ip<ngenpart; ip++) {
216 TParticle* part = (TParticle*)stack->Particle(ip);
217 // keep only electorns, muons, pions, kaons and protons
218 Int_t apdg = TMath::Abs(part->GetPdgCode());
219 if(apdg!=11 && apdg!=13 && apdg!=211 && apdg!=321 && apdg!=2212) continue;
220 // reject secondaries
221 if(TMath::Sqrt((part->Vx()-mcVertex[0])*(part->Vx()-mcVertex[0])+(part->Vy()-mcVertex[1])*(part->Vy()-mcVertex[1]))>0.0010) continue;
222 // reject incoming protons
223 Double_t energy = part->Energy();
224 if(energy>900.) continue;
225 Double_t pz = part->Pz();
226 Double_t y = 0.5*TMath::Log((energy+pz+1.e-13)/(energy-pz+1.e-13));
227 if(TMath::Abs(y)<1.0) dNchdy += 0.5; // count 1/2 of particles in |y|<1
228 // tracks refs
229 TClonesArray *trefs=0;
230 Int_t ntrefs = mcEvent->GetParticleAndTR(ip,part,trefs);
231 if(ntrefs<0) continue;
232 for(Int_t iref=0; iref<ntrefs; iref++) {
233 AliTrackReference *tref = (AliTrackReference*)trefs->At(iref);
234 if(tref->R()>10.) continue;
235 fhTrackRefs->Fill(tref->X(),tref->Y());
236 }
237 }
238 //printf("# primary particles = %7.1f\n",dNchdy);
239 }
240 // *********** MC info ***************
241
388ca814 242
243 // Trigger
38d12819 244 //ULong64_t triggerMask;
245 //ULong64_t spdFO = (1 << 14);
246 //ULong64_t v0left = (1 << 10);
247 //ULong64_t v0right = (1 << 11);
388ca814 248
74917c1f 249 //triggerMask=esdE->GetTriggerMask();
388ca814 250 // MB1: SPDFO || V0L || V0R
38d12819 251 //Bool_t eventTriggered = (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)));
388ca814 252 //MB2: GFO && V0R
253 //triggerMask & spdFO && ((triggerMask&v0left) || (triggerMask&v0right))
38d12819 254 //Bool_t eventTriggered = (triggerMask & spdFO);
388ca814 255
38d12819 256 //static AliTriggerAnalysis* triggerAnalysis = new AliTriggerAnalysis();
74917c1f 257 Bool_t eventTriggered = 0;//triggerAnalysis->IsTriggerFired(esdE, AliTriggerAnalysis::kSPDGFO /*| AliTriggerAnalysis::kOfflineFlag*/);
388ca814 258
8c7764e0 259 // use response of AliPhysicsSelection
260 eventTriggered = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
261
4f0574ad 262
263 Int_t nInFile = esdE->GetEventNumberInFile();
264
30b05a14 265 const AliMultiplicity *alimult = esdE->GetMultiplicity();
266 Int_t ntrklets=0,spd0cls=0;
267 if(alimult) {
268 ntrklets = alimult->GetNumberOfTracklets();
269
30b05a14 270 for(Int_t l=0;l<alimult->GetNumberOfTracklets();l++){
271 if(alimult->GetDeltaPhi(l)<-9998.) ntrklets--;
272 }
273 spd0cls = alimult->GetNumberOfSingleClusters()+ntrklets;
274 }
275
276
4f0574ad 277 UShort_t triggered, ntrkletsS, ntrksTRKnc;
278 UInt_t run, bx;
279 Float_t cetTimeLHC,xTRKnc, yTRKnc, zTRKnc;
280 fTreeBeamSpot->SetBranchAddress("run", &run);
281 fTreeBeamSpot->SetBranchAddress("cetTimeLHC", &cetTimeLHC);
282 fTreeBeamSpot->SetBranchAddress("bx", &bx);
283 fTreeBeamSpot->SetBranchAddress("triggered", &triggered);
284 fTreeBeamSpot->SetBranchAddress("ntrkletsS", &ntrkletsS);
285 fTreeBeamSpot->SetBranchAddress("xTRKnc", &xTRKnc);
286 fTreeBeamSpot->SetBranchAddress("yTRKnc", &yTRKnc);
287 fTreeBeamSpot->SetBranchAddress("zTRKnc", &zTRKnc);
288 fTreeBeamSpot->SetBranchAddress("ntrksTRKnc", &ntrksTRKnc);
289
290
aea5af08 291 Double_t tstamp = esdE->GetTimeStamp();
292 Float_t cetTime =(tstamp-1262304000.)+7200.;
293
294 Float_t cetTime1h =(tstamp-1262304000.)+3600.;
30b05a14 295
4f0574ad 296 cetTimeLHC = (Float_t)cetTime1h;
297
74917c1f 298 Int_t ntracks = esdE->GetNumberOfTracks();
388ca814 299 Int_t nITS5or6=0,nTPCin=0,nTPCinEta09=0;
74917c1f 300 //printf("Tracks # = %d\n",esdE->GetNumberOfTracks());
388ca814 301 for(Int_t itr=0; itr<ntracks; itr++) {
74917c1f 302 AliESDtrack *t = esdE->GetTrack(itr);
388ca814 303 if(t->GetNcls(0)>=5) nITS5or6++;
74917c1f 304 Double_t z0; t->GetZAt(0,esdE->GetMagneticField(),z0);
305 if(t->GetNcls(1)>0 && TMath::Abs(t->GetD(0,0,esdE->GetMagneticField()))<2.8 && TMath::Abs(z0)<20) {
388ca814 306 nTPCin++;
307 if(TMath::Abs(t->GetTgl())<1.5) nTPCinEta09++;
308 }
388ca814 309 }
310
4f0574ad 311
74917c1f 312 const AliESDVertex *spdv=esdE->GetPrimaryVertexSPD();
39258194 313 const AliESDVertex *spdvp=esdE->GetPileupVertexSPD(0);
74917c1f 314 const AliESDVertex *tpcv=esdE->GetPrimaryVertexTPC();
315 const AliESDVertex *trkv=esdE->GetPrimaryVertexTracks();
b588553c 316
317 // fill histos
318
319 if(spdv) {
320 if(spdv->GetNContributors()>0) {
321 TString title=spdv->GetTitle();
322 if(title.Contains("3D")) {
323 fhSPDVertexX->Fill(spdv->GetXv());
324 fhSPDVertexY->Fill(spdv->GetYv());
325 }
326 fhSPDVertexZ->Fill(spdv->GetZv());
327 }
328 }
329
330 if(trkv) {
331 if(trkv->GetNContributors()>0) {
332 fhTRKVertexX->Fill(trkv->GetXv());
333 fhTRKVertexY->Fill(trkv->GetYv());
334 fhTRKVertexZ->Fill(trkv->GetZv());
335 }
336 }
337
338 if(tpcv) {
339 if(tpcv->GetNContributors()>0) {
340 fhTPCVertexX->Fill(tpcv->GetXv());
341 fhTPCVertexY->Fill(tpcv->GetYv());
342 fhTPCVertexZ->Fill(tpcv->GetZv());
343 }
344 }
39258194 345
346 Float_t xpile=-999.;
347 Float_t ypile=-999.;
348 Float_t zpile=-999.;
349 Float_t expile=-999.;
350 Float_t eypile=-999.;
351 Float_t ezpile=-999.;
352 Int_t ntrkspile=-1;
353
354 if(esdE->GetNumberOfPileupVerticesSPD()>0 && spdvp){
355 xpile=spdvp->GetXv();
356 expile=spdvp->GetXRes();
357 ypile=spdvp->GetYv();
358 eypile=spdvp->GetYRes();
359 zpile=spdvp->GetZv();
360 ezpile=spdvp->GetZRes();
361 ntrkspile=spdvp->GetNContributors();
362 }
388ca814 363
b588553c 364 // fill ntuple
19076e2d 365 Int_t isize=82;
366 Float_t xnt[82]; for(Int_t iii=0;iii<isize;iii++) xnt[iii]=0.;
30b05a14 367
aea5af08 368 Int_t isizeSecNt=9;
369 Float_t secnt[9]; for(Int_t iii=0;iii<isizeSecNt;iii++) secnt[iii]=0.;
30b05a14 370
97805f7d 371 Int_t index=0;
30b05a14 372 Int_t indexSecNt=0;
97805f7d 373
74917c1f 374 xnt[index++]=(Float_t)esdE->GetRunNumber();
30b05a14 375 secnt[indexSecNt++]=(Float_t)esdE->GetRunNumber();
4f0574ad 376 run = (Int_t)esdE->GetRunNumber();
8c7764e0 377
30b05a14 378 xnt[index++]=cetTime; //(Float_t)esdE->GetTimeStamp();
aea5af08 379 //secnt[indexSecNt++]=cetTime;
380 secnt[indexSecNt++]=cetTime1h;
8c7764e0 381
30b05a14 382 xnt[index++]=(Float_t)esdE->GetBunchCrossNumber();
4f0574ad 383 secnt[indexSecNt++]=(Float_t)esdE->GetBunchCrossNumber();
384 bx = (Int_t)esdE->GetBunchCrossNumber();
97805f7d 385
30b05a14 386 xnt[index++]=(eventTriggered ? 1. : 0.);
387 secnt[indexSecNt++]=(eventTriggered ? 1. : 0.);
4f0574ad 388 triggered = (UShort_t)(eventTriggered ? 1 : 0);
389
30b05a14 390 xnt[index++]=(Float_t)dNchdy;
391
97805f7d 392 xnt[index++]=mcVertex[0];
393 xnt[index++]=mcVertex[1];
394 xnt[index++]=mcVertex[2];
388ca814 395
97805f7d 396 xnt[index++]=spdv->GetXv();
397 xnt[index++]=spdv->GetXRes();
398 xnt[index++]=spdv->GetYv();
399 xnt[index++]=spdv->GetYRes();
400 xnt[index++]=spdv->GetZv();
401 xnt[index++]=spdv->GetZRes();
402 xnt[index++]=spdv->GetNContributors();
8c7764e0 403 TString spdtitle = spdv->GetTitle();
404 xnt[index++]=(spdtitle.Contains("vertexer: 3D") ? 1. : 0.);
405 xnt[index++]=spdv->GetDispersion();
388ca814 406
97805f7d 407 xnt[index++]=tpcv->GetXv();
408 xnt[index++]=tpcv->GetXRes();
409 xnt[index++]=tpcv->GetYv();
410 xnt[index++]=tpcv->GetYRes();
411 xnt[index++]=tpcv->GetZv();
412 xnt[index++]=tpcv->GetZRes();
413 xnt[index++]=tpcv->GetNContributors();
8c7764e0 414 TString tpctitle = tpcv->GetTitle();
415 xnt[index++]=(tpctitle.Contains("WithConstraint") ? 1. : 0.);
388ca814 416
97805f7d 417 xnt[index++]=trkv->GetXv();
418 xnt[index++]=trkv->GetXRes();
419 xnt[index++]=trkv->GetYv();
420 xnt[index++]=trkv->GetYRes();
421 xnt[index++]=trkv->GetZv();
422 xnt[index++]=trkv->GetZRes();
423 xnt[index++]=trkv->GetNContributors();// tpccontrorig;
8c7764e0 424 TString trktitle = trkv->GetTitle();
425 xnt[index++]=(trktitle.Contains("WithConstraint") ? 1. : 0.);
388ca814 426
97805f7d 427 xnt[index++]=float(ntrklets);
30b05a14 428 secnt[indexSecNt++]=float(ntrklets);
4f0574ad 429 ntrkletsS = (UShort_t)ntrklets;
30b05a14 430
97805f7d 431 xnt[index++]=float(ntracks);
432 xnt[index++]=float(nITS5or6);
30b05a14 433
97805f7d 434 xnt[index++]=float(nTPCin);
435 xnt[index++]=float(nTPCinEta09);
388ca814 436
97805f7d 437 xnt[index++]=spd0cls;
39258194 438
439 xnt[index++]=xpile;
440 xnt[index++]=expile;
441 xnt[index++]=ypile;
442 xnt[index++]=eypile;
443 xnt[index++]=zpile;
444 xnt[index++]=ezpile;
445 xnt[index++]=(Float_t)ntrkspile;
446
447
448
8c7764e0 449 // add recalculated vertices TRK and TPC
97805f7d 450
8c7764e0 451 if(fRecoVtxTPC) {
452 AliESDVertex *tpcvnc = ReconstructPrimaryVertexTPC(kFALSE);
453 xnt[index++]=tpcvnc->GetXv();
454 xnt[index++]=tpcvnc->GetXRes();
455 xnt[index++]=tpcvnc->GetYv();
456 xnt[index++]=tpcvnc->GetYRes();
457 xnt[index++]=tpcvnc->GetZv();
458 xnt[index++]=tpcvnc->GetZRes();
459 xnt[index++]=tpcvnc->GetNContributors();
460 delete tpcvnc; tpcvnc=0;
461
462 AliESDVertex *tpcvc = ReconstructPrimaryVertexTPC(kTRUE);
463 xnt[index++]=tpcvc->GetXv();
464 xnt[index++]=tpcvc->GetXRes();
465 xnt[index++]=tpcvc->GetYv();
466 xnt[index++]=tpcvc->GetYRes();
467 xnt[index++]=tpcvc->GetZv();
468 xnt[index++]=tpcvc->GetZRes();
469 xnt[index++]=tpcvc->GetNContributors();
470 delete tpcvc; tpcvc=0;
39258194 471 } else index+=14;
8c7764e0 472
473 if(fRecoVtxITSTPC) {
474 AliESDVertex *trkvnc = ReconstructPrimaryVertexITSTPC(kFALSE);
475 xnt[index++]=trkvnc->GetXv();
476 xnt[index++]=trkvnc->GetXRes();
477 xnt[index++]=trkvnc->GetYv();
478 xnt[index++]=trkvnc->GetYRes();
479 xnt[index++]=trkvnc->GetZv();
480 xnt[index++]=trkvnc->GetZRes();
481 xnt[index++]=trkvnc->GetNContributors();
30b05a14 482
483 secnt[indexSecNt++]=trkvnc->GetXv();
484 secnt[indexSecNt++]=trkvnc->GetYv();
485 secnt[indexSecNt++]=trkvnc->GetZv();
486 secnt[indexSecNt++]=trkvnc->GetNContributors();
4f0574ad 487
488 xTRKnc = (Float_t)trkvnc->GetXv();
489 yTRKnc = (Float_t)trkvnc->GetYv();
490 zTRKnc = (Float_t)trkvnc->GetZv();
ee98f8eb 491 ntrksTRKnc = (trkvnc->GetNContributors()<0 ? 0 : (UShort_t)trkvnc->GetNContributors());
4f0574ad 492
30b05a14 493 delete trkvnc; trkvnc=0;
494
495
8c7764e0 496 AliESDVertex *trkvc = ReconstructPrimaryVertexITSTPC(kTRUE);
497 xnt[index++]=trkvc->GetXv();
498 xnt[index++]=trkvc->GetXRes();
499 xnt[index++]=trkvc->GetYv();
500 xnt[index++]=trkvc->GetYRes();
501 xnt[index++]=trkvc->GetZv();
502 xnt[index++]=trkvc->GetZRes();
503 xnt[index++]=trkvc->GetNContributors();
504 delete trkvc; trkvc=0;
39258194 505 } else index+=14;
506
4d95fd6c 507 if(fRecoVtxITSTPCHalfEvent) {
508 AliESDVertex *trkvncodd = ReconstructPrimaryVertexITSTPC(kFALSE,1);
509 AliESDVertex *trkvnceven = ReconstructPrimaryVertexITSTPC(kFALSE,2);
510 if(trkvncodd->GetNContributors()>0 &&
511 trkvnceven->GetNContributors()>0) {
512 xnt[index++]=trkvncodd->GetXv()-trkvnceven->GetXv();
4d95fd6c 513 xnt[index++]=trkvncodd->GetYv()-trkvnceven->GetYv();
4d95fd6c 514 xnt[index++]=trkvncodd->GetZv()-trkvnceven->GetZv();
007ec307 515 xnt[index++]=TMath::Sqrt(trkvncodd->GetXRes()*trkvncodd->GetXRes()+trkvnceven->GetXRes()*trkvnceven->GetXRes());
516 xnt[index++]=TMath::Sqrt(trkvncodd->GetYRes()*trkvncodd->GetYRes()+trkvnceven->GetYRes()*trkvnceven->GetYRes());
4d95fd6c 517 xnt[index++]=TMath::Sqrt(trkvncodd->GetZRes()*trkvncodd->GetZRes()+trkvnceven->GetZRes()*trkvnceven->GetZRes());
19076e2d 518 xnt[index++]=trkvnceven->GetNContributors();
519 xnt[index++]=trkvncodd->GetNContributors();
4d95fd6c 520 } else {
521 xnt[index++]=0.;
522 xnt[index++]=0.;
523 xnt[index++]=0.;
524 xnt[index++]=0.;
525 xnt[index++]=0.;
526 xnt[index++]=0.;
527 xnt[index++]=-1;
19076e2d 528 xnt[index++]=-1;
4d95fd6c 529 }
530 delete trkvncodd; trkvncodd=0;
531 delete trkvnceven; trkvnceven=0;
19076e2d 532 } else index+=8;
4d95fd6c 533
534
8c7764e0 535 if(index>isize) printf("AliAnalysisTaskVertexESD: ERROR, index!=isize\n");
b588553c 536 if(fFillNtuple) fNtupleVertexESD->Fill(xnt);
30b05a14 537
538 if(indexSecNt>isizeSecNt) printf("AliAnalysisTaskVertexESD: ERROR, indexSecNt!=isizeSecNt\n");
4f0574ad 539
540 // if(indexTree>isizeTree) printf("AliAnalysisTaskVertexESD: ERROR, indexTree!=isizeTree\n");
541 // only every second event (to reduce output size)
542 if(fFillTreeBeamSpot && (nInFile%2 == 0)) fTreeBeamSpot->Fill();
543
f6232e6e 544
388ca814 545 // Post the data already here
41deb8e3 546 PostData(1, fOutput);
388ca814 547
548 return;
549}
550
551//________________________________________________________________________
552void AliAnalysisTaskVertexESD::Terminate(Option_t *)
553{
554 // Draw result to the screen
555 // Called once at the end of the query
2ac70243 556 fOutput = dynamic_cast<TList*> (GetOutputData(1));
388ca814 557 if (!fOutput) {
558 Printf("ERROR: fOutput not available");
559 return;
560 }
30b05a14 561
562 if (!fNtupleVertexESD){
563 Printf("ERROR: fNtuple not available");
564 return;
565 }
566
388ca814 567 fNtupleVertexESD = dynamic_cast<TNtuple*>(fOutput->FindObject("fNtupleVertexESD"));
568
30b05a14 569
388ca814 570 return;
571}
572
573//_________________________________________________________________________
8c7764e0 574AliESDVertex* AliAnalysisTaskVertexESD::ReconstructPrimaryVertexTPC(Bool_t constr) const {
388ca814 575 // On the fly reco of TPC vertex from ESD
74917c1f 576 AliESDEvent* evt = (AliESDEvent*) fInputEvent;
577 AliVertexerTracks vertexer(evt->GetMagneticField());
97805f7d 578 vertexer.SetTPCMode(); // defaults
8c7764e0 579 Float_t diamondcovxy[3]; evt->GetDiamondCovXY(diamondcovxy);
580 Double_t pos[3]={evt->GetDiamondX(),evt->GetDiamondY(),0};
581 Double_t cov[6]={diamondcovxy[0],diamondcovxy[1],diamondcovxy[2],0.,0.,10.*10.};
582 AliESDVertex *initVertex = new AliESDVertex(pos,cov,1.,1);
388ca814 583 vertexer.SetVtxStart(initVertex);
584 delete initVertex;
8c7764e0 585 if(!constr) vertexer.SetConstraintOff();
388ca814 586
74917c1f 587 return vertexer.FindPrimaryVertex(evt);
388ca814 588}
94f15f9b 589
590//_________________________________________________________________________
4d95fd6c 591AliESDVertex* AliAnalysisTaskVertexESD::ReconstructPrimaryVertexITSTPC(Bool_t constr,Int_t mode) const {
94f15f9b 592 // On the fly reco of ITS+TPC vertex from ESD
4d95fd6c 593 // mode=0 use all tracks
594 // mode=1 use odd-number tracks
595 // mode=2 use even-number tracks
596
74917c1f 597 AliESDEvent* evt = (AliESDEvent*) fInputEvent;
598 AliVertexerTracks vertexer(evt->GetMagneticField());
94f15f9b 599 vertexer.SetITSMode(); // defaults
8c7764e0 600 vertexer.SetMinClusters(4); // default is 5
30b05a14 601 //vertexer.SetITSpureSA();
8c7764e0 602 Float_t diamondcovxy[3]; evt->GetDiamondCovXY(diamondcovxy);
603 Double_t pos[3]={evt->GetDiamondX(),evt->GetDiamondY(),0};
604 Double_t cov[6]={diamondcovxy[0],diamondcovxy[1],diamondcovxy[2],0.,0.,10.*10.};
605 AliESDVertex *initVertex = new AliESDVertex(pos,cov,1.,1);
94f15f9b 606 vertexer.SetVtxStart(initVertex);
607 delete initVertex;
8c7764e0 608 if(!constr) vertexer.SetConstraintOff();
94f15f9b 609
cb393b39 610 // use only ITS-TPC or only ITS-SA tracks
5457d525 611 if(fOnlyITSTPCTracks || fOnlyITSSATracks || mode>0) {
cb393b39 612 Int_t iskip=0;
74917c1f 613 Int_t *skip = new Int_t[evt->GetNumberOfTracks()];
614 for(Int_t itr=0;itr<evt->GetNumberOfTracks(); itr++) {
615 AliESDtrack* track = evt->GetTrack(itr);
cb393b39 616 if(fOnlyITSTPCTracks && track->GetNcls(1)==0) { // skip ITSSA
617 skip[iskip++]=itr;
4d95fd6c 618 continue;
cb393b39 619 }
620 if(fOnlyITSSATracks && track->GetNcls(1)>0) { // skip ITSTPC
621 skip[iskip++]=itr;
4d95fd6c 622 continue;
cb393b39 623 }
4d95fd6c 624 if(mode==1 && itr%2==0) skip[iskip++]=itr;
625 if(mode==2 && itr%2==1) skip[iskip++]=itr;
cb393b39 626 }
627 vertexer.SetSkipTracks(iskip,skip);
628 delete [] skip; skip=NULL;
629 }
630
74917c1f 631 return vertexer.FindPrimaryVertex(evt);
94f15f9b 632}