source: trunk/MagicSoft/Mars/manalysis/MMcCalibrationCalc.cc@ 2726

Last change on this file since 2726 was 2721, checked in by moralejo, 23 years ago
*** empty log message ***
File size: 6.3 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): Abelardo Moralejo, 12/2003 <mailto:moralejo@pd.infn.it>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MMcCalibrationCalc
28//
29// This task looks for the ìnformation about FADC pedestals in
30// MMcFadcHeader and translates it to the pedestal mean and rms (in adc counts),
31// and in the conversion factor between photons and ADC counts in
32// MCalibrationCam.
33// Then we create and fill also the MPedPhotCam object containing the pedestal
34// rms in units of photons.
35//
36// Input Containers:
37// MMcFadcHeader
38// [MRawRunHeader]
39//
40// Output Containers:
41// MCalibrationCam
42// MPedPhotCam
43//
44/////////////////////////////////////////////////////////////////////////////
45#include "MMcCalibrationCalc.h"
46
47#include "MParList.h"
48
49#include "MLog.h"
50#include "MLogManip.h"
51
52#include "MCalibrationPix.h"
53#include "MCalibrationCam.h"
54#include "MExtractedSignalCam.h"
55#include "MExtractedSignalPix.h"
56#include "MGeomCam.h"
57#include "MPedPhotCam.h"
58#include "MPedPhotPix.h"
59
60#include "MRawRunHeader.h"
61#include "MMcFadcHeader.hxx"
62
63ClassImp(MMcCalibrationCalc);
64
65using namespace std;
66
67MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
68{
69 fName = name ? name : "MMcCalibrationCalc";
70 fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
71
72 fADC2PhInner = 1.;
73 fADC2PhOuter = 1.;
74
75}
76
77// --------------------------------------------------------------------------
78//
79// Check for the run type. Return kTRUE if it is a MC run or if there
80// is no MC run header (old camera files) kFALSE in case of a different
81// run type
82//
83Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
84{
85 const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
86 if (!run)
87 {
88 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
89 return kTRUE;
90 }
91
92 return run->GetRunType() == kRTMonteCarlo;
93}
94
95// --------------------------------------------------------------------------
96//
97// Make sure, that there is an MCalibrationCam Object in the Parameter List.
98//
99Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
100{
101 //
102 // If it is no MC file skip this function...
103 //
104 if (!CheckRunType(pList))
105 return kTRUE;
106
107 if ( ! pList->FindCreateObj(AddSerialNumber("MCalibrationCam")))
108 {
109 *fLog << err << dbginf << "Cannot create MCalibrationCam... aborting." << endl;
110 return kFALSE;
111 }
112
113 if ( ! pList->FindCreateObj(AddSerialNumber("MPedPhotCam")))
114 {
115 *fLog << err << dbginf << "Cannot create MPedPhotCam... aborting." << endl;
116 return kFALSE;
117 }
118
119 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
120 if ( ! fGeom )
121 {
122 *fLog << err << dbginf << "Cannot find MGeomCam... aborting." << endl;
123 return kFALSE;
124 }
125
126 fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
127 if ( ! fSignalCam)
128 {
129 *fLog << err << dbginf << "Cannot find MExtractedSignalCam... aborting." << endl;
130 return kFALSE;
131 }
132
133 return kTRUE;
134
135}
136
137// --------------------------------------------------------------------------
138//
139// Check for the runtype.
140// Search for MCalibrationCam, MPedPhotCam and MMcFadcHeader.
141//
142Bool_t MMcCalibrationCalc::ReInit(MParList *pList)
143{
144 //
145 // If it is no MC file skip this function...
146 //
147 if (!CheckRunType(pList))
148 return kTRUE;
149
150 //
151 // Now check the existence of all necessary containers. This has
152 // to be done only if this is a MC file.
153 //
154
155 fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
156 if (!fHeaderFadc)
157 {
158 *fLog << err << dbginf << "MMcFadcHeader not found... aborting." << endl;
159 return kFALSE;
160 }
161
162 fCalCam = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationCam"));
163
164 if (!fCalCam)
165 {
166 *fLog << err << dbginf << "Could not create MCalibrationCam... aborting. " << endl;
167 return kFALSE;
168 }
169
170 fPedPhotCam = (MPedPhotCam*)pList->FindObject(AddSerialNumber("MPedPhotCam"));
171
172 if (!fPedPhotCam)
173 {
174 *fLog << err << dbginf << "Could not create MPedPhotCam... aborting. " << endl;
175 return kFALSE;
176 }
177
178 return kTRUE;
179}
180
181
182// --------------------------------------------------------------------------
183//
184// Fill the MCalibrationCam and MCerPhotPed objects
185//
186Int_t MMcCalibrationCalc::Process()
187{
188 const int num = fCalCam->GetSize();
189
190 for (int i=0; i<num; i++)
191 {
192 MCalibrationPix &calpix = (*fCalCam)[i];
193 MExtractedSignalPix &sigpix = (*fSignalCam)[i];
194
195 //
196 // ped mean and rms per pixel, in ADC counts, according to signal
197 // calculation (hi or low gain and number of integrated slices):
198 //
199 const Float_t pedestmean = sigpix.IsLoGainUsed()?
200 fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
201 fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
202
203 const Float_t pedestrms = sigpix.IsLoGainUsed()?
204 sqrt((Double_t)(fSignalCam->GetNumUsedLoGainFADCSlices())) * fHeaderFadc->GetPedestalRmsLow(i) :
205 sqrt((Double_t)(fSignalCam->GetNumUsedHiGainFADCSlices())) * fHeaderFadc->GetPedestalRmsHigh(i);
206
207 calpix.SetPedestal(pedestmean, pedestrms);
208 calpix.SetBlindPixelMethodValid();
209
210 if ( fGeom->GetPixRatio(i) > fGeom->GetPixRatio(0) )
211 calpix.SetConversionBlindPixelMethod(fADC2PhOuter, 0., 0.);
212 else
213 calpix.SetConversionBlindPixelMethod(fADC2PhInner, 0., 0.);
214
215 }
216
217 return kTRUE;
218}
Note: See TracBrowser for help on using the repository browser.