]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ESDCheck/AliHMPIDQATask.cxx
Adding OpenFile in CreateOutput (Yves)
[u/mrichter/AliRoot.git] / ESDCheck / AliHMPIDQATask.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 /* $Id$ */
17
18 //_________________________________________________________________________
19 // An analysis task to check the HMPID data in simulated data
20 //
21 //*-- Annalisa Mastroserio
22 //////////////////////////////////////////////////////////////////////////////
23
24 #include <TCanvas.h>
25 #include <TChain.h>
26 #include <TF1.h>
27 #include <TFile.h> 
28 #include <TH1F.h>
29 #include <TH2F.h>
30 #include <TLegend.h> 
31 #include <TROOT.h>
32 #include <TVector3.h> 
33
34 #include "AliHMPIDQATask.h" 
35 #include "AliESD.h" 
36 #include "AliLog.h"
37 #include "AliPID.h"
38
39 //______________________________________________________________________________
40 AliHMPIDQATask::AliHMPIDQATask(const char *name) : 
41   AliAnalysisTask(name,""),  
42   fChain(0),
43   fESD(0), 
44   fhHMPIDCkovP(0),
45   fhHMPIDMipXY(0),
46   fhHMPIDDifXY(0),
47   fhHMPIDSigP(0)
48 {
49   // Constructor.
50   // Input slot #0 works with an Ntuple
51   DefineInput(0, TChain::Class());
52   // Output slot #0 writes into a TH1 container
53   DefineOutput(0,  TObjArray::Class()) ; 
54
55   Int_t i ; 
56   for(i = 0 ; i < 5 ; i++) 
57     fhHMPIDProb[i]=0;
58 }
59
60 //______________________________________________________________________________
61 AliHMPIDQATask::~AliHMPIDQATask()
62 {
63   // dtor
64   fOutputContainer->Clear() ; 
65   delete fOutputContainer ; 
66   
67   delete fhHMPIDCkovP ;  
68   delete fhHMPIDMipXY ;  
69   delete fhHMPIDDifXY ;  
70   delete fhHMPIDSigP ;   
71   delete [] fhHMPIDProb ;
72 }
73
74 //______________________________________________________________________________
75 void AliHMPIDQATask::ConnectInputData(const Option_t*)
76 {
77   // Initialisation of branch container and histograms 
78     
79   AliInfo(Form("*** Initialization of %s", GetName())) ; 
80   
81   // Get input data
82   fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
83   if (!fChain) {
84     AliError(Form("Input 0 for %s not found\n", GetName()));
85     return ;
86   }
87   
88   // One should first check if the branch address was taken by some other task
89   char ** address = (char **)GetBranchAddress(0, "ESD");
90   if (address) {
91     fESD = (AliESD*)(*address);
92   } else {
93     fESD = new AliESD();
94     SetBranchAddress(0, "ESD", &fESD);
95   }
96 }
97
98 //________________________________________________________________________
99 void AliHMPIDQATask::CreateOutputObjects()
100 {  
101   // create histograms 
102
103   OpenFile(0) ; 
104
105   fhHMPIDCkovP    = new TH2F("CkovP" , "#theta_{c}, [rad];P, [GeV]", 150,   0,  7  ,100, -3, 1); 
106   fhHMPIDSigP     = new TH2F("SigP"  ,"#sigma_{#theta_c}"          , 150,   0,  7  ,100, 0, 1e20);
107   fhHMPIDMipXY    = new TH2F("MipXY" ,"mip position"               , 260,   0,130  ,252,0,126); 
108   fhHMPIDDifXY    = new TH2F("DifXY" ,"diff"                       , 260, -10, 10  ,252,-10,10); 
109   
110   fhHMPIDProb[0] = new TH1F("PidE" ,"PID: e yellow #mu magenta"  ,100,0,1); 
111   fhHMPIDProb[0]->SetLineColor(kYellow);
112   fhHMPIDProb[1] = new TH1F("PidMu","pid of #mu"                 ,100,0,1); 
113   fhHMPIDProb[1]->SetLineColor(kMagenta);
114   fhHMPIDProb[2] = new TH1F("PidPi","PID: #pi red K green p blue",100,0,1); 
115   fhHMPIDProb[2]->SetLineColor(kRed);
116   fhHMPIDProb[3] = new TH1F("PidK" ,"pid of K"                   ,100,0,1); 
117   fhHMPIDProb[3]->SetLineColor(kGreen);
118   fhHMPIDProb[4] = new TH1F("PidP" ,"pid of p"                   ,100,0,1); 
119   fhHMPIDProb[4]->SetLineColor(kBlue);
120  
121
122   
123   // create output container
124   
125   fOutputContainer = new TObjArray(9) ; 
126   fOutputContainer->SetName(GetName()) ; 
127
128   fOutputContainer->AddAt(fhHMPIDCkovP,      0) ; 
129   fOutputContainer->AddAt(fhHMPIDSigP,       1) ; 
130   fOutputContainer->AddAt(fhHMPIDMipXY,      2) ; 
131   fOutputContainer->AddAt(fhHMPIDDifXY,      3) ; 
132   fOutputContainer->AddAt(fhHMPIDProb[0],    4) ; 
133   fOutputContainer->AddAt(fhHMPIDProb[1],    5) ; 
134   fOutputContainer->AddAt(fhHMPIDProb[2],    6) ; 
135   fOutputContainer->AddAt(fhHMPIDProb[3],    7) ; 
136   fOutputContainer->AddAt(fhHMPIDProb[4],    8) ; 
137 }
138
139 //______________________________________________________________________________
140 void AliHMPIDQATask::Exec(Option_t *) 
141 {
142   // Processing of one event
143     
144   Long64_t entry = fChain->GetReadEntry() ;
145   
146   if (!fESD) {
147     AliError("fESD is not connected to the input!") ; 
148     return ; 
149   }
150   
151   if ( !((entry-1)%100) ) 
152     AliInfo(Form("%s ----> Processing event # %lld",  (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ; 
153   
154   // ************************  HMPID *************************************
155   Int_t iTrk ; 
156   for(iTrk = 0 ; iTrk < fESD->GetNumberOfTracks() ; iTrk++){
157     AliESDtrack *pTrk = fESD->GetTrack(iTrk) ;
158
159     fhHMPIDCkovP->Fill( pTrk->GetP(), pTrk->GetHMPIDsignal() ) ; 
160     fhHMPIDSigP ->Fill( pTrk->GetP(), TMath::Sqrt(pTrk->GetHMPIDchi2()) ) ;
161      
162 //     Float_t xm,ym; Int_t q,np;  pTrk->GetHMPIDmip(xm,ym,q,np);  fMipXY->Fill(xm,ym); //mip info
163 //     Float_t xd,yd,th,ph;        pTrk->GetHMPIDtrk(xd,yd,th,ph); fDifXY->Fill(xd,yd); //track info 
164      
165     Double_t pid[5] ;  
166     pTrk->GetHMPIDpid(pid) ; 
167     Int_t i ; 
168     for(i = 0 ; i < 5 ; i++) 
169       fhHMPIDProb[i]->Fill(pid[i]) ;
170   }//tracks loop 
171        
172   PostData(0, fOutputContainer);
173 }
174
175 //______________________________________________________________________________
176 void AliHMPIDQATask::Terminate(Option_t *)
177 {
178   // Processing when the event loop is ended
179   fOutputContainer = (TObjArray*)GetOutputData(0);
180   fhHMPIDCkovP   = (TH2F*)fOutputContainer->At(0);
181   fhHMPIDSigP    = (TH2F*)fOutputContainer->At(1);
182   fhHMPIDMipXY   = (TH2F*)fOutputContainer->At(2);
183   fhHMPIDDifXY   = (TH2F*)fOutputContainer->At(3);
184   fhHMPIDProb[0] = (TH1F*)fOutputContainer->At(4);
185   fhHMPIDProb[1] = (TH1F*)fOutputContainer->At(5);
186   fhHMPIDProb[2] = (TH1F*)fOutputContainer->At(6);
187   fhHMPIDProb[3] = (TH1F*)fOutputContainer->At(7);
188   fhHMPIDProb[4] = (TH1F*)fOutputContainer->At(8);
189
190   Bool_t problem = kFALSE ; 
191   AliInfo(Form(" *** %s Report:", GetName())) ; 
192
193   Float_t n = 1.292 ; //mean freon ref idx 
194   TF1 * hHMPIDpPi = new TF1("RiPiTheo", "acos(sqrt(x*x+[0]*[0])/(x*[1]))", 1.2, 7) ; 
195   hHMPIDpPi->SetLineWidth(1) ; 
196   hHMPIDpPi->SetParameter(1,n) ; 
197
198   AliPID ppp ;                 
199   hHMPIDpPi->SetLineColor(kRed);   
200   hHMPIDpPi->SetParameter(0,AliPID::ParticleMass(AliPID::kPion));    //mass
201
202   TF1 * hHMPIDK = static_cast<TF1*>(hHMPIDpPi->Clone()) ; 
203   hHMPIDK ->SetLineColor(kGreen) ; 
204   hHMPIDK ->SetParameter(0, AliPID::ParticleMass(AliPID::kKaon)) ; 
205
206   TF1 * hHMPIDP=static_cast<TF1*>(hHMPIDpPi->Clone()) ; 
207   hHMPIDP ->SetLineColor(kBlue) ;  
208   hHMPIDP ->SetParameter(0,AliPID::ParticleMass(AliPID::kProton)) ; 
209
210   TCanvas * cHMPID = new TCanvas("cHMPID","HMPID ESD Test") ;
211   cHMPID->SetFillColor(10) ; 
212   cHMPID->SetHighLightColor(10) ; 
213   cHMPID->Divide(3,2) ;
214
215   cHMPID->cd(1); 
216   fhHMPIDCkovP->Draw() ; 
217   hHMPIDpPi->Draw("same") ; 
218   hHMPIDK->Draw("same") ; 
219   hHMPIDP->Draw("same") ;   
220
221   cHMPID->cd(2) ; 
222   fhHMPIDMipXY->Draw() ;   
223
224   cHMPID->cd(3) ; 
225   fhHMPIDProb[0]->Draw() ; 
226   fhHMPIDProb[1]->Draw("same") ;
227   
228   cHMPID->cd(4) ; 
229   fhHMPIDSigP ->Draw() ;                                                          
230
231   cHMPID->cd(5) ; 
232   fhHMPIDDifXY->Draw() ;   
233
234   cHMPID->cd(6) ; 
235   fhHMPIDProb[2]->Draw() ; 
236   fhHMPIDProb[3]->Draw("same") ; 
237   fhHMPIDProb[4]->Draw("same") ; 
238
239   cHMPID->Print("HMPID.eps");
240   
241   char line[1024] ; 
242   sprintf(line, ".!tar -zcf %s.tar.gz *.eps", GetName()) ; 
243   gROOT->ProcessLine(line);
244   sprintf(line, ".!rm -fR *.eps"); 
245   gROOT->ProcessLine(line);
246   
247   AliInfo(Form("!!! All the eps files are in %s.tar.gz !!!", GetName())) ;
248
249   char * report ; 
250   if(problem)
251     report="Problems found, please check!!!";  
252   else 
253     report="OK";
254
255   AliInfo(Form("*** %s Summary Report: %s \n",GetName(), report)) ; 
256 }