]> git.uio.no Git - u/mrichter/AliRoot.git/blob - CORRFW/test/AliCFTaskForUnfolding.cxx
update for compilation
[u/mrichter/AliRoot.git] / CORRFW / test / AliCFTaskForUnfolding.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 // Task to prepare efficiency and response matrix for unfolding
18 //-----------------------------------------------------------------------
19 // Author : R. Vernet, INFN - Catania (it)
20 //-----------------------------------------------------------------------
21
22
23 #include "TStyle.h"
24 #include "AliCFTaskForUnfolding.h"
25 #include "TCanvas.h"
26 #include "AliStack.h"
27 #include "TParticle.h"
28 #include "TH1I.h"
29 #include "AliMCEvent.h"
30 #include "AliAnalysisManager.h"
31 #include "AliESDEvent.h"
32 #include "AliAODEvent.h"
33 #include "AliCFManager.h"
34 #include "AliCFCutBase.h"
35 #include "AliCFContainer.h"
36 #include "TChain.h"
37 #include "AliESDtrack.h"
38 #include "AliLog.h"
39 #include "THnSparse.h"
40 #include "TH2D.h"
41
42 ClassImp(AliCFTaskForUnfolding)
43
44 //__________________________________________________________________________
45 AliCFTaskForUnfolding::AliCFTaskForUnfolding() :
46   fCFManager(0x0),
47   fHistEventsProcessed(0x0),
48   fCorrelation(0x0)
49 {
50   //
51   //Default ctor
52   //
53 }
54 //___________________________________________________________________________
55 AliCFTaskForUnfolding::AliCFTaskForUnfolding(const Char_t* name) :
56   AliAnalysisTaskSE(name),
57   fCFManager(0x0),
58   fHistEventsProcessed(0x0),
59   fCorrelation(0x0)
60 {
61   //
62   // Constructor. Initialization of Inputs and Outputs
63   //
64   Info("AliCFTaskForUnfolding","Calling Constructor");
65
66   /*
67     DefineInput(0) and DefineOutput(0)
68     are taken care of by AliAnalysisTaskSE constructor
69   */
70   DefineOutput(1,TH1I::Class());
71   DefineOutput(2,AliCFContainer::Class());
72   DefineOutput(3,THnSparseD::Class());
73 }
74
75 //___________________________________________________________________________
76 AliCFTaskForUnfolding::~AliCFTaskForUnfolding() {
77   //
78   //destructor
79   //
80   Info("~AliCFTaskForUnfolding","Calling Destructor");
81   if (fCFManager)           delete fCFManager ;
82   if (fHistEventsProcessed) delete fHistEventsProcessed ;
83   if (fCorrelation)         delete fCorrelation ;
84 }
85
86 //_________________________________________________
87 void AliCFTaskForUnfolding::UserExec(Option_t *)
88 {
89   //
90   // Main loop function
91   //
92   AliInfo("") ;
93
94   AliVEvent*    fEvent = fInputEvent ;
95   AliVParticle* track ;
96   
97   if (!fEvent) {
98     Error("UserExec","NO EVENT FOUND!");
99     return;
100   }
101
102   if (!fMCEvent) Error("UserExec","NO MC INFO FOUND");
103   
104   //pass the MC evt handler to the cuts that need it 
105   fCFManager->SetMCEventInfo(fMCEvent);
106
107   // MC-event selection
108   Double_t containerInput[2] ;
109         
110   //loop on the MC event
111   for (Int_t ipart=0; ipart<fMCEvent->GetNumberOfTracks(); ipart++) { 
112     AliMCParticle *mcPart  = (AliMCParticle*)fMCEvent->GetTrack(ipart);
113     
114     if (!fCFManager->CheckParticleCuts(0,mcPart)) continue;
115     containerInput[0] = (Float_t)mcPart->Pt();
116     containerInput[1] = (Float_t)mcPart->Eta();
117     fCFManager->GetParticleContainer()->Fill(containerInput,0);
118   }    
119
120   //Now go to rec level
121   for (Int_t iTrack = 0; iTrack<fEvent->GetNumberOfTracks(); iTrack++) {
122     
123     track = fEvent->GetTrack(iTrack);
124     if (!fCFManager->CheckParticleCuts(1,track)) continue;
125     
126     Int_t label = track->GetLabel();
127     if (label<0) continue;
128     AliMCParticle* mcPart = (AliMCParticle*)fMCEvent->GetTrack(label);
129     // check if this track was part of the signal
130     if (!fCFManager->CheckParticleCuts(0,mcPart)) continue;
131
132     //fill the container
133     Double_t mom[3];
134     track->PxPyPz(mom);
135     Double_t pt=TMath::Sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
136     containerInput[0] = pt;
137     containerInput[1] = track->Eta();
138     fCFManager->GetParticleContainer()->Fill(containerInput,1) ;
139     containerInput[0] = mcPart->Pt();
140     containerInput[1] = mcPart->Eta();
141     fCFManager->GetParticleContainer()->Fill(containerInput,2);
142     
143     Double_t fill[4]; //fill response matrix
144     // dimensions 0&1 : pt,eta (Rec)
145     fill[0] = pt ;
146     fill[1] = track->Eta();
147     // dimensions 2&3 : pt,eta (MC)
148     fill[2] = mcPart->Pt();
149     fill[3] = mcPart->Eta();
150     fCorrelation->Fill(fill);
151   }
152   
153   fHistEventsProcessed->Fill(0);
154
155   /* PostData(0) is taken care of by AliAnalysisTaskSE */
156   PostData(1,fHistEventsProcessed) ;
157   PostData(2,fCFManager->GetParticleContainer()) ;
158   PostData(3,fCorrelation) ;
159 }
160
161
162 //___________________________________________________________________________
163 void AliCFTaskForUnfolding::Terminate(Option_t*)
164 {
165   // The Terminate() function is the last function to be called during
166   // a query. It always runs on the client, it can be used to present
167   // the results graphically or save the results to file.
168
169   Info("Terminate","");
170   AliAnalysisTaskSE::Terminate();
171
172   gStyle->SetPalette(1);
173
174   //draw some example plots....
175
176   AliCFContainer *cont= dynamic_cast<AliCFContainer*> (GetOutputData(2));
177   TH2D* h00 =   cont->ShowProjection(0,1,0) ;
178   TH2D* h01 =   cont->ShowProjection(0,1,1) ;
179   THnSparseD* hcorr = dynamic_cast<THnSparseD*> (GetOutputData(3));
180
181   TCanvas * c =new TCanvas("c","",800,400);
182   c->Divide(2,1);
183   c->cd(1);
184   h00->Draw("text");
185   c->cd(2);
186   h01->Draw("text");
187   c->SaveAs("spectra.eps");
188
189   TCanvas * c2 =new TCanvas("c2","",800,400);
190   c2->Divide(2,1);
191   c2->cd(1);
192   hcorr->Projection(0,2)->Draw("text");
193   c2->cd(2);
194   hcorr->Projection(1,3)->Draw("text");
195   c2->SaveAs("correlation.eps");
196 }
197
198
199 //___________________________________________________________________________
200 void AliCFTaskForUnfolding::UserCreateOutputObjects() {
201   //HERE ONE CAN CREATE OUTPUT OBJECTS, IN PARTICULAR IF THE OBJECT PARAMETERS DON'T NEED
202   //TO BE SET BEFORE THE EXECUTION OF THE TASK
203   //
204   Info("CreateOutputObjects","CreateOutputObjects of task %s", GetName());
205
206   //slot #1
207   OpenFile(1);
208   fHistEventsProcessed = new TH1I("fHistEventsProcessed","",1,0,1) ;
209
210 //   OpenFile(2);
211 //   OpenFile(3);
212 }
213