1 TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
2 void writeAR(TFile * fin, TFile *fou);
4 Int_t AliITSHits2SDigits(Int_t evNumber1=0,Int_t evNumber2=0, TString inFile = "galice.root", TString outFile="galice.root"){
6 // Dynamically link some shared libs
7 if (gClassTable->GetID("AliRun") < 0) {
8 gROOT->LoadMacro("loadlibs.C");
12 // Connect the Root Galice file containing Geometry, Kine and Hits
15 if(outFile.Data() == inFile.Data()){
16 file = AccessFile(inFile,"U");
19 file = AccessFile(inFile);
22 TFile *file2 = 0; // possible output file for TreeS
24 if(!(outFile.Data() == inFile.Data())){
25 // open output file and create TreeS on it
26 file2 = gAlice->InitTreeFile("S",outFile);
29 AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
31 cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
35 if(!(ITS->GetITSgeom())){
36 cerr << " AliITSgeom not found. Can't digitize with out it." << endl;
40 TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
41 TDatime ct = file->GetCreationDate();
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";
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);
62 ITS->SetTreeAddress();
63 cout<<"Making ITS SDigits for event "<<nevent<<endl;
65 Long_t size0 = file->GetSize();
71 // write the AliRun object to the output file
72 if(file2)writeAR(file,file2);
74 delete gAlice; gAlice=0;
78 //-------------------------------------------------------------------
79 TFile * AccessFile(TString FileName, TString acctype){
81 // Function used to open the input file and fetch the AliRun object
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");
89 if(acctype.Contains("N") && !file){
90 file = new TFile(FileName,"recreate");
92 if(!file) file = new TFile(FileName); // default readonly
93 if (!file->IsOpen()) {
94 cerr<<"Can't open "<<FileName<<" !" << endl;
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");
102 cerr << "AliRun object not found on file"<< endl;
108 //-------------------------------------------------------------------
109 void writeAR(TFile * fin, TFile *fou) {
110 TDirectory *current = gDirectory;
113 AliHeader *alhe = new AliHeader();
114 Te = (TTree*)fin->Get("TE");
115 Te->SetBranchAddress("Header",&alhe);
116 Te->SetBranchStatus("*",1);
118 TeNew = Te->CloneTree();
119 TeNew->Write(0,TObject::kOverwrite);
120 gAlice->Write(0,TObject::kOverwrite);
123 cout<<"AliRun object written to file\n";