source: trunk/MagicSoft/Mars/manalysis/MMcPedestalNSBAdd.cc@ 2193

Last change on this file since 2193 was 2178, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.0 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
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->GetRunType() == kRTMonteCarlo;
109}
110
111// --------------------------------------------------------------------------
112//
113// - check whether we have a monte carlo file. if not skip this task
114// - try to get MMcFadcHeader, MGeomCam and MPedestalCam from the parameter
115// list
116// - try to find a MMcRunHeader, too
117//
118Bool_t MMcPedestalNSBAdd::PreProcess(MParList *pList)
119{
120 if (!CheckRunType(pList))
121 {
122 *fLog << warn << dbginf << "Warning - MMcPedestalNSB is for Monte Carlo files only... removing this task from list." << endl;
123 return kSKIP;
124 }
125
126 fFadc = (MMcFadcHeader*)pList->FindObject("MMcFadcHeader");
127 if (!fFadc)
128 {
129 *fLog << err << dbginf << "MMcFadcHeader not found... aborting." << endl;
130 return kFALSE;
131 }
132
133 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
134 if (!fGeom)
135 {
136 *fLog << err << dbginf << "MGeomCam not found... aborting." << endl;
137 return kFALSE;
138 }
139
140 fPedCam = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
141 if (!fPedCam)
142 return kFALSE;
143
144 const MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
145 if (!mcrunheader && fDnsbPixel<0)
146 {
147 *fLog << err << dbginf << "Using the default argument only ";
148 *fLog << "allowed if MMcRunHeader is available... aborting." << endl;
149 return kFALSE;
150 }
151
152 return kTRUE;
153}
154
155// --------------------------------------------------------------------------
156//
157// If a MMcRunHeader is available the DNSB MMcRunHeader::GetNumPheFromDNSB
158// is returned. Otherwise the user given number is used.
159//
160Float_t MMcPedestalNSBAdd::GetDnsb(MParList *pList) const
161{
162 const MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
163 if (!mcrunheader && fDnsbPixel<0)
164 {
165 *fLog << err << dbginf << "Using the default argument only ";
166 *fLog << "allowed if MMcRunHeader is available... aborting." << endl;
167 return -1;
168 }
169
170 if (!mcrunheader)
171 return fDnsbPixel;
172
173 if (fDnsbPixel >= 0 && fDnsbPixel != mcrunheader->GetNumPheFromDNSB())
174 {
175 *fLog << warn << dbginf << "The MC file has been generated with diffuse nsb " << mcrunheader->GetNumPheFromDNSB();
176 *fLog <<" but you set up the diffuse NSB to " << fDnsbPixel << endl;
177
178 return fDnsbPixel;
179 }
180
181 return mcrunheader->GetNumPheFromDNSB();
182}
183
184// --------------------------------------------------------------------------
185//
186// This function is called each time MReadTree::Notify is called, which
187// happens when it changes the file to read from.
188// Here we add the contribution from NSB to the pedestals.
189// The ReInit searches for the following input containers:
190// - MRawRunHeader
191// - MMcRunHeader
192// - MMcFacdHeader
193// - MGeomCam
194//
195// The following output containers are also searched and created if
196// they were not found:
197// - MPedestalCam
198//
199Bool_t MMcPedestalNSBAdd::ReInit(MParList *pList)
200{
201 if (!CheckRunType(pList))
202 return kFALSE;
203
204 const Float_t dnsbpix = GetDnsb(pList) * 50.0/15.0;
205
206 if (dnsbpix < 0)
207 return kFALSE;
208
209 const int num = fFadc->GetNumPixel();
210
211 fPedCam->InitSize(num);
212
213 for (int i=0; i<num; i++)
214 {
215 MPedestalPix &pix = (*fPedCam)[i];
216
217 const Float_t pedrms = pix.GetSigma();
218 const Float_t ratio = fGeom->GetPixRatio(i);
219 const Float_t ampl = fFadc->GetAmplitud();
220
221 pix.SetSigma(sqrt(pedrms*pedrms + dnsbpix*ampl*ampl/ratio));
222 }
223
224 return kTRUE;
225}
226
Note: See TracBrowser for help on using the repository browser.