]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/macros/AddTaskScale.C
Merge branch 'master' into TPCdev
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / macros / AddTaskScale.C
1 AliAnalysisTaskScale* AddTaskScale(
2   const char *nTracks        = "Tracks",
3   const char *nClusters      = "CaloClustersCorr",
4   Double_t    trackptcut     = 0.150,
5   Double_t    clusptcut      = 0.150,
6   const char *taskname       = "Scale",
7   const char *sfuncPath      = 0,
8   const char *sfuncName      = 0
9 )
10 {  
11   // Get the pointer to the existing analysis manager via the static access method.
12   //==============================================================================
13   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
14   if (!mgr)
15   {
16     ::Error("AddTaskScale", "No analysis manager to connect to.");
17     return NULL;
18   }  
19   
20   // Check the analysis type using the event handlers connected to the analysis manager.
21   //==============================================================================
22   if (!mgr->GetInputEventHandler())
23   {
24     ::Error("AddTaskScale", "This task requires an input event handler");
25     return NULL;
26   }
27   
28   //-------------------------------------------------------
29   // Init the task and do settings
30   //-------------------------------------------------------
31
32   TString name(Form("%s_%s_%s_%d_%d", taskname, nTracks, nClusters, TMath::FloorNint(trackptcut*1000), TMath::FloorNint(clusptcut*1000)));
33   AliAnalysisTaskScale *scaletask = new AliAnalysisTaskScale(name);
34   AliParticleContainer *pcont = scaletask->AddParticleContainer(nTracks);
35   if(pcont) {
36     pcont->SetParticlePtCut(trackptcut);
37     pcont->SetParticleEtaLimits(-0.7,0.7); // only accept tracks in the EMCal eta range
38   }
39   AliClusterContainer  *ccont = scaletask->AddClusterContainer(nClusters);
40   if(ccont) ccont->SetClusPtCut(clusptcut);
41
42   if (sfuncPath != 0 && sfuncName != 0) {
43     TFile *file = TFile::Open(sfuncPath);
44     if (file && !file->IsZombie()) {
45       TF1* sfunc = dynamic_cast<TF1*>(file->Get(sfuncName));
46
47       if (sfunc) {
48         scaletask->SetScaleFunction(sfunc);
49         ::Info("AddTaskScale", Form("Scale function %s loaded from file %s.", sfuncName, sfuncPath));
50       }
51       else {
52         ::Error("AddTaskScale", Form("Scale function %s not found in file %s.", sfuncName, sfuncPath));
53       }
54       
55       file->Close();
56       delete file;
57       file = 0;
58     }
59     else {
60       ::Warning("AddTaskScale", "Could not open scale function file");
61     }
62   }
63
64   //-------------------------------------------------------
65   // Final settings, pass to manager and set the containers
66   //-------------------------------------------------------
67
68   mgr->AddTask(scaletask);
69
70   // Create containers for input/output
71   TString contname(name);
72   contname += "_Histos";
73   mgr->ConnectInput (scaletask, 0, mgr->GetCommonInputContainer() );
74   AliAnalysisDataContainer *coscale = mgr->CreateContainer(contname,
75                                                            TList::Class(),
76                                                            AliAnalysisManager::kOutputContainer,
77                                                            Form("%s", AliAnalysisManager::GetCommonFileName()));
78   mgr->ConnectOutput(scaletask,1,coscale);
79
80   return scaletask;
81 }