]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/STRANGENESS/Hypernuclei/AliAnalysisTaskESDNuclExFilter.cxx
Fix to return the TOF cluster index (Francesco)
[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 AliAnalysisTaskESDNuclExFilter::AliAnalysisTaskESDNuclExFilter(Bool_t onlyMuon, Bool_t keepAllEvents, Int_t mcMode, Int_t nsigmaTrk1,Int_t nsigmaTrk2, Int_t partType1,Int_t partType2):
126   AliAnalysisTaskSE(),
127   fTrackFilter(0x0),
128   fEnableMuonAOD(kTRUE),
129   fEnableDimuonAOD(kTRUE),
130   fOnlyMuon(onlyMuon),
131   fKeepAllEvents(keepAllEvents),
132   fMCMode(mcMode),
133   fnSigmaTrk1(nsigmaTrk1),
134   fnSigmaTrk2(nsigmaTrk2),
135   fpartType1(partType1),
136   fpartType2(partType2),
137   fPIDResponse(0)
138 {
139   // Default constructor
140 }
141
142 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):
143   AliAnalysisTaskSE(name),
144   fTrackFilter(0x0),
145   fEnableMuonAOD(kTRUE),
146   fEnableDimuonAOD(kTRUE),
147   fOnlyMuon(onlyMuon),
148   fKeepAllEvents(keepAllEvents),
149   fMCMode(mcMode),
150   fnSigmaTrk1(nsigmaTrk1),
151   fnSigmaTrk2(nsigmaTrk2),
152   fpartType1(partType1),
153   fpartType2(partType2),
154   murep(0),
155   fPIDResponse(0)
156 {
157   // Constructor
158 }
159
160 //______________________________________________________________________________
161 void AliAnalysisTaskESDNuclExFilter::UserCreateOutputObjects()
162 {
163   //-----------------------------------------------
164   // Particle Identification Setup (new PID object)
165   //-----------------------------------------------
166   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
167   //cout<<"===========================================Manager: "<<man<<endl;
168   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
169   //cout<<"ih: "<<inputHandler<<endl;
170   
171   fPIDResponse = inputHandler->GetPIDResponse();
172
173   // Create the output container
174   if (fTrackFilter) OutputTree()->GetUserInfo()->Add(fTrackFilter);
175   //cout<<"Sotto"<<endl;
176 }
177
178 //______________________________________________________________________________
179 void AliAnalysisTaskESDNuclExFilter::PrintTask(Option_t *option, Int_t indent) const
180 {
181   // Specify how we are configured
182   
183   AliAnalysisTaskSE::PrintTask(option,indent);
184   
185   TString spaces(' ',indent+3);
186   
187   if ( fOnlyMuon ) 
188     {
189       cout << spaces.Data() << "Keep only muon information " << endl;        
190     }
191   else 
192     {
193       cout << spaces.Data() << "Keep all information from standard AOD" << endl;
194     }
195   
196   if ( fKeepAllEvents ) 
197     {
198       cout << spaces.Data() << "Keep all events, regardless of number of muons" << endl;    
199     }
200   else 
201     {
202       cout << spaces.Data() << "Keep only events with at least one muon" << endl;
203     }
204   
205   if ( fMCMode > 0 ) 
206     {
207       cout << spaces.Data() << "Assuming work on MC data (i.e. will transmit MC branches)" << endl;
208     }
209 }
210
211 //______________________________________________________________________________
212 void AliAnalysisTaskESDNuclExFilter::AddFilteredAOD(const char* aodfilename, const char* title)
213 {
214   
215   //cout<<"Entro ne ADDFILTETEDAOD"<<endl;
216
217   AliAODHandler *aodH = (AliAODHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
218   if (!aodH) Fatal("UserCreateOutputObjects", "No AOD handler");
219   //cout<<"Add Filterd AOD "<<aodH->AddFilteredAOD(aodfilename,title)<<endl;
220   AliAODExtension* ext = aodH->AddFilteredAOD(aodfilename,title);
221   //cout<<"Handle inside add filterAOD: "<<aodH<<endl;
222   //cout<<"########### ext: "<<ext<<endl;
223   
224   if (!ext) return;
225   
226   //cout<<"ONLY MUON?? "<<fOnlyMuon<<endl;
227
228   if ( fOnlyMuon ) 
229     {    
230     
231       //cout<<"Inside fonly muon: "<<endl;
232
233       
234       if(!murep)delete murep;
235
236       murep = new AliAODNuclExReplicator("NuclExReplicator",
237                                          "remove non interesting tracks",
238                                          new AliAnalysisNonMuonTrackCuts,
239                                          new AliAnalysisNonPrimaryVertices,
240                                          fMCMode,fnSigmaTrk1,fnSigmaTrk2,fpartType1,fpartType2);
241       
242       //cout<<"murep: "<<murep<<endl;
243       
244       ext->DropUnspecifiedBranches(); // all branches not part of a FilterBranch call (below) will be dropped
245       
246       // ext->FilterBranch("header",murep);    
247       // ext->FilterBranch("tracks",murep);    
248       // ext->FilterBranch("vertices",murep);  
249       // ext->FilterBranch("dimuons",murep); //per test
250       // ext->FilterBranch("AliAODVZERO",murep);
251       // ext->FilterBranch("AliAODTZERO",murep);
252       
253       ext->FilterBranch("header",murep);    
254       ext->FilterBranch("vertices",murep);    
255       ext->FilterBranch("nuclei",murep);  
256       ext->FilterBranch("secvertices",murep); //per test
257       ext->FilterBranch("daughtertracks",murep);
258
259       //cout<<"add filterd aod"<<endl;
260       
261       if ( fMCMode > 0 ) 
262         {
263           // MC branches will be copied (if present), as they are, but only
264           // for events with at least one muon. 
265           // For events w/o muon, mcparticles array will be empty and mcheader will be dummy
266           // (e.g. strlen(GetGeneratorName())==0)
267           
268           ext->FilterBranch("mcparticles",murep);
269           ext->FilterBranch("mcHeader",murep);
270         }
271     }  
272   
273   //cout<<"fine add filterd"<<endl;
274 }
275
276 //______________________________________________________________________________
277 void AliAnalysisTaskESDNuclExFilter::Init()
278 {
279
280   //cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Sono in INIT"<<endl;
281   // Initialization
282   if(fEnableMuonAOD) 
283     AddFilteredAOD("AliAOD.NuclEx.root", "MuonEvents");
284   //cout<<"Fine INIT"<<endl;
285   //  if(fEnableDimuonAOD) AddFilteredAOD("AliAOD.Dimuons.root", "DimuonEvents");    
286 }
287
288
289 //______________________________________________________________________________
290 void AliAnalysisTaskESDNuclExFilter::UserExec(Option_t */*option*/)
291 {
292   // Execute analysis for current event                                     
293   
294   //cout<<">>>>>>>>>>>>Inside User exec<<<<<<<<<<<<<<<<<"<<endl;
295
296   Long64_t ientry = Entry();
297   if(fDebug)printf("Muon Filter: Analysing event # %5d\n", (Int_t) ientry);
298   //cout<<"--------------->Enter the user exec<------------------------------"<<endl;
299   
300   //Check the PIDresponse
301   if(!fPIDResponse) {
302     AliError("Cannot get pid response");
303     return;
304   }
305
306   //***************************************************
307
308   ConvertESDtoAOD();
309
310   //*************************************************
311   
312   //cout<<"-------------------------------------------------------------------FINE ESD TO AOD CONVERTER!!!"<<endl;
313   
314   // if(!murep)
315   //   delete murep;
316   
317 }
318
319
320
321
322
323 //---- Funziona
324
325
326 void AliAnalysisTaskESDNuclExFilter::ConvertESDtoAOD() 
327
328 {
329   //cout<<"========================> CONVERT ESD TO AOD <============================="<<endl;
330
331   
332   AliVEvent *event = InputEvent();
333   //cout<<"VEvent: "<<event<<endl;
334   AliAODEvent *lAODevent=(AliAODEvent*)InputEvent();
335   //cout<<"AOD Event: "<<event<<endl;
336   AliAODHeader* header =lAODevent->GetHeader();
337   //cout<<"header :"<<header<<endl;
338   Int_t jTracks =  lAODevent->GetNumberOfTracks();
339   //cout<<"n jtracks :"<<jTracks<<endl;
340
341   // Read primary vertex from AOD event 
342   // AliAODVertex *primary = *(AODEvent()->GetPrimaryVertex());
343
344   AliAODVertex *primary = lAODevent->GetPrimaryVertex();
345   if (fDebug && primary) primary->Print();
346   //cout<<"Primary vtx x: "<<primary->GetX()<<" "<<primary->GetY()<<" "<<primary->GetZ()<<endl;
347   
348     
349   AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
350   //AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
351
352   //cout<<"Mag field Filer: "<<lAODevent->GetMagneticField()<<endl;
353
354   // lAODevent->Print();
355
356   //cout<<"handler inside convert "<<handler<<endl;
357   if ( handler ){
358     
359     //cout<<"Hadler in the loop "<<handler<<endl;
360
361     //cout<<"Inside if handler loop"<<endl;
362
363     AliAODExtension *extNuclEx = handler->GetFilteredAOD("AliAOD.NuclEx.root");
364     //  AliAODExtension *extNuclEx = handler->GetFilteredAOD("../1/pass2/AliAOD.root");
365     
366     //cout<<"extmuon? "<<extNuclEx<<endl;
367
368     if ( extNuclEx ) {                          
369      //   extNuclEx->Init("");
370      extNuclEx->SetEvent(lAODevent);
371      extNuclEx->SelectEvent();
372      extNuclEx->Print();
373      extNuclEx->FinishEvent();
374      
375      //cout<<"extMuons? "<<extMuons<<endl;
376
377    }
378   }
379
380
381 }
382 //------------------------------------------------
383 void AliAnalysisTaskESDNuclExFilter::Terminate(Option_t */*option*/)
384 {
385   // Terminate analysis
386   //
387   //  delete murep;
388   
389   if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");
390 }