| 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 2001 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2002
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MHHillasExt
|
|---|
| 28 | //
|
|---|
| 29 | // This class contains histograms for every Hillas parameter
|
|---|
| 30 | //
|
|---|
| 31 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 32 | #include "MHHillasExt.h"
|
|---|
| 33 |
|
|---|
| 34 | #include <math.h>
|
|---|
| 35 |
|
|---|
| 36 | #include <TH1.h>
|
|---|
| 37 | #include <TPad.h>
|
|---|
| 38 | #include <TLegend.h>
|
|---|
| 39 | #include <TCanvas.h>
|
|---|
| 40 |
|
|---|
| 41 | #include "MLog.h"
|
|---|
| 42 | #include "MLogManip.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MGeomCam.h"
|
|---|
| 45 |
|
|---|
| 46 | #include "MParList.h"
|
|---|
| 47 |
|
|---|
| 48 | #include "MBinning.h"
|
|---|
| 49 | #include "MHillasExt.h"
|
|---|
| 50 | #include "MHillasSrc.h"
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MHHillasExt);
|
|---|
| 53 |
|
|---|
| 54 | using namespace std;
|
|---|
| 55 |
|
|---|
| 56 | // --------------------------------------------------------------------------
|
|---|
| 57 | //
|
|---|
| 58 | // Setup four histograms for Width, Length
|
|---|
| 59 | //
|
|---|
| 60 | MHHillasExt::MHHillasExt(const char *name, const char *title)
|
|---|
| 61 | : fMm2Deg(1), fUseMmScale(kTRUE), fHilName("MHillasExt")
|
|---|
| 62 | {
|
|---|
| 63 | //
|
|---|
| 64 | // set the name and title of this object
|
|---|
| 65 | //
|
|---|
| 66 | fName = name ? name : "MHHillasExt";
|
|---|
| 67 | fTitle = title ? title : "Container for extended Hillas histograms";
|
|---|
| 68 |
|
|---|
| 69 | //
|
|---|
| 70 | // loop over all Pixels and create two histograms
|
|---|
| 71 | // one for the Low and one for the High gain
|
|---|
| 72 | // connect all the histogram with the container fHist
|
|---|
| 73 | //
|
|---|
| 74 | fHAsym.SetDirectory(NULL);
|
|---|
| 75 | fHM3Long.SetDirectory(NULL);
|
|---|
| 76 | fHM3Trans.SetDirectory(NULL);
|
|---|
| 77 |
|
|---|
| 78 | fHAsym.SetName("Asymmetry");
|
|---|
| 79 | fHM3Long.SetName("3rd Mom Long");
|
|---|
| 80 | fHM3Trans.SetName("3rd Mom Trans");
|
|---|
| 81 |
|
|---|
| 82 | fHAsym.SetTitle("Asymmetry");
|
|---|
| 83 | fHM3Long.SetTitle("3^{rd} Moment Longitudinal");
|
|---|
| 84 | fHM3Trans.SetTitle("3^{rd} Moment Transverse");
|
|---|
| 85 |
|
|---|
| 86 | fHAsym.SetXTitle("Asym [mm]");
|
|---|
| 87 | fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
|
|---|
| 88 | fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
|
|---|
| 89 |
|
|---|
| 90 | fHAsym.SetYTitle("Counts");
|
|---|
| 91 | fHM3Long.SetYTitle("Counts");
|
|---|
| 92 | fHM3Trans.SetYTitle("Counts");
|
|---|
| 93 |
|
|---|
| 94 | fHAsym.SetFillStyle(4000);
|
|---|
| 95 | fHM3Long.SetFillStyle(4000);
|
|---|
| 96 | fHM3Trans.SetFillStyle(4000);
|
|---|
| 97 |
|
|---|
| 98 | fHM3Trans.SetLineColor(kBlue);
|
|---|
| 99 |
|
|---|
| 100 | MBinning bins;
|
|---|
| 101 |
|
|---|
| 102 | bins.SetEdges(101, -326, 326);
|
|---|
| 103 | bins.Apply(fHM3Long);
|
|---|
| 104 | bins.Apply(fHM3Trans);
|
|---|
| 105 |
|
|---|
| 106 | bins.SetEdges(101, -593, 593);
|
|---|
| 107 | bins.Apply(fHAsym);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // --------------------------------------------------------------------------
|
|---|
| 111 | //
|
|---|
| 112 | // Setup the Binning for the histograms automatically if the correct
|
|---|
| 113 | // instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
|
|---|
| 114 | // are found in the parameter list
|
|---|
| 115 | // Use this function if you want to set the conversion factor which
|
|---|
| 116 | // is used to convert the mm-scale in the camera plain into the deg-scale
|
|---|
| 117 | // used for histogram presentations. The conversion factor is part of
|
|---|
| 118 | // the camera geometry. Please create a corresponding MGeomCam container.
|
|---|
| 119 | //
|
|---|
| 120 | Bool_t MHHillasExt::SetupFill(const MParList *plist)
|
|---|
| 121 | {
|
|---|
| 122 | fHillasExt = (MHillasExt*)plist->FindObject(fHilName, "MHillasExt");
|
|---|
| 123 | if (!fHillasExt)
|
|---|
| 124 | {
|
|---|
| 125 | *fLog << err << fHilName << "[MHillasExt] not found in parameter list... aborting." << endl;
|
|---|
| 126 | return kFALSE;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
|
|---|
| 130 | if (!geom)
|
|---|
| 131 | *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
|
|---|
| 132 | else
|
|---|
| 133 | {
|
|---|
| 134 | fMm2Deg = geom->GetConvMm2Deg();
|
|---|
| 135 | SetMmScale(kFALSE);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | ApplyBinning(*plist, "Asym", &fHAsym);
|
|---|
| 139 | ApplyBinning(*plist, "M3Long", &fHM3Long);
|
|---|
| 140 | ApplyBinning(*plist, "M3Trans", &fHM3Trans);
|
|---|
| 141 |
|
|---|
| 142 | return kTRUE;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | // --------------------------------------------------------------------------
|
|---|
| 146 | //
|
|---|
| 147 | // Fill the four histograms with data from a MHillas-Container.
|
|---|
| 148 | // Be careful: Only call this with an object of type MHillas
|
|---|
| 149 | //
|
|---|
| 150 | Bool_t MHHillasExt::Fill(const MParContainer *par, const Stat_t w)
|
|---|
| 151 | {
|
|---|
| 152 | const MHillasSrc *src = (MHillasSrc*)par;
|
|---|
| 153 |
|
|---|
| 154 | const Double_t scale = TMath::Sign(fUseMmScale?1:fMm2Deg, (src ? src->GetCosDeltaAlpha() : 1));
|
|---|
| 155 |
|
|---|
| 156 | fHAsym.Fill(scale*fHillasExt->GetAsym(), w);
|
|---|
| 157 | fHM3Long.Fill(scale*fHillasExt->GetM3Long(), w);
|
|---|
| 158 | fHM3Trans.Fill(scale*fHillasExt->GetM3Trans(), w);
|
|---|
| 159 | //fHAsymna.Fill(scale*ext.GetAsymna());
|
|---|
| 160 | //fHAsym0.Fill(scale*ext.GetAsym0());
|
|---|
| 161 |
|
|---|
| 162 | return kTRUE;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | // --------------------------------------------------------------------------
|
|---|
| 166 | //
|
|---|
| 167 | // With this function you can convert the histogram ('on the fly') between
|
|---|
| 168 | // degrees and millimeters.
|
|---|
| 169 | //
|
|---|
| 170 | void MHHillasExt::SetMmScale(Bool_t mmscale)
|
|---|
| 171 | {
|
|---|
| 172 | if (fUseMmScale == mmscale)
|
|---|
| 173 | return;
|
|---|
| 174 |
|
|---|
| 175 | if (fMm2Deg<0)
|
|---|
| 176 | {
|
|---|
| 177 | *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
|
|---|
| 178 | return;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
|
|---|
| 182 | MH::ScaleAxis(&fHAsym, scale);
|
|---|
| 183 | MH::ScaleAxis(&fHM3Long, scale);
|
|---|
| 184 | MH::ScaleAxis(&fHM3Trans, scale);
|
|---|
| 185 |
|
|---|
| 186 | if (mmscale)
|
|---|
| 187 | {
|
|---|
| 188 | fHAsym.SetXTitle("Asym [mm]");
|
|---|
| 189 | fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
|
|---|
| 190 | fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
|
|---|
| 191 | }
|
|---|
| 192 | else
|
|---|
| 193 | {
|
|---|
| 194 | fHAsym.SetXTitle("Asym [\\circ]");
|
|---|
| 195 | fHM3Long.SetXTitle("3^{rd} M_{l} [\\circ]");
|
|---|
| 196 | fHM3Trans.SetXTitle("3^{rd} M_{t} [\\circ]");
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | fUseMmScale = mmscale;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | // --------------------------------------------------------------------------
|
|---|
| 203 | //
|
|---|
| 204 | // Use this function to setup your own conversion factor between degrees
|
|---|
| 205 | // and millimeters. The conversion factor should be the one calculated in
|
|---|
| 206 | // MGeomCam. Use this function with Caution: You could create wrong values
|
|---|
| 207 | // by setting up your own scale factor.
|
|---|
| 208 | //
|
|---|
| 209 | void MHHillasExt::SetMm2Deg(Float_t mmdeg)
|
|---|
| 210 | {
|
|---|
| 211 | if (mmdeg<0)
|
|---|
| 212 | {
|
|---|
| 213 | *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
|
|---|
| 214 | return;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | if (fMm2Deg>=0)
|
|---|
| 218 | *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
|
|---|
| 219 |
|
|---|
| 220 | fMm2Deg = mmdeg;
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | // --------------------------------------------------------------------------
|
|---|
| 224 | //
|
|---|
| 225 | // Creates a new canvas and draws the four histograms into it.
|
|---|
| 226 | // Be careful: The histograms belongs to this object and won't get deleted
|
|---|
| 227 | // together with the canvas.
|
|---|
| 228 | //
|
|---|
| 229 | void MHHillasExt::Draw(Option_t *)
|
|---|
| 230 | {
|
|---|
| 231 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
|---|
| 232 | pad->SetBorderMode(0);
|
|---|
| 233 |
|
|---|
| 234 | AppendPad("");
|
|---|
| 235 |
|
|---|
| 236 | pad->Divide(2, 1);
|
|---|
| 237 |
|
|---|
| 238 | pad->cd(1);
|
|---|
| 239 | gPad->SetBorderMode(0);
|
|---|
| 240 | MH::Draw(fHM3Long, fHM3Trans, "3^{rd} Moments");
|
|---|
| 241 |
|
|---|
| 242 | pad->cd(2);
|
|---|
| 243 | gPad->SetBorderMode(0);
|
|---|
| 244 | fHAsym.Draw();
|
|---|
| 245 |
|
|---|
| 246 | pad->Modified();
|
|---|
| 247 | pad->Update();
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | TH1 *MHHillasExt::GetHistByName(const TString name)
|
|---|
| 251 | {
|
|---|
| 252 | if (name.Contains("Asym", TString::kIgnoreCase))
|
|---|
| 253 | return &fHAsym;
|
|---|
| 254 | if (name.Contains("M3Long", TString::kIgnoreCase))
|
|---|
| 255 | return &fHM3Long;
|
|---|
| 256 | if (name.Contains("M3Trans", TString::kIgnoreCase))
|
|---|
| 257 | return &fHM3Trans;
|
|---|
| 258 |
|
|---|
| 259 | return NULL;
|
|---|
| 260 | }
|
|---|