]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/extra/AliAnalysisTaskEventCount.cxx
Coverity 18193
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / extra / AliAnalysisTaskEventCount.cxx
1 #include <Riostream.h>
2
3 #include <TChain.h>
4 #include <TH1.h>
5 #include <TH2.h>
6
7 #include "AliESDtrack.h"
8 #include "AliESDEvent.h"
9 #include "AliESDVertex.h"
10 #include "AliESDtrackCuts.h"
11
12 #include "AliAnalysisTask.h"
13 #include "AliAnalysisManager.h"
14 #include "AliInputEventHandler.h"
15
16 #include "AliStack.h"
17 #include "AliMCEvent.h"
18 #include "AliMCParticle.h"
19 #include "AliGenEventHeader.h"
20
21 #include "AliAnalysisTaskEventCount.h"
22
23 // analysis task creating basic QA plots for resonance particles
24 // Author: Ayben Karasu Uysal
25
26
27 ClassImp(AliAnalysisTaskEventCount)
28
29 //________________________________________________________________________
30 AliAnalysisTaskEventCount::AliAnalysisTaskEventCount(const char *name) :
31    AliAnalysisTaskSE(name), 
32    fAcceptTPC(kFALSE),
33    fVz(1E20),
34    fOutputList(0),
35    fHEvent(0), 
36    fTrackCuts(0)
37 {
38 //   
39 // Constructor
40 //
41
42    // Define input and output slots here
43    // Input slot #0 works with a TChain
44    DefineInput(0, TChain::Class());
45    
46    // Output slot #0 id reserved by the base class for AOD
47    // Output slot #1 writes into a TH1 container
48    DefineOutput(1, TList::Class());
49    
50    // setup to NULL all remaining histos
51    Int_t i;
52    for (i = 0; i < kTypes; i++) fCheck[i] = 0;
53 }
54
55 //________________________________________________________________________
56 void AliAnalysisTaskEventCount::UserCreateOutputObjects()
57 {
58 //
59 // Create histograms (called once)
60 //
61
62    // standard objects
63    fESDpid = new AliESDpid();
64    fTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE);
65    fTrackCuts->SetPtRange(0.1, 1E20);
66    fTrackCuts->SetEtaRange(-0.8, 0.8);
67
68    // create output list
69    fOutputList = new TList();
70    fOutputList->SetOwner();
71    
72    // create histograms
73    fHEvent = new TH1I("EventStat", "Event statistics", kTypes, 0, kTypes);
74    for (Int_t i = 0; i < kTypes; i++) {
75       fHEvent->GetXaxis()->SetBinLabel(i + 1, Title((EType)i));
76    }
77    
78    // add histograms to list
79    fOutputList->Add(fHEvent);
80    
81    PostData(1, fOutputList);
82 }
83
84 //________________________________________________________________________
85 void AliAnalysisTaskEventCount::UserExec(Option_t *)
86 {
87 //
88 // Execute computations
89 //
90
91    // assign first checks
92    fCheck[kAll]               = kTRUE;
93    fCheck[kPassPhysicsSel]    = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB);
94    fCheck[kGoodPrimaryVertex] = kFALSE;
95    fCheck[kHas1TrackAny]      = kFALSE;
96    fCheck[kHas1TrackQuality]  = kFALSE;
97    
98    // try to cast input event to ESD and loop on tracks
99    AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
100    if (!esd) return;
101    
102    // check primary vertex
103    const AliESDVertex *v0 = esd->GetPrimaryVertexTracks();
104    if (v0) {
105       if (v0->GetNContributors() > 0) 
106          fCheck[kGoodPrimaryVertex] = kTRUE;
107       else {
108          v0 = fESD->GetPrimaryVertexSPD();
109          if (v0) {
110             if (v0->GetNContributors() > 0) 
111                fCheck[kGoodPrimaryVertex] = kTRUE;
112             else {
113                if (fAcceptTPC) {
114                   v0 = esd->GetPrimaryVertexTPC();
115                   if (v0) {
116                      if (v0->GetNContributors() > 0) fCheck[kGoodPrimaryVertex] = kTRUE;
117                   }
118                }
119             }
120          }
121       }
122    }
123    
124    // check track count
125    if (esd->GetNumberOfTracks() > 0) fCheck[kHas1TrackAny] = kTRUE;
126    if (fTrackCuts->CountAcceptedTracks(esd) > 0) fCheck[kHas1TrackQuality] = kTRUE;
127    
128    // fill histogram
129    for (Int_t i = 0; i < kTypes; i++) {
130       if (fCheck[i]) fHEvent->Fill((Double_t)i + 0.01);
131    }
132    
133    PostData(1, fOutputList);
134 }
135
136 //________________________________________________________________________
137 void AliAnalysisTaskEventCount::Terminate(Option_t *)
138 {
139 //
140 // Termination
141 // Quickly check that the output list is there
142 //
143   
144    fOutputList = dynamic_cast<TList*>(GetOutputData(1));
145    if (!fOutputList) {
146       AliError("Output list not found!!!");
147       return;
148    }
149 }