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 **************************************************************************/
16 //-----------------------------------------------------------------------
17 // Example of task running on AliEn (CAF?)
18 // which provides standard way of calculating acceptance and efficiency
19 // between different steps of the procedure.
20 // The ouptut of the task is a AliCFContainer from which the efficiencies
22 //-----------------------------------------------------------------------
23 // Author : R. Vernet, Consorzio Cometa - Catania (it)
24 //-----------------------------------------------------------------------
27 #ifndef ALICFV0TASK_CXX
28 #define ALICFV0TASK_CXX
30 #include <TInterpreter.h>
32 #include "AliCFV0Task.h"
35 #include "TParticle.h"
38 #include "AliMCEventHandler.h"
39 #include "AliMCEvent.h"
40 #include "AliAnalysisManager.h"
41 #include "AliESDEvent.h"
42 #include "AliCFManager.h"
43 #include "AliCFCutBase.h"
44 #include "AliCFContainer.h"
46 #include "AliESDtrack.h"
49 #include "AliV0vertexer.h"
50 #include "AliCFPair.h"
52 //__________________________________________________________________________
53 AliCFV0Task::AliCFV0Task() :
59 fHistEventsProcessed(0x0)
63 //___________________________________________________________________________
64 AliCFV0Task::AliCFV0Task(const Char_t* name) :
65 AliAnalysisTask(name,"AliCFV0Task"),
71 fHistEventsProcessed(0x0)
74 // Constructor. Initialization of Inputs and Outputs
76 Info("AliCFV0Task","Calling Constructor");
77 DefineInput (0,TChain::Class());
78 DefineOutput(0,TH1I::Class());
79 DefineOutput(1,AliCFContainer::Class());
80 // DefineOutput(2,TList::Class());
83 //___________________________________________________________________________
84 AliCFV0Task& AliCFV0Task::operator=(const AliCFV0Task& c)
87 // Assignment operator
90 AliAnalysisTask::operator=(c) ;
91 fRebuildV0s = c.fRebuildV0s;
95 fCFManager = c.fCFManager;
96 fHistEventsProcessed = c.fHistEventsProcessed;
101 //___________________________________________________________________________
102 AliCFV0Task::AliCFV0Task(const AliCFV0Task& c) :
104 fRebuildV0s(c.fRebuildV0s),
108 fCFManager(c.fCFManager),
109 fHistEventsProcessed(c.fHistEventsProcessed)
116 //___________________________________________________________________________
117 AliCFV0Task::~AliCFV0Task() {
121 Info("~AliCFV0Task","Calling Destructor");
122 if (fChain) delete fChain ;
123 if (fESD) delete fESD ;
124 if (fCFManager) delete fCFManager ;
125 if (fHistEventsProcessed) delete fHistEventsProcessed ;
128 //___________________________________________________________________________
130 void AliCFV0Task::Init()
134 //_________________________________________________
135 void AliCFV0Task::Exec(Option_t *)
138 // Main loop function
142 AliMCEventHandler* mcTruth = (AliMCEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
144 if (!mcTruth) Error("Exec","NO MC INFO FOUND... EXITING");
146 // transform possible old AliESD into AliESDEvent
148 if (fESD->GetAliESDOld()) fESD->CopyFromOldESD(); //transition to new ESD format
150 //pass the MC evt handler to the cuts that need it
152 fCFManager->SetEventInfo(mcTruth);
155 AliMCEvent* mcEvent = mcTruth->MCEvent();
157 // MC-event selection
158 Double_t containerInput[2] ;
160 //loop on the MC event
161 Info("Exec","Looping on MC event");
162 for (Int_t ipart=0; ipart<mcEvent->GetNumberOfTracks(); ipart++) {
163 AliMCParticle *mcPart = mcEvent->GetTrack(ipart);
165 //check the MC-level cuts
166 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartGenCuts,mcPart)) continue;
167 containerInput[0] = mcPart->Pt();
168 containerInput[1] = mcPart->Eta() ;
169 //fill the container for Gen-level selection
170 fCFManager->GetParticleContainer()->Fill(containerInput,kStepGenerated);
172 //check the Acceptance-level cuts
173 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartAccCuts,mcPart)) continue;
174 //fill the container for Acceptance-level selection
175 fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructible);
179 //Now go to rec level
180 Info("Exec","Looping on ESD event");
182 if (fRebuildV0s) RebuildV0s() ;
183 printf("There are %d V0s in event\n",fESD->GetNumberOfV0s());
184 for (Int_t iV0 = 0; iV0<fESD->GetNumberOfV0s(); iV0++) {
186 AliESDv0* esdV0 = fESD->GetV0(iV0);
188 //check if mother reconstructed V0 can be associated to a MC V0
189 Int_t labMCV0 = IsMcV0(esdV0,fESD,mcEvent->Stack()) ;
190 if (labMCV0 <0) continue;
192 esdV0->ChangeMassHypothesis(fV0PDG); //important to do that before entering the cut check
194 AliCFPair pair(esdV0,fESD);
195 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartRecCuts,&pair)) continue;
197 //check if associated MC v0 passes the cuts
198 AliMCParticle* mcV0 = mcEvent->GetTrack(labMCV0);
201 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartGenCuts,mcV0)) continue;
205 esdV0->GetPxPyPz(mom[0],mom[1],mom[2]);
206 Double_t pt2 = mom[0]*mom[0]+mom[1]*mom[1] ;
207 Double_t pt = TMath::Sqrt(pt2);
208 Double_t energy = TMath::Sqrt(pt2 + mom[2]*mom[2] + TMath::Power(TDatabasePDG::Instance()->GetParticle(fV0PDG)->Mass(),2));
210 containerInput[0] = pt ;
211 containerInput[1] = GetRapidity(energy,mom[2]);
212 fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructed) ;
213 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartSelCuts,&pair)) continue ;
214 fCFManager->GetParticleContainer()->Fill(containerInput,kStepSelected);
217 fHistEventsProcessed->Fill(0);
218 PostData(0,fHistEventsProcessed) ;
219 PostData(1,fCFManager->GetParticleContainer()) ;
221 // TList * list = new TList();
222 // fCFManager->AddQAHistosToList(list);
223 // PostData(2,list) ;
227 //___________________________________________________________________________
228 void AliCFV0Task::Terminate(Option_t*)
230 // The Terminate() function is the last function to be called during
231 // a query. It always runs on the client, it can be used to present
232 // the results graphically or save the results to file.
234 Info("Terminate","");
235 AliAnalysisTask::Terminate();
238 Double_t max1 = fCFManager->GetParticleContainer()->ShowProjection(0,0)->GetMaximum();
239 Double_t max2 = fCFManager->GetParticleContainer()->ShowProjection(1,0)->GetMaximum();
241 fCFManager->GetParticleContainer()->ShowProjection(0,0)->GetYaxis()->SetRangeUser(0,max1*1.2);
242 fCFManager->GetParticleContainer()->ShowProjection(0,1)->GetYaxis()->SetRangeUser(0,max1*1.2);
243 fCFManager->GetParticleContainer()->ShowProjection(0,2)->GetYaxis()->SetRangeUser(0,max1*1.2);
244 fCFManager->GetParticleContainer()->ShowProjection(0,3)->GetYaxis()->SetRangeUser(0,max1*1.2);
246 fCFManager->GetParticleContainer()->ShowProjection(1,0)->GetYaxis()->SetRangeUser(0,max2*1.2);
247 fCFManager->GetParticleContainer()->ShowProjection(1,1)->GetYaxis()->SetRangeUser(0,max2*1.2);
248 fCFManager->GetParticleContainer()->ShowProjection(1,2)->GetYaxis()->SetRangeUser(0,max2*1.2);
249 fCFManager->GetParticleContainer()->ShowProjection(1,3)->GetYaxis()->SetRangeUser(0,max2*1.2);
251 fCFManager->GetParticleContainer()->ShowProjection(0,0)->SetMarkerStyle(23) ;
252 fCFManager->GetParticleContainer()->ShowProjection(0,1)->SetMarkerStyle(24) ;
253 fCFManager->GetParticleContainer()->ShowProjection(0,2)->SetMarkerStyle(25) ;
254 fCFManager->GetParticleContainer()->ShowProjection(0,3)->SetMarkerStyle(26) ;
256 fCFManager->GetParticleContainer()->ShowProjection(1,0)->SetMarkerStyle(23) ;
257 fCFManager->GetParticleContainer()->ShowProjection(1,1)->SetMarkerStyle(24) ;
258 fCFManager->GetParticleContainer()->ShowProjection(1,2)->SetMarkerStyle(25) ;
259 fCFManager->GetParticleContainer()->ShowProjection(1,3)->SetMarkerStyle(26) ;
261 TCanvas * c =new TCanvas("c","",1400,800);
265 fCFManager->GetParticleContainer()->ShowProjection(0,0)->Draw("p");
267 fCFManager->GetParticleContainer()->ShowProjection(0,1)->Draw("p");
269 fCFManager->GetParticleContainer()->ShowProjection(0,2)->Draw("p");
271 fCFManager->GetParticleContainer()->ShowProjection(0,3)->Draw("p");
273 fCFManager->GetParticleContainer()->ShowProjection(1,0)->Draw("p");
275 fCFManager->GetParticleContainer()->ShowProjection(1,1)->Draw("p");
277 fCFManager->GetParticleContainer()->ShowProjection(1,2)->Draw("p");
279 fCFManager->GetParticleContainer()->ShowProjection(1,3)->Draw("p");
281 c->SaveAs("plots.eps");
283 delete fHistEventsProcessed ;
286 //___________________________________________________________________________
287 void AliCFV0Task::ConnectInputData(Option_t *) {
289 // Initialize branches.
291 Info("ConnectInputData","ConnectInputData of task %s\n",GetName());
293 fChain = (TChain*)GetInputData(0);
294 fChain->SetBranchStatus("*FMD*",0);
295 fChain->SetBranchStatus("*CaloClusters*",0);
296 fESD = new AliESDEvent();
297 fESD->ReadFromTree(fChain);
300 //___________________________________________________________________________
301 void AliCFV0Task::CreateOutputObjects() {
302 //HERE ONE CAN CREATE OUTPUT OBJECTS, IN PARTICULAR IF THE OBJECT PARAMETERS DON'T NEED
303 //TO BE SET BEFORE THE EXECUTION OF THE TASK
305 Info("CreateOutputObjects","CreateOutputObjects of task %s\n", GetName());
308 fHistEventsProcessed = new TH1I("fHistEventsProcessed","",1,0,1) ;
311 //___________________________________________________________________________
312 Int_t AliCFV0Task::GetV0Label(UInt_t lab1, UInt_t lab2, AliStack* stack) const {
314 // returns the label of the V0, given the labels of the 2 daughter tracks
315 // returns -1 if the V0 is fake
318 TParticle* part1 = stack->Particle(lab1) ;
319 TParticle* part2 = stack->Particle(lab2) ;
321 Int_t part1MotherLab=part1->GetFirstMother();
322 Int_t part2MotherLab=part2->GetFirstMother();
324 if (part1MotherLab==-1 || part2MotherLab==-1) return -1 ;
325 if (part1MotherLab != part2MotherLab ) return -1 ;
326 if (stack->Particle(part1MotherLab)->GetPdgCode() != fV0PDG ) return -1 ;
330 if ( (part1->GetPdgCode()== -211 && part2->GetPdgCode()== 211) ||
331 (part1->GetPdgCode()== 211 && part2->GetPdgCode()== -211) ) return part1MotherLab ;
334 if ( (part1->GetPdgCode()== -211 && part2->GetPdgCode()== 2212) ||
335 (part1->GetPdgCode()== 2212 && part2->GetPdgCode()== -211) ) return part1MotherLab ;
338 if ( (part1->GetPdgCode()== 211 && part2->GetPdgCode()== -2212) ||
339 (part1->GetPdgCode()== -2212 && part2->GetPdgCode()== 211) ) return part1MotherLab ;
349 //___________________________________________________________________________
350 Double_t AliCFV0Task::GetRapidity(Double_t energy, Double_t pz) {
351 if (energy == pz || energy == -pz) {
352 printf("GetRapidity : ERROR : rapidity for 4-vector with E = Pz -- infinite result");
356 printf("GetRapidity : ERROR : rapidity for 4-vector with E = Pz -- infinite result");
359 Double_t y = 0.5 * log((energy + pz) / (energy - pz));
363 //___________________________________________________________________________
364 Int_t AliCFV0Task::IsMcV0(AliESDv0* v0, AliESDEvent* esd, AliStack* stack) const {
365 Int_t nindex = v0->GetNindex();
366 Int_t pindex = v0->GetPindex();
367 AliESDtrack *nTrack = esd->GetTrack(nindex) ;
368 AliESDtrack *pTrack = esd->GetTrack(pindex) ;
370 if (!nTrack || !pTrack) return -1 ;
372 Int_t nlab = nTrack->GetLabel() ;
373 Int_t plab = pTrack->GetLabel() ;
375 if (nlab <0 || plab <0) return -1 ;
377 Int_t v0Label = GetV0Label((UInt_t)nlab,(UInt_t)plab,stack) ;
382 //___________________________________________________________________________
383 void AliCFV0Task::RebuildV0s() {
387 //These are pp cuts : to change if Pb+Pb !
388 Double_t cuts[]={33, // max. allowed chi2
389 0.1,// min. allowed negative daughter's impact parameter
390 0.1,// min. allowed positive daughter's impact parameter
391 0.1,// max. allowed DCA between the daughter tracks
392 0.999,// max. allowed cosine of V0's pointing angle
393 0.9, // min. radius of the fiducial volume
394 100. // max. radius of the fiducial volume
396 // AliV0vertexer* v0Vertexer = new AliV0vertexer(cuts);
397 // v0Vertexer->SetVertex(primVertexPos);
398 AliV0vertexer* v0Vertexer = new AliV0vertexer();
399 v0Vertexer->SetCuts(cuts) ;
400 v0Vertexer->Tracks2V0vertices(fESD);