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