]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSHits2SDigits.C
Initialize all persistent data members.
[u/mrichter/AliRoot.git] / ITS / AliITSHits2SDigits.C
1 TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
2 void writeAR(TFile * fin, TFile *fou);
3
4 Int_t AliITSHits2SDigits(Int_t evNumber1=0,Int_t evNumber2=0, TString inFile = "galice.root", TString outFile="galice.root"){
5
6   // Dynamically link some shared libs
7   if (gClassTable->GetID("AliRun") < 0) {
8         gROOT->LoadMacro("loadlibs.C");
9         loadlibs();
10   } // end if
11
12   // Connect the Root Galice file containing Geometry, Kine and Hits
13
14   TFile *file;
15   if(outFile.Data() == inFile.Data()){
16     file = AccessFile(inFile,"U");
17   }
18   else {
19     file = AccessFile(inFile);
20   }
21   
22   TFile *file2 = 0;  // possible output file for TreeS
23
24   if(!(outFile.Data() == inFile.Data())){
25     // open output file and create TreeS on it
26     file2 = gAlice->InitTreeFile("S",outFile);
27   }
28
29   AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");      
30   if (!ITS) {
31         cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
32             << endl;
33         return 3;
34   }  // end if !ITS
35   if(!(ITS->GetITSgeom())){
36         cerr << " AliITSgeom not found. Can't digitize with out it." << endl;
37         return 4;
38   } // end if
39
40   TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
41   TDatime ct = file->GetCreationDate();
42
43   if(ct0->GetDate()>ct.GetDate()){
44         // For old files, must change SDD noise.
45     AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)->GetResponseModel();
46     resp1 = new AliITSresponseSDD();
47     ITS->SetResponseModel(1,resp1);
48     cout << "Changed response class for SDD: \n";
49     resp1->Print();
50   } // end if
51   TStopwatch timer;
52   timer.Start();
53   for(Int_t nevent = evNumber1; nevent <= evNumber2; nevent++){
54     gAlice->GetEvent(nevent);
55     if(!gAlice->TreeS() && file2 == 0){ 
56       cout << "Having to create the SDigits Tree." << endl;
57       gAlice->MakeTree("S");
58     } // end if !gAlice->TreeS()
59     if(file2)gAlice->MakeTree("S",file2);
60     //    make branch
61     ITS->MakeBranch("S");
62     ITS->SetTreeAddress();
63     cout<<"Making ITS SDigits for event "<<nevent<<endl;
64     TStopwatch timer;
65     Long_t size0 = file->GetSize();
66     ITS->Hits2SDigits();
67   }
68   timer.Stop();
69   timer.Print();
70
71   // write the AliRun object to the output file
72   if(file2)writeAR(file,file2);
73
74   delete gAlice;   gAlice=0;
75   file->Close();
76 }
77
78 //-------------------------------------------------------------------
79 TFile * AccessFile(TString FileName, TString acctype){
80
81   // Function used to open the input file and fetch the AliRun object
82
83   TFile *retfil = 0;
84   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
85   if (file) {file->Close(); delete file; file = 0;}
86   if(acctype.Contains("U")){
87     file = new TFile(FileName,"update");
88   }
89   if(acctype.Contains("N") && !file){
90     file = new TFile(FileName,"recreate");
91   }
92   if(!file) file = new TFile(FileName);   // default readonly
93   if (!file->IsOpen()) {
94         cerr<<"Can't open "<<FileName<<" !" << endl;
95         return retfil;
96   } 
97
98   // Get AliRun object from file or return if not on file
99   if (gAlice) {delete gAlice; gAlice = 0;}
100   gAlice = (AliRun*)file->Get("gAlice");
101   if (!gAlice) {
102         cerr << "AliRun object not found on file"<< endl;
103         return retfil;
104   } 
105   return file;
106 }
107
108 //-------------------------------------------------------------------
109 void writeAR(TFile * fin, TFile *fou) {
110   TDirectory *current = gDirectory;
111   TTree *Te;
112   TTree *TeNew;
113   AliHeader *alhe = new AliHeader();
114   Te = (TTree*)fin->Get("TE");
115   Te->SetBranchAddress("Header",&alhe);
116   Te->SetBranchStatus("*",1);
117   fou->cd();
118   TeNew = Te->CloneTree();
119   TeNew->Write(0,TObject::kOverwrite);
120   gAlice->Write(0,TObject::kOverwrite);
121   current->cd();
122   delete alhe;
123   cout<<"AliRun object written to file\n";
124 }
125
126
127
128
129