source: trunk/MagicSoft/Mars/mtemp/mifae/library/MCalibrateDC.cc@ 4075

Last change on this file since 4075 was 4075, checked in by jlopez, 20 years ago
*** empty log message ***
File size: 7.9 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! Author(s): Javier López , 5/2004 <mailto:jlopez@ifae.es>
18!
19! Copyright: MAGIC Software Development, 2000-2004
20!
21!
22\* ======================================================================== */
23
24/////////////////////////////////////////////////////////////////////////////
25//
26// MCalibrateDC
27//
28/////////////////////////////////////////////////////////////////////////////
29#include "MCalibrateDC.h"
30
31#include <TString.h>
32#include <TH1F.h>
33#include <TF1.h>
34
35#include "MLog.h"
36#include "MLogManip.h"
37
38#include "MGeomCam.h"
39#include "MGeomPix.h"
40#include "MCameraDC.h"
41#include "MTime.h"
42
43#include "MParList.h"
44#include "MTaskList.h"
45#include "MEvtLoop.h"
46
47#include "MReadReports.h"
48#include "MGeomApply.h"
49
50ClassImp(MCalibrateDC);
51using namespace std;
52
53MCalibrateDC::MCalibrateDC(TString filename, const char *name, const char *title) : fMinDCAllowed(0.5) //[ua]
54{
55 fName = name ? name : "MCalibrateDC";
56 fTitle = title ? title : "Taks to intercalibrate the DC of all pmts from a continuos light run";
57
58 fFileName = filename;
59
60 fStartingMissCalibration.Set(2004,3,8);
61 fEndingMissCalibration.Set(2004,4,15);
62
63 Int_t nbins = 120;
64 Float_t min = 0;
65 Float_t max = 30.;
66 fCalHist = new TH1F("calhist","",nbins,min,max);
67
68 fDCCalibration = 1.;
69 fDCCalibrationRMS = 0.;
70
71 fDCMissCalibrationFactor = 30./40.95;
72}
73MCalibrateDC::~MCalibrateDC()
74{
75 delete fCalHist;
76}
77
78Int_t MCalibrateDC::PreProcess(MParList *pList)
79{
80
81 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
82
83 if (!fGeomCam)
84 {
85 *fLog << err << AddSerialNumber("MGeomCam") << " not found ... aborting" << endl;
86 return kFALSE;
87 }
88
89 // Initialization of objects that need the information from MGeomCam
90 fDisplay.SetGeometry(*fGeomCam);
91 fNumPixels = fGeomCam->GetNumPixels();
92
93 fCurr = (MCameraDC*)pList->FindObject(AddSerialNumber("MCameraDC"));
94
95 if (!fCurr)
96 {
97 *fLog << err << AddSerialNumber("MCameraDC") << " not found ... aborting" << endl;
98 return kFALSE;
99 }
100
101 fTimeCurr = (MTime*)pList->FindObject(AddSerialNumber("MTimeCurrents"));
102
103 if (!fTimeCurr)
104 {
105 *fLog << err << AddSerialNumber("MTimeCurrents") << " not found ... aborting" << endl;
106 return kFALSE;
107 }
108
109 // Run over the continuos light run to get the DC intercalibration factors
110 fDCCalibrationFactor.Set(fNumPixels);
111 fDCCalibrationFactor.Reset(1.);
112
113 if ( fFileName != "" )
114 {
115 ProcessFile();
116 DCCalibrationCalc();
117
118 UInt_t numPixelsSetUnsuedForDC = 0;
119
120 for (UInt_t pix=1; pix<fNumPixels; pix++)
121 {
122 if (fDisplay.GetBinContent(pix+1) > fMinDCAllowed)
123 fDCCalibrationFactor[pix] = fDCCalibration/fDisplay.GetBinContent(pix+1);
124 else
125 {
126 numPixelsSetUnsuedForDC++;
127 fDCCalibrationFactor[pix] = 0.; //FIXME: Maybe to introduce a setunused in MCameraDC ?
128 }
129 }
130
131 *fLog << inf << GetName() << " set unused " << numPixelsSetUnsuedForDC << " because too low dc." << endl;
132
133 }
134
135 return kTRUE;
136}
137
138Int_t MCalibrateDC::Process()
139{
140
141 if (*fTimeCurr >= fStartingMissCalibration && *fTimeCurr <= fEndingMissCalibration)
142 {
143 for (UInt_t pix=1; pix<fNumPixels; pix++)
144 {
145 MGeomPix& pixel = (*fGeomCam)[pix];
146 if (pixel.GetSector() >=3 && pixel.GetSector() <=5)
147 (*fCurr)[pix] *= fDCCalibrationFactor[pix]*fDCMissCalibrationFactor;
148 else
149 (*fCurr)[pix] *= fDCCalibrationFactor[pix];
150
151 }
152 }
153 else
154 for (UInt_t pix=1; pix<fNumPixels; pix++)
155 (*fCurr)[pix] *= fDCCalibrationFactor[pix];
156
157 return kTRUE;
158}
159
160Bool_t MCalibrateDC::ProcessFile()
161{
162
163 MParList plist;
164 MTaskList tlist;
165 plist.AddToList(&tlist);
166
167 MCameraDC dccam;
168 plist.AddToList(&dccam);
169
170 // Reads the trees of the root file and the analysed branches
171 MReadReports read;
172 read.AddTree("Currents");
173 read.AddFile(fFileName); // after the reading of the trees!!!
174 read.AddToBranchList("MReportCurrents.*");
175
176 MGeomApply geomapl;
177
178 tlist.AddToList(&geomapl);
179 tlist.AddToList(&read);
180
181 // Enable logging to file
182 //*fLog.SetOutputFile(lname, kTRUE);
183
184 //
185 // Execute the eventloop
186 //
187 MEvtLoop evtloop(fName);
188 evtloop.SetParList(&plist);
189 evtloop.SetLogStream(fLog);
190
191 // Execute first analysis
192 if (!evtloop.PreProcess())
193 {
194 *fLog << err << GetDescriptor() << ": Failed." << endl;
195 return kFALSE;
196 }
197
198 while (tlist.Process())
199 fDisplay.AddCamContent(dccam);
200
201 evtloop.PostProcess();
202
203 tlist.PrintStatistics();
204
205 UInt_t numexecutions = read.GetNumExecutions();
206 UInt_t numPixels = fDisplay.GetNumPixels();
207 for (UInt_t pix = 1; pix <= numPixels; pix++)
208 fDisplay[pix] /= numexecutions;
209
210
211 *fLog << inf << GetDescriptor() << ": Done." << endl;
212
213 return kTRUE;
214}
215
216Bool_t MCalibrateDC::DCCalibrationCalc()
217{
218
219 for (UInt_t pix=1; pix<fNumPixels; pix++)
220 fCalHist->Fill(fDisplay.GetBinContent(pix+1));
221
222 Float_t nummaxprobdc = fCalHist->GetBinContent(fCalHist->GetMaximumBin());
223 Float_t maxprobdc = fCalHist->GetBinCenter(fCalHist->GetMaximumBin());
224 UInt_t bin = fCalHist->GetMaximumBin();
225 do
226 {
227 bin++;
228 }
229 while(fCalHist->GetBinContent(bin)/nummaxprobdc > 0.5);
230 Float_t halfmaxprobdc = fCalHist->GetBinCenter(bin);
231
232 *fLog << dbg << " maxprobdc[high] " << maxprobdc << "[" << nummaxprobdc << "] ";
233 *fLog << dbg << " halfmaxprobdc[high] " << halfmaxprobdc << "[" << fCalHist->GetBinContent(bin) << "]" << endl;
234
235 Float_t rmsguess = TMath::Abs(maxprobdc-halfmaxprobdc);
236 Float_t min = maxprobdc-3*rmsguess;
237 min = (min<0.?0.:min);
238 Float_t max = maxprobdc+3*rmsguess;
239
240 *fLog << dbg << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
241
242 TF1 func("func","gaus",min,max);
243 func.SetParameters(nummaxprobdc, maxprobdc, rmsguess);
244
245 fCalHist->Fit("func","QR0");
246
247 UInt_t aproxnumdegrees = 6*(bin-fCalHist->GetMaximumBin());
248 Float_t chiq = func.GetChisquare();
249 fDCCalibration = func.GetParameter(1);
250 fDCCalibrationRMS = func.GetParameter(2);
251
252 *fLog << dbg << " fDCCalibration " << fDCCalibration << " fDCCalibrationRMS " << fDCCalibrationRMS << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
253
254 Int_t numsigmas = 5;
255 Axis_t minbin = fDCCalibration-numsigmas*fDCCalibrationRMS/fCalHist->GetBinWidth(1);
256 minbin=minbin<1?1:minbin;
257 Axis_t maxbin = fDCCalibration+numsigmas*fDCCalibrationRMS/fCalHist->GetBinWidth(1);
258 *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << fCalHist->Integral((int)minbin,(int)maxbin) << endl;
259
260 //Check results from the fit are consistent
261 if (TMath::Abs(fDCCalibration-maxprobdc) > rmsguess || fDCCalibrationRMS > rmsguess)
262 {
263 *fLog << warn << GetName() << " Calibration DC fit give non consistent results." << endl;
264 *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
265 *fLog << warn << " fDCCalibration " << fDCCalibration << " fDCCalibrationRMS " << fDCCalibrationRMS << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
266 fDCCalibration = maxprobdc;
267 fDCCalibrationRMS = rmsguess/1.175; // FWHM=2.35*rms
268 }
269
270 return kTRUE;
271}
272
Note: See TracBrowser for help on using the repository browser.