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 locally, on AliEn and 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 : Marta Verweij - UU
24 //-----------------------------------------------------------------------
27 #ifndef ALIPWG4HighPtSpectra_CXX
28 #define ALIPWG4HighPtSpectra_CXX
30 #include "AliPWG4HighPtSpectra.h"
33 #include "TParticle.h"
35 #include "AliMCEvent.h"
36 #include "AliMCEventHandler.h"
37 #include "AliAnalysisManager.h"
38 #include "AliCFContainer.h"
40 #include "AliESDtrack.h"
41 #include "AliESDtrackCuts.h"
42 #include "AliExternalTrackParam.h"
43 #include "AliESDInputHandler.h"
45 using namespace std; //required for resolving the 'cout' symbol
47 ClassImp(AliPWG4HighPtSpectra)
49 //__________________________________________________________________________
50 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra() : AliAnalysisTask("AliPWG4HighPtSpectra", ""),
56 fHistEventsProcessed(0x0)
62 //___________________________________________________________________________
63 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra(const Char_t* name) :
64 AliAnalysisTask(name,""),
68 fTrackCuts(),//new AliESDtrackCuts),
70 fHistEventsProcessed(0x0)
73 // Constructor. Initialization of Inputs and Outputs
75 AliDebug(2,Form("AliPWG4HighPtQAMC","Calling Constructor"));
76 // Input slot #0 works with a TChain ESD
77 DefineInput(0, TChain::Class());
78 DefineOutput(0,TList::Class());
79 DefineOutput(1,AliCFContainer::Class());
82 //___________________________________________________________________________
83 AliPWG4HighPtSpectra& AliPWG4HighPtSpectra::operator=(const AliPWG4HighPtSpectra& c)
86 // Assignment operator
89 AliAnalysisTask::operator=(c) ;
90 fReadAODData = c.fReadAODData ;
91 fCFManager = c.fCFManager;
92 fHistList = c.fHistList;
93 fHistEventsProcessed = c.fHistEventsProcessed;
98 //___________________________________________________________________________
99 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra(const AliPWG4HighPtSpectra& c) :
101 fReadAODData(c.fReadAODData),
102 fCFManager(c.fCFManager),
104 fTrackCuts(c.fTrackCuts),
105 fHistList(c.fHistList),
106 fHistEventsProcessed(c.fHistEventsProcessed)
113 //___________________________________________________________________________
114 AliPWG4HighPtSpectra::~AliPWG4HighPtSpectra() {
118 Info("~AliPWG4HighPtSpectra","Calling Destructor");
119 if (fCFManager) delete fCFManager ;
120 if (fHistEventsProcessed) delete fHistEventsProcessed ;
122 //________________________________________________________________________
123 void AliPWG4HighPtSpectra::ConnectInputData(Option_t *)
127 AliDebug(2,Form(">> AliPWG4HighPtSpectra::ConnectInputData \n"));
128 // printf(">> AliPWG4HighPtSpectra::ConnectInputData \n");
130 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
132 AliDebug(2,Form("ERROR: Could not read chain from input slot 0"));
135 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
138 AliDebug(2,Form("ERROR: Could not get ESDInputHandler"));
140 fESD = esdH->GetEvent();
144 //_________________________________________________
145 void AliPWG4HighPtSpectra::Exec(Option_t *)//UserExec(Option_t *)
148 // Main loop function
150 AliDebug(2,Form(">> AliPWG4HighPtSpectra::Exec \n"));
153 AliDebug(2,Form("ERROR: fESD not available"));
157 // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
158 // This handler can return the current MC event
160 AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
162 AliDebug(2,Form("ERROR: Could not retrieve MC event handler"));
166 AliMCEvent* mcEvent = eventHandler->MCEvent();
168 AliDebug(2,Form("ERROR: Could not retrieve MC event"));
172 AliDebug(2,Form("MC particles: %d", mcEvent->GetNumberOfTracks()));
175 AliDebug(2,Form("ERROR: fESD not available"));
179 AliStack* stack = mcEvent->Stack(); //Particles Stack
181 AliDebug(2,Form("MC particles stack: %d", stack->GetNtrack()));
183 const AliESDVertex *vtx = fESD->GetPrimaryVertex();
186 if (vtx->GetNContributors() < 2) return;
189 if(TMath::Abs(pvtx[2])>10.) return;
191 AliDebug(2,Form("Vertex title %s, status %d, nCont %d\n",vtx->GetTitle(), vtx->GetStatus(), vtx->GetNContributors()));
192 // Need to keep track of evts without vertex
194 Int_t nTracks = fESD->GetNumberOfTracks();
195 AliDebug(2,Form("nTracks %d", nTracks));
197 // AliVEvent* fEvent = fInputEvent ;
200 // Error("UserExec","NO EVENT FOUND!");
204 // //pass the MC evt handler to the cuts that need it
205 // fCFManager->SetEventInfo(fMCEvent);
207 Double_t containerInputRec[1] ;
208 Double_t containerInputTPConly[1] ;
209 Double_t containerInputMC[1] ;
210 //Now go to rec level
211 for (Int_t iTrack = 0; iTrack<nTracks; iTrack++)
213 if(!fESD->GetTrack(iTrack) ) continue;
214 AliESDtrack* track = fESD->GetTrack(iTrack);
215 if(!(AliExternalTrackParam *)track->GetTPCInnerParam()) continue;
216 AliExternalTrackParam *trackTPC = (AliExternalTrackParam *)track->GetTPCInnerParam();
217 if(!track || !trackTPC) continue;
219 Int_t label = TMath::Abs(track->GetLabel());
220 TParticle *particle = stack->Particle(label) ;
221 if(!particle) continue;
225 containerInputRec[0] = track->Pt();
226 containerInputTPConly[0] = trackTPC->Pt();
227 containerInputMC[0] = particle->Pt();
229 if (fTrackCuts->AcceptTrack(track)) {
230 fCFManager->GetParticleContainer()->Fill(containerInputRec,kStepReconstructed);
231 fCFManager->GetParticleContainer()->Fill(containerInputTPConly,kStepReconstructedTPCOnly);
232 fCFManager->GetParticleContainer()->Fill(containerInputMC,kStepReconstructedMC);
234 // if (!fCFManager->CheckParticleCuts(1,track)) continue ;
235 if ( fTrackCuts->AcceptTrack(track) && !stack->IsPhysicalPrimary(label) ) {
236 fCFManager->GetParticleContainer()->Fill(containerInputRec,kStepSecondaries);
237 // int label_mom = TMath::Abs(particle->GetFirstMother());
238 // TParticle *mother = stack->Particle(label_mom);
239 // if(!mother) continue;
240 // cout << "#Daughters mom: " << mother->GetNDaughters() << "\tPDGmom: " << mother->GetPdgCode() << "\tPDGdaughter: " << particle->GetPdgCode() << endl;
245 for(int iPart = 1; iPart<(mcEvent->GetNumberOfTracks()); iPart++)//stack->GetNprimary();
247 // TParticle *part = stack->Particle(iPart);
248 AliMCParticle *mcPart = (AliMCParticle*)mcEvent->GetTrack(iPart);
249 if(!mcPart) continue;
252 containerInputMC[0] = mcPart->Pt();
254 if (!fCFManager->CheckParticleCuts(3,mcPart)) continue ;
258 Float_t trackLengthTPC = mcPart->GetTPCTrackLength(fESD->GetMagneticField(),0.1,counter,3.0);
259 // printf("TPCTrackLength %f \t %f \n", TPCTrackLength,fESD->GetMagneticField());
261 if(trackLengthTPC>80.) fCFManager->GetParticleContainer()->Fill(containerInputMC,kStepMCtrackable) ;
265 fHistEventsProcessed->Fill(0);
266 PostData(0,fHistList);
267 PostData(1,fCFManager->GetParticleContainer());
272 //___________________________________________________________________________
273 void AliPWG4HighPtSpectra::Terminate(Option_t*)
275 // The Terminate() function is the last function to be called during
276 // a query. It always runs on the client, it can be used to present
277 // the results graphically or save the results to file.
282 //___________________________________________________________________________
283 void AliPWG4HighPtSpectra::CreateOutputObjects() {
284 //HERE ONE CAN CREATE OUTPUT OBJECTS, IN PARTICULAR IF THE OBJECT PARAMETERS DON'T NEED
285 //TO BE SET BEFORE THE EXECUTION OF THE TASK
287 AliDebug(2,Form("CreateOutputObjects","CreateOutputObjects of task %s", GetName()));
289 Bool_t oldStatus = TH1::AddDirectoryStatus();
290 TH1::AddDirectory(kFALSE);
293 fHistList = new TList();
296 fHistEventsProcessed = new TH1I("fHistEventsProcessed","",1,0,1) ;
297 fHistList->Add(fHistEventsProcessed);
299 TH1::AddDirectory(oldStatus);