1 #if !defined(__CINT__) || defined(__MAKECINT__)
3 #include <TClonesArray.h>
6 #include <TStopwatch.h>
11 #include "AliHeader.h"
13 #include "AliITSDetType.h"
14 #include "AliITSsimulationFastPoints.h"
15 #include "AliITSresponse.h"
16 #include "AliITSresponseSDD.h"
17 #include "AliITSreconstruction.h"
18 #include "AliRunDigitizer.h"
19 #include "AliITSsegmentationSDD.h"
20 #include "AliITSDigitizer.h"
24 TFile* AccessInpFile(TString inFile);
25 void writeAR(TFile * fin, TFile *fou);
26 void AliITSSD2D(TString inFile = "galice.root", TString outFile = "");
27 void AliITSH2FR2files (TString inFile, TString outfile);
28 void AliITSH2SD2Files(TFile *file2);
29 void copyTK(TString inFile, TString outFile);
31 void AliITSHits2SDR(TString inFile = "galice.root", TString File1 = "galiceS.root",TString File2 = "galiceD.root", TString File3 = "galiceR.root"){
32 ////////////////////////////////////////////////////////////////////
33 // This macro takes hits from inFile file and
34 // produce fast RecPoints, Sdigits, Digits and slow Rec Points
35 // for the ITS using the standard detector simulations.
36 // The first argument is the input file which contains the tree with hits
37 // The second argument is the output file name onto which TreeS will
39 // The third and fourth arguments are the file names onto which TreeD
40 // and TreeR+TreeC will be written (respectively).
41 // The AliRun object and the KINE tree will be saved onto
42 // these files as well.
43 // This macro will process all of the events on input the root file.
44 // This macro can be compiled and it should be launched from an aliroot
46 // WARNING: Fast Rec Points are written on a branch named ITSRecPointsF
47 // this macro should be used with aliroot (it does not load the libraries)
48 ////////////////////////////////////////////////////////////////////
52 // Produce Fast Rec Points (on File3)
53 cout<<"Producing Fast rec points...\n";
54 AliITSH2FR2files(inFile,File3);
56 // TreeK is copied to File3 (for comparison purposes)
61 TFile *file = AccessInpFile(inFile);
63 cerr<<"Problems in accessing the input file\n";
66 TFile *file2 = gAlice->InitTreeFile("S",File1);
68 cout<<"Producing Summable digits ....\n";
69 AliITSH2SD2Files(file2);
70 // write the AliRun object to the output file
79 cout<<"Producing Digits ...\n";
80 AliITSSD2D(File1,File2);
82 // Produce Slow Rec. Points
83 TFile *fin = new TFile(File2);
84 gAlice = (AliRun*) fin->Get("gAlice");
86 AliITSreconstruction *itsr = new AliITSreconstruction(nulptr);
87 itsr->SetOutputFile(File3);
90 TFile *fou = gAlice->GetTreeRFile();
96 void AliITSH2SD2Files(TFile *file2){
98 // Function used to produce s-digits
100 AliITS *ITS = (AliITS*) gAlice->GetModule("ITS");
102 cerr<<"AliITS object not found on file" << endl;
105 if(!(ITS->GetITSgeom())){
106 cerr << " AliITSgeom not found. Can't digitize without it." << endl;
110 // these re-instantiations are necessary if the input file was created
111 // with aliroot version V3.07 or older
112 AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)->GetResponseModel();
113 resp1 = new AliITSresponseSDD();
114 ITS->SetResponseModel(1,resp1);
115 cout << "Changed response class for SDD: \n";
118 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
119 gAlice->GetEvent(nevent);
120 gAlice->MakeTree("S",file2);
121 ITS->MakeBranch("S");
122 ITS->SetTreeAddress();
128 TFile * AccessInpFile(TString inFile){
130 // Function used to open the input file and fetch the AliRun object
133 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
134 if (file) {file->Close(); delete file;}
135 file = new TFile(inFile);
136 if (!file->IsOpen()) {
137 cerr<<"Can't open "<<inFile<<" !" << endl;
141 // Get AliRun object from file or return if not on file
142 if (gAlice) delete gAlice; gAlice = 0;
143 gAlice = (AliRun*)file->Get("gAlice");
145 cerr << "AliRun object not found on file"<< endl;
151 void writeAR(TFile * fin, TFile *fou) {
152 TDirectory *current = gDirectory;
155 AliHeader *alhe = new AliHeader();
156 Te = (TTree*)fin->Get("TE");
157 Te->SetBranchAddress("Header",&alhe);
158 Te->SetBranchStatus("*",1);
160 TeNew = Te->CloneTree();
161 TeNew->Write(0,TObject::kOverwrite);
162 gAlice->Write(0,TObject::kOverwrite);
165 cout<<"AliRun object written to file\n";
169 void AliITSSD2D(TString inFile, TString outFile){
170 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
172 sprintf(ftmp,"%s",inFile.Data());
173 manager->SetInputStream(0,ftmp);
174 if(outFile != "")manager->SetOutputFile(outFile);
175 AliITSDigitizer *dITS = new AliITSDigitizer(manager);
177 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
178 TFile *file2= new TFile(outFile,"update");
182 file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
191 void AliITSH2FR2files (TString inFile, TString outfile)
194 TFile * file = AccessInpFile(inFile);
196 cerr<<"*** AliITSH2FR2files: Problems in accessing the input file\n";
200 // open output file and create TreeR on it
201 TFile * file2 = gAlice->InitTreeFile("R",outfile);
204 AliITS *ITS = (AliITS*) gAlice->GetModule("ITS");
206 cerr<<"ITSH2FR2files.C : AliITS object not found on file" << endl;
210 // Set the simulation model
212 for (Int_t i=0;i<3;i++) {
213 ITS->SetSimulationModel(i,new AliITSsimulationFastPoints());
223 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
224 gAlice->GetEvent(nevent);
225 if(!gAlice->TreeR())gAlice->MakeTree("R",file2);
226 ITS->MakeBranch("RF");
227 ITS->SetTreeAddress();
228 Int_t bgr_ev=nevent/nsignal;
229 ITS->HitsToFastRecPoints(nevent,bgr_ev,size," ","All"," ");
232 timer.Stop(); timer.Print();
239 void copyTK(TString inFile, TString outFile) {
241 TDirectory *current = gDirectory;
242 TParticle *part = new TParticle();
245 TFile *fin = AccessInpFile(inFile);
246 TFile *fou = new TFile(outFile,"update");
248 for(Int_t event= 0; event < gAlice->TreeE()->GetEntries(); event++){
250 sprintf(tname,"TreeK%d",event);
251 Tk = (TTree*)fin->Get(tname);
253 cerr<<"Trying to access a non-existent TTree : "<<tname<<endl;
256 Tk->SetBranchAddress("Particles",&part);
257 Tk->SetBranchStatus("*",1);
259 TkNew = Tk->CloneTree();