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, ""),
57 cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name)"<<endl;
59 // Define input and output slots here
60 // Input slot #0 works with a TChain
61 DefineInput(0, TChain::Class());
62 // Output slot #0 writes into a TList container
63 DefineOutput(0, TList::Class());
66 //________________________________________________________________________
67 void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
69 // Connect ESD or AOD here
71 cout<<"AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)"<<endl;
73 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
75 Printf("ERROR: Could not read chain from input slot 0");
77 // Disable all branches and enable only the needed ones
78 if (fAnalysisType == "MC") {
79 cout<<"!!!!!reading MC kinematics only"<<endl;
80 // we want to process only MC
81 tree->SetBranchStatus("*", kFALSE);
83 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
86 Printf("ERROR: Could not get ESDInputHandler");
88 fESD = esdH->GetEvent();
91 else if (fAnalysisType == "ESD") {
92 cout<<"!!!!!reading the ESD only"<<endl;
93 tree->SetBranchStatus("*", kFALSE);
94 tree->SetBranchStatus("Tracks.*", kTRUE);
96 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
99 Printf("ERROR: Could not get ESDInputHandler");
101 fESD = esdH->GetEvent();
103 else if (fAnalysisType == "AOD") {
104 cout<<"!!!!!reading the AOD only"<<endl;
105 AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
108 Printf("ERROR: Could not get AODInputHandler");
111 fAOD = aodH->GetEvent();
115 Printf("!!!!!Wrong analysis type: Only ESD, AOD and MC types are allowed!");
122 //________________________________________________________________________
123 void AliAnalysisTaskScalarProduct::CreateOutputObjects()
126 cout<<"AliAnalysisTaskScalarProduct::CreateOutputObjects()"<<endl;
128 if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "MC")) {
129 cout<<"WRONG ANALYSIS TYPE! only ESD, AOD and MC are allowed."<<endl;
134 fEventMaker = new AliFlowEventSimpleMaker();
136 fSP = new AliFlowAnalysisWithScalarProduct() ;
139 TString fName = "outputFromScalarProductAnalysis" ;
140 fName += fAnalysisType.Data() ;
142 fSP->SetHistFileName( fName.Data() );
149 //________________________________________________________________________
150 void AliAnalysisTaskScalarProduct::Exec(Option_t *)
153 // Called for each event
156 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
157 // This handler can return the current MC event
159 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
161 Printf("ERROR: Could not retrieve MC event handler");
165 AliMCEvent* mcEvent = eventHandler->MCEvent();
167 Printf("ERROR: Could not retrieve MC event");
171 Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
173 if (fAnalysisType == "MC") {
175 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent);
180 else if (fAnalysisType == "ESD") {
182 Printf("ERROR: fESD not available");
185 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
188 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
192 else if (fAnalysisType == "AOD") {
194 Printf("ERROR: fAOD not available");
197 Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
200 AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
207 //________________________________________________________________________
208 void AliAnalysisTaskScalarProduct::Terminate(Option_t *)
210 // Called once at the end of the query
212 PostData(0,fSP->GetHistFile());