AliRoot Core  13155fd (13155fd)
AliTreeTrending.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
20 
27 #include "TStatToolkit.h"
28 #include "Riostream.h"
29 #include <iostream>
30 #include "TSystem.h"
31 #include "TNamed.h"
32 #include "TFile.h"
33 #include "TTree.h"
34 #include "TPRegexp.h"
35 #include "TFriendElement.h"
36 #include "AliExternalInfo.h"
37 #include "TTreeFormula.h"
38 #include "TTreeFormulaManager.h"
39 #include "AliTreeTrending.h"
40 #include "TEntryList.h"
41 #include "TError.h"
42 #include "TStyle.h"
43 #include "TROOT.h"
44 #include "TLegend.h"
45 #include "AliTreeTrending.h"
46 #include <stdexcept> // std::invalid_argument
47 #include "AliDrawStyle.h"
48 
49 using std::cout;
50 using std::cerr;
51 using std::endl;
52 
53 
54 
55 ClassImp(AliTreeTrending)
56 
57 using std::cout;
58 using std::endl;
59 
60 // constants
61 const Int_t kMaxCanvasWidth=3000;
62 const Int_t kMinCanvasWidth=1000;
63 const Int_t kStepCanvasWidth=500;
64 
65 
66 
68  TNamed(),
69  fTree(NULL),
70  fUserDescription(NULL),
71  fLatexDescription(NULL),
72  fStatusGraphM(NULL),
73  fCurrentCssStyle(""),
74  fReport(NULL) {
75 }
76 //_____________________________________________________________________________
77 AliTreeTrending::AliTreeTrending(const char *name, const char *title, const char * cssStyle):
78  TNamed(name, title),
79  fTree(NULL),
80  fUserDescription(NULL),
81  fLatexDescription(NULL),
82  fStatusGraphM(NULL),
83  fCurrentCssStyle(cssStyle),
84  fReport(NULL) {
85  //
86  fReport=new TFile("report.root","recreate");
87  // Register default style
88  if (fCurrentCssStyle.Length()>0){
90  ::Error("AliTreeTrending::AliTreeTrending", "Requested CSS Style %s not registered", fCurrentCssStyle.Data());
92  }
93  }
94  if (fCurrentCssStyle.Length()==0){
95  if (AliDrawStyle::GetCssStyle("AliTreeTrending") == NULL) {
96  AliDrawStyle::RegisterCssStyle("AliTreeTrending", AliDrawStyle::ReadCSSFile("$AliRoot_SRC/STAT/test/AliTreeTrending.css", 0));
97  }
98  fCurrentCssStyle="AliTreeTrending";
99  }
100 }
101 
106 Bool_t AliTreeTrending::SetCssStyle(const char * cssStyle){
107  if (cssStyle){
108  if (AliDrawStyle::GetCssStyle(cssStyle)==NULL){
109  ::Error("AliTreeTrending::SetCssStyle", "Requested CSS Style %s not registered", cssStyle);
110  }else{
111  fCurrentCssStyle = cssStyle;
112  }
113  }
114 }
115 
116 
121  //
122  // Get latex version of description
123  //
124  TObjArray * description= new TObjArray();
125  TString sTimestamp = TString::Format("Creation time:%s",gSystem->GetFromPipe("date").Data());
126  TString sUser=TString::Format("User:%s",gSystem->GetFromPipe("echo $USER").Data());
127  TString sAlirootVer;
128  TString sAliPhysicsVer;
129  if (gSystem->GetFromPipe("echo $ALICE_VER") == "master" || gSystem->GetFromPipe("echo $ALICE_VER") == ""){
130  sAlirootVer = "AliRoot: " + gSystem->GetFromPipe("wdir=`pwd`; cd $AliRoot_SRC/; git describe; cd $wdir;");
131  }else {
132  sAlirootVer = "AliRoot: " + gSystem->GetFromPipe("echo $ALIROOT_VERSION");
133  }
134  if (gSystem->GetFromPipe("echo $ALIPHYSICS_VER") == "master" || gSystem->GetFromPipe("echo $ALIPHYSICS_VER") == ""){
135  sAliPhysicsVer = "AliPhysics: " + gSystem->GetFromPipe("wdir=`pwd`; cd $AliPhysics_SRC/; git describe; cd $wdir;");
136  }else {
137  sAliPhysicsVer = "AliPhysics: " + gSystem->GetFromPipe("echo $ALIPHYSICS_VERSION");
138  }
139  //
140  description->AddLast(latex->DrawLatexNDC(latex->GetX(), latex->GetY(),sTimestamp.Data()));
141  description->AddLast(latex->DrawLatexNDC(latex->GetX(), latex->GetY()-1.1*latex->GetTextSize(),sUser.Data()));
142  description->AddLast(latex->DrawLatexNDC(latex->GetX(), latex->GetY()-4.4*latex->GetTextSize(),sAlirootVer.Data()));
143  description->AddLast(latex->DrawLatexNDC(latex->GetX(), latex->GetY()-5.5*latex->GetTextSize(),sAliPhysicsVer.Data()));
144  if (fUserDescription!=NULL){
145  Int_t entries=fUserDescription->GetEntries();
146  for (Int_t i=0; i<entries; i++){
147  description->AddLast(latex->DrawLatexNDC(latex->GetX(), latex->GetY()-((6+i)*1.1)*latex->GetTextSize(),
148  TString::Format("%s: %s",fUserDescription->At(i)->GetName(), fUserDescription->At(i)->GetTitle()).Data()));
149  }
150  }
151  return description;
152 }
153 
156 void AliTreeTrending::AddUserDescription(TNamed * description){
157  //
158  // Add user description
159  // AliTreeTrending is owner
160  //
162  fUserDescription->AddLast(description);
163 }
164 
175 Bool_t AliTreeTrending::InitSummaryTrending(TString statusDescription[3], Float_t descriptionSize, TString cutString){
176  //
177  // Init drawing for the <detector> QA
178  // Detector specific qaConfig() has to be called before invoking this function
179  // 0.) Make descriptor
180  // 1.) Make default canvas - addapt canvas width to the number of entries to draw
181  // 2.) initialize status aliases (outliers etc.), status bar criteria, status lines, ...
182  // 3.) compute detector status graphs
183 
184  // 0.) Make descriptor
185  if (fTree==NULL) {
186  ::Error("AliTreeTrending::InitSummaryTrending", "Input tree not defined");
187  return 0;
188  }
189  if (fTree->GetAlias("tagID")==NULL && fTree->GetBranch("tagID")==NULL) {
190  ::Error("AliTreeTrending::InitSummaryTrending", "tagID is not defined");
191  return 0;
192  }
193  TLatex *latex= new TLatex;
194  latex->SetX(0.11);
195  latex->SetY(0.8);
196  latex->SetTextSize(descriptionSize);
198  // 1.) Make default canvas - addapt canvas width to the number of entries to draw
199  TGraphErrors *gr = (TGraphErrors*) TStatToolkit::MakeGraphSparse(fTree,"tagID:tagID","");
200  Int_t numberOfTags = gr->GetN();
201  cout<<"number of graph entries: "<<numberOfTags<<endl;
202  double SpaceForLegend = 0.;
203  Int_t canvas_width = SpaceForLegend + (numberOfTags+5)*30;
204  Int_t canvas_height = 600;
205  if ( canvas_width>kMaxCanvasWidth) canvas_width=kMaxCanvasWidth;
206  if ( canvas_width<kMinCanvasWidth) canvas_width=kMinCanvasWidth;
207 
208  fWorkingCanvas = new TCanvas("fWorkingCanvas","fWorkingCanvas",canvas_width,canvas_height);
209  fWorkingCanvas->SetGrid(3);
210  fWorkingCanvas->cd();
211  gPad->SetTicks(1,2);
212  // fWorkingCanvas->SetRightMargin(SpaceForLegend/canvas_width);
213  double leftLegend = 1 - 180./fWorkingCanvas->GetWw();
214  double rightLegend = 1 - 10./fWorkingCanvas->GetWw();
215 
216  // 2.) initialize status aliases (outliers etc.), status bar criteria, status lines, ...
217  TString sStatusBarVars = statusDescription[0];
218  TString sStatusBarNames = statusDescription[1];
219  TString sCriteria = statusDescription[2];
220  cout << "sStatusBarVars = " << sStatusBarVars.Data() << endl;
221  cout << "sCriteria = " << sCriteria.Data() << endl;
222 
223  // 3.) compute detector status graphs
224  fStatusGraphM = MakeMultiGraphStatus(fTree,"statusBar", sStatusBarVars+";tagID",sStatusBarNames,cutString.Data(),sCriteria,kTRUE);
225  if(fStatusGraphM==0) {
226  ::Error("AliTreeTrending::InitSummaryTrending","MakeMultiGraphStatus() returned NULL pointer when plotting the following variables: %s", sStatusBarVars.Data());
227  return 0;
228  }
229  else{
230  fStatusGraphM->GetYaxis()->SetTitle("");
231  fStatusGraphM->GetHistogram()->SetTitle("");
232  }
233  return kTRUE;
234 }
235 
238  gROOT->SetStyle("Plain");
239  gStyle->SetPalette(1);
240  gStyle->SetLabelSize(0.04,"x");
241  gStyle->SetPadTickX(1);
242  gStyle->SetPadTickY(1);
243 }
244 
249 void AliTreeTrending::AppendStatusPad(Float_t padRatio, Float_t bottomMargin, Float_t rightMargin){
250  //
251  // Add status pad and latex description to the canvas (can be pad?)
252  // status pad and latex description using data members of trendingDraw class
253  //
254  // 1.) Split canvas
255  // 2.) Draw status bar in lower part of canvas
256  //
257  if (fLatexDescription==NULL){
258  ::Error("AliTreeTrending::AppendStatusPad", "LatexDescription not initialized. Run AliTreeTrending::InitSummaryTrending");
259  return;
260  }
261  TCanvas *c1 = fWorkingCanvas;
262  c1->cd();
263  fLatexDescription->DrawClone();
264  //
265  // 1.) Split canvas
266  //
267  TCanvas* c1_clone = (TCanvas*) c1->Clone("c1_clone");
268  c1->Clear();
269  // produce new pads
270  c1->cd();
271  TPad* pad1 = new TPad("pad1", "pad1", 0., padRatio, 1., 1.);
272  pad1->Draw();
273  pad1->SetNumber(1); // so it can be called via "c1->cd(1);"
274  c1->cd();
275  TPad* pad2 = new TPad("pad2", "pad2", 0., 0., 1., padRatio);
276  pad2->Draw();
277  pad2->SetNumber(2);
278  // draw original canvas into first pad
279  c1->cd(1);
280  c1_clone->DrawClonePad();
281 
282  pad1->SetName("Top.class(statusPad)");
284 
285 // pad1->SetBottomMargin(0.001);
286 // pad1->SetRightMargin(rightMargin);
287  // set up second pad
288  c1->cd(2);
289 // pad2->SetGrid(3);
290 // pad2->SetTopMargin(0);
291 // pad2->SetBottomMargin(bottomMargin); // for the long x-axis labels (run numbers)
292 // pad2->SetRightMargin(rightMargin);
293  pad2->SetName("Bottom.class(statusPad)");
294  AliDrawStyle::TPadApplyStyle(fCurrentCssStyle.Data(),pad2); //"testStyle" to be changed to
295 
296  const Int_t nVars = fStatusGraphM->GetYaxis()->GetNbins();
297  TGraph* grAxis = (TGraph*) fStatusGraphM->GetListOfGraphs()->At(0);
298  Int_t entries = grAxis->GetN();
299  fStatusGraphM->GetXaxis()->SetLabelSize(5.7*TMath::Min(TMath::Max(5./entries,0.01),0.03));
300  fStatusGraphM->GetYaxis()->SetLabelSize(0.025/gPad->GetHNDC());
301  fStatusGraphM->Draw("ap");
302  c1->cd(1)->Draw();
303 }
304 
305 
313 
328 TMultiGraph * AliTreeTrending::MakeMultiGraphStatus(TTree *fTree, TString mgrName, TString expression, TString varTitle, TCut cutString, TString sCriteria, Bool_t setAxis) {
329  // 1. Make TMultiGraph for each group
330  TObjArray *oaStatusBarVars = expression.Tokenize(";:");
331  TObjArray *oaStatusBarNames = varTitle.Tokenize(";:");
332 
333  if(oaStatusBarVars->GetEntries()<1) ::Error("AliTreeTrending::MakeMultiGraphStatus", "Empty variable string provided");
334  if(oaStatusBarVars->GetEntries()-1!=oaStatusBarNames->GetEntries()) {
335  ::Error("AliTreeTrending::MakeMultiGraphStatus", "Variable\tNames");
336  for(int i=0; i<oaStatusBarVars->GetEntries(); i++){
337  TString varVars = TString(oaStatusBarVars->At(i)!=NULL?oaStatusBarVars->At(i)->GetName():"undef.");
338  TString varNames = TString(oaStatusBarNames->At(i)!=NULL?oaStatusBarNames->At(i)->GetName():"undef.");
339  ::Error("AliTreeTrending::MakeMultiGraphStatus", "%s\t%s",varVars.Data(),varNames.Data());
340  }
341  return 0;
342  }
343  Int_t nVars = oaStatusBarVars->GetEntriesFast() - 1;
344  TObjArray *graphArray = new TObjArray(nVars);
345  for (Int_t iVar = 0; iVar < nVars; iVar++) {
346  TString sVar = Form("%s:%s", oaStatusBarVars->At(iVar)->GetName(),
347  oaStatusBarVars->At(nVars)->GetName()); //e.g. -> dcar:run
348  TMultiGraph *multGr = TStatToolkit::MakeStatusMultGr(fTree, sVar.Data(), cutString, sCriteria.Data(), 2*iVar);
349  if (multGr) {
350  graphArray->AddAt(multGr, iVar);
351  ((TMultiGraph *) graphArray->At(iVar))->SetTitle(oaStatusBarNames->At(iVar)->GetName());
352  for (Int_t igr = 0; igr < multGr->GetListOfGraphs()->GetEntries(); igr++) { // Code names and codes to the object names
353  TGraph *cgr = (TGraph *) multGr->GetListOfGraphs()->At(igr);
354  //cgr->SetName(TString((oaStatusBarNames->At(iVar)->GetName())).Data());
355  }
356  } else {
357  ::Error("AliTreeTrending::MakeMultiGraphStatus", "TStatToolkit::MakeStatusMultGr(sVar=%s) returned with error -> next",sVar.Data());
358  continue;
359  }
360  }
361 
362  Bool_t added=kFALSE;
363  // 2.) Set Y ranges and Y labels for each graph
364  Double_t *yBins = new Double_t[nVars+1];
365  for(Int_t i=0; i<=nVars;i++) yBins[i] = Double_t(i);
366  TMultiGraph *mgrCombined=new TMultiGraph(mgrName,"Status");
367  for (Int_t i=0; i<nVars; i++) {
368  TMultiGraph * mgr=((TMultiGraph*) graphArray->At(i));
369  if (mgr==NULL) continue;
370  for (Int_t igr=0; igr<mgr->GetListOfGraphs()->GetEntries(); igr++) {
371  TGraph *cgr = (TGraph *) mgr->GetListOfGraphs()->At(igr);
372  if (cgr==NULL){
373  ::Error("AliTreeTrending::MakeMultiGraphStatus","Graph %d of multi-graph %s is 0", igr, mgr->GetName());
374  continue;
375  }
376  cgr->SetTitle(""); cgr->GetYaxis()->SetTitle("");
377  cgr->GetYaxis()->Set(nVars, yBins);
378  cgr->GetYaxis()->SetRangeUser(0,nVars);
379  for (Int_t jgr=0; jgr<nVars; jgr++) {
380  if(graphArray->At(jgr)!=NULL) cgr->GetYaxis()->SetBinLabel(jgr+1, graphArray->At(jgr)->GetTitle());
381  }
382  mgrCombined->Add(cgr);
383  added=kTRUE;
384  }
385  }
386 
387  if(! added) {
388  ::Error("AliTreeTrending::MakeMultiGraphStatus","No graphs could be added to multigraph - returning 0");
389  return 0;
390  }
391 
392  mgrCombined->SetMinimum(0); mgrCombined->SetMaximum(nVars);
393  // TStatToolkit::DrawMultiGraph(mgrCombined,"ap");
394  if (setAxis) { //TODO - to get axis graph has to be drawn - is there other option ?
395  TGraph *gr0=(TGraph *) mgrCombined->GetListOfGraphs()->At(0);
396  mgrCombined->Draw("ap");
397  mgrCombined->GetXaxis()->Set(gr0->GetXaxis()->GetNbins(), gr0->GetXaxis()->GetXbins()->GetArray());
398  for (Int_t jgr = 0; jgr < gr0->GetXaxis()->GetNbins(); jgr++)
399  mgrCombined->GetXaxis()->SetBinLabel(jgr + 1, gr0->GetXaxis()->GetBinLabel(jgr+1));
400  mgrCombined->GetYaxis()->Set(nVars, yBins);
401  mgrCombined->GetYaxis()->SetRangeUser(0, nVars);
402  for (Int_t jgr = 0; jgr < nVars; jgr++)
403  if(graphArray->At(jgr)!=NULL) mgrCombined->GetYaxis()->SetBinLabel(jgr + 1, graphArray->At(jgr)->GetTitle());
404  mgrCombined->GetYaxis()->SetTitle("");
405  mgrCombined->Draw("ap");
406  }
407  delete oaStatusBarVars;
408  delete oaStatusBarNames;
409  delete graphArray;
410  return mgrCombined;
411 }
412 
433 void AliTreeTrending::MakePlot(const char* outputDir, const char *figureName, const char *LegendTitle, std::vector<Double_t>& legendPos, const char *groupName, const char* expr, const char * cut, const char * markers, const char *colors, Bool_t drawSparse, Float_t markerSize, Float_t sigmaRange, Bool_t comp) {
434  TMultiGraph *mGraph=0;
435  fWorkingCanvas->Clear();
436  TLegend *legend = new TLegend(legendPos[0],legendPos[1],legendPos[2],legendPos[3],LegendTitle);
437  legend->SetBorderSize(0);
438  mGraph = TStatToolkit::MakeMultGraph(fTree,groupName,expr,cut,markers,colors,drawSparse,markerSize,sigmaRange,legend,comp);
439 
440  if (mGraph) for(Int_t it=0; it<mGraph->GetListOfGraphs()->GetSize(); it++){
441  TGraph* graph = (TGraph*) mGraph->GetListOfGraphs()->At(it);
442  if (groupName!=NULL && strlen(groupName)>0){ // example groupName=".class(multiGraphPair).{marker_style:25,21,22,23;marker_color:1,2,4,5;}"
443  graph->SetName(TString::Format("graph[%d].%s",it,groupName).Data());
444  }else {
445  graph->SetName(TString::Format("graph[%d].class(multiGraphPair)", it).Data());
446  }
447  // TODO add group name if exist
449  }
450 
451 
452  if(!mGraph){
453  ::Error("AliTreeTrending::MakePlot","No plot returned -> dummy plot! ");
454  ::Error("AliTreeTrending::MakePlot","Invalid query expression. Try tree->Draw(\"%s\",\"\t%s\")",expr, cut);
455  }
456  else {
457  mGraph->SetName(groupName);
458  if (drawSparse) TStatToolkit::RebinSparseMultiGraph(mGraph,(TGraph*)fStatusGraphM->GetListOfGraphs()->At(0));
459  TStatToolkit::DrawMultiGraph(mGraph,"alp");
460  AppendStatusPad(0.3, 0.4, 0.05);
461  legend->SetFillStyle(0);
462  legend->Draw();
463  }
464  if(outputDir!=0){
465  fWorkingCanvas->SaveAs(TString(outputDir)+"/"+TString(figureName));
466  fWorkingCanvas->Print(TString(outputDir)+"/report.pdf");
467  if (fReport) {fReport->cd(); fWorkingCanvas->Write(figureName); fReport->Flush();}
468  }
469 }
470 
485 void AliTreeTrending::AppendBand(const char* outputDir, const char *figureName, const char* expr, const char * cut, const char * lineStyle, const char *colors, Bool_t drawSparse, Float_t sigmaRange, Bool_t comp) {
486  TMultiGraph *graph=0;
487  graph = TStatToolkit::MakeMultGraph(fTree,"",expr,cut,lineStyle,colors,drawSparse,0,sigmaRange,0,comp);
488  if(!graph){
489  ::Error("MakePlot","No plot returned -> dummy plot!");
490  }
491  else {
492  if (drawSparse) TStatToolkit::RebinSparseMultiGraph(graph,(TGraph*)fStatusGraphM->GetListOfGraphs()->At(0));
493  TStatToolkit::DrawMultiGraph(graph,"l");
494  }
495  if(outputDir!=0){
496  fWorkingCanvas->SaveAs(TString(outputDir)+"/"+TString(figureName));
497  fWorkingCanvas->Print(TString(outputDir)+"/report.pdf");
498  if (fReport) {fReport->cd();fWorkingCanvas->Write(figureName);}
499  }
500 }
501 
512 
524 void AliTreeTrending::MakeStatusPlot(const char *outputDir, const char *figureName, TString expression, TString varTitle, TCut cutString, TString sCriteria, TString friendName) {
525  fWorkingCanvas->Clear();
526  TMultiGraph *multiGraph = NULL;
527  if (friendName.Length() > 0 && fTree->GetFriend(friendName)){
528  multiGraph = AliTreeTrending::MakeMultiGraphStatus(fTree->GetFriend(friendName), "", expression, varTitle, cutString, sCriteria,kTRUE);
529  }else{
530  multiGraph = AliTreeTrending::MakeMultiGraphStatus(fTree, "", expression, varTitle, cutString, sCriteria,kTRUE);
531  }
532 
533  if(multiGraph==0) {
534  ::Error("AliTreeTrending::MakeStatusPlot", "MakeMultiGraphStatus returned NULL pointer");
535  return;
536  }
537  TStatToolkit::RebinSparseMultiGraph(multiGraph,(TGraph*)fStatusGraphM->GetListOfGraphs()->At(0)); // rebin to the fStatusBar
538  TStatToolkit::DrawMultiGraph(multiGraph, "ap");
539  //multiGraph->Draw("ap");
540  AppendStatusPad(0.3, 0.4, 0.05);
541  if (outputDir != NULL) {
542  fWorkingCanvas->SaveAs(TString(outputDir) + "/" + TString(figureName));
543  fWorkingCanvas->Print(TString(outputDir) + "/report.pdf");
544  if (fReport) {fReport->cd();fWorkingCanvas->Write(figureName);}
545  }
546 }
547 
554 void AliTreeTrending::AppendDefaultBandsMinMax(const char *outputDir, const char *figureName, const char * bandNamePrefix, const char * selection, const char* groupName /*other drawing variable TString style*/ ){
555  TMultiGraph *mGraph=0;
556  const char* aType[6]={"WarningMin","WarningMax","OutlierMin","OutlierMax","PhysAccMin","PhysAccMax"}; //yellow 400 ,red 632 ,green 416/
557  TString expr;
558  for(Int_t itype=0; itype<6; itype++){
559  expr = bandNamePrefix+TString(aType[itype])+TString(":run");
560  mGraph = TStatToolkit::MakeMultGraph(fTree,"",expr,selection, "figTemplateTRDPair", "figTemplateTRDPair",kTRUE,0,6,0,kTRUE);
561  if(!mGraph){
562  ::Error("MakePlot","No plot returned -> dummy plot!");
563  }
564  else {
565  if (kTRUE) TStatToolkit::RebinSparseMultiGraph(mGraph,(TGraph*)fStatusGraphM->GetListOfGraphs()->At(0));
566  for(Int_t it=0; it<mGraph->GetListOfGraphs()->GetSize(); it++){
567  TGraph* band = (TGraph*) mGraph->GetListOfGraphs()->At(it);
568  if (groupName && strlen(groupName)>1){ // example groupName=".class(multiGraphPair).{marker_style:25,21,22,23;marker_color:1,2,4,5;}"
569  band->SetName(TString::Format("graph[%d]%s",itype,groupName).Data());
570  }else {
571  band->SetName(TString::Format("graph[%d].class(deadBand)", itype).Data());
572  }
573  // TODO add group name if exist
574  AliDrawStyle::TGraphApplyStyle(fCurrentCssStyle,band); //"testStyle" to be changed to fCurrenCSSStyle
575  }
576  TStatToolkit::DrawMultiGraph(mGraph,"l");
577  }
578  }
579  if(outputDir!=0){
580  fWorkingCanvas->SaveAs(TString(outputDir)+"/"+TString(figureName));
581  fWorkingCanvas->Print(TString(outputDir)+"/report.pdf");
582  if (fReport) {fReport->cd();fWorkingCanvas->Write(figureName);}
583  }
584 }
585 
586 
593 void AliTreeTrending::AppendDefaultBands(const char *outputDir, const char *figureName, const char * refVariable,const char * bandNamePrefix, const char * selection, const char* groupName /*other drawing variable TString style*/ ){
594  TMultiGraph *mGraph=0;
595  const char* aType[3]={"_WarningBand","_OutlierBand","_PhysAccBand"}; //yellow 400 ,red 632 ,green 416/
596  TString expr;
597  for(Int_t itype=0; itype<3; itype++){
598  expr = refVariable+TString("+")+bandNamePrefix+TString(aType[itype])+TString(";")+refVariable+TString("-")+bandNamePrefix+TString(aType[itype])+TString(":run");
599  mGraph = TStatToolkit::MakeMultGraph(fTree,"",expr,selection, "figTemplateTRDPair", "figTemplateTRDPair",kTRUE,0,6,0,kTRUE);
600  if(!mGraph){
601  ::Error("MakePlot","No plot returned -> dummy plot!");
602  }
603  else {
604  if (kTRUE) TStatToolkit::RebinSparseMultiGraph(mGraph,(TGraph*)fStatusGraphM->GetListOfGraphs()->At(0));
605  for(Int_t it=0; it<mGraph->GetListOfGraphs()->GetSize(); it++){
606  TGraph* band = (TGraph*) mGraph->GetListOfGraphs()->At(it);
607  if (groupName && strlen(groupName)>1){ // example groupName=".class(multiGraphPair).{marker_style:25,21,22,23;marker_color:1,2,4,5;}"
608  band->SetName(TString::Format("graph[%d]%s",itype,groupName).Data());
609  }else {
610  band->SetName(TString::Format("graph[%d].class(deadBand)", itype).Data());
611  }
612  // TODO add group name if exist
613  AliDrawStyle::TGraphApplyStyle(fCurrentCssStyle,band); //"testStyle" to be changed to fCurrenCSSStyle
614  }
615  TStatToolkit::DrawMultiGraph(mGraph,"l");
616  }
617  }
618  if(outputDir!=0){
619  fWorkingCanvas->SaveAs(TString(outputDir)+"/"+TString(figureName));
620  fWorkingCanvas->Print(TString(outputDir)+"/report.pdf");
621  if (fReport) {fReport->cd();fWorkingCanvas->Write(figureName);}
622  }
623 }
624 
632 
645 void AliTreeTrending::DecomposeStatusAlias(TTree* tree, TString currentString, TString &statusVar, TString &statusTitle, TPRegexp &suffix, Int_t &counter, TString &bitMaskAlias){
646  //
647  if (tree==NULL) throw std::invalid_argument("invalid tree argument");
648  counter++;
649  TString toAdd=currentString;
650  suffix.Substitute(toAdd,"");
651  statusVar+=toAdd;
652  statusVar+=";";
653  if (counter>1) bitMaskAlias+="+";
654  bitMaskAlias+=toAdd;
655  bitMaskAlias+="_#";
656  bitMaskAlias+=TString::Format("*(1<<%d)",counter);
657  TString title=toAdd;
658  if (TStatToolkit::GetMetadata(tree,(toAdd+".Title").Data())) title=TStatToolkit::GetMetadata(tree,toAdd+".Title")->GetTitle();
659  statusTitle+=title;
660  statusTitle+=";";
661  TString content=tree->GetAlias(currentString.Data());
662  TObjArray * array = content.Tokenize("|&");
663  printf("%d\t%s\t%s\n",counter,toAdd.Data(), content.Data());
664  for (Int_t i=0; i<array->GetEntries(); i++){
665  TString cString=array->At(i)->GetName();
666  cString.ReplaceAll("(","");
667  cString.ReplaceAll(")","");
668  if (suffix.Match(cString,"")>0) {
669  DecomposeStatusAlias(tree, cString, statusVar, statusTitle,suffix,counter,bitMaskAlias);
670  }
671  }
672 }
673 
674 
680 TString AliTreeTrending::ArrayNameToString(TCollection *array, TString sRegExp, TString separator){
681  TString output="";
682  TPRegexp regExp(sRegExp);
683  TIter next(array);
684  TObject *object;
685  while ( ( object =next())) {
686  if (regExp.Match(object->GetName())) {
687  output += object->GetName();
688  output += separator;
689  }
690  }
691  return output;
692 }
693 
694 
700 
705 void AliTreeTrending::AddJSROOTHtmlLink(FILE * pFile, TString title, TString prefix, TString items){
706  fprintf(pFile, "<b>%s</b>",title.Data());
707  fprintf(pFile, "<a href=\"%s&%s&layout=tabs\">[all,</a>",prefix.Data(),items.Data());
708  fprintf(pFile, "<a href=\"%s&%s&layout=collapsible&nobrowser\">col,</a>",prefix.Data(),items.Data());
709  fprintf(pFile, "<a href=\"%s&%s&layout=tabs&nobrowser\">tabs,</a>",prefix.Data(),items.Data());
710  fprintf(pFile, "<a href=\"%s&%s&layout=flex&nobrowser\">flex]</a>",prefix.Data(),items.Data());
711  fprintf(pFile, "<br>");
712 }
713 
714 
static const TObjArray * GetCssStyle(const char *styleName)
Definition: AliDrawStyle.h:293
Int_t colors[3]
Definition: CalibCosmic.C:62
TNamed * GetMetadata(TTree *tree, const char *vartagName, TString *prefix=0, Bool_t fullMatch=kFALSE)
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
TTree * fTree
Definition: MakeTreeStat.C:55
TMultiGraph * MakeStatusMultGr(TTree *tree, const char *expr, const char *cut, const char *alias, Int_t igr=0)
static void TGraphApplyStyle(const char *styleName, TGraph *cGraph, Int_t objNum=0, Int_t verbose=0)
TStyle * gStyle
#define TObjArray
TROOT * gROOT
const Float_t markerSize[5]
Definition: makeBBFit.C:59
TObjArray * array
Definition: AnalyzeLaser.C:12
TTree * tree
char * prefix
static void TPadApplyStyle(const char *styleName, TPad *cPad, Int_t verbose=0)
TGraph * gr
Definition: CalibTime.C:25
static TObjArray * ReadCSSFile(const char *inputName, TObjArray *array=nullptr, Int_t verbose=0)
AliComparisonDraw comp
Definition: TestAnalisys.C:74
void RebinSparseMultiGraph(TMultiGraph *multiGraph, TGraph *graphRef)
TLatex latex
static void RegisterCssStyle(const char *styleName, TObjArray *array)
Definition: AliDrawStyle.h:303
TGraph * MakeGraphSparse(TTree *tree, const char *expr="Entry", const char *cut="1", Int_t mstyle=25, Int_t mcolor=1, Float_t msize=-1, Float_t offset=0.0)
TCut cut
Definition: MakeGlobalFit.C:75
const Int_t markers[5]
Definition: makeBBFit.C:58
void DrawMultiGraph(TMultiGraph *graph, Option_t *option)
TMultiGraph * MakeMultGraph(TTree *tree, const char *groupName, const char *expr, const char *cut, const char *markers, const char *colors, Bool_t drawSparse, Float_t msize, Float_t sigmaRange, TLegend *legend, Bool_t comp=kTRUE)