]>
Commit | Line | Data |
---|---|---|
9d173aad | 1 | // AliAnalysisTaskTriggerStudy |
2 | ||
3 | // Author: Michele Floris, CERN | |
4 | // TODO: | |
5 | // - Add chi2/cluster plot for primary, secondaries and fakes | |
6 | ||
7 | ||
8 | #include "AliAnalysisTaskTriggerStudy.h" | |
9 | #include "AliESDInputHandler.h" | |
10 | #include "AliHistoListWrapper.h" | |
11 | #include "AliAnalysisManager.h" | |
12 | #include "AliMCEvent.h" | |
13 | #include "AliStack.h" | |
14 | #include "TH1I.h" | |
15 | #include "TH3D.h" | |
16 | #include "AliMCParticle.h" | |
17 | #include "AliGenEventHeader.h" | |
18 | #include "AliESDCentrality.h" | |
19 | ||
20 | #include <iostream> | |
21 | #include "AliTriggerAnalysis.h" | |
22 | #include "AliMultiplicity.h" | |
23 | #include "TFile.h" | |
24 | #include "AliLog.h" | |
25 | ||
26 | using namespace std; | |
27 | ||
28 | ClassImp(AliAnalysisTaskTriggerStudy) | |
29 | ||
52d405b5 | 30 | const char * AliAnalysisTaskTriggerStudy::kVDNames[] = {"C0MBS2","C0VBA","C0VBC","C0OM2"}; |
31 | ||
9d173aad | 32 | AliAnalysisTaskTriggerStudy::AliAnalysisTaskTriggerStudy() |
33 | : AliAnalysisTaskSE("TaskTriggerStudy"), | |
52d405b5 | 34 | fESD(0),fHistoList(0),fIsMC(0),fTriggerAnalysis(0),fHistoSuffix(""),fNTrackletsCut(1000000) |
9d173aad | 35 | { |
36 | // constructor | |
37 | ||
38 | DefineOutput(1, AliHistoListWrapper::Class()); | |
39 | ||
40 | } | |
41 | AliAnalysisTaskTriggerStudy::AliAnalysisTaskTriggerStudy(const char * name) | |
42 | : AliAnalysisTaskSE(name), | |
52d405b5 | 43 | fESD(0),fHistoList(0),fIsMC(0),fTriggerAnalysis(0),fHistoSuffix(""),fNTrackletsCut(1000000) |
9d173aad | 44 | { |
45 | // | |
46 | // Standard constructur which should be used | |
47 | // | |
48 | ||
49 | DefineOutput(1, AliHistoListWrapper::Class()); | |
50 | ||
51 | } | |
52 | ||
53 | AliAnalysisTaskTriggerStudy::AliAnalysisTaskTriggerStudy(const AliAnalysisTaskTriggerStudy& obj) : | |
a82dc581 | 54 | AliAnalysisTaskSE(obj) ,fESD (0), fIsMC(0), fTriggerAnalysis(0),fHistoSuffix("") |
9d173aad | 55 | { |
56 | //copy ctor | |
57 | fESD = obj.fESD ; | |
58 | fHistoList = obj.fHistoList; | |
59 | fTriggerAnalysis = obj.fTriggerAnalysis; | |
a82dc581 | 60 | fHistoSuffix = obj.fHistoSuffix; |
9d173aad | 61 | } |
62 | ||
63 | AliAnalysisTaskTriggerStudy::~AliAnalysisTaskTriggerStudy(){ | |
64 | // destructor | |
65 | ||
66 | if(!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) { | |
67 | if(fHistoList) { | |
68 | delete fHistoList; | |
69 | fHistoList = 0; | |
70 | } | |
71 | if(fTriggerAnalysis) { | |
72 | delete fTriggerAnalysis; | |
73 | fHistoList = 0; | |
74 | } | |
75 | } | |
76 | // Histo list should not be destroyed: fListWrapper is owner! | |
77 | ||
78 | } | |
79 | void AliAnalysisTaskTriggerStudy::UserCreateOutputObjects() | |
80 | { | |
81 | // Called once | |
82 | fHistoList = new AliHistoListWrapper("histoList","histogram list for trigger studies"); | |
83 | fTriggerAnalysis = new AliTriggerAnalysis(); | |
84 | } | |
85 | ||
86 | ||
87 | void AliAnalysisTaskTriggerStudy::UserExec(Option_t *) | |
88 | { | |
89 | // User code | |
90 | ||
91 | /* PostData(0) is taken care of by AliAnalysisTaskSE */ | |
92 | PostData(1,fHistoList); | |
93 | ||
94 | fESD = dynamic_cast<AliESDEvent*>(fInputEvent); | |
95 | if (strcmp(fESD->ClassName(),"AliESDEvent")) { | |
96 | AliFatal("Not processing ESDs"); | |
97 | } | |
98 | ||
9d173aad | 99 | |
100 | // get the multiplicity object | |
101 | const AliMultiplicity* mult = fESD->GetMultiplicity(); | |
102 | Int_t ntracklets = mult->GetNumberOfTracklets(); | |
103 | ||
52d405b5 | 104 | if(ntracklets > fNTrackletsCut) return; |
105 | ||
a82dc581 | 106 | // Reset histo suffix and fill reference histograms without any suffix |
107 | fHistoSuffix = ""; | |
9d173aad | 108 | GetHistoTracklets("all","All events")->Fill(ntracklets); |
109 | ||
110 | // Fast or in the outer layer | |
111 | Int_t nFastOrOnline = fTriggerAnalysis->SPDFiredChips(fESD, 1, 0, 2); // offline | |
112 | Int_t nFastOrOffline = fTriggerAnalysis->SPDFiredChips(fESD, 0, 0, 2); // online | |
9d173aad | 113 | |
114 | Bool_t c0sm1 = nFastOrOffline >= 1; | |
115 | Bool_t c0sm2 = nFastOrOffline >= 2; | |
116 | Bool_t c0sm3 = nFastOrOffline >= 3; | |
117 | Bool_t c0sm4 = nFastOrOffline >= 4; | |
118 | Bool_t c0sm5 = nFastOrOffline >= 5; | |
119 | ||
120 | // V0 triggers | |
121 | Bool_t c0v0A = fTriggerAnalysis->IsOfflineTriggerFired(fESD, AliTriggerAnalysis::kV0A); | |
122 | Bool_t c0v0C = fTriggerAnalysis->IsOfflineTriggerFired(fESD, AliTriggerAnalysis::kV0C); | |
123 | Bool_t v0AHW = (fTriggerAnalysis->V0Trigger(fESD, AliTriggerAnalysis::kASide, kTRUE) == AliTriggerAnalysis::kV0BB);// should replay hw trigger | |
a82dc581 | 124 | Bool_t v0CHW = (fTriggerAnalysis->V0Trigger(fESD, AliTriggerAnalysis::kCSide, kTRUE) == AliTriggerAnalysis::kV0BB);// should replay hw trigger |
9d173aad | 125 | |
9d173aad | 126 | // TOF triggers |
52d405b5 | 127 | // FIXME: move to triggeranalysis? |
128 | AliESDHeader*h = fESD->GetHeader(); // taken the header from AliESDEvent | |
129 | Bool_t c0OM2 = h->IsTriggerInputFired("0OM2"); // thr >= 2 (input 19) | |
130 | Bool_t c0OM3 = h->IsTriggerInputFired("0OM3"); // thr >= 3 (input 20) | |
9d173aad | 131 | |
132 | // Some macros for the online triggers | |
133 | Bool_t cMBS2A = c0sm2 && c0v0A; | |
134 | Bool_t cMBS2C = c0sm2 && c0v0C; | |
135 | Bool_t cMBAC = c0v0A && c0v0C; | |
52d405b5 | 136 | |
9d173aad | 137 | |
52d405b5 | 138 | Bool_t vdArray[kNVDEntries]; |
139 | vdArray[kVDC0MBS2] = c0sm2; | |
140 | vdArray[kVDC0VBA] = c0v0A; | |
141 | vdArray[kVDC0VBC] = c0v0C; | |
142 | vdArray[kVDC0OM2] = c0OM2; | |
143 | ||
144 | FillTriggerOverlaps("All", "All Events",vdArray); | |
a82dc581 | 145 | |
146 | ||
147 | // loop over trigger classes in the event | |
148 | TObjArray * tokens = 0; | |
149 | if(fIsMC) { | |
150 | // in case of montecarlo I override the trigger class | |
151 | tokens = new TObjArray; | |
152 | tokens->SetOwner(); | |
153 | // tokens->Add(new TObjString("CINT1B-ABCE-NOPF-ALL")); | |
154 | tokens->Add(new TObjString("MC")); | |
155 | } | |
156 | else { | |
157 | TString trgClasses = fESD->GetFiredTriggerClasses(); | |
158 | tokens = trgClasses.Tokenize(" "); | |
159 | } | |
160 | TIter iter(tokens); | |
161 | ||
162 | while(TObjString * tok = (TObjString*) iter.Next()){ | |
163 | // clean up trigger name | |
164 | TString trg = tok->GetString(); | |
165 | trg.Strip(TString::kTrailing, ' '); | |
166 | trg.Strip(TString::kLeading, ' '); | |
167 | ||
168 | fHistoSuffix = "_"; | |
169 | fHistoSuffix += trg; | |
170 | ||
171 | // Fill histograms mismatchs | |
172 | // TODO: check mismatch trigger class | |
173 | if(nFastOrOffline != nFastOrOnline) { | |
174 | GetHistoTracklets("mismatchingFastOr", "Events where fast or offline differs from fast-or online")->Fill(ntracklets); | |
175 | } | |
176 | ||
177 | if (c0v0A != v0AHW){ | |
178 | GetHistoTracklets("mismatchingV0A", "Events where V0A offline differs from V0A online")->Fill(ntracklets); | |
179 | } | |
180 | ||
181 | if (c0v0C != v0CHW){ | |
182 | GetHistoTracklets("mismatchingV0C", "Events where V0C offline differs from V0C online")->Fill(ntracklets); | |
183 | } | |
184 | ||
185 | // Fill a tracklet histo for each trigger type | |
186 | if(c0sm1) GetHistoTracklets("c0sm1" ,"Events were trigger c0sm1 fired" )->Fill(ntracklets); | |
187 | if(c0sm2) GetHistoTracklets("c0sm2" ,"Events were trigger c0sm2 fired" )->Fill(ntracklets); | |
188 | if(c0sm3) GetHistoTracklets("c0sm3" ,"Events were trigger c0sm3 fired" )->Fill(ntracklets); | |
189 | if(c0sm4) GetHistoTracklets("c0sm4" ,"Events were trigger c0sm4 fired" )->Fill(ntracklets); | |
190 | if(c0sm5) GetHistoTracklets("c0sm5" ,"Events were trigger c0sm5 fired" )->Fill(ntracklets); | |
191 | if(c0OM2) GetHistoTracklets("c0OM2" ,"Events were trigger c0OM2 fired" )->Fill(ntracklets); | |
192 | if(c0OM3) GetHistoTracklets("c0OM3" ,"Events were trigger c0OM3 fired" )->Fill(ntracklets); | |
193 | if(c0v0A) GetHistoTracklets("c0v0A" ,"Events were trigger c0v0A fired" )->Fill(ntracklets); | |
194 | if(c0v0C) GetHistoTracklets("c0v0C" ,"Events were trigger c0v0C fired" )->Fill(ntracklets); | |
195 | if(cMBS2A) GetHistoTracklets("cMBS2A","Events were trigger cMBS2A fired")->Fill(ntracklets); | |
196 | if(cMBS2C) GetHistoTracklets("cMBS2C","Events were trigger cMBS2C fired")->Fill(ntracklets); | |
197 | if(cMBAC ) GetHistoTracklets("cMBAC ","Events were trigger cMBAC fired")->Fill(ntracklets); | |
198 | // if() GetHistoTracklets("","Events were trigger fired"); | |
52d405b5 | 199 | |
200 | // Fill trigger overlaps | |
201 | FillTriggerOverlaps("All", "All Events in trigger class",vdArray); | |
202 | ||
a82dc581 | 203 | delete tokens; |
204 | } | |
205 | ||
206 | // if (fIsMC) { | |
9d173aad | 207 | |
208 | ||
209 | // if (!fMCEvent) { | |
210 | // AliError("No MC info found"); | |
211 | // } else { | |
212 | ||
213 | // //loop on the MC event | |
214 | // // Int_t nMCTracks = fMCEvent->GetNumberOfTracks(); | |
215 | // Int_t offset = fMCEvent->GetPrimaryOffset(); | |
216 | // Int_t nMCTracks = fMCEvent->GetNumberOfPrimaries()+offset; | |
217 | // for (Int_t ipart=offset; ipart<nMCTracks; ipart++) { | |
218 | ||
219 | // AliMCParticle *mcPart = (AliMCParticle*)fMCEvent->GetTrack(ipart); | |
220 | ||
221 | // // We don't care about neutrals and non-physical primaries | |
222 | // if(mcPart->Charge() == 0) continue; | |
223 | ||
e0376287 | 224 | // PHYSICAL PRIMARY |
9d173aad | 225 | // // Get MC vertex |
e0376287 | 226 | // TArrayF vertex; |
9d173aad | 227 | // fMCEvent->GenEventHeader()->PrimaryVertex(vertex); |
228 | // Float_t zv = vertex[2]; | |
229 | // // Float_t zv = vtxESD->GetZ(); | |
230 | // // Fill generated histo | |
231 | // hTracks[AliAnalysisMultPbTrackHistoManager::kHistoGen]->Fill(mcPart->Pt(),mcPart->Eta(),zv); | |
232 | ||
233 | // } | |
234 | // } | |
235 | // } | |
236 | ||
237 | ||
238 | ||
239 | ||
240 | } | |
241 | ||
242 | void AliAnalysisTaskTriggerStudy::Terminate(Option_t *){ | |
243 | // terminate | |
244 | // Save output in a more friendly format | |
245 | fHistoList = dynamic_cast<AliHistoListWrapper*> (GetOutputData(1)); | |
246 | if (!fHistoList){ | |
247 | Printf("ERROR: fHistoList not available"); | |
248 | return; | |
249 | } | |
250 | TFile * f = new TFile("trigger_study.root", "recreate"); | |
251 | fHistoList->GetList()->Write(); | |
252 | f->Close(); | |
253 | ||
254 | } | |
255 | ||
256 | TH1 * AliAnalysisTaskTriggerStudy::GetHistoTracklets(const char * name, const char * title){ | |
a82dc581 | 257 | // Book histo of events vs ntracklets, if needed |
9d173aad | 258 | |
a82dc581 | 259 | TString hname = "hTracklets_"; |
260 | hname+=name; | |
261 | hname+=fHistoSuffix; | |
9d173aad | 262 | TH1 * h = (TH1*) fHistoList->GetList()->FindObject(hname.Data()); |
263 | ||
264 | if(!h) { | |
265 | AliInfo(Form("Booking histo %s",hname.Data())); | |
266 | Bool_t oldStatus = TH1::AddDirectoryStatus(); | |
267 | TH1::AddDirectory(kFALSE); | |
268 | h = new TH1F (hname.Data(), title, 50, 0.5, 200); | |
269 | h->Sumw2(); | |
270 | h->SetXTitle("ntracklets"); | |
271 | fHistoList->GetList()->Add(h); | |
272 | TH1::AddDirectory(oldStatus); | |
273 | } | |
274 | return h; | |
275 | } | |
276 | ||
52d405b5 | 277 | void AliAnalysisTaskTriggerStudy::FillTriggerOverlaps (const char * name, const char * title, Bool_t * vdArray){ |
a82dc581 | 278 | //Fills a histo with the different trigger statistics in a venn like diagramm. Books it if needed. |
279 | ||
280 | // Get or book histo | |
281 | TString hname = "hTrigStat_"; | |
282 | hname+=name; | |
283 | hname+=fHistoSuffix; | |
284 | TH1 * h = (TH1*) fHistoList->GetList()->FindObject(hname.Data()); | |
285 | ||
286 | if(!h) { | |
287 | AliInfo(Form("Booking histo %s",hname.Data())); | |
288 | Bool_t oldStatus = TH1::AddDirectoryStatus(); | |
289 | TH1::AddDirectory(kFALSE); | |
52d405b5 | 290 | Int_t nbins = 0; |
291 | for(Int_t ientry = 0; ientry < kNVDEntries; ientry++){ | |
292 | nbins = nbins | (1<<ientry); | |
293 | } | |
294 | ||
295 | h = new TH1I (hname, title, nbins, -0.5, nbins-0.5); | |
a82dc581 | 296 | fHistoList->GetList()->Add(h); |
297 | TH1::AddDirectory(oldStatus); | |
52d405b5 | 298 | |
299 | // we look at the combinations of n triggers | |
300 | // We set a bit for each trigger to fill the diagram | |
301 | // This is much simpler and faster than any recursive function | |
302 | h->GetXaxis()->SetBinLabel(1,"NONE"); | |
303 | for(Int_t ibin = 1; ibin < nbins; ibin++){ | |
304 | TString binname = ""; | |
305 | Bool_t first = kTRUE; | |
306 | for(Int_t ivdentry = 0; ivdentry < kNVDEntries; ivdentry++){ | |
307 | if (ibin & (1<<ivdentry)) { | |
308 | if(!first) binname += " & "; | |
309 | binname += kVDNames[ivdentry]; | |
310 | first=kFALSE; | |
311 | } | |
312 | } | |
313 | h->GetXaxis()->SetBinLabel(ibin+1,binname.Data()); | |
314 | } | |
315 | ||
a82dc581 | 316 | } |
317 | ||
52d405b5 | 318 | UInt_t mask = 0; |
319 | for(Int_t ivdentry = 0; ivdentry < kNVDEntries; ivdentry++){ | |
320 | if(vdArray[ivdentry]) { | |
321 | mask = mask | (1<<ivdentry); | |
322 | // cout << " 1 " ; | |
323 | } //else cout << " 0 "; | |
324 | } | |
325 | // cout << hex << " = " << mask << endl; | |
a82dc581 | 326 | |
52d405b5 | 327 | h->Fill(mask); |
9d173aad | 328 | |
a82dc581 | 329 | } |