AliPhysics  608b256 (608b256)
AliAnalysisTaskSVtaskMCFilter.cxx
Go to the documentation of this file.
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 // Task for filtering out EPOS part of the simulated detector level events
18 //
19 //-----------------------------------------------------------------------
20 // Authors: Filip Krizek
21 
22 //-----------------------------------------------------------------------
23 
24 #include <TDatabasePDG.h>
25 #include <TParticle.h>
26 #include <TVector3.h>
27 #include <TList.h>
28 #include <TROOT.h>
29 #include <TH3F.h>
30 #include <TRandom3.h>
31 
32 #include "AliLog.h"
33 #include "AliAODMCHeader.h"
34 #include "AliAODHandler.h"
35 #include "AliAnalysisManager.h"
36 #include "AliLog.h"
37 #include "AliAODVertex.h"
38 #include "AliAODRecoCascadeHF.h"
40 #include "AliESDtrack.h"
41 #include "AliAODTrack.h"
42 #include "AliAODMCParticle.h"
43 #include "AliEmcalParticle.h"
44 #include "AliParticleContainer.h"
45 #include "AliTrackContainer.h"
46 #include "AliAnalysisDataSlot.h"
47 #include "AliAnalysisDataContainer.h"
48 #include "AliStack.h"
49 #include "AliAnalysisVertexingHF.h"
50 #include "AliVertexingHFUtils.h"
53 
55 
56 
58 fFilteredTracksArray(0x0),
59 fFilteredTracksName("mytracks"),
60 fInputTracksName("tracks"),
61 fFilterType(1),
62 fAodEvent(0x0),
63 fMCHeader(0x0),
64 fMCPartArray(0x0)
65 {
66  //constructor
67 
68 
69 }
70 //_______________________________________________________________________________
73 fFilteredTracksArray(0x0),
74 fFilteredTracksName("mytracks"),
75 fInputTracksName("tracks"),
76 fFilterType(1),
77 fAodEvent(0x0),
78 fMCHeader(0x0),
79 fMCPartArray(0x0)
80 {
81  //constructor
82 }
83 //_______________________________________________________________________________
85 {
86  //destructor
87 }
88 //_______________________________________________________________________________
90  //dummy
91  return;
92 }
93 //_______________________________________________________________________________
95 {
96 
97  //
98  // To be executed only once, for the first event
99  //
100 
101  AliDebug(2, "Entering ExecOnce()");
102 
103  // Load the event
104  fAodEvent = dynamic_cast<AliAODEvent*>(fInputEvent);
105 
106  if(!fAodEvent){
107  if (AODEvent() && IsStandardAOD()) {
108 
109  // In case there is an AOD handler writing a standard AOD, use the AOD
110  // event in memory rather than the input (ESD) event.
111  fAodEvent = dynamic_cast<AliAODEvent*>(AODEvent());
112  }
113  }
114 
115  fMCPartArray = dynamic_cast<TClonesArray*>(fAodEvent->FindListObject(AliAODMCParticle::StdBranchName()));
116  if(!fMCPartArray) {
117  AliError(Form("MC particles not found! Task '%s' will be disabled!", GetName()));
118  return;
119  }
120 
121  fMCHeader = (AliAODMCHeader*)fAodEvent->GetList()->FindObject(AliAODMCHeader::StdBranchName());
122  if(!fMCHeader) {
123  AliError(Form("MC header not found! Task '%s' will be disabled!", GetName()));
124  return;
125  }
126 
127  // add the filtered tracks to event if not yet there
128  if (!(InputEvent()->FindListObject(fFilteredTracksName))) {
129  if(fFilterType){
130  fFilteredTracksArray = new TClonesArray("AliAODTrack");
131  }else{
132  fFilteredTracksArray = new TClonesArray("AliAODMCParticle");
133  }
135  ::Info("AliAnalysisTaskSVtaskMCFilter::ExecOnce", "track collection with name '%s' has been added to the event.", fFilteredTracksName.Data());
136  InputEvent()->AddObject(fFilteredTracksArray);
137  }else{
138  AliError(Form("%s: Object with name %s already in event! Returning", GetName(), fFilteredTracksName.Data()));
139  return;
140  }
141 
143 }
144 
145 //_______________________________________________________________________________
147 {
148 
149  //
150  // Analysis execution
151  //
152 
153  //fFilteredTracksArray->Delete();
154  fFilteredTracksArray->Clear();
155 
156  // fix for temporary bug in ESDfilter
157  // the AODs with null vertex pointer didn't pass the PhysSel
158  if (!fAodEvent->GetPrimaryVertex() || TMath::Abs(fAodEvent->GetMagneticField()) < 0.001) return kFALSE;
159 
160  TString nameGen;
161  Int_t lab, mother;
162  AliAODMCParticle *mcpart = NULL;
163  Int_t n = fFilteredTracksArray->GetEntriesFast();
164 
165  if (fFilterType) { //detector level tracks
166  AliAODTrack* track = 0;
167  AliTrackContainer * tracks = dynamic_cast<AliTrackContainer *>(GetParticleContainer(fInputTracksName.Data()));
168  // Iterable approach (using C++11) loop over detector level tracks
169  for(auto trackIterator : tracks->accepted_momentum()){
170 
171  track = dynamic_cast<AliAODTrack *>(trackIterator.second); // Get the full track
172  if(track){
173  lab = TMath::Abs(track->GetLabel());
175 
176  while(nameGen.IsWhitespace()){ //if this particle does not have any generator name execute this loop
177  mcpart = (AliAODMCParticle*) fMCPartArray->At(lab); //find the corresponding MC particle
178  if(!mcpart){
179  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: No valid AliAODMCParticle at label %i\n",lab);
180  break;
181  }
182  mother = mcpart->GetMother(); //find the index of the corresponding mother
183  if(mother<0){ //the mother does not exist
184  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: Reached primary particle without valid mother\n");
185  break;
186  }
187  lab = mother; // change label to the mother
188  nameGen = AliVertexingHFUtils::GetGenerator(mother,fMCHeader); //change the name of generator to mother
189  }
190  if(!(nameGen.IsWhitespace() || nameGen.Contains("EPOS"))){
191  new ((*fFilteredTracksArray)[n]) AliAODTrack(*track);
192  n++;
193  }
194  }
195  }
196  }else{ //particle level particles
197  AliAODMCParticle* mcParticle = NULL;
198  AliAODMCParticle* initialmcParticle = NULL;
200 
201  Int_t index=0;
202 
203  // Iterable approach (using C++11) loop over detector level mcParticle
204  for(auto trackIterator : mcParticles->all_momentum()){
205  initialmcParticle = dynamic_cast<AliAODMCParticle*>(trackIterator.second); // Get the full track
206  if(initialmcParticle){
207  lab = index;//TMath::Abs(initialmcParticle->GetLabel());
209 
210  while(nameGen.IsWhitespace()){ //if this particle does not have any generator name execute this loop
211  mcParticle = (AliAODMCParticle*) fMCPartArray->At(lab); //find the corresponding MC particle
212  if(!mcParticle){
213  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: No valid AliAODMCParticle at label %i\n",lab);
214  break;
215  }
216 
217  mother = mcParticle->GetMother(); //find the index of the corresponding mother
218  if(mother<0){ //the mother does not exist
219  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: Reached primary particle without valid mother\n");
220  break;
221  }
222  lab = mother; // change label to the mother
223  nameGen = AliVertexingHFUtils::GetGenerator(mother,fMCHeader); //change the name of generator to mother
224  }
225 
226  if(!(nameGen.IsWhitespace() || nameGen.Contains("EPOS"))){
227  new ((*fFilteredTracksArray)[n]) AliAODMCParticle(*initialmcParticle);
228  n++;
229  }
230  }
231  index++;
232  }
233  }
234 
235 
236  return kTRUE;
237 }
Bool_t Run()
Run function. This is the core function of the analysis and contains the user code. Therefore users have to implement this function.
Base task in the EMCAL framework.
Container with name, TClonesArray and cuts for particles.
static TString GetGenerator(Int_t label, AliAODMCHeader *header)
AliParticleContainer * GetParticleContainer(Int_t i=0) const
Get particle container attached to this task.
int Int_t
Definition: External.C:63
TString fFilteredTracksName
output PYTHIA only tracks
const AliMCParticleIterableMomentumContainer all_momentum() const
AliMCParticleContainer * GetMCParticleContainer(Int_t i=0) const
virtual void ExecOnce()
Perform steps needed to initialize the analysis.
const AliTrackIterableMomentumContainer accepted_momentum() const
bool Bool_t
Definition: External.C:53
Container for MC-true particles within the EMCAL framework.
void ExecOnce()
Perform steps needed to initialize the analysis.