]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliHits2SDigits.C
Transition to NewIO
[u/mrichter/AliRoot.git] / STEER / AliHits2SDigits.C
CommitLineData
eab3429b 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__)
88cb7938 29#include "iostream.h"
eab3429b 30#include "TTree.h"
31#include "TBranch.h"
32#include "TDirectory.h"
33#include "TFile.h"
34#include "AliRun.h"
35#include "TParticle.h"
88cb7938 36#include "TPC/AliTPCDigitsArray.h"
eab3429b 37#include "AliHeader.h"
38#include "TGeometry.h"
39#include "TObjArray.h"
40#include "TString.h"
88cb7938 41#include "ITS/AliITS.h"
42#include "TPC/AliTPC.h"
43#include "PHOS/AliPHOSSDigitizer.h"
44#include "TRD/AliTRDdigitizer.h"
eab3429b 45#include "TStopwatch.h"
88cb7938 46#include "TRD/AliTRDparameter.h"
eab3429b 47#endif
48
88cb7938 49AliRunLoader* Init(TString fileName);
50
eab3429b 51AliTRDdigitizer *InitTRDdigitizer();
52void AliCopy(TFile *inputFile, TFile *outputFile);
53
54// global variables
55
56TFile *gFileHits = 0;
57Bool_t gSameFiles = kFALSE;
58Int_t gDEBUG = 1;
59
60
88cb7938 61Int_t AliHits2SDigits(TString fileName="rfio:galice.root",
62 Int_t nEvents = 1, Int_t firstEvent = 0, Int_t iITS = 0,
63 Int_t iTPC = 0, Int_t iTRD = 0,Int_t iPHOS = 0,
64 Int_t iCopy = 1)
eab3429b 65{
66//
67// Initialization
68//
88cb7938 69 AliRunLoader* rl = Init(fileName);
70 if (!rl) return 1;
eab3429b 71 if (iCopy) {
88cb7938 72// AliCopy(gFileHits,fileSDigits);
73// gFileHits->cd();
eab3429b 74 }
75
76// ITS
77 AliITS *ITS;
78 if (iITS) {
79 ITS = (AliITS*) gAlice->GetModule("ITS");
80 if (!ITS) {
81 iITS = 0;
82 cerr<<"AliITS object not found on file." << endl;
83 } else if (!ITS->GetITSgeom()) {
277674fa 84 cerr<<"AliITSgeom not found." << endl;
88cb7938 85 iITS = 0;
eab3429b 86 }
87 }
88
89// TPC
90 AliTPC *TPC;
91 if (iTPC) {
92 TPC = (AliTPC*)gAlice->GetDetector("TPC");
93 if (!TPC) {
94 iTPC = 0;
95 cerr<<"AliTPC object not found"<<endl;
96 }
97 }
98
99// TRD
100 AliTRDdigitizer *sdTRD;
101 if (iTRD) {
102 sdTRD = InitTRDdigitizer();
103 }
104
105
106// PHOS
107 AliPHOSSDigitizer *sdPHOS;
108 if (iPHOS) {
88cb7938 109 sdPHOS = new AliPHOSSDigitizer(fileName.Data());
eab3429b 110 }
111
88cb7938 112
eab3429b 113
114//
115// loop over events
116//
117 TStopwatch timer;
118 timer.Start();
119 for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
88cb7938 120 rl->GetEvent(iEvent);
121// gAlice->MakeTree("S",fileSDigits);
eab3429b 122
123// ITS
124 if (iITS) {
125 if (gDEBUG) {cout<<" Create ITS sdigits: ";}
88cb7938 126 AliLoader* loader = rl->GetLoader("ITSLoader");
127 if (loader)
128 {
129 loader->LoadHits("read");
130 loader->LoadSDigits("update");
131 ITS->SetTreeAddress();
132 ITS->Hits2SDigits();
133 loader->UnloadHits();
134 loader->UnloadSDigits();
135 if (gDEBUG) {cout<<"done"<<endl;}
136 }
137 else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
eab3429b 138 }
139
140// TPC
141 if (iTPC) {
142 if (gDEBUG) {cout<<" Create TPC sdigits: ";}
88cb7938 143 AliLoader* loader = rl->GetLoader("TPCLoader");
144 if (loader)
145 {
146 loader->LoadHits("read");
147 loader->LoadSDigits("update");
148
149 TPC->SetActiveSectors(1);
150 TPC->Hits2SDigits2(iEvent);
151 loader->UnloadHits();
152 loader->UnloadSDigits();
153 if (gDEBUG) {cout<<"done"<<endl;}
154 }
155 else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
eab3429b 156 }
157
158// TRD
159 if (iTRD) {
160 if (gDEBUG) {cout<<" Create TRD sdigits: ";}
88cb7938 161 AliLoader* loader = rl->GetLoader("TRDLoader");
162 if (loader)
163 {
164 loader->LoadHits("read");
165 loader->LoadSDigits("update");
166 sdTRD->MakeDigits();
167 sdTRD->WriteDigits();
168 loader->UnloadHits();
169 loader->UnloadSDigits();
170 if (gDEBUG) {cout<<"done"<<endl;}
171 }
172 else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
eab3429b 173 }
174
175 } // end of loop over events
176
177// PHOS processes always all events
178 if (iPHOS) {
179 sdPHOS->ExecuteTask("deb all");
180 }
181
182//
183// finish
184//
185 timer.Stop();
186 timer.Print();
187
88cb7938 188 delete rl;
eab3429b 189}
190
191
192////////////////////////////////////////////////////////////////////////
88cb7938 193AliRunLoader* Init(TString fileName)
194 {
eab3429b 195// open input file, read in gAlice, prepare output file
196 if (gAlice) delete gAlice;
197 gAlice = 0;
88cb7938 198 AliRunLoader*rl = AliRunLoader::Open(fileName);
199 if (rl == 0x0) return 0x0;
200 rl->LoadgAlice();
201 gAlice = rl->GetAliRun();
202 return rl;
203
eab3429b 204}
205
eab3429b 206
207////////////////////////////////////////////////////////////////////////
eab3429b 208////////////////////////////////////////////////////////////////////////
209AliTRDdigitizer *InitTRDdigitizer() {
210// initialization of TRD digitizer
211 AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
88cb7938 212 ,"TRD digitizer class");
eab3429b 213 sdTRD->SetDebug(0);
214 sdTRD->SetSDigits(kTRUE);
215 AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
88cb7938 216 ,"TRD parameter class");
eab3429b 217
218 sdTRD->SetParameter(TRDparam);
219 sdTRD->InitDetector();
59aa5372 220 if (!sdTRD->MakeBranch()) {
221 cerr<<"Problems with TRD digitizer initialization."<<endl;
222 }
eab3429b 223 return sdTRD;
224}
225////////////////////////////////////////////////////////////////////////
88cb7938 226/*void AliCopy(TFile *inputFile, TFile *outputFile) {
eab3429b 227// copy some objects
228
229// copy gAlice
230 if (gDEBUG) cout<<"Copy gAlice: ";
231 outputFile->cd();
232 gAlice->Write();
233 if (gDEBUG) cout<<"done"<<endl;
234
235 TTree *treeE = gAlice->TreeE();
236 if (!treeE) {
237 cerr<<"No TreeE found "<<endl;
238 return;
239 }
240
241// copy TreeE
242 if (gDEBUG) cout<<"Copy TreeE: ";
243 AliHeader *header = new AliHeader();
244 treeE->SetBranchAddress("Header", &header);
245 treeE->SetBranchStatus("*",1);
246 TTree *treeENew = treeE->CloneTree();
247 treeENew->Write();
248 if (gDEBUG) cout<<"done"<<endl;
249
250// copy AliceGeom
251 if (gDEBUG) cout<<"Copy AliceGeom: ";
252 TGeometry *AliceGeom = static_cast<TGeometry*>(inputFile->Get("AliceGeom"));
253 if (!AliceGeom) {
254 cerr<<"AliceGeom was not found in the input file "<<endl;
255 return;
256 }
257 AliceGeom->Write();
258 if (gDEBUG) cout<<"done"<<endl;
259
260}
88cb7938 261*/