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

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