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 "AliVertexGenFile.h"
35 #include "AliGenEventHeader.h"
36 #include "AliHeader.h"
39 ClassImp(AliVertexGenFile)
42 //_____________________________________________________________________________
43 AliVertexGenFile::AliVertexGenFile() :
50 // default constructor: initialize data members
54 //_____________________________________________________________________________
55 AliVertexGenFile::AliVertexGenFile(const char* fileName,
56 Int_t eventsPerEntry) :
60 fEventsPerEntry(eventsPerEntry),
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
67 TDirectory* dir = gDirectory;
69 fFile = TFile::Open(fileName);
70 if (!fFile || !fFile->IsOpen()) {
71 AliError(Form("could not open file %s", fileName));
76 fTree = (TTree*) fFile->Get("TE");
78 AliError(Form("no header tree found in file %s", fileName));
82 fHeader = new AliHeader;
83 fTree->SetBranchAddress("Header", &fHeader);
88 //_____________________________________________________________________________
89 AliVertexGenFile::~AliVertexGenFile()
93 if (fFile) fFile->Close();
99 //_____________________________________________________________________________
100 TVector3 AliVertexGenFile::GetVertex()
102 // get the vertex from the event header tree
104 Int_t entry = fEvent++ / fEventsPerEntry;
106 AliError("no header tree");
107 return TVector3(0,0,0);
110 if (fTree->GetEntry(entry) <= 0) {
111 AliError(Form("error loading entry %d", entry));
112 return TVector3(0,0,0);
115 if (!fHeader->GenEventHeader()) {
116 AliError("no generator event header");
117 return TVector3(0,0,0);
121 fHeader->GenEventHeader()->PrimaryVertex(vertex);
122 return TVector3(vertex[0], vertex[1], vertex[2]);