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

Last change on this file since 4073 was 4073, checked in by jlopez, 20 years ago
*** empty log message ***
File size: 7.5 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)
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 for (UInt_t pix=1; pix<fNumPixels; pix++)
119 fDCCalibrationFactor[pix] = fDCCalibration/fDisplay[pix];
120
121 }
122
123 return kTRUE;
124}
125
126Int_t MCalibrateDC::Process()
127{
128
129 if (*fTimeCurr >= fStartingMissCalibration && *fTimeCurr <= fEndingMissCalibration)
130 {
131 for (UInt_t pix=1; pix<fNumPixels; pix++)
132 {
133 MGeomPix& pixel = (*fGeomCam)[pix];
134 if (pixel.GetSector() >=3 && pixel.GetSector() <=5)
135 (*fCurr)[pix] *= fDCCalibrationFactor[pix]*fDCMissCalibrationFactor;
136 else
137 (*fCurr)[pix] *= fDCCalibrationFactor[pix];
138
139 }
140 }
141 else
142 for (UInt_t pix=1; pix<fNumPixels; pix++)
143 (*fCurr)[pix] *= fDCCalibrationFactor[pix];
144
145 return kTRUE;
146}
147
148Bool_t MCalibrateDC::ProcessFile()
149{
150
151 MParList plist;
152 MTaskList tlist;
153 plist.AddToList(&tlist);
154
155 MCameraDC dccam;
156 plist.AddToList(&dccam);
157
158 // Reads the trees of the root file and the analysed branches
159 MReadReports read;
160 read.AddTree("Currents");
161 read.AddFile(fFileName); // after the reading of the trees!!!
162 read.AddToBranchList("MReportCurrents.*");
163
164 MGeomApply geomapl;
165
166 tlist.AddToList(&geomapl);
167 tlist.AddToList(&read);
168
169 // Enable logging to file
170 //*fLog.SetOutputFile(lname, kTRUE);
171
172 //
173 // Execute the eventloop
174 //
175 MEvtLoop evtloop(fName);
176 evtloop.SetParList(&plist);
177 evtloop.SetLogStream(fLog);
178
179 // Execute first analysis
180 if (!evtloop.PreProcess())
181 {
182 *fLog << err << GetDescriptor() << ": Failed." << endl;
183 return kFALSE;
184 }
185
186 while (tlist.Process())
187 fDisplay.AddCamContent(dccam);
188
189 evtloop.PostProcess();
190
191 tlist.PrintStatistics();
192
193 UInt_t numexecutions = read.GetNumExecutions();
194 UInt_t numPixels = fDisplay.GetNumPixels();
195 for (UInt_t pix = 1; pix < numPixels; pix++)
196 fDisplay[pix] /= numexecutions;
197
198
199 *fLog << inf << GetDescriptor() << ": Done." << endl;
200
201 return kTRUE;
202}
203
204Bool_t MCalibrateDC::DCCalibrationCalc()
205{
206
207 for (UInt_t pix=1; pix<fNumPixels; pix++)
208 fCalHist->Fill(fDisplay.GetBinContent(pix+1));
209
210 Float_t nummaxprobdc = fCalHist->GetBinContent(fCalHist->GetMaximumBin());
211 Float_t maxprobdc = fCalHist->GetBinCenter(fCalHist->GetMaximumBin());
212 UInt_t bin = fCalHist->GetMaximumBin();
213 do
214 {
215 bin++;
216 }
217 while(fCalHist->GetBinContent(bin)/nummaxprobdc > 0.5);
218 Float_t halfmaxprobdc = fCalHist->GetBinCenter(bin);
219
220 *fLog << dbg << " maxprobdc[high] " << maxprobdc << "[" << nummaxprobdc << "] ";
221 *fLog << dbg << " halfmaxprobdc[high] " << halfmaxprobdc << "[" << fCalHist->GetBinContent(bin) << "]" << endl;
222
223 Float_t rmsguess = TMath::Abs(maxprobdc-halfmaxprobdc);
224 Float_t min = maxprobdc-3*rmsguess;
225 min = (min<0.?0.:min);
226 Float_t max = maxprobdc+3*rmsguess;
227
228 *fLog << dbg << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
229
230 TF1 func("func","gaus",min,max);
231 func.SetParameters(nummaxprobdc, maxprobdc, rmsguess);
232
233 fCalHist->Fit("func","QR0");
234
235 UInt_t aproxnumdegrees = 6*(bin-fCalHist->GetMaximumBin());
236 Float_t chiq = func.GetChisquare();
237 fDCCalibration = func.GetParameter(1);
238 fDCCalibrationRMS = func.GetParameter(2);
239
240 *fLog << dbg << " fDCCalibration " << fDCCalibration << " fDCCalibrationRMS " << fDCCalibrationRMS << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
241
242 Int_t numsigmas = 5;
243 Axis_t minbin = fDCCalibration-numsigmas*fDCCalibrationRMS/fCalHist->GetBinWidth(1);
244 minbin=minbin<1?1:minbin;
245 Axis_t maxbin = fDCCalibration+numsigmas*fDCCalibrationRMS/fCalHist->GetBinWidth(1);
246 *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << fCalHist->Integral((int)minbin,(int)maxbin) << endl;
247
248 //Check results from the fit are consistent
249 if (TMath::Abs(fDCCalibration-maxprobdc) > rmsguess || fDCCalibrationRMS > rmsguess)
250 {
251 *fLog << warn << GetName() << " Calibration DC fit give non consistent results." << endl;
252 *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
253 *fLog << warn << " fDCCalibration " << fDCCalibration << " fDCCalibrationRMS " << fDCCalibrationRMS << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
254 fDCCalibration = maxprobdc;
255 fDCCalibrationRMS = rmsguess/1.175; // FWHM=2.35*rms
256 }
257
258 return kTRUE;
259}
260
Note: See TracBrowser for help on using the repository browser.