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

Auxiliary program to edit PMT parameters map. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include "JLang/JLangToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTReadoutAddress.hh"
#include "JDetector/JPMTPhysicalAddress.hh"
#include "JDetector/JModuleAddressMap.hh"
#include "JDetector/JDetectorAddressMap.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.hh"
#include "JSupport/JMeta.hh"
#include "JTools/JRange.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 edit PMT parameters map.

Syntax:

    -A "<PMT physical address> (set|add|sub|mul|div) <key> <value>"

The PMT physical address corresponds to the data structure JDETECTOR::JPMTPhysicalAddress. The key corresponds to one of the data members of the JDETECTOR::JPMTParameters data structure.

Note that in the absence of option -a, the detector identifier should be specified using option -D so to obtain the correct PMT address mapping.

Multiple options -A will be processed in order of appearance.

Author
mdejong

Definition in file JEditPMTParametersMap.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 146 of file JEditPMTParametersMap.cc.

147 {
148  using namespace std;
149  using namespace JPP;
150 
151  typedef JModifier<JPMTPhysicalAddress> JModifier_t;
152  typedef JRange<double> JRange_t;
153 
154  string detectorFile;
155  int detectorID;
156  JPMTParametersMap parameters;
157  vector<JModifier_t> modifier;
158  JRange_t T_ns;
159  string outputFile;
160  int debug;
161 
162  try {
163 
164  JParser<> zap("Auxiliary program to edit PMT parameters map.");
165 
166  zap['a'] = make_field(detectorFile, "detector file.") = "";
167  zap['D'] = make_field(detectorID, "detector identifier (in absence of detector file).") = 0;
168  zap['P'] = make_field(parameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
169  zap['A'] = make_field(modifier, "PMT parameter modifier.") = JPARSER::initialised();
170  zap['T'] = make_field(T_ns, "time-over-threshold range.") = JRange_t();
171  zap['o'] = make_field(outputFile, "output file.") = "pmt.txt";
172  zap['d'] = make_field(debug) = 3;
173 
174  zap(argc, argv);
175  }
176  catch(const exception &error) {
177  FATAL(error.what() << endl);
178  }
179 
180 
181  if (detectorFile != "") {
182 
183  // Setting default PMT parameters for given detector.
184 
186 
187  try {
188  load(detectorFile, detector);
189  }
190  catch(const JException& error) {
191  FATAL(error);
192  }
193 
194  if (detectorID == 0) {
195 
196  detectorID = detector.getID();
197 
198  } else if (detectorID != detector.getID()) {
199 
200  FATAL("Inconsistent detector identifier " << detectorID << " != " << detector.getID() << endl);
201  }
202 
203 
204  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
205 
206  for (unsigned int pmt = 0; pmt != module->size(); ++pmt) {
207 
208  const JPMTIdentifier id(module->getID(), pmt);
209 
210  if (parameters.find(id) == parameters.end()) {
211 
212  NOTICE("Setting default parameters for PMT " << id << endl);
213 
214  parameters[id] = parameters.getDefaultPMTParameters();
215  }
216  }
217  }
218  }
219 
220  if (!modifier.empty()) {
221 
222  if (!hasDetectorAddressMap(detectorID)) {
223  FATAL("Invalid detector identifier " << detectorID << endl);
224  }
225 
226  const JDetectorAddressMap& demo = getDetectorAddressMap(detectorID);
227 
228  for (JPMTParametersMap::iterator ps = parameters.begin(); ps != parameters.end(); ++ps) {
229 
230  const JPMTPhysicalAddress& address = demo.get(ps->first);
231 
232  for (vector<JModifier_t>::const_iterator i = modifier.begin(); i != modifier.end(); ++i) {
233 
234  if (address == i->address) {
235 
236  NOTICE("Modifying parameters for PMT " << ps->first << endl);
237 
238  if (!i->apply(ps->second)) {
239  ERROR("No valid action: " << *i << endl);
240  }
241  }
242  }
243  }
244  }
245 
246 
247  if (T_ns != JRange_t()) {
248 
249  const int NPE = 1;
250 
251  for (JPMTParametersMap::iterator i = parameters.begin(); i != parameters.end(); ++i) {
252 
253  const JPMTAnalogueSignalProcessor cpu(i->second);
254 
255  i->second.QE *= (cpu.getIntegralOfProbability(i->second.threshold,
256  cpu.getNPE(T_ns.getUpperLimit(), NPE),
257  NPE)
258  /
259  cpu.getIntegralOfProbability(cpu.getNPE(T_ns.getLowerLimit(), NPE),
260  cpu.getNPE(T_ns.getUpperLimit(), NPE),
261  NPE));
262  }
263  }
264 
265 
266  if (outputFile != "") {
267 
268  parameters.comment.add(JMeta(argc, argv));
269 
270  ofstream out(outputFile.c_str());
271 
272  out << parameters << endl;
273 
274  out.close();
275  }
276 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Utility class to parse command line options.
Definition: JParser.hh:1410
General exception.
Definition: JException.hh:40
Detector data structure.
Definition: JDetector.hh:77
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
Lookup table for PMT addresses in detector.
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
string outputFile
const JModuleAddressMap & get(const int id) const
Get module address map.
Detector file.
Definition: JHead.hh:126
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
int getID() const
Get identifier.
Definition: JObjectID.hh:54
#define NOTICE(A)
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:64
Auxiliary class for map of PMT parameters.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:59
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
#define FATAL(A)
Definition: JMessage.hh:65
Data structure for PMT physical address.