Coverity
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAnalysisTaskSEMonitNorm.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2009, 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 // 
18 // Class for monitoring of information used for open charm normalization
19 // (triggers, candles, ...)
20 //
21 // Origin: davide.caffarri@pd.infn.it
22 //
23 //*************************************************************************
24
25 #include <TChain.h>
26 #include <TTree.h>
27 #include <TBranch.h>
28 #include <TObjArray.h>
29 #include <TH1F.h>
30 #include <TH2F.h>  
31 #include <TCanvas.h>
32
33 #include "AliAnalysisTask.h"
34 #include "AliAnalysisManager.h"
35 #include "AliESDEvent.h"
36 #include "AliESDInputHandler.h"
37 #include "AliTriggerAnalysis.h"
38 #include "AliLog.h"
39 #include "AliCounterCollection.h"
40 #include "AliAnalysisTaskSEMonitNorm.h"
41
42 ClassImp(AliAnalysisTaskSEMonitNorm)
43
44 //________________________________________________________________________
45 AliAnalysisTaskSEMonitNorm::AliAnalysisTaskSEMonitNorm(const char *name): 
46   AliAnalysisTaskSE(name), 
47   fESD(0), 
48   fOutput(0),
49   fCounterTrigg(0),
50   fCounterNotTrigg(0),
51   fCounterCandleTrig(0),
52   fCounterCandleNotTrig(0) 
53
54 {
55   // Constructor
56
57   // Define input and output slots here
58   // Output slot #0 writes into a TList container
59   DefineOutput(1, TList::Class());  //My private output
60   DefineOutput(2, AliCounterCollection::Class());
61   DefineOutput(3, AliCounterCollection::Class());
62   DefineOutput(4, AliCounterCollection::Class());
63   DefineOutput(5, AliCounterCollection::Class());
64
65 }
66 //________________________________________________________________________
67 AliAnalysisTaskSEMonitNorm::~AliAnalysisTaskSEMonitNorm()
68 {
69   // Destructor
70
71   // histograms are in the output list and deleted when the output
72   // list is deleted by the TSelector dtor
73
74   if (fOutput) {
75     delete fOutput;
76     fOutput = 0;
77   }
78
79   if (fCounterTrigg) {
80     delete fCounterTrigg;
81     fCounterTrigg = 0;
82   }
83
84   if (fCounterNotTrigg) {
85     delete fCounterNotTrigg;
86     fCounterNotTrigg = 0;
87  }
88
89   if (fCounterCandleTrig) {
90     delete fCounterCandleTrig;
91     fCounterCandleTrig = 0;
92   }
93   
94   if (fCounterCandleNotTrig) {
95     delete fCounterCandleNotTrig;
96     fCounterCandleNotTrig = 0;
97     
98   }
99   
100   
101 }
102
103
104 //________________________________________________________________________
105 void AliAnalysisTaskSEMonitNorm::UserCreateOutputObjects()
106 {
107   // Create histograms
108   // Called once
109
110   // Several histograms are more conveniently managed in a TList
111   fOutput = new TList;
112   fOutput->SetOwner();
113
114
115   //Counter for Normalization new line
116   fCounterTrigg = new AliCounterCollection("Triggered_Counter");//new line
117   fCounterTrigg->AddRubric("Event", "triggered/v0andONLINE/v0andOFFLINE/v0andOFF&ON/v0andON_notOFF/v0andOFF_notON/v0orOFF/V0orON");//new line
118   fCounterTrigg->AddRubric("Run", 10000000);//new line
119   fCounterTrigg->Init();//new line 
120   
121   fCounterNotTrigg = new AliCounterCollection("NotTriggered_Counter");//new line
122   fCounterNotTrigg->AddRubric("Event", "!triggered/v0andONLINE/v0andOFFLINE/v0andOFF&ON/v0andON_notOFF/v0andOFF_notON/v0orOFF/v0orON");//new line
123   fCounterNotTrigg->AddRubric("Run", 10000000);//new line
124   fCounterNotTrigg->Init();//new line 
125
126   fCounterCandleTrig = new AliCounterCollection("Candle_Triggered_Counter");//new line
127   fCounterCandleTrig->AddRubric("Event", "triggered/candles02/2xcandles02/primVtx/TPConly");//new line
128   fCounterCandleTrig->AddRubric("Run", 10000000);//new line
129   fCounterCandleTrig->Init();//new line 
130
131
132   fCounterCandleNotTrig = new AliCounterCollection("Candle_NotTriggered_Counter");//new line
133   fCounterCandleNotTrig->AddRubric("Event", "!triggered/candles02/2xcandles02/primVtx/TPConly");//new line
134   fCounterCandleNotTrig->AddRubric("Run", 10000000);//new line
135   fCounterCandleNotTrig->Init();//new line 
136
137   
138   PostData(1, fOutput);
139   PostData(2, fCounterTrigg);
140   PostData(3, fCounterNotTrigg);
141   PostData(4, fCounterCandleTrig);
142   PostData(5, fCounterCandleNotTrig);
143   return;
144 }
145
146 //________________________________________________________________________
147 void AliAnalysisTaskSEMonitNorm::UserExec(Option_t *) 
148 {
149   // Main loop
150   // Called for each event
151   
152   if (!InputEvent()) {
153     Printf("ERROR: fESD not available");
154     return;
155   }
156   AliESDEvent* esdE = (AliESDEvent*) InputEvent();
157   if (!esdE) {
158     Printf("ERROR: fESD not available");
159     return;
160   }
161
162   // Select PHYSICS events (type=7, for data) and MC events (type=0)
163   // fCheckEventType is kFALSE if fReadMC is kTRUE, hence check is skipped
164   if(esdE->GetEventType()!=7 ) return;
165   
166   Int_t runNumber = (Int_t)esdE->GetRunNumber();
167   
168   //static AliTriggerAnalysis* triggerAnalysis = new AliTriggerAnalysis();
169   Bool_t eventTriggered = 0;
170   
171   Bool_t flag02 = kFALSE;
172   Bool_t flagPVT = kFALSE;
173   Bool_t flagTPCOnly70 = kFALSE;
174
175   // use response of AliPhysicsSelection
176   eventTriggered = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
177   
178   
179   AliTriggerAnalysis *trigAnalys = new AliTriggerAnalysis();
180   Bool_t v0A; 
181   Bool_t v0C; 
182   Bool_t v0andOFF = kFALSE;
183   Bool_t v0orOFF = kFALSE;
184   if(esdE){
185     v0C = trigAnalys->IsOfflineTriggerFired(esdE , AliTriggerAnalysis::kV0C);
186     v0A = trigAnalys->IsOfflineTriggerFired(esdE , AliTriggerAnalysis::kV0A);
187     if(v0A&&v0C)v0andOFF=kTRUE;   
188     if (v0A||v0C)v0orOFF=kTRUE; 
189   }  
190
191   Int_t v0Con = trigAnalys->V0Trigger(esdE, AliTriggerAnalysis::kCSide, kTRUE, kFALSE);
192   Int_t v0Aon = trigAnalys->V0Trigger(esdE, AliTriggerAnalysis::kASide, kTRUE, kFALSE);
193
194   Bool_t v0andON=kFALSE;
195   if((v0Aon==AliTriggerAnalysis::kV0BB)&&(v0Con==AliTriggerAnalysis::kV0BB))v0andON=kTRUE;   
196
197   Bool_t v0orON =((v0Aon==AliTriggerAnalysis::kV0BB)||(v0Con==AliTriggerAnalysis::kV0BB));
198
199   Int_t trkEntries = (Int_t)esdE->GetNumberOfTracks();
200
201   for(Int_t i=0;i<trkEntries;i++){
202     AliESDtrack *track=(AliESDtrack*)esdE->GetTrack(i);
203     UShort_t nClusTPC=track->GetTPCNcls();
204     
205     //TPConly 
206     if((track->GetStatus()&AliESDtrack::kTPCin)&&TMath::Abs(track->Eta()<0.9)&&nClusTPC>=70){
207       if (!flagTPCOnly70){
208         flagTPCOnly70=kTRUE;
209       }
210     }
211
212     //candles02
213     if((nClusTPC>=70)&&(track->GetStatus()&AliESDtrack::kITSrefit)&&(track->GetStatus()&AliESDtrack::kTPCrefit)){
214       if((track->Pt()>0.2)){
215         if(!flag02) flag02=kTRUE;
216       }
217     }
218   }
219   
220   //prim Vtx
221   if(esdE){
222     const AliESDVertex *vtrc1 =  esdE->GetPrimaryVertex();
223     if(vtrc1 && vtrc1->GetNContributors()>0)  flagPVT=kTRUE;
224   }
225   
226   if (eventTriggered){
227
228     fCounterTrigg->Count(Form("Event:triggered/Run:%d", runNumber));
229     if (v0andON) fCounterTrigg->Count(Form("Event:v0andONLINE/Run:%d", runNumber));
230     if (v0andOFF) fCounterTrigg->Count(Form("Event:v0andOFFLINE/Run:%d", runNumber));
231     if (v0andON&&v0andOFF) fCounterTrigg->Count(Form("Event:v0andOFF&ON/Run:%d", runNumber));
232     if (v0andON&&!v0andOFF) fCounterTrigg->Count(Form("Event:v0andON_notOFF/Run:%d", runNumber));
233     if (!v0andON&&v0andOFF) fCounterTrigg->Count(Form("Event:v0andOFF_notON/Run:%d", runNumber));
234     if (v0orON)  fCounterTrigg->Count(Form("Event:v0orON/Run:%d", runNumber));
235     if (v0orOFF)  fCounterTrigg->Count(Form("Event:v0orOFF/Run:%d", runNumber));
236
237     fCounterCandleTrig->Count(Form("Event:triggered/Run:%d", runNumber));
238     if (flagTPCOnly70) fCounterCandleTrig->Count(Form("Event:TPConly/Run:%d", runNumber));
239     if (flag02) fCounterCandleTrig->Count(Form("Event:candles02/Run:%d", runNumber));
240     if (flagPVT) fCounterCandleTrig->Count(Form("Event:primVtx/Run:%d", runNumber));
241
242   }
243   else {
244     fCounterNotTrigg->Count(Form("Event:!triggered/Run:%d", runNumber));
245     if (v0andON) fCounterNotTrigg->Count(Form("Event:v0andONLINE/Run:%d", runNumber));
246     if (v0andOFF) fCounterNotTrigg->Count(Form("Event:v0andOFFLINE/Run:%d", runNumber));
247     if (v0andON&&v0andOFF) fCounterNotTrigg->Count(Form("Event:v0andOFF&ON/Run:%d", runNumber));
248     if (v0andON&&!v0andOFF) fCounterNotTrigg->Count(Form("Event:v0andON_notOFF/Run:%d", runNumber));
249     if (!v0andON&&v0andOFF) fCounterNotTrigg->Count(Form("Event:v0andOFF_notON/Run:%d", runNumber));
250     if (v0orON)  fCounterNotTrigg->Count(Form("Event:v0orON/Run:%d", runNumber));
251     if (v0orOFF)  fCounterNotTrigg->Count(Form("Event:v0orOFF/Run:%d", runNumber));
252
253     fCounterCandleNotTrig->Count(Form("Event:!triggered/Run:%d", runNumber));
254     if (flagTPCOnly70) fCounterCandleNotTrig->Count(Form("Event:TPConly/Run:%d", runNumber));
255     if (flag02) fCounterCandleNotTrig->Count(Form("Event:candles02/Run:%d", runNumber));
256     if (flagPVT) fCounterCandleNotTrig->Count(Form("Event:primVtx/Run:%d", runNumber));
257
258
259   }
260   
261   
262   // Post the data already here
263   PostData(1, fOutput);
264   PostData(2, fCounterTrigg);
265   PostData(3, fCounterNotTrigg);
266   PostData(4, fCounterCandleTrig);
267   PostData(5, fCounterCandleNotTrig);
268   
269   return;
270 }      
271
272 //________________________________________________________________________
273 void AliAnalysisTaskSEMonitNorm::Terminate(Option_t *) 
274 {
275   // Draw result to the screen
276   // Called once at the end of the query
277   fOutput = dynamic_cast<TList*> (GetOutputData(1));
278   if (!fOutput) {     
279     Printf("ERROR: fOutput not available");
280     return;
281   }
282   
283   fCounterTrigg = dynamic_cast<AliCounterCollection*> (GetOutputData(2));
284   if (!fCounterTrigg) {     
285     Printf("ERROR: fCounterTrigg not available");
286     return;
287   }
288   
289   fCounterNotTrigg = dynamic_cast<AliCounterCollection*> (GetOutputData(3));
290   if (!fCounterNotTrigg) {     
291     Printf("ERROR: fCounterNotTrigg not available");
292     return;
293   }
294   
295   fCounterCandleTrig = dynamic_cast<AliCounterCollection*> (GetOutputData(4));
296   if (!fCounterCandleTrig) {     
297     Printf("ERROR: fCounterCandleTrig not available");
298   return;
299   }
300
301   fCounterCandleNotTrig = dynamic_cast<AliCounterCollection*> (GetOutputData(5));
302   if (!fCounterCandleNotTrig) {     
303     Printf("ERROR: fCounterCandleNotTrig not available");
304     return;
305   }
306   
307   return;
308 }
309
310 //_________________________________________________________________________