00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4Condition.h"
00017
00018 #include "Riostream.h"
00019
00020 #include "TH1.h"
00021 #include "TROOT.h"
00022 #include "TList.h"
00023 #include "TCutG.h"
00024 #include "TVirtualPad.h"
00025 #include "snprintf.h"
00026
00027 #include "TGo4Log.h"
00028 #include "TGo4ConditionPainter.h"
00029
00030 const Double_t TGo4Condition::fgdUPDATEEPSILON=0.01;
00031
00032 Bool_t TGo4Condition::fgbLABELDRAW=kTRUE;
00033 Bool_t TGo4Condition::fgbLIMITSDRAW=kTRUE;
00034 Bool_t TGo4Condition::fgbINTDRAW=kTRUE;
00035 Bool_t TGo4Condition::fgbXMEANDRAW=kTRUE;
00036 Bool_t TGo4Condition::fgbXRMSDRAW=kTRUE;
00037 Bool_t TGo4Condition::fgbYMEANDRAW=kFALSE;
00038 Bool_t TGo4Condition::fgbYRMSDRAW=kFALSE;
00039 Bool_t TGo4Condition::fgbXMAXDRAW=kTRUE;
00040 Bool_t TGo4Condition::fgbYMAXDRAW=kFALSE;
00041 Bool_t TGo4Condition::fgbCMAXDRAW=kTRUE;
00042
00043
00044
00045
00046
00047 TGo4Condition::TGo4Condition() :
00048 TNamed(),
00049 TAttLine(),
00050 TAttFill(),
00051 fxPainter(0),
00052 fxCutHis(0),
00053 fxHisto(0),
00054 fiIsChanged(0)
00055 {
00056 TRACE((15,"TGo4Condition::TGo4Condition()",__LINE__, __FILE__));
00057 fiDim=0;
00058 fbEnabled = false;
00059 fbResult = true;
00060 fbTrue = true;
00061 fbFalse = false;
00062 fbMarkReset = false;
00063 fiCounts = 0;
00064 fiTrueCounts= 0;
00065 fbVisible=true;
00066 fbMultiEdit= true;
00067 fbHistogramLink=false;
00068 fdUpdateEpsilon=fgdUPDATEEPSILON;
00069 fbIsPainted=kFALSE;
00070 fbOwnedByEditor=kFALSE;
00071 fbStreamedCondition=kTRUE;
00072 InitLabelStyle();
00073 }
00074
00075
00076 TGo4Condition::TGo4Condition(const char* name, const char* title) :
00077 TNamed(name, title),
00078 TAttLine(),
00079 TAttFill(),
00080 fxPainter(0),
00081 fxCutHis(0),
00082 fxHisto(0),
00083 fiIsChanged(0)
00084 {
00085 TRACE((15,"TGo4Condition::TGo4Condition(Text_t*)",__LINE__, __FILE__));
00086 fiDim=0;
00087 fbEnabled = false;
00088 fbResult = true;
00089 fbTrue = true;
00090 fbFalse = false;
00091 fbMarkReset = false;
00092 fiCounts = 0;
00093 fiTrueCounts = 0;
00094 fbVisible=true;
00095 fbMultiEdit= true;
00096 fbHistogramLink=false;
00097 fdUpdateEpsilon=fgdUPDATEEPSILON;
00098 fbIsPainted=kFALSE;
00099 fbOwnedByEditor=kFALSE;
00100 fbStreamedCondition=kFALSE;
00101 InitLabelStyle();
00102 }
00103
00104
00105 TGo4Condition::~TGo4Condition()
00106 {
00107 TRACE((15,"TGo4Condition::~TGo4Condition()",__LINE__, __FILE__));
00108
00109 UnDraw("reset");
00110
00111 if(fxPainter) {
00112 delete fxPainter;
00113 fxPainter = 0;
00114 }
00115 if(fxCutHis) {
00116 delete fxCutHis;
00117 fxCutHis = 0;
00118 }
00119 }
00120
00121 Bool_t TGo4Condition::Test()
00122 {
00123 fiCounts++;
00124 return true;
00125 }
00126
00127
00128 void TGo4Condition::AddCondition(TGo4Condition* next)
00129 {
00130 TRACE((14,"TGo4Condition::AddCondition(TGo4Condition*)",__LINE__, __FILE__));
00131 }
00132
00133 void TGo4Condition::IncTrueCounts()
00134 {
00135 TRACE((12,"TGo4Condition::IncTrueCounts()",__LINE__, __FILE__));
00136 fiTrueCounts++;
00137 }
00138
00139 void TGo4Condition::IncCounts()
00140 {
00141 TRACE((12,"TGo4Condition::IncCounts()",__LINE__, __FILE__));
00142 fiCounts++;
00143 }
00144
00145 Int_t TGo4Condition::Counts()
00146 {
00147 TRACE((12,"TGo4Condition::Counts()",__LINE__, __FILE__));
00148 return fiCounts;
00149 }
00150
00151 Int_t TGo4Condition::TrueCounts()
00152 {
00153 TRACE((12,"TGo4Condition::TrueCounts()",__LINE__, __FILE__));
00154 return fiTrueCounts;
00155 }
00156
00157 void TGo4Condition::ResetCounts()
00158 {
00159 TRACE((12,"TGo4Condition::ResetCounts()",__LINE__, __FILE__));
00160 fiTrueCounts=0;
00161 fiCounts=0;
00162 }
00163
00164 void TGo4Condition::SetCounts(Int_t truecounts, Int_t counts)
00165 {
00166 TRACE((12,"TGo4Condition::SetCounts()",__LINE__, __FILE__));
00167 fiTrueCounts=truecounts;
00168 fiCounts=counts;
00169 }
00170
00171
00172
00173 void TGo4Condition::Invert(Bool_t on)
00174 {
00175 TRACE((12,"TGo4Condition::Invert",__LINE__, __FILE__));
00176 fbTrue = on ^ true;
00177 fbFalse = on ^ false;
00178 }
00179
00180
00181 void TGo4Condition::PrintCondition(Bool_t full){
00182 Float_t perc;
00183 Text_t line[128];
00184 Text_t num[64];
00185 if(fiCounts==0)perc=0.0;
00186 else perc=100.0/fiCounts*fiTrueCounts;
00187 cout << "Name:" << GetName()
00188 << " type:" << ClassName()
00189 << " title:" << GetTitle() << endl;
00190 if(fbHistogramLink)
00191 cout << "Connected to histogram " << fxHistoName << endl;
00192 if(fbEnabled) strcpy(line,"Is Checked ");
00193 else{
00194 if(fbResult) strcpy(line,"Always True ");
00195 else strcpy(line,"Always False ");
00196 }
00197 if(fbTrue) strcat(line,"normal ");
00198 else strcat(line,"inverse ");
00199 snprintf(num,63,", tested: %8d true: %8d is %3.0f%%",fiCounts,fiTrueCounts,perc);
00200 strcat(line,num);
00201 cout << line << endl;
00202 }
00203
00204 void TGo4Condition::PrintBar(){
00205 Float_t perc;
00206 Text_t line[128];
00207 Text_t num[64];
00208 strcpy(num,"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
00209 Char_t *pc;
00210 if(fiCounts==0) perc=0.0;
00211 else perc=100.0/fiCounts*fiTrueCounts;
00212 pc=num + (Int_t)perc/2;
00213 *pc=0;
00214 snprintf(line,127,"%-24s %8d %3.0f%% |%-50s|",GetName(),fiCounts,perc,num);
00215 *pc='+';
00216 cout << line << endl;
00217 }
00218
00219 void TGo4Condition::Print(Option_t* opt) const{
00220
00221 TGo4Condition* localthis=const_cast<TGo4Condition*>(this);
00222 TString option=opt;
00223 option.ToLower();
00224 if(option.IsNull() || option=="*")
00225 {
00226
00227 localthis->PrintBar();
00228 }
00229 else
00230 {
00231
00232 TString textbuffer="\nCondition ";
00233 textbuffer+=localthis->GetName();
00234 if(localthis->IsPolygonType())
00235 {
00236 textbuffer+=" (Polygon type, 2-dim)";
00237 }
00238 else
00239 {
00240 textbuffer+=" (Window type,";
00241 if(localthis->GetActiveCondition()->GetDimension()>1)
00242 textbuffer+=" 2-dim)";
00243 else
00244 textbuffer+=" 1-dim)";
00245 }
00246
00247
00248
00249 if(option.Contains("limits"))
00250 {
00251 Text_t buffer[256];
00252 snprintf(buffer,256,
00253 "\n! Xlow: \t\tXup: \t\tYlow: \t\tYup:\n %.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t",
00254 localthis->GetXLow(),localthis->GetXUp(),localthis->GetYLow(),localthis->GetYUp());
00255 textbuffer+=buffer;
00256
00257 }
00258 if(option.Contains("flags"))
00259 {
00260 Text_t buffer[256];
00261 snprintf(buffer,256,
00262 "\n! Status:\n! Enab.: \tVis.: \tRes.: \tTrue: \tCnts: \tTrueCnts:\n %d\t\t%d\t%d\t%d\t%d\t%d",
00263 localthis->fbEnabled, localthis->IsVisible(), localthis->fbResult, localthis->fbTrue,
00264 localthis->Counts(), localthis->TrueCounts());
00265 textbuffer+=buffer;
00266 }
00267 if(option.Contains("stats"))
00268 {
00269
00270
00271 textbuffer+="\n! with";
00272 TH1* hist=localthis->GetWorkHistogram();
00273 if(hist)
00274 {
00275 textbuffer+=" histogram: ";
00276 textbuffer+=hist->GetName();
00277 Text_t buffer[256];
00278 snprintf(buffer,256,
00279 "\n! Int:\t\tXmax:\t\tYmax:\t\tCmax:\t\tXmean:\t\tYmean:\t\tXrms:\t\tYrms:\n %.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f",
00280 localthis->GetIntegral(hist), localthis->GetXMax(hist),localthis->GetYMax(hist), localthis->GetCMax(hist),
00281 localthis->GetMean(hist,1), localthis->GetMean(hist,2), localthis->GetRMS(hist,1), localthis->GetRMS(hist,2));
00282 textbuffer+=buffer;
00283 }
00284 else
00285 {
00286 textbuffer+="out histogram";
00287 }
00288 }
00289
00290 if(option.Contains("go4log"))
00291 {
00292 TGo4Log::Message(1,textbuffer.Data());
00293 }
00294 else
00295 {
00296 cout << textbuffer.Data() << endl;
00297 }
00298 }
00299 }
00300
00301 Bool_t TGo4Condition::UpdateFrom(TGo4Condition * cond, Bool_t counts){
00302 fbTrue = cond->TGo4Condition::IsTrue();
00303 fbFalse = cond->TGo4Condition::IsFalse();
00304 fbResult = cond->TGo4Condition::FixedResult();
00305 fbEnabled = cond->TGo4Condition::IsEnabled();
00306 fbMarkReset = cond->fbMarkReset;
00307 fbVisible=cond->TGo4Condition::IsVisible();
00308 fbLabelDraw=cond->TGo4Condition::IsLabelDraw();
00309 fbMultiEdit=cond->TGo4Condition::IsMultiEdit();
00310 fbIntDraw= cond->TGo4Condition::IsIntDraw();
00311 fbXMeanDraw= cond->TGo4Condition::IsXMeanDraw();
00312 fbXRMSDraw= cond->TGo4Condition::IsXRMSDraw();
00313 fbYMeanDraw= cond->TGo4Condition::IsYMeanDraw();
00314 fbYRMSDraw= cond->TGo4Condition::IsYRMSDraw();
00315 fbXMaxDraw= cond->TGo4Condition::IsXMaxDraw();
00316 fbYMaxDraw= cond->TGo4Condition::IsYMaxDraw();
00317 fbCMaxDraw= cond->TGo4Condition::IsCMaxDraw();
00318 fbHistogramLink=cond->TGo4Condition::IsHistogramLink();
00319 fxHistoName=cond->fxHistoName;
00320 fdUpdateEpsilon= cond->fdUpdateEpsilon;
00321 fiDim=cond->GetDimension();
00322 if(counts){
00323 fiCounts = cond->TGo4Condition::Counts();
00324 fiTrueCounts = cond->TGo4Condition::TrueCounts();
00325 fbMarkReset = false;
00326 }
00327 if(fbMarkReset){
00328 ResetCounts();
00329 fbMarkReset = false;
00330 }
00331
00332 return kTRUE;
00333 }
00334
00335 void TGo4Condition::GetValues(Int_t & dim, Double_t & xmin, Double_t & xmax, Double_t & ymin, Double_t & ymax)
00336 {
00337 xmin = GetXLow();
00338 xmax = GetXUp();
00339 ymin = GetYLow();
00340 ymax = GetYUp();
00341 dim = GetDimension();
00342
00343 }
00344 Double_t TGo4Condition::GetXLow(){return 0;}
00345 Double_t TGo4Condition::GetXUp(){return 0;}
00346 Double_t TGo4Condition::GetYLow(){return 0;}
00347 Double_t TGo4Condition::GetYUp(){return 0;}
00348 TCutG* TGo4Condition::GetCut(Bool_t owner){ return 0;}
00349 Bool_t TGo4Condition::IsPolygonType(){return kFALSE;}
00350 Bool_t TGo4Condition::IsArrayType(){return kFALSE;}
00351 TGo4Condition* TGo4Condition::GetActiveCondition(){return this;}
00352
00353 void TGo4Condition::SetCurrentIndex(Int_t) { }
00354 Int_t TGo4Condition::GetCurrentIndex()
00355 {
00356 return 0;
00357 }
00358
00359 Int_t TGo4Condition::GetNumberOfConditions()
00360 {
00361 return 1;
00362 }
00363
00364 Int_t TGo4Condition::GetMemorySize()
00365 {
00366 Int_t size = sizeof(*this);
00367 if (GetName()!=0) size+=strlen(GetName());
00368 if (GetTitle()!=0) size+=strlen(GetTitle());
00369 return size;
00370 }
00371
00372 void TGo4Condition::MarkReset(Bool_t on)
00373 {
00374 fbMarkReset = on;
00375 }
00376 void TGo4Condition::Clear(Option_t* opt){
00377 ResetCounts();
00378 }
00379
00380 void TGo4Condition::GetFlags(Bool_t* enabled, Bool_t* lastresult, Bool_t* markreset,
00381 Bool_t* result, Bool_t* truevalue, Bool_t* falsevalue)
00382 {
00383 *enabled=fbEnabled;
00384 *lastresult=fbLastResult;
00385 *markreset=fbMarkReset;
00386 *result=fbResult;
00387 *truevalue=fbTrue;
00388 *falsevalue=fbFalse;
00389 }
00390 void TGo4Condition::SetFlags(Bool_t enabled, Bool_t lastresult, Bool_t markreset,
00391 Bool_t result, Bool_t truevalue, Bool_t falsevalue)
00392 {
00393 fbEnabled=enabled;
00394 fbLastResult=lastresult;
00395 fbMarkReset=markreset;
00396 fbResult=result;
00397 fbTrue=truevalue;
00398 fbFalse=falsevalue;
00399 }
00400
00401
00402
00403 Double_t TGo4Condition::GetIntegral(TH1* histo, Option_t* opt)
00404 {
00405 return 0;
00406 }
00407
00408 Double_t TGo4Condition::GetMean(TH1* histo, Int_t axis)
00409 {
00410 return 0;
00411 }
00412 Double_t TGo4Condition::GetRMS(TH1* histo, Int_t axis)
00413 {
00414 return 0;
00415 }
00416 Double_t TGo4Condition::GetXMax(TH1* histo)
00417 {
00418 return 0;
00419 }
00420 Double_t TGo4Condition::GetYMax(TH1* histo)
00421 {
00422 return 0;
00423 }
00424 Double_t TGo4Condition::GetCMax(TH1* histo)
00425 {
00426 return 0;
00427 }
00428
00429 void TGo4Condition::Disable(Bool_t result)
00430 {
00431 fbEnabled=kFALSE;
00432 fbResult=result;
00433 }
00434
00435 void TGo4Condition::Enable()
00436 {
00437 fbEnabled=kTRUE;
00438 }
00439
00440
00441 void TGo4Condition::SetVisible(Bool_t on)
00442 {
00443 fbVisible=on;
00444 }
00445
00446 Bool_t TGo4Condition::IsVisible()
00447 {
00448 return fbVisible;
00449 }
00450
00451 void TGo4Condition::SetHistogramLink(Bool_t on)
00452 {
00453 fbHistogramLink=on;
00454 }
00455
00456 Bool_t TGo4Condition::IsHistogramLink()
00457 {
00458 return (Bool_t) fbHistogramLink;
00459 }
00460
00461 void TGo4Condition::SetLabelDraw(Bool_t on)
00462 {
00463 fbLabelDraw=on;
00464 }
00465
00466 Bool_t TGo4Condition::IsLabelDraw()
00467 {
00468 return fbLabelDraw;
00469 }
00470
00471 void TGo4Condition::SetLimitsDraw(Bool_t on)
00472 {
00473 fbLimitsDraw=on;
00474 }
00475
00476 Bool_t TGo4Condition::IsLimitsDraw()
00477 {
00478 return fbLimitsDraw;
00479 }
00480
00481 void TGo4Condition::SetIntDraw(Bool_t on)
00482 {
00483 fbIntDraw=on;
00484 }
00485 Bool_t TGo4Condition::IsIntDraw()
00486 {
00487 return fbIntDraw;
00488 }
00489 void TGo4Condition::SetXMeanDraw(Bool_t on)
00490 {
00491 fbXMeanDraw=on;
00492 }
00493 Bool_t TGo4Condition::IsXMeanDraw()
00494 {
00495 return fbXMeanDraw;
00496 }
00497 void TGo4Condition::SetXRMSDraw(Bool_t on)
00498 {
00499 fbXRMSDraw=on;
00500 }
00501 Bool_t TGo4Condition::IsXRMSDraw()
00502 {
00503 return fbXRMSDraw;
00504 }
00505 void TGo4Condition::SetYMeanDraw(Bool_t on)
00506 {
00507 fbYMeanDraw=on;
00508 }
00509 Bool_t TGo4Condition::IsYMeanDraw()
00510 {
00511 return fbYMeanDraw;
00512 }
00513 void TGo4Condition::SetYRMSDraw(Bool_t on)
00514 {
00515 fbYRMSDraw=on;
00516 }
00517 Bool_t TGo4Condition::IsYRMSDraw()
00518 {
00519 return fbYRMSDraw;
00520 }
00521 void TGo4Condition::SetXMaxDraw(Bool_t on)
00522 {
00523 fbXMaxDraw=on;
00524 }
00525 Bool_t TGo4Condition::IsXMaxDraw()
00526 {
00527 return fbXMaxDraw;
00528 }
00529 void TGo4Condition::SetYMaxDraw(Bool_t on)
00530 {
00531 fbYMaxDraw=on;
00532 }
00533 Bool_t TGo4Condition::IsYMaxDraw()
00534 {
00535 return fbYMaxDraw;
00536 }
00537 void TGo4Condition::SetCMaxDraw(Bool_t on)
00538 {
00539 fbCMaxDraw=on;
00540 }
00541 Bool_t TGo4Condition::IsCMaxDraw()
00542 {
00543 return fbCMaxDraw;
00544 }
00545
00546 void TGo4Condition::SetHistogram(const char* name)
00547 {
00548 fxHistoName=name;
00549 fbHistogramLink=true;
00550 }
00551
00552 const char* TGo4Condition::GetLinkedHistogram()
00553 {
00554 return fxHistoName.Data();
00555 }
00556
00557 void TGo4Condition::SetPainter(TGo4ConditionPainter*)
00558 {
00559
00560
00561
00562 }
00563
00564
00565 void TGo4Condition::Paint(Option_t* opt)
00566 {
00568 if(fbStreamedCondition) {
00569 SetPainted(kTRUE);
00570 fbStreamedCondition=kFALSE;
00571 }
00572
00573 if(!IsPainted()) return;
00574 if(fxPainter==0) fxPainter=CreatePainter();
00575
00576 if(fxPainter!=0)
00577 {
00578 fxPainter->PaintCondition(opt);
00579 fxPainter->PaintLabel(opt);
00580 }
00581 }
00582
00583 void TGo4Condition::Draw(Option_t* opt)
00584 {
00585 if(TGo4Condition::IsVisible()) {
00586 if(gPad && gPad->GetListOfPrimitives()->FindObject(this)==0) {
00587 UnDraw();
00588 AppendPad(opt);
00589 }
00590 SetPainted(kTRUE);
00591 } else
00592 UnDraw(opt);
00593 }
00594
00595 void TGo4Condition::UnDraw(Option_t* opt)
00596 {
00597 SetPainted(kFALSE);
00598 gROOT->GetListOfCanvases()->RecursiveRemove(this);
00599
00600 if(fxPainter==0) fxPainter=CreatePainter();
00601
00602 if(fxPainter!=0) {
00603 fxPainter->UnPaintCondition(opt);
00604
00605 fxPainter->UnPaintLabel();
00606 }
00607 }
00608
00609 void TGo4Condition::Pop()
00610 {
00611 if(fxPainter!=0) fxPainter->DisplayToFront();
00612 }
00613
00614 TGo4ConditionPainter* TGo4Condition::CreatePainter()
00615 {
00616 return 0;
00617 }
00618
00619 void TGo4Condition::SaveLabelStyle()
00620 {
00621 TGo4Condition::fgbLABELDRAW=fbLabelDraw;
00622 TGo4Condition::fgbLIMITSDRAW=fbLimitsDraw;
00623 TGo4Condition::fgbINTDRAW=fbIntDraw;
00624 TGo4Condition::fgbXMEANDRAW=fbXMeanDraw;
00625 TGo4Condition::fgbXRMSDRAW=fbXRMSDraw;
00626 TGo4Condition::fgbYMEANDRAW=fbYMeanDraw;
00627 TGo4Condition::fgbYRMSDRAW=fbYRMSDraw;
00628 TGo4Condition::fgbXMAXDRAW=fbXMaxDraw;
00629 TGo4Condition::fgbYMAXDRAW=fbYMaxDraw;
00630 TGo4Condition::fgbCMAXDRAW=fbCMaxDraw;
00631 }
00632
00633 void TGo4Condition::InitLabelStyle()
00634 {
00635 fbLabelDraw=TGo4Condition::fgbLABELDRAW;
00636 fbLimitsDraw=TGo4Condition::fgbLIMITSDRAW;
00637 fbIntDraw=TGo4Condition::fgbINTDRAW;
00638 fbXMeanDraw=TGo4Condition::fgbXMEANDRAW;
00639 fbXRMSDraw=TGo4Condition::fgbXRMSDRAW;
00640 fbYMeanDraw=TGo4Condition::fgbYMEANDRAW;
00641 fbYRMSDraw=TGo4Condition::fgbYRMSDRAW;
00642 fbXMaxDraw=TGo4Condition::fgbXMAXDRAW;
00643 fbYMaxDraw=TGo4Condition::fgbYMAXDRAW;
00644 fbCMaxDraw=TGo4Condition::fgbCMAXDRAW;
00645 }
00646
00647 void TGo4Condition::ResetLabel(Option_t* opt)
00648 {
00649 if(fxPainter) {
00650 fxPainter->UnPaintLabel(opt);
00651 fxPainter->PaintLabel();
00652 }
00653 }
00654
00655 void TGo4Condition::SetWorkHistogram(TH1* histo)
00656 {
00657 fxHisto=histo;
00658 delete fxCutHis;
00659 fxCutHis=0;
00660 }
00661
00662 void TGo4Condition::DeletePainter()
00663 {
00664 if (fxPainter!=0) {
00665 delete fxPainter;
00666 fxPainter = 0;
00667 }
00668 }
00669
00670