1 #if !defined(__CINT__) || defined(__MAKECINT__)
5 #include "STEER/AliRun.h"
6 #include "STEER/AliRunDigitizer.h"
7 #include "ITS/AliITSDigitizer.h"
8 #include "ITS/AliITS.h"
9 #include "ITS/AliITSDetType.h"
10 #include "ITS/AliITSresponseSDD.h"
11 #include "TStopwatch.h"
15 TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
16 void writeAR(TFile * fin, TFile *fou);
17 Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt="");
19 Int_t AliITSHits2SDigits(TString hitFile = "galice.root",
20 TString sdigFile = "galice.root",TString opt=""){
21 // Standeard ITS Hits to SDigits.
23 // Dynamically link some shared libs
24 if (gClassTable->GetID("AliRun") < 0) {
25 gROOT->LoadMacro("loadlibs.C");
29 // Connect the Root Galice file containing Geometry, Kine and Hits
31 TFile *hitfile = 0; // pointer to input file.
32 TFile *sdigfile = 0; // possible output file for TreeD
33 if(sdigFile.CompareTo(hitFile) == 0){// write output to same file as input.
34 hitfile = AccessFile(hitFile,"U"); // input file open for update.
35 }else{ // different output file then input file.
36 hitfile = AccessFile(hitFile,"R"); // input file open as read only
37 // open output file and create TreeR on it
38 sdigfile = gAlice->InitTreeFile("S",sdigFile);
39 } // end if sdigFile == hitFile.
41 AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
43 cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
47 if(!(ITS->GetITSgeom())){
48 cerr << " AliITSgeom not found. Can't digitize with out it." << endl;
52 ChangeITSDefaults(hitfile,ITS,opt);
53 // write the AliRun object to the output file if different from input file.
54 if(sdigfile) writeAR(hitfile,sdigfile);
58 Int_t evNumber2 = gAlice->GetEventsPerRun();
60 for(Int_t event = evNumber1; event < evNumber2; event++){
61 gAlice->GetEvent(event);
62 if(!gAlice->TreeS() && sdigfile == 0){
63 cout << "Having to create the SDigits Tree." << endl;
64 gAlice->MakeTree("S");
65 } // end if !gAlice->TreeS()
66 if(sdigfile) gAlice->MakeTree("S",sdigfile);
69 ITS->SetTreeAddress();
71 cout<<"Making ITS SDigits for event "<<event<<endl;
78 cout << sdigFile << " size =" << sdigfile->GetSize() << endl;
80 cout << hitFile << " size =" << hitfile->GetSize() << endl;
81 } // end if sdigfile!=0
83 delete gAlice; // sdigfile is closed by deleting gAlice if != hitfile.
85 hitfile->Close(); hitfile=0;
87 //______________________________________________________________________
88 TFile * AccessFile(TString FileName, TString acctype){
89 // Function used to open the input file and fetch the AliRun object
92 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
98 if(acctype.Contains("U")){
99 file = new TFile(FileName,"UPDATE");
100 } // end if open for update
101 if(acctype.Contains("N") && !file){
102 file = new TFile(FileName,"RECREATE");
103 } // end if open a new file
104 if(!file) file = new TFile(FileName,"READ"); // default readonly
105 if (!file->IsOpen()) {
106 cerr << "Can't open " << FileName << " !" << endl;
108 } // end if error opeing file
110 // Get AliRun object from file or return if not on file
111 if (gAlice) {delete gAlice; gAlice = 0;}
112 gAlice = (AliRun*)file->Get("gAlice");
114 cerr << "AliRun object not found on file "<< FileName << "!" << endl;
115 file->Close(); // close file and return error.
120 //______________________________________________________________________
121 void writeAR(TFile * fin, TFile *fou) {
122 TDirectory *current = gDirectory;
125 AliHeader *alhe = new AliHeader();
126 TeOld = (TTree*)fin->Get("TE");
127 TeOld->SetBranchAddress("Header",&alhe);
128 TeOld->SetBranchStatus("*",1);
130 TeNew = TeOld->CloneTree();
131 TeNew->Write(0,TObject::kOverwrite);
132 gAlice->Write(0,TObject::kOverwrite);
136 cout << "AliRun object written to file" << endl;
139 //______________________________________________________________________
140 Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt){
142 TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
143 TDatime ct = hitfile->GetCreationDate();
145 if(ct0->GetDate()>ct.GetDate()){
146 // For old files, must change SDD noise.
147 AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)->
149 resp1 = new AliITSresponseSDD();
150 ITS->SetResponseModel(1,resp1);
151 cout << "Changed response class for SDD:" << endl;
155 if(opt.Contains("Dubna")){
156 AliITSresponseSPDdubna *resp0 = new AliITSresponseSPDdubna();
157 if(ITS->DetType(0)->GetResponseModel() !=0){
158 delete ((AliITSresponse*)ITS->DetType(0)->GetResponseModel());
159 ITS->DetType(0)->ResponseModel(0);
161 ITS->DetType(0)->ResponseModel(resp0);
162 AliITSsegmentationSPD *seg0 = (AliITSsegmentationSPD*)ITS->
163 DetType(0)->GetSegmentationModel();
164 AliITSsimulationSPDdubna *sim0 = new AliITSsimulationSPDdubna(seg0,
166 if(ITS->DetType(0)->GetSimulationModel() !=0){
167 delete ((AliITSsimulation*)ITS->DetType(0)->GetSimulationModel());
168 ITS->DetType(0)->SimulationModel(0);
170 ITS->DetType(0)->SimulationModel(sim0);