musrfit 1.10.0
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
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//--------------------------------------------------------------------------
96Bool_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//--------------------------------------------------------------------------
145{
146 Int_t maxBin = -1;
147 Double_t maxData = -999;
148
149 if (data == nullptr)
150 return maxBin;
151
152 for (UInt_t i=0; i<data->size(); i++) {
153 if (data->at(i) > maxData) {
154 maxData = data->at(i);
155 maxBin = i;
156 }
157 }
158
159 return maxBin;
160}
161
162//--------------------------------------------------------------------------
179Int_t main(Int_t argc, Char_t *argv[])
180{
181 Bool_t show_syntax = false;
182 Int_t status;
183 Bool_t success = true;
184 Char_t filename[1024];
185 Bool_t getT0FromPromptPeak = false;
186 Bool_t firstGoodBinOffsetPresent = false;
187 Int_t firstGoodBinOffset = 0;
188 Int_t timeout = 0;
189 Int_t fitType = -1;
190
191 if (argc == 1) {
193 return PMUSR_SUCCESS;
194 }
195
196 // add default shared library path /usr/local/lib if not already persent
197 const char *dsp = gSystem->GetDynamicPath();
198 if (strstr(dsp, "/usr/local/lib") == nullptr)
199 gSystem->AddDynamicPath("/usr/local/lib");
200
201 memset(filename, '\0', sizeof(filename));
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 (strlen(filename) == 0) {
227 strncpy(filename, argv[i], sizeof(filename));
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 (strlen(filename) == 0) {
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 Char_t startup_path_name[128];
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 strcpy(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);
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);
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 // check if the fittype is not NonMusr
316 PMsrRunList *runList = msrHandler->GetMsrRunList();
317 for (UInt_t i=0; i<runList->size(); i++) {
318 fitType = runList->at(i).GetFitType();
319 if (fitType == -1) { // i.e. not found in the RUN block, check the GLOBAL block
320 fitType = msrHandler->GetMsrGlobal()->GetFitType();
321 }
322 if (fitType == MSR_FITTYPE_NON_MUSR) {
323 std::cout << std::endl << ">> musrt0 **ERROR** t0 setting for NonMusr fit type doesn't make any sense, will quit ..." << std::endl;
324 success = false;
325 break;
326 }
327 }
328
329 // read all the necessary runs (raw data)
330 std::unique_ptr<PRunDataHandler> dataHandler;
331 if (success) {
332 if (startupHandler)
333 dataHandler = std::make_unique<PRunDataHandler>(msrHandler.get(), startupHandler->GetDataPathList());
334 else
335 dataHandler = std::make_unique<PRunDataHandler>(msrHandler.get());
336
337 dataHandler->ReadData();
338
339 success = dataHandler->IsAllDataAvailable();
340 if (!success) {
341 std::cout << std::endl << ">> musrt0 **ERROR** Couldn't read all data files, will quit ..." << std::endl;
342 }
343 }
344
345 if (getT0FromPromptPeak && success) {
346
347 Int_t histoNo = -1;
348 UInt_t t0Bin = 0;
349 TString *runName = nullptr;
350 UInt_t start, end;
351
352 // go through all runs in the msr-file
353 for (UInt_t i=0; i<runList->size(); i++) {
354 fitType = runList->at(i).GetFitType();
355 if (fitType == -1) { // i.e. not found in the RUN block, check the GLOBAL block
356 fitType = msrHandler->GetMsrGlobal()->GetFitType();
357 }
358 switch (fitType) {
361 if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
362 // get histo number
363 histoNo = runList->at(i).GetForwardHistoNo();
364 runName = runList->at(i).GetRunName();
365 // get bin position of maximal data
366 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
367 // set t0 to maximum data position
368 runList->at(i).SetT0Bin(t0Bin, 0);
369 // set data range as well if firstGoodBinOffset is given
370 if (firstGoodBinOffsetPresent) {
371 start = t0Bin + firstGoodBinOffset;
372 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
373 runList->at(i).SetDataRange(start, 0);
374 runList->at(i).SetDataRange(end, 1);
375 }
376 } else if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
377 // get histo number
378 histoNo = runList->at(i).GetForwardHistoNo();
379 runName = runList->at(i).GetRunName();
380 // get bin position of maximal data
381 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
382 // set t0 to maximum data position
383 runList->at(i).SetT0Bin(t0Bin, 0);
384 // set data range as well if firstGoodBinOffset is given
385 if (firstGoodBinOffsetPresent) {
386 start = t0Bin + firstGoodBinOffset;
387 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
388 runList->at(i).SetDataRange(start, 0);
389 runList->at(i).SetDataRange(end, 1);
390 }
391 // handle addruns
392 for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
393 runName = runList->at(i).GetRunName(j);
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).SetAddT0Bin(t0Bin, j-1, 0);
398 }
399 } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
400 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
401 // get histo number
402 histoNo = runList->at(i).GetForwardHistoNo(j);
403 runName = runList->at(i).GetRunName();
404 // get bin position of maximal data
405 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
406 // set t0 to maximum data position
407 runList->at(i).SetT0Bin(t0Bin, j);
408 if (firstGoodBinOffsetPresent && (j==0)) {
409 start = t0Bin + firstGoodBinOffset;
410 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
411 runList->at(i).SetDataRange(start, 0);
412 runList->at(i).SetDataRange(end, 1);
413 }
414 }
415 } else { // addruns / grouping
416 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
417 // get histo number
418 histoNo = runList->at(i).GetForwardHistoNo(j);
419 runName = runList->at(i).GetRunName();
420 // get bin position of maximal data
421 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
422 // set t0 to maximum data position
423 runList->at(i).SetT0Bin(t0Bin, j);
424 if (firstGoodBinOffsetPresent && (j==0)) {
425 start = t0Bin + firstGoodBinOffset;
426 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
427 runList->at(i).SetDataRange(start, 0);
428 runList->at(i).SetDataRange(end, 1);
429 }
430 // handle addruns
431 for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
432 runName = runList->at(i).GetRunName(k);
433 // get bin position of maximal data
434 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
435 // set t0 to maximum data position
436 runList->at(i).SetAddT0Bin(t0Bin, k-1, j);
437 }
438 }
439 }
440 break;
441 case MSR_FITTYPE_ASYM:
442 if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
443 // handle forward histo
444 // get histo number
445 histoNo = runList->at(i).GetForwardHistoNo();
446 runName = runList->at(i).GetRunName();
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).SetT0Bin(t0Bin, 0);
451 // set data range as well if firstGoodBinOffset is given
452 if (firstGoodBinOffsetPresent) {
453 start = t0Bin + firstGoodBinOffset;
454 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
455 runList->at(i).SetDataRange(start, 0);
456 runList->at(i).SetDataRange(end, 1);
457 }
458 // handle backward histo
459 // get histo number
460 histoNo = runList->at(i).GetBackwardHistoNo();
461 runName = runList->at(i).GetRunName();
462 // get bin position of maximal data
463 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
464 // set t0 to maximum data position
465 runList->at(i).SetT0Bin(t0Bin, 1);
466 // set data range as well if firstGoodBinOffset is given
467 if (firstGoodBinOffsetPresent) {
468 start = t0Bin + firstGoodBinOffset;
469 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
470 runList->at(i).SetDataRange(start, 2);
471 runList->at(i).SetDataRange(end, 3);
472 }
473 } else if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
474 // handle forward histo
475 // get histo number
476 histoNo = runList->at(i).GetForwardHistoNo();
477 runName = runList->at(i).GetRunName();
478 // get bin position of maximal data
479 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
480 // set t0 to maximum data position
481 runList->at(i).SetT0Bin(t0Bin, 0);
482 // set data range as well if firstGoodBinOffset is given
483 if (firstGoodBinOffsetPresent) {
484 start = t0Bin + firstGoodBinOffset;
485 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
486 runList->at(i).SetDataRange(start, 0);
487 runList->at(i).SetDataRange(end, 1);
488 }
489 // handle addruns
490 for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
491 runName = runList->at(i).GetRunName(j);
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).SetAddT0Bin(t0Bin, j-1, 0);
496 }
497 // handle backward histo
498 // get histo number
499 histoNo = runList->at(i).GetBackwardHistoNo();
500 runName = runList->at(i).GetRunName();
501 // get bin position of maximal data
502 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
503 // set t0 to maximum data position
504 runList->at(i).SetT0Bin(t0Bin, 1);
505 // set data range as well if firstGoodBinOffset is given
506 if (firstGoodBinOffsetPresent) {
507 start = t0Bin + firstGoodBinOffset;
508 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
509 runList->at(i).SetDataRange(start, 2);
510 runList->at(i).SetDataRange(end, 3);
511 }
512 // handle addruns
513 for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
514 runName = runList->at(i).GetRunName(j);
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).SetAddT0Bin(t0Bin, j-1, 1);
519 }
520 } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
521 // handle forward histo
522 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
523 // get histo number
524 histoNo = runList->at(i).GetForwardHistoNo(j);
525 runName = runList->at(i).GetRunName();
526 // get bin position of maximal data
527 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
528 // set t0 to maximum data position
529 runList->at(i).SetT0Bin(t0Bin, 2*j);
530 if (firstGoodBinOffsetPresent && (j==0)) {
531 start = t0Bin + firstGoodBinOffset;
532 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
533 runList->at(i).SetDataRange(start, 0);
534 runList->at(i).SetDataRange(end, 1);
535 }
536 }
537 // handle backward histo
538 for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
539 // get histo number
540 histoNo = runList->at(i).GetBackwardHistoNo(j);
541 runName = runList->at(i).GetRunName();
542 // get bin position of maximal data
543 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
544 // set t0 to maximum data position
545 runList->at(i).SetT0Bin(t0Bin, 2*j+1);
546 if (firstGoodBinOffsetPresent && (j==0)) {
547 start = t0Bin + firstGoodBinOffset;
548 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
549 runList->at(i).SetDataRange(start, 2);
550 runList->at(i).SetDataRange(end, 3);
551 }
552 }
553 } else { // addruns / grouping
554 // handle forward histo
555 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
556 // get histo number
557 histoNo = runList->at(i).GetForwardHistoNo(j);
558 runName = runList->at(i).GetRunName();
559 // get bin position of maximal data
560 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
561 // set t0 to maximum data position
562 runList->at(i).SetT0Bin(t0Bin, 2*j);
563 if (firstGoodBinOffsetPresent && (j==0)) {
564 start = t0Bin + firstGoodBinOffset;
565 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
566 runList->at(i).SetDataRange(start, 0);
567 runList->at(i).SetDataRange(end, 1);
568 }
569 // handle addruns
570 for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
571 runName = runList->at(i).GetRunName(k);
572 // get bin position of maximal data
573 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
574 // set t0 to maximum data position
575 runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j);
576 }
577 }
578 // handle backward histo
579 for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
580 // get histo number
581 histoNo = runList->at(i).GetBackwardHistoNo(j);
582 runName = runList->at(i).GetRunName();
583 // get bin position of maximal data
584 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
585 // set t0 to maximum data position
586 runList->at(i).SetT0Bin(t0Bin, 2*j+1);
587 if (firstGoodBinOffsetPresent && (j==0)) {
588 start = t0Bin + firstGoodBinOffset;
589 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
590 runList->at(i).SetDataRange(start, 2);
591 runList->at(i).SetDataRange(end, 3);
592 }
593 // handle addruns
594 for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
595 runName = runList->at(i).GetRunName(k);
596 // get bin position of maximal data
597 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
598 // set t0 to maximum data position
599 runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j+1);
600 }
601 }
602 }
603 break;
604 case MSR_FITTYPE_BNMR:
605 if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
606 // handle forward histo
607 // get histo number
608 histoNo = runList->at(i).GetForwardHistoNo();
609 runName = runList->at(i).GetRunName();
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).SetT0Bin(t0Bin, 0);
614 // set data range as well if firstGoodBinOffset is given
615 if (firstGoodBinOffsetPresent) {
616 start = t0Bin + firstGoodBinOffset;
617 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
618 runList->at(i).SetDataRange(start, 0);
619 runList->at(i).SetDataRange(end, 1);
620 }
621 // handle backward histo
622 // get histo number
623 histoNo = runList->at(i).GetBackwardHistoNo();
624 runName = runList->at(i).GetRunName();
625 // get bin position of maximal data
626 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
627 // set t0 to maximum data position
628 runList->at(i).SetT0Bin(t0Bin, 1);
629 // set data range as well if firstGoodBinOffset is given
630 if (firstGoodBinOffsetPresent) {
631 start = t0Bin + firstGoodBinOffset;
632 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
633 runList->at(i).SetDataRange(start, 2);
634 runList->at(i).SetDataRange(end, 3);
635 }
636 } else if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
637 // handle forward histo
638 // get histo number
639 histoNo = runList->at(i).GetForwardHistoNo();
640 runName = runList->at(i).GetRunName();
641 // get bin position of maximal data
642 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
643 // set t0 to maximum data position
644 runList->at(i).SetT0Bin(t0Bin, 0);
645 // set data range as well if firstGoodBinOffset is given
646 if (firstGoodBinOffsetPresent) {
647 start = t0Bin + firstGoodBinOffset;
648 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
649 runList->at(i).SetDataRange(start, 0);
650 runList->at(i).SetDataRange(end, 1);
651 }
652 // handle addruns
653 for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
654 runName = runList->at(i).GetRunName(j);
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).SetAddT0Bin(t0Bin, j-1, 0);
659 }
660 // handle backward histo
661 // get histo number
662 histoNo = runList->at(i).GetBackwardHistoNo();
663 runName = runList->at(i).GetRunName();
664 // get bin position of maximal data
665 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
666 // set t0 to maximum data position
667 runList->at(i).SetT0Bin(t0Bin, 1);
668 // set data range as well if firstGoodBinOffset is given
669 if (firstGoodBinOffsetPresent) {
670 start = t0Bin + firstGoodBinOffset;
671 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
672 runList->at(i).SetDataRange(start, 2);
673 runList->at(i).SetDataRange(end, 3);
674 }
675 // handle addruns
676 for (UInt_t j=1; j<runList->at(i).GetRunNameSize(); j++) {
677 runName = runList->at(i).GetRunName(j);
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).SetAddT0Bin(t0Bin, j-1, 1);
682 }
683 } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
684 // handle forward histo
685 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
686 // get histo number
687 histoNo = runList->at(i).GetForwardHistoNo(j);
688 runName = runList->at(i).GetRunName();
689 // get bin position of maximal data
690 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
691 // set t0 to maximum data position
692 runList->at(i).SetT0Bin(t0Bin, 2*j);
693 if (firstGoodBinOffsetPresent && (j==0)) {
694 start = t0Bin + firstGoodBinOffset;
695 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
696 runList->at(i).SetDataRange(start, 0);
697 runList->at(i).SetDataRange(end, 1);
698 }
699 }
700 // handle backward histo
701 for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
702 // get histo number
703 histoNo = runList->at(i).GetBackwardHistoNo(j);
704 runName = runList->at(i).GetRunName();
705 // get bin position of maximal data
706 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
707 // set t0 to maximum data position
708 runList->at(i).SetT0Bin(t0Bin, 2*j+1);
709 if (firstGoodBinOffsetPresent && (j==0)) {
710 start = t0Bin + firstGoodBinOffset;
711 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
712 runList->at(i).SetDataRange(start, 2);
713 runList->at(i).SetDataRange(end, 3);
714 }
715 }
716 } else { // addruns / grouping
717 // handle forward histo
718 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
719 // get histo number
720 histoNo = runList->at(i).GetForwardHistoNo(j);
721 runName = runList->at(i).GetRunName();
722 // get bin position of maximal data
723 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
724 // set t0 to maximum data position
725 runList->at(i).SetT0Bin(t0Bin, 2*j);
726 if (firstGoodBinOffsetPresent && (j==0)) {
727 start = t0Bin + firstGoodBinOffset;
728 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
729 runList->at(i).SetDataRange(start, 0);
730 runList->at(i).SetDataRange(end, 1);
731 }
732 // handle addruns
733 for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
734 runName = runList->at(i).GetRunName(k);
735 // get bin position of maximal data
736 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
737 // set t0 to maximum data position
738 runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j);
739 }
740 }
741 // handle backward histo
742 for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
743 // get histo number
744 histoNo = runList->at(i).GetBackwardHistoNo(j);
745 runName = runList->at(i).GetRunName();
746 // get bin position of maximal data
747 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
748 // set t0 to maximum data position
749 runList->at(i).SetT0Bin(t0Bin, 2*j+1);
750 if (firstGoodBinOffsetPresent && (j==0)) {
751 start = t0Bin + firstGoodBinOffset;
752 end = dataHandler->GetRunData(*runName)->GetDataBin(histoNo)->size();
753 runList->at(i).SetDataRange(start, 2);
754 runList->at(i).SetDataRange(end, 3);
755 }
756 // handle addruns
757 for (UInt_t k=1; k<runList->at(i).GetRunNameSize(); k++) {
758 runName = runList->at(i).GetRunName(k);
759 // get bin position of maximal data
760 t0Bin = musrt0_getMaxBin(dataHandler->GetRunData(*runName)->GetDataBin(histoNo));
761 // set t0 to maximum data position
762 runList->at(i).SetAddT0Bin(t0Bin, k-1, 2*j+1);
763 }
764 }
765 }
766 break;
767 default:
768 break;
769 }
770 }
771 } else {
772
773 // set t0's, data-range and bkg-range. There are 4 different cases, namely:
774 // 1. no addruns / no grouping of histos
775 // 2. addruns / no grouping of histos
776 // 3. no addruns / grouping of histos
777 // 4. addruns / grouping of histos
778 // case 1 is different form the others since t0, data-, and bkg-range can be collected for the given histogram
779 // cases 2-4 the procedure will be the following:
780 // 1) set for each given histogram the t0's
781 // 2) build the added up histogram, i.e. add all runs and/or histograms for the msr-run.
782 // 3) set the data-, and bkg-range
783 if (success) {
784 // generate Root application needed for PMusrCanvas
785 TApplication app("App", nullptr, nullptr);
786
787 PMusrT0Data musrT0Data;
788 std::vector<PRawRunData*> rawRunData;
789 PIntVector forwardHistos;
790 PIntVector backwardHistos;
791 // generate vector of all necessary PMusrT0 objects
792 for (UInt_t i=0; i<runList->size(); i++) {
793 fitType = runList->at(i).GetFitType();
794 if (fitType == -1) { // i.e. not found in the RUN block, check the GLOBAL block
795 fitType = msrHandler->GetMsrGlobal()->GetFitType();
796 }
797 switch (fitType) {
801 if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
802 // feed necessary data
803 musrT0Data.InitData();
804 musrT0Data.SetSingleHisto(true);
805 rawRunData.clear();
806 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
807 musrT0Data.SetRawRunData(rawRunData);
808 // feed data t0 if present
809 if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
810 musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
811 }
812 musrT0Data.SetRunNo(i);
813 musrT0Data.SetAddRunIdx(0); // no addruns
814 musrT0Data.SetHistoNoIdx(0);
815 forwardHistos.clear();
816 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
817 musrT0Data.SetHistoNo(forwardHistos);
820 // execute cmd
821 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
822 return 0;
823 }
824 } else {
825 if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
826 // feed necessary data
827 musrT0Data.InitData();
828 musrT0Data.SetSingleHisto(true);
829 musrT0Data.SetRunNo(i);
830 musrT0Data.SetHistoNoIdx(0);
831 forwardHistos.clear();
832 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
833 musrT0Data.SetHistoNo(forwardHistos);
835 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
836 rawRunData.clear();
837 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
838 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
839 musrT0Data.SetRawRunData(rawRunData);
840 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) {
841 // feed data t0 if present
842 if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
843 musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
844 }
845 // feed necessary data
846 musrT0Data.SetAddRunIdx(j); // addruns
847 if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
848 return 0;
849 }
850 }
851 } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
852 // feed necessary data
853 musrT0Data.InitData();
854 musrT0Data.SetSingleHisto(true);
855 musrT0Data.SetRunNo(i);
856 forwardHistos.clear();
857 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
858 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
859 musrT0Data.SetHistoNo(forwardHistos);
861 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
862 rawRunData.clear();
863 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
864 musrT0Data.SetRawRunData(rawRunData);
865 musrT0Data.SetAddRunIdx(0);
866 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
867 // feed data t0 if present
868 if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(j))) {
869 musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(j)));
870 }
871 // feed necessary data
872 musrT0Data.SetHistoNoIdx(j);
873 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
874 return 0;
875 }
876 }
877 } else { // addruns / grouping
878 // feed necessary data
879 musrT0Data.InitData();
880 musrT0Data.SetSingleHisto(true);
881 musrT0Data.SetRunNo(i);
882 forwardHistos.clear();
883 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
884 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
885 musrT0Data.SetHistoNo(forwardHistos);
887 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
888 rawRunData.clear();
889 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
890 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
891 musrT0Data.SetRawRunData(rawRunData);
892 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) { // addrun / grouping
893 musrT0Data.SetAddRunIdx(j); // addruns
894 for (UInt_t k=0; k<runList->at(i).GetForwardHistoNoSize(); k++) { // forward histo grouping
895 // feed data t0 if present
896 if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(k))) {
897 musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(k)));
898 }
899 // feed necessary data
900 musrT0Data.SetHistoNoIdx(k);
901 if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
902 return 0;
903 }
904 }
905 }
906 }
907 // get data- and bkg-range
909 // feed all t0's
910 for (UInt_t j=0; j<runList->at(i).GetT0BinSize(); j++) {
911 musrT0Data.SetT0Bin((UInt_t)runList->at(i).GetT0Bin(j), j);
912 for (UInt_t k=0; k<runList->at(i).GetAddT0BinEntries(); k++) {
913 musrT0Data.SetAddT0Bin((UInt_t)runList->at(i).GetAddT0Bin(k, j), k, j);
914 }
915 }
916 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
917 return 0;
918 }
919 }
920 break;
921 case MSR_FITTYPE_ASYM:
922 case MSR_FITTYPE_BNMR:
924 if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping
925 // feed necessary data forward
926 musrT0Data.InitData();
927 musrT0Data.SetSingleHisto(false);
928 rawRunData.clear();
929 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
930 musrT0Data.SetRawRunData(rawRunData);
931 // feed data t0 if present
932 if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
933 musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
934 }
935 musrT0Data.SetRunNo(i);
936 musrT0Data.SetAddRunIdx(0); // no addruns
937 musrT0Data.SetHistoNoIdx(0);
938 forwardHistos.clear();
939 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
940 musrT0Data.SetHistoNo(forwardHistos);
943 // execute cmd
944 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
945 return 0;
946 }
947 // feed necessary data backward
948 musrT0Data.InitData();
949 musrT0Data.SetSingleHisto(false);
950 rawRunData.clear();
951 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
952 musrT0Data.SetRawRunData(rawRunData);
953 // feed data t0 if present
954 if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
955 musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
956 }
957 musrT0Data.SetRunNo(i);
958 musrT0Data.SetAddRunIdx(0); // no addruns
959 musrT0Data.SetHistoNoIdx(0);
960 backwardHistos.clear();
961 backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(0));
962 musrT0Data.SetHistoNo(backwardHistos);
965 // execute cmd
966 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
967 return 0;
968 }
969 } else {
970 // get t0's
971 if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping
972 // feed necessary forward data
973 musrT0Data.InitData();
974 musrT0Data.SetSingleHisto(false);
975 musrT0Data.SetRunNo(i);
976 musrT0Data.SetHistoNoIdx(0);
977 forwardHistos.clear();
978 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0));
979 musrT0Data.SetHistoNo(forwardHistos);
981 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
982 rawRunData.clear();
983 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
984 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
985 musrT0Data.SetRawRunData(rawRunData);
986 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) {
987 // feed data t0 if present
988 if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
989 musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
990 }
991 // feed necessary data
992 musrT0Data.SetAddRunIdx(j); // addruns
993 if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
994 return 0;
995 }
996 }
997 // feed necessary backward data
998 musrT0Data.InitData();
999 musrT0Data.SetSingleHisto(false);
1000 musrT0Data.SetRunNo(i);
1001 musrT0Data.SetHistoNoIdx(0);
1002 backwardHistos.clear();
1003 backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(0));
1004 musrT0Data.SetHistoNo(backwardHistos);
1005 musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1006 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1007 rawRunData.clear();
1008 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
1009 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
1010 musrT0Data.SetRawRunData(rawRunData);
1011 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) {
1012 // feed data t0 if present
1013 if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(0))) {
1014 musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(0)));
1015 }
1016 // feed necessary data
1017 musrT0Data.SetAddRunIdx(j); // addruns
1018 if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
1019 return 0;
1020 }
1021 }
1022 } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping
1023 // feed necessary forward data
1024 musrT0Data.InitData();
1025 musrT0Data.SetSingleHisto(false);
1026 musrT0Data.SetRunNo(i);
1027 forwardHistos.clear();
1028 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
1029 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
1030 musrT0Data.SetHistoNo(forwardHistos);
1031 musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
1032 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1033 rawRunData.clear();
1034 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
1035 musrT0Data.SetRawRunData(rawRunData);
1036 musrT0Data.SetAddRunIdx(0);
1037 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++) {
1038 // feed data t0 if present
1039 if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(j))) {
1040 musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(j)));
1041 }
1042 // feed necessary data
1043 musrT0Data.SetHistoNoIdx(j);
1044 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1045 return 0;
1046 }
1047 }
1048 // feed necessary backward data
1049 musrT0Data.InitData();
1050 musrT0Data.SetSingleHisto(false);
1051 musrT0Data.SetRunNo(i);
1052 backwardHistos.clear();
1053 for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++)
1054 backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(j));
1055 musrT0Data.SetHistoNo(backwardHistos);
1056 musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1057 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1058 rawRunData.clear();
1059 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0))));
1060 musrT0Data.SetRawRunData(rawRunData);
1061 musrT0Data.SetAddRunIdx(0);
1062 for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++) {
1063 // feed data t0 if present
1064 if (rawRunData[0]->IsPresent(runList->at(i).GetForwardHistoNo(j))) {
1065 musrT0Data.SetT0BinData((UInt_t)rawRunData[0]->GetT0Bin(runList->at(i).GetForwardHistoNo(j)));
1066 }
1067 // feed necessary data
1068 musrT0Data.SetHistoNoIdx(j);
1069 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1070 return 0;
1071 }
1072 }
1073 } else { // addruns / grouping
1074 // feed necessary forward data
1075 musrT0Data.InitData();
1076 musrT0Data.SetSingleHisto(false);
1077 musrT0Data.SetRunNo(i);
1078 forwardHistos.clear();
1079 for (UInt_t j=0; j<runList->at(i).GetForwardHistoNoSize(); j++)
1080 forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j));
1081 musrT0Data.SetHistoNo(forwardHistos);
1082 musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
1083 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1084 rawRunData.clear();
1085 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
1086 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
1087 musrT0Data.SetRawRunData(rawRunData);
1088 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) { // addrun / grouping
1089 musrT0Data.SetAddRunIdx(j); // addruns
1090 for (UInt_t k=0; k<runList->at(i).GetForwardHistoNoSize(); k++) { // forward histo grouping
1091 // feed data t0 if present
1092 if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(k))) {
1093 musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(k)));
1094 }
1095 // feed necessary data
1096 musrT0Data.SetHistoNoIdx(k);
1097 if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
1098 return 0;
1099 }
1100 }
1101 }
1102 // feed necessary backward data
1103 musrT0Data.InitData();
1104 musrT0Data.SetSingleHisto(false);
1105 musrT0Data.SetRunNo(i);
1106 backwardHistos.clear();
1107 for (UInt_t j=0; j<runList->at(i).GetBackwardHistoNoSize(); j++)
1108 backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(j));
1109 musrT0Data.SetHistoNo(backwardHistos);
1110 musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1111 musrT0Data.SetCmdTag(PMUSRT0_GET_T0);
1112 rawRunData.clear();
1113 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++)
1114 rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j))));
1115 musrT0Data.SetRawRunData(rawRunData);
1116 for (UInt_t j=0; j<runList->at(i).GetRunNameSize(); j++) { // addrun / grouping
1117 musrT0Data.SetAddRunIdx(j); // addruns
1118 for (UInt_t k=0; k<runList->at(i).GetBackwardHistoNoSize(); k++) { // backward histo grouping
1119 // feed data t0 if present
1120 if (rawRunData[j]->IsPresent(runList->at(i).GetForwardHistoNo(k))) {
1121 musrT0Data.SetT0BinData((UInt_t)rawRunData[j]->GetT0Bin(runList->at(i).GetForwardHistoNo(k)));
1122 }
1123 // feed necessary data
1124 musrT0Data.SetHistoNoIdx(k);
1125 if (!musrt0_item(app, msrHandler.get(), musrT0Data, j, timeout)) {
1126 return 0;
1127 }
1128 }
1129 }
1130 }
1131 // get data- and bkg-range
1133 // feed all t0's
1134 for (UInt_t j=0; j<runList->at(i).GetT0BinSize(); j++) {
1135 musrT0Data.SetT0Bin((UInt_t)runList->at(i).GetT0Bin(j), j);
1136 for (UInt_t k=0; k<runList->at(i).GetAddT0BinEntries(); k++) {
1137 musrT0Data.SetAddT0Bin((UInt_t)runList->at(i).GetAddT0Bin(k, j), k, j);
1138 }
1139 }
1140 musrT0Data.SetHistoNo(forwardHistos);
1141 musrT0Data.SetDetectorTag(PMUSRT0_FORWARD);
1142 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1143 return 0;
1144 }
1145 musrT0Data.SetHistoNo(backwardHistos);
1146 musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD);
1147 if (!musrt0_item(app, msrHandler.get(), musrT0Data, 0, timeout)) {
1148 return 0;
1149 }
1150 }
1151 break;
1152 default:
1153 break;
1154 }
1155 }
1156 // cleanup
1157 rawRunData.clear();
1158 forwardHistos.clear();
1159 backwardHistos.clear();
1160 }
1161 }
1162
1163 // write msr-file
1164 msrHandler->WriteMsrLogFile(false);
1165
1166 // swap msr- and mlog-file
1167 // copy msr-file -> __temp.msr
1168 gSystem->CopyFile(filename, "__temp.msr", kTRUE);
1169 // copy mlog-file -> msr-file
1170 TString fln = TString(filename);
1171 Char_t ext[32];
1172 memset(ext, '\0', sizeof(ext));
1173 strncpy(ext, ".mlog", sizeof(ext));
1174 fln.ReplaceAll(".msr", 4, ext, strlen(ext));
1175 gSystem->CopyFile(fln.Data(), filename, kTRUE);
1176 // copy __temp.msr -> mlog-file
1177 gSystem->CopyFile("__temp.msr", fln.Data(), kTRUE);
1178 // delete __temp.msr
1179 gSystem->Exec("rm __temp.msr");
1180
1181 return PMUSR_SUCCESS;
1182}
#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 MSR_FITTYPE_ASYM
Fit asymmetry A(t) = (F-αB)/(F+αB)
Definition PMusr.h:216
#define PMUSR_SUCCESS
Successful operation completion.
Definition PMusr.h:53
std::vector< PMsrRunBlock > PMsrRunList
Definition PMusr.h:1245
#define MSR_FITTYPE_SINGLE_HISTO_RRF
Fit single histogram in rotating reference frame.
Definition PMusr.h:214
#define PMUSR_MSR_FILE_NOT_FOUND
MSR file could not be found at specified path.
Definition PMusr.h:59
#define MSR_FITTYPE_SINGLE_HISTO
Fit single histogram (e.g., positron counts vs. time)
Definition PMusr.h:212
#define MSR_FITTYPE_MU_MINUS
Fit negative muon (μ-) single histogram.
Definition PMusr.h:220
#define MSR_FITTYPE_ASYM_RRF
Fit asymmetry in rotating reference frame.
Definition PMusr.h:218
#define MSR_FITTYPE_NON_MUSR
Fit non-μSR data (general x-y data)
Definition PMusr.h:224
#define PMUSR_MSR_SYNTAX_ERROR
Syntax error detected in MSR file content.
Definition PMusr.h:63
std::vector< Int_t > PIntVector
Definition PMusr.h:367
#define MSR_FITTYPE_BNMR
Fit beta-detected NMR asymmetry.
Definition PMusr.h:222
#define PMUSR_WRONG_STARTUP_SYNTAX
Incorrect startup command syntax provided.
Definition PMusr.h:57
std::vector< Double_t > PDoubleVector
Definition PMusr.h:385
const char * startup_path_name
return status
int parseXmlFile(TSAXParser *, const char *)
Replacement function for TSAXParser::ParseFile().
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:84
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:221
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:201
virtual void SetAddRunIdx(const UInt_t addRunIdx)
Sets current addrun index.
Definition PMusrT0.h:132
static int timeout
Definition musrfit.cpp:71
Int_t musrt0_getMaxBin(const PDoubleVector *data)
Definition musrt0.cpp:144
Int_t main(Int_t argc, Char_t *argv[])
Definition musrt0.cpp:179
Bool_t musrt0_item(TApplication &app, PMsrHandler *msrHandler, PMusrT0Data &data, UInt_t idx, Int_t timeout)
Definition musrt0.cpp:96
void musrt0_syntax()
Definition musrt0.cpp:60