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 **************************************************************************/
15 //////////////////////////////////////////////////////////////////////////
17 // Class AnalysisTaskAliPtMothFromPtDaugh //
18 // AnalysisTaskSE used for the reconstruction of mothers particles //
19 // spectra (pT and pTMin) starting from the pT-spectra of //
20 // daughters particles. //
22 // Authors: Giuseppe Bruno & Fiorella Fionda //
24 //////////////////////////////////////////////////////////////////////////
28 #include "AliAnalysisManager.h"
29 #include "AliMCEventHandler.h"
30 #include "AliMCEvent.h"
36 #include "AliAnalysisTaskPtMothFromPtDaugh.h"
37 #include "AliPtMothFromPtDaugh.h"
38 #include "AliAnalysisTaskSE.h"
40 ClassImp(AliAnalysisTaskPtMothFromPtDaugh)
42 //_________________________________________________________________________________
43 AliAnalysisTaskPtMothFromPtDaugh::AliAnalysisTaskPtMothFromPtDaugh() :
47 fReadKineFromNtupla(0),
52 // Default Constructor
54 AliInfo("Default Constructor!\n");
57 //_________________________________________________________________________________
58 AliAnalysisTaskPtMothFromPtDaugh::AliAnalysisTaskPtMothFromPtDaugh(Bool_t IsNtuplaCreated) :
59 AliAnalysisTaskSE("TaskAliPtMothFromDaugh"),
62 fReadKineFromNtupla(IsNtuplaCreated),
67 // Basic AnalysisTaskSE Constructor
68 // Basic input of the analysis: TChain of galice.root files (optional)
69 // Basic ouput: TList of mothers histograms (pT and pTMin) (standard)
70 // TNtupla with kinematics informations of mothers
71 // and daughters (optional)
72 // If Ntupla already exists loop on kinematics is not needed
73 // therefore input is not defined
76 DefineInput(0,TChain::Class()); DefineOutput(2,TNtuple::Class());}
77 else {AliInfo("Ntupla is already created! Loop on events is skipped!\n");}
78 DefineOutput(1,TList::Class());
81 //___________________________________________________________________________________
82 AliAnalysisTaskPtMothFromPtDaugh::~AliAnalysisTaskPtMothFromPtDaugh()
88 { delete fPtMothDaugh; fPtMothDaugh=0;}
90 { delete fDecayKine; fDecayKine=0;}
92 { delete fFileNtuplaName; fFileNtuplaName=0;}
94 { delete fList; fList = 0; }
99 //_________________________________________________________________________________
100 void AliAnalysisTaskPtMothFromPtDaugh::UserCreateOutputObjects()
103 // Initialise the framework objects
106 // Initialise the framework objects. OutPut objects created are:
107 // 1) TList with mothers histograms
108 // 2) TNtuple with kinematics informations of mothers and daughters (optional)
112 if(fReadKineFromNtupla) return;
114 if(!AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()) {
115 Fatal("UserCreateOutputObjects", "This task needs a MC handler");
118 fDecayKine=new TNtuple("DecayKine","Decay kinematics","pdgM:pxM:pyM:pzM:yM:etaM:pdgD:pxD:pyD:pzD:yD:etaD");
122 //_________________________________________________________________________________
123 void AliAnalysisTaskPtMothFromPtDaugh::UserExec(Option_t */*option*/)
126 // Main loop. Called for every event
127 // This loop fill a TNtuple with kinematics informations for
128 // mother and daughter particles. TNtupla contains:
142 AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
143 if(!mcHandler) {AliError("Could not get MC event handler!"); return; }
144 mcHandler->SetReadTR(kFALSE);
145 AliMCEvent* mcEvent = mcHandler->MCEvent();
146 if(!mcEvent){ AliError("Could not get MC event!"); return; }
147 AliStack* stack = mcEvent->Stack();
148 if(!stack){ AliError("Could not get stack!"); return; }
149 Int_t nPrims = stack->GetNprimary();
150 float *inf = new float[12];
151 for (Int_t iTrack = 0; iTrack < nPrims; ++iTrack) {
152 TParticle *part = stack->Particle(iTrack);
153 Int_t pdg=TMath::Abs(part->GetPdgCode());
155 //check if particle is in mothers list
157 if(fPtMothDaugh->IsMothers(pdg))
159 //check if mother particle has a selected daugh
160 if(!fPtMothDaugh->IsSelectedDaugh(part,labelDaugh,stack)) continue;
161 TParticle *pDaugh=stack->Particle(labelDaugh);
162 fPtMothDaugh->Rapidity(part,y);
163 fPtMothDaugh->Rapidity(pDaugh,y2);
165 inf[0]=part->GetPdgCode();
171 inf[6]=pDaugh->GetPdgCode();
176 inf[11]=pDaugh->Eta();
177 fDecayKine->Fill(inf);
178 } //close if statement for mothers particles
179 } //end of tracks loop
180 PostData(2,fDecayKine);
185 //___________________________________________________________________________________
186 void AliAnalysisTaskPtMothFromPtDaugh::Terminate(Option_t */*option*/)
189 // Terminate method called at the end of the events loop.
190 // Get the Ntupla with kineamtics informations after the
191 // events loop or read it from the file fFileNtuplaName
192 // if the Ntupla is already created. Then use it to
193 // evaluate pT and pTMin spectra for mothers by means
194 // of the method implemented in AliPtMothFromPtDaugh
196 if(fReadKineFromNtupla) fDecayKine = ReadNtuplaFromFile(fFileNtuplaName);
198 fDecayKine = dynamic_cast<TNtuple*>(GetOutputData(2));
199 fList = dynamic_cast<TList*>(GetOutputData(1));
201 if(!fDecayKine) { AliInfo("TNtupla not available!\n"); return; }
202 if(!fList) { AliInfo("TList not availble!\n"); return; }
203 fPtMothDaugh->SetDecayNtupla(fDecayKine);
204 fPtMothDaugh->EvaluatePtMoth();
205 TH1F *fHistoPt = (TH1F*)fPtMothDaugh->GetHistoPtMother()->Clone();
206 TH1F *fHistoPtMin = (TH1F*)fPtMothDaugh->GetHistoPtMinMother()->Clone();
207 fList->Add(fHistoPt);
208 fList->Add(fHistoPtMin);
213 //___________________________________________________________________________________
214 TNtuple *AliAnalysisTaskPtMothFromPtDaugh::ReadNtuplaFromFile(char *inFileName)
217 // Get Ntupla from the file inFileName
218 // after the it is created.
219 // Input: name of the file - Output: TNtupla
221 TFile *f = new TFile(inFileName,"READ");
222 if(!f) {AliError(Form("File %s with TNtupla doesn't exist!",inFileName)); return 0x0;}
223 TNtuple *DecayKine=(TNtuple*)f->Get("DecayKine");
224 if(!DecayKine) { AliError("The TNtupla doesn't exist!\n"); return 0x0;}