| 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@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2007
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MHHillasExt
|
|---|
| 28 | //
|
|---|
| 29 | // This class contains histograms for every Hillas parameter
|
|---|
| 30 | //
|
|---|
| 31 | // Class Version 2:
|
|---|
| 32 | // ----------------
|
|---|
| 33 | // - fHMaxDist
|
|---|
| 34 | // + fHSlopeL
|
|---|
| 35 | //
|
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 | #include "MHHillasExt.h"
|
|---|
| 38 |
|
|---|
| 39 | #include <math.h>
|
|---|
| 40 |
|
|---|
| 41 | #include <TPad.h>
|
|---|
| 42 | #include <TLegend.h>
|
|---|
| 43 | #include <TCanvas.h>
|
|---|
| 44 |
|
|---|
| 45 | #include "MLog.h"
|
|---|
| 46 | #include "MLogManip.h"
|
|---|
| 47 |
|
|---|
| 48 | #include "MGeomCam.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MParList.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MBinning.h"
|
|---|
| 53 |
|
|---|
| 54 | #include "MHillas.h"
|
|---|
| 55 | #include "MHillasExt.h"
|
|---|
| 56 | #include "MHillasSrc.h"
|
|---|
| 57 |
|
|---|
| 58 | ClassImp(MHHillasExt);
|
|---|
| 59 |
|
|---|
| 60 | using namespace std;
|
|---|
| 61 |
|
|---|
| 62 | // --------------------------------------------------------------------------
|
|---|
| 63 | //
|
|---|
| 64 | // Setup four histograms for Width, Length
|
|---|
| 65 | //
|
|---|
| 66 | MHHillasExt::MHHillasExt(const char *name, const char *title)
|
|---|
| 67 | : fHillas(0), fHillasExt(0), fMm2Deg(1),
|
|---|
| 68 | fUseMmScale(kTRUE), fHilName("MHillasExt")
|
|---|
| 69 | {
|
|---|
| 70 | //
|
|---|
| 71 | // set the name and title of this object
|
|---|
| 72 | //
|
|---|
| 73 | fName = name ? name : "MHHillasExt";
|
|---|
| 74 | fTitle = title ? title : "Container for extended Hillas histograms";
|
|---|
| 75 |
|
|---|
| 76 | //
|
|---|
| 77 | // loop over all Pixels and create two histograms
|
|---|
| 78 | // one for the Low and one for the High gain
|
|---|
| 79 | // connect all the histogram with the container fHist
|
|---|
| 80 | //
|
|---|
| 81 | fHAsym.UseCurrentStyle();
|
|---|
| 82 | fHM3Long.UseCurrentStyle();
|
|---|
| 83 | fHM3Trans.UseCurrentStyle();
|
|---|
| 84 | fHSlopeL.UseCurrentStyle();
|
|---|
| 85 |
|
|---|
| 86 | fHAsym.SetName("Asymmetry");
|
|---|
| 87 | fHM3Long.SetName("M3l");
|
|---|
| 88 | fHM3Trans.SetName("M3t");
|
|---|
| 89 | fHSlopeL.SetName("SlopeL");
|
|---|
| 90 |
|
|---|
| 91 | fHAsym.SetTitle("Asymmetry");
|
|---|
| 92 | fHM3Long.SetTitle("3^{rd} Moment Longitudinal");
|
|---|
| 93 | fHM3Trans.SetTitle("3^{rd} Moment Transverse");
|
|---|
| 94 | fHSlopeL.SetTitle("Longitudinal time-slope vs. Dist");
|
|---|
| 95 |
|
|---|
| 96 | fHAsym.SetXTitle("Asym [mm]");
|
|---|
| 97 | fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
|
|---|
| 98 | fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
|
|---|
| 99 | fHSlopeL.SetXTitle("D [mm]");
|
|---|
| 100 |
|
|---|
| 101 | fHAsym.SetYTitle("Counts");
|
|---|
| 102 | fHM3Long.SetYTitle("Counts");
|
|---|
| 103 | fHM3Trans.SetYTitle("Counts");
|
|---|
| 104 | fHSlopeL.SetYTitle("S_{l} [ns/mm]");
|
|---|
| 105 |
|
|---|
| 106 | fHAsym.SetFillStyle(4000);
|
|---|
| 107 | fHM3Long.SetFillStyle(4000);
|
|---|
| 108 | fHM3Trans.SetFillStyle(4000);
|
|---|
| 109 | //fHSlopeL.SetFillStyle(4000);
|
|---|
| 110 |
|
|---|
| 111 | fHAsym.SetDirectory(NULL);
|
|---|
| 112 | fHM3Long.SetDirectory(NULL);
|
|---|
| 113 | fHM3Trans.SetDirectory(NULL);
|
|---|
| 114 | fHSlopeL.SetDirectory(NULL);
|
|---|
| 115 |
|
|---|
| 116 | fHM3Trans.SetLineColor(kBlue);
|
|---|
| 117 |
|
|---|
| 118 | MBinning binsx, binsy;
|
|---|
| 119 |
|
|---|
| 120 | binsx.SetEdges(51, -326, 326);
|
|---|
| 121 | binsx.Apply(fHM3Long);
|
|---|
| 122 | binsx.Apply(fHM3Trans);
|
|---|
| 123 |
|
|---|
| 124 | binsx.SetEdges(51, -593, 593);
|
|---|
| 125 | binsx.Apply(fHAsym);
|
|---|
| 126 |
|
|---|
| 127 | binsx.SetEdges(100, 0, 445);
|
|---|
| 128 | binsy.SetEdges(100, -0.04, 0.04);
|
|---|
| 129 | MH::SetBinning(&fHSlopeL, &binsx, &binsy);
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | // --------------------------------------------------------------------------
|
|---|
| 133 | //
|
|---|
| 134 | // Setup the Binning for the histograms automatically if the correct
|
|---|
| 135 | // instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
|
|---|
| 136 | // are found in the parameter list
|
|---|
| 137 | // Use this function if you want to set the conversion factor which
|
|---|
| 138 | // is used to convert the mm-scale in the camera plain into the deg-scale
|
|---|
| 139 | // used for histogram presentations. The conversion factor is part of
|
|---|
| 140 | // the camera geometry. Please create a corresponding MGeomCam container.
|
|---|
| 141 | //
|
|---|
| 142 | Bool_t MHHillasExt::SetupFill(const MParList *plist)
|
|---|
| 143 | {
|
|---|
| 144 | fHillasExt = (MHillasExt*)plist->FindObject(fHilName, "MHillasExt");
|
|---|
| 145 | if (!fHillasExt)
|
|---|
| 146 | {
|
|---|
| 147 | *fLog << err << fHilName << "[MHillasExt] not found in parameter list... aborting." << endl;
|
|---|
| 148 | return kFALSE;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | fHillas = (MHillas*)plist->FindObject("MHillas");
|
|---|
| 152 | if (!fHillas)
|
|---|
| 153 | {
|
|---|
| 154 | *fLog << err << "MHillas not found in parameter list... aborting." << endl;
|
|---|
| 155 | return kFALSE;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
|
|---|
| 159 | if (!geom)
|
|---|
| 160 | *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
|
|---|
| 161 | else
|
|---|
| 162 | {
|
|---|
| 163 | fMm2Deg = geom->GetConvMm2Deg();
|
|---|
| 164 | SetMmScale(kFALSE);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | ApplyBinning(*plist, "Asym", &fHAsym);
|
|---|
| 168 | ApplyBinning(*plist, "M3Long", &fHM3Long);
|
|---|
| 169 | ApplyBinning(*plist, "M3Trans", &fHM3Trans);
|
|---|
| 170 | ApplyBinning(*plist, "Dist", "Slope", &fHSlopeL);
|
|---|
| 171 |
|
|---|
| 172 | return kTRUE;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | // --------------------------------------------------------------------------
|
|---|
| 176 | //
|
|---|
| 177 | // Fill the four histograms with data from a MHillas-Container.
|
|---|
| 178 | // Be careful: Only call this with an object of type MHillas
|
|---|
| 179 | //
|
|---|
| 180 | Bool_t MHHillasExt::Fill(const MParContainer *par, const Stat_t w)
|
|---|
| 181 | {
|
|---|
| 182 | const MHillasSrc *src = (MHillasSrc*)par;
|
|---|
| 183 |
|
|---|
| 184 | const Double_t scale = TMath::Sign(fUseMmScale?1:fMm2Deg, (src ? src->GetCosDeltaAlpha() : 1));
|
|---|
| 185 | const Double_t dist = src ? src->GetDist() : fHillas->GetDist0();
|
|---|
| 186 |
|
|---|
| 187 | fHAsym.Fill(scale*fHillasExt->GetAsym(), w);
|
|---|
| 188 | fHM3Long.Fill(scale*fHillasExt->GetM3Long(), w);
|
|---|
| 189 | fHM3Trans.Fill(scale*fHillasExt->GetM3Trans(), w);
|
|---|
| 190 | fHSlopeL.Fill(scale*dist, fHillasExt->GetSlopeLong()/scale, w);
|
|---|
| 191 |
|
|---|
| 192 | return kTRUE;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | // --------------------------------------------------------------------------
|
|---|
| 196 | //
|
|---|
| 197 | // With this function you can convert the histogram ('on the fly') between
|
|---|
| 198 | // degrees and millimeters.
|
|---|
| 199 | //
|
|---|
| 200 | void MHHillasExt::SetMmScale(Bool_t mmscale)
|
|---|
| 201 | {
|
|---|
| 202 | if (fUseMmScale == mmscale)
|
|---|
| 203 | return;
|
|---|
| 204 |
|
|---|
| 205 | if (fMm2Deg<0)
|
|---|
| 206 | {
|
|---|
| 207 | *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
|
|---|
| 208 | return;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
|
|---|
| 212 | MH::ScaleAxis(&fHAsym, scale);
|
|---|
| 213 | MH::ScaleAxis(&fHM3Long, scale);
|
|---|
| 214 | MH::ScaleAxis(&fHM3Trans, scale);
|
|---|
| 215 | MH::ScaleAxis(&fHSlopeL, scale, 1./scale);
|
|---|
| 216 |
|
|---|
| 217 | if (mmscale)
|
|---|
| 218 | {
|
|---|
| 219 | fHAsym.SetXTitle("Asym [mm]");
|
|---|
| 220 | fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
|
|---|
| 221 | fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
|
|---|
| 222 | fHSlopeL.SetXTitle("D [mm]");
|
|---|
| 223 | fHSlopeL.SetYTitle("S_{l} [ns/mm]");
|
|---|
| 224 | }
|
|---|
| 225 | else
|
|---|
| 226 | {
|
|---|
| 227 | fHAsym.SetXTitle("Asym [\\circ]");
|
|---|
| 228 | fHM3Long.SetXTitle("3^{rd} M_{l} [\\circ]");
|
|---|
| 229 | fHM3Trans.SetXTitle("3^{rd} M_{t} [\\circ]");
|
|---|
| 230 | fHSlopeL.SetXTitle("D [\\circ]");
|
|---|
| 231 | fHSlopeL.SetYTitle("S_{l} [ns/\\circ]");
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | fUseMmScale = mmscale;
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | // --------------------------------------------------------------------------
|
|---|
| 238 | //
|
|---|
| 239 | // Use this function to setup your own conversion factor between degrees
|
|---|
| 240 | // and millimeters. The conversion factor should be the one calculated in
|
|---|
| 241 | // MGeomCam. Use this function with Caution: You could create wrong values
|
|---|
| 242 | // by setting up your own scale factor.
|
|---|
| 243 | //
|
|---|
| 244 | void MHHillasExt::SetMm2Deg(Float_t mmdeg)
|
|---|
| 245 | {
|
|---|
| 246 | if (mmdeg<0)
|
|---|
| 247 | {
|
|---|
| 248 | *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
|
|---|
| 249 | return;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | if (fMm2Deg>=0)
|
|---|
| 253 | *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
|
|---|
| 254 |
|
|---|
| 255 | fMm2Deg = mmdeg;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | // --------------------------------------------------------------------------
|
|---|
| 259 | //
|
|---|
| 260 | // Creates a new canvas and draws the four histograms into it.
|
|---|
| 261 | // Be careful: The histograms belongs to this object and won't get deleted
|
|---|
| 262 | // together with the canvas.
|
|---|
| 263 | //
|
|---|
| 264 | void MHHillasExt::Draw(Option_t *o)
|
|---|
| 265 | {
|
|---|
| 266 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
|---|
| 267 | pad->SetBorderMode(0);
|
|---|
| 268 |
|
|---|
| 269 | AppendPad("");
|
|---|
| 270 |
|
|---|
| 271 | // FIXME: If same-option given make two independant y-axis!
|
|---|
| 272 | const TString opt(o);
|
|---|
| 273 | const Bool_t same = opt.Contains("same");
|
|---|
| 274 |
|
|---|
| 275 | if (!same)
|
|---|
| 276 | pad->Divide(2,2);
|
|---|
| 277 | else
|
|---|
| 278 | {
|
|---|
| 279 | fHAsym.SetName("AsymmetrySame");
|
|---|
| 280 | fHM3Long.SetName("M3lSame");
|
|---|
| 281 | fHM3Trans.SetName("M3tSame");
|
|---|
| 282 | fHSlopeL.SetName("SlopeLSame");
|
|---|
| 283 |
|
|---|
| 284 | fHAsym.SetDirectory(0);
|
|---|
| 285 | fHM3Long.SetDirectory(0);
|
|---|
| 286 | fHM3Trans.SetDirectory(0);
|
|---|
| 287 | fHSlopeL.SetDirectory(0);
|
|---|
| 288 |
|
|---|
| 289 | fHM3Long.SetLineColor(kMagenta);
|
|---|
| 290 | fHM3Trans.SetLineColor(kCyan);
|
|---|
| 291 | fHAsym.SetLineColor(kBlue);
|
|---|
| 292 | fHSlopeL.SetMarkerColor(kBlue);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | pad->cd(1);
|
|---|
| 296 | gPad->SetBorderMode(0);
|
|---|
| 297 | RemoveFromPad("M3lSame");
|
|---|
| 298 | RemoveFromPad("M3tSame");
|
|---|
| 299 | MH::DrawSame(fHM3Long, fHM3Trans, "3^{rd} Moments", same);
|
|---|
| 300 |
|
|---|
| 301 | pad->cd(3);
|
|---|
| 302 | gPad->SetBorderMode(0);
|
|---|
| 303 | RemoveFromPad("AsymmetrySame");
|
|---|
| 304 | fHAsym.Draw(same?"same":"");
|
|---|
| 305 |
|
|---|
| 306 | pad->cd(2);
|
|---|
| 307 | gPad->SetBorderMode(0);
|
|---|
| 308 | //RemoveFromPad("SlopeLSame");
|
|---|
| 309 | //fHSlopeL.Draw(same?"same":"");
|
|---|
| 310 | if (same)
|
|---|
| 311 | {
|
|---|
| 312 | TH2 *h=dynamic_cast<TH2*>(gPad->FindObject("SlopeL"));
|
|---|
| 313 | if (h)
|
|---|
| 314 | {
|
|---|
| 315 | // This causes crashes in THistPainter::PaintTable
|
|---|
| 316 | // if the z-axis is not kept. No idea why...
|
|---|
| 317 | h->SetDrawOption("z");
|
|---|
| 318 | h->SetMarkerColor(kBlack);
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | RemoveFromPad("SlopeLSame");
|
|---|
| 322 | fHSlopeL.SetMarkerColor(kGreen);
|
|---|
| 323 | fHSlopeL.Draw("same");
|
|---|
| 324 | }
|
|---|
| 325 | else
|
|---|
| 326 | fHSlopeL.Draw("colz");
|
|---|
| 327 |
|
|---|
| 328 | delete pad->GetPad(4);
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | TH1 *MHHillasExt::GetHistByName(const TString name) const
|
|---|
| 332 | {
|
|---|
| 333 | if (name.Contains("Asym", TString::kIgnoreCase))
|
|---|
| 334 | return const_cast<TH1F*>(&fHAsym);
|
|---|
| 335 | if (name.Contains("M3L", TString::kIgnoreCase))
|
|---|
| 336 | return const_cast<TH1F*>(&fHM3Long);
|
|---|
| 337 | if (name.Contains("M3T", TString::kIgnoreCase))
|
|---|
| 338 | return const_cast<TH1F*>(&fHM3Trans);
|
|---|
| 339 | if (name.Contains("SlopeL", TString::kIgnoreCase))
|
|---|
| 340 | return const_cast<TH2F*>(&fHSlopeL);
|
|---|
| 341 |
|
|---|
| 342 | return NULL;
|
|---|
| 343 | }
|
|---|