1 // AliAnalysisTaskTriggerStudy
3 // Author: Michele Floris, CERN
5 // - Add chi2/cluster plot for primary, secondaries and fakes
8 #include "AliAnalysisTaskTriggerStudy.h"
9 #include "AliESDInputHandler.h"
10 #include "AliHistoListWrapper.h"
11 #include "AliAnalysisManager.h"
12 #include "AliMCEvent.h"
16 #include "AliMCParticle.h"
17 #include "AliGenEventHeader.h"
18 #include "AliESDCentrality.h"
21 #include "AliTriggerAnalysis.h"
22 #include "AliMultiplicity.h"
28 ClassImp(AliAnalysisTaskTriggerStudy)
30 AliAnalysisTaskTriggerStudy::AliAnalysisTaskTriggerStudy()
31 : AliAnalysisTaskSE("TaskTriggerStudy"),
32 fESD(0),fHistoList(0),fIsMC(0),fTriggerAnalysis(0),fHistoSuffix("")
36 DefineOutput(1, AliHistoListWrapper::Class());
39 AliAnalysisTaskTriggerStudy::AliAnalysisTaskTriggerStudy(const char * name)
40 : AliAnalysisTaskSE(name),
41 fESD(0),fHistoList(0),fIsMC(0),fTriggerAnalysis(0),fHistoSuffix("")
44 // Standard constructur which should be used
47 DefineOutput(1, AliHistoListWrapper::Class());
51 AliAnalysisTaskTriggerStudy::AliAnalysisTaskTriggerStudy(const AliAnalysisTaskTriggerStudy& obj) :
52 AliAnalysisTaskSE(obj) ,fESD (0), fIsMC(0), fTriggerAnalysis(0),fHistoSuffix("")
56 fHistoList = obj.fHistoList;
57 fTriggerAnalysis = obj.fTriggerAnalysis;
58 fHistoSuffix = obj.fHistoSuffix;
61 AliAnalysisTaskTriggerStudy::~AliAnalysisTaskTriggerStudy(){
64 if(!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
69 if(fTriggerAnalysis) {
70 delete fTriggerAnalysis;
74 // Histo list should not be destroyed: fListWrapper is owner!
77 void AliAnalysisTaskTriggerStudy::UserCreateOutputObjects()
80 fHistoList = new AliHistoListWrapper("histoList","histogram list for trigger studies");
81 fTriggerAnalysis = new AliTriggerAnalysis();
85 void AliAnalysisTaskTriggerStudy::UserExec(Option_t *)
89 /* PostData(0) is taken care of by AliAnalysisTaskSE */
90 PostData(1,fHistoList);
92 fESD = dynamic_cast<AliESDEvent*>(fInputEvent);
93 if (strcmp(fESD->ClassName(),"AliESDEvent")) {
94 AliFatal("Not processing ESDs");
97 // FIXME: two options here: either we add a loop setting the name of
98 // the histos with the trigger class in them (there may be a global
99 // SetHistoNamePrefix) or I put a cut to select only collision
102 // get the multiplicity object
103 const AliMultiplicity* mult = fESD->GetMultiplicity();
104 Int_t ntracklets = mult->GetNumberOfTracklets();
106 // Reset histo suffix and fill reference histograms without any suffix
108 GetHistoTracklets("all","All events")->Fill(ntracklets);
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
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;
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
124 Bool_t v0CHW = (fTriggerAnalysis->V0Trigger(fESD, AliTriggerAnalysis::kCSide, kTRUE) == AliTriggerAnalysis::kV0BB);// should replay hw trigger
127 // FIXME: implement real triggers
128 Bool_t c0OM2 = kFALSE;
129 Bool_t c0OM3 = kFALSE;
131 // Some macros for the online triggers
132 Bool_t cMBS2A = c0sm2 && c0v0A;
133 Bool_t cMBS2C = c0sm2 && c0v0C;
134 Bool_t cMBAC = c0v0A && c0v0C;
136 FillTriggerOverlaps("All", "All Events", nFastOrOffline,c0v0A,c0v0C,c0OM2,c0OM3,cMBS2A,cMBS2C,cMBAC);
139 // loop over trigger classes in the event
140 TObjArray * tokens = 0;
142 // in case of montecarlo I override the trigger class
143 tokens = new TObjArray;
145 // tokens->Add(new TObjString("CINT1B-ABCE-NOPF-ALL"));
146 tokens->Add(new TObjString("MC"));
149 TString trgClasses = fESD->GetFiredTriggerClasses();
150 tokens = trgClasses.Tokenize(" ");
154 while(TObjString * tok = (TObjString*) iter.Next()){
155 // clean up trigger name
156 TString trg = tok->GetString();
157 trg.Strip(TString::kTrailing, ' ');
158 trg.Strip(TString::kLeading, ' ');
163 // Fill histograms mismatchs
164 // TODO: check mismatch trigger class
165 if(nFastOrOffline != nFastOrOnline) {
166 GetHistoTracklets("mismatchingFastOr", "Events where fast or offline differs from fast-or online")->Fill(ntracklets);
170 GetHistoTracklets("mismatchingV0A", "Events where V0A offline differs from V0A online")->Fill(ntracklets);
174 GetHistoTracklets("mismatchingV0C", "Events where V0C offline differs from V0C online")->Fill(ntracklets);
177 // Fill a tracklet histo for each trigger type
178 if(c0sm1) GetHistoTracklets("c0sm1" ,"Events were trigger c0sm1 fired" )->Fill(ntracklets);
179 if(c0sm2) GetHistoTracklets("c0sm2" ,"Events were trigger c0sm2 fired" )->Fill(ntracklets);
180 if(c0sm3) GetHistoTracklets("c0sm3" ,"Events were trigger c0sm3 fired" )->Fill(ntracklets);
181 if(c0sm4) GetHistoTracklets("c0sm4" ,"Events were trigger c0sm4 fired" )->Fill(ntracklets);
182 if(c0sm5) GetHistoTracklets("c0sm5" ,"Events were trigger c0sm5 fired" )->Fill(ntracklets);
183 if(c0OM2) GetHistoTracklets("c0OM2" ,"Events were trigger c0OM2 fired" )->Fill(ntracklets);
184 if(c0OM3) GetHistoTracklets("c0OM3" ,"Events were trigger c0OM3 fired" )->Fill(ntracklets);
185 if(c0v0A) GetHistoTracklets("c0v0A" ,"Events were trigger c0v0A fired" )->Fill(ntracklets);
186 if(c0v0C) GetHistoTracklets("c0v0C" ,"Events were trigger c0v0C fired" )->Fill(ntracklets);
187 if(cMBS2A) GetHistoTracklets("cMBS2A","Events were trigger cMBS2A fired")->Fill(ntracklets);
188 if(cMBS2C) GetHistoTracklets("cMBS2C","Events were trigger cMBS2C fired")->Fill(ntracklets);
189 if(cMBAC ) GetHistoTracklets("cMBAC ","Events were trigger cMBAC fired")->Fill(ntracklets);
190 // if() GetHistoTracklets("","Events were trigger fired");
198 // AliError("No MC info found");
201 // //loop on the MC event
202 // // Int_t nMCTracks = fMCEvent->GetNumberOfTracks();
203 // Int_t offset = fMCEvent->GetPrimaryOffset();
204 // Int_t nMCTracks = fMCEvent->GetNumberOfPrimaries()+offset;
205 // for (Int_t ipart=offset; ipart<nMCTracks; ipart++) {
207 // AliMCParticle *mcPart = (AliMCParticle*)fMCEvent->GetTrack(ipart);
209 // // We don't care about neutrals and non-physical primaries
210 // if(mcPart->Charge() == 0) continue;
212 // // FIXME: add kTransportBit (uncomment below)
213 // if(!fMCEvent->Stack()->IsPhysicalPrimary(ipart)) continue;
215 // //check if current particle is a physical primary
216 // // Bool_t physprim=fMCEvent->IsPhysicalPrimary(label);
217 // // if (!physprim) continue;
218 // // if (!track) return kFALSE;
219 // // Bool_t transported = mcPart->Particle()->TestBit(kTransportBit);
220 // // if(!transported) return kFALSE;
223 // //FIXME: which vertex do I take for MC?
225 // fMCEvent->GenEventHeader()->PrimaryVertex(vertex);
226 // Float_t zv = vertex[2];
227 // // Float_t zv = vtxESD->GetZ();
228 // // Fill generated histo
229 // hTracks[AliAnalysisMultPbTrackHistoManager::kHistoGen]->Fill(mcPart->Pt(),mcPart->Eta(),zv);
240 void AliAnalysisTaskTriggerStudy::Terminate(Option_t *){
242 // Save output in a more friendly format
243 fHistoList = dynamic_cast<AliHistoListWrapper*> (GetOutputData(1));
245 Printf("ERROR: fHistoList not available");
248 TFile * f = new TFile("trigger_study.root", "recreate");
249 fHistoList->GetList()->Write();
254 TH1 * AliAnalysisTaskTriggerStudy::GetHistoTracklets(const char * name, const char * title){
255 // Book histo of events vs ntracklets, if needed
257 TString hname = "hTracklets_";
260 TH1 * h = (TH1*) fHistoList->GetList()->FindObject(hname.Data());
263 AliInfo(Form("Booking histo %s",hname.Data()));
264 Bool_t oldStatus = TH1::AddDirectoryStatus();
265 TH1::AddDirectory(kFALSE);
266 h = new TH1F (hname.Data(), title, 50, 0.5, 200);
268 h->SetXTitle("ntracklets");
269 fHistoList->GetList()->Add(h);
270 TH1::AddDirectory(oldStatus);
275 void AliAnalysisTaskTriggerStudy::FillTriggerOverlaps (const char * name, const char * title,
276 Int_t nFastOrOffline,
277 Bool_t v0A, Bool_t v0C, Bool_t OM2, Bool_t OM3,
278 Bool_t cMBS2A,Bool_t cMBS2C, Bool_t cMBAC) {
279 //Fills a histo with the different trigger statistics in a venn like diagramm. Books it if needed.
282 TString hname = "hTrigStat_";
285 TH1 * h = (TH1*) fHistoList->GetList()->FindObject(hname.Data());
288 AliInfo(Form("Booking histo %s",hname.Data()));
289 Bool_t oldStatus = TH1::AddDirectoryStatus();
290 TH1::AddDirectory(kFALSE);
292 h = new TH1I (hname, title, nbins, 0.5, nbins+0.5);
293 fHistoList->GetList()->Add(h);
294 TH1::AddDirectory(oldStatus);
297 // we look at the combinations of 4 triggers
299 h->GetXaxis()->SetBinLabel(ibin++,"FO2 & V0A & V0C & OM2");
300 h->GetXaxis()->SetBinLabel(ibin++,"FO2 & V0C & OM2");
301 h->GetXaxis()->SetBinLabel(ibin++,"FO2 & V0A & OM2");
302 h->GetXaxis()->SetBinLabel(ibin++,"FO2 & V0A & V0C");
303 h->GetXaxis()->SetBinLabel(ibin++,"FO2 & V0A");
304 h->GetXaxis()->SetBinLabel(ibin++,"FO2 & V0C");
305 h->GetXaxis()->SetBinLabel(ibin++,"FO2 & OM2");
306 h->GetXaxis()->SetBinLabel(ibin++,"OM2 & V0A");
307 h->GetXaxis()->SetBinLabel(ibin++,"OM2 & V0C");
308 h->GetXaxis()->SetBinLabel(ibin++,"V0A & V0C");
309 h->GetXaxis()->SetBinLabel(ibin++,"FO2");
310 h->GetXaxis()->SetBinLabel(ibin++,"V0A");
311 h->GetXaxis()->SetBinLabel(ibin++,"V0C");
312 h->GetXaxis()->SetBinLabel(ibin++,"OM2");
314 Bool_t fo2 = nFastOrOffline>=2;
316 if(fo2 && v0A && v0C && OM2) {cout << "Bin5: " << ibin << endl; h->Fill(1);}
317 if(fo2 && !v0A && v0C && OM2) {cout << "Bin6: " << ibin << endl; h->Fill(2);}
318 if(fo2 && v0A && !v0C && OM2) {cout << "Bin7: " << ibin << endl; h->Fill(3);}
319 if(fo2 && v0A && v0C && !OM2) {cout << "Bin8: " << ibin << endl; h->Fill(4);}
320 if(fo2 && v0A && !v0C && !OM2) {cout << "Bin9: " << ibin << endl; h->Fill(5);}
321 if(fo2 && !v0A && v0C && !OM2) {cout << "Bin10: " << ibin << endl; h->Fill(6);}
322 if(fo2 && !v0A && !v0C && OM2) {cout << "Bin11: " << ibin << endl; h->Fill(7);}
323 if(!fo2 && v0A && !v0C && OM2) {cout << "Bin12: " << ibin << endl; h->Fill(8);}
324 if(!fo2 && !v0A && v0C && OM2) {cout << "Bin13: " << ibin << endl; h->Fill(9);}
325 if(!fo2 && v0A && v0C && !OM2) {cout << "Bin14: " << ibin << endl; h->Fill(10);}
326 if(fo2 && !v0A && !v0C && !OM2) {cout << "Bin1: " << ibin << endl; h->Fill(11);}
327 if(!fo2 && v0A && !v0C && !OM2) {cout << "Bin2: " << ibin << endl; h->Fill(12);}
328 if(!fo2 && !v0A && v0C && !OM2) {cout << "Bin3: " << ibin << endl; h->Fill(13);}
329 if(!fo2 && !v0A && !v0C && OM2) {cout << "Bin4: " << ibin << endl; h->Fill(14);}