]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSDigits2RecPoints.C
Checking in the seeds of new cluster fitting code.
[u/mrichter/AliRoot.git] / ITS / AliITSDigits2RecPoints.C
CommitLineData
02a71a71 1#if !defined(__CINT__) || defined(__MAKECINT__)
2
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"
12
13#endif
14
cc2535cd 15TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
02a71a71 16void writeAR(TFile * fin, TFile *fou);
17Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt="");
18#define DEBUG
c2b05330 19Int_t AliITSDigits2RecPoints(TString digFile="galice.root",
20 TString recFile="galice.root",TString opt=""){
02a71a71 21 // Standard ITS Digits to RecPoints.
cc2535cd 22
02a71a71 23 // Dynamically link some shared libs
24 if (gClassTable->GetID("AliRun") < 0) {
25 gROOT->LoadMacro("loadlibs.C");
26 loadlibs();
27 } // end if
28
29 // Connect the Root Galice file containing Geometry, Kine and Hits
30
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.
39/*
40 AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
41 if (!ITS) {
42 cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
43 << endl;
44 return 3;
45 } // end if !ITS
46 if(!(ITS->GetITSgeom())){
47 cerr << " AliITSgeom not found. Can't digitize with out it." << endl;
48 return 4;
49 } // end if
50
51 ChangeITSDefaults(digfile,ITS,opt);
52*/
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;}
57// delete gAlice;
58// gAlice = 0;
cc2535cd 59
02a71a71 60 TStopwatch timer;
61
62#ifdef DEBUG
63 cout << "Creating reconstructed points from digits for the ITS..." << endl;
64#endif
65// const char *nulptr=0;
66 AliITSreconstruction *itsr = new AliITSreconstruction(gAlice);
67 if(digFile.CompareTo(recFile)!=0) {
68#ifdef DEBUG
69 cout << itsr << " filename=" << recFile << " compare="<<
70 digFile.CompareTo(recFile) << endl;
71#endif
72 itsr->SetOutputFile(recFile);
73 } // end if
74 timer.Start();
75 itsr->Init();
76 itsr->Exec();
77 timer.Stop();
78 timer.Print();
79 delete itsr;
80// delete gAlice;
81// gAlice = 0;
82 if(digfile){ digfile->Close(); digfile = 0;}
83 if(recfile){ recfile->Close(); recfile = 0;}
84 return 0;
85}
86//______________________________________________________________________
cc2535cd 87TFile * AccessFile(TString FileName, TString acctype){
02a71a71 88 // Function used to open the input file and fetch the AliRun object
cc2535cd 89
02a71a71 90 TFile *retfil = 0;
91 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
92 if(file) {
93 file->Close();
94 delete file;
95 file = 0;
96 } // end if file
97 if(acctype.Contains("U")){
98 file = new TFile(FileName,"UPDATE");
99 } // end if open for update
100 if(acctype.Contains("N") && !file){
101 file = new TFile(FileName,"RECREATE");
102 } // end if open a new file
103 if(!file) file = new TFile(FileName,"READ"); // default readonly
104 if (!file->IsOpen()) {
105 cerr << "Can't open " << FileName << " !" << endl;
cc2535cd 106 return retfil;
02a71a71 107 } // end if error opeing file
cc2535cd 108
02a71a71 109 // Get AliRun object from file or return if not on file
110 if (gAlice) {delete gAlice; gAlice = 0;}
111 gAlice = (AliRun*)file->Get("gAlice");
112 if (!gAlice) {
113 cerr << "AliRun object not found on file "<< FileName << "!" << endl;
114 file->Close(); // close file and return error.
cc2535cd 115 return retfil;
02a71a71 116 } // end if !gAlice
117 return file;
118}
119//______________________________________________________________________
120void writeAR(TFile * fin, TFile *fou) {
121 TDirectory *current = gDirectory;
122/*
123 TTree *TeOld;
124 TTree *TeNew;
125 AliHeader *alhe = new AliHeader();
126 TeOld = (TTree*)fin->Get("TE");
127 TeOld->SetBranchAddress("Header",&alhe);
128 TeOld->SetBranchStatus("*",1);
129 fou->cd();
130 TeNew = TeOld->CloneTree();
131 TeNew->Write(0,TObject::kOverwrite);
132*/
133 fou->cd();
134 gAlice->TreeE()->SetBranchStatus("*",1);
135 gAlice->TreeE()->Write(0,TObject::kOverwrite);
136 gAlice->Write(0,TObject::kOverwrite);
137 current->cd();
138// delete alhe;
139#ifdef DEBUG
140 cout << "AliRun object written to file" << endl;
141#endif
142}
143//______________________________________________________________________
144Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt){
145
146 TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
147 TDatime ct = hitfile->GetCreationDate();
148
149 if(ct0->GetDate()>ct.GetDate()){
150 // For old files, must change SDD noise.
151 AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)->
152 GetResponseModel();
153 resp1 = new AliITSresponseSDD();
154 ITS->SetResponseModel(1,resp1);
155 cout << "Changed response class for SDD:" << endl;
156 resp1->Print();
157 } // end if
158
159 if(opt.Contains("Dubna")){
160 AliITSresponseSPDdubna *resp0 = new AliITSresponseSPDdubna();
161 if(ITS->DetType(0)->GetResponseModel() !=0){
162 delete ((AliITSresponse*)ITS->DetType(0)->GetResponseModel());
163 ITS->DetType(0)->ResponseModel(0);
164 } // end if
165 ITS->DetType(0)->ResponseModel(resp0);
166 AliITSsegmentationSPD *seg0 = (AliITSsegmentationSPD*)ITS->
167 DetType(0)->GetSegmentationModel();
168 AliITSsimulationSPDdubna *sim0 = new AliITSsimulationSPDdubna(seg0,
169 resp0);
170 if(ITS->DetType(0)->GetSimulationModel() !=0){
171 delete ((AliITSsimulation*)ITS->DetType(0)->GetSimulationModel());
172 ITS->DetType(0)->SimulationModel(0);
173 } // end if
174 ITS->DetType(0)->SimulationModel(sim0);
175 } // end if Dubna
af8e1c2d 176}