| 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): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 19 | ! Author(s): Harald Kornmayer 1/2001
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | #include "MHMcCollectionArea.h"
|
|---|
| 27 |
|
|---|
| 28 | #include <TH2.h>
|
|---|
| 29 | #include <TCanvas.h>
|
|---|
| 30 |
|
|---|
| 31 | #include "MH.h"
|
|---|
| 32 |
|
|---|
| 33 | ClassImp(MHMcCollectionArea);
|
|---|
| 34 |
|
|---|
| 35 | // --------------------------------------------------------------------------
|
|---|
| 36 | //
|
|---|
| 37 | // Creates the three necessary histograms:
|
|---|
| 38 | // - selected showers (input)
|
|---|
| 39 | // - all showers (input)
|
|---|
| 40 | // - collection area (result)
|
|---|
| 41 | //
|
|---|
| 42 | MHMcCollectionArea::MHMcCollectionArea(const char *name, const char *title)
|
|---|
| 43 | {
|
|---|
| 44 | // initialize the histogram for the distribution r vs E
|
|---|
| 45 | //
|
|---|
| 46 | // we set the energy range from 1 Gev to 10000 GeV (in log 5 orders
|
|---|
| 47 | // of magnitude) and for each order we take 10 subdivision --> 50 xbins
|
|---|
| 48 | //
|
|---|
| 49 | // we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | fName = name ? name : "MHMcCollectionArea";
|
|---|
| 53 | fTitle = title ? title : "Data to Calculate Collection Area";
|
|---|
| 54 |
|
|---|
| 55 | const Int_t nbins = 50;
|
|---|
| 56 | const Float_t maxx = 5;
|
|---|
| 57 | const Float_t maxy = 500;
|
|---|
| 58 |
|
|---|
| 59 | Float_t *binsx = new Float_t[nbins+1];
|
|---|
| 60 | for (int i=0; i<nbins+1; i++)
|
|---|
| 61 | binsx[i] = pow(10, maxx*i/nbins);
|
|---|
| 62 |
|
|---|
| 63 | Float_t *binsy = new Float_t[nbins+1];
|
|---|
| 64 | for (int i=0; i<nbins+1; i++)
|
|---|
| 65 | binsy[i] = maxy*i/nbins;
|
|---|
| 66 |
|
|---|
| 67 | fHistAll = new TH2D("AllEvents", "All showers - Radius vs Energy distribution",
|
|---|
| 68 | nbins, binsx, nbins, binsy);
|
|---|
| 69 | fHistSel = new TH2D("SelectedEvents", "Selected showers - Radius vs Energy distribution",
|
|---|
| 70 | nbins, binsx, nbins, binsy);
|
|---|
| 71 | fHistCol = new TH1D("CollectionArea", "Collection Area vs. Energy",
|
|---|
| 72 | nbins, binsx);
|
|---|
| 73 |
|
|---|
| 74 | delete binsx;
|
|---|
| 75 | delete binsy;
|
|---|
| 76 |
|
|---|
| 77 | fHistAll->SetDirectory(NULL);
|
|---|
| 78 | fHistSel->SetDirectory(NULL);
|
|---|
| 79 | fHistCol->SetDirectory(NULL);
|
|---|
| 80 |
|
|---|
| 81 | fHistAll->SetXTitle("E [GeV]");
|
|---|
| 82 | fHistAll->SetYTitle("r [m]");
|
|---|
| 83 | fHistAll->SetZTitle("N");
|
|---|
| 84 |
|
|---|
| 85 | fHistSel->SetXTitle("E [GeV]");
|
|---|
| 86 | fHistSel->SetYTitle("r [m]");
|
|---|
| 87 | fHistSel->SetYTitle("N");
|
|---|
| 88 |
|
|---|
| 89 | fHistCol->SetXTitle("E [GeV]");
|
|---|
| 90 | fHistCol->SetYTitle("A [m^{2}]");
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | // --------------------------------------------------------------------------
|
|---|
| 94 | //
|
|---|
| 95 | // Delete the three histograms
|
|---|
| 96 | //
|
|---|
| 97 | MHMcCollectionArea::~MHMcCollectionArea()
|
|---|
| 98 | {
|
|---|
| 99 | delete fHistAll;
|
|---|
| 100 | delete fHistSel;
|
|---|
| 101 | delete fHistCol;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | // --------------------------------------------------------------------------
|
|---|
| 105 | //
|
|---|
| 106 | // Fill data into the histogram which contains all showers
|
|---|
| 107 | //
|
|---|
| 108 | void MHMcCollectionArea::FillAll(Float_t energy, Float_t radius)
|
|---|
| 109 | {
|
|---|
| 110 | fHistAll->Fill(energy, radius);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | // --------------------------------------------------------------------------
|
|---|
| 114 | //
|
|---|
| 115 | // Fill data into the histogram which contains the selected showers
|
|---|
| 116 | //
|
|---|
| 117 | void MHMcCollectionArea::FillSel(Float_t energy, Float_t radius)
|
|---|
| 118 | {
|
|---|
| 119 | fHistSel->Fill(energy, radius);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | // --------------------------------------------------------------------------
|
|---|
| 123 | //
|
|---|
| 124 | // Draw the histogram with all showers
|
|---|
| 125 | //
|
|---|
| 126 | void MHMcCollectionArea::DrawAll(Option_t* option)
|
|---|
| 127 | {
|
|---|
| 128 | if (!gPad)
|
|---|
| 129 | MH::MakeDefCanvas(fHistAll);
|
|---|
| 130 |
|
|---|
| 131 | fHistAll->Draw(option);
|
|---|
| 132 |
|
|---|
| 133 | gPad->SetLogx();
|
|---|
| 134 |
|
|---|
| 135 | gPad->Modified();
|
|---|
| 136 | gPad->Update();
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | // --------------------------------------------------------------------------
|
|---|
| 140 | //
|
|---|
| 141 | // Draw the histogram with the selected showers only.
|
|---|
| 142 | //
|
|---|
| 143 | void MHMcCollectionArea::DrawSel(Option_t* option)
|
|---|
| 144 | {
|
|---|
| 145 | if (!gPad)
|
|---|
| 146 | MH::MakeDefCanvas(fHistSel);
|
|---|
| 147 |
|
|---|
| 148 | fHistSel->Draw(option);
|
|---|
| 149 |
|
|---|
| 150 | gPad->SetLogx();
|
|---|
| 151 |
|
|---|
| 152 | gPad->Modified();
|
|---|
| 153 | gPad->Update();
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | // --------------------------------------------------------------------------
|
|---|
| 157 | //
|
|---|
| 158 | // Creates a new canvas and draws the histogram into it.
|
|---|
| 159 | // Be careful: The histogram belongs to this object and won't get deleted
|
|---|
| 160 | // together with the canvas.
|
|---|
| 161 | //
|
|---|
| 162 | TObject *MHMcCollectionArea::DrawClone(Option_t* option) const
|
|---|
| 163 | {
|
|---|
| 164 | TCanvas *c = MH::MakeDefCanvas(fHistCol);
|
|---|
| 165 |
|
|---|
| 166 | //
|
|---|
| 167 | // This is necessary to get the expected bahviour of DrawClone
|
|---|
| 168 | //
|
|---|
| 169 | gROOT->SetSelectedPad(NULL);
|
|---|
| 170 |
|
|---|
| 171 | fHistCol->DrawCopy(option);
|
|---|
| 172 |
|
|---|
| 173 | gPad->SetLogx();
|
|---|
| 174 |
|
|---|
| 175 | c->Modified();
|
|---|
| 176 | c->Update();
|
|---|
| 177 |
|
|---|
| 178 | return c;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | void MHMcCollectionArea::Draw(Option_t* option)
|
|---|
| 182 | {
|
|---|
| 183 | if (!gPad)
|
|---|
| 184 | MH::MakeDefCanvas(fHistCol);
|
|---|
| 185 |
|
|---|
| 186 | fHistCol->Draw(option);
|
|---|
| 187 |
|
|---|
| 188 | gPad->SetLogx();
|
|---|
| 189 |
|
|---|
| 190 | gPad->Modified();
|
|---|
| 191 | gPad->Update();
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // --------------------------------------------------------------------------
|
|---|
| 195 | //
|
|---|
| 196 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
|---|
| 197 | // flag
|
|---|
| 198 | //
|
|---|
| 199 | void MHMcCollectionArea::CalcEfficiency()
|
|---|
| 200 | {
|
|---|
| 201 | // Description!
|
|---|
| 202 |
|
|---|
| 203 | //
|
|---|
| 204 | // first of all calculate the efficency
|
|---|
| 205 | // do it here by hand to get the right error of efficency
|
|---|
| 206 | //
|
|---|
| 207 | const Int_t nbinx = fHistSel->GetXaxis()->GetNbins();
|
|---|
| 208 | const Int_t nbiny = fHistSel->GetYaxis()->GetNbins();
|
|---|
| 209 |
|
|---|
| 210 | for (Int_t ix=1; ix<=nbinx; ix++)
|
|---|
| 211 | {
|
|---|
| 212 | for (Int_t iy=1; iy<=nbiny; iy++)
|
|---|
| 213 | {
|
|---|
| 214 | const Float_t Na = fHistAll->GetCellContent(ix, iy);
|
|---|
| 215 |
|
|---|
| 216 | if (Na <= 0)
|
|---|
| 217 | continue;
|
|---|
| 218 |
|
|---|
| 219 | const Float_t Ns = fHistSel->GetCellContent(ix, iy);
|
|---|
| 220 |
|
|---|
| 221 | const Double_t eff = Ns/Na;
|
|---|
| 222 | const Double_t err = sqrt((1.-eff)*Ns)/Na;
|
|---|
| 223 |
|
|---|
| 224 | // old calculation from Harald:
|
|---|
| 225 | // const Double_t eff = Ns/Na;
|
|---|
| 226 | // const Double_t err = sqrt(Na + Na*Ns - Ns*Ns - Ns) / (Na*Na);
|
|---|
| 227 |
|
|---|
| 228 | fHistSel->SetCellContent(ix, iy, eff);
|
|---|
| 229 | fHistSel->SetCellError(ix, iy, err);
|
|---|
| 230 | }
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | //
|
|---|
| 234 | // now calculate the Collection area for different
|
|---|
| 235 | // energies
|
|---|
| 236 | //
|
|---|
| 237 | for (Int_t ix=1; ix<=nbinx; ix++)
|
|---|
| 238 | {
|
|---|
| 239 | Double_t errA = 0;
|
|---|
| 240 | Double_t colA = 0;
|
|---|
| 241 |
|
|---|
| 242 | for (Int_t iy=1; iy<=nbiny; iy++)
|
|---|
| 243 | {
|
|---|
| 244 | TAxis *yaxis = fHistSel->GetYaxis();
|
|---|
| 245 |
|
|---|
| 246 | const Double_t r1 = yaxis->GetBinLowEdge(iy);
|
|---|
| 247 | const Double_t r2 = yaxis->GetBinLowEdge(iy+1);
|
|---|
| 248 |
|
|---|
| 249 | const Double_t A = TMath::Pi() * (r2*r2 - r1*r1);
|
|---|
| 250 |
|
|---|
| 251 | const Double_t eff = fHistSel->GetCellContent(ix, iy);
|
|---|
| 252 | const Double_t err = fHistSel->GetCellError(ix, iy);
|
|---|
| 253 |
|
|---|
| 254 | colA += eff*A;
|
|---|
| 255 | errA += A*A * err*err;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | fHistCol->SetBinContent(ix, colA);
|
|---|
| 259 | fHistCol->SetBinError(ix, sqrt(errA));
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | SetReadyToSave();
|
|---|
| 263 | }
|
|---|