2 // Class AliRsnAnalysisSE
6 // authors: Martin Vala (martin.vala@cern.ch)
7 // Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
10 #include <Riostream.h>
19 #include "AliAnalysisManager.h"
20 #include "AliRsnPairMgr.h"
21 #include "AliRsnEventBuffer.h"
23 #include "AliMCEventHandler.h"
24 #include "AliESDEvent.h"
26 #include "AliRsnAnalysisSE.h"
28 ClassImp(AliRsnAnalysisSE)
30 //________________________________________________________________________
31 AliRsnAnalysisSE::AliRsnAnalysisSE(const char * name, Int_t bufferSize) :
32 AliRsnAnalysisTaskSEBase(name),
39 fBufferSize(bufferSize)
42 // Default constructor
46 DefineOutput(1, TList::Class());
49 //________________________________________________________________________
50 AliRsnAnalysisSE::~AliRsnAnalysisSE()
57 //________________________________________________________________________
58 void AliRsnAnalysisSE::InitIOVars()
61 // Init input output values
64 AliRsnAnalysisTaskSEBase::InitIOVars();
70 //________________________________________________________________________
71 void AliRsnAnalysisSE::UserCreateOutputObjects()
74 // UserCreateOutputObjects() of AliAnalysisTaskSE
78 fOutList = new TList();
84 for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++)
86 mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr);
88 listTmp = new TList();
89 listTmp->SetName(mgr->GetName());
90 for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++)
92 def = (AliRsnPair *) mgr->GetPairs()->At(i);
95 listTmp->Add(def->GenerateHistograms(mgr->GetName()));
96 if (def->IsMixed()) fDoesMixing = kTRUE;
99 fOutList->Add(listTmp);
102 fBuffer = new AliRsnEventBuffer(fBufferSize);
105 //________________________________________________________________________
106 void AliRsnAnalysisSE::UserExec(Option_t *)
109 // UserExec() of AliAnalysisTaskSE
112 static UInt_t eventID = 0;
114 if (fEntry++ % 100 == 0) cout << "[" << GetName() << "] : processing entry " << fEntry-1 << endl;
116 AliRsnEvent *curEvent = GetRsnEventFromInputType();
117 if (!curEvent) return;
118 curEvent->SetUniqueID(eventID++);
120 ProcessEventAnalysis(curEvent);
123 PostData(1, fOutList);
126 //________________________________________________________________________
127 void AliRsnAnalysisSE::Terminate(Option_t *)
130 // Terminate() of AliAnalysisTask
133 fOutList = dynamic_cast<TList*>(GetOutputData(1));
134 if (!fOutList) { AliError("At end of analysis, output list is NULL"); return; }
138 //________________________________________________________________________
139 void AliRsnAnalysisSE::ProcessEventAnalysis(AliRsnEvent *curEvent)
142 // Process of one event
145 // Adds event to Event Buffer
146 fBuffer->AddEvent(curEvent);
147 Int_t index = fBuffer->GetEventsBufferIndex();
151 if (fDoesMixing) matched = FindGoodMatches(index, nmatches);
153 // loop over all Pair managers
154 AliRsnPairMgr *mgr=0;
155 for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++)
157 mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr);
159 for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++)
161 pair = (AliRsnPair *) mgr->GetPairs()->At(i);
162 if (!pair->IsMixed()) {
163 pair->ProcessPair(curEvent, 0);
167 for (i = 0; i < matched.GetSize(); i++) {
169 if (iev < 0) continue;
170 AliRsnEvent *evmatch = fBuffer->GetEvent(iev);
171 pair->ProcessPair(curEvent, evmatch);
172 if (!pair->IsPairEqual()) pair->ProcessPair(evmatch, curEvent);
179 //________________________________________________________________________
180 void AliRsnAnalysisSE::PostEventProcess(const Short_t & index)
183 // Post process of one event
186 if (fInputType[index] != kRSN) return;
188 if (fBuffer->GetDeleteBufferWhenReset() == kFALSE) {
189 fRSN[index] = (AliRsnEvent*) fBuffer->GetNextEvent();
190 SetBranchAddress(0 , "rsnEvents", &fRSN[index]);
194 //________________________________________________________________________
195 void AliRsnAnalysisSE::AddPairMgr(AliRsnPairMgr * pairmgr)
197 fPairMgrs.Add(pairmgr);
200 //________________________________________________________________________
201 void AliRsnAnalysisSE::AddPairMgrFromConfig(TString configfile)
203 gROOT->LoadMacro(configfile.Data());
205 configfile.ReplaceAll(".C","");
207 AliRsnPairMgr *mgrRsn = (AliRsnPairMgr *) gROOT->ProcessLine(Form("%s();", configfile.Data()));
210 fPairMgrs.Add(mgrRsn);
213 //________________________________________________________________________
214 TArrayI AliRsnAnalysisSE::FindGoodMatches(Int_t iRef, Int_t &foundMatches)
216 // initialize the output array to the size of required mixed events
217 // and initialize all members to -1
219 TArrayI matched(fMixingNum);
220 for (i = 0; i < fMixingNum; i++) matched[i] = -1;
223 // starts from the position behind the reference index
224 // and goes backward; if it reaches the value 0, stops
225 AliRsnEvent *refEvent = fBuffer->GetEvent(iRef);
226 if (!refEvent) return matched;
227 AliRsnEvent *matchEvent = 0x0;
229 for (checkIndex = iRef - 1; ; checkIndex--) {
230 if (checkIndex < 0) checkIndex = fBuffer->GetEventsBufferSize() - 1;
231 if (checkIndex == iRef) break;
232 matchEvent = fBuffer->GetEvent(checkIndex);
233 if (!matchEvent) continue;
235 if (!fMixingCut->IsSelected(AliRsnCut::kMixEvent, refEvent, matchEvent)) continue;
237 // assign to current array slot the matched event
238 // and increment current slot and stops if it exceeds array size
239 matched[foundMatches++] = checkIndex;
240 if (foundMatches >= fMixingNum) break;
243 // returns the current index value,
244 // which is also the number of matched events found