don't lie in the log!
[u/mrichter/AliRoot.git] / PWGPP / EvTrkSelection / AliFakeTrackTask.cxx
1 #include "AliFakeTrackTask.h"
2 #include "AliAnalysisManager.h"
3
4 #include "AliESDEvent.h"
5
6
7 //#include "AliESDtrack.h"
8
9 #include "AliInputEventHandler.h"
10 #include "AliStack.h"
11 //#include "AliMCEventHandler.h"
12 #include "AliMCEvent.h"
13
14 #include "TH1F.h"
15 #include "TH2F.h"
16 #include "TMath.h"
17 #include "TH3F.h"
18 //#include "TMCProcess.h"
19 #include "AliVEvent.h"
20
21 #include "AliESDtrackCuts.h"
22 //#include "AliESDpidCuts.h"
23 //#include "AliESDpid.h"
24 #include "AliCentrality.h"
25 #include <iostream>
26 #include "TChain.h"
27
28 using namespace std;
29
30 ClassImp(AliFakeTrackTask)
31
32 AliFakeTrackTask::AliFakeTrackTask(const char *name ):
33 AliAnalysisTaskSE(name),fESD(0),
34 fptvsTPCsignalvsITSsignalAll(0),fptvsTPCsignalvsITSsignalGlobalgood(0), 
35 fptvsTPCsignalvsITSsignalGlobalfake(0),fptvsTPCsignalvsITSsignalTPCfake(0),
36 fptvsTPCsignalvsITSsignalITSfake(0),ffakestat(0),
37 ftrackcuts(0),flistout(0)       
38 {
39          DefineInput(0, TChain::Class());
40         DefineOutput(1, TList::Class());
41 }
42 //___________________________________________________________________________
43 AliFakeTrackTask:: ~AliFakeTrackTask()
44 {
45         if(fptvsTPCsignalvsITSsignalAll)
46                 delete fptvsTPCsignalvsITSsignalAll;
47         if(fptvsTPCsignalvsITSsignalGlobalgood)
48                 delete fptvsTPCsignalvsITSsignalGlobalgood;
49         if(fptvsTPCsignalvsITSsignalGlobalfake)
50                 delete fptvsTPCsignalvsITSsignalGlobalfake;
51         if(fptvsTPCsignalvsITSsignalTPCfake)
52                 delete  fptvsTPCsignalvsITSsignalTPCfake;
53         if(fptvsTPCsignalvsITSsignalITSfake)
54                 delete fptvsTPCsignalvsITSsignalITSfake;
55         if(ffakestat)
56                 delete ffakestat;       
57         if(ftrackcuts)
58                 delete  ftrackcuts;
59         if(flistout)
60                 delete flistout;
61
62 }
63 //____________________________________________________________________
64 void AliFakeTrackTask::UserCreateOutputObjects()
65 {
66         flistout=new TList();
67         flistout->SetOwner(kTRUE);
68         fptvsTPCsignalvsITSsignalAll=new TH3F("ptvsTPCsignalvsITSsignalAll","ptvsTPCsignalvsITSsignalAll",50,0,5.0,200,0,1000,200,0,1000);
69         fptvsTPCsignalvsITSsignalGlobalgood=new TH3F("ptvsTPCsignalvsITSsignalGlobalgood","ptvsTPCsignalvsITSsignalGlobalgood",50,0,5.0,200,0,1000,200,0,1000);
70         fptvsTPCsignalvsITSsignalGlobalfake=new TH3F("ptvsTPCsignalvsITSsignalGlobalfake","ptvsTPCsignalvsITSsignalGlobalfake",50,0,5.0,200,0,1000,200,0,1000);
71         fptvsTPCsignalvsITSsignalTPCfake=new TH3F("ptvsTPCsignalvsITSsignalTPCfake","ptvsTPCsignalvsITSsignalTPCfake",50,0,5.0,200,0,1000,200,0,1000);
72         fptvsTPCsignalvsITSsignalITSfake=new TH3F("ptvsTPCsignalvsITSsignalITSfake","ptvsTPCsignalvsITSsignalITSfake",50,0,5.0,200,0,1000,200,0,1000);
73         ffakestat= new TH1F("fake stats","fake stats",8,-0.5,7.5);
74         flistout->Add(fptvsTPCsignalvsITSsignalAll);
75         flistout->Add(fptvsTPCsignalvsITSsignalGlobalgood);
76         flistout->Add(fptvsTPCsignalvsITSsignalGlobalfake);
77         flistout->Add(fptvsTPCsignalvsITSsignalTPCfake);
78         flistout->Add(fptvsTPCsignalvsITSsignalITSfake);
79         flistout->Add(ffakestat);
80         PostData(1,  flistout); 
81
82 }
83 //_______________________________________________________________________
84 void AliFakeTrackTask::UserExec(Option_t *)
85 {
86         fESD = dynamic_cast<AliESDEvent*> (InputEvent());
87         if (!fESD) 
88         {
89                 Printf("ERROR: fESD not available");
90                 return;
91         }
92         //UInt_t isSelected=0;
93 /*      if(((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler())))
94                 isSelected=((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
95         if(!(isSelected&AliVEvent::kMB))
96         {
97                  PostData(1,  flistout);
98                  return;
99         }*/
100
101         const AliESDVertex *vertex = 0x0;
102         vertex = fESD->GetPrimaryVertexTracks();
103         if(vertex->GetNContributors()<1) 
104         {
105                 // SPD vertex
106                 vertex = fESD->GetPrimaryVertexSPD();
107                 if(vertex->GetNContributors()<1) 
108                 {
109                         //Printf("No good  Vertex.........\n");
110                         PostData(1,  flistout);
111                         return;                 
112                 }       
113         }
114         if(fESD->IsPileupFromSPDInMultBins())
115         {
116                 PostData(1,  flistout);
117                 return;
118         }               
119         if(TMath::Abs(vertex ->GetZ())>10.0)
120         {
121                         PostData(1,  flistout);
122                         return;
123         }       
124
125         if(!fPIDResponse) 
126         {
127                 AliAnalysisManager *man = AliAnalysisManager::GetAnalysisManager();
128                 AliInputEventHandler* inputHandler = (AliInputEventHandler*)(man->GetInputEventHandler());
129                 fPIDResponse = inputHandler->GetPIDResponse();
130         }
131
132         AliStack* stack=0x0;
133         AliMCEvent* mcEvent  = (AliMCEvent*) MCEvent();
134         if(mcEvent)     
135                 stack = mcEvent->Stack();
136         
137         Int_t nTracks=fESD->GetNumberOfTracks();
138         for (int i=0;i<nTracks;i++)
139         {
140                 AliESDtrack* esdtrack=fESD->GetTrack(i);
141                 //Printf("%d %d",i,nTracks);
142                 if(!ftrackcuts->AcceptTrack(esdtrack))
143                         continue;
144                 Int_t nSDDSSD=0;
145                 for (int j=0;j<4;j++)
146                 {
147                         if(esdtrack->HasPointOnITSLayer(i))
148                                 nSDDSSD++;
149                 }        
150                 //Printf("%d",nSDDSSD);
151
152                 if(nSDDSSD<3)
153                         continue;
154                 Float_t pt=esdtrack->Pt();
155                 Float_t signalTPC=esdtrack->GetTPCsignal();
156                 Float_t singalITS=esdtrack->GetITSsignal();
157                 Int_t faketype=0;
158                 fptvsTPCsignalvsITSsignalAll->Fill(pt,signalTPC,singalITS);
159                 if(!stack)
160                         continue;
161                 if(esdtrack->GetLabel()>0)
162                         fptvsTPCsignalvsITSsignalGlobalgood->Fill(pt,signalTPC,singalITS);
163                 else
164                 {
165                         fptvsTPCsignalvsITSsignalGlobalfake->Fill(pt,signalTPC,singalITS);
166                         faketype+=1;
167
168                 }       
169                 if(esdtrack->GetITSLabel()<0)
170                 {
171                         fptvsTPCsignalvsITSsignalITSfake->Fill(pt,signalTPC,singalITS);
172                         faketype+=2;
173                 }
174                 if(esdtrack->GetTPCLabel()<0)
175                 {
176                         fptvsTPCsignalvsITSsignalTPCfake->Fill(pt,signalTPC,singalITS);
177
178                         faketype+=4;
179                 }
180                 ffakestat->Fill(faketype);
181                 
182
183         }       
184         PostData(1,  flistout);
185
186