]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEER/AliVertexGenFile.cxx
Adding MFT (Antonio)
[u/mrichter/AliRoot.git] / STEER / STEER / AliVertexGenFile.cxx
CommitLineData
14248849 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Generator for vertices taken from a file //
21// //
22// The file name of the galice file is passed as argument to the //
23// constructor. If a second argument is given, this determines the number //
24// of events for which the same vertex is used. //
25// //
26///////////////////////////////////////////////////////////////////////////////
27
28
af7ba10c 29#include <TArrayF.h>
14248849 30#include <TFile.h>
31#include <TTree.h>
af7ba10c 32
2524c56f 33#include "AliVertexGenFile.h"
f37d970d 34#include "AliLog.h"
af7ba10c 35#include "AliGenEventHeader.h"
36#include "AliHeader.h"
14248849 37
38
39ClassImp(AliVertexGenFile)
40
41
42//_____________________________________________________________________________
43AliVertexGenFile::AliVertexGenFile() :
44 fFile(NULL),
45 fTree(NULL),
46 fHeader(NULL),
47 fEventsPerEntry(0),
48 fEvent(0)
49{
50// default constructor: initialize data members
51
52}
53
54//_____________________________________________________________________________
55AliVertexGenFile::AliVertexGenFile(const char* fileName,
56 Int_t eventsPerEntry) :
57 fFile(NULL),
58 fTree(NULL),
59 fHeader(NULL),
60 fEventsPerEntry(eventsPerEntry),
61 fEvent(0)
62{
63// main constructor:
64// fileName is the name of the galice file containing the vertices
65// eventsPerEntry is the number of events for which the same vertex is used
66
67 TDirectory* dir = gDirectory;
68
69 fFile = TFile::Open(fileName);
84061f6b 70 if (!fFile || !fFile->IsOpen()) {
f37d970d 71 AliError(Form("could not open file %s", fileName));
84061f6b 72 delete fFile;
73 fFile = NULL;
14248849 74 return;
75 }
76 fTree = (TTree*) fFile->Get("TE");
77 if (!fTree) {
f37d970d 78 AliError(Form("no header tree found in file %s", fileName));
14248849 79 dir->cd();
80 return;
81 }
82 fHeader = new AliHeader;
83 fTree->SetBranchAddress("Header", &fHeader);
84
85 dir->cd();
86}
87
88//_____________________________________________________________________________
89AliVertexGenFile::~AliVertexGenFile()
90{
91// clean up
92
84061f6b 93 if (fFile) fFile->Close();
14248849 94 delete fFile;
95 delete fHeader;
96}
97
98
99//_____________________________________________________________________________
100TVector3 AliVertexGenFile::GetVertex()
101{
102// get the vertex from the event header tree
103
104 Int_t entry = fEvent++ / fEventsPerEntry;
84061f6b 105 if (!fTree) {
f37d970d 106 AliError("no header tree");
84061f6b 107 return TVector3(0,0,0);
108 }
109
14248849 110 if (fTree->GetEntry(entry) <= 0) {
f37d970d 111 AliError(Form("error loading entry %d", entry));
14248849 112 return TVector3(0,0,0);
113 }
114
115 if (!fHeader->GenEventHeader()) {
f37d970d 116 AliError("no generator event header");
14248849 117 return TVector3(0,0,0);
118 }
119
120 TArrayF vertex(3);
121 fHeader->GenEventHeader()->PrimaryVertex(vertex);
122 return TVector3(vertex[0], vertex[1], vertex[2]);
123}
124
125