source: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.cc@ 1421

Last change on this file since 1421 was 1404, checked in by bigongia, 23 years ago
*** empty log message ***
File size: 6.7 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 7/2002 (moralejo@pd.infn.it)
19!
20! Copyright: MAGIC Software Development, 2002
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MCerPhotCalc2 //
28// //
29// This is a task which calculates the number of photons from the FADC //
30// time slices. It weights the each slice according to the fraction //
31// of signal which, in average, falls within it. This average has been //
32// determined over a run (about 1000 triggers, 0 deg z.a. gammas). //
33// //
34// Input Containers: //
35// MRawEvtData, MPedestalCam //
36// //
37// Output Containers: //
38// MCerPhotEvt //
39// //
40//////////////////////////////////////////////////////////////////////////////
41
42#include "MCerPhotCalc2.h"
43
44#include "MParList.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MMcRunHeader.hxx"
50
51#include "MRawRunHeader.h"
52#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
53#include "MCerPhotEvt.h"
54#include "MPedestalPix.h"
55#include "MPedestalCam.h"
56#include "MRawEvtPixelIter.h"
57
58ClassImp(MCerPhotCalc2);
59
60// --------------------------------------------------------------------------
61//
62// Default constructor.
63//
64MCerPhotCalc2::MCerPhotCalc2(const char *name, const char *title)
65{
66 fName = name ? name : "MCerPhotCalc2";
67 fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
68
69 AddToBranchList("MRawEvtData.fHiGainPixId");
70 AddToBranchList("MRawEvtData.fLoGainPixId");
71 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
72 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
73
74 fSumQuadWeights = fSumWeights = 0.;
75 for (Int_t i = 0; i < 15; i++)
76 {
77 fSumQuadWeights += fWeight[i]*fWeight[i];
78 fSumWeights += fWeight[i];
79 }
80 fSumQuadWeights = sqrt(fSumQuadWeights);
81
82}
83
84// --------------------------------------------------------------------------
85//
86// The PreProcess searches for the following input containers:
87// - MRawRunHeader
88// - MRawEvtData
89// - MPedestalCam
90//
91// The following output containers are also searched and created if
92// they were not found:
93// - MCerPhotEvt
94//
95Bool_t MCerPhotCalc2::PreProcess(MParList *pList)
96{
97 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
98 if (!fRunHeader)
99 {
100 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
105 if (!fRawEvt)
106 {
107 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
108 return kFALSE;
109 }
110
111 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
112 if (!fPedestals)
113 {
114 *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
115 return kFALSE;
116 }
117
118 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
119 if (!fCerPhotEvt)
120 return kFALSE;
121
122 return kTRUE;
123}
124
125// --------------------------------------------------------------------------
126//
127// Check for the run type and camera version.
128// If the file is a MC file and the used camera version is <= 40
129// we enable a fix for truncated pedestal means in this version.
130//
131Bool_t MCerPhotCalc2::ReInit(MParList *pList)
132{
133 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
134 if (!runheader)
135 {
136 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
137 return kTRUE;
138 }
139
140 if (runheader->GetRunType() != kRTMonteCarlo)
141 return kTRUE;
142
143 MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
144 if (!mcrunheader)
145 {
146 *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
147 return kTRUE;
148 }
149
150 if (mcrunheader->GetCamVersion() <= 40)
151 fEnableFix = kTRUE;
152
153 return kTRUE;
154}
155
156// --------------------------------------------------------------------------
157//
158// Calculate the integral of the FADC time slices and store them as a new
159// pixel in the MCerPhotEvt container.
160//
161Bool_t MCerPhotCalc2::Process()
162{
163 fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
164
165 MRawEvtPixelIter pixel(fRawEvt);
166
167 Float_t ADCBins[15];
168
169 while (pixel.Next())
170 {
171 const UInt_t pixid = pixel.GetPixelId();
172 const MPedestalPix &ped = (*fPedestals)[pixid];
173
174 //
175 // sanity check (old MC files sometimes have pixids>577)
176 //
177 if (!fPedestals->CheckBounds(pixid))
178 {
179 *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
180 return kCONTINUE;
181 }
182
183 // Mean pedestal:
184 const Double_t mean = fEnableFix ? ped.GetMean()-0.5 : ped.GetMean();
185
186 Byte_t *ptr = pixel.GetHiGainSamples();
187
188 Float_t nphot = 0.;
189 for(Int_t i = 0; i<15;i++)
190 {
191 ADCBins[i] = (Float_t) *(ptr+i);
192 nphot += ADCBins[i] * fWeight[i];
193 }
194
195 //
196 // We check that the pixel is not empty, if it is empty
197 // we won't substract the pedestal. Empty means that it has
198 // 0 signal in all the slices.
199 //
200 if (nphot!=0)
201 nphot -= mean*fSumWeights;
202
203 Float_t nphoterr = ped.GetSigma()* fSumQuadWeights;
204
205 fCerPhotEvt->AddPixel(pixid, nphot, nphoterr);
206
207 // FIXME! Handling of Lo Gains is missing!
208 }
209
210 fCerPhotEvt->SetReadyToSave();
211
212 return kTRUE;
213}
214
215Float_t MCerPhotCalc2::fWeight[15] = {0, 0.0809835, 0.289593, 0.366926, 0.211665, 0.0508328, 0., 0., 0., 0., 0., 0., 0., 0., 0.};
Note: See TracBrowser for help on using the repository browser.