Jpp  17.2.1-pre0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTriggerEfficiency1D.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TH1D.h"
8 
11 #include "JDAQ/JDAQEventIO.hh"
12 #include "JAAnet/JAAnetToolkit.hh"
13 
16 #include "JSupport/JSupport.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 /**
23  * \file
24  *
25  * Example program to histogram trigger efficiency.
26  * \author mdejong
27  */
28 int main(int argc, char **argv)
29 {
30  using namespace std;
31  using namespace JPP;
32  using namespace KM3NETDAQ;
33 
34  JTriggeredFileScanner<> inputFile;
35  string outputFile;
36  bool logx;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Example program to histogram trigger efficiency.");
42 
43  zap['f'] = make_field(inputFile);
44  zap['o'] = make_field(outputFile) = "efficiency.root";
45  zap['X'] = make_field(logx);
46  zap['d'] = make_field(debug) = 1;
47 
48  zap(argc, argv);
49  }
50  catch(const exception &error) {
51  FATAL(error.what() << endl);
52  }
53 
54 
55 
56 
57  Head head;
58 
59  try {
60  head = getHeader(inputFile);
61  }
62  catch(const JException& error) {
63  FATAL(error);
64  }
65 
66 
67  // output
68 
69  TFile out(outputFile.c_str(), "recreate");
70 
71  TH1D h0("h0", NULL, 100, 0.5, 100.5);
72  TH1D h1("h1", NULL, 100, 0.5, 100.5);
73  TH1D h2("h2", NULL, 100, 0.5, 100.5);
74 
75  h2.Sumw2();
76 
77  while (inputFile.hasNext()) {
78 
79  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
80 
81  JTriggeredFileScanner<>::multi_pointer_type ps = inputFile.next();
82 
83  const Evt* event = ps;
84 
85  int n = 0;
86 
87  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
88  if (!is_noise(*hit)) {
89  ++n;
90  }
91  }
92 
93  h1.Fill((Double_t) n, 1.0);
94  }
95  STATUS(endl);
96 
97 
98  for (JMultipleFileScanner<Evt> in(inputFile); in.hasNext(); ) {
99 
100  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
101 
102  const Evt* event = in.next();
103 
104  int n = 0;
105 
106  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
107  if (!is_noise(*hit)) {
108  ++n;
109  }
110  }
111 
112  h0.Fill((Double_t) n, 1.0);
113  }
114  STATUS(endl);
115 
116 
117  for (Int_t i = 1; i <= h1.GetNbinsX(); ++i) {
118 
119  const Double_t y1 = h1.GetBinContent(i);
120  const Double_t y0 = h0.GetBinContent(i);
121 
122  if (y0 != 0.0) {
123 
124  const Double_t y3 = y1 / y0;
125  const Double_t w3 = sqrt(y1 * (y0 - y1) / (y0*y0*y0));
126 
127  h2.SetBinContent(i, y3);
128  h2.SetBinError (i, w3);
129 
130  } else {
131  ERROR("Bin " << h0.GetName() << "[" << i << "] empty." << endl);
132  }
133  }
134 
135  out.Write();
136  out.Close();
137 }
138 
139 
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Synchronously read DAQ events and Monte Carlo events (and optionally other events).
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
string outputFile
bool is_noise(const Hit &hit)
Verify hit origin.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const int n
Definition: JPolint.hh:697
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
#define ERROR(A)
Definition: JMessage.hh:66
General purpose messaging.
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
#define FATAL(A)
Definition: JMessage.hh:67
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
General purpose class for multiple pointers.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62