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 "TRD/AliTRDdigitizer.h"
45 #include "TStopwatch.h"
46 #include "TRD/AliTRDparameter.h"
47 #include "TOF/AliTOFSDigitizer.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="rfio: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 = 0, 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()) {
89 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);
127 for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
128 gAlice->GetEvent(iEvent);
129 if (!gAlice->TreeS()) gAlice->MakeTree("S",fileSDigits);
133 if (gDEBUG) {cout<<" Create ITS sdigits: ";}
134 ITS->MakeBranch("S");
135 ITS->SetTreeAddress();
137 if (gDEBUG) {cout<<"done"<<endl;}
142 if (gDEBUG) {cout<<" Create TPC sdigits: ";}
144 // process all sectors
145 TPC->SetActiveSectors(1);
146 if (gDEBUG) {cout<<"All TPC sectors set active."<<endl;}
147 } else if (iTPC == 2) {
148 // process only sectors with hits
149 TPC->SetActiveSectors(0);
151 printf("\nActive sectors\n");
153 for (Int_t i=0;i<72;i++) {
154 if (TPC->IsSectorActive(i)) {
157 if (iActive%10 == 0) printf("\n");
163 TPC->Hits2SDigits2(iEvent);
164 if (gDEBUG) {cout<<"done"<<endl;}
169 if (gDEBUG) {cout<<" Create TRD sdigits: ";}
170 sdTRD->InitOutput(fileSDigits, iEvent);
172 sdTRD->WriteDigits();
173 if (gDEBUG) {cout<<"done"<<endl;}
176 } // end of loop over events
178 // PHOS processes always all events
180 sdPHOS->ExecuteTask("deb all");
183 // TOF does its own loop
197 sdTRD->GetParameter()->Write();
211 ////////////////////////////////////////////////////////////////////////
212 TFile* Init(TString fileNameSDigits, TString fileNameHits) {
213 // open input file, read in gAlice, prepare output file
214 if (gAlice) delete gAlice;
217 Bool_t gSameFiles = kFALSE;
218 if (fileNameSDigits == fileNameHits || fileNameSDigits == "") gSameFiles = kTRUE;
220 TString fileMode = "read";
221 if (gSameFiles) fileMode = "update";
223 gFileHits = TFile::Open(fileNameHits.Data(),fileMode.Data());
224 if (!gFileHits->IsOpen()) {
225 cerr<<"Can't open "<<fileNameHits.Data()<<" !\n";
228 if (!ImportgAlice(gFileHits)) return 0;
229 if (!gSameFiles) return gAlice->InitTreeFile("S",fileNameSDigits.Data());
234 ////////////////////////////////////////////////////////////////////////
235 TFile* OpenFile(TString fileName) {
236 // open file fileName
237 TFile *file = TFile::Open(fileName.Data());
238 if (!file->IsOpen()) {
239 cerr<<"Can't open "<<fileName.Data()<<" !\n";
245 ////////////////////////////////////////////////////////////////////////
246 Bool_t ImportgAlice(TFile *file) {
247 // read in gAlice object from the file
248 gAlice = (AliRun*)file->Get("gAlice");
249 if (!gAlice) return kFALSE;
252 ////////////////////////////////////////////////////////////////////////
253 AliTRDdigitizer *InitTRDdigitizer() {
254 // initialization of TRD digitizer
255 AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
256 ,"TRD digitizer class");
258 sdTRD->SetSDigits(kTRUE);
259 AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
260 ,"TRD parameter class");
262 sdTRD->SetParameter(TRDparam);
263 sdTRD->InitDetector();
264 if (!sdTRD->MakeBranch()) {
265 cerr<<"Problems with TRD digitizer initialization."<<endl;
269 ////////////////////////////////////////////////////////////////////////
270 void AliCopy(TFile *inputFile, TFile *outputFile) {
274 if (gDEBUG) cout<<"Copy gAlice: ";
277 if (gDEBUG) cout<<"done"<<endl;
279 TTree *treeE = gAlice->TreeE();
281 cerr<<"No TreeE found "<<endl;
286 if (gDEBUG) cout<<"Copy TreeE: ";
287 AliHeader *header = new AliHeader();
288 treeE->SetBranchAddress("Header", &header);
289 treeE->SetBranchStatus("*",1);
290 TTree *treeENew = treeE->CloneTree();
292 if (gDEBUG) cout<<"done"<<endl;
295 if (gDEBUG) cout<<"Copy AliceGeom: ";
296 TGeometry *AliceGeom = static_cast<TGeometry*>(inputFile->Get("AliceGeom"));
298 cerr<<"AliceGeom was not found in the input file "<<endl;
302 if (gDEBUG) cout<<"done"<<endl;