AliPhysics  1811c8f (1811c8f)
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<Double_t>> GetRunInfo ( TString evsQA )
339 {
340  std::map<Int_t,std::vector<Double_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  Double_t mu;
347  tree->SetBranchAddress("run",&run);
348  tree->SetBranchAddress("fill",&fill);
349  tree->SetBranchAddress("bcs",&bcs);
350  tree->SetBranchAddress("mu",&mu);
351  for ( Long64_t ientry=0; ientry<tree->GetEntries(); ientry++ ) {
352  tree->GetEntry(ientry);
353  auto search = map.find(run);
354  if ( search != map.end() ) continue;
355  auto vec = &(map[run]);
356  vec->push_back((Double_t)fill);
357  vec->push_back((Double_t)bcs);
358  vec->push_back(mu);
359  }
360  }
361  delete file;
362  }
363  return map;
364 }
365 
366 //_________________________________
367 void MakeRunSummary ( ofstream &outFile, TString trackerQA, TString evsQA = "", ifstream* inFile = 0x0 )
368 {
369 
370  std::map<Int_t,std::vector<Double_t>> map = GetRunInfo(evsQA);
371 
372  TObjArray* runListArr = GetRunList(trackerQA);
373  runListArr->Sort();
374 
375  Bool_t readSummary = ( inFile ) ? kTRUE : kFALSE;
376 
377  TString romanNum[10] = {"I","II","III","IV","V","VI","VII","VIII","IX","X"};
378 
379  Int_t nRuns = runListArr->GetEntries();
380  Int_t nRunsPerPage = 40;
381  Int_t nRunsPerColumn = nRunsPerPage/2;
382 
383  Int_t nPages = nRuns/nRunsPerPage;
384  if ( nRuns%nRunsPerPage > 0 ) nPages++;
385 
386  Int_t irun = 0;
387  Int_t readRun = -2, currRun = -1;
388 
389  Int_t previousFill = -1;
390  Double_t previousMu = 0.;
391 
392  for ( Int_t ipage=0; ipage<nPages; ipage++ ) {
393  TString title = "Run summary";
394  if ( nPages > 1 ) title += Form(" (%s)",romanNum[ipage].Data());
395  BeginFrame(title,outFile);
396  outFile << " \\begin{columns}[onlytextwidth,T]" << endl;
397  outFile << " \\footnotesize" << endl;
398  for ( Int_t icol=0; icol<2; icol++ ) {
399  Bool_t needsHline = ( icol == 0 || irun < nRuns );
400  outFile << " \\column{0.5\\textwidth}" << endl;
401  outFile << " \\centering" << endl;
402  outFile << " \\begin{tabular}{|cp{0.63\\textwidth}|}" << endl;
403  if ( needsHline ) outFile << " \\hline" << endl;
404  if ( nRuns == 0 ) {
405  outFile << " \\runTab[\\errorColor]{xxx}{xxx}" << endl;
406  }
407  else {
408  while ( irun<nRuns ) {
409  currRun = static_cast<TObjString*>(runListArr->UncheckedAt(irun++))->GetString().Atoi();
410  Bool_t isNew = kTRUE;
411  TString readLines = "", currLine = "";
412  while ( readSummary ) {
413  currLine.ReadLine(*inFile,kFALSE);
414  if ( currLine.Contains("runTab") ) {
415  TString sRun = currLine(TRegexp("{[0-9][0-9][0-9][0-9][0-9][0-9]}"));
416  sRun.Remove(TString::kLeading,'{');
417  sRun.Remove(TString::kTrailing,'}');
418  readRun = sRun.Atoi();
419  if ( readRun <= currRun ) readLines += currLine + "\n";
420  if ( readRun == currRun ) {
421  isNew = kFALSE;
422  break;
423  }
424  }
425  else if ( currLine.Contains("colorLegend") ) readSummary = kFALSE;
426  }
427  if ( isNew ) {
428  auto search = map.find(currRun);
429  TString info = "";
430  if ( search != map.end() ) {
431  auto vec = search->second;
432  Int_t fill = (Int_t)vec[0];
433  Double_t mu = vec[2];
434  Double_t ratio = previousMu > 0. ? mu/previousMu : 10.;
435  if ( fill != previousFill || TMath::Abs(1.-ratio) > 0.5 ) {
436  previousFill = fill;
437  previousMu = mu;
438  info = Form("Fill %i, IB %i, mu %.3f",fill,(Int_t)vec[1],mu);
439  }
440  }
441  outFile << " \\runTab{" << currRun << "}{" << info.Data() << "}" << endl;
442  }
443  else outFile << readLines.Data();
444  if ( irun%nRunsPerColumn == 0 ) break;
445  }
446  }
447 
448  if ( needsHline ) outFile << " \\hline" << endl;
449  if ( icol == 1 && ipage == nPages -1 ) {
450  outFile << " \\hline" << endl;
451  outFile << " \\colorLegend" << endl;
452  outFile << " \\hline" << endl;
453  }
454  outFile << " \\end{tabular}" << endl;
455  if ( icol == 0 ) outFile << endl;
456  else {
457  outFile << " \\end{columns}" << endl;
458  EndFrame(outFile);
459  }
460  } // loop on columns
461  } // loop on pages
462 
463  delete runListArr;
464 }
465 
466 //_________________________________
467 void MakePreamble ( ofstream &outFile )
468 {
469  if ( ! outFile.is_open() ) return;
470  outFile << "\\documentclass[9pt,table]{beamer}" << endl;
471  outFile << "\\mode<presentation>" << endl;
472  outFile << "\\usepackage[T1]{fontenc}" << endl;
473  outFile << "\\usepackage{lmodern}" << endl;
474  outFile << "\\usepackage{textcomp}" << endl;
475  outFile << "\\usepackage{amsmath}" << endl;
476  outFile << "\\usepackage{color,graphicx}" << endl;
477  outFile << "\\usepackage{colortbl}" << endl;
478  outFile << "\\usepackage{multirow}" << endl;
479  outFile << "\\usepackage{pifont}" << endl;
480  outFile << "\\usepackage{wasysym}" << endl;
481  outFile << "\\usepackage{appendixnumberbeamer}" << endl;
482  outFile << "\\usepackage[absolute,overlay]{textpos}" << endl;
483  outFile << "\\usetheme{Madrid}" << endl;
484  outFile << "\\useoutertheme{shadow}" << endl;
485  outFile << endl;
486  outFile << "\\setbeamersize{text margin left=0.5cm, text margin right=0.5cm}" << endl;
487  outFile << endl;
488  outFile << "\\hypersetup{colorlinks,linkcolor=red,urlcolor=blue}" << endl;
489  outFile << endl;
490  outFile << "% Slightly change the template" << endl;
491  outFile << "\\setbeamertemplate{navigation symbols}{} %suppress navigation symbols (bottom-right of frame)" << endl;
492 
493  outFile << "\\setbeamercolor*{author in head/foot}{parent=palette tertiary}" << endl;
494  outFile << "\\setbeamercolor*{title in head/foot}{parent=palette secondary}" << endl;
495  outFile << "\\setbeamercolor*{date in head/foot}{parent=palette primary}" << endl;
496  // outFile << "\\setbeamercolor*{section in head/foot}{parent=palette tertiary}" << endl;
497  // outFile << "\\setbeamercolor*{subsection in head/foot}{parent=palette primary}" << endl;
498  outFile << "\\newcommand{\\changeFootline}[1]{" << endl;
499  outFile << " \\setbeamertemplate{footline}{" << endl;
500  outFile << " \\hbox{%" << endl;
501  outFile << " \\begin{beamercolorbox}[wd=.2\\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%" << endl;
502  outFile << " \\insertshortauthor%~~(\\insertshortinstitute)" << endl;
503  outFile << " \\end{beamercolorbox}%" << endl;
504  outFile << " \\begin{beamercolorbox}[wd=.6\\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%" << endl;
505  outFile << " \\hypersetup{hidelinks}%" << endl;
506  outFile << " \\insertshorttitle" << endl;
507  outFile << " \\hspace*{2em}\\insertshortdate{}" << endl;
508  outFile << " \\end{beamercolorbox}%" << endl;
509  outFile << " \\begin{beamercolorbox}[wd=.2\\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%" << endl;
510  outFile << " #1\\hspace*{2ex}" << endl;
511  outFile << " \\end{beamercolorbox}}%" << endl;
512  outFile << " }}" << endl;
513  outFile << "\\changeFootline{\\insertframenumber / \\inserttotalframenumber}" << endl;
514  outFile << "\\setbeamertemplate{headline}{}" << endl;
515  outFile << endl;
516  outFile << endl;
517  outFile << "\\newcommand{\\badForPassColor}{magenta!50!white}" << endl;
518  outFile << "\\newcommand{\\errorColor}{red!50!white}" << endl;
519 // outFile << "\\newcommand{\\newColor}{blue!20!white}" << endl;
520  outFile << "\\newcommand{\\notInLogColor}{black!20!white}" << endl;
521  outFile << "\\newcommand{\\pendingColor}{yellow!50!white}" << endl;
522  outFile << "\\newcommand{\\warningColor}{orange!50!white}" << endl;
523  outFile << "\\newcommand{\\colorLegend}{" << endl;
524 // outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\newColor}{~~} = newly analyzed}\\\\" << endl;
525  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\notInLogColor}{~~} = non-selected from e-logbook}\\\\" << endl;
526  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\pendingColor}{~~} = pending statement}\\\\" << endl;
527  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\warningColor}{~~} = possible problem}\\\\" << endl;
528  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\errorColor}{~~} = problem spotted}\\\\" << endl;
529  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\badForPassColor}{~~} = bad for this pass}\\\\}" << endl;
530  outFile << "\\newcommand{\\runTab}[3][white]{\\cellcolor{#1} #2 & \\cellcolor{#1} #3\\\\}" << endl;
531  outFile << endl;
532  outFile << "\\newcommand{\\pik}{\\ensuremath{\\pi\\mathrm{/K}}}" << endl;
533  outFile << "\\newcommand{\\mum}{\\mbox{$\\mu {\\rm m}$}}" << endl;
534  outFile << "\\newcommand{\\mom}{\\mbox{GeV$\\kern-0.15em /\\kern-0.12em c$}}" << endl;
535  outFile << "\\newcommand{\\pt}{\\ensuremath{p_{\\mathrm{T}}}}" << endl;
536  outFile << "\\newcommand{\\dd}{\\text{d}}" << endl;
537  outFile << "\\newcommand{\\raa}{\\ensuremath{R_{AA}}}" << endl;
538  outFile << "\\newcommand{\\un}[1]{\\protect\\detokenize{#1}}" << endl;
539  outFile << endl;
540 }
541 
542 //_________________________________
543 void BeginSlides ( TString period, TString pass, TString authors, ofstream &outFile )
544 {
545  if ( ! outFile.is_open() ) return;
546  TString authorsShort = "";
547  Bool_t previousIsLetter = kFALSE;
548  for ( Int_t ichar=0; ichar<authors.Length(); ichar++ ) {
549  TString currChar = authors[ichar];
550  currChar.ToUpper();
551  Int_t currentIsLetter = currChar.IsAlpha();
552  if ( currentIsLetter && ! previousIsLetter ) authorsShort += currChar + ".";
553  if ( currChar == "," ) authorsShort += ",";
554  previousIsLetter = currentIsLetter;
555  }
556 
557  outFile << "\\title{Muon QA: " << period.Data() << " " << pass.Data() << "}" << endl;
558  outFile << "\\author[" << authorsShort.Data() << "]{" << authors.Data() << "}" << endl;
559  outFile << "\\date{\\today}" << endl;
560 
561  outFile << "\\begin{document}" << endl;
562  outFile << "\\setlength{\\TPHorizModule}{1bp}" << endl;
563  outFile << "\\setlength{\\TPVertModule}{1bp}" << endl;
564  outFile << "\\textblockorigin{0bp}{0bp}" << endl;
565 
566  outFile << endl;
567  outFile << "\\begin{frame}[plain]" << endl;
568  outFile << " \\titlepage" << endl;
569  outFile << "\\end{frame}" << endl;
570 }
571 
572 //_________________________________
573 void EndSlides ( ofstream &outFile )
574 {
575  if ( ! outFile.is_open() ) return;
576  outFile << "\\end{document}" << endl;
577  outFile.close();
578 }
579 
580 //_________________________________
581 void StartAppendix ( ofstream &outFile )
582 {
583  if ( ! outFile.is_open() ) return;
584  outFile << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
585  outFile << "\\appendix" << endl;
586  outFile << "\\renewcommand{\\theframenumber}{A.\\arabic{framenumber}}" << endl;
587  outFile << "\\changeFootline{\\theframenumber}" << endl;
588  outFile << "\\begin{frame}[plain]" << endl;
589  outFile << " \\title{Backup slides}\\author{}\\date{}\\institute{}\\subtitle{}" << endl;
590  outFile << " \\titlepage" << endl;
591  outFile << "\\end{frame}" << endl;
592 }
593 
594 //_________________________________
595 void WriteRunList ( TString trackerQA, TString outFilename = "runListQA.txt" )
596 {
597  TObjArray* runListArr = GetRunList(trackerQA);
598 
599  ofstream outFile(outFilename);
600  for ( Int_t irun=0; irun<runListArr->GetEntries(); irun++ ) {
601  outFile << static_cast<TObjString*>(runListArr->At(irun))->GetString().Atoi() << endl;
602  }
603  outFile.close();
604  delete runListArr;
605 }
606 
607 
608 //_________________________________
609 TObjArray* UpdateExisting ( TString texFilename, TString trackerQA, TString evsQA )
610 {
611  TObjArray* trigList = NULL;
612  TString backupFile = texFilename;
613  backupFile.Append(".backup");
614  printf("Copying existing file into %s\n",backupFile.Data());
615  TFile::Cp(texFilename.Data(),backupFile);
616  ofstream outFile(texFilename.Data(),std::ofstream::out | std::ofstream::trunc);
617  ifstream inFile(backupFile.Data());
618  TString currLine = "", frameTitle = "";
619  Int_t nBlanks = 0;
620  while ( ! inFile.eof() ) {
621  currLine.ReadLine(inFile,kFALSE);
622  // Avoid too many blank lines
623  if ( currLine.IsNull() ) {
624  nBlanks++;
625  if ( nBlanks > 2 ) continue;
626  }
627  else nBlanks = 0;
628  if ( currLine == "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" ) {
629  frameTitle.ReadLine(inFile,kFALSE);
630  currLine += Form("\n%s",frameTitle.Data());
631  frameTitle.ReadLine(inFile,kFALSE);
632  currLine += Form("\n%s",frameTitle.Data());
633  if ( frameTitle.Contains("frametitle") && frameTitle.Contains("Run summary") ) {
634  MakeRunSummary(outFile, trackerQA, evsQA, &inFile);
635  while ( currLine != "\\end{frame}" ) {
636  currLine.ReadLine(inFile);
637  }
638  continue;
639  }
640  }
641  else if ( currLine.Contains("%TriggerList=") ) {
642  TString triggers = currLine;
643  triggers.Remove(0,triggers.Index("=")+1);
644  trigList = triggers.Tokenize(",");
645  }
646  outFile << currLine.Data() << endl;
647  }
648  inFile.close();
649 
650  return trigList;
651 }
652 
653 //_________________________________
654 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 = "" )
655 {
656 
657  TString fileNames[2] = {trackerQA,triggerQA};
658  for ( Int_t ifile=0; ifile<2; ifile++ ) {
659  if ( gSystem->AccessPathName(fileNames[ifile].Data()) ) {
660  printf("Fatal: cannot open %s\n",fileNames[ifile].Data());
661  return;
662  }
663  }
664 
665  TObjArray* trigList = 0x0;
666  ofstream outFile;
667  if ( gSystem->AccessPathName(texFilename.Data()) == 0 ) {
668  printf("Output file %s already exists: updating it\n", texFilename.Data());
669  trigList = UpdateExisting(texFilename, trackerQA, evsQA);
670  }
671  else {
672  EscapeSpecialChars(period);
673  EscapeSpecialChars(pass);
674 
675  trigList = triggerList.Tokenize(",");
676 
677  outFile.open(texFilename);
678  outFile << "% !TEX pdfSinglePage" << endl; // Useful for texshop
679  outFile << "%TriggerList=" << triggerList.Data() << endl;
680  MakePreamble(outFile);
681  BeginSlides(period,pass,authors,outFile);
682 
683  MakeSummary(period,outFile);
684  MakeRunSummary(outFile, trackerQA, evsQA);
685  }
686 
687  MakeSingleFigureSlide("AllTriggers",trackerQA,"Number of events per trigger",outFile);
688  MakeSingleFigureSlide("L2AQAoverSCALERS",triggerQA,"Reconstruction: reconstructed triggers in QA wrt L2A from OCDB scalers",outFile);
689 
690  // Bool_t isNew = MakeSingleFigureSlide("Trigger_fromChamberEff", triggerQA, "MTR chamber efficiency (from trigger track)", outFile);
691  Bool_t isNew = MakeTriggerRPCslides(triggerQA, outFile);
692  if ( ! isNew ) MakeTriggerSlide(triggerQA,outFile);
693 
694  for ( Int_t itrig=0; itrig<trigList->GetEntries(); itrig++ ) {
695  TString currTrig = trigList->At(itrig)->GetName();
696  TString shortTrig = GetTriggerShort(currTrig);
697  MakeSingleFigureSlide(Form("RatioTrackTypes_cent0trigger%s",currTrig.Data()),trackerQA,Form("Muon tracks / event in %s events",shortTrig.Data()),outFile);
698  MakeSingleFigureSlide(Form("RatioTrackTypes_cent3trigger%s",currTrig.Data()),trackerQA,Form("Muon tracks / event in %s events (central collisions)",shortTrig.Data()),outFile,"",kFALSE);
699  MakeSingleFigureSlide(Form("TrackMult_cent0trigger%s",currTrig.Data()),trackerQA,Form("Muon tracker-trigger tracks / event in %s events",shortTrig.Data()),outFile);
700  MakeSingleFigureSlide(Form("AsymMatchedtrigger%s",currTrig.Data()),trackerQA,Form("Charge asymmetry in %s events",shortTrig.Data()),outFile);
701  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);
702  }
703  MakeSingleFigureSlide("cNClusters",trackerQA,"Average number of clusters per track and dispersion",outFile); MakeSingleFigureSlide("cNClustersPerCh",trackerQA,"Average number of clusters per chamber",outFile,"","clustersPerChamber");
704 
705  if ( outFile.is_open() ) StartAppendix(outFile);
706  MakeSingleFigureSlide("PhysSelCutOnCollTrigger",trackerQA,"Physics selection effects",outFile);
707  MakeSingleFigureSlide("cClusterHitMapPerCh",trackerQA,"Average cluster position per chamber",outFile,"","clustersPosition");
708  MakeSingleFigureSlide("cChi2",trackerQA,"Tracking quality",outFile);
709 
710  if ( isNew ) MakeTriggerRPCslides(triggerQA, outFile, kTRUE);
711  else {
712  MakeTriggerRPCslide(triggerQA,outFile);
713  MakeTriggerRPCslide(triggerQA,outFile,kTRUE);
714  }
715  MakeSingleFigureSlide("cLptHpt",trackerQA,"Trigger \\pt\\ cut",outFile,"",kTRUE,kTRUE);
716 
717  if ( outFile.is_open() ) {
718  BeginFrame("Hardware issues",outFile);
719  outFile << "MUON Trigger" << endl;
720  MakeDefaultItem(outFile);
721  outFile << endl;
722  outFile << "MUON tracker" << endl;
723  MakeDefaultItem(outFile);
724  EndFrame(outFile);
725 
726  EndSlides(outFile);
727  }
728 
729  delete trigList;
730 
731  if ( ! outRunList.IsNull() ) WriteRunList(trackerQA, outRunList);
732 }
void BeginSlides(TString period, TString pass, TString authors, ofstream &outFile)
Definition: MakeSlides.C:543
const char * filename
Definition: TestFCM.C:1
Bool_t MakeTriggerSlide(TString filename, ofstream &outFile)
Definition: MakeSlides.C:182
double Double_t
Definition: External.C:58
Int_t fNpages
Definition: MakeSlides.C:26
const char * title
Definition: MakeQAPdf.C:27
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:595
TObjArray * UpdateExisting(TString texFilename, TString trackerQA, TString evsQA)
Definition: MakeSlides.C:609
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
std::map< Int_t, std::vector< Double_t > > GetRunInfo(TString evsQA)
Definition: MakeSlides.C:338
void MakePreamble(ofstream &outFile)
Definition: MakeSlides.C:467
void EscapeSpecialChars(TString &str)
Definition: MakeSlides.C:121
void EndSlides(ofstream &outFile)
Definition: MakeSlides.C:573
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:654
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:581
void MakeRunSummary(ofstream &outFile, TString trackerQA, TString evsQA="", ifstream *inFile=0x0)
Definition: MakeSlides.C:367
bool Bool_t
Definition: External.C:53
Definition: External.C:196
TString GetTriggerShort(TString trigName)
Definition: MakeSlides.C:30