musrfit 1.10.0
MuSR_td_PSI_bin.cpp
Go to the documentation of this file.
1/********************************************************************************************
2
3 MuSR_td_PSI_bin.cpp
4
5 implementation of the class 'MuSR_td_PSI_bin'
6
7 Main class to read mdu and td_bin PSI MuSR data.
8
9*********************************************************************************************
10
11 begin : Alex Amato, October 2005
12 modified : Andrea Raselli, October 2009
13 : Andreas Suter, May 2020
14 copyright : (C) 2005 by
15 email : alex.amato@psi.ch
16
17********************************************************************************************/
18
19/***************************************************************************
20 * *
21 * This program is free software; you can redistribute it and/or modify *
22 * it under the terms of the GNU General Public License as published by *
23 * the Free Software Foundation; either version 2 of the License, or *
24 * (at your option) any later version. *
25 * *
26 ***************************************************************************/
27
28
29#include <iostream>
30#include <fstream>
31#include <cstring>
32#include <cmath>
33
34#include "MuSR_td_PSI_bin.h"
35
36//*******************************
37//Implementation constructor
38//*******************************
39
42
47
48
49//*******************************
50//Implementation destructor
51//*******************************
52
55
60
61
62//*******************************
63//Implementation Read (generic read)
64//*******************************
65
80
81 int MuSR_td_PSI_bin::Read(const char * fileName)
82 {
83 std::ifstream file_name;
84
85 Clear();
86
87 fFilename = fileName;
88
89 file_name.open(fileName, std::ios_base::binary); // open file
90 if (file_name.fail())
91 {
92 fReadStatus = "ERROR Open "+fFilename+" failed!";
93 return 1; // ERROR open failed
94 }
95
96 char *buffer_file = new char[3];
97 if (!buffer_file)
98 {
99 fReadStatus = "ERROR Allocating data buffer";
100 return 3; // ERROR allocating data buffer
101 }
102
103 file_name.read(buffer_file, 2); // read format identifier of header
104 // into buffer
105 if (file_name.fail())
106 {
107 file_name.close();
108 delete [] buffer_file;
109 fReadStatus = "ERROR Reading "+fFilename+" header failed!";
110 return 1; // ERROR reading header failed
111 }
112
113 strncpy(fFormatId,buffer_file,2);
114 fFormatId[2] = '\0';
115
116 file_name.close();
117 delete [] buffer_file;
118
119 if (fFormatId[0] == '1') {
120 if (fFormatId[1] != 'N') {
121 std::cout << "**WARNING** found '" << fFormatId << "'. Will change it to '1N'" << std::endl;
122 fFormatId[1] = 'N';
123 }
124 }
125
126 // file may either be PSI binary format
127 if (strncmp(fFormatId,"1N",2) == 0)
128 {
129 return ReadBin(fileName); // then read it as PSI bin
130 }
131
132 // or MDU format (pTA, TDC or 32 channel TDC)
133 else if ((strncmp(fFormatId,"M3",2) == 0) ||(strncmp(fFormatId,"T4",2) == 0) ||
134 (strncmp(fFormatId,"T5",2) == 0))
135 {
136 return ReadMdu(fileName); // else read it as MDU
137 }
138 else
139 {
140 fReadStatus = "ERROR Unknown file format in "+fFilename+"!";
141 return 2; // ERROR unsupported version
142 }
143
144 }
145
146 //*******************************
147 //Implementation Write (generic write)
148 //*******************************
149
164
165int MuSR_td_PSI_bin::Write(const char *fileName)
166{
167 std::string fln = fileName;
168 size_t found = fln.find_last_of(".");
169 if (found == fln.npos) {
170 return 1; // no extension found
171 }
172 std::string ext = fln.substr(found+1);
173 int status = 0;
174 if (ext == "bin")
175 status = WriteBin(fileName);
176 else if (ext == "mdu")
177 status = WriteMdu(fileName);
178 else
179 return 2;
180
181 return status;
182}
183
184//*******************************
185//Implementation readbin
186//*******************************
187
188/* -- type definitions taken from tydefs.h -- */
189
190#if ((defined(__DECC) || defined(__VAXC)) && !defined(unix) && !defined(OS_OSF1))
191
192#if defined (__ALPHA)
193typedef short int Int16;
194typedef int Int32;
195#else
196typedef int Int16;
197typedef long int Int32;
198#endif
199
200
201#elif defined (__osf__) /* --- DEC UNIX or OFS/1 (AXP or else) --- */
202
203#if defined (__alpha)
204typedef short int Int16;
205typedef int Int32;
206#else
207typedef int Int16;
208typedef long int Int32;
209#endif
210
211#else /* other operating system */
212
213/* 32 bit word length */
214#if (defined(_WIN32) || defined(__linux__) || defined(_Darwin_) || defined(_WIN32GCC))
215typedef short Int16;
216typedef int Int32;
217#else
218typedef int Int16;
219typedef long int Int32;
220#endif
221
222#endif
223
224typedef float Float32;
225
226//*******************************
227//Implementation ReadBin
228//*******************************
229
244
245int MuSR_td_PSI_bin::ReadBin(const char * fileName)
246{
247 std::ifstream file_name;
248 Int16 *dum_Int16;
249 Int32 *dum_Int32;
250 Float32 *dum_Float32;
251 int i;
252
253 Int16 tdc_resolution;
254 Int16 tdc_overflow ;
255
256 Float32 mon_low[4];
257 Float32 mon_high[4];
258 Int32 mon_num_events;
259 char mon_dev[13];
260
261 Int16 num_data_records_file;
262 Int16 length_data_records_bins;
263 Int16 num_data_records_histo;
264
265 Int32 period_save;
266 Int32 period_mon;
267
268 Clear();
269
270 if (sizeof(Int16) != 2)
271 {
272 fReadStatus = "ERROR Size of Int16 data type is not 2 bytes!";
273 return 1; // ERROR open failed
274 }
275
276 if (sizeof(Int32) != 4)
277 {
278 fReadStatus = "ERROR Sizeof Int32 data type is not 4 bytes";
279 return 1; // ERROR open failed
280 }
281
282 if (sizeof(Float32) != 4)
283 {
284 fReadStatus = "ERROR Sizeof Float32 data type is not 4 bytes";
285 return 1; // ERROR open failed
286 }
287
288 fFilename = fileName;
289
290 file_name.open(fileName, std::ios_base::binary); // open PSI bin file
291 if (file_name.fail())
292 {
293 fReadStatus = "ERROR Open "+fFilename+" failed!";
294 return 1; // ERROR open failed
295 }
296
297 char *buffer_file = new char[1024];
298 if (!buffer_file)
299 {
300 fReadStatus = "ERROR Allocating buffer to read header failed!";
301 return 3; // ERROR allocating data buffer
302 }
303
304 file_name.read(buffer_file, 1024); // read header into buffer
305 if (file_name.fail())
306 {
307 file_name.close();
308 delete [] buffer_file;
309 fReadStatus = "ERROR Reading "+fFilename+" header failed!";
310 return 1; // ERROR reading header failed
311 }
312 // fill header data into member variables
313 strncpy(fFormatId,buffer_file,2);
314 fFormatId[2] = '\0';
315
316 if (fFormatId[1] != 'N') // the warning is already issued in read()
317 fFormatId[1] = 'N';
318
319 if (strcmp(fFormatId,"1N") != 0)
320 {
321 file_name.close();
322 delete [] buffer_file;
323 fReadStatus = "ERROR Unknown file format in "+fFilename+"!";
324 return 2; // ERROR unsupported version
325 }
326
327 dum_Int16 = (Int16 *) &buffer_file[2];
328 tdc_resolution = *dum_Int16;
329
330 dum_Int16 = (Int16 *) &buffer_file[4];
331 tdc_overflow = *dum_Int16;
332
333 dum_Int16 = (Int16 *) &buffer_file[6];
334 fNumRun = *dum_Int16;
335
336 dum_Int16 = (Int16 *) &buffer_file[28];
337 fLengthHisto = *dum_Int16;
338
339 dum_Int16 = (Int16 *) &buffer_file[30];
340 fNumberHisto = *dum_Int16;
341
342 strncpy(fSample,buffer_file+138,10);
343 fSample[10] = '\0';
344
345 strncpy(fTemp,buffer_file+148,10);
346 fTemp[10] = '\0';
347
348 strncpy(fField,buffer_file+158,10);
349 fField[10] = '\0';
350
351 strncpy(fOrient,buffer_file+168,10);
352 fOrient[10] = '\0';
353
354 strncpy(fSetup, buffer_file+178, 10);
355 fSetup[10] = '\0';
356
357 strncpy(fComment,buffer_file+860,62);
358 fComment[62] = '\0';
359
360 strncpy(fDateStart,buffer_file+218,9);
361 fDateStart[9] = '\0';
362
363 strncpy(fDateStop,buffer_file+227,9);
364 fDateStop[9] = '\0';
365
366 strncpy(fTimeStart,buffer_file+236,8);
367 fTimeStart[8] = '\0';
368
369 strncpy(fTimeStop,buffer_file+244,8);
370 fTimeStop[8] = '\0';
371
372 dum_Int32 = (Int32 *) &buffer_file[424];
373 fTotalEvents = *dum_Int32;
374
375 for (i=0; i<=15; i++) {
376 strncpy(fLabelsHisto[i],buffer_file+948+i*4,4);
377 fLabelsHisto[i][4] = '\0';
378
379 dum_Int32 = (Int32 *) &buffer_file[296+i*4];
380 fEventsPerHisto[i] = *dum_Int32;
381
382 dum_Int16 = (Int16 *) &buffer_file[458+i*2];
383 fIntegerT0[i] = *dum_Int16;
384
385 dum_Int16 = (Int16 *) &buffer_file[490+i*2];
386 fFirstGood[i] = *dum_Int16;
387
388 dum_Int16 = (Int16 *) &buffer_file[522+i*2];
389 fLastGood[i] = *dum_Int16;
390 }
391
392 for (i=0; i<=15; i++) {
393 dum_Float32 = (Float32 *) &buffer_file[792+i*4];
394 fRealT0[i] = *dum_Float32;
395 }
396
397 fNumberScaler = 18;
398
399 for (i=0; i<=5; i++) {
400 dum_Int32 = (Int32 *) &buffer_file[670+i*4];
401 fScalers[i] = *dum_Int32;
402
403 strncpy(fLabelsScalers[i],buffer_file+924+i*4,4);
404 fLabelsScalers[i][4] = '\0';
405 }
406
407 for (i=6; i<fNumberScaler; i++) {
408 dum_Int32 = (Int32 *) &buffer_file[360+(i-6)*4];
409 fScalers[i] = *dum_Int32;
410
411 strncpy(fLabelsScalers[i],buffer_file+554+(i-6)*4,4);
412 fLabelsScalers[i][4] = '\0';
413 }
414
415 dum_Float32 = (Float32 *) &buffer_file[1012];
416 fBinWidth = static_cast<double>(*dum_Float32);
417
418 if (fBinWidth == 0.)
419 {
420 fBinWidth=0.125*(625.E-6)*pow(static_cast<double>(2.0),static_cast<double>(tdc_resolution));
421 }
422
423 fDefaultBinning = 1;
424
425 fNumberTemper = 4;
426 for (i=0; i< fNumberTemper; i++) {
427 dum_Float32 = (Float32 *) &buffer_file[716+i*4];
428 fTemper[i] = *dum_Float32;
429
430 dum_Float32 = (Float32 *) &buffer_file[738+i*4];
431 fTempDeviation[i] = *dum_Float32;
432
433 dum_Float32 = (Float32 *) &buffer_file[72+i*4];
434 mon_low[i] = *dum_Float32;
435
436 dum_Float32 = (Float32 *) &buffer_file[88+i*4];
437 mon_high[i] = *dum_Float32;
438 }
439
440 dum_Int32 = (Int32 *) &buffer_file[712];
441 mon_num_events = *dum_Int32;
442 strncpy(mon_dev,buffer_file+60,12);
443 mon_dev[12] = '\0';
444
445 dum_Int16 = (Int16 *) &buffer_file[128]; // numdaf
446 num_data_records_file = *dum_Int16;
447
448 dum_Int16 = (Int16 *) &buffer_file[130]; // lendaf
449 length_data_records_bins = *dum_Int16;
450
451 dum_Int16 = (Int16 *) &buffer_file[132]; // kdafhi
452 num_data_records_histo = *dum_Int16;
453
454 dum_Int16 = (Int16 *) &buffer_file[134]; // khidaf
455 if (*dum_Int16 != 1) {
456 std::cout << "ERROR number of histograms/record not equals 1!"
457 << " Required algorithm is not implemented!" << std::endl;
458 delete [] buffer_file;
459 file_name.close();
460 fReadStatus = "ERROR Algorithm to read multiple histograms in one block -"
461 " necessary to read " + fFilename + " - is not implemented!";
462 return 4; // ERROR algorithm not implemented
463 }
464
465 dum_Int32 = (Int32 *) &buffer_file[654];
466 period_save = *dum_Int32;
467
468 dum_Int32 = (Int32 *) &buffer_file[658];
469 period_mon = *dum_Int32;
470
471 if (buffer_file) delete [] buffer_file;
472
473 if (fNumberHisto <= 0)
474 {
475 file_name.close();
476 fReadStatus = "ERROR Less than 1 histogram in " + fFilename;
477 return 5; // ERROR number of histograms < 1
478 }
479
480 // allocate histograms
481 fHisto.resize(fNumberHisto);
482
483 for (i=0; i<fNumberHisto; i++) {
484 fHisto[i].resize(fLengthHisto);
485 }
486
487 char *buffer_file_histo = new char[Int32(num_data_records_file)
488 *Int32(length_data_records_bins)*4];
489 if (!buffer_file_histo) {
490 Clear();
491 file_name.close();
492 fReadStatus = "ERROR Allocating buffer to read histogram failed!";
493 return 3; // ERROR allocating histogram buffer
494 }
495 file_name.seekg(1024, std::ios_base::beg); // beginning of histogram data
496
497 file_name.read(buffer_file_histo, Int32(num_data_records_file)
498 *Int32(length_data_records_bins)*4);
499 if (file_name.fail()) {
500 Clear();
501 delete [] buffer_file_histo;
502 file_name.close();
503 fReadStatus = "ERROR Reading data in "+fFilename+" failed!";
504 return 6; // ERROR reading data failed
505 }
506 file_name.close();
507
508 // process histograms
509 std::vector<double> dummy_vector;
510
511 fHistosVector.clear();
512 for (i=0; i<fNumberHisto; i++) {
513 dummy_vector.clear();
514 for (int j=0; j<fLengthHisto; j++) {
515 dum_Int32 = (Int32 *) &buffer_file_histo[(i*Int32(num_data_records_histo)*
516 Int32(length_data_records_bins)+j)*sizeof(Int32)];
517 fHisto[i][j]= *dum_Int32;
518 dummy_vector.push_back(double(fHisto[i][j]));
519 }
520 fHistosVector.push_back(dummy_vector);
521 }
522
523 if (buffer_file_histo) delete [] buffer_file_histo;
524
525 fReadStatus = "SUCCESS";
526 fReadingOk = true;
527
528 return 0;
529}
530
531//*******************************
532//Implementation WriteBin
533//*******************************
534
547
548int MuSR_td_PSI_bin::WriteBin(const char *fileName)
549{
550 if (!CheckDataConsistency(2)) {
551 fWriteStatus = "ERROR Given data set is incompatible with the PSI-BIN format!";
552 return 4;
553 }
554
555 std::ofstream fout;
556
557 // prepare buffer
558 char *buffer = new char[1024];
559 if (buffer == nullptr) {
560 fWriteStatus = "ERROR Allocating buffer to write header failed!";
561 return 3; // ERROR allocating data buffer
562 }
563 // initialize buffer
564 memset(buffer, 0, 1024);
565
566 // fill header info into the buffer
567
568 fout.open(fileName, std::ios_base::binary); // open PSI bin file
569 if (fout.fail()) {
570 fWriteStatus = "ERROR Open " + std::string(fileName) + " failed!";
571 return 1; // ERROR open failed
572 }
573
574 Int16 dum_Int16=0;
575 Int32 dum_Int32=0;
576 Float32 dum_Float32=0;
577 // handle header -----------------------------------------------------------------------
578 // psi-bin identifier
579 strncpy(buffer, "1N", 2);
580 // write tdc resolution code
581 dum_Int16 = -1;
582 memcpy(buffer+2, &dum_Int16, 2);
583 // write run number
584 dum_Int16 = (Int16)fNumRun;
585 memcpy(buffer+6, &dum_Int16, 2);
586 // write length of histogram: LENHIS
587 dum_Int16 = (Int16)fLengthHisto;
588 memcpy(buffer+28, &dum_Int16, 2);
589 // write number of histogram (maximum == 16): NUMHIS
590 dum_Int16 = (Int16)fNumberHisto;
591 memcpy(buffer+30, &dum_Int16, 2);
592 // write number of data records: NUMDAF = NUMHIS*KDAFHI
593 dum_Int16 = (Int16)(fNumberHisto * (int)((fLengthHisto + MAXREC - 1) / MAXREC));
594 memcpy(buffer+128, &dum_Int16, 2);
595 // write record size: LENDAF
596 dum_Int16 = MAXREC;
597 memcpy(buffer+130, (const char*)&dum_Int16, 2);
598 // write number of records per histogram: KDAFHI
599 dum_Int16 = (Int16)(fLengthHisto + MAXREC - 1) / MAXREC;
600 memcpy(buffer+132, &dum_Int16, 2);
601 // write number of histograms per record: KHIDAF
602 dum_Int16 = 1;
603 memcpy(buffer+134, &dum_Int16, 2);
604 // write fSample info
605 strncpy(buffer+138, fSample, 10);
606 // write temperature info
607 strncpy(buffer+148, fTemp, 10);
608 // write field info
609 strncpy(buffer+158, fField, 10);
610 // write orientation info
611 strncpy(buffer+168, fOrient, 10);
612 // write setup info
613 strncpy(buffer+178, fSetup, 10);
614 // write run start date
615 strncpy(buffer+218, fDateStart, 9);
616 // write run stop date
617 strncpy(buffer+227, fDateStop, 9);
618 // write run start time
619 strncpy(buffer+236, fTimeStart, 8);
620 // write run stop time
621 strncpy(buffer+244, fTimeStop, 8);
622
623 // write number of events of each histogram
624 Int32 noEvents = 0;
625 Int32 totalEvents = 0;
626 for (int i=0; i<fNumberHisto; i++) {
627 noEvents = 0;
628 for (int j=0; j<fLengthHisto; j++) {
629 noEvents += fHisto[i][j];
630 }
631 totalEvents += noEvents;
632 memcpy(buffer+296+4*i, &noEvents, 4);
633 }
634 // write scaler contents 7 to 18
635 for (int i=0; i<12; i++) {
636 dum_Int32 = (Int32)fScalers[i+6];
637 memcpy(buffer+360+4*i, &dum_Int32, 4);
638 }
639 // write total number of events
640 memcpy(buffer+424, &totalEvents, 4);
641
642 for (int i=0; i<fNumberHisto; i++) {
643 // write t0 for each histogram
644 dum_Int16 = (Int16)fIntegerT0[i];
645 memcpy(buffer+458+2*i, (const char *)&dum_Int16, 2);
646 // write first good bin for each histogram
647 dum_Int16 = (Int16)fFirstGood[i];
648 memcpy(buffer+490+2*i, (const char *)&dum_Int16, 2);
649 // write last good bin for each histogram
650 dum_Int16 = (Int16)fLastGood[i];
651 memcpy(buffer+522+2*i, (const char *)&dum_Int16, 2);
652 }
653 // write labels for scalers 7-18
654 for (int i=6; i<fNumberScaler; i++) {
655 strncpy(buffer+554+i*4, fLabelsScalers[i], 4);
656 }
657 // write scaler contents 1 to 6
658 for (int i=0; i<6; i++) {
659 dum_Int32 = (Int32)fScalers[i];
660 memcpy(buffer+670+i*4, &dum_Int32, 4);
661 }
662 // write number of measurements used for temperature
663 dum_Int32 = (Int32)fNumberTemper;
664 memcpy(buffer+712, (const char *)&dum_Int32, 4);
665 for (int i=0; i<fNumberTemper; i++) {
666 // write temperature means
667 dum_Float32 = (Float32)fTemper[i];
668 memcpy(buffer+716+i*4, (const char *)&dum_Float32, 4);
669 // write temperature std dev
670 dum_Float32 = (Float32)fTempDeviation[i];
671 memcpy(buffer+738+i*4, (const char *)&dum_Float32, 4);
672 }
673 // write run comment
674 strncpy(buffer+860, fComment, 62);
675 // write labels of scalers 1-6
676 for (int i=0; i<6; i++) {
677 strncpy(buffer+924+i*4, fLabelsScalers[i], 4);
678 }
679 // write labels of histograms
680 for (int i=0; i<fNumberHisto; i++) {
681 strncpy(buffer+948+i*4, fLabelsHisto[i], 4);
682 }
683 // write TDS time resolution
684 dum_Float32 = static_cast<Float32>(fBinWidth);
685 memcpy(buffer+1012, (const char*)&dum_Float32, 4);
686
687 // write header information
688 fout.write(buffer, 1024);
689
690 // handle histograms -----------------------------------------------------------------
691
692 // prepare write buffer
693 if (buffer) { // Get rid of the header buffer
694 delete [] buffer;
695 buffer = nullptr;
696 }
697 buffer = new char[4*MAXREC];
698 if (!buffer) {
699 fWriteStatus = "ERROR Allocating buffer to write data failed!";
700 return 3; // ERROR allocating data buffer
701 }
702 // initialize buffer
703 memset(buffer, 0, 4*MAXREC);
704
705 bool buffer_empty = false;
706 for (int i=0; i<fNumberHisto; i++) {
707 for (int j=0; j<fLengthHisto; j++) {
708 dum_Int32 = (Int32)fHisto[i][j];
709 memcpy(buffer+(4*j)%(4*MAXREC), &dum_Int32, 4);
710 buffer_empty = false;
711 if ((j > 0) && (j%MAXREC == 0)) {
712 fout.write(buffer, 4*MAXREC);
713 // reinizialize buffer
714 memset(buffer, 0, 4*MAXREC);
715 buffer_empty = true;
716 }
717 }
718 // check if there is still a record to be written
719 if (!buffer_empty) {
720 fout.write(buffer, 4*MAXREC);
721 // reinizialize buffer
722 memset(buffer, 0, 4*MAXREC);
723 }
724 }
725
726 fout.close();
727
728 // clean up
729 if (buffer) {
730 delete [] buffer;
731 buffer = nullptr;
732 }
733
734 return 0;
735}
736
737
738//*******************************
739//Implementation readmdu
740//*******************************
741
742#define DATESTR 12 /* Length of date string 01-NOV-1999 */
743#define TIMESTR 9 /* Length of time string 08:45:30 */
744
745/* automatic data conversion */
746#define TITLESTR 40
747#define SUBTITLESTR 62
748#define DATAFORMATSTR 20
749#define DETECTLISTSTR 200
750#define TEMPLISTSTR 50
751
752 /* - event types and event evaluation mode */
753#define PTAMODE_NONE 0 /* not initialised */
754#define PTAMODE_NORMAL 1 /* "normal" events M-P.. */
755#define PTAMODE_CLOCK 2 /* additional clock generated events to prevent
756 overflow of pTA*/
757#define PTAMODE_ECHO 4 /* echo mode M-P .. Echo (delayed M signal) */
758
759 /* - tag types */
760#define PTATAGC_NONE 'N'
761#define PTATAGC_MUON 'M'
762#define PTATAGC_POSITRON 'P'
763#define PTATAGC_CLOCK 'C'
764#define PTATAGC_ECHO 'E'
765#define PTATAGC_VETO 'V'
766#define PTATAGC_UNKNOWN 'U'
767
768 /* - number of tags and tag name string length */
769#define PTAMAXTAGS 16 /* max number of pTA tags for pTA MDU M3 */
770#define TDCMAXTAGS16 16 /* max number of pTA tags for TDC MDU T4 */
771#define TDCMAXTAGS32 32 /* max number of pTA tags for TDC MDU T5 */
773#define MAXTAGSTR 12 /* max length of pTA tag strings */
774
775/* ---------------------------------------------------------------------- */
776
777/* basic structure of a MidasDUmp file witten by pTA front end
778
779 // write header information
780 fwrite(&gpTAfhead, gpTAfhead.NumBytesHeader, 1, fp);
781
782 // write settings information
783 fwrite(&gpTAset, gpTAfhead.NumBytesSettings, 1, fp);
784
785 // write statistic
786 fwrite(&gpTAstattot, gpTAfhead.NumBytesStatistics, 1, fp);
787
788 for (i = 0; i < PTAMAXTAGS; i++) {
789 // write tag record of histogram
790 fwrite(&gpTAset.tag[i], gpTAfhead.NumBytesTag, 1, fp);
791
792 // write histogram data
793 if ((gpTAset.tag[i].Type == PTATAGC_POSITRON) &&
794 ((nbins =(gpTAset.tag[i].Histomaxb - gpTAset.tag[i].Histominb + 1)) > 1) &&
795 (gpHistogram[i] != NULL))
796 fwrite(gpHistogram[i], sizeof(unsigned int), nbins, fp);
797 }
798
799
800 */
801 /* - general file header part used to save runs */
802typedef struct _FeFileHeaderRec {
803 char FmtId;
811
812 /* information for automatic data conversion */
815 char DataFormat[DATAFORMATSTR];// data format (automatically converted to)
816 Int32 HistoResolution; // TDC resolution factor for tarGet format
817 // or pTA timespan
821 char DetectorNumberList[DETECTLISTSTR]; // list of detectors to be converted
822 // to the tarGet data format
823 /* additional information */
827
837
838 /* - pTA tag information */
839typedef struct _pTATagRec {
841 char Type;
842
843 /* original pTA list mode (raw) time difference */
846 Int32 Rawminb; /* bin range may be 0-262143 (or larger if PTAMODE_CLOCK) */
848
849 /* a modified time difference (binning) may be stored in histo */
854 Int32 t0b; /* t0, tfirst tlast in [bins] for automatic data conversion */
855 Int32 tfb; /* NOTE: t0b, tfb, tlb are in bin units of the tarGet format!! */
858
859 /* - pTA settings relevant for td_musr for pTA M3 format*/
860typedef struct _pTASettingsRec {
861 Int32 mode; /* PTAMODE_NORMAL[+PTAMODE_CLOCK] or PTAMODE_ECHO */
862 Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */
863 Int32 posps; /* post pile up [ps] ; info only */
864 Int32 preb; /* pre pile up [bins] */
865 Int32 posb; /* post pile up [bins] */
866 Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */
867 Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */
868 Int32 ecsb; /* muon echo signal delay (PTAMODE_ECHO) [bins] */
869 Int32 ectb; /* muon echo tolerance (PTAMODE_ECHO) [bins] */
870 Int32 timespan; /* pTA timespan */
871 Int32 minrate; /* minimum event rate */
872 Int32 eortag; /* end of run tag number */
873 Int32 eorlim; /* end of run limit */
876
877 /* - pTA settings relevant for td_musr for TDC T4 format */
878typedef struct _pTATDCSettingsRec {
879 Int32 mode; /* PTAMODE_NORMAL[+PTAMODE_CLOCK] or PTAMODE_ECHO */
880 Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */
881 Int32 posps; /* post pile up [ps] ; info only */
882 Int32 preb; /* pre pile up [bins] */
883 Int32 posb; /* post pile up [bins] */
884 Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */
885 Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */
886 Int32 ecsb; /* muon echo signal delay (PTAMODE_ECHO) [bins] */
887 Int32 ectb; /* muon echo tolerance (PTAMODE_ECHO) [bins] */
888 Int32 resolutioncode; /* type specific TDC resolution code 25 ps, 200ps */
889 Int32 minrate; /* minimum event rate */
890 Int32 eortag; /* end of run tag number */
891 Int32 eorlim; /* end of run limit */
894
895 /* - pTA settings relevant for td_musr for TDC T5 format */
896typedef struct _pTATDC32SettingsRec {
897 Int32 mode; /* PTAMODE_NORMAL[+PTAMODE_CLOCK] or PTAMODE_ECHO */
898 Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */
899 Int32 posps; /* post pile up [ps] ; info only */
900 Int32 preb; /* pre pile up [bins] */
901 Int32 posb; /* post pile up [bins] */
902 Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */
903 Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */
904 Int32 ecsb; /* muon echo signal delay (PTAMODE_ECHO) [bins] */
905 Int32 ectb; /* muon echo tolerance (PTAMODE_ECHO) [bins] */
906 Int32 resolutioncode; /* type specific TDC resolution code 25 ps, 200ps */
907 Int32 minrate; /* minimum event rate */
908 Int32 eortag; /* end of run tag number */
909 Int32 eorlim; /* end of run limit */
912
913 /* - pTA td_musr statistic for pTA M3 format */
914typedef struct _pTAStatisticRec {
924 Int32 EPrePileup; /* M-P-M Pileup */
925 Int32 EPostPileup; /* M-M-P Pileup */
931 Int32 EOverFlowBits; /* overflow flag bits for time and event counter overflow*/
932 Int32 TSOverFlowBits; /* overflow flag bits for tag scaler overflow */
933 Int32 HSOverFlowBits; /* overflow flag bits for histogram scaler overflow */
934 Int32 HOverFlowBits; /* overflow flag bits for histogram overflow */
936
937 /* - pTA td_musr statistic for TDC T4 format */
938typedef struct _pTATDCStatisticRec {
948 Int32 EPrePileup; /* M-P-M Pileup */
949 Int32 EPostPileup; /* M-M-P Pileup */
955 Int32 EOverFlowBits; /* overflow flag bits for time and event counter overflow*/
956 Int32 TSOverFlowBits; /* overflow flag bits for tag scaler overflow */
957 Int32 HSOverFlowBits; /* overflow flag bits for histogram scaler overflow */
958 Int32 HOverFlowBits; /* overflow flag bits for histogram overflow */
960
961 /* - pTA td_musr statistic for TDC T5 format*/
962typedef struct _pTATDC32StatisticRec {
972 Int32 EPrePileup; /* M-P-M Pileup */
973 Int32 EPostPileup; /* M-M-P Pileup */
979 Int32 EOverFlowBits; /* overflow flag bits for time and event counter overflow*/
980 Int32 TSOverFlowBits; /* overflow flag bits for tag scaler overflow */
981 Int32 HSOverFlowBits; /* overflow flag bits for histogram scaler overflow */
982 Int32 HOverFlowBits; /* overflow flag bits for histogram overflow */
984
985/* ---------------------------------------------------------------------- */
986
987//*******************************
988//Implementation ReadMdu
989//*******************************
990
1005int MuSR_td_PSI_bin::ReadMdu(const char * fileName)
1006{
1007 std::ifstream file_name;
1008 int i, j;
1009
1010 Clear();
1011
1012 if (sizeof(Int32) != 4)
1013 {
1014 fReadStatus = "ERROR Sizeof( Int32 ) data type is not 4 bytes";
1015 return 1; // ERROR open failed
1016 }
1017
1018 fFilename = fileName;
1019
1020 file_name.open(fileName, std::ios_base::binary); // open PSI bin file
1021 if (file_name.fail())
1022 {
1023 fReadStatus = "ERROR Open "+fFilename+" failed!";
1024 return 1; // ERROR open failed
1025 }
1026
1027 pTAFileHeaderRec gpTAfhead;
1028 //FeFileHeaderPtr gpFehead = &gpTAfhead.Header;
1029
1030 file_name.read((char *)&gpTAfhead, sizeof gpTAfhead); // read header into buffer
1031 if (file_name.fail())
1032 {
1033 file_name.close();
1034 fReadStatus = "ERROR Reading "+fFilename+" header failed!";
1035 return 1; // ERROR reading header failed
1036 }
1037 // fill header data into member variables
1038 fFormatId[0] = gpTAfhead.Header.FmtId;
1039 fFormatId[1] = gpTAfhead.Header.FmtVersion;
1040 fFormatId[2] = '\0';
1041
1042 if ((strcmp(fFormatId,"M3") != 0) && (strcmp(fFormatId,"T4") != 0) &&
1043 (strcmp(fFormatId,"T5") != 0))
1044 {
1045 file_name.close();
1046 fReadStatus = "ERROR Unknown file format in "+fFilename+"!";
1047 return 2; // ERROR unsupported version
1048 }
1049
1050 if (sizeof(pTAFileHeaderRec) != gpTAfhead.NumBytesHeader)
1051 {
1052 file_name.close();
1053 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTAFileHeaderRec size";
1054 return 1; // ERROR reading header failed
1055 }
1056
1057 // header size OK read header information
1058 strncpy(fSample,&gpTAfhead.Header.RunTitle[0],10);
1059 fSample[10] = '\0';
1060
1061 strncpy(fTemp, &gpTAfhead.Header.RunTitle[10],10);
1062 fTemp[10] = '\0';
1063
1064 strncpy(fField, &gpTAfhead.Header.RunTitle[20],10);
1065 fField[10] = '\0';
1066
1067 strncpy(fOrient,&gpTAfhead.Header.RunTitle[30],10);
1068 fOrient[10] = '\0';
1069
1070 strncpy(fComment,&gpTAfhead.Header.RunSubTitle[0],62);
1071 fComment[62] = '\0';
1072
1073 strncpy(&fDateStart[0],&gpTAfhead.Header.StartDate[0],7);
1074 strncpy(&fDateStart[7],&gpTAfhead.Header.StartDate[9],2);
1075 fDateStart[9] = '\0';
1076
1077 strncpy(&fDateStop[0],&gpTAfhead.Header.EndDate[0],7);
1078 strncpy(&fDateStop[7],&gpTAfhead.Header.EndDate[9],2);
1079 fDateStop[9] = '\0';
1080
1081 strncpy(fTimeStart,&gpTAfhead.Header.StartTime[0],8);
1082 fTimeStart[8] = '\0';
1083
1084 strncpy(fTimeStop,&gpTAfhead.Header.EndTime[0],8);
1085 fTimeStop[8] = '\0';
1086
1087 fNumRun = gpTAfhead.Header.RunNumber;
1088
1089 if (sizeof(pTATagRec) != gpTAfhead.NumBytesTag) {
1090 file_name.close();
1091 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTATagRec size";
1092 return 1; // ERROR reading header failed
1093 }
1094
1095#ifdef MIDEBUG1
1096 cout << "Header.MeanTemp = " << gpTAfhead.Header.MeanTemp << endl;
1097 cout << "Header.TempDev = " << gpTAfhead.Header.TempDev << endl;
1098#endif
1099
1100 // read temperature deviation from header string (td0 [td1 [td2 [td3]]])
1101 fNumberTemper = sscanf(gpTAfhead.Header.TempDev,"%f %f %f %f",
1103 &fTempDeviation[3]);
1104
1105 // fill unused
1106 for (i=fNumberTemper; i<MAXTEMPER; i++)
1107 fTempDeviation[i] = 0.f;
1108
1109 // read temperature from header string (t0 [t1 [t2 [t3]]])
1110 fNumberTemper = sscanf(gpTAfhead.Header.MeanTemp,"%f %f %f %f",
1111 &fTemper[0], &fTemper[1], &fTemper[2], &fTemper[3]);
1112
1113 // fill unused
1114 for (i=fNumberTemper; i<MAXTEMPER; i++) {
1115 fTemper[i] = 0.f;
1116 fTempDeviation[i] = 0.f;
1117 }
1118
1119#ifdef MIDEBUG1
1120 cout << "Header.DataFormat = " << gpTAfhead.Header.DataFormat << endl;
1121 cout << "Header.HistoResolution = " << gpTAfhead.Header.HistoResolution << endl;
1122 cout << "Header.BinOffset = " << gpTAfhead.Header.BinOffset << endl;
1123 cout << "Header.BinsPerHistogram = " << gpTAfhead.Header.BinsPerHistogram << endl;
1124 cout << "Header.NumberOfDetectors = " << gpTAfhead.Header.NumberOfDetectors << endl;
1125 cout << "Header.DetectorNumberList = " << gpTAfhead.Header.DetectorNumberList << endl;
1126#endif
1127
1128 // process detector list in gpTAfhead.Header.NumberOfDetectors
1129 // for pTA only histograms of selected detectors are valid
1130 bool selected[MAXHISTO];
1131
1132 for (i=0; i < MAXHISTO; i++)
1133 selected[i] = false;
1134
1135 for (i=0,j=0; i <= (int)strlen(gpTAfhead.Header.DetectorNumberList); i++) {
1136 if ((gpTAfhead.Header.DetectorNumberList[i] == ' ') ||
1137 (gpTAfhead.Header.DetectorNumberList[i] == '\0')) {
1138 int it;
1139 if (sscanf(&gpTAfhead.Header.DetectorNumberList[j],"%d",&it) == 1) {
1140 j = i+1; // assume next char is start of next number
1141 if ((it >= 0) && (it < MAXHISTO)) {
1142 selected[it] = true;
1143#ifdef MIDEBUG1
1144 cout << "Histogram " << it << " is selected " << endl;
1145#endif
1146 } else {
1147 std::cout << "error " << it << " is out of range |0 - " << MAXHISTO-1 << "|"
1148 << std::endl;
1149 }
1150 } else {
1151 std::cout << "error reading " << &gpTAfhead.Header.DetectorNumberList[j] << std::endl;
1152 }
1153 }
1154 }
1155
1156 int tothist = 0;
1157 int resolutionfactor = 1;
1158
1159 // ---- process version specific settings and total statistics
1160 if (strcmp(fFormatId,"M3") == 0) {
1161
1162 if (sizeof(pTASettingsRec) != gpTAfhead.NumBytesSettings) {
1163 file_name.close();
1164 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTASettingsRec size";
1165 return 1; // ERROR reading header failed
1166 }
1167
1168 if (sizeof(pTAStatisticRec) != gpTAfhead.NumBytesStatistics) {
1169 file_name.close();
1170 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTAStatisticRec size";
1171 return 1; // ERROR reading header failed
1172 }
1173
1174 pTASettingsRec gpTAsetpta;
1175 pTAStatisticRec gpTAstattotpta;
1176
1177 tothist = PTAMAXTAGS;
1178
1179 file_name.read((char *)&gpTAsetpta, sizeof gpTAsetpta);//read settings into buffer
1180 if (file_name.fail()) {
1181 file_name.close();
1182 fReadStatus = "ERROR Reading "+fFilename+" settings failed!";
1183 return 1; // ERROR reading settings failed
1184 }
1185
1186 // read stat into buffer
1187 file_name.read((char *)&gpTAstattotpta, sizeof gpTAstattotpta);
1188 if (file_name.fail()) {
1189 file_name.close();
1190 fReadStatus = "ERROR Reading "+fFilename+" statistics failed!";
1191 return 1; // ERROR reading statistics failed
1192 }
1193
1195 for (i=0; i < fNumberScaler; i++) {
1196 strncpy(fLabelsScalers[i],gpTAsetpta.tag[i].Label,MAXLABELSIZE);
1197 fLabelsScalers[i][MAXLABELSIZE-1] = '\0';
1198
1199 fScalers[i] = gpTAstattotpta.TagScaler[i];
1200 }
1201
1202 int timespan;
1203
1204 resolutionfactor = 1;
1205 timespan = gpTAfhead.Header.HistoResolution; // tarGet timespan (PSIBIN)
1206 // t0, fg, lg
1207 if (gpTAsetpta.timespan == 11) // pta timespan
1208 fBinWidth = 0.000625;
1209 else if (gpTAsetpta.timespan == 10)
1210 fBinWidth = 0.0003125;
1211 else if (gpTAsetpta.timespan == 9)
1212 fBinWidth = 0.00015625;
1213 else if (gpTAsetpta.timespan == 8)
1214 fBinWidth = 0.000078125;
1215 else if (gpTAsetpta.timespan == 7)
1216 fBinWidth = 0.0000390625;
1217 else if (gpTAsetpta.timespan == 6)
1218 fBinWidth = 0.00001953125;
1219 else {
1220 file_name.close();
1221 fReadStatus = "ERROR "+fFilename+" settings resolution code failed!";
1222 return 1; // ERROR reading settings failed
1223 }
1224
1225 if (timespan+8-gpTAsetpta.timespan < 0) {
1226 // NIY error
1227 } else {
1228 /* PSI resolution pTA timespan resolution [usec]
1229 * -2 6 0.00001953125
1230 * -1 7 0.0000390625
1231 * 0 8 0.000078125
1232 * 1 9 0.00015625
1233 * 2 10 0.0003125
1234 * 3 11 0.000625
1235 * 4 - 0.00125
1236 * 5 - 0.0025
1237 * 6 - 0.005
1238 */
1239 // resolution factor for binning
1240 for (i=0; i < timespan+8-gpTAsetpta.timespan; i++)
1241 resolutionfactor *= 2;
1242 }
1243
1244 fLengthHisto = 0;
1245 fNumberHisto = 0;
1246 for (i=0; i<tothist; i++) {
1247 /* read histogram data */
1248 if (gpTAsetpta.tag[i].Type == PTATAGC_POSITRON) {
1249 int nbins;
1250
1251#ifdef MIDEBUG1
1252 cout << "Tag[" << i << "] Histomin = " << gpTAsetpta.tag[i].Histominb
1253 << " Histomax = " << gpTAsetpta.tag[i].Histomaxb << endl;
1254#endif
1255 // is a histogram there
1256 if ((nbins=(gpTAsetpta.tag[i].Histomaxb-gpTAsetpta.tag[i].Histominb + 1))>1) {
1257
1258 // for pTA only: read histogram only if histogram was selected
1259 if (selected[i]) {
1260 // first histo -> take histogram length
1261 if (fNumberHisto == 0)
1262 fLengthHisto = nbins+gpTAsetpta.tag[i].Histominb;
1263 // different histogram length?
1264 else if (fLengthHisto != nbins+gpTAsetpta.tag[i].Histominb) {
1265 std::cout << "Different histogram lengths!" << std::endl;
1266 }
1267 fNumberHisto++;
1268 }
1269 }
1270 }
1271 }
1272
1273 // check gpTAfhead.Header.NumberOfDetectors
1274 if (fNumberHisto != gpTAfhead.Header.NumberOfDetectors)
1275 std::cout << "Number of found histos " << fNumberHisto << " and number in header "
1276 << gpTAfhead.Header.NumberOfDetectors << " differ!" << std::endl;
1277
1278 // special case: subtract 1 from stored histogram to Get desired histogram length
1279 if (fLengthHisto > 0) fLengthHisto -= 1;
1280
1281 } else if (strcmp(fFormatId,"T4") == 0) {
1282
1283 if (sizeof(pTATDCSettingsRec) != gpTAfhead.NumBytesSettings) {
1284 file_name.close();
1285 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTATDCSettingsRec size";
1286 return 1; // ERROR reading header failed
1287 }
1288
1289 if (sizeof(pTATDCStatisticRec) != gpTAfhead.NumBytesStatistics) {
1290 file_name.close();
1291 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTATDCStatisticRec size";
1292 return 1; // ERROR reading header failed
1293 }
1294
1295 pTATDCSettingsRec gpTAsettdc;
1296 pTATDCStatisticRec gpTAstattottdc;
1297
1298 tothist = TDCMAXTAGS16;
1299
1300 file_name.read((char *)&gpTAsettdc, sizeof gpTAsettdc);//read settings into buffer
1301 if (file_name.fail()) {
1302 file_name.close();
1303 fReadStatus = "ERROR Reading "+fFilename+" settings failed!";
1304 return 1; // ERROR reading settings failed
1305 }
1306
1307 file_name.read((char *)&gpTAstattottdc, sizeof gpTAstattottdc); // read stat into buffer
1308 if (file_name.fail()) {
1309 file_name.close();
1310 fReadStatus = "ERROR Reading "+fFilename+" statistics failed!";
1311 return 1; // ERROR reading statistics failed
1312 }
1313
1315 for (i=0; i < fNumberScaler; i++) {
1316 strncpy(fLabelsScalers[i],gpTAsettdc.tag[i].Label,MAXLABELSIZE);
1317 fLabelsScalers[i][MAXLABELSIZE-1] = '\0';
1318
1319 fScalers[i] = gpTAstattottdc.TagScaler[i];
1320 }
1321
1322 resolutionfactor = gpTAfhead.Header.HistoResolution;
1323 if (gpTAsettdc.resolutioncode == 25)
1324 fBinWidth = 0.0000244140625;
1325 else if (gpTAsettdc.resolutioncode == 100)
1326 fBinWidth = 0.00009765625;
1327 else if (gpTAsettdc.resolutioncode == 200)
1328 fBinWidth = 0.0001953125;
1329 else if (gpTAsettdc.resolutioncode == 800)
1330 fBinWidth = 0.0007812500;
1331 else {
1332 file_name.close();
1333 fReadStatus = "ERROR "+fFilename+" settings resolution code failed!";
1334 return 1; // ERROR reading settings failed
1335 }
1336
1337 fLengthHisto = 0;
1338 fNumberHisto = 0;
1339 for (i=0; i<tothist; i++) {
1340 /* read histogram data */
1341 if (gpTAsettdc.tag[i].Type == PTATAGC_POSITRON) {
1342 int nbins;
1343
1344#ifdef MIDEBUG1
1345 cout << "Tag[" << i << "] Histomin = " << gpTAsettdc.tag[i].Histominb
1346 << " Histomax = " << gpTAsettdc.tag[i].Histomaxb << endl;
1347#endif
1348 // is a histogram there
1349 if ((nbins=(gpTAsettdc.tag[i].Histomaxb-gpTAsettdc.tag[i].Histominb + 1))>1) {
1350 // first histo -> take histogram length
1351 if (fNumberHisto == 0)
1352 fLengthHisto = nbins+gpTAsettdc.tag[i].Histominb;
1353 // different histogram length?
1354 else if (fLengthHisto != nbins+gpTAsettdc.tag[i].Histominb) {
1355 std::cout << "Different histogram lengths!" << std::endl;
1356 }
1357 fNumberHisto++;
1358 }
1359 }
1360 }
1361
1362 } else if (strcmp(fFormatId,"T5") == 0) {
1363
1364 if (sizeof(pTATDC32SettingsRec) != gpTAfhead.NumBytesSettings) {
1365 file_name.close();
1366 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTATDC32SettingsRec size";
1367 return 1; // ERROR reading header failed
1368 }
1369
1370 if (sizeof(pTATDC32StatisticRec) != gpTAfhead.NumBytesStatistics) {
1371 file_name.close();
1372 fReadStatus = "ERROR Reading "+fFilename+" incorrect pTATDC32StatisticRec size";
1373 return 1; // ERROR reading header failed
1374 }
1375
1376 pTATDC32SettingsRec gpTAsettdc32;
1377 pTATDC32StatisticRec gpTAstattottdc32;
1378
1379 tothist = TDCMAXTAGS32;
1380
1381 // read settings into buffer
1382 file_name.read((char *)&gpTAsettdc32, sizeof gpTAsettdc32);
1383 if (file_name.fail()) {
1384 file_name.close();
1385 fReadStatus = "ERROR Reading "+fFilename+" settings failed!";
1386 return 1; // ERROR reading settings failed
1387 }
1388
1389 // read stat into buffer
1390 file_name.read((char *)&gpTAstattottdc32, sizeof gpTAstattottdc32);
1391 if (file_name.fail()) {
1392 file_name.close();
1393 fReadStatus = "ERROR Reading "+fFilename+" statistics failed!";
1394 return 1; // ERROR reading statistics failed
1395 }
1396
1398 for (i=0; i < fNumberScaler; i++) {
1399 strncpy(fLabelsScalers[i],gpTAsettdc32.tag[i].Label,MAXLABELSIZE);
1400 fLabelsScalers[i][MAXLABELSIZE-1] = '\0';
1401
1402 fScalers[i] = gpTAstattottdc32.TagScaler[i];
1403 }
1404
1405 resolutionfactor = gpTAfhead.Header.HistoResolution;
1406 if (gpTAsettdc32.resolutioncode == 25)
1407 fBinWidth = 0.0000244140625;
1408 else if (gpTAsettdc32.resolutioncode == 100)
1409 fBinWidth = 0.00009765625;
1410 else if (gpTAsettdc32.resolutioncode == 200)
1411 fBinWidth = 0.0001953125;
1412 else if (gpTAsettdc32.resolutioncode == 800)
1413 fBinWidth = 0.0007812500;
1414 else
1415 {
1416 file_name.close();
1417 fReadStatus = "ERROR "+fFilename+" settings resolution code failed!";
1418 return 1; // ERROR reading settings failed
1419 }
1420
1421 fLengthHisto = 0;
1422 fNumberHisto = 0;
1423 for (i=0; i<tothist; i++) {
1424 /* read histogram data */
1425 if (gpTAsettdc32.tag[i].Type == PTATAGC_POSITRON) {
1426 int nbins;
1427
1428#ifdef MIDEBUG1
1429 cout << "Tag[" << i << "] Histomin = " << gpTAsettdc32.tag[i].Histominb
1430 << " Histomax = " << gpTAsettdc32.tag[i].Histomaxb << endl;
1431#endif
1432 // is a histogram there?
1433 if ((nbins=(gpTAsettdc32.tag[i].Histomaxb-gpTAsettdc32.tag[i].Histominb + 1))>1) {
1434
1435 // first histo -> take histogram length
1436 if (fNumberHisto == 0)
1437 fLengthHisto = nbins+gpTAsettdc32.tag[i].Histominb;
1438 // different histogram length?
1439 else if (fLengthHisto != nbins+gpTAsettdc32.tag[i].Histominb) {
1440 std::cout << "Different histogram lengths!" << std::endl;
1441 }
1442 fNumberHisto++;
1443 }
1444 }
1445 }
1446
1447 } else {
1448 tothist = 0;
1449 }
1450
1451 // no histograms to process?
1452 if (tothist <= 0) {
1453 Clear();
1454 file_name.close();
1455 fReadStatus = "ERROR Less than 1 histogram in " + fFilename;
1456 return 5; // ERROR number of histograms < 1
1457 }
1458
1459 if (tothist > MAXHISTO) {
1460 std::cout << "ERROR number of histograms " << tothist << " exceedes maximum "
1461 << MAXHISTO << "! - Setting maximum number " << std::endl;
1462 tothist = MAXHISTO;
1463 }
1464
1465#ifdef MIDEBUG1
1466 cout << "Number of histograms is " << fNumberHisto << endl;
1467 cout << "Histogram length is " << fLengthHisto << endl;
1468 cout << "Resolutionfactor for t0, fg, lg is " << resolutionfactor << endl;
1469#endif
1470
1471 fDefaultBinning = resolutionfactor;
1472
1473 // allocate histograms
1474 fHisto.resize(int(fNumberHisto));
1475
1476 for (i=0; i<fNumberHisto; i++) {
1477 fHisto[i].resize(fLengthHisto);
1478 }
1479
1480 pTATagRec tag;
1481
1482 fTotalEvents = 0;
1483
1484 for (i=0; i<fNumberHisto; i++)
1485 fEventsPerHisto[i] = 0;
1486
1487 int ihist = 0;
1488 Int32 *thist = nullptr;
1489 std::vector<double> dummy_vector;
1490
1491 fHistosVector.clear();
1492 for (i=0,ihist=0; i< tothist; i++) {
1493 file_name.read((char *)&tag, sizeof tag); // read tag into buffer
1494 if (file_name.fail()) {
1495 dummy_vector.clear();
1496 Clear();
1497 if (thist != nullptr) {
1498 delete [] thist;
1499 thist = nullptr;
1500 }
1501 file_name.close();
1502 fReadStatus = "ERROR Reading "+fFilename+" tag failed!";
1503 return 6; // ERROR reading tag failed
1504 }
1505 /* read histogram data */
1506 if (tag.Type == PTATAGC_POSITRON) {
1507 int nbins;
1508
1509#ifdef MIDEBUG1
1510 cout << "Tag[" << i << "] " << tag.Label << " : Histomin = " << tag.Histominb
1511 << " Histomax = " << tag.Histomaxb << endl;
1512#endif
1513 // is a histogram there?
1514 if ((nbins=(tag.Histomaxb-tag.Histominb + 1))>1) {
1515 if (thist == nullptr)
1516 thist = new Int32[nbins];
1517 if (thist == nullptr) {
1518 Clear();
1519 file_name.close();
1520 fReadStatus = "ERROR Allocating histogram buffer failed!";
1521 return 3; // ERROR allocating histogram buffer
1522 }
1523
1524 file_name.read((char *)thist, sizeof(Int32)*nbins);// read hist into buffer
1525 if (file_name.fail()) {
1526 Clear();
1527 if (thist != nullptr) {
1528 delete [] thist;
1529 thist = nullptr;
1530 }
1531 file_name.close();
1532 fReadStatus = "ERROR Reading "+fFilename+" hist failed!";
1533 return 6; // ERROR reading hist failed
1534 }
1535
1536 // for pTA only: use histogram only, if histogram was selected
1537 // else take all histos but mark not selected
1538 if (selected[i] || (strcmp(fFormatId,"M3") != 0)) {
1539
1540 if (ihist < MAXHISTO) { // max number of histos not yet reached?
1541 dummy_vector.clear();
1542
1543 strncpy(fLabelsHisto[ihist],tag.Label,MAXLABELSIZE);
1544 fLabelsHisto[ihist][MAXLABELSIZE-1] = '\0';
1545
1546 // mark with ** when not selected
1547 if (!selected[i] && (strlen(fLabelsHisto[ihist])<MAXLABELSIZE-2))
1548 strcat(fLabelsHisto[ihist],"**");
1549
1550 // calculate t0, fg, lg for "raw" TDC /pTA actually specified for binned
1551 // histograms
1552 // taking largest possible bin value for t0 and fg
1553 fIntegerT0[ihist] = (tag.t0b+1)*resolutionfactor -1;
1554 fFirstGood[ihist] = (tag.tfb+1)*resolutionfactor -1;
1555 fLastGood[ihist] = tag.tlb*resolutionfactor;
1556
1557 // store histogram
1558 // in case of non zero offset init
1559 for (j=0; j<tag.Histominb; j++) {
1560 fHisto[ihist][j]= 0;
1561 dummy_vector.push_back(double(fHisto[ihist][j]));
1562 }
1563 // fill histogram
1564 for (j=tag.Histominb; j<fLengthHisto; j++) {
1565 fHisto[ihist][j]= *(thist+j-tag.Histominb);
1566 dummy_vector.push_back(double(fHisto[ihist][j]));
1567
1568 // do summation of events between fg and lg
1569 if ((j >= fFirstGood[ihist]) && (j <= fLastGood[ihist]))
1570 fEventsPerHisto[ihist] += *(thist+j-tag.Histominb);
1571 }
1572 fHistosVector.push_back(dummy_vector);
1573
1574 // only add selected histo(s) to total events
1575 if (selected[i])
1576 fTotalEvents += fEventsPerHisto[ihist];
1577 }
1578 ihist++;
1579 }
1580 }
1581 }
1582 }
1583
1584 if (thist != nullptr) {
1585 delete [] thist;
1586 thist = nullptr;
1587 }
1588
1589 file_name.close();
1590
1591 fReadStatus = "SUCCESS";
1592 fReadingOk = true;
1593
1594 return 0;
1595}
1596
1597//*******************************
1598//Implementation WriteMdu
1599//*******************************
1600
1615int MuSR_td_PSI_bin::WriteMdu(const char * fileName)
1616{
1617 std::cerr << std::endl << "MuSR_td_PSI_bin::WriteMdu - not yet implemented" << std::endl;
1618 return 0;
1619}
1620
1621
1622//*******************************
1623//Implementation ReadingOK
1624//*******************************
1625
1632bool MuSR_td_PSI_bin::ReadingOK() const
1633{
1634 return fReadingOk;
1635}
1636
1637//*******************************
1638//Implementation WritingOK
1639//*******************************
1640
1647bool MuSR_td_PSI_bin::WritingOK() const
1648{
1649 return fWritingOk;
1650}
1651
1652//*******************************
1653//Implementation CheckDataConsistency
1654//*******************************
1655
1672{
1673 if (fNumberHisto <= 0) {
1674 fConsistencyOk = false;
1675 fConsistencyStatus = "**ERROR** number histograms is zero or less!";
1676 return fConsistencyOk;
1677 }
1678
1679 if (fNumberHisto > MAXHISTO) {
1680 fConsistencyOk = false;
1681 fConsistencyStatus = "**ERROR** number of histograms requested: ";
1683 fConsistencyStatus += ", which is larger than the possible maximum of 32.";
1684 return fConsistencyOk;
1685 }
1686
1687 if (fLengthHisto <= 0) {
1688 fConsistencyOk = false;
1689 fConsistencyStatus = "**ERROR** histogram length is zero or less!";
1690 return fConsistencyOk;
1691 }
1692
1693 if (fLengthHisto > 32767) {
1694 fConsistencyOk = false;
1695 fConsistencyStatus = "**ERROR** histogram length is too large (maximum being 32767)!";
1696 return fConsistencyOk;
1697 }
1698
1699 if ((fLengthHisto % 256 != 0) && (tag == 1)) {
1700 fConsistencyOk = false;
1701 fConsistencyStatus = "**ERROR** histogram length is not a multiple of 256!";
1702 return fConsistencyOk;
1703 }
1704
1705 if ((fNumberHisto * fLengthHisto > 65536) && (tag != 2)) {
1706 fConsistencyOk = false;
1707 fConsistencyStatus = "**ERROR** fNumberHisto * fLengthHisto > 65536!";
1708 return fConsistencyOk;
1709 }
1710
1711 if (fHisto.size() == 0) {
1712 fConsistencyOk = false;
1713 fConsistencyStatus = "**ERROR** no histograms present!";
1714 return fConsistencyOk;
1715 }
1716
1717 fConsistencyOk = true;
1718 fConsistencyStatus = "SUCCESS";
1719
1720 return fConsistencyOk;
1721}
1722
1723
1724//*******************************
1725//Implementation ReadStatus
1726//*******************************
1727
1734std::string MuSR_td_PSI_bin::ReadStatus() const
1735{
1736 return fReadStatus;
1737}
1738
1739//*******************************
1740//Implementation WriteStatus
1741//*******************************
1742
1749std::string MuSR_td_PSI_bin::WriteStatus() const
1750{
1751 return fWriteStatus;
1752}
1753
1754//*******************************
1755//Implementation ConsistencyStatus
1756//*******************************
1757
1764std::string MuSR_td_PSI_bin::ConsistencyStatus() const
1765{
1766 return fConsistencyStatus;
1767}
1768
1769//*******************************
1770//Implementation Filename
1771//*******************************
1772
1778std::string MuSR_td_PSI_bin::Filename() const
1779{
1780 return fFilename;
1781}
1782
1783
1784//*******************************
1785//Implementation GetHistoInt
1786//*******************************
1787
1794int MuSR_td_PSI_bin::GetHistoInt(int histo_num, int j)
1795{
1796 if (!fReadingOk) return 0;
1797
1798 if (( histo_num < 0) || (histo_num >= int(fNumberHisto)) ||
1799 (j < 0 ) || (j >= fLengthHisto))
1800 return 0;
1801#ifdef MIDEBUG
1802 cout << "fHistosVector[0][0] = " << fHistosVector[0][0] << endl;
1803#endif
1804 return fHisto[histo_num][j];
1805}
1806
1807//*******************************
1808//Implementation GetHisto
1809//*******************************
1810
1817double MuSR_td_PSI_bin::GetHisto(int histo_num, int j)
1818{
1819 if (!fReadingOk) return 0.;
1820
1821 if (( histo_num < 0) || (histo_num >= int(fNumberHisto)) ||
1822 (j < 0 ) || (j >= fLengthHisto))
1823 return 0.;
1824#ifdef MIDEBUG
1825 cout << "fHistosVector[0][0] = " << fHistosVector[0][0] << endl;
1826#endif
1827 return static_cast<double>(fHisto[histo_num][j]);
1828}
1829
1830//*******************************
1831//Implementation GetHistoArray
1832//*******************************
1833
1846std::vector<double> MuSR_td_PSI_bin::GetHistoArray(int histo_num, int binning)
1847{
1848 std::vector<double> histo_array;
1849
1850 if (!fReadingOk) return histo_array;
1851
1852 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
1853 return histo_array;
1854
1855 histo_array.resize((int)(fLengthHisto/binning));
1856
1857 if (histo_array.size() == 0) return histo_array;
1858
1859 for (int i=0; i<int(int(fLengthHisto)/binning); i++) {
1860 histo_array[i] = 0;
1861 for (int j = 0; j < binning; j++)
1862 histo_array[i] += double(fHisto[histo_num][i*binning+j]);
1863 }
1864
1865 return histo_array;
1866}
1867
1868 //*******************************
1869 //Implementation PutHistoArrayInt
1870 //*******************************
1871
1891 int MuSR_td_PSI_bin::PutHistoArrayInt(std::vector<std::vector<int> > &histoData, int tag)
1892 {
1893 // check that the number of histograms are within allowed boundaries
1894 if ((histoData.size() == 0) || (histoData.size() > 32)) {
1895 fConsistencyOk = false;
1896 fConsistencyStatus = "**ERROR** number of histograms out of range! Must be > 0 and < 32.";
1897 return -1;
1898 }
1899
1900 // check that all the given histograms have the same length
1901 unsigned int size = histoData[0].size();
1902 bool ok = true;
1903 for (unsigned int i=1; i<histoData.size(); i++) {
1904 if (histoData[i].size() != size) {
1905 ok = false;
1906 break;
1907 }
1908 }
1909 if (!ok) {
1910 fConsistencyOk = false;
1911 fConsistencyStatus = "**ERROR** not all histograms have the same length!";
1912 return -2;
1913 }
1914
1915 // overwrite fNumberHisto
1916 fNumberHisto = static_cast<int>(histoData.size());
1917
1918 // calculate the allowed histo length
1919 int lengthHisto = (65536 / histoData.size()) - ((65536 / histoData.size()) % 256);
1920 if (lengthHisto > 32512)
1921 lengthHisto = 32512;
1922 if (tag == 2) {
1923 if (lengthHisto > 32512)
1924 lengthHisto = 32512;
1925 }
1926
1927 // calculate the needed data length
1928 int dataLength = ((int)histoData[0].size());
1929 int rebin = (int)histoData[0].size() / lengthHisto;
1930 if (tag == 0) {
1931 // calculate what rebinning is needed
1932 if ((int)histoData[0].size() % lengthHisto != 0)
1933 rebin++;
1934 if ((((int)histoData[0].size()/rebin) % 256) == 0)
1935 dataLength = (int)histoData[0].size()/rebin;
1936 else
1937 dataLength = (((int)histoData[0].size()/rebin/256)+1)*256;
1938 } else if ((tag == 1) || (tag == 2)) {
1939 if (((int)histoData[0].size() % 256) != 0)
1940 dataLength = (((int)histoData[0].size()/256)+1)*256;
1941 }
1942
1943 // overwrite fLengthHisto
1944 fLengthHisto = dataLength;
1945
1946 // allocate the necessary memory
1947 int noOfHistos = histoData.size();
1948 fHisto.resize(noOfHistos);
1949
1950 for (unsigned int i=0; i<noOfHistos; i++) {
1951 fHisto[i].resize(fLengthHisto);
1952 }
1953
1954 // check how the data shall be treated
1955 if (tag == 0) { // rebin and zero pad at need (strict)
1956 // rebin data such that it is compatible with PSI-BIN
1957 std::vector< std::vector<int> > data;
1958 data.resize(fNumberHisto);
1959
1960 int val = 0;
1961 for (int i=0; i<fNumberHisto; i++) {
1962 for (unsigned int j=0; j<histoData[i].size(); j++) {
1963 if ((j>0) && (j%rebin == 0)) {
1964 data[i].push_back(val);
1965 val = 0;
1966 }
1967 val += histoData[i][j];
1968 }
1969 }
1970
1971 // fill the histograms
1972 for (int i=0; i<fNumberHisto; i++) {
1973 for (int j=0; j<fLengthHisto; j++) {
1974 if (j<(int)data[i].size())
1975 fHisto[i][j] = data[i][j];
1976 else
1977 fHisto[i][j] = 0;
1978 }
1979 }
1980
1981 // rescale T0, fgb, lgb, and time resolution
1982 for (int i=0; i<fNumberHisto; i++) {
1984 fIntegerT0[i] /= rebin;
1985 fFirstGood[i] /= rebin;
1986 fLastGood[i] /= rebin;
1987 }
1988 fBinWidth *= rebin;
1989 } else if ((tag == 1) || (tag == 2)) { // truncate at need tag=1 (strict), or just fill tag=2 (loose)
1990 // feed the histograms
1991 for (int i=0; i<fNumberHisto; i++) {
1992 for (int j=0; j<fLengthHisto; j++) {
1993 if (j < histoData[i].size())
1994 fHisto[i][j] = histoData[i][j];
1995 else
1996 fHisto[i][j] = 0;
1997 }
1998 }
1999
2000 // check if T0, fgb, and lgb are still within proper boundaries
2001 for (int i=0; i<fNumberHisto; i++) {
2002 if (fIntegerT0[i] > fLengthHisto)
2003 fIntegerT0[i] = 0;
2005 if (fFirstGood[i] > fLengthHisto)
2006 fFirstGood[i] = 0;
2007 if (fLastGood[i] > fLengthHisto)
2008 fLastGood[i] = fLengthHisto-1;
2009 }
2010 } else {
2011 fConsistencyOk = false;
2012 fConsistencyStatus = "**ERROR** found unsupported tag!";
2013 return -3;
2014 }
2015
2016 return 0;
2017 }
2018
2019//*******************************
2020//Implementation GetHistoVector
2021//*******************************
2022
2034 std::vector<double> MuSR_td_PSI_bin::GetHistoVector(int histo_num, int binning)
2035 {
2036 std::vector<double> histo_vector; //(int(fLengthHisto/binning))
2037
2038 if (!fReadingOk) return histo_vector;
2039
2040 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2041 return histo_vector;
2042
2043 for (int i = 0; i < int(fLengthHisto/binning); i++)
2044 histo_vector.push_back(0.);
2045
2046 for (int i = 0; i < int(fLengthHisto/binning); i++) {
2047 for (int j = 0; j < binning; j++)
2048 histo_vector[i] += double(fHisto[histo_num][i*binning+j]);
2049 }
2050
2051 return histo_vector;
2052 }
2053
2054//*******************************
2055//Implementation GetHistoVectorNo0
2056//*******************************
2057
2070 std::vector<double> MuSR_td_PSI_bin::GetHistoVectorNo0(int histo_num, int binning)
2071 {
2072 std::vector<double> histo_vector; //(int(fLengthHisto/binning));
2073
2074 if (!fReadingOk) return histo_vector;
2075
2076 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2077 return histo_vector;
2078
2079 for (int i = 0; i < int(fLengthHisto/binning); i++)
2080 histo_vector.push_back(0.);
2081
2082 for (int i = 0; i < int(fLengthHisto/binning); i++) {
2083 for (int j = 0; j < binning; j++)
2084 histo_vector[i] += double(fHisto[histo_num][i*binning+j]);
2085
2086 if (histo_vector[i] < 0.5 ) {
2087 histo_vector[i] = 0.1;
2088 }
2089 }
2090
2091 return histo_vector;
2092 }
2093
2094
2095//**********************************
2096//Implementation GetHistoArrayInt
2097//**********************************
2098
2110 std::vector<int> MuSR_td_PSI_bin::GetHistoArrayInt(int histo_num)
2111 {
2112 std::vector<int> histo_array;
2113
2114 if (!fReadingOk) return histo_array;
2115
2116 if ( histo_num < 0 || histo_num >= int(fNumberHisto))
2117 return histo_array;
2118
2119 histo_array.resize(fLengthHisto);
2120
2121 if (histo_array.size() == 0)
2122 return histo_array;
2123
2124 histo_array = fHisto[histo_num];
2125
2126 return histo_array;
2127 }
2128
2129
2130//*******************************
2131//Implementation GetHistoFromT0Array
2132//*******************************
2133
2147 double* MuSR_td_PSI_bin::GetHistoFromT0Array(int histo_num, int binning, int offset)
2148 {
2149 if (!fReadingOk) return nullptr;
2150
2151 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2152 return nullptr;
2153
2154 double *histo_fromt0_array =
2155 new double[int((int(fLengthHisto)-GetT0Int(histo_num)-offset+1)/binning)];
2156
2157 if (!histo_fromt0_array) return nullptr;
2158
2159 for (int i = 0; i < int((int(fLengthHisto)-GetT0Int(histo_num)-offset)/binning); i++) {
2160 histo_fromt0_array[i] = 0;
2161 for (int j = 0; j < binning; j++)
2162 histo_fromt0_array[i] +=
2163 double(fHisto[histo_num][i*binning+j+GetT0Int(histo_num)+offset]);
2164 }
2165
2166 return histo_fromt0_array;
2167 }
2168
2169
2170//*******************************
2171//Implementation GetHistoFromT0Vector
2172//*******************************
2173
2186 std::vector<double> MuSR_td_PSI_bin::GetHistoFromT0Vector(int histo_num, int binning, int offset)
2187 {
2188 std::vector<double> histo_fromt0_vector; // (int((int(fLengthHisto)-GetT0Int(histo_num)+1)/binning));
2189
2190 if (!fReadingOk) return histo_fromt0_vector;
2191
2192 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2193 return histo_fromt0_vector;
2194
2195 for (int i = 0; i < int((int(fLengthHisto)-GetT0Int(histo_num)-offset)/binning); i++)
2196 histo_fromt0_vector.push_back(0.);
2197
2198 for (int i = 0; i < int((int(fLengthHisto)-GetT0Int(histo_num)-offset)/binning); i++) {
2199 for (int j = 0; j < binning; j++)
2200 histo_fromt0_vector[i] +=
2201 double(fHisto[histo_num][i*binning+j+GetT0Int(histo_num)+offset]);
2202 }
2203
2204 return histo_fromt0_vector;
2205 }
2206
2207
2208//*******************************
2209//Implementation GetHistoGoodBinsArray
2210//*******************************
2211
2224 double * MuSR_td_PSI_bin::GetHistoGoodBinsArray(int histo_num, int binning)
2225 {
2226 if (!fReadingOk) return nullptr;
2227 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2228 return nullptr;
2229
2230 double *histo_goodBins_array =
2231 new double[int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num)+1)/binning)];
2232
2233 if (!histo_goodBins_array) return nullptr;
2234
2235 for (int i = 0; i < int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num))/binning); i++) {
2236 histo_goodBins_array[i] = 0;
2237 for (int j = 0; j < binning; j++)
2238 histo_goodBins_array[i] +=
2239 double(fHisto[histo_num][i*binning+j+GetFirstGoodInt(histo_num)]);
2240 }
2241
2242 return histo_goodBins_array;
2243 }
2244
2245
2246//*******************************
2247//Implementation GetHistoGoodBinsVector
2248//*******************************
2249
2262 std::vector<double> MuSR_td_PSI_bin::GetHistoGoodBinsVector(int histo_num, int binning)
2263 {
2264 std::vector<double> histo_goodBins_vector;
2265
2266 if (!fReadingOk) return histo_goodBins_vector;
2267
2268 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2269 return histo_goodBins_vector;
2270
2271 for (int i = 0; i < int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num))/binning); i++)
2272 histo_goodBins_vector.push_back(0.);
2273
2274 for (int i = 0; i < int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num))/binning); i++) {
2275 for (int j = 0; j < binning; j++)
2276 histo_goodBins_vector[i] +=
2277 double(fHisto[histo_num][i*binning+j+GetFirstGoodInt(histo_num)]);
2278 }
2279
2280 return histo_goodBins_vector;
2281 }
2282
2283
2284//*******************************
2285//Implementation GetHistoFromT0MinusBkgArray
2286//*******************************
2287
2307 double * MuSR_td_PSI_bin::GetHistoFromT0MinusBkgArray(int histo_num,
2308 int lower_bckgrd, int higher_bckgrd, int binning, int offset)
2309 {
2310 if (!fReadingOk) return nullptr;
2311
2312 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2313 return nullptr;
2314
2315 if ( lower_bckgrd < 0 || higher_bckgrd >= int(fLengthHisto) || lower_bckgrd > higher_bckgrd )
2316 return nullptr;
2317
2318 double bckgrd = 0;
2319
2320 for (int k = lower_bckgrd; k <= higher_bckgrd; k++) {
2321 bckgrd += double(fHisto[histo_num][k]);
2322 }
2323 bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1);
2324
2325 double *histo_fromt0_minus_bckgrd_array =
2326 new double[int((int(fLengthHisto)-GetT0Int(histo_num)-offset+1)/binning)];
2327
2328 if (!histo_fromt0_minus_bckgrd_array) return NULL;
2329
2330 for (int i = 0; i < int((int(fLengthHisto)-GetT0Int(histo_num)-offset)/binning); i++) {
2331 histo_fromt0_minus_bckgrd_array[i] = 0;
2332 for (int j = 0; j < binning; j++)
2333 histo_fromt0_minus_bckgrd_array[i] +=
2334 double(fHisto[histo_num][i*binning+j+GetT0Int(histo_num)+offset]) - bckgrd;
2335 }
2336
2337 return histo_fromt0_minus_bckgrd_array;
2338 }
2339
2340//*******************************
2341//Implementation GetHistoFromT0MinusBkgVector
2342//*******************************
2343
2362 std::vector<double> MuSR_td_PSI_bin::GetHistoFromT0MinusBkgVector(int histo_num, int lower_bckgrd,
2363 int higher_bckgrd, int binning, int offset)
2364 {
2365 std::vector<double> histo_fromt0_minus_bckgrd_vector; // (int((int(fLengthHisto)-GetT0Int(histo_num)+1)/binning));
2366
2367 if (!fReadingOk) return histo_fromt0_minus_bckgrd_vector;
2368
2369 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2370 return histo_fromt0_minus_bckgrd_vector;
2371
2372 if ( lower_bckgrd < 0 || higher_bckgrd >= int(fLengthHisto) || lower_bckgrd > higher_bckgrd )
2373 return histo_fromt0_minus_bckgrd_vector;
2374
2375 double bckgrd = 0;
2376 for (int k = lower_bckgrd; k <= higher_bckgrd; k++) {
2377 bckgrd += double(fHisto[histo_num][k]);
2378 }
2379 bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1);
2380
2381 for (int i = 0; i < int((int(fLengthHisto)-GetT0Int(histo_num)-offset)/binning); i++)
2382 histo_fromt0_minus_bckgrd_vector.push_back(0.);
2383
2384 for (int i = 0; i < int((int(fLengthHisto)-GetT0Int(histo_num)-offset)/binning); i++) {
2385 for (int j = 0; j < binning; j++)
2386 histo_fromt0_minus_bckgrd_vector[i] +=
2387 double(fHisto[histo_num][i*binning+j+GetT0Int(histo_num)+offset]) - bckgrd;
2388 }
2389
2390 return histo_fromt0_minus_bckgrd_vector;
2391 }
2392
2393
2394//*******************************
2395//Implementation GetHistoGoodBinsMinusBkgArray
2396//*******************************
2397
2417 double * MuSR_td_PSI_bin::GetHistoGoodBinsMinusBkgArray(int histo_num, int lower_bckgrd,
2418 int higher_bckgrd, int binning)
2419 {
2420 if (!fReadingOk) return nullptr;
2421
2422 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2423 return nullptr;
2424
2425 if ( lower_bckgrd < 0 || higher_bckgrd >= int(fLengthHisto) || lower_bckgrd > higher_bckgrd )
2426 return nullptr;
2427
2428 double bckgrd = 0;
2429 for (int k = lower_bckgrd; k <= higher_bckgrd; k++) {
2430 bckgrd += double(fHisto[histo_num][k]);
2431 }
2432 bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1);
2433
2434 double *histo_goodBins_minus_bckgrd_array =
2435 new double[int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num)+1)/binning)];
2436
2437 if (!histo_goodBins_minus_bckgrd_array) return nullptr;
2438
2439 for (int i = 0; i < int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num))/binning); i++) {
2440 histo_goodBins_minus_bckgrd_array[i] = 0;
2441 for (int j = 0; j < binning; j++)
2442 histo_goodBins_minus_bckgrd_array[i] +=
2443 double(fHisto[histo_num][i*binning+j+GetFirstGoodInt(histo_num)]) - bckgrd;
2444 }
2445
2446 return histo_goodBins_minus_bckgrd_array;
2447 }
2448
2449
2450//*******************************
2451//Implementation GetHistoGoodBinsMinusBkgVector
2452//*******************************
2453
2472 std::vector<double> MuSR_td_PSI_bin::GetHistoGoodBinsMinusBkgVector(int histo_num, int lower_bckgrd,
2473 int higher_bckgrd, int binning)
2474 {
2475 std::vector<double> histo_goodBins_minus_bckgrd_vector; ;
2476
2477 if (!fReadingOk) return histo_goodBins_minus_bckgrd_vector;
2478
2479 if ( histo_num < 0 || histo_num >= int(fNumberHisto) || binning <= 0 )
2480 return histo_goodBins_minus_bckgrd_vector;
2481
2482 if ( lower_bckgrd < 0 || higher_bckgrd >= int(fLengthHisto) || lower_bckgrd > higher_bckgrd )
2483 return histo_goodBins_minus_bckgrd_vector;
2484
2485 double bckgrd = 0;
2486 for (int k = lower_bckgrd; k <= higher_bckgrd; k++) {
2487 bckgrd += double(fHisto[histo_num][k]);
2488 }
2489 bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1);
2490
2491 for (int i = 0; i < int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num))/binning); i++)
2492 histo_goodBins_minus_bckgrd_vector.push_back(0.);
2493
2494 for (int i = 0; i < int((GetLastGoodInt(histo_num)-GetFirstGoodInt(histo_num))/binning); i++) {
2495 for (int j = 0; j < binning; j++)
2496 histo_goodBins_minus_bckgrd_vector[i] +=
2497 double(fHisto[histo_num][i*binning+j+GetFirstGoodInt(histo_num)]) - bckgrd;
2498 }
2499
2500 return histo_goodBins_minus_bckgrd_vector;
2501 }
2502
2503
2504//*******************************
2505//Implementation GetAsymmetryArray
2506//*******************************
2507
2529 double* MuSR_td_PSI_bin::GetAsymmetryArray(int histo_num_plus, int histo_num_minus, double alpha_param,
2530 int binning, int lower_bckgrd_plus, int higher_bckgrd_plus,
2531 int lower_bckgrd_minus, int higher_bckgrd_minus, int offset,
2532 double y_offset)
2533 {
2534 int max_t0 = Tmax(GetT0Int(histo_num_plus),GetT0Int(histo_num_minus));
2535
2536 if (!fReadingOk) return nullptr;
2537
2538 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
2539 return nullptr;
2540
2541 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
2542 return nullptr;
2543
2544 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
2545 return nullptr;
2546
2547 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
2548 return nullptr;
2549
2550
2551 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus, lower_bckgrd_plus,
2552 higher_bckgrd_plus, binning, offset);
2553 if (dummy_1 == nullptr) return nullptr;
2554
2555 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus, lower_bckgrd_minus,
2556 higher_bckgrd_minus, binning, offset);
2557 if (dummy_2 == nullptr) {
2558 delete [] dummy_1;
2559 return nullptr;
2560 }
2561
2562 double *asymmetry_array = new double[int((int(fLengthHisto)-max_t0-offset+1)/binning)];
2563
2564 if (!asymmetry_array) return nullptr;
2565
2566 for (int i = 0; i < int((int(fLengthHisto)-max_t0)/binning); i++) {
2567 asymmetry_array[i] = (dummy_1[i] - alpha_param * dummy_2[i]) /
2568 (dummy_1[i] + alpha_param * dummy_2[i]) + y_offset;
2569 }
2570
2571 delete [] dummy_1;
2572 delete [] dummy_2;
2573
2574 return asymmetry_array;
2575 }
2576
2577
2578//*******************************
2579//Implementation GetAsymmetryVector
2580//*******************************
2581
2600 std::vector<double> MuSR_td_PSI_bin::GetAsymmetryVector(int histo_num_plus, int histo_num_minus, double alpha_param,
2601 int binning, int lower_bckgrd_plus, int higher_bckgrd_plus,
2602 int lower_bckgrd_minus, int higher_bckgrd_minus, int offset, double y_offset)
2603 {
2604 int max_t0 = Tmax(GetT0Int(histo_num_plus),GetT0Int(histo_num_minus));
2605
2606 std::vector<double> asymmetry_vector; // (int((int(fLengthHisto)-max_t0+1)/binning));
2607
2608 if (!fReadingOk) return asymmetry_vector;
2609
2610 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
2611 return asymmetry_vector;
2612
2613 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
2614 return asymmetry_vector;
2615
2616 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
2617 return asymmetry_vector;
2618
2619 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
2620 return asymmetry_vector;
2621
2622 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus, lower_bckgrd_plus,
2623 higher_bckgrd_plus, binning, offset);
2624 if (dummy_1 == nullptr) return asymmetry_vector;
2625
2626 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus, lower_bckgrd_minus,
2627 higher_bckgrd_minus, binning, offset);
2628 if (dummy_2 == nullptr) {
2629 delete [] dummy_1;
2630 return asymmetry_vector;
2631 }
2632
2633 for (int i = 0; i < int((int(fLengthHisto)-max_t0-offset)/binning); i++)
2634 asymmetry_vector.push_back(0.);
2635
2636 for (int i = 0; i < int((int(fLengthHisto)-max_t0-offset)/binning); i++) {
2637 asymmetry_vector[i] = (dummy_1[i] - alpha_param * dummy_2[i]) /
2638 (dummy_1[i] + alpha_param * dummy_2[i]) + y_offset;
2639 }
2640
2641 delete [] dummy_1;
2642 delete [] dummy_2;
2643
2644 return asymmetry_vector;
2645 }
2646
2647
2648//*******************************
2649//Implementation GetErrorAsymmetryArray
2650//*******************************
2651
2670 double * MuSR_td_PSI_bin::GetErrorAsymmetryArray(int histo_num_plus, int histo_num_minus, double alpha_param,
2671 int binning, int lower_bckgrd_plus, int higher_bckgrd_plus,
2672 int lower_bckgrd_minus, int higher_bckgrd_minus, int offset)
2673 {
2674 int max_t0 = Tmax(GetT0Int(histo_num_plus),GetT0Int(histo_num_minus));
2675
2676 if (!fReadingOk) return nullptr;
2677
2678 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
2679 return nullptr;
2680
2681 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
2682 return nullptr;
2683
2684 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
2685 return nullptr;
2686
2687 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
2688 return nullptr;
2689
2690 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus, lower_bckgrd_plus,
2691 higher_bckgrd_plus, binning, offset);
2692 if (dummy_1 == nullptr) return nullptr;
2693
2694 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus, lower_bckgrd_minus,
2695 higher_bckgrd_minus, binning, offset);
2696 if (dummy_2 == nullptr) {
2697 delete [] dummy_1;
2698 return nullptr;
2699 }
2700
2701 double *error_asymmetry_array = new double[int((int(fLengthHisto)-max_t0-offset+1)/binning)];
2702
2703 if (!error_asymmetry_array) return nullptr;
2704
2705 for (int i = 0; i < int((fLengthHisto-max_t0-offset)/binning); i++) {
2706 if (dummy_1[i] < 0.5 || dummy_2[i] < 0.5 )
2707 error_asymmetry_array[i] = 1.0;
2708 else
2709 error_asymmetry_array[i] = double(2.) * alpha_param * sqrt(dummy_1[i]*dummy_2[i]*(dummy_1[i]+dummy_2[i])) /
2710 pow(dummy_1[i] + alpha_param * dummy_2[i],2.);
2711 }
2712
2713 delete [] dummy_1;
2714 delete [] dummy_2;
2715
2716 return error_asymmetry_array;
2717 }
2718
2719
2720//*******************************
2721//Implementation GetErrorAsymmetryVector
2722//*******************************
2723
2741 std::vector<double> MuSR_td_PSI_bin::GetErrorAsymmetryVector(int histo_num_plus, int histo_num_minus, double alpha_param,
2742 int binning, int lower_bckgrd_plus, int higher_bckgrd_plus,
2743 int lower_bckgrd_minus, int higher_bckgrd_minus, int offset)
2744 {
2745 int max_t0 = Tmax(GetT0Int(histo_num_plus),GetT0Int(histo_num_minus));
2746
2747 std::vector<double> error_asymmetry_vector; //(int((int(fLengthHisto)-max_t0+1)/binning));
2748
2749 if (!fReadingOk) return error_asymmetry_vector;
2750
2751 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
2752 return error_asymmetry_vector;
2753
2754 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
2755 return error_asymmetry_vector;
2756
2757 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
2758 return error_asymmetry_vector;
2759
2760 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
2761 return error_asymmetry_vector;
2762
2763 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus, lower_bckgrd_plus,
2764 higher_bckgrd_plus, binning, offset);
2765 if (dummy_1 == nullptr) return error_asymmetry_vector;
2766
2767 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus, lower_bckgrd_minus,
2768 higher_bckgrd_minus, binning, offset);
2769 if (dummy_2 == nullptr) {
2770 delete [] dummy_1;
2771 return error_asymmetry_vector;
2772 }
2773
2774 for (int i = 0; i < int((int(fLengthHisto)-max_t0-offset)/binning); i++)
2775 error_asymmetry_vector.push_back(0.);
2776
2777 for (int i = 0; i < int((int(fLengthHisto-max_t0-offset))/binning); i++) {
2778 if (dummy_1[i] < 0.5 || dummy_2[i] < 0.5 )
2779 error_asymmetry_vector[i] = 1.0;
2780 else
2781 error_asymmetry_vector[i] = double(2.) * alpha_param * sqrt(dummy_1[i]*dummy_2[i]*(dummy_1[i]+dummy_2[i])) /
2782 pow(dummy_1[i] + alpha_param * dummy_2[i],2.);
2783 }
2784
2785 delete [] dummy_1;
2786 delete [] dummy_2;
2787
2788 return error_asymmetry_vector;
2789 }
2790
2791
2792//*******************************
2793//Implementation GetAsymmetryGoodBinsArray
2794//*******************************
2795
2815 double * MuSR_td_PSI_bin::GetAsymmetryGoodBinsArray(int histo_num_plus, int histo_num_minus, double alpha_param,
2816 int binning, int lower_bckgrd_plus, int higher_bckgrd_plus,
2817 int lower_bckgrd_minus, int higher_bckgrd_minus)
2818 {
2819 int hsize = int((Tmin(GetLastGoodInt(histo_num_plus)-GetFirstGoodInt(histo_num_plus),
2820 GetLastGoodInt(histo_num_minus)-GetFirstGoodInt(histo_num_minus))+1)/binning);
2821
2822 if (!fReadingOk) return nullptr;
2823
2824 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
2825 return nullptr;
2826
2827 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
2828 return nullptr;
2829
2830 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
2831 return nullptr;
2832
2833 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
2834 return nullptr;
2835
2836 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus, lower_bckgrd_plus,
2837 higher_bckgrd_plus, binning);
2838 if (dummy_1 == nullptr) return nullptr;
2839
2840 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus, lower_bckgrd_minus,
2841 higher_bckgrd_minus, binning);
2842 if (dummy_2 == nullptr) {
2843 delete [] dummy_1;
2844 return nullptr;
2845 }
2846
2847 int hstart = Tmax(GetFirstGoodInt(histo_num_plus)-GetT0Int(histo_num_plus),GetFirstGoodInt(histo_num_minus)-GetT0Int(histo_num_minus));
2848
2849 double *asymmetry_goodBins_array = new double[hsize];
2850
2851 if (!asymmetry_goodBins_array) return nullptr;
2852
2853 for (int i = 0; i < hsize; i++) {
2854 asymmetry_goodBins_array[i] = (dummy_1[i+hstart] - alpha_param * dummy_2[i+hstart]) /
2855 (dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart]);
2856 }
2857
2858 delete [] dummy_1;
2859 delete [] dummy_2;
2860
2861 return asymmetry_goodBins_array;
2862 }
2863
2864
2865//*******************************
2866//Implementation GetAsymmetryGoodBinsVector
2867//*******************************
2868
2887 std::vector<double> MuSR_td_PSI_bin::GetAsymmetryGoodBinsVector(int histo_num_plus, int histo_num_minus, double alpha_param,
2888 int binning, int lower_bckgrd_plus, int higher_bckgrd_plus,
2889 int lower_bckgrd_minus, int higher_bckgrd_minus)
2890 {
2891 int hsize = int((Tmin(GetLastGoodInt(histo_num_plus)-GetFirstGoodInt(histo_num_plus),
2892 GetLastGoodInt(histo_num_minus)-GetFirstGoodInt(histo_num_minus))+1)/binning);
2893
2894 std::vector<double> asymmetry_goodBins_vector;
2895
2896 if (!fReadingOk) return asymmetry_goodBins_vector;
2897
2898 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
2899 return asymmetry_goodBins_vector;
2900
2901 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
2902 return asymmetry_goodBins_vector;
2903
2904 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
2905 return asymmetry_goodBins_vector;
2906
2907 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
2908 return asymmetry_goodBins_vector;
2909
2910 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus, lower_bckgrd_plus,
2911 higher_bckgrd_plus, binning);
2912 if (dummy_1 == nullptr) return asymmetry_goodBins_vector;
2913
2914 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus, lower_bckgrd_minus,
2915 higher_bckgrd_minus, binning);
2916 if (dummy_2 == nullptr) {
2917 delete [] dummy_1;
2918 return asymmetry_goodBins_vector;
2919 }
2920
2921 for (int i = 0; i < hsize; i++)
2922 asymmetry_goodBins_vector.push_back(0.);
2923
2924 int hstart = Tmax(GetFirstGoodInt(histo_num_plus)-GetT0Int(histo_num_plus),GetFirstGoodInt(histo_num_minus)-GetT0Int(histo_num_minus));
2925
2926 for (int i = 0; i < hsize; i++) {
2927 asymmetry_goodBins_vector[i] = (dummy_1[i+hstart] - alpha_param * dummy_2[i+hstart]) /
2928 (dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart]);
2929 }
2930 delete [] dummy_1;
2931 delete [] dummy_2;
2932
2933 return asymmetry_goodBins_vector;
2934 }
2935
2936
2937//*******************************
2938//Implementation GetErrorAsymmetryGoodBinsArray
2939//*******************************
2940
2959 double * MuSR_td_PSI_bin::GetErrorAsymmetryGoodBinsArray(int histo_num_plus, int histo_num_minus, double alpha_param,
2960 int binning, int lower_bckgrd_plus, int higher_bckgrd_plus,
2961 int lower_bckgrd_minus, int higher_bckgrd_minus)
2962 {
2963 int hsize = int((Tmin(GetLastGoodInt(histo_num_plus)
2964 -GetFirstGoodInt(histo_num_plus),
2965 GetLastGoodInt(histo_num_minus)
2966 -GetFirstGoodInt(histo_num_minus))+1)/binning);
2967
2968 if (!fReadingOk) return nullptr;
2969
2970 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
2971 return nullptr;
2972
2973 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
2974 return nullptr;
2975
2976 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
2977 return nullptr;
2978
2979 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
2980 return nullptr;
2981
2982 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus,
2983 lower_bckgrd_plus, higher_bckgrd_plus, binning);
2984 if (dummy_1 == nullptr) return nullptr;
2985
2986 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus,
2987 lower_bckgrd_minus, higher_bckgrd_minus, binning);
2988 if (dummy_2 == nullptr) {
2989 delete [] dummy_1;
2990 return nullptr;
2991 }
2992 int hstart = Tmax(GetFirstGoodInt(histo_num_plus)-GetT0Int(histo_num_plus),
2993 GetFirstGoodInt(histo_num_minus)-GetT0Int(histo_num_minus));
2994
2995 double *error_asymmetry_goodBins_array = new double[hsize];
2996
2997 if (!error_asymmetry_goodBins_array) return nullptr;
2998
2999 for (int i = 0; i < hsize; i++) {
3000 if (dummy_1[i+hstart] < 0.5 || dummy_2[i+hstart] < 0.5 )
3001 error_asymmetry_goodBins_array[i] = 1.0;
3002 else
3003 error_asymmetry_goodBins_array[i] =
3004 double(2.) * alpha_param * sqrt(dummy_1[i+hstart]*dummy_2[i+hstart]
3005 *(dummy_1[i+hstart]+dummy_2[i+hstart])) /
3006 pow(dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart],2.);
3007 }
3008
3009 delete [] dummy_1;
3010 delete [] dummy_2;
3011
3012 return error_asymmetry_goodBins_array;
3013 }
3014
3015
3016//*******************************
3017//Implementation GetErrorAsymmetryGoodBinsVector
3018//*******************************
3019
3041 std::vector<double> MuSR_td_PSI_bin::GetErrorAsymmetryGoodBinsVector(int histo_num_plus,
3042 int histo_num_minus, double alpha_param,
3043 int binning, int lower_bckgrd_plus,
3044 int higher_bckgrd_plus,
3045 int lower_bckgrd_minus, int higher_bckgrd_minus)
3046 {
3047 int hsize = int((Tmin(GetLastGoodInt(histo_num_plus)-GetFirstGoodInt(histo_num_plus),
3048 GetLastGoodInt(histo_num_minus)-GetFirstGoodInt(histo_num_minus))+1)/binning);
3049
3050 std::vector<double> error_asymmetry_goodBins_vector;
3051
3052 if (!fReadingOk) return error_asymmetry_goodBins_vector;
3053
3054 if ( histo_num_plus < 0 || histo_num_plus >= int(fNumberHisto) || binning <= 0 )
3055 return error_asymmetry_goodBins_vector;
3056
3057 if ( histo_num_minus < 0 || histo_num_minus >= int(fNumberHisto) )
3058 return error_asymmetry_goodBins_vector;
3059
3060 if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(fLengthHisto) || lower_bckgrd_plus > higher_bckgrd_plus )
3061 return error_asymmetry_goodBins_vector;
3062
3063 if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(fLengthHisto) || lower_bckgrd_minus > higher_bckgrd_minus )
3064 return error_asymmetry_goodBins_vector;
3065
3066 double *dummy_1 = GetHistoFromT0MinusBkgArray(histo_num_plus, lower_bckgrd_plus,
3067 higher_bckgrd_plus, binning);
3068 if (dummy_1 == nullptr) return error_asymmetry_goodBins_vector;
3069
3070 double *dummy_2 = GetHistoFromT0MinusBkgArray(histo_num_minus, lower_bckgrd_minus,
3071 higher_bckgrd_minus, binning);
3072 if (dummy_2 == nullptr) {
3073 delete [] dummy_1;
3074 return error_asymmetry_goodBins_vector;
3075 }
3076
3077 for (int i = 0; i < hsize; i++)
3078 error_asymmetry_goodBins_vector.push_back(0.);
3079
3080 int hstart = Tmax(GetFirstGoodInt(histo_num_plus)-GetT0Int(histo_num_plus),GetFirstGoodInt(histo_num_minus)-GetT0Int(histo_num_minus));
3081
3082 for (int i = 0; i < hsize; i++) {
3083 if (dummy_1[i+hstart] < 0.5 || dummy_2[i+hstart] < 0.5 )
3084 error_asymmetry_goodBins_vector[i] = 1.0;
3085 else
3086 error_asymmetry_goodBins_vector[i] = double(2.) * alpha_param
3087 * sqrt(dummy_1[i+hstart]*dummy_2[i+hstart]*(dummy_1[i+hstart]+dummy_2[i+hstart])) /
3088 pow(dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart],2.);
3089 }
3090
3091 delete [] dummy_1;
3092 delete [] dummy_2;
3093
3094 return error_asymmetry_goodBins_vector;
3095 }
3096
3097
3098//*******************************
3099//Implementation GetNumberScalerInt
3100//*******************************
3101
3106 {
3107 return int(fNumberScaler);
3108 }
3109
3110 //*******************************
3111 //Implementation PutNumberScalerInt
3112 //*******************************
3113
3124 {
3125 if ((val < 0) || (val >= MAXSCALER))
3126 return -1;
3127
3128 fNumberScaler = val;
3129
3130 return 0;
3131 }
3132
3133//*******************************
3134//Implementation GetScalersVector
3135//*******************************
3136
3140 std::vector<long> MuSR_td_PSI_bin::GetScalersVector()
3141 {
3142 std::vector<long> scalers_vect(fNumberScaler);
3143
3144 for ( int i = 0; i < fNumberScaler; i++ )
3145 scalers_vect[i] = long(fScalers[i]);
3146
3147 return scalers_vect;
3148 }
3149
3150 //*******************************
3151 //Implementation PutScalersVector
3152 //*******************************
3153
3163 int MuSR_td_PSI_bin::PutScalersVector(std::vector<int> scalerData)
3164 {
3165 if ((int)scalerData.size() > MAXSCALER)
3166 return -1;
3167
3168 for (unsigned int i=0; i<scalerData.size(); i++)
3169 fScalers[i] = scalerData[i];
3170
3171 return 0;
3172 }
3173
3174//*******************************
3175//Implementation GetMaxT0Int
3176//*******************************
3177
3182 {
3183 int max_t0 = 0;
3184
3185 for (int i = 0; i < int(fNumberHisto); i++) {
3186 if (int(fIntegerT0[i]) > max_t0)
3187 max_t0 = int(fIntegerT0[i]);
3188 }
3189 return max_t0;
3190 }
3191
3192
3193//*******************************
3194//Implementation GetMax2T0Int
3195//*******************************
3196
3202 int MuSR_td_PSI_bin::GetMax2T0Int(int k, int j)
3203 {
3204 if (( k < 0 || k >= int(fNumberHisto)) || ( j < 0 || j >= int(fNumberHisto)))
3205 return -1;
3206
3207 int max_t0 = int(fIntegerT0[j]);
3208 if (int(fIntegerT0[k]) >= max_t0)
3209 max_t0 = int(fIntegerT0[k]);
3210
3211 return max_t0;
3212 }
3213
3214//*******************************
3215//Implementation GetMin2T0Int
3216//*******************************
3217
3223 int MuSR_td_PSI_bin::GetMin2T0Int(int k, int j)
3224 {
3225 if (( k < 0 || k >= int(fNumberHisto)) || ( j < 0 || j >= int(fNumberHisto)))
3226 return -1;
3227
3228 int min_t0 = int(fIntegerT0[j]);
3229 if (int(fIntegerT0[k]) <= min_t0)
3230 min_t0 = int(fIntegerT0[k]);
3231
3232 return min_t0;
3233 }
3234
3235//*******************************
3236//Implementation GetMinT0Int
3237//*******************************
3238
3243 {
3244 int min_t0 = int(fLengthHisto);
3245
3246 for (int i = 0; i < int(fNumberHisto); i++) {
3247 if (int(fIntegerT0[i]) < min_t0)
3248 min_t0 = int(fIntegerT0[i]);
3249 }
3250
3251 return min_t0;
3252 }
3253
3254
3255//*******************************
3256//Implementation GetBinWidthPicoSec
3257//*******************************
3258
3263 {
3264 return fBinWidth*1.0e6;
3265 }
3266
3267 //*******************************
3268 //Implementation PutBinWidthPicoSec
3269 //*******************************
3270
3276 void MuSR_td_PSI_bin::PutBinWidthPicoSec(double binWidth)
3277 {
3278 fBinWidth = binWidth*1.0e-6;
3279 }
3280
3281//*******************************
3282//Implementation GetBinWidthNanoSec
3283//*******************************
3284
3289 {
3290 return fBinWidth*1.0e3;
3291 }
3292
3293 //*******************************
3294 //Implementation PutBinWidthNanoSec
3295 //*******************************
3296
3302 void MuSR_td_PSI_bin::PutBinWidthNanoSec(double binWidth)
3303 {
3304 fBinWidth = binWidth*1.0e-3;
3305 }
3306
3307//*******************************
3308//Implementation GetBinWidthMicroSec
3309//*******************************
3310
3315 {
3316 return fBinWidth;
3317 }
3318
3319 //*******************************
3320 //Implementation PutBinWidthMicroSec
3321 //*******************************
3322
3328 void MuSR_td_PSI_bin::PutBinWidthMicroSec(double binWidth)
3329 {
3330 fBinWidth = binWidth;
3331 }
3332
3333//*******************************
3334//Implementation GetEventsHistoLong
3335//*******************************
3336
3343 {
3344 if ( i < 0 || i >= fNumberHisto)
3345 return -1;
3346 else
3347 return long(fEventsPerHisto[i]);
3348 }
3349
3350//*******************************
3351//Implementation GetEventsHistoVector
3352//*******************************
3353
3357 std::vector<long> MuSR_td_PSI_bin::GetEventsHistoVector()
3358 {
3359 std::vector<long> eventsHisto(fNumberHisto);
3360
3361 for ( int i = 0; i < fNumberHisto; i++ )
3362 eventsHisto[i] = long(fEventsPerHisto[i]);
3363 return eventsHisto;
3364 }
3365
3366//*******************************
3367//Implementation GetT0Double
3368//*******************************
3369
3375 double MuSR_td_PSI_bin::GetT0Double(int i)
3376 {
3377 if ( i < 0 || i >= int(fNumberHisto))
3378 return -1.;
3379 else
3380 return double(fRealT0[i]);
3381 }
3382
3383
3384//*******************************
3385//Implementation GetDefaultBinning
3386//*******************************
3387
3393 {
3394 if (fDefaultBinning < 1)
3395 return 1;
3396 else
3397 return fDefaultBinning;
3398 }
3399
3400//*******************************
3401//Implementation GetT0Int
3402//*******************************
3403
3409 int MuSR_td_PSI_bin::GetT0Int(int i)
3410 {
3411 if ( i < 0 || i >= int(fNumberHisto))
3412 return -1;
3413 else
3414 return int(fIntegerT0[i]);
3415 }
3416
3417 //*******************************
3418 //Implementation PutT0Int
3419 //*******************************
3420
3431 int MuSR_td_PSI_bin::PutT0Int(int histoNo, int t0)
3432 {
3433 if ((histoNo < 0) || (histoNo >= MAXHISTO))
3434 return -1;
3435
3436 fIntegerT0[histoNo] = t0;
3437
3438 return 0;
3439 }
3440
3441//*******************************
3442//Implementation GetT0Vector
3443//*******************************
3444
3448 std::vector<int> MuSR_td_PSI_bin::GetT0Vector()
3449 {
3450 std::vector<int> t0(fNumberHisto);
3451
3452 for ( int i = 0; i < int(fNumberHisto); i++ )
3453 t0[i] = int(fIntegerT0[i]);
3454
3455 return t0;
3456 }
3457
3458 //*******************************
3459 //Implementation PutT0Vector
3460 //*******************************
3461
3469 int MuSR_td_PSI_bin::PutT0Vector(std::vector<int> &t0Data)
3470 {
3471 if (static_cast<int>(t0Data.size()) >= MAXHISTO)
3472 return -1;
3473
3474 for (unsigned int i=0; i<t0Data.size(); i++)
3475 fIntegerT0[i] = t0Data[i];
3476
3477 return 0;
3478 }
3479
3480//*******************************
3481//Implementation GetFirstGoodInt
3482//*******************************
3483
3490 {
3491 if ( i < 0 || i >= int(fNumberHisto))
3492 return -1;
3493 else
3494 return int(fFirstGood[i]);
3495 }
3496
3497 //*******************************
3498 //Implementation PutFirstGoodInt
3499 //*******************************
3500
3511 int MuSR_td_PSI_bin::PutFirstGoodInt(int i, int j)
3512 {
3513 if ((i < 0) || (i >= MAXHISTO))
3514 return -1;
3515
3516 fFirstGood[i] = j;
3517
3518 return 0;
3519 }
3520
3521//*******************************
3522//Implementation GetFirstGoodVector
3523//*******************************
3524
3528 std::vector<int> MuSR_td_PSI_bin::GetFirstGoodVector()
3529 {
3530 std::vector<int> firstGood(fNumberHisto);
3531
3532 for ( int i = 0; i < fNumberHisto; i++ )
3533 firstGood[i] = int(fFirstGood[i]);
3534
3535 return firstGood;
3536 }
3537
3538//*******************************
3539//Implementation GetLastGoodInt
3540//*******************************
3541
3548 {
3549 if ( i < 0 || i >= int(fNumberHisto))
3550 return -1;
3551 else
3552 return int(fLastGood[i]);
3553 }
3554
3555//*******************************
3556//Implementation GetLastGoodVector
3557//*******************************
3558
3562 std::vector<int> MuSR_td_PSI_bin::GetLastGoodVector()
3563 {
3564 std::vector<int> lastGood(fNumberHisto);
3565
3566 for ( int i = 0; i < fNumberHisto; i++ )
3567 lastGood[i] = int(fLastGood[i]);
3568
3569 return lastGood;
3570 }
3571
3572//*******************************
3573//Implementation GetMaxLastGoodInt
3574//*******************************
3575
3580 {
3581 int max_lastGood = 0;
3582
3583 for (int i = 0; i < int(fNumberHisto); i++) {
3584 if (int(fLastGood[i]) > max_lastGood)
3585 max_lastGood = int(fLastGood[i]);
3586 }
3587
3588 return max_lastGood;
3589 }
3590
3591//*******************************
3592//Implementation GetMax2LastGoodInt
3593//*******************************
3594
3600 int MuSR_td_PSI_bin::GetMax2LastGoodInt(int k, int j)
3601 {
3602 if (( k < 0 || k >= int(fNumberHisto)) || ( j < 0 || j >= int(fNumberHisto)))
3603 return -1;
3604 else {
3605 int max_lastGood = int(fLastGood[j]);
3606
3607 if (int(fLastGood[k]) > max_lastGood)
3608 max_lastGood = int(fLastGood[k]);
3609
3610 return max_lastGood;
3611 }
3612 }
3613
3614//*******************************
3615//Implementation GetMinLastGoodInt
3616//*******************************
3617
3622 {
3623 int min_lastGood = int(fLastGood[0]);
3624
3625 for (int i = 1; i < int(fNumberHisto); i++) {
3626 if (int(fLastGood[i]) < min_lastGood)
3627 min_lastGood = int(fLastGood[i]);
3628 }
3629
3630 return min_lastGood;
3631 }
3632
3633//*******************************
3634//Implementation GetMin2LastGoodInt
3635//*******************************
3636
3642 int MuSR_td_PSI_bin::GetMin2LastGoodInt(int k, int j)
3643 {
3644 if (( k < 0 || k >= int(fNumberHisto)) || ( j < 0 || j >= int(fNumberHisto)))
3645 return -1;
3646 else {
3647 int min_lastGood = int(fLastGood[j]);
3648
3649 if (int(fLastGood[k]) < min_lastGood)
3650 min_lastGood = int(fLastGood[k]);
3651
3652 return min_lastGood;
3653 }
3654 }
3655
3656//*******************************
3657//Implementation PutLastGoodInt
3658//*******************************
3659
3665 int MuSR_td_PSI_bin::PutLastGoodInt(int i, int j)
3666 {
3667 if ((i < 0) || (i >= fNumberHisto))
3668 return -1;
3669
3670 fLastGood[i] = j;
3671
3672 return 0;
3673 }
3674
3675//*******************************
3676//Implementation PutRunNumberInt
3677//*******************************
3678
3685 {
3686 if (i <= 0 )
3687 return -1;
3688
3689 fNumRun = i;
3690
3691 return 0;
3692 }
3693
3694
3695//*******************************
3696//Implementation GetSample()
3697//*******************************
3698
3702 std::string MuSR_td_PSI_bin::GetSample()
3703 {
3704 std::string strData;
3705
3706 strData = fSample;
3707
3708 return strData;
3709 }
3710
3711 //*******************************
3712 //Implementation PutSample()
3713 //*******************************
3714
3724 int MuSR_td_PSI_bin::PutSample(std::string sampleStr)
3725 {
3726 if (sampleStr.size() >= 11)
3727 return -1;
3728
3729 strcpy(fSample, sampleStr.c_str());
3730
3731 return 0;
3732 }
3733
3734//*******************************
3735//Implementation GetTemp()
3736//*******************************
3737
3741 std::string MuSR_td_PSI_bin::GetTemp()
3742 {
3743 std::string strData;
3744
3745 strData = fTemp;
3746
3747 return strData;
3748 }
3749
3750 //*******************************
3751 //Implementation PutTemp()
3752 //*******************************
3753
3763 int MuSR_td_PSI_bin::PutTemp(std::string tempStr)
3764 {
3765 if (tempStr.size() >= 11)
3766 return -1;
3767
3768 strcpy(fTemp, tempStr.c_str());
3769
3770 return 0;
3771 }
3772
3773//*******************************
3774//Implementation GetOrient()
3775//*******************************
3776
3780 std::string MuSR_td_PSI_bin::GetOrient()
3781 {
3782 std::string strData;
3783
3784 strData = fOrient;
3785
3786 return strData;
3787 }
3788
3789 //*******************************
3790 //Implementation PutOrient()
3791 //*******************************
3792
3802 int MuSR_td_PSI_bin::PutOrient(std::string orientStr)
3803 {
3804 if (orientStr.size() >= 11)
3805 return -1;
3806
3807 strcpy(fOrient, orientStr.c_str());
3808
3809 return 0;
3810 }
3811
3812//*******************************
3813//Implementation GetField()
3814//*******************************
3815
3819 std::string MuSR_td_PSI_bin::GetField()
3820 {
3821 std::string strData;
3822
3823 strData = fField;
3824
3825 return strData;
3826 }
3827
3828 //*******************************
3829 //Implementation PutField()
3830 //*******************************
3831
3841 int MuSR_td_PSI_bin::PutField(std::string fieldStr)
3842 {
3843 if (fieldStr.size() >= 11)
3844 return -1;
3845
3846 strcpy(fField, fieldStr.c_str());
3847
3848 return 0;
3849 }
3850
3851 //*******************************
3852 //Implementation GetSetup()
3853 //*******************************
3854
3858 std::string MuSR_td_PSI_bin::GetSetup()
3859 {
3860 std::string strData;
3861
3862 strData = fSetup;
3863
3864 return strData;
3865 }
3866
3867 //*******************************
3868 //Implementation PutSetup()
3869 //*******************************
3870
3880 int MuSR_td_PSI_bin::PutSetup(std::string setupStr)
3881 {
3882 if (setupStr.size() >= 11)
3883 return -1;
3884
3885 strcpy(fSetup, setupStr.c_str());
3886
3887 return 0;
3888 }
3889
3890//*******************************
3891//Implementation GetComment()
3892//*******************************
3893
3897 std::string MuSR_td_PSI_bin::GetComment()
3898 {
3899 std::string strData;
3900
3901 strData = fComment;
3902
3903 return strData;
3904 }
3905
3906 //*******************************
3907 //Implementation PutComment()
3908 //*******************************
3909
3918 int MuSR_td_PSI_bin::PutComment(std::string commentStr)
3919 {
3920 strncpy(fComment, commentStr.c_str(), 62);
3921 fComment[62] = '\0';
3922
3923 return 0;
3924 }
3925
3926//*******************************
3927//Implementation Get_nameHisto()
3928//*******************************
3929
3935 std::string MuSR_td_PSI_bin::GetNameHisto(int i)
3936 {
3937 std::string strData{""};
3938
3939 if ((i >= 0) && (i < fNumberHisto))
3940 strData = fLabelsHisto[i];
3941
3942 return strData;
3943 }
3944
3945 //*******************************
3946 //Implementation PutNameHisto()
3947 //*******************************
3948
3960 int MuSR_td_PSI_bin::PutNameHisto(std::string histoName, int i)
3961 {
3962 if ((i<0) || (i>=fNumberHisto))
3963 return -1;
3964
3965 if (static_cast<int>(histoName.length()) >= MAXLABELSIZE)
3966 return -2;
3967
3968 strcpy(fLabelsHisto[i], histoName.c_str());
3969
3970 return 0;
3971 }
3972
3973//*******************************
3974//Implementation GetHistoNamesVector()
3975//*******************************
3976
3980 std::vector<std::string> MuSR_td_PSI_bin::GetHistoNamesVector()
3981 {
3982 std::vector<std::string> str_Vector;
3983
3984 std::string strData;
3985 for (int i = 0; i < fNumberHisto; i++) {
3986 strData = fLabelsHisto[i];
3987 str_Vector.push_back(strData);
3988 }
3989
3990 return str_Vector;
3991 }
3992
3993 //*******************************
3994 //Implementation PutHistoNamesVector()
3995 //*******************************
3996
4007 int MuSR_td_PSI_bin::PutHistoNamesVector(std::vector<std::string> &histoNames)
4008 {
4009 if (static_cast<int>(histoNames.size()) > fNumberHisto)
4010 return -1;
4011
4012 for (unsigned int i=0; i<histoNames.size(); i++) {
4013 if (static_cast<int>(histoNames[i].length()) >= MAXLABELSIZE)
4014 return -2;
4015 else
4016 strcpy(fLabelsHisto[i], histoNames[i].c_str());
4017 }
4018
4019 return 0;
4020 }
4021
4022//*******************************
4023//Implementation GetScalersNamesVector()
4024//*******************************
4025
4029 std::vector<std::string> MuSR_td_PSI_bin::GetScalersNamesVector()
4030 {
4031 std::vector<std::string> str_Vector;
4032
4033 std::string strData;
4034 for (int i = 0; i < fNumberScaler; i++) {
4035 strData = fLabelsScalers[i];
4036 str_Vector.push_back(strData);
4037 }
4038
4039 return str_Vector;
4040 }
4041
4042 //*******************************
4043 //Implementation PutScalersNamesVector()
4044 //*******************************
4045
4055 int MuSR_td_PSI_bin::PutScalersNamesVector(std::vector<std::string> scalersName)
4056 {
4057 if (static_cast<int>(scalersName.size()) > MAXSCALER)
4058 return -1;
4059
4060 for (unsigned int i=0; i<scalersName.size(); i++) {
4061 strncpy(fLabelsScalers[i], scalersName[i].c_str(), MAXLABELSIZE-1);
4062 fLabelsScalers[i][MAXLABELSIZE-1] = '\0';
4063 }
4064
4065 return 0;
4066 }
4067
4068 //*******************************
4069 //Implementation PutNumberTemperatureInt
4070 //*******************************
4071
4082 {
4083 if ((noOfTemps < 0) || (noOfTemps > MAXTEMPER))
4084 return -1;
4085
4086 fNumberTemper = noOfTemps;
4087
4088 return 0;
4089 }
4090
4091//*******************************
4092//Implementation GetTemperaturesVector()
4093//*******************************
4094
4098 std::vector<double> MuSR_td_PSI_bin::GetTemperaturesVector()
4099 {
4100 std::vector<double> dbl_Temper;
4101
4102 for (int i = 0; i < fNumberTemper; i++) {
4103 dbl_Temper.push_back(double(fTemper[i]));
4104 }
4105
4106 return dbl_Temper;
4107 }
4108
4109 //*******************************
4110 //Implementation PutTemperaturesVector()
4111 //*******************************
4112
4122 int MuSR_td_PSI_bin::PutTemperaturesVector(std::vector<double> &tempVals)
4123 {
4124 if (static_cast<int>(tempVals.size()) > MAXTEMPER)
4125 return -1;
4126
4127 for (unsigned int i=0; i<tempVals.size(); i++)
4128 fTemper[i] = tempVals[i];
4129
4130 return 0;
4131 }
4132
4133//*******************************
4134//Implementation GetDevTemperaturesVector()
4135//*******************************
4136
4140 std::vector<double> MuSR_td_PSI_bin::GetDevTemperaturesVector()
4141 {
4142 std::vector<double> dbl_devTemper;
4143
4144 for (int i = 0; i < fNumberTemper; i++) {
4145 dbl_devTemper.push_back(double(fTempDeviation[i]));
4146 }
4147
4148 return dbl_devTemper;
4149 }
4150
4151 //*******************************
4152 //Implementation PutDevTemperaturesVector()
4153 //*******************************
4154
4164 int MuSR_td_PSI_bin::PutDevTemperaturesVector(std::vector<double> &devTempVals)
4165 {
4166 if (static_cast<int>(devTempVals.size()) > MAXTEMPER)
4167 return -1;
4168
4169 for (unsigned int i=0; i<devTempVals.size(); i++)
4170 fTempDeviation[i] = devTempVals[i];
4171
4172 return 0;
4173 }
4174
4175//*******************************
4176//Implementation GetTimeStartVector()
4177//*******************************
4178
4183 std::vector<std::string> MuSR_td_PSI_bin::GetTimeStartVector()
4184
4185 {
4186 std::vector<std::string> timeStart(2);
4187
4188 timeStart[0] = fDateStart;
4189 timeStart[1] = fTimeStart;
4190
4191 return timeStart;
4192 }
4193
4194 //*******************************
4195 //Implementation PutTimeStartVector()
4196 //*******************************
4197
4210 int MuSR_td_PSI_bin::PutTimeStartVector(std::vector<std::string> timeStart)
4211 {
4212 if (timeStart.size() != 2)
4213 return -1;
4214
4215 // date
4216 if (timeStart[0].length() > 9)
4217 return -2;
4218
4219 // time
4220 if (timeStart[1].length() > 8)
4221 return -3;
4222
4223 strcpy(fDateStart, timeStart[0].c_str());
4224 strcpy(fTimeStart, timeStart[1].c_str());
4225
4226 return 0;
4227 }
4228
4229//*******************************
4230//Implementation GetTimeStopVector()
4231//*******************************
4232
4237 std::vector<std::string> MuSR_td_PSI_bin::GetTimeStopVector()
4238 {
4239 std::vector<std::string> timeStop(2);
4240
4241 timeStop[0] = fDateStop;
4242 timeStop[1] = fTimeStop;
4243
4244 return timeStop;
4245 }
4246
4247 //*******************************
4248 //Implementation PutTimeStopVector()
4249 //*******************************
4250
4263 int MuSR_td_PSI_bin::PutTimeStopVector(std::vector<std::string> timeStop)
4264 {
4265 if (timeStop.size() != 2)
4266 return -1;
4267
4268 // date
4269 if (timeStop[0].length() > 9)
4270 return -2;
4271
4272 // time
4273 if (timeStop[1].length() > 8)
4274 return -3;
4275
4276 strcpy(fDateStop, timeStop[0].c_str());
4277 strcpy(fTimeStop, timeStop[1].c_str());
4278
4279 return 0;
4280 }
4281
4282//*******************************
4283//Implementation Clear()
4284//*******************************
4285
4290 {
4291 int i,j;
4292
4293 // NIY maybe flag when histo should not be released
4294
4295 // free private histograms
4296 fHisto.clear();
4297
4298 // free public vector
4299 fHistosVector.clear();
4300
4301 // init other member variables
4302 fFilename = "?";
4303 fReadingOk = false;
4304 fWritingOk = false;
4305 fConsistencyOk = false;
4306 fReadStatus = "";
4307 fWriteStatus = "";
4308 fConsistencyStatus = "";
4309
4310 strcpy(fFormatId,"??");
4311
4312 fNumRun = 0;
4313 //01234567890
4314 strcpy(fSample, " ");
4315 strcpy(fTemp, " ");
4316 strcpy(fField, " ");
4317 strcpy(fOrient, " ");
4318 strcpy(fSetup, " ");
4319 strcpy(fComment, " ");
4320 strcpy(fDateStart," ");
4321 strcpy(fTimeStart," ");
4322 strcpy(fDateStop, " ");
4323 strcpy(fTimeStop, " ");
4324
4325 fBinWidth = 0.;
4326 fNumberHisto = 0;
4327 fLengthHisto = 0;
4328 fTotalEvents = 0;
4329 fDefaultBinning = 1;
4330
4331 for (i=0; i < MAXHISTO; i++) {
4332 for (j=0; j < MAXLABELSIZE-1; j++)
4333 fLabelsHisto[i][j] = ' ';
4334 fLabelsHisto[i][MAXLABELSIZE-1] = '\0';
4335 fEventsPerHisto[i] = 0;
4336 fRealT0[i] = 0.f;
4337 fIntegerT0[i] = 0;
4338 fFirstGood[i] = 0;
4339 fLastGood[i] = 0;
4340 }
4341
4342 fNumberScaler = 0;
4343 for (i=0; i < MAXSCALER; i++) {
4344 for (j=0; j < MAXLABELSIZE-1; j++)
4345 fLabelsScalers[i][j] = ' ';
4346 fLabelsScalers[i][MAXLABELSIZE-1] = '\0';
4347
4348 fScalers[i] = 0;
4349 }
4350
4351 fNumberTemper = 0;
4352 for (i=0; i < MAXTEMPER; i++) {
4353 fTemper[i] = 0.f;
4354 fTempDeviation[i] = 0.f;
4355 }
4356
4357 return 0;
4358 }
4359
4360//*******************************
4361//Implementation Show()
4362//*******************************
4366 int MuSR_td_PSI_bin::Show() const
4367 {
4368 std::cout << "Filename is " << fFilename << std::endl;
4369 if (fReadingOk) {
4370 int i;
4371
4372 std::cout << "Format Identifier is " << fFormatId << std::endl;
4373
4374 std::cout << "Run number is " << fNumRun << std::endl;
4375 std::cout << "Sample is " << fSample << std::endl;
4376 std::cout << "Temperature is " << fTemp << std::endl;
4377 std::cout << "Field is " << fField << std::endl;
4378 std::cout << "Orientation is " << fOrient << std::endl;
4379 std::cout << "Comment is " << fComment << std::endl;
4380
4381 std::cout << "Start Date is " << fDateStart << std::endl;
4382 std::cout << "Start Time is " << fTimeStart << std::endl;
4383
4384 std::cout << "End Date is " << fDateStop << std::endl;
4385 std::cout << "End Time is " << fTimeStop << std::endl;
4386
4387 std::cout << "Bin width is " << fBinWidth << " [usec]" << std::endl;
4388 std::cout << "Number of histograms is " << fNumberHisto << std::endl;
4389 std::cout << "Histogram length is " << fLengthHisto << std::endl;
4390 std::cout << "Default binning is " << fDefaultBinning << std::endl;
4391 std::cout << "Total number of events is " << fTotalEvents << std::endl;
4392
4393 for (i=0; i < fNumberHisto; i++) {
4394 std::cout << "Histogram " << i << " Name is >" << fLabelsHisto[i]
4395 << "< Events per histogram is " << fEventsPerHisto[i] << std::endl;
4396 std::cout << " real t0 is " << fRealT0[i] << std::endl;
4397 std::cout << " t0 is " << fIntegerT0[i] << std::endl;
4398 std::cout << " first good bin is " << fFirstGood[i] << std::endl;
4399 std::cout << " last good bin is " << fLastGood[i] << std::endl;
4400 }
4401
4402 std::cout << "Number of scalers is " << fNumberScaler << std::endl;
4403 for (i=0; i < fNumberScaler; i++) {
4404 std::cout << "Scaler " << i << " Name is >" << fLabelsScalers[i]
4405 << "< Value is " << fScalers[i] << std::endl;
4406 }
4407
4408 std::cout << "Number of temperatures is " << fNumberTemper << std::endl;
4409 for (i=0; i < fNumberTemper; i++) {
4410 std::cout << "Temperature " << i << " is " << fTemper[i]
4411 << " Deviation is " << fTempDeviation[i] << std::endl;
4412 }
4413
4414 } else {
4415 std::cout << fReadStatus << std::endl;
4416 }
4417 return 0;
4418 }
4419
4420//*******************************
4421//Implementation Tmax
4422//*******************************
4424 int MuSR_td_PSI_bin::Tmax(int x, int y)
4425 {
4426 if (x >= y) {
4427 return x;
4428 }
4429 return y;
4430 }
4431
4432
4433//*******************************
4434//Implementation Tmin
4435//*******************************
4437 int MuSR_td_PSI_bin::Tmin(int x, int y)
4438 {
4439 if (x >= y) {
4440 return y;
4441 }
4442 return x;
4443 }
4444
4445/************************************************************************************
4446 * EOF MuSR_td_PSI_bin.cpp *
4447 ************************************************************************************/
4448
struct _pTATDC32SettingsRec * pTATDC32SettingsPtr
struct _pTAStatisticRec pTAStatisticRec
struct _pTATagRec * pTATagPtr
#define SUBTITLESTR
#define TIMESTR
struct _FeFileHeaderRec * FeFileHeaderPtr
struct _pTASettingsRec * pTASettingsPtr
struct _pTATDCStatisticRec pTATDCStatisticRec
#define DETECTLISTSTR
struct _pTASettingsRec pTASettingsRec
struct _pTATDCSettingsRec * pTATDCSettingsPtr
struct _pTATDCStatisticRec * pTATDCStatisticPtr
struct _pTAStatisticRec * pTAStatisticPtr
struct _pTAFileHeaderRec * pTAFileHeaderPtr
#define DATESTR
struct _pTATagRec pTATagRec
struct _FeFileHeaderRec FeFileHeaderRec
#define PTAMAXTAGS
#define PTATAGC_POSITRON
#define TDCMAXTAGS32
#define DATAFORMATSTR
#define TITLESTR
struct _pTATDC32SettingsRec pTATDC32SettingsRec
int Int16
float Float32
long int Int32
#define TEMPLISTSTR
struct _pTATDCSettingsRec pTATDCSettingsRec
#define TDCMAXTAGS16
struct _pTATDC32StatisticRec * pTATDC32StatisticPtr
struct _pTATDC32StatisticRec pTATDC32StatisticRec
#define MAXTAGSTR
struct _pTAFileHeaderRec pTAFileHeaderRec
const int MAXSCALER
const int MAXHISTO
const int MAXLABELSIZE
const int MAXREC
const int MAXTEMPER
return status
int Write(const char *fileName)
Method to write a PSI-bin or an MDU file.
double GetBinWidthPicoSec()
Method returning a double representing the bin-width in picoseconds.
std::string GetOrient()
Method returning a string containing the orientation specified in the title.
std::vector< double > GetHistoArray(int histo_num, int binning)
Method to obtain an array of type double containing the values of the histogram <histo_num> with binn...
int fFirstGood[MAXHISTO]
int GetT0Int(int i)
Method returning an integer representing the t0 point (from the "integer" t0 in the header) for a spe...
int fScalers[MAXSCALER]
int PutDevTemperaturesVector(std::vector< double > &devTemps)
Method setting a vector of doubles containing standard deviations of the monitored values (usually te...
int PutNameHisto(std::string histoName, int i)
Method setting a string containing the name of the histogram <i>
int PutT0Vector(std::vector< int > &t0Data)
Method setting a vector of integer containing the t0 values of the histograms specified in the header...
int GetMinT0Int()
Method to determine the minimum value of the t0 bins.
double * GetAsymmetryArray(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus, int offset=0, double y_offset=0.)
Method to obtain an array of double containing the values of the asymmetry between 2 histograms.
int GetLastGoodInt(int i)
Method returning an integer representing the last good bin specified in the header for a specified hi...
std::vector< double > GetHistoFromT0MinusBkgVector(int histo_num, int lower_bckgdr, int higher_bckgdr, int binning, int offset=0)
Method to obtain a vector of double containing the values of the histogram <histo_num> with binning <...
std::vector< int > GetT0Vector()
Method returning a vector of integer containing the t0 values of the histograms specified in the head...
std::string GetNameHisto(int i)
Method returning a string containing the name of the histogram <i>
int Tmin(int x, int y)
int PutNumberTemperatureInt(int noOfTemps)
Method setting an integer representing the number of temperatures.
std::vector< double > GetHistoGoodBinsVector(int histo_num, int binning)
Method to obtain a vector of double containing the values of the histogram <histo_num> with binning <...
int PutFirstGoodInt(int i, int j)
Method setting an integer representing the first good bin specified in the header for a specified his...
int PutTemp(std::string temp)
Method setting a string containing the fSample temperature.
bool WritingOK() const
Method to obtain if writing and processing of the data file was OK.
bool CheckDataConsistency(int tag=0)
Check if a given set of data is consistent with the PSI-BIN limitations. If false,...
int PutSample(std::string sample)
Method setting a string containing the fSample name.
std::vector< double > GetTemperaturesVector()
Method returning a vector of doubles containing monitored values (usually temperatures)
~MuSR_td_PSI_bin()
Simple Destructor clearing some pointers and variables.
std::vector< std::string > GetHistoNamesVector()
Method returning a vector of strings containing the names of the histograms.
std::vector< double > GetErrorAsymmetryVector(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus, int offset=0)
Method to obtain a vector of double containing the values of the error of the asymmetry between 2 his...
std::vector< int > GetLastGoodVector()
Method returning a vector of integer containing the last good bin values of the histograms specified ...
double * GetHistoGoodBinsMinusBkgArray(int histo_num, int lower_bckgrd, int higher_bckgrd, int binning)
Method to obtain an array of type double containing the values of the histogram <histo_num> with binn...
std::vector< int > GetHistoArrayInt(int histo_num)
Method to obtain an array of type integer containing the values of the histogram <histo_num>
int GetMax2T0Int(int k, int j)
Method to determine the maximum value of the last good bins of 2 histograms.
int PutT0Int(int histoNo, int t0)
Method setting an integer representing the t0 point (from the "integer" t0 in the header) for a speci...
char fLabelsScalers[MAXSCALER][MAXLABELSIZE]
int PutScalersNamesVector(std::vector< std::string > scalersName)
Method setting a vector of strings containing the names of the scalers.
double GetT0Double(int i)
Method returning a double representing the t0 point (from the "real" t0 in the header) for a specifie...
std::string ConsistencyStatus() const
Method to obtain error/success information on data consistency check.
int Clear()
Method to clear member variables before using instance for next read.
char fLabelsHisto[MAXHISTO][MAXLABELSIZE]
std::string GetField()
Method returning a string containing the field specified in the title.
std::vector< long > GetScalersVector()
Method providing a vector of long containing the values of the scalers.
double GetBinWidthMicroSec()
Method returning a double representing the bin-width in microseconds.
std::vector< std::vector< double > > fHistosVector
double * GetHistoFromT0Array(int histo_num, int binning, int offset=0)
Method to obtain an array of type double containing the values of the histogram <histo_num> with binn...
float fRealT0[MAXHISTO]
int PutField(std::string field)
Method setting a string containing the field.
int GetMin2T0Int(int k, int j)
Method to determine the minimum value of the last good bins of 2 histograms.
float fTemper[MAXTEMPER]
void PutBinWidthPicoSec(double binWidth)
Method setting a double representing the bin-width in picoseconds.
std::string Filename() const
Method to obtain the file name.
std::vector< double > GetAsymmetryVector(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus, int offset=0, double y_offset=0.)
Method to obtain a vector of double containing the values of the asymmetry between 2 histograms.
int PutComment(std::string comment)
Method setting a string containing the comment.
int ReadMdu(const char *fileName)
Method to read a MuSR MDU file.
int fIntegerT0[MAXHISTO]
int WriteBin(const char *fileName)
Method to write a PSI-bin file.
int GetMin2LastGoodInt(int k, int j)
Method to determine the minimum value of the last good bins of 2 histograms.
std::string GetTemp()
Method returning a string containing the temperature specified in the title.
int GetMinLastGoodInt()
Method providing the minimum value of the last good bins.
int Show() const
Method to show current values of member variables.
int ReadBin(const char *fileName)
Method to read a PSI-bin file.
std::string fReadStatus
std::vector< std::string > GetTimeStartVector()
Method returning a vector of strings containing 1) the date when the run was started and 2) the time ...
std::vector< double > GetHistoFromT0Vector(int histo_num, int binning, int offset=0)
Method to obtain a vector of double containing the values of the histogram <histo_num> with binning <...
int PutHistoArrayInt(std::vector< std::vector< int > > &histo, int tag=0)
Method to set the histograms which is a vector of vector of int's (histogram). There are two differen...
void PutBinWidthMicroSec(double binWidth)
Method setting a double representing the bin-width in microseconds.
std::vector< int > GetFirstGoodVector()
Method returning a vector of integer containing the first good bin values of the histograms specified...
double * GetHistoGoodBinsArray(int histo_num, int binning)
Method to obtain an array of type double containing the values of the histogram <histo_num> with binn...
std::string fWriteStatus
int PutLastGoodInt(int i, int j)
Method to modify the last good bin (value <j>) of the histogram <i>
int PutScalersVector(std::vector< int > scalerData)
Method set a vector of long containing the values of the scalers.
long GetEventsHistoLong(int i)
Method returning a long representing the number of events in a specified histograms.
std::vector< std::string > GetScalersNamesVector()
Method returning a vector of strings containing the names of the scalers.
std::vector< std::string > GetTimeStopVector()
Method returning a vector of strings containing 1) the date when the run was stopped and 2) the time ...
void PutBinWidthNanoSec(double binWidth)
Method setting a double representing the bin-width in nanoseconds.
std::vector< double > GetDevTemperaturesVector()
Method returning a vector of doubles containing standard deviations of the monitored values (usually ...
int GetMax2LastGoodInt(int k, int j)
Method to determine the maximum value of the "last good bins" of 2 histograms.
std::string WriteStatus() const
Method to obtain error/success information after writing.
std::string fConsistencyStatus
int PutTimeStartVector(std::vector< std::string > timeStart)
Method setting a vector of strings containing 1) the date when the run was started and 2) the time wh...
double * GetErrorAsymmetryGoodBinsArray(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus)
Method to obtain an array of double containing the values of the error of the asymmetry between 2 his...
std::vector< double > GetHistoVectorNo0(int histo_num, int binning)
Method to obtain a vector of double containing the values of the histogram <histo_num> with binning <...
double GetBinWidthNanoSec()
Method returning a double representing the bin-width in nanoseconds.
int PutHistoNamesVector(std::vector< std::string > &histoNames)
Method setting a vector containing the names of all the histograms.
int PutRunNumberInt(int i)
Method to modify the run number (value <i>)
std::string ReadStatus() const
Method to obtain error/success information after reading.
std::vector< double > GetErrorAsymmetryGoodBinsVector(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus)
Method to obtain a vector of double containing the values of the error of the asymmetry between 2 his...
std::vector< double > GetHistoGoodBinsMinusBkgVector(int histo_num, int lower_bckgrd, int higher_bckgrd, int binning)
Method to obtain a vector of double containing the values of the histogram <histo_num> with binning <...
int Read(const char *fileName)
Method to read a PSI-bin or an MDU file.
int GetMaxT0Int()
Method to determine the maximum value of the t0 bins.
double * GetAsymmetryGoodBinsArray(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus)
Method to obtain an array of double containing the values of the asymmetry between 2 histograms.
int PutSetup(std::string setup)
Method setting a string containing the setup.
int GetNumberScalerInt()
Method returning an integer representing the number of histograms.
int PutNumberScalerInt(int val)
Method seting the number of scalers present.
double GetHisto(int histo_num, int j)
Method to return the value of a single bin as double.
int GetMaxLastGoodInt()
Method returning an integer containing the maximum value of the "last good bins" of all histograms.
bool ReadingOK() const
Method to obtain if reading and processing of the data file was OK.
std::string GetSample()
Method returning a string containing the fSample name.
int GetFirstGoodInt(int i)
Method returning an integer representing the first good bin specified in the header for a specified h...
int fLastGood[MAXHISTO]
std::string fFilename
int GetDefaultBinning()
Method returning an integer representing the default binning.
std::vector< std::vector< int > > fHisto
float fTempDeviation[MAXTEMPER]
int GetHistoInt(int histo_num, int j)
Method to return the value of a single bin as integer.
double * GetErrorAsymmetryArray(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus, int offset=0)
Method to obtain an array of double containing the values of the error of the asymmetry between 2 his...
double * GetHistoFromT0MinusBkgArray(int histo_num, int lower_bckgdr, int higher_bckgdr, int binning, int offset=0)
Method to obtain an array of type double containing the values of the histogram <histo_num> with binn...
int Tmax(int x, int y)
std::vector< double > GetHistoVector(int histo_num, int binning)
Method to obtain a vector of double containing the values of the histogram <histo_num> with binning <...
std::string GetComment()
Method returning a string containing the comment specified in the title.
std::string GetSetup()
Method returning a string containing the setup.
int PutTemperaturesVector(std::vector< double > &temps)
Method setting a vector of doubles containing monitored values (usually temperatures)
std::vector< double > GetAsymmetryGoodBinsVector(int histo_num_plus, int histo_num_minus, double alpha_param, int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, int higher_bckgrd_minus)
Method to obtain a vector of double containing the values of the asymmetry between 2 histograms.
int PutOrient(std::string orientation)
Method setting a string containing the fSample orientation.
int WriteMdu(const char *fileName)
Method to write a MuSR MDU file.
int fEventsPerHisto[MAXHISTO]
std::vector< long > GetEventsHistoVector()
Method returning a vector of long containing the number of events in the histograms.
MuSR_td_PSI_bin()
Simple Constructor setting some pointers and variables.
int PutTimeStopVector(std::vector< std::string > timeStop)
Method setting a vector of strings containing 1) the date when the run was started and 2) the time wh...
#define NULL
Definition mud.h:167
char MeanTemp[TEMPLISTSTR]
char RunSubTitle[SUBTITLESTR+1]
char EndDate[DATESTR]
char StartTime[TIMESTR]
char DataFormat[DATAFORMATSTR]
char EndTime[TIMESTR]
char TempDev[TEMPLISTSTR]
char StartDate[DATESTR]
char RunTitle[TITLESTR+1]
char DetectorNumberList[DETECTLISTSTR]
FeFileHeaderRec Header
pTATagRec tag[PTAMAXTAGS]
Int32 HistogramScaler[PTAMAXTAGS]
Int32 TagScaler[PTAMAXTAGS]
pTATagRec tag[TDCMAXTAGS32]
Int32 HistogramScaler[TDCMAXTAGS32]
Int32 TagScaler[TDCMAXTAGS32]
pTATagRec tag[TDCMAXTAGS16]
Int32 HistogramScaler[TDCMAXTAGS16]
Int32 TagScaler[TDCMAXTAGS16]
char Label[MAXTAGSTR]