AliPhysics  b0c77bb (b0c77bb)
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 //_______________________________________________________________________________
72 fFilteredTracksArray(0x0),
73 fFilteredTracksName("mytracks"),
74 fInputTracksName("tracks"),
75 fFilterType(1),
76 fAodEvent(0x0),
77 fMCHeader(0x0),
78 fMCPartArray(0x0)
79 {
80  //constructor
81 }
82 //_______________________________________________________________________________
84 {
85  //destructor
86 }
87 //_______________________________________________________________________________
89  //dummy
90  return;
91 }
92 //_______________________________________________________________________________
94 {
95 
96  //
97  // To be executed only once, for the first event
98  //
99 
100  AliDebug(2, "Entering ExecOnce()");
101 
102  // Load the event
103  fAodEvent = dynamic_cast<AliAODEvent*>(fInputEvent);
104 
105  if(!fAodEvent){
106  if (AODEvent() && IsStandardAOD()) {
107 
108  // In case there is an AOD handler writing a standard AOD, use the AOD
109  // event in memory rather than the input (ESD) event.
110  fAodEvent = dynamic_cast<AliAODEvent*>(AODEvent());
111  }
112  }
113 
114  fMCPartArray = dynamic_cast<TClonesArray*>(fAodEvent->FindListObject(AliAODMCParticle::StdBranchName()));
115  if(!fMCPartArray) {
116  AliError(Form("MC particles not found! Task '%s' will be disabled!", GetName()));
117  return;
118  }
119 
120  fMCHeader = (AliAODMCHeader*)fAodEvent->GetList()->FindObject(AliAODMCHeader::StdBranchName());
121  if(!fMCHeader) {
122  AliError(Form("MC header not found! Task '%s' will be disabled!", GetName()));
123  return;
124  }
125 
126  // add the filtered tracks to event if not yet there
127  if (!(InputEvent()->FindListObject(fFilteredTracksName))) {
128  if(fFilterType){
129  fFilteredTracksArray = new TClonesArray("AliAODTrack");
130  }else{
131  fFilteredTracksArray = new TClonesArray("AliAODMCParticle");
132  }
134  ::Info("AliAnalysisTaskSVtaskMCFilter::ExecOnce", "track collection with name '%s' has been added to the event.", fFilteredTracksName.Data());
135  InputEvent()->AddObject(fFilteredTracksArray);
136  }else{
137  AliError(Form("%s: Object with name %s already in event! Returning", GetName(), fFilteredTracksName.Data()));
138  return;
139  }
140 
142 }
143 
144 //_______________________________________________________________________________
146 {
147 
148  //
149  // Analysis execution
150  //
151 
152  //fFilteredTracksArray->Delete();
153  fFilteredTracksArray->Clear();
154 
155  // fix for temporary bug in ESDfilter
156  // the AODs with null vertex pointer didn't pass the PhysSel
157  if (!fAodEvent->GetPrimaryVertex() || TMath::Abs(fAodEvent->GetMagneticField()) < 0.001) return kFALSE;
158 
159  TString nameGen;
160  Int_t lab, mother;
161  AliAODMCParticle *mcpart = NULL;
162  Int_t n = fFilteredTracksArray->GetEntriesFast();
163 
164  if (fFilterType) { //detector level tracks
165  AliAODTrack* track = 0;
166  AliTrackContainer * tracks = dynamic_cast<AliTrackContainer *>(GetParticleContainer(fInputTracksName.Data()));
167  // Iterable approach (using C++11) loop over detector level tracks
168  for(auto trackIterator : tracks->accepted_momentum()){
169 
170  track = dynamic_cast<AliAODTrack *>(trackIterator.second); // Get the full track
171  if(track){
172  lab = TMath::Abs(track->GetLabel());
174 
175  while(nameGen.IsWhitespace()){ //if this particle does not have any generator name execute this loop
176  mcpart = (AliAODMCParticle*) fMCPartArray->At(lab); //find the corresponding MC particle
177  if(!mcpart){
178  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: No valid AliAODMCParticle at label %i\n",lab);
179  break;
180  }
181  mother = mcpart->GetMother(); //find the index of the corresponding mother
182  if(mother<0){ //the mother does not exist
183  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: Reached primary particle without valid mother\n");
184  break;
185  }
186  lab = mother; // change label to the mother
187  nameGen = AliVertexingHFUtils::GetGenerator(mother,fMCHeader); //change the name of generator to mother
188  }
189  if(!(nameGen.IsWhitespace() || nameGen.Contains("EPOS"))){
190  new ((*fFilteredTracksArray)[n]) AliAODTrack(*track);
191  n++;
192  }
193  }
194  }
195  }else{ //particle level particles
196  AliAODMCParticle* mcParticle = NULL;
197  AliAODMCParticle* initialmcParticle = NULL;
199 
200  Int_t index=0;
201 
202  // Iterable approach (using C++11) loop over detector level mcParticle
203  for(auto trackIterator : mcParticles->all_momentum()){
204  initialmcParticle = dynamic_cast<AliAODMCParticle*>(trackIterator.second); // Get the full track
205  if(initialmcParticle){
206  lab = index;//TMath::Abs(initialmcParticle->GetLabel());
208 
209  while(nameGen.IsWhitespace()){ //if this particle does not have any generator name execute this loop
210  mcParticle = (AliAODMCParticle*) fMCPartArray->At(lab); //find the corresponding MC particle
211  if(!mcParticle){
212  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: No valid AliAODMCParticle at label %i\n",lab);
213  break;
214  }
215 
216  mother = mcParticle->GetMother(); //find the index of the corresponding mother
217  if(mother<0){ //the mother does not exist
218  printf("AliAnalysisTaskMultCheck::IsTrackInjected - BREAK: Reached primary particle without valid mother\n");
219  break;
220  }
221  lab = mother; // change label to the mother
222  nameGen = AliVertexingHFUtils::GetGenerator(mother,fMCHeader); //change the name of generator to mother
223  }
224 
225  if(!(nameGen.IsWhitespace() || nameGen.Contains("EPOS"))){
226  new ((*fFilteredTracksArray)[n]) AliAODMCParticle(*initialmcParticle);
227  n++;
228  }
229  }
230  index++;
231  }
232  }
233 
234 
235  return kTRUE;
236 }
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.
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.