Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4ConditionsBase/TGo4WinCond.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4WinCond.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TGo4WinCondPainter.h"
00021 #include "Go4Log/TGo4Log.h"
00022 
00023 // -----------------------------------------------
00024 // Constructors
00025 // -----------------------------------------------
00026 TGo4WinCond::TGo4WinCond(const Text_t * name, const Text_t * title)
00027 : TGo4Condition(name,title),
00028 fLow1(0),fUp1(0),fLow2(0),fUp2(0),
00029 fiSaveXMin(0),fiSaveXMax(0),fiSaveYMin(0),fiSaveYMax(0)
00030 {
00031 TRACE((15,"TGo4WinCond::TGo4WinCond(name,title)",__LINE__, __FILE__));
00032 }
00033 // -----------------------------------------------
00034 TGo4WinCond::TGo4WinCond(const Text_t * name)
00035 : TGo4Condition(name,"Go4 window condition"),
00036 fLow1(0),fUp1(0),fLow2(0),fUp2(0),
00037 fiSaveXMin(0),fiSaveXMax(0),fiSaveYMin(0),fiSaveYMax(0)
00038 {
00039 TRACE((15,"TGo4WinCond::TGo4WinCond(name)",__LINE__, __FILE__));
00040 }
00041 // -----------------------------------------------
00042 TGo4WinCond::TGo4WinCond()
00043 : TGo4Condition(),
00044 fLow1(0),fUp1(0),fLow2(0),fUp2(0),
00045 fiSaveXMin(0),fiSaveXMax(0),fiSaveYMin(0),fiSaveYMax(0)
00046 {
00047 TRACE((15,"TGo4WinCond::TGo4WinCond()",__LINE__, __FILE__));
00048 }
00049 // -----------------------------------------------
00050 TGo4WinCond::~TGo4WinCond()
00051 {
00052 TRACE((15,"TGo4WinCond::~TGo4WinCond()",__LINE__, __FILE__));
00053 }
00054 
00055 // -----------------------------------------------
00056 Bool_t TGo4WinCond::Test(Double_t v1, Double_t v2){
00057 IncCounts();
00058 if(!IsEnabled()){
00059   if(FixedResult()) IncTrueCounts();
00060   return FixedResult();
00061 }
00062 if(v1 <  fLow1) return IsFalse();
00063 if(v1 >= fUp1)  return IsFalse();
00064 if(v2 <  fLow2) return IsFalse();
00065 if(v2 >= fUp2)  return IsFalse();
00066 IncTrueCounts();
00067 return IsTrue();
00068 }
00069 // -----------------------------------------------
00070 Bool_t TGo4WinCond::Test(Double_t v1){
00071 IncCounts();
00072 if(!IsEnabled()){
00073   if(FixedResult()) IncTrueCounts();
00074   return FixedResult();
00075 }
00076 if(v1 <  fLow1) return IsFalse();
00077 if(v1 >= fUp1)  return IsFalse();
00078 IncTrueCounts();
00079 return IsTrue();
00080 }
00081 // -----------------------------------------------
00082 void TGo4WinCond::SetValues(Double_t low1, Double_t up1, Double_t low2, Double_t up2){
00083     if(InheritsFrom("TGo4WinCond")){
00084 fLow1 = low1;
00085 fUp1  = up1;
00086 fLow2 = low2;
00087 fUp2  = up2;
00088 SetDimension(2);
00089 }
00090 else cout << "Cannot set window values " << GetName() << " class " << ClassName() << endl;
00091 }
00092 // -----------------------------------------------
00093 void TGo4WinCond::SetValues(Double_t low1, Double_t up1){
00094     if(InheritsFrom("TGo4WinCond")){
00095 fLow1 = low1;
00096 fUp1  = up1;
00097 SetDimension(1);
00098 }
00099 else cout << "Cannot set window values " << GetName() << " class " << ClassName() << endl;
00100 }
00101 // -----------------------------------------------
00102 void TGo4WinCond::GetValues(Int_t & dim, Double_t & x1, Double_t & y1, Double_t & x2, Double_t & y2){
00103 x1  = fLow1;
00104 y1  = fUp1;
00105 x2  = fLow2;
00106 y2  = fUp2;
00107 dim = GetDimension();
00108 }
00109 
00110 Double_t TGo4WinCond::GetXLow()
00111 {
00112    return fLow1;;
00113 }
00114 Double_t TGo4WinCond::GetXUp()
00115 {
00116    return fUp1;;
00117 }
00118 Double_t TGo4WinCond::GetYLow()
00119 {
00120    return fLow2;
00121 }
00122 Double_t TGo4WinCond::GetYUp()
00123 {
00124    return fUp2;
00125 }
00126 
00127 Bool_t TGo4WinCond::IsPolygonType()
00128 {
00129    return kFALSE;
00130 }
00131 // -----------------------------------------------
00132 void TGo4WinCond::PrintCondition(Bool_t limits){
00133    TGo4Condition::PrintCondition();
00134 if(limits)
00135 {
00136 Text_t line[128];
00137 if(GetDimension()==1) snprintf(line,127,"[%8.2f,%8.2f]",fLow1,fUp1);
00138 else         snprintf(line,127,"[%8.2f,%8.2f][%8.2f,%8.2f]",fLow1,fUp1,fLow2,fUp2);
00139 cout << line     << endl;
00140 }}
00141 
00142 
00143 Double_t TGo4WinCond::GetIntegral(TH1* histo, Option_t* opt)
00144 {
00145 if(histo==0) return 0;
00146 Double_t result=0;
00147 SetHistogramRanges(histo);
00148 result=histo->Integral(opt);
00149 RestoreHistogramRanges(histo);
00150 return result;
00151 }
00152 
00153 Double_t TGo4WinCond::GetMean(TH1* histo, Int_t axis)
00154 {
00155 if(histo==0) return 0;
00156 Double_t result=0;
00157 SetHistogramRanges(histo);
00158 result=histo->GetMean(axis);
00159 RestoreHistogramRanges(histo);
00160 return result;
00161 }
00162 Double_t TGo4WinCond::GetRMS(TH1* histo, Int_t axis)
00163 {
00164 if(histo==0) return 0;
00165 Double_t result=0;
00166 SetHistogramRanges(histo);
00167 result=histo->GetRMS(axis);
00168 RestoreHistogramRanges(histo);
00169 return result;
00170 }
00171 Double_t TGo4WinCond::GetXMax(TH1* histo)
00172 {
00173 if(histo==0) return 0;
00174 Double_t result=0;
00175 SetHistogramRanges(histo);
00176 TAxis* xax=histo->GetXaxis();
00177 Int_t maxbin=histo->GetMaximumBin();
00178 if(histo->GetDimension()==1)
00179    {
00180    result=xax->GetBinCenter(maxbin);
00181 
00182    }
00183 else if (histo->GetDimension()==2)
00184    {
00185       Int_t xmaxbin=maxbin%(histo->GetNbinsX()+2);
00186       result=xax->GetBinCenter(xmaxbin);
00187    }
00188 else
00189    {
00190       result=0; // no support for 3d histos at the moment!
00191    }
00192 RestoreHistogramRanges(histo);
00193 return result;
00194 }
00195 Double_t TGo4WinCond::GetYMax(TH1* histo)
00196 {
00197 if(histo==0) return 0;
00198 Double_t result=0;
00199 SetHistogramRanges(histo);
00200 if(histo->GetDimension()==1)
00201    {
00202       result=histo->GetMaximum();
00203    }
00204 else if (histo->GetDimension()==2)
00205    {
00206       TAxis* yax=histo->GetYaxis();
00207       Int_t maxbin=histo->GetMaximumBin();
00208       Int_t maxybin=maxbin/(histo->GetNbinsX()+2);
00209       result=yax->GetBinCenter(maxybin);
00210    }
00211 else
00212    {
00213       result=0; // no support for 3d histos at the moment!
00214    }
00215 RestoreHistogramRanges(histo);
00216 return result;
00217 }
00218 Double_t TGo4WinCond::GetCMax(TH1* histo)
00219 {
00220 if(histo==0) return 0;
00221 Double_t result=0;
00222 SetHistogramRanges(histo);
00223 result=histo->GetMaximum();
00224 RestoreHistogramRanges(histo);
00225 return result;
00226 }
00227 
00228 void TGo4WinCond::SetHistogramRanges(TH1* histo)
00229 {
00230 if(histo==0) return;
00231 Double_t xmin=fLow1;
00232 Double_t xmax=fUp1;
00233 Double_t ymin=fLow2;
00234 Double_t ymax=fUp2;
00235 TAxis* xax=histo->GetXaxis();
00236 fiSaveXMin=xax->GetFirst();
00237 fiSaveXMax=xax->GetLast();
00238 Int_t xminbin=xax->FindBin(xmin);
00239 Int_t xmaxbin=xax->FindBin(xmax);
00240 Int_t yminbin=0;
00241 Int_t ymaxbin=0;
00242 TAxis* yax=histo->GetYaxis();
00243 if(yax && histo->GetDimension()>1)
00244 {
00245    fiSaveYMin=yax->GetFirst();
00246    fiSaveYMax=yax->GetLast();
00247    yminbin=yax->FindBin(ymin);
00248    ymaxbin=yax->FindBin(ymax);
00249 }
00250     // set histo range to condition limits
00251 xax->SetRange(xminbin,xmaxbin);
00252 if(yax&& histo->GetDimension()>1)
00253    yax->SetRange(yminbin,ymaxbin);
00254 }
00255 
00256 void TGo4WinCond::RestoreHistogramRanges(TH1* histo)
00257 {
00258 if(histo==0) return;
00259 TAxis* xax=histo->GetXaxis();
00260 TAxis* yax=histo->GetYaxis();
00261 xax->SetRange(fiSaveXMin,fiSaveXMax);
00262 if(yax&& histo->GetDimension()>1)
00263    yax->SetRange(fiSaveYMin,fiSaveYMax);
00264 
00265 
00266 }
00267 
00268 
00269 
00270 // -----------------------------------------------
00271 Bool_t TGo4WinCond::UpdateFrom(TGo4Condition * cond, Bool_t counts){
00272    if(!TGo4Condition::UpdateFrom(cond,counts)) return kFALSE;
00273    if(cond->InheritsFrom("TGo4WinCond"))
00274       {
00275          //cout << "Update " << GetName() << endl;
00276          Int_t dimension=0;
00277          ((TGo4WinCond*)cond)->GetValues(dimension,fLow1,fUp1,fLow2,fUp2);  // get limits from source
00278          SetDimension(dimension);
00279          return kTRUE;
00280       }
00281    else
00282       {
00283          cout << "Cannot update " << GetName() << " from " << cond->ClassName() << endl;
00284          return kFALSE;
00285       }
00286 }
00287 
00288 void TGo4WinCond::SetPainter(TGo4ConditionPainter* painter)
00289 {
00290 // delete old painter, replace by the new one
00291 // overwritten method in subclass may check if painter is correct type
00292 if(painter==0) return;
00293 if(painter->InheritsFrom("TGo4WinCondPainter"))
00294    {
00295       if(fxPainter) delete fxPainter;
00296       fxPainter=painter;
00297       fxPainter->SetCondition(this);
00298    }
00299 else
00300    {
00301       TGo4Log::Warn("Could not set painter of class %s for TGo4WinCond %s",
00302          painter->IsA()->GetName(),GetName());
00303    }
00304 }
00305 
00306 TGo4ConditionPainter* TGo4WinCond::CreatePainter()
00307 {
00308    TGo4ConditionPainter* painter=new TGo4WinCondPainter(GetName());
00309    painter->SetCondition(this);
00310    return painter;
00311 }
00312 
00313 
00314 ClassImp(TGo4WinCond)
00315 
00316 
00317 
00318 
00319 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:52 2005 for Go4-v2.10-5 by doxygen1.2.15