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 TH1I *hUsed = new TH1I("hRsnUsed", "skipped and used events in this analysis", 2, 0, 2);
103 fOutList->Add(hUsed);
105 fBuffer = new AliRsnEventBuffer(fBufferSize);
108 //________________________________________________________________________
109 void AliRsnAnalysisSE::UserExec(Option_t *)
112 // UserExec() of AliAnalysisTaskSE
115 static UInt_t eventID = 0;
117 if (fEntry++ % 100 == 0) cout << "[" << GetName() << "] : processing entry " << fEntry-1 << endl;
119 TH1I *h = (TH1I*)fOutList->FindObject("hRsnUsed");
121 AliRsnEvent *curEvent = GetRsnEventFromInputType();
123 curEvent->SetUniqueID(eventID++);
124 ProcessEventAnalysis(curEvent);
132 PostData(1, fOutList);
135 //________________________________________________________________________
136 void AliRsnAnalysisSE::Terminate(Option_t *)
139 // Terminate() of AliAnalysisTask
142 fOutList = dynamic_cast<TList*>(GetOutputData(1));
143 if (!fOutList) { AliError("At end of analysis, output list is NULL"); return; }
147 //________________________________________________________________________
148 void AliRsnAnalysisSE::ProcessEventAnalysis(AliRsnEvent *curEvent)
151 // Process of one event
154 // Adds event to Event Buffer
155 fBuffer->AddEvent(curEvent);
156 Int_t index = fBuffer->GetEventsBufferIndex();
160 if (fDoesMixing) matched = FindGoodMatches(index, nmatches);
162 // loop over all Pair managers
163 AliRsnPairMgr *mgr=0;
164 for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++)
166 mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr);
168 for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++)
170 pair = (AliRsnPair *) mgr->GetPairs()->At(i);
171 if (!pair->IsMixed()) {
172 pair->ProcessPair(curEvent, 0);
176 for (i = 0; i < matched.GetSize(); 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);
188 //________________________________________________________________________
189 void AliRsnAnalysisSE::PostEventProcess(const Short_t & index)
192 // Post process of one event
195 if (fInputType[index] != kRSN) return;
197 if (fBuffer->GetDeleteBufferWhenReset() == kFALSE) {
198 fRSN[index] = (AliRsnEvent*) fBuffer->GetNextEvent();
199 SetBranchAddress(0 , "rsnEvents", &fRSN[index]);
203 //________________________________________________________________________
204 void AliRsnAnalysisSE::AddPairMgr(AliRsnPairMgr * pairmgr)
206 fPairMgrs.Add(pairmgr);
209 //________________________________________________________________________
210 void AliRsnAnalysisSE::AddPairMgrFromConfig(TString configfile)
212 gROOT->LoadMacro(configfile.Data());
214 configfile.ReplaceAll(".C","");
216 AliRsnPairMgr *mgrRsn = (AliRsnPairMgr *) gROOT->ProcessLine(Form("%s();", configfile.Data()));
219 fPairMgrs.Add(mgrRsn);
222 //________________________________________________________________________
223 TArrayI AliRsnAnalysisSE::FindGoodMatches(Int_t iRef, Int_t &foundMatches)
225 // initialize the output array to the size of required mixed events
226 // and initialize all members to -1
228 TArrayI matched(fMixingNum);
229 for (i = 0; i < fMixingNum; i++) matched[i] = -1;
232 // starts from the position behind the reference index
233 // and goes backward; if it reaches the value 0, stops
234 AliRsnEvent *refEvent = fBuffer->GetEvent(iRef);
235 if (!refEvent) return matched;
236 AliRsnEvent *matchEvent = 0x0;
238 for (checkIndex = iRef - 1; ; checkIndex--) {
239 if (checkIndex < 0) checkIndex = fBuffer->GetEventsBufferSize() - 1;
240 if (checkIndex == iRef) break;
241 matchEvent = fBuffer->GetEvent(checkIndex);
242 if (!matchEvent) continue;
244 if (!fMixingCut->IsSelected(AliRsnCut::kMixEvent, refEvent, matchEvent)) continue;
246 // assign to current array slot the matched event
247 // and increment current slot and stops if it exceeds array size
248 matched[foundMatches++] = checkIndex;
249 if (foundMatches >= fMixingNum) break;
252 // returns the current index value,
253 // which is also the number of matched events found