| 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-2004 | 
|---|
| 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.UseCurrentStyle(); | 
|---|
| 75 | fHM3Long.UseCurrentStyle(); | 
|---|
| 76 | fHM3Trans.UseCurrentStyle(); | 
|---|
| 77 | fHMaxDist.UseCurrentStyle(); | 
|---|
| 78 |  | 
|---|
| 79 | fHAsym.SetName("Asymmetry"); | 
|---|
| 80 | fHM3Long.SetName("M3l"); | 
|---|
| 81 | fHM3Trans.SetName("M3t"); | 
|---|
| 82 | fHMaxDist.SetName("MaxDist"); | 
|---|
| 83 |  | 
|---|
| 84 | fHAsym.SetTitle("Asymmetry"); | 
|---|
| 85 | fHM3Long.SetTitle("3^{rd} Moment Longitudinal"); | 
|---|
| 86 | fHM3Trans.SetTitle("3^{rd} Moment Transverse"); | 
|---|
| 87 | fHMaxDist.SetTitle("Distance of max distant pixel"); | 
|---|
| 88 |  | 
|---|
| 89 | fHAsym.SetXTitle("Asym [mm]"); | 
|---|
| 90 | fHM3Long.SetXTitle("3^{rd} M_{l} [mm]"); | 
|---|
| 91 | fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]"); | 
|---|
| 92 | fHMaxDist.SetXTitle("D_{max} [mm]"); | 
|---|
| 93 |  | 
|---|
| 94 | fHAsym.SetYTitle("Counts"); | 
|---|
| 95 | fHM3Long.SetYTitle("Counts"); | 
|---|
| 96 | fHM3Trans.SetYTitle("Counts"); | 
|---|
| 97 | fHMaxDist.SetYTitle("Counts"); | 
|---|
| 98 |  | 
|---|
| 99 | fHAsym.SetFillStyle(4000); | 
|---|
| 100 | fHM3Long.SetFillStyle(4000); | 
|---|
| 101 | fHM3Trans.SetFillStyle(4000); | 
|---|
| 102 | fHMaxDist.SetFillStyle(4000); | 
|---|
| 103 |  | 
|---|
| 104 | fHAsym.SetDirectory(NULL); | 
|---|
| 105 | fHM3Long.SetDirectory(NULL); | 
|---|
| 106 | fHM3Trans.SetDirectory(NULL); | 
|---|
| 107 | fHMaxDist.SetDirectory(NULL); | 
|---|
| 108 |  | 
|---|
| 109 | fHM3Trans.SetLineColor(kBlue); | 
|---|
| 110 |  | 
|---|
| 111 | MBinning bins; | 
|---|
| 112 |  | 
|---|
| 113 | bins.SetEdges(51, -326, 326); | 
|---|
| 114 | bins.Apply(fHM3Long); | 
|---|
| 115 | bins.Apply(fHM3Trans); | 
|---|
| 116 |  | 
|---|
| 117 | bins.SetEdges(51, -593, 593); | 
|---|
| 118 | bins.Apply(fHAsym); | 
|---|
| 119 |  | 
|---|
| 120 | bins.SetEdges(100, 0, 593); | 
|---|
| 121 | bins.Apply(fHMaxDist); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | // -------------------------------------------------------------------------- | 
|---|
| 125 | // | 
|---|
| 126 | // Setup the Binning for the histograms automatically if the correct | 
|---|
| 127 | // instances of MBinning (with the names 'BinningWidth' and 'BinningLength') | 
|---|
| 128 | // are found in the parameter list | 
|---|
| 129 | // Use this function if you want to set the conversion factor which | 
|---|
| 130 | // is used to convert the mm-scale in the camera plain into the deg-scale | 
|---|
| 131 | // used for histogram presentations. The conversion factor is part of | 
|---|
| 132 | // the camera geometry. Please create a corresponding MGeomCam container. | 
|---|
| 133 | // | 
|---|
| 134 | Bool_t MHHillasExt::SetupFill(const MParList *plist) | 
|---|
| 135 | { | 
|---|
| 136 | fHillasExt = (MHillasExt*)plist->FindObject(fHilName, "MHillasExt"); | 
|---|
| 137 | if (!fHillasExt) | 
|---|
| 138 | { | 
|---|
| 139 | *fLog << err << fHilName << "[MHillasExt] not found in parameter list... aborting." << endl; | 
|---|
| 140 | return kFALSE; | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam"); | 
|---|
| 144 | if (!geom) | 
|---|
| 145 | *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl; | 
|---|
| 146 | else | 
|---|
| 147 | { | 
|---|
| 148 | fMm2Deg = geom->GetConvMm2Deg(); | 
|---|
| 149 | SetMmScale(kFALSE); | 
|---|
| 150 | } | 
|---|
| 151 |  | 
|---|
| 152 | ApplyBinning(*plist, "Asym",    &fHAsym); | 
|---|
| 153 | ApplyBinning(*plist, "M3Long",  &fHM3Long); | 
|---|
| 154 | ApplyBinning(*plist, "M3Trans", &fHM3Trans); | 
|---|
| 155 | ApplyBinning(*plist, "MaxDist", &fHMaxDist); | 
|---|
| 156 |  | 
|---|
| 157 | return kTRUE; | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | // -------------------------------------------------------------------------- | 
|---|
| 161 | // | 
|---|
| 162 | // Fill the four histograms with data from a MHillas-Container. | 
|---|
| 163 | // Be careful: Only call this with an object of type MHillas | 
|---|
| 164 | // | 
|---|
| 165 | Bool_t MHHillasExt::Fill(const MParContainer *par, const Stat_t w) | 
|---|
| 166 | { | 
|---|
| 167 | const MHillasSrc *src = (MHillasSrc*)par; | 
|---|
| 168 |  | 
|---|
| 169 | const Double_t scale = TMath::Sign(fUseMmScale?1:fMm2Deg, (src ? src->GetCosDeltaAlpha() : 1)); | 
|---|
| 170 |  | 
|---|
| 171 | fHAsym.Fill(scale*fHillasExt->GetAsym(), w); | 
|---|
| 172 | fHM3Long.Fill(scale*fHillasExt->GetM3Long(), w); | 
|---|
| 173 | fHM3Trans.Fill(scale*fHillasExt->GetM3Trans(), w); | 
|---|
| 174 | fHMaxDist.Fill(TMath::Abs(scale*fHillasExt->GetMaxDist()), w); | 
|---|
| 175 |  | 
|---|
| 176 | return kTRUE; | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | // -------------------------------------------------------------------------- | 
|---|
| 180 | // | 
|---|
| 181 | // With this function you can convert the histogram ('on the fly') between | 
|---|
| 182 | // degrees and millimeters. | 
|---|
| 183 | // | 
|---|
| 184 | void MHHillasExt::SetMmScale(Bool_t mmscale) | 
|---|
| 185 | { | 
|---|
| 186 | if (fUseMmScale == mmscale) | 
|---|
| 187 | return; | 
|---|
| 188 |  | 
|---|
| 189 | if (fMm2Deg<0) | 
|---|
| 190 | { | 
|---|
| 191 | *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl; | 
|---|
| 192 | return; | 
|---|
| 193 | } | 
|---|
| 194 |  | 
|---|
| 195 | const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg; | 
|---|
| 196 | MH::ScaleAxis(&fHAsym,    scale); | 
|---|
| 197 | MH::ScaleAxis(&fHM3Long,  scale); | 
|---|
| 198 | MH::ScaleAxis(&fHM3Trans, scale); | 
|---|
| 199 | MH::ScaleAxis(&fHMaxDist, scale); | 
|---|
| 200 |  | 
|---|
| 201 | if (mmscale) | 
|---|
| 202 | { | 
|---|
| 203 | fHAsym.SetXTitle("Asym [mm]"); | 
|---|
| 204 | fHM3Long.SetXTitle("3^{rd} M_{l} [mm]"); | 
|---|
| 205 | fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]"); | 
|---|
| 206 | fHMaxDist.SetXTitle("D_{max} [mm]"); | 
|---|
| 207 | } | 
|---|
| 208 | else | 
|---|
| 209 | { | 
|---|
| 210 | fHAsym.SetXTitle("Asym [\\circ]"); | 
|---|
| 211 | fHM3Long.SetXTitle("3^{rd} M_{l} [\\circ]"); | 
|---|
| 212 | fHM3Trans.SetXTitle("3^{rd} M_{t} [\\circ]"); | 
|---|
| 213 | fHMaxDist.SetXTitle("D_{max} [\\circ]"); | 
|---|
| 214 | } | 
|---|
| 215 |  | 
|---|
| 216 | fUseMmScale = mmscale; | 
|---|
| 217 | } | 
|---|
| 218 |  | 
|---|
| 219 | // -------------------------------------------------------------------------- | 
|---|
| 220 | // | 
|---|
| 221 | // Use this function to setup your own conversion factor between degrees | 
|---|
| 222 | // and millimeters. The conversion factor should be the one calculated in | 
|---|
| 223 | // MGeomCam. Use this function with Caution: You could create wrong values | 
|---|
| 224 | // by setting up your own scale factor. | 
|---|
| 225 | // | 
|---|
| 226 | void MHHillasExt::SetMm2Deg(Float_t mmdeg) | 
|---|
| 227 | { | 
|---|
| 228 | if (mmdeg<0) | 
|---|
| 229 | { | 
|---|
| 230 | *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl; | 
|---|
| 231 | return; | 
|---|
| 232 | } | 
|---|
| 233 |  | 
|---|
| 234 | if (fMm2Deg>=0) | 
|---|
| 235 | *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl; | 
|---|
| 236 |  | 
|---|
| 237 | fMm2Deg = mmdeg; | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 | // -------------------------------------------------------------------------- | 
|---|
| 241 | // | 
|---|
| 242 | // Creates a new canvas and draws the four histograms into it. | 
|---|
| 243 | // Be careful: The histograms belongs to this object and won't get deleted | 
|---|
| 244 | // together with the canvas. | 
|---|
| 245 | // | 
|---|
| 246 | void MHHillasExt::Draw(Option_t *o) | 
|---|
| 247 | { | 
|---|
| 248 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this); | 
|---|
| 249 | pad->SetBorderMode(0); | 
|---|
| 250 |  | 
|---|
| 251 | AppendPad(""); | 
|---|
| 252 |  | 
|---|
| 253 | // FIXME: If same-option given make two independant y-axis! | 
|---|
| 254 | const TString opt(o); | 
|---|
| 255 | const Bool_t same = opt.Contains("same"); | 
|---|
| 256 |  | 
|---|
| 257 | if (!same) | 
|---|
| 258 | pad->Divide(2,2); | 
|---|
| 259 | else | 
|---|
| 260 | { | 
|---|
| 261 | fHAsym.SetName("AsymmetrySame"); | 
|---|
| 262 | fHM3Long.SetName("M3lSame"); | 
|---|
| 263 | fHM3Trans.SetName("M3tSame"); | 
|---|
| 264 | fHMaxDist.SetName("MaxDistSame"); | 
|---|
| 265 |  | 
|---|
| 266 | fHAsym.SetDirectory(0); | 
|---|
| 267 | fHM3Long.SetDirectory(0); | 
|---|
| 268 | fHM3Trans.SetDirectory(0); | 
|---|
| 269 | fHMaxDist.SetDirectory(0); | 
|---|
| 270 |  | 
|---|
| 271 | fHM3Long.SetLineColor(kMagenta); | 
|---|
| 272 | fHM3Trans.SetLineColor(kCyan); | 
|---|
| 273 | fHAsym.SetLineColor(kBlue); | 
|---|
| 274 | fHMaxDist.SetLineColor(kBlue); | 
|---|
| 275 | } | 
|---|
| 276 |  | 
|---|
| 277 | pad->cd(1); | 
|---|
| 278 | gPad->SetBorderMode(0); | 
|---|
| 279 | RemoveFromPad("M3lSame"); | 
|---|
| 280 | RemoveFromPad("M3tSame"); | 
|---|
| 281 | MH::DrawSame(fHM3Long, fHM3Trans, "3^{rd} Moments", same); | 
|---|
| 282 |  | 
|---|
| 283 | pad->cd(3); | 
|---|
| 284 | gPad->SetBorderMode(0); | 
|---|
| 285 | RemoveFromPad("AsymmetrySame"); | 
|---|
| 286 | fHAsym.Draw(same?"same":""); | 
|---|
| 287 |  | 
|---|
| 288 | pad->cd(2); | 
|---|
| 289 | gPad->SetBorderMode(0); | 
|---|
| 290 | RemoveFromPad("MaxDistSame"); | 
|---|
| 291 | fHMaxDist.Draw(same?"same":""); | 
|---|
| 292 |  | 
|---|
| 293 | delete pad->GetPad(4); | 
|---|
| 294 | } | 
|---|
| 295 |  | 
|---|
| 296 | TH1 *MHHillasExt::GetHistByName(const TString name) const | 
|---|
| 297 | { | 
|---|
| 298 | if (name.Contains("Asym", TString::kIgnoreCase)) | 
|---|
| 299 | return const_cast<TH1F*>(&fHAsym); | 
|---|
| 300 | if (name.Contains("M3L", TString::kIgnoreCase)) | 
|---|
| 301 | return const_cast<TH1F*>(&fHM3Long); | 
|---|
| 302 | if (name.Contains("M3T", TString::kIgnoreCase)) | 
|---|
| 303 | return const_cast<TH1F*>(&fHM3Trans); | 
|---|
| 304 | if (name.Contains("MaxDist", TString::kIgnoreCase)) | 
|---|
| 305 | return const_cast<TH1F*>(&fHMaxDist); | 
|---|
| 306 |  | 
|---|
| 307 | return NULL; | 
|---|
| 308 | } | 
|---|