16 namespace FITL1DTSLICES {
 
   27   double logPoison(
double n, 
double nhat, 
double logP_min = -999999.9) {
 
   28     if (nhat < 0.0 || n < 0.0) {
 
   29       FATAL(
"logPoisson: n (" << n <<
") or nhat (" << nhat << 
") is < 0.0" << std::endl);
 
   31     if (n == 0.0 && nhat == 0.0) {
 
   34     if (n == 0.0 && nhat > 0.0) {
 
   37     if (n >= 0.0 && nhat == 0.0) {
 
   41     if (poisson == 0) 
return 0.0; 
 
   42     else              return TMath::Log(poisson);
 
   45   double getLogQuality(
const TH1D* 
data, 
const TH1D* 
model, 
int di, 
double data_bkg = 0.0001, 
double model_bkg = 0.0001) {
 
   51     int i_low = data->GetNbinsX() / 4; 
 
   52     int i_hgh = data->GetNbinsX() / 4 * 3; 
 
   53     for (
int i = i_low; 
i <= i_hgh; ++
i) {
 
   55       double nhat = model_bkg;
 
   56       if (
i >= 1 && i <= data->GetNbinsX()) {
 
   58         n = data->GetBinContent(
i);
 
   60       if (
i+di >= 1 && 
i+di <= model->GetNbinsX()) {
 
   62         nhat = model->GetBinContent(
i+di);
 
   79 int main(
int argc, 
char **argv)
 
   82   using namespace FITL1DTSLICES;
 
   97     JParser<> zap(
"Program to calculate log-likelihood distributions between DOM pairs and fit a poly2 to find the shape, used in FitL1dt to find time offsets");
 
   99     zap[
'f'] = 
make_field(inputFile,    
"input file")                                        = 
"monitor.root";
 
  100     zap[
'm'] = 
make_field(modelFile,    
"model file");
 
  102     zap[
'a'] = 
make_field(detectorFile, 
"detector file");
 
  103     zap[
'T'] = 
make_field(TMax_ns,      
"scan range around 0 in data-model comparison [ns]") = 50.0;
 
  104     zap[
't'] = 
make_field(dt_fitrange,  
"fitrange of polynomial to quality [ns]")            = 5.0;
 
  105     zap[
'r'] = 
make_field(rebin,        
"rebin the histograms")                              = 1;
 
  106     zap[
'N'] = 
make_field(normaliseMC,  
"normalize the MC histogram");
 
  109     if (zap.
read(argc, argv) != 0) {
 
  113   catch(
const exception &error) {
 
  114     FATAL(error.what() << endl);
 
  118   const double TSignal_ns = 750.0; 
 
  125   catch(
const JException& error) {
 
  130   TFile* 
in = TFile::Open(inputFile.c_str(), 
"exist");
 
  131   TFile* in_model = TFile::Open(modelFile.c_str(), 
"exist");
 
  133   if (
in == NULL || !
in->IsOpen()) {
 
  134     FATAL(
"File: " << inputFile << 
" not opened." << endl);
 
  136   if (in_model == NULL || !in_model->IsOpen()) {
 
  137     FATAL(
"File: " << modelFile << 
" not opened." << endl);
 
  149   for (JDetector::iterator moduleA = 
detector.begin(); moduleA != 
detector.end(); ++moduleA) {
 
  151     TString label = Form(
"%i", moduleA->getID());
 
  152     h2A.GetXaxis()->SetBinLabel(idom+1, label);
 
  153     h2A.GetYaxis()->SetBinLabel(idom+1, label);
 
  154     h2B.GetXaxis()->SetBinLabel(idom+1, label);
 
  155     h2B.GetYaxis()->SetBinLabel(idom+1, label);
 
  156     h2C.GetXaxis()->SetBinLabel(idom+1, label);
 
  157     h2C.GetYaxis()->SetBinLabel(idom+1, label);
 
  159     h2Bbare.GetXaxis()->SetBinLabel(idom+1, label);
 
  160     h2Bbare.GetYaxis()->SetBinLabel(idom+1, label);
 
  163   for (JDetector::iterator moduleA = 
detector.begin(); moduleA != 
detector.end(); ++moduleA) {
 
  165     DEBUG(
"Module " << moduleA->getID() << endl);
 
  166     const JString title = JString(moduleA->getID());
 
  170     TH2D* d2s = (TH2D*) 
in->Get((title + 
".2S").c_str());
 
  171     TH1D* d1l = (TH1D*) 
in->Get((title + 
".1L").c_str());
 
  173     if (d2s == NULL || d1l == NULL) {
 
  174       WARNING(
"No data in data histogram " << title << endl);
 
  179     TH2D* m2s = (TH2D*) in_model->Get((title + 
".2S").c_str());
 
  180     TH1D* m1l = (TH1D*) in_model->Get((title + 
".1L").c_str());
 
  182     if (m2s == NULL || m1l == NULL) {
 
  183       WARNING(
"No mata in model histogram " << title << endl);
 
  188     for (JDetector::iterator moduleB = moduleA; moduleB != 
detector.end(); ++moduleB) {
 
  191       if (moduleB->getID() == moduleA->getID()) { 
 
  194       if (moduleB->getString() != moduleA->getString()) { 
 
  198       TH1D* d1s = d2s->ProjectionY((title + Form(
".%i.d1S", moduleB->getID())).c_str(), 
 
  199           d2s->GetXaxis()->FindBin(TString(Form(
"%i", moduleB->getID()))), 
 
  200           d2s->GetXaxis()->FindBin(TString(Form(
"%i", moduleB->getID()))), 
"e");
 
  201       TH1D* m1s = m2s->ProjectionY((title + Form(
".%i.m1S", moduleB->getID())).c_str(), 
 
  202           m2s->GetXaxis()->FindBin(TString(Form(
"%i", moduleB->getID()))), 
 
  203           m2s->GetXaxis()->FindBin(TString(Form(
"%i", moduleB->getID()))), 
"e");
 
  205       if (d1s->Integral() <= 0.0 || m1s->Integral() <= 0.0) { 
 
  210       double binCenterMaxBin = d1s->GetXaxis()->GetBinCenter(d1s->GetMaximumBin());
 
  211       double backgroundrate_s = 0.0;
 
  213       for (
int j = 1; 
j <= d1s->GetXaxis()->GetNbins(); ++
j) {
 
  214         if (fabs(d1s->GetXaxis()->GetBinCenter(
j) - binCenterMaxBin) > TSignal_ns ) { 
 
  215           backgroundrate_s += d1s->GetBinContent(
j); 
 
  219       backgroundrate_s /= nbins;
 
  222       binCenterMaxBin = m1s->GetXaxis()->GetBinCenter(m1s->GetMaximumBin());
 
  223       double backgroundrate_m = 0.0;
 
  225       for (
int j = 1; 
j <= m1s->GetXaxis()->GetNbins(); ++
j) {
 
  226         if (fabs(m1s->GetXaxis()->GetBinCenter(
j) - binCenterMaxBin) > TSignal_ns ) { 
 
  227           backgroundrate_m += m1s->GetBinContent(
j); 
 
  231       backgroundrate_m /= nbins;
 
  234       const double Ld = d1l->GetBinContent(d1l->GetXaxis()->FindBin(TString(Form(
"%i", moduleB->getID()))));
 
  235       const double Lm = m1l->GetBinContent(m1l->GetXaxis()->FindBin(TString(Form(
"%i", moduleB->getID()))));
 
  237       for (
int j = 1; 
j <= d1s->GetXaxis()->GetNbins(); ++
j) {
 
  238         const double y  = d1s->GetBinContent(
j);
 
  239         const double dy = d1s->GetBinError(
j);
 
  241         d1s->SetBinContent(
j, y);
 
  242         d1s->SetBinError(
j, dy);
 
  246       for (
int j = 1; 
j <= m1s->GetXaxis()->GetNbins(); ++
j) {
 
  247         const double y  = m1s->GetBinContent(
j);
 
  248         const double dy = m1s->GetBinError(
j);
 
  250         m1s->SetBinContent(
j, y * Ld/Lm);
 
  251         m1s->SetBinError(
j, dy*Ld/Lm);
 
  256         const double scalefactor = d1s->Integral()/m1s->Integral();
 
  257         m1s->Scale(scalefactor);
 
  269       int ddt_min = -0.5*TMax_ns;  
 
  270       int ddt_max =  0.5*TMax_ns;  
 
  272       TH1D q1((title + Form(
".%i.q1", moduleB->getID())).c_str(), (title + Form(
".%i.q1", moduleB->getID())).c_str(), (ddt_max-ddt_min)/rebin+1, ddt_min-0.5*rebin, ddt_max+0.5*rebin);
 
  274       for (
int di = 1; di <= q1.GetNbinsX(); di++) {
 
  275         q1.SetBinContent(di, 
getLogQuality(d1s, m1s, (
int)(q1.GetBinCenter(di)/rebin), 0.0, 0.0));
 
  279       const double dt_fitmid = q1.GetBinCenter(q1.GetMaximumBin());
 
  281       TF1 q1f((title + Form(
".%i.q1f", moduleB->getID())).c_str(), 
"[0]*x*x + [1]*x + [2]", dt_fitmid - dt_fitrange, dt_fitmid + dt_fitrange);
 
  282       q1f.SetParLimits(0, -1e5, 0.0); 
 
  284       string fitoptions = 
"R";
 
  288       q1.Fit(&q1f, fitoptions.c_str());
 
  294       const double Aij = q1f.GetParameter(0);
 
  295       const double Bij = q1f.GetParameter(1);
 
  296       const double Cij = q1f.GetParameter(2);
 
  298       double bareBij = Bij / Aij;
 
  299       if (Aij == 0) bareBij = 0;
 
  301       if (fabs(-0.5*Bij/Aij - dt_fitmid) > 3 || fabs(-0.5*Bij/Aij) > dt_fitrange) {
 
  302         WARNING(
"  Please check fit of pair " << idom << 
", " << jdom << 
" : " << moduleA->getID() << 
", " << moduleB->getID() << endl); 
 
  303         WARNING(
"  DOMpair " << idom << 
"; " << jdom << 
"  A=" << Aij << 
" B=" << Bij << 
" , max at: " << dt_fitmid << 
" [ns], best fit at " << -0.5*Bij/Aij << 
" ns " << endl);
 
  305       DEBUG(
"DOMpair " << idom << 
"; " << jdom << 
"  A=" << Aij << 
" B=" << Bij << 
" , max at: " << dt_fitmid << 
" [ns], best fit at " << -0.5*Bij/Aij << 
" ns " << endl);
 
  307       h2A.SetBinContent(idom+1, jdom+1, Aij);
 
  308       h2A.SetBinContent(jdom+1, idom+1, Aij);
 
  309       h2B.SetBinContent(idom+1, jdom+1, Bij);
 
  310       h2B.SetBinContent(jdom+1, idom+1,-Bij);
 
  311       h2C.SetBinContent(idom+1, jdom+1, Cij);
 
  312       h2C.SetBinContent(jdom+1, idom+1, Cij);
 
  314       h2Bbare.SetBinContent(idom+1, jdom+1, bareBij);
 
  315       h2Bbare.SetBinContent(jdom+1, idom+1, 0);
 
Utility class to parse command line options. 
 
int main(int argc, char *argv[])
 
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance. 
 
Data structure for detector geometry and calibration. 
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object 
 
double Poisson(const size_t n, const double mu)
Poisson cumulative density distribition. 
 
int read(const int argc, const char *const argv[])
Parse the program's command line options. 
 
void load(const std::string &file_name, JDetector &detector)
Load detector from input file. 
 
Utility class to parse command line options. 
 
double poisson(const size_t n, const double mu)
Poisson probability density distribition. 
 
do set_variable DETECTOR_TXT $WORKDIR detector
 
KM3NeT DAQ constants, bit handling, etc. 
 
double logPoison(double n, double nhat, double logP_min=-999999.9)
 
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
 
#define DEBUG(A)
Message macros. 
 
double getLogQuality(const TH1D *data, const TH1D *model, int di, double data_bkg=0.0001, double model_bkg=0.0001)