AliPhysics  vAN-20150427 (e6e7aad)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
MakeSlides.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 
3 #include <Riostream.h>
4 
5 // ROOT includes
6 #include "TString.h"
7 #include "TSystem.h"
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TEnv.h"
11 #include "TObjArray.h"
12 #include "TObjString.h"
13 #include "TArrayI.h"
14 #endif
15 
16 //_________________________________
17 TString GetConvertedFilename ( TString filename )
18 {
19  TString convertedFilename = filename;
20  convertedFilename.ReplaceAll(".pdf",".txt");
21  return convertedFilename;
22 }
23 
24 //_________________________________
25 TString GetTriggerShort ( TString trigName )
26 {
27  TObjArray* arr = trigName.Tokenize("-");
28  TString shortName = arr->At(0)->GetName();
29  if ( arr->GetEntries() > 2 ) {
30  shortName.Append(Form("-%s",arr->At(1)->GetName()));
31  }
32  delete arr;
33  return shortName;
34 }
35 
36 //_________________________________
37 Int_t GetPage ( TString pattern, TString filename )
38 {
39  TString convertedFilename = GetConvertedFilename(filename);
40 
41  if ( gSystem->AccessPathName(convertedFilename.Data()) != 0 ) {
42  gSystem->Exec(Form("gs -dBATCH -dNOPAUSE -sDEVICE=txtwrite -sOutputFile=- %s > %s",filename.Data(),convertedFilename.Data()));
43  }
44 
45  ifstream inFile(convertedFilename.Data());
46  if ( ! inFile.is_open() ) return -1;
47 
48  TObjArray* patternArr = pattern.Tokenize("&");
49  TArrayI foundPages(patternArr->GetEntries());
50  foundPages.Reset(-1);
51 
52  TString currLine = "";
53  Int_t currPage = -1;
54  Bool_t allOk = kFALSE;
55  while ( ! inFile.eof() ) {
56  currLine.ReadLine(inFile);
57  if ( currLine.Contains("Page") ) {
58  currLine.Remove(0,5);
59  currPage = currLine.Atoi();
60  foundPages.Reset(-1);
61  }
62  else {
63  for ( Int_t ipat=0; ipat<patternArr->GetEntries(); ipat++ ) {
64  TString currPattern = static_cast<TObjString*>(patternArr->At(ipat))->GetString();
65  if ( currLine.Contains(currPattern.Data()) ) {
66  foundPages[ipat] = currPage;
67  Bool_t matchAll = kTRUE;
68  for ( Int_t jpat=0; jpat<patternArr->GetEntries(); jpat++ ) {
69  if ( foundPages[ipat] != foundPages[jpat] ) {
70  matchAll = kFALSE;
71  break;
72  }
73  }
74  if ( matchAll ) {
75  allOk = kTRUE;
76  break;
77  }
78  }
79  }
80  if ( allOk ) break;
81  }
82  }
83  inFile.close();
84  delete patternArr;
85  if ( ! allOk ) {
86  printf("Warning: cannot find %s\n",pattern.Data());
87  return -1;
88  }
89  return foundPages[0];
90 }
91 
92 
93 //_________________________________
94 void EscapeSpecialChars ( TString& str )
95 {
96  str.ReplaceAll("\\","");
97  TString specials = "_";
98  TObjArray* specialList = specials.Tokenize(" ");
99  for ( Int_t ichar=0; ichar<specialList->GetEntries(); ichar++ ) {
100  TString currChar = static_cast<TObjString*>(specialList->At(ichar))->GetString();
101  if ( str.Contains(currChar.Data()) ) str.ReplaceAll(currChar.Data(),Form("\\\%s",currChar.Data()));
102  }
103  delete specialList;
104 }
105 
106 //_________________________________
107 void BeginFrame ( TString title, ofstream& outFile )
108 {
109  outFile << endl;
110  outFile << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
111  outFile << "\\begin{frame}" << endl;
112  outFile << " \\frametitle{" << title.Data() << "}" << endl;
113 }
114 
115 //_________________________________
116 void EndFrame ( ofstream& outFile )
117 {
118  outFile << "\\end{frame}" << endl;
119 }
120 
121 //_________________________________
122 void MakeDefaultItem ( ofstream& outFile, TString defaultItem = "" )
123 {
124  outFile << "\\begin{itemize}" << endl;
125  outFile << " \\item " << defaultItem.Data() << endl;
126  outFile << "\\end{itemize}" << endl;
127 }
128 
129 //_________________________________
130 Bool_t MakeSingleFigureSlide ( TString pattern, TString filename, TString title, ofstream &outFile )
131 {
132  Int_t pageNum = GetPage(pattern,filename);
133  if ( pageNum<0 ) {
134  return kFALSE;
135  }
136 
137  BeginFrame(title,outFile);
138  outFile << " \\begin{columns}[onlytextwidth]" << endl;
139  outFile << " \\column{\\textwidth}" << endl;
140  outFile << " \\centering" << endl;
141  outFile << " \\includegraphics[width=0.98\\textwidth,height=0.92\\textheight,page=" << pageNum << "]{" << gSystem->BaseName(filename.Data()) << "}" <<endl;
142  outFile << " \\end{columns}" << endl;
143  EndFrame(outFile);
144  return kTRUE;
145 }
146 
147 //_________________________________
148 Bool_t MakeTriggerSlide ( TString filename, ofstream &outFile )
149 {
150  BeginFrame("Trigger chamber efficiencies", outFile);
151  outFile << " \\begin{columns}[onlytextwidth]" << endl;
152  outFile << " \\column{0.66\\textwidth}" << endl;
153  outFile << " \\centering" << endl;
154  for ( Int_t ich=0; ich<4; ich++ ) {
155  if ( ich%2 == 0 ) outFile << endl;
156  Int_t ipage = GetPage(Form("Trigger chamber efficiency vs run for chamber %i",11+ich),filename);
157  outFile << " \\includegraphics[width=0.48\\textwidth,page=" << ipage << "]{" << filename.Data() << "}" << endl;
158  }
159  outFile << " \\column{0.34\\textwidth}" << endl;
160  outFile << " \\centering" << endl;
161  Int_t ipage = GetPage("Multinomial probability",filename);
162  outFile << " \\includegraphics[width=0.98\\textwidth,page=" << ipage << "]{" << filename.Data() << "}" << endl;
163  outFile << " \\end{columns}" << endl;
164  EndFrame(outFile);
165  return kTRUE;
166 }
167 
168 //_________________________________
169 Bool_t MakeTriggerRPCslide ( TString filename, ofstream &outFile )
170 {
171  BeginFrame("Trigger chamber efficiencies per RPC",outFile);
172  outFile << " \\begin{columns}[onlytextwidth]" << endl;
173  outFile << " \\column{\\textwidth}" << endl;
174  outFile << " \\centering" << endl;
175  for ( Int_t ich=0; ich<4; ich++ ) {
176  if ( ich%2 == 0 ) outFile << endl;
177  Int_t ipage = GetPage(Form("Trigger chamber efficiency vs run for chamber %i&RPC",11+ich),filename);
178  outFile << " \\includegraphics[width=0.37\\textwidth,page=" << ipage << "]{" << filename.Data() << "}" << endl;
179  }
180  outFile << " \\end{columns}" << endl;
181  EndFrame(outFile);
182  return kTRUE;
183 }
184 
185 //_________________________________
186 void MakeSummary ( TString period, ofstream &outFile )
187 {
188  BeginFrame("Summary I",outFile);
189  outFile << "General informations" << endl;
190  outFile << "\\begin{itemize}" << endl;
191  outFile << " \\item Runs selected for MUON on ALICE logbook:" << endl;
192  outFile << " \\begin{itemize}" << endl;
193  outFile << " \\item Period: " << period.Data() << endl;
194  outFile << " \\item Run Type: PHYSICS" << endl;
195  outFile << " \\item Beam: STABLE" << endl;
196  outFile << " \\item At least [ MUON\\_TRG \\& MUON\\_TRK \\& SPD ] as Readout" << endl;
197  outFile << " \\item Quality: globaly GOOD and NOT BAD for readout Detectors" << endl;
198  outFile << " \\item Duration: at least 10 min" << endl;
199  outFile << " \\end{itemize}" << endl;
200  outFile << "\\end{itemize}" << endl;
201  outFile << endl;
202  outFile << " \\vspace{5mm}" << endl;
203  outFile << endl;
204  outFile << "\\begin{columns}[onlytextwidth]" << endl;
205  outFile << " \\column{\\textwidth}" << endl;
206  outFile << " \\centering" << endl;
207  outFile << " \\begin{tabular}{|l|lll|}" << endl;
208  outFile << " \\hline" << endl;
209  outFile << " & Total runs & CMUL & CMSL \\\\" << endl;
210  outFile << " \\hline" << endl;
211  outFile << " ALICE logbook & xx & xx & xx\\\\" << endl;
212  outFile << " Good from QA & xx & xx & xx\\\\" << endl;
213  outFile << " \\hline" << endl;
214  outFile << " \\end{tabular}" << endl;
215  outFile << "\\end{columns}" << endl;
216  EndFrame(outFile);
217 
218  BeginFrame("Summary II",outFile);
219  outFile << endl;
220  outFile << "General:" << endl;
221  MakeDefaultItem(outFile);
222  outFile << endl;
223  outFile << "MTR efficiency:" << endl;
224  MakeDefaultItem(outFile,"More than xx\\% efficiency in trigger chambers, stable");
225  outFile << endl;
226  outFile << "MCH and MUON data quality:" << endl;
227  MakeDefaultItem(outFile);
228  EndFrame(outFile);
229 
230  BeginFrame("Run summary",outFile);
231  outFile << " \\begin{columns}[onlytextwidth,T]" << endl;
232  outFile << " \\footnotesize" << endl;
233  outFile << " \\column{0.5\\textwidth}" << endl;
234  outFile << " \\centering" << endl;
235  outFile << " \\begin{tabular}{|cp{0.63\\textwidth}|}" << endl;
236  outFile << " \\hline" << endl;
237  outFile << " \\runTab[\\errorColor]{xxx}{xxx}" << endl;
238  outFile << " \\hline" << endl;
239  outFile << " \\end{tabular}" << endl;
240  outFile << endl;
241  outFile << " \\column{0.5\\textwidth}" << endl;
242  outFile << " \\begin{tabular}{|cp{0.63\\textwidth}|}" << endl;
243  outFile << " \\hline" << endl;
244  outFile << " \\colorLegend" << endl;
245  outFile << " \\hline" << endl;
246  outFile << " \\end{tabular}" << endl;
247  outFile << " \\end{columns}" << endl;
248  EndFrame(outFile);
249 }
250 
251 //_________________________________
252 void MakePreamble ( ofstream &outFile )
253 {
254  outFile << "\\documentclass[9pt,table]{beamer}" << endl;
255  outFile << "\\mode<presentation>" << endl;
256  outFile << "\\usepackage[T1]{fontenc}" << endl;
257  outFile << "\\usepackage{lmodern}" << endl;
258  outFile << "\\usepackage{amsmath}" << endl;
259  outFile << "\\usepackage{color,graphicx}" << endl;
260  outFile << "\\usepackage{colortbl}" << endl;
261  outFile << "\\usepackage{multirow}" << endl;
262  outFile << "\\usepackage{pifont}" << endl;
263  outFile << "\\usepackage{wasysym}" << endl;
264  outFile << "\\usepackage{appendixnumberbeamer}" << endl;
265  outFile << "\\usepackage[absolute,overlay]{textpos}" << endl;
266  outFile << "\\usetheme{Madrid}" << endl;
267  outFile << "\\useoutertheme{shadow}" << endl;
268 
269  outFile << "\\setbeamersize{text margin left=0.5cm, text margin right=0.5cm}" << endl;
270  outFile << endl;
271  outFile << "% Slightly change the template" << endl;
272  outFile << "\\setbeamertemplate{navigation symbols}{} %suppress navigation symbols (bottom-right of frame)" << endl;
273 
274  outFile << "\\setbeamercolor*{author in head/foot}{parent=palette tertiary}" << endl;
275  outFile << "\\setbeamercolor*{title in head/foot}{parent=palette secondary}" << endl;
276  outFile << "\\setbeamercolor*{date in head/foot}{parent=palette primary}" << endl;
277  outFile << "\\setbeamercolor*{section in head/foot}{parent=palette tertiary}" << endl;
278  outFile << "\\setbeamercolor*{subsection in head/foot}{parent=palette primary}" << endl;
279  outFile << "\\newcommand{\\changeFootline}[1]{" << endl;
280  outFile << " \\setbeamertemplate{footline}{" << endl;
281  outFile << " \\hbox{%" << endl;
282  outFile << " \\begin{beamercolorbox}[wd=.2\\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%" << endl;
283  outFile << " \\insertshortauthor%~~(\\insertshortinstitute)" << endl;
284  outFile << " \\end{beamercolorbox}%" << endl;
285  outFile << " \\begin{beamercolorbox}[wd=.6\\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%" << endl;
286  outFile << " \\insertshorttitle" << endl;
287  outFile << " \\hspace*{2em}\\insertshortdate{}" << endl;
288  outFile << " \\end{beamercolorbox}%" << endl;
289  outFile << " \\begin{beamercolorbox}[wd=.2\\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%" << endl;
290  outFile << " #1\\hspace*{2ex}" << endl;
291  outFile << " \\end{beamercolorbox}}%" << endl;
292  outFile << " }}" << endl;
293  outFile << "\\changeFootline{\\insertframenumber{} / \\inserttotalframenumber}" << endl;
294  outFile << "\\setbeamertemplate{headline}{}" << endl;
295  outFile << endl;
296  outFile << endl;
297  outFile << "\\newcommand{\\errorColor}{red!50!white}" << endl;
298  outFile << "\\newcommand{\\warningColor}{orange!50!white}" << endl;
299  outFile << "\\newcommand{\\pendingColor}{yellow!50!white}" << endl;
300  outFile << "\\newcommand{\\newColor}{blue!20!white}" << endl;
301  outFile << "\\newcommand{\\colorLegend}{" << endl;
302  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\newColor}{~~} = newly analyzed}\\\\" << endl;
303  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\pendingColor}{~~} = pending statement}\\\\" << endl;
304  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\warningColor}{~~} = possible problem}\\\\" << endl;
305  outFile << " \\multicolumn{2}{|l|}{\\colorbox{\\errorColor}{~~} = problem spotted}\\\\}" << endl;
306  outFile << "\\newcommand{\\runTab}[3][white]{\\cellcolor{#1} #2 & \\cellcolor{#1} #3\\\\}" << endl;
307  outFile << endl;
308  outFile << "\\newcommand{\\pik}{\\ensuremath{\\pi\\mathrm{/K}}}" << endl;
309  outFile << "\\newcommand{\\mum}{\\mbox{$\\mu {\\rm m}$}}" << endl;
310  outFile << "\\newcommand{\\mom}{\\mbox{GeV$\\kern-0.15em /\\kern-0.12em c$}}" << endl;
311  outFile << "\\newcommand{\\pt}{\\ensuremath{p_{\\mathrm{T}}}}" << endl;
312  outFile << "\\newcommand{\\dd}{\\text{d}}" << endl;
313  outFile << "\\newcommand{\\raa}{\\ensuremath{R_{AA}}}" << endl;
314 }
315 
316 //_________________________________
317 void BeginSlides ( TString period, TString pass, TString authors, ofstream &outFile )
318 {
319  TString authorsShort = "";
320  Bool_t previousIsLetter = kFALSE;
321  for ( Int_t ichar=0; ichar<authors.Length(); ichar++ ) {
322  TString currChar = authors[ichar];
323  currChar.ToUpper();
324  Int_t currentIsLetter = currChar.IsAlpha();
325  if ( currentIsLetter && ! previousIsLetter ) authorsShort += currChar + ".";
326  if ( currChar == "," ) authorsShort += ",";
327  previousIsLetter = currentIsLetter;
328  }
329 
330  outFile << "\\title{Muon QA: " << period.Data() << " " << pass.Data() << "}" << endl;
331  outFile << "\\author[" << authorsShort.Data() << "]{" << authors.Data() << "}" << endl;
332  outFile << "\\date{\\today}" << endl;
333 
334  outFile << "\\begin{document}" << endl;
335  outFile << "\\setlength{\\TPHorizModule}{1bp}" << endl;
336  outFile << "\\setlength{\\TPVertModule}{1bp}" << endl;
337  outFile << "\\textblockorigin{0bp}{0bp}" << endl;
338  outFile << endl;
339  outFile << "\\graphicspath{{images/}}" << endl;
340 
341  outFile << endl;
342  outFile << "\\begin{frame}" << endl;
343  outFile << " \\titlepage" << endl;
344  outFile << "\\end{frame}" << endl;
345 }
346 
347 //_________________________________
348 void EndSlides ( ofstream &outFile )
349 {
350  outFile << "\\end{document}" << endl;
351  outFile.close();
352 }
353 
354 //_________________________________
355 void StartAppendix ( ofstream &outFile )
356 {
357  outFile << endl;
358  outFile << endl;
359  outFile << "\\AtBeginSection[] % Do nothing for \\section*" << endl;
360  outFile << "{" << endl;
361  outFile << " \\begin{frame}<beamer>" << endl;
362  outFile << " \\begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}" << endl;
363  outFile << " \\usebeamerfont{title}\\insertsectionhead" << endl;
364  outFile << " \\end{beamercolorbox}" << endl;
365  outFile << " \\end{frame}" << endl;
366  outFile << "}" << endl;
367  outFile << endl;
368  outFile << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
369  outFile << "\\appendix" << endl;
370  outFile <<"\\changeFootline{A.\\insertframenumber{}}" << endl;
371  outFile << "\\section{\\huge Backup slides}" << endl;
372 }
373 
374 //_________________________________
375 void MakeSlides ( TString period, TString pass, TString triggerList, TString authors, TString trackerQA = "QA_muon_tracker.pdf", TString triggerQA = "QA_muon_trigger.pdf", TString texFilename = "muonQA.tex" )
376 {
377  if ( gSystem->AccessPathName(texFilename.Data()) == 0 ) {
378  printf("Output file %s already exists\nPlease remove it!\n", texFilename.Data());
379  return;
380  }
381 
382  TString hasGs = gSystem->GetFromPipe("which gs");
383  if ( hasGs.IsNull() ) {
384  printf("The macro selects the pdf page with gs, but the program was not found on this machine. Sorry, but slides cannot be automatically generated on this machine.\n");
385  return;
386  }
387 
388  EscapeSpecialChars(period);
389  EscapeSpecialChars(pass);
390 
391  TObjArray* trigList = triggerList.Tokenize(",");
392 
393  ofstream outFile(texFilename);
394  MakePreamble(outFile);
395  BeginSlides(period,pass,authors,outFile);
396 
397  MakeSummary(period,outFile);
398 
399  MakeSingleFigureSlide("Selections: RUN",trackerQA,"Number of events per trigger",outFile);
400  MakeSingleFigureSlide("L2A from QA",triggerQA,"Reconstruction: reconstructed triggers in QA wrt L2A from OCDB scalers",outFile);
401  MakeTriggerSlide(triggerQA,outFile);
402 
403  for ( Int_t itrig=0; itrig<trigList->GetEntries(); itrig++ ) {
404  TString currTrig = trigList->At(itrig)->GetName();
405  TString shortTrig = GetTriggerShort(currTrig);
406  MakeSingleFigureSlide(Form("Number of Tracks /%s",currTrig.Data()),trackerQA,Form("Muon tracks / event in %s events",shortTrig.Data()),outFile);
407  MakeSingleFigureSlide(Form("Sum of trigger tracks (matched + trigger-only) / # events in %s",currTrig.Data()),trackerQA,Form("Muon tracker-trigger tracks / event in %s events",shortTrig.Data()),outFile);
408  MakeSingleFigureSlide(Form("Matched tracks charge asymmetry for %s with acc. cuts",currTrig.Data()),trackerQA,Form("Charge asymmetry in %s events",shortTrig.Data()),outFile);
409  MakeSingleFigureSlide(Form("Identified beam-gas tracks (pxDCA cuts) in matched tracks for %s",currTrig.Data()),trackerQA,Form("Rel. num. of beam-gas tracks (id. by p$\\times$DCA cuts) in %s events",shortTrig.Data()),outFile);
410  }
411  MakeSingleFigureSlide("averaged number of associated clusters or of the number of chamber hit per track",trackerQA,"Average number of clusters per track and dispersion",outFile);
412  MakeSingleFigureSlide("averaged number of clusters in chamber i per track",trackerQA,"Average number of clusters per chamber",outFile);
413 
414  StartAppendix(outFile);
415  MakeSingleFigureSlide("Phys. Sel. for all selected triggers",trackerQA,"Physics selection effects",outFile);
416  MakeSingleFigureSlide("<X> of clusters - associated to a track - in chamber i",trackerQA,"Average cluster position per chamber",outFile);
417  MakeSingleFigureSlide("averaged normalized",trackerQA,"Tracking quality",outFile);
418 
419  MakeTriggerRPCslide(triggerQA,outFile);
420  MakeSingleFigureSlide("Trigger Lpt cut per run",trackerQA,"Trigger \\pt\\ cut",outFile);
421 
422  BeginFrame("Hardware issues",outFile);
423  outFile << "MUON Trigger" << endl;
424  MakeDefaultItem(outFile);
425  outFile << endl;
426  outFile << "MUON tracker" << endl;
427  MakeDefaultItem(outFile);
428  EndFrame(outFile);
429 
430  EndSlides(outFile);
431 
432  delete trigList;
433 
434  // Clean converted txt files
435  TString filenames[2] = {trackerQA, triggerQA};
436  for ( Int_t ifile=0; ifile<2; ifile++ ) {
437  TString convertedFilename = GetConvertedFilename(filenames[ifile]);
438  if ( gSystem->AccessPathName(convertedFilename.Data()) == 0 ) gSystem->Exec(Form("rm %s",convertedFilename.Data()));
439  }
440 }
void BeginSlides(TString period, TString pass, TString authors, ofstream &outFile)
Definition: MakeSlides.C:317
Bool_t MakeTriggerSlide(TString filename, ofstream &outFile)
Definition: MakeSlides.C:148
void MakeDefaultItem(ofstream &outFile, TString defaultItem="")
Definition: MakeSlides.C:122
void BeginFrame(TString title, ofstream &outFile)
Definition: MakeSlides.C:107
Bool_t MakeSingleFigureSlide(TString pattern, TString filename, TString title, ofstream &outFile)
Definition: MakeSlides.C:130
Bool_t MakeTriggerRPCslide(TString filename, ofstream &outFile)
Definition: MakeSlides.C:169
void MakePreamble(ofstream &outFile)
Definition: MakeSlides.C:252
void EscapeSpecialChars(TString &str)
Definition: MakeSlides.C:94
void EndSlides(ofstream &outFile)
Definition: MakeSlides.C:348
void EndFrame(ofstream &outFile)
Definition: MakeSlides.C:116
Int_t GetPage(TString pattern, TString filename)
Definition: MakeSlides.C:37
void MakeSummary(TString period, ofstream &outFile)
Definition: MakeSlides.C:186
void StartAppendix(ofstream &outFile)
Definition: MakeSlides.C:355
TString GetConvertedFilename(TString filename)
Definition: MakeSlides.C:17
void MakeSlides(TString period, TString pass, TString triggerList, TString authors, TString trackerQA="QA_muon_tracker.pdf", TString triggerQA="QA_muon_trigger.pdf", TString texFilename="muonQA.tex")
Definition: MakeSlides.C:375
TString GetTriggerShort(TString trigName)
Definition: MakeSlides.C:25