| 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 <mailto:jlopez@ifae.es> | 
|---|
| 19 | !   Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de> | 
|---|
| 20 | ! | 
|---|
| 21 | !   Copyright: MAGIC Software Development, 2000-2001 | 
|---|
| 22 | ! | 
|---|
| 23 | ! | 
|---|
| 24 | \* ======================================================================== */ | 
|---|
| 25 |  | 
|---|
| 26 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 27 | // | 
|---|
| 28 | //  MHMcEfficiencyEnergy | 
|---|
| 29 | // | 
|---|
| 30 | // This class holds the information (histogram and fit function) | 
|---|
| 31 | // about the energy threshold for a particular trigger condition. | 
|---|
| 32 | // | 
|---|
| 33 | //////////////////////////////////////////////////////////////////////////// | 
|---|
| 34 | #include "MHMcEfficiencyEnergy.h" | 
|---|
| 35 |  | 
|---|
| 36 | #include <math.h> | 
|---|
| 37 |  | 
|---|
| 38 | #include <TH2.h> | 
|---|
| 39 | #include <TCanvas.h> | 
|---|
| 40 |  | 
|---|
| 41 | #include "MH.h" | 
|---|
| 42 | #include "MBinning.h" | 
|---|
| 43 |  | 
|---|
| 44 | #include "MHMcEnergyImpact.h" | 
|---|
| 45 |  | 
|---|
| 46 | ClassImp(MHMcEfficiencyEnergy); | 
|---|
| 47 |  | 
|---|
| 48 | // ------------------------------------------------------------------------- | 
|---|
| 49 | // | 
|---|
| 50 | //  Default Constructor. | 
|---|
| 51 | // | 
|---|
| 52 | MHMcEfficiencyEnergy::MHMcEfficiencyEnergy(const char *name, const char *title) | 
|---|
| 53 | : fHist() | 
|---|
| 54 | { | 
|---|
| 55 | fName  = name  ? name  : "MHMcEfficiencyEnergy"; | 
|---|
| 56 | fTitle = title ? title : "Trigger Efficieny vs. Energy"; | 
|---|
| 57 |  | 
|---|
| 58 | //  - we initialize the histogram | 
|---|
| 59 | //  - we have to give diferent names for the diferent histograms because | 
|---|
| 60 | //    root don't allow us to have diferent histograms with the same name | 
|---|
| 61 |  | 
|---|
| 62 | fHist.SetName(fName); | 
|---|
| 63 | fHist.SetTitle(fTitle); | 
|---|
| 64 |  | 
|---|
| 65 | fHist.SetDirectory(NULL); | 
|---|
| 66 |  | 
|---|
| 67 | fHist.SetXTitle("E [GeV]"); | 
|---|
| 68 | fHist.SetYTitle("Trig. Eff. [1]"); | 
|---|
| 69 |  | 
|---|
| 70 | MBinning binse; | 
|---|
| 71 | binse.SetEdgesLog(10, 1, 100000); // [GeV] | 
|---|
| 72 | MH::SetBinning(&fHist, &binse); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | void MHMcEfficiencyEnergy::SetName(const char *name) | 
|---|
| 76 | { | 
|---|
| 77 | fName = name; | 
|---|
| 78 | fHist.SetName(name); | 
|---|
| 79 | fHist.SetDirectory(NULL); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | void MHMcEfficiencyEnergy::SetTitle(const char *title) | 
|---|
| 83 | { | 
|---|
| 84 | fTitle = title; | 
|---|
| 85 | fHist.SetTitle(title); | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | // ------------------------------------------------------------------------ | 
|---|
| 89 | // | 
|---|
| 90 | // Drawing function. It creates its own canvas. | 
|---|
| 91 | // | 
|---|
| 92 | void MHMcEfficiencyEnergy::Draw(Option_t *option) | 
|---|
| 93 | { | 
|---|
| 94 | TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this); | 
|---|
| 95 | pad->SetBorderMode(0); | 
|---|
| 96 |  | 
|---|
| 97 | AppendPad(""); | 
|---|
| 98 |  | 
|---|
| 99 | pad->SetLogx(); | 
|---|
| 100 |  | 
|---|
| 101 | fHist.Draw(option); | 
|---|
| 102 |  | 
|---|
| 103 | pad->Modified(); | 
|---|
| 104 | pad->Update(); | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | void MHMcEfficiencyEnergy::Calc(const TH2D &hsel, const TH2D &hall) | 
|---|
| 108 | { | 
|---|
| 109 | // | 
|---|
| 110 | // Set the binning from the two axis of one of the two histograms | 
|---|
| 111 | // | 
|---|
| 112 | MH::SetBinning(&fHist, ((TH2D&)hsel).GetXaxis()); | 
|---|
| 113 |  | 
|---|
| 114 | // | 
|---|
| 115 | // This is necessary to initialize thze error calculation correctly | 
|---|
| 116 | // (Nothing important: The histogram set the size of its internal | 
|---|
| 117 | // array storing the errors to the correct size) | 
|---|
| 118 | // | 
|---|
| 119 | fHist.Sumw2(); | 
|---|
| 120 |  | 
|---|
| 121 | // | 
|---|
| 122 | // Calculate the efficiency by dividing the number of selected | 
|---|
| 123 | // (eg. triggered) showers by the number of all showers per bin. | 
|---|
| 124 | // Both histograms are weighted with weight 1, and for the error | 
|---|
| 125 | // calculation we assume a binomial error calculation. | 
|---|
| 126 | // | 
|---|
| 127 | TH1D &tsel = *((TH2D&)hsel).ProjectionX(); | 
|---|
| 128 | TH1D &tall = *((TH2D&)hall).ProjectionX(); | 
|---|
| 129 | fHist.Divide(&tsel, &tall, 1, 1); | 
|---|
| 130 | delete &tsel; | 
|---|
| 131 | delete &tall; | 
|---|
| 132 |  | 
|---|
| 133 | SetReadyToSave(); | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | // -------------------------------------------------------------------------- | 
|---|
| 137 | // | 
|---|
| 138 | //  Calculate the EfficiencyEnergy and set the 'ReadyToSave' flag. | 
|---|
| 139 | //  The EfficiencyEnergy is calculated as the number of selected showers | 
|---|
| 140 | //  (eg. triggered ones) divided by the number of all showers. | 
|---|
| 141 | //  For error calculation Binomial errors are computed. | 
|---|
| 142 | // | 
|---|
| 143 | void MHMcEfficiencyEnergy::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall) | 
|---|
| 144 | { | 
|---|
| 145 | Calc(*mcsel.GetHist(), *mcall.GetHist()); | 
|---|
| 146 | } | 
|---|