source: branches/Mars_IncreaseNsb/mpedestal/MMcPedestalNSBAdd.cc@ 20115

Last change on this file since 20115 was 3803, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.8 KB
Line 
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): Oscar Blanch, 11/2001 <mailto:blanch@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MMcPedestalNSBAdd
28// -----------------
29//
30// This Task adds the contribution of the diffuse NSB to the FADC
31// pedestals. We assume that NSB introduces larger fluctuation but does
32// not change the mean value.
33// To be precise we add quadratically to the rms, which is already in
34// MPedestalCam, the NSB contribution.
35// The number of photons from the diffuse NSB follows a poisson
36// distribution with expected mean value X, then its standard deviation
37// is sqrt(X).
38// X is the number of phe per ns so we have to convert in FADC counts per
39// slice:
40//
41// Y = sqrt(X * FADC_time / Number_of_slices * pixel_size)
42// * Amp_single_phe_response
43//
44// Input Containers:
45// MMcFadcHeader
46// MRawRunHeader
47// [MMcRunHeader]
48//
49// Output Containers:
50// MPedestalCam
51//
52/////////////////////////////////////////////////////////////////////////////
53#include "MMcPedestalNSBAdd.h"
54
55#include "MParList.h"
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60#include "MGeomCam.h"
61#include "MGeomPix.h"
62
63#include "MPedestalPix.h"
64#include "MPedestalCam.h"
65
66#include "MRawRunHeader.h"
67#include "MMcRunHeader.hxx"
68#include "MMcFadcHeader.hxx"
69
70ClassImp(MMcPedestalNSBAdd);
71
72using namespace std;
73
74// --------------------------------------------------------------------------
75//
76// Default constructor.
77//
78MMcPedestalNSBAdd::MMcPedestalNSBAdd(const Float_t difnsb,
79 const char *name, const char *title)
80 : fDnsbPixel(difnsb)
81{
82 fName = name ? name : "MMcPedestalNSBAdd";
83 fTitle = title ? title : "Add diffuse NSB to the pedestal signal";
84
85 //
86 // This is not needed here using MReadMarsFile because for the
87 // RunHeader tree the auto scheme is disabled by default
88 //
89 AddToBranchList("MMcFadcHeader.fPedesMean");
90 AddToBranchList("MMcFadcHeader.fElecNoise");
91}
92
93// --------------------------------------------------------------------------
94//
95// Check for the run type. Return kTRUE if it is a MC run or if there
96// is no MC run header (old camera files) kFALSE in case of a different
97// run type
98//
99Bool_t MMcPedestalNSBAdd::CheckRunType(MParList *pList) const
100{
101 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
102 if (!runheader)
103 {
104 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
105 return kTRUE;
106 }
107
108 return runheader->IsMonteCarloRun();
109}
110
111// --------------------------------------------------------------------------
112//
113// Check for the camera version. This class should not be used with
114// camera files >= 0.7
115//
116Bool_t MMcPedestalNSBAdd::CheckCamVersion(MParList *pList) const
117{
118 const MMcRunHeader *run = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
119 if (!run)
120 *fLog << warn << dbginf << "MMcRunHeader not found... assuming camera<0.7" << endl;
121
122 return !run || run->GetCamVersion()<70;
123}
124
125// --------------------------------------------------------------------------
126//
127// If a MMcRunHeader is available the DNSB MMcRunHeader::GetNumPheFromDNSB
128// is returned. Otherwise the user given number is used.
129//
130Float_t MMcPedestalNSBAdd::GetDnsb(MParList *pList) const
131{
132 const MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
133 if (!mcrunheader && fDnsbPixel<0)
134 {
135 *fLog << err << dbginf << "Using the default argument only ";
136 *fLog << "allowed if MMcRunHeader is available... aborting." << endl;
137 return -1;
138 }
139
140 if (!mcrunheader)
141 return fDnsbPixel;
142
143 if (fDnsbPixel >= 0 && fDnsbPixel != mcrunheader->GetNumPheFromDNSB())
144 {
145 *fLog << warn << dbginf << "The MC file has been generated with diffuse nsb " << mcrunheader->GetNumPheFromDNSB();
146 *fLog <<" but you set up the diffuse NSB to " << fDnsbPixel << endl;
147
148 return fDnsbPixel;
149 }
150
151 return mcrunheader->GetNumPheFromDNSB();
152}
153
154// --------------------------------------------------------------------------
155//
156// This function is called each time MReadTree::Notify is called, which
157// happens when it changes the file to read from.
158// Here we add the contribution from NSB to the pedestals.
159// The ReInit searches for the following input containers:
160// - MRawRunHeader
161// - MMcRunHeader
162// - MMcFacdHeader
163// - MGeomCam
164//
165// The following output containers are also searched and created if
166// they were not found:
167// - MPedestalCam
168//
169Bool_t MMcPedestalNSBAdd::ReInit(MParList *pList)
170{
171 //
172 // If it is no MC file skip this function...
173 //
174 if (!CheckRunType(pList))
175 return kTRUE;
176
177 //
178 // If it is the wrong camera version this algorithm is not needed...
179 //
180 if (!CheckCamVersion(pList))
181 return kTRUE;
182
183 //
184 // Now check the existance of all necessary containers. This has
185 // to be done only if this is a MC file and the camera version
186 // is correct.
187 //
188 MPedestalCam *pedcam = (MPedestalCam*)pList->FindCreateObj(AddSerialNumber("MPedestalCam"));
189 if (!pedcam)
190 return kFALSE;
191
192 MMcFadcHeader *fadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
193 if (!fadc)
194 {
195 *fLog << err << dbginf << "MMcFadcHeader not found... aborting." << endl;
196 return kFALSE;
197 }
198
199 MGeomCam *geom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
200 if (!geom)
201 {
202 *fLog << err << dbginf << "MGeomCam not found... aborting." << endl;
203 return kFALSE;
204 }
205
206 const Float_t dnsbpix = GetDnsb(pList) * 50.0/15.0;
207
208 if (dnsbpix < 0)
209 return kFALSE;
210
211 const int num = pedcam->GetSize();
212
213 for (int i=0; i<num; i++)
214 {
215 MPedestalPix &pix = (*pedcam)[i];
216
217 const Float_t pedrms = pix.GetPedestalRms();
218 const Float_t ratio = geom->GetPixRatio(i);
219 const Float_t ampl = fadc->GetAmplitud();
220
221 pix.SetPedestalRms(sqrt(pedrms*pedrms + dnsbpix*ampl*ampl/ratio));
222 }
223
224 pedcam->SetReadyToSave();
225
226 return kTRUE;
227}
Note: See TracBrowser for help on using the repository browser.