Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSlewingK40.cc File Reference

Auxiliary program to determine time slewing from K40 data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <random>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TF1.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JMath/JMathToolkit.hh"
#include "JTrigger/JHitR0.hh"
#include "JTrigger/JHitToolkit.hh"
#include "JTools/JRange.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JSupport.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to determine time slewing from K40 data.

Author
mdejong

Definition in file JSlewingK40.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 37 of file JSlewingK40.cc.

38 {
39  using namespace std;
40  using namespace JPP;
41  using namespace KM3NETDAQ;
42 
44  JLimit_t& numberOfEvents = inputFile.getLimit();
45  string outputFile;
46  string detectorFile;
47  Double_t TMax_ns;
48  JRange<double> totVeto_ns;
49  JRange<int> multiplicity;
50  JRange<double> ct;
51  bool slewing;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Auxiliary program to determine time slewing from K40 data.");
57 
58  zap['f'] = make_field(inputFile);
59  zap['o'] = make_field(outputFile) = "monitor.root";
60  zap['a'] = make_field(detectorFile);
61  zap['n'] = make_field(numberOfEvents) = JLimit::max();
62  zap['T'] = make_field(TMax_ns) = 20.5; // [ns]
63  zap['t'] = make_field(totVeto_ns) = JRange<double>(0, 1e4); // time over threshold of reference hits [ns]
64  zap['M'] = make_field(multiplicity) = JRange<int>(2, 2);
65  zap['C'] = make_field(ct) = JRange<double>(0.0, 1.0); // cosine space angle between PMTs
66  zap['S'] = make_field(slewing);
67  zap['d'] = make_field(debug) = 1;
68 
69  zap(argc, argv);
70  }
71  catch(const exception &error) {
72  FATAL(error.what() << endl);
73  }
74 
75 
76  using namespace KM3NETDAQ;
77 
78  if (!multiplicity.is_valid()) { FATAL("Invalid multiplicity " << multiplicity << endl); }
79  if ( multiplicity.getLowerLimit() < 2) { FATAL("Invalid multiplicity " << multiplicity << endl); }
80  if (!totVeto_ns .is_valid()) { FATAL("Invalid time over threshold " << totVeto_ns << endl); }
81 
82  JHit::setSlewing(slewing);
83 
85 
86  try {
87  load(detectorFile, detector);
88  }
89  catch(const JException& error) {
90  FATAL(error);
91  }
92 
93  if (detector.empty()) {
94  FATAL("Empty detector." << endl);
95  }
96 
97  const JModuleRouter router(detector);
98 
99 
100  TFile out(outputFile.c_str(), "recreate");
101 
102  TH1D h0("h0", NULL, 41, -TMax_ns, +TMax_ns);
103  TH1D h1("h1", NULL, 50, -0.5, 49.5);
104  TProfile2D hx("hx", NULL, 50, -0.5, 49.5, 50, -0.5, 49.5, -2*TMax_ns, +2*TMax_ns);
105  TProfile h2("h2", NULL, 100, 0.5, 100.5, -2*TMax_ns, +2*TMax_ns);
106 
107  h0.Sumw2();
108  h1.Sumw2();
109 
110  random_device rd;
111  mt19937 g(rd());
112 
113  vector<JHitR0> buffer;
114 
115  while (inputFile.hasNext()) {
116 
117  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
118 
119  const JDAQTimeslice* timeslice = inputFile.next();
120 
121  for (JDAQTimeslice::const_iterator super_frame = timeslice->begin(); super_frame != timeslice->end(); ++super_frame) {
122 
123  if (router.hasModule(super_frame->getModuleID()) && !super_frame->empty()) {
124 
125  const JModule& module = router.getModule(super_frame->getModuleID());
126 
127  // process data
128 
129  buffer.resize(super_frame->size());
130 
131  vector<JHitR0>::iterator out = buffer.begin();
132 
133  for (JDAQSuperFrame::const_iterator i = super_frame->begin(); i != super_frame->end(); ++i) {
134  *out = JHitR0(i->getPMT(), JHitToolkit<JHit>::getHit(*i, module.getPMT(i->getPMT())));
135  ++out;
136  }
137 
138  sort(buffer.begin(), buffer.end());
139 
140  for (vector<JHitR0>::iterator p = buffer.begin(); p != buffer.end(); ) {
141 
143 
144  while (++q != buffer.end() && q->getT() - p->getT() <= TMax_ns ) {}
145 
146  if (multiplicity(distance(p,q))) {
147 
148  shuffle(p,q,g);
149 
150  for (vector<JHitR0>::const_iterator __p = p; __p != q; ++__p) {
151  for (vector<JHitR0>::const_iterator __q = __p; ++__q != q; ) {
152 
153  const double dot = JMATH::getDot(module.getPMT(__p->getPMT()),
154  module.getPMT(__q->getPMT()));
155 
156  if (ct(dot)) {
157 
158  h0.Fill(__q->getT() - __p->getT());
159  h1.Fill(__q->getToT());
160  hx.Fill(__p->getToT(), __q->getToT(), __q->getT() - __p->getT());
161 
162  if (totVeto_ns(__p->getToT())) {
163  h2.Fill(__q->getToT(), __q->getT() - __p->getT());
164  }
165  }
166  }
167  }
168 
169  sort(p,q);
170  }
171 
172  p = q;
173  }
174  }
175  }
176  }
177  STATUS(endl);
178 
179 
180  // Fit function
181 
182  TF1 f1("f1", "[0]*exp([1]*sqrt(x) + [2]*x) + [3]");
183 
184  f1.SetParameter(0, h2.GetMaximum());
185  f1.SetParameter(1, -0.01);
186  f1.SetParameter(2, -0.05);
187  f1.SetParameter(3, h2.GetMinimum());
188 
189  h2.ProjectionX()->Fit(&f1, "", "same");
190 
191  for (int i = 0; i != f1.GetNpar(); ++i) {
192  cout << "\tstatic double p" << i << "() { return " << setw(9) << setprecision(5) << f1.GetParameter(i) << "; }" << endl;
193  }
194 
195 
196  out.Write();
197  out.Close();
198 }
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
Data structure for a composite optical module.
Definition: JModule.hh:67
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
bool is_valid(const json &js)
Check validity of JSon data.
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
string outputFile
const JPolynome f1(1.0, 2.0, 3.0)
Function.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:226
Reduced data structure for L0 hit.
Definition: JHitR0.hh:25
Hit data structure.
Definition: JDAQHit.hh:34
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Data time slice.
double getDot(const JFirst_t &first, const JSecond_t &second)
Get dot product of objects.
then $JPP_DIR examples JDetector JSlewing P slewing
Definition: JSlewing.sh:43
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:172
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62