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