Logo ROOT   6.14/05
Reference Guide
mp104_processH1.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// \notebook -nodraw
4 /// Illustrate the usage of the multiproc to process the H1 analysis
5 /// example.
6 ///
7 /// \macro_code
8 ///
9 /// \author Gerardo Ganis
10 
11 #include "TString.h"
12 #include "TROOT.h"
13 #include "TTree.h"
14 #include "TH1F.h"
15 #include "TH2F.h"
16 #include "TEntryList.h"
17 #include "TTreeReader.h"
18 #include "TTreeReaderArray.h"
19 #include "TTreeReaderValue.h"
20 #include "TSystem.h"
21 #include "TMath.h"
22 #include "TCanvas.h"
23 #include "TStyle.h"
24 #include "TF1.h"
25 #include "TLine.h"
26 #include "TPaveStats.h"
27 #include "TStopwatch.h"
29 
30 static std::string tutname = "mp104_processH1: ";
31 static std::string logfile = "mp104_processH1.log";
32 static RedirectHandle_t gRH;
33 
34 const char *fh1[] = {"http://root.cern.ch/files/h1/dstarmb.root", "http://root.cern.ch/files/h1/dstarp1a.root",
35  "http://root.cern.ch/files/h1/dstarp1b.root", "http://root.cern.ch/files/h1/dstarp2.root"};
36 
37 int mp104_processH1()
38 {
39 
40  // MacOSX may generate connection to WindowServer errors
41  gROOT->SetBatch(kTRUE);
42 
43  TStopwatch stp;
44 
45  // Prepare dataset: vector of files
46  std::vector<std::string> files;
47  for (int i = 0; i < 4; i++) {
48  files.push_back(fh1[i]);
49  }
50 
51 // Check and fit lambdas
52 #include "mp_H1_lambdas.C"
53 
54  ROOT::TTreeProcessorMP pool(3);
55 
56  std::cout << tutname << "processing the H1 dataset with a lambda \n";
57 
58  auto hListFun = pool.Process(files, doH1, "h42");
59 
60  // Check the output
61  if (checkH1(hListFun) < 0)
62  return -1;
63 
64  // Do the fit
65  if (doFit(hListFun, logfile.c_str()) < 0)
66  return -1;
67 
68  stp.Print();
69  stp.Start();
70 
71  // Run the analysis with a selector
72 
73  TString selectorPath = gROOT->GetTutorialDir();
74  selectorPath += "/tree/h1analysisTreeReader.C+";
75  std::cout << tutname << "processing the H1 dataset with selector '" << selectorPath << "'\n";
76  auto sel = TSelector::GetSelector(selectorPath);
77 
78  // In a second run we use sel
79  gSystem->RedirectOutput(logfile.c_str(), "w", &gRH);
80  auto hListSel = pool.Process(files, *sel, "h42");
81  gSystem->RedirectOutput(0, 0, &gRH);
82 
83  // Check the output
84  if (checkH1(hListSel) < 0)
85  return -1;
86 
87  // Do the fit
88  if (doFit(hListSel, logfile.c_str()) < 0)
89  return -1;
90 
91  stp.Print();
92  stp.Start();
93 
94  return 0;
95 }
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
Definition: TStopwatch.cxx:219
#define gROOT
Definition: TROOT.h:410
Basic string class.
Definition: TString.h:131
<a href="http://nbviewer.jupyter.org/url/root.cern.ch/doc/master/notebooks/mp_H1_lambdas.C.nbconvert.ipynb" target="_blank"><img src= notebook.gif alt="View in nbviewer" style="height:1em" ></a> <a href="https://cern.ch/swanserver/cgi-bin/go?projurl=https://root.cern.ch/doc/master/notebooks/mp_H1_lambdas.C.nbconvert.ipynb" target="_blank"><img src="http://swanserver.web.cern.ch/swanserver/images/badge_swan_white_150.png" alt="Open in SWAN" style="height:1em" ></a> Lambdas used to check and fit the result of the H1 analysis.
This class provides an interface to process a TTree dataset in parallel with multi-process technology...
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
static TSelector * GetSelector(const char *filename)
The code in filename is loaded (interpreted or compiled, see below), filename must contain a valid cl...
Definition: TSelector.cxx:142
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
Definition: TSystem.cxx:1688
const Bool_t kTRUE
Definition: RtypesCore.h:87
Stopwatch class.
Definition: TStopwatch.h:28