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.
Data structure for track fit results.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
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.