Changeset 2587
- Timestamp:
- 12/02/03 14:33:36 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r2586 r2587 4 4 5 5 -*-*- END OF LINE -*-*- 6 2003/12/02: Thomas Bretz 7 8 * mfilter/MFEventSelector2.[h,cc]: 9 - fixed and reorganized screen output 10 - added some small comments to the code 11 - moved some code from Process() to the new private function Select 12 - fixed uncounted events (underflow bins were not counted) 13 - renamed nonsens fErrors to fCounter 14 - fixed usage of fDisplay 15 16 6 17 7 18 2003/12/01: Markus Gaug -
trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc
r2574 r2587 17 17 ! 18 18 ! Author(s): Thomas Bretz, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de> 19 ! 19 ! Author(s): Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de> 20 20 ! 21 21 ! Copyright: MAGIC Software Development, 2000-2003 … … 156 156 // -------------------------------------------------------------------------- 157 157 // 158 // 158 // Delete fHistRes if instatiated 159 159 // 160 160 MFEventSelector2::~MFEventSelector2() 161 161 { 162 if (fHistRes)163 delete fHistRes;162 if (fHistRes) 163 delete fHistRes; 164 164 } 165 165 … … 170 170 void MFEventSelector2::SetUseOrigDistribution(Bool_t b) 171 171 { 172 fUseOrigDistribution = b; 173 174 *fLog << "MFEventSelector2 : use the distribution from the input file as the target distribution" 175 << endl; 172 fUseOrigDistribution = b; 173 174 *fLog << inf; 175 *fLog << "MFEventSelector2 set "; 176 if (!b) 177 *fLog << "not "; 178 *fLog << "to use the distribution from the input file as target distribution." << endl; 176 179 } 177 180 … … 210 213 } 211 214 212 *fLog << "-------------------------"<< endl;213 *fLog << "MFEventSelector2 : Start of eventloop to generate the original distribution"214 215 *fLog << inf << underline << endl; 216 *fLog << "MFEventSelector2::ReadDistribution:" << endl; 217 *fLog << " - Start of eventloop to generate the original distribution..." << endl; 215 218 216 219 MEvtLoop run(GetName()); … … 243 246 tlist.PrintStatistics(0, kTRUE); 244 247 245 *fLog << "MFEventSelector2::ReadDistribution; Original distribution has " 246 << fHistOrig->GetHist().GetEntries() << " entries" << endl; 247 *fLog << "MFEventSelector2 : End of eventloop to generate the original distribution" 248 << endl; 249 *fLog << "-------------------------" << endl; 248 *fLog << inf; 249 *fLog << "MFEventSelector2::ReadDistribution:" << endl; 250 *fLog << " - Original distribution has " << fHistOrig->GetHist().GetEntries() << " entries." << endl; 251 *fLog << " - End of eventloop to generate the original distribution." << endl; 250 252 251 253 return read.Rewind(); … … 266 268 // set the nominal distribution equal to the original distribution 267 269 268 TH1 *hnp; 269 if (fUseOrigDistribution) 270 hnp = (TH1*)(fHistOrig->GetHist()).Clone(); 271 else 272 hnp = &fHistNom->GetHist(); 270 TH1 *hnp = fUseOrigDistribution ? (TH1*)(fHistOrig->GetHist()).Clone() : &fHistNom->GetHist(); 273 271 274 272 TH1 &hn = *hnp; … … 302 300 if (fNumMax>0) 303 301 { 304 *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events = " 305 << fNumMax << ", maximum no.of events possible = " 306 << hn.Integral() << endl; 302 *fLog << inf; 303 *fLog << "MFEventSelector2::PrepareHistograms:" << endl; 304 *fLog << " - requested number of events = " << fNumMax << endl; 305 *fLog << " - maximum number of events possible = " << hn.Integral() << endl; 307 306 308 307 if (fNumMax > hn.Integral()) 309 308 { 310 *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events (" 311 << fNumMax << ") is too high" << endl; 312 *fLog << " reduce it to " 313 << hn.Integral() << endl; 309 *fLog << warn << "WARNING - Requested no.of events (" << fNumMax; 310 *fLog << ") is too high... reduced to " << hn.Integral() << endl; 314 311 } 315 316 else 317 hn.Scale(fNumMax/hn.Integral()); 312 else 313 hn.Scale(fNumMax/hn.Integral()); 318 314 } 319 315 … … 358 354 return kFALSE; 359 355 } 356 // FALLTHROUGH! 360 357 case 2: 361 358 if (!fDataY.PreProcess(parlist)) … … 364 361 return kFALSE; 365 362 } 363 // FALLTHROUGH! 366 364 case 1: 367 365 if (!fDataX.PreProcess(parlist)) … … 385 383 Int_t MFEventSelector2::PreProcess(MParList *parlist) 386 384 { 387 memset(f Errors, 0, sizeof(fErrors));385 memset(fCounter, 0, sizeof(fCounter)); 388 386 389 387 MTaskList *tasklist = (MTaskList*)parlist->FindObject("MTaskList"); … … 424 422 425 423 return read->CallPreProcess(parlist); 424 } 425 426 // -------------------------------------------------------------------------- 427 // 428 // Part of Process(). Select() at the end checks whether a selection should 429 // be done or not. Under-/Overflowbins are rejected. 430 // 431 Bool_t MFEventSelector2::Select(Int_t bin) 432 { 433 // under- and overflow bins are not counted 434 if (bin<0) 435 return kFALSE; 436 437 Bool_t rc = kFALSE; 438 439 if (gRandom->Rndm()*fIs[bin]<=fNom[bin]) 440 { 441 // how many events do we still want to read in this bin 442 fNom[bin] -= 1; 443 rc = kTRUE; 444 445 // fill bin (same as Fill(valx, valy, valz)) 446 TH1 &h = fHistRes->GetHist(); 447 h.AddBinContent(bin+1); 448 h.SetEntries(h.GetEntries()+1); 449 } 450 451 // how many events are still pending to be read 452 fIs[bin] -= 1; 453 454 return rc; 426 455 } 427 456 … … 436 465 Int_t MFEventSelector2::Process() 437 466 { 438 fResult = kFALSE;439 440 467 // get x,y and z (0 if fData not valid) 441 468 const Double_t valx=fDataX.GetValue(); … … 443 470 const Double_t valz=fDataZ.GetValue(); 444 471 445 446 // get corresponding bin number 447 const Int_t bin = fHistNom->FindFixBin(valx, valy, valz)-1; 448 449 // under- and overflow bins are not counted 450 if (bin<0) 451 return kTRUE; 452 453 454 if (gRandom->Rndm()*fIs[bin]<=fNom[bin]) 455 { 456 // how many events do we still want to read in this bin 457 fNom[bin]-=1; 458 fResult = kTRUE; 459 460 // fill bin (same as Fill(valx, valy, valz)) 461 TH1 &h = fHistRes->GetHist(); 462 h.AddBinContent(bin+1); 463 h.SetEntries(h.GetEntries()+1); 464 } 465 // how many events are still pending to be read 466 fIs[bin]-=1; 467 468 //---------------------- 469 Int_t rc; 470 if (fResult) 471 { 472 rc = 0; 473 fErrors[rc]++; 474 return kTRUE; 475 } 476 rc = 1; 477 fErrors[rc]++; 478 //---------------------- 472 // Get corresponding bin number and check 473 // whether a selection should be made 474 fResult = Select(fHistNom->FindFixBin(valx, valy, valz)-1); 475 476 fCounter[fResult ? 1 : 0]++; 479 477 480 478 return kTRUE; … … 488 486 { 489 487 //--------------------------------- 490 if (GetNumExecutions() != 0) 488 489 if (GetNumExecutions()>0) 491 490 { 492 491 *fLog << inf << endl; 493 492 *fLog << GetDescriptor() << " execution statistics:" << endl; 494 493 *fLog << dec << setfill(' '); 495 *fLog << " " << setw(7) << f Errors[1] << " (" << setw(3)496 << (int)(f Errors[1]*100/GetNumExecutions())494 *fLog << " " << setw(7) << fCounter[1] << " (" << setw(3) 495 << (int)(fCounter[0]*100/GetNumExecutions()) 497 496 << "%) Events not selected" << endl; 498 497 499 *fLog << " " << f Errors[0] << " ("500 << (int)(f Errors[0]*100/GetNumExecutions())501 << "%) Events selected !" << endl;498 *fLog << " " << fCounter[0] << " (" 499 << (int)(fCounter[1]*100/GetNumExecutions()) 500 << "%) Events selected" << endl; 502 501 *fLog << endl; 503 502 } 503 504 504 //--------------------------------- 505 505 506 if ( !fCanvas || !fDisplay)507 return kTRUE;508 509 fCanvas->cd(4);510 fHistRes->DrawClone("nonew");511 fCanvas->Modified();512 fCanvas->Update();506 if (fDisplay && fDisplay->HasCanvas(fCanvas)) 507 { 508 fCanvas->cd(4); 509 fHistRes->DrawClone("nonew"); 510 fCanvas->Modified(); 511 fCanvas->Update(); 512 } 513 513 514 514 return kTRUE; 515 515 } 516 517 518 519 520 521 522 523 524 -
trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h
r2574 r2587 44 44 45 45 Bool_t fResult; 46 Int_t fErrors[2];46 Int_t fCounter[2]; 47 47 48 48 TH1 &InitHistogram(MH3* &hist); … … 50 50 void PrepareHistograms(); 51 51 Bool_t PreProcessData(MParList *parlist); 52 Bool_t Select(Int_t bin); 52 53 53 54 Int_t PreProcess(MParList *parlist);
Note:
See TracChangeset
for help on using the changeset viewer.