]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliHits2SDigits.C
TOF raw data: preliminary implementation and style changes
[u/mrichter/AliRoot.git] / TOF / AliHits2SDigits.C
CommitLineData
ea7a588a 1////////////////////////////////////////////////////////////////////////
2//
3// name: AliHits2SDigits
4// date: 4.4.2002
5// last update: 4.4.2002
6// author: Jiri Chudoba
7// version: 1.0
8//
9// description:
10// creates sdigits for several detectors
11// stores sdigits in separate file (or in the source file
12// with hits). Stores gAlice object and copies TE to the
13// file with sdigits
14//
15// input:
16// TString fileNameSDigits ... output file with sdigits
17// TString fileNameHits ... input file with hits
18// Int_t nEvents ... how many events to proceed
19// Int_t firstEvent ... first event number
20// Int_t ITS, TPC, ... many flags for diff. detectors
21//
22// History:
23//
24// 04.04.02 - first version
25//
26////////////////////////////////////////////////////////////////////////
27
28#if !defined(__CINT__) || defined(__MAKECINT__)
29#include "iostream.h"
30#include "TTree.h"
31#include "TBranch.h"
32#include "TDirectory.h"
33#include "TFile.h"
34#include "AliRun.h"
35#include "TParticle.h"
36#include "TPC/AliTPCDigitsArray.h"
37#include "AliHeader.h"
38#include "TGeometry.h"
39#include "TObjArray.h"
40#include "TString.h"
41#include "ITS/AliITS.h"
42#include "TPC/AliTPC.h"
43#include "PHOS/AliPHOSSDigitizer.h"
44#include "TOF/AliTOFSDigitizer.h"
45#include "TRD/AliTRDdigitizer.h"
46#include "TStopwatch.h"
47#include "TRD/AliTRDparameter.h"
48#endif
49
50TFile* Init(TString fileNameSDigits, TString fileNameHits);
51TFile* OpenFile(TString fileName);
52Bool_t ImportgAlice(TFile *file);
53AliTRDdigitizer *InitTRDdigitizer();
54void AliCopy(TFile *inputFile, TFile *outputFile);
55
56// global variables
57
58TFile *gFileHits = 0;
59Bool_t gSameFiles = kFALSE;
60Int_t gDEBUG = 1;
61
62
63Int_t AliHits2SDigits(TString fileNameSDigits="sdigits.root",
bf6bf84c 64 TString fileNameHits="galice.root",
ea7a588a 65 Int_t nEvents = 1, Int_t firstEvent = 0, Int_t iITS = 0,
66 Int_t iTPC = 0, Int_t iTRD = 0,Int_t iPHOS = 0,
67 Int_t iTOF = 1, Int_t iCopy = 1)
68{
69//
70// Initialization
71//
72 TFile *fileSDigits;
73 fileSDigits = Init(fileNameSDigits, fileNameHits);
74 if (!fileSDigits) return 1;
75 if (iCopy) {
76 AliCopy(gFileHits,fileSDigits);
77 gFileHits->cd();
78 }
79
80// ITS
81 AliITS *ITS;
82 if (iITS) {
83 ITS = (AliITS*) gAlice->GetModule("ITS");
84 if (!ITS) {
85 iITS = 0;
86 cerr<<"AliITS object not found on file." << endl;
87 } else if (!ITS->GetITSgeom()) {
88 cerr<<"AliITSgeom not found." << endl;
89 iITS = 0;
90 }
91 }
92
93// TPC
94 AliTPC *TPC;
95 if (iTPC) {
96 TPC = (AliTPC*)gAlice->GetDetector("TPC");
97 if (!TPC) {
98 iTPC = 0;
99 cerr<<"AliTPC object not found"<<endl;
100 }
101 }
102
103// TRD
104 AliTRDdigitizer *sdTRD;
105 if (iTRD) {
106 sdTRD = InitTRDdigitizer();
107 }
108
109
110// PHOS
111 AliPHOSSDigitizer *sdPHOS;
112 if (iPHOS) {
113 sdPHOS = new AliPHOSSDigitizer(fileNameHits.Data());
114 }
115
116// TOF
117 AliTOFSDigitizer *sdTOF;
118 if (iTOF) {
bf6bf84c 119 sdTOF = new AliTOFSDigitizer(fileNameHits.Data(),firstEvent,nEvents);
ea7a588a 120 }
121
122
123//
124// loop over events
125//
126 TStopwatch timer;
127 timer.Start();
128 for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
129 gAlice->GetEvent(iEvent);
130 gAlice->MakeTree("S",fileSDigits);
131
132// ITS
133 if (iITS) {
134 if (gDEBUG) {cout<<" Create ITS sdigits: ";}
135 ITS->MakeBranch("S");
136 ITS->SetTreeAddress();
137 ITS->Hits2SDigits();
138 if (gDEBUG) {cout<<"done"<<endl;}
139 }
140
141// TPC
142 if (iTPC) {
143 if (gDEBUG) {cout<<" Create TPC sdigits: ";}
144 TPC->SetActiveSectors(1);
145 TPC->Hits2SDigits2(iEvent);
146 if (gDEBUG) {cout<<"done"<<endl;}
147 }
148
149// TRD
150 if (iTRD) {
151 if (gDEBUG) {cout<<" Create TRD sdigits: ";}
152 sdTRD->InitOutput(fileSDigits, iEvent);
153 sdTRD->MakeDigits();
154 sdTRD->WriteDigits();
155 if (gDEBUG) {cout<<"done"<<endl;}
156 }
157
158 } // end of loop over events
159
160// PHOS processes always all events
161 if (iPHOS) {
162 sdPHOS->ExecuteTask("deb all");
163 }
164
165// TOF (precesses the events as specified in the AliTOFSDigitizer
166// par ctor)
167 if (iTOF) {
168 // Activate this line if you want to print the
169 // parameters used for sdigitization
170 // sdTOF->PrintParameters();
171 sdTOF->Exec("all");
172 }
173
174//
175// finish
176//
177 timer.Stop();
178 timer.Print();
179
180 if (iTRD) {
181 fileSDigits->cd();
182 sdTRD->GetParameter()->Write();
183 gFileHits->cd();
184 }
185
186 fileSDigits->Close();
187 delete fileSDigits;
188 if (!gSameFiles) {
189 gFileHits->Close();
190 delete gFileHits;
191 }
192
193}
194
195
196////////////////////////////////////////////////////////////////////////
197TFile* Init(TString fileNameSDigits, TString fileNameHits) {
198// open input file, read in gAlice, prepare output file
199 if (gAlice) delete gAlice;
200 gAlice = 0;
201
202 Bool_t gSameFiles = kFALSE;
203 if (fileNameSDigits == fileNameHits || fileNameSDigits == "") gSameFiles = kTRUE;
204
205 TString fileMode = "read";
206 if (gSameFiles) fileMode = "update";
207
208 gFileHits = TFile::Open(fileNameHits.Data(),fileMode.Data());
209 if (!gFileHits->IsOpen()) {
210 cerr<<"Can't open "<<fileNameHits.Data()<<" !\n";
211 return 0;
212 }
213 if (!ImportgAlice(gFileHits)) return 0;
214 if (!gSameFiles) return gAlice->InitTreeFile("S",fileNameSDigits.Data());
215 return gFileHits;
216
217}
218
219////////////////////////////////////////////////////////////////////////
220TFile* OpenFile(TString fileName) {
221// open file fileName
222 TFile *file = TFile::Open(fileName.Data());
223 if (!file->IsOpen()) {
224 cerr<<"Can't open "<<fileName.Data()<<" !\n";
225 return 0;
226 }
227 return file;
228}
229
230////////////////////////////////////////////////////////////////////////
231Bool_t ImportgAlice(TFile *file) {
232// read in gAlice object from the file
233 gAlice = (AliRun*)file->Get("gAlice");
234 if (!gAlice) return kFALSE;
235 return kTRUE;
236}
237////////////////////////////////////////////////////////////////////////
238AliTRDdigitizer *InitTRDdigitizer() {
239// initialization of TRD digitizer
240 AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
241 ,"TRD digitizer class");
242 sdTRD->SetDebug(0);
243 sdTRD->SetSDigits(kTRUE);
244 AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
245 ,"TRD parameter class");
246
247 sdTRD->SetParameter(TRDparam);
248 sdTRD->InitDetector();
249 return sdTRD;
250}
251////////////////////////////////////////////////////////////////////////
252void AliCopy(TFile *inputFile, TFile *outputFile) {
253// copy some objects
254
255// copy gAlice
256 if (gDEBUG) cout<<"Copy gAlice: ";
257 outputFile->cd();
258 gAlice->Write();
259 if (gDEBUG) cout<<"done"<<endl;
260
261 TTree *treeE = gAlice->TreeE();
262 if (!treeE) {
263 cerr<<"No TreeE found "<<endl;
264 return;
265 }
266
267// copy TreeE
268 if (gDEBUG) cout<<"Copy TreeE: ";
269 AliHeader *header = new AliHeader();
270 treeE->SetBranchAddress("Header", &header);
271 treeE->SetBranchStatus("*",1);
272 TTree *treeENew = treeE->CloneTree();
273 treeENew->Write();
274 if (gDEBUG) cout<<"done"<<endl;
275
276// copy AliceGeom
277 if (gDEBUG) cout<<"Copy AliceGeom: ";
278 TGeometry *AliceGeom = static_cast<TGeometry*>(inputFile->Get("AliceGeom"));
279 if (!AliceGeom) {
280 cerr<<"AliceGeom was not found in the input file "<<endl;
281 return;
282 }
283 AliceGeom->Write();
284 if (gDEBUG) cout<<"done"<<endl;
285
286}