-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff_rms.c
743 lines (620 loc) · 22.9 KB
/
diff_rms.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
/*
void f4(const TH1F *const pTH1F, float &resolution, float &resolutionError, bool fixDistributionCentre, bool print)
{
static const float FLOAT_MAX(std::numeric_limits<float>::max());
if (NULL == pTH1F)
return;
if (5 > pTH1F->GetEntries())
{
std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries) - skipped" << std::endl;
return;
}
// Calculate raw properties of distribution
float sum = 0., total = 0.;
double sx = 0., sxx = 0.;
const unsigned int nbins(pTH1F->GetNbinsX());
for (unsigned int i = 0; i <= nbins; ++i)
{
const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i)));
const float yi(pTH1F->GetBinContent(i));
sx += yi * binx;
sxx += yi * binx * binx;
total += yi;
}
const float rawMean(sx / total);
const float rawMeanSquared(sxx / total);
const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean));
sum = 0.;
unsigned int is0 = 0;
for (unsigned int i = 0; (i <= nbins) && (sum < total / 10.); ++i)
{
sum += pTH1F->GetBinContent(i);
is0 = i;
}
// Calculate truncated properties
float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX);
float high(0.f);
for (unsigned int istart = 0; istart <= is0; ++istart)
{
double sumn = 0.;
double csum = 0.;
double sumx = 0.;
double sumxx = 0.;
unsigned int iend = 0;
for (unsigned int i = istart; (i <= nbins) && (csum < 0.9 * total); ++i)
{
const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i)));
const float yi(pTH1F->GetBinContent(i));
csum += yi;
if (sumn < 0.9 * total)
{
sumn += yi;
sumx += yi * binx;
sumxx+= yi * binx * binx;
iend = i;
}
}
const float localMean(sumx / sumn);
const float localMeanSquared(sumxx / sumn);
const float localRms(std::sqrt(localMeanSquared - localMean * localMean));
if (localRms < rmsmin)
{
mean = localMean;
rms = localRms;
low = pTH1F->GetBinLowEdge(istart);
high = pTH1F->GetBinLowEdge(iend);
rmsmin = localRms;
if (fixDistributionCentre)
{
float centre = 91.2;
if (mean > 3500.)
{
//throw InvalidEnergyException();
cout << "QWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQW" << endl;
}
if ((mean > 2500.) && (mean < 3500.))
centre = 3000.;
if ((mean > 1500.) && (mean < 2500.))
centre = 2000.;
if ((mean > 700.) && (mean < 1500.))
centre = 1000.;
if ((mean > 400.) && (mean < 700.))
centre = 500.;
if ((mean > 250.) && (mean < 400.))
centre = 360.;
if ((mean > 150.) && (mean < 250.))
centre = 200.;
sigma = rms / mean * sqrt(centre);
sigmasigma = sigma / std::sqrt(total);
frac = rms / mean * std::sqrt(2) * 100.;
efrac = frac / std::sqrt(total);
}
else
{
sigma = rms;
sigmasigma = sigma / std::sqrt(total);
}
}
}
if (print)
{
std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin
<< " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma;
(fixDistributionCentre) ? (std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl) : (std::cout << std::endl);
}
resolution = frac;
resolutionError = efrac;
}
void f3(const TH1F *const m_histogram)
{
static const float FLOAT_MAX(std::numeric_limits<float>::max());
float m_fitRangeLow(std::numeric_limits<float>::max());
float m_fitRangeHigh(std::numeric_limits<float>::max());
float m_rMSFitRange(std::numeric_limits<float>::max());
float m_fitPercentage = 90.0;
if (NULL == m_histogram)
return;
if (5 > m_histogram->GetEntries())
{
std::cout << m_histogram->GetName() << " (" << m_histogram->GetEntries() << " entries) - skipped" << std::endl;
return;
}
// Calculate raw properties of distribution (ie rms100)
float sum = 0., total = 0.;
double sx = 0., sxx = 0.;
const unsigned int nbins(m_histogram->GetNbinsX());
for (unsigned int i = 0; i <= nbins; ++i)
{
const float binx(m_histogram->GetBinLowEdge(i) + (0.5 * m_histogram->GetBinWidth(i)));
const float yi(m_histogram->GetBinContent(i));
sx += yi * binx;
sxx += yi * binx * binx;
total += yi;
}
const float rawMean(sx / total);
const float rawMeanSquared(sxx / total);
const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean));
sum = 0.;
unsigned int is0 = 0;
// The /10 comes from the fact that for rms 90 the start point for the fit must occur in the first 10% of the data.
float frac = (1 - (m_fitPercentage/100.0));
for (unsigned int i = 0; (i <= nbins) && (sum < total * frac); ++i)
{
sum += m_histogram->GetBinContent(i);
is0 = i;
}
// Calculate truncated properties
float rmsmin(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX);
float high(0.f);
for (unsigned int istart = 0; istart <= is0; ++istart)
{
double sumn = 0.;
double csum = 0.;
double sumx = 0.;
double sumxx = 0.;
unsigned int iend = 0;
for (unsigned int i = istart; (i <= nbins) && (csum < (m_fitPercentage/100) * total); ++i)
{
const float binx(m_histogram->GetBinLowEdge(i) + (0.5 * m_histogram->GetBinWidth(i)));
const float yi(m_histogram->GetBinContent(i));
//csum is the sum of yi from istart and is used to stop the sum when this exceeds X% of data.
csum += yi;
if (sumn < (m_fitPercentage/100) * total)
{
// These variables define the final sums required once we have considered X% of data, anything else is
// continuously overwritten.
sumn += yi;
sumx += yi * binx;
sumxx+= yi * binx * binx;
iend = i;
}
}
const float localMean(sumx / sumn);
const float localMeanSquared(sumxx / sumn);
// Standard deviation formula
const float localRms(std::sqrt(localMeanSquared - localMean * localMean));
if (localRms < rmsmin)
{
mean = localMean;
if (istart==0)
{
low = 0;
m_fitRangeLow = 0;
}
else
{
low = m_histogram->GetBinLowEdge(istart);
m_fitRangeLow=m_histogram->GetBinLowEdge(istart) + (0.5 * m_histogram->GetBinWidth(istart));
}
high = m_histogram->GetBinLowEdge(iend);
rmsmin = localRms;
m_fitRangeHigh=m_histogram->GetBinLowEdge(iend) + (0.5 * m_histogram->GetBinWidth(iend));
}
}
m_rMSFitRange = rmsmin;
std::cout << m_histogram->GetName() << " (" << m_histogram->GetEntries() << " entries), rawrms: " << rawRms << ", rmsx: " << rmsmin
<< " (" << low << "-" << high << "), low_fit and high_fit " << " (" << m_fitRangeLow << "-" << m_fitRangeHigh
<< "), << mean: " << mean << std::endl;
}
void f2(const TH1F *const pTH1F, float &resolution, float &resolutionError, float &scale, float &scaleError, bool print)
{
static const float FLOAT_MAX(std::numeric_limits<float>::max());
if (NULL == pTH1F)
return;
if (5 > pTH1F->GetEntries())
{
std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries) - skipped" << std::endl;
return;
}
// Calculate raw properties of distribution
float sum = 0., total = 0.;
double sx = 0., sxx = 0.;
const unsigned int nbins(pTH1F->GetNbinsX());
for (unsigned int i = 0; i <= nbins; ++i)
{
const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i)));
const float yi(pTH1F->GetBinContent(i));
sx += yi * binx;
sxx += yi * binx * binx;
total += yi;
}
const float rawMean(sx / total);
const float rawMeanSquared(sxx / total);
const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean));
sum = 0.;
unsigned int is0 = 0;
for (unsigned int i = 0; (i <= nbins) && (sum < total / 10.); ++i)
{
sum += pTH1F->GetBinContent(i);
is0 = i;
}
// Calculate truncated properties
float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX);
float high(0.f);
for (unsigned int istart = 0; istart <= is0; ++istart)
{
double sumn = 0.;
double csum = 0.;
double sumx = 0.;
double sumxx = 0.;
unsigned int iend = 0;
for (unsigned int i = istart; (i <= nbins) && (csum < 0.9 * total); ++i)
{
const float binx(pTH1F->GetBinLowEdge(i) + (0.5 * pTH1F->GetBinWidth(i)));
const float yi(pTH1F->GetBinContent(i));
csum += yi;
if (sumn < 0.9 * total)
{
sumn += yi;
sumx += yi * binx;
sumxx+= yi * binx * binx;
iend = i;
}
}
const float localMean(sumx / sumn);
const float localMeanSquared(sumxx / sumn);
const float localRms(std::sqrt(localMeanSquared - localMean * localMean));
if (localRms < rmsmin)
{
mean = localMean;
rms = localRms;
low = pTH1F->GetBinLowEdge(istart);
high = pTH1F->GetBinLowEdge(iend);
rmsmin = localRms;
sigma = rms;
sigmasigma = sigma / std::sqrt(total);
frac = rms / mean * std::sqrt(2) * 100.;
efrac = frac / std::sqrt(total);
}
}
if (print)
{
std::cout << pTH1F->GetName() << " (" << pTH1F->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin
<< " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma;
std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl;
}
resolution = frac;
resolutionError = efrac;
scale = mean;
scaleError = sigma;
}
*/
void f2( TH1F* h, float &value, float &a, float &b, int &l, int &r )
{
static const float FLOAT_MAX(std::numeric_limits<float>::max());
cout << "Value2 === " << value << endl;
cout << "Value2 / 100.0 === " << value / 100.0 << endl;
if (NULL == h)
return;
if (5 > h->GetEntries())
{
std::cout << h->GetName() << " (" << h->GetEntries() << " entries) - skipped" << std::endl;
return;
}
// Calculate raw properties of distribution
float sum = 0., total = 0.;
double sx = 0., sxx = 0.;
const unsigned int nbins(h->GetNbinsX());
for (unsigned int i = 0; i <= nbins; ++i)
{
const float binx(h->GetBinLowEdge(i) + (0.5 * h->GetBinWidth(i)));
const float yi(h->GetBinContent(i));
sx += yi * binx;
sxx += yi * binx * binx;
total += yi;
}
const float rawMean(sx / total);
const float rawMeanSquared(sxx / total);
const float rawRms(std::sqrt(rawMeanSquared - rawMean * rawMean));
sum = 0.;
unsigned int is0 = 0;
for (unsigned int i = 0; (i <= nbins) && (sum < total * ( 1.0 - (value)/(100.0) ) ); ++i)
{
sum += h->GetBinContent(i);
is0 = i;
}
// Calculate truncated properties
float rmsmin(FLOAT_MAX), sigma(FLOAT_MAX), sigmasigma(FLOAT_MAX), frac(FLOAT_MAX), efrac(FLOAT_MAX), mean(FLOAT_MAX), low(FLOAT_MAX), rms(FLOAT_MAX);
float high(0.f);
for (unsigned int istart = 0; istart <= is0; ++istart)
{
double sumn = 0.;
double csum = 0.;
double sumx = 0.;
double sumxx = 0.;
unsigned int iend = 0;
for (unsigned int i = istart; (i <= nbins) && (csum < ( value / 100.0 ) * total); ++i)
{
const float binx(h->GetBinLowEdge(i) + (0.5 * h->GetBinWidth(i)));
const float yi(h->GetBinContent(i));
csum += yi;
if (sumn < ( value / 100.0 ) * total)
{
sumn += yi;
sumx += yi * binx;
sumxx+= yi * binx * binx;
iend = i;
}
}
const float localMean(sumx / sumn);
const float localMeanSquared(sumxx / sumn);
const float localRms(std::sqrt(localMeanSquared - localMean * localMean));
if (localRms < rmsmin)
{
mean = localMean;
rms = localRms;
low = h->GetBinLowEdge(istart);
l = istart;
high = h->GetBinLowEdge(iend);
r = iend;
rmsmin = localRms;
sigma = rms;
sigmasigma = sigma / std::sqrt(total);
frac = rms / mean * std::sqrt(2) * 100.;
efrac = frac / std::sqrt(total);
}
}
/* if (1)
{
std::cout << h->GetName() << " (" << h->GetEntries() << " entries), rawrms: " << rawRms << ", rms90: " << rmsmin
<< " (" << low << "-" << high << "), mean: " << mean << ", sigma: " << sigma << "+-" << sigmasigma;
std::cout << ", sE/E: " << frac << "+-" << efrac << std::endl;
}
resolution = frac;
resolutionError = efrac;
scale = mean;
scaleError = sigma; */
printf( "RMS of central %0.f%% = %f, RMS total = %f, Mean of central %.f%% = %f, Mean total = %f\n", value, rmsmin, h -> GetRMS(), value, mean, h -> GetMean() );
a = mean;
b = rmsmin;
}
void f( TH1F* h, float &value, float &a, float &b, int &l, int &r ) {
cout << "Value === " << value << endl;
cout << "Value / 100.0 === " << value / 100.0 << endl;
TAxis* axis = h -> GetXaxis();
Int_t nbins = axis -> GetNbins();
Int_t imean = axis -> FindBin( h -> GetMean() );
Double_t entries = ( value / 100.0 ) * ( h -> GetEntries() );
Double_t w = h -> GetBinContent( imean );
Double_t x = h -> GetBinCenter( imean );
Double_t sumw = w;
Double_t sumwx = w*x;
Double_t sumwx2 = w*x*x;
for ( Int_t i = 1; i < nbins; i++ ) {
if ( i > 0 ) {
w = h -> GetBinContent( imean - i );
x = h -> GetBinCenter( imean - i );
l = imean - i;
sumw += w;
sumwx += w*x;
sumwx2 += w*x*x;
}
if ( i <= nbins ) {
w = h -> GetBinContent( imean + i );
x = h -> GetBinCenter( imean + i );
r = imean + i;
sumw += w;
sumwx += w*x;
sumwx2 += w*x*x;
}
if ( sumw > entries ) break;
}
x = sumwx / sumw;
Double_t rms2 = TMath::Abs( ( sumwx2 / sumw ) - ( x * x ) );
Double_t result = TMath::Sqrt( rms2 );
printf( "RMS of central %0.f%% = %f, RMS total = %f, Mean of central %.f%% = %f, Mean total = %f\n", value, result, h -> GetRMS(), value, x, h -> GetMean() );
a = x;
b = result;
}
void fit_data( const int fenergy = 5, const int nBins = 1000 ) {
float FFF = 90.0;
char fname_out[ 200 ];
for ( int i = 0; i < 200; i++ ) fname_out[ i ] = 0;
char fname[ 200 ];
char ftempname[ 200 ];
char fname2[ 200 ];
for ( int i = 0; i < 200; i++ ) fname[ i ] = 0;
for ( int i = 0; i < 200; i++ ) ftempname[ i ] = 0;
for ( int i = 0; i < 200; i++ ) fname2[ i ] = 0;
sprintf( ftempname, "gun_k0L_%dgev_FTFP_BERT_5000evt_ILD_l5_v02steel", fenergy );
sprintf( fname, "%s.root", ftempname );
TH1F *hist;
TH1F *hist2;
TH1F *hist3;
TCanvas *c1 = new TCanvas("c1", "c1", 1);
/* TCanvas *c2 = new TCanvas("c2", "c2", 1);
TCanvas *c3 = new TCanvas("c3", "c3", 1);
TCanvas *c4 = new TCanvas("c4", "c4", 1);
TCanvas *c5 = new TCanvas("c5", "c5", 1);
TCanvas *c6 = new TCanvas("c6", "c6", 1);
TCanvas *c7 = new TCanvas("c7", "c7", 1);
TCanvas *c8 = new TCanvas("c8", "c8", 1);
*/
gStyle->SetOptStat(0);
const char *treeName = "tree";
const float binLo = 0.0;
const float binHi = fenergy + 30.0;
//
// Open data file
//
std::cout << "Trying to open data file... ";
TFile *file = new TFile(fname, "READ");
if (!file) { // if error occure then exit
std::cout << "[FAIL]" << std::endl;
return;
}
std::cout << "[OK]" << std::endl;
//
// Open file for output
//
sprintf( fname_out, "out_diff_rms_%0.f.txt", FFF );
FILE *out = fopen(fname_out, "a+");
printf("File open... ");
if (!out) {
printf("[FAIL]\n");
return;
} else printf("[OK]\n");
//
// Setup a TTree
//
std::cout << "Setup a tree... ";
TTree *tree = (TTree *)file->Get(treeName);
if (!tree) {
std::cout << "[FAIL]" << std::endl;
file->Close();
return;
}
std::cout << "[OK]" << std::endl;
unsigned int nEvents = tree->GetEntries();
//
// Setup a branch
//
Float_t energy = 0;
tree->SetBranchAddress("energy", &energy);
//
// Create a histogram and random generator
//
hist = new TH1F("hist", "hist", nBins, binLo, binHi);
for ( int i = 0; i <nEvents; i++ ) {
tree -> GetEntry(i);
if ( energy > 0 ) hist -> Fill( energy );
}
// cout << "Underflow hist === " << hist->GetBinContent( 0 ) << endl;
// cout << "Overflow hist === " << hist->GetBinContent( nBins + 1 ) << endl;
float mean = hist -> GetMean();
float meanerror = hist -> GetMeanError();
float rms = hist -> GetRMS();
float rmserror = hist -> GetRMSError();
cout << " 0:"
<< " Mean: " << mean
<< " Mean error: " << meanerror
<< " RMS: " << rms
<< " RMS error: " << rmserror
<< endl;
cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl;
cout << "f2:" << endl;
float f2value = FFF;
float f2mean = 0;
float f2rms = 0;
int f2left = 0;
int f2right = 0;
f2( hist, f2value, f2mean, f2rms, f2left, f2right );
cout << "f2mean = " << f2mean << " and f2rms = " << f2rms << endl;
cout << "f2left = " << f2left << " and f2right = " << f2right << endl;
cout << "Left value f2 = " << hist->GetBinCenter( f2left ) << " and right value f2 = " << hist->GetBinCenter( f2right ) << endl;
cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" << endl;
cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
cout << "f:" << endl;
float fvalue = FFF;
float fmean = 0;
float frms = 0;
int fleft = 0;
int fright = 0;
f( hist, fvalue, fmean, frms, fleft, fright );
cout << "fmean = " << fmean << " and frms = " << frms << endl;
cout << "fleft = " << fleft << " and fright = " << fright << endl;
cout << "Left value f = " << hist->GetBinCenter( fleft ) << " and right value f = " << hist->GetBinCenter( fright ) << endl;
cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
hist2 = (TH1F*)hist->Clone();
hist3 = (TH1F*)hist->Clone();
hist2->GetXaxis()->SetRange(fleft, fright);
hist3->GetXaxis()->SetRange(f2left, f2right);
cout << "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" << endl;
cout << "Underflow hist2 === " << hist2->GetBinContent( 0 ) << endl;
cout << "Overflow hist2 === " << hist2->GetBinContent( nBins + 1 ) << endl;
float mean_hist2 = hist2 -> GetMean();
float meanerror_hist2 = hist2 -> GetMeanError();
float rms_hist2 = hist2 -> GetRMS();
float rmserror_hist2 = hist2 -> GetRMSError();
cout << " 0:"
<< " Mean2: " << mean_hist2
<< " Mean2 error: " << meanerror_hist2
<< " RMS2: " << rms_hist2
<< " RMS2 error: " << rmserror_hist2
<< endl;
cout << "Underflow hist3 === " << hist3->GetBinContent( 0 ) << endl;
cout << "Overflow hist3 === " << hist3->GetBinContent( nBins + 1 ) << endl;
float mean_hist3 = hist3 -> GetMean();
float meanerror_hist3 = hist3 -> GetMeanError();
float rms_hist3 = hist3 -> GetRMS();
float rmserror_hist3 = hist3 -> GetRMSError();
cout << " 0:"
<< " Mean3: " << mean_hist3
<< " Mean3 error: " << meanerror_hist3
<< " RMS3: " << rms_hist3
<< " RMS3 error: " << rmserror_hist3
<< endl;
cout << "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" << endl;
/*
c2 -> cd();
hist -> SetMarkerStyle(20);
hist -> SetMarkerColor(kBlue);
hist -> SetLineColor(kBlue);
hist -> Draw("p e");
c3 -> cd();
hist90 -> SetMarkerStyle(20);
hist90 -> SetMarkerColor(kRed);
hist90 -> SetLineColor(kRed);
hist90 -> Draw("p e");
c4 -> cd();
hist95 -> SetMarkerStyle(20);
hist95 -> SetMarkerColor(kGreen);
hist95 -> SetLineColor(kGreen);
hist95 -> Draw("p e");
c5 -> cd();
hist2 -> SetMarkerStyle(20);
hist2 -> SetMarkerColor(kRed);
hist2 -> SetLineColor(kRed);
hist2 -> Draw("p e");
c6 -> cd();
hist3 -> SetMarkerStyle(20);
hist3 -> SetMarkerColor(kGreen);
hist3 -> SetLineColor(kGreen);
hist3 -> Draw("p e");
c7 -> cd();
hist->SetTitle("1");
hist->GetYaxis()->SetTitle("Number of events");
hist->GetXaxis()->SetTitle("Energy, GeV");
hist -> SetMarkerStyle(20);
hist -> SetMarkerColor(kBlue);
hist -> SetLineColor(kBlue);
hist -> Draw("p e");
hist2 -> SetMarkerStyle(20);
hist2 -> SetMarkerColor(kRed);
hist2 -> SetLineColor(kRed);
hist2 -> Draw("p e SAME");
// hist3 -> SetMarkerStyle(20);
// hist3 -> SetMarkerColor(kGreen);
// hist3 -> SetLineColor(kGreen);
// hist3 -> Draw("p e SAME");
c8 -> cd();
c8->Update();
hist->SetTitle("Full distribution and 95% of the distribution");
hist->GetYaxis()->SetTitle("Number of events");
hist->GetXaxis()->SetTitle("Energy, GeV");
hist -> SetMarkerStyle(20);
hist -> SetMarkerColor(kBlue);
hist -> SetLineColor(kBlue);
hist -> Draw("p e");
// hist2 -> SetMarkerStyle(20);
// hist2 -> SetMarkerColor(kRed);
// hist2 -> SetLineColor(kRed);
// hist2 -> Draw("p e SAME");
hist3 -> SetMarkerStyle(20);
hist3 -> SetMarkerColor(kGreen);
hist3 -> SetLineColor(kGreen);
hist3 -> Draw("p e SAME");
*/
fprintf( out, "%d %E %E %E %E %E %E %E %E\n", fenergy, mean_hist2, meanerror_hist2, rms_hist2, rmserror_hist2, mean_hist3, meanerror_hist3, rms_hist3, rmserror_hist3 );
delete hist;
fclose( out );
file -> Close();
}
void diff_rms( const int bins = 1000 ) {
// int mass[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90 };
int mass[] = { 5, 10, 15, 20, 25, 30, 40, 50, 60 };
int dim = 9; // 16
for (int i = 0; i < dim; i++ ) {
fit_data( mass[ i ], bins );
}
}