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