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 AliITSDigits2RecPoints(TString digFile="galice.root",
20 TString recFile="galice.root",TString opt=""){
21 // Standard ITS Digits to RecPoints.
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 *digfile = 0; // pointer to input file.
32 TFile *recfile = 0; // possible output file for TreeD
33 if(recFile.CompareTo(digFile) == 0) { //write output to same file as input.
34 digfile = AccessFile(digFile,"U"); // input file open for update.
35 }else{ // different output file then input file.
36 digfile = AccessFile(digFile,"R"); // input file open as read only
37 recfile = new TFile(recFile,"NEW");
38 } // end if sdigFile == hitFile.
40 AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
42 cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
46 if(!(ITS->GetITSgeom())){
47 cerr << " AliITSgeom not found. Can't digitize with out it." << endl;
51 ChangeITSDefaults(digfile,ITS,opt);
53 // write the AliRun object to the output file if different from input file.
54 if(recfile) writeAR(digfile,recfile);
55 if(recfile){ recfile->Close(); recfile = 0;}
56 // if(digfile){ digfile->Close(); digfile = 0;}
63 cout << "Creating reconstructed points from digits for the ITS..." << endl;
65 // const char *nulptr=0;
66 AliITSreconstruction *itsr = new AliITSreconstruction(gAlice);
67 if(digFile.CompareTo(recFile)!=0) {
69 cout << itsr << " filename=" << recFile << " compare="<<
70 digFile.CompareTo(recFile) << endl;
72 itsr->SetOutputFile(recFile);
82 if(digfile){ digfile->Close(); digfile = 0;}
83 if(recfile){ recfile->Close(); recfile = 0;}
86 //______________________________________________________________________
87 TFile * AccessFile(TString FileName, TString acctype){
88 // Function used to open the input file and fetch the AliRun object
91 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
92 if(file) file->Close();
93 if(acctype.Contains("U")){
94 file = new TFile(FileName,"UPDATE");
95 } // end if open for update
96 if(acctype.Contains("N") && !file){
97 file = new TFile(FileName,"RECREATE");
98 } // end if open a new file
99 if(!file) file = new TFile(FileName,"READ"); // default readonly
100 if (!file->IsOpen()) {
101 cerr << "Can't open " << FileName << " !" << endl;
103 } // end if error opeing file
105 // Get AliRun object from file or return if not on file
106 if (gAlice) {delete gAlice; gAlice = 0;}
107 gAlice = (AliRun*)file->Get("gAlice");
109 cerr << "AliRun object not found on file "<< FileName << "!" << endl;
110 file->Close(); // close file and return error.
115 //______________________________________________________________________
116 void writeAR(TFile * fin, TFile *fou) {
117 TDirectory *current = gDirectory;
121 AliHeader *alhe = new AliHeader();
122 TeOld = (TTree*)fin->Get("TE");
123 TeOld->SetBranchAddress("Header",&alhe);
124 TeOld->SetBranchStatus("*",1);
126 TeNew = TeOld->CloneTree();
127 TeNew->Write(0,TObject::kOverwrite);
130 gAlice->TreeE()->SetBranchStatus("*",1);
131 gAlice->TreeE()->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);