| 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, 09/2004 <mailto:markus@ifae.es>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 25 | //
|
|---|
| 26 | // MCalibColorSteer
|
|---|
| 27 | //
|
|---|
| 28 | // Steers the occurrance of different calibration colours in one calibration
|
|---|
| 29 | // run.
|
|---|
| 30 | //
|
|---|
| 31 | // Input Containers:
|
|---|
| 32 | // MCalibrationPattern
|
|---|
| 33 | // MParList
|
|---|
| 34 | // MCalibrationIntensityChargeCam
|
|---|
| 35 | // MCalibrationIntensityRelTimeCam
|
|---|
| 36 | // MBadPixelsIntensityCam
|
|---|
| 37 | //
|
|---|
| 38 | // Output Containers:
|
|---|
| 39 | // MCalibrationIntensityChargeCam
|
|---|
| 40 | // MCalibrationIntensityRelTimeCam
|
|---|
| 41 | // MBadPixelsIntensityCam
|
|---|
| 42 | //
|
|---|
| 43 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 44 | #include "MCalibColorSteer.h"
|
|---|
| 45 |
|
|---|
| 46 | #include "MLog.h"
|
|---|
| 47 | #include "MLogManip.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MParList.h"
|
|---|
| 50 | #include "MTaskList.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MHCalibrationCam.h"
|
|---|
| 53 | #include "MCalibrationChargeCam.h"
|
|---|
| 54 | #include "MCalibrationBlindCam.h"
|
|---|
| 55 |
|
|---|
| 56 | #include "MCalibrationIntensityChargeCam.h"
|
|---|
| 57 | #include "MCalibrationIntensityBlindCam.h"
|
|---|
| 58 | #include "MCalibrationIntensityQECam.h"
|
|---|
| 59 | #include "MCalibrationIntensityRelTimeCam.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MBadPixelsIntensityCam.h"
|
|---|
| 62 |
|
|---|
| 63 | #include "MCalibrationChargeCam.h"
|
|---|
| 64 | #include "MCalibrationChargeCalc.h"
|
|---|
| 65 | #include "MCalibrationRelTimeCalc.h"
|
|---|
| 66 |
|
|---|
| 67 | #include "MRawRunHeader.h"
|
|---|
| 68 | #include "MCalibrationPattern.h"
|
|---|
| 69 |
|
|---|
| 70 | #include "MGeomCam.h"
|
|---|
| 71 |
|
|---|
| 72 | ClassImp(MCalibColorSteer);
|
|---|
| 73 |
|
|---|
| 74 | using namespace std;
|
|---|
| 75 |
|
|---|
| 76 | // --------------------------------------------------------------------------
|
|---|
| 77 | //
|
|---|
| 78 | // Default constructor.
|
|---|
| 79 | //
|
|---|
| 80 | MCalibColorSteer::MCalibColorSteer(const char *name, const char *title)
|
|---|
| 81 | : fCalibPattern(NULL), fGeom(NULL), fParList(NULL),
|
|---|
| 82 | fIntensCharge(NULL), fIntensRelTime(NULL), fIntensBad(NULL),
|
|---|
| 83 | fBad(NULL), fChargeCalc(NULL), fRelTimeCalc(NULL)
|
|---|
| 84 | {
|
|---|
| 85 |
|
|---|
| 86 | fName = name ? name : "MCalibColorSteer";
|
|---|
| 87 | fTitle = title ? title : "Task to steer the processing of different colours in the calibration events";
|
|---|
| 88 |
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // -----------------------------------------------------------------------------------
|
|---|
| 92 | //
|
|---|
| 93 | // The following container are searched for and execution aborted if not in MParList:
|
|---|
| 94 | // - MCalibrationPattern
|
|---|
| 95 | // - MTaskList
|
|---|
| 96 | //
|
|---|
| 97 | Int_t MCalibColorSteer::PreProcess(MParList *pList)
|
|---|
| 98 | {
|
|---|
| 99 |
|
|---|
| 100 | fCalibPattern = (MCalibrationPattern*)pList->FindObject("MCalibrationPattern");
|
|---|
| 101 | if (!fCalibPattern)
|
|---|
| 102 | {
|
|---|
| 103 | *fLog << err << "MCalibrationPattern not found... abort." << endl;
|
|---|
| 104 | return kFALSE;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 108 | if (!fRunHeader)
|
|---|
| 109 | {
|
|---|
| 110 | *fLog << err << "MRawRunHeader not found... abort." << endl;
|
|---|
| 111 | return kFALSE;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
|---|
| 115 | if (!fGeom)
|
|---|
| 116 | {
|
|---|
| 117 | *fLog << err << "MGeomCam not found... abort." << endl;
|
|---|
| 118 | return kFALSE;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | fParList = pList;
|
|---|
| 122 | if (!fParList)
|
|---|
| 123 | {
|
|---|
| 124 | *fLog << err << "MParList not found... abort." << endl;
|
|---|
| 125 | return kFALSE;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | MTaskList *tlist = (MTaskList*)pList->FindObject("MTaskList");
|
|---|
| 129 | if (!tlist)
|
|---|
| 130 | {
|
|---|
| 131 | *fLog << err << "MTaskList not found... abort." << endl;
|
|---|
| 132 | return kFALSE;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | //
|
|---|
| 136 | // Look for the MBadPixels Intensity Cam
|
|---|
| 137 | //
|
|---|
| 138 | fIntensBad = (MBadPixelsIntensityCam*)pList->FindCreateObj("MBadPixelsIntensityCam");
|
|---|
| 139 | if (fIntensBad)
|
|---|
| 140 | *fLog << inf << "Found MBadPixelsIntensityCam ... " << flush;
|
|---|
| 141 | else
|
|---|
| 142 | return kFALSE;
|
|---|
| 143 |
|
|---|
| 144 | //
|
|---|
| 145 | // Look for the MBadPixels Intensity Cam
|
|---|
| 146 | //
|
|---|
| 147 | fBad = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
|
|---|
| 148 | if (fBad)
|
|---|
| 149 | {
|
|---|
| 150 | *fLog << inf << "Found also MBadPixelsCam ... " << flush;
|
|---|
| 151 | fIntensBad->GetCam()->Merge(*fBad);
|
|---|
| 152 | }
|
|---|
| 153 | else
|
|---|
| 154 | return kFALSE;
|
|---|
| 155 |
|
|---|
| 156 | //
|
|---|
| 157 | // Look for the MCalibrationIntensityBlindCam
|
|---|
| 158 | //
|
|---|
| 159 | fIntensBlind = (MCalibrationIntensityBlindCam*)pList->FindCreateObj("MCalibrationIntensityBlindCam");
|
|---|
| 160 |
|
|---|
| 161 | if (fIntensBlind)
|
|---|
| 162 | *fLog << inf << "Found MCalibrationIntensityBlindCam ... " << flush;
|
|---|
| 163 | else
|
|---|
| 164 | return kFALSE;
|
|---|
| 165 |
|
|---|
| 166 | //
|
|---|
| 167 | // Look for the MFillH name "FillChargeCam". In case yes, initialize the
|
|---|
| 168 | // corresponding IntensityCam
|
|---|
| 169 | //
|
|---|
| 170 | if (pList->FindObject(AddSerialNumber("MHCalibrationChargeCam")))
|
|---|
| 171 | {
|
|---|
| 172 |
|
|---|
| 173 | fIntensCharge = (MCalibrationIntensityChargeCam*)pList->FindCreateObj("MCalibrationIntensityChargeCam");
|
|---|
| 174 | fIntensQE = (MCalibrationIntensityQECam*) pList->FindCreateObj("MCalibrationIntensityQECam");
|
|---|
| 175 |
|
|---|
| 176 | fChargeCalc = (MCalibrationChargeCalc*)tlist->FindObject("MCalibrationChargeCalc");
|
|---|
| 177 |
|
|---|
| 178 | *fLog << inf << "Found MHCalibrationChargeCam ... " << flush;
|
|---|
| 179 |
|
|---|
| 180 | if (!fIntensCharge)
|
|---|
| 181 | {
|
|---|
| 182 | *fLog << err << "Could not find nor create MCalibrationIntensityChargeCam abort... " << endl;
|
|---|
| 183 | return kFALSE;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | if (!fIntensQE)
|
|---|
| 187 | {
|
|---|
| 188 | *fLog << err << "Could not find nor create MCalibrationIntensityQECam abort... " << endl;
|
|---|
| 189 | return kFALSE;
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | if (!fChargeCalc)
|
|---|
| 193 | {
|
|---|
| 194 | *fLog << err << "Could not find MCalibrationChargeCalc abort... " << endl;
|
|---|
| 195 | return kFALSE;
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | //
|
|---|
| 200 | // Look for the MFillH name "FillRelTimeCam". In case yes, initialize the
|
|---|
| 201 | // corresponding IntensityCam
|
|---|
| 202 | //
|
|---|
| 203 | if (pList->FindObject(AddSerialNumber("MHCalibrationRelTimeCam")))
|
|---|
| 204 | {
|
|---|
| 205 |
|
|---|
| 206 | fIntensRelTime = (MCalibrationIntensityRelTimeCam*)pList->FindCreateObj("MCalibrationIntensityRelTimeCam");
|
|---|
| 207 | fRelTimeCalc = (MCalibrationRelTimeCalc*)tlist->FindObject(AddSerialNumber("MCalibrationRelTimeCalc"));
|
|---|
| 208 |
|
|---|
| 209 | *fLog << inf << "Found MHCalibrationRelTimeCam ... " << flush;
|
|---|
| 210 |
|
|---|
| 211 | if (!fIntensRelTime)
|
|---|
| 212 | {
|
|---|
| 213 | *fLog << err << "Could not find nor create MCalibrationIntensityRelTimeCam abort... " << endl;
|
|---|
| 214 | return kFALSE;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | if (!fRelTimeCalc)
|
|---|
| 218 | {
|
|---|
| 219 | *fLog << err << "Could not find MCalibrationRelTimeCalc abort... " << endl;
|
|---|
| 220 | return kFALSE;
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | fColor = MCalibrationCam::kNONE;
|
|---|
| 225 | fStrength = 0.;
|
|---|
| 226 |
|
|---|
| 227 | return kTRUE;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | // --------------------------------------------------------------------------
|
|---|
| 231 | //
|
|---|
| 232 | // Reads the pattern from MCalibrationPattern and initializes new containers in the
|
|---|
| 233 | // Intensity Cams, if the pattern has changed. Executes Finalize of the
|
|---|
| 234 | // MCalibration*Calc classes in that case.
|
|---|
| 235 | //
|
|---|
| 236 | Int_t MCalibColorSteer::Process()
|
|---|
| 237 | {
|
|---|
| 238 |
|
|---|
| 239 | const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
|
|---|
| 240 | const Float_t strength = fCalibPattern->GetPulserStrength();
|
|---|
| 241 |
|
|---|
| 242 | if (fColor ==MCalibrationCam::kNONE)
|
|---|
| 243 | {
|
|---|
| 244 | fColor = col;
|
|---|
| 245 | fStrength = strength;
|
|---|
| 246 | return kTRUE;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | const Float_t strdiff = TMath::Abs(fStrength-strength);
|
|---|
| 250 |
|
|---|
| 251 | if (col == MCalibrationCam::kNONE || (col == fColor && strdiff < 0.05))
|
|---|
| 252 | return kTRUE;
|
|---|
| 253 |
|
|---|
| 254 | *fLog << inf << GetDescriptor() << " : Color - old=" << fColor << flush;
|
|---|
| 255 | fColor = col;
|
|---|
| 256 | *fLog << " / new=" << fColor << endl;
|
|---|
| 257 |
|
|---|
| 258 | *fLog << inf << GetDescriptor() << " : Strength - old=" << fStrength << flush;
|
|---|
| 259 | fStrength = strength;
|
|---|
| 260 | *fLog << " / new=" << fStrength << endl;
|
|---|
| 261 |
|
|---|
| 262 | //
|
|---|
| 263 | // Finalize Possible calibration histogram classes...
|
|---|
| 264 | //
|
|---|
| 265 | *fLog << inf << GetDescriptor() << " : Finalize calibration histograms..." << flush;
|
|---|
| 266 | if (Finalize("MHCalibrationChargeCam")) *fLog << "MHCalibrationChargeCam...";
|
|---|
| 267 | if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam...";
|
|---|
| 268 | if (Finalize("MHCalibrationRelTimeCam")) *fLog << "MHCalibrationRelTimeCam...";
|
|---|
| 269 | if (Finalize("MHCalibrationTestCam")) *fLog << "MHCalibrationChargeCam...";
|
|---|
| 270 | if (Finalize("MHCalibrationTestTimeCam")) *fLog << "MHCalibrationChargeCam...";
|
|---|
| 271 |
|
|---|
| 272 | //
|
|---|
| 273 | // Finalize possible calibration calculation tasks
|
|---|
| 274 | //
|
|---|
| 275 | *fLog << endl;
|
|---|
| 276 | *fLog << inf << GetDescriptor() << " : Finalize calibration calculations..." << flush;
|
|---|
| 277 | if (fChargeCalc)
|
|---|
| 278 | fChargeCalc->Finalize();
|
|---|
| 279 | if (fRelTimeCalc)
|
|---|
| 280 | fRelTimeCalc->Finalize();
|
|---|
| 281 |
|
|---|
| 282 | ReInitialize();
|
|---|
| 283 |
|
|---|
| 284 | return kTRUE;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 | // --------------------------------------------------------------------------
|
|---|
| 289 | //
|
|---|
| 290 | // Searches for name in the MParList and calls, if existing:
|
|---|
| 291 | // - MHCalibrationCam::Finalize()
|
|---|
| 292 | // - MHCalibrationCam::ResetHists()
|
|---|
| 293 | //
|
|---|
| 294 | Bool_t MCalibColorSteer::Finalize(const char* name)
|
|---|
| 295 | {
|
|---|
| 296 |
|
|---|
| 297 | MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
|
|---|
| 298 | if (!hist)
|
|---|
| 299 | return kFALSE;
|
|---|
| 300 |
|
|---|
| 301 | hist->Finalize();
|
|---|
| 302 | hist->ResetHists();
|
|---|
| 303 | hist->SetColor( fCalibPattern->GetPulserColor());
|
|---|
| 304 | return kTRUE;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | // --------------------------------------------------------------------------
|
|---|
| 308 | //
|
|---|
| 309 | // Re-Intitializes new containers inside the Intensity Cams.
|
|---|
| 310 | // From now on, a call to the IntensityCam functions returns pointers
|
|---|
| 311 | // to the newly created Containers.
|
|---|
| 312 | //
|
|---|
| 313 | Bool_t MCalibColorSteer::ReInitialize()
|
|---|
| 314 | {
|
|---|
| 315 |
|
|---|
| 316 | *fLog << endl;
|
|---|
| 317 |
|
|---|
| 318 | TString namep = GetNamePattern();
|
|---|
| 319 |
|
|---|
| 320 | if (fIntensBad)
|
|---|
| 321 | {
|
|---|
| 322 | fIntensBad->AddToList(Form("MBadPixelsCam%s",namep.Data()),*fGeom);
|
|---|
| 323 | *fLog << inf << "New MBadPixelsCam with " << namep << endl;
|
|---|
| 324 | fIntensBad->GetCam()->Merge(*fBad);
|
|---|
| 325 | *fLog << inf << "Merged new MBadPixelsCam with first of list" << endl;
|
|---|
| 326 | }
|
|---|
| 327 | if (fIntensCharge)
|
|---|
| 328 | {
|
|---|
| 329 | MCalibrationChargeCam *oldcam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
|
|---|
| 330 | fIntensCharge->AddToList(Form("MCalibrationChargeCam%s",namep.Data()),*fGeom);
|
|---|
| 331 | MCalibrationChargeCam *cam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
|
|---|
| 332 | cam->SetPulserColor(fCalibPattern->GetPulserColor());
|
|---|
| 333 | if (!cam->CopyHiLoConversionFactors(*oldcam))
|
|---|
| 334 | return kFALSE;
|
|---|
| 335 | *fLog << inf << "New MCalibrationChargeCam with name: " << cam->GetName() << endl;
|
|---|
| 336 | }
|
|---|
| 337 | if (fIntensQE)
|
|---|
| 338 | {
|
|---|
| 339 | fIntensQE->AddToList(Form("MCalibrationQECam%s",namep.Data()),*fGeom);
|
|---|
| 340 | *fLog << inf << "New MCalibrationQECam with: " << namep << endl;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | if (fIntensBlind)
|
|---|
| 344 | {
|
|---|
| 345 | fIntensBlind->AddToList(Form("MCalibrationBlindCam%s",namep.Data()),*fGeom);
|
|---|
| 346 | MCalibrationCam *cam = fIntensBlind->GetCam();
|
|---|
| 347 | cam->SetPulserColor(fCalibPattern->GetPulserColor());
|
|---|
| 348 | *fLog << inf << "New MCalibrationBlindCam with name: " << cam->GetName() << endl;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | if (fIntensRelTime)
|
|---|
| 352 | {
|
|---|
| 353 | fIntensRelTime->AddToList(Form("MCalibrationRelTimeCam%s",namep.Data()),*fGeom);
|
|---|
| 354 | MCalibrationCam *cam = fIntensRelTime->GetCam();
|
|---|
| 355 | cam->SetPulserColor(fCalibPattern->GetPulserColor());
|
|---|
| 356 | *fLog << inf << "New MCalibrationRelTimeCam with name: " << cam->GetName() << endl;
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | return kTRUE;
|
|---|
| 360 |
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | TString MCalibColorSteer::GetNamePattern()
|
|---|
| 364 | {
|
|---|
| 365 |
|
|---|
| 366 | const Float_t strength = fCalibPattern->GetPulserStrength();
|
|---|
| 367 | const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
|
|---|
| 368 |
|
|---|
| 369 | TString result = Form("%2.1f",strength);
|
|---|
| 370 |
|
|---|
| 371 | switch (col)
|
|---|
| 372 | {
|
|---|
| 373 | case MCalibrationCam::kCT1:
|
|---|
| 374 | result += "CT1";
|
|---|
| 375 | break;
|
|---|
| 376 | case MCalibrationCam::kGREEN:
|
|---|
| 377 | result += "GREEN";
|
|---|
| 378 | break;
|
|---|
| 379 | case MCalibrationCam::kBLUE:
|
|---|
| 380 | result += "BLUE";
|
|---|
| 381 | break;
|
|---|
| 382 | case MCalibrationCam::kUV:
|
|---|
| 383 | result += "UV";
|
|---|
| 384 | break;
|
|---|
| 385 | default:
|
|---|
| 386 | break;
|
|---|
| 387 | }
|
|---|
| 388 | return result;
|
|---|
| 389 | }
|
|---|