]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/AliGenInfoTask.cxx
TPC scaled resolution (Jacek Otwinowski)
[u/mrichter/AliRoot.git] / PWG1 / AliGenInfoTask.cxx
1 //
2 // This class is the task for connecting together 
3 // MC information and the RC information 
4 //
5 // The task is a wrapper over two components
6 // AliGenInfoMaker
7 // AliESDRecInfoMaker.h
8
9 // ROOT includes
10 #include <TChain.h>
11 #include <TMath.h>
12
13 // ALIROOT includes
14 #include <AliAnalysisManager.h>
15 #include <AliESDInputHandler.h>
16 #include "AliStack.h"
17 #include "AliMCEvent.h"
18 #include "AliMCEventHandler.h"
19
20 #include <AliESD.h>
21 #include "AliGenInfoTask.h"
22 #include "AliGenInfoMaker.h"
23 #include "AliHelix.h"
24
25 // STL includes
26 #include <iostream>
27
28 using namespace std;
29
30 ClassImp(AliGenInfoTask)
31
32 //________________________________________________________________________
33 AliGenInfoTask::AliGenInfoTask() : 
34   AliAnalysisTask(), 
35   fGenMaker(0),
36   fDebug(0),
37   fESD(0), 
38   fESDfriend(0), 
39   fListOfHists(0),
40   fMaxTracks(0),      // Max tracks in histogram
41   hESDTracks(0) ,     //! N ESD tracks
42   hGoodTracks(0)     //! GOOD tracks
43 {
44   //
45   // Default constructor (should not be used)
46   //
47   fDebug = 0;
48   SetMaxTracks();
49 }
50
51 AliGenInfoTask::AliGenInfoTask(const AliGenInfoTask& /*info*/) : 
52   AliAnalysisTask(), 
53   fGenMaker(0),
54   fDebug(0),
55   fESD(0), 
56   fESDfriend(0), 
57   fListOfHists(0),
58   fMaxTracks(0),      // Max tracks in histogram
59   hESDTracks(0) ,     //! N ESD tracks
60   hGoodTracks(0)     //! GOOD tracks
61 {
62   //
63   // Default constructor 
64   //
65   fDebug = 0;
66   SetMaxTracks();
67 }
68
69
70
71 //________________________________________________________________________
72 AliGenInfoTask::AliGenInfoTask(const char *name) : 
73   AliAnalysisTask(name, "AliGenInfoTask"), 
74   fGenMaker(0), 
75   fDebug(0),
76   fESD(0), 
77   fESDfriend(0), 
78   fListOfHists(0),
79   fMaxTracks(0),      // Max tracks in histogram
80   hESDTracks(0) ,     //! N ESD tracks
81   hGoodTracks(0)     //! GOOD tracks
82 {
83   //
84   // Normal constructor
85   //
86   fGenMaker = new AliGenInfoMaker;
87   fGenMaker->SetIO();
88   // Input slot #0 works with a TChain
89   DefineInput(0, TChain::Class());
90   // Output slot #0 writes into a TList
91   DefineOutput(0, TList::Class());
92   
93   fDebug = 0;
94   SetMaxTracks();
95 }
96
97 //________________________________________________________________________
98 void AliGenInfoTask::ConnectInputData(Option_t *) 
99 {
100   //
101   // Connect the input data
102   //
103   if(fDebug>3)
104     cout << "AnalysisTaskTPCCluster::ConnectInputData()" << endl;
105
106   AliESDInputHandler* esdH = (AliESDInputHandler*) 
107     ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
108   fESD = esdH->GetEvent();
109
110   if(fESD==0) {
111     
112     cout << endl << "WARNING: NO ESD event found" << endl << endl;
113   } else {
114
115     fESDfriend = 
116       (AliESDfriend*)fESD->FindListObject("AliESDfriend");  
117     
118     if(fESDfriend==0) {
119       
120       cout << endl << "WARNING: NO ESD friend found" << endl << endl;
121     }
122   }
123 }
124
125 //________________________________________________________________________
126 void AliGenInfoTask::CreateOutputObjects() 
127 {
128   //
129   // Connect the output objects
130   //
131   if(fDebug>3)
132     cout << "AnalysisTaskTPCCluster::CreateOutputObjects()" << endl;
133   
134 //    OpenFile(0);
135 //   fListOfHists = new TList();
136   
137 //   hESDTracks = 
138 //     new TH1F("hESDTracks", 
139 //           "Number of ESD tracks per event; N ESD tracks; Counts", 
140 //           TMath::Min(fMaxTracks, 100), 0, fMaxTracks);
141 //   fListOfHists->Add(hESDTracks);
142
143 //   hGoodTracks = 
144 //     new TH1F("hGoodTracks", 
145 //           "Number of Good tracks per event; N good tracks; Counts", 
146 //           TMath::Min(fMaxTracks, 100), 0, fMaxTracks);
147 //   fListOfHists->Add(hGoodTracks);
148 }
149
150
151 //________________________________________________________________________
152 void AliGenInfoTask::Exec(Option_t *) {
153   //
154   // Execute analysis for current event 
155   // For the moment I require that mcTruth is there!  I am afraid to
156   // get out of sync if it is missing for some events since I use the
157   // number of MC events for normalisation
158   //
159
160   if(fDebug>3)
161     cout << "AliGenInfoTask::Exec()" << endl;
162
163   if (fESD) {
164     //    AliHelix::SetBz(fESD->GetMagneticField());   // Enable after commit of AliHelix
165   }
166   
167   // Monte carlo info
168   AliMCEventHandler* mcinfo = (AliMCEventHandler*) (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());  
169   // If MC has been connected   
170   
171   if (!mcinfo){
172     cout << "Not MC info\n" << endl;
173   }
174   fGenMaker->ProcessEvent(mcinfo);
175
176
177
178   if(fESD==0 || fESDfriend==0) {
179     
180     cout << "AliGenInfoTask::Exec(): WARNING: fESD=" << fESD 
181          << ", fESDfriend=" << fESDfriend << endl;
182     // Post final data. It will be written to a file with option "RECREATE"
183     PostData(0, fListOfHists);
184     return;
185   }
186  
187   fESD->SetESDfriend(fESDfriend);
188   const Int_t nESDTracks = fESD->GetNumberOfTracks();
189   
190   if(fDebug>0){
191     cout << " AliGenIfoTask::Exec() Number of ESD tracks: " << nESDTracks << endl;
192   }
193   if ( nESDTracks != fESDfriend->GetNumberOfTracks() ) {
194      AliWarning("Number of Tracks differs from Number of Friend-Tracks!");
195      printf("Number of tracks: %i, number of friend tracks: %i \n", nESDTracks, fESDfriend->GetNumberOfTracks());
196      return;
197   }
198 //   // Post final data. It will be written to a file with option "RECREATE"
199   PostData(0, fListOfHists);
200 }      
201
202 //________________________________________________________________________
203 Int_t AliGenInfoTask::FillTrackHistograms(Int_t nTracks, AliESDtrack* track, AliESDfriendTrack* friendTrack, AliTPCseed* seed) {
204   //
205   // This method should be overloaded and used to make cuts on tracks
206   // and fill histograms. 
207   // return 0 if track was rejected, 1 if accepted
208   //
209
210   if(nTracks && track && friendTrack && seed)
211     return 1;
212   else
213     return 0;
214 }
215
216 //________________________________________________________________________
217 void AliGenInfoTask::Terminate(Option_t *) {
218     //
219     // Terminate loop
220     //
221   if(fDebug>3)
222     printf("AliGenInfoTask: Terminate() \n");  
223   fGenMaker->CloseOutputFile();
224 }