]>
Commit | Line | Data |
---|---|---|
517b7f8f | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2000, 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 | **************************************************************************/ | |
88cb7938 | 15 | //Piotr.Skowronski@cern.ch : |
16 | //Corrections applied in order to compile (only) with new I/O and folder structure | |
17 | //To be implemented correctly by responsible | |
18 | ||
19 | #include "AliRunLoader.h" | |
20 | #include "AliLoader.h" | |
517b7f8f | 21 | |
517b7f8f | 22 | #include <TTree.h> |
23 | #include <TVector.h> | |
24 | #include <TObjArray.h> | |
25 | #include <TFile.h> | |
26 | #include <TDirectory.h> | |
27 | ||
28 | ||
29 | #include "AliTOFMerger.h" | |
30 | #include "AliTOF.h" | |
31 | #include "AliTOFSDigitizer.h" | |
32 | #include "AliTOFhit.h" | |
33 | #include "AliTOFdigit.h" | |
34 | ||
35 | #include "AliRun.h" | |
36 | #include "AliPDG.h" | |
37 | ||
38 | #include <stdlib.h> | |
f8014e68 | 39 | #include <Riostream.h> |
40 | #include <Riostream.h> | |
517b7f8f | 41 | |
42 | ClassImp(AliTOFMerger) | |
43 | ||
44 | //___________________________________________ | |
45 | AliTOFMerger::AliTOFMerger() | |
46 | { | |
bd0c63ae | 47 | // Default ctor |
48 | fNDigits = 0; | |
517b7f8f | 49 | fEvNrSig = 0; |
50 | fEvNrBgr = 0; | |
51 | fMerge =kDigitize; | |
2685bf00 | 52 | fDigits = 0; |
53 | fSDigits =0; | |
54 | fFnBgr = 0; | |
55 | fFnSig = 0; | |
56 | fBgrFile = 0; | |
88cb7938 | 57 | fRunLoader = 0 ; |
517b7f8f | 58 | } |
59 | ||
60 | //------------------------------------------------------------------------ | |
61 | AliTOFMerger::~AliTOFMerger() | |
62 | { | |
bd0c63ae | 63 | // Dtor |
517b7f8f | 64 | if(fSDigits) { |
65 | fSDigits->Delete(); | |
66 | delete fSDigits ; | |
67 | fSDigits = 0; | |
68 | } | |
2d8b0188 | 69 | delete fBgrFile; |
70 | fBgrFile = 0; | |
71 | if(fFnBgr) { | |
72 | delete[] fFnBgr; | |
73 | fFnBgr = 0; | |
74 | } | |
75 | if(fFnSig) { | |
76 | delete[] fFnSig; | |
77 | fFnSig = 0; | |
78 | } | |
88cb7938 | 79 | delete fRunLoader; |
517b7f8f | 80 | } |
81 | ||
82 | ||
83 | //------------------------------------------------------------------------ | |
84 | void AliTOFMerger::Init() | |
85 | { | |
86 | // Initialisation | |
87 | if (fMerge) fBgrFile = InitBgr(); | |
88 | ||
89 | } | |
90 | ||
91 | ||
92 | ||
93 | //------------------------------------------------------------------------ | |
94 | TFile* AliTOFMerger::InitBgr() | |
95 | { | |
96 | // Initialise background event | |
88cb7938 | 97 | fRunLoader = AliRunLoader::Open(fFnBgr);//open session and mount on default event folder |
98 | ||
517b7f8f | 99 | TFile *file = new TFile(fFnBgr); |
100 | // add error checking later | |
101 | printf("\n AliTOFMerger has opened %s file with background event \n", fFnBgr); | |
102 | return file; | |
103 | } | |
104 | ||
105 | //------------------------------------------------------------------------ | |
106 | void AliTOFMerger::Digitise() | |
107 | { | |
bd0c63ae | 108 | // as in FMD |
109 | // keep galice.root for signal and name differently the file for | |
110 | // background when add! otherwise the track info for signal will be lost ! | |
111 | ||
517b7f8f | 112 | #ifdef DEBUG |
113 | cout<<"ALiTOFMerger::>SDigits2Digits start...\n"; | |
114 | #endif | |
88cb7938 | 115 | Int_t retval; |
116 | ||
117 | if (fRunLoader == 0x0) | |
118 | { | |
119 | Error("Exec","Event is not loaded. Exiting"); | |
120 | return; | |
121 | } | |
88cb7938 | 122 | |
f540341d | 123 | if (fRunLoader->GetAliRun() == 0x0) { |
124 | retval = fRunLoader->LoadgAlice(); | |
125 | if (retval) | |
126 | { | |
127 | Error("Exec","Error occured while loading gAlice. Exiting"); | |
128 | return; | |
129 | } | |
130 | } | |
131 | ||
132 | if (fRunLoader->TreeE() == 0x0) { | |
133 | retval = fRunLoader->LoadHeader(); | |
134 | if (retval) | |
135 | { | |
136 | Error("Exec","Error occured while loading header. Exiting"); | |
137 | return; | |
138 | } | |
139 | } | |
140 | ||
141 | if (fRunLoader->TreeK() == 0x0) { | |
142 | retval = fRunLoader->LoadKinematics("READ"); | |
143 | if (retval) | |
144 | { | |
145 | Error("Exec","Error occured while loading kinematics. Exiting"); | |
146 | return; | |
147 | } | |
148 | } | |
88cb7938 | 149 | |
150 | AliLoader* gime = fRunLoader->GetLoader("TOFLoader"); | |
151 | if (gime == 0x0) | |
152 | { | |
153 | Error("Exec","Can not find TOF loader in event. Exiting."); | |
154 | return; | |
155 | } | |
156 | gAlice = fRunLoader->GetAliRun(); | |
157 | ||
bd0c63ae | 158 | AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ; |
159 | ||
160 | ||
161 | TFile *f1 =0; | |
88cb7938 | 162 | TTree *TK = fRunLoader->TreeK(); |
bd0c63ae | 163 | if (TK) f1 = TK->GetCurrentFile(); |
164 | ||
88cb7938 | 165 | fRunLoader->GetEvent(fEvNrSig); |
166 | ||
167 | if(gime->TreeD() == 0) | |
168 | gime->MakeTree("D") ; | |
bd0c63ae | 169 | |
88cb7938 | 170 | gime->TreeD()->Reset(); |
bd0c63ae | 171 | |
172 | // read and write digits for signal | |
173 | ReadWriteDigit(fEvNrSig); | |
174 | ||
88cb7938 | 175 | if(fMerge) |
176 | { | |
177 | // bgr file | |
178 | fBgrFile->cd(); | |
179 | // gAlice->TreeS()->Reset(); | |
180 | gAlice = (AliRun*)fBgrFile->Get("gAlice"); | |
181 | ReadWriteDigit(fEvNrBgr); | |
182 | } //if merge | |
bd0c63ae | 183 | |
184 | ||
185 | f1->cd(); | |
186 | ||
187 | //Make branch for digits | |
188 | TOF->MakeBranch("D"); | |
189 | ||
88cb7938 | 190 | gime->TreeD()->Reset(); |
191 | gime->TreeD()->Fill(); | |
bd0c63ae | 192 | |
193 | fDigits = TOF->Digits(); | |
194 | ||
88cb7938 | 195 | gime->WriteDigits("OVERWRITE"); |
bd0c63ae | 196 | |
197 | gAlice->ResetDigits(); | |
198 | ||
199 | } | |
200 | ||
201 | //--------------------------------------------------------------------- | |
202 | ||
203 | void AliTOFMerger::ReadWriteDigit(Int_t iEvNum) | |
204 | { | |
205 | // | |
206 | // Read Sdigits from the current file and write them in the TreeD | |
207 | // | |
208 | AliTOFdigit* tofsdigit; | |
209 | ||
210 | AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ; | |
211 | ||
88cb7938 | 212 | Int_t retval = fRunLoader->GetEvent(iEvNum); |
213 | if (retval) | |
214 | { | |
215 | Error("ReadWriteDigit","Error while getting event %d",iEvNum); | |
216 | return; | |
217 | } | |
218 | ||
219 | AliLoader* gime = fRunLoader->GetLoader("TOFLoader"); | |
220 | if (gime == 0x0) | |
221 | { | |
222 | Error("Exec","Can not find TOF loader in event. Exiting."); | |
223 | return; | |
224 | } | |
225 | ||
226 | ||
227 | ||
228 | if(gime->TreeS()==0) | |
229 | { | |
230 | cout<<" TreeS==0 -> return"<<gime->TreeS()<<endl; | |
231 | return ; | |
232 | } | |
bd0c63ae | 233 | |
234 | Int_t ndig, k; | |
235 | Int_t tracks[3]; // track info | |
236 | Int_t vol[5]; // location for a digit | |
237 | Float_t digit[2]; // TOF digit variables | |
238 | ||
239 | gAlice->ResetDigits(); | |
88cb7938 | 240 | gime->TreeS()->GetEvent(iEvNum); |
bd0c63ae | 241 | TClonesArray * TOFdigits = tofinfile->SDigits(); |
242 | ||
243 | ndig=TOFdigits->GetEntries(); | |
244 | ||
245 | for (k=0; k<ndig; k++) { | |
246 | tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k); | |
247 | ||
248 | tracks[0] = tofsdigit->GetTrack(0); | |
249 | tracks[1] = tofsdigit->GetTrack(1); | |
250 | tracks[2] = tofsdigit->GetTrack(2); | |
251 | ||
252 | vol[0] = tofsdigit->GetSector(); | |
253 | vol[1] = tofsdigit->GetPlate(); | |
766a7c4e | 254 | vol[2] = tofsdigit->GetStrip(); |
255 | vol[3] = tofsdigit->GetPadx(); | |
256 | vol[4] = tofsdigit->GetPadz(); | |
bd0c63ae | 257 | |
258 | digit[0] = tofsdigit->GetTdc(); | |
259 | digit[1] = tofsdigit->GetAdc(); | |
260 | ||
261 | new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit); | |
262 | } // end loop on sdigits in the current file | |
517b7f8f | 263 | } |
bd0c63ae | 264 | |
265 | ||
266 |