Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRunAnalyzer.cc
Go to the documentation of this file.
1 // c++ standard library
2 #include <iostream>
3 #include <iomanip>
4 
5 // Jpp
7 
8 #include "JAAnet/JAAnetDictionary.hh"
9 
10 #include "JDetector/JDetector.hh"
13 
14 #include "JTools/JRange.hh"
15 #include "JLang/JToken.hh"
16 #include "JGizmo/JGizmoToolkit.hh"
17 
18 #include "JDAQ/JDAQEventIO.hh"
19 
20 #include "JSupport/JSupport.hh"
21 #include "JSupport/JMeta.hh"
23 #include "JSupport/JTreeScanner.hh"
25 
26 #include "Jeep/JParser.hh"
27 
30 
31 #include "JDAQ/JDAQTimesliceIO.hh"
33 
34 #include "JLang/JObjectReader.hh"
35 
36 #include "TROOT.h"
37 #include "JROOT/JRootFileReader.hh"
39 #include "JROOT/JRootToolkit.hh"
40 #include "JROOT/JRootFileWriter.hh"
41 
42 #include "JSupport/JSupport.hh"
44 
45 //JRunAnalyzer
46 #include "JRunAnalyzer.hh"
47 #include "JRunHistograms.hh"
48 
49 #include <TSystem.h>
50 
51 using namespace KM3NETDAQ;
52 using namespace JDETECTOR;
53 using namespace JLANG;
54 using namespace JPP;
55 
56 /**
57  * \author rgruiz, adomi
58  */
59 
60 int main(int argc, char **argv) {
61 
62  typedef JToken<';'> JToken_t;
63 
64  JMultipleFileScanner<> inputFile;
65  string outputFile;
66  string detectorFile;
67  JLimit_t nTimeslices;
68  JLimit_t nSummaryslices;
69  JLimit_t nEvents;
71 
72  try {
73 
74  JParser<> zap;
75 
76  zap['f'] = make_field(inputFile , "Path to input file " );
77  zap['o'] = make_field(outputFile , "Path to output file" ) = "out.root";
78  zap['a'] = make_field(detectorFile , "path to detector file" );
79  zap['t'] = make_field(nTimeslices , "number of timeslices" ) = JLimit::max();
80  zap['s'] = make_field(nSummaryslices , "number of summaryslices") = JLimit::max();
81  zap['n'] = make_field(nEvents , "number of events" ) = JLimit::max();
82  zap['@'] = make_field(parameters, "parameter values, e.g: \"p0 = 1.0;\"");
83 
84 
85  zap(argc,argv);
86  }
87  catch(const exception &error) {
88  ERROR(error.what() << endl);
89  }
90 
92 
93  try {
94  load (detectorFile, detector);
95  }
96  catch(const JException & error) {
97  FATAL( "FATAL ERROR. Could not open detector file '" << detectorFile << "'." << endl);
98  }
99 
100  bool pmt_analysis = false;
101 
102  for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
103 
104  if(getParameter(*i) == 0 && getValue(*i) > 0) pmt_analysis = true;
105 
106  }
107 
108  if(pmt_analysis == true){
109  cout << "JRUNANALYZER RUNNING WITH ALL AVAILABLE PLOTS. It may take a while!" << endl;
110  } else {
111  cout << "JRUNANALYZER RUNNING WITH A REDUCED NUMBER OF PLOTS." << endl;
112  }
113 
115 
116  Head head;
117 
118  try{
119  head = getHeader(in);
120  }catch(const exception&){}
121 
122  JHead buffer(head);
123 
124  buffer.DAQ.livetime_s = getLivetime(inputFile.begin(), inputFile.end());
125 
126  buffer.push(& JAANET::JHead::DAQ);
127 
128  copy(buffer, head);
129 
130  cout << "START\n";
131 
132  JRunAnalyzer Analyzer (inputFile, detector, nTimeslices, nSummaryslices, nEvents, pmt_analysis);
133 
134  Analyzer.readEvents ();
135  cout << "read events!\n";
136  Analyzer.readSummaryData ();
137  cout << "read summarydata!\n";
138  Analyzer.readTimesliceData<JDAQTimeslice> ();
142  cout << "read timeslices!\n";
144 
145  cout << "before histos!\n";
146 
147  TFile out(outputFile.c_str(), "recreate");
148 
149  cout << "outputfile!\n";
150 
151  putObject(out, JMeta(argc, argv));
152  putObject(out, head);
153 
154  JDAQHeader header;
155 
156  for(const auto& i: inputFile){
157 
158 
160 
161  const JDAQEvent* event = in.next();
162 
163  if (header.getDetectorID() != event->getDetectorID() ||
164  header.getRunNumber () != event->getRunNumber ()) {
165 
166  header = event->getDAQHeader();
167 
168  putObject(out, header);
169 
170  break;
171  }
172  }
173  }
174 
175  for(const auto& i: inputFile){
176 
177  JMeta::copy(i.c_str(), out);
178  }
179 
180  Analyzer.writeToFile(out);
181 
182  out.Close();
183 
184 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
int main(int argc, char *argv[])
Definition: Main.cc:15
int getParameter(const std::string &text)
Get parameter number from text string.
ROOT TTree parameter settings of various packages.
int getDetectorID() const
Get detector identifier.
Detector data structure.
Definition: JDetector.hh:89
static void copy(const char *const file_name, TFile &out)
Copy meta data.
Definition: JMeta.hh:421
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
static counter_type max()
Get maximum counter value.
Definition: JLimit.hh:117
double livetime_s
Live time [s].
Definition: JHead.hh:1040
string outputFile
Class dedicated to the analysis of KM3NeT runs.
Definition: JRunAnalyzer.hh:28
int getRunNumber() const
Get run number.
Data structure for detector geometry and calibration.
Timeslice data structure for L1 data.
void writeToFile(TFile &f)
void readTimesliceData()
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
void push(T JHead::*pd)
Push given data member to Head.
Definition: JHead.hh:1306
virtual bool hasNext() override
Check availability of next element.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Timeslice data structure for L2 data.
ROOT I/O of application specific meta data.
#define ERROR(A)
Definition: JMessage.hh:66
Support methods.
Data time slice.
Timeslice data structure for SN data.
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
void readSummaryData()
Monte Carlo run header.
Definition: JHead.hh:1167
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
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxiliary class to define a range between two values.
double getLivetime(const std::string &file_name)
Get data taking live time.
Utility class to parse command line options.
const JDAQHeader & getDAQHeader() const
Get DAQ header.
Definition: JDAQHeader.hh:49
Wrapper class around string.
Definition: JToken.hh:23
virtual const pointer_type & next() override
Get next element.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
do set_variable DETECTOR_TXT $WORKDIR detector
KM3NeT DAQ constants, bit handling, etc.
JAANET::DAQ DAQ
Definition: JHead.hh:1518
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
void readEvents()
Timeslice data structure for L0 data.