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

Auxiliary program to merge the time offsets of two detector files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JGeometry3D/JQuaternion3D.hh"
#include "JTools/JRange.hh"
#include "JTools/JConstants.hh"
#include "JTools/JQuantile.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JTrigger/JTriggerToolkit.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 merge the time offsets of two detector files.


The time offsets can be averaged (-T "average") or merge accordingly to the odd/even PMT identification (-T "odd"). If the keyword odd is used, the time offsets of the PMTs with an odd identity are extracted from the detector file corresponding to the -a option. The other time offsets are extracted from the detector file corresponding to the -b option. The parity is calculated as following:

     (floor id - 1)*31 + PMT id
Author
acreusot

Definition in file mergeTimeOffsets.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 65 of file mergeTimeOffsets.cc.

66 {
67  using namespace std;
68  using namespace JPP;
69 
70  string detectorFile_a;
71  string detectorFile_b;
72  string outputFile;
73  string mergeType;
74  int debug;
75 
76  try {
77  JParser<> zap("Auxiliary program to find differences between two detector files.");
78  zap['a'] = make_field(detectorFile_a);
79  zap['b'] = make_field(detectorFile_b);
80  zap['o'] = make_field(outputFile) = "";
81  zap['T'] = make_field(mergeType) = "average";
82  zap['d'] = make_field(debug) = 1;
83  zap(argc, argv);
84  }
85  catch(const exception &error) {
86  FATAL(error.what() << endl);
87  }
88 
89 
90  JDetector detector_a;
91  JDetector detector_b;
92  try {
93  load(detectorFile_a, detector_a);
94  }
95  catch(const JException& error) {
96  FATAL(error);
97  }
98  try {
99  load(detectorFile_b, detector_b);
100  }
101  catch(const JException& error) {
102  FATAL(error);
103  }
104 
105  bool is_equal = true;
106  const JModuleRouter module_router_a(detector_a);
107  const JModuleRouter module_router_b(detector_b);
108 
109  JDetector detectorMerged;
110  try {
111  load(outputFile, detectorMerged);
112  }
113  catch(const JException& error) {
114  FATAL(error);
115  }
116  const JModuleRouter module_routerMerged(detectorMerged);
117 
118  // compare detector IDs
119  if (detector_a.getID() != detector_b.getID()) {
120  DEBUG("* Different detector identifiers "
121  << setw(5) << detector_a.getID() << " (A) and " << endl
122  << setw(5) << detector_b.getID() << " (B)." << endl
123  << endl);
124  is_equal = false;
125  }
126 
127  // compare the modules that the files have in common
128  DEBUG("Comparing module by module." << endl);
129  for (JDetector::iterator module = detectorMerged.begin(); module != detectorMerged.end(); ++module) {
130  if (!module_router_b.hasModule(module->getID())) {
131  continue;
132  is_equal = false;
133  }
134  const JModule* module_b = &module_router_b.getModule(module->getID());
135  if (!module_router_a.hasModule(module->getID())) {
136  continue;
137  is_equal = false;
138  }
139  const JModule* module_a = &module_router_a.getModule(module->getID());
140  DEBUG(" Module " << setw(10) << module->getID());
141 
142  // comparing by PMT
143  // t0
144  for (unsigned int pmt = 0; pmt < module->size(); ++pmt) {
145  const JPMT& pmt_a = module_a->getPMT(pmt);
146  const JPMT& pmt_b = module_b->getPMT(pmt);
147  double newT0 = 0;
148  if (mergeType == "average") {
149  newT0 = 0.5*(pmt_a.getT0() + pmt_b.getT0());
150  } else if (mergeType == "odd") {
151  const int floorId = module_a->getFloor();
152  const int parityId = (floorId - 1)*NUMBER_OF_PMTS + pmt;
153  if (parityId % 2 != 0) {
154  newT0 = pmt_a.getT0();
155  } else {
156  newT0 = pmt_b.getT0();
157  }
158  }
159  module->getPMT(pmt).setT0(newT0);
160  }
161  }
162  DEBUG(endl);
163  //NOTICE("Store calibration data on file " << outputFile << endl);
164  //detectorMerged.comment.add(JMeta(argc, argv));
165  store(outputFile, detectorMerged);
166  ASSERT(is_equal);
167  return 0;
168 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:57
Detector data structure.
Definition: JDetector.hh:80
Router for direct addressing of module data in detector data structure.
string outputFile
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:47
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
int debug
debug level
Definition: JSirene.cc:63
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:211
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
double getT0() const
Get time offset.