| 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, 2/2006 <mailto:tbretz@astro.uni-wuerzburg.de> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2006 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | // MHSrcPosCam | 
|---|
| 28 | // | 
|---|
| 29 | // | 
|---|
| 30 | // FIXME: Use ReInit... | 
|---|
| 31 | // | 
|---|
| 32 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| 33 | #include "MHSrcPosCam.h" | 
|---|
| 34 |  | 
|---|
| 35 | #include <TCanvas.h> | 
|---|
| 36 |  | 
|---|
| 37 | #include "MGeomCam.h" | 
|---|
| 38 | #include "MSrcPosCam.h" | 
|---|
| 39 | #include "MParameters.h" | 
|---|
| 40 | #include "MPointingPos.h" | 
|---|
| 41 |  | 
|---|
| 42 | #include "MString.h" | 
|---|
| 43 | #include "MBinning.h" | 
|---|
| 44 | #include "MParList.h" | 
|---|
| 45 |  | 
|---|
| 46 | #include "MLog.h" | 
|---|
| 47 | #include "MLogManip.h" | 
|---|
| 48 |  | 
|---|
| 49 | ClassImp(MHSrcPosCam); | 
|---|
| 50 |  | 
|---|
| 51 | using namespace std; | 
|---|
| 52 |  | 
|---|
| 53 | // -------------------------------------------------------------------------- | 
|---|
| 54 | // | 
|---|
| 55 | // Default Constructor | 
|---|
| 56 | // | 
|---|
| 57 | MHSrcPosCam::MHSrcPosCam(const char *name, const char *title) | 
|---|
| 58 | : fTimeEffOn(NULL), fEffOnTime(NULL), fSourcePos(NULL) | 
|---|
| 59 | { | 
|---|
| 60 | // | 
|---|
| 61 | //   set the name and title of this object | 
|---|
| 62 | // | 
|---|
| 63 | fName  = name  ? name  : "MHSrcPosCam"; | 
|---|
| 64 | fTitle = title ? title : "Histogram for source position distribution"; | 
|---|
| 65 |  | 
|---|
| 66 | fHist.SetName("SourcePos"); | 
|---|
| 67 | fHist.SetTitle("Source position distribution in camera coordinates"); | 
|---|
| 68 | fHist.SetXTitle("dx [\\circ]"); | 
|---|
| 69 | fHist.SetYTitle("dy [\\circ]"); | 
|---|
| 70 | fHist.SetZTitle("T_{eff} [s]"); | 
|---|
| 71 | fHist.SetDirectory(NULL); | 
|---|
| 72 | fHist.UseCurrentStyle(); | 
|---|
| 73 | fHist.GetXaxis()->CenterTitle(); | 
|---|
| 74 | fHist.GetYaxis()->CenterTitle(); | 
|---|
| 75 | fHist.SetContour(99); | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 | MBinning bins; | 
|---|
| 79 | bins.SetEdges(51, -0.2499, 0.2499); // bin=0.01ø  ~0.5SE | 
|---|
| 80 |  | 
|---|
| 81 | MH::SetBinning(&fHist, &bins, &bins); | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | Bool_t MHSrcPosCam::SetupFill(const MParList *pl) | 
|---|
| 85 | { | 
|---|
| 86 | fTimeEffOn = (MTime*)pl->FindObject("MTimeEffectiveOnTime"); | 
|---|
| 87 | if (!fTimeEffOn) | 
|---|
| 88 | { | 
|---|
| 89 | *fLog << err << "ERROR - MTimeEffOnTime not found... aborting." << endl; | 
|---|
| 90 | return kFALSE; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | MGeomCam *geom = (MGeomCam*)pl->FindObject("MGeomCam"); | 
|---|
| 94 | if (!geom) | 
|---|
| 95 | { | 
|---|
| 96 | *fLog << err << "ERROR - MGeomCam not found... aborting." << endl; | 
|---|
| 97 | return kFALSE; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | fEffOnTime = (MParameterD*)pl->FindObject("MEffectiveOnTime"); | 
|---|
| 101 | if (!fEffOnTime) | 
|---|
| 102 | { | 
|---|
| 103 | *fLog << err << "ERROR - MEffectiveOnTime not found... aborting." << endl; | 
|---|
| 104 | return kFALSE; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | MPointingPos *pos = (MPointingPos*)pl->FindObject("MSourcePos", "MPointingPos"); | 
|---|
| 108 | if (!pos) | 
|---|
| 109 | { | 
|---|
| 110 | *fLog << warn << "ERROR - MSourcePos not found... aborting." << endl; | 
|---|
| 111 | return kFALSE; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | const TString src = pos->GetString("radec"); | 
|---|
| 115 | fHist.SetTitle(MString::Format("SrcPos distribution in camera: %s", src.Data())); | 
|---|
| 116 |  | 
|---|
| 117 | fHist.Reset(); | 
|---|
| 118 | fXY            = TVector2(); | 
|---|
| 119 | fNum           = 0; | 
|---|
| 120 | fTimeLastEffOn = MTime(); | 
|---|
| 121 | fConvMm2Deg    = geom->GetConvMm2Deg(); | 
|---|
| 122 |  | 
|---|
| 123 | return kTRUE; | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 126 | // -------------------------------------------------------------------------- | 
|---|
| 127 | // | 
|---|
| 128 | // | 
|---|
| 129 | // | 
|---|
| 130 | Bool_t MHSrcPosCam::Fill(const MParContainer *par, const Stat_t w) | 
|---|
| 131 | { | 
|---|
| 132 | const MSrcPosCam *cam = dynamic_cast<const MSrcPosCam*>(par); | 
|---|
| 133 | if (!cam) | 
|---|
| 134 | { | 
|---|
| 135 | *fLog << err << dbginf << "Got no MSrcPosCam as argument of Fill()..." << endl; | 
|---|
| 136 | return kFALSE; | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | //    if (fName=="MHSrcPosCam") | 
|---|
| 140 | //    { | 
|---|
| 141 | fXY += cam->GetXY(); | 
|---|
| 142 | fNum++; | 
|---|
| 143 |  | 
|---|
| 144 | if (fTimeLastEffOn==MTime()) | 
|---|
| 145 | fTimeLastEffOn=*fTimeEffOn; | 
|---|
| 146 |  | 
|---|
| 147 | if (fTimeLastEffOn == *fTimeEffOn) | 
|---|
| 148 | return kTRUE; | 
|---|
| 149 |  | 
|---|
| 150 | fXY *= fConvMm2Deg/fNum; | 
|---|
| 151 |  | 
|---|
| 152 | fHist.Fill(fXY.X(), fXY.Y(), fEffOnTime->GetVal()); | 
|---|
| 153 | //    } | 
|---|
| 154 | //    else | 
|---|
| 155 | //        fHist.Fill(cam->GetX()*fConvMm2Deg, cam->GetY()*fConvMm2Deg); | 
|---|
| 156 |  | 
|---|
| 157 | fXY            = TVector2(); | 
|---|
| 158 | fNum           = 0; | 
|---|
| 159 | fTimeLastEffOn = *fTimeEffOn; | 
|---|
| 160 |  | 
|---|
| 161 | return kTRUE; | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | void MHSrcPosCam::Paint(Option_t *) | 
|---|
| 165 | { | 
|---|
| 166 | MH::SetPalette("glow1", 99); | 
|---|
| 167 | } | 
|---|
| 168 |  | 
|---|
| 169 | // -------------------------------------------------------------------------- | 
|---|
| 170 | // | 
|---|
| 171 | // | 
|---|
| 172 | // | 
|---|
| 173 | void MHSrcPosCam::Draw(Option_t *) | 
|---|
| 174 | { | 
|---|
| 175 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this); | 
|---|
| 176 | pad->SetBorderMode(0); | 
|---|
| 177 |  | 
|---|
| 178 | //pad->Divide(2,2); | 
|---|
| 179 |  | 
|---|
| 180 | gPad->SetLeftMargin(0.25); | 
|---|
| 181 | gPad->SetRightMargin(0.25); | 
|---|
| 182 |  | 
|---|
| 183 | gPad->SetGridx(); | 
|---|
| 184 | gPad->SetGridy(); | 
|---|
| 185 |  | 
|---|
| 186 | fHist.Draw("colz"); | 
|---|
| 187 |  | 
|---|
| 188 | AppendPad(); | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|