]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/STRANGENESS/Hypernuclei/AliAnalysisTaskESDNuclExFilter.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / Hypernuclei / AliAnalysisTaskESDNuclExFilter.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 "AliAnalysisTaskESDNuclExFilter.h"
29
30 #include "AliAODDimuon.h"
31 #include "AliAODEvent.h"
32 #include "AliAODHandler.h"
33 #include "AliAODExtension.h"
34 #include "AliAODMCParticle.h"
35 #include "AliAODNuclExReplicator.h"
36 #include "AliAODVertex.h"
37 #include "AliAnalysisFilter.h"
38 #include "AliAnalysisManager.h"
39 #include "AliCodeTimer.h"
40 #include "AliESDEvent.h"
41 #include "AliESDInputHandler.h"
42 #include "AliESDMuonTrack.h"
43 #include "AliESDVertex.h"
44 #include "AliESDtrack.h"
45 #include "AliLog.h"
46 #include "AliMCEvent.h"
47 #include "AliMCEventHandler.h"
48 #include "AliMultiplicity.h"
49 #include <TChain.h>
50 #include <TFile.h>
51 #include <TParticle.h>
52 #include "AliESDtrackCuts.h"
53 #include "AliAODTrack.h"
54 #include "AliAODPid.h"
55 #include "TF1.h"
56 #include "AliPIDResponse.h"
57
58 using std::cout;
59 using std::endl;
60 ClassImp(AliAnalysisTaskESDNuclExFilter)
61 //ClassImp(AliAnalysisNonMuonTrackCuts)
62
63 ////////////////////////////////////////////////////////////////////////
64
65 // AliAnalysisNonMuonTrackCuts::AliAnalysisNonMuonTrackCuts()
66 // {
67 //   // default ctor 
68 // }
69
70 // Bool_t AliAnalysisNonMuonTrackCuts::IsSelected(TObject* obj)
71 // {
72 //   // Returns true if the object is a muon track
73 //   AliAODTrack* track = dynamic_cast<AliAODTrack*>(obj);
74
75 //   ULong_t  status;
76
77 //   if(track){
78     
79 //     status  = (ULong_t)track->GetStatus();
80
81 //     if(track->GetTPCNcls() > 80 &&
82 //        track->Chi2perNDF() < 5  &&
83 //        track->IsOn(AliAODTrack::kTPCrefit) &&
84 //        track->IsOn(AliAODTrack::kTPCin)    &&
85 //        !track->IsOn(AliAODTrack::kITSpureSA))
86 //       {
87 //      return kTRUE;
88 //       }
89 //   } 
90   
91 //   else 
92 //     return kFALSE;
93   
94
95 // }
96
97 // AliAnalysisNonPrimaryVertices::AliAnalysisNonPrimaryVertices()
98 // {
99 //   // default ctor   
100 // }
101
102 // Bool_t AliAnalysisNonPrimaryVertices::IsSelected(TObject* obj)
103 // {
104 //   // Returns true if the object is a primary vertex
105   
106 //   AliAODVertex* vertex = dynamic_cast<AliAODVertex*>(obj);
107 //   if (vertex)
108 //     {
109 //       if ( vertex->GetType() == AliAODVertex::kPrimary     ||
110 //         vertex->GetType() == AliAODVertex::kMainSPD     ||
111 //         vertex->GetType() == AliAODVertex::kPileupSPD   ||
112 //         vertex->GetType() == AliAODVertex::kPileupTracks||
113 //         vertex->GetType() == AliAODVertex::kMainTPC )
114 //      {
115 //        return kTRUE;
116 //      }
117 //     }
118   
119 //   //  enum AODVtx_t {kUndef=-1, kPrimary, kKink, kV0, kCascade, kMulti, kMainSPD, kPileupSPD, kPileupTracks,kMainTPC};
120
121 //   return kFALSE;
122   
123 // }
124 //-----------------------------------------------------------------------------------
125
126 AliAnalysisTaskESDNuclExFilter::AliAnalysisTaskESDNuclExFilter(Bool_t onlyMuon, Bool_t keepAllEvents, Int_t mcMode, Int_t nsigmaTrk1,Int_t nsigmaTrk2, Int_t partType1,Int_t partType2):
127   AliAnalysisTaskSE(),
128   fTrackFilter(0x0),
129   fEnableMuonAOD(kTRUE),
130   fEnableDimuonAOD(kTRUE),
131   fOnlyMuon(onlyMuon),
132   fKeepAllEvents(keepAllEvents),
133   fMCMode(mcMode),
134   fnSigmaTrk1(nsigmaTrk1),
135   fnSigmaTrk2(nsigmaTrk2),
136   fpartType1(partType1),
137   fpartType2(partType2),
138   murep(0x0),
139   fPIDResponse(0)
140 {
141   // Default constructor
142 }
143
144 AliAnalysisTaskESDNuclExFilter::AliAnalysisTaskESDNuclExFilter(const char* name, Bool_t onlyMuon, Bool_t keepAllEvents, Int_t mcMode, Int_t nsigmaTrk1,Int_t nsigmaTrk2, Int_t partType1,Int_t partType2):
145   AliAnalysisTaskSE(name),
146   fTrackFilter(0x0),
147   fEnableMuonAOD(kTRUE),
148   fEnableDimuonAOD(kTRUE),
149   fOnlyMuon(onlyMuon),
150   fKeepAllEvents(keepAllEvents),
151   fMCMode(mcMode),
152   fnSigmaTrk1(nsigmaTrk1),
153   fnSigmaTrk2(nsigmaTrk2),
154   fpartType1(partType1),
155   fpartType2(partType2),
156   murep(0x0),
157   fPIDResponse(0)
158 {
159   // Constructor
160 }
161
162 //______________________________________________________________________________
163 void AliAnalysisTaskESDNuclExFilter::UserCreateOutputObjects()
164 {
165   //-----------------------------------------------
166   // Particle Identification Setup (new PID object)
167   //-----------------------------------------------
168   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
169   //cout<<"===========================================Manager: "<<man<<endl;
170   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
171   //cout<<"ih: "<<inputHandler<<endl;
172   
173   fPIDResponse = inputHandler->GetPIDResponse();
174
175   // Create the output container
176   if (fTrackFilter) OutputTree()->GetUserInfo()->Add(fTrackFilter);
177   //cout<<"Sotto"<<endl;
178 }
179
180 //______________________________________________________________________________
181 void AliAnalysisTaskESDNuclExFilter::PrintTask(Option_t *option, Int_t indent) const
182 {
183   // Specify how we are configured
184   
185   AliAnalysisTaskSE::PrintTask(option,indent);
186   
187   TString spaces(' ',indent+3);
188   
189   if ( fOnlyMuon ) 
190     {
191       cout << spaces.Data() << "Keep only muon information " << endl;        
192     }
193   else 
194     {
195       cout << spaces.Data() << "Keep all information from standard AOD" << endl;
196     }
197   
198   if ( fKeepAllEvents ) 
199     {
200       cout << spaces.Data() << "Keep all events, regardless of number of muons" << endl;    
201     }
202   else 
203     {
204       cout << spaces.Data() << "Keep only events with at least one muon" << endl;
205     }
206   
207   if ( fMCMode > 0 ) 
208     {
209       cout << spaces.Data() << "Assuming work on MC data (i.e. will transmit MC branches)" << endl;
210     }
211 }
212
213 //______________________________________________________________________________
214 void AliAnalysisTaskESDNuclExFilter::AddFilteredAOD(const char* aodfilename, const char* title, Bool_t toMerge)
215 {
216   
217   //cout<<"Entro ne ADDFILTETEDAOD"<<endl;
218
219   AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
220   if (!aodH) Fatal("UserCreateOutputObjects", "No AOD handler");
221
222   if(aodH){
223
224     //cout<<"Add Filterd AOD "<<aodH->AddFilteredAOD(aodfilename,title)<<endl;
225     AliAODExtension* ext = aodH->AddFilteredAOD(aodfilename,title,toMerge);
226     //cout<<"Handle inside add filterAOD: "<<aodH<<endl;
227     //cout<<"########### ext: "<<ext<<endl;
228     
229     if (!ext) return;
230     
231     //cout<<"ONLY MUON?? "<<fOnlyMuon<<endl;
232     
233     if ( fOnlyMuon ) 
234       {    
235         
236         //cout<<"Inside fonly muon: "<<endl;
237         
238         
239         if(!murep)delete murep;
240         
241         murep = new AliAODNuclExReplicator("NuclExReplicator",
242                                            "remove non interesting tracks",
243                                            // new AliAnalysisNonMuonTrackCuts,
244                                            // new AliAnalysisNonPrimaryVertices,
245                                            fMCMode,fnSigmaTrk1,fnSigmaTrk2,fpartType1,fpartType2);
246         
247         //cout<<"murep: "<<murep<<endl;
248         
249         ext->DropUnspecifiedBranches(); // all branches not part of a FilterBranch call (below) will be dropped
250         
251         // ext->FilterBranch("header",murep);    
252         // ext->FilterBranch("tracks",murep);    
253         // ext->FilterBranch("vertices",murep);  
254         // ext->FilterBranch("dimuons",murep); //per test
255         // ext->FilterBranch("AliAODVZERO",murep);
256         // ext->FilterBranch("AliAODTZERO",murep);
257         
258         ext->FilterBranch("header",murep);    
259         ext->FilterBranch("vertices",murep);    
260         ext->FilterBranch("nuclei",murep);  
261         ext->FilterBranch("secvertices",murep); //per test
262         ext->FilterBranch("daughtertracks",murep);
263         
264         //cout<<"add filterd aod"<<endl;
265         
266         if ( fMCMode > 0 ) 
267           {
268             // MC branches will be copied (if present), as they are, but only
269             // for events with at least one muon. 
270             // For events w/o muon, mcparticles array will be empty and mcheader will be dummy
271             // (e.g. strlen(GetGeneratorName())==0)
272             
273             ext->FilterBranch("mcparticles",murep);
274             ext->FilterBranch("mcHeader",murep);
275           }
276       }  
277     
278   }
279   //cout<<"fine add filterd"<<endl;
280 }
281
282 //______________________________________________________________________________
283 void AliAnalysisTaskESDNuclExFilter::Init()
284 {
285
286   //cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Sono in INIT"<<endl;
287   // Initialization
288   if(fEnableMuonAOD) 
289     AddFilteredAOD("AliAOD.NuclEx.root", "NuclexFilteredEvents",kTRUE);
290   //cout<<"Fine INIT"<<endl;
291   //  if(fEnableDimuonAOD) AddFilteredAOD("AliAOD.Dimuons.root", "DimuonEvents");    
292 }
293
294
295 //______________________________________________________________________________
296 void AliAnalysisTaskESDNuclExFilter::UserExec(Option_t */*option*/)
297 {
298   // Execute analysis for current event                                     
299   
300   //cout<<">>>>>>>>>>>>Inside User exec<<<<<<<<<<<<<<<<<"<<endl;
301
302   Long64_t ientry = Entry();
303   if(fDebug)printf("Muon Filter: Analysing event # %5d\n", (Int_t) ientry);
304   //cout<<"--------------->Enter the user exec<------------------------------"<<endl;
305   
306   //Check the PIDresponse
307   if(!fPIDResponse) {
308     AliError("Cannot get pid response");
309     return;
310   }
311
312   //***************************************************
313
314   ConvertESDtoAOD();
315
316   //*************************************************
317   
318   //cout<<"-------------------------------------------------------------------FINE ESD TO AOD CONVERTER!!!"<<endl;
319   
320   // if(!murep)
321   //   delete murep;
322   
323 }
324
325
326
327
328
329 //---- Funziona
330
331
332 void AliAnalysisTaskESDNuclExFilter::ConvertESDtoAOD() 
333
334 {
335   //cout<<"========================> CONVERT ESD TO AOD <============================="<<endl;
336
337   
338   AliAODEvent *lAODevent=(AliAODEvent*)InputEvent();
339
340   // Read primary vertex from AOD event 
341   // AliAODVertex *primary = *(AODEvent()->GetPrimaryVertex());
342
343   AliAODVertex *primary = lAODevent->GetPrimaryVertex();
344   if (fDebug && primary) primary->Print();
345   //cout<<"Primary vtx x: "<<primary->GetX()<<" "<<primary->GetY()<<" "<<primary->GetZ()<<endl;
346   
347     
348   AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
349   //AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
350
351   //cout<<"Mag field Filer: "<<lAODevent->GetMagneticField()<<endl;
352
353   // lAODevent->Print();
354
355   //cout<<"handler inside convert "<<handler<<endl;
356   if ( handler ){
357     
358     //cout<<"Hadler in the loop "<<handler<<endl;
359
360     //cout<<"Inside if handler loop"<<endl;
361
362     AliAODExtension *extNuclEx = handler->GetFilteredAOD("AliAOD.NuclEx.root");
363     //  AliAODExtension *extNuclEx = handler->GetFilteredAOD("../1/pass2/AliAOD.root");
364     
365     //cout<<"extmuon? "<<extNuclEx<<endl;
366
367     if ( extNuclEx ) {                          
368      //   extNuclEx->Init("");
369       
370       // extNuclEx->GetAOD()->GetHeader()->ResetEventplanePointer();
371       // extNuclEx->GetTree()->Fill(); // fill header for all events without tracks
372
373       extNuclEx->SetEvent(lAODevent);
374       extNuclEx->SelectEvent();
375       // extNuclEx->IsFilteredAOD();
376       // extNuclEx->Print();
377       extNuclEx->FinishEvent();
378      
379      //cout<<"extMuons? "<<extMuons<<endl;
380
381    }
382   }
383
384
385 }
386 //------------------------------------------------
387 void AliAnalysisTaskESDNuclExFilter::Terminate(Option_t */*option*/)
388 {
389   // Terminate analysis
390   //
391   //  delete murep;
392   
393   if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");
394 }