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