| 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 10/2002 <mailto:thomas.bretz@epfl.ch> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2012 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | // MCalibrateFact | 
|---|
| 28 | // | 
|---|
| 29 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 30 | #include "MCalibrateFact.h" | 
|---|
| 31 |  | 
|---|
| 32 | #include "MLog.h" | 
|---|
| 33 | #include "MLogManip.h" | 
|---|
| 34 |  | 
|---|
| 35 | #include "MParList.h" | 
|---|
| 36 | #include "MTaskList.h" | 
|---|
| 37 | #include "MSignalCam.h" | 
|---|
| 38 | #include "MBadPixelsCam.h" | 
|---|
| 39 | #include "MExtractedSignalPix.h" | 
|---|
| 40 | #include "MExtractedSignalCam.h" | 
|---|
| 41 |  | 
|---|
| 42 | ClassImp(MCalibrateFact); | 
|---|
| 43 |  | 
|---|
| 44 | using namespace std; | 
|---|
| 45 |  | 
|---|
| 46 | // -------------------------------------------------------------------------- | 
|---|
| 47 | // | 
|---|
| 48 | // Default constructor. | 
|---|
| 49 | // | 
|---|
| 50 | MCalibrateFact::MCalibrateFact(const char *name, const char *title) | 
|---|
| 51 | : fIn(0), fOut(0), fBadPixels(0), | 
|---|
| 52 | fNameExtractedSignalCam("MExtractedSignalCam"), | 
|---|
| 53 | fNameSignalCam("MSignalCam"), | 
|---|
| 54 | fScale(1) | 
|---|
| 55 | { | 
|---|
| 56 | fName  = name  ? name  : "MCalibrateFact"; | 
|---|
| 57 | fTitle = title ? title : ""; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | // -------------------------------------------------------------------------- | 
|---|
| 61 | // | 
|---|
| 62 | //  Delete the filter if it was created automatically | 
|---|
| 63 | // | 
|---|
| 64 | MCalibrateFact::~MCalibrateFact() | 
|---|
| 65 | { | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | // -------------------------------------------------------------------------- | 
|---|
| 69 | // | 
|---|
| 70 | Int_t MCalibrateFact::PreProcess(MParList *plist) | 
|---|
| 71 | { | 
|---|
| 72 | fIn = (MExtractedSignalCam*)plist->FindObject(fNameExtractedSignalCam, "MExtractedSignalCam"); | 
|---|
| 73 | if (!fIn) | 
|---|
| 74 | { | 
|---|
| 75 | *fLog << err << fNameExtractedSignalCam << " [MExtractedSignalCam] not found... abort." << endl; | 
|---|
| 76 | return kFALSE; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | fBadPixels = (MBadPixelsCam*)plist->FindCreateObj("MBadPixelsCam"); | 
|---|
| 80 | if (!fBadPixels) | 
|---|
| 81 | return kFALSE; | 
|---|
| 82 |  | 
|---|
| 83 | fOut = (MSignalCam*)plist->FindCreateObj("MSignalCam", fNameSignalCam); | 
|---|
| 84 | if (!fOut) | 
|---|
| 85 | return kFALSE; | 
|---|
| 86 |  | 
|---|
| 87 | if (fScale!=1) | 
|---|
| 88 | *fLog << inf << "Using additional scale factor of " << fScale << endl; | 
|---|
| 89 |  | 
|---|
| 90 | return kTRUE; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | // -------------------------------------------------------------------------- | 
|---|
| 94 | // | 
|---|
| 95 | Bool_t MCalibrateFact::ReInit(MParList *plist) | 
|---|
| 96 | { | 
|---|
| 97 | if (fCalibConst.GetSize()==0) | 
|---|
| 98 | { | 
|---|
| 99 | fCalibConst.Set(fIn->GetSize()); | 
|---|
| 100 | fCalibConst.Reset(1); | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | if (UInt_t(fIn->GetSize()) != fCalibConst.GetSize()) | 
|---|
| 104 | { | 
|---|
| 105 | *fLog << err << "Size mismatch." << endl; | 
|---|
| 106 | return kFALSE; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | return kTRUE; | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | Int_t MCalibrateFact::Process() | 
|---|
| 113 | { | 
|---|
| 114 | const UInt_t npix = fIn->GetSize(); | 
|---|
| 115 |  | 
|---|
| 116 | for (UInt_t idx=0; idx<npix; idx++) | 
|---|
| 117 | { | 
|---|
| 118 | const MExtractedSignalPix &sig = (*fIn)[idx]; | 
|---|
| 119 |  | 
|---|
| 120 | const Double_t signal = sig.GetExtractedSignalHiGain(); | 
|---|
| 121 | const Bool_t   ok     = /*!sig.IsHiGainSaturated() &&*/ sig.IsHiGainValid(); | 
|---|
| 122 |  | 
|---|
| 123 | const Double_t nphot = signal * fCalibConst[idx] * fScale; | 
|---|
| 124 | fOut->AddPixel(idx, nphot, 0); | 
|---|
| 125 |  | 
|---|
| 126 | if (!ok) | 
|---|
| 127 | (*fBadPixels)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt); | 
|---|
| 128 |  | 
|---|
| 129 | /* | 
|---|
| 130 | if (!ok) | 
|---|
| 131 | { | 
|---|
| 132 | if (sig.IsHiGainSaturated()) | 
|---|
| 133 | numsathi++; | 
|---|
| 134 |  | 
|---|
| 135 | if (sig.IsLoGainSaturated()) | 
|---|
| 136 | numsatlo++; | 
|---|
| 137 | }*/ | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | //fOut->SetNumPixelsSaturated(numsathi, numsatlo); | 
|---|
| 141 | //fOut->SetReadyToSave(); | 
|---|
| 142 |  | 
|---|
| 143 | return kTRUE; | 
|---|
| 144 |  | 
|---|
| 145 | } | 
|---|
| 146 |  | 
|---|