Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDomAnalyser.cc
Go to the documentation of this file.
1 // c++ standard library
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JSupport/JSupport.hh"
7 #include "JSupport/JMeta.hh"
10 
13 
14 #include "JROOT/JManager.hh"
15 
16 #include "Jeep/JParser.hh"
19 #include "JDAQ/JDAQTimesliceIO.hh"
20 
21 #include "TH1D.h"
22 #include "TMath.h"
23 
24 using namespace KM3NETDAQ;
25 using namespace JLANG;
26 using namespace JPP;
27 using namespace std;
28 
29 /*
30  * Rebins a histogram with constant bin width in a linear scale, so that the bins will have constant width in log10 scale.
31  *
32  * \param h The histogram.
33  */
34 inline void BinLogX (TH1* h){
35 
36  TAxis *axis = h->GetXaxis();
37  int bins = axis->GetNbins();
38  Axis_t min = axis->GetXmin();
39  Axis_t max = axis->GetXmax();
40  Axis_t width = (max - min) / bins;
41  Axis_t *new_bins = new Axis_t[bins + 1];
42 
43  for (int i = 0; i <= bins; i++) {
44  new_bins[i] = TMath::Power(10, min + i * width);
45  }
46 
47  axis->Set(bins, new_bins);
48  delete new_bins;
49 }
50 
51 
52 int main(int argc, char **argv) {
53 
55  JLimit_t& nSlices = inputFile.getLimit();
56  JROOTClassSelector selector;
57  string outputFile;
58  string detectorFile;
59 
60  try {
61 
62  JParser<> zap;
63 
64  zap['f'] = make_field(inputFile , "Path to input file ");
65  zap['o'] = make_field(outputFile , "Path to output file") = "out.root";
66  zap['C'] = make_field(selector , "timeslice selector, e.g. JDAQTimesliceL1.") = getROOTClassSelection<JDAQTimesliceTypes_t>();
67  zap['s'] = make_field(nSlices , "number of slices" ) = JLimit::max();
68 
69  zap(argc,argv);
70  }
71  catch(const exception &error) {
72  ERROR(error.what() << endl);
73  }
74 
75  const double factor = 1./(1.0e-6 * getFrameTime()); // [kHz]
76 
77  TH1D* h1 = new TH1D("rate_%", NULL, 100, -2, 2);
78  TH1D* h2 = new TH1D("time_%", NULL, 1, -0.5, 0.5);
79 
81  JTreeScannerInterface<JDAQTimeslice>* s = map[selector];
82  s->configure(inputFile);
83 
84  if (s->hasNext()){
85  JFrameIndexRange range (s->begin()->getFrameIndex() , s->rbegin()->getFrameIndex());
86  h2->SetBins(range.second - range.first + 1, range.first - 0.5, range.second + 0.5);
87  }
88 
89  BinLogX(h1);
90 
93 
95 
96  counter_type counter = 0;
97 
98  for ( ; scanner.hasNext() && counter != inputFile.getLimit(); ++counter) {
99 
100  JDAQTimeslice* slice = scanner.next();
101 
102  for(JDAQTimeslice::const_iterator frame = slice->begin() ; frame != slice->end() ; ++frame) {
103 
104  vector <int> pmt_hit_count (NUMBER_OF_PMTS , 0) ;
105 
106  for (JDAQSuperFrame::const_iterator hit = frame->begin() ; hit != frame->end() ; ++hit){
107  pmt_hit_count[hit->getPMT()]++;
108  }
109 
110  for (int pmt = 0 ; pmt != NUMBER_OF_PMTS ; ++pmt) {
111  r[JDAQPMTIdentifier(frame->getModuleID(),pmt)]->Fill(pmt_hit_count[pmt]*factor);
112  t[JDAQPMTIdentifier(frame->getModuleID(),pmt)]->Fill(slice->getFrameIndex(), pmt_hit_count[pmt]*factor);
113  }
114  }
115  }
116 
117  for (typename JManager < JDAQPMTIdentifier , TH1D >::const_iterator i = r.begin() ; i != r.end() ; ++i){
118 
119  for(int j=1 ; j < i -> second -> GetNbinsX() ; ++j){
120 
121  double width = i->second->GetXaxis()->GetBinWidth(j);
122  i -> second->SetBinContent(j ,i->second->GetBinContent(j)/width);
123  i -> second->SetBinError (j ,i->second->GetBinError (j)/width);
124  }
125  }
126 
127  TFile out(outputFile.c_str(), "recreate");
128  putObject(&out, JMeta(argc, argv));
129  r.Write(out);
130  t.Write(out);
131 }
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
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
void BinLogX(T *h)
Auxiliary class to select ROOT class based on class name.
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
static counter_type max()
Get maximum counter value.
Definition: JLimit.hh:117
Long64_t counter_type
Type definition for counter.
data_type r[M+1]
Definition: JPolint.hh:742
Dynamic ROOT object management.
Auxiliary class for a type holder.
Definition: JType.hh:19
Auxiliary class for multiplexing object iterators.
string outputFile
Auxiliary interface for direct access of elements in ROOT TChain.
int getFrameIndex() const
Get frame index.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Hit data structure.
Definition: JDAQHit.hh:34
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
ROOT I/O of application specific meta data.
#define ERROR(A)
Definition: JMessage.hh:66
Support methods.
Data time slice.
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
virtual const pointer_type & next() override
Get next element.
virtual bool hasNext() override
Check availability of next element.
Auxiliary class to select JTreeScanner based on ROOT class name.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
int j
Definition: JPolint.hh:666
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.