]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/base/AliAnalysisTaskPtMothFromPtDaugh.cxx
Remove files committed by mistake
[u/mrichter/AliRoot.git] / PWG3 / base / AliAnalysisTaskPtMothFromPtDaugh.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 //                                                                      //
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.                                               //
21 //                                                                      //
22 //             Authors: Giuseppe Bruno & Fiorella Fionda                //
23 //                                                                      //
24 //////////////////////////////////////////////////////////////////////////
25
26 #include <TChain.h>
27
28 #include "AliAnalysisManager.h"
29 #include "AliMCEventHandler.h"
30 #include "AliMCEvent.h"
31 #include "AliStack.h"
32 #include "TNtuple.h"
33 #include "TH1F.h"
34 #include "TFile.h"
35 #include "AliLog.h"
36 #include "AliAnalysisTaskPtMothFromPtDaugh.h"
37 #include "AliPtMothFromPtDaugh.h"
38 #include "AliAnalysisTaskSE.h"
39
40 ClassImp(AliAnalysisTaskPtMothFromPtDaugh)
41
42 //_________________________________________________________________________________
43 AliAnalysisTaskPtMothFromPtDaugh::AliAnalysisTaskPtMothFromPtDaugh() :
44   AliAnalysisTaskSE(),
45   fPtMothDaugh(0),
46   fDecayKine(0),
47   fReadKineFromNtupla(0),
48   fFileNtuplaName(0),
49   fList(0)
50 {
51   //
52   // Default Constructor
53   //
54   AliInfo("Default Constructor!\n");  
55 }
56
57 //_________________________________________________________________________________
58 AliAnalysisTaskPtMothFromPtDaugh::AliAnalysisTaskPtMothFromPtDaugh(Bool_t IsNtuplaCreated) :
59   AliAnalysisTaskSE("TaskAliPtMothFromDaugh"),
60   fPtMothDaugh(0),
61   fDecayKine(0),
62   fReadKineFromNtupla(IsNtuplaCreated),
63   fFileNtuplaName(0),
64   fList(0)
65 {
66     //
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
74     //
75     if(!IsNtuplaCreated){
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());
79 }
80
81 //___________________________________________________________________________________
82 AliAnalysisTaskPtMothFromPtDaugh::~AliAnalysisTaskPtMothFromPtDaugh()
83    {
84     //
85     // Destructor
86     //
87     if(fPtMothDaugh)
88      { delete fPtMothDaugh; fPtMothDaugh=0;}
89     if(fDecayKine)
90      { delete fDecayKine; fDecayKine=0;}
91     if(fFileNtuplaName)
92      { delete fFileNtuplaName; fFileNtuplaName=0;}
93     if (fList)
94      { delete fList; fList = 0; }
95    }
96
97
98
99 //_________________________________________________________________________________
100 void AliAnalysisTaskPtMothFromPtDaugh::UserCreateOutputObjects()
101 {
102   //
103   // Initialise the framework objects
104   //
105    //
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)  
109     //
110     fList = new TList();
111     fList->SetOwner();
112     if(fReadKineFromNtupla) return;
113
114     if(!AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()) {
115      Fatal("UserCreateOutputObjects", "This task needs a MC handler");
116      return;
117      }
118     fDecayKine=new TNtuple("DecayKine","Decay kinematics","pdgM:pxM:pyM:pzM:yM:etaM:pdgD:pxD:pyD:pzD:yD:etaD");
119     return;
120 }
121
122 //_________________________________________________________________________________
123 void AliAnalysisTaskPtMothFromPtDaugh::UserExec(Option_t */*option*/)
124 {
125     //
126     // Main loop. Called for every event
127     // This loop fill a TNtuple with kinematics informations for 
128     // mother and daughter particles. TNtupla contains:  
129     //                   pdg of Mothers
130     //                    px      "
131     //                    py      "
132     //                    pz      "
133     //                  rapidity  "
134     //                   eta      "
135     //                   pdg of Daughter
136     //                    px      "
137     //                    py      "
138     //                    pz      "
139     //                  rapidity  "
140     //                   eta      "         
141     //
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());
154     Double_t y,y2;
155     //check if particle is in mothers list
156     Int_t labelDaugh;
157     if(fPtMothDaugh->IsMothers(pdg))
158            {
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);
164
165            inf[0]=part->GetPdgCode();
166            inf[1]=part->Px();
167            inf[2]=part->Py();
168            inf[3]=part->Pz();
169            inf[4]=y;
170            inf[5]=part->Eta();
171            inf[6]=pDaugh->GetPdgCode();
172            inf[7]=pDaugh->Px();
173            inf[8]=pDaugh->Py();
174            inf[9]=pDaugh->Pz();
175            inf[10]=y2;
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);
181     PostData(1,fList);
182     return;
183 }
184
185 //___________________________________________________________________________________
186 void AliAnalysisTaskPtMothFromPtDaugh::Terminate(Option_t */*option*/)
187    {
188     //
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
195     //
196     if(fReadKineFromNtupla) fDecayKine = ReadNtuplaFromFile(fFileNtuplaName);
197     else{ 
198          fDecayKine = dynamic_cast<TNtuple*>(GetOutputData(2));
199          fList = dynamic_cast<TList*>(GetOutputData(1));
200         }
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);
209     PostData(1,fList);
210     return;
211    }
212
213 //___________________________________________________________________________________
214 TNtuple *AliAnalysisTaskPtMothFromPtDaugh::ReadNtuplaFromFile(char *inFileName)
215    {
216     // 
217     // Get Ntupla from the file inFileName
218     // after the it is created. 
219     // Input: name of the file - Output: TNtupla
220     //
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;}
225     return DecayKine;
226    }