source: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc@ 1540

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