]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisTask.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisTask.cxx
1 //
2 // Class AliRsnAnalysisTask
3 //
4 // Virtual Class derivated from AliRsnVAnalysisTask which will be base class
5 // for all RSN SE tasks
6 //
7 // authors: Martin Vala (martin.vala@cern.ch)
8 //          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
9 //
10
11 #include <Riostream.h>
12 #include <TList.h>
13 #include <TH1.h>
14
15 #include "AliESDEvent.h"
16 #include "AliMCEvent.h"
17 #include "AliAODEvent.h"
18
19 #include "AliRsnCutSet.h"
20 #include "AliRsnVATProcessInfo.h"
21 #include "AliRsnAnalysisTask.h"
22
23 ClassImp(AliRsnAnalysisTask)
24
25 //_____________________________________________________________________________
26 AliRsnAnalysisTask::AliRsnAnalysisTask(const char *name, Bool_t useKine) :
27    AliRsnVAnalysisTask(name, useKine),
28    fRsnAnalysisManager(),
29    fEventCuts("eventCuts", AliRsnCut::kEvent),
30    fOutList(0x0),
31    fZeroEventPercentWarning(100),
32    fUseZeroEventWarning(kTRUE)
33 {
34 //
35 // Default constructor.
36 // Defines another output slot for histograms/ntuples
37 //
38
39    DefineOutput(2, TList::Class());
40 }
41
42 //_____________________________________________________________________________
43 AliRsnAnalysisTask::AliRsnAnalysisTask(const AliRsnAnalysisTask& copy) :
44    AliRsnVAnalysisTask(copy),
45    fRsnAnalysisManager(copy.fRsnAnalysisManager),
46    fEventCuts(copy.fEventCuts),
47    fOutList(0x0),
48    fZeroEventPercentWarning(copy.fZeroEventPercentWarning),
49    fUseZeroEventWarning(copy.fUseZeroEventWarning)
50 {
51 //
52 // Copy constructor.
53 //
54 }
55
56 //_____________________________________________________________________________
57 AliRsnAnalysisTask& AliRsnAnalysisTask::operator=(const AliRsnAnalysisTask& copy)
58 {
59 //
60 // Assigment operator.
61 //
62
63    AliRsnVAnalysisTask::operator=(copy);
64
65    fRsnAnalysisManager = copy.fRsnAnalysisManager;
66    fEventCuts = copy.fEventCuts;
67    if (fOutList) fOutList->Clear();
68    fZeroEventPercentWarning = copy.fZeroEventPercentWarning;
69    fUseZeroEventWarning = copy.fUseZeroEventWarning;
70
71    return (*this);
72 }
73
74 //_____________________________________________________________________________
75 void AliRsnAnalysisTask::RsnUserCreateOutputObjects()
76 {
77 //
78 // Creation of output objects.
79 // These are created through the utility methods in the analysis manager,
80 // which asks all the AliRsnPair objects to initialize their output which
81 // is then linked to the TList data member of this, which will contain all the output.
82 //
83
84    // initialize the list
85    if (!fOutList) fOutList = new TList;
86    fOutList->Clear();
87    fOutList->SetOwner(kTRUE);
88
89    // initialize all pairs
90    fRsnAnalysisManager.InitAllPairs(fOutList);   
91
92    PostData(2, fOutList);
93 }
94
95 //_____________________________________________________________________________
96 void AliRsnAnalysisTask::RsnUserExec(Option_t*)
97 {
98 //
99 // Execution of the analysis task.
100 // Recovers the input event and processes it with all included pair objects,
101 // using 'reconstructed' or 'MonteCarlo' functions depending on MC-only flag.
102 //
103
104    if (IsMixing()) return;
105
106    fRsnAnalysisManager.ProcessAll(&fRsnEvent[0], 0x0, fMCOnly);
107
108    PostData(2, fOutList);
109 }
110
111 //_____________________________________________________________________________
112 void AliRsnAnalysisTask::RsnUserExecMix(Option_t* /*opt*/)
113 {
114 //
115 // Execution of the analysis task with event mixing.
116 // Recovers the input event and processes it with all included pair objects,
117 // using 'reconstructed' or 'MonteCarlo' functions depending on MC-only flag.
118 //
119
120    if (!IsMixing()) return;
121    AliDebug(AliLog::kDebug, Form("RSN Mixing %lld %d [%lld,%lld] %d", fMixedEH->CurrentEntry(), fMixedEH->NumberMixed(), fMixedEH->CurrentEntryMain(), fMixedEH->CurrentEntryMix(), fMixedEH->CurrentBinIndex()));
122
123    // the virtual class has already sorted tracks in the PID index
124    // so we need here just to call the execution of analysis
125    fRsnAnalysisManager.ProcessAll(&fRsnEvent[0], &fRsnEvent[1], fMCOnly);
126 }
127
128 //_____________________________________________________________________________
129 void AliRsnAnalysisTask::RsnTerminate(Option_t*)
130 {
131 //
132 // Termination.
133 // Could be added some monitor histograms here.
134 //
135 }
136
137 //______________________________________________________________________________
138 Bool_t AliRsnAnalysisTask::RsnEventProcess()
139 {
140 //
141 // Customized event pre-processing.
142 // First checks if the current event passes all cuts,
143 // and if it does, updates the informations and then
144 // call the operations which are already defined in the
145 // omonyme function in mother class
146 //
147
148    // initially, an event is expected to be bad
149    fTaskInfo.SetEventUsed(kFALSE);
150
151    if (!AliRsnVAnalysisTask::RsnEventProcess()) return kFALSE;
152
153    // check #1: number of tracks in event (reject empty events)
154    Int_t    ntracks = fRsnEvent[0].GetMultiplicityFromTracks();
155    Double_t zeroEventPercent = 0.0;
156    if (ntracks < 1) {
157       // if using the checker for amount of empty events, update it
158       if (fUseZeroEventWarning) {
159          TH1I *hist = (TH1I*)fInfoList->FindObject(fTaskInfo.GetEventHistogramName());
160          if (hist) {
161             if (hist->Integral() > 1) zeroEventPercent = (Double_t)hist->GetBinContent(1) / hist->Integral() * 100;
162             if ((zeroEventPercent > fZeroEventPercentWarning) && (fEntry > 100))
163                AliWarning(Form("%3.2f%% Events are with zero tracks (CurrentEvent=%d)!!!", zeroEventPercent, fEntry));
164          }
165       }
166
167       // empty events are rejected by default
168       fTaskInfo.SetEventUsed(kFALSE);
169       AliDebug(AliLog::kDebug, "Empty event. Skipping...");
170       return kFALSE;
171    }
172
173    // check the event cuts and update the info data accordingly
174    // events not passing the cuts must be rejected
175    if (!fEventCuts.IsSelected(&fRsnEvent[0])) {
176       fTaskInfo.SetEventUsed(kFALSE);
177       return kFALSE;
178    }
179
180    // if we reach this point, cuts were passed;
181    // then additional operations can be done
182
183    // find leading particle (without any PID/momentum restriction)
184    fRsnEvent[0].SelectLeadingParticle(0);
185
186    // final return value is positive
187    // but call the mother class method which updates info object
188    fTaskInfo.SetEventUsed(kTRUE);
189    return kTRUE;
190 }