Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Namespaces | Functions
JMonitorL1dt.cc File Reference

Auxiliary program to plot L1 time difference correlations between DOMs. More...

#include "km3net-dataformat/online/JDAQ.hh"
#include "km3net-dataformat/online/JDAQTimeslice.hh"
#include "km3net-dataformat/online/JDAQSummaryslice.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDAQ/JDAQEvaluator.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JTrigger/JHitL1.hh"
#include "JTrigger/JBuildL2.hh"
#include "JTrigger/JPMTSelector.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JSupport.hh"
#include "JLang/JObjectMultiplexer.hh"
#include "JROOT/JROOTClassSelector.hh"
#include "Jeep/JParser.hh"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TMath.h"
#include <string>
#include <iostream>

Go to the source code of this file.

Classes

class  MONITORL1DT::JElement
 Data structure for hit time and DOM identifier. More...
 
struct  MONITORL1DT::JHistogram
 Auxiliary data structure for histogram management. More...
 

Namespaces

 MONITORL1DT
 

Functions

bool MONITORL1DT::operator< (const JElement &first, const JElement &second)
 Sort JElement in time. More...
 
int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to plot L1 time difference correlations between DOMs.

Author
kmelis, lnauta

Definition in file JMonitorL1dt.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 105 of file JMonitorL1dt.cc.

106 {
107  using namespace std;
108  using namespace MONITORL1DT;
109  using namespace JPP;
110 
112  string outputFile;
113  string detectorFile;
114  Double_t Timewindow_ns;
115  double TmaxL1_ns;
116  JROOTClassSelector selector;
117  unsigned int multiplicity;
118  double livetime_s;
119  int debug;
120 
121  try {
122 
123  JParser<> zap("Program to create L1 hit time difference histograms from raw data.");
124 
125  zap['f'] = make_field(inputFile, "input file");
126  zap['o'] = make_field(outputFile, "output file") = "monitor.root";
127  zap['a'] = make_field(detectorFile, "detector file");
128  zap['t'] = make_field(TmaxL1_ns, "max time between L1 hits [ns]") = 1000.0;
129  zap['T'] = make_field(Timewindow_ns, "time window around t=0 [ns]") = 2400.0;
130  zap['C'] = make_field(selector, "datastream selector") = getROOTClassSelection<JDAQTimesliceTypes_t>();
131  zap['m'] = make_field(multiplicity, "minimal multiplicity of the L1 hits") = 2;
132  zap['L'] = make_field(livetime_s, "livetime of the data, set to positive value") = -1.0; // set to positive value if you want to set the livetime manually (i.e. MC)
133  zap['d'] = make_field(debug) = 1;
134 
135  if (zap.read(argc, argv) != 0)
136  return 1;
137  }
138  catch(const exception &error) {
139  FATAL(error.what() << endl);
140  }
141 
142  cout.tie(&cerr);
143 
145 
146  try {
147  load(detectorFile, detector);
148  }
149  catch(const JException& error) {
150  FATAL(error);
151  }
152 
153  if (detector.empty()) {
154  FATAL("Empty detector." << endl);
155  }
156 
157  const JModuleRouter router(detector);
158 
159  typedef vector<JHitL1> JFrameL1_t;
160 
161  const double ctMin = -1; // full angle over the DOM
162  const JBuildL2<JHitL1> buildL2(JL2Parameters(multiplicity, TmaxL1_ns, ctMin));
163 
164  vector<JHistogram> zmap(detector.size());
165 
166  const int nx = detector.size();
167  const double xmin = -0.5;
168  const double xmax = nx - 0.5;
169 
170  const double ymin = -floor(Timewindow_ns) + 0.5;
171  const double ymax = +floor(Timewindow_ns) + 0.5; // changed - to + to get an even number for Nbins, rebin needs numbers that have divisors.
172  const int ny = (int) ((ymax - ymin) / 1.0);
173 
174  NOTICE("Running JMonitorL1dt: Monitoring L1 time differences MonitorL1dt creating histograms.");
175  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
176 
177  const JModuleAddress& address = router.getAddress(module->getID());
178 
179  STATUS("Booking histograms for module " << module->getID() << endl);
180 
181  const JString title(module->getID());
182  JString titleString1D;
183  JString titleString2D;
184  titleString1D = title + ".1L";
185  titleString2D = title + ".2S";
186 
187  zmap[address.first] = JHistogram(new TH2D((titleString2D).c_str(), NULL, nx, xmin, xmax, ny, ymin, ymax),
188  new TH1D((titleString1D).c_str(), NULL, nx, xmin, xmax));
189 
190  for (JDetector::iterator mod = detector.begin(); mod != detector.end(); ++mod) {
191  zmap[address.first].h2s->GetXaxis()->SetBinLabel(distance(detector.begin(), mod)+1, Form("%i", mod->getID()));
192  zmap[address.first].h1l->GetXaxis()->SetBinLabel(distance(detector.begin(), mod)+1, Form("%i", mod->getID()));
193  }
194  }
195 
196 
197  JTreeScanner<JDAQSummaryslice, JDAQEvaluator> summaryFile(inputFile);
198 
200 
201  int counter = 0;
202 
203  for ( ; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
204 
205  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
206 
207  const JDAQTimeslice* timeslice = in.next();
208 
209  JFrameL1_t frameL1;
211  vector<bool> DOM_OK(detector.size(), true);
212 
213  for (JDAQTimeslice::const_iterator super_frame = timeslice->begin(); super_frame != timeslice->end(); ++super_frame) {
214  if (router.hasModule(super_frame->getModuleID()) && !super_frame->empty()) {
215 
216  const JModuleAddress& address = router.getAddress(super_frame->getModuleID());
217  const JModule& module = detector.getModule(address);
218 
219  frameL1.clear();
220 
221  buildL2(*super_frame, module, back_inserter(frameL1));
222 
223  for (JFrameL1_t::iterator L1hit = frameL1.begin(); L1hit != frameL1.end(); ++L1hit) {
224  buffer.push_back(JElement(address.first, L1hit->begin()->getT()));
225  }
226  }
227  }
228 
229  for (vector<JHistogram>::iterator h1 = zmap.begin(); h1 != zmap.end(); ++h1) {
230  if (!DOM_OK[distance(zmap.begin(), h1)]) {
231  continue;
232  }
233  for (unsigned int i = 0; i < detector.size(); ++i) {
234  if (DOM_OK[i]) { h1->h1l->Fill(i, getFrameTime() * 1e-9); } // fill the th1 with the frametime (how long did it measure) in seconds, all weight will give total measured time
235  }
236  }
237 
238  // fill histograms with correlations
239  sort(buffer.begin(), buffer.end());
240 
241  for (vector<JElement>::const_iterator p = buffer.begin(); p != buffer.end(); ) {
243 
244  while (++q != buffer.end() && q->t - p->t <= Timewindow_ns ) {
245  // if (p->id == q->id) { continue; }
246 
247  zmap[p->id].h2s->Fill(q->id, q->t - p->t);
248  zmap[q->id].h2s->Fill(p->id, p->t - q->t);
249  }
250  p++; // move over to the next L1
251  }
252  buffer.clear();
253  }
254  STATUS(endl);
255 
256  // livetime in case set manually
257  if (livetime_s > 0.0) {
258  for (vector<JHistogram>::iterator i = zmap.begin(); i != zmap.end(); ++i) {
259  TH1D* hl = i->h1l;
260  for (int ibin = 1; ibin <= hl->GetNbinsX(); ++ibin) {
261  hl->SetBinContent(ibin, livetime_s);
262  hl->SetBinError(ibin, 0.0000001);
263  }
264  }
265  }
266 
267  TFile out(outputFile.c_str(), "recreate");
268 
269  for (vector<JHistogram>::iterator i = zmap.begin(); i != zmap.end(); ++i) {
270  i->h2s->Write();
271  i->h1l->Write();
272  }
273 
274  out.Write();
275  out.Close();
276 }
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Wrapper class around STL string class.
Definition: JString.hh:27
Data structure for a composite optical module.
Definition: JModule.hh:50
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Auxiliary class to select ROOT class based on class name.
Router for direct addressing of module data in detector data structure.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
Auxiliary class for multiplexing object iterators.
string outputFile
int first
index of module in detector data structure
Template L2 builder.
Definition: JBuildL2.hh:45
Detector file.
Definition: JHead.hh:130
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
Data structure for hit time and DOM identifier.
Definition: JMonitorL1dt.cc:34
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
#define NOTICE(A)
Definition: JMessage.hh:64
Data time slice.
Address of module in detector data structure.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for L2 parameters.
General purpose class for object reading from a list of file names.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Template definition of histogram object interface.
Definition: JHistogram.hh:27