99ccd98d28a6cb65bcc6cad20452129149adaa5d
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / sim / PlotSysInfo.C
1 TVirtualPad* MakeCanvas(const char* title="")
2 {
3   static Int_t cId = 0;
4   TCanvas* c = new TCanvas(Form("c%02d", ++cId), title);
5   c->SetTopMargin(0.02);
6   c->SetRightMargin(0.02);
7   c->cd();
8   return c;
9 }
10
11 Double_t SumUsage(TTree*      tree, 
12                   const char* exp, 
13                   const char* cut, 
14                   bool        draw=false)
15 {
16   //
17   // return sum of usage
18   //
19   if (draw) MakeCanvas(Form("%s [%s]", exp, cut));
20   
21   Int_t  entries = tree->Draw(exp, cut, (draw ? "" : "goff"));
22   if (entries==0) return 0;
23
24   Double_t mean = TMath::Mean(entries, tree->GetV1());
25   return entries * mean;
26 }
27 Double_t TopUsage(TTree*      tree, 
28                   const char* exp, 
29                   const char* cut, 
30                   Int_t       order)
31 {
32   Int_t entries = tree->Draw(exp, cut, "goff");
33   if (entries <= 1 || !tree->GetV1()) return -10000;
34   
35   TArrayI index(entries);
36   TMath::Sort(entries, tree->GetV1(), index.fArray);
37
38   Int_t    oindex = TMath::Min(order, entries);
39   Double_t value  = tree->GetV1()[index[oindex-1]];
40   
41   return value;
42 }
43   
44 TH1* ExtractHist(TTree*      tree,
45                  const char* exp, 
46                  const char* cut,
47                  const char* name,
48                  const char* xtitle="", 
49                  const char* ytitle="",
50                  Bool_t      draw=false)
51 {
52   tree->Draw(Form("%s>>tmpa", exp), cut, "GOFF");
53   if (!tree->GetHistogram()) return 0;
54
55   TH1* ret = static_cast<TH1*>(tree->GetHistogram()->Clone(name));
56   delete tree->GetHistogram();
57   ret->SetXTitle(xtitle);
58   ret->SetYTitle(ytitle);
59   ret->SetMarkerStyle(22);
60   ret->SetMarkerSize(1);
61   if (draw) {
62     if (draw) MakeCanvas(name);
63     ret->Draw();
64   }
65   return ret;
66 }
67                  
68                  
69 void Print(std::ostream& o,
70            const char*   name, 
71            Double_t      dT, 
72            Double_t      dVM, 
73            Double_t      alldT, 
74            Double_t      alldVM)
75 {
76   o << name << "\t" 
77     << dT   << "\t" 
78     << dVM  << "\t" 
79     << 100*(alldT  > 0 ? dT  / alldT  : 0) << "\t" 
80     << 100*(alldVM > 0 ? dVM / alldVM : 0) << std::endl;
81 }
82
83 const char* dets[] = {"ITS", 
84                       "TPC", 
85                       "TRD", 
86                       "TOF", 
87                       "PHOS", 
88                       "HMPID", 
89                       "EMCAL", 
90                       "MUON", 
91                       "FMD", 
92                       "ZDC", 
93                       "PMD", 
94                       "T0", 
95                       "VZERO", 
96                       "ACORDE", 
97                       "HLT",
98                       0 };
99
100
101 void
102 Plot1SysInfo(const char* file, UShort_t draw=0x1)
103 {
104   // gROOT->LoadMacro("$ALICE_ROOT/../master-src/macros/PlotSys.C+");
105
106   // --- Create output file and tree ---------------------------------
107   TString rootOut(file); 
108   rootOut.ReplaceAll(".log", ".root");
109   rootOut.ReplaceAll(".foo", ".root");
110   Info("", "Writing to ROOT file %s", rootOut.Data());
111   TFile* out  = TFile::Open(rootOut, "RECREATE");
112   TTree* tree = AliSysInfo::MakeTree(file);
113
114
115   
116   // --- Create ASCII output ------------------------------------------
117   TString sumOut(rootOut); 
118   sumOut.ReplaceAll(".root", ".sum");
119   Info("", "Writing to ASCII file %s", sumOut.Data());
120   std::ofstream ascii(sumOut.Data());
121   ascii << "Det/C:sumDt/F:sumDvm/F:fracDt/F:fracDvm/F" << std::endl;
122
123   // --- Get global stuff ---------------------------------------------
124   const char* all     = "id0>=0&&id2>=0";
125   Double_t sumdTAll   = SumUsage(tree, "deltaT",  all, draw & 0x1);
126   Double_t sumdVMAll  = SumUsage(tree, "deltaVM", all, draw & 0x1);
127   Double_t topdT      = TopUsage(tree, "deltaT",  "id2<3", 20);
128   Double_t topdVM     = TopUsage(tree, "deltaVM", "", 20);
129   TCut     cutT("cutDT", Form("deltaT > %f", topdT));
130   TCut     cutVM("cutVM", Form("deltaVM > %f", topdVM));
131   
132   ExtractHist(tree, "deltaVM:sname", "1"+cutVM,
133               "DVMvsName","","#DeltaVM [MB]", draw&0x4);
134   ExtractHist(tree, "VM:sname", "id2<3"+cutVM, 
135               "VMvsName", "", "VM [MB]", draw&0x4);
136   ExtractHist(tree, "VM:T", "deltaVM>1", 
137               "VMvsTime", "Time [sec]", "VM [MB]", draw&0x4);
138   ExtractHist(tree, "deltaT:sname","id2<3"+cutT,
139               "CPUvsName","","#DeltaT [sec]", draw&0x4);
140   
141
142
143   Print(ascii, "all", sumdTAll, sumdVMAll, sumdTAll, sumdVMAll);
144
145   
146
147   // --- Loop over detetors ------------------------------------------
148   const char** pdet = dets;
149   Int_t        idet = 0;
150   while (*pdet) { 
151     TString  cut    = Form("id0==%d && id2 >= 0", idet);
152     Double_t sumdT  = SumUsage(tree, "deltaT",  cut, draw & 0x2);
153     Double_t sumdVM = SumUsage(tree, "deltaVM", cut, draw & 0x2);
154     Print(ascii, *pdet, sumdT, sumdVM, sumdTAll, sumdVMAll);
155     
156 #if 0
157     TString cut2    = Form("id0==%d",idet);
158     ExtractHist(tree, "deltaVM:sname", cut2.Data()+cutVM,
159                 Form("DVMvsName_%02d", idet), "", "#DeltaVM [MB]", draw&0x8);
160     ExtractHist(tree, "VM:sname",      cut2.Data()+cutVM,
161                 Form("VMvsName_%02d", idet), "", "VM [MB]", draw&0x8);
162     ExtractHist(tree, "deltaT:sname",  cut2.Data()+cutT, 
163                 Form("CPUvsName_%02d", idet),"", "#DeltaT [sec]", draw&0x8);
164 #endif
165
166     pdet++;
167     idet++;
168   }
169   ascii.close();
170
171   new TBrowser;
172 }
173
174   
175
176 PlotSysInfo(ULong_t pid=431808952)
177 {
178   Plot1SysInfo(Form("%d_simwatch.log", pid));
179   Plot1SysInfo(Form("%d_recowatch.log", pid));
180 }
181
182