Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4WinCond.cxx

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

Generated on Fri Nov 28 12:59:07 2008 for Go4-v3.04-1 by  doxygen 1.4.2