]>
Commit | Line | Data |
---|---|---|
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 | ||
29 | #include <TArrayF.h> | |
30 | #include <TFile.h> | |
31 | #include <TTree.h> | |
32 | ||
33 | #include "AliVertexGenFile.h" | |
34 | #include "AliLog.h" | |
35 | #include "AliGenEventHeader.h" | |
36 | #include "AliHeader.h" | |
37 | ||
38 | ||
39 | ClassImp(AliVertexGenFile) | |
40 | ||
41 | ||
42 | //_____________________________________________________________________________ | |
43 | AliVertexGenFile::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 | //_____________________________________________________________________________ | |
55 | AliVertexGenFile::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); | |
70 | if (!fFile || !fFile->IsOpen()) { | |
71 | AliError(Form("could not open file %s", fileName)); | |
72 | delete fFile; | |
73 | fFile = NULL; | |
74 | return; | |
75 | } | |
76 | fTree = (TTree*) fFile->Get("TE"); | |
77 | if (!fTree) { | |
78 | AliError(Form("no header tree found in file %s", fileName)); | |
79 | dir->cd(); | |
80 | return; | |
81 | } | |
82 | fHeader = new AliHeader; | |
83 | fTree->SetBranchAddress("Header", &fHeader); | |
84 | ||
85 | dir->cd(); | |
86 | } | |
87 | ||
88 | //_____________________________________________________________________________ | |
89 | AliVertexGenFile::~AliVertexGenFile() | |
90 | { | |
91 | // clean up | |
92 | ||
93 | if (fFile) fFile->Close(); | |
94 | delete fFile; | |
95 | delete fHeader; | |
96 | } | |
97 | ||
98 | ||
99 | //_____________________________________________________________________________ | |
100 | TVector3 AliVertexGenFile::GetVertex() | |
101 | { | |
102 | // get the vertex from the event header tree | |
103 | ||
104 | Int_t entry = fEvent++ / fEventsPerEntry; | |
105 | if (!fTree) { | |
106 | AliError("no header tree"); | |
107 | return TVector3(0,0,0); | |
108 | } | |
109 | ||
110 | if (fTree->GetEntry(entry) <= 0) { | |
111 | AliError(Form("error loading entry %d", entry)); | |
112 | return TVector3(0,0,0); | |
113 | } | |
114 | ||
115 | if (!fHeader->GenEventHeader()) { | |
116 | AliError("no generator event header"); | |
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 |