dcf75f0ae644d2632eb69094fe66c8a7ddaaacab
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskDiJets.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17  
18 #include "AliAnalysisTaskDiJets.h"
19 #include "AliAODEvent.h"
20 #include "AliAODJet.h"
21 #include "AliAODDiJet.h"
22 #include <TClonesArray.h>
23 #include <TLorentzVector.h>
24 #include <TStyle.h>
25
26
27 ClassImp(AliAnalysisTaskDiJets)
28
29 ////////////////////////////////////////////////////////////////////////
30
31 AliAnalysisTaskDiJets::AliAnalysisTaskDiJets():
32     AliAnalysisTaskSE(),
33     fDiJets(0),
34     fDiJetsIn(0),
35     fUseAODInput(kFALSE),
36     fFillAOD(kFALSE),
37     fJetBranch("jets"),
38     fAOD(0),
39     fHistList(0),
40     fH1DeltaPt(0),
41     fH1DeltaPhi(0),
42     fH1PhiImbal(0),
43     fH1Asym(0),
44     fH2Pt2vsPt1(0),
45     fH2DifvsSum(0)
46 {
47   // Default constructor
48 }
49
50 //----------------------------------------------------------------------
51 AliAnalysisTaskDiJets::AliAnalysisTaskDiJets(const char* name):
52     AliAnalysisTaskSE(name),
53     fDiJets(0),
54     fDiJetsIn(0),
55     fUseAODInput(kFALSE),
56     fFillAOD(kFALSE),
57     fJetBranch("jets"),
58     fAOD(0),
59     fHistList(0),
60     fH1DeltaPt(0),
61     fH1DeltaPhi(0),
62     fH1PhiImbal(0),
63     fH1Asym(0),
64     fH2Pt2vsPt1(0),
65     fH2DifvsSum(0)
66 {
67   // Default constructor
68     DefineOutput(1, TList::Class());  
69 }
70
71 //----------------------------------------------------------------------
72 void AliAnalysisTaskDiJets::UserCreateOutputObjects()
73 {
74 // Create the output container
75 //
76     if (fDebug) printf("AnalysisTaskDiJets::CreateOutPutData() \n");
77     fDiJets = new TClonesArray("AliAODDiJet", 0);
78     if (fFillAOD){
79       fDiJets->SetName(Form("dijets_%s",fJetBranch.Data()));
80       AddAODBranch("TClonesArray", &fDiJets);
81         }
82
83     if (!fHistList) fHistList = new TList();
84     Float_t pi=TMath::Pi();
85     gStyle->SetPalette(1);
86
87     fH1DeltaPt  = new TH1F("DeltaPt","Difference between the jets' Pt;#Deltap_{T} (GeV/c);Entries",150,0.,150.);
88     fH1DeltaPt->SetMarkerSize(0.6);
89     fH1DeltaPt->SetMarkerColor(4);
90     fH1DeltaPt->SetMarkerStyle(21);
91     fH1DeltaPt->SetOption("E");
92
93     fH1DeltaPhi = new TH1F("DeltaPhi","Difference in the azimuthal angle;#Delta#phi;Entries",100,0.,pi);
94     fH1DeltaPhi->SetMarkerSize(0.6);
95     fH1DeltaPhi->SetMarkerColor(4);
96     fH1DeltaPhi->SetMarkerStyle(21);
97     fH1DeltaPhi->SetOption("E");
98
99     fH1PhiImbal = new TH1F("PhiImb","Phi imbalance;#phi;Entries",100,-pi,pi);
100     fH1PhiImbal->SetMarkerSize(0.6);
101     fH1PhiImbal->SetMarkerColor(4);
102     fH1PhiImbal->SetMarkerStyle(21);
103     fH1PhiImbal->SetOption("E");
104
105     fH1Asym     = new TH1F("Asym","Pt asymmetry;#Deltap_{T}/(p_{T,1}+p_{T,2});Entries",50,0.,1.);
106     fH1Asym->SetMarkerSize(0.6);
107     fH1Asym->SetMarkerColor(4);
108     fH1Asym->SetMarkerStyle(21);
109     fH1Asym->SetOption("E");
110
111     fH2Pt2vsPt1 = new TH2F("Pt2vsPt1","Pt2 versus Pt1;p_{T,1} (GeV/c);p_{T,2} (GeV/c)",250,0.,250.,250,0.,250.);
112     fH2Pt2vsPt1->SetOption("cont0");
113
114     fH2DifvsSum = new TH2F("DifvsSum","Pt difference vs Pt sum;p_{T,1}+p_{T,2} (GeV/c);#Deltap_{T} (GeV/c)",400,0.,400.,150,0.,150.);
115     fH2DifvsSum->SetOption("cont0");
116
117     fHistList->Add(fH1DeltaPt);
118     fHistList->Add(fH1DeltaPhi);
119     fHistList->Add(fH1PhiImbal);
120     fHistList->Add(fH1Asym);
121     fHistList->Add(fH2Pt2vsPt1);
122     fHistList->Add(fH2DifvsSum);
123 }
124
125 //----------------------------------------------------------------------
126 void AliAnalysisTaskDiJets::Init()
127 {
128     // Initialization
129     if (fDebug) printf("AnalysisTaskDiJets::Init() \n");
130 }
131
132 //----------------------------------------------------------------------
133 void AliAnalysisTaskDiJets::UserExec(Option_t */*option*/)
134 {
135 // Execute analysis for current event
136 //
137     if (fDiJets) fDiJets->Delete();
138
139     if(fUseAODInput){
140       AliAODEvent* fAOD   = dynamic_cast<AliAODEvent*> (InputEvent());
141       if(!fAOD){
142         // We do not have an input AOD, look in the output
143         if (fDebug) printf("%s:%d No AOD event in the input\n",(char*)__FILE__,__LINE__);
144         return;
145       }
146     } else {
147       fAOD = AODEvent();
148       if(!fAOD){
149         if (fDebug) printf("%s:%d AODEvent not found in the Output",(char*)__FILE__,__LINE__);
150         return;
151       }
152     }
153
154     TClonesArray* jets = (TClonesArray*) fAOD->FindListObject(fJetBranch.Data());
155     // N.B. if we take the aod from the output this is always
156     // empty and since it is the same as fDiJets 
157     fDiJetsIn = (TClonesArray*) (fAOD->GetList()->FindObject("dijets"));
158
159     if (fDiJetsIn) {
160       if (fDebug) printf("Found %d dijets in old list \n", fDiJetsIn->GetEntries());
161       AliAODJet* jj1, *jj2;
162       AliAODDiJet* testJ;
163
164       if (fDiJetsIn->GetEntries() > 0) {
165         testJ = (AliAODDiJet*) (fDiJetsIn->At(0));
166         jj1 = testJ->Jet(0);
167         jj1->Print("");
168         jj2 = testJ->Jet(1);
169         jj2->Print("");
170       }
171     }
172
173     Int_t nj = jets->GetEntriesFast();
174     if (fDebug) printf("There are %5d jets in the event \n", nj);
175
176     if (nj < 2){
177       PostData(1, fHistList);
178       return;
179     }
180     AliAODJet* jet1 = (AliAODJet*) (jets->At(0));
181     TLorentzVector v1 = *(jet1->MomentumVector());
182     AliAODJet* jet2 = (AliAODJet*) (jets->At(1));
183     TLorentzVector v2 = *(jet2->MomentumVector());
184     TLorentzVector v = v1 + v2;
185     Int_t ndi = fDiJets->GetEntriesFast();
186     TClonesArray &lref = *fDiJets;
187     new(lref[ndi]) AliAODDiJet(v);
188     AliAODDiJet* dijet = (AliAODDiJet*) (fDiJets->At(ndi));
189     dijet->SetJetRefs(jet1, jet2);
190
191     fH1DeltaPt->Fill(jet1->Pt()-jet2->Pt());
192     fH1DeltaPhi->Fill(dijet->DeltaPhi());
193     fH1PhiImbal->Fill(dijet->PhiImbalance());
194     fH1Asym->Fill((jet1->Pt()-jet2->Pt())/(jet1->Pt()+jet2->Pt()));
195     fH2Pt2vsPt1->Fill(jet1->Pt(),jet2->Pt());
196     fH2DifvsSum->Fill(jet1->Pt()+jet2->Pt(),jet1->Pt()-jet2->Pt());
197
198     PostData(1, fHistList);
199     return;
200 }
201
202 //----------------------------------------------------------------------
203 void AliAnalysisTaskDiJets::Terminate(Option_t */*option*/)
204 {
205 // Terminate analysis
206 //
207     if (fDebug) printf("AnalysisDiJets: Terminate() \n");
208 }
209