]>
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); | |
68 | if (!fFile) { | |
69 | Error("AliVertexGenFile", "could not open file %s", fileName); | |
70 | return; | |
71 | } | |
72 | fTree = (TTree*) fFile->Get("TE"); | |
73 | if (!fTree) { | |
74 | Error("AliVertexGenFile", "not header tree found in file %s", fileName); | |
75 | dir->cd(); | |
76 | return; | |
77 | } | |
78 | fHeader = new AliHeader; | |
79 | fTree->SetBranchAddress("Header", &fHeader); | |
80 | ||
81 | dir->cd(); | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliVertexGenFile::~AliVertexGenFile() | |
86 | { | |
87 | // clean up | |
88 | ||
89 | fFile->Close(); | |
90 | delete fFile; | |
91 | delete fHeader; | |
92 | } | |
93 | ||
94 | ||
95 | //_____________________________________________________________________________ | |
96 | TVector3 AliVertexGenFile::GetVertex() | |
97 | { | |
98 | // get the vertex from the event header tree | |
99 | ||
100 | Int_t entry = fEvent++ / fEventsPerEntry; | |
101 | if (fTree->GetEntry(entry) <= 0) { | |
102 | Error("GetVertex", "error loading entry %d", entry); | |
103 | return TVector3(0,0,0); | |
104 | } | |
105 | ||
106 | if (!fHeader->GenEventHeader()) { | |
107 | Error("GetVertex", "no generator event header"); | |
108 | return TVector3(0,0,0); | |
109 | } | |
110 | ||
111 | TArrayF vertex(3); | |
112 | fHeader->GenEventHeader()->PrimaryVertex(vertex); | |
113 | return TVector3(vertex[0], vertex[1], vertex[2]); | |
114 | } | |
115 | ||
116 |