| 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/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MHCurrents
|
|---|
| 28 | //
|
|---|
| 29 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 30 | #include "MHCurrents.h"
|
|---|
| 31 |
|
|---|
| 32 | #include <TCanvas.h>
|
|---|
| 33 |
|
|---|
| 34 | #include "MLog.h"
|
|---|
| 35 | #include "MLogManip.h"
|
|---|
| 36 |
|
|---|
| 37 | #include "MParList.h"
|
|---|
| 38 | #include "MBinning.h"
|
|---|
| 39 | #include "MCurrents.h"
|
|---|
| 40 | #include "MCamDisplay.h"
|
|---|
| 41 |
|
|---|
| 42 | #include "MGeomCam.h"
|
|---|
| 43 | #include "MGeomPix.h"
|
|---|
| 44 |
|
|---|
| 45 | ClassImp(MHCurrents);
|
|---|
| 46 |
|
|---|
| 47 | using namespace std;
|
|---|
| 48 |
|
|---|
| 49 | // --------------------------------------------------------------------------
|
|---|
| 50 | //
|
|---|
| 51 | // Reset all pixels to 0 and reset fEntries to 0.
|
|---|
| 52 | //
|
|---|
| 53 | void MHCurrents::Clear(const Option_t *)
|
|---|
| 54 | {
|
|---|
| 55 | // FIXME: Implement a clear function with setmem
|
|---|
| 56 | for (int i=0; i<577; i++)
|
|---|
| 57 | {
|
|---|
| 58 | fSum[i] = 0;
|
|---|
| 59 | fRms[i] = 0;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | fEntries = 0;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | // --------------------------------------------------------------------------
|
|---|
| 66 | //
|
|---|
| 67 | // Initialize the name and title of the task.
|
|---|
| 68 | // Resets the sum histogram
|
|---|
| 69 | //
|
|---|
| 70 | MHCurrents::MHCurrents(const char *name, const char *title)
|
|---|
| 71 | : fSum(577), fRms(577), fCam(NULL), fEvt(NULL), fDispl(NULL)
|
|---|
| 72 | {
|
|---|
| 73 | //
|
|---|
| 74 | // set the name and title of this object
|
|---|
| 75 | //
|
|---|
| 76 | fName = name ? name : "MHCurrents";
|
|---|
| 77 | fTitle = title ? title : "Average of MCurrents";
|
|---|
| 78 |
|
|---|
| 79 | Clear();
|
|---|
| 80 |
|
|---|
| 81 | fHist.SetName("currents;avg");
|
|---|
| 82 | fHist.SetTitle("Avg.Currents [nA]");
|
|---|
| 83 | fHist.SetXTitle("Pixel Index");
|
|---|
| 84 | fHist.SetYTitle("A [nA]");
|
|---|
| 85 | fHist.SetDirectory(NULL);
|
|---|
| 86 | fHist.SetLineColor(kGreen);
|
|---|
| 87 | fHist.SetMarkerStyle(kFullDotMedium);
|
|---|
| 88 | fHist.SetMarkerSize(0.3);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // --------------------------------------------------------------------------
|
|---|
| 92 | //
|
|---|
| 93 | // Delete the corresponding camera display if available
|
|---|
| 94 | //
|
|---|
| 95 | MHCurrents::~MHCurrents()
|
|---|
| 96 | {
|
|---|
| 97 | if (fDispl)
|
|---|
| 98 | delete fDispl;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | // --------------------------------------------------------------------------
|
|---|
| 102 | //
|
|---|
| 103 | // Get the event (MCerPhotEvt) the histogram might be filled with. If
|
|---|
| 104 | // it is not given, it is assumed, that it is filled with the argument
|
|---|
| 105 | // of the Fill function.
|
|---|
| 106 | // Looks for the camera geometry MGeomCam and resets the sum histogram.
|
|---|
| 107 | //
|
|---|
| 108 | Bool_t MHCurrents::SetupFill(const MParList *plist)
|
|---|
| 109 | {
|
|---|
| 110 | fEvt = (MCurrents*)plist->FindObject("MCurrents");
|
|---|
| 111 | if (!fEvt)
|
|---|
| 112 | *fLog << warn << GetDescriptor() << ": No MCerPhotEvt available..." << endl;
|
|---|
| 113 |
|
|---|
| 114 | fCam = (MGeomCam*)plist->FindObject("MGeomCam");
|
|---|
| 115 | if (!fCam)
|
|---|
| 116 | *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
|
|---|
| 117 |
|
|---|
| 118 | Clear();
|
|---|
| 119 |
|
|---|
| 120 | MBinning bins;
|
|---|
| 121 | bins.SetEdges(577, -0.5, 576.5);
|
|---|
| 122 | bins.Apply(fHist);
|
|---|
| 123 |
|
|---|
| 124 | return kTRUE;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | // --------------------------------------------------------------------------
|
|---|
| 128 | //
|
|---|
| 129 | // Fill the histograms with data from a MCerPhotEvt-Container.
|
|---|
| 130 | //
|
|---|
| 131 | Bool_t MHCurrents::Fill(const MParContainer *par, const Stat_t w)
|
|---|
| 132 | {
|
|---|
| 133 | const MCurrents *evt = par ? (MCurrents*)par : fEvt;
|
|---|
| 134 | if (!evt)
|
|---|
| 135 | {
|
|---|
| 136 | *fLog << err << dbginf << "No MCurrents found..." << endl;
|
|---|
| 137 | return kFALSE;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | for (UInt_t idx=0; idx<577; idx++)
|
|---|
| 141 | {
|
|---|
| 142 | Float_t val;
|
|---|
| 143 | if (!evt->GetPixelContent(val, idx))
|
|---|
| 144 | continue;
|
|---|
| 145 |
|
|---|
| 146 | fSum[idx] += val;
|
|---|
| 147 | fRms[idx] += val*val;
|
|---|
| 148 |
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | fEntries++;
|
|---|
| 152 |
|
|---|
| 153 | return kTRUE;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | // --------------------------------------------------------------------------
|
|---|
| 157 | //
|
|---|
| 158 | // Scale the sum container with the number of entries
|
|---|
| 159 | //
|
|---|
| 160 | Bool_t MHCurrents::Finalize()
|
|---|
| 161 | {
|
|---|
| 162 | if (fEntries<2)
|
|---|
| 163 | {
|
|---|
| 164 | *fLog << warn << "WARNING - " << GetDescriptor() << " doesn't contain enough entries." << endl;
|
|---|
| 165 | return kTRUE;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | for (UInt_t i=0; i<577; i++)
|
|---|
| 169 | {
|
|---|
| 170 | // calc sdev^2 for pixel index i
|
|---|
| 171 | // var^2 = (sum[xi^2] - sum[xi]^2/n) / (n-1);
|
|---|
| 172 | fRms[i] -= fSum[i]*fSum[i]/fEntries;
|
|---|
| 173 | fRms[i] /= fEntries-1;
|
|---|
| 174 |
|
|---|
| 175 | if (fRms[i]<0)
|
|---|
| 176 | {
|
|---|
| 177 | *fLog << warn << "WARNING - fRms[" << i <<"]= " << fRms[i] << " -> was set to 0 " << endl;
|
|---|
| 178 | fRms[i]=0;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | else
|
|---|
| 182 | fRms[i] = TMath::Sqrt(fRms[i]);
|
|---|
| 183 |
|
|---|
| 184 | // calc mean value for pixel index i
|
|---|
| 185 | fSum[i] /= fEntries;
|
|---|
| 186 |
|
|---|
| 187 | fHist.SetBinContent(i+1, fSum[i]);
|
|---|
| 188 | fHist.SetBinError( i+1, fRms[i]);
|
|---|
| 189 | }
|
|---|
| 190 | return kTRUE;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | // --------------------------------------------------------------------------
|
|---|
| 194 | //
|
|---|
| 195 | // Draw the present 'fill status'
|
|---|
| 196 | //
|
|---|
| 197 | void MHCurrents::Draw(Option_t *o)
|
|---|
| 198 | {
|
|---|
| 199 | if (!fCam)
|
|---|
| 200 | {
|
|---|
| 201 | *fLog << warn << "WARNING - Cannot draw " << GetDescriptor() << ": No Camera Geometry available." << endl;
|
|---|
| 202 | return;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 750, 600);
|
|---|
| 206 | pad->SetBorderMode(0);
|
|---|
| 207 |
|
|---|
| 208 | SetDrawOption(o);
|
|---|
| 209 | AppendPad("");
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | // --------------------------------------------------------------------------
|
|---|
| 213 | //
|
|---|
| 214 | // If a camera display is not yet assigned, assign a new one.
|
|---|
| 215 | //
|
|---|
| 216 | void MHCurrents::Paint(Option_t *option)
|
|---|
| 217 | {
|
|---|
| 218 | if (!fCam)
|
|---|
| 219 | {
|
|---|
| 220 | *fLog << warn << "WARNING - Cannot paint " << GetDescriptor() << ": No Camera Geometry available." << endl;
|
|---|
| 221 | return;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | if (!fDispl)
|
|---|
| 225 | fDispl = new MCamDisplay(fCam);
|
|---|
| 226 |
|
|---|
| 227 | TString opt(GetDrawOption());
|
|---|
| 228 |
|
|---|
| 229 | fDispl->Fill(opt.Contains("rms", TString::kIgnoreCase) ? fRms : fSum);
|
|---|
| 230 | fDispl->Paint();
|
|---|
| 231 | }
|
|---|