| 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): Abelardo Moralejo 06/2003 <mailto:moralejo@pd.infn.it> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2003 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | // MHTrigLvl0 | 
|---|
| 28 | // | 
|---|
| 29 | // This is intended to be a sort of "level 0 trigger display". What it really | 
|---|
| 30 | // does is to store the number of events of a data file in which each pixel | 
|---|
| 31 | // has gone above a given threshold (fPixelThreshold) which is chosen when | 
|---|
| 32 | // calling the constructor. Displaying a camera view with these values can | 
|---|
| 33 | // help identify noisy pixels. See the macro pixfixrate.C to see an example | 
|---|
| 34 | // of its use. Many things are to be fixed. Only inner pixels are shown now | 
|---|
| 35 | // (which are anyhow those involved in the trigger), and the camera geometry | 
|---|
| 36 | // (number of pixels, and how many inner ones) is not yet read from the input | 
|---|
| 37 | // file. | 
|---|
| 38 | // The "pedestal" we are using is just the signal in the first ADC slice | 
|---|
| 39 | // (seems reasonable from the inspection of the available test data files). | 
|---|
| 40 | // | 
|---|
| 41 | // | 
|---|
| 42 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 43 | #include "MHTrigLvl0.h" | 
|---|
| 44 |  | 
|---|
| 45 | #include <TCanvas.h> | 
|---|
| 46 |  | 
|---|
| 47 | #include "MLog.h" | 
|---|
| 48 | #include "MLogManip.h" | 
|---|
| 49 |  | 
|---|
| 50 | #include "MParList.h" | 
|---|
| 51 | #include "MRawEvtData.h" | 
|---|
| 52 | #include "MRawEvtPixelIter.h" | 
|---|
| 53 | #include "MCamDisplay.h" | 
|---|
| 54 |  | 
|---|
| 55 | #include "MGeomCam.h" | 
|---|
| 56 | #include "MGeomPix.h" | 
|---|
| 57 |  | 
|---|
| 58 | ClassImp(MHTrigLvl0); | 
|---|
| 59 |  | 
|---|
| 60 | using namespace std; | 
|---|
| 61 |  | 
|---|
| 62 | // -------------------------------------------------------------------------- | 
|---|
| 63 | // | 
|---|
| 64 | // Reset all pixels to 0 and reset fEntries to 0. | 
|---|
| 65 | // | 
|---|
| 66 | void MHTrigLvl0::Clear() | 
|---|
| 67 | { | 
|---|
| 68 | fSum.Reset(); | 
|---|
| 69 | for (int i=0; i<577; i++) | 
|---|
| 70 | { | 
|---|
| 71 | fSum.AddPixel(i, 0, 0); | 
|---|
| 72 | fSum[i].SetPixelUnused(); | 
|---|
| 73 | } | 
|---|
| 74 | fSum.FixSize(); | 
|---|
| 75 | fEntries = 0; | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | // -------------------------------------------------------------------------- | 
|---|
| 79 | // | 
|---|
| 80 | // Initialize the name and title of the task. | 
|---|
| 81 | // Resets the sum histogram | 
|---|
| 82 | // | 
|---|
| 83 | MHTrigLvl0::MHTrigLvl0(const Float_t pixelthreshold, | 
|---|
| 84 | const char *name, const char *title) | 
|---|
| 85 | : fCam(NULL), fRawEvt(NULL), fDispl(NULL) | 
|---|
| 86 | { | 
|---|
| 87 | // | 
|---|
| 88 | //   set the name and title of this object | 
|---|
| 89 | // | 
|---|
| 90 | fName  = name  ? name  : "MHTrigLvl0"; | 
|---|
| 91 | fTitle = title ? title : "Number of hits above per pixel"; | 
|---|
| 92 | fPixelThreshold = pixelthreshold; | 
|---|
| 93 |  | 
|---|
| 94 | Clear(); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | // -------------------------------------------------------------------------- | 
|---|
| 98 | // | 
|---|
| 99 | // Delete the corresponding camera display if available | 
|---|
| 100 | // | 
|---|
| 101 | MHTrigLvl0::~MHTrigLvl0() | 
|---|
| 102 | { | 
|---|
| 103 | if (fDispl) | 
|---|
| 104 | delete fDispl; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | // -------------------------------------------------------------------------- | 
|---|
| 108 | // | 
|---|
| 109 | // Get the event (MRawEvtData) the histogram might be filled with. If | 
|---|
| 110 | // it is not given, it is assumed, that it is filled with the argument | 
|---|
| 111 | // of the Fill function. | 
|---|
| 112 | // Looks for the camera geometry MGeomCam and resets the sum histogram. | 
|---|
| 113 | // | 
|---|
| 114 | Bool_t MHTrigLvl0::SetupFill(const MParList *plist) | 
|---|
| 115 | { | 
|---|
| 116 | fRawEvt = (MRawEvtData*)plist->FindObject("MRawEvtData"); | 
|---|
| 117 | if (!fRawEvt) | 
|---|
| 118 | { | 
|---|
| 119 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl; | 
|---|
| 120 | return kFALSE; | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | fCam = (MGeomCam*)plist->FindObject("MGeomCam"); | 
|---|
| 124 | if (!fCam) | 
|---|
| 125 | *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl; | 
|---|
| 126 |  | 
|---|
| 127 | Clear(); | 
|---|
| 128 |  | 
|---|
| 129 | return kTRUE; | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|
| 132 | // -------------------------------------------------------------------------- | 
|---|
| 133 | // | 
|---|
| 134 | // Fill the histograms with data from a MCerPhotEvt-Container. | 
|---|
| 135 | // | 
|---|
| 136 | Bool_t MHTrigLvl0::Fill(const MParContainer *par, const Stat_t w) | 
|---|
| 137 | { | 
|---|
| 138 | MRawEvtData *rawevt = par ? (MRawEvtData*) par : fRawEvt; | 
|---|
| 139 | if (!rawevt) | 
|---|
| 140 | { | 
|---|
| 141 | *fLog << err << dbginf << "No MRawEvtData found..." << endl; | 
|---|
| 142 | return kFALSE; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | MRawEvtPixelIter pixel(rawevt); | 
|---|
| 146 |  | 
|---|
| 147 | while(pixel.Next()) | 
|---|
| 148 | { | 
|---|
| 149 | const UInt_t pixid = pixel.GetPixelId(); | 
|---|
| 150 |  | 
|---|
| 151 | // FIXME: number of inner pixels should be read from file | 
|---|
| 152 | if (pixid > 396) | 
|---|
| 153 | break; | 
|---|
| 154 | if (pixid == 0) | 
|---|
| 155 | continue; | 
|---|
| 156 |  | 
|---|
| 157 | fSum[pixid].SetPixelUsed(); | 
|---|
| 158 |  | 
|---|
| 159 | // | 
|---|
| 160 | // FIXME: we now use as "pedestal" the value of the first ADC slice! | 
|---|
| 161 | // | 
|---|
| 162 | Float_t baseline = rawevt->GetNumHiGainSamples() * | 
|---|
| 163 | pixel.GetHiGainSamples()[0]; | 
|---|
| 164 |  | 
|---|
| 165 | Float_t pixel_signal = pixel.GetSumHiGainSamples() - baseline; | 
|---|
| 166 |  | 
|---|
| 167 | Float_t pixel_is_on = ( pixel_signal > fPixelThreshold)? 1. : 0.; | 
|---|
| 168 |  | 
|---|
| 169 | fSum[pixid].AddNumPhotons(pixel_is_on); | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | fEntries++; | 
|---|
| 173 |  | 
|---|
| 174 | return kTRUE; | 
|---|
| 175 | } | 
|---|
| 176 |  | 
|---|
| 177 | // -------------------------------------------------------------------------- | 
|---|
| 178 | // | 
|---|
| 179 | // Set to Unused outer pixels. | 
|---|
| 180 | // | 
|---|
| 181 | Bool_t MHTrigLvl0::Finalize() | 
|---|
| 182 | { | 
|---|
| 183 | // | 
|---|
| 184 | // Show only pixels in the inner region of the camera: | 
|---|
| 185 | // (otherwise, problem with the too different ranges) | 
|---|
| 186 | // | 
|---|
| 187 | for (Int_t i=0; i<577; i++) | 
|---|
| 188 | // FIXME: read number of total and inner pixels from file | 
|---|
| 189 | { | 
|---|
| 190 | if (i > 396) | 
|---|
| 191 | fSum[i].SetPixelUnused(); | 
|---|
| 192 | } | 
|---|
| 193 |  | 
|---|
| 194 | //  fSum.Scale(fEntries); Now disabled, scale was not readable otherwise. | 
|---|
| 195 |  | 
|---|
| 196 | return kTRUE; | 
|---|
| 197 | } | 
|---|
| 198 |  | 
|---|
| 199 | // -------------------------------------------------------------------------- | 
|---|
| 200 | // | 
|---|
| 201 | // Draw the present 'fill status' | 
|---|
| 202 | // | 
|---|
| 203 | void MHTrigLvl0::Draw(Option_t *) | 
|---|
| 204 | { | 
|---|
| 205 | if (!fCam) | 
|---|
| 206 | { | 
|---|
| 207 | *fLog << warn << "WARNING - Cannot draw " << GetDescriptor() << ": No Camera Geometry available." << endl; | 
|---|
| 208 | return; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 750, 600); | 
|---|
| 212 | pad->SetBorderMode(0); | 
|---|
| 213 |  | 
|---|
| 214 | AppendPad(""); | 
|---|
| 215 | } | 
|---|
| 216 |  | 
|---|
| 217 | // -------------------------------------------------------------------------- | 
|---|
| 218 | // | 
|---|
| 219 | // If a camera display is not yet assigned, assign a new one. | 
|---|
| 220 | // | 
|---|
| 221 | void MHTrigLvl0::Paint(Option_t *option) | 
|---|
| 222 | { | 
|---|
| 223 | if (!fCam) | 
|---|
| 224 | { | 
|---|
| 225 | *fLog << warn << "WARNING - Cannot paint " << GetDescriptor() << ": No Camera Geometry available." << endl; | 
|---|
| 226 | return; | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | if (!fDispl) | 
|---|
| 230 | fDispl = new MCamDisplay(fCam); | 
|---|
| 231 |  | 
|---|
| 232 | fDispl->Fill(fSum); | 
|---|
| 233 | fDispl->Paint(); | 
|---|
| 234 | } | 
|---|