58 bool selectHTRentry(
const JFit& bf) {
61 double dz = bf.
getDZ() ;
67 if (dz > -0.97) {
return false ; }
73 double logPoison(
double n,
double nhat,
double logP_min = -999999.9) {
74 if (nhat < 0.0 || n < 0.0) {
FATAL(
"logPoisson: n (" << n <<
") or nhat (" << nhat <<
") is < 0.0" << std::endl) ; }
75 if (n == 0.0 && nhat == 0.0) {
return 0.0 ; }
76 if (n == 0.0 && nhat > 0.0) {
return logP_min ; }
77 if (n >= 0.0 && nhat == 0.0) {
return logP_min ; }
78 return TMath::Log(TMath::Poisson(n, nhat)) ;
81 double getLogQuality(
const TH1D* data,
const TH1D* model,
int di,
double n_min = 0.0001,
double nhat_min = 0.0001) {
84 const double logQ_min = -999999.9 ;
85 const double logQ_empty = TMath::Max(logQ_min, logPoison(n_min, nhat_min)) ;
88 for (
int i = 1 ; i <= data->GetNbinsX() ; ++i) {
90 if (i+di < 1 || i+di > model->GetNbinsX()) {
99 double n = TMath::Max(n_min, data->GetBinContent(i)) ;
100 double nhat = TMath::Max(nhat_min, model->GetBinContent(i+di)) ;
102 q += TMath::Max(logQ_min, logPoison(n, nhat)) ;
120 int main(
int argc,
char **argv)
124 using namespace KM3NETDAQ;
126 string detectorFile ;
127 string inputFile_data;
129 double livetime_data;
134 bool overwriteDetector;
154 catch(
const exception& error) {
155 FATAL(error.what() << endl);
168 double dt_min = -100.0 ;
169 double dt_max = 100.0 ;
170 double dt_N =+(dt_max-dt_min)+1 ;
174 TFile infile_data(inputFile_data.c_str(),
"read") ;
175 TFile infile_mc(inputFile_mc.c_str(),
"read") ;
177 TFile outfile(
outputFile.c_str(),
"recreate") ;
181 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
183 int domid = module->getID() ;
185 TString DOMID(Form(
"%d", domid)) ;
186 TTree* htr_tree_data = (TTree*)infile_data.Get(DOMID+
".htr") ;
187 if (htr_tree_data == NULL) {
WARNING(
"Couldn't find model " << DOMID <<
".htr in data file " << inputFile_data <<
" skipping DOM " << endl) ; continue ; }
189 NOTICE(
"processing " << DOMID << endl ) ;
193 htr_tree_data->SetBranchAddress(
"dt",&htr_dt);
194 htr_tree_data->SetBranchAddress(
"bestfit",&bestfit) ;
196 TH1D htr_data(DOMID+
".htr_data", DOMID+
".htr_data", dt_N, dt_min-0.5, dt_max+0.5) ;
198 Long64_t nentries = htr_tree_data->GetEntries();
199 for (Long64_t i=0;i<nentries;i++) {
200 htr_tree_data->GetEntry(i);
203 if (selectHTRentry(*bestfit)) { htr_data.Fill(htr_dt) ; }
207 if (htr_data.Integral() < 1) {
WARNING(
"No data in data file " << inputFile_data <<
" skipping DOM " << DOMID << endl) ; continue ; }
210 TTree* htr_tree_mc = (TTree*)infile_mc.Get(htr_tree_data->GetName()) ;
211 if (htr_tree_mc == NULL) {
WARNING(
"Couldn't find model " << htr_tree_data->GetName() <<
" in model file " << inputFile_mc <<
" skipping DOM " << endl) ; continue ; }
212 htr_tree_mc->SetBranchAddress(
"dt",&htr_dt);
213 htr_tree_mc->SetBranchAddress(
"bestfit",&bestfit) ;
215 TH1D htr_mc(DOMID+
".htr_mc", DOMID+
".htr_mc", dt_N, dt_min-0.5, dt_max+0.5) ;
217 nentries = htr_tree_mc->GetEntries();
218 for (Long64_t i=0;i<nentries;i++) {
219 htr_tree_mc->GetEntry(i);
222 if (selectHTRentry(*bestfit)) { htr_mc.Fill(htr_dt) ; }
226 if (htr_mc.Integral() < 1) {
WARNING(
"No data in model file " << inputFile_mc <<
" skipping DOM " << DOMID << endl) ; continue ; }
230 htr_mc.Scale(1.0/livetime_mc) ;
231 htr_data.Scale(1.0/livetime_data) ;
233 const double nmin = 0.01/livetime_mc ;
234 TH1D q1(DOMID+
".1q", DOMID+
".q1", 41, -20.5, 20.5) ;
236 for (
int di = 0 ; di < q1.GetNbinsX() ; di++) {
237 q1.SetBinContent(di+1, getLogQuality(&htr_data, &htr_mc, q1.GetBinCenter(di+1), nmin, nmin)) ;
240 double dt_bestfit = q1.GetXaxis()->GetBinCenter(q1.GetMaximumBin()) ;
243 TF1 f1(DOMID+
".1f",
"([0]*x+[1])*x+[2]", dt_bestfit+dtrange.getLowerLimit() , dt_bestfit+dtrange.getUpperLimit()) ;
244 f1.SetParameter(0, 1.0) ;
245 f1.SetParameter(1, 0.0) ;
246 f1.SetParameter(2, 10.0) ;
249 if (fabs(dt_bestfit - -0.5*f1.GetParameter(1)/f1.GetParameter(0)) < 1.0) {
250 dt_bestfit = -0.5*f1.GetParameter(1)/f1.GetParameter(0) ;
253 timeshift[distance(
detector.begin(), module)] = dt_bestfit ;
256 TDirectory* dir = outfile.mkdir(DOMID);
264 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
269 for (JDetector::iterator mod =
detector.begin(); mod !=
detector.end(); ++mod) {
271 if (noInterString && module->getString() != mod->getString()) { continue ; }
273 ave += timeshift.at(distance(
detector.begin(), mod)) ;
279 DEBUG(
"Best fit shift " << module->getID() <<
" : " << timeshift[distance(
detector.begin(), module)]-ave <<
" [ns] " << endl ) ;
281 if (overwriteDetector) {
283 module->getPMT(pmt).addT0(timeshift[distance(
detector.begin(), module)]-ave);
289 if (overwriteDetector) {
291 NOTICE(
"Store calibration data on file " << detectorFile << endl);
Utility class to parse command line options.
General purpose data regression method.
Recording of objects on file according a format that follows from the file name extension.
Data structure for detector geometry and calibration.
Various implementations of functional maps.
Basic data structure for L0 hit.
Data structure for track fit results.
Basic data structure for time and time over threshold information of hit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
General purpose messaging.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
double getDZ() const
Get Z-slope.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
ROOT TTree parameter settings.
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
#define DEBUG(A)
Message macros.
int main(int argc, char *argv[])