| 1 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 2 | // Input Containers:
|
|---|
| 3 | // MGeomCam
|
|---|
| 4 | // MCerPhotEvt
|
|---|
| 5 | // MPedestalCam
|
|---|
| 6 | //
|
|---|
| 7 | // Output Containers:
|
|---|
| 8 | // MIslands
|
|---|
| 9 | //
|
|---|
| 10 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 11 | #include "MIslandCalc.h"
|
|---|
| 12 |
|
|---|
| 13 | #include <stdlib.h> // atof
|
|---|
| 14 | #include <fstream> // ofstream, SavePrimitive
|
|---|
| 15 |
|
|---|
| 16 | #include "MLog.h"
|
|---|
| 17 | #include "MLogManip.h"
|
|---|
| 18 |
|
|---|
| 19 | #include "MIslands.h"
|
|---|
| 20 |
|
|---|
| 21 | #include "MParList.h"
|
|---|
| 22 |
|
|---|
| 23 | //#include "MImgCleanStd.h"
|
|---|
| 24 |
|
|---|
| 25 | #include "MLog.h"
|
|---|
| 26 | #include "MLogManip.h"
|
|---|
| 27 |
|
|---|
| 28 | #include "MGeomPix.h"
|
|---|
| 29 | #include "MGeomCam.h"
|
|---|
| 30 |
|
|---|
| 31 | #include "MCerPhotPix.h"
|
|---|
| 32 | #include "MCerPhotEvt.h"
|
|---|
| 33 |
|
|---|
| 34 | #include "MPedestalCam.h"
|
|---|
| 35 | #include "MPedestalPix.h"
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | ClassImp(MIslandCalc);
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | using namespace std;
|
|---|
| 42 |
|
|---|
| 43 | // --------------------------------------------------------------------------
|
|---|
| 44 | //
|
|---|
| 45 | // Default constructor.
|
|---|
| 46 | //
|
|---|
| 47 | MIslandCalc::MIslandCalc(const char *name, const char *title)
|
|---|
| 48 | : fIsl(NULL)
|
|---|
| 49 | {
|
|---|
| 50 | fName = name ? name : "MIslandCalc";
|
|---|
| 51 | fTitle = title ? title : "Calculate island parameters";
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | Int_t MIslandCalc::PreProcess (MParList *pList)
|
|---|
| 57 | {
|
|---|
| 58 | fCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 59 | if (!fCam)
|
|---|
| 60 | {
|
|---|
| 61 | *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
|
|---|
| 62 | return kFALSE;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
|
|---|
| 66 | if (!fEvt)
|
|---|
| 67 | {
|
|---|
| 68 | *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
|
|---|
| 69 | return kFALSE;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | fPed = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
|---|
| 73 | if (!fPed)
|
|---|
| 74 | {
|
|---|
| 75 | *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
|
|---|
| 76 | return kFALSE;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | fIsl = (MIslands*)pList->FindCreateObj(AddSerialNumber("MIslands"));
|
|---|
| 81 | if (!fIsl)
|
|---|
| 82 | return kFALSE;
|
|---|
| 83 |
|
|---|
| 84 | return kTRUE;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | //tries to clean a bit more the image avoiding noisy islands
|
|---|
| 89 |
|
|---|
| 90 | Int_t MIslandCalc::Process()
|
|---|
| 91 | {
|
|---|
| 92 |
|
|---|
| 93 | Float_t noise;
|
|---|
| 94 | Float_t signal;
|
|---|
| 95 |
|
|---|
| 96 | Int_t npix = 577;
|
|---|
| 97 | Int_t sflag;
|
|---|
| 98 | Int_t control;
|
|---|
| 99 |
|
|---|
| 100 | Int_t nvect = 0;
|
|---|
| 101 | Int_t fIslNum = 0;
|
|---|
| 102 | Float_t fSigToNoise[30];
|
|---|
| 103 |
|
|---|
| 104 | Int_t vect[100][577];
|
|---|
| 105 | Int_t kk[577];
|
|---|
| 106 |
|
|---|
| 107 | for(Int_t m = 0; m < 50 ; m++)
|
|---|
| 108 | for(Int_t n = 0; n < 577 ; n++)
|
|---|
| 109 | vect[m][n] = 0;
|
|---|
| 110 |
|
|---|
| 111 | for(Int_t n = 0; n < 577 ; n++)
|
|---|
| 112 | kk[n] = 0;
|
|---|
| 113 |
|
|---|
| 114 | // loop over all pixels
|
|---|
| 115 | for(Int_t idx=0 ; idx<npix ; idx++)
|
|---|
| 116 | {
|
|---|
| 117 | const MGeomPix &gpix = (*fCam)[idx];
|
|---|
| 118 | const Int_t nnmax = gpix.GetNumNeighbors();
|
|---|
| 119 |
|
|---|
| 120 | if(idx<0 || idx==npix)
|
|---|
| 121 | {
|
|---|
| 122 | cout << "Pixel (software) index out of range [0-576]. Available number of pixels=" << npix << endl;
|
|---|
| 123 | return 1;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | if(fEvt->IsPixelCore(idx) || fEvt->IsPixelUsed(idx))
|
|---|
| 128 | {
|
|---|
| 129 | sflag = 0;
|
|---|
| 130 |
|
|---|
| 131 | for(Int_t j=0; j < nnmax ; j++)
|
|---|
| 132 | {
|
|---|
| 133 | const Int_t idx2 = gpix.GetNeighbor(j);
|
|---|
| 134 |
|
|---|
| 135 | if (idx2 < idx)
|
|---|
| 136 | {
|
|---|
| 137 | for(Int_t k = 1; k <= nvect; k++)
|
|---|
| 138 | {
|
|---|
| 139 | if (vect[k][idx2] == 1)
|
|---|
| 140 | {
|
|---|
| 141 | sflag = 1;
|
|---|
| 142 | vect[k][idx] = 1;
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | if (sflag == 0)
|
|---|
| 149 | {
|
|---|
| 150 | nvect++;
|
|---|
| 151 | vect[nvect][idx] = 1;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | fIslNum = nvect;
|
|---|
| 158 |
|
|---|
| 159 | // Repeated Chain Corrections
|
|---|
| 160 | for(Int_t i = 1; i <= nvect; i++)
|
|---|
| 161 | {
|
|---|
| 162 | for(Int_t j = i+1; j <= nvect; j++)
|
|---|
| 163 | {
|
|---|
| 164 | control = 0;
|
|---|
| 165 | for(Int_t k = 0; k < npix; k++)
|
|---|
| 166 | {
|
|---|
| 167 | if (vect[i][k] == 1 && vect[j][k] == 1)
|
|---|
| 168 | {
|
|---|
| 169 | control = 1;
|
|---|
| 170 | //cout << " two vectors coincide... "<< endl;
|
|---|
| 171 | break;
|
|---|
| 172 | }
|
|---|
| 173 | }
|
|---|
| 174 | if (control == 1)
|
|---|
| 175 | {
|
|---|
| 176 | for(Int_t k = 0; k < npix; k++)
|
|---|
| 177 | {
|
|---|
| 178 | if(vect[j][k] == 1)
|
|---|
| 179 | vect[i][k] = 1;
|
|---|
| 180 | vect[j][k] = 0;
|
|---|
| 181 | }
|
|---|
| 182 | fIslNum = fIslNum-1;
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | cout << " Let me see..." << endl;
|
|---|
| 188 | cout << " Number of vectors: " << nvect << endl;
|
|---|
| 189 | cout << " Number of islands: " << fIslNum << endl;
|
|---|
| 190 |
|
|---|
| 191 | //examine each island...
|
|---|
| 192 |
|
|---|
| 193 | Int_t fPixNum[30];
|
|---|
| 194 |
|
|---|
| 195 | for(Int_t i = 1; i<=fIslNum ; i++)
|
|---|
| 196 | {
|
|---|
| 197 | signal = 0;
|
|---|
| 198 | noise = 0;
|
|---|
| 199 | fPixNum[i] = 0;
|
|---|
| 200 | for(Int_t idx=0 ; idx<npix ; idx++)
|
|---|
| 201 | {
|
|---|
| 202 | const MCerPhotPix &pix = (*fEvt)[idx];
|
|---|
| 203 | const MPedestalPix &ped = (*fPed)[idx];
|
|---|
| 204 |
|
|---|
| 205 | if (vect[i][idx]==1){
|
|---|
| 206 |
|
|---|
| 207 | fPixNum[i]++;
|
|---|
| 208 | signal += pix.GetNumPhotons() * (fCam->GetPixRatio(idx));
|
|---|
| 209 | noise += pow(ped.GetPedestalRms(),2);
|
|---|
| 210 |
|
|---|
| 211 | }
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | cout << "Signal: " << signal<<endl;
|
|---|
| 215 | cout << "Noise: " << noise << endl;
|
|---|
| 216 | fSigToNoise[i] = (Float_t)signal/(Float_t)sqrt(noise);
|
|---|
| 217 |
|
|---|
| 218 | fIsl->SetIslNum(fIslNum);
|
|---|
| 219 | fIsl->SetPixNum(i,fPixNum[i]);
|
|---|
| 220 | fIsl->SetSigToNoise(i,fSigToNoise[i]);
|
|---|
| 221 |
|
|---|
| 222 | cout << " Island Num " << i << endl;
|
|---|
| 223 | cout << " Pixel Number in the island: " << fPixNum[i] << endl;
|
|---|
| 224 | cout << " Signal to Noise of the island : " << fSigToNoise[i] << endl;
|
|---|
| 225 |
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | return 1;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|