- Timestamp:
- 04/15/04 19:54:59 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r3759 r3760 26 26 27 27 * macros/bootcampstandardanalysis.C 28 * macros/pedphotcalc.C 28 29 - updated the macro to the cvs-standard used at the Udine bootcamp 29 30 -
trunk/MagicSoft/Mars/macros/pedphotcalc.C
r3438 r3760 26 26 ! 27 27 \* ======================================================================== */ 28 28 ///////////////////////////////////////////////////////////////////////////// 29 // 30 // pedphotcalc.C 31 // 32 // This macro is an example of the use of MPedPhotCalc. It computes 33 // the pedestal mean and rms from pedestal files undergoing the 34 // signal extraction + calibration chain, in units of photons. It 35 // produces plots of the relevant computed quantities. 36 // 37 // Needs as arguments the run number of a pedestal file ("*_P_*.root"), 38 // one of a calibration file ("*_C_*.root"). 39 // performs the pedestal calculation, the calibration 40 /// constants calculation and the calibration of the pedestals. 41 // 42 // The TString inpath has to be set correctly. 43 // 44 // The macro searches for the pulser colour which corresponds to the calibration 45 // run number. If the run number is smaller than 20000, pulser colour "CT1" 46 // is assumed, otherwise, it searches for the strings "green", "blue", "uv" or 47 // "ct1" in the filenames. If no colour or multiple colours are found, the 48 // execution is aborted. 49 // 50 //////////////////////////////////////////////////////////////////////////////////// 29 51 #include "MParList.h" 30 52 #include "MTaskList.h" 53 #include "MJPedestal.h" 54 #include "MJCalibration.h" 31 55 #include "MPedestalCam.h" 56 #include "MPedestalPix.h" 32 57 #include "MReadMarsFile.h" 33 58 #include "MGeomApply.h" 34 #include "MPedCalcPedRun.h"35 59 #include "MGeomCamMagic.h" 36 60 #include "MEvtLoop.h" 61 #include "MCalibrationCam.h" 37 62 #include "MCalibrationChargeCam.h" 38 #include "MHCalibrationChargeCam.h" 39 #include "MCalibrationChargePINDiode.h" 40 #include "MHCalibrationChargePINDiode.h" 41 #include "MCalibrationChargeBlindPix.h" 42 #include "MHCalibrationChargeBlindPix.h" 43 #include "MCalibrationChargeCalc.h" 63 #include "MCalibrationChargePix.h" 64 #include "MCalibrationQECam.h" 65 #include "MCalibrationQEPix.h" 44 66 #include "MExtractedSignalCam.h" 45 67 #include "MExtractSignal.h" 46 #include "MExtractedSignalPINDiode.h"47 #include "MExtractPINDiode.h"48 #include "MExtractedSignalBlindPixel.h"49 #include "MExtractBlindPixel.h"50 68 #include "MCerPhotEvt.h" 51 69 #include "MCalibrate.h" 52 70 #include "MPedPhotCalc.h" 53 71 #include "MPedPhotCam.h" 54 #include "MBadPixelsCam.h" 72 #include "MPedPhotPix.h" 73 #include "MHCamera.h" 74 #include "MRunIter.h" 75 #include "MDirIter.h" 76 #include "MStatusDisplay.h" 55 77 #include "MHCamera.h" 56 78 … … 58 80 #include "TString.h" 59 81 #include "TCanvas.h" 60 61 #include <iostream> 62 63 64 const TString pedfile="/disc02/Data/rootdata/Miscellaneous/2003_12_19/20031218_03522_P_Park_E.root"; 65 const TString calfile="/disc02/Data/rootdata/Miscellaneous/2003_12_19/20031218_03527_C_Park_E.root"; 66 67 void pedphotcalc(TString pedname=pedfile,TString calname=calfile) 82 #include "TStyle.h" 83 #include "TF1.h" 84 #include "TLegend.h" 85 86 #include <iostream.h> 87 #include "Getline.h" 88 89 const TString inpath = "/mnt/Data/rootdata/CrabNebula/2004_02_10/"; 90 const Int_t dpedrun = 14607; 91 const Int_t dcalrun1 = 14608; 92 const Int_t dcalrun2 = 0; 93 const Bool_t usedisplay = kTRUE; 94 95 static MCalibrationCam::PulserColor_t FindColor(MDirIter* run) 68 96 { 69 97 70 /* 71 This macro is an example of the use of MPedPhotCalc. It computes 72 the pedestal mean and rms from pedestal files undergoing the 73 signal extraction + calibration chain, in units of photons. It 74 produces plots of the relevant computed quantities. 75 */ 76 98 MCalibrationCam::PulserColor_t col = MCalibrationCam::kNONE; 99 100 TString filenames; 101 102 while (!(filenames=run->Next()).IsNull()) 103 { 104 105 filenames.ToLower(); 106 107 if (filenames.Contains("green")) 108 if (col == MCalibrationCam::kNONE) 109 { 110 cout << "Found colour: Green in " << filenames << endl; 111 col = MCalibrationCam::kGREEN; 112 } 113 else if (col != MCalibrationCam::kGREEN) 114 { 115 cout << "Different colour found in " << filenames << "... abort" << endl; 116 return MCalibrationCam::kNONE; 117 } 118 119 if (filenames.Contains("blue")) 120 if (col == MCalibrationCam::kNONE) 121 { 122 cout << "Found colour: Blue in " << filenames << endl; 123 col = MCalibrationCam::kBLUE; 124 } 125 else if (col != MCalibrationCam::kBLUE) 126 { 127 cout << "Different colour found in " << filenames << "... abort" << endl; 128 return MCalibrationCam::kNONE; 129 } 130 131 if (filenames.Contains("uv")) 132 if (col == MCalibrationCam::kNONE) 133 { 134 cout << "Found colour: Uv in " << filenames << endl; 135 col = MCalibrationCam::kUV; 136 } 137 else if (col != MCalibrationCam::kUV) 138 { 139 cout << "Different colour found in " << filenames << "... abort" << endl; 140 return MCalibrationCam::kNONE; 141 } 142 143 if (filenames.Contains("ct1")) 144 if (col == MCalibrationCam::kNONE) 145 { 146 cout << "Found colour: Ct1 in " << filenames << endl; 147 col = MCalibrationCam::kCT1; 148 } 149 else if (col != MCalibrationCam::kCT1) 150 { 151 cout << "Different colour found in " << filenames << "... abort" << endl; 152 return MCalibrationCam::kNONE; 153 } 154 155 } 156 157 158 159 if (col == MCalibrationCam::kNONE) 160 cout << "No colour found in filenames of runs: " << ((MRunIter*)run)->GetRunsAsString() 161 << "... abort" << endl; 162 163 return col; 164 } 165 166 167 168 void DrawProjection(MHCamera *obj1, Int_t fit) 169 { 170 TH1D *obj2 = (TH1D*)obj1->Projection(obj1->GetName()); 171 obj2->SetDirectory(0); 172 obj2->Draw(); 173 obj2->SetBit(kCanDelete); 174 gPad->SetLogy(); 175 176 if (obj1->GetGeomCam().InheritsFrom("MGeomCamMagic")) 177 { 178 TArrayI s0(3); 179 s0[0] = 6; 180 s0[1] = 1; 181 s0[2] = 2; 182 183 TArrayI s1(3); 184 s1[0] = 3; 185 s1[1] = 4; 186 s1[2] = 5; 187 188 TArrayI inner(1); 189 inner[0] = 0; 190 191 TArrayI outer(1); 192 outer[0] = 1; 193 194 // Just to get the right (maximum) binning 195 TH1D *half[4]; 196 half[0] = obj1->ProjectionS(s0, inner, "Sector 6-1-2 Inner"); 197 half[1] = obj1->ProjectionS(s1, inner, "Sector 3-4-5 Inner"); 198 half[2] = obj1->ProjectionS(s0, outer, "Sector 6-1-2 Outer"); 199 half[3] = obj1->ProjectionS(s1, outer, "Sector 3-4-5 Outer"); 200 201 for (int i=0; i<4; i++) 202 { 203 half[i]->SetLineColor(kRed+i); 204 half[i]->SetDirectory(0); 205 half[i]->SetBit(kCanDelete); 206 half[i]->Draw("same"); 207 } 208 } 209 210 const Double_t min = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst()); 211 const Double_t max = obj2->GetBinCenter(obj2->GetXaxis()->GetLast()); 212 const Double_t integ = obj2->Integral("width")/2.5066283; 213 const Double_t mean = obj2->GetMean(); 214 const Double_t rms = obj2->GetRMS(); 215 const Double_t width = max-min; 216 217 if (rms==0 || width==0) 218 return; 219 220 const TString dgausformula("([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])" 221 "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])"); 222 223 TF1 *f=0; 224 switch (fit) 225 { 226 // FIXME: MAYBE add function to TH1? 227 case 0: 228 f = new TF1("sgaus", "gaus(0)", min, max); 229 f->SetLineColor(kYellow); 230 f->SetBit(kCanDelete); 231 f->SetParNames("Area", "#mu", "#sigma"); 232 f->SetParameters(integ/rms, mean, rms); 233 f->SetParLimits(0, 0, integ); 234 f->SetParLimits(1, min, max); 235 f->SetParLimits(2, 0, width/1.5); 236 obj2->Fit(f, "QLRM"); 237 break; 238 239 case 1: 240 f = new TF1("dgaus", dgausformula, min, max); 241 f->SetLineColor(kYellow); 242 f->SetBit(kCanDelete); 243 f->SetParNames("A_{tot}", "#mu_{1}", "#sigma_{1}", "A_{2}", "#mu_{2}", "#sigma_{2}"); 244 f->SetParameters(integ, (min+mean)/2, width/4, 245 integ/width/2, (max+mean)/2, width/4); 246 // The left-sided Gauss 247 f->SetParLimits(0, integ-1.5, integ+1.5); 248 f->SetParLimits(1, min+(width/10), mean); 249 f->SetParLimits(2, 0, width/2); 250 // The right-sided Gauss 251 f->SetParLimits(3, 0, integ); 252 f->SetParLimits(4, mean, max-(width/10)); 253 f->SetParLimits(5, 0, width/2); 254 obj2->Fit(f, "QLRM"); 255 break; 256 257 default: 258 obj2->Fit("gaus", "Q"); 259 obj2->GetFunction("gaus")->SetLineColor(kYellow); 260 break; 261 } 262 } 263 264 void CamDraw(TCanvas &c, Int_t x, Int_t y, MHCamera &cam1, Int_t fit) 265 { 266 c.cd(x); 267 gPad->SetBorderMode(0); 268 MHCamera *obj1=(MHCamera*)cam1.DrawCopy("hist"); 269 270 c.cd(x+y); 271 gPad->SetBorderMode(0); 272 obj1->Draw(); 273 274 c.cd(x+2*y); 275 gPad->SetBorderMode(0); 276 DrawProjection(obj1, fit); 277 } 278 279 void pedphotcalc(const Int_t prun=dpedrun, // pedestal file 280 const Int_t crun1=dcalrun1, const Int_t crun2=dcalrun2 // calibration file(s) 281 ) 282 { 283 284 MRunIter pruns; 285 MRunIter cruns; 286 287 pruns.AddRun(prun,inpath); 288 289 if (crun2==0) 290 cruns.AddRun(crun1,inpath); 291 else 292 cruns.AddRuns(crun1,crun2,inpath); 293 294 MCalibrationCam::PulserColor_t color; 295 296 if (crun1 < 20000) 297 color = MCalibrationCam::kCT1; 298 else 299 color = FindColor((MDirIter*)&cruns); 300 301 if (color == MCalibrationCam::kNONE) 302 { 303 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE); 304 305 while (1) 306 { 307 timer.TurnOn(); 308 TString input = Getline("Could not find the correct colour: Type 'q' to exit, " 309 "green, blue, uv or ct1 to go on: "); 310 timer.TurnOff(); 311 312 if (input=="q\n") 313 return ; 314 315 if (input=="green") 316 color = MCalibrationCam::kGREEN; 317 if (input=="blue") 318 color = MCalibrationCam::kBLUE; 319 if (input=="uv") 320 color = MCalibrationCam::kUV; 321 if (input=="ct1") 322 color = MCalibrationCam::kCT1; 323 } 324 } 325 326 // 327 // Now setup the tasks and tasklist for the pedestals: 328 // --------------------------------------------------- 329 // 330 MGeomCamMagic geomcam; 331 MGeomApply geomapl; 332 MStatusDisplay *display = NULL; 333 77 334 /************************************/ 78 335 /* FIRST LOOP: PEDESTAL COMPUTATION */ 79 336 /************************************/ 80 337 81 MParList plist; 82 MTaskList tlist; 83 plist.AddToList(&tlist); 84 85 // containers 86 MPedestalCam pedcam; 87 plist.AddToList(&pedcam); 88 89 //tasks 90 MReadMarsFile read("Events", pedname); 91 MGeomApply geomapl; 92 MPedCalcPedRun pedcalc; 93 MGeomCamMagic geomcam; 94 95 read.DisableAutoScheme(); 96 97 tlist.AddToList(&read); 98 tlist.AddToList(&geomapl); 99 tlist.AddToList(&pedcalc); 100 101 // Create and execute the event looper 102 MEvtLoop evtloop; 103 evtloop.SetParList(&plist); 338 MJPedestal pedloop; 339 pedloop.SetInput(&pruns); 340 if (usedisplay) 341 { 342 display = new MStatusDisplay; 343 display->SetUpdateTime(3000); 344 display->Resize(850,700); 345 display->SetBit(kCanDelete); 346 pedloop.SetDisplay(display); 347 } 104 348 105 349 cout << "*************************" << endl; 106 350 cout << "** COMPUTING PEDESTALS **" << endl; 107 351 cout << "*************************" << endl; 108 if (!evtloop.Eventloop()) 352 353 if (!pedloop.Process()) 109 354 return; 110 111 tlist.PrintStatistics();355 356 MPedestalCam pedcam = pedloop.GetPedestalCam(); 112 357 113 358 /****************************/ … … 115 360 /****************************/ 116 361 117 MParList plist2; 118 MTaskList tlist2; 119 plist2.AddToList(&tlist2); 120 121 // containers 122 MCalibrationChargeCam calcam; 123 MExtractedSignalCam sigcam; 124 MBadPixelsCam badcam; 125 126 MCalibrationChargeCam chargecam; 127 MCalibrationChargePINDiode chargepin; 128 MCalibrationChargeBlindPixel chargeblind; 129 chargeblind.SetColor(MCalibrationChargeBlindPix::kECT1); 130 chargepin.SetColor( MCalibrationChargePINDiode::kECT1); 131 // 132 plist2.AddToList(&geomcam); 133 plist2.AddToList(&pedcam); 134 plist2.AddToList(&calcam); 135 plist2.AddToList(&sigcam); 136 plist2.AddToList(&badcam); 137 plist2.AddToList(&chargecam); 138 plist2.AddToList(&chargepin); 139 plist2.AddToList(&chargeblind); 140 141 //tasks 142 MReadMarsFile read2("Events", calname); 143 read2.DisableAutoScheme(); 144 145 MExtractPINDiode pincalc; 146 MExtractBlindPixel blindcalc; 147 MExtractSignal sigcalc; 148 MCalibrationChargeCalc calcalc; 149 150 MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode"); 151 MFillH fillblind("MHCalibrationChargeBlindPixel", "MExtractedSignalBlindPixel"); 152 MFillH fillcam("MHCalibrationChargeCam" , "MExtractedSignalCam"); 153 // 154 // Apply a filter against cosmics 155 // (was directly in MCalibrationChargeCalc in earlier versions) 156 // 157 MFCosmics cosmics; 158 MContinue cont(&cosmics); 159 160 tlist2.AddToList(&read2); 161 tlist2.AddToList(&geomapl); 162 tlist2.AddToList(&blindcalc); 163 tlist2.AddToList(&pincalc); 164 tlist2.AddToList(&sigcalc); 165 // 166 // In case, you want to skip the cosmics rejection, 167 // uncomment the next line 168 // 169 tlist2.AddToList(&cont); 170 // 171 tlist2.AddToList(&fillpin); 172 tlist2.AddToList(&fillblind); 173 tlist2.AddToList(&fillcam); 174 tlist2.AddToList(&calcalc); 175 176 // Execute second loop (calibration) 177 MEvtLoop evtloop2; 178 evtloop2.SetParList(&plist2); 362 // 363 // Now setup the new tasks for the calibration: 364 // --------------------------------------------------- 365 // 366 MJCalibration calloop; 367 calloop.SetColor(color); 368 calloop.SetInput(&cruns); 369 // 370 // Use as signal extractor MExtractSignal: 371 // 372 calloop.SetExtractorLevel(1); 373 // 374 // The next two commands are for the display: 375 // 376 if (usedisplay) 377 { 378 calloop.SetDisplay(display); 379 calloop.SetDataCheck(); 380 } 179 381 180 382 cout << "***********************************" << endl; 181 383 cout << "** COMPUTING CALIBRATION FACTORS **" << endl; 182 384 cout << "***********************************" << endl; 183 if (!evtloop2.Eventloop()) 385 386 if (!calloop.Process(pedcam)) 184 387 return; 185 388 186 tlist2.PrintStatistics();187 188 389 MCalibrationChargeCam &calcam = calloop.GetCalibrationCam(); 390 MCalibrationQECam &qecam = calloop.GetQECam(); 391 189 392 /************************************************************************/ 190 393 /* THIRD LOOP: PEDESTAL COMPUTATION USING EXTRACTED SIGNAL (IN PHOTONS) */ … … 202 405 203 406 plist3.AddToList(&geomcam); 204 plist3.AddToList(&pedcam); 205 plist3.AddToList(&calcam); 407 plist3.AddToList(&pedcam ); 408 plist3.AddToList(&calcam ); 409 plist3.AddToList(&qecam ); 206 410 plist3.AddToList(&photcam); 207 411 plist3.AddToList(&extedsig); … … 209 413 210 414 //tasks 211 MReadMarsFile read3("Events", pedname); 415 MReadMarsFile read3("Events"); 416 read3.DisableAutoScheme(); 417 static_cast<MRead&>(read3).AddFiles(pruns); 418 419 MExtractSignal sigcalc; 212 420 MCalibrate photcalc; 421 photcalc.SetCalibrationMode(MCalibrate::kFfactor); 213 422 MPedPhotCalc pedphotcalc; 214 423 215 read3.DisableAutoScheme();216 217 424 tlist3.AddToList(&read3); 218 425 tlist3.AddToList(&geomapl); … … 233 440 tlist3.PrintStatistics(); 234 441 235 236 442 /**********************/ 237 443 /* PRODUCE NICE PLOTS */ 238 444 /**********************/ 239 445 446 if (usedisplay) 447 { 448 449 MHCamera disp0(geomcam, "MPedPhotCam;ped", "Pedestals"); 450 MHCamera disp1(geomcam, "MPedPhotCam;rms", "Sigma Pedestal"); 451 452 disp0.SetCamContent(pedphotcam, 0); 453 disp0.SetCamError (pedphotcam, 1); 454 455 disp1.SetCamContent(pedphotcam, 1); 456 457 disp0.SetYTitle("Pedestal signal [photons]"); 458 disp1.SetYTitle("Pedestal signal RMS [photons]"); 459 460 // 461 // Display data 462 // 463 TCanvas &c1 = display->AddTab("PedPhotCam"); 464 c1.Divide(2,3); 465 466 CamDraw(c1, 1, 2, disp0, 0); 467 CamDraw(c1, 2, 2, disp1, 1); 468 469 } 470 471 472 #if 0 240 473 const UShort_t npix = 577; 241 474 … … 250 483 TH1F* calhist = new TH1F("calhist","Calibration factors",npix,0,npix); 251 484 TH1F* caldist = new TH1F("caldist","Calibration factors",100,0,1); 485 TH1F* qehist = new TH1F("qehist", "Quantrum efficiencies",npix,0,npix); 486 TH1F* qedist = new TH1F("qedist", "Quantrum efficiencies",100,0,1); 252 487 253 488 // pedestal signals … … 260 495 for(int i=0;i<npix;i++) 261 496 { 497 MCalibrationChargePix &calpix = (MCalibrationChargePix&)calcam[i]; 498 MCalibrationQEPix &qepix = (MCalibrationQEPix&) qecam[i]; 499 262 500 const Float_t ped = pedcam[i].GetPedestal(); 263 501 const Float_t pedrms = pedcam[i].GetPedestalRms(); 264 const Float_t cal = cal cam[i].GetMeanConversionBlindPixelMethod();265 const Float_t calerr = calcam[i].GetErrorConversionBlindPixelMethod();502 const Float_t cal = calpix.GetMeanConvFADC2Phe(); 503 const Float_t qe = qepix .GetQECascadesFFactor(); 266 504 const Float_t pedphot = pedphotcam[i].GetMean(); 267 505 const Float_t pedphotrms = pedphotcam[i].GetRms(); … … 274 512 calhist->Fill(i,cal); 275 513 caldist->Fill(cal); 514 qehist->Fill(i,qe); 515 qedist->Fill(qe); 276 516 277 517 pedphothist->Fill(i,pedphot); … … 287 527 canvas->SetBorderMode(0); // Delete the Canvas' border line 288 528 canvas->cd(); 289 canvas->SetBorderMode(0); 290 291 canvas->Divide(2,4); 529 530 canvas->Divide(2,5); 292 531 293 532 // draw pedestal histo … … 322 561 pedrmsdist->Draw("same"); 323 562 324 325 563 TLegend* leg2 = new TLegend(.14,.68,.39,.88); 326 564 leg2->SetHeader(""); … … 339 577 calhist->SetMaximum(1); 340 578 calhist->SetMinimum(0); 341 calhist->GetYaxis()->SetTitle("Calibration factor (ph oton/ADC count)");579 calhist->GetYaxis()->SetTitle("Calibration factor (phe/ADC count)"); 342 580 calhist->SetStats(kFALSE); 343 581 calhist->Draw(); … … 347 585 gPad->cd(); 348 586 gPad->SetBorderMode(0); 349 caldist->GetXaxis()->SetTitle("Calibration factor (ph oton/ADC count)");587 caldist->GetXaxis()->SetTitle("Calibration factor (phe/ADC count)"); 350 588 caldist->Draw(); 351 589 590 // draw qe histo 591 canvas->cd(5); 592 gPad->cd(); 593 gPad->SetBorderMode(0); 594 qehist->GetXaxis()->SetTitle("Pixel SW Id"); 595 qehist->SetMaximum(1); 596 qehist->SetMinimum(0); 597 qehist->GetYaxis()->SetTitle("Quantum efficiency for cascades"); 598 qehist->SetStats(kFALSE); 599 qehist->Draw(); 600 601 // draw qe distribution 602 canvas->cd(6); 603 gPad->cd(); 604 gPad->SetBorderMode(0); 605 qedist->GetXaxis()->SetTitle("Quantum efficiency for cascades"); 606 qedist->Draw(); 607 352 608 // draw pedestal signal histo 353 canvas->cd( 5);609 canvas->cd(7); 354 610 gPad->cd(); 355 611 gPad->SetBorderMode(0); … … 360 616 361 617 // draw pedestal signal distribution 362 canvas->cd( 6);618 canvas->cd(8); 363 619 gPad->cd(); 364 620 gPad->SetBorderMode(0); … … 367 623 368 624 // draw pedestal signal rms histo 369 canvas->cd( 7);625 canvas->cd(9); 370 626 gPad->cd(); 371 627 gPad->SetBorderMode(0); … … 376 632 377 633 // draw pedestal signal rms distribution 378 canvas->cd( 8);634 canvas->cd(10); 379 635 gPad->cd(); 380 636 gPad->SetBorderMode(0); … … 382 638 pedphotrmsdist->Draw(); 383 639 384 return; 640 canvas->SaveAs("pedphotcalc.root"); 641 642 #endif 385 643 } 386
Note:
See TracChangeset
for help on using the changeset viewer.