]>
Commit | Line | Data |
---|---|---|
47f1ee9a | 1 | #if !defined(__CINT__) || defined(__MAKECINT__) |
02a71a71 | 2 | |
47f1ee9a | 3 | #include "iostream.h" |
4 | #include "TDatetime.h" | |
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" | |
02a71a71 | 12 | |
47f1ee9a | 13 | #endif |
14 | ||
02a71a71 | 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=""); | |
18 | //#define DEBUG | |
19 | Int_t AliITSMerge(TString digFile="galiceMD.root", | |
20 | TString sdigFileSig="galiceS_sig.root", | |
21 | TString sdigFileBg="",TString opt=""){ | |
22 | // Standeard ITS SDigits to Digits, with posible merging. | |
23 | ||
24 | // Dynamically link some shared libs | |
25 | if (gClassTable->GetID("AliRun") < 0) { | |
26 | gROOT->LoadMacro("loadlibs.C"); | |
27 | loadlibs(); | |
28 | } // end if | |
29 | // Connect the Root Galice file containing Geometry, Kine and Hits | |
30 | if (gAlice) {delete gAlice; gAlice = 0;} | |
31 | ||
32 | TFile *sdigfilesig = 0; // pointer to signal input file. | |
33 | TFile *sdigfilebg = 0; // pointer to background input file. | |
34 | TFile *digfile = 0; // possible output file for TreeD | |
35 | ||
36 | // Setup to copy gAlice and the event tree to the output file. | |
37 | ||
38 | if(digFile.CompareTo(sdigFileSig)==0){//write output to same file as input. | |
39 | sdigfilesig = AccessFile(sdigFileSig,"U");//input file open for update. | |
40 | }else{ // different output file then input file. | |
41 | sdigfilesig = AccessFile(sdigFileSig,"R");//input file open read only | |
42 | digfile = new TFile(digFile,"NEW"); | |
43 | } // end if digFile == hitFile. | |
44 | ||
45 | AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS"); | |
46 | if (!ITS) { | |
47 | cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file" | |
48 | << endl; | |
49 | return 3; | |
50 | } // end if !ITS | |
51 | ||
52 | ChangeITSDefaults(sdigfilesig,ITS,opt); | |
53 | // write the AliRun object to the output file if different from input file. | |
54 | if(digfile){ | |
55 | writeAR(sdigfilesig,digfile); | |
56 | digfile->Close(); // Manager will open in update mode. | |
57 | digfile = 0; | |
58 | } // end if digfile | |
59 | sdigfilesig->Close(); | |
60 | sdigfilesig = 0; | |
61 | // delete gAlice; gAlice=0; // there is a problem with deleting gAlice???? | |
62 | ||
63 | AliRunDigitizer *manager; | |
64 | if(sdigFileBg.CompareTo("")==0) { // do not merge. | |
65 | manager = new AliRunDigitizer(1,1); | |
66 | }else{ | |
67 | manager = new AliRunDigitizer(2,1); | |
68 | manager->SetInputStream(0,sdigFileSig.Data()); | |
69 | manager->SetInputStream(1,sdigFileBg.Data()); | |
70 | } // end if | |
71 | if (digFile.CompareTo(sdigFileSig) !=0) { | |
72 | manager->SetOutputFile(digFile); | |
73 | } // end if | |
74 | // manager->SetCopyTreesFromInput(0); | |
75 | AliITSDigitizer *dITS = new AliITSDigitizer(manager); | |
76 | if(opt.Contains("ROI")==0) dITS->SetByRegionOfInterestFlag(1); | |
77 | ||
78 | TStopwatch timer; | |
79 | timer.Start(); | |
80 | manager->Exec("all"); | |
81 | timer.Stop(); | |
82 | timer.Print(); | |
83 | ||
84 | if(digfile!=0){ | |
85 | cout << digFile << " size =" << digfile->GetSize() << endl; | |
86 | }else if(sdigfilesig!=0){ | |
87 | cout << sdigFileSig << " size =" << sdigfilesig->GetSize() << endl; | |
88 | } // end if sdigfile!=0 | |
89 | ||
90 | ||
91 | if(digfile) digfile->Close(); | |
92 | if(sdigfilesig) sdigfilesig->Close(); | |
93 | if(sdigfilebg) sdigfilebg->Close(); | |
94 | ||
95 | // There is a problem deleting gAlice. It is related to the destructor | |
96 | // and the fTreeE in AliRun. So for now it is not deleted. | |
97 | // delete gAlice; // digfile is closed by deleting gAlice if != hitfile. | |
98 | // gAlice = 0; | |
99 | delete manager; | |
b709217a | 100 | } |
02a71a71 | 101 | //______________________________________________________________________ |
102 | TFile * AccessFile(TString FileName, TString acctype){ | |
103 | // Function used to open the input file and fetch the AliRun object | |
47f1ee9a | 104 | |
02a71a71 | 105 | TFile *retfil = 0; |
106 | TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName); | |
107 | if(file) { | |
108 | file->Close(); | |
109 | delete file; | |
110 | file = 0; | |
111 | } // end if file | |
112 | if(acctype.Contains("U")){ | |
113 | file = new TFile(FileName,"UPDATE"); | |
114 | } // end if open for update | |
115 | if(acctype.Contains("N") && !file){ | |
116 | file = new TFile(FileName,"RECREATE"); | |
117 | } // end if open a new file | |
118 | if(!file) file = new TFile(FileName,"READ"); // default readonly | |
119 | if (!file->IsOpen()) { | |
120 | cerr << "Can't open " << FileName << " !" << endl; | |
121 | return retfil; | |
122 | } // end if error opeing file | |
123 | ||
124 | // Get AliRun object from file or return if not on file | |
125 | if (gAlice) {delete gAlice; gAlice = 0;} | |
126 | gAlice = (AliRun*)file->Get("gAlice"); | |
127 | if (!gAlice) { | |
128 | cerr << "AliRun object not found on file "<< FileName << "!" << endl; | |
129 | file->Close(); // close file and return error. | |
130 | return retfil; | |
131 | } // end if !gAlice | |
132 | return file; | |
133 | } | |
134 | //______________________________________________________________________ | |
135 | void writeAR(TFile * fin, TFile *fou) { | |
136 | TDirectory *current = gDirectory; | |
137 | TTree *TeOld; | |
138 | TTree *TeNew; | |
139 | AliHeader *alhe = new AliHeader(); | |
140 | TeOld = (TTree*)fin->Get("TE"); | |
141 | TeOld->SetBranchAddress("Header",&alhe); | |
142 | TeOld->SetBranchStatus("*",1); | |
143 | fou->cd(); | |
144 | TeNew = TeOld->CloneTree(); | |
145 | TeNew->Write(0,TObject::kOverwrite); | |
146 | gAlice->Write(0,TObject::kOverwrite); | |
147 | current->cd(); | |
148 | delete alhe; | |
149 | #ifdef DEBUG | |
150 | cout << "AliRun object written to file" << endl; | |
151 | #endif | |
152 | } | |
153 | //______________________________________________________________________ | |
154 | Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt){ | |
155 | ||
156 | TDatime *ct0 = new TDatime(2002,04,26,00,00,00); | |
157 | TDatime ct = hitfile->GetCreationDate(); | |
158 | ||
159 | if(ct0->GetDate()>ct.GetDate()){ | |
160 | // For old files, must change SDD noise. | |
161 | AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)-> | |
162 | GetResponseModel(); | |
163 | resp1 = new AliITSresponseSDD(); | |
164 | ITS->SetResponseModel(1,resp1); | |
165 | cout << "Changed response class for SDD:" << endl; | |
166 | resp1->Print(); | |
167 | } // end if | |
168 | ||
169 | if(opt.Contains("Dubna")){ | |
170 | AliITSresponseSPDdubna *resp0 = new AliITSresponseSPDdubna(); | |
171 | if(ITS->DetType(0)->GetResponseModel() !=0){ | |
172 | delete ((AliITSresponse*)ITS->DetType(0)->GetResponseModel()); | |
173 | ITS->DetType(0)->ResponseModel(0); | |
174 | } // end if | |
175 | ITS->DetType(0)->ResponseModel(resp0); | |
176 | AliITSsegmentationSPD *seg0 = (AliITSsegmentationSPD*)ITS-> | |
177 | DetType(0)->GetSegmentationModel(); | |
178 | AliITSsimulationSPDdubna *sim0 = new AliITSsimulationSPDdubna(seg0, | |
179 | resp0); | |
180 | if(ITS->DetType(0)->GetSimulationModel() !=0){ | |
181 | delete ((AliITSsimulation*)ITS->DetType(0)->GetSimulationModel()); | |
182 | ITS->DetType(0)->SimulationModel(0); | |
183 | } // end if | |
184 | ITS->DetType(0)->SimulationModel(sim0); | |
185 | } // end if Dubna | |
186 | } |