#include "dynamic_calibration.hh" #include "JDynamics/JDynamics.hh" #include "JSupport/JMultipleFileScanner.hh" #include #include "stringutil.hh" #include "rootutil.hh" #include "Det.hh" #include "Vec.hh" using namespace std; using stringutil::print; using stringutil::file_exists; /*! read a jpp vector-like object */ template void vread(Vec& v , const T& jppthing ) { v.set( jppthing.getX(), jppthing.getY(), jppthing.getZ() ); } /*! read a jpp vector-like object containing a direction */ template void vreadd(Vec& v , const T& jppthing ) { v.set( jppthing.getDX(), jppthing.getDY(), jppthing.getDZ() ); } /*! Read a JDETECTOR::JPMT */ void read_pmt( Pmt& pmt, const JDETECTOR::JPMT& jpmt, bool init = false ) { if (init) pmt.id = jpmt.getID(); else if (pmt.id != jpmt.getID()) fatal("pmt id mismatch."); vreadd( pmt.dir, jpmt.getDirection() ); vread( pmt.pos, jpmt.getPosition() ); } /*! read a JDETECTOR::JModule */ void read_dom( Dom& dom , const JDETECTOR::JModule& jmod, bool init = false ) { if ( init ) { dom.id = jmod.getID(); //dom.line_id = jmod.getLine(); dom.floor_id = jmod.getFloor(); dom.pmts.resize( jmod.size() ); } else if ( dom.id != jmod.getID() ) fatal ("dom id mismatch.", dom.id , jmod.getID() ); vread( dom.pos, jmod.getPosition() ); if ( dom.pmts.size() != jmod.size() ) { fatal("dom with different number of pmts?", dom.pmts.size(), jmod.size() ); } for (unsigned i = 0; i< dom.pmts.size() ; i ++ ) { read_pmt( dom.pmts[i], jmod.at(i), init ); } } void read_det( Det& det, const JDETECTOR::JDetector& jdet, bool init = false ) { // todo: utm coordinates etc for(const auto& module : jdet ) { read_dom( det.doms[ module.getID() ], module, init ); } if (init) det.init_pmts(); } Det to_det( const JDETECTOR::JDetector& jdet ) { Det r; read_det( r, jdet , true ); return r; } DynamicCalibration::DynamicCalibration( string detector_file, string orientations_file, string positions_file ) { JDETECTOR::JDetector jdetector; load( detector_file, jdetector); JACOUSTICS::getMechanics.load(jdetector.getID()); // you gotta get the mechanics; don't forget it. int Tmax_s = 100; // time interval before recomputing detector jdyn = new JDYNAMICS::JDynamics( jdetector, Tmax_s); // jdetector copied to jdyn typedef JPP::JTYPELIST::typelist calibration_types; vector v = { orientations_file, positions_file }; // better check, 'cause jpp doesn't. (but allow emtpy, because sometimes we want it) for (auto fn : v ) { if (fn != "" && !file_exists( fn)) fatal( "file does not exist", fn ); } print ("loading dynamic calibration files..."); print (v); JSUPPORT::JMultipleFileScanner calib_files_scanner ( v ); jdyn->load( calib_files_scanner ); // find approximate min/max time over all doms. t0.SetSec(0); t1.SetSec( 2147483647 ); // latest posible time. for( auto z : jdyn->position ) { TTimeStamp t0_,t1_; t0_.SetSec( long( z.second.getXmin()) ); t1_.SetSec( long( z.second.getXmax()) ); if ( t0_> t0 ) t0 = t0_; if ( t1_< t1 ) t1 = t1_; } print("input files for dynamic calibration loaded."); print("calibration loaded (postion) from", t0.AsString(), "to", t1.AsString() ); } Det DynamicCalibration::get_det() { return to_det( jdyn->getDetector() ); } void DynamicCalibration::update(Det& det, int utc_seconds ) { { TIMER( update dynamic) jdyn->update( utc_seconds ); } { // TODO : this only needs to happen if jdyn actially changed. TIMER( transfer dynamic ) read_det( det, jdyn->getDetector() ); } } DynamicCalibration::~DynamicCalibration() { delete jdyn; } void print_jdetetor(JDETECTOR::JDetector& detector ) { for(const auto& module : detector ) { print( "module ", module.getID() ); for ( const auto& pmt : module ) { print ("pmt", pmt.getID(), pmt.getDirection() ); } } } DynamicCalibration testdyn( string detector_file, string orientations_file, string positions_file ) { print ("test dynamic calibration"); print ( detector_file ); print ( orientations_file ); print ( positions_file ); DynamicCalibration D( detector_file, orientations_file, positions_file ); return D; };