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 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.
24 // Dynamically link some shared libs
25 if (gClassTable->GetID("AliRun") < 0) {
26 gROOT->LoadMacro("loadlibs.C");
29 // Connect the Root Galice file containing Geometry, Kine and Hits
30 if (gAlice) {delete gAlice; gAlice = 0;}
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
36 // Setup to copy gAlice and the event tree to the output file.
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.
45 AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
47 cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
52 ChangeITSDefaults(sdigfilesig,ITS,opt);
53 // write the AliRun object to the output file if different from input file.
55 writeAR(sdigfilesig,digfile);
56 digfile->Close(); // Manager will open in update mode.
61 // delete gAlice; gAlice=0; // there is a problem with deleting gAlice????
63 AliRunDigitizer *manager;
64 if(sdigFileBg.CompareTo("")==0) { // do not merge.
65 manager = new AliRunDigitizer(1,1);
67 manager = new AliRunDigitizer(2,1);
68 manager->SetInputStream(0,sdigFileSig.Data());
69 manager->SetInputStream(1,sdigFileBg.Data());
71 if (digFile.CompareTo(sdigFileSig) !=0) {
72 manager->SetOutputFile(digFile);
74 // manager->SetCopyTreesFromInput(0);
75 AliITSDigitizer *dITS = new AliITSDigitizer(manager);
76 if(opt.Contains("ROI")){
77 cout << "Region of Interest selected" << endl;
78 dITS->SetByRegionOfInterestFlag(1);
80 cout << "Digizing everthing" << endl;
81 dITS->SetByRegionOfInterestFlag(0);
91 cout << digFile << " size =" << digfile->GetSize() << endl;
92 }else if(sdigfilesig!=0){
93 cout << sdigFileSig << " size =" << sdigfilesig->GetSize() << endl;
94 } // end if sdigfile!=0
97 if(digfile) digfile->Close();
98 if(sdigfilesig) sdigfilesig->Close();
99 if(sdigfilebg) sdigfilebg->Close();
101 // There is a problem deleting gAlice. It is related to the destructor
102 // and the fTreeE in AliRun. So for now it is not deleted.
103 // delete gAlice; // digfile is closed by deleting gAlice if != hitfile.
107 //______________________________________________________________________
108 TFile * AccessFile(TString FileName, TString acctype){
109 // Function used to open the input file and fetch the AliRun object
112 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
118 if(acctype.Contains("U")){
119 file = new TFile(FileName,"UPDATE");
120 } // end if open for update
121 if(acctype.Contains("N") && !file){
122 file = new TFile(FileName,"RECREATE");
123 } // end if open a new file
124 if(!file) file = new TFile(FileName,"READ"); // default readonly
125 if (!file->IsOpen()) {
126 cerr << "Can't open " << FileName << " !" << endl;
128 } // end if error opeing file
130 // Get AliRun object from file or return if not on file
131 if (gAlice) {delete gAlice; gAlice = 0;}
132 gAlice = (AliRun*)file->Get("gAlice");
134 cerr << "AliRun object not found on file "<< FileName << "!" << endl;
135 file->Close(); // close file and return error.
140 //______________________________________________________________________
141 void writeAR(TFile * fin, TFile *fou) {
142 TDirectory *current = gDirectory;
145 AliHeader *alhe = new AliHeader();
146 TeOld = (TTree*)fin->Get("TE");
147 TeOld->SetBranchAddress("Header",&alhe);
148 TeOld->SetBranchStatus("*",1);
150 TeNew = TeOld->CloneTree();
151 TeNew->Write(0,TObject::kOverwrite);
152 gAlice->Write(0,TObject::kOverwrite);
156 cout << "AliRun object written to file" << endl;
159 //______________________________________________________________________
160 Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt){
162 TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
163 TDatime ct = hitfile->GetCreationDate();
165 if(ct0->GetDate()>ct.GetDate()){
166 // For old files, must change SDD noise.
167 AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)->
169 resp1 = new AliITSresponseSDD();
170 ITS->SetResponseModel(1,resp1);
171 cout << "Changed response class for SDD:" << endl;
175 if(opt.Contains("Dubna")){
176 AliITSresponseSPDdubna *resp0 = new AliITSresponseSPDdubna();
177 if(ITS->DetType(0)->GetResponseModel() !=0){
178 delete ((AliITSresponse*)ITS->DetType(0)->GetResponseModel());
179 ITS->DetType(0)->ResponseModel(0);
181 ITS->DetType(0)->ResponseModel(resp0);
182 AliITSsegmentationSPD *seg0 = (AliITSsegmentationSPD*)ITS->
183 DetType(0)->GetSegmentationModel();
184 AliITSsimulationSPDdubna *sim0 = new AliITSsimulationSPDdubna(seg0,
186 if(ITS->DetType(0)->GetSimulationModel() !=0){
187 delete ((AliITSsimulation*)ITS->DetType(0)->GetSimulationModel());
188 ITS->DetType(0)->SimulationModel(0);
190 ITS->DetType(0)->SimulationModel(sim0);