1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
21 // Authors: S. Bufalino (stefania.bufalino@cern.ch)
22 // R. Lea (ramona.lea@cern.ch)
23 // Based on AliAnalysisTaskESDMuonFilter.cxx
25 // (see AddFilteredAOD method)
28 #include "AliAnalysisTaskESDNuclExFilter.h"
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"
46 #include "AliMCEvent.h"
47 #include "AliMCEventHandler.h"
48 #include "AliMultiplicity.h"
51 #include <TParticle.h>
52 #include "AliESDtrackCuts.h"
53 #include "AliAODTrack.h"
54 #include "AliAODPid.h"
56 #include "AliPIDResponse.h"
60 ClassImp(AliAnalysisTaskESDNuclExFilter)
61 ClassImp(AliAnalysisNonMuonTrackCuts)
63 ////////////////////////////////////////////////////////////////////////
65 AliAnalysisNonMuonTrackCuts::AliAnalysisNonMuonTrackCuts()
70 Bool_t AliAnalysisNonMuonTrackCuts::IsSelected(TObject* obj)
72 // Returns true if the object is a muon track
73 AliAODTrack* track = dynamic_cast<AliAODTrack*>(obj);
79 status = (ULong_t)track->GetStatus();
81 if(track->GetTPCNcls() > 80 &&
82 track->Chi2perNDF() < 5 &&
83 track->IsOn(AliAODTrack::kTPCrefit) &&
84 track->IsOn(AliAODTrack::kTPCin) &&
85 !track->IsOn(AliAODTrack::kITSpureSA))
97 AliAnalysisNonPrimaryVertices::AliAnalysisNonPrimaryVertices()
102 Bool_t AliAnalysisNonPrimaryVertices::IsSelected(TObject* obj)
104 // Returns true if the object is a primary vertex
106 AliAODVertex* vertex = dynamic_cast<AliAODVertex*>(obj);
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 )
119 // enum AODVtx_t {kUndef=-1, kPrimary, kKink, kV0, kCascade, kMulti, kMainSPD, kPileupSPD, kPileupTracks,kMainTPC};
125 AliAnalysisTaskESDNuclExFilter::AliAnalysisTaskESDNuclExFilter(Bool_t onlyMuon, Bool_t keepAllEvents, Int_t mcMode, Int_t nsigmaTrk1,Int_t nsigmaTrk2, Int_t partType1,Int_t partType2):
128 fEnableMuonAOD(kTRUE),
129 fEnableDimuonAOD(kTRUE),
131 fKeepAllEvents(keepAllEvents),
133 fnSigmaTrk1(nsigmaTrk1),
134 fnSigmaTrk2(nsigmaTrk2),
135 fpartType1(partType1),
136 fpartType2(partType2),
139 // Default constructor
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),
145 fEnableMuonAOD(kTRUE),
146 fEnableDimuonAOD(kTRUE),
148 fKeepAllEvents(keepAllEvents),
150 fnSigmaTrk1(nsigmaTrk1),
151 fnSigmaTrk2(nsigmaTrk2),
152 fpartType1(partType1),
153 fpartType2(partType2),
160 //______________________________________________________________________________
161 void AliAnalysisTaskESDNuclExFilter::UserCreateOutputObjects()
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;
171 fPIDResponse = inputHandler->GetPIDResponse();
173 // Create the output container
174 if (fTrackFilter) OutputTree()->GetUserInfo()->Add(fTrackFilter);
175 //cout<<"Sotto"<<endl;
178 //______________________________________________________________________________
179 void AliAnalysisTaskESDNuclExFilter::PrintTask(Option_t *option, Int_t indent) const
181 // Specify how we are configured
183 AliAnalysisTaskSE::PrintTask(option,indent);
185 TString spaces(' ',indent+3);
189 cout << spaces.Data() << "Keep only muon information " << endl;
193 cout << spaces.Data() << "Keep all information from standard AOD" << endl;
196 if ( fKeepAllEvents )
198 cout << spaces.Data() << "Keep all events, regardless of number of muons" << endl;
202 cout << spaces.Data() << "Keep only events with at least one muon" << endl;
207 cout << spaces.Data() << "Assuming work on MC data (i.e. will transmit MC branches)" << endl;
211 //______________________________________________________________________________
212 void AliAnalysisTaskESDNuclExFilter::AddFilteredAOD(const char* aodfilename, const char* title)
215 //cout<<"Entro ne ADDFILTETEDAOD"<<endl;
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;
226 //cout<<"ONLY MUON?? "<<fOnlyMuon<<endl;
231 //cout<<"Inside fonly muon: "<<endl;
234 if(!murep)delete murep;
236 murep = new AliAODNuclExReplicator("NuclExReplicator",
237 "remove non interesting tracks",
238 new AliAnalysisNonMuonTrackCuts,
239 new AliAnalysisNonPrimaryVertices,
240 fMCMode,fnSigmaTrk1,fnSigmaTrk2,fpartType1,fpartType2);
242 //cout<<"murep: "<<murep<<endl;
244 ext->DropUnspecifiedBranches(); // all branches not part of a FilterBranch call (below) will be dropped
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);
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);
259 //cout<<"add filterd aod"<<endl;
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)
268 ext->FilterBranch("mcparticles",murep);
269 ext->FilterBranch("mcHeader",murep);
273 //cout<<"fine add filterd"<<endl;
276 //______________________________________________________________________________
277 void AliAnalysisTaskESDNuclExFilter::Init()
280 //cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Sono in INIT"<<endl;
283 AddFilteredAOD("AliAOD.NuclEx.root", "MuonEvents");
284 //cout<<"Fine INIT"<<endl;
285 // if(fEnableDimuonAOD) AddFilteredAOD("AliAOD.Dimuons.root", "DimuonEvents");
289 //______________________________________________________________________________
290 void AliAnalysisTaskESDNuclExFilter::UserExec(Option_t */*option*/)
292 // Execute analysis for current event
294 //cout<<">>>>>>>>>>>>Inside User exec<<<<<<<<<<<<<<<<<"<<endl;
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;
300 //Check the PIDresponse
302 AliError("Cannot get pid response");
306 //***************************************************
310 //*************************************************
312 //cout<<"-------------------------------------------------------------------FINE ESD TO AOD CONVERTER!!!"<<endl;
326 void AliAnalysisTaskESDNuclExFilter::ConvertESDtoAOD()
329 //cout<<"========================> CONVERT ESD TO AOD <============================="<<endl;
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;
341 // Read primary vertex from AOD event
342 // AliAODVertex *primary = *(AODEvent()->GetPrimaryVertex());
344 AliAODVertex *primary = lAODevent->GetPrimaryVertex();
345 if (fDebug && primary) primary->Print();
346 //cout<<"Primary vtx x: "<<primary->GetX()<<" "<<primary->GetY()<<" "<<primary->GetZ()<<endl;
349 AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
350 //AliAODHandler* handler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
352 //cout<<"Mag field Filer: "<<lAODevent->GetMagneticField()<<endl;
354 // lAODevent->Print();
356 //cout<<"handler inside convert "<<handler<<endl;
359 //cout<<"Hadler in the loop "<<handler<<endl;
361 //cout<<"Inside if handler loop"<<endl;
363 AliAODExtension *extNuclEx = handler->GetFilteredAOD("AliAOD.NuclEx.root");
364 // AliAODExtension *extNuclEx = handler->GetFilteredAOD("../1/pass2/AliAOD.root");
366 //cout<<"extmuon? "<<extNuclEx<<endl;
369 // extNuclEx->Init("");
370 extNuclEx->SetEvent(lAODevent);
371 extNuclEx->SelectEvent();
373 extNuclEx->FinishEvent();
375 //cout<<"extMuons? "<<extMuons<<endl;
382 //------------------------------------------------
383 void AliAnalysisTaskESDNuclExFilter::Terminate(Option_t */*option*/)
385 // Terminate analysis
389 if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");