]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliHits2SDigits.C
Adding track references at decay points (M.Ivanov)
[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 //
12 // input:
13 //       TString fileName ... galice input file
14 //       Int_t nEvents  ... how many events to proceed
15 //       Int_t firstEvent  ... first event number
16 //       Int_t ITS, TPC, ...   many flags for diff. detectors
17 //
18 // History:
19 //
20 // 21.07.03 - changes for NewIO
21 //
22 // 04.04.02 - first version
23 // 
24 ////////////////////////////////////////////////////////////////////////
25
26 #if !defined(__CINT__) || defined(__MAKECINT__)
27 #include "iostream.h"
28 #include "TTree.h"
29 #include "TBranch.h"
30 #include "TDirectory.h"
31 #include "TFile.h"
32 #include "AliRun.h"
33 #include "TParticle.h"
34 #include "TPC/AliTPCDigitsArray.h"
35 #include "AliHeader.h"
36 #include "TGeometry.h"
37 #include "TObjArray.h"
38 #include "TString.h"
39 #include "ITS/AliITS.h"
40 #include "TPC/AliTPC.h"
41 #include "PHOS/AliPHOSSDigitizer.h"
42 #include "TRD/AliTRDdigitizer.h"
43 #include "TStopwatch.h"
44 #include "TRD/AliTRDparameter.h"
45 #endif
46
47 AliRunLoader* Init(TString fileName);
48
49 AliTRDdigitizer *InitTRDdigitizer();
50
51 // global variables
52
53 TFile *gFileHits = 0;
54 Bool_t gSameFiles = kFALSE;
55 Int_t gDEBUG = 1;
56
57
58 Int_t AliHits2SDigits(TString fileName="galice.root", 
59                   Int_t nEvents = 1, Int_t firstEvent = 0, Int_t iITS = 0,
60                   Int_t iTPC = 0, Int_t iTRD = 0,Int_t iPHOS = 0)
61 {
62 //
63 // Initialization
64 //
65   AliRunLoader* rl = Init(fileName);
66   if (!rl) return 1;
67
68 // ITS
69   AliITS *ITS = NULL;
70   if (iITS) {
71     ITS  = (AliITS*) gAlice->GetModule("ITS");
72     if (!ITS) {
73       iITS = 0;
74       cerr<<"AliITS object not found on file." << endl;
75     } else if (!ITS->GetITSgeom()) {
76       cerr<<"AliITSgeom not found." << endl;
77       iITS = 0;
78     }
79   }
80
81 // TPC
82   AliTPC *TPC = NULL;
83   if (iTPC) {
84     TPC = (AliTPC*)gAlice->GetDetector("TPC");
85     if (!TPC) {
86       iTPC = 0;
87       cerr<<"AliTPC object not found"<<endl;
88     }
89   }
90
91 // TRD
92   AliTRDdigitizer *sdTRD = NULL;
93   if (iTRD) {
94     sdTRD = InitTRDdigitizer();
95   }
96
97
98 // PHOS
99   AliPHOSSDigitizer *sdPHOS = NULL;
100   if (iPHOS) {
101     sdPHOS = new AliPHOSSDigitizer(fileName.Data());
102   }
103
104
105
106 //
107 // loop over events
108 //
109   TStopwatch timer;
110   timer.Start();
111   for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
112     rl->GetEvent(iEvent);
113 //    gAlice->MakeTree("S",fileSDigits);
114     
115 // ITS
116     if (iITS) {
117       if (gDEBUG) {cout<<"  Create ITS sdigits: ";}
118       AliLoader* loader = rl->GetLoader("ITSLoader");
119       if (loader)
120        { 
121         loader->LoadHits("read");
122         loader->LoadSDigits("recreate");
123         if(!loader->TreeS()) loader->MakeTree("S");
124         ITS->MakeBranch("S");
125         ITS->SetTreeAddress();
126         ITS->Hits2SDigits();
127         loader->UnloadHits();
128         loader->UnloadSDigits();
129         if (gDEBUG) {cout<<"done"<<endl;}
130        }
131       else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
132     }
133
134 // TPC
135     if (iTPC) {
136       if (gDEBUG) {cout<<"  Create TPC sdigits: ";}
137       AliLoader* loader = rl->GetLoader("TPCLoader");
138       if (loader)
139        { 
140         loader->LoadHits("read");
141         loader->LoadSDigits("recreate");
142       
143         TPC->SetTreeAddress();
144         TPC->SetActiveSectors(1);
145         TPC->Hits2SDigits2(iEvent);
146         loader->UnloadHits();
147         loader->UnloadSDigits();
148         if (gDEBUG) {cout<<"done"<<endl;}
149        }
150       else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
151     }
152
153 // TRD
154     if (iTRD) {
155       if (gDEBUG) {cout<<"  Create TRD sdigits: ";}
156       AliLoader* loader = rl->GetLoader("TRDLoader");
157       if (loader)
158        { 
159         loader->LoadHits("read");
160         loader->LoadSDigits("recreate");
161         sdTRD->MakeDigits();
162         sdTRD->WriteDigits();
163         loader->UnloadHits();
164         loader->UnloadSDigits();
165         if (gDEBUG) {cout<<"done"<<endl;}
166        }
167       else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
168     }
169     
170   } // end of loop over events
171
172 // PHOS processes always all events
173   if (iPHOS) {
174     sdPHOS->ExecuteTask("deb all");
175   }
176
177 //
178 // finish 
179 //
180   timer.Stop(); 
181   timer.Print();
182
183   delete rl;
184   return 0;
185 }
186  
187
188 ////////////////////////////////////////////////////////////////////////
189 AliRunLoader* Init(TString fileName) 
190  {
191 // open input file, read in gAlice, prepare output file
192   if (gAlice) delete gAlice;
193   gAlice = 0;
194   AliRunLoader*rl = AliRunLoader::Open(fileName);
195   if (rl == 0x0) return 0x0;
196   rl->LoadgAlice();
197   gAlice = rl->GetAliRun();
198   return rl;
199  
200 }
201
202
203 ////////////////////////////////////////////////////////////////////////
204 ////////////////////////////////////////////////////////////////////////
205 AliTRDdigitizer *InitTRDdigitizer() {
206 // initialization of TRD digitizer
207   AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
208                                      ,"TRD digitizer class");
209   sdTRD->SetDebug(0);
210   sdTRD->SetSDigits(kTRUE);
211   AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
212                                       ,"TRD parameter class");
213
214   sdTRD->SetParameter(TRDparam);
215   sdTRD->InitDetector();
216   return sdTRD;
217 }