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

Auxiliary program to check t0's. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TF1.h"
#include "TFitResult.h"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDAQ/JDAQHeaderIO.hh"
#include "JROOT/JRootFileReader.hh"
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JPMTHVRunSettings.hh"
#include "JDB/JLocation_t.hh"
#include "JDB/JSupport.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JCalibrate/JCalibrateK40.hh"
#include "JROOT/JManager.hh"
#include "JTools/JRange.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JProperties.hh"
#include "Jeep/JPrint.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 check t0's.

Author
mdejong

Definition in file JCheckK40.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 120 of file JCheckK40.cc.

121 {
122  using namespace std;
123  using namespace JPP;
124  using namespace KM3NETDAQ;
125 
126  typedef JRange<size_t> JRange_t;
127 
128  JServer server;
129  string usr;
130  string pwd;
131  string cookie;
132  string detectorFile;
133  pair<string, string> inputFile;
134  string outputFile;
135  double precision;
136  double Wmin = 100.0;
137  JRange_t X;
138  string option;
139  int debug;
140 
141  try {
142 
143  JProperties properties;
144 
145  properties.insert(gmake_property(Wmin));
146 
147  JParser<> zap("Auxiliary program to check t0's.");
148 
149  zap['s'] = make_field(server) = getServernames();
150  zap['u'] = make_field(usr) = "";
151  zap['!'] = make_field(pwd) = "";
152  zap['C'] = make_field(cookie) = "";
153  zap['a'] = make_field(detectorFile);
154  zap['f'] = make_field(inputFile, "pair of input files (output of JCalibrateK40)");
155  zap['o'] = make_field(outputFile) = "k40.root";
156  zap['e'] = make_field(precision, "precision for HV comparison") = 0.5;
157  zap['@'] = make_field(properties) = JPARSER::initialised();
158  zap['x'] = make_field(X, "ROOT fit range (PMT pairs).") = JRange_t(300, numeric_limits<size_t>::max());
159  zap['O'] = make_field(option, "ROOT fit option, see TH1::Fit.") = "";
160  zap['U'] = make_field(usePMTID);
161  zap['d'] = make_field(debug) = 2;
162 
163  zap(argc, argv);
164  }
165  catch(const exception &error) {
166  FATAL(error.what() << endl);
167  }
168 
169 
170  try {
171  JDB::reset(usr, pwd, cookie);
172  }
173  catch(const exception& error) {
174  FATAL(error.what() << endl);
175  }
176 
177  JSetup setups[] = {
178  JSetup(inputFile.first),
179  JSetup(inputFile.second)
180  };
181 
182  for (int i = 0; i != 2; ++i) {
183  DEBUG(setw(32) << setups[i].file_name << ' ' << setups[i].header.getDetectorID() << ' ' << setups[i].header.getRunNumber() << endl);
184  }
185 
187 
188  try {
189  load(detectorFile, detector);
190  }
191  catch(const JException& error) {
192  FATAL(error);
193  }
194 
195  if (option.find('S') == string::npos) { option += 'S'; }
196  if (option.find('Q') == string::npos && debug < JEEP::debug_t) { option += 'Q'; }
197 
198 
199  JManager<int, TH1D> H1(new TH1D("[%]", NULL, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
200 
201 
202  TF1 f1("f1", "[0]*TMath::Gaus(x,[1],[2]) + [3]");
203 
204  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
205 
206  TH2D* h2[] = {
207  setups[0].get(MAKE_CSTRING(module->getID() << _2S)),
208  setups[1].get(MAKE_CSTRING(module->getID() << _2S))
209  };
210 
211  DEBUG("Module " << setw(10) << module->getID() << ' ' << (h2[0] != NULL) << (h2[0] != NULL) << endl);
212 
213  if (h2[0] == NULL ||
214  h2[1] == NULL) {
215  continue;
216  }
217 
218  JCombinatorics combinatorics;
219 
220  combinatorics.configure(module->size());
221 
222  combinatorics.sort(JPairwiseComparator(*module));
223 
224  vector<JQuantile> Q(module->size());
225 
226  for (size_t ip = max(X.getLowerLimit(), size_t(0)); ip != min(X.getUpperLimit(), combinatorics.getNumberOfPairs()); ++ip) {
227 
228  const JCombinatorics::pair_type pair = combinatorics.getPair(ip);
229 
230  const JLocation_t location_1(module->getString(), module->getFloor(), pair.first);
231  const JLocation_t location_2(module->getString(), module->getFloor(), pair.second);
232 
233  const bool hv_1 = (fabs(setups[0].HV[location_1] - setups[1].HV[location_1]) < precision);
234  const bool hv_2 = (fabs(setups[0].HV[location_2] - setups[1].HV[location_2]) < precision);
235 
236  double t1[] = {
237  numeric_limits<double>::max(),
238  numeric_limits<double>::max()
239  };
240 
241  const Int_t ix = ip + 1;
242 
243  for (int i = 0; i != 2; ++i) {
244 
245  TH1D h1("__py", NULL, h2[i]->GetYaxis()->GetNbins(), h2[i]->GetYaxis()->GetXmin(), h2[i]->GetYaxis()->GetXmax());
246 
247  // start values
248 
249  Double_t ymin = numeric_limits<double>::max();
250  Double_t ymax = numeric_limits<double>::lowest();
251  Double_t mean = 0.0;
252  Double_t sigma = 4.5;
253  Double_t W = 0.0;
254 
255  for (int iy = 1; iy <= h1.GetNbinsX(); ++iy) {
256 
257  const Double_t x = h1.GetBinCenter(iy);
258  const Double_t y = h2[i]->GetBinContent(ix,iy);
259 
260  h1.SetBinContent(iy, y);
261  h1.SetBinError (iy, sqrt(y));
262 
263  if (y > ymax) {
264  mean = x;
265  ymax = y;
266  }
267 
268  if (y < ymin) {
269  ymin = y;
270  }
271 
272  W += y;
273  }
274 
275  if (W >= Wmin) {
276 
277  f1.SetParameter(0, ymax);
278  f1.SetParameter(1, mean);
279  f1.SetParameter(2, sigma);
280  f1.SetParameter(3, ymin);
281 
282  TFitResultPtr result = h1.Fit(&f1, option.c_str(), "same");
283 
284  if (result.Get() == NULL) {
285  FATAL("Invalid TFitResultPtr " << h1.GetName() << endl);
286  }
287 
288  if (debug >= debug_t || !result->IsValid()) {
289  cout << "Histogram slice: "
290  << setw(3) << ix << ' '
291  << FIXED(7,3) << f1.GetParameter(1) << " +/- "
292  << FIXED(7,3) << f1.GetParError(1) << ' '
293  << FIXED(7,3) << result->Chi2() << '/'
294  << result->Ndf() << ' '
295  << (result->IsValid() ? "" : "failed") << endl;
296  }
297 
298  t1[i] = f1.GetParameter(1);
299  }
300  }
301 
302  if (t1[0] != numeric_limits<double>::max() &&
303  t1[1] != numeric_limits<double>::max()) {
304 
305  if (hv_1 != hv_2) {
306 
308 
309  if (hv_1) {
310  p2 = JCombinatorics::pair_type(pair.second, pair.first);
311  }
312 
313  if (hv_2) {
314  p2 = JCombinatorics::pair_type(pair.first, pair.second);
315  }
316 
317  if (debug >= debug_t) {
318  cout << setw(10) << module->getID() << "." << FILL(2,'0') << p2.first << FILL() << ' ';
319  cout << "(" << FILL(2,'0') << p2.second << FILL() << ")" << ' ';
320  cout << FIXED(6,2) << (combinatorics.getSign(p2) * (t1[1] - t1[0])) << endl;
321  }
322 
323  Q[p2.first].put(combinatorics.getSign(p2) * (t1[1] - t1[0]));
324  }
325  }
326  }
327 
328  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
329  if (Q[i].getCount() >= 2) {
330  H1[module->getID()]->SetBinContent(i+1, Q[i].getMean());
331  H1[module->getID()]->SetBinError (i+1, Q[i].getSTDev());
332  }
333  }
334  }
335 
336  if (outputFile != "") {
337  H1.Write(outputFile.c_str());
338  }
339 }
Utility class to parse command line options.
Definition: JParser.hh:1500
const pair_type & getPair(const int index) const
Get pair of indices for given index.
General exception.
Definition: JException.hh:23
JCombinatorics::pair_type pair_type
Auxiliary class to convert pair of indices to unique index and back.
Q(UTCMax_s-UTCMin_s)-livetime_s
debug
Definition: JMessage.hh:29
void configure(const int numberOfIndices)
Configure.
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
Detector data structure.
Definition: JDetector.hh:89
Utility class to parse parameter values.
Definition: JProperties.hh:496
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
void sort(JComparator_t comparator)
Sort address pairs.
double getMean(vector< double > &v)
get mean of vector content
size_t getNumberOfPairs() const
Get number of pairs.
Type definition of range.
Definition: JHead.hh:39
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Auxiliary class to sort pairs of PMT addresses within optical module.
Detector file.
Definition: JHead.hh:224
Auxiliary data structure for location of product in detector.
Definition: JLocation_t.hh:24
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
return result
Definition: JPolint.hh:743
then break fi done getCenter read X Y Z let X
static int getSign(const int first, const int second)
Sign of pair of indices.
int debug
debug level
Definition: JSirene.cc:63
Range of values.
Definition: JRange.hh:38
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
p2
Definition: module-Z:fit.sh:74
void reset(T &value)
Reset value.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:98
int getCount(const T &hit)
Get hit count.
Wrapper class for server name.
Definition: JDB.hh:42
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
static const char *const _2S
Name extension for 2D counts.