1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Generator for vertices taken from a file //
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. //
26 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliVertexGenFile.h"
30 #include "AliHeader.h"
31 #include "AliGenEventHeader.h"
37 ClassImp(AliVertexGenFile)
40 //_____________________________________________________________________________
41 AliVertexGenFile::AliVertexGenFile() :
48 // default constructor: initialize data members
52 //_____________________________________________________________________________
53 AliVertexGenFile::AliVertexGenFile(const char* fileName,
54 Int_t eventsPerEntry) :
58 fEventsPerEntry(eventsPerEntry),
62 // fileName is the name of the galice file containing the vertices
63 // eventsPerEntry is the number of events for which the same vertex is used
65 TDirectory* dir = gDirectory;
67 fFile = TFile::Open(fileName);
69 Error("AliVertexGenFile", "could not open file %s", fileName);
72 fTree = (TTree*) fFile->Get("TE");
74 Error("AliVertexGenFile", "not header tree found in file %s", fileName);
78 fHeader = new AliHeader;
79 fTree->SetBranchAddress("Header", &fHeader);
84 //_____________________________________________________________________________
85 AliVertexGenFile::~AliVertexGenFile()
95 //_____________________________________________________________________________
96 TVector3 AliVertexGenFile::GetVertex()
98 // get the vertex from the event header tree
100 Int_t entry = fEvent++ / fEventsPerEntry;
101 if (fTree->GetEntry(entry) <= 0) {
102 Error("GetVertex", "error loading entry %d", entry);
103 return TVector3(0,0,0);
106 if (!fHeader->GenEventHeader()) {
107 Error("GetVertex", "no generator event header");
108 return TVector3(0,0,0);
112 fHeader->GenEventHeader()->PrimaryVertex(vertex);
113 return TVector3(vertex[0], vertex[1], vertex[2]);