]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/STRANGENESS/Hypernuclei/AliAnalysisTaskESDNuclExFilter.cxx
Fixing coverity bugs
[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)
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   //cout<<"Add Filterd AOD "<<aodH->AddFilteredAOD(aodfilename,title)<<endl;
222   AliAODExtension* ext = aodH->AddFilteredAOD(aodfilename,title);
223   //cout<<"Handle inside add filterAOD: "<<aodH<<endl;
224   //cout<<"########### ext: "<<ext<<endl;
225   
226   if (!ext) return;
227   
228   //cout<<"ONLY MUON?? "<<fOnlyMuon<<endl;
229
230   if ( fOnlyMuon ) 
231     {    
232     
233       //cout<<"Inside fonly muon: "<<endl;
234
235       
236       if(!murep)delete murep;
237
238       murep = new AliAODNuclExReplicator("NuclExReplicator",
239                                          "remove non interesting tracks",
240                                          // new AliAnalysisNonMuonTrackCuts,
241                                          // new AliAnalysisNonPrimaryVertices,
242                                          fMCMode,fnSigmaTrk1,fnSigmaTrk2,fpartType1,fpartType2);
243       
244       //cout<<"murep: "<<murep<<endl;
245       
246       ext->DropUnspecifiedBranches(); // all branches not part of a FilterBranch call (below) will be dropped
247       
248       // ext->FilterBranch("header",murep);    
249       // ext->FilterBranch("tracks",murep);    
250       // ext->FilterBranch("vertices",murep);  
251       // ext->FilterBranch("dimuons",murep); //per test
252       // ext->FilterBranch("AliAODVZERO",murep);
253       // ext->FilterBranch("AliAODTZERO",murep);
254       
255       ext->FilterBranch("header",murep);    
256       ext->FilterBranch("vertices",murep);    
257       ext->FilterBranch("nuclei",murep);  
258       ext->FilterBranch("secvertices",murep); //per test
259       ext->FilterBranch("daughtertracks",murep);
260
261       //cout<<"add filterd aod"<<endl;
262       
263       if ( fMCMode > 0 ) 
264         {
265           // MC branches will be copied (if present), as they are, but only
266           // for events with at least one muon. 
267           // For events w/o muon, mcparticles array will be empty and mcheader will be dummy
268           // (e.g. strlen(GetGeneratorName())==0)
269           
270           ext->FilterBranch("mcparticles",murep);
271           ext->FilterBranch("mcHeader",murep);
272         }
273     }  
274   
275   //cout<<"fine add filterd"<<endl;
276 }
277
278 //______________________________________________________________________________
279 void AliAnalysisTaskESDNuclExFilter::Init()
280 {
281
282   //cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Sono in INIT"<<endl;
283   // Initialization
284   if(fEnableMuonAOD) 
285     AddFilteredAOD("AliAOD.NuclEx.root", "MuonEvents");
286   //cout<<"Fine INIT"<<endl;
287   //  if(fEnableDimuonAOD) AddFilteredAOD("AliAOD.Dimuons.root", "DimuonEvents");    
288 }
289
290
291 //______________________________________________________________________________
292 void AliAnalysisTaskESDNuclExFilter::UserExec(Option_t */*option*/)
293 {
294   // Execute analysis for current event                                     
295   
296   //cout<<">>>>>>>>>>>>Inside User exec<<<<<<<<<<<<<<<<<"<<endl;
297
298   Long64_t ientry = Entry();
299   if(fDebug)printf("Muon Filter: Analysing event # %5d\n", (Int_t) ientry);
300   //cout<<"--------------->Enter the user exec<------------------------------"<<endl;
301   
302   //Check the PIDresponse
303   if(!fPIDResponse) {
304     AliError("Cannot get pid response");
305     return;
306   }
307
308   //***************************************************
309
310   ConvertESDtoAOD();
311
312   //*************************************************
313   
314   //cout<<"-------------------------------------------------------------------FINE ESD TO AOD CONVERTER!!!"<<endl;
315   
316   // if(!murep)
317   //   delete murep;
318   
319 }
320
321
322
323
324
325 //---- Funziona
326
327
328 void AliAnalysisTaskESDNuclExFilter::ConvertESDtoAOD() 
329
330 {
331   //cout<<"========================> CONVERT ESD TO AOD <============================="<<endl;
332
333   
334   AliAODEvent *lAODevent=(AliAODEvent*)InputEvent();
335
336   // Read primary vertex from AOD event 
337   // AliAODVertex *primary = *(AODEvent()->GetPrimaryVertex());
338
339   AliAODVertex *primary = lAODevent->GetPrimaryVertex();
340   if (fDebug && primary) primary->Print();
341   //cout<<"Primary vtx x: "<<primary->GetX()<<" "<<primary->GetY()<<" "<<primary->GetZ()<<endl;
342   
343     
344   AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
345   //AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
346
347   //cout<<"Mag field Filer: "<<lAODevent->GetMagneticField()<<endl;
348
349   // lAODevent->Print();
350
351   //cout<<"handler inside convert "<<handler<<endl;
352   if ( handler ){
353     
354     //cout<<"Hadler in the loop "<<handler<<endl;
355
356     //cout<<"Inside if handler loop"<<endl;
357
358     AliAODExtension *extNuclEx = handler->GetFilteredAOD("AliAOD.NuclEx.root");
359     //  AliAODExtension *extNuclEx = handler->GetFilteredAOD("../1/pass2/AliAOD.root");
360     
361     //cout<<"extmuon? "<<extNuclEx<<endl;
362
363     if ( extNuclEx ) {                          
364      //   extNuclEx->Init("");
365      
366       extNuclEx->SetEvent(lAODevent);
367       extNuclEx->SelectEvent();
368       // extNuclEx->IsFilteredAOD();
369       // extNuclEx->Print();
370       extNuclEx->FinishEvent();
371      
372      //cout<<"extMuons? "<<extMuons<<endl;
373
374    }
375   }
376
377
378 }
379 //------------------------------------------------
380 void AliAnalysisTaskESDNuclExFilter::Terminate(Option_t */*option*/)
381 {
382   // Terminate analysis
383   //
384   //  delete murep;
385   
386   if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");
387 }