Changeset 5667
- Timestamp:
- 12/22/04 11:24:46 (20 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r5666 r5667 20 20 21 21 -*-*- END OF LINE -*-*- 22 23 2004/12/22: Eva Domingo (for Wolfgang Wittek) 24 25 * mfbase/MFEventSelector2.[h,cc]: 26 - the 'original' distribution, a subsample of which wants 27 to be selected, now can be determined with some previous 28 selection cuts. When determing the 'original' distribution 29 in PreProcess() not only the 'read' object but also the 30 'filter' object (with the name "FilterSelector2") of the 31 current event loop is used. 32 22 33 23 34 2004/12/22: Abelardo Moralejo -
trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc
r5448 r5667 19 19 ! Author(s): Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de> 20 20 ! 21 ! Copyright: MAGIC Software Development, 2000-200 321 ! Copyright: MAGIC Software Development, 2000-2005 22 22 ! 23 23 ! … … 29 29 // 30 30 // This is a filter to make a selection of events from a file, according to 31 // a certain predetermined distribution in a given parameter (or combination31 // a certain requested distribution in a given parameter (or combination 32 32 // of parameters). The distribution is passed to the class through a histogram 33 33 // of the relevant parameter(s) contained in an object of type MH3. The filter … … 38 38 // values of the parameters, and is dictated by the input histogram). 39 39 // 40 // This procedure requires the determination of the original distribution 41 // of the given parameters for the total sample of events on the input file. 42 // If the event loop contains a filter with name "FilterSelector2", this 43 // filter will be applied when determining the original distribution. 44 // 40 45 // See Constructor for more instructions and also the example below: 41 46 // … … 111 116 #include "MH3.h" // MH3 112 117 #include "MRead.h" // MRead 118 //#include "MProgressBar.h" // 113 119 #include "MEvtLoop.h" // MEvtLoop 114 120 #include "MTaskList.h" // MTaskList 115 121 #include "MBinning.h" // MBinning 122 #include "MContinue.h" // 116 123 #include "MFillH.h" // MFillH 117 124 #include "MParList.h" // MParList … … 148 155 // note that also in this case a dummy nominal distribution has to be 149 156 // provided in the first argument (the dummy distribution defines the 150 // variable(s) of interest and the binnings) 157 // variable(s) of interest, their binnings and their requested ranges; 158 // events outside these ranges won't be accepted). 151 159 // 152 160 MFEventSelector2::MFEventSelector2(MH3 &hist, const char *name, const char *title) 153 161 : fHistOrig(NULL), fHistNom(&hist), fHistRes(NULL), 154 162 fDataX(hist.GetRule('x')), fDataY(hist.GetRule('y')), 155 fDataZ(hist.GetRule('z')), fNumMax(-1), fHistIsProbability(kFALSE) 163 fDataZ(hist.GetRule('z')), fNumMax(-1), fHistIsProbability(kFALSE), 164 fUseOrigDist(kTRUE) 156 165 { 157 166 fName = name ? (TString)name : gsDefName; 158 167 fTitle = title ? (TString)title : gsDefTitle; 168 169 // name of filter to be applied when determining the original distribution 170 // for all data on the input file 171 fFilterName = "FilterSelector2"; 159 172 } 160 173 … … 195 208 // Reading task of the present loop is used in a new eventloop. 196 209 // 197 Bool_t MFEventSelector2::ReadDistribution(MRead &read )210 Bool_t MFEventSelector2::ReadDistribution(MRead &read, MFilter *filter) 198 211 { 199 212 if (read.GetEntries() > kMaxUInt) // FIXME: LONG_MAX ??? … … 205 218 *fLog << inf << underline << endl; 206 219 *fLog << "MFEventSelector2::ReadDistribution:" << endl; 207 *fLog << " - Start of eventloop to generate the original distribution..." << endl; 208 209 MEvtLoop run(GetName()); 220 *fLog << "**********************" << endl; 221 *fLog << " - Start of eventloop to generate the original distribution..." 222 << endl; 223 224 if (filter != NULL) 225 { 226 *fLog << " filter used : " << filter->GetName() 227 << endl; 228 } 229 230 231 MEvtLoop run("ReadDistribution"); 232 //MProgressBar bar; 233 //run.SetProgressBar(&bar); 234 210 235 MParList plist; 211 236 MTaskList tlist; … … 224 249 225 250 MFillH fill(fHistOrig); 251 fill.SetName("FillHistOrig"); 226 252 fill.SetBit(MFillH::kDoNotDisplay); 227 253 tlist.AddToList(&read); 254 255 MContinue contfilter(filter); 256 if (filter != NULL) 257 { 258 contfilter.SetName("ContFilter"); 259 tlist.AddToList(&contfilter); 260 } 261 228 262 tlist.AddToList(&fill); 229 263 run.SetDisplay(fDisplay); 230 264 if (!run.Eventloop()) 231 265 { 232 *fLog << err << dbginf << "Evtloop in MFEventSelector2::ReadDistribution failed." << endl; 266 *fLog << err << dbginf 267 << "Evtloop in MFEventSelector2::ReadDistribution failed." 268 << endl; 233 269 return kFALSE; 234 270 } 235 271 236 tlist.PrintStatistics( );272 tlist.PrintStatistics(0, kTRUE); 237 273 238 274 *fLog << inf; 239 275 *fLog << "MFEventSelector2::ReadDistribution:" << endl; 240 *fLog << " - Original distribution has " << fHistOrig->GetHist().GetEntries() << " entries." << endl; 241 *fLog << " - End of eventloop to generate the original distribution." << endl; 276 *fLog << " - Original distribution has " 277 << fHistOrig->GetHist().GetEntries() << " entries." << endl; 278 *fLog << " - End of eventloop to generate the original distribution." 279 << endl; 280 *fLog << "**********************" << endl; 242 281 243 282 return read.Rewind(); … … 258 297 // set the nominal distribution equal to the original distribution 259 298 260 const Bool_t useorigdist = fHistNom->GetHist().GetEntries()==0; 261 TH1 *hnp = useorigdist ? (TH1*)(fHistOrig->GetHist()).Clone() : &fHistNom->GetHist(); 299 const Bool_t fUseOrigDist = fHistNom->GetHist().GetEntries()==0; 300 TH1 *hnp = fUseOrigDist ? (TH1*)(fHistOrig->GetHist()).Clone() : 301 &fHistNom->GetHist(); 262 302 263 303 TH1 &hn = *hnp; … … 327 367 } 328 368 329 if ( useorigdist)369 if (fUseOrigDist) 330 370 delete hnp; 331 371 } … … 370 410 // 3) Initialize the histogram for the resulting distribution 371 411 // 4) Prepare the random selection 372 // 5) Repreprocess the reading task.412 // 5) Repreprocess the reading and filter task. 373 413 // 374 414 Int_t MFEventSelector2::PreProcess(MParList *parlist) … … 386 426 return kFALSE; 387 427 388 fHistNom->SetTitle(fHistIsProbability ? "ProbabilityDistribution" : "Users Nominal Distribution"); 428 fHistNom->SetTitle(fHistIsProbability ? "ProbabilityDistribution" : 429 "Users Nominal Distribution"); 389 430 390 431 if (fHistIsProbability) … … 410 451 } 411 452 412 if (!ReadDistribution(*read)) 453 MFilter *filter = (MFilter*)tasklist->FindObject(fFilterName); 454 if (!filter) 455 { 456 *fLog << inf 457 << "No filter will be used when making the original distribution" 458 << endl; 459 filter = NULL; 460 } 461 462 463 if (!ReadDistribution(*read, filter)) 413 464 return kFALSE; 465 414 466 415 467 // Prepare histograms and arrays for selection 416 468 PrepareHistograms(); 417 469 418 return read->CallPreProcess(parlist); 470 *fLog << "MFEventSelector2::PreProcess; call PreProcess() for read and filter object again" 471 << endl; 472 Int_t rcr = read->CallPreProcess(parlist); 473 Int_t rcf = filter->CallPreProcess(parlist); 474 475 *fLog << "rcr, rcf = " << rcr << ", " << rcf << endl; 476 477 return rcf*rcr; 419 478 } 420 479 … … 426 485 Bool_t MFEventSelector2::Select(Int_t bin) 427 486 { 428 // under- and overflow bins are not counted487 // under- and overflow bins are not accepted 429 488 if (bin<0) 430 489 return kFALSE; … … 450 509 } 451 510 511 // -------------------------------------------------------------------------- 512 // 452 513 Bool_t MFEventSelector2::SelectProb(Int_t ibin) const 453 514 { … … 455 516 // If value is outside histogram range, accept event 456 517 // 457 return ibin<0 ? kTRUE : fHistNom->GetHist().GetBinContent(ibin) > gRandom->Uniform(); 518 return ibin<0 ? kTRUE : 519 fHistNom->GetHist().GetBinContent(ibin) > gRandom->Uniform(); 458 520 } 459 521 … … 473 535 const Double_t valz=fDataZ.GetValue(); 474 536 537 // don't except the event if it is outside the axis range 538 // of the requested distribution 475 539 const Int_t ibin = fHistNom->FindFixBin(valx, valy, valz)-1; 476 477 // Get corresponding bin number and check 478 // whether a selection should be made 540 if (!fHistIsProbability) 541 { 542 if (ibin < 0) 543 { 544 fResult = kFALSE; 545 fCounter[1] += 1; 546 return kTRUE; 547 } 548 } 549 550 // check whether a selection should be made 479 551 fResult = fHistIsProbability ? SelectProb(ibin) : Select(ibin); 480 481 fCounter[fResult ? 1 : 0]++; 552 if (!fResult) 553 { 554 fCounter[2] += 1; 555 return kTRUE; 556 } 557 558 fCounter[0] += 1; 482 559 483 560 return kTRUE; … … 497 574 *fLog << GetDescriptor() << " execution statistics:" << endl; 498 575 *fLog << dec << setfill(' '); 576 499 577 *fLog << " " << setw(7) << fCounter[1] << " (" << setw(3) 500 << (int)(fCounter[0]*100/GetNumExecutions()) 501 << "%) Events not selected" << endl; 578 << (int)((Float_t)(fCounter[1]*100)/(Float_t)(GetNumExecutions())+0.5) 579 << "%) Events not selected due to under/over flow" << endl; 580 581 *fLog << " " << setw(7) << fCounter[2] << " (" << setw(3) 582 << (int)((Float_t)(fCounter[2]*100)/(Float_t)(GetNumExecutions())+0.5) 583 << "%) Events not selected due to requested distribution" 584 << endl; 502 585 503 586 *fLog << " " << fCounter[0] << " (" 504 << (int)( fCounter[1]*100/GetNumExecutions())587 << (int)((Float_t)(fCounter[0]*100)/(Float_t)(GetNumExecutions())+0.5) 505 588 << "%) Events selected" << endl; 506 589 *fLog << endl; … … 519 602 return kTRUE; 520 603 } 604 605 606 607 608 609 -
trunk/MagicSoft/Mars/mfbase/MFEventSelector2.h
r5448 r5667 41 41 TCanvas *fCanvas; //! canvas for online display 42 42 43 TString fFilterName; // name of the MFilter object to be used 44 // when determining the original distribution 45 43 46 Bool_t fResult; 44 47 Bool_t fHistIsProbability; 45 Int_t fCounter[2]; 48 Bool_t fUseOrigDist; // flag indicating that in the selection the 49 // original distribution is not changed 50 51 Int_t fCounter[3]; 46 52 47 53 TH1 &InitHistogram(MH3* &hist); 48 Bool_t ReadDistribution(MRead &read );54 Bool_t ReadDistribution(MRead &read, MFilter *filter); 49 55 void PrepareHistograms(); 50 56 Bool_t PreProcessData(MParList *parlist);
Note:
See TracChangeset
for help on using the changeset viewer.