-///////////////////////////////////////////////////////
-//
-// Basic class for Performance/Calibration TRD tasks
-//
-// It performs generic tasks like :
-// - data file manegment
-// - reference container management
-// - debug container management
-// - interaction with AliAnalysisManager
-// - Plot functor loop
-//
-// Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008
-//
-/////////////////////////////////////////////////////////
-
-#include "TClass.h"
-#include "TMethod.h"
-#include "TMethodCall.h"
-#include "TMethodArg.h"
-#include "TFile.h"
-#include "TChain.h"
-#include "TList.h"
-#include "TMap.h"
-#include "TH1.h"
-#include "TF1.h"
-#include "TObjArray.h"
-#include "TDirectory.h"
-#include "TTreeStream.h"
-
-#include "AliLog.h"
-#include "AliAnalysisTask.h"
-
-#include "info/AliTRDeventInfo.h"
-#include "AliTRDrecoTask.h"
-
-ClassImp(AliTRDrecoTask)
-
-TList* AliTRDrecoTask::fgTrendPoint(NULL);
-TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);
-//_______________________________________________________
-AliTRDrecoTask::AliTRDrecoTask()
- : AliAnalysisTaskSE()
- ,fNRefFigures(0)
- ,fContainer(NULL)
- ,fEvent(NULL)
- ,fTracks(NULL)
- ,fkTrack(NULL)
- ,fkMC(NULL)
- ,fkESD(NULL)
- ,fPlotFuncList(NULL)
- ,fRunTerminate(kFALSE)
-{
-// Default constructor
- snprintf(fNameId, 10, "no name");
-}
-
-//_______________________________________________________
-AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)
- : AliAnalysisTaskSE(name)
- ,fNRefFigures(0)
- ,fContainer(NULL)
- ,fEvent(NULL)
- ,fTracks(NULL)
- ,fkTrack(NULL)
- ,fkMC(NULL)
- ,fkESD(NULL)
- ,fPlotFuncList(NULL)
- ,fRunTerminate(kFALSE)
-{
-// Constructor for all derived performance tasks
-
- SetTitle(title);
- snprintf(fNameId, 10, "no name");
- DefineInput (1, TObjArray::Class()); // track list
- DefineOutput(1, TObjArray::Class()); // histogram list
-}
-
-//_______________________________________________________
-AliTRDrecoTask::~AliTRDrecoTask()
-{
-
- // Generic task destructor
-
- AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));
- if(fgDebugStream){
- delete fgDebugStream;
- fgDebugStream = NULL;
- }
-
- if(fPlotFuncList){
- fPlotFuncList->Delete();
- delete fPlotFuncList;
- fPlotFuncList = NULL;
- }
-
- if(fContainer){
- if(fContainer->IsOwner()) fContainer->Delete();
- delete fContainer;
- fContainer = NULL;
- }
-
- if(fgTrendPoint){
- TFile::Open("TRD.PerformanceTrend.root", "UPDATE");
- fgTrendPoint->Write();
- delete fgTrendPoint;
- fgTrendPoint=NULL;
- gFile->Close();
- }
-}
-
-//_______________________________________________________
-Int_t AliTRDrecoTask::GetNRefFigures() const
-{
- if(!fNRefFigures) AliWarning("No reference plots available.");
- return fNRefFigures;
-}
-
-//_______________________________________________________
-void AliTRDrecoTask::UserCreateOutputObjects()
-{
- if(!HasFunctorList()) InitFunctorList();
- fContainer = Histos();
- PostData(1, fContainer);
-}
-
-//_______________________________________________________
-void AliTRDrecoTask::UserExec(Option_t *)
-{
-// Loop over Plot functors published by particular tasks
-
- fTracks = dynamic_cast<TObjArray *>(GetInputData(1));
- fEvent = dynamic_cast<AliTRDeventInfo *>(GetInputData(2));
- if(!fPlotFuncList){
- AliWarning("No functor list defined for the reference plots");
- return;
- }
- if(!fTracks) return;
- if(!fTracks->GetEntriesFast()) return;
- else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));
-
- AliTRDtrackInfo *trackInfo = NULL;
- TIter plotIter(fPlotFuncList);
- TObjArrayIter trackIter(fTracks);
- while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){
- fkTrack = trackInfo->GetTrack();
- fkMC = trackInfo->GetMCinfo();
- fkESD = trackInfo->GetESDinfo();
-
- TMethodCall *plot = NULL;
- plotIter.Reset();
- while((plot=dynamic_cast<TMethodCall*>(plotIter()))){
- plot->Execute(this);
- }
- }
-}
-
-//_______________________________________________________
-Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)
-{
- AliWarning("Retrieving reference figures not implemented.");
- return kFALSE;
-}
-
-//_______________________________________________________
-Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)
-{
-// Generic publisher for trend values
-
- if(!fgTrendPoint){
- fgTrendPoint = new TList();
- fgTrendPoint->SetOwner();
- }
- fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));
- return kTRUE;
-}
-
-//_______________________________________________________
-void AliTRDrecoTask::InitFunctorList()
-{
-// Initialize list of functors
-
- TClass *c = this->IsA();
-
- TMethod *m = NULL;
- TIter methIter(c->GetListOfMethods());
- while((m=dynamic_cast<TMethod*>(methIter()))){
- TString name(m->GetName());
- if(!name.BeginsWith("Plot")) continue;
- if(!fPlotFuncList) fPlotFuncList = new TList();
- fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));
- }
-}
-
-//_______________________________________________________
-Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)
-{
-// Generic container loader
-
- if(!TFile::Open(file)){
- AliWarning(Form("Couldn't open file %s.", file));
- return kFALSE;
- }
- if(!gFile->cd(dir)){
- AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
- return kFALSE;
- }
- TObjArray *o = NULL;
- if(!(o = (TObjArray*)gDirectory->Get(GetName()))){
- AliWarning("Missing histogram container.");
- return kFALSE;
- }
- fContainer = (TObjArray*)o->Clone(GetName());
- gFile->Close();
- return kTRUE;
-}
-
-//________________________________________________________
-Bool_t AliTRDrecoTask::Save(TObjArray * const 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 = NULL, *outObject = NULL;
- while((inObject = iter->Next())){
- outObject = inObject->Clone();
- outObject->Write(NULL, TObject::kSingleKey);
- }
- delete iter;
- gFile->Close(); delete gFile;
- cwd->cd();
- return kTRUE;
-}
-
-//_______________________________________________________
-Bool_t AliTRDrecoTask::PostProcess()
-{
-// To be implemented by particular tasks
-
- AliWarning("Post processing of reference histograms not implemented.");
- return kTRUE;
-}
-
-//_______________________________________________________
-void AliTRDrecoTask::MakeSummary()
-{
-// To be implemented by particular tasks
- AliWarning("Summary not available");
-}
-
-//_______________________________________________________
-void AliTRDrecoTask::SetDebugLevel(Int_t level)
-{
-// Generic debug handler
-
- AliAnalysisTaskSE::SetDebugLevel(level);
- if(DebugLevel()>=1){
- AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));
- TDirectory *savedir = gDirectory;
- fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");
- savedir->cd();
- }
-}
-
-//____________________________________________________________________
-void AliTRDrecoTask::Terminate(Option_t *)
-{
- //
- // Terminate
- //
-
- if(fgDebugStream){
- delete fgDebugStream;
- fgDebugStream = NULL;
- }
- fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));
- if(fContainer && fRunTerminate){
- PostProcess();
- MakeSummary();
- }
-}
-
-//________________________________________________________
-void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const 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);
-}
+///////////////////////////////////////////////////////\r
+//\r
+// Basic class for Performance/Calibration TRD tasks\r
+// \r
+// It performs generic tasks like :\r
+// - data file manegment\r
+// - reference container management\r
+// - debug container management\r
+// - interaction with AliAnalysisManager\r
+// - Plot functor loop\r
+//\r
+// Author: Alexandru Bercuci <A.Bercuci@gsi.de>, 10/09/2008\r
+//\r
+/////////////////////////////////////////////////////////\r
+\r
+#include "TClass.h"\r
+#include "TMethod.h"\r
+#include "TMethodCall.h"\r
+#include "TMethodArg.h"\r
+#include "TFile.h"\r
+#include "TChain.h"\r
+#include "TList.h"\r
+#include "TMap.h"\r
+#include "TH1.h"\r
+#include "TF1.h"\r
+#include "TObjArray.h"\r
+#include "TDirectory.h"\r
+#include "TTreeStream.h"\r
+\r
+#include "AliLog.h"\r
+#include "AliAnalysisTask.h"\r
+\r
+#include "info/AliTRDeventInfo.h"\r
+#include "AliTRDrecoTask.h"\r
+\r
+ClassImp(AliTRDrecoTask)\r
+\r
+TList* AliTRDrecoTask::fgTrendPoint(NULL);\r
+TTreeSRedirector* AliTRDrecoTask::fgDebugStream(NULL);\r
+//_______________________________________________________\r
+AliTRDrecoTask::AliTRDrecoTask()\r
+ : AliAnalysisTaskSE()\r
+ ,fNRefFigures(0)\r
+ ,fContainer(NULL)\r
+ ,fEvent(NULL)\r
+ ,fTracks(NULL)\r
+ ,fkTrack(NULL)\r
+ ,fkMC(NULL)\r
+ ,fkESD(NULL)\r
+ ,fPlotFuncList(NULL)\r
+ ,fRunTerminate(kFALSE)\r
+{\r
+// Default constructor\r
+ snprintf(fNameId, 10, "no name");\r
+}\r
+\r
+//_______________________________________________________\r
+AliTRDrecoTask::AliTRDrecoTask(const char *name, const char *title)\r
+ : AliAnalysisTaskSE(name)\r
+ ,fNRefFigures(0)\r
+ ,fContainer(NULL)\r
+ ,fEvent(NULL)\r
+ ,fTracks(NULL)\r
+ ,fkTrack(NULL)\r
+ ,fkMC(NULL)\r
+ ,fkESD(NULL)\r
+ ,fPlotFuncList(NULL)\r
+ ,fRunTerminate(kFALSE)\r
+{\r
+// Constructor for all derived performance tasks\r
+\r
+ SetTitle(title);\r
+ snprintf(fNameId, 10, "no name");\r
+ DefineInput (1, TObjArray::Class()); // track list\r
+ DefineInput (2, AliTRDeventInfo::Class()); // event info object\r
+ DefineOutput(1, TObjArray::Class()); // histogram list\r
+}\r
+\r
+//_______________________________________________________\r
+AliTRDrecoTask::~AliTRDrecoTask() \r
+{\r
+\r
+ // Generic task destructor\r
+\r
+ AliDebug(2, Form(" Ending task %s[%s]", GetName(), GetTitle()));\r
+ if(fgDebugStream){ \r
+ delete fgDebugStream;\r
+ fgDebugStream = NULL;\r
+ }\r
+\r
+ if(fPlotFuncList){\r
+ fPlotFuncList->Delete();\r
+ delete fPlotFuncList;\r
+ fPlotFuncList = NULL;\r
+ }\r
+ \r
+ if(fContainer){\r
+ if(fContainer->IsOwner()) fContainer->Delete();\r
+ delete fContainer;\r
+ fContainer = NULL;\r
+ }\r
+\r
+ if(fgTrendPoint){\r
+ TFile::Open("TRD.PerformanceTrend.root", "UPDATE");\r
+ fgTrendPoint->Write();\r
+ delete fgTrendPoint;\r
+ fgTrendPoint=NULL;\r
+ gFile->Close();\r
+ }\r
+}\r
+\r
+//_______________________________________________________\r
+Int_t AliTRDrecoTask::GetNRefFigures() const \r
+{ \r
+ if(!fNRefFigures) AliWarning("No reference plots available.");\r
+ return fNRefFigures; \r
+} \r
+\r
+//_______________________________________________________\r
+void AliTRDrecoTask::UserCreateOutputObjects()\r
+{\r
+ if(!HasFunctorList()) InitFunctorList();\r
+ fContainer = Histos();\r
+ PostData(1, fContainer);\r
+}\r
+\r
+//_______________________________________________________\r
+void AliTRDrecoTask::UserExec(Option_t *)\r
+{\r
+// Loop over Plot functors published by particular tasks\r
+\r
+ fTracks = dynamic_cast<TObjArray *>(GetInputData(1));\r
+ fEvent = dynamic_cast<AliTRDeventInfo *>(GetInputData(2));\r
+\r
+ if(!fPlotFuncList){\r
+ AliWarning("No functor list defined for the reference plots");\r
+ return;\r
+ }\r
+ if(!fTracks) return;\r
+ if(!fTracks->GetEntriesFast()) return;\r
+ else AliDebug(2, Form("Tracks[%d] for %s", fTracks->GetEntriesFast(), GetName()));\r
+\r
+ AliTRDtrackInfo *trackInfo = NULL;\r
+ TIter plotIter(fPlotFuncList);\r
+ TObjArrayIter trackIter(fTracks);\r
+ while((trackInfo = dynamic_cast<AliTRDtrackInfo*>(trackIter()))){\r
+ fkTrack = trackInfo->GetTrack();\r
+ fkMC = trackInfo->GetMCinfo();\r
+ fkESD = trackInfo->GetESDinfo();\r
+\r
+ TMethodCall *plot = NULL;\r
+ plotIter.Reset();\r
+ while((plot=dynamic_cast<TMethodCall*>(plotIter()))){\r
+ plot->Execute(this);\r
+ }\r
+ }\r
+}\r
+\r
+//_______________________________________________________\r
+Bool_t AliTRDrecoTask::GetRefFigure(Int_t /*ifig*/)\r
+{\r
+ AliWarning("Retrieving reference figures not implemented.");\r
+ return kFALSE;\r
+}\r
+\r
+//_______________________________________________________\r
+Bool_t AliTRDrecoTask::PutTrendValue(const Char_t *name, Double_t val)\r
+{\r
+// Generic publisher for trend values\r
+\r
+ if(!fgTrendPoint){\r
+ fgTrendPoint = new TList();\r
+ fgTrendPoint->SetOwner();\r
+ }\r
+ fgTrendPoint->AddLast(new TNamed(Form("%s_%s", GetName(), name), Form("%f", val)));\r
+ return kTRUE;\r
+}\r
+\r
+//_______________________________________________________\r
+void AliTRDrecoTask::InitFunctorList()\r
+{\r
+// Initialize list of functors\r
+\r
+ TClass *c = this->IsA();\r
+\r
+ TMethod *m = NULL;\r
+ TIter methIter(c->GetListOfMethods());\r
+ while((m=dynamic_cast<TMethod*>(methIter()))){\r
+ TString name(m->GetName());\r
+ if(!name.BeginsWith("Plot")) continue;\r
+ if(!fPlotFuncList) fPlotFuncList = new TList();\r
+ fPlotFuncList->AddLast(new TMethodCall(c, (const char*)name, ""));\r
+ }\r
+}\r
+\r
+//_______________________________________________________\r
+Bool_t AliTRDrecoTask::Load(const Char_t *file, const Char_t *dir)\r
+{\r
+// Generic container loader\r
+\r
+ if(!TFile::Open(file)){\r
+ AliWarning(Form("Couldn't open file %s.", file));\r
+ return kFALSE;\r
+ }\r
+ if(!gFile->cd(dir)){\r
+ AliWarning(Form("Couldn't cd to %s in %s.", dir, file));\r
+ return kFALSE;\r
+ }\r
+ TObjArray *o = NULL;\r
+ if(!(o = (TObjArray*)gDirectory->Get(GetName()))){\r
+ AliWarning("Missing histogram container.");\r
+ return kFALSE;\r
+ }\r
+ fContainer = (TObjArray*)o->Clone(GetName());\r
+ gFile->Close();\r
+ return kTRUE;\r
+}\r
+\r
+//________________________________________________________\r
+Bool_t AliTRDrecoTask::Save(TObjArray * const results){\r
+ //\r
+ // Store the output graphs in a ROOT file\r
+ // Input TObject array will not be written as Key to the file,\r
+ // only content itself\r
+ //\r
+\r
+ TDirectory *cwd = gDirectory;\r
+ if(!TFile::Open(Form("TRD.Result%s.root", GetName()), "RECREATE")) return kFALSE;\r
+\r
+ TIterator *iter = results->MakeIterator();\r
+ TObject *inObject = NULL, *outObject = NULL;\r
+ while((inObject = iter->Next())){\r
+ outObject = inObject->Clone();\r
+ outObject->Write(NULL, TObject::kSingleKey);\r
+ }\r
+ delete iter;\r
+ gFile->Close(); delete gFile;\r
+ cwd->cd(); \r
+ return kTRUE;\r
+}\r
+\r
+//_______________________________________________________\r
+Bool_t AliTRDrecoTask::PostProcess()\r
+{\r
+// To be implemented by particular tasks\r
+\r
+ AliWarning("Post processing of reference histograms not implemented.");\r
+ return kTRUE;\r
+}\r
+\r
+//_______________________________________________________\r
+void AliTRDrecoTask::MakeSummary()\r
+{\r
+// To be implemented by particular tasks\r
+ AliWarning("Summary not available");\r
+}\r
+\r
+//_______________________________________________________\r
+void AliTRDrecoTask::SetDebugLevel(Int_t level)\r
+{\r
+// Generic debug handler\r
+\r
+ AliAnalysisTaskSE::SetDebugLevel(level);\r
+ if(DebugLevel()>=1){\r
+ AliInfo(Form("Debug Level for Task %s set to %d", GetName(), level));\r
+ TDirectory *savedir = gDirectory;\r
+ fgDebugStream = new TTreeSRedirector("TRD.DebugPerformance.root");\r
+ savedir->cd();\r
+ }\r
+}\r
+\r
+//____________________________________________________________________\r
+void AliTRDrecoTask::Terminate(Option_t *)\r
+{\r
+ //\r
+ // Terminate\r
+ //\r
+\r
+ if(fgDebugStream){ \r
+ delete fgDebugStream;\r
+ fgDebugStream = NULL;\r
+ }\r
+ fContainer = dynamic_cast<TObjArray *>(GetOutputData(1));\r
+ if(fContainer && fRunTerminate){\r
+ PostProcess();\r
+ MakeSummary();\r
+ }\r
+}\r
+\r
+//________________________________________________________\r
+void AliTRDrecoTask::Adjust(TF1 *f, TH1 * const h)\r
+{\r
+// Helper function to avoid duplication of code\r
+// Make first guesses on the fit parameters\r
+\r
+ // find the intial parameters of the fit !! (thanks George)\r
+ Int_t nbinsy = Int_t(.5*h->GetNbinsX());\r
+ Double_t sum = 0.;\r
+ for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;\r
+ f->SetParLimits(0, 0., 3.*sum);\r
+ f->SetParameter(0, .9*sum);\r
+\r
+ f->SetParLimits(1, -.2, .2);\r
+ f->SetParameter(1, -0.1);\r
+\r
+ f->SetParLimits(2, 0., 4.e-1);\r
+ f->SetParameter(2, 2.e-2);\r
+ if(f->GetNpar() <= 4) return;\r
+\r
+ f->SetParLimits(3, 0., sum);\r
+ f->SetParameter(3, .1*sum);\r
+\r
+ f->SetParLimits(4, -.3, .3);\r
+ f->SetParameter(4, 0.);\r
+\r
+ f->SetParLimits(5, 0., 1.e2);\r
+ f->SetParameter(5, 2.e-1);\r
+}\r