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

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