| 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): Markus Gaug 02/2004 <mailto:markus@ifae.es>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MHCalibrationChargePINDiode
|
|---|
| 28 | //
|
|---|
| 29 | // Histogram class for the charge calibration of the PIN Diode.
|
|---|
| 30 | // Stores and fits the charges, the RMS of the charges and stores the
|
|---|
| 31 | // location of the maximum FADC slice. Charges are taken from MExtractedSignalPINDiode.
|
|---|
| 32 | //
|
|---|
| 33 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 34 | #include "MHCalibrationChargePINDiode.h"
|
|---|
| 35 |
|
|---|
| 36 | #include <TH1.h>
|
|---|
| 37 | #include <TF1.h>
|
|---|
| 38 | #include <TPad.h>
|
|---|
| 39 | #include <TVirtualPad.h>
|
|---|
| 40 | #include <TCanvas.h>
|
|---|
| 41 |
|
|---|
| 42 | #include "MLog.h"
|
|---|
| 43 | #include "MLogManip.h"
|
|---|
| 44 |
|
|---|
| 45 | #include "MParList.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MExtractedSignalPINDiode.h"
|
|---|
| 48 | #include "MCalibrationChargePINDiode.h"
|
|---|
| 49 |
|
|---|
| 50 | ClassImp(MHCalibrationChargePINDiode);
|
|---|
| 51 |
|
|---|
| 52 | using namespace std;
|
|---|
| 53 |
|
|---|
| 54 | const Int_t MHCalibrationChargePINDiode::fgChargeNbins = 200;
|
|---|
| 55 | const Axis_t MHCalibrationChargePINDiode::fgChargeFirst = -0.5;
|
|---|
| 56 | const Axis_t MHCalibrationChargePINDiode::fgChargeLast = 199.5;
|
|---|
| 57 | const Int_t MHCalibrationChargePINDiode::fgRmsChargeNbins = 100;
|
|---|
| 58 | const Axis_t MHCalibrationChargePINDiode::fgRmsChargeFirst = 0.;
|
|---|
| 59 | const Axis_t MHCalibrationChargePINDiode::fgRmsChargeLast = 100.;
|
|---|
| 60 | const Int_t MHCalibrationChargePINDiode::fgAbsTimeNbins = 30;
|
|---|
| 61 | const Axis_t MHCalibrationChargePINDiode::fgAbsTimeFirst = -0.5;
|
|---|
| 62 | const Axis_t MHCalibrationChargePINDiode::fgAbsTimeLast = 29.5;
|
|---|
| 63 | // --------------------------------------------------------------------------
|
|---|
| 64 | //
|
|---|
| 65 | // Default Constructor.
|
|---|
| 66 | //
|
|---|
| 67 | // Sets:
|
|---|
| 68 | // - the default number for MHGausEvents::fNbins (fgChargeNbins)
|
|---|
| 69 | // - the default number for MHGausEvents::fFirst (fgChargeFirst)
|
|---|
| 70 | // - the default number for MHGausEvents::fLast (fgChargeLast)
|
|---|
| 71 | // - the default number for fRmsChargeNbins (fgRmsChargeNbins)
|
|---|
| 72 | // - the default number for fRmsChargeFirst (fgRmsChargeFirst)
|
|---|
| 73 | // - the default number for fRmsChargeLast (fgRmsChargeLast)
|
|---|
| 74 | // - the default number for fAbsTimeNbins (fgAbsTimeNbins)
|
|---|
| 75 | // - the default number for fAbsTimeFirst (fgAbsTimeFirst)
|
|---|
| 76 | // - the default number for fAbsTimeLast (fgAbsTimeLast)
|
|---|
| 77 | //
|
|---|
| 78 | // - the default name of the fHGausHist ("HCalibrationChargePINDiode")
|
|---|
| 79 | // - the default title of the fHGausHist ("Distribution of Summed FADC slices PIN Diode")
|
|---|
| 80 | // - the default x-axis title for fHGausHist ("Sum FADC Slices")
|
|---|
| 81 | // - the default y-axis title for fHGausHist ("Nr. of events")
|
|---|
| 82 | // - the default name of the fHAbsTime ("HAbsTimePINDiode")
|
|---|
| 83 | // - the default title of the fHAbsTime ("Distribution of Absolute Arrival Times PIN Diode")
|
|---|
| 84 | // - the default x-axis title for fHAbsTime ("Absolute Arrival Time [FADC slice nr]")
|
|---|
| 85 | // - the default y-axis title for fHAbsTime ("Nr. of events")
|
|---|
| 86 | // - the default name of the fHRmsCharge ("HRmsChargePINDiode")
|
|---|
| 87 | // - the default title of the fHRmsCharge ("Distribution of Variances of summed FADC slices PIN Diode")
|
|---|
| 88 | // - the default x-axis title for fHRmsCharge ("RMS (sum) [FADC slices]")
|
|---|
| 89 | // - the default y-axis title for fHRmsCharge ("Nr. of events")
|
|---|
| 90 | // - the default directory of the fHRmsCharge (NULL)
|
|---|
| 91 | // - the current style for fHRmsCharge (NULL)
|
|---|
| 92 | //
|
|---|
| 93 | // Initializes:
|
|---|
| 94 | // - fHRmsCharge()
|
|---|
| 95 | // - all pointers to NULL
|
|---|
| 96 | //
|
|---|
| 97 | // Calls:
|
|---|
| 98 | // - Clear()
|
|---|
| 99 | //
|
|---|
| 100 | MHCalibrationChargePINDiode::MHCalibrationChargePINDiode(const char *name, const char *title)
|
|---|
| 101 | : fPINDiode(NULL), fHRmsCharge()
|
|---|
| 102 | {
|
|---|
| 103 |
|
|---|
| 104 | fName = name ? name : "MHCalibrationChargePINDiode";
|
|---|
| 105 | fTitle = title ? title : "Fill the FADC sums of the PINDiode events and perform the fits";
|
|---|
| 106 |
|
|---|
| 107 | SetNbins( fgChargeNbins );
|
|---|
| 108 | SetFirst( fgChargeFirst );
|
|---|
| 109 | SetLast ( fgChargeLast );
|
|---|
| 110 |
|
|---|
| 111 | SetRmsChargeNbins();
|
|---|
| 112 | SetRmsChargeFirst();
|
|---|
| 113 | SetRmsChargeLast();
|
|---|
| 114 |
|
|---|
| 115 | SetAbsTimeNbins();
|
|---|
| 116 | SetAbsTimeFirst();
|
|---|
| 117 | SetAbsTimeLast();
|
|---|
| 118 |
|
|---|
| 119 | fHGausHist.SetName("HCalibrationChargePINDiode");
|
|---|
| 120 | fHGausHist.SetTitle("Distribution of Summed FADC slices PIN Diode");
|
|---|
| 121 | fHGausHist.SetXTitle("Sum FADC Slices");
|
|---|
| 122 | fHGausHist.SetYTitle("Nr. of events");
|
|---|
| 123 |
|
|---|
| 124 | fHAbsTime.SetName("HAbsTimePINDiode");
|
|---|
| 125 | fHAbsTime.SetTitle("Distribution of Absolute Arrival Times PIN Diode");
|
|---|
| 126 | fHAbsTime.SetXTitle("Absolute Arrival Time [FADC slice nr]");
|
|---|
| 127 | fHAbsTime.SetYTitle("Nr. of events");
|
|---|
| 128 |
|
|---|
| 129 | fHRmsCharge.SetName("HRmsChargePINDiode");
|
|---|
| 130 | fHRmsCharge.SetTitle("Distribution of Variances of summed FADC slices PIN Diode");
|
|---|
| 131 | fHRmsCharge.SetXTitle("RMS (sum) [FADC slices]");
|
|---|
| 132 | fHRmsCharge.SetYTitle("Nr. of events");
|
|---|
| 133 | fHRmsCharge.UseCurrentStyle();
|
|---|
| 134 | fHRmsCharge.SetDirectory(NULL);
|
|---|
| 135 |
|
|---|
| 136 | Clear();
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | // --------------------------------------------------------------------------
|
|---|
| 140 | //
|
|---|
| 141 | // Initializes Binning of the following histograms:
|
|---|
| 142 | // - fHGausHist.SetBins(fNbins,fFirst,fLast);
|
|---|
| 143 | // - fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
|
|---|
| 144 | // - fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
|
|---|
| 145 | //
|
|---|
| 146 | Bool_t MHCalibrationChargePINDiode::SetupFill(const MParList *pList)
|
|---|
| 147 | {
|
|---|
| 148 |
|
|---|
| 149 | MHGausEvents::InitBins();
|
|---|
| 150 |
|
|---|
| 151 | fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
|
|---|
| 152 | fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
|
|---|
| 153 |
|
|---|
| 154 | return kTRUE;
|
|---|
| 155 |
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | // --------------------------------------------------------------------------
|
|---|
| 159 | //
|
|---|
| 160 | // Gets or creates the pointers to:
|
|---|
| 161 | // - MCalibrationChargePINDiode
|
|---|
| 162 | //
|
|---|
| 163 | Bool_t MHCalibrationChargePINDiode::ReInit(MParList *pList)
|
|---|
| 164 | {
|
|---|
| 165 |
|
|---|
| 166 | fPINDiode = (MCalibrationChargePINDiode*)pList->FindCreateObj("MCalibrationChargePINDiode");
|
|---|
| 167 | if (!fPINDiode)
|
|---|
| 168 | {
|
|---|
| 169 | *fLog << err << "MCalibrationChargePINDiode not found... aborting " << endl;
|
|---|
| 170 | return kFALSE;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | return kTRUE;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | // --------------------------------------------------------------------------
|
|---|
| 177 | //
|
|---|
| 178 | // Retrieves from MExtractedSignalPINDiode:
|
|---|
| 179 | // - Number of used FADC samples via MExtractedSignalPINDiode::GetNumFADCSamples()
|
|---|
| 180 | // - Extracted signal via MExtractedSignalPINDiode::GetExtractedSignal()
|
|---|
| 181 | // - Signal Rms MExtractedSignalPINDiode::GetExtractedRms()
|
|---|
| 182 | // - Arrival Time MExtractedSignalPINDiode::GetExtractedTime()
|
|---|
| 183 | //
|
|---|
| 184 | // Fills the following histograms:
|
|---|
| 185 | // - MHGausEvents::FillHistAndArray(signal)
|
|---|
| 186 | // - MHCalibrationChargePix::FillAbsTime(time);
|
|---|
| 187 | // - FillRmsCharge(rms);
|
|---|
| 188 | //
|
|---|
| 189 | Bool_t MHCalibrationChargePINDiode::Fill(const MParContainer *par, const Stat_t w)
|
|---|
| 190 | {
|
|---|
| 191 |
|
|---|
| 192 | MExtractedSignalPINDiode *extractor = (MExtractedSignalPINDiode*)par;
|
|---|
| 193 |
|
|---|
| 194 | if (!extractor)
|
|---|
| 195 | {
|
|---|
| 196 | *fLog << err << "No argument in MExtractedSignalPINDiode::Fill... abort." << endl;
|
|---|
| 197 | return kFALSE;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | Float_t slices = (Float_t)extractor->GetNumFADCSamples();
|
|---|
| 201 |
|
|---|
| 202 | if (slices == 0.)
|
|---|
| 203 | {
|
|---|
| 204 | *fLog << err << "Number of used signal slices in MExtractedSignalPINDiode is zero ... abort."
|
|---|
| 205 | << endl;
|
|---|
| 206 | return kFALSE;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | const Float_t signal = (float)extractor->GetExtractedSignal();
|
|---|
| 210 | const Float_t time = extractor->GetExtractedTime();
|
|---|
| 211 | const Float_t rms = extractor->GetExtractedRms();
|
|---|
| 212 |
|
|---|
| 213 | FillHistAndArray(signal);
|
|---|
| 214 | FillAbsTime(time);
|
|---|
| 215 | FillRmsCharge(rms);
|
|---|
| 216 |
|
|---|
| 217 | return kTRUE;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | // --------------------------------------------------------------------------
|
|---|
| 221 | //
|
|---|
| 222 | // Returns kTRUE, if empty
|
|---|
| 223 | //
|
|---|
| 224 | // Performs the following fits:
|
|---|
| 225 | // - MHGausEvents::FitGaus()
|
|---|
| 226 | // - FitRmsCharge()
|
|---|
| 227 | //
|
|---|
| 228 | // Creates the fourier spectrum (MHGausEvents::CreateFourierSpectrum()
|
|---|
| 229 | // and sets bit MCalibrationChargePINDiode::SetOscillating( MHGausEvents::IsFourierSpectrumOK() )
|
|---|
| 230 | // Retrieves the results of the following fits and stores them in MCalibrationChargePINDiode:
|
|---|
| 231 | // - Mean Charge and Error
|
|---|
| 232 | // - Sigma Charge and Error
|
|---|
| 233 | // - Fit Probability
|
|---|
| 234 | // - Abs Time Mean
|
|---|
| 235 | // - Abs Time Rms
|
|---|
| 236 | // - Rms Charge Mean and Error
|
|---|
| 237 | // - Rms Charge Sigma and Error
|
|---|
| 238 | //
|
|---|
| 239 | Bool_t MHCalibrationChargePINDiode::Finalize()
|
|---|
| 240 | {
|
|---|
| 241 |
|
|---|
| 242 | if (IsGausFitOK() || IsEmpty())
|
|---|
| 243 | return kTRUE;
|
|---|
| 244 |
|
|---|
| 245 | FitGaus();
|
|---|
| 246 | FitRmsCharge();
|
|---|
| 247 |
|
|---|
| 248 | CreateFourierSpectrum();
|
|---|
| 249 | fPINDiode->SetOscillating ( !IsFourierSpectrumOK() );
|
|---|
| 250 |
|
|---|
| 251 | fPINDiode->SetMean ( fMean );
|
|---|
| 252 | fPINDiode->SetMeanVar ( fMeanErr * fMeanErr );
|
|---|
| 253 | fPINDiode->SetSigma ( fSigma );
|
|---|
| 254 | fPINDiode->SetSigmaVar ( fSigmaErr * fMeanErr );
|
|---|
| 255 | fPINDiode->SetProb ( fProb );
|
|---|
| 256 |
|
|---|
| 257 | fPINDiode->SetAbsTimeMean( GetAbsTimeMean() );
|
|---|
| 258 | fPINDiode->SetAbsTimeRms( GetAbsTimeRms() );
|
|---|
| 259 |
|
|---|
| 260 | fPINDiode->SetRmsChargeMean( GetRmsChargeMean() );
|
|---|
| 261 | fPINDiode->SetRmsChargeMeanErr( GetRmsChargeMeanErr() );
|
|---|
| 262 | fPINDiode->SetRmsChargeSigma( GetRmsChargeSigma() );
|
|---|
| 263 | fPINDiode->SetRmsChargeSigmaErr( GetRmsChargeSigmaErr() );
|
|---|
| 264 |
|
|---|
| 265 | return kTRUE;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | // --------------------------------------------------------------------------
|
|---|
| 269 | //
|
|---|
| 270 | // Fills fHRmsCharge with q
|
|---|
| 271 | // Returns kFALSE, if overflow or underflow occurred, else kTRUE
|
|---|
| 272 | //
|
|---|
| 273 | Bool_t MHCalibrationChargePINDiode::FillRmsCharge(const Float_t q)
|
|---|
| 274 | {
|
|---|
| 275 | return fHRmsCharge.Fill(q) > -1;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | // -----------------------------------------------------------
|
|---|
| 279 | //
|
|---|
| 280 | // Fits -- not yet implemented
|
|---|
| 281 | //
|
|---|
| 282 | Bool_t MHCalibrationChargePINDiode::FitRmsCharge(Option_t *option)
|
|---|
| 283 | {
|
|---|
| 284 | return 1;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 | // -------------------------------------------------------------------------
|
|---|
| 289 | //
|
|---|
| 290 | // Draw the histogram
|
|---|
| 291 | //
|
|---|
| 292 | // The following options can be chosen:
|
|---|
| 293 | //
|
|---|
| 294 | // "": displays the fHGausHist with fits and fHRmsCharge
|
|---|
| 295 | // "all": executes additionally MHGausEvents::Draw(), with option "fourierevents"
|
|---|
| 296 | //
|
|---|
| 297 | void MHCalibrationChargePINDiode::Draw(const Option_t *opt)
|
|---|
| 298 | {
|
|---|
| 299 |
|
|---|
| 300 | TString option(opt);
|
|---|
| 301 | option.ToLower();
|
|---|
| 302 |
|
|---|
| 303 | Int_t win = 1;
|
|---|
| 304 |
|
|---|
| 305 | TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
|
|---|
| 306 | TVirtualPad *pad = NULL;
|
|---|
| 307 |
|
|---|
| 308 | oldpad->SetBorderMode(0);
|
|---|
| 309 |
|
|---|
| 310 | if (option.Contains("all"))
|
|---|
| 311 | {
|
|---|
| 312 | option.ReplaceAll("all","");
|
|---|
| 313 | oldpad->Divide(2,1);
|
|---|
| 314 | win = 2;
|
|---|
| 315 | oldpad->cd(1);
|
|---|
| 316 | TVirtualPad *newpad = gPad;
|
|---|
| 317 | pad = newpad;
|
|---|
| 318 | pad->Divide(1,2);
|
|---|
| 319 | pad->cd(1);
|
|---|
| 320 | }
|
|---|
| 321 | else
|
|---|
| 322 | {
|
|---|
| 323 | pad = oldpad;
|
|---|
| 324 | pad->Divide(1,2);
|
|---|
| 325 | pad->cd(1);
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | if (!IsEmpty())
|
|---|
| 329 | gPad->SetLogy();
|
|---|
| 330 |
|
|---|
| 331 | gPad->SetTicks();
|
|---|
| 332 |
|
|---|
| 333 | fHGausHist.Draw(opt);
|
|---|
| 334 | if (fFGausFit)
|
|---|
| 335 | {
|
|---|
| 336 | fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
|
|---|
| 337 | fFGausFit->Draw("same");
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | pad->cd(2);
|
|---|
| 341 | fHRmsCharge.Draw(opt);
|
|---|
| 342 |
|
|---|
| 343 | oldpad->cd(2);
|
|---|
| 344 | MHGausEvents::Draw("fourierevents");
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|