end-of-line normalization
[u/mrichter/AliRoot.git] / PWGJE / UserTasks / AliAnalysisTaskJetHadronCorrelation.cxx
1 //#include <string.h>
2 //#include <TStyle.h>
3 #include <list>
4 #include <string>
5
6 #include "TTree.h"
7 #include "TCanvas.h"
8 #include "AliAnalysisTask.h"
9 #include "AliInputEventHandler.h"
10 #include "AliESDtrack.h"
11 #include "AliAODVertex.h"
12 #include "AliAODCluster.h"
13
14 #include <TROOT.h>
15 #include <TRandom.h>
16 #include <TSystem.h>
17 #include <TInterpreter.h>
18 #include <TChain.h>
19 #include <TFile.h>
20 #include <TKey.h>
21 #include <TH1F.h>
22 #include <TH2F.h>
23 #include <TH3F.h>
24 #include <TProfile.h>
25 #include <TList.h>
26 #include <TLorentzVector.h>
27 #include <TClonesArray.h>
28 #include <TRefArray.h>
29
30 #include "TDatabasePDG.h"
31 #include "AliAnalysisManager.h"
32 #include "AliJetFinder.h"
33 #include "AliJetHeader.h"
34 #include "AliJetReader.h"
35 #include "AliJetReaderHeader.h"
36 #include "AliUA1JetHeaderV1.h"
37 #include "AliSISConeJetHeader.h"
38 #include "AliESDEvent.h"
39 #include "AliAODEvent.h"
40 #include "AliAODHandler.h"
41 #include "AliAODInputHandler.h"
42 #include "AliAODTrack.h"
43 #include "AliAODMCParticle.h"
44 #include "AliAODJet.h"
45 #include "AliAODJetEventBackground.h"
46 #include "AliMCParticle.h"
47 #include "AliAODMCParticle.h"
48 #include "AliMCEventHandler.h"
49 #include "AliMCEvent.h"
50 #include "AliStack.h"
51
52 #include "AliAODHeader.h"
53 #include "AliAODMCHeader.h"
54 //#include "AliGenPythiaEventHeader.h"
55 #include "AliJetKineReaderHeader.h"
56 #include "AliGenCocktailEventHeader.h"
57 #include "AliInputEventHandler.h"
58 #include "AliGenEventHeader.h"
59 #include "AliGenDPMjetEventHeader.h"
60
61 #include "AliAnalysisTaskJetHadronCorrelation.h"
62 #include "AliAnalysisTaskPhiCorrelations.h"
63 //#include "AliAnalysisHelperJetTasks.h"
64 #include "AliPWG4HighPtQAMC.h"
65
66 using std::cout;
67 using std::endl;
68
69 ClassImp(AliAnalysisTaskJetHadronCorrelation)
70
71                                 //________________________________________________________________________
72                                 AliAnalysisTaskJetHadronCorrelation::AliAnalysisTaskJetHadronCorrelation():
73                                                                 AliAnalysisTaskSE(),
74                                                                 fUseAODInput(kFALSE),
75                                                                 fJetBranch("jets"),
76                                                                 fNonStdFile(""),
77                                                                 fAODIn(0x0),
78                                                                 fAODOut(0x0),
79                                                                 fAODExtension(0x0),
80                                                                 JFAlg("ANTIKT"),         
81                                                                 Radius(0.4),
82                                                                 Filtermask(272),
83                                                                 BackM(0),
84                                                                 TrackPtcut(0.15),
85                                                                 SkipCone(0),
86                                                                 IsMC(kTRUE),
87                                                                 JetEScale(1.),
88                                                                 TrackEScale(1.),
89                                                                 fxsec(0.),
90                                                                 ftrial(1.),
91                                                                 fHistList(0x0), // Output list
92   fIfiles(0),
93                                                                 fH1Events(0x0),
94                                                                 fH1Xsec(0x0),
95                                                                 fH1Trials(0x0),
96                                                                 fH1Track_pt              (0x0),
97                                                                 fH1Track_phi             (0x0),
98                                                                 fH1Track_eta             (0x0),
99                                                                 fH1MCTrack_pt            (0x0),
100                                                                 fH1MCTrack_phi           (0x0),
101                                                                 fH1MCTrack_eta           (0x0),
102                                                                 fH1MCPrimTrack_pt        (0x0),
103                                                                 fH1MCPrimTrack_phi       (0x0),
104                                                                 fH1MCPrimTrack_eta       (0x0),
105                                                                 fH1Jet_pt                (0x0),
106                                                                 fH1Jet_phi               (0x0),
107                                                                 fH1Jet_eta               (0x0),
108                                                                 fH1leadJet_pt            (0x0),
109                                                                 fH1leadJet_pt_dijet      (0x0),
110                                                                 fH1subJet_pt_dijet       (0x0),
111                                                                 fH1JetMC_pt              (0x0),
112                                                                 fH1leadJetMC_pt          (0x0),
113                                                                 fH1leadJetMC_pt_dijet    (0x0),
114                                                                 fH1subJetMC_pt_dijet     (0x0),
115                                                                 fH2JetsJet_dphi          (0x0),
116                                                                 fH2JetsJet_deta          (0x0),
117                                                                 fH2JetsJet_Aj            (0x0),
118                                                                 fH2JetsJet_pt            (0x0),
119                                                                 fH2JetsJetMC_dphi        (0x0),
120                                                                 fH2JetsJetMC_deta        (0x0),
121                                                                 fH2JetsJetMC_Aj          (0x0),
122                                                                 fH2JetsJetMC_pt          (0x0),
123                                                                 fH2Mult_Mtrack           (0x0),
124                                                                 fH2Mult_Mlead            (0x0),
125                                                                 fH2Mult_Mjet             (0x0),
126                                                                 fH2Mult_Njet             (0x0),
127                                                                 fH2Mult_Aj               (0x0),
128                                                                 fH2Mlead_Aj              (0x0),
129                                                                 fH2Jet_pt_Mlead          (0x0),
130                                                                 fH2Jet_pt_Munder         (0x0),
131                                                                 fH2leadJetMCptResolution (0x0),
132                                                                 fH2TrackMCptResolution   (0x0),
133                                                                 fH2TrackMCptEfficiency   (0x0),
134                                                                 fH2AjCorrelation_MCRec   (0x0),
135                                                                 fH2MleadCorrelation_MCRec(0x0)
136 {
137                                 for(int j=0;j<5;j++){
138                                                                 fH1ndiJ_ediv                             [j]=0;
139                                                                 fH1Aj                                    [j]=0;
140                                                                 fH1Mlead                                 [j]=0;
141                                                                 fH1leadJetMC_dphiResolution              [j]=0;
142                                                                 fH1subJetMC_dphiResolution               [j]=0;
143                                                                 fH1leadJetMC_Efficiency                  [j]=0;
144                                                                 fH1subJetMC_Efficiency                   [j]=0;
145                                                                 for(int k=0;k<5;k++){
146                                                                                                 fH1JetHadron_dphi_ediv           [j][k]=0;
147                                                                                                 fH1JetHadron_dphi_tptweight_ediv [j][k]=0;
148                                                                                                 fH1JetHadron_dphi_tJptweight_ediv[j][k]=0;
149                                                                                                 fH1JetHadronMC_dphi_ediv           [j][k]=0;
150                                                                                                 fH1JetHadronMC_dphi_tptweight_ediv [j][k]=0;
151                                                                                                 fH1JetHadronMC_dphi_tJptweight_ediv[j][k]=0;
152                                                                                                 fH1JetHadronMCPrim_dphi_ediv           [j][k]=0;
153                                                                                                 fH1JetHadronMCPrim_dphi_tptweight_ediv [j][k]=0;
154                                                                                                 fH1JetHadronMCPrim_dphi_tJptweight_ediv[j][k]=0;
155                                                                 }
156                                 }
157                                 for(int j=0;j<3;j++){
158                                                                 fH1ndiJ_2040Mlead                               [j]=0;
159                                                                 fH1ndiJ_2040Aj                                  [j]=0;
160                                                                 for(int k=0;k<5;k++){
161                                                                                                 fH1JetHadron_dphi_tptweight2040_Mleaddep[j][k]=0;
162                                                                                                 fH1JetHadron_dphi_tptweight2040_Ajdep   [j][k]=0;
163                                                                                                 fH1JetHadronMC_dphi_tptweight2040_Mleaddep[j][k]=0;
164                                                                                                 fH1JetHadronMC_dphi_tptweight2040_Ajdep   [j][k]=0;
165                                                                                                 fH1JetHadronMCPrim_dphi_tptweight2040_Mleaddep[j][k]=0;
166                                                                                                 fH1JetHadronMCPrim_dphi_tptweight2040_Ajdep   [j][k]=0;
167                                                                 }
168                                 }
169                                 // Default constructor
170 }
171
172 //________________________________________________________________________
173 AliAnalysisTaskJetHadronCorrelation::AliAnalysisTaskJetHadronCorrelation(const char *name):
174                                 AliAnalysisTaskSE(name),
175                                 fUseAODInput(kFALSE),
176                                 fJetBranch("jets"),
177                                 fNonStdFile(""),
178                                 fAODIn(0x0), 
179                                 fAODOut(0x0), 
180                                 fAODExtension(0x0),
181                                 JFAlg("ANTIKT"),         
182                                 Radius(0.4),
183                                 Filtermask(272),
184                                 BackM(0),
185                                 TrackPtcut(0.15),
186                                 SkipCone(0),
187                                 IsMC(kTRUE),
188                                 JetEScale(1.),
189                                 TrackEScale(1.),
190                                 fxsec(0.),
191                                 ftrial(1.),
192                                 fHistList(0x0), // Output list
193                                 fIfiles(0),
194                                 fH1Events(0x0),
195                                 fH1Xsec(0x0),
196                                 fH1Trials(0x0),
197                                 fH1Track_pt              (0x0),
198                                 fH1Track_phi             (0x0),
199                                 fH1Track_eta             (0x0),
200                                 fH1MCTrack_pt            (0x0),
201                                 fH1MCTrack_phi           (0x0),
202                                 fH1MCTrack_eta           (0x0),
203                                 fH1MCPrimTrack_pt        (0x0),
204                                 fH1MCPrimTrack_phi       (0x0),
205                                 fH1MCPrimTrack_eta       (0x0),
206                                 fH1Jet_pt                (0x0),
207                                 fH1Jet_phi               (0x0),
208                                 fH1Jet_eta               (0x0),
209                                 fH1leadJet_pt            (0x0),
210                                 fH1leadJet_pt_dijet      (0x0),
211                                 fH1subJet_pt_dijet       (0x0),
212                                 fH1JetMC_pt              (0x0),
213                                 fH1leadJetMC_pt          (0x0),
214                                 fH1leadJetMC_pt_dijet    (0x0),
215                                 fH1subJetMC_pt_dijet     (0x0),
216                                 fH2JetsJet_dphi          (0x0),
217                                 fH2JetsJet_deta          (0x0),
218                                 fH2JetsJet_Aj            (0x0),
219                                 fH2JetsJet_pt            (0x0),
220                                 fH2JetsJetMC_dphi        (0x0),
221                                 fH2JetsJetMC_deta        (0x0),
222                                 fH2JetsJetMC_Aj          (0x0),
223                                 fH2JetsJetMC_pt          (0x0),
224                                 fH2Mult_Mtrack           (0x0),
225                                 fH2Mult_Mlead            (0x0),
226                                 fH2Mult_Mjet             (0x0),
227                                 fH2Mult_Njet             (0x0),
228                                 fH2Mult_Aj               (0x0),
229                                 fH2Mlead_Aj              (0x0),
230                                 fH2Jet_pt_Mlead          (0x0),
231                                 fH2Jet_pt_Munder         (0x0),
232                                 fH2leadJetMCptResolution (0x0),
233                                 fH2TrackMCptResolution   (0x0),
234                                 fH2TrackMCptEfficiency   (0x0),
235                                 fH2AjCorrelation_MCRec   (0x0),
236                                 fH2MleadCorrelation_MCRec(0x0)
237 {
238
239                                 for(int j=0;j<5;j++){
240                                                                 fH1ndiJ_ediv                             [j]=0;
241                                                                 fH1Aj                                    [j]=0;
242                                                                 fH1Mlead                                 [j]=0;
243                                                                 fH1leadJetMC_dphiResolution              [j]=0;
244                                                                 fH1subJetMC_dphiResolution               [j]=0;
245                                                                 fH1leadJetMC_Efficiency                  [j]=0;
246                                                                 fH1subJetMC_Efficiency                   [j]=0;
247                                                                 for(int k=0;k<5;k++){
248                                                                                                 fH1JetHadron_dphi_ediv           [j][k]=0;
249                                                                                                 fH1JetHadron_dphi_tptweight_ediv [j][k]=0;
250                                                                                                 fH1JetHadron_dphi_tJptweight_ediv[j][k]=0;
251                                                                                                 fH1JetHadronMC_dphi_ediv           [j][k]=0;
252                                                                                                 fH1JetHadronMC_dphi_tptweight_ediv [j][k]=0;
253                                                                                                 fH1JetHadronMC_dphi_tJptweight_ediv[j][k]=0;
254                                                                                                 fH1JetHadronMCPrim_dphi_ediv           [j][k]=0;
255                                                                                                 fH1JetHadronMCPrim_dphi_tptweight_ediv [j][k]=0;
256                                                                                                 fH1JetHadronMCPrim_dphi_tJptweight_ediv[j][k]=0;
257                                                                 }
258                                 }
259                                 for(int j=0;j<3;j++){
260                                                                 fH1ndiJ_2040Mlead                               [j]=0;
261                                                                 fH1ndiJ_2040Aj                                  [j]=0;
262                                                                 for(int k=0;k<5;k++){
263                                                                                                 fH1JetHadron_dphi_tptweight2040_Mleaddep[j][k]=0;
264                                                                                                 fH1JetHadron_dphi_tptweight2040_Ajdep   [j][k]=0;
265                                                                                                 fH1JetHadronMC_dphi_tptweight2040_Mleaddep[j][k]=0;
266                                                                                                 fH1JetHadronMC_dphi_tptweight2040_Ajdep   [j][k]=0;
267                                                                                                 fH1JetHadronMCPrim_dphi_tptweight2040_Mleaddep[j][k]=0;
268                                                                                                 fH1JetHadronMCPrim_dphi_tptweight2040_Ajdep   [j][k]=0;
269                                                                 }
270                                 }
271
272                                 // Default constructor
273                                 // Constructor
274                                 // Define input and output slots here
275                                 // Input slot #0 works with a TChain
276                                 DefineInput(0, TChain::Class());
277                                 // Output slot #0 id reserved by the base class for AOD
278                                 // Output slot #1 writes into a TH1 container
279                                 DefineOutput(1, TList::Class());
280 }
281
282 //________________________________________________________________________
283 void AliAnalysisTaskJetHadronCorrelation::UserCreateOutputObjects()
284 {
285                                 // Create histograms
286                                 // Called once
287
288                                 fHistList = new TList();fHistList->SetOwner(kTRUE); cout<<"TList is created for output "<<endl;
289                                 //if (!fHistList){ fHistList = new TList();fHistList->SetOwner(kTRUE); cout<<"TList is created for output "<<endl;}
290
291                                 Bool_t oldStatus = TH1::AddDirectoryStatus();
292                                 TH1::AddDirectory(kFALSE);
293                                 Float_t pi=TMath::Pi();
294
295
296                                 char *histname;
297
298                                 fH1Events                  = new TH1F    ("Events"        ,"Events"            ,1,0,1);
299                                 fH1Xsec                    = new TProfile("Xsec"          ,"Xsec"              ,1,0,1);
300                                 fH1Trials                  = new TH1F    ("Trials"        ,"Trials"            ,1,0,1);
301
302                                 fH1Track_pt                = new TH1F("Track_pt"          ,"Track_pt"          ,200,0,200);
303                                 fH1Track_phi               = new TH1F("Track_phi"         ,"Track_phi"         ,100,0,2*pi);
304                                 fH1Track_eta               = new TH1F("Track_eta"         ,"Track_eta"         ,100,-1.,1);
305                                 fH1MCTrack_pt              = new TH1F("MCTrack_pt"        ,"MCTrack_pt"        ,200,0,200);
306                                 fH1MCTrack_phi             = new TH1F("MCTrack_phi"       ,"MCTrack_phi"       ,100,0,2*pi);
307                                 fH1MCTrack_eta             = new TH1F("MCTrack_eta"       ,"MCTrack_eta"       ,100,-1.,1);
308                                 fH1MCPrimTrack_pt          = new TH1F("MCPrimTrack_pt"    ,"MCPrimTrack_pt"    ,200,0,200);
309                                 fH1MCPrimTrack_phi         = new TH1F("MCPrimTrack_phi"   ,"MCPrimTrack_phi"   ,100,0,2*pi);
310                                 fH1MCPrimTrack_eta         = new TH1F("MCPrimTrack_eta"   ,"MCPrimTrack_eta"   ,100,-1.,1);
311                                 fH1Jet_pt                  = new TH1F("Jet_pt"            ,"Jet_pt"            ,200,0,200);
312                                 fH1Jet_phi                 = new TH1F("Jet_phi"           ,"Jet_pt"            ,100,0,2*pi);
313                                 fH1Jet_eta                 = new TH1F("Jet_eta"           ,"Jet_pt"            ,100,-1.,1);
314                                 fH1leadJet_pt              = new TH1F("leadJet_pt"        ,"leadJet_pt"        ,200,0,200);
315                                 fH1leadJet_pt_dijet        = new TH1F("leadJet_pt_dijet"  ,"leadJet_pt_dijet"  ,200,0,200);
316                                 fH1subJet_pt_dijet         = new TH1F("subJet_pt_dijet"   ,"subJet_pt_dijet"   ,200,0,200);
317                                 fH1JetMC_pt                = new TH1F("JetMC_pt"          ,"JetMC_pt"          ,200,0,200);
318                                 fH1leadJetMC_pt            = new TH1F("leadJetMC_pt"      ,"leadJetMC_pt"      ,200,0,200);
319                                 fH1leadJetMC_pt_dijet      = new TH1F("leadJetMC_pt_dijet","leadJetMC_pt_dijet",200,0,200);
320                                 fH1subJetMC_pt_dijet       = new TH1F("subJetMC_pt_dijet" ,"subJetMC_pt_dijet" ,200,0,200);
321                                 fH2JetsJet_dphi            = new TH2F("JetsJet_dphi"      ,"JetsJet_dphi"      ,200,0,200,100,-2*pi,2*pi);
322                                 fH2JetsJet_deta            = new TH2F("JetsJet_deta"      ,"JetsJet_deta"      ,200,0,200,100,-1.5,1.5);
323                                 fH2JetsJet_Aj              = new TH2F("JetsJet_Aj"        ,"JetsJet_Aj"        ,200,0,200,100,0,1.2);
324                                 fH2JetsJet_pt              = new TH2F("JetsJet_pt"        ,"JetsJet_pt"        ,200,0,200,200,0,200);
325                                 fH2JetsJetMC_dphi          = new TH2F("JetsJetMC_dphi"    ,"JetsJetMC_dphi"    ,200,0,200,100,-2*pi,2*pi);
326                                 fH2JetsJetMC_deta          = new TH2F("JetsJetMC_deta"    ,"JetsJetMC_deta"    ,200,0,200,100,-1.5,1.5);
327                                 fH2JetsJetMC_Aj            = new TH2F("JetsJetMC_Aj"      ,"JetsJetMC_Aj"      ,200,0,200,100,0,1.2);
328                                 fH2JetsJetMC_pt            = new TH2F("JetsJetMC_pt"      ,"JetsJetMC_pt"      ,200,0,200,200,0,200);
329                                 fH2Mult_Mtrack             = new TH2F("Mult_Mtrack"       ,"Mult_Mtrack"       ,50,0,250,50,0,250); 
330                                 fH2Mult_Mlead              = new TH2F("Mult_Mlead"        ,"Mult_Mlead"        ,50,0,250,25,0,25);   
331                                 fH2Mult_Mjet               = new TH2F("Mult_Mjet"         ,"Mult_Mjet"         ,50,0,250,50,0,100);  
332                                 fH2Mult_Njet               = new TH2F("Mult_Njet"         ,"Mult_Njet"         ,50,0,250,50,0,50);   
333                                 fH2Mult_Aj                 = new TH2F("Mult_Aj"           ,"Mult_Aj"           ,50,0,250,25,0,1.2);  
334                                 fH2Mlead_Aj                = new TH2F("Mlead_Aj"          ,"Mlead_Aj"          ,25,0,25,25,0,1.2);   
335                                 fH2Jet_pt_Mlead            = new TH2F("Jet_pt_Mlead"      ,"Jet_pt_Mlead"      ,50,0,200,25,0,25);   
336                                 fH2Jet_pt_Munder           = new TH2F("Jet_pt_Munder"     ,"Jet_pt_Munder"     ,50,0,200,25,0,5);    
337                                 fH2leadJetMCptResolution   = new TH2F("leadJetMCptResolution" ,"leadJetMCptResolution" ,200,0,200,200,0,200);    
338                                 fH2TrackMCptResolution     = new TH2F("TrackMCptResolution"   ,"TrackMCptResolution"   ,200,0,200,200,0,200);    
339                                 fH2TrackMCptEfficiency     = new TH2F("TrackMCptEfficiency"   ,"TrackMCptEfficiency"   ,200,0,200,100,0,1.2);    
340                                 fH2AjCorrelation_MCRec     = new TH2F("AjCorrelation_MCRec"   ,"AjCorrelation_MCRec"   ,60,0,1.2,60,0,1.2);    
341                                 fH2MleadCorrelation_MCRec  = new TH2F("MleadCorrelation_MCRec","MleadCorrelation_MCRec",60,0,60,60,0,60);    
342
343                                 for(int j=0;j<5;j++){
344                                                                 histname = Form("ndiJ_ediv%d",j);
345                                                                 fH1ndiJ_ediv[j]= new TH1F(histname,histname,1,1,2);
346                                                                 histname        = Form("Aj%d",j);                    
347                                                                 fH1Aj[j]    = new TH1F(histname,histname,50,0,1.2);  
348                                                                 histname        = Form("Mlead%d",j);                 
349                                                                 fH1Mlead[j] = new TH1F(histname,histname,50,0,50);   
350                                                                 histname = Form("leadJetMC_dphiResolution%d",j);
351                                                                 fH1leadJetMC_dphiResolution[j] = new TH1F(histname,histname,200,-2*pi,2*pi);
352                                                                 histname = Form("subJetMC_dphiResolution%d",j);
353                                                                 fH1subJetMC_dphiResolution[j] = new TH1F(histname,histname,200,-2*pi,2*pi);
354                                                                 histname = Form("leadJetMC_Efficiency%d",j);
355                                                                 fH1leadJetMC_Efficiency[j] = new TH1F(histname,histname,100,0,1.2);
356                                                                 histname = Form("subJetMC_Efficiency%d",j);
357                                                                 fH1subJetMC_Efficiency[j] = new TH1F(histname,histname,100,0,1.2);
358                                                                 for(int k=0;k<5;k++){
359                                                                                                 histname = Form("JetHadron_dphi_ediv%d%d",j,k);
360                                                                                                 fH1JetHadron_dphi_ediv             [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
361                                                                                                 histname = Form("JetHadron_dphi_tptweight_ediv%d%d",j,k);
362                                                                                                 fH1JetHadron_dphi_tptweight_ediv   [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
363                                                                                                 histname = Form("JetHadron_dphi_tJptweight_ediv%d%d",j,k);
364                                                                                                 fH1JetHadron_dphi_tJptweight_ediv  [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
365                                                                                                 histname = Form("JetHadronMC_dphi_ediv%d%d",j,k);
366                                                                                                 fH1JetHadronMC_dphi_ediv             [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
367                                                                                                 histname = Form("JetHadronMC_dphi_tptweight_ediv%d%d",j,k);
368                                                                                                 fH1JetHadronMC_dphi_tptweight_ediv   [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
369                                                                                                 histname = Form("JetHadronMC_dphi_tJptweight_ediv%d%d",j,k);
370                                                                                                 fH1JetHadronMC_dphi_tJptweight_ediv  [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
371                                                                                                 histname = Form("JetHadronMCPrim_dphi_ediv%d%d",j,k);
372                                                                                                 fH1JetHadronMCPrim_dphi_ediv             [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
373                                                                                                 histname = Form("JetHadronMCPrim_dphi_tptweight_ediv%d%d",j,k);
374                                                                                                 fH1JetHadronMCPrim_dphi_tptweight_ediv   [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
375                                                                                                 histname = Form("JetHadronMCPrim_dphi_tJptweight_ediv%d%d",j,k);
376                                                                                                 fH1JetHadronMCPrim_dphi_tJptweight_ediv  [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
377                                                                 }
378                                 }
379                                 for(int j=0;j<3;j++){
380                                                                 histname = Form("ndiJ_2040Mlead%d",j);
381                                                                 fH1ndiJ_2040Mlead[j]= new TH1F(histname,histname,1,1,2);
382                                                                 histname = Form("ndiJ_2040Aj%d",j);
383                                                                 fH1ndiJ_2040Aj[j]= new TH1F(histname,histname,1,1,2);
384                                                                 for(int k=0;k<5;k++){
385                                                                                                 histname = Form("JetHadron_dphi_tptweight2040_Mleaddep%d%d",j,k);
386                                                                                                 fH1JetHadron_dphi_tptweight2040_Mleaddep   [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
387                                                                                                 histname = Form("JetHadron_dphi_tptweight2040_Ajdep%d%d",j,k);
388                                                                                                 fH1JetHadron_dphi_tptweight2040_Ajdep      [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
389                                                                                                 histname = Form("JetHadronMC_dphi_tptweight2040_Mleaddep%d%d",j,k);
390                                                                                                 fH1JetHadronMC_dphi_tptweight2040_Mleaddep   [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
391                                                                                                 histname = Form("JetHadronMC_dphi_tptweight2040_Ajdep%d%d",j,k);
392                                                                                                 fH1JetHadronMC_dphi_tptweight2040_Ajdep      [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
393                                                                                                 histname = Form("JetHadronMCPrim_dphi_tptweight2040_Mleaddep%d%d",j,k);
394                                                                                                 fH1JetHadronMCPrim_dphi_tptweight2040_Mleaddep   [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
395                                                                                                 histname = Form("JetHadronMCPrim_dphi_tptweight2040_Ajdep%d%d",j,k);
396                                                                                                 fH1JetHadronMCPrim_dphi_tptweight2040_Ajdep      [j][k]= new TH1F(histname,histname,200,-1./2.*pi,3./2.*pi);
397                                                                 }
398                                 }
399
400
401                                 if(IsMC){
402                                                                 fHistList->Add(fH1Events            );
403                                                                 fHistList->Add(fH1Xsec              );
404                                                                 fHistList->Add(fH1Trials            );
405                                                                 fHistList->Add(fH1Track_pt          );
406                                                                 fHistList->Add(fH1Track_phi         );
407                                                                 fHistList->Add(fH1Track_eta         );
408                                                                 fHistList->Add(fH1MCTrack_pt        );
409                                                                 fHistList->Add(fH1MCTrack_phi       );
410                                                                 fHistList->Add(fH1MCTrack_eta       );
411                                                                 fHistList->Add(fH1MCPrimTrack_pt    );
412                                                                 fHistList->Add(fH1MCPrimTrack_phi   );
413                                                                 fHistList->Add(fH1MCPrimTrack_eta   );
414                                                                 fHistList->Add(fH1Jet_pt            );
415                                                                 fHistList->Add(fH1Jet_phi           );
416                                                                 fHistList->Add(fH1Jet_eta           );
417                                                                 fHistList->Add(fH1leadJet_pt        );
418                                                                 fHistList->Add(fH1leadJet_pt_dijet  );
419                                                                 fHistList->Add(fH1subJet_pt_dijet   );
420                                                                 fHistList->Add(fH1JetMC_pt          );
421                                                                 fHistList->Add(fH1leadJetMC_pt      );
422                                                                 fHistList->Add(fH1leadJetMC_pt_dijet);
423                                                                 fHistList->Add(fH1subJetMC_pt_dijet );
424                                                                 fHistList->Add(fH2JetsJet_dphi      );
425                                                                 fHistList->Add(fH2JetsJet_deta      );
426                                                                 fHistList->Add(fH2JetsJet_Aj        );
427                                                                 fHistList->Add(fH2JetsJet_pt        );
428                                                                 fHistList->Add(fH2JetsJetMC_dphi    );
429                                                                 fHistList->Add(fH2JetsJetMC_deta    );
430                                                                 fHistList->Add(fH2JetsJetMC_Aj      );
431                                                                 fHistList->Add(fH2JetsJetMC_pt      );
432                                                                 fHistList->Add(fH2Mult_Mtrack       );
433                                                                 fHistList->Add(fH2Mult_Mlead        ); 
434                                                                 fHistList->Add(fH2Mult_Mjet         );  
435                                                                 fHistList->Add(fH2Mult_Njet         );  
436                                                                 fHistList->Add(fH2Mult_Aj           );    
437                                                                 fHistList->Add(fH2Mlead_Aj          );   
438                                                                 fHistList->Add(fH2Jet_pt_Mlead      );   
439                                                                 fHistList->Add(fH2Jet_pt_Munder     );  
440                                                                 fHistList->Add(fH2leadJetMCptResolution );
441                                                                 fHistList->Add(fH2TrackMCptResolution   );
442                                                                 fHistList->Add(fH2TrackMCptEfficiency   );
443                                                                 fHistList->Add(fH2AjCorrelation_MCRec   );
444                                                                 fHistList->Add(fH2MleadCorrelation_MCRec);
445                                                                 for(int j=0;j<5;j++){
446                                                                                                 fHistList->Add(fH1ndiJ_ediv                        [j]);
447                                                                                                 fHistList->Add(fH1Aj                               [j]);
448                                                                                                 fHistList->Add(fH1Mlead                            [j]);
449                                                                                                 fHistList->Add(fH1leadJetMC_dphiResolution         [j]);
450                                                                                                 fHistList->Add(fH1subJetMC_dphiResolution          [j]);
451                                                                                                 fHistList->Add(fH1leadJetMC_Efficiency             [j]);
452                                                                                                 fHistList->Add(fH1subJetMC_Efficiency              [j]);
453                                                                                                 for(int k=0;k<5;k++){
454                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_ediv               [j][k]);
455                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tptweight_ediv     [j][k]);
456                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tJptweight_ediv    [j][k]);
457                                                                                                                                 fHistList->Add(fH1JetHadronMC_dphi_ediv               [j][k]);
458                                                                                                                                 fHistList->Add(fH1JetHadronMC_dphi_tptweight_ediv     [j][k]);
459                                                                                                                                 fHistList->Add(fH1JetHadronMC_dphi_tJptweight_ediv    [j][k]);
460                                                                                                                                 fHistList->Add(fH1JetHadronMCPrim_dphi_ediv               [j][k]);
461                                                                                                                                 fHistList->Add(fH1JetHadronMCPrim_dphi_tptweight_ediv     [j][k]);
462                                                                                                                                 fHistList->Add(fH1JetHadronMCPrim_dphi_tJptweight_ediv    [j][k]);
463                                                                                                 }
464                                                                 }
465                                                                 for(int j=0;j<3;j++){
466                                                                                                 fHistList->Add(fH1ndiJ_2040Mlead    [j]);
467                                                                                                 fHistList->Add(fH1ndiJ_2040Aj       [j]);
468                                                                                                 for(int k=0;k<5;k++){
469                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tptweight2040_Mleaddep     [j][k]);
470                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tptweight2040_Ajdep        [j][k]);
471                                                                                                                                 fHistList->Add(fH1JetHadronMC_dphi_tptweight2040_Mleaddep     [j][k]);
472                                                                                                                                 fHistList->Add(fH1JetHadronMC_dphi_tptweight2040_Ajdep        [j][k]);
473                                                                                                                                 fHistList->Add(fH1JetHadronMCPrim_dphi_tptweight2040_Mleaddep     [j][k]);
474                                                                                                                                 fHistList->Add(fH1JetHadronMCPrim_dphi_tptweight2040_Ajdep        [j][k]);
475                                                                                                 }
476                                                                 }
477                                 }
478                                 else{
479                                                                 fHistList->Add(fH1Events            );
480                                                                 fHistList->Add(fH1Track_pt          );
481                                                                 fHistList->Add(fH1Track_phi         );
482                                                                 fHistList->Add(fH1Track_eta         );
483                                                                 fHistList->Add(fH1Jet_pt            );
484                                                                 fHistList->Add(fH1Jet_phi           );
485                                                                 fHistList->Add(fH1Jet_eta           );
486                                                                 fHistList->Add(fH1leadJet_pt        );
487                                                                 fHistList->Add(fH1leadJet_pt_dijet  );
488                                                                 fHistList->Add(fH1subJet_pt_dijet   );
489                                                                 fHistList->Add(fH2JetsJet_dphi      );
490                                                                 fHistList->Add(fH2JetsJet_deta      );
491                                                                 fHistList->Add(fH2JetsJet_Aj        );
492                                                                 fHistList->Add(fH2JetsJet_pt        );
493                                                                 fHistList->Add(fH2Mult_Mtrack       );
494                                                                 fHistList->Add(fH2Mult_Mlead        ); 
495                                                                 fHistList->Add(fH2Mult_Mjet         );  
496                                                                 fHistList->Add(fH2Mult_Njet         );  
497                                                                 fHistList->Add(fH2Mult_Aj           );    
498                                                                 fHistList->Add(fH2Mlead_Aj          );   
499                                                                 fHistList->Add(fH2Jet_pt_Mlead      );   
500                                                                 fHistList->Add(fH2Jet_pt_Munder     );  
501                                                                 for(int j=0;j<5;j++){
502                                                                                                 fHistList->Add(fH1ndiJ_ediv                        [j]);
503                                                                                                 fHistList->Add(fH1Aj                               [j]);
504                                                                                                 fHistList->Add(fH1Mlead                            [j]);
505                                                                                                 for(int k=0;k<5;k++){
506                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_ediv               [j][k]);
507                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tptweight_ediv     [j][k]);
508                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tJptweight_ediv    [j][k]);
509                                                                                                 }
510                                                                 }
511                                                                 for(int j=0;j<3;j++){
512                                                                                                 fHistList->Add(fH1ndiJ_2040Mlead    [j]);
513                                                                                                 fHistList->Add(fH1ndiJ_2040Aj       [j]);
514                                                                                                 for(int k=0;k<5;k++){
515                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tptweight2040_Mleaddep     [j][k]);
516                                                                                                                                 fHistList->Add(fH1JetHadron_dphi_tptweight2040_Ajdep        [j][k]);
517                                                                                                 }
518                                                                 }
519                                 }
520
521                                 // =========== Switch on Sumw2 for all histos ===========
522                                 for (Int_t i=0; i<fHistList->GetEntries(); ++i) 
523                                 {
524                                                                 TH1 *h1 = dynamic_cast<TH1*>(fHistList->At(i));
525                                                                 if (h1)
526                                                                 {
527                                                                                                 h1->Sumw2();
528                                                                                                 continue;
529                                                                 }
530                                                                 THnSparse *hn = dynamic_cast<THnSparse*>(fHistList->At(i));
531                                                                 if(hn)hn->Sumw2();
532                                 }
533                                 TH1::AddDirectory(oldStatus);
534
535                                 PostData(1,fHistList);
536 }
537
538
539 //----------------------------------------------------------------------                                                 
540 void AliAnalysisTaskJetHadronCorrelation::Init()
541 {
542                                 // Initialization                                                                                                    
543                                 if (fDebug) printf("AnalysisTaskJetHadronCorrelation::Init() \n");
544
545 }
546
547 Bool_t AliAnalysisTaskJetHadronCorrelation::Notify()
548 {
549
550
551                                 fAODIn = dynamic_cast<AliAODEvent*>(InputEvent());
552                                 fAODOut = AODEvent();
553                                 if(fNonStdFile.Length()!=0){
554                                                                 AliAODHandler *aodH = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
555                                                                 fAODExtension = (aodH?aodH->GetExtension(fNonStdFile.Data()):0);
556                                                                 if(fAODExtension){
557                                                                                                 if(fDebug>1)Printf("AODExtension found for %s ",fNonStdFile.Data());
558                                                                 }
559                                 }
560
561                                 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
562                                 fxsec=0;
563                                 ftrial=1;
564
565                                 if(tree){
566                                                                 TFile *curfile = tree->GetCurrentFile();
567                                                                 if(!curfile){
568                                                                                                 Error("Notify","No current file");
569                                                                                                 return kFALSE;
570                                                                 }
571                                                                 if(IsMC){
572                                                                                                 AliPWG4HighPtQAMC::PythiaInfoFromFile(curfile->GetName(),fxsec,ftrial);
573                                                                                                 fH1Xsec  ->Fill(0.,fxsec);
574                                                                                                 fH1Trials->Fill(0.,ftrial);
575                                                                 }
576
577                                 }
578
579                                 printf("Reading File %s ",fInputHandler->GetTree()->GetCurrentFile()->GetName());
580                                 return kTRUE;
581 }
582 void AliAnalysisTaskJetHadronCorrelation::FinishTaskOutput()
583 {
584 }
585
586
587
588 //________________________________________________________________________
589 void AliAnalysisTaskJetHadronCorrelation::UserExec(Option_t *) 
590 {
591
592
593                                 // Main loop (called each event)
594                                 // Execute analysis for current event
595
596                                 AliAODEvent *fAOD;
597                                 TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
598                                 if( handler && handler->InheritsFrom("AliAODInputHandler") ) {
599                                                                 fAOD  =  ((AliAODInputHandler*)handler)->GetEvent();
600                                                                 if(fUseAODInput) fAODIn = fAOD;
601                                                                 if (fDebug > 1)  Printf("%s:%d AOD event from input", (char*)__FILE__,__LINE__);
602                                 }
603                                 else {
604                                                                 handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
605                                                                 if( handler && handler->InheritsFrom("AliAODHandler") ) {
606                                                                                                 fAOD = ((AliAODHandler*)handler)->GetAOD();
607                                                                                                 fAODIn = fAOD;
608                                                                                                 if (fDebug > 1)  Printf("%s:%d AOD event from output", (char*)__FILE__,__LINE__);
609                                                                 }
610                                 }
611
612                                 if(!fAODIn && !fUseAODInput){ // case we have AOD in input & output and want jets from output
613                                                                 TObject* outHandler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
614                                                                 if( outHandler && outHandler->InheritsFrom("AliAODHandler") ) {
615                                                                                                 fAODIn = ((AliAODHandler*)outHandler)->GetAOD();
616                                                                                                 if (fDebug > 1)  Printf("%s:%d jets from output AOD", (char*)__FILE__,__LINE__);
617                                                                 }
618                                 }
619                                 if (!fAODIn) {
620                                                                 Printf("ERROR %s : fAODIn not available",(char*)__FILE__);
621                                                                 return;
622                                 }
623
624                                 AliInputEventHandler* inputHandler = (AliInputEventHandler*)
625                                                                 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
626                                 if(!(inputHandler->IsEventSelected() & AliVEvent::kMB)){
627                                                                 if (fDebug > 1 ) Printf(" Trigger Selection: event REJECTED ... ");
628                                                                 return;
629                                 }
630                                 fH1Events->Fill(0);
631
632                                 AliAODHeader* aliH = dynamic_cast <AliAODHeader*> (fAODIn->GetHeader());
633                                 if(!aliH){
634                                                                 Printf("ERROR: AliAODHeader not available");
635                                                                 return;
636                                 }
637                                 double Mult = aliH->GetRefMultiplicity();
638
639                                 // start jet analysis  -------------------------Init.
640                                 Float_t pi=TMath::Pi();
641
642                                 Double_t Jet_pt   [20][5000];
643                                 Double_t Jet_phi  [20][5000];
644                                 Double_t Jet_eta  [20][5000];
645                                 Double_t Jet_area [20][5000];
646                                 Double_t subJet_pt [20][5000];
647                                 Double_t subJet_eta[20][5000];
648                                 Double_t Track_n  ;
649                                 Double_t Track_pt [5000];
650                                 Double_t Track_eta[5000];
651                                 Double_t Track_phi[5000];
652                                 Double_t MCTrack_n  ;
653                                 Double_t MCTrack_pt [5000];
654                                 Double_t MCTrack_eta[5000];
655                                 Double_t MCTrack_phi[5000];
656
657                                 Track_n=0;MCTrack_n=0;
658                                 for(int i=0;i<20;i++){
659                                                                 for(int j=0;j<1000;j++){
660                                                                                                 Jet_pt[i][j]=0.;
661                                                                                                 Jet_phi[i][j]=999.;
662                                                                                                 Jet_eta[i][j]=999.;
663                                                                                                 Jet_area[i][j]=999.;
664                                                                                                 subJet_pt[i][j]=0.;
665                                                                                                 subJet_eta[i][j]=999.;
666                                                                                                 Track_pt [j]=0.;
667                                                                                                 Track_phi[j]=999.;
668                                                                                                 Track_eta[j]=999.;
669                                                                                                 MCTrack_pt [j]=0.;
670                                                                                                 MCTrack_phi[j]=999.;
671                                                                                                 MCTrack_eta[j]=999.;
672                                                                 }
673                                 }
674
675                                 int nLJetAOD=999; double ptLJetAOD=0;double phiLJetAOD=999.;double etaLJetAOD=999.;double ptsLJetAOD=0;double phisLJetAOD=900.;double etasLJetAOD=900.;
676                                 int nLJetMC2=999; double ptLJetMC2=0;double phiLJetMC2=999.;double etaLJetMC2=999.;double ptsLJetMC2=0;double phisLJetMC2=900.;double etasLJetMC2=900.;
677                                 int nLJetMC =999; double ptLJetMC =0;double phiLJetMC =999.;double etaLJetMC =999.;double ptsLJetMC =0;double phisLJetMC =900.;double etasLJetMC =900.;
678                                 bool findLJetAOD=false;
679                                 bool findLJetMC2=false;
680                                 bool findDiJet=false,findDiJetMC=false;
681                                 int nLJet = 999;
682                                 int Mjet_tot =0;
683                                 int Njet_tot =0;
684
685                                 double Aj=99.,AjMC=99.;
686                                 double Mlead=99.,MleadMC=99.;
687                                 int    Munder=99.;
688
689                                 ////--------------------------------------------------------------------Init.
690
691                                 TString cAdd = "";
692                                 TString Branchname_gen,Branchname_gen2,Branchname_rec;
693                                 if((JFAlg=="ANTIKT")||(JFAlg=="KT")){
694                                                                 cAdd += Form("%02d_",(int)((Radius+0.01)*10.));
695                                                                 cAdd += Form("B%d",(int)BackM);
696                                                                 cAdd += Form("_Filter%05d",Filtermask);
697                                                                 cAdd += Form("_Cut%05d",(int)(1000.*TrackPtcut));
698                                                                 cAdd += Form("_Skip%02d",SkipCone);
699                                                                 Branchname_gen  = Form("clustersAODMC_%s%s",JFAlg.Data(),cAdd.Data());
700                                                                 Branchname_gen2 = Form("clustersAODMC2_%s%s",JFAlg.Data(),cAdd.Data());
701                                                                 Branchname_rec  = Form("clustersAOD_%s%s",JFAlg.Data(),cAdd.Data());
702                                 }
703                                 else{
704                                                                 cAdd += Form("%02d_",(int)((Radius+0.01)*10.));
705                                                                 cAdd += Form("B%d",(int)BackM);
706                                                                 cAdd += Form("_Filter%05d",Filtermask);
707                                                                 cAdd += Form("_Cut%05d",(int)(1000.*TrackPtcut));
708                                                                 Branchname_gen  = Form("jetsAODMC_%s%s",JFAlg.Data(),cAdd.Data());
709                                                                 Branchname_gen2 = Form("jetsAODMC2_%s%s",JFAlg.Data(),cAdd.Data());
710                                                                 Branchname_rec  = Form("jetsAOD_%s%s",JFAlg.Data(),cAdd.Data());
711                                 }
712
713
714
715                                 //count number of tracks@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
716                                 //Reconstructed Track
717                                 TClonesArray* tracks = dynamic_cast <TClonesArray*> (fAODIn->GetTracks());
718                                 if(!tracks){
719                                                                 if (fDebug > 1)  Printf("%s:%d could not get AODtracks", (char*)__FILE__,__LINE__);
720                                                                 return;
721                                 }
722
723                                 Bool_t TrackEff[5000];
724                                 for(int i=0;i<5000;i++){
725                                                                 TrackEff[i]=false;
726                                 }
727                                 Int_t nt = fAODIn->GetNumberOfTracks();
728                                 AliAODTrack* trackAOD=NULL;
729                                 for(int ntrack =0;ntrack<nt;ntrack++){
730                                                                 trackAOD = (AliAODTrack*) (tracks->At(ntrack));
731                                                                 Bool_t bgoodT=false;
732                                                                 if(Filtermask!=272){if(trackAOD->TestFilterMask(Filtermask))bgoodT=true;}
733                                                                 else               {if(trackAOD->IsHybridGlobalConstrainedGlobal())bgoodT=true;} //for hybrid Track cuts
734                                                                 if(!bgoodT)continue;
735                                                                 if(TMath::Abs(trackAOD->Eta())<0.9){
736                                                                                                 Track_n++;
737                                                                                                 fH1Track_pt ->Fill(trackAOD->Pt()*TrackEScale);
738                                                                                                 fH1Track_phi->Fill(trackAOD->Phi());
739                                                                                                 fH1Track_eta->Fill(trackAOD->Eta());
740                                                                                                 //cout<<"Scale "<<TrackEScale<<"  org pt "<<trackAOD->Pt()<< " scaled pt "<< trackAOD->Pt()*TrackEScale <<endl;
741                                                                                                 if(IsMC){
742                                                                                                                                 // track pt resplution-------------------
743                                                                                                                                 Int_t MCID = TMath::Abs(trackAOD->GetLabel());
744                                                                                                                                 TClonesArray* mctracks = dynamic_cast <TClonesArray*> (fAODIn->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
745                                                                                                                                 if(!mctracks){
746                                                                                                                                                                 if (fDebug > 1)  Printf("%s:%d could not get AODMCtracks", (char*)__FILE__,__LINE__);
747                                                                                                                                                                 continue;
748                                                                                                                                 }
749                                                                                                                                 AliAODMCParticle *trackMCAOD = (AliAODMCParticle*) mctracks->At(MCID);
750                                                                                                                                 fH2TrackMCptResolution->Fill(trackMCAOD->Pt(),trackAOD->Pt());
751                                                                                                                                 TrackEff[MCID]=true;
752                                                                                                                                 // --------------------------------------
753                                                                                                 }
754                                                                 }
755                                 }
756                                 if(IsMC){
757                                                                 //MC Track
758                                                                 TClonesArray* mctracks = dynamic_cast <TClonesArray*> (fAODIn->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
759                                                                 if(!mctracks){
760                                                                                                 if (fDebug > 1)  Printf("%s:%d could not get AODMCtracks", (char*)__FILE__,__LINE__);
761                                                                                                 return;
762                                                                 }
763                                                                 Int_t ntmc = mctracks->GetEntriesFast();
764                                                                 AliAODMCParticle* trackMCAOD;
765                                                                 int lastprim=0;
766                                                                 for(int ntrack =0;ntrack<ntmc;ntrack++){
767                                                                                                 trackMCAOD = (AliAODMCParticle*) (mctracks->At(ntrack));
768                                                                                                 if((trackMCAOD->IsPhysicalPrimary())==1)lastprim=ntrack;
769                                                                 }
770                                                                 for(int ntrack =0;ntrack<ntmc;ntrack++){
771                                                                                                 trackMCAOD = (AliAODMCParticle*) (mctracks->At(ntrack));
772                                                                                                 if((trackMCAOD->GetPdgCode()>10)&&((trackMCAOD->GetMother())>1)&&(ntrack>lastprim)&&(trackMCAOD->Charge())){// for Decay particles
773                                                                                                                                 if(TMath::Abs(trackMCAOD->Eta())<0.9){
774                                                                                                                                                                 fH1MCTrack_pt ->Fill(trackMCAOD->Pt());
775                                                                                                                                                                 fH1MCTrack_phi->Fill(trackMCAOD->Phi());
776                                                                                                                                                                 fH1MCTrack_eta->Fill(trackMCAOD->Eta());
777                                                                                                                                                                 if(TrackEff[ntrack])fH2TrackMCptEfficiency->Fill(trackMCAOD->Pt(),1);
778                                                                                                                                                                 else                fH2TrackMCptEfficiency->Fill(trackMCAOD->Pt(),0);
779                                                                                                                                 }
780                                                                                                 }
781                                                                                                 if((trackMCAOD->IsPhysicalPrimary())&&(trackMCAOD->Charge())){// for Physical particles
782                                                                                                                                 if(TMath::Abs(trackMCAOD->Eta())<0.9){
783                                                                                                                                                                 MCTrack_n++;
784                                                                                                                                                                 fH1MCTrack_pt ->Fill(trackMCAOD->Pt());
785                                                                                                                                                                 fH1MCTrack_phi->Fill(trackMCAOD->Phi());
786                                                                                                                                                                 fH1MCTrack_eta->Fill(trackMCAOD->Eta());
787                                                                                                                                                                 fH1MCPrimTrack_pt ->Fill(trackMCAOD->Pt());
788                                                                                                                                                                 fH1MCPrimTrack_phi->Fill(trackMCAOD->Phi());
789                                                                                                                                                                 fH1MCPrimTrack_eta->Fill(trackMCAOD->Eta());
790                                                                                                                                                                 if(TrackEff[ntrack])fH2TrackMCptEfficiency->Fill(trackMCAOD->Pt(),1);
791                                                                                                                                                                 else                fH2TrackMCptEfficiency->Fill(trackMCAOD->Pt(),0);
792                                                                                                                                 }
793                                                                                                 }
794                                                                 }
795                                 }
796                                 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  count number of tracks
797
798
799
800
801                                 for(int algorithm=0;algorithm<3;algorithm++){
802
803                                                                 if(algorithm==0)fJetBranch   = Branchname_rec.Data();
804                                                                 if(algorithm==1)fJetBranch   = Branchname_gen2.Data();
805                                                                 if(algorithm==2)fJetBranch   = Branchname_gen.Data();
806
807                                                                 if((!IsMC&&(algorithm==1||algorithm==2)))continue;
808
809                                                                 TClonesArray* jets = dynamic_cast <TClonesArray*> (fAODIn->FindListObject(fJetBranch.Data()));
810                                                                 if(!jets){
811                                                                                                 printf(" Tere are no Branch named %s \n",fJetBranch.Data());
812                                                                                                 continue;
813                                                                 }
814                                                                 Int_t nj = jets->GetEntriesFast();
815                                                                 if (fDebug) printf("There are %5d jets in the event \n", nj);
816                                                                 AliAODJet* jetsAOD;
817                                                                 //Find Leading Jet -------------------------------------------------------
818                                                                 for(int njet =0;njet<nj;njet++){
819                                                                                                 jetsAOD = (AliAODJet*) (jets->At(njet));
820                                                                                                 Jet_pt   [algorithm][njet] = jetsAOD->Pt()*JetEScale;
821                                                                                                 Jet_phi  [algorithm][njet] = jetsAOD->Phi();  
822                                                                                                 Jet_eta  [algorithm][njet] = jetsAOD->Eta();
823                                                                                                 Jet_area [algorithm][njet] = jetsAOD->EffectiveAreaCharged();
824
825
826                                                                                                 TRefArray *reftracks = jetsAOD->GetRefTracks();
827                                                                                                 if(algorithm==0){if(Jet_pt[algorithm][njet]>1.)Mjet_tot +=  reftracks->GetEntriesFast();Njet_tot++;}
828                                                                                                 double eta_cut_Jet=0.5;
829                                                                                                 if((TMath::Abs(Jet_eta[algorithm][njet])<eta_cut_Jet)&&(Jet_pt[algorithm][njet]>10.)){
830                                                                                                                                 if(algorithm==0){
831                                                                                                                                                                 fH1Jet_pt ->Fill(Jet_pt [algorithm][njet]);  
832                                                                                                                                                                 fH1Jet_phi->Fill(Jet_phi[algorithm][njet]);  
833                                                                                                                                                                 fH1Jet_eta->Fill(Jet_eta[algorithm][njet]);  
834                                                                                                                                                                 if(Jet_pt[algorithm][njet]>ptLJetAOD){
835                                                                                                                                                                                                 findLJetAOD=true;
836                                                                                                                                                                                                 nLJetAOD=njet;ptLJetAOD=Jet_pt[algorithm][njet];phiLJetAOD=Jet_phi[algorithm][njet];etaLJetAOD=Jet_eta[algorithm][njet];
837                                                                                                                                                                 }
838                                                                                                                                 }
839                                                                                                                                 if(algorithm==1){
840                                                                                                                                                                 fH1JetMC_pt->Fill(Jet_pt[algorithm][njet]);  
841                                                                                                                                                                 if(Jet_pt[algorithm][njet]>ptLJetMC2){
842                                                                                                                                                                                                 findLJetMC2=true;
843                                                                                                                                                                                                 nLJetMC2=njet;ptLJetMC2=Jet_pt[algorithm][njet];phiLJetMC2=Jet_phi[algorithm][njet];etaLJetMC2=Jet_eta[algorithm][njet];
844                                                                                                                                                                 }
845                                                                                                                                 }
846                                                                                                                                 if(algorithm==2){
847                                                                                                                                                                 if(Jet_pt[algorithm][njet]>ptLJetMC){
848                                                                                                                                                                                                 nLJetMC=njet;ptLJetMC=Jet_pt[algorithm][njet];phiLJetMC=Jet_phi[algorithm][njet];etaLJetMC=Jet_eta[algorithm][njet];
849                                                                                                                                                                 }
850                                                                                                                                 }
851                                                                                                 }
852                                                                 }//njet loop
853                                                                 if(algorithm==0){nLJet=nLJetAOD;fH1leadJet_pt  ->Fill(Jet_pt[algorithm][nLJet]);}
854                                                                 if(algorithm==1){nLJet=nLJetMC2;fH1leadJetMC_pt->Fill(Jet_pt[algorithm][nLJet]);}
855                                                                 if(algorithm==2){nLJet=nLJetMC;}
856                                                                 if(findLJetAOD&&(algorithm==0)){
857                                                                                                 jetsAOD = (AliAODJet*) (jets->At(nLJet));
858                                                                                                 TRefArray *reftracks = jetsAOD->GetRefTracks();
859                                                                                                 Mlead = reftracks->GetEntriesFast();
860                                                                 }
861                                                                 if(findLJetMC2&&(algorithm==1)){
862                                                                                                 jetsAOD = (AliAODJet*) (jets->At(nLJetMC2));
863                                                                                                 TRefArray *reftracks = jetsAOD->GetRefTracks();
864                                                                                                 MleadMC = reftracks->GetEntriesFast();
865                                                                 }
866                                                                 //----------------------------------------------------------- Leading Jet
867                                                                 if(nj<2)continue;
868                                                                 //Find Sub leading Jet ==================================================
869                                                                 for(int njet=0;njet<nj;njet++){
870                                                                                                 if(njet==nLJet)continue;
871                                                                                                 jetsAOD = (AliAODJet *)jets->At(njet);
872                                                                                                 subJet_pt [algorithm][njet] = jetsAOD->Pt()*JetEScale;
873                                                                                                 subJet_eta[algorithm][njet] = jetsAOD->Eta();
874                                                                                                 double eta_cut_Jet=0.5;
875                                                                                                 if((TMath::Abs(subJet_eta[algorithm][njet])<eta_cut_Jet) && (subJet_pt[algorithm][njet]>10.)){
876                                                                                                                                 if(subJet_pt[algorithm][njet]>ptsLJetAOD&&algorithm==0){
877                                                                                                                                                                 ptsLJetAOD=Jet_pt[algorithm][njet];phisLJetAOD=Jet_phi[algorithm][njet];etasLJetAOD=Jet_eta[algorithm][njet];
878                                                                                                                                 }
879                                                                                                                                 if(subJet_pt[algorithm][njet]>ptsLJetMC2 &&algorithm==1){
880                                                                                                                                                                 ptsLJetMC2=Jet_pt[algorithm][njet];phisLJetMC2=Jet_phi[algorithm][njet];etasLJetMC2=Jet_eta[algorithm][njet];
881                                                                                                                                 }
882                                                                                                                                 if(subJet_pt[algorithm][njet]>ptsLJetMC &&algorithm==2){
883                                                                                                                                                                 ptsLJetMC =Jet_pt[algorithm][njet];phisLJetMC =Jet_phi[algorithm][njet];etasLJetMC =Jet_eta[algorithm][njet];
884                                                                                                                                 }
885                                                                                                 }
886                                                                 }
887                                                                 //====================================================== Sub leading Jet 
888
889                                                                 double Leading_pt=0.;double Leading_phi=999.;double Leading_eta=999.;double sLeading_pt=0.;double sLeading_phi=999.;double sLeading_eta=999.;
890                                                                 if(algorithm==0){Leading_pt=ptLJetAOD;Leading_phi=phiLJetAOD;Leading_eta=etaLJetAOD;sLeading_pt=ptsLJetAOD;sLeading_phi=phisLJetAOD;sLeading_eta=etasLJetAOD;}
891                                                                 if(algorithm==1){Leading_pt=ptLJetMC2;Leading_phi=phiLJetMC2;Leading_eta=etaLJetMC2;sLeading_pt=ptsLJetMC2;sLeading_phi=phisLJetMC2;sLeading_eta=etasLJetMC2;}
892                                                                 if(algorithm==2){Leading_pt=ptLJetMC ;Leading_phi=phiLJetMC ;Leading_eta=etaLJetMC ;sLeading_pt=ptsLJetMC ;sLeading_phi=phisLJetMC ;sLeading_eta=etasLJetMC ;}
893
894                                                                 ////Di-Jet event trigger +++++++++++++++++++++++++++++++++++++++++++++++
895                                                                 double DPhi = DeltaPhi(Leading_phi,sLeading_phi);
896                                                                 double DEta = Leading_eta-sLeading_eta;
897                                                                 if(algorithm==0){
898                                                                                                 fH2JetsJet_dphi->Fill(Leading_pt,DPhi);
899                                                                                                 fH2JetsJet_deta->Fill(Leading_pt,DEta);
900                                                                 }
901                                                                 if(algorithm==1){
902                                                                                                 fH2JetsJetMC_dphi->Fill(Leading_pt,DPhi);
903                                                                                                 fH2JetsJetMC_deta->Fill(Leading_pt,DEta);
904                                                                 }
905                                                                 if((TMath::Cos(DPhi)<-0.5)&&(Leading_pt>10.)&&(sLeading_pt>10.)){
906                                                                                                 if(algorithm==0)Aj   = (Leading_pt-sLeading_pt)/(Leading_pt+sLeading_pt);
907                                                                                                 if(algorithm==1)AjMC = (Leading_pt-sLeading_pt)/(Leading_pt+sLeading_pt);
908                                                                                                 if(algorithm==0){
909                                                                                                                                 fH1subJet_pt_dijet ->Fill(sLeading_pt);
910                                                                                                                                 fH1leadJet_pt_dijet->Fill(Leading_pt);
911                                                                                                                                 fH2JetsJet_Aj      ->Fill(Leading_pt,Aj);
912                                                                                                                                 fH2JetsJet_pt      ->Fill(Leading_pt,sLeading_pt);
913                                                                                                                                 fH2Mult_Aj         ->Fill(Mult,Aj); 
914                                                                                                                                 fH2Mlead_Aj        ->Fill(Mlead,Aj);
915                                                                                                                                 for(int eb=0;eb<5;eb++){
916                                                                                                                                                                 if(TMath::Abs(Leading_pt -10.-20.*(eb))<10.){
917                                                                                                                                                                                                 fH1Aj[eb]   ->Fill(Aj);
918                                                                                                                                                                 }
919                                                                                                                                 }
920                                                                                                 }
921                                                                                                 if(algorithm==1){
922                                                                                                                                 fH1leadJetMC_pt_dijet->Fill(Leading_pt);
923                                                                                                                                 fH1subJetMC_pt_dijet ->Fill(sLeading_pt);
924                                                                                                                                 fH2JetsJetMC_Aj      ->Fill(Leading_pt,AjMC);
925                                                                                                                                 fH2JetsJetMC_pt      ->Fill(Leading_pt,sLeading_pt);
926                                                                                                                                 findDiJetMC=true;
927                                                                                                 }
928                                                                                                 findDiJet=true;
929
930                                                                 }
931                                                                 ////+++++++++++++++++++++++++++++++++++++++++++++++ Di-Jet event trigger 
932
933                                                                 if(algorithm!=0)continue;// for only data & reconstructed Jets
934
935
936                                                                 //Jet-Hadron Correlation###############################################
937                                                                 if((findDiJet)&&(Leading_pt>10.)&&(sLeading_pt>10.)){
938                                                                                                 double eta_cut_Jet=0.5;
939                                                                                                 if(TMath::Abs(Leading_eta)<eta_cut_Jet){
940                                                                                                                                 for(int eb=0;eb<5;eb++){
941                                                                                                                                                                 if(TMath::Abs(Leading_pt -10.-20.*(eb))<10.){
942                                                                                                                                                                                                 fH1ndiJ_ediv[eb]->Fill(1);
943                                                                                                                                                                                                 if(eb==1){
944                                                                                                                                                                                                                                 if((0<Mlead)&&Mlead<7)              {fH1ndiJ_2040Mlead[0]->Fill(1);}
945                                                                                                                                                                                                                                 else if((7<=Mlead)&&(Mlead<10))     {fH1ndiJ_2040Mlead[1]->Fill(1);}
946                                                                                                                                                                                                                                 else                                {fH1ndiJ_2040Mlead[2]->Fill(1);}
947                                                                                                                                                                                                                                 if((0<Aj)&&(Aj<0.19))               {fH1ndiJ_2040Aj   [0]->Fill(1);}
948                                                                                                                                                                                                                                 else if((0.19<=Aj)&&(Aj<0.38))      {fH1ndiJ_2040Aj   [1]->Fill(1);}
949                                                                                                                                                                                                                                 else                                {fH1ndiJ_2040Aj   [2]->Fill(1);}
950                                                                                                                                                                                                 }
951                                                                                                                                                                                                 fH1Mlead[eb]->Fill(Mlead);
952                                                                                                                                                                                                 for(int ntrack =0;ntrack<nt;ntrack++){
953                                                                                                                                                                                                                                 trackAOD = (AliAODTrack*) (fAODIn->GetTrack(ntrack));
954                                                                                                                                                                                                                                 Bool_t bgoodT=false;
955                                                                                                                                                                                                                                 if(Filtermask!=272){if(trackAOD->TestFilterMask(Filtermask))bgoodT=true;}
956                                                                                                                                                                                                                                 else{               if(trackAOD->IsHybridGlobalConstrainedGlobal())bgoodT=true;} //for hybrid Track cuts
957                                                                                                                                                                                                                                 if(!bgoodT)continue;
958                                                                                                                                                                                                                                 Track_pt   [ntrack]      = (trackAOD->Pt()*TrackEScale);
959                                                                                                                                                                                                                                 Track_phi  [ntrack]      = trackAOD->Phi();
960                                                                                                                                                                                                                                 Track_eta  [ntrack]      = trackAOD->Eta();
961
962                                                                                                                                                                                                                                 //cout<<"Scale "<<TrackEScale<<"  org pt "<<trackAOD->Pt()<< " scaled pt "<< trackAOD->Pt()*TrackEScale <<endl;
963
964                                                                                                                                                                                                                                 double DelPhi = DeltaPhi(Leading_phi,Track_phi[ntrack]);
965                                                                                                                                                                                                                                 if(TMath::Abs(Track_eta[ntrack])<0.9){
966                                                                                                                                                                                                                                                                 if((TMath::Abs(DelPhi-pi/2.)<pi/8.)||((DelPhi+pi/2.)<pi/8.)||(TMath::Abs(DelPhi-3./2.*pi)<pi/8.))Munder++;
967                                                                                                                                                                                                                                                                 for(int teb=0;teb<5;teb++){
968                                                                                                                                                                                                                                                                                                 if(teb==0){if(!( Track_pt[ntrack]>0.15))continue;}
969                                                                                                                                                                                                                                                                                                 if(teb==1){if(!((Track_pt[ntrack]<1.5)&&(Track_pt[ntrack]>0.15)))continue;}
970                                                                                                                                                                                                                                                                                                 if(teb==2){if(!((Track_pt[ntrack]<3.0)&&(Track_pt[ntrack]>1.5)))continue;}
971                                                                                                                                                                                                                                                                                                 if(teb==3){if(!((Track_pt[ntrack]<4.5)&&(Track_pt[ntrack]>3.0)))continue;}
972                                                                                                                                                                                                                                                                                                 if(teb==4){if(!( Track_pt[ntrack]>4.5))continue;}
973                                                                                                                                                                                                                                                                                                 fH1JetHadron_dphi_ediv                [eb][teb]->Fill(DelPhi); 
974                                                                                                                                                                                                                                                                                                 fH1JetHadron_dphi_tptweight_ediv      [eb][teb]->Fill(DelPhi,Track_pt[ntrack]);
975                                                                                                                                                                                                                                                                                                 fH1JetHadron_dphi_tJptweight_ediv     [eb][teb]->Fill(DelPhi,Track_pt[ntrack]/Leading_pt);
976                                                                                                                                                                                                                                                                                                 if(eb==1){
977                                                                                                                                                                                                                                                                                                                                 if((0<Mlead)&&Mlead<7)         {fH1JetHadron_dphi_tptweight2040_Mleaddep[0][teb]->Fill(DelPhi,Track_pt[ntrack]);}
978                                                                                                                                                                                                                                                                                                                                 else if((7<=Mlead)&&(Mlead<10)){fH1JetHadron_dphi_tptweight2040_Mleaddep[1][teb]->Fill(DelPhi,Track_pt[ntrack]);}
979                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadron_dphi_tptweight2040_Mleaddep[2][teb]->Fill(DelPhi,Track_pt[ntrack]);}
980                                                                                                                                                                                                                                                                                                                                 if((0<Aj)&&(Aj<0.19))          {fH1JetHadron_dphi_tptweight2040_Ajdep   [0][teb]->Fill(DelPhi,Track_pt[ntrack]);}
981                                                                                                                                                                                                                                                                                                                                 else if((0.19<=Aj)&&(Aj<0.38)) {fH1JetHadron_dphi_tptweight2040_Ajdep   [1][teb]->Fill(DelPhi,Track_pt[ntrack]);}
982                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadron_dphi_tptweight2040_Ajdep   [2][teb]->Fill(DelPhi,Track_pt[ntrack]);}
983                                                                                                                                                                                                                                                                                                 }
984                                                                                                                                                                                                                                                                 }
985                                                                                                                                                                                                                                 }
986                                                                                                                                                                                                 }//Track Loop
987                                                                                                                                                                                                 if(IsMC){
988                                                                                                                                                                                                                                 //MC Track
989                                                                                                                                                                                                                                 TClonesArray* mctracks = dynamic_cast <TClonesArray*> (fAODIn->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
990                                                                                                                                                                                                                                 if(!mctracks){
991                                                                                                                                                                                                                                                                 if (fDebug > 1)  Printf("%s:%d could not get AODMCtracks", (char*)__FILE__,__LINE__);
992                                                                                                                                                                                                                                                                 continue;
993                                                                                                                                                                                                                                 }
994                                                                                                                                                                                                                                 Int_t ntmc = mctracks->GetEntriesFast();
995                                                                                                                                                                                                                                 AliAODMCParticle* trackMCAOD;
996                                                                                                                                                                                                                                 int lastprim=0;
997                                                                                                                                                                                                                                 for(int ntrack =0;ntrack<ntmc;ntrack++){
998                                                                                                                                                                                                                                                                 trackMCAOD = (AliAODMCParticle*) (mctracks->At(ntrack));
999                                                                                                                                                                                                                                                                 if((trackMCAOD->IsPhysicalPrimary())==1)lastprim=ntrack;
1000                                                                                                                                                                                                                                 }
1001                                                                                                                                                                                                                                 for(int ntrack =0;ntrack<ntmc;ntrack++){
1002                                                                                                                                                                                                                                                                 trackMCAOD = (AliAODMCParticle*) (mctracks->At(ntrack));
1003                                                                                                                                                                                                                                                                 if((trackMCAOD->GetPdgCode()>10)&&((trackMCAOD->GetMother())>1)&&(ntrack>lastprim)&&(trackMCAOD->Charge())){// for Decay particles
1004                                                                                                                                                                                                                                                                                                 MCTrack_pt   [ntrack]      = trackMCAOD->Pt();
1005                                                                                                                                                                                                                                                                                                 MCTrack_phi  [ntrack]      = trackMCAOD->Phi();
1006                                                                                                                                                                                                                                                                                                 MCTrack_eta  [ntrack]      = trackMCAOD->Eta();
1007                                                                                                                                                                                                                                                                                                 double DelPhi = DeltaPhi(Leading_phi,MCTrack_phi[ntrack]);
1008                                                                                                                                                                                                                                                                                                 if(TMath::Abs(MCTrack_eta[ntrack])<0.9){
1009                                                                                                                                                                                                                                                                                                                                 for(int teb=0;teb<5;teb++){
1010                                                                                                                                                                                                                                                                                                                                                                 if(teb==0){if(!( MCTrack_pt[ntrack]>0.15))continue;}
1011                                                                                                                                                                                                                                                                                                                                                                 if(teb==1){if(!((MCTrack_pt[ntrack]<1.5)&&(MCTrack_pt[ntrack]>0.15)))continue;}
1012                                                                                                                                                                                                                                                                                                                                                                 if(teb==2){if(!((MCTrack_pt[ntrack]<3.0)&&(MCTrack_pt[ntrack]>1.5)))continue;}
1013                                                                                                                                                                                                                                                                                                                                                                 if(teb==3){if(!((MCTrack_pt[ntrack]<4.5)&&(MCTrack_pt[ntrack]>3.0)))continue;}
1014                                                                                                                                                                                                                                                                                                                                                                 if(teb==4){if(!( MCTrack_pt[ntrack]>4.5))continue;}
1015                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMC_dphi_ediv                [eb][teb]->Fill(DelPhi); 
1016                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMC_dphi_tptweight_ediv      [eb][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);
1017                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMC_dphi_tJptweight_ediv     [eb][teb]->Fill(DelPhi,MCTrack_pt[ntrack]/Leading_pt);
1018                                                                                                                                                                                                                                                                                                                                                                 if(eb==1){
1019                                                                                                                                                                                                                                                                                                                                                                                                 if((0<Mlead)&&Mlead<7)         {fH1JetHadronMC_dphi_tptweight2040_Mleaddep[0][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1020                                                                                                                                                                                                                                                                                                                                                                                                 else if((7<=Mlead)&&(Mlead<10)){fH1JetHadronMC_dphi_tptweight2040_Mleaddep[1][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1021                                                                                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadronMC_dphi_tptweight2040_Mleaddep[2][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1022                                                                                                                                                                                                                                                                                                                                                                                                 if((0<Aj)&&(Aj<0.19))          {fH1JetHadronMC_dphi_tptweight2040_Ajdep   [0][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1023                                                                                                                                                                                                                                                                                                                                                                                                 else if((0.19<=Aj)&&(Aj<0.38)) {fH1JetHadronMC_dphi_tptweight2040_Ajdep   [1][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1024                                                                                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadronMC_dphi_tptweight2040_Ajdep   [2][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1025                                                                                                                                                                                                                                                                                                                                                                 }
1026                                                                                                                                                                                                                                                                                                                                 }
1027                                                                                                                                                                                                                                                                                                 }
1028                                                                                                                                                                                                                                                                 }
1029                                                                                                                                                                                                                                                                 if((trackMCAOD->IsPhysicalPrimary())&&(trackMCAOD->Charge())){// for Physical particles
1030                                                                                                                                                                                                                                                                                                 MCTrack_pt   [ntrack]      = trackMCAOD->Pt();
1031                                                                                                                                                                                                                                                                                                 MCTrack_phi  [ntrack]      = trackMCAOD->Phi();
1032                                                                                                                                                                                                                                                                                                 MCTrack_eta  [ntrack]      = trackMCAOD->Eta();
1033                                                                                                                                                                                                                                                                                                 double DelPhi = DeltaPhi(Leading_phi,MCTrack_phi[ntrack]);
1034                                                                                                                                                                                                                                                                                                 if(TMath::Abs(MCTrack_eta[ntrack])<0.9){
1035                                                                                                                                                                                                                                                                                                                                 for(int teb=0;teb<5;teb++){
1036                                                                                                                                                                                                                                                                                                                                                                 if(teb==0){if(!( MCTrack_pt[ntrack]>0.15))continue;}
1037                                                                                                                                                                                                                                                                                                                                                                 if(teb==1){if(!((MCTrack_pt[ntrack]<1.5)&&(MCTrack_pt[ntrack]>0.15)))continue;}
1038                                                                                                                                                                                                                                                                                                                                                                 if(teb==2){if(!((MCTrack_pt[ntrack]<3.0)&&(MCTrack_pt[ntrack]>1.5)))continue;}
1039                                                                                                                                                                                                                                                                                                                                                                 if(teb==3){if(!((MCTrack_pt[ntrack]<4.5)&&(MCTrack_pt[ntrack]>3.0)))continue;}
1040                                                                                                                                                                                                                                                                                                                                                                 if(teb==4){if(!( MCTrack_pt[ntrack]>4.5))continue;}
1041                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMC_dphi_ediv                [eb][teb]->Fill(DelPhi); 
1042                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMC_dphi_tptweight_ediv      [eb][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);
1043                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMC_dphi_tJptweight_ediv     [eb][teb]->Fill(DelPhi,MCTrack_pt[ntrack]/Leading_pt);
1044                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMCPrim_dphi_ediv                [eb][teb]->Fill(DelPhi); 
1045                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMCPrim_dphi_tptweight_ediv      [eb][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);
1046                                                                                                                                                                                                                                                                                                                                                                 fH1JetHadronMCPrim_dphi_tJptweight_ediv     [eb][teb]->Fill(DelPhi,MCTrack_pt[ntrack]/Leading_pt);
1047                                                                                                                                                                                                                                                                                                                                                                 if(eb==1){
1048                                                                                                                                                                                                                                                                                                                                                                                                 if((0<Mlead)&&Mlead<7)         {fH1JetHadronMC_dphi_tptweight2040_Mleaddep[0][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1049                                                                                                                                                                                                                                                                                                                                                                                                 else if((7<=Mlead)&&(Mlead<10)){fH1JetHadronMC_dphi_tptweight2040_Mleaddep[1][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1050                                                                                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadronMC_dphi_tptweight2040_Mleaddep[2][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1051                                                                                                                                                                                                                                                                                                                                                                                                 if((0<Aj)&&(Aj<0.19))          {fH1JetHadronMC_dphi_tptweight2040_Ajdep   [0][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1052                                                                                                                                                                                                                                                                                                                                                                                                 else if((0.19<=Aj)&&(Aj<0.38)) {fH1JetHadronMC_dphi_tptweight2040_Ajdep   [1][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1053                                                                                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadronMC_dphi_tptweight2040_Ajdep   [2][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1054
1055                                                                                                                                                                                                                                                                                                                                                                                                 if((0<Mlead)&&Mlead<7)         {fH1JetHadronMCPrim_dphi_tptweight2040_Mleaddep[0][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1056                                                                                                                                                                                                                                                                                                                                                                                                 else if((7<=Mlead)&&(Mlead<10)){fH1JetHadronMCPrim_dphi_tptweight2040_Mleaddep[1][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1057                                                                                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadronMCPrim_dphi_tptweight2040_Mleaddep[2][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1058                                                                                                                                                                                                                                                                                                                                                                                                 if((0<Aj)&&(Aj<0.19))          {fH1JetHadronMCPrim_dphi_tptweight2040_Ajdep   [0][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1059                                                                                                                                                                                                                                                                                                                                                                                                 else if((0.19<=Aj)&&(Aj<0.38)) {fH1JetHadronMCPrim_dphi_tptweight2040_Ajdep   [1][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1060                                                                                                                                                                                                                                                                                                                                                                                                 else                           {fH1JetHadronMCPrim_dphi_tptweight2040_Ajdep   [2][teb]->Fill(DelPhi,MCTrack_pt[ntrack]);}
1061                                                                                                                                                                                                                                                                                                                                                                 }
1062                                                                                                                                                                                                                                                                                                                                 }
1063                                                                                                                                                                                                                                                                                                 }
1064                                                                                                                                                                                                                                                                 }
1065                                                                                                                                                                                                                                 }
1066                                                                                                                                                                                                 }
1067                                                                                                                                                                 }
1068                                                                                                                                 }// Momentum Loop Jet
1069                                                                                                                                 fH2Jet_pt_Munder   ->Fill(Leading_pt,(double)Munder/(1.8*pi/2.)*Jet_area[0][nLJet]);
1070                                                                                                                                 fH2Jet_pt_Mlead    ->Fill(Leading_pt,Mlead);
1071                                                                                                 }//eta cut
1072                                                                 }// Di-Jet
1073                                                                 //############################################### Jet-Hadron Correlation
1074                                 }// algorithm LOOP
1075                                 if(IsMC){
1076                                                                 for(int eb=0;eb<5;eb++){
1077                                                                                                 double DPhi,DEta;
1078                                                                                                 if(TMath::Abs(ptLJetAOD -10.-20.*(eb))<10.){
1079                                                                                                                                 DPhi = DeltaPhi(phiLJetMC,phiLJetAOD);
1080                                                                                                                                 DEta = etaLJetMC-etaLJetAOD;
1081                                                                                                                                 fH1leadJetMC_dphiResolution[eb]->Fill(DPhi);
1082                                                                                                                                 if(sqrt(pow(DPhi,2)+pow(DEta,2))<0.4)fH1leadJetMC_Efficiency[eb]->Fill(1);
1083                                                                                                                                 else                                 fH1leadJetMC_Efficiency[eb]->Fill(0);
1084                                                                                                                                 DPhi = DeltaPhi(phisLJetMC,phisLJetAOD);
1085                                                                                                                                 DEta = etasLJetMC-etasLJetAOD;
1086                                                                                                                                 fH1subJetMC_dphiResolution[eb]->Fill(DPhi);
1087                                                                                                                                 if(sqrt(pow(DPhi,2)+pow(DEta,2))<0.4)fH1subJetMC_Efficiency[eb]->Fill(1);
1088                                                                                                                                 else                                 fH1subJetMC_Efficiency[eb]->Fill(0);
1089                                                                                                                                 DPhi = DeltaPhi(phiLJetMC2,phiLJetAOD);
1090                                                                                                                                 DEta = etaLJetMC2-etaLJetAOD;
1091
1092                                                                                                                                 if(sqrt(pow(DPhi,2)+pow(DEta,2))<0.4)fH2leadJetMCptResolution->Fill(ptLJetMC2,ptLJetAOD);
1093                                                                                                                                 if(findDiJetMC)fH2AjCorrelation_MCRec   ->Fill(AjMC,Aj);
1094                                                                                                                                 if(findDiJetMC)fH2MleadCorrelation_MCRec->Fill(MleadMC,Mlead);
1095                                                                                                 }
1096                                                                 }
1097                                                                 fH2Mult_Mtrack->Fill(Mult,Track_n); 
1098                                                                 fH2Mult_Mjet  ->Fill(Mult,Mjet_tot);
1099                                                                 fH2Mult_Njet  ->Fill(Mult,Njet_tot);
1100                                                                 if(findLJetAOD)fH2Mult_Mlead ->Fill(Mult,Mlead);   
1101                                 }
1102                                 else{
1103                                                                 fH2Mult_Mtrack->Fill(Mult,Track_n); 
1104                                                                 fH2Mult_Mjet  ->Fill(Mult,Mjet_tot);
1105                                                                 fH2Mult_Njet  ->Fill(Mult,Njet_tot);
1106                                                                 if(findLJetAOD)fH2Mult_Mlead ->Fill(Mult,Mlead);   
1107                                 }
1108
1109                                 PostData(1, fHistList);
1110                                 return;
1111 }      
1112
1113 //________________________________________________________________________
1114 void AliAnalysisTaskJetHadronCorrelation::Terminate(Option_t *){
1115                                 // Terminate analysis
1116                                 if (fDebug) printf("AnalysisTaskPt: Terminate() \n");
1117 }
1118
1119 Double_t AliAnalysisTaskJetHadronCorrelation::DeltaPhi(Double_t phi1,Double_t phi2){
1120                                 Float_t pi=TMath::Pi();
1121                                 Double_t dphi = phi1-phi2;
1122                                 if     (dphi<(-1./2*pi))dphi = dphi +2*pi;
1123                                 else if(dphi>( 3./2*pi))dphi = dphi -2*pi;
1124                                 return dphi;
1125 }