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 ///////////////////////////////////////////////////////////////////////////////
33 #include "AliGenEventHeader.h"
34 #include "AliHeader.h"
35 #include "AliVertexGenFile.h"
38 ClassImp(AliVertexGenFile)
41 //_____________________________________________________________________________
42 AliVertexGenFile::AliVertexGenFile() :
49 // default constructor: initialize data members
53 //_____________________________________________________________________________
54 AliVertexGenFile::AliVertexGenFile(const char* fileName,
55 Int_t eventsPerEntry) :
59 fEventsPerEntry(eventsPerEntry),
63 // fileName is the name of the galice file containing the vertices
64 // eventsPerEntry is the number of events for which the same vertex is used
66 TDirectory* dir = gDirectory;
68 fFile = TFile::Open(fileName);
69 if (!fFile || !fFile->IsOpen()) {
70 Error("AliVertexGenFile", "could not open file %s", fileName);
75 fTree = (TTree*) fFile->Get("TE");
77 Error("AliVertexGenFile", "no header tree found in file %s", fileName);
81 fHeader = new AliHeader;
82 fTree->SetBranchAddress("Header", &fHeader);
87 //_____________________________________________________________________________
88 AliVertexGenFile::~AliVertexGenFile()
92 if (fFile) fFile->Close();
98 //_____________________________________________________________________________
99 TVector3 AliVertexGenFile::GetVertex()
101 // get the vertex from the event header tree
103 Int_t entry = fEvent++ / fEventsPerEntry;
105 Error("GetVertex", "no header tree");
106 return TVector3(0,0,0);
109 if (fTree->GetEntry(entry) <= 0) {
110 Error("GetVertex", "error loading entry %d", entry);
111 return TVector3(0,0,0);
114 if (!fHeader->GenEventHeader()) {
115 Error("GetVertex", "no generator event header");
116 return TVector3(0,0,0);
120 fHeader->GenEventHeader()->PrimaryVertex(vertex);
121 return TVector3(vertex[0], vertex[1], vertex[2]);