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

Last change on this file since 4061 was 4061, checked in by jlopez, 21 years ago
*** empty log message ***
File size: 6.0 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
45ClassImp(MCalibrateDC);
46using namespace std;
47
48MCalibrateDC::MCalibrateDC(TString filename, const char *name, const char *title)
49{
50 fName = name ? name : "MCalibrateDC";
51 fTitle = title ? title : "Taks to intercalibrate the DC of all pmts from a continuos light run";
52
53 fStartingMissCalibration.Set(2004,3,8);
54 fEndingMissCalibration.Set(2004,4,15);
55
56 fDCMissCalibrationFactor = 30./40.96;
57 fFileName = filename;
58
59 Int_t nbins = 120;
60 Float_t min = 0;
61 Float_t max = 30.;
62 fCalHist = new TH1F("calhist","",nbins,min,max);
63
64 fDCCalibration = 1.;
65 fDCCalibrationRMS = 0.;
66}
67MCalibrateDC::~MCalibrateDC()
68{
69 delete fCalHist;
70}
71
72Int_t MCalibrateDC::PreProcess(MParList *pList)
73{
74
75 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
76
77 if (!fGeomCam)
78 {
79 *fLog << err << AddSerialNumber("MGeomCam") << " not found ... aborting" << endl;
80 return kFALSE;
81 }
82
83 fCurr = (MCameraDC*)pList->FindObject(AddSerialNumber("MCameraDC"));
84
85 if (!fCurr)
86 {
87 *fLog << err << AddSerialNumber("MCameraDC") << " not found ... aborting" << endl;
88 return kFALSE;
89 }
90
91 fTimeCurr = (MTime*)pList->FindObject(AddSerialNumber("MTimeCurrents"));
92
93 if (!fTimeCurr)
94 {
95 *fLog << err << AddSerialNumber("MTimeCurrents") << " not found ... aborting" << endl;
96 return kFALSE;
97 }
98
99 // Run over the continuos light run to get the DC intercalibration factors
100 fNumPixels = fGeomCam->GetNumPixels();
101 fDCCalibrationFactor.Set(fNumPixels);
102 fDCCalibrationFactor.Reset(1.);
103
104 if ( fFileName != "" )
105 {
106 // FIXME::Here it should be done the loop over the continuos light run
107 DCCalibrationCalc();
108
109 for (UInt_t pix=1; pix<fNumPixels; pix++)
110 fDCCalibrationFactor[pix] = fDCCalibration/fDisplay[pix];
111
112 }
113
114 return kTRUE;
115}
116
117Int_t MCalibrateDC::Process()
118{
119
120 if (*fTimeCurr >= fStartingMissCalibration && *fTimeCurr <= fEndingMissCalibration)
121 {
122 for (UInt_t pix=1; pix<fNumPixels; pix++)
123 {
124 MGeomPix& pixel = (*fGeomCam)[pix];
125 if (pixel.GetSector() >=3 && pixel.GetSector() <=5)
126 fDCCalibrationFactor[pix]*=fDCMissCalibrationFactor;
127 }
128 }
129
130 for (UInt_t pix=1; pix<fNumPixels; pix++)
131 (*fCurr)[pix]= (*fCurr)[pix]*fDCCalibrationFactor[pix];
132
133 return kTRUE;
134}
135
136Bool_t MCalibrateDC::DCCalibrationCalc()
137{
138
139 for (UInt_t pix=1; pix<fNumPixels; pix++)
140 fCalHist->Fill(fDisplay.GetBinContent(pix+1));
141
142 Float_t nummaxprobdc = fCalHist->GetBinContent(fCalHist->GetMaximumBin());
143 Float_t maxprobdc = fCalHist->GetBinCenter(fCalHist->GetMaximumBin());
144 UInt_t bin = fCalHist->GetMaximumBin();
145 do
146 {
147 bin++;
148 }
149 while(fCalHist->GetBinContent(bin)/nummaxprobdc > 0.5);
150 Float_t halfmaxprobdc = fCalHist->GetBinCenter(bin);
151
152 *fLog << dbg << " maxprobdc[high] " << maxprobdc << "[" << nummaxprobdc << "] ";
153 *fLog << dbg << " halfmaxprobdc[high] " << halfmaxprobdc << "[" << fCalHist->GetBinContent(bin) << "]" << endl;
154
155 Float_t rmsguess = TMath::Abs(maxprobdc-halfmaxprobdc);
156 Float_t min = maxprobdc-3*rmsguess;
157 min = (min<0.?0.:min);
158 Float_t max = maxprobdc+3*rmsguess;
159
160 *fLog << dbg << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
161
162 TF1 func("func","gaus",min,max);
163 func.SetParameters(nummaxprobdc, maxprobdc, rmsguess);
164
165 fCalHist->Fit("func","QR0");
166
167 UInt_t aproxnumdegrees = 6*(bin-fCalHist->GetMaximumBin());
168 Float_t chiq = func.GetChisquare();
169 fDCCalibration = func.GetParameter(1);
170 fDCCalibrationRMS = func.GetParameter(2);
171
172 *fLog << dbg << " fDCCalibration " << fDCCalibration << " fDCCalibrationRMS " << fDCCalibrationRMS << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
173
174 Int_t numsigmas = 5;
175 Axis_t minbin = fDCCalibration-numsigmas*fDCCalibrationRMS/fCalHist->GetBinWidth(1);
176 minbin=minbin<1?1:minbin;
177 Axis_t maxbin = fDCCalibration+numsigmas*fDCCalibrationRMS/fCalHist->GetBinWidth(1);
178 *fLog << dbg << " Number of pixels with dc under " << numsigmas << " sigmas = " << fCalHist->Integral((int)minbin,(int)maxbin) << endl;
179
180 //Check results from the fit are consistent
181 if (TMath::Abs(fDCCalibration-maxprobdc) > rmsguess || fDCCalibrationRMS > rmsguess)
182 {
183 *fLog << warn << GetName() << " Calibration DC fit give non consistent results." << endl;
184 *fLog << warn << " maxprobdc " << maxprobdc << " rmsguess " << rmsguess << endl;
185 *fLog << warn << " fDCCalibration " << fDCCalibration << " fDCCalibrationRMS " << fDCCalibrationRMS << " chiq/ndof " << chiq << "/" << aproxnumdegrees << endl;
186 fDCCalibration = maxprobdc;
187 fDCCalibrationRMS = rmsguess/1.175; // FWHM=2.35*rms
188 }
189
190 return kTRUE;
191}
192
Note: See TracBrowser for help on using the repository browser.