Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 std::vector<std::string> files {"http://root.cern.ch/files/h1/dstarmb.root",
35  "http://root.cern.ch/files/h1/dstarp1a.root",
36  "http://root.cern.ch/files/h1/dstarp1b.root",
37  "http://root.cern.ch/files/h1/dstarp2.root"};
38 
39 int mp104_processH1()
40 {
41 
42  // MacOSX may generate connection to WindowServer errors
43  gROOT->SetBatch(kTRUE);
44 
45  TStopwatch stp;
46 
47  // Check and fit lambdas
48  #include "mp_H1_lambdas.C"
49 
50  ROOT::TTreeProcessorMP pool(3);
51 
52  std::cout << tutname << "processing the H1 dataset with a lambda \n";
53 
54  auto hListFun = pool.Process(files, doH1, "h42");
55 
56  // Check the output
57  if (checkH1(hListFun) < 0)
58  return -1;
59 
60  // Do the fit
61  if (doFit(hListFun, logfile.c_str()) < 0)
62  return -1;
63 
64  stp.Print();
65  stp.Start();
66 
67  // Run the analysis with a selector
68 
69  TString selectorPath = gROOT->GetTutorialDir();
70  selectorPath += "/tree/h1analysisTreeReader.C+";
71  std::cout << tutname << "processing the H1 dataset with selector '" << selectorPath << "'\n";
72  auto sel = TSelector::GetSelector(selectorPath);
73 
74  // In a second run we use sel
75  gSystem->RedirectOutput(logfile.c_str(), "w", &gRH);
76  auto hListSel = pool.Process(files, *sel, "h42");
77  gSystem->RedirectOutput(0, 0, &gRH);
78 
79  // Check the output
80  if (checkH1(hListSel) < 0)
81  return -1;
82 
83  // Do the fit
84  if (doFit(hListSel, logfile.c_str()) < 0)
85  return -1;
86 
87  stp.Print();
88  stp.Start();
89 
90  return 0;
91 }