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