Jpp  18.6.0-rc.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 
16 #include "JSupport/JSupport.hh"
17 #include "JSupport/JMeta.hh"
19 #include "JSupport/JTreeScanner.hh"
22 
23 #include "JReconstruction/JEvt.hh"
25 
26 #include "Jeep/JProperties.hh"
27 #include "Jeep/JParser.hh"
28 
31 
32 #include "JDAQ/JDAQEventIO.hh"
33 #include "JDAQ/JDAQTimesliceIO.hh"
35 
36 #include "JLang/JObjectReader.hh"
37 
38 #include "TROOT.h"
39 #include "JROOT/JRootFileReader.hh"
41 #include "JROOT/JRootToolkit.hh"
42 #include "JROOT/JRootFileWriter.hh"
43 #include "JROOT/JTreeParameters.hh"
44 
45 #include "JSupport/JSupport.hh"
47 
48 #include "JRunAnalyzer/JRunInfo.hh"
49 
50 //JRunAnalyzer
51 #include "JRunAnalyzer.hh"
52 #include "JRunHistograms.hh"
53 
54 #include <TSystem.h>
55 #include "TTree.h"
56 
57 /**
58  * \author rgruiz, adomi
59  */
60 
61 int main(int argc, char **argv) {
62 
63  using namespace KM3NETDAQ;
64  using namespace JPP;
65 
66  JSingleFileScanner<> inputFile;
68  string detectorFile;
69  JLimit_t numberOfTimeslices = JLimit::max();
70  JLimit_t numberOfSummaryslices = JLimit::max();
71  JLimit_t numberOfEvents = JLimit::max();
72  int analysis_level;
73 
74 
75  try {
76 
77  JProperties properties;
78 
79  properties.insert(gmake_property(numberOfTimeslices));
80  properties.insert(gmake_property(numberOfSummaryslices));
81  properties.insert(gmake_property(numberOfEvents));
82 
83  JParser<> zap;
84 
85  zap['f'] = make_field(inputFile , "input file " );
86  zap['o'] = make_field(outputFile , "output file" ) = "out.root";
87  zap['a'] = make_field(detectorFile , "detector file" );
88  zap['@'] = make_field(properties) = JPARSER::initialised();
89  zap['L'] = make_field(analysis_level , "analysis level") = 0, 1, 2;
90 
91  zap(argc,argv);
92  }
93  catch(const exception &error) {
94  ERROR(error.what() << endl);
95  }
96 
98 
99  try {
100  load (detectorFile, detector);
101  }
102  catch(const JException & error) {
103  FATAL( "FATAL ERROR. Could not open detector file '" << detectorFile << "'." << endl);
104  }
105 
106  if(analysis_level == 1){
107  cout << "ANALYSIS OF ALL AVAILABLE PMTs INFORMATION. It may take a while!" << endl;
108  } else if (analysis_level == 2){
109  cout << "BASIC ANALYSIS AT TRIGGER AND RECONSTRUCTION LEVEL." << 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);
125 
126  buffer.push(& JAANET::JHead::DAQ);
127 
128  copy(buffer, head);
129 
130  cout << "START\n";
131 
132  outputFile.open();
133 
134  JRootFile* p = dynamic_cast<JRootFile*>(outputFile.get());
135 
136  if (p == NULL) {
137  FATAL("WRONG FILE TYPE");
138  }
139 
140  TFile* out = p->getFile();
141 
142  cout << out->GetName() << endl;
143 
144  outputFile.put(JMeta(argc, argv));
145 
146  JDAQHeader header;
147 
148  for(JTreeScanner<JDAQEvent> in(inputFile); in.hasNext();){
149 
150  const JDAQEvent* event = in.next();
151 
152  if (header.getDetectorID() != event->getDetectorID() ||
153  header.getRunNumber () != event->getRunNumber ()) {
154 
155  header = event->getDAQHeader();
156 
157  putObject(out, header);
158 
159  break;
160  }
161  }
162 
163  const run_info runinfo(header.getDetectorID(),
164  header.getRunNumber(),
165  buffer.DAQ.livetime_s,
166  buffer.livetime.numberOfSeconds);
167 
168  outputFile.put(runinfo);
169 
170  JRunAnalyzer Analyzer (inputFile, detector, out, numberOfTimeslices, numberOfSummaryslices, numberOfEvents, analysis_level);
171 
172  cout << "read events\n";
173  Analyzer.readEvents ();
174  cout << "read summarydata\n";
175  Analyzer.readSummaryData ();
176  cout << "read timeslices\n";
177  Analyzer.readTimesliceData<JDAQTimeslice> ();
182 
183  if(analysis_level == 2){
184  cout << "read reconstructed events\n";
185  Analyzer.readRecoEvents ();
186  }
187 
188  Analyzer.writeToFile(out, analysis_level);
189 
190  outputFile.close();
191 }
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:1711
General exception.
Definition: JException.hh:24
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Detector data structure.
Definition: JDetector.hh:89
Recording of objects on file according a format that follows from the file name extension.
void readRecoEvents()
Utility class to parse parameter values.
Definition: JProperties.hh:497
void writeToFile(TFile *f, int analysis_level)
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:84
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.
Utility class to parse parameter values.
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:2158
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 The output file must have the wildcard in the e g root fi 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.
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:1606
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:1603