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 // Author : R. Vernet, Consorzio Cometa - Catania (it)
18 //-----------------------------------------------------------------------
22 #include <TInterpreter.h>
24 #include "AliCFRsnTask.h"
27 #include "TParticle.h"
30 #include "AliMCEventHandler.h"
31 #include "AliMCEvent.h"
32 #include "AliAnalysisManager.h"
33 #include "AliESDEvent.h"
34 #include "AliCFManager.h"
35 #include "AliCFCutBase.h"
36 #include "AliCFContainer.h"
38 #include "AliESDtrack.h"
40 #include "AliRsnDaughter.h"
41 #include "AliCFPair.h"
44 //__________________________________________________________________________
45 AliCFRsnTask::AliCFRsnTask() :
50 fHistEventsProcessed(0x0)
54 //___________________________________________________________________________
55 AliCFRsnTask::AliCFRsnTask(const Char_t* name) :
56 AliAnalysisTask(name,"AliCFRsnTask"),
61 fHistEventsProcessed(0x0)
64 // Constructor. Initialization of Inputs and Outputs
66 Info("AliCFRsnTask","Calling Constructor");
67 DefineInput (0,TChain::Class());
68 DefineOutput(0,TH1I::Class());
69 DefineOutput(1,AliCFContainer::Class());
70 // DefineOutput(2,TList::Class());
73 //___________________________________________________________________________
74 AliCFRsnTask& AliCFRsnTask::operator=(const AliCFRsnTask& c)
77 // Assignment operator
80 AliAnalysisTask::operator=(c) ;
84 fCFManager = c.fCFManager;
85 fHistEventsProcessed = c.fHistEventsProcessed;
90 //___________________________________________________________________________
91 AliCFRsnTask::AliCFRsnTask(const AliCFRsnTask& c) :
96 fCFManager(c.fCFManager),
97 fHistEventsProcessed(c.fHistEventsProcessed)
104 //___________________________________________________________________________
105 AliCFRsnTask::~AliCFRsnTask() {
109 Info("~AliCFRsnTask","Calling Destructor");
110 if (fChain) delete fChain ;
111 if (fESD) delete fESD ;
112 if (fCFManager) delete fCFManager ;
113 if (fHistEventsProcessed) delete fHistEventsProcessed ;
116 //___________________________________________________________________________
118 void AliCFRsnTask::Init()
122 //_________________________________________________
123 void AliCFRsnTask::Exec(Option_t *)
126 // Main loop function
130 AliMCEventHandler* mcTruth = (AliMCEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
132 if (!mcTruth) Error("Exec","NO MC INFO FOUND... EXITING");
134 // transform possible old AliESD into AliESDEvent
136 if (fESD->GetAliESDOld()) fESD->CopyFromOldESD(); //transition to new ESD format
138 //pass the MC evt handler to the cuts that need it
140 fCFManager->SetEventInfo(mcTruth);
143 AliMCEvent* mcEvent = mcTruth->MCEvent();
144 AliStack* stack = mcEvent->Stack();
146 // MC-event selection
147 Double_t containerInput[2] ;
149 //loop on the MC event
150 Info("Exec","Looping on MC event");
151 for (Int_t ipart=0; ipart<stack->GetNprimary(); ipart++) {
152 AliMCParticle *mcPart = mcEvent->GetTrack(ipart);
154 //check the MC-level cuts
155 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartGenCuts,mcPart)) continue;
156 containerInput[0] = mcPart->Pt();
157 containerInput[1] = mcPart->Eta() ;
158 //fill the container for Gen-level selection
159 fCFManager->GetParticleContainer()->Fill(containerInput,kStepGenerated);
161 //check the Acceptance-level cuts
162 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartAccCuts,mcPart)) continue;
163 //fill the container for Acceptance-level selection
164 fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructible);
168 //Now go to rec level
169 Info("Exec","Looping on ESD event");
171 //SET THE ESD AS EVENT INFO IN RECONSTRUCTION CUTS
172 TObjArray* fCutsReco = fCFManager->GetParticleCutsList(AliCFManager::kPartRecCuts);
173 TObjArray* fCutsPID = fCFManager->GetParticleCutsList(AliCFManager::kPartSelCuts);
174 TObjArrayIter iter1(fCutsReco);
175 TObjArrayIter iter2(fCutsPID);
176 AliCFCutBase *cut = 0;
177 while ( (cut = (AliCFCutBase*)iter1.Next()) ) {
178 cut->SetEvtInfo(fESD);
180 while ( (cut = (AliCFCutBase*)iter2.Next()) ) {
181 cut->SetEvtInfo(fESD);
184 for (Int_t iTrack1 = 0; iTrack1<fESD->GetNumberOfTracks(); iTrack1++) {
185 AliESDtrack* esdTrack1 = fESD->GetTrack(iTrack1);
187 if (esdTrack1->Charge()>=0) continue;
188 Int_t esdLabel1 = esdTrack1->GetLabel();
189 if (esdLabel1<0) continue;
191 for (Int_t iTrack2 = 0; iTrack2<fESD->GetNumberOfTracks(); iTrack2++) {
192 AliESDtrack* esdTrack2 = fESD->GetTrack(iTrack2);
194 if (esdTrack2->Charge()<=0) continue;
195 Int_t esdLabel2 = esdTrack2->GetLabel();
196 if (esdLabel2<0) continue;
198 // copy ESDtrack data into RsnDaughter (and make Bayesian PID)
199 //if problem with copy constructor, use the following special command to destroy the pointer when exiting scope
200 //std::auto_ptr<AliRsnDaughter> track1(AliRsnDaughter::Adopt(esdTrack1,iTrack1));
202 AliRsnDaughter* tmp1=AliRsnDaughter::Adopt(esdTrack1,iTrack1);
203 AliRsnDaughter* tmp2=AliRsnDaughter::Adopt(esdTrack2,iTrack2);
204 AliRsnDaughter track1(*tmp1);
205 AliRsnDaughter track2(*tmp2);
209 TParticle *part1 = stack->Particle(esdLabel1);
210 track1.SetTruePDG(part1->GetPdgCode());
211 Int_t mother1 = part1->GetFirstMother();
212 track1.SetMother(mother1);
214 TParticle *mum = stack->Particle(mother1);
215 track1.SetMotherPDG(mum->GetPdgCode());
218 TParticle *part2 = stack->Particle(esdLabel2);
219 track2.SetTruePDG(part2->GetPdgCode());
220 Int_t mother2 = part2->GetFirstMother();
221 track2.SetMother(mother2);
223 TParticle *mum = stack->Particle(mother2);
224 track2.SetMotherPDG(mum->GetPdgCode());
227 //make a mother resonance from the 2 candidate daughters
228 AliRsnDaughter rsn = AliRsnDaughter::Sum(track1,track2) ;
229 AliCFPair pair(esdTrack1,esdTrack2);
231 //check if true resonance
232 if (rsn.GetMotherPDG() != fRsnPDG) continue;
233 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartRecCuts,&pair)) continue;
235 //check if associated MC resonance passes the cuts
236 Int_t motherLabel=rsn.GetLabel();
237 if (motherLabel<0) continue ;
238 AliMCParticle* mcRsn = mcEvent->GetTrack(motherLabel);
239 if (!mcRsn) continue;
240 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartGenCuts,mcRsn)) continue;
243 containerInput[0] = rsn.GetPt() ;
244 containerInput[1] = GetRapidity(rsn.GetEnergy(),rsn.GetPz());
245 fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructed) ;
247 if (!fCFManager->CheckParticleCuts(AliCFManager::kPartSelCuts,&pair)) continue ;
248 fCFManager->GetParticleContainer()->Fill(containerInput,kStepSelected);
252 fHistEventsProcessed->Fill(0);
253 PostData(0,fHistEventsProcessed) ;
254 PostData(1,fCFManager->GetParticleContainer()) ;
256 // TList * list = new TList();
257 // fCFManager->AddQAHistosToList(list);
258 // PostData(2,list) ;
262 //___________________________________________________________________________
263 void AliCFRsnTask::Terminate(Option_t*)
265 // The Terminate() function is the last function to be called during
266 // a query. It always runs on the client, it can be used to present
267 // the results graphically or save the results to file.
269 Info("Terminate","");
270 AliAnalysisTask::Terminate();
273 Double_t max1 = fCFManager->GetParticleContainer()->ShowProjection(0,0)->GetMaximum();
274 Double_t max2 = fCFManager->GetParticleContainer()->ShowProjection(1,0)->GetMaximum();
276 fCFManager->GetParticleContainer()->ShowProjection(0,0)->GetYaxis()->SetRangeUser(0,max1*1.2);
277 fCFManager->GetParticleContainer()->ShowProjection(0,1)->GetYaxis()->SetRangeUser(0,max1*1.2);
278 fCFManager->GetParticleContainer()->ShowProjection(0,2)->GetYaxis()->SetRangeUser(0,max1*1.2);
279 fCFManager->GetParticleContainer()->ShowProjection(0,3)->GetYaxis()->SetRangeUser(0,max1*1.2);
281 fCFManager->GetParticleContainer()->ShowProjection(1,0)->GetYaxis()->SetRangeUser(0,max2*1.2);
282 fCFManager->GetParticleContainer()->ShowProjection(1,1)->GetYaxis()->SetRangeUser(0,max2*1.2);
283 fCFManager->GetParticleContainer()->ShowProjection(1,2)->GetYaxis()->SetRangeUser(0,max2*1.2);
284 fCFManager->GetParticleContainer()->ShowProjection(1,3)->GetYaxis()->SetRangeUser(0,max2*1.2);
286 fCFManager->GetParticleContainer()->ShowProjection(0,0)->SetMarkerStyle(23) ;
287 fCFManager->GetParticleContainer()->ShowProjection(0,1)->SetMarkerStyle(24) ;
288 fCFManager->GetParticleContainer()->ShowProjection(0,2)->SetMarkerStyle(25) ;
289 fCFManager->GetParticleContainer()->ShowProjection(0,3)->SetMarkerStyle(26) ;
291 fCFManager->GetParticleContainer()->ShowProjection(1,0)->SetMarkerStyle(23) ;
292 fCFManager->GetParticleContainer()->ShowProjection(1,1)->SetMarkerStyle(24) ;
293 fCFManager->GetParticleContainer()->ShowProjection(1,2)->SetMarkerStyle(25) ;
294 fCFManager->GetParticleContainer()->ShowProjection(1,3)->SetMarkerStyle(26) ;
296 TCanvas * c =new TCanvas("c","",1400,800);
300 fCFManager->GetParticleContainer()->ShowProjection(0,0)->Draw("p");
302 fCFManager->GetParticleContainer()->ShowProjection(0,1)->Draw("p");
304 fCFManager->GetParticleContainer()->ShowProjection(0,2)->Draw("p");
306 fCFManager->GetParticleContainer()->ShowProjection(0,3)->Draw("p");
308 fCFManager->GetParticleContainer()->ShowProjection(1,0)->Draw("p");
310 fCFManager->GetParticleContainer()->ShowProjection(1,1)->Draw("p");
312 fCFManager->GetParticleContainer()->ShowProjection(1,2)->Draw("p");
314 fCFManager->GetParticleContainer()->ShowProjection(1,3)->Draw("p");
316 c->SaveAs("plots.eps");
318 delete fHistEventsProcessed ;
321 //___________________________________________________________________________
322 void AliCFRsnTask::ConnectInputData(Option_t *) {
324 // Initialize branches.
326 Info("ConnectInputData","ConnectInputData of task %s\n",GetName());
328 fChain = (TChain*)GetInputData(0);
329 fChain->SetBranchStatus("*FMD*",0);
330 fChain->SetBranchStatus("*CaloClusters*",0);
331 fESD = new AliESDEvent();
332 fESD->ReadFromTree(fChain);
335 //___________________________________________________________________________
336 void AliCFRsnTask::CreateOutputObjects() {
337 //HERE ONE CAN CREATE OUTPUT OBJECTS, IN PARTICULAR IF THE OBJECT PARAMETERS DON'T NEED
338 //TO BE SET BEFORE THE EXECUTION OF THE TASK
340 Info("CreateOutputObjects","CreateOutputObjects of task %s\n", GetName());
343 fHistEventsProcessed = new TH1I("fHistEventsProcessed","",1,0,1) ;
346 //___________________________________________________________________________
347 Double_t AliCFRsnTask::GetRapidity(Double_t energy, Double_t pz) {
348 if (energy == pz || energy == -pz) {
349 printf("GetRapidity : ERROR : rapidity for 4-vector with E = Pz -- infinite result");
353 printf("GetRapidity : ERROR : rapidity for 4-vector with E = Pz -- infinite result");
356 Double_t y = 0.5 * log((energy + pz) / (energy - pz));