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 | // Input Containers:
|
---|
30 | // MRawRunHeader
|
---|
31 | // MMcFadcHeader
|
---|
32 | // MHillas
|
---|
33 | // MNewImagePar
|
---|
34 | // MMcEvt
|
---|
35 | //
|
---|
36 | // Output Containers:
|
---|
37 | // MCalibrationCam
|
---|
38 | //
|
---|
39 | /////////////////////////////////////////////////////////////////////////////
|
---|
40 | #include "MMcCalibrationCalc.h"
|
---|
41 |
|
---|
42 | #include "MParList.h"
|
---|
43 |
|
---|
44 | #include "MLog.h"
|
---|
45 | #include "MLogManip.h"
|
---|
46 |
|
---|
47 | #include "MCalibrationPix.h"
|
---|
48 | #include "MCalibrationCam.h"
|
---|
49 | #include "MGeomCam.h"
|
---|
50 | #include "MRawRunHeader.h"
|
---|
51 | #include "MMcFadcHeader.hxx"
|
---|
52 | #include "MHillas.h"
|
---|
53 | #include "MNewImagePar.h"
|
---|
54 | #include "MMcEvt.hxx"
|
---|
55 |
|
---|
56 | ClassImp(MMcCalibrationCalc);
|
---|
57 |
|
---|
58 | using namespace std;
|
---|
59 |
|
---|
60 | MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
|
---|
61 | {
|
---|
62 | fName = name ? name : "MMcCalibrationCalc";
|
---|
63 | fTitle = title ? title : "Calculate and write conversion factors into MCalibrationCam Container";
|
---|
64 |
|
---|
65 | fADC2Phot = 0.;
|
---|
66 | fEvents = 0;
|
---|
67 |
|
---|
68 | fHistRatio = new TH1F("HistRatio", "Ratio fPassPhotCone/fSize", 1000., 0., 10.);
|
---|
69 | }
|
---|
70 |
|
---|
71 | // --------------------------------------------------------------------------
|
---|
72 | //
|
---|
73 | // Check for the run type. Return kTRUE if it is a MC run or if there
|
---|
74 | // is no MC run header (old camera files) kFALSE in case of a different
|
---|
75 | // run type
|
---|
76 | //
|
---|
77 | Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
|
---|
78 | {
|
---|
79 | const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
80 | if (!run)
|
---|
81 | {
|
---|
82 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
83 | return kTRUE;
|
---|
84 | }
|
---|
85 |
|
---|
86 | return run->GetRunType() == kRTMonteCarlo;
|
---|
87 | }
|
---|
88 |
|
---|
89 | // --------------------------------------------------------------------------
|
---|
90 | //
|
---|
91 | // Make sure, that there is an MCalibrationCam Object in the Parameter List.
|
---|
92 | //
|
---|
93 | Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
|
---|
94 | {
|
---|
95 | //
|
---|
96 | // If it is no MC file display error and exit
|
---|
97 | //
|
---|
98 | if (!CheckRunType(pList))
|
---|
99 | {
|
---|
100 | *fLog << err << dbginf << "This is no MC file... aborting." << endl;
|
---|
101 | return kFALSE;
|
---|
102 | }
|
---|
103 |
|
---|
104 | fCalCam = (MCalibrationCam*) pList->FindObject(AddSerialNumber("MCalibrationCam"));
|
---|
105 |
|
---|
106 | if ( !fCalCam )
|
---|
107 | {
|
---|
108 | *fLog << err << dbginf << "Cannot find MCalibrationCam... aborting." << endl;
|
---|
109 | return kFALSE;
|
---|
110 | }
|
---|
111 |
|
---|
112 | fHillas = (MHillas*) pList->FindCreateObj(AddSerialNumber("MHillas"));
|
---|
113 | if ( !fHillas)
|
---|
114 | {
|
---|
115 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MHillas") << "... aborting." << endl;
|
---|
116 | return kFALSE;
|
---|
117 | }
|
---|
118 |
|
---|
119 | fNew = (MNewImagePar*) pList->FindCreateObj(AddSerialNumber("MNewImagePar"));
|
---|
120 | if ( !fNew)
|
---|
121 | {
|
---|
122 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MNewImagePar") << "... aborting." << endl;
|
---|
123 | return kFALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 | fMcEvt = (MMcEvt*) pList->FindCreateObj(AddSerialNumber("MMcEvt"));
|
---|
127 | if ( !fMcEvt)
|
---|
128 | {
|
---|
129 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MMcEvt") << "... aborting." << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | return kTRUE;
|
---|
134 |
|
---|
135 | }
|
---|
136 |
|
---|
137 | // --------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // Check for the runtype.
|
---|
140 | // Search for MGeomCam and MMcFadcHeader.
|
---|
141 | //
|
---|
142 | Bool_t MMcCalibrationCalc::ReInit(MParList *pList)
|
---|
143 | {
|
---|
144 | //
|
---|
145 | // Now check the existence of all necessary containers.
|
---|
146 | //
|
---|
147 |
|
---|
148 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
149 | if ( ! fGeom )
|
---|
150 | {
|
---|
151 | *fLog << err << dbginf << "Cannot find MGeomCam... aborting." << endl;
|
---|
152 | return kFALSE;
|
---|
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 | //
|
---|
163 | // FIXME: Check that the relevant parameters in the FADC header are the
|
---|
164 | // same for all the analyzed data!
|
---|
165 | //
|
---|
166 |
|
---|
167 | return kTRUE;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | // --------------------------------------------------------------------------
|
---|
172 | //
|
---|
173 | // Obtain average ratio of photons in camera to image Size.
|
---|
174 | //
|
---|
175 | Int_t MMcCalibrationCalc::Process()
|
---|
176 | {
|
---|
177 |
|
---|
178 | if ( fNew->GetNumSaturatedPixels() > 0 )
|
---|
179 | return kTRUE;
|
---|
180 |
|
---|
181 | fADC2Phot += fMcEvt->GetPassPhotCone() / fHillas->GetSize();
|
---|
182 | fEvents ++;
|
---|
183 |
|
---|
184 | fHistRatio->Fill(fMcEvt->GetPassPhotCone()/fHillas->GetSize());
|
---|
185 |
|
---|
186 | return kTRUE;
|
---|
187 | }
|
---|
188 |
|
---|
189 | // --------------------------------------------------------------------------
|
---|
190 | //
|
---|
191 | // Fill the MCalibrationCam object
|
---|
192 | //
|
---|
193 | Int_t MMcCalibrationCalc::PostProcess()
|
---|
194 | {
|
---|
195 |
|
---|
196 | if (fEvents > 0)
|
---|
197 | fADC2Phot /= fEvents;
|
---|
198 | else
|
---|
199 | {
|
---|
200 | *fLog << err << dbginf << "No events were read! Aborting." << endl;
|
---|
201 | return kFALSE;
|
---|
202 | }
|
---|
203 |
|
---|
204 | const int num = fCalCam->GetSize();
|
---|
205 |
|
---|
206 | for (int i=0; i<num; i++)
|
---|
207 | {
|
---|
208 | MCalibrationPix &calpix = (*fCalCam)[i];
|
---|
209 |
|
---|
210 | Float_t factor = fADC2Phot*calpix.GetMeanConversionBlindPixelMethod();
|
---|
211 |
|
---|
212 | calpix.SetConversionBlindPixelMethod(factor, 0., 0.);
|
---|
213 |
|
---|
214 | }
|
---|
215 |
|
---|
216 | return kTRUE;
|
---|
217 |
|
---|
218 | }
|
---|