]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/qaRec/AliTRDrecoTask.cxx
Transfer of the initialisation of the QA Data objects in the framework; clean the...
[u/mrichter/AliRoot.git] / TRD / qaRec / AliTRDrecoTask.cxx
index 6019cc11f51182ff2a11538c0f9fb3a667588ece..f9144b3b0677f9cf2f158d55fbf8f59387b2de06 100644 (file)
@@ -4,6 +4,8 @@
 #include "TMethodArg.h"
 #include "TFile.h"
 #include "TList.h"
+#include "TH1.h"
+#include "TF1.h"
 #include "TObjArray.h"
 #include "TDirectory.h"
 #include "TTreeStream.h"
@@ -14,7 +16,7 @@
 #include "AliTRDrecoTask.h"
 
 ClassImp(AliTRDrecoTask)
-
+FILE* AliTRDrecoTask::fgFile = 0x0;
 //_______________________________________________________
 AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
   : AliAnalysisTask(name, title)
@@ -35,6 +37,7 @@ AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
 //_______________________________________________________
 AliTRDrecoTask::~AliTRDrecoTask() 
 {
+  printf(" %s (%s)\n", GetName(), GetTitle());
   if(fDebugStream){ 
     delete fDebugStream;
     fDebugStream = 0x0;
@@ -47,10 +50,16 @@ AliTRDrecoTask::~AliTRDrecoTask()
   }
   
   if(fContainer){
-    //fContainer->Delete();
+    if(fContainer->IsOwner()) fContainer->Delete();
     delete fContainer;
     fContainer = 0x0;
   }
+
+  if(fgFile){
+    fflush(fgFile);
+    fclose(fgFile);
+    fgFile = 0x0;
+  }
 }
 
 //_______________________________________________________
@@ -91,9 +100,20 @@ void AliTRDrecoTask::Exec(Option_t *)
 }
 
 //_______________________________________________________
-void AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
+Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
 {
   AliWarning("Retrieving reference figures not implemented.");
+  return kFALSE;
+}
+
+//_______________________________________________________
+Bool_t AliTRDrecoTask::PutTrendValue(Char_t *name, Double_t val, Double_t err)
+{
+  if(!fgFile){
+    fgFile = fopen("TRD.Performance.txt", "at");
+  }
+  fprintf(fgFile, "%s_%s %f %f\n", GetName(), name, val, err);
+  return kTRUE;
 }
 
 //_______________________________________________________
@@ -108,18 +128,47 @@ void AliTRDrecoTask::InitFunctorList()
     if(!name.BeginsWith("Plot")) continue;
     if(!fPlotFuncList) fPlotFuncList = new TList();
     fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
-    printf("%s%s\n", m->GetName(), m->GetSignature());
   }
 }
 
 //_______________________________________________________
 Bool_t AliTRDrecoTask::Load(const Char_t *filename)
 {
-  if(!TFile::Open(filename)) return kFALSE;
-  TObjArray *o = (TObjArray*)gFile->Get(GetName());
+  if(!TFile::Open(filename)){
+    AliWarning(Form("Couldn't open file %s.", filename));
+    return kFALSE;
+  }
+  TObjArray *o = 0x0;
+  if(!(o = (TObjArray*)gFile->Get(GetName()))){
+    AliWarning("Missing histogram container.");
+    return kFALSE;
+  }
   fContainer = (TObjArray*)o->Clone(GetName());
   gFile->Close();
-  return kFALSE;
+  return kTRUE;
+}
+
+//________________________________________________________
+Bool_t AliTRDrecoTask::Save(TObjArray *results){
+  //
+  // Store the output graphs in a ROOT file
+  // Input TObject array will not be written as Key to the file,
+  // only content itself
+  //
+
+  TDirectory *cwd = gDirectory;
+  if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;
+
+  TIterator *iter = results->MakeIterator();
+  TObject *inObject = 0x0, *outObject = 0x0;
+  while((inObject = iter->Next())){
+    outObject = inObject->Clone();
+    outObject->Write(0x0, TObject::kSingleKey);
+  }
+  delete iter;
+  gFile->Close(); delete gFile;
+  cwd->cd(); 
+  return kTRUE;
 }
 
 //_______________________________________________________
@@ -135,7 +184,37 @@ void AliTRDrecoTask::SetDebugLevel(Int_t level)
   fDebugLevel = level;
   if(fDebugLevel>=1){
     TDirectory *savedir = gDirectory;
-    fDebugStream = new TTreeSRedirector(Form("TRD.Debug%s.root", GetName()));
+    fDebugStream = new TTreeSRedirector(Form("TRD.DBG%s.root", GetName()));
     savedir->cd();
   }
 }
+
+//________________________________________________________
+void AliTRDrecoTask::Adjust(TF1 *f, TH1 *h)
+{
+// Helper function to avoid duplication of code
+// Make first guesses on the fit parameters
+
+  // find the intial parameters of the fit !! (thanks George)
+  Int_t nbinsy = Int_t(.5*h->GetNbinsX());
+  Double_t sum = 0.;
+  for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
+  f->SetParLimits(0, 0., 3.*sum);
+  f->SetParameter(0, .9*sum);
+
+  f->SetParLimits(1, -.2, .2);
+  f->SetParameter(1, -0.1);
+
+  f->SetParLimits(2, 0., 4.e-1);
+  f->SetParameter(2, 2.e-2);
+  if(f->GetNpar() <= 4) return;
+
+  f->SetParLimits(3, 0., sum);
+  f->SetParameter(3, .1*sum);
+
+  f->SetParLimits(4, -.3, .3);
+  f->SetParameter(4, 0.);
+
+  f->SetParLimits(5, 0., 1.e2);
+  f->SetParameter(5, 2.e-1);
+}