Adding track references at decay points (M.Ivanov)
[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
eab3429b 11//
12// input:
8de97894 13// TString fileName ... galice input file
eab3429b 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//
8de97894 20// 21.07.03 - changes for NewIO
21//
eab3429b 22// 04.04.02 - first version
23//
24////////////////////////////////////////////////////////////////////////
25
26#if !defined(__CINT__) || defined(__MAKECINT__)
88cb7938 27#include "iostream.h"
eab3429b 28#include "TTree.h"
29#include "TBranch.h"
30#include "TDirectory.h"
31#include "TFile.h"
32#include "AliRun.h"
33#include "TParticle.h"
88cb7938 34#include "TPC/AliTPCDigitsArray.h"
eab3429b 35#include "AliHeader.h"
36#include "TGeometry.h"
37#include "TObjArray.h"
38#include "TString.h"
88cb7938 39#include "ITS/AliITS.h"
40#include "TPC/AliTPC.h"
41#include "PHOS/AliPHOSSDigitizer.h"
42#include "TRD/AliTRDdigitizer.h"
eab3429b 43#include "TStopwatch.h"
88cb7938 44#include "TRD/AliTRDparameter.h"
eab3429b 45#endif
46
88cb7938 47AliRunLoader* Init(TString fileName);
48
eab3429b 49AliTRDdigitizer *InitTRDdigitizer();
eab3429b 50
51// global variables
52
53TFile *gFileHits = 0;
54Bool_t gSameFiles = kFALSE;
55Int_t gDEBUG = 1;
56
57
8de97894 58Int_t AliHits2SDigits(TString fileName="galice.root",
88cb7938 59 Int_t nEvents = 1, Int_t firstEvent = 0, Int_t iITS = 0,
8de97894 60 Int_t iTPC = 0, Int_t iTRD = 0,Int_t iPHOS = 0)
eab3429b 61{
62//
63// Initialization
64//
88cb7938 65 AliRunLoader* rl = Init(fileName);
66 if (!rl) return 1;
eab3429b 67
68// ITS
8de97894 69 AliITS *ITS = NULL;
eab3429b 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()) {
277674fa 76 cerr<<"AliITSgeom not found." << endl;
88cb7938 77 iITS = 0;
eab3429b 78 }
79 }
80
81// TPC
8de97894 82 AliTPC *TPC = NULL;
eab3429b 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
8de97894 92 AliTRDdigitizer *sdTRD = NULL;
eab3429b 93 if (iTRD) {
94 sdTRD = InitTRDdigitizer();
95 }
96
97
98// PHOS
8de97894 99 AliPHOSSDigitizer *sdPHOS = NULL;
eab3429b 100 if (iPHOS) {
88cb7938 101 sdPHOS = new AliPHOSSDigitizer(fileName.Data());
eab3429b 102 }
103
88cb7938 104
eab3429b 105
106//
107// loop over events
108//
109 TStopwatch timer;
110 timer.Start();
111 for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
88cb7938 112 rl->GetEvent(iEvent);
113// gAlice->MakeTree("S",fileSDigits);
eab3429b 114
115// ITS
116 if (iITS) {
117 if (gDEBUG) {cout<<" Create ITS sdigits: ";}
88cb7938 118 AliLoader* loader = rl->GetLoader("ITSLoader");
119 if (loader)
120 {
121 loader->LoadHits("read");
8de97894 122 loader->LoadSDigits("recreate");
123 if(!loader->TreeS()) loader->MakeTree("S");
124 ITS->MakeBranch("S");
88cb7938 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;}
eab3429b 132 }
133
134// TPC
135 if (iTPC) {
136 if (gDEBUG) {cout<<" Create TPC sdigits: ";}
88cb7938 137 AliLoader* loader = rl->GetLoader("TPCLoader");
138 if (loader)
139 {
140 loader->LoadHits("read");
8de97894 141 loader->LoadSDigits("recreate");
88cb7938 142
8de97894 143 TPC->SetTreeAddress();
88cb7938 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;}
eab3429b 151 }
152
153// TRD
154 if (iTRD) {
155 if (gDEBUG) {cout<<" Create TRD sdigits: ";}
88cb7938 156 AliLoader* loader = rl->GetLoader("TRDLoader");
157 if (loader)
158 {
159 loader->LoadHits("read");
8de97894 160 loader->LoadSDigits("recreate");
88cb7938 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;}
eab3429b 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
88cb7938 183 delete rl;
8de97894 184 return 0;
eab3429b 185}
186
187
188////////////////////////////////////////////////////////////////////////
88cb7938 189AliRunLoader* Init(TString fileName)
190 {
eab3429b 191// open input file, read in gAlice, prepare output file
192 if (gAlice) delete gAlice;
193 gAlice = 0;
88cb7938 194 AliRunLoader*rl = AliRunLoader::Open(fileName);
195 if (rl == 0x0) return 0x0;
196 rl->LoadgAlice();
197 gAlice = rl->GetAliRun();
198 return rl;
199
eab3429b 200}
201
eab3429b 202
203////////////////////////////////////////////////////////////////////////
eab3429b 204////////////////////////////////////////////////////////////////////////
205AliTRDdigitizer *InitTRDdigitizer() {
206// initialization of TRD digitizer
207 AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
88cb7938 208 ,"TRD digitizer class");
eab3429b 209 sdTRD->SetDebug(0);
210 sdTRD->SetSDigits(kTRUE);
211 AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
88cb7938 212 ,"TRD parameter class");
eab3429b 213
214 sdTRD->SetParameter(TRDparam);
215 sdTRD->InitDetector();
216 return sdTRD;
217}