| 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 08/2002 <mailto:tbretz@astro.uni-wuerzburg.de> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2002 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | //                                                                         // | 
|---|
| 27 | //  MCameraSmooth                                                          // | 
|---|
| 28 | //                                                                         // | 
|---|
| 29 | //  This task fills each pixel in the camera with the average of the       // | 
|---|
| 30 | //  number of cerenkov photons from its surrounding pixels. This can       // | 
|---|
| 31 | //  be done using the central pixel or ignoring the central pixel.         // | 
|---|
| 32 | //                                                                         // | 
|---|
| 33 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 34 | #include "MCameraSmooth.h" | 
|---|
| 35 |  | 
|---|
| 36 | #include "MLog.h" | 
|---|
| 37 | #include "MLogManip.h" | 
|---|
| 38 |  | 
|---|
| 39 | #include "MParList.h" | 
|---|
| 40 |  | 
|---|
| 41 | #include "MGeomPix.h" | 
|---|
| 42 | #include "MGeomCam.h" | 
|---|
| 43 | #include "MSignalPix.h" | 
|---|
| 44 | #include "MSignalCam.h" | 
|---|
| 45 |  | 
|---|
| 46 | ClassImp(MCameraSmooth); | 
|---|
| 47 |  | 
|---|
| 48 | using namespace std; | 
|---|
| 49 |  | 
|---|
| 50 | // -------------------------------------------------------------------------- | 
|---|
| 51 | // | 
|---|
| 52 | // Default constructor. You can specify the numer of loops how often a | 
|---|
| 53 | // smoothing should be done. The default is 1. | 
|---|
| 54 | // | 
|---|
| 55 | MCameraSmooth::MCameraSmooth(Byte_t n, const char *name, const char *title) | 
|---|
| 56 | : fCounts(n), fUseCentralPixel(kTRUE) | 
|---|
| 57 | { | 
|---|
| 58 | fName  = name  ? name  : "MCameraSmooth"; | 
|---|
| 59 | fTitle = title ? title : "Task to smooth the camera"; | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | // -------------------------------------------------------------------------- | 
|---|
| 63 | // | 
|---|
| 64 | //  - get the MSignalCam from the parlist (abort if missing) | 
|---|
| 65 | //  - get MGeomCam from the parameter list | 
|---|
| 66 | // | 
|---|
| 67 | Int_t MCameraSmooth::PreProcess (MParList *pList) | 
|---|
| 68 | { | 
|---|
| 69 | fEvt = (MSignalCam*)pList->FindObject("MSignalCam"); | 
|---|
| 70 | if (!fEvt) | 
|---|
| 71 | { | 
|---|
| 72 | *fLog << err << dbginf << "MSignalCam not found... aborting." << endl; | 
|---|
| 73 | return kFALSE; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | fGeomCam = (MGeomCam*)pList->FindObject("MGeomCam"); | 
|---|
| 77 | if (!fGeomCam) | 
|---|
| 78 | { | 
|---|
| 79 | *fLog << warn << dbginf << "No camera geometry available... aborting." << endl; | 
|---|
| 80 |  | 
|---|
| 81 | return kFALSE; | 
|---|
| 82 | } | 
|---|
| 83 | return kTRUE; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | // -------------------------------------------------------------------------- | 
|---|
| 87 | // | 
|---|
| 88 | // Do the smoothing | 
|---|
| 89 | // | 
|---|
| 90 | Int_t MCameraSmooth::Process() | 
|---|
| 91 | { | 
|---|
| 92 | const UShort_t entries = fEvt->GetNumPixels(); | 
|---|
| 93 |  | 
|---|
| 94 | // | 
|---|
| 95 | // remove the pixels in fPixelsID if they are set to be used, | 
|---|
| 96 | // (set them to 'unused' state) | 
|---|
| 97 | // | 
|---|
| 98 |  | 
|---|
| 99 | Double_t *photons = new Double_t[entries]; | 
|---|
| 100 | Double_t *errors  = new Double_t[entries]; | 
|---|
| 101 |  | 
|---|
| 102 | for (int n=0; n<fCounts; n++) | 
|---|
| 103 | { | 
|---|
| 104 | for (UShort_t i=0; i<entries; i++) | 
|---|
| 105 | { | 
|---|
| 106 | MSignalPix &pix = (*fEvt)[i]; | 
|---|
| 107 |  | 
|---|
| 108 | //const Int_t id = pix.GetPixId(); | 
|---|
| 109 |  | 
|---|
| 110 | const MGeomPix &gpix = (*fGeomCam)[i]; | 
|---|
| 111 |  | 
|---|
| 112 | const Int_t nn = gpix.GetNumNeighbors(); | 
|---|
| 113 |  | 
|---|
| 114 | Int_t num  = fUseCentralPixel ? 1 : 0; | 
|---|
| 115 | photons[i] = fUseCentralPixel ? pix.GetNumPhotons() : 0; | 
|---|
| 116 | errors[i]  = fUseCentralPixel ? pix.GetErrorPhot()  : 0; | 
|---|
| 117 |  | 
|---|
| 118 | for (int j=0; j<nn; j++) | 
|---|
| 119 | { | 
|---|
| 120 | const UShort_t nid = gpix.GetNeighbor(j); | 
|---|
| 121 |  | 
|---|
| 122 | const MSignalPix &evtpix = (*fEvt)[nid]; | 
|---|
| 123 | photons[i] += evtpix.GetNumPhotons(); | 
|---|
| 124 | errors[i]  += evtpix.GetErrorPhot(); | 
|---|
| 125 | num++; | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | photons[i] /= num; | 
|---|
| 129 | errors[i]  /= num; | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|
| 132 | for (UShort_t i=0; i<entries; i++) | 
|---|
| 133 | (*fEvt)[i].Set(photons[i], errors[i]); | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | delete photons; | 
|---|
| 137 | delete errors; | 
|---|
| 138 |  | 
|---|
| 139 | return kTRUE; | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|