75 using namespace FITL1DT;
80 bool overwriteDetector;
89 JParser<> zap(
"Program to calculate time offsets from FitL1dtSlices output");
91 zap[
'f'] =
make_field(inputFile,
"input file") =
"fitslices.root";
93 zap[
'a'] =
make_field(detectorFile,
"detector file");
94 zap[
'A'] =
make_field(overwriteDetector,
"overwrite the input detector file");
95 zap[
'D'] =
make_field(noInterDU,
"do not use inter DU information in the calculation");
96 zap[
'r'] =
make_field(idom_ref,
"reference DOM set to t=0") = 9;
97 zap[
'F'] =
make_field(maxFloors,
"number of floors used in fit") = 9999;
100 if (zap.read(argc, argv) != 0) {
104 catch(
const exception &error) {
105 FATAL(error.what() << endl);
114 catch(
const JException& error) {
119 for (JDetector::iterator moduleA =
detector.begin(); moduleA !=
detector.end(); ++moduleA) {
120 DU_IDs.insert(moduleA->getString());
126 TFile*
in = TFile::Open(inputFile.c_str(),
"exist");
128 if (
in == NULL || !
in->IsOpen()) {
129 FATAL(
"File: " << inputFile <<
" not opened." << endl);
133 TH2D* h2A = (TH2D*)
in->Get(
"Aij");
134 TH2D* h2B = (TH2D*)
in->Get(
"Bij");
136 if (h2A == NULL || h2B == NULL) {
137 FATAL(
"File does not contain histogram with matrix. Please use FitL1dtSlices script first." << endl);
155 for (JDetector::iterator moduleA =
detector.begin(); moduleA !=
detector.end(); ++moduleA) {
157 const int ibin = h2A->GetXaxis()->FindBin(TString(Form(
"%i", moduleA->getID())));
159 if (noInterDU && (moduleA->getString() != *DU_ID)) {
163 for (JDetector::iterator moduleB =
detector.begin(); moduleB !=
detector.end(); ++moduleB) {
165 const int jbin = h2A->GetXaxis()->FindBin(TString(Form(
"%i", moduleB->getID())));
171 if (noInterDU && (moduleB->getString() != *DU_ID)) {
175 if (fabs(moduleA->getFloor() - moduleB->getFloor()) > maxFloors) {
179 double Aij = h2A->GetBinContent(ibin, jbin);
180 double Bij = h2B->GetBinContent(ibin, jbin);
187 NOTICE(
" " << idom <<
" " << jdom <<
" " << moduleA->getID() <<
" " << moduleB->getID() <<
" Aij: " << Aij <<
" Bij: " << Bij <<
" bf: " << -0.5*Bij/Aij << endl);
189 fitA.at(idom, jdom) = -4.0*Aij;
190 fitA.at(idom, idom) += 4.0*Aij;
191 fitB[idom] += 2.0*Bij;
192 diag[idom] += 4.0*Aij;
197 unsigned int icolumn = 0;
200 while (icolumn < fitA.size()) {
201 if (fitA.at(icolumn, icolumn) == 0) {
203 fitB.erase(fitB.begin() + icolumn);
205 changet0[idom] =
false;
213 if (fitA.size() <= 1) {
220 TMatrixDSym fit_A(fitA.size());
222 TVectorD fit_B(fitB.size());
224 for (
unsigned int i = 0;
i < fitA.size();
i++) {
225 for (
unsigned int j = 0;
j < fitA.size();
j++) {
226 fit_A(
i,
j) = fitA.at(
i,
j);
232 for (
int i = 0;
i < fit_A.GetNrows(); ++
i) {
233 fit_A(idom_ref-1,
i) = 0.0;
234 fit_A(
i, idom_ref-1) = 0.0;
236 fit_A(idom_ref-1, idom_ref-1) = 1.0;
237 fit_B(idom_ref-1) = 0.0;
239 if (
debug >= 2) fit_A.Print();
242 Double_t fit_A_det = -999;
243 fit_A.Invert(&fit_A_det);
244 if (fit_A_det == 0) {
245 NOTICE(
"Matrix not invertible." << endl);
248 if (
debug >= 2) fit_A.Print();
251 TVectorD dt_i = fit_A * fit_B;
255 for (JDetector::iterator moduleA =
detector.begin(); moduleA !=
detector.end(); ++moduleA) {
257 if (changet0[idom]) {
259 vart0[idom] = TMath::Sqrt(-1 / diag[idom]);
271 for (JDetector::iterator moduleA =
detector.begin(); moduleA !=
detector.end(); ++moduleA) {
273 NOTICE(
"Changing t0 of DOM " << moduleA->getID() <<
" (S"<<setw(2) << moduleA->getString() <<
"F" << setw(2) << moduleA->getFloor() <<
") by " << setw(13) << dt0[idom] <<
" [ns] ");
275 if (status[idom] == 0) {
276 NOTICE(
" ** unable to fit **" << endl);
278 else if (moduleA->getFloor() == idom_ref) {
279 NOTICE(
" ** fixed **" << endl);
285 if (overwriteDetector) {
286 moduleA->add(dt0[idom]);
288 h_dt0.GetXaxis()->SetBinLabel(idom+1, Form(
"%i", moduleA->getID()));
289 h_dt0.SetBinContent(idom+1, dt0[idom]);
290 h_dt0.SetBinError(idom+1, vart0[idom]);
297 if (overwriteDetector) {
298 NOTICE(
"Store calibration data on file " << detectorFile << endl);
Utility class to parse command line options.
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
do set_variable DETECTOR_TXT $WORKDIR detector
JMatrixNS removeRowColumn(const JMatrixNS &A, int C)
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in