]>
Commit | Line | Data |
---|---|---|
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 | ||
28 | ClassImp(AliRsnAnalysisSE) | |
29 | ||
30 | //________________________________________________________________________ | |
15d5fd02 | 31 | AliRsnAnalysisSE::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 | //________________________________________________________________________ | |
50 | AliRsnAnalysisSE::~AliRsnAnalysisSE() | |
51 | { | |
15d5fd02 | 52 | // |
aec0ec32 | 53 | // Destructor |
15d5fd02 | 54 | // |
aec0ec32 | 55 | } |
56 | ||
57 | //________________________________________________________________________ | |
58 | void 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 | //________________________________________________________________________ | |
71 | void 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; | |
71ca2775 | 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; | |
e343e521 | 88 | //listTmp = new TList(); |
89 | //listTmp->SetName(mgr->GetName()); | |
aec0ec32 | 90 | for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++) |
91 | { | |
92 | def = (AliRsnPair *) mgr->GetPairs()->At(i); | |
93 | if (def) | |
94 | { | |
e343e521 | 95 | //listTmp->Add(def->GenerateHistograms(mgr->GetName())); |
96 | def->GenerateHistograms(mgr->GetName(), fOutList); | |
15d5fd02 | 97 | if (def->IsMixed()) fDoesMixing = kTRUE; |
aec0ec32 | 98 | } |
99 | } | |
e343e521 | 100 | //fOutList->Add(listTmp); |
aec0ec32 | 101 | } |
102 | ||
cc781f3d | 103 | TH1I *hUsed = new TH1I("hRsnUsed", "skipped and used events in this analysis", 2, 0, 2); |
104 | fOutList->Add(hUsed); | |
105 | ||
15d5fd02 | 106 | fBuffer = new AliRsnEventBuffer(fBufferSize); |
aec0ec32 | 107 | } |
108 | ||
109 | //________________________________________________________________________ | |
110 | void AliRsnAnalysisSE::UserExec(Option_t *) | |
111 | { | |
15d5fd02 | 112 | // |
aec0ec32 | 113 | // UserExec() of AliAnalysisTaskSE |
15d5fd02 | 114 | // |
115 | ||
116 | static UInt_t eventID = 0; | |
aec0ec32 | 117 | |
15d5fd02 | 118 | if (fEntry++ % 100 == 0) cout << "[" << GetName() << "] : processing entry " << fEntry-1 << endl; |
aec0ec32 | 119 | |
cc781f3d | 120 | TH1I *h = (TH1I*)fOutList->FindObject("hRsnUsed"); |
aec0ec32 | 121 | |
cc781f3d | 122 | AliRsnEvent *curEvent = GetRsnEventFromInputType(); |
123 | if (curEvent) { | |
124 | curEvent->SetUniqueID(eventID++); | |
125 | ProcessEventAnalysis(curEvent); | |
126 | PostEventProcess(); | |
127 | h->Fill(1); | |
128 | } | |
129 | else { | |
130 | h->Fill(0); | |
131 | } | |
aec0ec32 | 132 | |
133 | PostData(1, fOutList); | |
134 | } | |
135 | ||
136 | //________________________________________________________________________ | |
137 | void AliRsnAnalysisSE::Terminate(Option_t *) | |
138 | { | |
15d5fd02 | 139 | // |
aec0ec32 | 140 | // Terminate() of AliAnalysisTask |
15d5fd02 | 141 | // |
aec0ec32 | 142 | |
143 | fOutList = dynamic_cast<TList*>(GetOutputData(1)); | |
15d5fd02 | 144 | if (!fOutList) { AliError("At end of analysis, output list is NULL"); return; } |
145 | //fOutList->Print(); | |
aec0ec32 | 146 | } |
147 | ||
148 | //________________________________________________________________________ | |
149 | void AliRsnAnalysisSE::ProcessEventAnalysis(AliRsnEvent *curEvent) | |
150 | { | |
15d5fd02 | 151 | // |
aec0ec32 | 152 | // Process of one event |
15d5fd02 | 153 | // |
aec0ec32 | 154 | |
155 | // Adds event to Event Buffer | |
15d5fd02 | 156 | fBuffer->AddEvent(curEvent); |
157 | Int_t index = fBuffer->GetEventsBufferIndex(); | |
158 | ||
159 | Int_t nmatches; | |
160 | TArrayI matched(0); | |
161 | if (fDoesMixing) matched = FindGoodMatches(index, nmatches); | |
aec0ec32 | 162 | |
163 | // loop over all Pair managers | |
164 | AliRsnPairMgr *mgr=0; | |
165 | for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++) | |
166 | { | |
167 | mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr); | |
168 | AliRsnPair *pair=0; | |
169 | for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++) | |
170 | { | |
171 | pair = (AliRsnPair *) mgr->GetPairs()->At(i); | |
15d5fd02 | 172 | if (!pair->IsMixed()) { |
173 | pair->ProcessPair(curEvent, 0); | |
174 | } | |
175 | else { | |
71ca2775 | 176 | Int_t j, iev; |
177 | for (j = 0; j < matched.GetSize(); j++) { | |
178 | iev = matched[j]; | |
15d5fd02 | 179 | if (iev < 0) continue; |
180 | AliRsnEvent *evmatch = fBuffer->GetEvent(iev); | |
181 | pair->ProcessPair(curEvent, evmatch); | |
182 | if (!pair->IsPairEqual()) pair->ProcessPair(evmatch, curEvent); | |
183 | } | |
184 | } | |
aec0ec32 | 185 | } |
186 | } | |
187 | } | |
188 | ||
189 | //________________________________________________________________________ | |
190 | void AliRsnAnalysisSE::PostEventProcess(const Short_t & index) | |
191 | { | |
15d5fd02 | 192 | // |
aec0ec32 | 193 | // Post process of one event |
15d5fd02 | 194 | // |
aec0ec32 | 195 | |
15d5fd02 | 196 | if (fInputType[index] != kRSN) return; |
aec0ec32 | 197 | |
15d5fd02 | 198 | if (fBuffer->GetDeleteBufferWhenReset() == kFALSE) { |
199 | fRSN[index] = (AliRsnEvent*) fBuffer->GetNextEvent(); | |
200 | SetBranchAddress(0 , "rsnEvents", &fRSN[index]); | |
201 | } | |
aec0ec32 | 202 | } |
203 | ||
15d5fd02 | 204 | //________________________________________________________________________ |
aec0ec32 | 205 | void AliRsnAnalysisSE::AddPairMgr(AliRsnPairMgr * pairmgr) |
206 | { | |
207 | fPairMgrs.Add(pairmgr); | |
208 | } | |
922688c0 | 209 | |
15d5fd02 | 210 | //________________________________________________________________________ |
8a6b5ac8 | 211 | void AliRsnAnalysisSE::AddPairMgrFromConfig(TString configfile,TString analysisName) |
922688c0 | 212 | { |
213 | gROOT->LoadMacro(configfile.Data()); | |
214 | ||
215 | configfile.ReplaceAll(".C",""); | |
216 | ||
8a6b5ac8 | 217 | analysisName.ReplaceAll("_","-"); |
218 | ||
219 | AliRsnPairMgr *mgrRsn = (AliRsnPairMgr *) gROOT->ProcessLine(Form("%s(\"%s\");", configfile.Data(),analysisName.Data())); | |
922688c0 | 220 | if (!mgrRsn) return; |
221 | ||
222 | fPairMgrs.Add(mgrRsn); | |
223 | } | |
15d5fd02 | 224 | |
225 | //________________________________________________________________________ | |
226 | TArrayI AliRsnAnalysisSE::FindGoodMatches(Int_t iRef, Int_t &foundMatches) | |
227 | { | |
228 | // initialize the output array to the size of required mixed events | |
229 | // and initialize all members to -1 | |
230 | Int_t i; | |
231 | TArrayI matched(fMixingNum); | |
232 | for (i = 0; i < fMixingNum; i++) matched[i] = -1; | |
233 | foundMatches = 0; | |
234 | ||
235 | // starts from the position behind the reference index | |
236 | // and goes backward; if it reaches the value 0, stops | |
237 | AliRsnEvent *refEvent = fBuffer->GetEvent(iRef); | |
238 | if (!refEvent) return matched; | |
239 | AliRsnEvent *matchEvent = 0x0; | |
240 | Int_t checkIndex; | |
241 | for (checkIndex = iRef - 1; ; checkIndex--) { | |
242 | if (checkIndex < 0) checkIndex = fBuffer->GetEventsBufferSize() - 1; | |
243 | if (checkIndex == iRef) break; | |
244 | matchEvent = fBuffer->GetEvent(checkIndex); | |
245 | if (!matchEvent) continue; | |
246 | if (fMixingCut) { | |
247 | if (!fMixingCut->IsSelected(AliRsnCut::kMixEvent, refEvent, matchEvent)) continue; | |
248 | } | |
249 | // assign to current array slot the matched event | |
250 | // and increment current slot and stops if it exceeds array size | |
251 | matched[foundMatches++] = checkIndex; | |
252 | if (foundMatches >= fMixingNum) break; | |
253 | } | |
254 | ||
255 | // returns the current index value, | |
256 | // which is also the number of matched events found | |
257 | return matched; | |
258 | } |