source: releases/Mars.2014.05.26/mpedestal/MMcPedestalCopy.cc@ 18459

Last change on this file since 18459 was 9336, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.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): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MMcPedestalCopy
28//
29// This task looks for the ìnformation about FADC pedestals in
30// MMcFadcHeader and translates it to the pedestal values in
31// MPedestalCam
32//
33// Input Containers:
34// MMcFadcHeader
35// [MMcRunHeader]
36// [MRawRunHeader]
37//
38// Output Containers:
39// MPedestalCam
40//
41/////////////////////////////////////////////////////////////////////////////
42#include "MMcPedestalCopy.h"
43
44#include "MParList.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MPedestalPix.h"
50#include "MPedestalCam.h"
51
52#include "MRawRunHeader.h"
53#include "MMcRunHeader.hxx"
54#include "MMcFadcHeader.hxx"
55
56ClassImp(MMcPedestalCopy);
57
58using namespace std;
59
60MMcPedestalCopy::MMcPedestalCopy(const char *name, const char *title)
61{
62 fName = name ? name : "MMcPedestalCopy";
63 fTitle = title ? title : "Copy MC pedestals into MPedestal Container";
64
65 //
66 // This is not needed here using MReadMarsFile because for the
67 // RunHeader tree the auto scheme is disabled by default
68 //
69 AddToBranchList("MMcFadcHeader.fPedesMean");
70 AddToBranchList("MMcFadcHeader.fElecNoise");
71}
72
73// --------------------------------------------------------------------------
74//
75// Make sure that there is a MPedestalCam object in the parameter list.
76//
77Int_t MMcPedestalCopy::PreProcess(MParList *pList)
78{
79 return pList->FindCreateObj(AddSerialNumber("MPedestalCam")) ? kTRUE : kFALSE;
80}
81
82// --------------------------------------------------------------------------
83//
84// Check for the runtype.
85// Search for MPedestalCam and MMcFadcHeader.
86//
87Bool_t MMcPedestalCopy::ReInit(MParList *pList)
88{
89 const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
90 if (!run)
91 {
92 *fLog << warn << dbginf << "Warning - cannot check file type, " << AddSerialNumber("MRawRunHeader") << " not found." << endl;
93 return kTRUE;
94 }
95
96 //
97 // If it is no MC file skip this function...
98 //
99 if (!run->IsMonteCarloRun())
100 {
101 *fLog << inf << "This is no MC file... skipping." << endl;
102 return kTRUE;
103 }
104
105 MPedestalCam *pedcam = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
106 if (!pedcam)
107 {
108 *fLog << err << "MPedestalCam not found... aborting." << endl;
109 return kFALSE;
110 }
111
112 // Get MMcRunHeader to check camera version
113 MMcRunHeader *mcrun = (MMcRunHeader*)pList->FindObject(AddSerialNumber("MMcRunHeader"));
114
115 // Check if it is a ceres file
116 if (mcrun && mcrun->IsCeres())
117 {
118 *fLog << inf << "This is a ceres file... subtracting Baseline from ElectronicNoise [MPedestalCam]." << endl;
119
120 MPedestalCam *noise = (MPedestalCam*)pList->FindObject(AddSerialNumber("ElectronicNoise"), "MPedestalCam");
121 if (!noise)
122 {
123 *fLog << err << "ElectronicNoise [MPedestalCam] not found... aborting." << endl;
124 return kFALSE;
125 }
126
127 const int num = pedcam->GetSize();
128 for (int i=0; i<num; i++)
129 {
130 const MPedestalPix &n = (*noise)[i];
131
132 (*pedcam)[i].Set(n.GetPedestal()/run->GetScale(),
133 n.GetPedestalRms()/run->GetScale());
134 }
135
136 pedcam->SetReadyToSave();
137
138 return kTRUE;
139 }
140
141 //
142 // Now check the existance of all necessary containers. This has
143 // to be done only if this is a MC file.
144 //
145 MMcFadcHeader *fadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
146 if (!fadc)
147 {
148 *fLog << err << "MMcFadcHeader not found... aborting." << endl;
149 return kFALSE;
150 }
151
152 if (!mcrun)
153 *fLog << warn << dbginf << AddSerialNumber("MMcRunHeader") << " not found... assuming camera<0.7" << endl;
154
155 const Bool_t camver70 = mcrun && mcrun->GetCamVersion()>=70;
156
157 const int num = pedcam->GetSize();
158 for (int i=0; i<num; i++)
159 {
160 // Here one should compute the Pedestal taking into account how
161 // the MC makes the transformation analogic-digital for the FADC.
162 // This is done only once per file -> not time critical.
163 const Float_t pedest = fadc->GetPedestal(i);
164 const Float_t sigma = camver70 ? fadc->GetPedestalRmsHigh(i) : fadc->GetElecNoise(i);
165
166 (*pedcam)[i].Set(pedest/run->GetScale(), sigma/run->GetScale());
167 }
168
169 if (camver70)
170 pedcam->SetReadyToSave();
171
172 return kTRUE;
173}
Note: See TracBrowser for help on using the repository browser.