1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 **************************************************************************/
18 //////////////////////////////////////////////////////////////////////////
20 // Class AnalysisTaskAliPtMothFromPtDaugh //
21 // AnalysisTaskSE used for the reconstruction of mothers particles //
22 // spectra (pT and pTMin) starting from the pT-spectra of //
23 // daughters particles. //
25 // Authors: Giuseppe Bruno & Fiorella Fionda //
27 //////////////////////////////////////////////////////////////////////////
31 #include "AliAnalysisManager.h"
32 #include "AliMCEventHandler.h"
33 #include "AliMCEvent.h"
39 #include "AliAnalysisTaskPtMothFromPtDaugh.h"
40 #include "AliPtMothFromPtDaugh.h"
41 #include "AliAnalysisTaskSE.h"
43 ClassImp(AliAnalysisTaskPtMothFromPtDaugh)
45 //_________________________________________________________________________________
46 AliAnalysisTaskPtMothFromPtDaugh::AliAnalysisTaskPtMothFromPtDaugh() :
50 fReadKineFromNtupla(0),
55 // Default Constructor
57 AliInfo("Default Constructor!\n");
60 //_________________________________________________________________________________
61 AliAnalysisTaskPtMothFromPtDaugh::AliAnalysisTaskPtMothFromPtDaugh(Bool_t IsNtuplaCreated) :
62 AliAnalysisTaskSE("TaskAliPtMothFromDaugh"),
65 fReadKineFromNtupla(IsNtuplaCreated),
70 // Basic AnalysisTaskSE Constructor
71 // Basic input of the analysis: TChain of galice.root files (optional)
72 // Basic ouput: TList of mothers histograms (pT and pTMin) (standard)
73 // TNtupla with kinematics informations of mothers
74 // and daughters (optional)
75 // If Ntupla already exists loop on kinematics is not needed
76 // therefore input is not defined
79 DefineInput(0,TChain::Class()); DefineOutput(2,TNtuple::Class());}
80 else {AliInfo("Ntupla is already created! Loop on events is skipped!\n");}
81 DefineOutput(1,TList::Class());
84 //___________________________________________________________________________________
85 AliAnalysisTaskPtMothFromPtDaugh::~AliAnalysisTaskPtMothFromPtDaugh()
91 { delete fPtMothDaugh; fPtMothDaugh=0;}
93 { delete fDecayKine; fDecayKine=0;}
95 { delete fFileNtuplaName; fFileNtuplaName=0;}
97 { delete fList; fList = 0; }
102 //_________________________________________________________________________________
103 void AliAnalysisTaskPtMothFromPtDaugh::UserCreateOutputObjects()
106 // Initialise the framework objects
109 // Initialise the framework objects. OutPut objects created are:
110 // 1) TList with mothers histograms
111 // 2) TNtuple with kinematics informations of mothers and daughters (optional)
115 if(fReadKineFromNtupla) return;
117 if(!AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()) {
118 Fatal("UserCreateOutputObjects", "This task needs a MC handler");
121 fDecayKine=new TNtuple("DecayKine","Decay kinematics","pdgM:pxM:pyM:pzM:yM:etaM:pdgD:pxD:pyD:pzD:yD:etaD");
125 //_________________________________________________________________________________
126 void AliAnalysisTaskPtMothFromPtDaugh::UserExec(Option_t */*option*/)
129 // Main loop. Called for every event
130 // This loop fill a TNtuple with kinematics informations for
131 // mother and daughter particles. TNtupla contains:
145 AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
146 if(!mcHandler) {AliError("Could not get MC event handler!"); return; }
147 mcHandler->SetReadTR(kFALSE);
148 AliMCEvent* mcEvent = mcHandler->MCEvent();
149 if(!mcEvent){ AliError("Could not get MC event!"); return; }
150 AliStack* stack = mcEvent->Stack();
151 if(!stack){ AliError("Could not get stack!"); return; }
152 Int_t nPrims = stack->GetNprimary();
153 float *inf = new float[12];
154 for (Int_t iTrack = 0; iTrack < nPrims; ++iTrack) {
155 TParticle *part = stack->Particle(iTrack);
156 Int_t pdg=TMath::Abs(part->GetPdgCode());
158 //check if particle is in mothers list
160 if(fPtMothDaugh->IsMothers(pdg))
162 //check if mother particle has a selected daugh
163 if(!fPtMothDaugh->IsSelectedDaugh(part,labelDaugh,stack)) continue;
164 TParticle *pDaugh=stack->Particle(labelDaugh);
165 fPtMothDaugh->Rapidity(part,y);
166 fPtMothDaugh->Rapidity(pDaugh,y2);
168 inf[0]=part->GetPdgCode();
174 inf[6]=pDaugh->GetPdgCode();
179 inf[11]=pDaugh->Eta();
180 fDecayKine->Fill(inf);
181 } //close if statement for mothers particles
182 } //end of tracks loop
183 PostData(2,fDecayKine);
189 //___________________________________________________________________________________
190 void AliAnalysisTaskPtMothFromPtDaugh::Terminate(Option_t */*option*/)
193 // Terminate method called at the end of the events loop.
194 // Get the Ntupla with kineamtics informations after the
195 // events loop or read it from the file fFileNtuplaName
196 // if the Ntupla is already created. Then use it to
197 // evaluate pT and pTMin spectra for mothers by means
198 // of the method implemented in AliPtMothFromPtDaugh
200 if(fReadKineFromNtupla) fDecayKine = ReadNtuplaFromFile(fFileNtuplaName);
202 fDecayKine = dynamic_cast<TNtuple*>(GetOutputData(2));
203 fList = dynamic_cast<TList*>(GetOutputData(1));
205 if(!fDecayKine) { AliInfo("TNtupla not available!\n"); return; }
206 if(!fList) { AliInfo("TList not availble!\n"); return; }
207 fPtMothDaugh->SetDecayNtupla(fDecayKine);
208 fPtMothDaugh->EvaluatePtMoth();
209 TH1F *fHistoPt = (TH1F*)fPtMothDaugh->GetHistoPtMother()->Clone();
210 TH1F *fHistoPtMin = (TH1F*)fPtMothDaugh->GetHistoPtMinMother()->Clone();
211 fList->Add(fHistoPt);
212 fList->Add(fHistoPtMin);
217 //___________________________________________________________________________________
218 TNtuple *AliAnalysisTaskPtMothFromPtDaugh::ReadNtuplaFromFile(char *inFileName)
221 // Get Ntupla from the file inFileName
222 // after the it is created.
223 // Input: name of the file - Output: TNtupla
225 TFile *f = new TFile(inFileName,"READ");
226 if(!f) {AliError(Form("File %s with TNtupla doesn't exist!",inFileName)); return 0x0;}
227 TNtuple *DecayKine=(TNtuple*)f->Get("DecayKine");
228 if(!DecayKine) { AliError("The TNtupla doesn't exist!\n"); return 0x0;}