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): Josep Flix <mailto:jflix@ifae.es>
|
---|
19 | ! Javier Rico <mailto:jrico@ifae.es>
|
---|
20 | ! (01/04)
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | /////////////////////////////////////////////////////////////////////////////
|
---|
28 | // //
|
---|
29 | // MPedPhotCalc //
|
---|
30 | // //
|
---|
31 | // This is a Task class to compute, for each pixel, the signal mean and //
|
---|
32 | // rms from a pedestal run file that has undergone the standard signal //
|
---|
33 | // extration and calibration procedure. The signal rms can be used as //
|
---|
34 | // reference to compute the significance of the measured signals in the //
|
---|
35 | // following data runs (e.g. during the image cleaning). //
|
---|
36 | // //
|
---|
37 | // Input Containers: //
|
---|
38 | // MCerPhotEvt //
|
---|
39 | // //
|
---|
40 | // Output Containers: //
|
---|
41 | // MPedPhotCam
|
---|
42 | // //
|
---|
43 | // //
|
---|
44 | /////////////////////////////////////////////////////////////////////////////
|
---|
45 |
|
---|
46 | #include "MLog.h"
|
---|
47 | #include "MLogManip.h"
|
---|
48 |
|
---|
49 | #include "MPedPhotCalc.h"
|
---|
50 | #include "MParList.h"
|
---|
51 | #include "MRawRunHeader.h"
|
---|
52 | #include "MCerPhotPix.h"
|
---|
53 | #include "MCerPhotEvt.h"
|
---|
54 | #include "MPedPhotPix.h"
|
---|
55 | #include "MPedPhotCam.h"
|
---|
56 |
|
---|
57 | ClassImp(MPedPhotCalc);
|
---|
58 |
|
---|
59 | using namespace std;
|
---|
60 |
|
---|
61 | MPedPhotCalc::MPedPhotCalc(const char *name, const char *title)
|
---|
62 | {
|
---|
63 | fName = name ? name : "MPedPhotCalc";
|
---|
64 | fTitle = title ? title : "Task to calculate pedestals from the charge computed from pedestal runs (in units of photons)";
|
---|
65 | }
|
---|
66 |
|
---|
67 | Int_t MPedPhotCalc::PreProcess( MParList *pList )
|
---|
68 | {
|
---|
69 | // Look for input container
|
---|
70 | fCerPhot = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
|
---|
71 | if (!fCerPhot)
|
---|
72 | {
|
---|
73 | *fLog << err << "MPedPhotCalc::PreProcess Error: MCerPhotEvt not found... aborting." << endl;
|
---|
74 | return kFALSE;
|
---|
75 | }
|
---|
76 |
|
---|
77 | // Create output container
|
---|
78 | fPedestals = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam");
|
---|
79 | if (!fPedestals)
|
---|
80 | return kFALSE;
|
---|
81 |
|
---|
82 | return kTRUE;
|
---|
83 | }
|
---|
84 |
|
---|
85 | Bool_t MPedPhotCalc::ReInit(MParList *pList)
|
---|
86 | {
|
---|
87 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
88 | if (!runheader)
|
---|
89 | {
|
---|
90 | *fLog << warn << dbginf;
|
---|
91 | *fLog << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
92 | }
|
---|
93 | else
|
---|
94 | if (runheader->GetRunType() == kRTMonteCarlo)
|
---|
95 | return kTRUE;
|
---|
96 |
|
---|
97 |
|
---|
98 | fNumPixels = fPedestals->GetSize();
|
---|
99 |
|
---|
100 | // Initialize arrays
|
---|
101 | if(fSumx.GetSize()==0)
|
---|
102 | {
|
---|
103 | fSumx.Set(fNumPixels);
|
---|
104 | fSumx2.Set(fNumPixels);
|
---|
105 |
|
---|
106 | memset(fSumx.GetArray(), 0, sizeof(Float_t)*fNumPixels);
|
---|
107 | memset(fSumx2.GetArray(), 0, sizeof(Float_t)*fNumPixels);
|
---|
108 | }
|
---|
109 |
|
---|
110 | return kTRUE;
|
---|
111 | }
|
---|
112 |
|
---|
113 | Int_t MPedPhotCalc::Process()
|
---|
114 | {
|
---|
115 | for(UInt_t i=0;i<fCerPhot->GetNumPixels();i++)
|
---|
116 | {
|
---|
117 | MCerPhotPix &pix = (*fCerPhot)[i];
|
---|
118 | Float_t nphot = pix.GetNumPhotons();
|
---|
119 | Int_t idx = pix.GetPixId();
|
---|
120 |
|
---|
121 | fSumx[idx] += nphot;
|
---|
122 | fSumx2[idx] += nphot*nphot;
|
---|
123 | }
|
---|
124 |
|
---|
125 | fPedestals->SetReadyToSave();
|
---|
126 |
|
---|
127 | return kTRUE;
|
---|
128 | }
|
---|
129 |
|
---|
130 | Int_t MPedPhotCalc::PostProcess()
|
---|
131 | {
|
---|
132 | // Compute pedestals and rms from fSumx and fSumx2 arrays
|
---|
133 | const Int_t n = GetNumExecutions();
|
---|
134 |
|
---|
135 | for(Int_t i=0;i<fNumPixels;i++)
|
---|
136 | {
|
---|
137 | const Float_t sum = fSumx.At(i);
|
---|
138 | const Float_t sum2 = fSumx2.At(i);
|
---|
139 |
|
---|
140 | const Float_t photped = sum/n;
|
---|
141 | const Float_t photrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.));
|
---|
142 |
|
---|
143 | (*fPedestals)[i].Set(photped,photrms);
|
---|
144 | }
|
---|
145 |
|
---|
146 | return kTRUE;
|
---|
147 | }
|
---|