Jpp  18.3.1
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 "JSupport/JSupport.hh"
19 #include "JSupport/JMeta.hh"
21 #include "JSupport/JTreeScanner.hh"
24 
25 #include "JReconstruction/JEvt.hh"
27 
28 #include "Jeep/JParser.hh"
29 
32 
33 #include "JDAQ/JDAQEventIO.hh"
34 #include "JDAQ/JDAQTimesliceIO.hh"
36 
37 #include "JLang/JObjectReader.hh"
38 
39 #include "TROOT.h"
40 #include "JROOT/JRootFileReader.hh"
42 #include "JROOT/JRootToolkit.hh"
43 #include "JROOT/JRootFileWriter.hh"
44 #include "JROOT/JTreeParameters.hh"
45 
46 #include "JSupport/JSupport.hh"
48 
49 #include "JRunAnalyzer/JRunInfo.hh"
50 
51 //JRunAnalyzer
52 #include "JRunAnalyzer.hh"
53 #include "JRunHistograms.hh"
54 
55 #include <TSystem.h>
56 #include "TTree.h"
57 
58 /**
59  * \author rgruiz, adomi
60  */
61 
62 int main(int argc, char **argv) {
63 
64  using namespace KM3NETDAQ;
65  using namespace JPP;
66 
67  typedef JToken<';'> JToken_t;
68 
69  JSingleFileScanner<> inputFile;
71  string detectorFile;
72  JLimit_t nTimeslices;
73  JLimit_t nSummaryslices;
74  JLimit_t nEvents;
76 
77  try {
78 
79  JParser<> zap;
80  zap['f'] = make_field(inputFile , "input file " );
81  zap['o'] = make_field(outputFile , "output file" ) = "out.root";
82  zap['a'] = make_field(detectorFile , "detector file" );
83  zap['t'] = make_field(nTimeslices , "number of timeslices" ) = JLimit::max();
84  zap['s'] = make_field(nSummaryslices , "number of summaryslices") = JLimit::max();
85  zap['n'] = make_field(nEvents , "number of events" ) = JLimit::max();
86  zap['@'] = make_field(parameters, "parameter values, e.g: \"p0 = 1.0;\"");
87 
88  zap(argc,argv);
89  }
90  catch(const exception &error) {
91  ERROR(error.what() << endl);
92  }
93 
95 
96  try {
97  load (detectorFile, detector);
98  }
99  catch(const JException & error) {
100  FATAL( "FATAL ERROR. Could not open detector file '" << detectorFile << "'." << endl);
101  }
102 
103  int analysis_level = 0;
104 
105  for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
106 
107  if(getParameter(*i) == 0 && getValue(*i) == 1) analysis_level = 1;
108  if(getParameter(*i) == 0 && getValue(*i) == 2) analysis_level = 2;
109 
110  }
111 
112  if(analysis_level == 1){
113  cout << "ANALYSIS OF ALL AVAILABLE PMTs INFORMATION. It may take a while!" << endl;
114  } else if (analysis_level == 2){
115  cout << "BASIC ANALYSIS AT TRIGGER AND RECONSTRUCTION LEVEL." << endl;
116  } else {
117  cout << "JRUNANALYZER RUNNING WITH A REDUCED NUMBER OF PLOTS." << endl;
118  }
119 
121 
122  Head head;
123 
124  try{
125  head = getHeader(in);
126  }catch(const exception&){}
127 
128  JHead buffer(head);
129 
130  buffer.DAQ.livetime_s = getLivetime(inputFile);
131 
132  buffer.push(& JAANET::JHead::DAQ);
133 
134  copy(buffer, head);
135 
136  cout << "START\n";
137 
138  outputFile.open();
139 
140  JRootFile* p = dynamic_cast<JRootFile*>(outputFile.get());
141 
142  if (p == NULL) {
143  FATAL("WRONG FILE TYPE");
144  }
145 
146  TFile* out = p->getFile();
147 
148  cout << out->GetName() << endl;
149 
150  outputFile.put(JMeta(argc, argv));
151 
152  JDAQHeader header;
153 
154  for(JTreeScanner<JDAQEvent> in(inputFile); in.hasNext();){
155 
156  const JDAQEvent* event = in.next();
157 
158  if (header.getDetectorID() != event->getDetectorID() ||
159  header.getRunNumber () != event->getRunNumber ()) {
160 
161  header = event->getDAQHeader();
162 
163  putObject(out, header);
164 
165  break;
166  }
167  }
168 
169  const run_info runinfo(header.getDetectorID(),
170  header.getRunNumber(),
171  buffer.DAQ.livetime_s,
172  buffer.livetime.numberOfSeconds);
173 
174  outputFile.put(runinfo);
175 
176  JRunAnalyzer Analyzer (inputFile, detector, out, nTimeslices, nSummaryslices, nEvents, analysis_level);
177 
178  cout << "read events\n";
179  Analyzer.readEvents ();
180  cout << "read summarydata\n";
181  Analyzer.readSummaryData ();
182  cout << "read timeslices\n";
183  Analyzer.readTimesliceData<JDAQTimeslice> ();
188 
189  if(analysis_level == 2){
190  cout << "read reconstructed events\n";
191  Analyzer.readRecoEvents ();
192  }
193 
194  Analyzer.writeToFile(out, analysis_level);
195 
196  outputFile.close();
197 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
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.
Detector data structure.
Definition: JDetector.hh:89
Recording of objects on file according a format that follows from the file name extension.
void readRecoEvents()
void writeToFile(TFile *f, int analysis_level)
*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
virtual const pointer_type & next() override
Get next element.
static counter_type max()
Get maximum counter value.
Definition: JLimit.hh:128
double livetime_s
Live time [s].
Definition: JHead.hh:1053
string outputFile
Class dedicated to the analysis of KM3NeT runs.
Definition: JRunAnalyzer.hh:32
Template definition for direct access of elements in ROOT TChain.
Data structure for detector geometry and calibration.
Timeslice data structure for L1 data.
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
Detector file.
Definition: JHead.hh:226
Monte Carlo run header.
Definition: JHead.hh:1234
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
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()
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
void push(T JHead::*pd)
Push given data member to Head.
Definition: JHead.hh:1374
#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.
virtual bool hasNext() override
Check availability of next element.
Auxiliary class to define a range between two values.
double getLivetime(const std::string &file_name)
Get data taking live time.
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:48
Utility class to parse command line options.
Wrapper class around string.
Definition: JToken.hh:23
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
do set_variable DETECTOR_TXT $WORKDIR detector
KM3NeT DAQ constants, bit handling, etc.
void readEvents()
JAANET::DAQ DAQ
Definition: JHead.hh:1604
double numberOfSeconds
Live time [s].
Definition: JHead.hh:896
Timeslice data structure for L0 data.
ROOT file.
Definition: JRootFile.hh:45
JAANET::livetime livetime
Definition: JHead.hh:1601