]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/STRANGENESS/Hypernuclei/AliAnalysisTaskESDNuclExFilterMC.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / Hypernuclei / AliAnalysisTaskESDNuclExFilterMC.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 // Create a new AOD starting from the general AOD. This Task can be used also strating 
18 //from ESD changing the input handler. (Method to be testeted on the grid)
19 // filtering of the ESD. 
20 //
21 // Authors: S. Bufalino (stefania.bufalino@cern.ch)
22 //          R. Lea      (ramona.lea@cern.ch)
23 // Based on AliAnalysisTaskESDMuonFilter.cxx  
24 //
25 // (see AddFilteredAOD method)
26 //
27
28 #include "AliAnalysisTaskESDNuclExFilterMC.h"
29
30 #include "AliAODEvent.h"
31 #include "AliAODHandler.h"
32 #include "AliAODExtension.h"
33 #include "AliAODMCParticle.h"
34 #include "AliAODMCNuclExReplicator.h"
35 #include "AliAODVertex.h"
36 #include "AliAnalysisFilter.h"
37 #include "AliAnalysisManager.h"
38 #include "AliCodeTimer.h"
39 #include "AliESDEvent.h"
40 #include "AliESDInputHandler.h"
41 #include "AliESDMuonTrack.h"
42 #include "AliESDVertex.h"
43 #include "AliESDtrack.h"
44 #include "AliLog.h"
45 #include "AliMCEvent.h"
46 #include "AliMCEventHandler.h"
47 #include "AliMultiplicity.h"
48 #include <TChain.h>
49 #include <TFile.h>
50 #include <TParticle.h>
51 #include "AliESDtrackCuts.h"
52 #include "AliAODTrack.h"
53 #include "AliAODPid.h"
54 #include "TF1.h"
55 //#include "AliPIDResponse.h"
56
57 using std::cout;
58 using std::endl;
59 ClassImp(AliAnalysisTaskESDNuclExFilterMC)
60
61 ////////////////////////////////////////////////////////////////////////
62
63 AliAnalysisTaskESDNuclExFilterMC::AliAnalysisTaskESDNuclExFilterMC(Bool_t onlyMuon, Bool_t keepAllEvents, Int_t mcMode, Int_t nsigmaTrk1,Int_t nsigmaTrk2, Int_t partType1,Int_t partType2):
64   AliAnalysisTaskSE(),
65   fTrackFilter(0x0),
66   fEnableMuonAOD(kTRUE),
67   fEnableDimuonAOD(kTRUE),
68   fOnlyMuon(onlyMuon),
69   fKeepAllEvents(keepAllEvents),
70   fMCMode(mcMode),
71   fnSigmaTrk1(nsigmaTrk1),
72   fnSigmaTrk2(nsigmaTrk2),
73   fpartType1(partType1),
74   fpartType2(partType2),
75   murep(0x0)
76 {
77   // Default constructor
78 }
79
80 AliAnalysisTaskESDNuclExFilterMC::AliAnalysisTaskESDNuclExFilterMC(const char* name, Bool_t onlyMuon, Bool_t keepAllEvents, Int_t mcMode, Int_t nsigmaTrk1,Int_t nsigmaTrk2, Int_t partType1,Int_t partType2):
81   AliAnalysisTaskSE(name),
82   fTrackFilter(0x0),
83   fEnableMuonAOD(kTRUE),
84   fEnableDimuonAOD(kTRUE),
85   fOnlyMuon(onlyMuon),
86   fKeepAllEvents(keepAllEvents),
87   fMCMode(mcMode),
88   fnSigmaTrk1(nsigmaTrk1),
89   fnSigmaTrk2(nsigmaTrk2),
90   fpartType1(partType1),
91   fpartType2(partType2),
92   murep(0x0)
93   
94 {
95   // Constructor
96 }
97
98 //______________________________________________________________________________
99 void AliAnalysisTaskESDNuclExFilterMC::UserCreateOutputObjects()
100 {
101   
102   // Create the output container
103   if (fTrackFilter) OutputTree()->GetUserInfo()->Add(fTrackFilter);
104
105 }
106
107 //______________________________________________________________________________
108 void AliAnalysisTaskESDNuclExFilterMC::PrintTask(Option_t *option, Int_t indent) const
109 {
110   // Specify how we are configured
111   
112   AliAnalysisTaskSE::PrintTask(option,indent);
113   
114   TString spaces(' ',indent+3);
115   
116   if ( fOnlyMuon ) 
117     {
118       cout << spaces.Data() << "Keep only muon information " << endl;        
119     }
120   else 
121     {
122       cout << spaces.Data() << "Keep all information from standard AOD" << endl;
123     }
124   
125   if ( fKeepAllEvents ) 
126     {
127       cout << spaces.Data() << "Keep all events, regardless of number of muons" << endl;    
128     }
129   else 
130     {
131       cout << spaces.Data() << "Keep only events with at least one muon" << endl;
132     }
133   
134   if ( fMCMode > 0 ) 
135     {
136       cout << spaces.Data() << "Assuming work on MC data (i.e. will transmit MC branches)" << endl;
137     }
138 }
139
140 //______________________________________________________________________________
141 void AliAnalysisTaskESDNuclExFilterMC::AddFilteredAOD(const char* aodfilename, const char* title, Bool_t toMerge)
142 {
143   
144   //cout<<"Entro ne ADDFILTETEDAOD"<<endl;
145
146   AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
147   if (!aodH) Fatal("UserCreateOutputObjects", "No AOD handler");
148
149   if(aodH){
150
151     AliAODExtension* ext = aodH->AddFilteredAOD(aodfilename,title,toMerge);
152     
153     if (!ext) return;
154     
155     if ( fOnlyMuon ) 
156       {    
157         
158         if(!murep)delete murep;
159         
160         murep = new AliAODMCNuclExReplicator("NuclExReplicator",
161                                              "remove non interesting tracks",
162                                              fMCMode,fnSigmaTrk1,fnSigmaTrk2,fpartType1,fpartType2);
163         
164         
165         ext->DropUnspecifiedBranches(); // all branches not part of a FilterBranch call (below) will be dropped
166         
167         ext->FilterBranch("header",murep);    
168         ext->FilterBranch("vertices",murep);    
169         ext->FilterBranch("nuclei",murep);  
170         ext->FilterBranch("secvertices",murep); //per test
171         ext->FilterBranch("daughtertracks",murep);
172         
173         //cout<<"add filterd aod"<<endl;
174         
175         if ( fMCMode > 0 ) 
176           {
177             // MC branches will be copied (if present), as they are, but only
178             // for events with at least one muon. 
179             // For events w/o muon, mcparticles array will be empty and mcheader will be dummy
180             // (e.g. strlen(GetGeneratorName())==0)
181             
182             ext->FilterBranch("mcparticles",murep);
183             ext->FilterBranch("mcHeader",murep);
184           }
185       }  
186     
187   }
188   //cout<<"fine add filterd"<<endl;
189 }
190
191 //______________________________________________________________________________
192 void AliAnalysisTaskESDNuclExFilterMC::Init()
193 {
194
195   // Initialization
196   if(fEnableMuonAOD) 
197     AddFilteredAOD("AliAOD.NuclEx.root", "NuclexFilteredEvents",kTRUE);
198 }
199
200
201 //______________________________________________________________________________
202 void AliAnalysisTaskESDNuclExFilterMC::UserExec(Option_t */*option*/)
203 {
204   // Execute analysis for current event                                     
205   
206   Long64_t ientry = Entry();
207   if(fDebug)printf("Muon Filter: Analysing event # %5d\n", (Int_t) ientry);
208   
209   //***************************************************
210
211   ConvertESDtoAOD();
212
213   //*************************************************
214   
215 }
216
217
218 void AliAnalysisTaskESDNuclExFilterMC::ConvertESDtoAOD() 
219
220 {
221
222   //cout<<"========================> CONVERT ESD TO AOD <============================="<<endl;
223
224   
225   AliAODEvent *lAODevent=(AliAODEvent*)InputEvent();
226
227   // Read primary vertex from AOD event 
228   // AliAODVertex *primary = *(AODEvent()->GetPrimaryVertex());
229
230   AliAODVertex *primary = lAODevent->GetPrimaryVertex();
231   if (fDebug && primary) primary->Print();
232   //cout<<"Primary vtx x: "<<primary->GetX()<<" "<<primary->GetY()<<" "<<primary->GetZ()<<endl;
233       
234   AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
235  
236   if ( handler ){
237     
238     AliAODExtension *extNuclEx = handler->GetFilteredAOD("AliAOD.NuclEx.root");
239     
240     if ( extNuclEx ) {                          
241     
242       extNuclEx->SetEvent(lAODevent);
243       extNuclEx->SelectEvent();
244       extNuclEx->FinishEvent();
245       
246     }
247   }
248   
249 }
250 //------------------------------------------------
251 void AliAnalysisTaskESDNuclExFilterMC::Terminate(Option_t */*option*/)
252 {
253   // Terminate analysis
254   //
255   //  delete murep;
256   
257   if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");
258 }