29 static const std::string reset_t =
"reset";
30 static const std::string set_t =
"set";
31 static const std::string add_t =
"add";
32 static const std::string sub_t =
"sub";
33 static const std::string rot_t =
"rot";
34 static const std::string mul_t =
"mul";
35 static const std::string via_t =
"via";
37 static const std::string rand_t =
"rand";
38 static const std::string randset_t = rand_t + set_t;
39 static const std::string randadd_t = rand_t + add_t;
40 static const std::string randsub_t = rand_t + sub_t;
41 static const std::string randrot_t = rand_t + rot_t;
42 static const std::string randmul_t = rand_t + mul_t;
43 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());
275 static bool apply(
JModule& module,
const std::string& action,
const JVector3D& pos)
278 gRandom->Gaus(0.0, pos.
getY()),
279 gRandom->Gaus(0.0, pos.
getZ()));
283 else if (action == add_t)
285 else if (action == sub_t)
287 else if (action == randset_t)
289 else if (action == randadd_t)
291 else if (action == randsub_t)
308 inline const JModifier& getModifier(
const int id,
const JModifier& modifier)
314 const string::size_type pos = modifier.action.find(rand_t);
316 if (pos != string::npos) {
318 JModifier&
result = buffer[id][modifier.action][modifier.data.size()];
323 result.action = modifier.action.substr(pos + rand_t.length());
325 for (
size_t i = 0; i != modifier.data.size(); ++i) {
326 result.data.push_back(gRandom->Gaus(0.0, modifier.data[i]));
359 bool apply(
JPMT& pmt)
const
363 if (action == set_t) {
367 }
else if (action == reset_t) {
378 catch(
const std::exception&) {}
391 friend inline std::istream&
operator>>(std::istream& in, JPMTModifier& modifier)
393 return in >> static_cast<JPMTIdentifier&>(modifier) >> modifier.action >> modifier.value;
404 friend inline std::ostream&
operator<<(std::ostream& out,
const JPMTModifier& modifier)
406 out << static_cast<const JPMTIdentifier&>(modifier);
408 out << modifier.action;
410 out << modifier.value;
430 static const char SEPARATOR =
'-';
447 friend inline std::istream&
operator>>(std::istream& in, JRange_t& range)
449 if (in >> range.first) {
450 if (in.get() != (int) JRange_t::SEPARATOR || ! (in >> range.second)) {
451 in.setstate(std::ios::badbit);
466 friend inline std::ostream&
operator<<(std::ostream& out,
const JRange_t& range)
468 return out << range.first << JRange_t::SEPARATOR << range.second;
536 int main(
int argc,
char **argv)
553 JParser<> zap(
"Auxiliary program to modify detector.");
567 catch(
const exception &error) {
568 FATAL(error.what() << endl);
584 if (!keep.empty() && !rm.empty()) {
585 FATAL(
"Use either option -k or -r." << endl);
598 istringstream is(*i);
605 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ) {
607 bool __rm__ = !keep.empty() && rm.empty();
630 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
634 DEBUG(
"Modifier" <<
' '
635 <<
"(" << setw(3) << module->
getString() <<
"," << setw(2) << module->
getFloor() <<
")" <<
' '
636 << setw(8) << module->
getID() <<
' '
637 <<
"action" <<
' ' << i->action <<
JEEPZ() << i->data << endl);
639 if (!i->apply(*module)) {
640 ERROR(
"No valid action: " << *i << endl);
649 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
653 const JModifier& modifier = getModifier(module->
getString(), *i);
655 DEBUG(
"Modifier" <<
' '
656 <<
"(" << setw(3) << module->
getString() <<
"," << setw(2) << module->
getFloor() <<
")" <<
' '
657 << setw(8) << module->
getID() <<
' '
658 <<
"action" <<
' ' << modifier.action <<
JEEPZ() << modifier.data << endl);
660 if (!modifier.apply(*module)) {
661 ERROR(
"No valid action: " << *i << endl);
670 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
674 DEBUG(
"PMT modifier" <<
' '
675 <<
"(" << setw(8) << module->
getID() <<
"," << setw(2) << i->getPMTAddress() <<
")" <<
' '
676 <<
"action" <<
' ' << i->action <<
' '
677 <<
"value" <<
' ' << i->value << endl);
679 if (i->getPMTAddress() < 0 ||
681 !i->apply(module->
getPMT(i->getPMTAddress()))) {
682 ERROR(
"No valid action: " << *i << endl);