10 #include <type_traits>
88 static const std::string
fix_t =
"fix";
91 static const std::string
stage_t =
"stage";
120 bool hasString(
const int id)
const
136 static constexpr
double RADIUS_M = 1.0;
157 std::
set<int>(buffer.begin(), buffer.end())
171 std::set_difference(A.begin(), A.end(), B.begin(), B.end(), std::inserter(*
this, this->begin()));
187 std::set_difference(A.begin(), A.end(), B.begin(), B.end(), std::inserter(*
this, this->begin()));
200 for (
int id; in >> id; ) {
221 for (
const int id :
object) {
297 virtual void apply(
const double step)
override
301 module.add(direction * step);
330 for (
size_t i = 0; i !=
detector.size(); ++i) {
343 virtual void apply(
const double step)
override
345 for (
const auto i : index) {
374 for (
size_t i = 0; i !=
detector.size(); ++i) {
387 virtual void apply(
const double step)
override
389 for (
const auto i : index) {
421 tripods (setup.tripods),
436 virtual void apply(
const double step)
override
438 tripods[index].add(direction * step);
461 hydrophones (setup.hydrophones),
462 transmitters(setup.transmitters)
477 virtual void apply(
const double step)
override
483 if (index[0] != hydrophones .size()) { hydrophones [index[0]].rotate(R); }
484 if (index[1] != transmitters.size()) { transmitters[index[1]].rotate(R); }
504 Nmax (
std::numeric_limits<size_t>::max()),
530 for (
double value; in >> value; ) {
531 object.steps.push_back(value);
554 out << setw(2) <<
object.option <<
' '
555 << setw(2) <<
object.mestimator <<
' '
558 << setw(3) <<
object.Nextra;
560 for (
const double value :
object.steps) {
561 out <<
' ' <<
FIXED(9,5) << value;
585 const size_t threads,
587 filenames(filenames),
594 setup.tripods.load(filenames.
tripod.c_str());
599 for (JDetector::const_iterator i = setup.detector.begin(); i != setup.detector.end(); ++i) {
600 receivers[i->getID()] = i->getLocation();
607 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
613 fits.initialise(setup);
615 this->V.
set(setup.detector.getUTMZ());
622 ROOT::EnableThreadSafety();
662 (*this)[module.
getString()].push_back(module);
677 this->parameters = parameters;
683 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
685 if (fits.strings .count(module->getString()) == 0)
686 A.push_back(*module);
687 else if (fits.transmitters.count(module->getString()) != 0)
690 C.push_back(*module);
693 setup.detector.swap(A);
695 for (
const auto& element : B) {
696 setup.detector.push_back(element.second.base);
703 for (
const int i : fits.tripods) {
709 for (
const int i : fits.transmitters) {
715 const double chi2 = fit(*
this);
717 for (
auto& element : B) {
719 const JModule& base = setup.detector.getModule(router->getAddress(
JLocation(element.second.base.getString(),0)));
722 for (string_type::iterator module = element.second.begin(); module != element.second.end(); ++module) {
726 setup.detector.push_back(*module);
730 copy(
C.begin(),
C.end(), back_inserter(setup.detector));
736 STATUS(
"detector: " <<
FIXED(9,4) << chi2 << endl);
750 this->parameters = parameters;
754 for (
const int i : fits.strings) {
760 for (
const int i : fits.tripods) {
766 for (
const int i :
ids_t(fits.hydrophones, fits.transmitters)) {
770 for (
const int i : fits.transmitters) {
772 JModule& module = setup.detector.getModule(router->getAddress(
JLocation(i,0)));
778 const double chi2 = fit(*
this);
780 STATUS(
"detector: " <<
FIXED(9,4) << chi2 << endl);
794 this->parameters = parameters;
800 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
802 buffer[module->getString()].push_back(*module);
804 if (module->getZ() > z0) {
811 for (transmitters_container::iterator i = setup.transmitters.begin(); i != setup.transmitters.end(); ++i) {
813 tx.push_back(router->getModule(i->getLocation()));
815 catch(
const exception&) {}
818 for (
const int i : fits.strings) {
820 setup.detector.swap(buffer[i]);
822 copy(tx.begin(), tx.end(), back_inserter(setup.detector));
831 const double chi2 = fit(*
this);
833 STATUS(
"string: " << setw(4) << i <<
' ' <<
FIXED(9,4) << chi2 << endl);
840 setup.detector.clear();
842 for (
const auto& element : buffer) {
843 copy(element.second.begin(), element.second.end(), back_inserter(setup.detector));
860 this->parameters = parameters;
864 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
865 if (fits.strings.count(module->getString()) != 0 && module->getFloor() != 0) {
870 const double chi2 = fit(*
this);
872 STATUS(
"detector: " <<
FIXED(9,4) << chi2 << endl);
886 this->parameters = parameters;
890 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
891 if (fits.strings.count(module->getString()) != 0 && module->getFloor() == 0) {
896 const double chi2 = fit(*
this);
898 STATUS(
"detector: " <<
FIXED(9,4) << chi2 << endl);
914 this->parameters = parameters;
918 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
919 if (fits.strings.count(module->getString()) != 0 && module->getFloor() != 0) {
926 const double chi2 = fit(*
this);
928 STATUS(
"detector: " <<
FIXED(9,4) << chi2 << endl);
943 const JGeometry geometry(setup.detector, setup.hydrophones);
947 for (tripods_container::const_iterator i = setup.tripods.begin(); i != setup.tripods.end(); ++i) {
949 emitters[i->getID()] =
JEmitter(i->getID(), i->getUTMPosition() - setup.detector.getUTMPosition());
953 for (transmitters_container::const_iterator i = setup.transmitters.begin(); i != setup.transmitters.end(); ++i) {
955 emitters[i->getID()] =
JEmitter(i->getID(), i->getPosition() + router->getModule(i->getLocation()).getPosition());
957 catch(
const exception&) {}
963 this->output.clear();
970 JFremantle fremantle(geometry, V, parameters, threads, 2 * threads);
978 for (input_type::const_iterator evt = superevt.begin(); evt != superevt.end(); ++evt) {
980 if (emitters.
has(evt->getID())) {
982 const JEmitter& emitter = emitters [evt->getID()];
983 const double weight =
getWeight(evt->getID());
985 for (JEvent::const_iterator i = evt->begin(); i != evt->end(); ++i) {
991 receivers[i->getID()],
1008 }
else if (option == 2) {
1013 JPlatypus platypus(geometry, emitters, V, parameters, in, threads);
1020 return numeric_limits<float>::max();
1030 void run(
const std::string& script)
1032 using namespace std;
1033 using namespace JPP;
1035 ifstream in(script.c_str());
1043 if (buffer.empty() || buffer[0] ==
skip_t) {
1047 istringstream is(buffer);
1053 fits.initialise(setup);
1055 }
else if (key ==
fix_t) {
1060 if (is >> type >>
id) {
1062 fits.strings .
fix(
id);
1063 fits.hydrophones .fix(
id);
1064 fits.transmitters.fix(
id);
1066 fits.tripods .fix(
id);
1077 if (is >> stage >> input) {
1079 STATUS(
"stage " << setw(3) << stage <<
" {" << input <<
"}" << endl);
1085 ofstream out(
MAKE_CSTRING(
"stage-" << stage <<
".log"));
1090 switch (stage[stage.size() - 1]) {
1152 void store(
const std::string& dir =
".")
1154 using namespace JPP;
1156 if (
getFileStatus(dir.c_str()) || (mkdir(dir.c_str(), S_IRWXU | S_IRWXG) != -1)) {
1160 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1161 module->set(router->getModule(module->getLocation()).getPosition());
1166 setup.tripods.store(
getFilename(dir, filenames.tripod).c_str());
1168 if (filenames.hydrophone !=
"") { setup.hydrophones .store(
getFilename(dir, filenames.hydrophone) .c_str()); }
1169 if (filenames.transmitter !=
"") { setup.transmitters.store(
getFilename(dir, filenames.transmitter).c_str()); }
1187 for (JDetector::const_iterator i = setup.detector.begin(); i != setup.detector.end(); ++i) {
1189 buffer.insert(i->getID());
1204 using namespace std;
1208 for (tripods_container::const_iterator i = setup.tripods.begin(); i != setup.tripods.end(); ++i) {
1209 buffer.insert(i->getID());
1212 for (transmitters_container::const_iterator i = setup.transmitters.begin(); i != setup.transmitters.end(); ++i) {
1216 const JModule& module = router->getModule(i->getLocation());
1219 buffer.insert(i->getID());
1222 catch(
const exception&) {}
1259 using namespace std;
1260 using namespace JPP;
1265 JLimit_t& numberOfEvents = inputFile.getLimit();
1270 disable_container disable;
1276 JParser<> zap(
"Application to perform acoustic pre-calibration.");
1278 zap[
'f'] =
make_field(inputFile,
"output of JAcousticEventBuilder[.sh]");
1279 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
1282 zap[
's'] =
make_field(script,
"steering script");
1289 zap[
'N'] =
make_field(threads,
"number of threads") = 1;
1294 catch(
const exception &error) {
1295 FATAL(error.what() << endl);
1299 FATAL(
"Invalid number of threads " << threads << endl);
1315 if (emitters.count(evt->
getID())) {
1316 zbuf.push_back(*evt);
1320 sort(zbuf.begin(), zbuf.end());
1322 for (buffer_type::iterator p = zbuf.begin(), q; p != zbuf.end(); p = q) {
1324 for (q = p; ++q != zbuf.end() && q->begin()->getToE() <= p->rbegin()->getToE() + parameters.
Tmax_s; ) {}
1330 for (buffer_type::iterator evt = p; evt != q; ++evt) {
1336 for (JEvent::iterator i = evt->begin(); i != __end; ) {
1341 if (receivers.count(i->getID()) && i->getQ() >= parameters.
Qmin * (parameters.
Qmin <= 1.0 ? i->getW() : 1.0)) {
1346 iter_swap(i, --__end);
1349 buffer.push_back(
JEvent(evt->getDetectorID(), buffer.size(), evt->getID(), evt->begin(), __end));
1353 sydney.
input.push_back(buffer);
ROOT TTree parameter settings.
Data structure for detector geometry and calibration.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General purpose class for hash map of unique elements.
Data structure for hydrophone.
Fit functions of acoustic model.
Direct access to location in detector data structure.
General purpose messaging.
Data structure for optical module.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define MAKE_CSTRING(A)
Make C-string.
#define MAKE_STRING(A)
Make string.
Auxiliary class to define a range between two values.
int main(int argc, char **argv)
Acoustic transmission identifier.
Data structure for transmitter.
Data structure for tripod.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Thread pool for global fits.
static output_type * output
optional output
void enqueue(input_type &data)
Queue data.
static JMATH::JQuantile_t Q
chi2/NDF
Thread pool for global fits using super events.
static JMATH::JQuantile_t Q
chi2/NDF
Router for direct addressing of location data in detector data structure.
Logical location of module.
int getFloor() const
Get floor number.
int getString() const
Get string number.
const JLocation & getLocation() const
Get location.
Data structure for a composite optical module.
bool has(const int bit) const
Test PMT status.
JModule & set(const JVector3D &pos)
Set position.
Auxiliary class for CPU timing and usage.
unsigned long long usec_wall
const JPosition3D & getPosition() const
Get position.
Data structure for vector in three dimensions.
JVector3D & add(const JVector3D &vector)
Add vector.
double getY() const
Get y position.
double getZ() const
Get z position.
double getX() const
Get x position.
int getID() const
Get identifier.
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
Implementation of object output from STD container.
Exception for accessing a value in a collection that is outside of its range.
Utility class to parse command line options.
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
static const int HYDROPHONE_DISABLE
Enable (disable) use of hydrophone if this status bit is 0 (1);.
static const int TRANSMITTER_DISABLE
Enable (disable) use of transmitter if this status bit is 0 (1);.
static const int PIEZO_DISABLE
Enable (disable) use of piezo if this status bit is 0 (1);.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Auxiliary classes and methods for acoustic position calibration.
static const std::string string_t
string
size_t getMinimumNumberOfEmitters(T __begin, T __end)
Get minimum number of emitters for any string in data.
double getWeight(T __begin, T __end)
Get total weight of data points.
static const std::string tripod_t
tripod
JContainer< std::vector< JTripod > > tripods_container
JContainer< std::vector< JTransmitter > > transmitters_container
static const std::string initialise_t
initialise
JContainer< std::vector< JHydrophone > > hydrophones_container
static const char skip_t
Script commands.
static const std::string stage_t
fit stage
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
static const std::string fix_t
fix objects
size_t getNumberOfEmitters(T __begin, T __end)
Get number of emitters.
static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0)
Function object for velocity of sound.
static JDetectorMechanics getMechanics
Function object to get string mechanics.
file Auxiliary data structures and methods for detector calibration.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Auxiliary classes and methods for 3D geometrical objects and operations.
static const JVector3D JVector3X_t(1, 0, 0)
unit x-vector
static const JVector3D JVector3Y_t(0, 1, 0)
unit y-vector
static const JVector3D JVector3Z_t(0, 0, 1)
unit z-vector
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
static const double C
Physics constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< JHitW0 > buffer_type
hits
static JStat getFileStatus
Function object for file status.
Auxiliary data structure for floating point format specification.
detector()
Default constructor.
static void overlap(T p, T q, const double Tmax_s)
Empty overlapping events.
int getID() const
Get emitter identifier.
Auxiliary data structure for handling of file names.
std::string transmitter
transmitter
std::string detector
detector
std::string hydrophone
hydrophone
double Qmin
minimal quality transmission
double deadTime_s
dead time between events [s]
size_t Nmin
minimum number of emitters
double Tmax_s
time window to combine events [s]
bool hasLocation(const JLocation &location) const
Check if this detector has given location.
Template definition of fit function of acoustic model.
Auxiliary data structure for setup of complete system.
tripods_container tripods
tripods
transmitters_container transmitters
transmitters
JDetector detector
detector
Implementation for depth dependend velocity of sound.
JSoundVelocity & set(const double z0)
Set depth.
Auxiliary class to edit orientation of anchor.
virtual void apply(const double step) override
Apply step.
JAnchorEditor(JSetup &setup, const int id)
Constructor.
std::vector< JTransmitter > & transmitters
std::vector< JHydrophone > & hydrophones
Auxiliary class to edit length of Dyneema ropes.
JDyneemaEditor(JSetup &setup, const int id, const double z0=0.0)
Constructor.
std::vector< size_t > index
virtual void apply(const double step) override
Apply step.
Auxiliary class to edit (z) position of module.
virtual void apply(const double step) override
Apply step.
JModuleEditor(JModule &module, const JVector3D &direction)
Constructor.
JModuleEditor(JModule &module)
Constructor.
Extended data structure for parameters of stage.
friend std::ostream & operator<<(std::ostream &out, const JParameters_t &object)
Write parameters to output stream.
JParameters_t()
Default constuctor.
friend std::istream & operator>>(std::istream &in, JParameters_t &object)
Read parameters from input stream.
std::vector< double > steps
Auxiliary class to edit (x,y,z) position of string.
std::vector< size_t > index
JStringEditor(JSetup &setup, const int id, const JVector3D &direction, const bool option)
Constructor.
virtual void apply(const double step) override
Apply step.
Auxiliary class to edit (x,y,z) position of tripod.
JTripodEditor(JSetup &setup, const int id, const JVector3D &direction)
Constructor.
virtual void apply(const double step) override
Apply step.
std::vector< JTripod > & tripods
Auxiliary data structure for detector with decomposed strings.
void push_back(const JModule &module)
Add module.
Auxiliary data structure for group of lists of identifiers of to-be-fitted objects.
ids_t transmitters
identifiers of strings with transmitter
ids_t tripods
identifiers of tripods
void initialise(const JSetup &setup)
Initialise.
ids_t hydrophones
identifiers of strings with hydrophone
fits_t()
Default constructor.
ids_t strings
identifiers of strings
List of object identifiers.
ids_t(const ids_t &A, const ids_t &B)
Difference constructor.
friend std::ostream & operator<<(std::ostream &out, const ids_t &object)
Write identifiers to output stream.
void fix(const ids_t &B)
Fix.
ids_t()
Default constructor.
ids_t(const std::vector< int > &buffer)
Copy constructor.
friend std::istream & operator>>(std::istream &in, ids_t &object)
Read identifiers from input stream.
Auxiliary data structure for decomposed string.
void push_back(const JModule &module)
Add module.
Main class for pre-calibration using acoustics data.
double operator()(const int option) const
Get chi2.
JSydney(const JFilenames &filenames, const JSoundVelocity &V, const size_t threads, const int debug)
Constructor.
void stage_x(const JParameters_t ¶meters)
Fit procedure to determine the (x,y,z) positions of the modules.
ids_t getReceivers() const
Get list of identifiers of receivers.
std::unique_ptr< JLocationRouter > router
JTOOLS::JHashMap< int, JLocation > receivers
void run(const std::string &script)
Run.
void store(const std::string &dir=".")
Store data in given directory.
ids_t getEmitters() const
Get list of identifiers of emitters.
std::vector< input_type > input
void stage_c(const JParameters_t ¶meters)
Fit procedure to determine the z-positions of the modules.
std::vector< JSuperEvt > output
JFitParameters parameters
std::vector< JEvent > input_type
void stage_0(const JParameters_t ¶meters)
Fit procedure to determine the positions of tripods and transmitters using strings that are fixed.
void stage_d(const JParameters_t ¶meters)
Fit procedure to determine the z-positions of anchors.
void stage_b(const JParameters_t ¶meters)
Fit procedure to determine the stretching and z-positions of individual strings.
void stage_a(const JParameters_t ¶meters)
Fit procedure to determine the positions of the strings and tripods.
Acoustic transmission identifier.
int getID() const
Get identifier.
Auxiliary data structure to unify weights of acoustics data according to the number of pings per emit...
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Auxiliary data structure for editable parameter.
Auxiliary data structure for fit parameter.
Implementation of object iteration from STD container.
double getMean() const
Get mean value.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary class for defining the range of iterations of objects.
Auxiliary data structure for floating point format specification.