Analysis.hh
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <thread>
7 
8 #include "boca/generic/Types.hh"
9 #include "boca/io/Io.hh"
11 #include "boca/analysis/Base.hh"
12 #include "boca/analysis/Data.hh"
13 #include "boca/event/Event.hh"
14 
15 namespace boca
16 {
17 
28 template<typename Tagger_>
29 class Analysis : public analysis::Base
30 {
31 
32 protected:
33 
34  template<typename Class_>
35  bool TaggerIs() const
36  {
37  return typeid(Tagger_).hash_code() == typeid(Class_).hash_code();
38  }
39 
40 private:
41 
42  void TagLoop(Phase phase) override
43  {
44  FileWriter file_writer(Tagger().ExportFileName(phase));
45  ClearFiles();
46  SetFiles(phase);
47  for (auto &file : this->Files(phase.Tag())) FileLoop({phase, file, file_writer, tagger_});
48  }
49 
54  void FileLoop(boca::analysis::Files<Tagger_> files)
55  {
56  auto single = true;
57  if (single) return Thread({files, TrainNumberMax(), 1, 1});
58  auto threads = std::vector<std::thread> {};
59  // int cores = std::thread::hardware_concurrency();
60  auto cores = 2;
61  for (auto core : IntegerRange(cores)) threads.emplace_back([&] {
62  Thread({files, TrainNumberMax(), cores, core + 1});
63  });
64  for (auto &thread : threads) thread.join();
65  }
66 
67  void Thread(analysis::Data<Tagger_> data)
68  {
69  data.ReadEvents(PreCuts(), [&](Stage stage) {
70  return EventNumberMax(stage);
71  }, [&](Event const & event) {
72  return PassPreCut(event);
73  });
74  }
75 
76  void RunSignificance() override
77  {
78  if (Exists(Tagger().ExportFileName())) return;
80  auto plotting = Plotting<Tagger_> {Tagger()};
81  plotting.OptimalCuts();
82  }
83 
84  void RunEfficiency() override
85  {
86  if (Exists(Tagger().ExportFileName())) return;
88  auto plotting = Plotting<Tagger_> {Tagger()};
89  plotting.TaggingEfficiency();
90  }
91 
92  void RunPlots() override
93  {
94  if (Exists(Tagger().ExportFolderName())) return;
95  auto plotting = Plotting<Tagger_> {Tagger()};
97  plotting.RunPlots(Stage::trainer);
99  plotting.RunPlots(Stage::reader);
100  // if (Exists(Tagger().ExportFileName())) std::remove(Tagger().ExportFileName().c_str());
101  }
102 
103  void RunPlotHist() override
104  {
105  // if (Exists(Tagger().ExportFolderName())) return;
106  auto plotting = Plotting<Tagger_> {Tagger()};
108  plotting.RunPlotHist();
109  }
110 
111  void RunCut() override
112  {
114  RunTrainer();
117  auto plotting = Plotting<Tagger_> {Tagger()};
118  plotting.OptimalCuts();
119  }
120 
121  Tagger_ &Tagger() override
122  {
123  return tagger_;
124  }
125 
126  Tagger_ const &Tagger() const override
127  {
128  return tagger_;
129  }
130 
131  Tagger_ tagger_;
132 
133 };
134 
135 }
Training stage.
decltype(auto) IntegerRange(Integer last)
Definition: Types.hh:18
Stage
The stage of the multivariant tagging process.
Definition: Stage.hh:15
std::vector< boca::FileInfo > Files(Tag tag)
Definition: Base.cpp:71
Base for all analyses.
Definition: Base.hh:58
virtual void SetFiles(Phase const &phase)=0
void ClearFiles()
Definition: Base.cpp:172
bool TaggerIs() const
Definition: Analysis.hh:35
Definition: Plotting.hh:11
virtual bool PassPreCut(Event const &) const
Definition: Base.cpp:253
bool Exists(std::string const &name)
Definition: Io.cpp:10
boca::PreCuts PreCuts() const
Definition: Base.cpp:130
Definition: FileWriter.hh:10
Base class for the event Topology.
Definition: Event.hh:53
provides main analysis loops and logic.
Definition: Analysis.hh:29
virtual long EventNumberMax(Stage stage) const
Definition: Base.cpp:244
Definition: Files.hh:21
Boosted Collider Analysis.
Definition: Analysis.hh:15
void PrepareFiles(Stage stage)
Definition: Base.cpp:77
Definition: Data.hh:17
Tagger base class using Branch template
Definition: Tagger.hh:23
void RunTrainer()
Definition: Base.cpp:193
Reading stage.
virtual long TrainNumberMax() const
Definition: Base.cpp:85
The phases of the multivariant tagging process.
Definition: Phase.hh:16
boca::Tag Tag() const
The Tag of the multivariant tagging process.
Definition: Phase.cpp:18
void RunTagger(Stage stage)
Definition: Base.cpp:186
void ReadEvents(PreCuts const &pre_cuts, std::function< long(Stage)> const &event_number_max, std::function< bool(boca::Event const &)> const &pass_pre_cut)
Definition: Data.hh:30