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