1 /*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include "Riostream.h" //needed as include
19 #include "TFile.h" //needed as include
23 class AliAnalysisTask;
24 #include "AliAnalysisManager.h"
26 #include "AliESDEvent.h"
27 #include "AliESDInputHandler.h"
29 #include "AliAODEvent.h"
30 #include "AliAODInputHandler.h"
32 #include "AliMCEventHandler.h"
33 #include "AliMCEvent.h"
35 #include "AliAnalysisTaskScalarProduct.h"
36 #include "AliFlowEventSimpleMaker.h"
37 #include "AliFlowAnalysisWithScalarProduct.h"
39 // AliAnalysisTaskScalarProduct:
41 // analysis task for Scalar Product Method
43 // Author: Naomi van der Kolk (kolk@nikhef.nl)
45 ClassImp(AliAnalysisTaskScalarProduct)
47 //________________________________________________________________________
48 AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name) :
49 AliAnalysisTask(name, ""),
58 cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name)"<<endl;
60 // Define input and output slots here
61 // Input slot #0 works with a TChain
62 DefineInput(0, TChain::Class());
63 // Output slot #0 writes into a TList container
64 DefineOutput(0, TList::Class());
68 //________________________________________________________________________
69 AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct() :
78 cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct()"<<endl;
81 //________________________________________________________________________
82 AliAnalysisTaskScalarProduct::~AliAnalysisTaskScalarProduct()
88 // histograms are in the output list and deleted when the output
89 // list is deleted by the TSelector dtor
92 // delete fListHistos;
93 // fListHistos = NULL;
97 //________________________________________________________________________
98 void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
100 // Connect ESD or AOD here
102 cout<<"AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)"<<endl;
104 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
106 Printf("ERROR: Could not read chain from input slot 0");
108 // Disable all branches and enable only the needed ones
109 if (fAnalysisType == "MC") {
110 cout<<"!!!!!reading MC kinematics only"<<endl;
111 // we want to process only MC
112 tree->SetBranchStatus("*", kFALSE);
114 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
117 Printf("ERROR: Could not get ESDInputHandler");
119 fESD = esdH->GetEvent();
122 else if (fAnalysisType == "ESD") {
123 cout<<"!!!!!reading the ESD only"<<endl;
124 tree->SetBranchStatus("*", kFALSE);
125 tree->SetBranchStatus("Tracks.*", kTRUE);
127 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
130 Printf("ERROR: Could not get ESDInputHandler");
132 fESD = esdH->GetEvent();
134 else if (fAnalysisType == "AOD") {
135 cout<<"!!!!!reading the AOD only"<<endl;
136 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
139 Printf("ERROR: Could not get AODInputHandler");
142 fAOD = aodH->GetEvent();
146 Printf("!!!!!Wrong analysis type: Only ESD, AOD and MC types are allowed!");
153 //________________________________________________________________________
154 void AliAnalysisTaskScalarProduct::CreateOutputObjects()
156 // Called at every worker node to initialize
157 cout<<"AliAnalysisTaskScalarProduct::CreateOutputObjects()"<<endl;
159 fEventMaker = new AliFlowEventSimpleMaker();
161 fSP = new AliFlowAnalysisWithScalarProduct() ;
165 if (fSP->GetHistList()) {
166 fSP->GetHistList()->Print();
167 // fListHistos = new TList(fSP->GetHistList());
168 fListHistos = fSP->GetHistList();
169 fListHistos->Print();
171 else {Printf("ERROR: Could not retrieve histogram list"); }
174 //________________________________________________________________________
175 void AliAnalysisTaskScalarProduct::Exec(Option_t *)
178 // Called for each event
183 if (fAnalysisType == "MC") {
185 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
186 // This handler can return the current MC event
188 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
190 Printf("ERROR: Could not retrieve MC event handler");
194 AliMCEvent* mcEvent = eventHandler->MCEvent();
196 Printf("ERROR: Could not retrieve MC event");
201 Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
202 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent);
207 else if (fAnalysisType == "ESD") {
209 Printf("ERROR: fESD not available");
212 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
215 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
219 else if (fAnalysisType == "AOD") {
221 Printf("ERROR: fAOD not available");
224 Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
227 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
232 fListHistos->Print();
233 PostData(0,fListHistos);
236 //________________________________________________________________________
237 void AliAnalysisTaskScalarProduct::Terminate(Option_t *)
239 // Called once at the end of the query
241 // PostData(0,fListHistos);
242 fListHistos = (TList*)GetOutputData(0);
243 cout << "histgram list in Terminate" << endl;
246 fListHistos->Print();
250 cout << "histgram list pointer is empty" << endl;
253 // delete fEventMaker;