setting the eta range for clustered tracks, adding the correct signature for backgrou...
[u/mrichter/AliRoot.git] / PWG4 / macros / AddTaskJetCluster.C
1  AliAnalysisTaskJetCluster *AddTaskJetCluster(char* bRec = "AOD",char* bGen = "",UInt_t filterMask = 16, UInt_t iPhysicsSelectionFlag = AliVEvent::kMB,Char_t *jf = "KT", Float_t radius = 0.4,Int_t nSkip = 0,Int_t kWriteAOD = kFALSE,char* deltaFile = "",Float_t ptTrackCut = 0.15);
2
3 Int_t kBackgroundMode = 0;
4 Float_t kPtTrackCut = 0.15;
5 Float_t kTrackEtaCut = 0.8;
6
7 AliAnalysisTaskJetCluster *AddTaskJetClusterDelta(UInt_t filterMask = 16,Bool_t kUseAODMC = kFALSE,UInt_t iPhysicsSelectionFlag = AliVEvent::kMB,Char_t *jf = "KT", UInt_t iFlag){
8    AliAnalysisTaskJetCluster *js = 0;
9    if(kUseAODMC&&false){// do not use the MC info yet
10      if(iFlag&(1<<0))js = AddTaskJetCluster("AOD","AODMC",filterMask,iPhysicsSelectionFlag,jf,0.00001);
11      if(iFlag&(1<<1))js = AddTaskJetCluster("AOD","AODMC",filterMask,iPhysicsSelectionFlag,jf,0.1);
12      if(iFlag&(1<<2))js = AddTaskJetCluster("AOD","AODMC",filterMask,iPhysicsSelectionFlag,jf,0.2);
13      if(iFlag&(1<<4))js = AddTaskJetCluster("AOD","AODMC",filterMask,iPhysicsSelectionFlag,jf,0.4);
14      if(iFlag&(1<<6))js = AddTaskJetCluster("AOD","AODMC",filterMask,iPhysicsSelectionFlag,jf,0.6);
15      if(iFlag&(1<<8))js = AddTaskJetCluster("AOD","AODMC",filterMask,iPhysicsSelectionFlag,jf,0.8);
16      if(iFlag&(1<<10))js = AddTaskJetCluster("AOD","AODMC",filterMask,iPhysicsSelectionFlag,jf,1.0);
17    }
18    else{
19      if(iFlag&(1<<0))js = AddTaskJetCluster("AOD","",filterMask,iPhysicsSelectionFlag,jf,0.00001);
20      if(iFlag&(1<<1))js = AddTaskJetCluster("AOD","",filterMask,iPhysicsSelectionFlag,jf,0.1);
21      if(iFlag&(1<<2))js = AddTaskJetCluster("AOD","",filterMask,iPhysicsSelectionFlag,jf,0.2);
22      if(iFlag&(1<<4))js = AddTaskJetCluster("AOD","",filterMask,iPhysicsSelectionFlag,jf,0.4);
23      if(iFlag&(1<<6))js = AddTaskJetCluster("AOD","",filterMask,iPhysicsSelectionFlag,jf,0.6);
24      if(iFlag&(1<<8))js = AddTaskJetCluster("AOD","",filterMask,iPhysicsSelectionFlag,jf,0.8);
25      if(iFlag&(1<<10))js = AddTaskJetCluster("AOD","",filterMask,iPhysicsSelectionFlag,jf,1.0);
26    }
27
28    return js;
29  }
30
31
32  AliAnalysisTaskJetCluster *AddTaskJetCluster(char* bRec,char* bGen ,UInt_t filterMask,UInt_t iPhysicsSelectionFlag,Char_t *jf,Float_t radius,Int_t nSkip,Int_t kWriteAOD,char *deltaFile,Float_t ptTrackCut)
33  {
34  // Creates a jet fider task, configures it and adds it to the analysis manager.
35    kPtTrackCut = ptTrackCut;
36
37    TString outputFile(deltaFile);
38     // Get the pointer to the existing analysis manager via the static access method.
39     //==============================================================================
40     AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
41     if (!mgr) {
42        ::Error("AddTaskJetCluster", "No analysis manager to connect to.");
43        return NULL;
44     }  
45
46     // Check the analysis type using the event handlers connected to the analysis manager.
47     //==============================================================================
48     if (!mgr->GetInputEventHandler()) {
49       ::Error("AddTaskJetCluster", "This task requires an input event handler");
50        return NULL;
51     }
52
53     TString type = mgr->GetInputEventHandler()->GetDataType();
54     TString typeRec(bRec);
55     TString typeGen(bGen);
56     if(!typeRec.Contains("AODextra")) {
57       typeGen.ToUpper();
58       typeRec.ToUpper();
59     }
60     cout << "typeRec: " << typeRec << endl;
61     // Create the task and configure it.
62     //===========================================================================
63
64
65
66
67     TString cAdd = "";
68     cAdd += Form("%02d_",(int)((radius+0.01)*10.));
69     cAdd += Form("B%d",(int)kBackgroundMode);
70     cAdd += Form("_Filter%05d",filterMask);
71     cAdd += Form("_Cut%05d",(int)(1000.*kPtTrackCut));
72     cAdd += Form("_Skip%02d",nSkip);
73     Printf("%s %E",cAdd.Data(),kPtTrackCut);
74     AliAnalysisTaskJetCluster* pwg4spec = new  AliAnalysisTaskJetCluster(Form("JetCluster%s_%s%s",bRec,jf,cAdd.Data()));
75       
76    // or a config file
77    // pwg4spec->SetAnalysisType(AliAnalysisTaskJetCluster::kAnaMC);
78    // if(iAODanalysis)pwg4spec->SetAODInput(kTRUE);
79    // pwg4spec->SetDebugLevel(11); 
80    pwg4spec->SetFilterMask(filterMask); 
81    //   pwg4spec->SetUseGlobalSelection(kTRUE); 
82
83    if(type == "AOD"){
84      // Assume all jet are produced already
85      pwg4spec->SetAODTrackInput(kTRUE);
86      pwg4spec->SetAODMCInput(kTRUE);
87    }
88
89    if(typeRec.Contains("AODMC2b")){// work down from the top AODMC2b -> AODMC2 -> AODMC -> AOD
90      pwg4spec->SetTrackTypeRec(AliAnalysisTaskJetCluster::kTrackAODMCChargedAcceptance);
91      pwg4spec->SetTrackPtCut(kTrackEtaCut);
92    }
93    else if (typeRec.Contains("AODMC2")){
94      pwg4spec->SetTrackTypeRec(AliAnalysisTaskJetCluster::kTrackAODMCCharged);
95      pwg4spec->SetTrackPtCut(5);
96    }
97    else if (typeRec.Contains("AODMC")){
98      pwg4spec->SetTrackTypeRec(AliAnalysisTaskJetCluster::kTrackAODMCAll);
99      pwg4spec->SetTrackPtCut(5);
100    }
101    else if (typeRec.Contains("AODextraonly")) {
102      pwg4spec->SetTrackTypeRec(AliAnalysisTaskJetCluster::kTrackAODextraonly);
103      pwg4spec->SetTrackPtCut(kPtTrackCut);
104      pwg4spec->SetTrackPtCut(kTrackEtaCut);
105    }
106    else if (typeRec.Contains("AODextra")) {
107      cout << "AliAnalysisTaskJetCluster::kTrackAODextra: " << AliAnalysisTaskJetCluster::kTrackAODextra << endl;
108      pwg4spec->SetTrackTypeRec(AliAnalysisTaskJetCluster::kTrackAODextra);
109      pwg4spec->SetTrackPtCut(kPtTrackCut);
110      pwg4spec->SetTrackPtCut(kTrackEtaCut);
111    }
112    else if (typeRec.Contains("AOD")) {
113      pwg4spec->SetTrackTypeRec(AliAnalysisTaskJetCluster::kTrackAOD);
114      pwg4spec->SetTrackPtCut(kPtTrackCut);
115      pwg4spec->SetTrackPtCut(kTrackEtaCut);
116    }
117
118    pwg4spec->SetRparam(radius);
119
120    switch (jf) {
121    case "ANTIKT":
122      pwg4spec->SetAlgorithm(2); // antikt from fastjet/JetDefinition.hh
123      break;
124    case "CA":
125      pwg4spec->SetAlgorithm(1); // CA from fastjet/JetDefinition.hh
126      break;
127    case "KT":
128      pwg4spec->SetAlgorithm(0); // kt from fastjet/JetDefinition.hh
129      break;
130    default:
131      ::Error("AddTaskJetCluster", "Wrong jet finder selected\n");
132      return 0;
133    }
134
135    
136    if(kWriteAOD){
137      if(outputFile.Length())pwg4spec->SetJetOutputFile(outputFile);
138      pwg4spec->SetJetOutputBranch(Form("clusters%s_%s%s",bRec,jf,cAdd.Data()));
139      pwg4spec->SetJetOutputMinPt(0); // store only jets / clusters above a certain threshold
140    }
141
142    pwg4spec->SetNSkipLeadingRan(nSkip);
143
144    if(iPhysicsSelectionFlag)pwg4spec->SelectCollisionCandidates(iPhysicsSelectionFlag);
145
146    mgr->AddTask(pwg4spec);
147
148    // Create ONLY the output containers for the data produced by the task.
149    // Get and connect other common input/output containers via the manager as below
150    //==============================================================================
151    AliAnalysisDataContainer *coutput1_Spec = mgr->CreateContainer(Form("pwg4cluster_%s_%s_%s%s",bRec,bGen,jf,cAdd.Data()), TList::Class(),AliAnalysisManager::kOutputContainer,Form("%s:PWG4_cluster_%s_%s_%s%s",AliAnalysisManager::GetCommonFileName(),bRec,bGen,jf,cAdd.Data()));
152
153    mgr->ConnectInput  (pwg4spec, 0, mgr->GetCommonInputContainer());
154    mgr->ConnectOutput (pwg4spec, 0, mgr->GetCommonOutputContainer());
155    mgr->ConnectOutput (pwg4spec,  1, coutput1_Spec );
156    
157    return pwg4spec;
158 }