]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/macros/AddTaskScale.C
Read scale factor functions from a root file
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / macros / AddTaskScale.C
CommitLineData
c46201cb 1AliAnalysisTaskScale* AddTaskScale(
e61400a6 2 const char *nTracks = "Tracks",
3 const char *nClusters = "CaloClustersCorr",
59f16b27 4 Double_t trackptcut = 0.150,
5 Double_t clusptcut = 0.150,
6 const char *taskname = "Scale",
74807f86 7 const char *sfuncPath = 0,
8 const char *sfuncName = 0
c46201cb 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
59f16b27 32 TString name(Form("%s_%s_%s_%d_%d", taskname, nTracks, nClusters, TMath::FloorNint(trackptcut*1000), TMath::FloorNint(clusptcut*1000)));
e61400a6 33 AliAnalysisTaskScale *scaletask = new AliAnalysisTaskScale(name);
b77147f1 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);
b2603283 40 if(ccont) ccont->SetClusPtCut(clusptcut);
c46201cb 41
74807f86 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
c46201cb 64 //-------------------------------------------------------
65 // Final settings, pass to manager and set the containers
66 //-------------------------------------------------------
67
e61400a6 68 mgr->AddTask(scaletask);
c46201cb 69
70 // Create containers for input/output
a5621834 71 TString contname(name);
72 contname += "_Histos";
e61400a6 73 mgr->ConnectInput (scaletask, 0, mgr->GetCommonInputContainer() );
a5621834 74 AliAnalysisDataContainer *coscale = mgr->CreateContainer(contname,
e61400a6 75 TList::Class(),
76 AliAnalysisManager::kOutputContainer,
74807f86 77 Form("%s", AliAnalysisManager::GetCommonFileName()));
e61400a6 78 mgr->ConnectOutput(scaletask,1,coscale);
c46201cb 79
e61400a6 80 return scaletask;
c46201cb 81}