]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/JetTasks/AliPWG4HighPtSpectra.cxx
rmoved printout
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliPWG4HighPtSpectra.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 // 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
21 // can be calculated
22 //-----------------------------------------------------------------------
23 // Author : Marta Verweij - UU
24 //-----------------------------------------------------------------------
25
26
27 #ifndef ALIPWG4HighPtSpectra_CXX
28 #define ALIPWG4HighPtSpectra_CXX
29
30 #include "AliPWG4HighPtSpectra.h"
31
32 #include "AliStack.h"
33 #include "TParticle.h"
34 #include "TH1I.h"
35 #include "AliMCEvent.h"
36 #include "AliMCEventHandler.h"
37 #include "AliAnalysisManager.h"
38 #include "AliCFContainer.h"
39 #include "TChain.h"
40 #include "AliESDtrack.h"
41 #include "AliESDtrackCuts.h"
42 #include "AliExternalTrackParam.h"
43 #include "AliESDInputHandler.h"
44
45 using namespace std; //required for resolving the 'cout' symbol
46
47 ClassImp(AliPWG4HighPtSpectra)
48
49 //__________________________________________________________________________
50 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra() : AliAnalysisTask("AliPWG4HighPtSpectra", ""), 
51   fReadAODData(0),
52   fCFManager(0x0),
53   fESD(0),
54   fTrackCuts(0),
55   fHistList(0),
56   fHistEventsProcessed(0x0)
57 {
58   //
59   //Default ctor
60   //
61 }
62 //___________________________________________________________________________
63 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra(const Char_t* name) :
64   AliAnalysisTask(name,""),
65   fReadAODData(0),
66   fCFManager(0x0),
67   fESD(0),
68   fTrackCuts(),//new AliESDtrackCuts),
69   fHistList(0),
70   fHistEventsProcessed(0x0)
71 {
72   //
73   // Constructor. Initialization of Inputs and Outputs
74   //
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());
80 }
81
82 //___________________________________________________________________________
83 AliPWG4HighPtSpectra& AliPWG4HighPtSpectra::operator=(const AliPWG4HighPtSpectra& c) 
84 {
85   //
86   // Assignment operator
87   //
88   if (this!=&c) {
89     AliAnalysisTask::operator=(c) ;
90     fReadAODData = c.fReadAODData ;
91     fCFManager  = c.fCFManager;
92     fHistList = c.fHistList;
93     fHistEventsProcessed = c.fHistEventsProcessed;
94   }
95   return *this;
96 }
97
98 //___________________________________________________________________________
99 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra(const AliPWG4HighPtSpectra& c) :
100   AliAnalysisTask(c),
101   fReadAODData(c.fReadAODData),
102   fCFManager(c.fCFManager),
103   fESD(c.fESD),
104   fTrackCuts(c.fTrackCuts),
105   fHistList(c.fHistList),
106   fHistEventsProcessed(c.fHistEventsProcessed)
107 {
108   //
109   // Copy Constructor
110   //
111 }
112
113 //___________________________________________________________________________
114 AliPWG4HighPtSpectra::~AliPWG4HighPtSpectra() {
115   //
116   //destructor
117   //
118   Info("~AliPWG4HighPtSpectra","Calling Destructor");
119   if (fCFManager)           delete fCFManager ;
120   if (fHistEventsProcessed) delete fHistEventsProcessed ;
121 }
122 //________________________________________________________________________
123 void AliPWG4HighPtSpectra::ConnectInputData(Option_t *) 
124 {
125   // Connect ESD here
126   // Called once
127   AliDebug(2,Form(">> AliPWG4HighPtSpectra::ConnectInputData \n"));
128   //  printf(">> AliPWG4HighPtSpectra::ConnectInputData \n");
129
130   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
131   if (!tree) {
132     AliDebug(2,Form("ERROR: Could not read chain from input slot 0"));
133   } else {
134     
135     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
136     
137     if (!esdH) {
138       AliDebug(2,Form("ERROR: Could not get ESDInputHandler"));
139     } else
140       fESD = esdH->GetEvent();
141   }
142  
143 }
144 //_________________________________________________
145 void AliPWG4HighPtSpectra::Exec(Option_t *)//UserExec(Option_t *)
146 {
147   //
148   // Main loop function
149   //
150   AliDebug(2,Form(">> AliPWG4HighPtSpectra::Exec \n"));  
151
152   if (!fESD) {
153     AliDebug(2,Form("ERROR: fESD not available"));
154     return;
155   }
156
157   // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
158   // This handler can return the current MC event
159   AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
160   AliStack* stack = 0x0;
161   AliMCEvent* mcEvent = 0x0;
162
163   if(eventHandler) {
164     mcEvent = eventHandler->MCEvent();
165     if (!mcEvent) {
166       AliDebug(2,Form("ERROR: Could not retrieve MC event"));
167       return;
168     }
169     
170     AliDebug(2,Form("MC particles: %d", mcEvent->GetNumberOfTracks()));
171     
172     stack = mcEvent->Stack();                //Particles Stack
173     
174     AliDebug(2,Form("MC particles stack: %d", stack->GetNtrack()));
175   }
176   
177   if (!fESD) {
178     AliDebug(2,Form("ERROR: fESD not available"));
179     return;
180   }
181
182   const AliESDVertex *vtx = fESD->GetPrimaryVertex();
183
184   // Need vertex cut
185   if (vtx->GetNContributors() < 2) return;
186   double pvtx[3];
187   vtx->GetXYZ(pvtx);
188   if(TMath::Abs(pvtx[2])>10.) return;
189
190   AliDebug(2,Form("Vertex title %s, status %d, nCont %d\n",vtx->GetTitle(), vtx->GetStatus(), vtx->GetNContributors()));
191   // Need to keep track of evts without vertex
192
193   Int_t nTracks = fESD->GetNumberOfTracks();
194   AliDebug(2,Form("nTracks %d", nTracks));
195
196   Double_t containerInputRec[1] ;
197   Double_t containerInputTPConly[1] ;
198   Double_t containerInputMC[1] ;
199   //Now go to rec level
200   for (Int_t iTrack = 0; iTrack<nTracks; iTrack++) 
201     {   
202       if(!fESD->GetTrack(iTrack) ) continue;
203       AliESDtrack* track = fESD->GetTrack(iTrack);
204       if(!(AliExternalTrackParam *)track->GetTPCInnerParam()) continue;
205       AliExternalTrackParam *trackTPC = (AliExternalTrackParam *)track->GetTPCInnerParam();
206       if(!track || !trackTPC) continue;
207
208     
209       //fill the container
210       containerInputRec[0] = track->Pt();
211       containerInputTPConly[0] = trackTPC->Pt();
212
213       if (fTrackCuts->AcceptTrack(track)) {
214         fCFManager->GetParticleContainer()->Fill(containerInputRec,kStepReconstructed);
215         fCFManager->GetParticleContainer()->Fill(containerInputTPConly,kStepReconstructedTPCOnly);
216         
217         //Only fill the secondary particle container if MC information is available
218         if(eventHandler) {
219           Int_t label = TMath::Abs(track->GetLabel());
220           TParticle *particle = stack->Particle(label) ;
221           if(!particle) continue;
222           containerInputMC[0] = particle->Pt();      
223           fCFManager->GetParticleContainer()->Fill(containerInputMC,kStepReconstructedMC);
224           if (!stack->IsPhysicalPrimary(label) ) {
225             fCFManager->GetParticleContainer()->Fill(containerInputRec,kStepSecondaries);
226           }
227         }
228       }
229       
230     }
231
232   if(eventHandler) {
233     for(int iPart = 1; iPart<(mcEvent->GetNumberOfTracks()); iPart++)//stack->GetNprimary();
234       {
235         AliMCParticle *mcPart  = (AliMCParticle*)mcEvent->GetTrack(iPart);
236         if(!mcPart) continue;
237         
238         //fill the container
239         containerInputMC[0] = mcPart->Pt();
240         
241         if (!fCFManager->CheckParticleCuts(3,mcPart)) continue ;
242         
243         int counter;
244         
245         Float_t trackLengthTPC = mcPart->GetTPCTrackLength(fESD->GetMagneticField(),0.1,counter,3.0);
246         
247         if(trackLengthTPC>80.) fCFManager->GetParticleContainer()->Fill(containerInputMC,kStepMCtrackable) ;
248         
249       }
250   }
251
252    fHistEventsProcessed->Fill(0);
253    PostData(0,fHistList);
254    PostData(1,fCFManager->GetParticleContainer());
255
256 }
257
258
259 //___________________________________________________________________________
260 void AliPWG4HighPtSpectra::Terminate(Option_t*)
261 {
262   // The Terminate() function is the last function to be called during
263   // a query. It always runs on the client, it can be used to present
264   // the results graphically or save the results to file.
265
266
267 }
268
269 //___________________________________________________________________________
270 void AliPWG4HighPtSpectra::CreateOutputObjects() {
271   //HERE ONE CAN CREATE OUTPUT OBJECTS, IN PARTICULAR IF THE OBJECT PARAMETERS DON'T NEED
272   //TO BE SET BEFORE THE EXECUTION OF THE TASK
273   //
274   AliDebug(2,Form("CreateOutputObjects","CreateOutputObjects of task %s", GetName()));
275
276   OpenFile(0);
277   fHistList = new TList();
278   //slot #1
279   //  OpenFile(0);
280   fHistEventsProcessed = new TH1I("fHistEventsProcessed","",1,0,1) ;
281   fHistList->Add(fHistEventsProcessed);
282
283 }
284
285 #endif