]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG3/hfe/AliHFEcontainer.cxx
Major update of the HFE package (comments inside the code
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEcontainer.cxx
index 0cb937e44454560032964928de8ed431e036afdc..6353b2983cb44d6bd27d1847c080054e3bf9208e 100644 (file)
@@ -25,6 +25,7 @@
 #include <TClass.h>
 #include <TCollection.h>
 #include <THashList.h>
+#include <THnSparse.h>
 #include <TList.h>
 #include <TObjArray.h>
 #include <TObjString.h>
@@ -41,6 +42,7 @@ ClassImp(AliHFEcontainer::AliHFEvarInfo)
 AliHFEcontainer::AliHFEcontainer():
   TNamed("HFEcontainer", ""),
   fContainers(NULL),
+  fCorrelationMatrices(NULL),
   fVariables(NULL),
   fNVars(0),
   fNEvents(0)
@@ -49,12 +51,14 @@ AliHFEcontainer::AliHFEcontainer():
   // Default constructor
   //
   fContainers = new THashList();
+  fContainers->SetOwner();
 }
 
 //__________________________________________________________________
 AliHFEcontainer::AliHFEcontainer(const Char_t *name):
   TNamed(name, ""),
   fContainers(NULL),
+  fCorrelationMatrices(NULL),
   fVariables(NULL),
   fNVars(0),
   fNEvents(0)
@@ -63,12 +67,14 @@ AliHFEcontainer::AliHFEcontainer(const Char_t *name):
   // Default constructor
   //
   fContainers = new THashList();
+  fContainers->SetOwner();
 }
 
 //__________________________________________________________________
 AliHFEcontainer::AliHFEcontainer(const Char_t *name, UInt_t nVar):
   TNamed(name, ""),
   fContainers(NULL),
+  fCorrelationMatrices(NULL),
   fVariables(NULL),
   fNVars(0),
   fNEvents(0)
@@ -78,6 +84,7 @@ AliHFEcontainer::AliHFEcontainer(const Char_t *name, UInt_t nVar):
   // Setting Number of Variables too
   //
   fContainers = new THashList();
+  fContainers->SetOwner();
   SetNumberOfVariables(nVar);
 }
 
@@ -85,22 +92,37 @@ AliHFEcontainer::AliHFEcontainer(const Char_t *name, UInt_t nVar):
 AliHFEcontainer::AliHFEcontainer(const AliHFEcontainer &ref):
   TNamed(ref),
   fContainers(NULL),
+  fCorrelationMatrices(NULL),
   fVariables(NULL),
   fNVars(ref.fNVars),
   fNEvents(ref.fNEvents)
 {
   //
   // Copy constructor
-  // creates a new object with new containers
+  // creates a new object with new (empty) containers
   //
-  fContainers = new THashList;
-  for(Int_t ien = 0; ien < ref.fContainers->GetEntries(); ien++)
-    fContainers->Add(new AliCFContainer(*dynamic_cast<AliCFContainer *>(ref.fContainers->At(ien))));
   if(fNVars){
     fVariables = new TObjArray(fNVars);
     for(UInt_t ivar = 0; ivar < fNVars; ivar++)
       fVariables->AddAt(new AliHFEvarInfo(*dynamic_cast<AliHFEvarInfo *>(ref.fVariables->UncheckedAt(ivar))), ivar);
   }
+  fContainers = new THashList;
+  fContainers->SetOwner();
+  AliCFContainer *ctmp = NULL;
+  for(Int_t ien = 0; ien < ref.fContainers->GetEntries(); ien++){
+    ctmp = dynamic_cast<AliCFContainer *>(ref.fContainers->At(ien));
+    CreateContainer(ctmp->GetName(), ctmp->GetTitle(), ctmp->GetNStep());
+  }
+  // Copy also correlation matrices
+  if(ref.fCorrelationMatrices){
+    THnSparseF *htmp = NULL;
+    fCorrelationMatrices = new THashList;
+    fCorrelationMatrices->SetOwner();
+    for(Int_t ien = 0; ien < ref.fCorrelationMatrices->GetEntries(); ien++){
+      htmp = dynamic_cast<THnSparseF *>(ref.fCorrelationMatrices->At(ien));
+      CreateCorrelationMatrix(htmp->GetName(), htmp->GetTitle());
+    }
+  }
 }
 
 //__________________________________________________________________
@@ -122,7 +144,16 @@ AliHFEcontainer &AliHFEcontainer::operator=(const AliHFEcontainer &ref){
   } else {
     fVariables = NULL;
   }
-
+  // Copy also correlation matrices
+  if(ref.fCorrelationMatrices){
+    THnSparseF *htmp = NULL;
+    fCorrelationMatrices = new THashList;
+    fCorrelationMatrices->SetOwner();
+    for(Int_t ien = 0; ien < ref.fCorrelationMatrices->GetEntries(); ien++){
+      htmp = dynamic_cast<THnSparseF *>(ref.fCorrelationMatrices->At(ien));
+      CreateCorrelationMatrix(htmp->GetName(), htmp->GetTitle());
+    }
+  }
   return *this;
 }
 
@@ -131,8 +162,8 @@ AliHFEcontainer::~AliHFEcontainer(){
   //
   // Destructor
   //
-  fContainers->Delete();
   delete fContainers;
+  if(fCorrelationMatrices) delete fCorrelationMatrices;
   if(fVariables){
     fVariables->Delete();
     delete fVariables;
@@ -161,6 +192,12 @@ Long64_t AliHFEcontainer::Merge(TCollection *coll){
     containers.Add(cont->fContainers);
     fContainers->Merge(&containers);
 
+    if(fCorrelationMatrices && cont->fCorrelationMatrices){
+      containers.Clear();
+      containers.Add(cont->fCorrelationMatrices);
+      fCorrelationMatrices->Merge(&containers);
+    }
+
     fNEvents += cont->GetNumberOfEvents();
     count++;
   }
@@ -206,7 +243,40 @@ void AliHFEcontainer::CreateContainer(const Char_t *name, const Char_t *title, U
 }
 
 //__________________________________________________________________
-AliCFContainer *AliHFEcontainer::GetCFContainer(const Char_t *name){
+void AliHFEcontainer::CreateCorrelationMatrix(const Char_t *name, const Char_t *title){
+  //
+  // Create Correlation Matrix
+  //
+  if(!fCorrelationMatrices){
+    fCorrelationMatrices = new THashList;
+    fCorrelationMatrices->SetName("fCorrelationMatrices");
+    fCorrelationMatrices->SetOwner();
+  }
+
+  Int_t *nBins = new Int_t[2*fNVars];
+  AliHFEvarInfo *var = NULL;
+  for(UInt_t ivar = 0; ivar < fNVars; ivar++){
+    var = dynamic_cast<AliHFEvarInfo *>(fVariables->UncheckedAt(ivar));
+    nBins[ivar] = var->GetNumberOfBins();
+    nBins[ivar+fNVars] = var->GetNumberOfBins();
+  }
+
+  THnSparseF * hTmp = new THnSparseF(name, title, 2*fNVars, nBins);
+  for(UInt_t ivar = 0; ivar < fNVars; ivar++){
+    var = dynamic_cast<AliHFEvarInfo *>(fVariables->UncheckedAt(ivar));
+    hTmp->SetBinEdges(ivar,var->GetBinning());
+    //hTmp->GetAxis(ivar)->Set(var->GetNumberOfBins(), var->GetBinning());
+    hTmp->GetAxis(ivar)->SetTitle(var->GetVarName()->Data());
+    //hTmp->GetAxis(ivar + fNVars)->Set(var->GetNumberOfBins(), var->GetBinning());
+    hTmp->GetAxis(ivar + fNVars)->SetTitle(Form("%s_{MC}", var->GetVarName()->Data()));
+    hTmp->SetBinEdges(ivar+fNVars,var->GetBinning());
+  }
+  hTmp->Sumw2();
+  fCorrelationMatrices->AddLast(hTmp);
+}
+
+//__________________________________________________________________
+AliCFContainer *AliHFEcontainer::GetCFContainer(const Char_t *name) const{
   //
   // Find a given container 
   //
@@ -214,13 +284,46 @@ AliCFContainer *AliHFEcontainer::GetCFContainer(const Char_t *name){
 }
 
 //__________________________________________________________________
-void AliHFEcontainer::FillCFContainer(const Char_t *name, UInt_t step, Double_t *content){
+THnSparseF *AliHFEcontainer::GetCorrelationMatrix(const Char_t *name) const{
+  //
+  // Find Correlation Matrix
+  //
+  return dynamic_cast<THnSparseF *>(fCorrelationMatrices->FindObject(name));
+}
+
+//__________________________________________________________________
+void AliHFEcontainer::FillCFContainer(const Char_t *name, UInt_t step, Double_t *content, Double_t weight) const {
+  //
+  // Fill container
+  //
+  AliCFContainer *cont = GetCFContainer(name);
+  if(!cont) return;
+  cont->Fill(content, step, weight);
+}
+
+//__________________________________________________________________
+void AliHFEcontainer::FillCFContainerStepname(const Char_t *name, const Char_t *steptitle, Double_t *content, Double_t weight)const{
   //
   // Fill container
   //
   AliCFContainer *cont = GetCFContainer(name);
   if(!cont) return;
-  cont->Fill(content, step);
+  // find the matching step title
+  Int_t mystep = -1;
+  for(Int_t istep = 0; istep < cont->GetNStep(); istep++){
+    TString tstept = cont->GetStepTitle(istep);
+    if(!tstept.CompareTo(steptitle)){
+      mystep = istep;
+      break;
+    }
+  }
+  if(mystep < 0){
+    // step not found
+    AliDebug(1, Form("Step %s not found in container %s", steptitle, name));
+    return;
+  }
+  AliDebug(1, Form("Filling step %s(%d) for container %s", steptitle, mystep, name));
+  cont->Fill(content, mystep, weight);
 }
 
 //__________________________________________________________________
@@ -250,12 +353,6 @@ AliCFContainer *AliHFEcontainer::MakeMergedCFContainer(const Char_t *name, const
   for(UInt_t ibin = 0; ibin < fNVars; ibin++) dummyBinning[ibin] = 1;
   AliCFContainer *cmerged = new AliCFContainer(name, title, nStepMerged, fNVars, dummyBinning);
   delete dummyBinning;
-  // cleanup old container content so that we can fill it with the new content
-  AliInfo("Removing temporary grids");
-  for(Int_t istep = 0; istep < cmerged->GetNStep(); istep++){
-    AliCFGridSparse *grid = cmerged->GetGrid(istep);
-    delete grid;
-  }
   // Fill container with content
   AliInfo("Filling new container");
   Int_t cstep = 0;
@@ -268,6 +365,18 @@ AliCFContainer *AliHFEcontainer::MakeMergedCFContainer(const Char_t *name, const
   }
   return cmerged;
 }
+
+//__________________________________________________________________
+void AliHFEcontainer::SetStepTitle(const Char_t *contname, const Char_t *steptitle, UInt_t step){
+  //
+  // Set title for given analysis step in container with name contname
+  //
+  AliCFContainer *cont = GetCFContainer(contname);
+  if(!cont) return;
+  if(step >= static_cast<UInt_t>(cont->GetNStep())) return;
+  cont->SetStepTitle(step, steptitle);
+}
+
 //__________________________________________________________________
 void AliHFEcontainer::MakeLinearBinning(UInt_t var, UInt_t nBins, Double_t begin, Double_t end){
   //