34 static const std::string reset_t =
"reset";
35 static const std::string set_t =
"set";
36 static const std::string add_t =
"add";
37 static const std::string sub_t =
"sub";
38 static const std::string rot_t =
"rot";
39 static const std::string mul_t =
"mul";
40 static const std::string via_t =
"via";
41 static const std::string assign_t =
"=";
43 static const std::string rand_t =
"rand";
44 static const std::string randset_t = rand_t + set_t;
45 static const std::string randadd_t = rand_t + add_t;
46 static const std::string randsub_t = rand_t + sub_t;
47 static const std::string randrot_t = rand_t + rot_t;
48 static const std::string randmul_t = rand_t + mul_t;
49 static const std::string randvia_t = rand_t + via_t;
73 return (action !=
"" && !data.empty());
83 bool apply(
JModule& module)
const
85 switch (data.size()) {
88 return apply(module, action);
91 return apply(module, action, data[0]);
94 return apply(module, action,
JVector3D(data[0], data[1], 0.0));
97 return apply(module, action,
JVector3D(data[0], data[1], data[2]));
112 friend inline std::istream&
operator>>(std::istream&
in, JModifier& modifier)
116 if (in >> modifier.id >> modifier.action) {
118 modifier.data.clear();
120 for (
double x; in >> x; ) {
121 modifier.data.push_back(x);
124 in.clear(ios_base::eofbit);
138 friend inline std::ostream&
operator<<(std::ostream& out,
const JModifier& modifier)
142 out << modifier.action;
165 static bool apply(
JModule& module,
const std::string& action)
167 if (action == reset_t) {
171 for (JModule::iterator
pmt = module.begin();
pmt != module.end(); ++
pmt) {
192 static bool apply(
JModule& module,
const std::string& action,
const double value)
194 if (action == set_t) {
198 }
else if (action == add_t) {
202 }
else if (action == sub_t) {
206 }
else if (action == rot_t) {
216 }
else if (action == mul_t) {
224 }
else if (action == via_t) {
228 }
else if (action == randadd_t) {
230 module.
add(gRandom->Gaus(0.0, value));
232 }
else if (action == randsub_t) {
234 module.
sub(gRandom->Gaus(0.0, value));
236 }
else if (action == randrot_t){
246 }
else if (action == randmul_t) {
254 }
else if (action == randvia_t) {
256 module.
add(gRandom->Gaus(0.0, value) * module.
getFloor());
258 }
else if (action == assign_t) {
260 module.
setID((
int) value);
279 static bool apply(
JModule& module,
const std::string& action,
const JVector3D& pos)
282 gRandom->Gaus(0.0, pos.
getY()),
283 gRandom->Gaus(0.0, pos.
getZ()));
287 else if (action == add_t)
289 else if (action == sub_t)
291 else if (action == randset_t)
293 else if (action == randadd_t)
295 else if (action == randsub_t)
312 inline const JModifier& getModifier(
const int id,
const JModifier& modifier)
318 const string::size_type pos = modifier.action.find(rand_t);
320 if (pos != string::npos) {
322 JModifier&
result = buffer[id][modifier.action][modifier.data.size()];
324 if (!result.is_valid()) {
327 result.action = modifier.action.substr(pos + rand_t.length());
329 for (
size_t i = 0; i != modifier.data.size(); ++i) {
330 result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
367 if (action == set_t) {
371 }
else if (action == reset_t) {
382 catch(
const std::exception&) {}
395 friend inline std::istream&
operator>>(std::istream& in, JPMTModifier& modifier)
397 return in >>
static_cast<JPMTIdentifier&
>(modifier) >> modifier.action >> modifier.value;
408 friend inline std::ostream&
operator<<(std::ostream& out,
const JPMTModifier& modifier)
410 out << static_cast<const JPMTIdentifier&>(modifier);
412 out << modifier.action;
414 out << modifier.value;
434 static const char SEPARATOR =
'-';
453 if (in >> range.first) {
454 if (in.get() != (int) JRange_t::SEPARATOR || ! (in >> range.second)) {
455 in.setstate(std::ios::badbit);
472 return out << range.first << JRange_t::SEPARATOR << range.second;
541 int main(
int argc,
char **argv)
558 JParser<> zap(
"Auxiliary program to modify detector.");
572 catch(
const exception &error) {
573 FATAL(error.what() << endl);
589 if (!keep.empty() && !rm.empty()) {
590 FATAL(
"Use either option -k or -r." << endl);
609 istringstream
is(*i);
616 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ) {
618 bool __rm__ = !keep.empty() && rm.empty();
641 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
645 DEBUG(
"Modifier" <<
' '
646 <<
"(" << setw(3) << module->
getString() <<
"," << setw(2) << module->
getFloor() <<
")" <<
' '
647 << setw(8) << module->
getID() <<
' '
648 <<
"action" <<
' ' << i->action <<
JEEPZ() << i->data << endl);
650 if (!i->apply(*module)) {
651 ERROR(
"No valid action: " << *i << endl);
660 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
664 const JModifier& modifier = getModifier(module->
getString(), *i);
666 DEBUG(
"Modifier" <<
' '
667 <<
"(" << setw(3) << module->
getString() <<
"," << setw(2) << module->
getFloor() <<
")" <<
' '
668 << setw(8) << module->
getID() <<
' '
669 <<
"action" <<
' ' << modifier.action <<
JEEPZ() << modifier.data << endl);
671 if (!modifier.apply(*module)) {
672 ERROR(
"No valid action: " << *i << endl);
681 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
683 if (module->
getID() == i->getModuleID() || i->getModuleID() ==
WILD_CARD) {
685 DEBUG(
"PMT modifier" <<
' '
686 <<
"(" << setw(8) << module->
getID() <<
"," << setw(2) << i->getPMTAddress() <<
")" <<
' '
687 <<
"action" <<
' ' << i->action <<
' '
688 <<
"value" <<
' ' << i->value << endl);
693 if (!i->apply(module->
getPMT(pmt))) {
694 ERROR(
"No valid action: " << *i << endl);
698 }
else if (i->getPMTAddress() < 0 ||
700 !i->apply(module->
getPMT(i->getPMTAddress()))) {
701 ERROR(
"No valid action: " << *i << endl);
Utility class to parse command line options.
static const JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
int getFloor() const
Get floor number.
Data structure for a composite optical module.
void reset(const JPMTStatusBits_t bit)
Reset PMT status.
void set(const JPMTStatusBits_t bit)
Set PMT status.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Utility class to parse parameter values.
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Data structure for PMT calibration.
Data structure for detector geometry and calibration.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
JModule & sub(const JVector3D &pos)
Subtract position.
I/O formatting auxiliaries.
Version with PMT status field and comments.
Data structure for vector in three dimensions.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
int getID() const
Get identifier.
bool is_valid(const json &js)
Check validity of JSon data.
Data structure for PMT geometry and calibration.
double getY() const
Get y position.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Auxiliary data structure for streaming of STL containers.
const JPosition3D & getPosition() const
Get position.
static const JModule & getInstance()
Get reference to unique instance of this class object.
const JPMT & getPMT(const int index) const
Get PMT.
void rotate(const JRotation3D &R)
Rotate module.
General purpose messaging.
Direct access to module in detector data structure.
JRange< Double_t > JRange_t
int getString() const
Get string number.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
static const char WILD_CARD
void setID(const int id)
Set identifier.
double getX() const
Get x position.
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
JModule & set(const JVector3D &pos)
Set position.
double getZ() const
Get z position.
JModule & add(const JVector3D &pos)
Add position.
void setPosition(const JVector3D &pos)
Set position.
#define DEBUG(A)
Message macros.
JPosition3D getPosition(const Vec &v)
Get position.
int main(int argc, char *argv[])