Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CHistogram.cxx

Go to the documentation of this file.
00001 //
00002 // CHistogram class
00003 //
00004 // Tetsuo Arisawa 2000/06/16
00005 // for HistoDisplay v.1.62 class
00006 //
00007 // 2000/09/01 T.A
00008 // Version 2.0
00009 // fSubtractHisto is cloned internally. Destructor is ok.
00010 // Version 3.0
00011 // Draw(), Paint() with UpdateTObject in CObject.
00012 // Version 3.1 2000 09/15
00013 //
00014 
00015 #include "CHistogram.h"
00016 #include <iostream> // cout,endl
00017 
00018 #include "TVirtualPad.h" //gPad
00019 #include "TList.h"
00020 
00021 #ifdef CDF
00022   #include "EdmUtilities/CdfClassImp.hh"
00023   CdfClassImp(CHistogram)
00024 #else
00025   ClassImp(CHistogram)
00026 #endif
00027   
00028 CHistogram::CHistogram(TH1 *h1, const TObject *inputsource,
00029                        TH1 *subtracthisto, TH1 *refhisto )
00030   : CObject(h1, inputsource),fSubtractHisto(NULL), fRefHisto(refhisto),
00031     fHistoDrawn(NULL)
00032 {
00033   SetSubtractHisto( subtracthisto );
00034   UpdateHisto();
00035 }
00036 
00037 CHistogram::CHistogram(const CHistogram &chisto)
00038     :CObject()
00039 {
00040   if (this != &chisto) copy(chisto);
00041 }
00042 
00043 
00044 CHistogram::CHistogram(const CObject &cobj)
00045     :CObject()
00046 {
00047   TObject *obj = cobj.GetTObject();
00048   if ( obj && obj->InheritsFrom(TH1::Class()) ) 
00049     CHistogram( (TH1*)obj, cobj.GetInputSource(), 0, 0);
00050 }
00051 
00052 CHistogram::CHistogram():CObject(){}
00053 
00054 
00055 void CHistogram::copy(const CHistogram &chisto) 
00056 {
00057   TH1 *histo = (TH1*) chisto.GetTObject();
00058 
00059   if ( !histo ) return;
00060 
00061   if ( fTObject && fTObject != chisto.fTObject ) delete fTObject;
00062   //fTObject = histo->Clone();
00063   fTObject = histo;
00064 
00065   fInputSource = chisto.GetInputSource();
00066 
00067   TH1 *subtracthisto =  (TH1*) chisto.GetSubtractHisto() ;
00068   SetSubtractHisto( subtracthisto );
00069 
00070   fRefHisto = chisto.GetRefHisto();
00071 
00072   UpdateHisto();
00073 
00074 }
00075 
00076 void CHistogram::free() 
00077 {
00078   if ( fSubtractHisto ) {
00079     delete fSubtractHisto;
00080     fSubtractHisto = 0;
00081   }
00082 
00083   if ( fHistoDrawn ) {
00084     delete fHistoDrawn;
00085     fHistoDrawn = 0;
00086   }
00087 
00088   //if ( fTObject ) delete fTObject; // done by ~CObject()
00089 
00090 }
00091 
00092 
00093 CHistogram::~CHistogram(){
00094   free();
00095 }
00096 
00097 
00098 CHistogram& CHistogram::operator=(const CHistogram &chisto) {
00099   if (this != &chisto) {
00100     free();
00101     copy(chisto);
00102   }
00103   return *this;
00104 }
00105 
00106 void CHistogram::SetSubtractHisto(TH1* subtracthisto){
00107   // Set histo to be subtracted.
00108   // subtracthisto's clone is stored internally.
00109 
00110   if ( fSubtractHisto && fSubtractHisto != subtracthisto )
00111     delete fSubtractHisto;
00112 
00113   if ( subtracthisto ) {
00114     fSubtractHisto = (TH1*) subtracthisto->Clone();
00115   }
00116   else {
00117     fSubtractHisto = 0;
00118   }
00119 
00120   UpdateHisto();
00121 
00122 }
00123 
00124 void CHistogram::SetRefHisto(TH1* refhisto){
00125   fRefHisto = refhisto;
00126 }
00127 
00128 
00129 TH1* CHistogram::SubtractedHisto()
00130 {
00131   // return subtracted histogram.
00132 
00133   TH1 *histo;
00134   if ( fTObject && fTObject->InheritsFrom( TH1::Class() ) ) {
00135     histo = (TH1*)fTObject;
00136   }
00137   else {
00138     return 0;
00139   }
00140 
00141   TH1* histonew = (TH1*)( histo->Clone() );
00142 
00143   TH1 *subtracthisto = fSubtractHisto;
00144 
00145   if ( histonew && subtracthisto) {
00146 
00147     histonew->Add(subtracthisto, -1.);
00148 
00149     histonew
00150       ->SetEntries( histo->GetEntries() 
00151                     - subtracthisto->GetEntries() );
00152 
00153    // After Root Version 2.23.12
00154     Stat_t s1[10], s2[10];
00155     Int_t i;
00156     for (i=0;i<10;i++) {s1[i] = s2[i] = 0;}
00157     histo->GetStats(s1);
00158     subtracthisto->GetStats(s2);
00159     for (i=0;i<10;i++) s1[i] -= s2[i];
00160     histonew->PutStats(s1);
00161     //-
00162 
00163   } //if (histonew && subtracthisto) 
00164 
00165   return histonew;
00166 }
00167 
00168 
00169 void CHistogram::UpdateHisto()
00170 {
00171   if ( fHistoDrawn ) delete fHistoDrawn;
00172   fHistoDrawn = SubtractedHisto();
00173 }
00174 
00175 
00176 void CHistogram::Draw( Option_t *option )
00177 {
00178   //if ( fHistoDrawn ) fHistoDrawn->Draw( option );
00179 
00180   if ( option == "" ) option = fTObject->GetOption();
00181 
00182   TString opt = option;
00183   opt.ToLower();
00184   if (gPad && !opt.Contains("same")) {
00185     //the following statement is necessary in case one attempts to draw
00186     //a temporary histogram already in the current pad
00187     if ( TestBit(kCanDelete) ) gPad->GetListOfPrimitives()->Remove(this);
00188     gPad->Clear();
00189   }
00190   AppendPad(opt.Data());
00191 
00192 }
00193 
00194 
00195 void CHistogram::Paint( Option_t *option )
00196 {
00197   if ( fHistoDrawn ) fHistoDrawn->Paint( option );
00198 }
00199 
00200 
00201 

Generated on Mon Feb 15 11:06:31 2010 for loon by  doxygen 1.3.9.1