]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Changing binning when adding histogram, if needed.
authormfloris <mfloris@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 31 Mar 2011 19:39:36 +0000 (19:39 +0000)
committermfloris <mfloris@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 31 Mar 2011 19:39:36 +0000 (19:39 +0000)
OADB/AliOADBPWG2Spectra.cxx
OADB/AliOADBPWG2Spectra.h

index db537c073d3ab82c21737d556ae76b0aba4e0cfd..6cd7ae3aab3e71a824fd6e8c8e0a1b76715277cd 100644 (file)
@@ -10,7 +10,7 @@
 
 ClassImp(AliOADBPWG2Spectra)
 
-const char * AliOADBPWG2Spectra::fDetectorNames[] = {"ITS", "ITSTPC", "TPC", "TOF", "TOFTPC"};
+const char * AliOADBPWG2Spectra::fDetectorNames[] = {"ITS", "ITSTPC", "TPC", "TOF", "TOFTPC", "Dummy", "Dummy"};
 const char * AliOADBPWG2Spectra::fPidTypeNames[]  = {"GaussFit", "NSigma", "Bayes", "Kinks"};
 const char * AliOADBPWG2Spectra::fChargeTags[]    = {"Pos", "Neg"};
 const char * AliOADBPWG2Spectra::fParticleNames[] = {"Pion", "Kaon", "Proton"};
@@ -59,6 +59,7 @@ const char * AliOADBPWG2Spectra::GetHistoName(EPWG2SpectraDetector det, EPWG2Spe
   // h[Name]_[Detector(s)]_[PIDType]_[Particle]_[Pos|Neg]_[MultiplicityOrCentralityIndex]
   // where "name" is the name of this container
 
+  
   static TString histoName;
   if (centrTag)
     histoName.Form("h%s_%s_%s_%s_%s_%s_%d", GetName(), fDetectorNames[det], fPidTypeNames[pidType], fParticleNames[part], fChargeTags[charge], centrTag, centrBin);
@@ -81,8 +82,20 @@ TH1D * AliOADBPWG2Spectra::GetHisto(EPWG2SpectraDetector det, EPWG2SpectraPIDTyp
 void  AliOADBPWG2Spectra::AddHisto(TH1D * h, EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
                                    EPWG2SpectraCharge charge, const char * centrTag, Int_t centrBin) {
   // Add a histogram to the list
-  // Rename it if necessary
+  // Rename and rebinn it if necessary
+  
+  if(!h) {
+    AliWarning("Empty pointer to histogram");
+    return;
+  }
+  
   const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin);
+  static TH1D * htest = BookHisto(kDetDummy, kGaussFit,kPion, kPos);
+  if(!CompareBinning(h,htest)){
+    AliWarning("Histo have different binning! Rebinning to standard"){
+      h = GetHistoStandardBinning(h,det,pidType,part,charge,centrTag,centrBin);
+    }
+  }
   TH1D * hold = (TH1D*) fHistos->FindObject(name);
   if (hold) fHistos->Remove(hold);
   delete hold;
@@ -123,3 +136,50 @@ void AliOADBPWG2Spectra::Browse(TBrowser *b)
    else
       TObject::Browse(b);
 }
+
+TH1D * AliOADBPWG2Spectra::GetHistoStandardBinning(const TH1D* h, EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
+                                                  EPWG2SpectraCharge charge, const char * centrTag, Int_t centrBin) {
+  // Returns a histo with the standard binning and the same content of h
+  // if the bins of h are not a subset of the standard binning, it crashes with a fatal error
+  // under and overflows are ignored
+  
+  // 1. Create a histogram with the standard binning
+  TH1D * hStd = BookHisto(det,  pidType,  part, charge, centrTag, centrBin);
+  Int_t nBinsH1=hStd->GetNbinsX();
+  Int_t nBinsH2=h->GetNbinsX();
+  // Loop over standard bins, 
+  for(Int_t iBin=1; iBin<=nBinsH1; iBin++){
+    Float_t lowPtH1 =hStd->GetBinLowEdge(iBin);
+    Float_t binWidH1=hStd->GetBinWidth(iBin);
+    // Loop over H2 bins and find overlapping bins to H1
+    for(Int_t jBin=1; jBin<=nBinsH2; jBin++){
+      Float_t lowPtH2=h->GetBinLowEdge(jBin);
+      Float_t binWidH2=h->GetBinWidth(jBin);
+      if(TMath::Abs(lowPtH1-lowPtH2)<0.001 && TMath::Abs(binWidH2-binWidH1)<0.001){
+       hStd->SetBinContent(jBin, h->GetBinContent(iBin));
+       hStd->SetBinError  (jBin, h->GetBinError  (iBin));
+       break;
+      }
+      if(TMath::Abs(lowPtH1-lowPtH2)<0.001){
+       AliFatal(Form("Found partially overlapping bins! [(%f,%f)(%f,%f)]",lowPtH1,binWidH1,lowPtH2,binWidH2));
+      }
+    }
+  }
+  return hStd;
+}
+
+Bool_t AliOADBPWG2Spectra::CompareBinning(TH1 * h1, TH1 * h2) {
+
+  // returns true if h1 and h2 have the same binning
+  Int_t nbins1 = h1->GetNbinsX();
+  Int_t nbins2 = h2->GetNbinsX();
+  
+  if(nbins1 != nbins2) return kFALSE;
+  
+  for(Int_t ibin = 1; ibin <= nbins1; ibin++){
+    if(TMath::Abs(h1->GetBinLowEdge(ibin) - h2->GetBinLowEdge(ibin))<0.001) return kFALSE;
+    if(TMath::Abs(h1->GetBinWidth(ibin) - h2->GetBinWidth(ibin))<0.001) return kFALSE;
+  }
+  
+  return kTRUE;
+}
index f89c8bac0cb2c82c7631767b09c2674b2f2cf2c7..d6985f1d63f88be6228b8446852c068da70909f6 100644 (file)
 
 class TList;
 class TH1D;
-
+class TH1;
 class AliOADBPWG2Spectra : public TNamed {
 
  public :
 
-  enum EPWG2SpectraDetector { kITSsa=0, kITSTPC, kTPC, kTOF, kTOFTPC, kNDetectors };
+  enum EPWG2SpectraDetector { kITSsa=0, kITSTPC, kTPC, kTOF, kTOFTPC, kNDetectors, kDetDummy };
   enum EPWG2SpectraPIDType  { kGaussFit=0, kNSigma, kBayes, kKinks, kNPIDTypes };
   enum EPWG2SpectraCharge   { kPos=0, kNeg, kNCharge };
-  enum EPWG2SpectraParticle { kPion = 0, kKaon, kProton };
+  enum EPWG2SpectraParticle { kPion = 0, kKaon, kProton, kNParticle };
   AliOADBPWG2Spectra();
   AliOADBPWG2Spectra(char* name);
   virtual ~AliOADBPWG2Spectra();
@@ -36,6 +36,10 @@ class AliOADBPWG2Spectra : public TNamed {
   TH1D * BookHisto(EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
                   EPWG2SpectraCharge charge, const char * centrTag = 0, Int_t centrBin = -1) ;
     
+  TH1D * GetHistoStandardBinning(const TH1D* h, EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
+                                EPWG2SpectraCharge charge, const char * centrTag, Int_t centrBin) ;
+
+  Bool_t CompareBinning(TH1 * h1, TH1 * h2) ;
 
   virtual void Print (const Option_t * opt = "") const  { fHistos->Print(opt); }