source: tags/Mars-V0.8/manalysis/MMcPedestalNSBAdd.cc

Last change on this file was 1540, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 8.1 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// MMcRunHeader //
47// MRawRunHeader //
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
72// --------------------------------------------------------------------------
73//
74// Default constructor.
75//
76MMcPedestalNSBAdd::MMcPedestalNSBAdd(const Float_t difnsb,
77 const char *name, const char *title)
78 : fDnsbPixel(difnsb)
79{
80 fName = name ? name : "MMcPedestalNSBAdd";
81 fTitle = title ? title : "Task to copy monte carlo pedestals into MPedestal Container";
82
83 //
84 // This is not needed here using MReadMarsFile because for the
85 // RunHeader tree the auto scheme is disabled by default
86 //
87 AddToBranchList("MMcFadcHeader.fPedesMean");
88 AddToBranchList("MMcFadcHeader.fElecNoise");
89}
90
91// --------------------------------------------------------------------------
92//
93// Check for the run type. Return kTRUE if it is a MC run or if there
94// is no MC run header (old camera files) kFALSE in case of a different
95// run type
96//
97Bool_t MMcPedestalNSBAdd::CheckRunType(MParList *pList) const
98{
99 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
100 if (!runheader)
101 {
102 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
103 return kTRUE;
104 }
105
106 return runheader->GetRunType() == kRTMonteCarlo;
107}
108
109// --------------------------------------------------------------------------
110//
111// - check whether we have a monte carlo file. if not skip this task
112// - try to get MMcFadcHeader, MGeomCam and MPedestalCam from the parameter
113// list
114// - try to find a MMcRunHeader, too
115//
116Bool_t MMcPedestalNSBAdd::PreProcess(MParList *pList)
117{
118 if (!CheckRunType(pList))
119 {
120 *fLog << warn << dbginf << "Warning - MMcPedestalNSB is for Monte Carlo files only... removing this task from list." << endl;
121 return kSKIP;
122 }
123
124 fFadc = (MMcFadcHeader*)pList->FindObject("MMcFadcHeader");
125 if (!fFadc)
126 {
127 *fLog << err << dbginf << "MMcFadcHeader not found... aborting." << endl;
128 return kFALSE;
129 }
130
131 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
132 if (!fGeom)
133 {
134 *fLog << err << dbginf << "MGeomCam not found... aborting." << endl;
135 return kFALSE;
136 }
137
138 fPedCam = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
139 if (!fPedCam)
140 return kFALSE;
141
142 const MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
143 if (!mcrunheader && fDnsbPixel<0)
144 {
145 *fLog << err << dbginf << "Using the default argument only ";
146 *fLog << "allowed if MMcRunHeader is available... aborting." << endl;
147 return kFALSE;
148 }
149
150 return kTRUE;
151}
152
153// --------------------------------------------------------------------------
154//
155// If a MMcRunHeader is available the DNSB MMcRunHeader::GetNumPheFromDNSB
156// is returned. Otherwise the user given number is used.
157//
158Float_t MMcPedestalNSBAdd::GetDnsb(MParList *pList) const
159{
160 const MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
161 if (!mcrunheader && fDnsbPixel<0)
162 {
163 *fLog << err << dbginf << "Using the default argument only ";
164 *fLog << "allowed if MMcRunHeader is available... aborting." << endl;
165 return -1;
166 }
167
168 if (!mcrunheader)
169 return fDnsbPixel;
170
171 if (fDnsbPixel >= 0 && fDnsbPixel != mcrunheader->GetNumPheFromDNSB())
172 {
173 *fLog << warn << dbginf << "The MC file has been generated with diffuse nsb " << mcrunheader->GetNumPheFromDNSB();
174 *fLog <<" but you set up the diffuse NSB to " << fDnsbPixel << endl;
175
176 return fDnsbPixel;
177 }
178
179 return mcrunheader->GetNumPheFromDNSB();
180}
181
182// --------------------------------------------------------------------------
183//
184// This function is called each time MReadTree::Notify is called, which
185// happens when it changes the file to read from.
186// Here we add the contribution from NSB to the pedestals.
187// The ReInit searches for the following input containers:
188// - MRawRunHeader
189// - MMcRunHeader
190// - MMcFacdHeader
191// - MGeomCam
192//
193// The following output containers are also searched and created if
194// they were not found:
195// - MPedestalCam
196//
197Bool_t MMcPedestalNSBAdd::ReInit(MParList *pList)
198{
199 if (!CheckRunType(pList))
200 return kFALSE;
201
202 const Float_t dnsbpix = GetDnsb(pList) * 50.0/15.0;
203
204 if (dnsbpix < 0)
205 return kFALSE;
206
207 const int num = fFadc->GetNumPixel();
208
209 fPedCam->InitSize(num);
210
211 const Float_t size0 = (*fGeom)[0].GetR() * (*fGeom)[0].GetR();
212
213 for (int i=0; i<num; i++)
214 {
215 MPedestalPix &pix = (*fPedCam)[i];
216 const MGeomPix &pixgeom = (*fGeom)[i];
217
218 const Float_t pedrms = pix.GetSigma();
219 const Float_t size = pixgeom.GetR()*pixgeom.GetR()/size0;
220
221 const Float_t ampl = fFadc->GetAmplitud();
222
223 pix.SetSigma(sqrt(pedrms*pedrms + dnsbpix*ampl*ampl*size));
224 }
225
226 return kTRUE;
227}
228
Note: See TracBrowser for help on using the repository browser.