Adding abstract class for comparison components
[u/mrichter/AliRoot.git] / PWG1 / AliComparisonEff.cxx
index 46278ff..747b260 100644 (file)
@@ -4,26 +4,31 @@
 // it keeps selection cuts used during comparison. The comparison \r
 // information is stored in the ROOT histograms. Analysis of these \r
 // histograms can be done by using Analyse() class function. The result of \r
-// the analysis (histograms) are stored in the output picture_eff.root file.\r
-//  \r
+// the analysis (histograms/graphs) are stored in the folder which is \r
+// a data member of AliComparisonEff.\r
+// \r
 // Author: J.Otwinowski 04/02/2008 \r
 //------------------------------------------------------------------------------\r
 \r
 /*\r
-  // after running analysis, read the file, and get component\r
\r
+  // after running comparison task, read the file, and get component\r
   gSystem->Load("libPWG1.so");\r
   TFile f("Output.root");\r
-  AliComparisonEff * comp = (AliComparisonEff*)f.Get("AliComparisonEff");\r
+  AliComparisonEff * compObj = (AliComparisonEff*)f.Get("AliComparisonEff");\r
 \r
+  // analyse comparison data\r
+  compObj->Analyse();\r
+\r
+  // the output histograms/graphs will be stored in the folder "folderEff" \r
+  compObj->GetAnalysisFolder()->ls("*");\r
+\r
+  // user can save whole comparison object (or only folder with anlysed histograms) \r
+  // in the seperate output file (e.g.)\r
+  TFile fout("Analysed_Eff.root","recreate");\r
+  compObj->Write(); // compObj->GetAnalysisFolder()->Write();\r
+  fout.Close();\r
 \r
-  // analyse comparison data (output stored in pictures_eff.root)\r
-  comp->Analyse();\r
\r
-  // paramtetrisation of the TPC track length (for information only)\r
-  TF1 fl("fl","((min(250./(abs(x+0.000001)),250)-90))",0,2);  // length function\r
-  TF1 fl2("fl2","[0]/((min(250./(abs(x+0.000001)),250)-90))^[1]",0,2);\r
-  fl2.SetParameter(1,1);\r
-  fl2.SetParameter(0,1);\r
 */\r
 \r
 \r
@@ -66,7 +71,7 @@ ClassImp(AliComparisonEff)
 \r
 //_____________________________________________________________________________\r
 AliComparisonEff::AliComparisonEff():\r
-  TNamed("AliComparisonEff","AliComparisonEff"),\r
+  AliComparisonObject("AliComparisonEff"),\r
 \r
   // histograms\r
  \r
@@ -103,7 +108,10 @@ AliComparisonEff::AliComparisonEff():
   fCutsRC(0), \r
   fCutsMC(0),\r
 \r
-  fVertex(0)\r
+  fVertex(0),\r
+\r
+  // histogram folder \r
+  fAnalysisFolder(0)\r
 {\r
   // init vertex\r
   fVertex = new AliESDVertex();\r
@@ -125,15 +133,14 @@ AliComparisonEff::AliComparisonEff():
        fTPCPtDCAXYPid[i]=0;   \r
        fTPCPtDCAZPid[i]=0; \r
   }\r
-  InitHisto();\r
-  InitCuts();\r
+  Init();\r
 }\r
 \r
 //_____________________________________________________________________________\r
 AliComparisonEff::~AliComparisonEff(){\r
 \r
   // \r
-  if(fMCPt)  delete  fEffTPCPt; fEffTPCPt=0;\r
+  if(fMCPt)  delete  fMCPt; fMCPt=0;\r
   if(fMCRecPt)  delete  fMCRecPt; fMCRecPt=0;\r
   if(fMCRecPrimPt)  delete  fMCRecPrimPt; fMCRecPrimPt=0;\r
   if(fMCRecSecPt)  delete  fMCRecSecPt; fMCRecSecPt=0;\r
@@ -184,10 +191,12 @@ AliComparisonEff::~AliComparisonEff(){
        if(fTPCPtDCAXYPid[i]) delete  fTPCPtDCAXYPid[i]; fTPCPtDCAXYPid[i]=0;\r
        if(fTPCPtDCAZPid[i]) delete   fTPCPtDCAZPid[i];  fTPCPtDCAZPid[i]=0;\r
   }\r
+\r
+  if(fAnalysisFolder) delete fAnalysisFolder; fAnalysisFolder=0;\r
 }\r
 \r
 //_____________________________________________________________________________\r
-void AliComparisonEff::InitHisto(){\r
+void AliComparisonEff::Init(){\r
 \r
   // Init histograms\r
   //\r
@@ -317,16 +326,15 @@ void AliComparisonEff::InitHisto(){
     sprintf(name, "fTPCPtDCAZPid_%d",i);\r
        fTPCPtDCAZPid[i]= new TH3F(name,name,50,0.1,3,100,0,100,5,0,5);\r
   }\r
-}\r
-\r
-//_____________________________________________________________________________\r
-void AliComparisonEff::InitCuts()\r
-{\r
 \r
+  // init cuts\r
   if(!fCutsMC) \r
     AliDebug(AliLog::kError, "ERROR: Cannot find AliMCInfoCuts object");\r
   if(!fCutsRC) \r
     AliDebug(AliLog::kError, "ERROR: Cannot find AliRecInfoCuts object");\r
+\r
+  // init folder\r
+  fAnalysisFolder = CreateFolder("folderEff","Analysis Efficiency Folder");\r
 }\r
 \r
 //_____________________________________________________________________________\r
@@ -335,8 +343,6 @@ void AliComparisonEff::Process(AliMCInfo* infoMC, AliESDRecInfo *infoRC)
   // Fill efficiency comparison information\r
   \r
   AliExternalTrackParam *track = 0;\r
-  Double_t kRadius    = 3.0;      // beam pipe radius\r
-  Double_t kMaxStep   = 5.0;      // max step\r
   Double_t field      = AliTracker::GetBz(); // nominal Bz field [kG]\r
   Double_t kMaxD      = 123456.0; // max distance\r
 \r
@@ -387,11 +393,8 @@ void AliComparisonEff::Process(AliMCInfo* infoMC, AliESDRecInfo *infoRC)
     {\r
       if ((track = new AliExternalTrackParam(*infoRC->GetESDtrack()->GetTPCInnerParam())) != 0 )\r
       {\r
-\r
-        Bool_t bStatus = AliTracker::PropagateTrackTo(track,kRadius,infoMC->GetMass(),kMaxStep,kTRUE);\r
         Bool_t bDCAStatus = track->PropagateToDCA(fVertex,field,kMaxD,dca,cov);\r
-\r
-               if(bStatus && bDCAStatus) {\r
+               if(bDCAStatus) {\r
                //\r
                cov[2] = track->GetCovariance()[2];\r
 \r
@@ -607,8 +610,7 @@ Long64_t AliComparisonEff::Merge(TCollection* list)
   while((obj = iter->Next()) != 0) \r
   {\r
     AliComparisonEff* entry = dynamic_cast<AliComparisonEff*>(obj);\r
-    if (entry == 0) \r
-      continue; \r
+    if (entry == 0) continue; \r
   \r
     fMCPt->Add(entry->fMCPt);\r
     fMCRecPt->Add(entry->fMCRecPt);\r
@@ -665,24 +667,29 @@ return count;
 //_____________________________________________________________________________\r
 void AliComparisonEff::Analyse() \r
 {\r
-  // Analyse output histograms\r
+  // Analyse comparison information and store output histograms\r
+  // in the folder "folderEff" \r
+  //\r
   \r
+  TH1::AddDirectory(kFALSE);\r
+\r
   AliComparisonEff * comp=this;\r
+  TFolder *folder = comp->GetAnalysisFolder();\r
 \r
-  // calculate efficiency and contamination (4 sigma) \r
+  // recreate folder every time\r
+  if(folder) delete folder;\r
+  folder = CreateFolder("folderEff","Analysis Eff Folder");\r
+  folder->SetOwner();\r
 \r
+  // calculate efficiency and contamination (4 sigma) \r
   TH1 *h_sigmaidealpid[20];\r
   TH1 *h_sigmafullpid[20];\r
   TH1 *h_sigmaday0pid[20];\r
 \r
-  //TH1 *h_sigmaday0pidclone[20];\r
-\r
   TH1 *h_sigmaidealpidtot[4];\r
   TH1 *h_sigmafullpidtot[4];\r
   TH1 *h_sigmaday0pidtot[4];\r
 \r
-  //TH1 *h_sigmaday0pidtotclone[4];\r
-\r
   char name[256];\r
   char name1[256];\r
   Int_t idx;\r
@@ -731,7 +738,6 @@ void AliComparisonEff::Analyse()
        sprintf(name,"h_sigmaday0pid_%d",idx);\r
        h_sigmaday0pid[idx] = comp->fTPCPtDCASigmaDay0Pid[i]->Project3D();\r
        h_sigmaday0pid[idx]->SetName(name);\r
-\r
        } \r
   }\r
 \r
@@ -772,70 +778,80 @@ void AliComparisonEff::Analyse()
     h_sigmaday0pid[idx+15]->Divide(h_sigmaday0pidtot[2]);\r
   }\r
 \r
-  // write results\r
-  TFile *fp = new TFile("pictures_eff.root","recreate");\r
-  fp->cd();\r
-\r
   TCanvas * c = new TCanvas("Efficiency","Track efficiency");\r
   c->cd();\r
 \r
-  fMCPt->Write();\r
-  fMCRecPt->Write();\r
-  fMCRecPrimPt->Write();\r
-  fMCRecSecPt->Write();\r
-\r
-  for(int i = 0; i<4;i++)  \r
-  {\r
-   comp->fTPCPtDCASigmaIdealPid[i]->GetYaxis()->SetRange();\r
-   comp->fTPCPtDCASigmaIdealPid[i]->GetZaxis()->SetRange();\r
-   comp->fTPCPtDCASigmaFullPid[i]->GetYaxis()->SetRange();\r
-   comp->fTPCPtDCASigmaFullPid[i]->GetZaxis()->SetRange();\r
-   comp->fTPCPtDCASigmaDay0Pid[i]->GetYaxis()->SetRange();\r
-   comp->fTPCPtDCASigmaDay0Pid[i]->GetZaxis()->SetRange();\r
-\r
-    comp->fTPCPtDCASigmaIdealPid[i]->Write();\r
-    comp->fTPCPtDCASigmaFullPid[i]->Write();\r
-    comp->fTPCPtDCASigmaDay0Pid[i]->Write();\r
-  }\r
   //\r
   comp->fEffTPCTanF->SetXTitle("Tan(#theta)");\r
   comp->fEffTPCTanF->SetYTitle("eff_{findable}");\r
-  comp->fEffTPCTanF->Write("EffTanFindable");\r
+  comp->fEffTPCTanF->SetName("EffTanFindable");\r
   //\r
   comp->fEffTPCTan->SetXTitle("Tan(#theta)");\r
   comp->fEffTPCTan->SetYTitle("eff_{all}");\r
-  comp->fEffTPCTan->Write("EffTanAll");\r
+  comp->fEffTPCTan->SetName("EffTanAll");\r
 \r
-  h_sigmaidealpidtot[1]->Write("Eff_SigmaIdeal");\r
-  h_sigmaidealpidtot[3]->Write("Cont_SigmaIdeal");\r
+  if(folder) folder->Add(comp->fEffTPCTanF);\r
+  if(folder) folder->Add(comp->fEffTPCTan);\r
 \r
-  h_sigmafullpidtot[1]->Write("Eff_SigmaFull");\r
-  h_sigmafullpidtot[3]->Write("Cont_SigmaFull");\r
+  h_sigmaidealpidtot[1]->SetName("Eff_SigmaIdeal");\r
+  h_sigmaidealpidtot[3]->SetName("Cont_SigmaIdeal");\r
 \r
-  h_sigmaday0pidtot[1]->Write("Eff_SigmaDay0");\r
-  h_sigmaday0pidtot[3]->Write("Cont_SigmaDay0");\r
+  if(folder) folder->Add(h_sigmaidealpidtot[1]);\r
+  if(folder) folder->Add(h_sigmaidealpidtot[3]);\r
+\r
+  h_sigmafullpidtot[1]->SetName("Eff_SigmaFull");\r
+  h_sigmafullpidtot[3]->SetName("Cont_SigmaFull");\r
+\r
+  if(folder) folder->Add(h_sigmafullpidtot[1]);\r
+  if(folder) folder->Add(h_sigmafullpidtot[3]);\r
+\r
+  h_sigmaday0pidtot[1]->SetName("Eff_SigmaDay0");\r
+  h_sigmaday0pidtot[3]->SetName("Cont_SigmaDay0");\r
+\r
+  if(folder) folder->Add(h_sigmaday0pidtot[1]);\r
+  if(folder) folder->Add(h_sigmaday0pidtot[3]);\r
 \r
   for(Int_t idx = 0; idx<5; idx++)\r
   {\r
     sprintf(name,"Eff_SigmaIdeal_%d",idx);\r
     sprintf(name1,"Cont_SigmaIdeal_%d",idx);\r
 \r
-    h_sigmaidealpid[idx+5]->Write(name);\r
-    h_sigmaidealpid[idx+15]->Write(name1);\r
+    h_sigmaidealpid[idx+5]->SetName(name);\r
+    h_sigmaidealpid[idx+15]->SetName(name1);\r
+\r
+       if(folder) folder->Add(h_sigmaidealpid[idx+5]);\r
+       if(folder) folder->Add(h_sigmaidealpid[idx+15]);\r
 \r
     sprintf(name,"Eff_SigmaFull_%d",idx);\r
     sprintf(name1,"Cont_SigmaFull_%d",idx);\r
 \r
-    h_sigmafullpid[idx+5]->Write(name);\r
-    h_sigmafullpid[idx+15]->Write(name1);\r
+    h_sigmafullpid[idx+5]->SetName(name);\r
+    h_sigmafullpid[idx+15]->SetName(name1);\r
+\r
+       if(folder) folder->Add(h_sigmafullpid[idx+5]);\r
+       if(folder) folder->Add(h_sigmafullpid[idx+15]);\r
 \r
     sprintf(name,"Eff_SigmaDay0_%d",idx);\r
     sprintf(name1,"Cont_SigmaDay0_%d",idx);\r
 \r
-    h_sigmaday0pid[idx+5]->Write(name);\r
-    h_sigmaday0pid[idx+15]->Write(name1);\r
+    h_sigmaday0pid[idx+5]->SetName(name);\r
+    h_sigmaday0pid[idx+15]->SetName(name1);\r
+\r
+       if(folder) folder->Add(h_sigmaday0pid[idx+5]);\r
+       if(folder) folder->Add(h_sigmaday0pid[idx+15]);\r
   }\r
 \r
-  //\r
-  fp->Close();\r
+  // set pointer to fAnalysisFolder\r
+  fAnalysisFolder = folder;\r
+\r
+}\r
+\r
+//_____________________________________________________________________________\r
+TFolder* AliComparisonEff::CreateFolder(TString name,TString title) { \r
+// create folder for analysed histograms\r
+//\r
+TFolder *folder = 0;\r
+  folder = new TFolder(name.Data(),title.Data());\r
+\r
+  return folder;\r
 }\r