1 ////////////////////////////////////////////////////////////////////////
3 // name: AliHits2SDigits
5 // last update: 4.4.2002
6 // author: Jiri Chudoba
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
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
24 // 04.04.02 - first version
26 ////////////////////////////////////////////////////////////////////////
28 #if !defined(__CINT__) || defined(__MAKECINT__)
32 #include "TDirectory.h"
35 #include "TParticle.h"
36 #include "TPC/AliTPCDigitsArray.h"
37 #include "AliHeader.h"
38 #include "TGeometry.h"
39 #include "TObjArray.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"
50 TFile* Init(TString fileNameSDigits, TString fileNameHits);
51 TFile* OpenFile(TString fileName);
52 Bool_t ImportgAlice(TFile *file);
53 AliTRDdigitizer *InitTRDdigitizer();
54 void AliCopy(TFile *inputFile, TFile *outputFile);
59 Bool_t gSameFiles = kFALSE;
63 Int_t AliHits2SDigits(TString fileNameSDigits="sdigits.root",
64 TString fileNameHits="galice.root",
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)
73 fileSDigits = Init(fileNameSDigits, fileNameHits);
74 if (!fileSDigits) return 1;
76 AliCopy(gFileHits,fileSDigits);
83 ITS = (AliITS*) gAlice->GetModule("ITS");
86 cerr<<"AliITS object not found on file." << endl;
87 } else if (!ITS->GetITSgeom()) {
88 cerr<<"AliITSgeom not found." << endl;
96 TPC = (AliTPC*)gAlice->GetDetector("TPC");
99 cerr<<"AliTPC object not found"<<endl;
104 AliTRDdigitizer *sdTRD;
106 sdTRD = InitTRDdigitizer();
111 AliPHOSSDigitizer *sdPHOS;
113 sdPHOS = new AliPHOSSDigitizer(fileNameHits.Data());
117 AliTOFSDigitizer *sdTOF;
119 sdTOF = new AliTOFSDigitizer(fileNameHits.Data(),firstEvent,nEvents);
128 for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
129 gAlice->GetEvent(iEvent);
130 gAlice->MakeTree("S",fileSDigits);
134 if (gDEBUG) {cout<<" Create ITS sdigits: ";}
135 ITS->MakeBranch("S");
136 ITS->SetTreeAddress();
138 if (gDEBUG) {cout<<"done"<<endl;}
143 if (gDEBUG) {cout<<" Create TPC sdigits: ";}
144 TPC->SetActiveSectors(1);
145 TPC->Hits2SDigits2(iEvent);
146 if (gDEBUG) {cout<<"done"<<endl;}
151 if (gDEBUG) {cout<<" Create TRD sdigits: ";}
152 sdTRD->InitOutput(fileSDigits, iEvent);
154 sdTRD->WriteDigits();
155 if (gDEBUG) {cout<<"done"<<endl;}
158 } // end of loop over events
160 // PHOS processes always all events
162 sdPHOS->ExecuteTask("deb all");
165 // TOF (precesses the events as specified in the AliTOFSDigitizer
168 // Activate this line if you want to print the
169 // parameters used for sdigitization
170 // sdTOF->PrintParameters();
182 sdTRD->GetParameter()->Write();
186 fileSDigits->Close();
196 ////////////////////////////////////////////////////////////////////////
197 TFile* Init(TString fileNameSDigits, TString fileNameHits) {
198 // open input file, read in gAlice, prepare output file
199 if (gAlice) delete gAlice;
202 Bool_t gSameFiles = kFALSE;
203 if (fileNameSDigits == fileNameHits || fileNameSDigits == "") gSameFiles = kTRUE;
205 TString fileMode = "read";
206 if (gSameFiles) fileMode = "update";
208 gFileHits = TFile::Open(fileNameHits.Data(),fileMode.Data());
209 if (!gFileHits->IsOpen()) {
210 cerr<<"Can't open "<<fileNameHits.Data()<<" !\n";
213 if (!ImportgAlice(gFileHits)) return 0;
214 if (!gSameFiles) return gAlice->InitTreeFile("S",fileNameSDigits.Data());
219 ////////////////////////////////////////////////////////////////////////
220 TFile* 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";
230 ////////////////////////////////////////////////////////////////////////
231 Bool_t ImportgAlice(TFile *file) {
232 // read in gAlice object from the file
233 gAlice = (AliRun*)file->Get("gAlice");
234 if (!gAlice) return kFALSE;
237 ////////////////////////////////////////////////////////////////////////
238 AliTRDdigitizer *InitTRDdigitizer() {
239 // initialization of TRD digitizer
240 AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
241 ,"TRD digitizer class");
243 sdTRD->SetSDigits(kTRUE);
244 AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
245 ,"TRD parameter class");
247 sdTRD->SetParameter(TRDparam);
248 sdTRD->InitDetector();
251 ////////////////////////////////////////////////////////////////////////
252 void AliCopy(TFile *inputFile, TFile *outputFile) {
256 if (gDEBUG) cout<<"Copy gAlice: ";
259 if (gDEBUG) cout<<"done"<<endl;
261 TTree *treeE = gAlice->TreeE();
263 cerr<<"No TreeE found "<<endl;
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();
274 if (gDEBUG) cout<<"done"<<endl;
277 if (gDEBUG) cout<<"Copy AliceGeom: ";
278 TGeometry *AliceGeom = static_cast<TGeometry*>(inputFile->Get("AliceGeom"));
280 cerr<<"AliceGeom was not found in the input file "<<endl;
284 if (gDEBUG) cout<<"done"<<endl;