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 152 of file JEditPMTParametersMap.cc.

153 {
154  using namespace std;
155  using namespace JPP;
156 
157  typedef JModifier<JPMTPhysicalAddress> JModifier_t;
158  typedef JRange<double> JRange_t;
159 
160  string detectorFile;
161  int detectorID;
163  vector<JModifier_t> modifier;
164  JRange_t T_ns;
165  string outputFile;
166  int debug;
167 
168  try {
169 
170  JParser<> zap("Auxiliary program to edit PMT parameters map.");
171 
172  zap['a'] = make_field(detectorFile, "detector file.") = "";
173  zap['D'] = make_field(detectorID, "detector identifier (in absence of detector file).") = 0;
174  zap['P'] = make_field(parameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
175  zap['A'] = make_field(modifier, "PMT parameter modifier.") = JPARSER::initialised();
176  zap['T'] = make_field(T_ns, "time-over-threshold range.") = JRange_t();
177  zap['o'] = make_field(outputFile, "output file.") = "pmt.txt";
178  zap['d'] = make_field(debug) = 3;
179 
180  zap(argc, argv);
181  }
182  catch(const exception &error) {
183  FATAL(error.what() << endl);
184  }
185 
186 
187  if (detectorFile != "") {
188 
189  // Setting default PMT parameters for given detector.
190 
192 
193  try {
194  load(detectorFile, detector);
195  }
196  catch(const JException& error) {
197  FATAL(error);
198  }
199 
200  if (detectorID == 0) {
201 
202  detectorID = detector.getID();
203 
204  } else if (detectorID != detector.getID()) {
205 
206  FATAL("Inconsistent detector identifier " << detectorID << " != " << detector.getID() << endl);
207  }
208 
209 
210  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
211 
212  for (unsigned int pmt = 0; pmt != module->size(); ++pmt) {
213 
214  const JPMTIdentifier id(module->getID(), pmt);
215 
216  if (parameters.find(id) == parameters.end()) {
217 
218  NOTICE("Setting default parameters for PMT " << id << endl);
219 
220  parameters[id] = parameters.getDefaultPMTParameters();
221  }
222  }
223  }
224  }
225 
226  if (!modifier.empty()) {
227 
228  if (!hasDetectorAddressMap(detectorID)) {
229  FATAL("Invalid detector identifier " << detectorID << endl);
230  }
231 
232  const JDetectorAddressMap& demo = getDetectorAddressMap(detectorID);
233 
234  for (JPMTParametersMap::iterator ps = parameters.begin(); ps != parameters.end(); ++ps) {
235 
236  const JPMTPhysicalAddress& address = demo.get(ps->first);
237 
238  for (vector<JModifier_t>::const_iterator i = modifier.begin(); i != modifier.end(); ++i) {
239 
240  if (i->address == address || i->address == WILDCARD) {
241 
242  NOTICE("Modifying parameters for PMT " << ps->first << endl);
243 
244  if (!i->apply(ps->second)) {
245  ERROR("No valid action: " << *i << endl);
246  }
247  }
248  }
249  }
250  }
251 
252 
253  if (T_ns != JRange_t()) {
254 
255  const int NPE = 1;
256 
257  for (JPMTParametersMap::iterator i = parameters.begin(); i != parameters.end(); ++i) {
258 
259  const JPMTAnalogueSignalProcessor cpu(i->second);
260 
261  i->second.QE *= (cpu.getIntegralOfChargeProbability(i->second.threshold,
262  cpu.getNPE(T_ns.getUpperLimit(), NPE),
263  NPE)
264  /
265  cpu.getIntegralOfChargeProbability(cpu.getNPE(T_ns.getLowerLimit(), NPE),
266  cpu.getNPE(T_ns.getUpperLimit(), NPE),
267  NPE));
268  }
269  }
270 
271 
272  if (outputFile != "") {
273 
274  parameters.comment.add(JMeta(argc, argv));
275 
276  ofstream out(outputFile.c_str());
277 
278  out << parameters << endl;
279 
280  out.close();
281  }
282 }
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:1493
General exception.
Definition: JException.hh:23
Detector data structure.
Definition: JDetector.hh:80
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Lookup table for PMT addresses in detector.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
string outputFile
const JModuleAddressMap & get(const int id) const
Get module address map.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
int getID() const
Get identifier.
Definition: JObjectID.hh:55
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
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:61
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
#define FATAL(A)
Definition: JMessage.hh:67
JRange< Double_t > JRange_t
Definition: JFitToT.hh:34
Data structure for PMT physical address.