]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnAnalysisSE.cxx
Several updates from the validation phase of the Fast Or DA (A. Mastroserio)
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisSE.cxx
CommitLineData
aec0ec32 1//
2// Class AliRsnAnalysisSE
3//
4// TODO
5//
6// authors: Martin Vala (martin.vala@cern.ch)
7// Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
8//
9
15d5fd02 10#include <Riostream.h>
11
aec0ec32 12#include <TSystem.h>
13#include <TFile.h>
14#include <TFolder.h>
922688c0 15#include <TROOT.h>
aec0ec32 16
17#include "AliLog.h"
18
19#include "AliAnalysisManager.h"
20#include "AliRsnPairMgr.h"
21#include "AliRsnEventBuffer.h"
22
23#include "AliMCEventHandler.h"
24#include "AliESDEvent.h"
25
26#include "AliRsnAnalysisSE.h"
27
28ClassImp(AliRsnAnalysisSE)
29
30//________________________________________________________________________
15d5fd02 31AliRsnAnalysisSE::AliRsnAnalysisSE(const char * name, Int_t bufferSize) :
32 AliRsnAnalysisTaskSEBase(name),
33 fDoesMixing(kFALSE),
34 fMixingNum(0),
35 fMixingCut(0x0),
36 fPairMgrs(0),
37 fOutList(0x0),
38 fBuffer(0x0),
39 fBufferSize(bufferSize)
aec0ec32 40{
15d5fd02 41//
aec0ec32 42// Default constructor
15d5fd02 43//
aec0ec32 44
45 InitIOVars();
46 DefineOutput(1, TList::Class());
47}
48
49//________________________________________________________________________
50AliRsnAnalysisSE::~AliRsnAnalysisSE()
51{
15d5fd02 52//
aec0ec32 53// Destructor
15d5fd02 54//
aec0ec32 55}
56
57//________________________________________________________________________
58void AliRsnAnalysisSE::InitIOVars()
59{
15d5fd02 60//
aec0ec32 61// Init input output values
15d5fd02 62//
aec0ec32 63
aec0ec32 64 AliRsnAnalysisTaskSEBase::InitIOVars();
65
15d5fd02 66 fBuffer = 0;
aec0ec32 67 fOutList = 0;
aec0ec32 68}
69
70//________________________________________________________________________
71void AliRsnAnalysisSE::UserCreateOutputObjects()
72{
15d5fd02 73//
aec0ec32 74// UserCreateOutputObjects() of AliAnalysisTaskSE
15d5fd02 75//
aec0ec32 76
e0baff8c 77 OpenFile(0);
aec0ec32 78 fOutList = new TList();
79 fOutList->SetOwner();
80 AliRsnPair *def=0;
81 AliRsnPairMgr *mgr=0;
82 TList *listTmp;
15d5fd02 83 fDoesMixing = kFALSE;
aec0ec32 84 for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++)
85 {
86 mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr);
87 if (!mgr) continue;
88 listTmp = new TList();
89 listTmp->SetName(mgr->GetName());
90 for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++)
91 {
92 def = (AliRsnPair *) mgr->GetPairs()->At(i);
93 if (def)
94 {
e0baff8c 95 listTmp->Add(def->GenerateHistograms(mgr->GetName()));
15d5fd02 96 if (def->IsMixed()) fDoesMixing = kTRUE;
aec0ec32 97 }
98 }
99 fOutList->Add(listTmp);
100 }
101
cc781f3d 102 TH1I *hUsed = new TH1I("hRsnUsed", "skipped and used events in this analysis", 2, 0, 2);
103 fOutList->Add(hUsed);
104
15d5fd02 105 fBuffer = new AliRsnEventBuffer(fBufferSize);
aec0ec32 106}
107
108//________________________________________________________________________
109void AliRsnAnalysisSE::UserExec(Option_t *)
110{
15d5fd02 111//
aec0ec32 112// UserExec() of AliAnalysisTaskSE
15d5fd02 113//
114
115 static UInt_t eventID = 0;
aec0ec32 116
15d5fd02 117 if (fEntry++ % 100 == 0) cout << "[" << GetName() << "] : processing entry " << fEntry-1 << endl;
aec0ec32 118
cc781f3d 119 TH1I *h = (TH1I*)fOutList->FindObject("hRsnUsed");
aec0ec32 120
cc781f3d 121 AliRsnEvent *curEvent = GetRsnEventFromInputType();
122 if (curEvent) {
123 curEvent->SetUniqueID(eventID++);
124 ProcessEventAnalysis(curEvent);
125 PostEventProcess();
126 h->Fill(1);
127 }
128 else {
129 h->Fill(0);
130 }
aec0ec32 131
132 PostData(1, fOutList);
133}
134
135//________________________________________________________________________
136void AliRsnAnalysisSE::Terminate(Option_t *)
137{
15d5fd02 138//
aec0ec32 139// Terminate() of AliAnalysisTask
15d5fd02 140//
aec0ec32 141
142 fOutList = dynamic_cast<TList*>(GetOutputData(1));
15d5fd02 143 if (!fOutList) { AliError("At end of analysis, output list is NULL"); return; }
144 //fOutList->Print();
aec0ec32 145}
146
147//________________________________________________________________________
148void AliRsnAnalysisSE::ProcessEventAnalysis(AliRsnEvent *curEvent)
149{
15d5fd02 150//
aec0ec32 151// Process of one event
15d5fd02 152//
aec0ec32 153
154 // Adds event to Event Buffer
15d5fd02 155 fBuffer->AddEvent(curEvent);
156 Int_t index = fBuffer->GetEventsBufferIndex();
157
158 Int_t nmatches;
159 TArrayI matched(0);
160 if (fDoesMixing) matched = FindGoodMatches(index, nmatches);
aec0ec32 161
162 // loop over all Pair managers
163 AliRsnPairMgr *mgr=0;
164 for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++)
165 {
166 mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr);
167 AliRsnPair *pair=0;
168 for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++)
169 {
170 pair = (AliRsnPair *) mgr->GetPairs()->At(i);
15d5fd02 171 if (!pair->IsMixed()) {
172 pair->ProcessPair(curEvent, 0);
173 }
174 else {
175 Int_t i, iev;
176 for (i = 0; i < matched.GetSize(); i++) {
177 iev = matched[i];
178 if (iev < 0) continue;
179 AliRsnEvent *evmatch = fBuffer->GetEvent(iev);
180 pair->ProcessPair(curEvent, evmatch);
181 if (!pair->IsPairEqual()) pair->ProcessPair(evmatch, curEvent);
182 }
183 }
aec0ec32 184 }
185 }
186}
187
188//________________________________________________________________________
189void AliRsnAnalysisSE::PostEventProcess(const Short_t & index)
190{
15d5fd02 191//
aec0ec32 192// Post process of one event
15d5fd02 193//
aec0ec32 194
15d5fd02 195 if (fInputType[index] != kRSN) return;
aec0ec32 196
15d5fd02 197 if (fBuffer->GetDeleteBufferWhenReset() == kFALSE) {
198 fRSN[index] = (AliRsnEvent*) fBuffer->GetNextEvent();
199 SetBranchAddress(0 , "rsnEvents", &fRSN[index]);
200 }
aec0ec32 201}
202
15d5fd02 203//________________________________________________________________________
aec0ec32 204void AliRsnAnalysisSE::AddPairMgr(AliRsnPairMgr * pairmgr)
205{
206 fPairMgrs.Add(pairmgr);
207}
922688c0 208
15d5fd02 209//________________________________________________________________________
8a6b5ac8 210void AliRsnAnalysisSE::AddPairMgrFromConfig(TString configfile,TString analysisName)
922688c0 211{
212 gROOT->LoadMacro(configfile.Data());
213
214 configfile.ReplaceAll(".C","");
215
8a6b5ac8 216 analysisName.ReplaceAll("_","-");
217
218 AliRsnPairMgr *mgrRsn = (AliRsnPairMgr *) gROOT->ProcessLine(Form("%s(\"%s\");", configfile.Data(),analysisName.Data()));
922688c0 219 if (!mgrRsn) return;
220
221 fPairMgrs.Add(mgrRsn);
222}
15d5fd02 223
224//________________________________________________________________________
225TArrayI AliRsnAnalysisSE::FindGoodMatches(Int_t iRef, Int_t &foundMatches)
226{
227 // initialize the output array to the size of required mixed events
228 // and initialize all members to -1
229 Int_t i;
230 TArrayI matched(fMixingNum);
231 for (i = 0; i < fMixingNum; i++) matched[i] = -1;
232 foundMatches = 0;
233
234 // starts from the position behind the reference index
235 // and goes backward; if it reaches the value 0, stops
236 AliRsnEvent *refEvent = fBuffer->GetEvent(iRef);
237 if (!refEvent) return matched;
238 AliRsnEvent *matchEvent = 0x0;
239 Int_t checkIndex;
240 for (checkIndex = iRef - 1; ; checkIndex--) {
241 if (checkIndex < 0) checkIndex = fBuffer->GetEventsBufferSize() - 1;
242 if (checkIndex == iRef) break;
243 matchEvent = fBuffer->GetEvent(checkIndex);
244 if (!matchEvent) continue;
245 if (fMixingCut) {
246 if (!fMixingCut->IsSelected(AliRsnCut::kMixEvent, refEvent, matchEvent)) continue;
247 }
248 // assign to current array slot the matched event
249 // and increment current slot and stops if it exceeds array size
250 matched[foundMatches++] = checkIndex;
251 if (foundMatches >= fMixingNum) break;
252 }
253
254 // returns the current index value,
255 // which is also the number of matched events found
256 return matched;
257}