]>
Commit | Line | Data |
---|---|---|
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 | |
33 | #include "AliGenEventHeader.h" | |
34 | #include "AliHeader.h" | |
35 | #include "AliVertexGenFile.h" | |
14248849 | 36 | |
37 | ||
38 | ClassImp(AliVertexGenFile) | |
39 | ||
40 | ||
41 | //_____________________________________________________________________________ | |
42 | AliVertexGenFile::AliVertexGenFile() : | |
43 | fFile(NULL), | |
44 | fTree(NULL), | |
45 | fHeader(NULL), | |
46 | fEventsPerEntry(0), | |
47 | fEvent(0) | |
48 | { | |
49 | // default constructor: initialize data members | |
50 | ||
51 | } | |
52 | ||
53 | //_____________________________________________________________________________ | |
54 | AliVertexGenFile::AliVertexGenFile(const char* fileName, | |
55 | Int_t eventsPerEntry) : | |
56 | fFile(NULL), | |
57 | fTree(NULL), | |
58 | fHeader(NULL), | |
59 | fEventsPerEntry(eventsPerEntry), | |
60 | fEvent(0) | |
61 | { | |
62 | // main constructor: | |
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 | |
65 | ||
66 | TDirectory* dir = gDirectory; | |
67 | ||
68 | fFile = TFile::Open(fileName); | |
84061f6b | 69 | if (!fFile || !fFile->IsOpen()) { |
14248849 | 70 | Error("AliVertexGenFile", "could not open file %s", fileName); |
84061f6b | 71 | delete fFile; |
72 | fFile = NULL; | |
14248849 | 73 | return; |
74 | } | |
75 | fTree = (TTree*) fFile->Get("TE"); | |
76 | if (!fTree) { | |
84061f6b | 77 | Error("AliVertexGenFile", "no header tree found in file %s", fileName); |
14248849 | 78 | dir->cd(); |
79 | return; | |
80 | } | |
81 | fHeader = new AliHeader; | |
82 | fTree->SetBranchAddress("Header", &fHeader); | |
83 | ||
84 | dir->cd(); | |
85 | } | |
86 | ||
87 | //_____________________________________________________________________________ | |
88 | AliVertexGenFile::~AliVertexGenFile() | |
89 | { | |
90 | // clean up | |
91 | ||
84061f6b | 92 | if (fFile) fFile->Close(); |
14248849 | 93 | delete fFile; |
94 | delete fHeader; | |
95 | } | |
96 | ||
97 | ||
98 | //_____________________________________________________________________________ | |
99 | TVector3 AliVertexGenFile::GetVertex() | |
100 | { | |
101 | // get the vertex from the event header tree | |
102 | ||
103 | Int_t entry = fEvent++ / fEventsPerEntry; | |
84061f6b | 104 | if (!fTree) { |
105 | Error("GetVertex", "no header tree"); | |
106 | return TVector3(0,0,0); | |
107 | } | |
108 | ||
14248849 | 109 | if (fTree->GetEntry(entry) <= 0) { |
110 | Error("GetVertex", "error loading entry %d", entry); | |
111 | return TVector3(0,0,0); | |
112 | } | |
113 | ||
114 | if (!fHeader->GenEventHeader()) { | |
115 | Error("GetVertex", "no generator event header"); | |
116 | return TVector3(0,0,0); | |
117 | } | |
118 | ||
119 | TArrayF vertex(3); | |
120 | fHeader->GenEventHeader()->PrimaryVertex(vertex); | |
121 | return TVector3(vertex[0], vertex[1], vertex[2]); | |
122 | } | |
123 | ||
124 |