AliEveEventManager
[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
25
26 ClassImp(AliAnalysisTaskDiJets)
27
28 ////////////////////////////////////////////////////////////////////////
29
30 AliAnalysisTaskDiJets::AliAnalysisTaskDiJets():
31     AliAnalysisTaskSE(),
32     fDiJets(0),
33     fDiJetsIn(0)
34 {
35   // Default constructor
36 }
37
38 AliAnalysisTaskDiJets::AliAnalysisTaskDiJets(const char* name):
39     AliAnalysisTaskSE(name),
40     fDiJets(0),
41     fDiJetsIn(0)
42 {
43   // Default constructor
44 }
45
46 void AliAnalysisTaskDiJets::UserCreateOutputObjects()
47 {
48 // Create the output container
49 //
50     if (fDebug > 1) printf("AnalysisTaskDiJets::CreateOutPutData() \n");
51     fDiJets = new TClonesArray("AliAODDiJet", 0);
52     fDiJets->SetName("Dijets");
53     AddAODBranch("TClonesArray", &fDiJets);
54 }
55
56 void AliAnalysisTaskDiJets::Init()
57 {
58     // Initialization
59     if (fDebug > 1) printf("AnalysisTaskDiJets::Init() \n");
60 }
61
62 void AliAnalysisTaskDiJets::UserExec(Option_t */*option*/)
63 {
64 // Execute analysis for current event
65 //
66     fDiJets->Delete();
67     AliAODEvent* aod   = dynamic_cast<AliAODEvent*> (InputEvent());
68     TClonesArray* jets = aod->GetJets();
69     fDiJetsIn = (TClonesArray*) (aod->GetList()->FindObject("Dijets"));
70    
71     if (fDiJetsIn) {
72         printf("Found %d dijets in old list \n", fDiJetsIn->GetEntries());
73         AliAODJet* jj1, *jj2;
74         AliAODDiJet* testJ;
75         
76         if (fDiJetsIn->GetEntries() > 0) {
77             testJ = (AliAODDiJet*) (fDiJetsIn->At(0));
78             jj1 = testJ->Jet(0);
79             jj1->Print("");
80             jj2 = testJ->Jet(1);
81             jj2->Print("");
82         }
83     }
84     
85     
86     Int_t nj = jets->GetEntriesFast();
87     printf("There are %5d jets in the event \n", nj);
88     if (nj > 1) {
89                 for (Int_t iJet1=0; iJet1<nj; iJet1++){
90                         AliAODJet* jet1 = (AliAODJet*) (jets->At(iJet1));
91                         TLorentzVector v1 = *(jet1->MomentumVector());
92                         for (Int_t iJet2=iJet1+1; iJet2<nj; iJet2++){
93                                 AliAODJet* jet2 = (AliAODJet*) (jets->At(iJet2));
94                                 TLorentzVector v2 = *(jet2->MomentumVector());
95                                 TLorentzVector v = v1 + v2;
96                                 Int_t ndi = fDiJets->GetEntriesFast();
97                                 TClonesArray &lref = *fDiJets;
98                                 new(lref[ndi]) AliAODDiJet(v);;
99                                 AliAODDiJet* dijet = (AliAODDiJet*) (fDiJets->At(ndi));
100                                 dijet->SetJetRefs(jet1, jet2);
101                         }
102                 }
103     }
104     
105 }
106
107 void AliAnalysisTaskDiJets::Terminate(Option_t */*option*/)
108 {
109 // Terminate analysis
110 //
111     if (fDebug > 1) printf("AnalysisDiJets: Terminate() \n");
112 }
113