1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Javier Lopez 05/2001 (jlopez@ifae.es)
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | #include "MHMcEnergy.h"
|
---|
26 |
|
---|
27 | #include <iostream.h>
|
---|
28 |
|
---|
29 | #include <TH1.h>
|
---|
30 | #include <TF1.h>
|
---|
31 | #include <TCanvas.h>
|
---|
32 | #include <TPaveLabel.h>
|
---|
33 |
|
---|
34 | ClassImp(MHMcEnergy);
|
---|
35 |
|
---|
36 | MHMcEnergy::MHMcEnergy(const UInt_t idx, const char *name, const char *title)
|
---|
37 | {
|
---|
38 | //
|
---|
39 | // default constructor
|
---|
40 | //
|
---|
41 | char aux[15]="MHMcEnergy";
|
---|
42 |
|
---|
43 | if (idx>0)
|
---|
44 | sprintf(aux+10, ";%i", idx);
|
---|
45 | *fName = name ? name : aux;
|
---|
46 | *fTitle = title ? title : "Container for a MC energy histogram" ;
|
---|
47 |
|
---|
48 | // - we initialize the histogram and the gaus function
|
---|
49 | // - we have to give diferent names for the diferent histograms because
|
---|
50 | // root don't allow us to have diferent histograms with the same name
|
---|
51 |
|
---|
52 | strcpy(aux, "fLogEnergy");
|
---|
53 | if (idx>0)
|
---|
54 | sprintf(aux+10, ";%i", idx);
|
---|
55 | fLogEner = new TF1(aux, "gaus", 1., 3.);
|
---|
56 |
|
---|
57 | strcpy(aux, "hLogEnergy");
|
---|
58 | if (idx>0)
|
---|
59 | sprintf(aux+10, ";%i", idx);
|
---|
60 | hLogEner = new TH1F(aux, "", 100, 0.5, 4.5);
|
---|
61 | hLogEner->SetXTitle("log(E) [GeV]");
|
---|
62 | hLogEner->SetYTitle("dN/dE");
|
---|
63 | //hLogEner->SetBins(60);
|
---|
64 | }
|
---|
65 |
|
---|
66 | MHMcEnergy::~MHMcEnergy()
|
---|
67 | {
|
---|
68 | delete hLogEner;
|
---|
69 | delete fLogEner;
|
---|
70 | }
|
---|
71 |
|
---|
72 | void MHMcEnergy::Fill(Float_t log10E, Float_t w)
|
---|
73 | {
|
---|
74 | hLogEner->Fill(log10E, w);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void MHMcEnergy::Fit(Axis_t xxmin, Axis_t xxmax)
|
---|
78 | {
|
---|
79 | //
|
---|
80 | // 0: don't draw the function (it is drawn together with the histogram)
|
---|
81 | // +: add these function to the list of fits. Don't delete the last fit.
|
---|
82 | //
|
---|
83 | // FIXME: R means: use the range specified in the function (xxmin, xxmax are ignored!)
|
---|
84 | // Q means: quiet (why?)
|
---|
85 | //
|
---|
86 | //
|
---|
87 | hLogEner->Fit(fLogEner->GetName(), "Q0+", "", xxmin, xxmax);
|
---|
88 | }
|
---|
89 |
|
---|
90 | void MHMcEnergy::Draw(Option_t *option)
|
---|
91 | {
|
---|
92 | char text[50];
|
---|
93 | sprintf(text, "Energy Threshold = %4.1f +- %4.1f GeV",
|
---|
94 | GetThreshold(), GetThresholdErr());
|
---|
95 |
|
---|
96 | const Float_t min = hLogEner->GetMinimum();
|
---|
97 | const Float_t max = hLogEner->GetMaximum();
|
---|
98 | const Float_t sum = min+max;
|
---|
99 |
|
---|
100 | TCanvas *c=new TCanvas("Energy Distribution","Energy distribution for triggered events");
|
---|
101 |
|
---|
102 | hLogEner->Draw(option);
|
---|
103 |
|
---|
104 | TPaveLabel* label = new TPaveLabel(2.2, 0.75*sum, 4.4, 0.90*sum, text);
|
---|
105 | label->SetFillColor(10);
|
---|
106 | label->SetTextSize(0.3);
|
---|
107 | label->Draw();
|
---|
108 |
|
---|
109 | c->Modified();
|
---|
110 | c->Update();
|
---|
111 | }
|
---|
112 |
|
---|
113 | void MHMcEnergy::Print(Option_t*)
|
---|
114 | {
|
---|
115 | cout << "Threshold: " << GetThreshold() << " +- " << GetThresholdErr() << endl;
|
---|
116 | }
|
---|
117 |
|
---|
118 | Float_t MHMcEnergy::GetThreshold() const
|
---|
119 | {
|
---|
120 | const Float_t p1 = fLogEner->GetParameter(1);
|
---|
121 |
|
---|
122 | return pow(10, p1);
|
---|
123 | }
|
---|
124 |
|
---|
125 | Float_t MHMcEnergy::GetThresholdErr() const
|
---|
126 | {
|
---|
127 | const Float_t lg10 = log(10);
|
---|
128 | const Float_t p1 = fLogEner->GetParameter(1);
|
---|
129 | const Float_t p1err = fLogEner->GetParError(1);
|
---|
130 |
|
---|
131 | return pow(10, p1) * p1err * lg10;
|
---|
132 | }
|
---|
133 |
|
---|
134 | Float_t MHMcEnergy::GetGaussPeak() const
|
---|
135 | {
|
---|
136 | return fLogEner->GetParameter(1);
|
---|
137 | }
|
---|
138 |
|
---|
139 | Float_t MHMcEnergy::GetGaussSigma() const
|
---|
140 | {
|
---|
141 | return fLogEner->GetParameter(2);
|
---|
142 | }
|
---|
143 |
|
---|