new TTask to replace non-working AliITSFindClusterV2.C macro.
[u/mrichter/AliRoot.git] / ITS / AliITSHits2Digits.C
CommitLineData
cc2535cd 1TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
2void writeAR(TFile * fin, TFile *fou);
3
4Int_t AliITSHits2Digits(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 TreeD
23
24 if(!(outFile.Data() == inFile.Data())){
25 // open output file and create TreeR on it
26 file2 = gAlice->InitTreeFile("D",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
54 for(Int_t nevent = evNumber1; nevent <= evNumber2; nevent++){
55 cout<<"Producing Digits for event n."<<nevent<<endl;
56 gAlice->GetEvent(nevent);
57 if(!gAlice->TreeD() && file2 == 0){
58 cout << "Having to create the Digits Tree." << endl;
59 gAlice->MakeTree("D");
60 }
61 if(file2)gAlice->MakeTree("D",file2);
62 ITS->MakeBranch("D");
63 ITS->SetTreeAddress();
64 ITS->Hits2Digits();
65 }
66 timer.Stop();
67 timer.Print();
68
69 // write the AliRun object to the output file
70 if(file2)writeAR(file,file2);
71
72 delete gAlice;
73 gAlice=0;
74 file->Close();
75}
76
77//-------------------------------------------------------------------
78TFile * AccessFile(TString FileName, TString acctype){
79
80 // Function used to open the input file and fetch the AliRun object
81
82 TFile *retfil = 0;
83 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
84 if (file) {file->Close(); delete file; file = 0;}
85 if(acctype.Contains("U")){
86 file = new TFile(FileName,"update");
87 }
88 if(acctype.Contains("N") && !file){
89 file = new TFile(FileName,"recreate");
90 }
91 if(!file) file = new TFile(FileName); // default readonly
92 if (!file->IsOpen()) {
93 cerr<<"Can't open "<<FileName<<" !" << endl;
94 return retfil;
95 }
96
97 // Get AliRun object from file or return if not on file
98 if (gAlice) {delete gAlice; gAlice = 0;}
99 gAlice = (AliRun*)file->Get("gAlice");
100 if (!gAlice) {
101 cerr << "AliRun object not found on file"<< endl;
102 return retfil;
103 }
104 return file;
105}
106
107//-------------------------------------------------------------------
108void writeAR(TFile * fin, TFile *fou) {
109 TDirectory *current = gDirectory;
110 TTree *Te;
111 TTree *TeNew;
112 AliHeader *alhe = new AliHeader();
113 Te = (TTree*)fin->Get("TE");
114 Te->SetBranchAddress("Header",&alhe);
115 Te->SetBranchStatus("*",1);
116 fou->cd();
117 TeNew = Te->CloneTree();
118 TeNew->Write(0,TObject::kOverwrite);
119 gAlice->Write(0,TObject::kOverwrite);
120 current->cd();
121 delete alhe;
122 cout<<"AliRun object written to file\n";
123}
124
125
126
127
128