26 #include "TObjString.h"
27 #include "TObjArray.h"
30 #include "TGraphAsymmErrors.h"
35 #include "AliVParticle.h"
36 #include "AliAODTrack.h"
37 #include "AliESDMuonTrack.h"
40 #include "AliAnalysisManager.h"
41 #include "AliAnalysisDataSlot.h"
42 #include "AliAnalysisDataContainer.h"
45 #include "AliVAnalysisMuon.h"
46 #include "AliMuonEventCuts.h"
47 #include "AliMuonTrackCuts.h"
48 #include "AliMergeableCollection.h"
49 #include "AliAnalysisMuonUtility.h"
73 AliVAnalysisMuon(name, cuts),
88 DefineOutput(2, TList::Class());
103 if ( ! AliAnalysisManager::GetAnalysisManager() || ! AliAnalysisManager::GetAnalysisManager()->IsProofMode() ) {
114 TList* outList =
new TList();
116 FillEffHistoList(physSel, trigClassNames, centrality, trackSelection, outList);
128 if ( ! fMergeableCollection )
return kFALSE;
129 TString histoName =
"";
130 TString histoPattern =
"";
133 for ( Int_t icount=0; icount<
kNcounts; ++icount ) {
135 histoPattern = Form(
"%s%s", histoName.Data(), trackSelection.Data());
136 histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
138 histo->SetName(histoName.Data());
139 histo->SetTitle(histoName.Data());
145 histo->SetDirectory(0);
148 for ( Int_t icount=0; icount<
kNcounts; ++icount ) {
149 for ( Int_t ich=0; ich<4; ++ich ) {
151 histoPattern = Form(
"%s%s", histoName.Data(), trackSelection.Data());
152 histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
154 histo->SetName(histoName.Data());
155 histo->SetTitle(histoName.Data());
161 histo->SetDirectory(0);
165 for ( Int_t icount=0; icount<
kNcounts; ++icount ) {
166 for ( Int_t ich=0; ich<4; ++ich ) {
168 histoPattern = Form(
"%s%s", histoName.Data(), trackSelection.Data());
169 histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
171 histo->SetName(histoName.Data());
172 histo->SetTitle(histoName.Data());
178 histo->SetDirectory(0);
184 histoPattern = Form(
"%s%s", histoName.Data(), trackSelection.Data());
185 histo = (TH1*)GetSum(physSel, trigClassNames, centrality, histoPattern);
187 histo->SetName(histoName.Data());
188 histo->SetTitle(histoName.Data());
193 histo->SetDirectory(0);
207 TString histoName =
"";
208 for ( Int_t isel=0; isel<kNselections; ++isel ) {
209 for ( Int_t itrig=0; itrig<GetAllSelectedTrigClasses()->GetEntries(); ++itrig ) {
210 for ( Int_t icent=1; icent<=GetCentralityClasses()->GetNbins(); ++icent ) {
211 for ( Int_t itrackSel=0; itrackSel<
kNtrackSel; ++itrackSel ) {
212 for ( Int_t imethod=0; imethod<
kNeffMethods; ++imethod ) {
214 for ( Int_t icount=-1; icount<
kNcounts; ++icount ) {
215 for ( Int_t ich=-1; ich<4; ++ich ) {
218 for ( Int_t jmatch=imatch+1; jmatch<=
kMatchHpt; ++jmatch ) {
219 histoName =
GetHistoName(itype, icount, ich, itrackSel, jmatch, imethod);
220 TH1* histoAdd = (TH1*)fMergeableCollection->GetObject(Form(
"/%s/%s/%s/",fPhysSelKeys->At(isel)->GetName(), GetAllSelectedTrigClasses()->At(itrig)->GetName(), GetCentralityClasses()->GetBinLabel(icent)), histoName);
221 if ( ! histoAdd )
continue;
222 histoName =
GetHistoName(itype, icount, ich, itrackSel, imatch, imethod);
223 if ( ! histo ) histo = (TH1*)GetMergeableObject(fPhysSelKeys->At(isel)->GetName(), GetAllSelectedTrigClasses()->At(itrig)->GetName(), GetCentralityClasses()->GetBinLabel(icent), histoName);
224 AliDebug(2,Form(
"Adding %s (%g) to %s (%g)", histoAdd->GetName(), histoAdd->Integral(), histo->GetName(), histo->Integral()));
225 histo->Add(histoAdd);
237 TString physSel = fPhysSelKeys->At(kPhysSelPass)->GetName();
238 TString trigClass =
"ANY";
239 TString centrality =
"all";
244 AliVAnalysisMuon::FinishTaskOutput();
255 TString matchTrigNames =
"Nopt Apt Lpt Hpt";
258 TString countTypeNames =
"bendPlaneCount nonBendPlaneCount bothPlanesCount allTracksCount";
261 TString histoTypeKeys =
"Chamber Slat Board checkRejectedBoard";
264 TString effMethodKeys =
"FromTrk FromTrg";
267 TString trackSelNames =
"Match NoSelMatch";
278 TString histoName =
"";
281 for ( Int_t itrackSel = 0; itrackSel<
kNtrackSel; ++itrackSel ) {
282 for ( Int_t imethod=0; imethod<
kNeffMethods; ++imethod ) {
283 for ( Int_t imatch = 0; imatch<
kNtrigMatch; ++imatch ) {
284 for ( Int_t icount=0; icount<
kNcounts; ++icount ) {
286 for ( Int_t ich=0; ich<4; ++ich ) {
297 fMuonTrackCuts->Print();
311 Int_t nBoardBins = 234;
312 Float_t boardLow = 1.-0.5, boardHigh = (Float_t)nBoardBins+1.-0.5;
313 const Char_t* boardName =
"board";
315 TString histoName =
"";
320 histo =
new TH1F(histoName, histoName, 4, 11.-0.5, 4.+11.-0.5);
321 histo->GetXaxis()->SetTitle(
"chamber");
322 histo->GetYaxis()->SetTitle(
"counts");
326 histo =
new TH1F(histoName, histoName, 18, 0.-0.5, 18.-0.5);
327 histo->GetXaxis()->SetTitle(
"slat");
328 histo->GetYaxis()->SetTitle(
"counts");
332 histo =
new TH1F(histoName, histoName, nBoardBins, boardLow, boardHigh);
333 histo->GetXaxis()->SetTitle(boardName);
334 histo->GetYaxis()->SetTitle(
"counts");
338 histo =
new TH2F(histoName.Data(),
"Rejected tracks motivation", 5, 20.5, 25.5, nBoardBins, boardLow, boardHigh);
339 histo->GetXaxis()->SetBinLabel(1,
"Many pads");
340 histo->GetXaxis()->SetBinLabel(2,
"Few pads");
341 histo->GetXaxis()->SetBinLabel(3,
"Outside geom");
342 histo->GetXaxis()->SetBinLabel(4,
"Tracker track");
343 histo->GetXaxis()->SetBinLabel(5,
"Masked board");
344 histo->GetYaxis()->SetTitle(boardName);
357 TString histoName =
"";
358 if ( itype < kHcheckBoard && icount >= 0 ) histoName +=
static_cast<TObjString*
>(
fCountTypeKeys->At(icount))->GetString();
359 if ( itype >= 0 ) histoName += ((TObjString*)
fHistoTypeKeys->At(itype))->GetString();
360 if ( ichamber >= 0 ) histoName += Form(
"Ch%i", 11+ichamber);
361 if ( itrackSel >= 0 ) histoName +=
static_cast<TObjString*
>(
fTrackSelKeys->At(itrackSel))->GetString();
362 if ( imatch >= 0 ) histoName +=
static_cast<TObjString*
>(
fMatchTrigKeys->At(imatch))->GetString();
363 if ( imethod >= 0 ) histoName +=
static_cast<TObjString*
>(
fEffMethodKeys->At(imethod))->GetString();
374 Int_t slat = 0, board = 0;
376 TString histoName =
"";
378 TArrayI othersEfficient(4);
380 AliVParticle* track = 0x0;
382 UInt_t addMask[4] = {0, AliMuonTrackCuts::kMuMatchApt, AliMuonTrackCuts::kMuMatchApt|AliMuonTrackCuts::kMuMatchLpt, AliMuonTrackCuts::kMuMatchApt|AliMuonTrackCuts::kMuMatchLpt|AliMuonTrackCuts::kMuMatchHpt};
384 Int_t nTracks = AliAnalysisMuonUtility::GetNTracks(InputEvent());
385 for ( Int_t itrack = 0; itrack < nTracks; ++itrack ) {
386 track = AliAnalysisMuonUtility::GetTrack(itrack,InputEvent());
388 Bool_t matchTracker = AliAnalysisMuonUtility::IsMuonTrack(track);
390 Int_t matchTrig = AliAnalysisMuonUtility::GetMatchTrigger(track);
391 UInt_t selection = fMuonTrackCuts->GetSelectionMask(track);
394 UInt_t filterMask = fMuonTrackCuts->GetFilterMask() | addMask[matchTrig];
395 Bool_t isSelected = ( ( selection & filterMask ) == filterMask );
397 for ( Int_t imethod=0; imethod<
kNeffMethods; ++imethod ) {
399 if ( ! matchTracker || track->P() < 10. )
continue;
400 pattern = AliAnalysisMuonUtility::GetMUONTrigHitsMapTrk(track);
401 board = AliESDMuonTrack::GetCrossedBoard(pattern);
404 if ( matchTrig == 0 )
continue;
405 pattern = AliAnalysisMuonUtility::GetMUONTrigHitsMapTrg(track);
406 board = ( AliAnalysisMuonUtility::IsAODEvent(InputEvent()) ) ? AliESDMuonTrack::GetCrossedBoard(pattern) : ((AliESDMuonTrack*)track)->LoCircuit();
409 Int_t effFlag = AliESDMuonTrack::GetEffFlag(pattern);
411 if ( effFlag < AliESDMuonTrack::kChEff ) {
412 for ( Int_t itrackSel=0; itrackSel<
kNtrackSel; ++itrackSel ) {
413 if ( itrackSel ==
kSelectTrack && ! isSelected )
continue;
414 for ( Int_t itrig=0; itrig<selectTrigClasses.GetEntries(); ++itrig ) {
415 TString trigClassName = ((TObjString*)selectTrigClasses.At(itrig))->GetString();
418 ((TH2F*)GetMergeableObject(physSel, trigClassName, centrality, histoName))->Fill(AliESDMuonTrack::GetSlatOrInfo(pattern), board);
424 othersEfficient.Reset(1);
425 for ( Int_t cath=0; cath<2; ++cath ) {
426 for ( Int_t ich=0; ich<4; ++ich ) {
427 if ( ! AliESDMuonTrack::IsChamberHit(pattern, cath, ich) ) {
428 for ( Int_t jch=0; jch<4; jch++ ) {
429 if ( jch != ich ) othersEfficient[jch] = 0;
436 Bool_t rejectTrack = kTRUE;
437 for ( Int_t ich=0; ich<4; ++ich ) {
438 if ( othersEfficient[ich] > 0 ) {
439 rejectTrack = kFALSE;
444 if ( rejectTrack )
continue;
446 slat = AliESDMuonTrack::GetSlatOrInfo(pattern);
448 for ( Int_t ich=0; ich<4; ++ich ) {
449 if ( ! othersEfficient[ich] )
453 Int_t iChamber = 11 + ich;
455 Bool_t hitsBend = AliESDMuonTrack::IsChamberHit(pattern, 0, ich);
456 Bool_t hitsNonBend = AliESDMuonTrack::IsChamberHit(pattern, 1, ich);
461 ( hitsBend && hitsNonBend ),
465 for ( Int_t itrackSel=0; itrackSel<
kNtrackSel; ++itrackSel ) {
466 if ( itrackSel ==
kSelectTrack && ! isSelected )
continue;
467 for (Int_t icount=0; icount<
kNcounts; ++icount){
468 if ( ! fillHisto[icount] )
continue;
469 for ( Int_t itrig=0; itrig<selectTrigClasses.GetEntries(); ++itrig ) {
470 TString trigClassName = ((TObjString*)selectTrigClasses.At(itrig))->GetString();
473 ((TH1*)GetMergeableObject(physSel, trigClassName, centrality, histoName))->Fill(iChamber);
475 if ( effFlag < AliESDMuonTrack::kSlatEff )
continue;
477 ((TH1*)GetMergeableObject(physSel, trigClassName, centrality, histoName))->Fill(slat);
479 if ( effFlag < AliESDMuonTrack::kBoardEff )
continue;
481 ((TH1*)GetMergeableObject(physSel, trigClassName, centrality, histoName))->Fill(board);
500 AliVAnalysisMuon::Terminate(
"");
502 if ( ! fMergeableCollection )
return;
510 TObjArray* physSel = ((TObjString*)fTerminateOptions->At(0))->GetString().Tokenize(
" ");
512 TObjArray* trigClasses = ((TObjString*)fTerminateOptions->At(1))->GetString().Tokenize(
" ");
513 trigClasses->SetOwner();
514 TObjArray* centrality = ((TObjString*)fTerminateOptions->At(2))->GetString().Tokenize(
" ");
515 centrality->SetOwner();
516 TString furtherOpt = ((TObjString*)fTerminateOptions->At(3))->GetString();
518 TString currName =
"";
519 TObjArray* optArr = furtherOpt.Tokenize(
" ");
520 TObjArray trackSel, methodSel;
522 methodSel.SetOwner();
523 TString outFileOpt =
"";
524 for ( Int_t iopt=0; iopt<optArr->GetEntries(); iopt++ ) {
525 currName = optArr->At(iopt)->GetName();
526 if ( currName.Contains(
".root") ) outFileOpt = currName;
527 else if ( currName.Contains(
"Match") ) trackSel.Add(
new TObjString(currName));
528 else if ( currName.Contains(
"From") ) methodSel.Add(
new TObjString(currName));
535 furtherOpt.ToUpper();
541 TString histoName =
"", yAxisTitle =
"";
545 TGraphAsymmErrors* effGraph = 0x0;
551 for ( Int_t icount=0; icount<
kNcounts-1; ++icount ) {
553 TCanvas* can =
new TCanvas(currName.Data(), currName.Data(), igroup1*xshift,igroup2*yshift,600,600);
555 TLegend* leg =
new TLegend(0.6, 0.6, 0.9, 0.9);
556 leg->SetBorderSize(1);
557 for ( Int_t ich=0; ich<4; ++ich ) {
558 TGraph* refGraph = 0x0;
560 gPad->SetRightMargin(0.03);
563 TString drawOpt =
"AP";
564 for ( Int_t isel=0; isel<physSel->GetEntries(); ++isel ) {
565 for ( Int_t itrig=0; itrig<trigClasses->GetEntries(); ++itrig ) {
566 for ( Int_t icent=0; icent<centrality->GetEntries(); ++icent ) {
567 for ( Int_t imethodSel=0; imethodSel<methodSel.GetEntries(); ++imethodSel ) {
568 for ( Int_t itrackSel=0; itrackSel<trackSel.GetEntries(); ++itrackSel ) {
570 histoName += Form(
"%s%s",trackSel.At(itrackSel)->GetName(),methodSel.At(imethodSel)->GetName());
571 den = (TH1*)GetSum(physSel->At(isel)->GetName(), trigClasses->At(itrig)->GetName(), centrality->At(icent)->GetName(), histoName.Data());
573 printf(
"Warning: cannot find %s\n", histoName.Data());
576 histoName =
GetHistoName(chosenType, icount, ich, -1, -1, -1);
577 histoName += Form(
"%s%s",trackSel.At(itrackSel)->GetName(),methodSel.At(imethodSel)->GetName());
578 num = (TH1*)GetSum(physSel->At(isel)->GetName(), trigClasses->At(itrig)->GetName(), centrality->At(icent)->GetName(), histoName.Data());
579 if ( ! num )
continue;
580 effGraph =
new TGraphAsymmErrors(num, den,
"e0");
581 currName = Form(
"%s_%s_%s_%s_%s", physSel->At(isel)->GetName(), trigClasses->At(itrig)->GetName(), centrality->At(icent)->GetName(), trackSel.At(itrackSel)->GetName(), methodSel.At(imethodSel)->GetName());
582 effGraph->SetTitle(currName.Data());
586 yAxisTitle =
"Efficiency";
588 if ( furtherOpt.Contains(
"DIFF") || furtherOpt.Contains(
"PULL") ) {
593 Double_t currX, currY, baseX, baseY, errYlow = 0., errYhigh = 0., newY = 0.;
594 Double_t refVal = 1., errY = 0.;
595 for ( Int_t ipoint=0; ipoint<effGraph->GetN(); ipoint++ ) {
596 refGraph->GetPoint(ipoint, baseX, baseY);
597 effGraph->GetPoint(ipoint, currX, currY);
598 Double_t errX = effGraph->GetErrorXlow(ipoint);
599 if ( furtherOpt.Contains(
"DIFF") ) {
600 refVal = ( baseY > 0. ) ? baseY : 1.;
601 newY = ( currY - baseY ) / refVal;
602 Double_t errYlow1 = effGraph->GetErrorYlow(ipoint);
603 Double_t errYlow2 = refGraph->GetErrorYlow(ipoint);
604 Double_t errYhigh1 = effGraph->GetErrorYhigh(ipoint);
605 Double_t errYhigh2 = refGraph->GetErrorYhigh(ipoint);
606 errYlow = TMath::Sqrt(errYlow1*errYlow1 + errYlow2*errYlow2) / refVal;
607 errYhigh = TMath::Sqrt(errYhigh1*errYhigh1 + errYhigh2*errYhigh2) / refVal;
609 yAxisTitle =
"(eff - ref ) / ref";
610 effGraph->SetTitle(Form(
"Rel. diff. w.r.t. %s", refGraph->GetTitle()));
614 else if ( furtherOpt.Contains(
"PULL") ) {
615 errY = 0.5 * ( effGraph->GetErrorYlow(ipoint) + effGraph->GetErrorYhigh(ipoint));
616 newY = ( errY > 0. ) ? ( currY - baseY ) / errY : 0.;
620 yAxisTitle =
"(eff - ref ) / err";
621 effGraph->SetTitle(Form(
"Pull w.r.t. %s", refGraph->GetTitle()));
625 effGraph->SetPoint(ipoint, currX, newY);
626 effGraph->SetPointError(ipoint, errX, errX, errYlow, errYhigh);
629 effGraph->GetYaxis()->SetRangeUser(ymin, ymax);
630 effGraph->GetYaxis()->SetTitle(yAxisTitle.Data());
631 effGraph->SetLineColor(icolor);
632 effGraph->SetMarkerColor(icolor);
633 effGraph->SetMarkerStyle(20 + istyle);
636 if ( icolor == 5 || icolor == 10 ) icolor++;
638 effGraph->Draw(drawOpt.Data());
640 if ( ich < 3 )
continue;
641 leg->AddEntry(effGraph, currName.Data(),
"lp");
657 fList =
dynamic_cast<TList*
>(GetOutputData(2));
663 TString baseName[3] = {
"Chamber",
"RPC",
"Board"};
665 TString effName[kNcounts-1] = {
"BendPlane",
"NonBendPlane",
"BothPlanes"};
666 for ( Int_t itype=0; itype<3; itype++ ) {
667 for ( Int_t icount=0; icount<kNcounts-1; icount++ ){
668 TString canName = Form(
"efficiencyPer%s_%s",baseName[itype].Data(),effName[icount].Data());
669 TCanvas* can =
new TCanvas(canName.Data(),canName.Data(),10*(1+kNcounts*itype+icount),10*(1+kNcounts*itype+icount),310,310);
670 can->SetFillColor(10); can->SetHighLightColor(10);
671 can->SetLeftMargin(0.15); can->SetBottomMargin(0.15);
675 for ( Int_t ich=-1; ich<4; ich++ ) {
676 histoName =
GetHistoName(baseIndex[itype], icount, ich, -1, -1, -1);
677 num = (TH1*)
fList->FindObject(histoName.Data());
678 histoName =
GetHistoName(baseIndex[itype], kNcounts-1, ich, -1, -1, -1);
679 den = (TH1*)
fList->FindObject(histoName.Data());
680 if ( ! num || ! den )
continue;
681 effGraph =
new TGraphAsymmErrors(num, den,
"e0");
682 effGraph->GetYaxis()->SetRangeUser(0., 1.1);
683 effGraph->GetYaxis()->SetTitle(
"Efficiency");
684 effGraph->GetXaxis()->SetTitle(baseName[itype].Data());
686 effGraph->Draw(
"AP");
687 if ( itype == 0 )
break;
694 if ( ! outFileOpt.IsNull() ) {
695 TObjArray* outFileOptList = outFileOpt.Tokenize(
"?");
696 AliInfo(Form(
"Creating file %s", outFileOptList->At(0)->GetName()));
697 TList* effList =
GetEffHistoList(outFileOptList->At(1)->GetName(), outFileOptList->At(2)->GetName(), outFileOptList->At(3)->GetName(), outFileOptList->At(4)->GetName());
698 effList->SetName(GetOutputSlot(2)->GetContainer()->GetName());
699 if ( effList ->GetEntries() == 0 ) {
700 printf(
"\nWarning: no histograms satisfying the requested conditions.\n(%s %s %s %s).\nOutput %s not created.\n", outFileOptList->At(1)->GetName(), outFileOptList->At(2)->GetName(), outFileOptList->At(3)->GetName(), outFileOptList->At(4)->GetName(),outFileOptList->At(0)->GetName());
703 TFile* outFile = TFile::Open(outFileOptList->At(0)->GetName(),
"RECREATE");
704 effList->Write(effList->GetName(),TObject::kSingleKey);
708 delete outFileOptList;
Bool_t FillEffHistoList(TString physSel, TString trigClassNames, TString centrality, TString trackSelection, TList *outList)
TObjArray * fTrackSelKeys
Selection names.
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
void Terminate(Option_t *option)
void ProcessEvent(TString physSel, const TObjArray &selectTrigClasses, TString centrality)
Hit pattern from tracker track extrapolation.
TObjArray * fHistoTypeKeys
Base histogram name.
Check rejected tracks per board.
Check rejected tracks per board.
TObjArray * fMatchTrigKeys
Match trigger names.
TList * GetEffHistoList(TString physSel, TString trigClassNames, TString centrality, TString trackSelection)
TObjArray * fCountTypeKeys
Count type keys.
Counts per slat histogram index.
TH1 * GetCountHisto(Int_t itype, Int_t icount, Int_t ichamber, Int_t itrackSel, Int_t imatch, Int_t imethod)
Total number of matched types.
Counts per board histogram index.
Total number of track selection.
AliAnalysisTaskTrigChEff()
virtual ~AliAnalysisTaskTrigChEff()
TString GetHistoName(Int_t itype, Int_t icount, Int_t ichamber, Int_t itrackSel, Int_t imatch, Int_t imethod)
void MyUserCreateOutputObjects()
tracks used for calculation
Counts per cathode histogram index.
TList * fList
TList output object.
TObjArray * fEffMethodKeys
Efficiency methods keys.
Total number of efficiency methods.