AliPhysics  63e47e1 (63e47e1)
MakeSlides.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 
3 #include <map>
4 #include <vector>
5 
6 #include <Riostream.h>
7 
8 // ROOT includes
9 #include "TString.h"
10 #include "TSystem.h"
11 #include "TROOT.h"
12 #include "TFile.h"
13 #include "TEnv.h"
14 #include "TObjArray.h"
15 #include "TObjString.h"
16 #include "TArrayI.h"
17 #include "TPRegexp.h"
18 #include "TRegexp.h"
19 #include "TCanvas.h"
20 #include "TAxis.h"
21 #include "TH2.h"
22 #include "TLegend.h"
23 #include "TTree.h"
24 #endif
25 
27 const char* outPdf = "trending.pdf";
28 
29 //_________________________________
31 {
32  TObjArray* arr = trigName.Tokenize("-");
33  TString shortName = arr->At(0)->GetName();
34  if ( arr->GetEntries() > 2 ) {
35  shortName.Append(Form("-%s",arr->At(1)->GetName()));
36  }
37  delete arr;
38  return shortName;
39 }
40 
41 //_________________________________
42 std::vector<int> GetRunList(TString filename)
43 {
44  std::vector<int> runList;
45 
46  TFile *file = TFile::Open(filename.Data());
47  if (file) {
48  TCanvas *can = static_cast<TCanvas *>(file->Get("Global/AllTriggers"));
49  if (can) {
50  TH2 *histo = nullptr;
51  TIter next(can->GetListOfPrimitives());
52  TObject *obj = nullptr;
53  while ((obj = next())) {
54  if (obj->InheritsFrom(TH2::Class())) {
55  histo = static_cast<TH2 *>(obj);
56  break;
57  }
58  }
59  if (histo) {
60  TAxis *axis = histo->GetXaxis();
61  if (axis->GetNbins() > 0) {
62  for (Int_t ibin = 1; ibin <= axis->GetNbins(); ibin++) {
63  runList.push_back(TString(axis->GetBinLabel(ibin)).Atoi());
64  }
65  }
66  }
67  }
68  }
69 
70  delete file;
71  return runList;
72 }
73 
74 //_________________________________
75 Bool_t PrintToPdf ( TString objName, TString filename, Bool_t closeFile, Bool_t warnIfMissing )
76 {
77  Bool_t isOk = kFALSE;
78  TFile* file = TFile::Open(filename.Data());
79  if ( ! file ) return isOk;
80 
81  // The canvases must be drawn in order to be printed
82  // But drawing takes time.
83  // We set it temporary to batch mode to avoid drawing
84  // and come back to the initial mode in the end
85  bool isBatch = gROOT->IsBatch();
86  gROOT->SetBatch(true);
87 
88  TObject* obj = file->FindObjectAny(objName.Data());
89  if ( obj ) {
90  TCanvas* can = 0x0;
91  if ( obj->IsA() == TCanvas::Class() ) {
92  can = static_cast<TCanvas*>(obj);
93  can->Draw(); // This is needed or the print will not work
94  }
95  else {
96  can = new TCanvas(Form("%s_can",obj->GetName()),obj->GetTitle(),600,600);
97  TString drawOpt = "e";
98  if ( obj->InheritsFrom(TH2::Class()) ) {
99  drawOpt = "COLZ";
100  TH2* histo = static_cast<TH2*>(obj);
101  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
102  }
103  obj->Draw(drawOpt.Data());
104  }
105  TString outFile(outPdf);
106  if ( fNpages == 0 ) outFile.Append("(");
107  else if ( closeFile ) outFile.Append(")");
108  fNpages++;
109  can->Print(outFile.Data());
110  if ( obj != can ) delete obj;
111  delete can; // We do not want the canvas to be drawn
112  isOk = kTRUE;
113  }
114  else if ( warnIfMissing ) {
115  printf("Warning: cannot find %s\n",objName.Data());
116  }
117 
118  delete file;
119 
120  gROOT->SetBatch(isBatch);
121 
122  return isOk;
123 }
124 
125 //_________________________________
127 {
128  str.ReplaceAll("\\","");
129  TString specials = "_";
130  TObjArray* specialList = specials.Tokenize(" ");
131  for ( Int_t ichar=0; ichar<specialList->GetEntries(); ichar++ ) {
132  TString currChar = static_cast<TObjString*>(specialList->At(ichar))->GetString();
133  if ( str.Contains(currChar.Data()) ) str.ReplaceAll(currChar.Data(),Form("\\\%s",currChar.Data()));
134  }
135  delete specialList;
136 }
137 
138 //_________________________________
139 void BeginFrame ( TString title, ofstream& outFile, TString label = "" )
140 {
141  if ( ! outFile.is_open() ) return;
142  outFile << endl;
143  outFile << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
144  outFile << "\\begin{frame}";
145  if ( ! label.IsNull() ) outFile << "\\label{" << label.Data() << "}";
146  outFile << endl;
147  outFile << " \\frametitle{" << title.Data() << "}" << endl;
148 }
149 
150 //_________________________________
151 void EndFrame ( ofstream& outFile )
152 {
153  if ( ! outFile.is_open() ) return;
154  outFile << "\\end{frame}" << endl;
155 }
156 
157 //_________________________________
158 void MakeDefaultItem ( ofstream& outFile, TString defaultItem = "" )
159 {
160  if ( ! outFile.is_open() ) return;
161  outFile << "\\begin{itemize}" << endl;
162  outFile << " \\item " << defaultItem.Data() << endl;
163  outFile << "\\end{itemize}" << endl;
164 }
165 
166 //_________________________________
167 Bool_t MakeSingleFigureSlide ( TString objName, TString filename, TString title, ofstream& outFile, TString label = "", Bool_t warnIfMissing = kTRUE, Bool_t closePdf = kFALSE )
168 {
169  Bool_t isOk = PrintToPdf(objName,filename,closePdf,warnIfMissing);
170  if ( ! isOk ) {
171  return kFALSE;
172  }
173 
174  if ( ! outFile.is_open() ) return kTRUE;
175 
176  BeginFrame(title,outFile,label);
177  outFile << " \\begin{columns}[onlytextwidth]" << endl;
178  outFile << " \\column{\\textwidth}" << endl;
179  outFile << " \\centering" << endl;
180  outFile << " \\includegraphics[width=0.98\\textwidth,height=0.92\\textheight,page=" << fNpages << "]{" << outPdf << "}" <<endl;
181  outFile << " \\end{columns}" << endl;
182  EndFrame(outFile);
183  return kTRUE;
184 }
185 
186 //_________________________________
187 Bool_t MakeTriggerSlide ( TString filename, ofstream &outFile )
188 {
189  TString baseName[3] = {"bendPlane","nonBendPlane","bothPlanes"};
190  Int_t colors[3] = {kBlack,kRed,kBlue};
191  TH2* histo[3] = {0x0,0x0,0x0};
192  TH1* histoTotal = 0x0;
193  TFile* file = TFile::Open(filename.Data());
194  for ( Int_t ieff=0; ieff<3; ieff++ ) {
195  histo[ieff] = static_cast<TH2*>(file->FindObjectAny(Form("effEvolution%sChamber",baseName[ieff].Data())));
196  histo[ieff]->SetDirectory(0);
197  }
198  histoTotal = static_cast<TH1*>(file->FindObjectAny("totalEffEvolution"));
199  histoTotal->SetDirectory(0);
200  delete file;
201 
202  TCanvas* can = new TCanvas("trigChEff","trigChEff",600,600);
203  can->Divide(2,2,0,0);
204  TLegend* leg = 0x0;
205  TString drawOpt = "";
206  for ( Int_t ich=1; ich<=4; ich++ ) {
207  can->cd(ich);
208  if ( ich == 4 ) leg = new TLegend(0.3,0.17,0.7,0.37);
209  gPad->SetTicks(1,1);
210  if ( ich > 2 ) gPad->SetBottomMargin(0.15);
211  for ( Int_t ieff=0; ieff<3; ieff++ ) {
212  TH1* proj = histo[ieff]->ProjectionX(Form("%s%i",histo[ieff]->GetName(),10+ich),ich,ich);
213  proj->SetLineColor(colors[ieff]);
214  proj->SetMarkerColor(colors[ieff]);
215  proj->SetMarkerStyle(20+ieff);
216  proj->SetMarkerSize(0.7);
217  proj->SetStats(kFALSE);
218  proj->SetTitle(Form("Chamber %i",10+ich));
219  proj->GetYaxis()->SetRangeUser(0.9,1.01);
220  proj->GetXaxis()->SetLabelSize(0.06);
221  proj->LabelsOption("v");
222  drawOpt = "e";
223  if ( gPad->GetListOfPrimitives() != 0 ) drawOpt.Append("same");
224  proj->Draw(drawOpt.Data());
225  if ( leg ) leg->AddEntry(proj,baseName[ieff].Data(),"lp");
226  }
227  if ( leg ) leg->Draw();
228  }
229  for ( Int_t ieff=0; ieff<3; ieff++ ) delete histo[ieff];
230  can->Print(outPdf);
231  fNpages++;
232  delete can;
233  can = new TCanvas("totalTrigEff","totalTrifEff",600,600);
234  can->SetLeftMargin(0.15);
235  can->SetBottomMargin(0.15);
236  histoTotal->GetXaxis()->SetLabelSize(0.06);
237  histoTotal->Draw("e");
238  can->Print(outPdf);
239  fNpages++;
240  delete can;
241 
242  if ( ! outFile.is_open() ) return kTRUE;
243 
244  BeginFrame("Trigger chamber efficiencies", outFile);
245  outFile << " \\begin{columns}[onlytextwidth]" << endl;
246  outFile << " \\column{0.66\\textwidth}" << endl;
247  outFile << " \\centering" << endl;
248  outFile << " \\includegraphics[width=0.98\\textwidth,page=" << fNpages-1 << "]{" << outPdf << "}" << endl;
249  outFile << " \\column{0.34\\textwidth}" << endl;
250  outFile << " \\centering" << endl;
251  outFile << " \\includegraphics[width=0.98\\textwidth,page=" << fNpages << "]{" << outPdf << "}" << endl;
252  outFile << " \\end{columns}" << endl;
253  EndFrame(outFile);
254  return kTRUE;
255 }
256 
257 //_________________________________
258 Bool_t MakeTriggerRPCslide ( TString filename, ofstream &outFile, Bool_t outliers = kFALSE )
259 {
260  for ( Int_t ich=0; ich<4; ich++ ) {
261  TString currName = Form("effEvolutionbothPlanesRPCCh%i",11+ich);
262  if ( outliers ) currName += "_outlier";
263  PrintToPdf(currName,filename,kFALSE,kFALSE);
264  }
265 
266  if ( ! outFile.is_open() ) return kTRUE;
267  TString baseName = outliers ? "eff.-<eff.> for outliers" : "efficiency";
268  BeginFrame(Form("Trigger chamber %s per RPC",baseName.Data()),outFile,outliers?"":"rpcEff");
269  outFile << " \\begin{columns}[onlytextwidth]" << endl;
270  outFile << " \\column{\\textwidth}" << endl;
271  outFile << " \\centering" << endl;
272  for ( Int_t ich=0; ich<4; ich++ ) {
273  if ( ich%2 == 0 ) outFile << endl;
274  outFile << " \\includegraphics[width=0.37\\textwidth,page=" << fNpages-3+ich << "]{" << outPdf << "}" << endl;
275  }
276  outFile << " \\end{columns}" << endl;
277  EndFrame(outFile);
278  return kTRUE;
279 }
280 
281 //_________________________________
282 Bool_t MakeTriggerRPCslides ( TString filename, ofstream &outFile, Bool_t fromTrackerTrack = kFALSE )
283 {
284  TString trType = ( fromTrackerTrack ) ? "Tracker" : "Trigger";
285  for ( Int_t ich=0; ich<4; ich++ ) {
286  Int_t chamber = 11+ich;
287  TString trigEffName = Form("%s_fromRPCEffCh%i",trType.Data(),chamber);
288  Bool_t isOk = MakeSingleFigureSlide(trigEffName.Data(), filename.Data(), Form("MTR RPC efficiency for chamber %i (from %s track)",chamber, trType.Data()), outFile);
289  if ( ! isOk ) return kFALSE;
290  }
291  return kTRUE;
292 }
293 
294 //_________________________________
295 void MakeSummary ( TString period, ofstream &outFile )
296 {
297  if ( ! outFile.is_open() ) return;
298  BeginFrame("Summary I",outFile);
299  outFile << "General informations" << endl;
300  outFile << "\\begin{itemize}" << endl;
301  outFile << " \\item Runs selected for MUON on ALICE logbook:" << endl;
302  outFile << " \\begin{itemize}" << endl;
303  outFile << " \\item Run Type: PHYSICS" << endl;
304  outFile << " \\item Duration: at least 10 min" << endl;
305  outFile << " \\item GDC mStream Recording: Yes" << endl;
306  outFile << " \\item Period: " << period.Data() << endl;
307  outFile << " \\item Detectors: At least [ MUON\\_TRG \\& MUON\\_TRK ] as Readout" << endl;
308  outFile << " \\item Quality: globally GOOD and NOT BAD for readout Detectors" << endl;
309  outFile << " \\item Beam Mode: STABLE" << endl;
310  outFile << " \\end{itemize}" << endl;
311  outFile << "\\end{itemize}" << endl;
312  outFile << endl;
313  outFile << " \\vspace{5mm}" << endl;
314  outFile << endl;
315  outFile << "\\begin{columns}[onlytextwidth]" << endl;
316  outFile << " \\column{\\textwidth}" << endl;
317  outFile << " \\centering" << endl;
318  outFile << " \\begin{tabular}{|l|lll|}" << endl;
319  outFile << " \\hline" << endl;
320  outFile << " & Total runs & CMUL & CMSL \\\\" << endl;
321  outFile << " \\hline" << endl;
322  outFile << " ALICE logbook & xx & xx & xx\\\\" << endl;
323  outFile << " Good from QA & xx & xx & xx\\\\" << endl;
324  outFile << " \\hline" << endl;
325  outFile << " \\end{tabular}" << endl;
326  outFile << "\\end{columns}" << endl;
327  EndFrame(outFile);
328 
329  BeginFrame("Summary II",outFile);
330  outFile << endl;
331  outFile << "General:" << endl;
332  MakeDefaultItem(outFile);
333  outFile << endl;
334  outFile << "MTR efficiency:" << endl;
335  MakeDefaultItem(outFile);
336  outFile << endl;
337  outFile << "MCH and MUON data quality:" << endl;
338  MakeDefaultItem(outFile);
339  EndFrame(outFile);
340 }
341 
342 //_________________________________
343 std::map<int,std::vector<double>> GetRunInfo ( TString evsQA )
344 {
345  std::map<int,std::vector<double>> evsInfo;
346  if ( gSystem->AccessPathName(evsQA.Data()) == 0 ) {
347  TFile* file = TFile::Open(evsQA);
348  TTree* tree = static_cast<TTree*>(file->Get("trending"));
349  if ( tree ) {
350  int run, fill, bcs;
351  double mu;
352  tree->SetBranchAddress("run",&run);
353  tree->SetBranchAddress("fill",&fill);
354  tree->SetBranchAddress("bcs",&bcs);
355  tree->SetBranchAddress("mu",&mu);
356  for ( Long64_t ientry=0; ientry<tree->GetEntries(); ientry++ ) {
357  tree->GetEntry(ientry);
358  auto search = evsInfo.find(run);
359  if ( search != evsInfo.end() ) continue;
360  auto vec = &(evsInfo[run]);
361  vec->push_back((double)fill);
362  vec->push_back((double)bcs);
363  vec->push_back(mu);
364  }
365  }
366  delete file;
367  }
368  return evsInfo;
369 }
370 
371 //_________________________________
372 std::map<int, TString> GetRunSummary(ifstream& inFile)
373 {
374  std::map<int, TString> runSummary;
375  TString currLine;
376  int readRun = -1;
377  TString runInfo = "";
378  int nOpen = 0, nClosed = 0;
379  while ( ! inFile.eof() ) {
380  currLine.ReadLine(inFile,kFALSE);
381  int nOpenInLine = currLine.CountChar('{');
382  int nClosedInLine = currLine.CountChar('}');
383  if ( currLine.Contains("runTab") ) {
384  TString sRun = currLine(TRegexp("{[0-9][0-9][0-9][0-9][0-9][0-9]}"));
385  sRun.Remove(TString::kLeading,'{');
386  sRun.Remove(TString::kTrailing,'}');
387  readRun = sRun.Atoi();
388  nOpen = nOpenInLine;
389  nClosed = nClosedInLine;
390  runInfo = currLine + "\n";
391  }
392  else if ( currLine.Contains("colorLegend") ) {
393  break;
394  }
395 
396  if ( readRun < 0 ) continue;
397 
398  if ( nOpen > nClosed ) {
399  runInfo += currLine + "\n";
400  }
401  else if ( nOpen == nClosed ) {
402  runSummary[readRun] = runInfo;
403  readRun = -1;
404  }
405  }
406  return runSummary;
407 }
408 
409 //_________________________________
410 void MakeRunSummary ( ofstream &outFile, TString trackerQA, TString evsQA = "", ifstream* inFile = 0x0 )
411 {
412 
413  std::map<int,std::vector<double>> evsInfo = GetRunInfo(evsQA);
414  std::map<int, TString> runSummary;
415  if ( inFile ) runSummary = GetRunSummary(*inFile);
416 
417  std::vector<int> runList = GetRunList(trackerQA);
418  for ( auto& runNum : runList ) {
419  // Add current runs if needed.
420  // Do nothing if runs were already there...
421  runSummary[runNum];
422  }
423 
424  int previousFill = -1;
425  double previousMu = -1.;
426  for ( auto& entry : runSummary ) {
427  if ( entry.second.IsNull() ) {
428  TString runInfo = "";
429  auto search = evsInfo.find(entry.first);
430  if ( search != evsInfo.end() ) {
431  auto vec = search->second;
432  int fill = (int)vec[0];
433  double mu = vec[2];
434  double relDiff = TMath::Abs( mu - previousMu);
435  if ( previousMu != 0. ) relDiff /= previousMu;
436  if ( fill != previousFill || relDiff > 0.5 ) {
437  previousFill = fill;
438  previousMu = mu;
439  runInfo = Form("Fill %i, IB %i, mu %.3f",fill,(Int_t)vec[1],mu);
440  }
441  }
442  entry.second = Form(" \\runTab{%i}{%s}\n",entry.first,runInfo.Data());
443  }
444  }
445 
446  if ( runSummary.empty() ) runSummary[0] = " \\runTab[\\errorColor]{0}{xxx}";
447 
448  TString romanNum[10] = {"I","II","III","IV","V","VI","VII","VIII","IX","X"};
449 
450  int maxLinesPerColumn = 20;
451  int nCharPerLine = 42;
452 
453  auto it = runSummary.begin();
454  int ipage = 0;
455  while ( it != runSummary.end() ) {
456  TString title = "Run summary";
457  TString pageNum = romanNum[ipage % 10];
458  for (int idec = 0; idec < ipage / 10; ++idec) {
459  pageNum.Prepend("X");
460  }
461  title += Form(" (%s)", pageNum.Data());
462  BeginFrame(title, outFile);
463  outFile << " \\begin{columns}[onlytextwidth,T]" << endl;
464  outFile << " \\footnotesize" << endl;
465  for (int icol = 0; icol < 2; ++icol) {
466  outFile << " \\column{0.5\\textwidth}" << endl;
467  outFile << " \\centering" << endl;
468  outFile << " \\begin{tabular}{|cp{0.63\\textwidth}|}" << endl;
469  outFile << " \\hline" << endl;
470  int nLines = 0;
471  for (; it != runSummary.end(); ++it) {
472  int nChars = it->second.Length() - it->second.Index("{");
473  nLines += 1 + nChars/nCharPerLine;
474  if (nLines > maxLinesPerColumn) {
475  break;
476  }
477  outFile << it->second.Data();
478  }
479  outFile << " \\hline" << endl;
480  if (it == runSummary.end() && icol == 1) {
481  outFile << " \\hline" << endl;
482  outFile << " \\colorLegend" << endl;
483  outFile << " \\hline" << endl;
484  }
485  outFile << " \\end{tabular}" << endl;
486  } // loop on columns
487  outFile << " \\end{columns}" << endl;
488  EndFrame(outFile);
489  ++ipage;
490  } // loop on pages
491 }
492 
493 //_________________________________
494 void MakePreamble ( ofstream &outFile )
495 {
496  if ( ! outFile.is_open() ) return;
497  outFile << "\\documentclass[9pt,table]{beamer}" << endl;
498  outFile << "\\mode<presentation>" << endl;
499  outFile << "\\usepackage[T1]{fontenc}" << endl;
500  outFile << "\\usepackage{lmodern}" << endl;
501  outFile << "\\usepackage{textcomp}" << endl;
502  outFile << "\\usepackage{amsmath}" << endl;
503  outFile << "\\usepackage{color,graphicx}" << endl;
504  outFile << "\\usepackage{colortbl}" << endl;
505  outFile << "\\usepackage{multirow}" << endl;
506  outFile << "\\usepackage{pifont}" << endl;
507  outFile << "\\usepackage{wasysym}" << endl;
508  outFile << "\\usepackage{appendixnumberbeamer}" << endl;
509  outFile << "\\usepackage[absolute,overlay]{textpos}" << endl;
510  outFile << "\\usetheme{Madrid}" << endl;
511  outFile << "\\useoutertheme{shadow}" << endl;
512  outFile << endl;
513  outFile << "\\setbeamersize{text margin left=0.5cm, text margin right=0.5cm}" << endl;
514  outFile << endl;
515  outFile << "\\hypersetup{colorlinks,linkcolor=red,urlcolor=blue}" << endl;
516  outFile << endl;
517  outFile << "% Slightly change the template" << endl;
518  outFile << "\\setbeamertemplate{navigation symbols}{} %suppress navigation symbols (bottom-right of frame)" << endl;
519 
520  outFile << "\\setbeamercolor*{author in head/foot}{parent=palette tertiary}" << endl;
521  outFile << "\\setbeamercolor*{title in head/foot}{parent=palette secondary}" << endl;
522  outFile << "\\setbeamercolor*{date in head/foot}{parent=palette primary}" << endl;
523  // outFile << "\\setbeamercolor*{section in head/foot}{parent=palette tertiary}" << endl;
524  // outFile << "\\setbeamercolor*{subsection in head/foot}{parent=palette primary}" << endl;
525  outFile << "\\newcommand{\\changeFootline}[1]{" << endl;
526  outFile << " \\setbeamertemplate{footline}{" << endl;
527  outFile << " \\hbox{%" << endl;
528  outFile << " \\begin{beamercolorbox}[wd=.2\\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%" << endl;
529  outFile << " \\insertshortauthor%~~(\\insertshortinstitute)" << endl;
530  outFile << " \\end{beamercolorbox}%" << endl;
531  outFile << " \\begin{beamercolorbox}[wd=.6\\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%" << endl;
532  outFile << " \\hypersetup{hidelinks}%" << endl;
533  outFile << " \\insertshorttitle" << endl;
534  outFile << " \\hspace*{2em}\\insertshortdate{}" << endl;
535  outFile << " \\end{beamercolorbox}%" << endl;
536  outFile << " \\begin{beamercolorbox}[wd=.2\\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%" << endl;
537  outFile << " #1\\hspace*{2ex}" << endl;
538  outFile << " \\end{beamercolorbox}}%" << endl;
539  outFile << " }}" << endl;
540  outFile << "\\changeFootline{\\insertframenumber / \\inserttotalframenumber}" << endl;
541  outFile << "\\setbeamertemplate{headline}{}" << endl;
542  outFile << endl;
543  outFile << endl;
544  outFile << "\\newcommand{\\badForPassColor}{magenta!50!white}" << endl;
545  outFile << "\\newcommand{\\errorColor}{red!50!white}" << endl;
546 // outFile << "\\newcommand{\\newColor}{blue!20!white}" << endl;
547  outFile << "\\newcommand{\\notInLogColor}{black!20!white}" << endl;
548  outFile << "\\newcommand{\\pendingColor}{yellow!50!white}" << endl;
549  outFile << "\\newcommand{\\warningColor}{orange!50!white}" << endl;
550  outFile << "\\newcommand{\\colorLegend}{" << endl;
551 // outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\newColor}{~~} = newly analyzed}\\\\" << endl;
552  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\notInLogColor}{~~} = non-selected from e-logbook}\\\\" << endl;
553  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\pendingColor}{~~} = pending statement}\\\\" << endl;
554  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\warningColor}{~~} = possible problem}\\\\" << endl;
555  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\errorColor}{~~} = problem spotted}\\\\" << endl;
556  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\badForPassColor}{~~} = bad for this pass}\\\\}" << endl;
557  outFile << "\\newcommand{\\runTab}[3][white]{\\cellcolor{#1} #2 & \\cellcolor{#1} #3\\\\}" << endl;
558  outFile << endl;
559  outFile << "\\newcommand{\\pik}{\\ensuremath{\\pi\\mathrm{/K}}}" << endl;
560  outFile << "\\newcommand{\\mum}{\\mbox{$\\mu {\\rm m}$}}" << endl;
561  outFile << "\\newcommand{\\mom}{\\mbox{GeV$\\kern-0.15em /\\kern-0.12em c$}}" << endl;
562  outFile << "\\newcommand{\\pt}{\\ensuremath{p_{\\mathrm{T}}}}" << endl;
563  outFile << "\\newcommand{\\dd}{\\text{d}}" << endl;
564  outFile << "\\newcommand{\\raa}{\\ensuremath{R_{AA}}}" << endl;
565  outFile << "\\newcommand{\\un}[1]{\\protect\\detokenize{#1}}" << endl;
566  outFile << endl;
567 }
568 
569 //_________________________________
570 void BeginSlides ( TString period, TString pass, TString authors, ofstream &outFile )
571 {
572  if ( ! outFile.is_open() ) return;
573  TString authorsShort = "";
574  Bool_t previousIsLetter = kFALSE;
575  for ( Int_t ichar=0; ichar<authors.Length(); ichar++ ) {
576  TString currChar = authors[ichar];
577  currChar.ToUpper();
578  Int_t currentIsLetter = currChar.IsAlpha();
579  if ( currentIsLetter && ! previousIsLetter ) authorsShort += currChar + ".";
580  if ( currChar == "," ) authorsShort += ",";
581  previousIsLetter = currentIsLetter;
582  }
583 
584  outFile << "\\title{Muon QA: " << period.Data() << " " << pass.Data() << "}" << endl;
585  outFile << "\\author[" << authorsShort.Data() << "]{" << authors.Data() << "}" << endl;
586  outFile << "\\date{\\today}" << endl;
587 
588  outFile << "\\begin{document}" << endl;
589  outFile << "\\setlength{\\TPHorizModule}{1bp}" << endl;
590  outFile << "\\setlength{\\TPVertModule}{1bp}" << endl;
591  outFile << "\\textblockorigin{0bp}{0bp}" << endl;
592 
593  outFile << endl;
594  outFile << "\\begin{frame}[plain]" << endl;
595  outFile << " \\titlepage" << endl;
596  outFile << "\\end{frame}" << endl;
597 }
598 
599 //_________________________________
600 void EndSlides ( ofstream &outFile )
601 {
602  if ( ! outFile.is_open() ) return;
603  outFile << "\\end{document}" << endl;
604  outFile.close();
605 }
606 
607 //_________________________________
608 void StartAppendix ( ofstream &outFile )
609 {
610  if ( ! outFile.is_open() ) return;
611  outFile << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
612  outFile << "\\appendix" << endl;
613  outFile << "\\renewcommand{\\theframenumber}{A.\\arabic{framenumber}}" << endl;
614  outFile << "\\changeFootline{\\theframenumber}" << endl;
615  outFile << "\\begin{frame}[plain]" << endl;
616  outFile << " \\title{Backup slides}\\author{}\\date{}\\institute{}\\subtitle{}" << endl;
617  outFile << " \\titlepage" << endl;
618  outFile << "\\end{frame}" << endl;
619 }
620 
621 //_________________________________
622 void WriteRunList ( TString trackerQA, TString outFilename = "runListQA.txt" )
623 {
624  std::vector<int> runList = GetRunList(trackerQA);
625 
626  ofstream outFile(outFilename);
627  for ( auto& runNum : runList ) {
628  outFile << runNum << endl;
629  }
630  outFile.close();
631 }
632 
633 //_________________________________
634 TObjArray* UpdateExisting ( TString texFilename, TString trackerQA, TString evsQA )
635 {
636  TObjArray* trigList = NULL;
637  TString backupFile = texFilename;
638  backupFile.Append(".backup");
639  printf("Copying existing file into %s\n",backupFile.Data());
640  TFile::Cp(texFilename.Data(),backupFile);
641  ofstream outFile(texFilename.Data(),std::ofstream::out | std::ofstream::trunc);
642  ifstream inFile(backupFile.Data());
643  TString currLine = "", frameTitle = "";
644  Int_t nBlanks = 0;
645  while ( ! inFile.eof() ) {
646  currLine.ReadLine(inFile,kFALSE);
647  // Avoid too many blank lines
648  if ( currLine.IsNull() ) {
649  nBlanks++;
650  if ( nBlanks > 2 ) continue;
651  }
652  else nBlanks = 0;
653  if ( currLine == "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" ) {
654  frameTitle.ReadLine(inFile,kFALSE);
655  currLine += Form("\n%s",frameTitle.Data());
656  frameTitle.ReadLine(inFile,kFALSE);
657  currLine += Form("\n%s",frameTitle.Data());
658  if ( frameTitle.Contains("frametitle") && frameTitle.Contains("Run summary") ) {
659  MakeRunSummary(outFile, trackerQA, evsQA, &inFile);
660  while ( currLine != "\\end{frame}" ) {
661  currLine.ReadLine(inFile);
662  }
663  continue;
664  }
665  }
666  else if ( currLine.Contains("%TriggerList=") ) {
667  TString triggers = currLine;
668  triggers.Remove(0,triggers.Index("=")+1);
669  trigList = triggers.Tokenize(",");
670  }
671  outFile << currLine.Data() << endl;
672  }
673  inFile.close();
674 
675  return trigList;
676 }
677 
678 //_________________________________
679 void MakeSlides ( TString period, TString pass, TString triggerList, TString authors, TString trackerQA = "QA_muon_tracker.root", TString triggerQA = "QA_muon_trigger.root", TString evsQA = "trending_evs.root", TString texFilename = "muonQA.tex", TString outRunList = "" )
680 {
681 
682  TString fileNames[2] = {trackerQA,triggerQA};
683  for ( Int_t ifile=0; ifile<2; ifile++ ) {
684  if ( gSystem->AccessPathName(fileNames[ifile].Data()) ) {
685  printf("Fatal: cannot open %s\n",fileNames[ifile].Data());
686  return;
687  }
688  }
689 
690  TObjArray* trigList = 0x0;
691  ofstream outFile;
692  if ( gSystem->AccessPathName(texFilename.Data()) == 0 ) {
693  printf("Output file %s already exists: updating it\n", texFilename.Data());
694  trigList = UpdateExisting(texFilename, trackerQA, evsQA);
695  }
696  else {
697  EscapeSpecialChars(period);
698  EscapeSpecialChars(pass);
699 
700  trigList = triggerList.Tokenize(",");
701 
702  outFile.open(texFilename);
703  outFile << "% !TEX pdfSinglePage" << endl; // Useful for texshop
704  outFile << "%TriggerList=" << triggerList.Data() << endl;
705  MakePreamble(outFile);
706  BeginSlides(period,pass,authors,outFile);
707 
708  MakeSummary(period,outFile);
709  MakeRunSummary(outFile, trackerQA, evsQA);
710  }
711 
712  MakeSingleFigureSlide("AllTriggers",trackerQA,"Number of events per trigger",outFile);
713  MakeSingleFigureSlide("L2AQAoverSCALERS",triggerQA,"Reconstruction: reconstructed triggers in QA wrt L2A from OCDB scalers",outFile);
714 
715  // Bool_t isNew = MakeSingleFigureSlide("Trigger_fromChamberEff", triggerQA, "MTR chamber efficiency (from trigger track)", outFile);
716  Bool_t isNew = MakeTriggerRPCslides(triggerQA, outFile);
717  if ( ! isNew ) MakeTriggerSlide(triggerQA,outFile);
718 
719  for ( Int_t itrig=0; itrig<trigList->GetEntries(); itrig++ ) {
720  TString currTrig = trigList->At(itrig)->GetName();
721  TString shortTrig = GetTriggerShort(currTrig);
722  MakeSingleFigureSlide(Form("RatioTrackTypes_cent0trigger%s",currTrig.Data()),trackerQA,Form("Muon tracks / event in %s events",shortTrig.Data()),outFile);
723  MakeSingleFigureSlide(Form("RatioTrackTypes_cent3trigger%s",currTrig.Data()),trackerQA,Form("Muon tracks / event in %s events (central collisions)",shortTrig.Data()),outFile,"",kFALSE);
724  MakeSingleFigureSlide(Form("TrackMult_cent0trigger%s",currTrig.Data()),trackerQA,Form("Muon tracker-trigger tracks / event in %s events",shortTrig.Data()),outFile);
725  MakeSingleFigureSlide(Form("AsymMatchedtrigger%s",currTrig.Data()),trackerQA,Form("Charge asymmetry in %s events",shortTrig.Data()),outFile);
726  MakeSingleFigureSlide(Form("BeamGasMatchedtrigger%s",currTrig.Data()),trackerQA,Form("Rel. num. of beam-gas tracks (id. by p$\\times$DCA cuts) in %s events",shortTrig.Data()),outFile,currTrig);
727  }
728  MakeSingleFigureSlide("cNClusters",trackerQA,"Average number of clusters per track and dispersion",outFile); MakeSingleFigureSlide("cNClustersPerCh",trackerQA,"Average number of clusters per chamber",outFile,"","clustersPerChamber");
729 
730  if ( outFile.is_open() ) StartAppendix(outFile);
731  MakeSingleFigureSlide("PhysSelCutOnCollTrigger",trackerQA,"Physics selection effects",outFile);
732  MakeSingleFigureSlide("cClusterHitMapPerCh",trackerQA,"Average cluster position per chamber",outFile,"","clustersPosition");
733  MakeSingleFigureSlide("cChi2",trackerQA,"Tracking quality",outFile);
734 
735  if ( isNew ) MakeTriggerRPCslides(triggerQA, outFile, kTRUE);
736  else {
737  MakeTriggerRPCslide(triggerQA,outFile);
738  MakeTriggerRPCslide(triggerQA,outFile,kTRUE);
739  }
740  MakeSingleFigureSlide("cLptHpt",trackerQA,"Trigger \\pt\\ cut",outFile,"",kTRUE,kTRUE);
741 
742  if ( outFile.is_open() ) {
743  BeginFrame("Hardware issues",outFile);
744  outFile << "MUON Trigger" << endl;
745  MakeDefaultItem(outFile);
746  outFile << endl;
747  outFile << "MUON tracker" << endl;
748  MakeDefaultItem(outFile);
749  EndFrame(outFile);
750 
751  EndSlides(outFile);
752  }
753 
754  delete trigList;
755 
756  if ( ! outRunList.IsNull() ) WriteRunList(trackerQA, outRunList);
757 }
void BeginSlides(TString period, TString pass, TString authors, ofstream &outFile)
Definition: MakeSlides.C:570
std::map< int, TString > GetRunSummary(ifstream &inFile)
Definition: MakeSlides.C:372
const char * filename
Definition: TestFCM.C:1
Bool_t MakeTriggerSlide(TString filename, ofstream &outFile)
Definition: MakeSlides.C:187
Int_t fNpages
Definition: MakeSlides.C:26
const char * title
Definition: MakeQAPdf.C:27
void MakeDefaultItem(ofstream &outFile, TString defaultItem="")
Definition: MakeSlides.C:158
Bool_t MakeSingleFigureSlide(TString objName, TString filename, TString title, ofstream &outFile, TString label="", Bool_t warnIfMissing=kTRUE, Bool_t closePdf=kFALSE)
Definition: MakeSlides.C:167
long long Long64_t
Definition: External.C:43
TSystem * gSystem
void WriteRunList(TString trackerQA, TString outFilename="runListQA.txt")
Definition: MakeSlides.C:622
TObjArray * UpdateExisting(TString texFilename, TString trackerQA, TString evsQA)
Definition: MakeSlides.C:634
const char * outPdf
Definition: MakeSlides.C:27
Bool_t MakeTriggerRPCslide(TString filename, ofstream &outFile, Bool_t outliers=kFALSE)
Definition: MakeSlides.C:258
Bool_t MakeTriggerRPCslides(TString filename, ofstream &outFile, Bool_t fromTrackerTrack=kFALSE)
Definition: MakeSlides.C:282
Bool_t PrintToPdf(TString objName, TString filename, Bool_t closeFile, Bool_t warnIfMissing)
Definition: MakeSlides.C:75
int Int_t
Definition: External.C:63
void MakePreamble(ofstream &outFile)
Definition: MakeSlides.C:494
void EscapeSpecialChars(TString &str)
Definition: MakeSlides.C:126
void EndSlides(ofstream &outFile)
Definition: MakeSlides.C:600
std::map< int, std::vector< double > > GetRunInfo(TString evsQA)
Definition: MakeSlides.C:343
void BeginFrame(TString title, ofstream &outFile, TString label="")
Definition: MakeSlides.C:139
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Int_t colors[nPtBins]
void MakeSlides(TString period, TString pass, TString triggerList, TString authors, TString trackerQA="QA_muon_tracker.root", TString triggerQA="QA_muon_trigger.root", TString evsQA="trending_evs.root", TString texFilename="muonQA.tex", TString outRunList="")
Definition: MakeSlides.C:679
std::vector< int > GetRunList(TString filename)
Definition: MakeSlides.C:42
void EndFrame(ofstream &outFile)
Definition: MakeSlides.C:151
Definition: External.C:220
void MakeSummary(TString period, ofstream &outFile)
Definition: MakeSlides.C:295
TFile * file
TList with histograms for a given trigger.
void StartAppendix(ofstream &outFile)
Definition: MakeSlides.C:608
void MakeRunSummary(ofstream &outFile, TString trackerQA, TString evsQA="", ifstream *inFile=0x0)
Definition: MakeSlides.C:410
bool Bool_t
Definition: External.C:53
Definition: External.C:196
TString GetTriggerShort(TString trigName)
Definition: MakeSlides.C:30