]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliHits2SDigits.C
Transition to NewIO
[u/mrichter/AliRoot.git] / STEER / AliHits2SDigits.C
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 "TRD/AliTRDdigitizer.h"
45 #include "TStopwatch.h"
46 #include "TRD/AliTRDparameter.h"
47 #endif
48
49 AliRunLoader* Init(TString fileName);
50
51 AliTRDdigitizer *InitTRDdigitizer();
52 void AliCopy(TFile *inputFile, TFile *outputFile);
53
54 // global variables
55
56 TFile *gFileHits = 0;
57 Bool_t gSameFiles = kFALSE;
58 Int_t gDEBUG = 1;
59
60
61 Int_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)
65 {
66 //
67 // Initialization
68 //
69   AliRunLoader* rl = Init(fileName);
70   if (!rl) return 1;
71   if (iCopy) {
72 //    AliCopy(gFileHits,fileSDigits);
73 //    gFileHits->cd();
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()) {
84       cerr<<"AliITSgeom not found." << endl;
85       iITS = 0;
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) {
109     sdPHOS = new AliPHOSSDigitizer(fileName.Data());
110   }
111
112
113
114 //
115 // loop over events
116 //
117   TStopwatch timer;
118   timer.Start();
119   for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
120     rl->GetEvent(iEvent);
121 //    gAlice->MakeTree("S",fileSDigits);
122     
123 // ITS
124     if (iITS) {
125       if (gDEBUG) {cout<<"  Create ITS sdigits: ";}
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;}
138     }
139
140 // TPC
141     if (iTPC) {
142       if (gDEBUG) {cout<<"  Create TPC sdigits: ";}
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;}
156     }
157
158 // TRD
159     if (iTRD) {
160       if (gDEBUG) {cout<<"  Create TRD sdigits: ";}
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;}
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
188   delete rl;
189 }
190  
191
192 ////////////////////////////////////////////////////////////////////////
193 AliRunLoader* Init(TString fileName) 
194  {
195 // open input file, read in gAlice, prepare output file
196   if (gAlice) delete gAlice;
197   gAlice = 0;
198   AliRunLoader*rl = AliRunLoader::Open(fileName);
199   if (rl == 0x0) return 0x0;
200   rl->LoadgAlice();
201   gAlice = rl->GetAliRun();
202   return rl;
203  
204 }
205
206
207 ////////////////////////////////////////////////////////////////////////
208 ////////////////////////////////////////////////////////////////////////
209 AliTRDdigitizer *InitTRDdigitizer() {
210 // initialization of TRD digitizer
211   AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
212                                      ,"TRD digitizer class");
213   sdTRD->SetDebug(0);
214   sdTRD->SetSDigits(kTRUE);
215   AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
216                                       ,"TRD parameter class");
217
218   sdTRD->SetParameter(TRDparam);
219   sdTRD->InitDetector();
220   if (!sdTRD->MakeBranch()) {
221     cerr<<"Problems with TRD digitizer initialization."<<endl;
222   }
223   return sdTRD;
224 }
225 ////////////////////////////////////////////////////////////////////////
226 /*void AliCopy(TFile *inputFile, TFile *outputFile) {
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 }
261 */