musrfit  1.9.2
musrt0.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  musrt0.cpp
4 
5  Author: Andreas Suter
6  e-mail: andreas.suter@psi.ch
7 
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * Copyright (C) 2007-2023 by Andreas Suter *
12  * andreas.suter@psi.ch *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the *
26  * Free Software Foundation, Inc., *
27  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28  ***************************************************************************/
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 
38 #include <iostream>
39 #include <memory>
40 
41 #include <TApplication.h>
42 #include <TSAXParser.h>
43 #include <TROOT.h>
44 #include <TSystem.h>
45 
46 #ifdef HAVE_GIT_REV_H
47 #include "git-revision.h"
48 #endif
49 
50 #include "PMusr.h"
51 #include "PStartupHandler.h"
52 #include "PMsrHandler.h"
53 #include "PRunDataHandler.h"
54 #include "PMusrT0.h"
55 
56 //--------------------------------------------------------------------------
61 {
62  std::cout << std::endl << "usage: musrt0 <msr-file> [{--getT0FromPromptPeak | -g} [<firstGoodBinOffset>]]";
63  std::cout << std::endl << " [--timeout <timeout>] | --show-dynamic-path | --version | --help";
64  std::cout << std::endl << " <msr-file>: msr input file";
65  std::cout << std::endl << " --getT0FromPromptPeak, -g with <firstGoodBinOffset>:";
66  std::cout << std::endl << " will, in non-interactive mode estimate the t0's from the prompt peak";
67  std::cout << std::endl << " and write it into the msr-file.";
68  std::cout << std::endl << " if <firstGoodBinOffset> is given, to first good bin will be t0+<firstGoodBinOffset>.";
69  std::cout << std::endl << " if no <firstGoodBinOffset> is given, only t0 will be set.";
70  std::cout << std::endl << " --timeout <timeout>: <timeout> given in seconds after which musrview terminates.";
71  std::cout << std::endl << " If <timeout> <= 0, no timeout will take place. Default <timeout> is 0.";
72  std::cout << std::endl;
73  std::cout << std::endl << " 'musrt0 <msr-file>' will execute musrt0";
74  std::cout << std::endl << " 'musrt0 <msr-file> --timeout 180' will execute musrt0, but terminate it after";
75  std::cout << std::endl << " 180 sec if not already done so.";
76  std::cout << std::endl << " 'musrt0' or 'musrt0 --help' will show this help";
77  std::cout << std::endl << " 'musrt0 --version' will print the musrt0 version";
78  std::cout << std::endl << " 'musrt0 --show-dynamic-path' dumps the dynamic search paths and exit.";
79  std::cout << std::endl << std::endl;
80 }
81 
82 //--------------------------------------------------------------------------
96 Bool_t musrt0_item(TApplication &app, PMsrHandler *msrHandler, PMusrT0Data &data, UInt_t idx, Int_t timeout)
97 {
98  std::unique_ptr<PMusrT0> musrT0 = std::make_unique<PMusrT0>(data);
99 
100  // check if the musrT0 object is valid
101  if (!musrT0->IsValid()) {
102  std::cerr << std::endl << ">> musrt0 **ERROR** invalid item found! (idx=" << idx << ")";
103  std::cerr << std::endl;
104  return false;
105  }
106 
107  // set timeout
108  musrT0->SetTimeout(timeout);
109 
110  // set the msr-file handler. The handler cannot be transfered at construction time since rootcling is not able to handle the PMsrHandler class
111  musrT0->SetMsrHandler(msrHandler);
112 
113  // check if only t0, data-, and bkg-range is wished, if not, only initialize t0 at this point
115  musrT0->InitT0();
116 
117  // check if only t0 is wished, if not, initialize data- and bkg-ranges
118  if (data.GetCmdTag() != PMUSRT0_GET_T0)
119  musrT0->InitDataAndBkg();
120 
121  // connect SIGNAL 'Done' of musrT0 with the SLOT 'Terminate' of app. This will terminate the main application if
122  // the local musrT0 object emits 'Done'
123  musrT0->Connect("Done(Int_t)", "TApplication", &app, "Terminate(Int_t)");
124 
125  app.Run(true); // true needed that Run will return after quit
126  Bool_t result = true;
127  if (musrT0->GetStatus() >= 1)
128  result = false;
129  else
130  result = true;
131 
132  // disconnect all SIGNALS and SLOTS connected t0 musrT0
133  musrT0->Disconnect(musrT0.get());
134 
135  return result;
136 }
137 
138 //--------------------------------------------------------------------------
144 Int_t musrt0_getMaxBin(const PDoubleVector *data)
145 {
146  Int_t maxBin = -1;
147  Double_t maxData = -999;
148 
149  for (UInt_t i=0; i<data->size(); i++) {
150  if (data->at(i) > maxData) {
151  maxData = data->at(i);
152  maxBin = i;
153  }
154  }
155 
156  return maxBin;
157 }
158 
159 //--------------------------------------------------------------------------
176 Int_t main(Int_t argc, Char_t *argv[])
177 {
178  Bool_t show_syntax = false;
179  Int_t status;
180  Bool_t success = true;
181  Char_t filename[1024];
182  Bool_t getT0FromPromptPeak = false;
183  Bool_t firstGoodBinOffsetPresent = false;
184  Int_t firstGoodBinOffset = 0;
185  Int_t timeout = 0;
186  Int_t fitType = -1;
187 
188  if (argc == 1) {
189  musrt0_syntax();
190  return PMUSR_SUCCESS;
191  }
192 
193  // add default shared library path /usr/local/lib if not already persent
194  const char *dsp = gSystem->GetDynamicPath();
195  if (strstr(dsp, "/usr/local/lib") == nullptr)
196  gSystem->AddDynamicPath("/usr/local/lib");
197 
198  memset(filename, '\0', sizeof(filename));
199  for (int i=1; i<argc; i++) {
200  if (!strcmp(argv[i], "--version")) {
201 #ifdef HAVE_CONFIG_H
202 #ifdef HAVE_GIT_REV_H
203  std::cout << std::endl << "musrt0 version: " << PACKAGE_VERSION << ", git-branch: " << GIT_BRANCH << ", git-rev: " << GIT_CURRENT_SHA1 << " (" << BUILD_TYPE << "), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
204 #else
205  std::cout << std::endl << "musrt0 version: " << PACKAGE_VERSION << " (" << BUILD_TYPE << "), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
206 #endif
207 #else
208 #ifdef HAVE_GIT_REV_H
209  std::cout << std::endl << "musrt0 git-branch: " << GIT_BRANCH << ", git-rev: " << GIT_CURRENT_SHA1 << std::endl << std::endl;
210 #else
211  std::cout << std::endl << "musrt0 version: unknown." << std::endl << std::endl;
212 #endif
213 #endif
214  return PMUSR_SUCCESS;
215  } else if (!strcmp(argv[i], "--help")) {
216  musrt0_syntax();
217  return PMUSR_SUCCESS;
218  } else if (!strcmp(argv[i], "--show-dynamic-path")) {
219  std::cout << std::endl << "musrt0: internal dynamic search paths for shared libraries/root dictionaries:";
220  std::cout << std::endl << " '" << gSystem->GetDynamicPath() << "'" << std::endl << std::endl;
221  return PMUSR_SUCCESS;
222  } else if (strstr(argv[i], ".msr")) { // check for filename
223  if (strlen(filename) == 0) {
224  strcpy(filename, argv[i]);
225  } else {
226  std::cout << std::endl << "**ERROR** only one file name allowed." << std::endl;
227  show_syntax = true;
228  break;
229  }
230  } else if (!strcmp(argv[i], "--getT0FromPromptPeak") || !strcmp(argv[i], "-g")) { // T0 from prompt peak option
231  getT0FromPromptPeak = true;
232  if (i+1 < argc) {
233  TString offset(argv[i+1]);
234  if (offset.IsFloat()) {
235  firstGoodBinOffsetPresent = true;
236  firstGoodBinOffset = offset.Atof();
237  i++;
238  }
239  }
240  } else if (!strcmp(argv[i], "--timeout")) {
241  if (i+1 < argc) {
242  TString numStr(argv[i+1]);
243  if (numStr.IsDigit()) {
244  timeout = numStr.Atoi();
245  } else {
246  std::cout << std::endl << "**ERROR** timeout '" << argv[i+1] << "' is not a number" << std::endl;
247  show_syntax = true;
248  break;
249  }
250  i++;
251  } else {
252  std::cout << std::endl << "**ERROR** no timeout given." << std::endl;
253  show_syntax = true;
254  break;
255  }
256  } else {
257  show_syntax = true;
258  break;
259  }
260  }
261 
262  if (strlen(filename) == 0) {
263  std::cout << std::endl << "**ERROR** msr-file missing!" << std::endl;
264  show_syntax = true;
265  }
266 
267  if (show_syntax) {
268  musrt0_syntax();
270  }
271 
272  // read startup file
273  Char_t startup_path_name[128];
274  std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
275  std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>();
276  if (!startupHandler->StartupFileFound()) {
277  std::cerr << std::endl << ">> musrt0 **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
278  std::cerr << std::endl;
279  } else {
280  strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
281  saxParser->ConnectToHandler("PStartupHandler", startupHandler.get());
282  //status = saxParser->ParseFile(startup_path_name);
283  // parsing the file as above seems to lead to problems in certain environments;
284  // use the parseXmlFile function instead (see PStartupHandler.cpp for the definition)
285  status = parseXmlFile(saxParser.get(), startup_path_name);
286  // check for parse errors
287  if (status) { // error
288  std::cerr << std::endl << ">> musrt0 **WARNING** Reading/parsing musrfit_startup.xml failed.";
289  std::cerr << std::endl;
290  }
291  }
292 
293  // read msr-file
294  std::unique_ptr<PMsrHandler> msrHandler = std::make_unique<PMsrHandler>(filename);
295  status = msrHandler->ReadMsrFile();
296  if (status != PMUSR_SUCCESS) {
297  switch (status) {
299  std::cout << std::endl << ">> musrt0 **ERROR** couldn't find '" << filename << "'" << std::endl << std::endl;
300  break;
302  std::cout << std::endl << "**SYNTAX ERROR** in file " << filename << ", full stop here." << std::endl << std::endl;
303  break;
304  default:
305  std::cout << std::endl << "**UNKNOWN ERROR** when trying to read the msr-file" << std::endl << std::endl;
306  break;
307  }
308  return status;
309  }
310  msrHandler->CopyMsrStatisticBlock(); // just copy the statistics block since no fit is performed
311 
312  // check if the fittype is not NonMusr
313  PMsrRunList *runList = msrHandler->GetMsrRunList();
314  for (UInt_t i=0; i<runList->size(); i++) {
315  fitType = runList->at(i).GetFitType();
316  if (fitType == -1) { // i.e. not found in the RUN block, check the GLOBAL block
317  fitType = msrHandler->GetMsrGlobal()->GetFitType();
318  }
319  if (fitType == MSR_FITTYPE_NON_MUSR) {
320  std::cout << std::endl << ">> musrt0 **ERROR** t0 setting for NonMusr fit type doesn't make any sense, will quit ..." << std::endl;
321  success = false;
322  break;
323  }
324  }
325 
326  // read all the necessary runs (raw data)
327  std::unique_ptr<PRunDataHandler> dataHandler;
328  if (success) {
329  if (startupHandler)
330  dataHandler = std::make_unique<PRunDataHandler>(msrHandler.get(), startupHandler->GetDataPathList());
331  else
332  dataHandler = std::make_unique<PRunDataHandler>(msrHandler.get());
333 
334  dataHandler->ReadData();
335 
336  success = dataHandler->IsAllDataAvailable();
337  if (!success) {
338  std::cout << std::endl << ">> musrt0 **ERROR** Couldn't read all data files, will quit ..." << std::endl;
339  }
340  }
341 
342  if (getT0FromPromptPeak && success) {
343 
344  Int_t histoNo = -1;
345  UInt_t t0Bin = 0;
346  TString *runName = nullptr;
347  UInt_t start, end;
348 
349  // go through all runs in the msr-file
350  for (UInt_t i=0; i<runList->size(); i++) {
351  fitType = runList->at(i).GetFitType();
352  if (fitType == -1) { // i.e. not found in the RUN block, check the GLOBAL block
353  fitType = msrHandler->GetMsrGlobal()->GetFitType();
354  }
355  switch (fitType) {
358  if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
359  // get histo number
360  histoNo = runList->at(i).GetForwardHistoNo();
361  runName = runList->at(i).GetRunName();
362  // get bin position of maximal data
363  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
364  // set t0 to maximum data position
365  runList->at(i).SetT0Bin(t0Bin, 0);
366  // set data range as well if firstGoodBinOffset is given
367  if (firstGoodBinOffsetPresent) {
368  start = t0Bin + firstGoodBinOffset;
369  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
370  runList->at(i).SetDataRange(start, 0);
371  runList->at(i).SetDataRange(end, 1);
372  }
373  } else if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
374  // get histo number
375  histoNo = runList->at(i).GetForwardHistoNo();
376  runName = runList->at(i).GetRunName();
377  // get bin position of maximal data
378  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
379  // set t0 to maximum data position
380  runList->at(i).SetT0Bin(t0Bin, 0);
381  // set data range as well if firstGoodBinOffset is given
382  if (firstGoodBinOffsetPresent) {
383  start = t0Bin + firstGoodBinOffset;
384  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
385  runList->at(i).SetDataRange(start, 0);
386  runList->at(i).SetDataRange(end, 1);
387  }
388  // handle addruns
389  for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
390  runName = runList->at(i).GetRunName(j);
391  // get bin position of maximal data
392  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
393  // set t0 to maximum data position
394  runList->at(i).SetAddT0Bin(t0Bin, j-1, 0);
395  }
396  } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
397  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
398  // get histo number
399  histoNo = runList->at(i).GetForwardHistoNo(j);
400  runName = runList->at(i).GetRunName();
401  // get bin position of maximal data
402  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
403  // set t0 to maximum data position
404  runList->at(i).SetT0Bin(t0Bin, j);
405  if (firstGoodBinOffsetPresent && (j==0)) {
406  start = t0Bin + firstGoodBinOffset;
407  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
408  runList->at(i).SetDataRange(start, 0);
409  runList->at(i).SetDataRange(end, 1);
410  }
411  }
412  } else { // addruns / grouping
413  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
414  // get histo number
415  histoNo = runList->at(i).GetForwardHistoNo(j);
416  runName = runList->at(i).GetRunName();
417  // get bin position of maximal data
418  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
419  // set t0 to maximum data position
420  runList->at(i).SetT0Bin(t0Bin, j);
421  if (firstGoodBinOffsetPresent && (j==0)) {
422  start = t0Bin + firstGoodBinOffset;
423  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
424  runList->at(i).SetDataRange(start, 0);
425  runList->at(i).SetDataRange(end, 1);
426  }
427  // handle addruns
428  for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
429  runName = runList->at(i).GetRunName(k);
430  // get bin position of maximal data
431  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
432  // set t0 to maximum data position
433  runList->at(i).SetAddT0Bin(t0Bin, k-1, j);
434  }
435  }
436  }
437  break;
438  case MSR_FITTYPE_ASYM:
439  if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
440  // handle forward histo
441  // get histo number
442  histoNo = runList->at(i).GetForwardHistoNo();
443  runName = runList->at(i).GetRunName();
444  // get bin position of maximal data
445  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
446  // set t0 to maximum data position
447  runList->at(i).SetT0Bin(t0Bin, 0);
448  // set data range as well if firstGoodBinOffset is given
449  if (firstGoodBinOffsetPresent) {
450  start = t0Bin + firstGoodBinOffset;
451  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
452  runList->at(i).SetDataRange(start, 0);
453  runList->at(i).SetDataRange(end, 1);
454  }
455  // handle backward histo
456  // get histo number
457  histoNo = runList->at(i).GetBackwardHistoNo();
458  runName = runList->at(i).GetRunName();
459  // get bin position of maximal data
460  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
461  // set t0 to maximum data position
462  runList->at(i).SetT0Bin(t0Bin, 1);
463  // set data range as well if firstGoodBinOffset is given
464  if (firstGoodBinOffsetPresent) {
465  start = t0Bin + firstGoodBinOffset;
466  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
467  runList->at(i).SetDataRange(start, 2);
468  runList->at(i).SetDataRange(end, 3);
469  }
470  } else if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
471  // handle forward histo
472  // get histo number
473  histoNo = runList->at(i).GetForwardHistoNo();
474  runName = runList->at(i).GetRunName();
475  // get bin position of maximal data
476  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
477  // set t0 to maximum data position
478  runList->at(i).SetT0Bin(t0Bin, 0);
479  // set data range as well if firstGoodBinOffset is given
480  if (firstGoodBinOffsetPresent) {
481  start = t0Bin + firstGoodBinOffset;
482  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
483  runList->at(i).SetDataRange(start, 0);
484  runList->at(i).SetDataRange(end, 1);
485  }
486  // handle addruns
487  for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
488  runName = runList->at(i).GetRunName(j);
489  // get bin position of maximal data
490  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
491  // set t0 to maximum data position
492  runList->at(i).SetAddT0Bin(t0Bin, j-1, 0);
493  }
494  // handle backward histo
495  // get histo number
496  histoNo = runList->at(i).GetBackwardHistoNo();
497  runName = runList->at(i).GetRunName();
498  // get bin position of maximal data
499  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
500  // set t0 to maximum data position
501  runList->at(i).SetT0Bin(t0Bin, 1);
502  // set data range as well if firstGoodBinOffset is given
503  if (firstGoodBinOffsetPresent) {
504  start = t0Bin + firstGoodBinOffset;
505  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
506  runList->at(i).SetDataRange(start, 2);
507  runList->at(i).SetDataRange(end, 3);
508  }
509  // handle addruns
510  for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
511  runName = runList->at(i).GetRunName(j);
512  // get bin position of maximal data
513  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
514  // set t0 to maximum data position
515  runList->at(i).SetAddT0Bin(t0Bin, j-1, 1);
516  }
517  } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
518  // handle forward histo
519  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
520  // get histo number
521  histoNo = runList->at(i).GetForwardHistoNo(j);
522  runName = runList->at(i).GetRunName();
523  // get bin position of maximal data
524  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
525  // set t0 to maximum data position
526  runList->at(i).SetT0Bin(t0Bin, 2*j);
527  if (firstGoodBinOffsetPresent && (j==0)) {
528  start = t0Bin + firstGoodBinOffset;
529  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
530  runList->at(i).SetDataRange(start, 0);
531  runList->at(i).SetDataRange(end, 1);
532  }
533  }
534  // handle backward histo
535  for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
536  // get histo number
537  histoNo = runList->at(i).GetBackwardHistoNo(j);
538  runName = runList->at(i).GetRunName();
539  // get bin position of maximal data
540  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
541  // set t0 to maximum data position
542  runList->at(i).SetT0Bin(t0Bin, 2*j+1);
543  if (firstGoodBinOffsetPresent && (j==0)) {
544  start = t0Bin + firstGoodBinOffset;
545  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
546  runList->at(i).SetDataRange(start, 2);
547  runList->at(i).SetDataRange(end, 3);
548  }
549  }
550  } else { // addruns / grouping
551  // handle forward histo
552  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
553  // get histo number
554  histoNo = runList->at(i).GetForwardHistoNo(j);
555  runName = runList->at(i).GetRunName();
556  // get bin position of maximal data
557  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
558  // set t0 to maximum data position
559  runList->at(i).SetT0Bin(t0Bin, 2*j);
560  if (firstGoodBinOffsetPresent && (j==0)) {
561  start = t0Bin + firstGoodBinOffset;
562  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
563  runList->at(i).SetDataRange(start, 0);
564  runList->at(i).SetDataRange(end, 1);
565  }
566  // handle addruns
567  for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
568  runName = runList->at(i).GetRunName(k);
569  // get bin position of maximal data
570  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
571  // set t0 to maximum data position
572  runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j);
573  }
574  }
575  // handle backward histo
576  for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
577  // get histo number
578  histoNo = runList->at(i).GetBackwardHistoNo(j);
579  runName = runList->at(i).GetRunName();
580  // get bin position of maximal data
581  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
582  // set t0 to maximum data position
583  runList->at(i).SetT0Bin(t0Bin, 2*j+1);
584  if (firstGoodBinOffsetPresent && (j==0)) {
585  start = t0Bin + firstGoodBinOffset;
586  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
587  runList->at(i).SetDataRange(start, 2);
588  runList->at(i).SetDataRange(end, 3);
589  }
590  // handle addruns
591  for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
592  runName = runList->at(i).GetRunName(k);
593  // get bin position of maximal data
594  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
595  // set t0 to maximum data position
596  runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j+1);
597  }
598  }
599  }
600  break;
601  case MSR_FITTYPE_BNMR:
602  if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
603  // handle forward histo
604  // get histo number
605  histoNo = runList->at(i).GetForwardHistoNo();
606  runName = runList->at(i).GetRunName();
607  // get bin position of maximal data
608  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
609  // set t0 to maximum data position
610  runList->at(i).SetT0Bin(t0Bin, 0);
611  // set data range as well if firstGoodBinOffset is given
612  if (firstGoodBinOffsetPresent) {
613  start = t0Bin + firstGoodBinOffset;
614  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
615  runList->at(i).SetDataRange(start, 0);
616  runList->at(i).SetDataRange(end, 1);
617  }
618  // handle backward histo
619  // get histo number
620  histoNo = runList->at(i).GetBackwardHistoNo();
621  runName = runList->at(i).GetRunName();
622  // get bin position of maximal data
623  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
624  // set t0 to maximum data position
625  runList->at(i).SetT0Bin(t0Bin, 1);
626  // set data range as well if firstGoodBinOffset is given
627  if (firstGoodBinOffsetPresent) {
628  start = t0Bin + firstGoodBinOffset;
629  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
630  runList->at(i).SetDataRange(start, 2);
631  runList->at(i).SetDataRange(end, 3);
632  }
633  } else if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
634  // handle forward histo
635  // get histo number
636  histoNo = runList->at(i).GetForwardHistoNo();
637  runName = runList->at(i).GetRunName();
638  // get bin position of maximal data
639  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
640  // set t0 to maximum data position
641  runList->at(i).SetT0Bin(t0Bin, 0);
642  // set data range as well if firstGoodBinOffset is given
643  if (firstGoodBinOffsetPresent) {
644  start = t0Bin + firstGoodBinOffset;
645  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
646  runList->at(i).SetDataRange(start, 0);
647  runList->at(i).SetDataRange(end, 1);
648  }
649  // handle addruns
650  for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
651  runName = runList->at(i).GetRunName(j);
652  // get bin position of maximal data
653  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
654  // set t0 to maximum data position
655  runList->at(i).SetAddT0Bin(t0Bin, j-1, 0);
656  }
657  // handle backward histo
658  // get histo number
659  histoNo = runList->at(i).GetBackwardHistoNo();
660  runName = runList->at(i).GetRunName();
661  // get bin position of maximal data
662  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
663  // set t0 to maximum data position
664  runList->at(i).SetT0Bin(t0Bin, 1);
665  // set data range as well if firstGoodBinOffset is given
666  if (firstGoodBinOffsetPresent) {
667  start = t0Bin + firstGoodBinOffset;
668  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
669  runList->at(i).SetDataRange(start, 2);
670  runList->at(i).SetDataRange(end, 3);
671  }
672  // handle addruns
673  for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
674  runName = runList->at(i).GetRunName(j);
675  // get bin position of maximal data
676  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
677  // set t0 to maximum data position
678  runList->at(i).SetAddT0Bin(t0Bin, j-1, 1);
679  }
680  } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
681  // handle forward histo
682  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
683  // get histo number
684  histoNo = runList->at(i).GetForwardHistoNo(j);
685  runName = runList->at(i).GetRunName();
686  // get bin position of maximal data
687  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
688  // set t0 to maximum data position
689  runList->at(i).SetT0Bin(t0Bin, 2*j);
690  if (firstGoodBinOffsetPresent && (j==0)) {
691  start = t0Bin + firstGoodBinOffset;
692  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
693  runList->at(i).SetDataRange(start, 0);
694  runList->at(i).SetDataRange(end, 1);
695  }
696  }
697  // handle backward histo
698  for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
699  // get histo number
700  histoNo = runList->at(i).GetBackwardHistoNo(j);
701  runName = runList->at(i).GetRunName();
702  // get bin position of maximal data
703  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
704  // set t0 to maximum data position
705  runList->at(i).SetT0Bin(t0Bin, 2*j+1);
706  if (firstGoodBinOffsetPresent && (j==0)) {
707  start = t0Bin + firstGoodBinOffset;
708  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
709  runList->at(i).SetDataRange(start, 2);
710  runList->at(i).SetDataRange(end, 3);
711  }
712  }
713  } else { // addruns / grouping
714  // handle forward histo
715  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
716  // get histo number
717  histoNo = runList->at(i).GetForwardHistoNo(j);
718  runName = runList->at(i).GetRunName();
719  // get bin position of maximal data
720  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
721  // set t0 to maximum data position
722  runList->at(i).SetT0Bin(t0Bin, 2*j);
723  if (firstGoodBinOffsetPresent && (j==0)) {
724  start = t0Bin + firstGoodBinOffset;
725  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
726  runList->at(i).SetDataRange(start, 0);
727  runList->at(i).SetDataRange(end, 1);
728  }
729  // handle addruns
730  for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
731  runName = runList->at(i).GetRunName(k);
732  // get bin position of maximal data
733  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
734  // set t0 to maximum data position
735  runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j);
736  }
737  }
738  // handle backward histo
739  for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
740  // get histo number
741  histoNo = runList->at(i).GetBackwardHistoNo(j);
742  runName = runList->at(i).GetRunName();
743  // get bin position of maximal data
744  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
745  // set t0 to maximum data position
746  runList->at(i).SetT0Bin(t0Bin, 2*j+1);
747  if (firstGoodBinOffsetPresent && (j==0)) {
748  start = t0Bin + firstGoodBinOffset;
749  end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
750  runList->at(i).SetDataRange(start, 2);
751  runList->at(i).SetDataRange(end, 3);
752  }
753  // handle addruns
754  for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
755  runName = runList->at(i).GetRunName(k);
756  // get bin position of maximal data
757  t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
758  // set t0 to maximum data position
759  runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j+1);
760  }
761  }
762  }
763  break;
764  default:
765  break;
766  }
767  }
768  } else {
769 
770  // set t0's, data-range and bkg-range. There are 4 different cases, namely:
771  // 1. no addruns / no grouping of histos
772  // 2. addruns / no grouping of histos
773  // 3. no addruns / grouping of histos
774  // 4. addruns / grouping of histos
775  // case 1 is different form the others since t0, data-, and bkg-range can be collected for the given histogram
776  // cases 2-4 the procedure will be the following:
777  // 1) set for each given histogram the t0's
778  // 2) build the added up histogram, i.e. add all runs and/or histograms for the msr-run.
779  // 3) set the data-, and bkg-range
780  if (success) {
781  // generate Root application needed for PMusrCanvas
782  TApplication app("App", &argc, argv);
783 
784  PMusrT0Data musrT0Data;
785  std::vector<PRawRunData*> rawRunData;
786  PIntVector forwardHistos;
787  PIntVector backwardHistos;
788  // generate vector of all necessary PMusrT0 objects
789  for (UInt_t i=0; i<runList->size(); i++) {
790  fitType = runList->at(i).GetFitType();
791  if (fitType == -1) { // i.e. not found in the RUN block, check the GLOBAL block
792  fitType = msrHandler->GetMsrGlobal()->GetFitType();
793  }
794  switch (fitType) {
798  if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
799  // feed necessary data
800  musrT0Data.InitData();
801  musrT0Data.SetSingleHisto(true);
802  rawRunData.clear();
803  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
804  musrT0Data.SetRawRunData(rawRunData);
805  // feed data t0 if present
806  if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
807  musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
808  }
809  musrT0Data.SetRunNo(i);
810  musrT0Data.SetAddRunIdx(0); // no addruns
811  musrT0Data.SetHistoNoIdx(0);
812  forwardHistos.clear();
813  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
814  musrT0Data.SetHistoNo(forwardHistos);
815  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
817  // execute cmd
818  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
819  exit(0);
820  }
821  } else {
822  if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
823  // feed necessary data
824  musrT0Data.InitData();
825  musrT0Data.SetSingleHisto(true);
826  musrT0Data.SetRunNo(i);
827  musrT0Data.SetHistoNoIdx(0);
828  forwardHistos.clear();
829  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
830  musrT0Data.SetHistoNo(forwardHistos);
831  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
832  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
833  rawRunData.clear();
834  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
835  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
836  musrT0Data.SetRawRunData(rawRunData);
837  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) {
838  // feed data t0 if present
839  if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
840  musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
841  }
842  // feed necessary data
843  musrT0Data.SetAddRunIdx(j); // addruns
844  if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
845  exit(0);
846  }
847  }
848  } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
849  // feed necessary data
850  musrT0Data.InitData();
851  musrT0Data.SetSingleHisto(true);
852  musrT0Data.SetRunNo(i);
853  forwardHistos.clear();
854  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
855  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
856  musrT0Data.SetHistoNo(forwardHistos);
857  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
858  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
859  rawRunData.clear();
860  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
861  musrT0Data.SetRawRunData(rawRunData);
862  musrT0Data.SetAddRunIdx(0);
863  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
864  // feed data t0 if present
865  if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(j))) {
866  musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(j)));
867  }
868  // feed necessary data
869  musrT0Data.SetHistoNoIdx(j);
870  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
871  exit(0);
872  }
873  }
874  } else { // addruns / grouping
875  // feed necessary data
876  musrT0Data.InitData();
877  musrT0Data.SetSingleHisto(true);
878  musrT0Data.SetRunNo(i);
879  forwardHistos.clear();
880  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
881  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
882  musrT0Data.SetHistoNo(forwardHistos);
883  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
884  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
885  rawRunData.clear();
886  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
887  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
888  musrT0Data.SetRawRunData(rawRunData);
889  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) { // addrun / grouping
890  musrT0Data.SetAddRunIdx(j); // addruns
891  for (UInt_t k=0; k<runList->at(i).GetForwardHistoNoSize(); k++) { // forward histo grouping
892  // feed data t0 if present
893  if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(k))) {
894  musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(k)));
895  }
896  // feed necessary data
897  musrT0Data.SetHistoNoIdx(k);
898  if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
899  exit(0);
900  }
901  }
902  }
903  }
904  // get data- and bkg-range
906  // feed all t0's
907  for (UInt_t j=0; j<runList->at(i).GetT0BinSize(); j++) {
908  musrT0Data.SetT0Bin((UInt_t)runList->at(i).GetT0Bin(j), j);
909  for (UInt_t k=0; k<runList->at(i).GetAddT0BinEntries(); k++) {
910  musrT0Data.SetAddT0Bin((UInt_t)runList->at(i).GetAddT0Bin(k, j), k, j);
911  }
912  }
913  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
914  exit(0);
915  }
916  }
917  break;
918  case MSR_FITTYPE_ASYM:
919  case MSR_FITTYPE_BNMR:
921  if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
922  // feed necessary data forward
923  musrT0Data.InitData();
924  musrT0Data.SetSingleHisto(false);
925  rawRunData.clear();
926  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
927  musrT0Data.SetRawRunData(rawRunData);
928  // feed data t0 if present
929  if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
930  musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
931  }
932  musrT0Data.SetRunNo(i);
933  musrT0Data.SetAddRunIdx(0); // no addruns
934  musrT0Data.SetHistoNoIdx(0);
935  forwardHistos.clear();
936  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
937  musrT0Data.SetHistoNo(forwardHistos);
938  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
940  // execute cmd
941  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
942  exit(0);
943  }
944  // feed necessary data backward
945  musrT0Data.InitData();
946  musrT0Data.SetSingleHisto(false);
947  rawRunData.clear();
948  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
949  musrT0Data.SetRawRunData(rawRunData);
950  // feed data t0 if present
951  if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
952  musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
953  }
954  musrT0Data.SetRunNo(i);
955  musrT0Data.SetAddRunIdx(0); // no addruns
956  musrT0Data.SetHistoNoIdx(0);
957  backwardHistos.clear();
958  backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(0));
959  musrT0Data.SetHistoNo(backwardHistos);
960  musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
962  // execute cmd
963  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
964  exit(0);
965  }
966  } else {
967  // get t0's
968  if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
969  // feed necessary forward data
970  musrT0Data.InitData();
971  musrT0Data.SetSingleHisto(false);
972  musrT0Data.SetRunNo(i);
973  musrT0Data.SetHistoNoIdx(0);
974  forwardHistos.clear();
975  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
976  musrT0Data.SetHistoNo(forwardHistos);
977  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
978  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
979  rawRunData.clear();
980  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
981  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
982  musrT0Data.SetRawRunData(rawRunData);
983  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) {
984  // feed data t0 if present
985  if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
986  musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
987  }
988  // feed necessary data
989  musrT0Data.SetAddRunIdx(j); // addruns
990  if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
991  exit(0);
992  }
993  }
994  // feed necessary backward data
995  musrT0Data.InitData();
996  musrT0Data.SetSingleHisto(false);
997  musrT0Data.SetRunNo(i);
998  musrT0Data.SetHistoNoIdx(0);
999  backwardHistos.clear();
1000  backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(0));
1001  musrT0Data.SetHistoNo(backwardHistos);
1002  musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1003  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1004  rawRunData.clear();
1005  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
1006  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
1007  musrT0Data.SetRawRunData(rawRunData);
1008  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) {
1009  // feed data t0 if present
1010  if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
1011  musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
1012  }
1013  // feed necessary data
1014  musrT0Data.SetAddRunIdx(j); // addruns
1015  if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
1016  exit(0);
1017  }
1018  }
1019  } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
1020  // feed necessary forward data
1021  musrT0Data.InitData();
1022  musrT0Data.SetSingleHisto(false);
1023  musrT0Data.SetRunNo(i);
1024  forwardHistos.clear();
1025  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
1026  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
1027  musrT0Data.SetHistoNo(forwardHistos);
1028  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
1029  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1030  rawRunData.clear();
1031  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
1032  musrT0Data.SetRawRunData(rawRunData);
1033  musrT0Data.SetAddRunIdx(0);
1034  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
1035  // feed data t0 if present
1036  if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(j))) {
1037  musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(j)));
1038  }
1039  // feed necessary data
1040  musrT0Data.SetHistoNoIdx(j);
1041  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1042  exit(0);
1043  }
1044  }
1045  // feed necessary backward data
1046  musrT0Data.InitData();
1047  musrT0Data.SetSingleHisto(false);
1048  musrT0Data.SetRunNo(i);
1049  backwardHistos.clear();
1050  for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++)
1051  backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(j));
1052  musrT0Data.SetHistoNo(backwardHistos);
1053  musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1054  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1055  rawRunData.clear();
1056  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
1057  musrT0Data.SetRawRunData(rawRunData);
1058  musrT0Data.SetAddRunIdx(0);
1059  for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
1060  // feed data t0 if present
1061  if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(j))) {
1062  musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(j)));
1063  }
1064  // feed necessary data
1065  musrT0Data.SetHistoNoIdx(j);
1066  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1067  exit(0);
1068  }
1069  }
1070  } else { // addruns / grouping
1071  // feed necessary forward data
1072  musrT0Data.InitData();
1073  musrT0Data.SetSingleHisto(false);
1074  musrT0Data.SetRunNo(i);
1075  forwardHistos.clear();
1076  for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
1077  forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
1078  musrT0Data.SetHistoNo(forwardHistos);
1079  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
1080  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1081  rawRunData.clear();
1082  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
1083  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
1084  musrT0Data.SetRawRunData(rawRunData);
1085  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) { // addrun / grouping
1086  musrT0Data.SetAddRunIdx(j); // addruns
1087  for (UInt_t k=0; k<runList->at(i).GetForwardHistoNoSize(); k++) { // forward histo grouping
1088  // feed data t0 if present
1089  if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(k))) {
1090  musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(k)));
1091  }
1092  // feed necessary data
1093  musrT0Data.SetHistoNoIdx(k);
1094  if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
1095  exit(0);
1096  }
1097  }
1098  }
1099  // feed necessary backward data
1100  musrT0Data.InitData();
1101  musrT0Data.SetSingleHisto(false);
1102  musrT0Data.SetRunNo(i);
1103  backwardHistos.clear();
1104  for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++)
1105  backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(j));
1106  musrT0Data.SetHistoNo(backwardHistos);
1107  musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1108  musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1109  rawRunData.clear();
1110  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
1111  rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
1112  musrT0Data.SetRawRunData(rawRunData);
1113  for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) { // addrun / grouping
1114  musrT0Data.SetAddRunIdx(j); // addruns
1115  for (UInt_t k=0; k<runList->at(i).GetBackwardHistoNoSize(); k++) { // backward histo grouping
1116  // feed data t0 if present
1117  if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(k))) {
1118  musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(k)));
1119  }
1120  // feed necessary data
1121  musrT0Data.SetHistoNoIdx(k);
1122  if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
1123  exit(0);
1124  }
1125  }
1126  }
1127  }
1128  // get data- and bkg-range
1130  // feed all t0's
1131  for (UInt_t j=0; j<runList->at(i).GetT0BinSize(); j++) {
1132  musrT0Data.SetT0Bin((UInt_t)runList->at(i).GetT0Bin(j), j);
1133  for (UInt_t k=0; k<runList->at(i).GetAddT0BinEntries(); k++) {
1134  musrT0Data.SetAddT0Bin((UInt_t)runList->at(i).GetAddT0Bin(k, j), k, j);
1135  }
1136  }
1137  musrT0Data.SetHistoNo(forwardHistos);
1138  musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
1139  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1140  exit(0);
1141  }
1142  musrT0Data.SetHistoNo(backwardHistos);
1143  musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1144  if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1145  exit(0);
1146  }
1147  }
1148  break;
1149  default:
1150  break;
1151  }
1152  }
1153  // cleanup
1154  rawRunData.clear();
1155  forwardHistos.clear();
1156  backwardHistos.clear();
1157  }
1158  }
1159 
1160  // write msr-file
1161  msrHandler->WriteMsrLogFile(false);
1162 
1163  // swap msr- and mlog-file
1164  // copy msr-file -> __temp.msr
1165  gSystem->CopyFile(filename, "__temp.msr", kTRUE);
1166  // copy mlog-file -> msr-file
1167  TString fln = TString(filename);
1168  Char_t ext[32];
1169  strcpy(ext, ".mlog");
1170  fln.ReplaceAll(".msr", 4, ext, strlen(ext));
1171  gSystem->CopyFile(fln.Data(), filename, kTRUE);
1172  // copy __temp.msr -> mlog-file
1173  gSystem->CopyFile("__temp.msr", fln.Data(), kTRUE);
1174  // delete __temp.msr
1175  gSystem->Exec("rm __temp.msr");
1176 
1177  return PMUSR_SUCCESS;
1178 }
virtual void InitData()
Definition: PMusrT0.cpp:76
#define MSR_FITTYPE_BNMR
Definition: PMusr.h:111
void musrt0_syntax()
Definition: musrt0.cpp:60
std::vector< PMsrRunBlock > PMsrRunList
Definition: PMusr.h:754
#define MSR_FITTYPE_SINGLE_HISTO_RRF
Definition: PMusr.h:107
virtual Int_t GetCmdTag()
Definition: PMusrT0.h:80
#define MSR_FITTYPE_SINGLE_HISTO
Definition: PMusr.h:106
Bool_t musrt0_item(TApplication &app, PMsrHandler *msrHandler, PMusrT0Data &data, UInt_t idx, Int_t timeout)
Definition: musrt0.cpp:96
int parseXmlFile(TSAXParser *, const char *)
#define PMUSRT0_GET_DATA_AND_BKG_RANGE
Definition: PMusrT0.h:55
#define PMUSR_MSR_FILE_NOT_FOUND
Definition: PMusr.h:47
virtual void SetT0Bin(UInt_t val, UInt_t idx)
Definition: PMusrT0.cpp:206
std::vector< Int_t > PIntVector
Definition: PMusr.h:178
std::vector< Double_t > PDoubleVector
Definition: PMusr.h:196
virtual void SetDetectorTag(const UInt_t detectorTag)
Definition: PMusrT0.h:94
virtual void SetT0BinData(UInt_t val)
Definition: PMusrT0.h:98
#define MSR_FITTYPE_NON_MUSR
Definition: PMusr.h:112
virtual void SetRunNo(const UInt_t runNo)
Definition: PMusrT0.h:90
const char * startup_path_name
static int timeout
Definition: musrfit.cpp:71
virtual void SetCmdTag(const UInt_t cmdTag)
Definition: PMusrT0.h:95
Int_t musrt0_getMaxBin(const PDoubleVector *data)
Definition: musrt0.cpp:144
virtual void SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx)
Definition: PMusrT0.cpp:224
virtual void SetSingleHisto(const Bool_t flag)
Definition: PMusrT0.h:88
#define PMUSRT0_GET_T0
Definition: PMusrT0.h:54
#define MSR_FITTYPE_MU_MINUS
Definition: PMusr.h:110
#define PMUSR_MSR_SYNTAX_ERROR
Definition: PMusr.h:49
virtual void SetHistoNoIdx(const UInt_t histoNoIdx)
Definition: PMusrT0.h:92
#define PMUSR_WRONG_STARTUP_SYNTAX
Definition: PMusr.h:46
virtual void SetRawRunData(const std::vector< PRawRunData *> rawRunData)
Definition: PMusrT0.h:89
#define PMUSRT0_GET_T0_DATA_AND_BKG_RANGE
Definition: PMusrT0.h:56
#define PMUSRT0_FORWARD
Definition: PMusrT0.h:51
Int_t main(Int_t argc, Char_t *argv[])
Definition: musrt0.cpp:176
#define MSR_FITTYPE_ASYM_RRF
Definition: PMusr.h:109
#define PMUSR_SUCCESS
Definition: PMusr.h:44
virtual void SetHistoNo(const PIntVector histoNo)
Definition: PMusrT0.h:93
#define PMUSRT0_BACKWARD
Definition: PMusrT0.h:52
#define MSR_FITTYPE_ASYM
Definition: PMusr.h:108
return status
virtual void SetAddRunIdx(const UInt_t addRunIdx)
Definition: PMusrT0.h:91