Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JSydney.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <vector>
5#include <set>
6#include <algorithm>
7#include <limits>
8#include <functional>
9#include <filesystem>
10
11#include <type_traits>
12#include <functional>
13#include <future>
14#include <mutex>
15#include <thread>
16#include <vector>
17#include <queue>
18
19#include "TROOT.h"
20#include "TFile.h"
21
23
24#include "JLang/JPredicate.hh"
25#include "JLang/JComparator.hh"
26#include "JLang/JComparison.hh"
30#include "JLang/JVectorize.hh"
31
34#include "JDetector/JTripod.hh"
36#include "JDetector/JModule.hh"
39
40#include "JFit/JGradient.hh"
41
42#include "JTools/JHashMap.hh"
43#include "JTools/JRange.hh"
44
45#include "JMath/JQuantile_t.hh"
46
48
52#include "JAcoustics/JHit.hh"
55#include "JAcoustics/JEvent.hh"
62
63#include "Jeep/JTimer.hh"
64#include "Jeep/JeepToolkit.hh"
65#include "Jeep/JContainer.hh"
66#include "Jeep/JParser.hh"
67#include "Jeep/JMessage.hh"
68
69
70namespace JACOUSTICS {
71
74 using JEEP::JContainer;
76
77 using namespace JDETECTOR;
78
79
83
84
85 /**
86 * Script commands.
87 */
88 static const char skip_t = '#'; //!< skip line
89 static const std::string initialise_t = "initialise"; //!< initialise
90 static const std::string fix_t = "fix"; //!< fix objects
91 static const std::string string_t = "string"; //!< string
92 static const std::string tripod_t = "tripod"; //!< tripod
93 static const std::string stage_t = "stage"; //!< fit stage
94 static const std::string set_t = "set"; //!< set coordinate of object
95 static const char X_t = 'x'; //!< set x-coordinate
96 static const char Y_t = 'y'; //!< set y-coordinate
97 static const char Z_t = 'z'; //!< set z-coordinate
98
99 /**
100 * Auxiliary data structure for handling of file names.
101 */
102 struct JFilenames {
103 /**
104 * Strip leading and trailing white spaces.
105 *
106 * \return file names
107 */
117
118 std::string detector; //!< detector
119 std::string tripod; //!< tripod
120 std::string hydrophone; //!< hydrophone
121 std::string transmitter; //!< transmitter
122 };
123
124
125 /**
126 * Auxiliary data structure for setup of complete system.
127 */
128 struct JSetup {
129 JDetector detector; //!< detector
130 JDetectorMechanics_t mechanics; //!< mechanical model
132 struct :
134 {
135 /**
136 * Check if there is a hydrophone on given string.
137 *
138 * \param id string identifier
139 * \return true if hydrophone present; else false
140 */
141 bool hasString(const int id) const
142 {
143 using namespace std;
144
145 return (find_if(this->begin(), this->end(), make_predicate(&JHydrophone::getString, id)) != this->end());
146 }
147 } hydrophones; //!< hydrophones
149 };
150
151
152 /**
153 * Main class for pre-calibration using acoustics data.
154 */
155 struct JSydney {
156
157 static constexpr double RADIUS_M = 1.0; //!< maximal horizontal distance between T-bar and emitter/hydrophone
158
159 /**
160 * Auxiliary data structure for fit options.
161 */
162 struct fit_t {
163 /**
164 * Set value of given coordinate.
165 *
166 * \param c coordinate
167 * \param value value
168 */
169 void set(const char c, const bool value)
170 {
171 switch (c) {
172
173 case X_t:
174 this->x = value;
175 break;
176
177 case Y_t:
178 this->y = value;
179 break;
180
181 case Z_t:
182 this->z = value;
183 break;
184 }
185 }
186
187 bool x = true; //!< x-coordinate
188 bool y = true; //!< y-coordinate
189 bool z = true; //!< z-coordinate
190 };
191
192
193 /**
194 * Map object identifiers to fit options.
195 */
196 struct ids_t :
197 public std::map<int, fit_t>
198 {
200
201 using map_type::insert;
202 using map_type::erase;
203
204
205 /**
206 * Default constructor.
207 */
209 {}
210
211
212 /**
213 * Copy constructor.
214 *
215 * \param buffer list of identifiers
216 */
217 ids_t(const array_type<int>& buffer)
218 {
219 for (const int i : buffer) {
220 this->insert(i);
221 }
222 }
223
224
225 /**
226 * Difference constructor.
227 * Make list of all object identifiers in A that are not in B.
228 *
229 * \param A list of identifiers
230 * \param B list of identifiers
231 */
232 ids_t(const ids_t& A,
233 const ids_t& B) :
234 ids_t(A)
235 {
236 erase(B);
237 }
238
239
240 /**
241 * Insert identifier.
242 *
243 * \param id identifier
244 */
245 void insert(const int id)
246 {
247 this->insert(std::make_pair(id, fit_t()));
248 }
249
250
251 /**
252 * Erase elements that are in given list of identifiers.
253 *
254 * \param B list of identifiers
255 */
256 void erase(const ids_t& B)
257 {
258 for (const auto& i : B) {
259 this->erase(i.first);
260 }
261 }
262
263
264 /**
265 * Set fit options of elements to result of given logical operator combined with fit options in given list of identifiers.
266 *
267 * \param B list of identifiers
268 * \param OP operator
269 */
270 template<class T>
271 void set(const ids_t& B, const T& OP)
272 {
273 for (const auto i : B) {
274
275 iterator p = this->find(i.first);
276
277 if (p != this->end()) {
278 p->second.x = OP(p->second.x, i.second.x);
279 p->second.y = OP(p->second.y, i.second.y);
280 p->second.z = OP(p->second.z, i.second.z);
281 }
282 }
283 }
284
285
286 /**
287 * Set fit option of all elements for given coordinate.
288 *
289 * \param c coordinate
290 * \param value value
291 */
292 void set(const char c, const bool value)
293 {
294 for (iterator i = this->begin(); i != this->end(); ++i) {
295 i->second.set(c, value);
296 }
297 }
298
299
300 /**
301 * Read identifiers from input stream
302 *
303 * \param in input stream
304 * \param object identifiers
305 * \return input stream
306 */
307 friend inline std::istream& operator>>(std::istream& in, ids_t& object)
308 {
309 for (int id; in >> id; ) {
310 object.insert(id);
311 }
312
313 if (!in.bad()) {
314 in.clear();
315 }
316
317 return in;
318 }
319
320
321 /**
322 * Write identifiers and fit options to output stream
323 *
324 * \param out output stream
325 * \param object identifiers
326 * \return output stream
327 */
328 friend inline std::ostream& operator<<(std::ostream& out, const ids_t& object)
329 {
330 for (const auto& i : object) {
331 out << ' ' << i.first
332 << '.'
333 << (i.second.x ? X_t : ' ')
334 << (i.second.y ? Y_t : ' ')
335 << (i.second.z ? Z_t : ' ');
336 }
337
338 return out;
339 }
340 };
341
342
343 /**
344 * Auxiliary data structure for group of lists of identifiers of to-be-fitted objects.
345 */
346 struct fits_t {
347 /**
348 * Default constructor.
349 */
351 {}
352
353
354 /**
355 * Initialise.
356 *
357 * \param setup setup
358 */
360 {
361 using namespace JPP;
362
363 strings = make_array(setup.detector .begin(), setup.detector .end(), &JModule ::getString);
364 tripods = make_array(setup.tripods .begin(), setup.tripods .end(), &JTripod ::getID);
365 hydrophones = make_array(setup.hydrophones .begin(), setup.hydrophones .end(), &JHydrophone ::getString);
366 transmitters = make_array(setup.transmitters.begin(), setup.transmitters.end(), &JTransmitter::getString);
367 }
368
369 ids_t strings; //!< identifiers of strings
370 ids_t tripods; //!< identifiers of tripods
371 ids_t hydrophones; //!< identifiers of strings with hydrophone
372 ids_t transmitters; //!< identifiers of strings with transmitter
373 };
374
375
376 /**
377 * Auxiliary class to edit (z) position of module.
378 */
380 public JParameter_t
381 {
382 /**
383 * Constructor.
384 *
385 * \param module module
386 */
391
392
393 /**
394 * Constructor.
395 *
396 * \param module module
397 * \param direction direction
398 */
403
404
405 /**
406 * Apply step.
407 *
408 * \param step step
409 */
410 virtual void apply(const double step) override
411 {
412 using namespace JPP;
413
414 module.add(direction * step);
415 }
416
417 private:
420 };
421
422
423 /**
424 * Auxiliary class to edit (x,y,z) position of string.
425 */
427 public JParameter_t
428 {
429 /**
430 * Constructor.
431 *
432 * The option <tt>true</tt> and <tt>false</tt> correspond to all modules and optical modules only, respectively.
433 *
434 * \param setup setup
435 * \param id string number
436 * \param direction direction
437 * \param option option
438 */
439 JStringEditor(JSetup& setup, const int id, const JVector3D& direction, const bool option) :
442 {
443 for (size_t i = 0; i != detector.size(); ++i) {
444 if (detector[i].getString() == id && (detector[i].getFloor() != 0 || option)) {
445 index.push_back(i);
446 }
447 }
448 }
449
450
451 /**
452 * Apply step.
453 *
454 * \param step step
455 */
456 virtual void apply(const double step) override
457 {
458 for (const auto i : index) {
459 detector[i].add(direction * step);
460 }
461 }
462
463 private:
467 };
468
469
470 /**
471 * Auxiliary class to edit length of Dyneema ropes.
472 */
474 public JParameter_t
475 {
476 /**
477 * Constructor.
478 *
479 * \param setup setup
480 * \param id string number
481 * \param z0 reference position
482 */
483 JDyneemaEditor(JSetup& setup, const int id, const double z0 = 0.0) :
485 z0 (z0)
486 {
487 for (size_t i = 0; i != detector.size(); ++i) {
488 if (detector[i].getString() == id && detector[i].getFloor() != 0) {
489 index.push_back(i);
490 }
491 }
492 }
493
494
495 /**
496 * Apply step.
497 *
498 * \param step step
499 */
500 virtual void apply(const double step) override
501 {
502 for (const auto i : index) {
503
504 JModule& module = detector[i];
505
506 if (step > 0.0)
507 module.set(JVector3D(module.getX(), module.getY(), z0 + (module.getZ() - z0) * (1.0 + step)));
508 else if (step < 0.0)
509 module.set(JVector3D(module.getX(), module.getY(), z0 + (module.getZ() - z0) / (1.0 - step)));
510 }
511 }
512
513 private:
515 double z0;
517 };
518
519
520 /**
521 * Auxiliary class to edit (x,y,z) position of tripod.
522 */
524 public JParameter_t
525 {
526 /**
527 * Constructor.
528 *
529 * \param setup setup
530 * \param id tripod identifier
531 * \param direction direction
532 */
533 JTripodEditor(JSetup& setup, const int id, const JVector3D& direction) :
536 {
537 using namespace std;
538 using namespace JPP;
539
540 index = distance(tripods.begin(), find_if(tripods.begin(), tripods.end(), make_predicate(&JTripod::getID, id)));
541 }
542
543
544 /**
545 * Apply step.
546 *
547 * \param step step
548 */
549 virtual void apply(const double step) override
550 {
551 tripods[index].add(direction * step);
552 }
553
554 private:
557 size_t index;
558 };
559
560
561 /**
562 * Auxiliary class to edit orientation of anchor.
563 */
565 public JParameter_t
566 {
567 /**
568 * Constructor.
569 *
570 * \param setup setup
571 * \param id string identifier
572 */
573 JAnchorEditor(JSetup& setup, const int id) :
576 {
577 using namespace std;
578 using namespace JPP;
579
580 index[0] = distance(hydrophones .begin(), find_if(hydrophones .begin(), hydrophones .end(), make_predicate(&JHydrophone ::getString, id)));
581 index[1] = distance(transmitters.begin(), find_if(transmitters.begin(), transmitters.end(), make_predicate(&JTransmitter::getString, id)));
582 }
583
584
585 /**
586 * Apply step.
587 *
588 * \param step step
589 */
590 virtual void apply(const double step) override
591 {
592 using namespace JPP;
593
594 const JRotation3Z R(step);
595
596 if (index[0] != hydrophones .size()) { hydrophones [index[0]].rotate(R); }
597 if (index[1] != transmitters.size()) { transmitters[index[1]].rotate(R); }
598 }
599
600 private:
603 size_t index[2];
604 };
605
606
607 /**
608 * Extended data structure for parameters of stage.
609 */
611 public JFitParameters
612 {
613 /**
614 * Default constuctor.
615 */
617 Nmax (std::numeric_limits<size_t>::max()),
618 Nextra (0),
619 epsilon(1.0e-4),
620 debug (3)
621 {}
622
623
624 /**
625 * Read parameters from input stream
626 *
627 * \param in input stream
628 * \param object parameters
629 * \return input stream
630 */
631 friend inline std::istream& operator>>(std::istream& in, JParameters_t& object)
632 {
633 object = JParameters_t();
634
635 in >> object.option
636 >> object.mestimator
637 >> object.sigma_s
638 >> object.stdev
639 >> object.Nextra;
640
641 if (in) {
642
643 for (double value; in >> value; ) {
644 object.steps.push_back(value);
645 }
646
647 if (!in.bad()) {
648 in.clear();
649 }
650 }
651
652 return in;
653 }
654
655
656 /**
657 * Write parameters to output stream
658 *
659 * \param out output stream
660 * \param object parameters
661 * \return output stream
662 */
663 friend inline std::ostream& operator<<(std::ostream& out, const JParameters_t& object)
664 {
665 using namespace std;
666
667 out << setw(2) << object.option << ' '
668 << setw(2) << object.mestimator << ' '
669 << SCIENTIFIC(9,3) << object.sigma_s << ' '
670 << SCIENTIFIC(9,3) << object.stdev << ' '
671 << setw(3) << object.Nextra;
672
673 for (const double value : object.steps) {
674 out << ' ' << FIXED(9,5) << value;
675 }
676
677 return out;
678 }
679
680 size_t Nmax;
681 size_t Nextra;
682 double epsilon;
683 int debug;
685 };
686
687
688 /**
689 * Constructor.
690 *
691 * \param filenames file names
692 * \param mechanics mechanical model parameters
693 * \param V sound velocity
694 * \param threads threads
695 * \param debug debug
696 */
698 const JDetectorMechanics_t& mechanics,
699 const JSoundVelocity& V,
700 const size_t threads,
701 const int debug) :
703 V(V),
705 debug(debug)
706 {
707 load(filenames.detector, setup.detector);
708
709 setup.mechanics = mechanics;
710 setup.tripods.load(filenames.tripod.c_str());
711
712 if (filenames.hydrophone != "") { setup.hydrophones .load(filenames.hydrophone .c_str()); }
713 if (filenames.transmitter != "") { setup.transmitters.load(filenames.transmitter.c_str()); }
714
715 for (JDetector::const_iterator i = setup.detector.begin(); i != setup.detector.end(); ++i) {
716 receivers[i->getID()] = i->getLocation();
717 }
718
719 // detach PMTs
720
721 detector = setup.detector;
722
723 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
724 module->clear();
725 }
726
727 router.reset(new JLocationRouter(setup.detector));
728
730
731 this->V.set(setup.detector.getUTMZ()); // sound velocity at detector depth
732
735
737
738 ROOT::EnableThreadSafety();
739 }
740
741
742 /**
743 * Auxiliary data structure for decomposed string.
744 */
745 struct string_type :
746 public std::vector<JModule> // optical modules
747 {
748 /**
749 * Add module.
750 *
751 * \param module module
752 */
753 void push_back(const JModule& module)
754 {
755 if (module.getFloor() == 0)
756 this->base = module;
757 else
759 }
760
761 JModule base; // base module
762 };
763
764
765 /**
766 * Auxiliary data structure for detector with decomposed strings.
767 */
769 public std::map<int, string_type>
770 {
771 /**
772 * Add module.
773 *
774 * \param module module
775 */
776 void push_back(const JModule& module)
777 {
778 (*this)[module.getString()].push_back(module);
779 }
780 };
781
782
783 /**
784 * Fit procedure to determine the positions of tripods and transmitters using strings that are fixed.
785 *
786 * \param parameters parameters
787 */
789 {
790 using namespace std;
791 using namespace JPP;
792
793 this->parameters = parameters;
794
795 JDetector A; // old strings
796 detector_type B; // new strings with transmitter -> fit only base module
797 JDetector C; // new strings w/o transmitter -> discard completely from fit
798
799 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
800
801 if (fits.strings .count(module->getString()) == 0)
802 A.push_back(*module);
803 else if (fits.transmitters.count(module->getString()) != 0)
804 B.push_back(*module);
805 else
806 C.push_back(*module);
807 }
808
809 setup.detector.swap(A);
810
811 for (const auto& element : B) {
812 setup.detector.push_back(element.second.base);
813 }
814
815 router.reset(new JLocationRouter(setup.detector));
816
817 JGradient fit(parameters.Nmax, parameters.Nextra, parameters.epsilon, parameters.debug);
818
819 for (const auto& i : fits.tripods) {
820 if (i.second.x) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "tripod.x: " << RIGHT(4) << i.first), new JTripodEditor(setup, i.first, JVector3X_t), parameters.steps[0])); }
821 if (i.second.y) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "tripod.y: " << RIGHT(4) << i.first), new JTripodEditor(setup, i.first, JVector3Y_t), parameters.steps[0])); }
822 if (i.second.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "tripod.z: " << RIGHT(4) << i.first), new JTripodEditor(setup, i.first, JVector3Z_t), parameters.steps[0])); }
823 }
824
825 for (const auto& i : fits.transmitters) {
826 if (i.second.x) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "transmitter.x: " << RIGHT(4) << i.first), new JStringEditor(setup, i.first, JVector3X_t, true), parameters.steps[0])); }
827 if (i.second.y) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "transmitter.y: " << RIGHT(4) << i.first), new JStringEditor(setup, i.first, JVector3Y_t, true), parameters.steps[0])); }
828 if (i.second.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "transmitter.z: " << RIGHT(4) << i.first), new JStringEditor(setup, i.first, JVector3Z_t, true), parameters.steps[0])); }
829 }
830
831 const double chi2 = fit(*this);
832
833 for (auto& element : B) {
834
835 const JModule& base = setup.detector.getModule(router->getAddress(JLocation(element.second.base.getString(),0)));
836 const JVector3D pos = base.getPosition() - element.second.base.getPosition();
837
838 for (string_type::iterator module = element.second.begin(); module != element.second.end(); ++module) {
839
840 module->add(pos);
841
842 setup.detector.push_back(*module);
843 }
844 }
845
846 copy(C.begin(), C.end(), back_inserter(setup.detector));
847
848 sort(setup.detector.begin(), setup.detector.end(), make_comparator(&JModule::getLocation));
849
850 router.reset(new JLocationRouter(setup.detector));
851
852 STATUS("detector: " << FIXED(9,4) << chi2 << endl);
853 }
854
855
856 /**
857 * Fit procedure to determine the positions of the strings and tripods.
858 *
859 * \param parameters parameters
860 */
862 {
863 using namespace std;
864 using namespace JPP;
865
866 this->parameters = parameters;
867
868 JGradient fit(parameters.Nmax, parameters.Nextra, parameters.epsilon, parameters.debug);
869
870 for (const auto& i : fits.strings) {
871 if (i.second.x) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "string.x: " << RIGHT(4) << i.first), new JStringEditor(setup, i.first, JVector3X_t, true), parameters.steps[0])); }
872 if (i.second.y) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "string.y: " << RIGHT(4) << i.first), new JStringEditor(setup, i.first, JVector3Y_t, true), parameters.steps[0])); }
873 if (i.second.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "string.z: " << RIGHT(4) << i.first), new JStringEditor(setup, i.first, JVector3Z_t, false), parameters.steps[0])); }
874 }
875
876 for (const auto& i : fits.tripods) {
877 if (i.second.x) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "tripod.x: " << RIGHT(4) << i.first), new JTripodEditor(setup, i.first, JVector3X_t), parameters.steps[1])); }
878 if (i.second.y) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "tripod.y: " << RIGHT(4) << i.first), new JTripodEditor(setup, i.first, JVector3Y_t), parameters.steps[1])); }
879 if (i.second.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "tripod.z: " << RIGHT(4) << i.first), new JTripodEditor(setup, i.first, JVector3Z_t), parameters.steps[1])); }
880 }
881
882 for (const auto& i : ids_t(fits.hydrophones, fits.transmitters)) {
883 fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "anchor.R: " << RIGHT(4) << i.first), new JAnchorEditor(setup, i.first), parameters.steps[0] / RADIUS_M));
884 }
885
886 for (const auto& i : fits.transmitters) {
887
888 JModule& module = setup.detector.getModule(router->getAddress(JLocation(i.first,0)));
889
890 if (true) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "anchor.R: " << RIGHT(4) << i.first), new JAnchorEditor(setup, i.first), parameters.steps[0] / RADIUS_M)); }
891 if (i.second.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "anchor.z: " << RIGHT(4) << i.first), new JModuleEditor(module), parameters.steps[0])); }
892 }
893
894 const double chi2 = fit(*this);
895
896 STATUS("detector: " << FIXED(9,4) << chi2 << endl);
897 }
898
899
900 /**
901 * Fit procedure to determine the stretching and z-positions of individual strings.
902 *
903 * \param parameters parameters
904 */
906 {
907 using namespace std;
908 using namespace JPP;
909
910 this->parameters = parameters;
911
912 map<int, JDetector> buffer;
913
914 double z0 = 0.0;
915
916 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
917
918 buffer[module->getString()].push_back(*module);
919
920 if (module->getZ() > z0) {
921 z0 = module->getZ();
922 }
923 }
924
925 JDetector tx;
926
927 for (transmitters_container::iterator i = setup.transmitters.begin(); i != setup.transmitters.end(); ++i) {
928 try {
929 tx.push_back(router->getModule(i->getLocation()));
930 }
931 catch(const exception&) {}
932 }
933
934 for (const auto& i : fits.strings) {
935
936 setup.detector.swap(buffer[i.first]);
937
938 copy(tx.begin(), tx.end(), back_inserter(setup.detector));
939
940 router.reset(new JLocationRouter(setup.detector));
941
942 JGradient fit(parameters.Nmax, parameters.Nextra, parameters.epsilon, parameters.debug);
943
944 if (i.second.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "string.M: " << RIGHT(4) << i.first), new JDyneemaEditor(setup, i.first, z0), parameters.steps[0])); }
945 if (i.second.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "string.z: " << RIGHT(4) << i.first), new JStringEditor (setup, i.first, JVector3Z_t, false), parameters.steps[1])); }
946
947 const double chi2 = fit(*this);
948
949 STATUS("string: " << setw(4) << i.first << ' ' << FIXED(9,4) << chi2 << endl);
950
951 buffer[i.first].clear();
952
953 copy_if(setup.detector.begin(), setup.detector.end(), back_inserter(buffer[i.first]), make_predicate(&JModule::getString, i.first));
954 }
955
956 setup.detector.clear();
957
958 for (const auto& element : buffer) {
959 copy(element.second.begin(), element.second.end(), back_inserter(setup.detector));
960 }
961
962 router.reset(new JLocationRouter(setup.detector));
963 }
964
965
966 /**
967 * Fit procedure to determine the z-positions of the modules.
968 *
969 * \param parameters parameters
970 */
972 {
973 using namespace std;
974 using namespace JPP;
975
976 this->parameters = parameters;
977
978 JGradient fit(parameters.Nmax, parameters.Nextra, parameters.epsilon, parameters.debug);
979
980 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
981 if (fits.strings.count(module->getString()) != 0 && module->getFloor() != 0) {
982 fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "module.z: " << right << module->getLocation()), new JModuleEditor(*module), parameters.steps[0]));
983 }
984 }
985
986 const double chi2 = fit(*this);
987
988 STATUS("detector: " << FIXED(9,4) << chi2 << endl);
989 }
990
991
992 /**
993 * Fit procedure to determine the z-positions of anchors.
994 *
995 * \param parameters parameters
996 */
998 {
999 using namespace std;
1000 using namespace JPP;
1001
1002 this->parameters = parameters;
1003
1004 JGradient fit(parameters.Nmax, parameters.Nextra, parameters.epsilon, parameters.debug);
1005
1006 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
1007
1008 if (fits.strings.count(module->getString()) != 0 && module->getFloor() == 0) {
1009
1010 const fit_t fcc = fits.strings.at(module->getString());
1011
1012 if (fcc.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "module.z: " << right << module->getLocation()), new JModuleEditor(*module), parameters.steps[0])); }
1013 }
1014 }
1015
1016 const double chi2 = fit(*this);
1017
1018 STATUS("detector: " << FIXED(9,4) << chi2 << endl);
1019 }
1020
1021
1022 /**
1023 * Fit procedure to determine the (x,y,z) positions of the modules.
1024 * This procedure should be considered unorthodox - it can be used to modify the detector file in such a way
1025 * to accommodate anomalies in the shapes of a string (e.g. entanglement of string in D0ORCA018).
1026 *
1027 * \param parameters parameters
1028 */
1030 {
1031 using namespace std;
1032 using namespace JPP;
1033
1034 this->parameters = parameters;
1035
1036 JGradient fit(parameters.Nmax, parameters.Nextra, parameters.epsilon, parameters.debug);
1037
1038 for (JDetector::iterator module = setup.detector.begin(); module != setup.detector.end(); ++module) {
1039
1040 if (fits.strings.count(module->getString()) != 0 && module->getFloor() != 0) {
1041
1042 const fit_t fcc = fits.strings.at(module->getString());
1043
1044 if (fcc.x) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "module.x: " << right << module->getLocation()), new JModuleEditor(*module, JVector3X_t), parameters.steps[0])); }
1045 if (fcc.y) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "module.y: " << right << module->getLocation()), new JModuleEditor(*module, JVector3Y_t), parameters.steps[0])); }
1046 if (fcc.z) { fit.push_back(JModifier_t(MAKE_STRING(LEFT(16) << "module.z: " << right << module->getLocation()), new JModuleEditor(*module, JVector3Z_t), parameters.steps[0])); }
1047 }
1048 }
1049
1050 const double chi2 = fit(*this);
1051
1052 STATUS("detector: " << FIXED(9,4) << chi2 << endl);
1053 }
1054
1055
1056 /**
1057 * Get chi2.
1058 *
1059 * \param option option
1060 * \return chi2/NDF
1061 */
1062 double operator()(const int option) const
1063 {
1064 using namespace std;
1065 using namespace JPP;
1066
1067 const JGeometry geometry(setup.detector, setup.mechanics, setup.hydrophones);
1068
1069 JHashMap<int, JEmitter> emitters;
1070
1071 for (tripods_container::const_iterator i = setup.tripods.begin(); i != setup.tripods.end(); ++i) {
1072 {
1073 emitters[i->getID()] = JEmitter(i->getID(), i->getUTMPosition() - setup.detector.getUTMPosition());
1074 }
1075 }
1076
1077 for (transmitters_container::const_iterator i = setup.transmitters.begin(); i != setup.transmitters.end(); ++i) {
1078 try {
1079 emitters[i->getID()] = JEmitter(i->getID(), i->getPosition() + router->getModule(i->getLocation()).getPosition());
1080 }
1081 catch(const exception&) {} // if no module available, discard transmitter
1082 }
1083
1084 if (option == 0 || // step wise improvement of the chi2
1085 option == 1) { // evaluation of the chi2 before the determination of the gradient of the chi2
1086
1087 this->output.clear();
1088
1089 JSTDObjectWriter<JSuperEvt> out(this->output); // write data for subsequent use
1090
1091 JFremantle::output = (option == 1 ? &out : NULL);
1092
1093 {
1094 JFremantle fremantle(geometry, V, parameters, threads, 2 * threads);
1095
1096 for (const input_type& superevt : input) {
1097
1098 const JWeight getWeight(superevt.begin(), superevt.end());
1099
1100 vector<JHit> data;
1101
1102 for (input_type::const_iterator evt = superevt.begin(); evt != superevt.end(); ++evt) {
1103
1104 if (emitters.has(evt->getID())) {
1105
1106 const JEmitter& emitter = emitters [evt->getID()];
1107 const double weight = getWeight(evt->getID());
1108
1109 for (JEvent::const_iterator i = evt->begin(); i != evt->end(); ++i) {
1110
1111 if (geometry.hasLocation(receivers[i->getID()])) {
1112
1113 data.push_back(JHit(emitter,
1114 distance(superevt.begin(), evt),
1115 receivers[i->getID()],
1116 i->getToA(),
1118 weight));
1119 }
1120 }
1121 }
1122 }
1123
1124 if (getMinimumNumberOfEmitters(data.begin(), data.end()) >= parameters.Nmin) {
1125 fremantle.enqueue(data);
1126 }
1127 }
1128 }
1129
1130 return JFremantle::Q.getMean(numeric_limits<float>::max());
1131
1132 } else if (option == 2) { // evaluation of the derivative of the chi2 to each fit parameter
1133
1134 {
1136
1137 JPlatypus platypus(geometry, emitters, V, parameters, in, threads);
1138 }
1139
1140 return JPlatypus::Q.getMean(numeric_limits<float>::max());
1141
1142 } else {
1143
1144 return numeric_limits<float>::max();
1145 }
1146 }
1147
1148
1149 /**
1150 * Run.
1151 *
1152 * \param script steering script
1153 */
1154 void run(const std::string& script)
1155 {
1156 using namespace std;
1157 using namespace JPP;
1158
1159 ifstream in(script.c_str());
1160
1161 while (in) {
1162
1163 string buffer, key;
1164
1165 if (getline(in, buffer)) {
1166
1167 if (buffer.empty() || buffer[0] == skip_t) {
1168 continue;
1169 }
1170
1171 istringstream is(buffer);
1172
1173 is >> key;
1174
1175 if (key == initialise_t) { // set object identifiers
1176
1178
1179 } else if (key == fix_t) { // fix object identifiers
1180
1181 string type; // type of object
1182 ids_t id; // identifiers
1183
1184 if (is >> type >> id) {
1185 if (type == string_t) {
1186 fits.strings .erase(id);
1187 fits.hydrophones .erase(id);
1189 } else if (type == tripod_t) {
1190 fits.tripods .erase(id);
1191 } else {
1192 THROW(JValueOutOfRange, "Invalid type <" << type << ">");
1193 }
1194 }
1195
1196 } else if (key == set_t) { // set coordinates
1197
1198 string type; // type of object
1199 char c; // coordinate
1200 ids_t id; // identifiers
1201
1202 if (is >> type >> c >> id) {
1203
1204 if (c == X_t ||
1205 c == Y_t ||
1206 c == Z_t) {
1207
1208 id.set(c, false);
1209
1210 if (type == string_t) {
1211 fits.strings .set(id, logical_and());
1212 fits.hydrophones .set(id, logical_and());
1213 fits.transmitters.set(id, logical_and());
1214 } else if (type == tripod_t) {
1215 fits.tripods .set(id, logical_and());
1216 } else {
1217 THROW(JValueOutOfRange, "Invalid type <" << type << ">; possible values " << string_t << " or " << tripod_t);
1218 }
1219
1220 } else {
1221 THROW(JValueOutOfRange, "Invalid coordinate <" << c << ">; possible values " << X_t << ", " << Y_t << " or " << Z_t);
1222 }
1223 }
1224
1225 } else if (key == stage_t) { // stage
1226
1227 string stage;
1229
1230 if (is >> stage >> input) {
1231
1232 STATUS("stage " << setw(3) << stage << " {" << input << "}" << endl);
1233
1234 JTimer timer;
1235
1236 timer.start();
1237
1238 ofstream out(MAKE_CSTRING("stage-" << stage << ".log"));
1239
1240 {
1241 JRedirectStream redirect(cout, out);
1242
1243 switch (stage[stage.size() - 1]) {
1244
1245 case '0':
1246 stage_0(input);
1247 break;
1248
1249 case 'a':
1250 case 'A':
1251 stage_a(input);
1252 break;
1253
1254 case 'b':
1255 case 'B':
1256 stage_b(input);
1257 break;
1258
1259 case 'c':
1260 case 'C':
1261 stage_c(input);
1262 break;
1263
1264 case 'd':
1265 case 'D':
1266 stage_d(input);
1267 break;
1268
1269 case 'x':
1270 case 'X':
1271 stage_x(input);
1272 break;
1273
1274 default:
1275 THROW(JValueOutOfRange, "Invalid stage <" << stage << ">");
1276 break;
1277 }
1278 }
1279
1280 out.close();
1281
1282 store(stage);
1283 store();
1284
1285 timer.stop();
1286
1287 STATUS("Elapsed time " << FIXED(12,3) << timer.usec_wall * 1.0e-6 << " s." << endl);
1288 }
1289
1290 } else {
1291 THROW(JValueOutOfRange, "Invalid key <" << key << ">");
1292 }
1293 }
1294 }
1295
1296 in.close();
1297 }
1298
1299
1300 /**
1301 * Store data in given directory.
1302 *
1303 * \param dir directory
1304 */
1305 void store(const std::string& dir = ".")
1306 {
1307 using namespace std;
1308 using namespace JPP;
1309
1310 error_code error;
1311
1312 if (filesystem::is_directory(dir, error) || filesystem::create_directory(dir)) {
1313
1314 // attach PMTs
1315
1316 for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1317 module->set(router->getModule(module->getLocation()).getPosition());
1318 }
1319
1321
1322 setup.tripods.store(getFilename(dir, filenames.tripod).c_str());
1323
1324 if (filenames.hydrophone != "") { setup.hydrophones .store(getFilename(dir, filenames.hydrophone) .c_str()); }
1325 if (filenames.transmitter != "") { setup.transmitters.store(getFilename(dir, filenames.transmitter).c_str()); }
1326
1327 } else {
1328
1329 THROW(JValueOutOfRange, "Invalid directory <" << dir << ">");
1330 }
1331 }
1332
1333
1334 /**
1335 * Get list of identifiers of receivers.
1336 *
1337 * \return list of identifiers
1338 */
1340 {
1341 ids_t buffer;
1342
1343 for (JDetector::const_iterator i = setup.detector.begin(); i != setup.detector.end(); ++i) {
1344 if ((i->getFloor() != 0 && !i->has(PIEZO_DISABLE)) || (setup.hydrophones.hasString(i->getString()) && !i->has(HYDROPHONE_DISABLE))) {
1345 buffer.insert(i->getID());
1346 }
1347 }
1348
1349 return buffer;
1350 }
1351
1352
1353 /**
1354 * Get list of identifiers of emitters.
1355 *
1356 * \return list of identifiers
1357 */
1359 {
1360 using namespace std;
1361
1362 ids_t buffer;
1363
1364 for (tripods_container::const_iterator i = setup.tripods.begin(); i != setup.tripods.end(); ++i) {
1365 buffer.insert(i->getID());
1366 }
1367
1368 for (transmitters_container::const_iterator i = setup.transmitters.begin(); i != setup.transmitters.end(); ++i) {
1369
1370 try {
1371
1372 const JModule& module = router->getModule(i->getLocation());
1373
1374 if (!module.has(TRANSMITTER_DISABLE)) {
1375 buffer.insert(i->getID());
1376 }
1377 }
1378 catch(const exception&) {}
1379 }
1380
1381 return buffer;
1382 }
1383
1384
1387 size_t threads;
1391
1393 std::unique_ptr<JLocationRouter> router;
1394
1397
1398 private:
1400
1403 };
1404}
1405
1406
1407/**
1408 * \file
1409 *
1410 * Application to perform acoustic pre-calibration.
1411 * \author mdejong
1412 */
1413int main(int argc, char **argv)
1414{
1415 using namespace std;
1416 using namespace JPP;
1417
1418 typedef JContainer< std::set<JTransmission_t> > disable_container;
1419
1421 JLimit_t& numberOfEvents = inputFile.getLimit();
1422 JFilenames filenames; // file names
1423 JFitParameters parameters; // fit parameters
1424 string script; // script file
1425 JSoundVelocity V = getSoundVelocity; // default sound velocity
1426 JDetectorMechanics mechanics; // mechanical model data
1427 disable_container disable; // disable tansmissions
1428 size_t threads; // number of threads
1429 int debug;
1430
1431 try {
1432
1433 JParser<> zap("Application to perform acoustic pre-calibration.");
1434
1435 zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]");
1436 zap['n'] = make_field(numberOfEvents) = JLimit::max();
1437 zap['a'] = make_field(filenames.detector);
1438 zap['@'] = make_field(parameters) = JPARSER::initialised();
1439 zap['s'] = make_field(script, "steering script");
1440 zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
1441 zap['T'] = make_field(filenames.tripod, "tripod file");
1442 zap['Y'] = make_field(filenames.transmitter, "transmitter file") = JPARSER::initialised();
1443 zap['H'] = make_field(filenames.hydrophone, "hydrophone file") = JPARSER::initialised();
1444 zap['M'] = make_field(mechanics, "mechanics data") = JPARSER::initialised();
1445 zap['!'] = make_field(disable, "disable transmission") = JPARSER::initialised();
1446 zap['N'] = make_field(threads, "number of threads") = 1;
1447 zap['d'] = make_field(debug) = 1;
1448
1449 zap(argc, argv);
1450 }
1451 catch(const exception &error) {
1452 FATAL(error.what() << endl);
1453 }
1454
1455 if (threads == 0) {
1456 FATAL("Invalid number of threads " << threads << endl);
1457 }
1458
1459 JSydney sydney(filenames.strip(), mechanics, V, threads, debug);
1460
1461 const JSydney::ids_t receivers = sydney.getReceivers();
1462 const JSydney::ids_t emitters = sydney.getEmitters();
1463
1465
1466 buffer_type zbuf;
1467
1468 while (inputFile.hasNext()) {
1469
1470 const JEvent* evt = inputFile.next();
1471
1472 if (emitters.count(evt->getID())) {
1473 zbuf.push_back(*evt);
1474 }
1475 }
1476
1477 sort(zbuf.begin(), zbuf.end()); // sort according first time-of-emission
1478
1479 for (buffer_type::iterator p = zbuf.begin(), q; p != zbuf.end(); p = q) {
1480
1481 for (q = p; ++q != zbuf.end() && q->begin()->getToE() <= p->rbegin()->getToE() + parameters.Tmax_s; ) {}
1482
1483 JEvent::overlap(p, q, parameters.deadTime_s); // empty overlapping events
1484
1485 JSydney::input_type buffer;
1486
1487 for (buffer_type::iterator evt = p; evt != q; ++evt) {
1488
1489 sort(evt->begin(), evt->end(), JKatoomba<>::compare);
1490
1491 JEvent::iterator __end = unique(evt->begin(), evt->end(), make_comparator(&JTransmission::getID, JComparison::eq()));
1492
1493 for (JEvent::iterator i = evt->begin(); i != __end; ) {
1494
1495 if (disable.count(JTransmission_t(evt->getID(), i->getID())) == 0 &&
1496 disable.count(JTransmission_t(-1, i->getID())) == 0) {
1497
1498 if (receivers.count(i->getID()) && i->getQ() >= parameters.Qmin * (parameters.Qmin <= 1.0 ? i->getW() : 1.0)) {
1499 ++i; continue;
1500 }
1501 }
1502
1503 iter_swap(i, --__end);
1504 }
1505
1506 buffer.push_back(JEvent(evt->getDetectorID(), buffer.size(), evt->getID(), evt->begin(), __end));
1507 }
1508
1509 if (getNumberOfEmitters(buffer.begin(), buffer.end()) >= parameters.Nmin) {
1510 sydney.input.push_back(buffer);
1511 }
1512 }
1513
1514 sydney.run(script);
1515}
Acoustics toolkit.
Acoustic event.
Acoustic hit.
ROOT TTree parameter settings.
Container I/O.
Data structure for detector geometry and calibration.
Acoustic emitter.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Acoustic fit parameters.
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.
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
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
Definition JParser.hh:2107
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:57
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:48
Auxiliary class to define a range between two values.
Sound velocity.
Acoustic super event fit toolkit.
Acoustic event fit.
Acoustic transmission identifier.
Data structure for transmitter.
Data structure for tripod.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
Auxiliary methods for handling file names, type names and environment.
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
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of location data in detector data structure.
Logical location of module.
Definition JLocation.hh:40
int getFloor() const
Get floor number.
Definition JLocation.hh:146
int getString() const
Get string number.
Definition JLocation.hh:135
Data structure for a composite optical module.
Definition JModule.hh:76
bool has(const int bit) const
Test PMT status.
Definition JStatus.hh:198
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
unsigned long long usec_wall
Definition JTimer.hh:238
void stop()
Stop timer.
Definition JTimer.hh:127
void start()
Start timer.
Definition JTimer.hh:106
const JPosition3D & getPosition() const
Get position.
Rotation around Z-axis.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
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.
Definition JParser.hh:1664
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.
bool has(const T &value) const
Test whether given value is present.
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.
Definition JHead.cc:157
Auxiliary classes and methods for acoustic position calibration.
static const std::string string_t
string
Definition JSydney.cc:91
size_t getMinimumNumberOfEmitters(T __begin, T __end)
Get minimum number of emitters for any string in data.
static const std::string tripod_t
tripod
Definition JSydney.cc:92
static const char Z_t
set z-coordinate
Definition JSydney.cc:97
JContainer< std::vector< JTripod > > tripods_container
Definition JSydney.cc:80
static const std::string set_t
set coordinate of object
Definition JSydney.cc:94
JContainer< std::vector< JTransmitter > > transmitters_container
Definition JSydney.cc:82
static const std::string initialise_t
initialise
Definition JSydney.cc:89
JContainer< std::vector< JHydrophone > > hydrophones_container
Definition JSydney.cc:81
static const char Y_t
set y-coordinate
Definition JSydney.cc:96
static const char skip_t
Script commands.
Definition JSydney.cc:88
static const char X_t
set x-coordinate
Definition JSydney.cc:95
static const std::string stage_t
fit stage
Definition JSydney.cc:93
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
static const std::string fix_t
fix objects
Definition JSydney.cc:90
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.
file Auxiliary data structures and methods for detector calibration.
Definition JAnchor.hh:12
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.
std::string strip(const std::string &file_name)
Strip leading and trailing white spaces from file name.
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
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.
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
array_type< JValue_t > make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition JVectorize.hh:69
@ LEFT
Definition JTwosome.hh:18
@ RIGHT
Definition JTwosome.hh:18
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
Definition JPerth.cc:74
JRECONSTRUCTION::JWeight getWeight
JFIT::JEvent JEvent
Definition JHistory.hh:454
Definition setup.py:1
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Auxiliary data structure for mechanical model parameters of strings in a given detector.
Auxiliary data structure for mechanical model parameters with commented data.
Definition JMechanics.hh:36
Acoustic emitter.
Definition JEmitter.hh:30
int getID() const
Get emitter identifier.
Auxiliary data structure for handling of file names.
Definition JSydney.cc:102
std::string transmitter
transmitter
Definition JSydney.cc:121
JFilenames & strip()
Strip leading and trailing white spaces.
Definition JSydney.cc:108
std::string detector
detector
Definition JSydney.cc:118
std::string hydrophone
hydrophone
Definition JSydney.cc:120
std::string tripod
tripod
Definition JSydney.cc:119
double Qmin
minimal quality transmission
double deadTime_s
dead time between events [s]
size_t Nmin
minimum number of emitters
double sigma_s
time-of-arrival resolution [s]
double Tmax_s
time window to combine events [s]
bool hasLocation(const JLocation &location) const
Check if this detector has given location.
Definition JGeometry.hh:614
Acoustics hit.
Template definition of fit function of acoustic model.
Auxiliary data structure for setup of complete system.
Definition JSydney.cc:128
tripods_container tripods
tripods
Definition JSydney.cc:131
hydrophones
hydrophones
JDetectorMechanics_t mechanics
mechanical model
Definition JSydney.cc:130
transmitters_container transmitters
transmitters
Definition JSydney.cc:148
JDetector detector
detector
Definition JSydney.cc:129
Implementation for depth dependend velocity of sound.
JSoundVelocity & set(const double z0)
Set depth.
Auxiliary class to edit orientation of anchor.
Definition JSydney.cc:566
virtual void apply(const double step) override
Apply step.
Definition JSydney.cc:590
JAnchorEditor(JSetup &setup, const int id)
Constructor.
Definition JSydney.cc:573
std::vector< JTransmitter > & transmitters
Definition JSydney.cc:602
std::vector< JHydrophone > & hydrophones
Definition JSydney.cc:601
Auxiliary class to edit length of Dyneema ropes.
Definition JSydney.cc:475
JDyneemaEditor(JSetup &setup, const int id, const double z0=0.0)
Constructor.
Definition JSydney.cc:483
std::vector< size_t > index
Definition JSydney.cc:516
virtual void apply(const double step) override
Apply step.
Definition JSydney.cc:500
Auxiliary class to edit (z) position of module.
Definition JSydney.cc:381
virtual void apply(const double step) override
Apply step.
Definition JSydney.cc:410
JModuleEditor(JModule &module, const JVector3D &direction)
Constructor.
Definition JSydney.cc:399
JModuleEditor(JModule &module)
Constructor.
Definition JSydney.cc:387
Extended data structure for parameters of stage.
Definition JSydney.cc:612
JParameters_t()
Default constuctor.
Definition JSydney.cc:616
friend std::ostream & operator<<(std::ostream &out, const JParameters_t &object)
Write parameters to output stream.
Definition JSydney.cc:663
std::vector< double > steps
Definition JSydney.cc:684
friend std::istream & operator>>(std::istream &in, JParameters_t &object)
Read parameters from input stream.
Definition JSydney.cc:631
Auxiliary class to edit (x,y,z) position of string.
Definition JSydney.cc:428
std::vector< size_t > index
Definition JSydney.cc:466
JStringEditor(JSetup &setup, const int id, const JVector3D &direction, const bool option)
Constructor.
Definition JSydney.cc:439
virtual void apply(const double step) override
Apply step.
Definition JSydney.cc:456
Auxiliary class to edit (x,y,z) position of tripod.
Definition JSydney.cc:525
JTripodEditor(JSetup &setup, const int id, const JVector3D &direction)
Constructor.
Definition JSydney.cc:533
virtual void apply(const double step) override
Apply step.
Definition JSydney.cc:549
std::vector< JTripod > & tripods
Definition JSydney.cc:555
Auxiliary data structure for detector with decomposed strings.
Definition JSydney.cc:770
void push_back(const JModule &module)
Add module.
Definition JSydney.cc:776
Auxiliary data structure for fit options.
Definition JSydney.cc:162
void set(const char c, const bool value)
Set value of given coordinate.
Definition JSydney.cc:169
bool z
z-coordinate
Definition JSydney.cc:189
bool x
x-coordinate
Definition JSydney.cc:187
bool y
y-coordinate
Definition JSydney.cc:188
Auxiliary data structure for group of lists of identifiers of to-be-fitted objects.
Definition JSydney.cc:346
ids_t transmitters
identifiers of strings with transmitter
Definition JSydney.cc:372
ids_t tripods
identifiers of tripods
Definition JSydney.cc:370
void initialise(const JSetup &setup)
Initialise.
Definition JSydney.cc:359
ids_t hydrophones
identifiers of strings with hydrophone
Definition JSydney.cc:371
fits_t()
Default constructor.
Definition JSydney.cc:350
ids_t strings
identifiers of strings
Definition JSydney.cc:369
Map object identifiers to fit options.
Definition JSydney.cc:198
ids_t(const ids_t &A, const ids_t &B)
Difference constructor.
Definition JSydney.cc:232
friend std::istream & operator>>(std::istream &in, ids_t &object)
Read identifiers from input stream.
Definition JSydney.cc:307
friend std::ostream & operator<<(std::ostream &out, const ids_t &object)
Write identifiers and fit options to output stream.
Definition JSydney.cc:328
void erase(const ids_t &B)
Erase elements that are in given list of identifiers.
Definition JSydney.cc:256
void insert(const int id)
Insert identifier.
Definition JSydney.cc:245
ids_t(const array_type< int > &buffer)
Copy constructor.
Definition JSydney.cc:217
void set(const ids_t &B, const T &OP)
Set fit options of elements to result of given logical operator combined with fit options in given li...
Definition JSydney.cc:271
std::map< int, fit_t > map_type
Definition JSydney.cc:199
ids_t()
Default constructor.
Definition JSydney.cc:208
void set(const char c, const bool value)
Set fit option of all elements for given coordinate.
Definition JSydney.cc:292
Auxiliary data structure for decomposed string.
Definition JSydney.cc:747
void push_back(const JModule &module)
Add module.
Definition JSydney.cc:753
Main class for pre-calibration using acoustics data.
Definition JSydney.cc:155
double operator()(const int option) const
Get chi2.
Definition JSydney.cc:1062
void stage_x(const JParameters_t &parameters)
Fit procedure to determine the (x,y,z) positions of the modules.
Definition JSydney.cc:1029
ids_t getReceivers() const
Get list of identifiers of receivers.
Definition JSydney.cc:1339
JFilenames filenames
Definition JSydney.cc:1385
std::unique_ptr< JLocationRouter > router
Definition JSydney.cc:1393
JTOOLS::JHashMap< int, JLocation > receivers
Definition JSydney.cc:1392
void run(const std::string &script)
Run.
Definition JSydney.cc:1154
static constexpr double RADIUS_M
maximal horizontal distance between T-bar and emitter/hydrophone
Definition JSydney.cc:157
JDetector detector
PMTs.
Definition JSydney.cc:1401
void store(const std::string &dir=".")
Store data in given directory.
Definition JSydney.cc:1305
ids_t getEmitters() const
Get list of identifiers of emitters.
Definition JSydney.cc:1358
JSoundVelocity V
Definition JSydney.cc:1386
std::vector< input_type > input
Definition JSydney.cc:1396
void stage_c(const JParameters_t &parameters)
Fit procedure to determine the z-positions of the modules.
Definition JSydney.cc:971
std::vector< JSuperEvt > output
Definition JSydney.cc:1399
JFitParameters parameters
Definition JSydney.cc:1402
JSydney(const JFilenames &filenames, const JDetectorMechanics_t &mechanics, const JSoundVelocity &V, const size_t threads, const int debug)
Constructor.
Definition JSydney.cc:697
void stage_0(const JParameters_t &parameters)
Fit procedure to determine the positions of tripods and transmitters using strings that are fixed.
Definition JSydney.cc:788
std::vector< JEvent > input_type
Definition JSydney.cc:1395
void stage_d(const JParameters_t &parameters)
Fit procedure to determine the z-positions of anchors.
Definition JSydney.cc:997
void stage_b(const JParameters_t &parameters)
Fit procedure to determine the stretching and z-positions of individual strings.
Definition JSydney.cc:905
void stage_a(const JParameters_t &parameters)
Fit procedure to determine the positions of the strings and tripods.
Definition JSydney.cc:861
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).
Definition JContainer.hh:41
Conjugate gradient fit.
Definition JGradient.hh:76
Auxiliary data structure for editable parameter.
Definition JGradient.hh:50
Auxiliary data structure for fit parameter.
Definition JGradient.hh:29
Implementation of object iteration from STD container.
Auxiliary data structure for return type of make methods.
Definition JVectorize.hh:28
double getMean() const
Get mean value.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:66
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
General purpose class for hash map of unique keys.
Definition JHashMap.hh:75
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488