19 #include <Riostream.h>
20 #include "TObjString.h"
21 #include "TObjArray.h"
27 #include "TDirectory.h"
33 #include "TGridResult.h"
34 #include "TGraphAsymmErrors.h"
44 #include "TFileMerger.h"
45 #include "TFitResultPtr.h"
48 #include "AliMergeableCollection.h"
49 #include "AliCounterCollection.h"
51 #include "AliAnalysisMuonUtility.h"
54 #include "AliCDBManager.h"
55 #include "AliCDBStorage.h"
57 #include "AliCDBEntry.h"
58 #include "AliMUONCDB.h"
59 #include "AliMUONTriggerEfficiencyCells.h"
107 return SetCondition(physSel, trigClassName, centrality, itrackSel, imatch, imethod, kFALSE);
115 if ( ! trigOut->GetMergeableCollection() ) {
116 AliError(Form(
"Cannot find %s in %s",outputName,filename));
132 if ( idxFromRun >= 0 ) obj =
fRunMap[idxFromRun];
135 obj->SetUniqueID(
fRunMap.size());
154 if ( irpc == 0 || irpc == 9 ) {
155 Int_t arr[] = {26,27,28,29,48,49,50,51,68,69,84,85,100,101,113};
156 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
157 boards.Set(nBoards,arr);
159 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
161 else if ( irpc == 1 || irpc == 8 ) {
162 Int_t arr[] = {9,10,11,30,31,32,33,52,53,54,55,70,71,86,87,102,103,114};
163 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
164 boards.Set(nBoards,arr);
166 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
168 else if ( irpc == 2 || irpc == 7 ) {
169 Int_t arr[] = {12,13,34,35,56,57,72,73,88,89,104,105,115};
170 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
171 boards.Set(nBoards,arr);
173 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
175 else if ( irpc == 3 || irpc == 6 ) {
176 Int_t arr[] = {14,15,36,37,58,59,74,75,90,91,106,107,116};
177 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
178 boards.Set(nBoards,arr);
180 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
182 else if ( irpc == 4 || irpc == 5 ) {
183 Int_t arr[] = {16,38,60,76,92,108,117};
184 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
185 boards.Set(nBoards,arr);
187 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
189 else if ( irpc == 17 || irpc == 10 ) {
190 Int_t arr[] = {6,7,8,22,23,24,25,44,45,46,47,66,67,82,83,98,99,112};
191 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
192 boards.Set(nBoards,arr);
194 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
196 else if ( irpc == 16 || irpc == 11 ) {
197 Int_t arr[] = {4,5,20,21,42,43,64,65,80,81,96,97,111};
198 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
199 boards.Set(nBoards,arr);
201 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
203 else if ( irpc == 15 || irpc == 12 ) {
204 Int_t arr[] = {2,3,18,19,40,41,62,63,78,79,94,95,110};
205 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
206 boards.Set(nBoards,arr);
208 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
210 else if ( irpc == 14 || irpc == 13 ) {
211 Int_t arr[] = {1,17,39,61,77,93,109};
212 Int_t nBoards =
sizeof(arr)/
sizeof(arr[0]);
213 boards.Set(nBoards,arr);
215 for (
Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
227 clonedEffHistos->SetOwner();
228 TIter next(effHistos);
230 while ( (obj = next()) ) {
231 clonedEffHistos->Add(obj->Clone());
233 return clonedEffHistos;
242 AliInfo(
"Building efficiency map for systematic uncertainties");
245 Double_t xref=0., yref=0., xpt=0., ypt=0.;
250 std::vector<std::string> systKeys = obj->GetSortKeys();
251 Int_t nSysts = systKeys.size();
254 TList* effHistos = obj->GetEffHistoList(
fConditions->UncheckedAt(0)->GetName());
257 for (
Int_t ich=0; ich<4; ich++ ) {
261 TH1* histoList[nSysts*4];
262 TH1* systHistoList[4];
263 for (
Int_t isyst=0; isyst<nSysts; isyst++ ) {
264 effHistos = obj->GetEffHistoList(systKeys[isyst].c_str());
265 for (
Int_t icount=0; icount<4; icount++ ) {
267 histoList[4*isyst+icount] =
static_cast<TH1*
>(effHistos->FindObject(currName.Data()));
269 systHistoList[icount] =
static_cast<TH1*
>(systematicList->FindObject(currName.Data()));
275 checkEffList[isyst] =
new TGraphAsymmErrors(histoList[inum],histoList[iden],
"e0");
278 for (
Int_t icount=0; icount<3; icount++ ) {
288 for (
Int_t ipt=0; ipt<refGraph->GetN(); ipt++ ) {
289 refGraph->GetPoint(ipt,xref,yref);
290 Int_t chosenSyst = -1;
292 for (
Int_t isyst=1; isyst<nSysts; isyst++ ) {
294 graph->GetPoint(ipt,xpt,ypt);
296 Double_t err = (diff > 0.) ? graph->GetErrorYlow(ipt) : graph->GetErrorYhigh(ipt);
297 Double_t absDiff = TMath::Abs(diff);
298 if ( absDiff < nSigmas*err )
continue;
299 if ( foundAbsDiff < absDiff ) {
300 foundAbsDiff = absDiff;
306 AliDebug(2,Form(
"Chamber %i board %i systematicCondition %i",11+ich,ibin,chosenSyst));
307 if ( chosenSyst >= 0 ) {
308 for (
Int_t icount=0; icount<4; icount++ ) {
309 systHistoList[icount]->SetBinContent(ibin,histoList[4*chosenSyst+icount]->GetBinContent(ibin));
315 for (
Int_t icount=0; icount<3; icount++ ) {
317 graph->GetPoint(ipt,xpt,ypt);
318 Double_t errHigh = graph->GetErrorYhigh(ipt);
319 Double_t errLow = graph->GetErrorYlow(ipt);
320 Double_t newEff = ( errLow > errHigh ) ? ypt - errLow : ypt + errHigh;
321 Double_t newCount = TMath::Nint(newEff * countAll);
322 if ( newCount < 0 || newCount > countAll ) {
323 TString warning = Form(
"WARNING: ch %i board %i cath %i systDiff %g newEff %g / %g",11+ich,ibin,icount,newEff-yref,newCount,countAll);
324 if ( newCount < 0 ) newCount = 0;
325 else newCount = countAll;
326 warning += Form(
" => setting numerator to %g",newCount);
327 AliWarning(warning.Data());
329 systHistoList[icount]->SetBinContent(ibin,newCount);
333 for (
Int_t it=0; it<nSysts; it++ )
delete checkEffList[it];
334 for (
Int_t it=0; it<3; it++ )
delete refEffList[it];
336 obj->AddEffHistoList(
"Systematics",systematicList);
347 if ( srcs.Contains(
"raw://") ) {
348 AliError(
"The method assumes that the specified storage is a SpecificStorage. Hence, please replace raw:// with the actual path in alien, e.g.: alien://folder=/alice/data/<year>/OCDB");
351 TObjArray* sourceList = srcs.Tokenize(
",");
353 effHistoLists.SetOwner();
355 TIter next(sourceList);
356 TObjString* src = 0x0;
357 while ( (src = static_cast<TObjString*>(next())) ) {
359 if ( ! readList )
continue;
360 effHistoLists.Add(readList);
372 TObjArray* titleList = sTitles.Tokenize(
",");
376 Int_t nLists = effHistoLists->GetEntriesFast();
378 TString sCanvasNameSuffix(canvasNameSuffix);
379 if ( ! sCanvasNameSuffix.IsNull() && ! sCanvasNameSuffix.BeginsWith(
"_") ) sCanvasNameSuffix.Prepend(
"_");
382 enum {kEff, kDiff, kPull};
387 if ( sOpt.Contains(
"diff") ) {
389 yTitle =
"Eff. - (ref.Eff)";
391 else if ( sOpt.Contains(
"pull") ) {
393 yTitle =
"(Eff - (ref.Eff)) / err";
397 if ( iopt != kEff && nLists <2 ) {
398 AliError(Form(
"You ask for %s but you only provided one set of histograms: nothing done",opt));
402 Bool_t needsLegend = ( nLists > 1 );
405 Int_t colors[] = {kBlack, kRed, kSpring, kTeal, kBlue, kViolet, kMagenta, kOrange, kGray};
413 for (
Int_t itype=0; itype<2; itype++ ) {
415 for (
Int_t icount=0; icount<3; icount++ ) {
417 for (
Int_t ich=0; ich<4; ich++ ) {
422 for (
Int_t ilist=0; ilist<nLists; ilist++ ) {
423 TString currTitle = titleList->At(ilist)->GetName();
424 TList* effHistos =
static_cast<TList*
>(effHistoLists->UncheckedAt(ilist));
426 TH1* histoDen =
static_cast<TH1*
>(effHistos->FindObject(currName.Data()));
428 TH1* histoNum =
static_cast<TH1*
>(effHistos->FindObject(currName.Data()));
430 currName = histoNum->GetName();
431 currName.ReplaceAll(
"Count",
"Eff");
432 currName.Append(Form(
"_%s",currTitle.Data()));
433 graph->SetName(currName.Data());
435 if ( iopt != kEff ) {
437 for (
Int_t ipt=0; ipt<graph->GetN(); ipt++ ) {
438 refGraph->GetPoint(ipt,xref,yref);
439 graph->GetPoint(ipt,xpt,ypt);
441 if ( TMath::Abs(diff) > 1.e-4 ) nDiffs++;
442 if ( iopt == kDiff ) graph->SetPoint(ipt,xpt,diff);
443 else if ( iopt == kPull ) {
444 Double_t err =
GetError(graph->GetErrorYlow(ipt),graph->GetErrorYhigh(ipt));
445 Double_t pull = ( err > 0. ) ? diff/err : 0.;
446 graph->SetPoint(ipt,xpt,pull);
457 currName = graph->GetName();
458 currName.Remove(currName.Length()-currTitle.Length()-5);
459 currName += sCanvasNameSuffix;
460 can =
new TCanvas(currName.Data(),currName.Data(),20*ican,20*ican,600,600);
464 if ( needsLegend && ! leg ) {
465 leg =
new TLegend(0.35, 0.15, 0.65, 0.45);
466 if ( refGraph ) leg->SetHeader(Form(
"Ref.: %s",titleList->At(0)->GetName()));
470 Int_t icolor = ( ilist < ncolors ) ? colors[ilist] : 20+ilist;
471 graph->SetLineColor(icolor);
472 graph->SetMarkerColor(icolor);
473 graph->SetMarkerStyle(20+ilist);
474 graph->SetMarkerSize(0.5);
475 graph->GetXaxis()->SetTitle(xTitle.Data());
476 graph->GetYaxis()->SetTitle(yTitle.Data());
477 graph->Draw((gPad->GetListOfPrimitives()->GetEntries()==0)?
"ap":
"p");
478 if ( leg ) leg->AddEntry(graph,titleList->At(ilist)->GetName(),
"lp");
480 if (leg ) leg->Draw();
496 AliWarning(
"No condition found! Please specify the default efficiency condition with SetEffConditions and then add additional tests with AddSystematicCondition");
506 effHistoLists.SetOwner();
508 for (
Int_t icond=0; icond<nConditions; icond++ ) {
513 effHistoLists.Add(effHistos);
514 titles += Form(
"%s,",condTitle.Data());
517 titles.Remove(TString::kTrailing,
',');
528 AliWarning(
"There is only one merged object: nothing to compare to");
532 AliInfo(
"Comparing the merged efficiencies");
539 TList* effHistos = obj->GetEffHistoList(condition->GetName());
540 effHistoList.Add(effHistos);
541 titles += Form(
"%i_%i,",obj->GetMinRun(),obj->GetMaxRun());
543 titles.Remove(TString::kTrailing,
',');
553 TObjArray* sourceList = srcs.Tokenize(
",");
555 effHistoLists.SetOwner();
559 AliError(
"The method requires to set an efficiency confition with SetEffConditions");
563 TIter next(sourceList);
564 TObjString* src = 0x0;
565 while ( (src = static_cast<TObjString*>(next())) ) {
566 if ( ! src->String().EndsWith(
".root") ) {
567 AliError(
"The method reads files with the output of AliAnalysisTaskTrigChEff and re-compute the efficiency");
572 if ( ! readList )
continue;
573 effHistoLists.Add(readList);
621 TDirectory *savdir = gDirectory;
622 TDirectory *adir = savdir->mkdir(source->GetName());
626 TIter nextkey(source->GetListOfKeys());
627 while ((key = (TKey*)nextkey())) {
628 const char *classname = key->GetClassName();
629 TClass *cl = gROOT->GetClass(classname);
631 if (cl->InheritsFrom(TDirectory::Class())) {
632 source->cd(key->GetName());
633 TDirectory *subdir = gDirectory;
637 }
else if (cl->InheritsFrom(TTree::Class())) {
640 TTree *newT = T->CloneTree(-1,
"fast");
646 obj->Write(obj->GetName(),TObject::kSingleKey);
650 adir->SaveSelf(kTRUE);
662 Bool_t isGrid = (! sPattern.IsNull());
664 if ( sOutDir.IsNull() ) {
666 TString data = sPath(TRegexp(
"/data/"));
667 TString year = sPath(TRegexp(
"/20[0-9][0-9]/"));
668 TString period = sPath(TRegexp(
"/LHC[0-9][0-9][a-z]"));
670 TString pass = AliAnalysisMuonUtility::GetPassName(path);
671 if ( pass.IsNull() ) pass = AliAnalysisMuonUtility::GetPassName(pattern);
672 sOutDir = data+year+period+pass;
673 sOutDir.ReplaceAll(
"//",
"/");
674 sOutDir.Remove(TString::kTrailing,
'/');
675 sOutDir.Remove(TString::kLeading,
'/');
677 else sOutDir = sPath;
678 sOutDir.Remove(TString::kTrailing,
'/');
679 sOutDir.Remove(TString::kLeading,
'/');
682 TGridResult* res = 0x0;
685 if ( ! gGrid ) TGrid::Connect(
"alien://");
686 res = gGrid->Query(path,pattern);
689 if (
gSystem->Exec(
"which curl &> /dev/null") == 0 ) hasCurl = kTRUE;
694 ofstream outFile(localFileList);
697 Bool_t overwrite = kFALSE;
698 for (
Int_t irun=0; irun<rl->GetEntries(); irun++ ) {
699 TString run =
static_cast<TObjString*
>(rl->At(irun))->String();
700 TString dest = Form(
"%s/%09i/QAresults.root",sOutDir.Data(),run.Atoi());
702 if (
gSystem->AccessPathName(destDir.Data()) )
ExecCommand(Form(
"mkdir -p %s",destDir.Data()),kFALSE);
705 if (
gSystem->AccessPathName(dest) == 0 ) {
708 cout <<
"Local file " << dest.Data() <<
" already exist: overwrite? [y/n/ya/na (a=use decision for all)]" << endl;
710 if ( decision.EndsWith(
"a") ) prompt = kFALSE;
711 if ( decision.BeginsWith(
"y") ) overwrite = kTRUE;
712 else overwrite = kFALSE;
714 copyFile = overwrite;
719 for (
Int_t ifile=0; ifile<res->GetEntries(); ifile++ ) {
720 TString inFilename = res->GetKey(ifile,
"turl");
721 if ( inFilename.Contains(run.Data()) ) {
726 if ( src.IsNull() ) {
727 AliWarning(Form(
"Cannot find output for run %s",run.Data()));
731 TFile* outFile = TFile::Open(dest,
"RECREATE");
732 TFile* inFile = TFile::Open(src);
734 TDirectory* dir =
static_cast<TDirectory*
>(inFile->Get(directory));
739 else isFileOk = kFALSE;
745 src = Form(
"http://aliqamu.web.cern.ch/aliqamu/%s",dest.Data());
749 Int_t cmdOut =
gSystem->Exec(Form(
"curl -f -# -o %s %s",dest.Data(),src.Data()));
750 isFileOk = ( cmdOut == 0 );
752 else isFileOk = TFile::Cp(src.Data(),dest.Data());
756 if ( isFileOk ) outFile <<
gSystem->pwd() <<
"/" << dest.Data() << endl;
758 AliWarning(Form(
"Problem getting run %s",run.Data()));
771 TString baseNames[3] = {
"Chamber",
"RPC",
"Board"};
772 TString base = baseNames[itype] +
"Eff";
775 AliWarning(
"Please specify RPC");
778 base += Form(
"InRPC%i",irpc);
798 for (
Int_t ich=0; ich<nCh; ich++ ) {
801 TCanvas* can =
new TCanvas(canName.Data(),canName.Data(),25*ich,25*ich,width,height);
802 can->Divide(nColumns,nRows,0,0);
805 for (
Int_t idetelem=0; idetelem<nDetEl; idetelem++ ) {
809 Int_t detElemId = idetelem;
814 TLegend* leg =
new TLegend(0.2,0.15,0.8,0.4);
815 leg->SetHeader(title.Data());
816 for (
Int_t icount=0; icount<2; icount++ ) {
818 gr->SetLineColor(icount+1);
819 gr->SetMarkerColor(icount+1);
820 gr->SetMarkerStyle(24+2*icount);
821 gr->GetYaxis()->SetRangeUser(minEff,maxEff);
822 gr->GetXaxis()->SetLabelSize(0.07);
826 gr->Draw(icount==0?
"ap":
"p");
827 TString legTitle = ( icount==0 ) ?
"bending plane" :
"non-bending plane";
828 leg->AddEntry(gr,legTitle.Data(),
"lp");
829 if ( maxNsigmaOutliers > 0. ) {
831 outliers->SetLineColor(6+icount);
832 outliers->SetMarkerColor(6+icount);
833 outliers->SetMarkerStyle(20+2*icount);
834 outliers->SetLineWidth(2);
836 legTitle.ReplaceAll(
"plane",
"outliers");
837 leg->AddEntry(outliers,legTitle.Data(),
"lp");
851 AliWarning(
"This function is valid only for itype 1 and 2");
855 TString baseNames[3] = {
"Chamber",
"RPC",
"Board"};
856 TString base = baseNames[itype] +
"Stat";
859 AliWarning(
"Please specify RPC");
862 base += Form(
"InRPC%i",irpc);
875 for (
Int_t ich=0; ich<nCh; ich++ ) {
877 TH1* sumHistos = 0x0;
878 for (
Int_t idetelem=0; idetelem<nDetEl; idetelem++ ) {
879 Int_t detElemId = idetelem;
882 histos[idetelem]->SetName(Form(
"%s_stat",histos[idetelem]->GetName()));
883 histos[idetelem]->SetStats(0);
884 if ( sumHistos ) sumHistos->Add(histos[idetelem]);
885 else sumHistos =
static_cast<TH1*
>(histos[idetelem]->Clone(
"sumHistos"));
889 TCanvas* can =
new TCanvas(canName.Data(),canName.Data(),25*ich,25*ich,width,height);
890 can->Divide(nColumns,nRows,0,0);
891 for (
Int_t idetelem=0; idetelem<nDetEl; idetelem++ ) {
895 Int_t detElemId = idetelem;
898 TLegend* leg =
new TLegend(0.2,0.65,0.8,0.9);
899 leg->SetHeader(title.Data());
901 gr->SetHistogram(static_cast<TH1F*>(histos[idetelem]));
903 gr->SetMarkerStyle(24);
904 gr->SetMarkerSize(0.5);
905 gr->GetYaxis()->SetRangeUser(minY,maxY);
906 gr->GetYaxis()->SetTitle(Form(
"Tracks in %s / Sum of tracks of %ss in %s",baseNames[itype].
Data(),baseNames[itype].
Data(),baseNames[itype-1].
Data()));
911 if ( maxNsigmaOutliers > 0. ) {
913 outliers->SetLineColor(6);
914 outliers->SetMarkerColor(6);
915 outliers->SetMarkerStyle(20);
916 outliers->SetLineWidth(2);
918 legTitle =
"outliers";
919 leg->AddEntry(outliers,legTitle.Data(),
"lp");
934 AliInfo(
"Drawing the systematic variations");
936 Int_t colors[] = {kBlack, kRed, kSpring, kTeal, kBlue, kViolet, kMagenta, kOrange, kGray};
948 std::vector<std::string> systKeys = obj->GetSortKeys();
949 std::vector<std::string> shortSystName;
950 for ( std::string
str : systKeys ) {
953 Int_t nSysts = systKeys.size();
955 TString baseName = Form(
"mergedTrigEff_%i_%i",obj->GetMinRun(),obj->GetMaxRun());
962 for (
Int_t iplane=0; iplane<8; iplane++ ) {
963 effGraphs[iplane].SetOwner();
968 for (
Int_t isyst=0; isyst<nSysts; isyst++ ) {
969 TList* effHistos = obj->GetEffHistoList(systKeys[isyst].c_str());
970 effHistoLists.Add(effHistos);
971 titles += Form(
"%s,",shortSystName[isyst].c_str());
973 for (
Int_t ich=0; ich<4; ich++ ) {
975 TH1* histoDen =
static_cast<TH1*
>(effHistos->FindObject(currName.Data()));
976 for (
Int_t icount=0; icount<2; icount++ ) {
977 Int_t iplane = 4*icount+ich;
979 if ( histoDen->GetEntries() > 0 ) {
981 TH1* histoNum =
static_cast<TH1*
>(effHistos->FindObject(currName.Data()));
984 effGraphs[iplane].AddAtAndExpand(gr,isyst);
988 AliWarning(Form(
"No entries in count %i and ch %i for %s",countTypes[icount],ich,shortSystName[isyst].c_str()));
994 titles.Remove(TString::kTrailing,
',');
998 TString canName = Form(
"EffSyst_%s",baseName.Data());
999 Int_t pos = 25*(imerged+1);
1000 TCanvas* can =
new TCanvas(canName.Data(),canName.Data(),pos,pos,1200,800);
1001 can->Divide(4,2,0,0);
1003 for (
Int_t icount=0; icount<2; icount++ ) {
1004 for (
Int_t ich=0; ich<4; ich++ ) {
1005 Int_t iplane = 4*icount+ich;
1007 gPad->SetTicks(1,1);
1009 TLegend* leg =
new TLegend(0.15,0.7,0.9,0.9);
1010 leg->SetHeader(
Namer()->GetHistoName(-1,icount,ich,-1,-1,-1));
1011 TH1* sumHisto = 0x0;
1012 for (
Int_t isyst=1; isyst<nSysts; isyst++ ) {
1013 if ( isEmpty[isyst] == 1 )
continue;
1014 TH1* histo =
new TH1D(Form(
"syst_%s_%s_plane%i_ch%i",baseName.Data(),shortSystName[isyst].c_str(),icount,11+ich),
"",200,-0.1,0.1);
1015 histo->GetXaxis()->SetTitle(
"Eff.-(ref.Eff.)");
1016 histo->GetYaxis()->SetTitle(
"1/#sigma^{2}");
1020 for (
Int_t ipt=0; ipt<gr->GetN(); ipt++ ) {
1021 gr->GetPoint(ipt,xpt,ypt);
1023 Double_t invErr2 = ( err > 0. ) ? 1./(err*err) : 0.;
1024 grRef->GetPoint(ipt,xref,yref);
1027 histo->Fill(diff,invErr2);
1031 sumHisto =
static_cast<TH1*
>(histo->Clone(Form(
"syst_%s_plane%i_ch%i",baseName.Data(),icount,11+ich)));
1032 sumHisto->SetLineColor(1);
1034 leg->AddEntry(sumHisto,
"All systematics",
"l");
1036 else sumHisto->Add(histo);
1037 Int_t icolor = ( isyst < ncolors ) ? colors[isyst] : 20+isyst;
1038 histo->SetLineColor(icolor);
1039 histo->Draw(
"same");
1040 leg->AddEntry(histo,shortSystName[isyst].c_str(),
"l");
1047 canName = Form(
"TriggerEff_3outOf4_syst_%s",baseName.Data());
1049 TCanvas* canSyst =
new TCanvas(canName.Data(),canName.Data(),pos,pos,600,600);
1051 TLegend* leg =
new TLegend(0.15,0.7,0.9,0.4);
1054 for (
Int_t isyst=0; isyst<nSysts; isyst++ ) {
1055 if ( isEmpty[isyst] == 1 )
continue;
1056 histo[isyst] =
new TH1D(Form(
"TriggerEff_syst_%s_%s",shortSystName[isyst].c_str(),baseName.Data()),
"Dispersion of trigger probability (3/4)",200,-0.1,0.1);
1057 histo[isyst]->GetXaxis()->SetTitle(
"Trig. prob. - (ref. trig. prob)");
1058 histo[isyst]->GetYaxis()->SetTitle(
"1/#sigma^{2}");
1061 for (
Int_t ipt=0; ipt<
nDE; ipt++ ) {
1063 for (
Int_t isyst=0; isyst<nSysts; isyst++ ) {
1064 if ( isEmpty[isyst] == 1 )
continue;
1065 Double_t trigProb = 1., trigProbErr2 = 0.;
1066 for (
Int_t icount=0; icount<2; icount++ ) {
1067 for (
Int_t ich=0; ich<4; ich++ ) {
1068 Int_t iplane = 4*icount+ich;
1070 gr->GetPoint(ipt,xpt,ypt);
1072 effErr[ich] =
GetError(gr->GetErrorYlow(ipt),gr->GetErrorYhigh(ipt));
1077 trigProbErr2 += effErr34*effErr34;
1081 refTrigProb = trigProb;
1085 Double_t invErr2 = ( trigProbErr2>0. ) ? 1./trigProbErr2 : 0.;
1086 histo[isyst]->Fill(trigProb-refTrigProb,invErr2);
1091 for (
Int_t isyst=0; isyst<nSysts; isyst++ ) {
1092 if ( isEmpty[isyst] == 1 )
continue;
1093 TString title = ( isyst == 0 ) ?
"All systematics" : shortSystName[isyst].c_str();
1094 Int_t icolor = ( isyst < ncolors ) ? colors[isyst] : 20+isyst;
1095 histo[isyst]->SetLineColor(icolor);
1096 histo[isyst]->Draw((isyst == 0)?
"":
"same");
1097 leg->AddEntry(histo[isyst],title.Data(),
"l");
1098 if ( isyst>0 ) histo[0]->Add(histo[isyst]);
1111 if ( gROOT->IsBatch() ) prompt = kFALSE;
1114 cout << command.Data() <<
" ? [y/n]" << endl;
1119 if ( decision ==
"y" ) {
1120 cout <<
"Executing: " << command.Data() << endl;
1121 gSystem->Exec(command.Data());
1140 Int_t nChanges = par[0];
1142 Int_t matchChange = -1;
1143 for (
Int_t iknot=0; iknot<nChanges; iknot++ ) {
1144 Int_t iparChange = 2*(iknot+1);
1145 Double_t diff = xx - par[iparChange];
1146 if ( diff >= 0. && diff < matchDiff ) {
1148 matchChange = iparChange;
1151 if ( matchChange >= 0 ) val = par[matchChange+1];
1161 TH1* statHisto = 0x0;
1164 TList* effHistoList = obj->GetEffHistoList(
fConditions->UncheckedAt(0)->GetName());
1165 Int_t run = obj->GetMinRun();
1166 if ( run < firstRun || run > lastRun )
continue;
1169 if ( statHisto ) statHisto->Add(histo);
1170 else statHisto =
static_cast<TH1*
>(histo->Clone(
"tmpStatHisto"));
1173 if ( ! statHisto )
return 0.;
1178 Int_t excludeBoardsHalf[] = {1, 17, 39, 61, 77, 93,109,
1179 16, 38, 60, 76, 92, 108, 117,
1180 110, 111, 112, 113, 114, 115, 116};
1181 Int_t nExcludedHalf =
sizeof(excludeBoardsHalf)/
sizeof(excludeBoardsHalf[0]);
1182 for (
Int_t ibin=1; ibin<=statHisto->GetNbinsX(); ibin++ ) {
1184 for (
Int_t iexcl=0; iexcl<nExcludedHalf; iexcl++ ) {
1185 if ( ibin == excludeBoardsHalf[iexcl] || ibin == excludeBoardsHalf[iexcl]+117 ) {
1190 if ( skip )
continue;
1191 statPerDE += statHisto->GetBinContent(ibin);
1196 statPerDE = statHisto->Integral();
1197 nDe = (
Double_t)statHisto->GetNbinsX();
1199 statPerDE = nDe > 0. ? statPerDE/nDe : -1.;
1209 Int_t itrackSel = condition->UncheckedAt(3)->GetUniqueID();
1210 Int_t imatch = condition->UncheckedAt(4)->GetUniqueID();
1211 Int_t imethod = condition->UncheckedAt(5)->GetUniqueID();
1213 return trigOut->
GetEffHistoList(condition->At(0)->GetName(),condition->At(1)->GetName(),condition->At(2)->GetName(),itrackSel,imatch,imethod);
1220 return TMath::Max(errLow,errHigh);
1228 return static_cast<TH1*
>(effHistoList->At(ihisto));
1236 AliInfo(
"Selecting ranges with homogeneous efficiency");
1240 TH1F* hRunChangeCount =
new TH1F(
"runChangeCount",
"Number of RPCs changing efficiency per run",nRuns,-0.5,-0.5+(
Double_t)nRuns);
1241 hRunChangeCount->SetXTitle(
"Run num.");
1242 hRunChangeCount->SetYTitle(
"Num. of RPCs with change in eff.");
1243 for (
Int_t irun=0; irun<nRuns; irun++ ) {
1244 hRunChangeCount->GetXaxis()->SetBinLabel(irun+1,Form(
"%i",
GetRunNumber(irun)));
1249 Int_t nCanvas = perRPC ? 4 : 18;
1252 for (
Int_t irpc=0; irpc<18; irpc++ ) {
1255 Int_t firstDetEl = perRPC ? irpc : 0;
1256 Int_t lastDetEl = perRPC ? irpc : boards.GetSize()-1;
1258 for (
Int_t ich=0; ich<4; ich++ ) {
1259 Int_t ican = perRPC ? ich : irpc;
1260 TCanvas* can =
static_cast<TCanvas*
>(canList.At(ican));
1262 TString canName = perRPC ? Form(
"testRanges_ch%i",11+ich) : Form(
"testRanges_RPC%i",irpc);
1263 can =
new TCanvas(canName.Data(),canName.Data(),10*ich,10*ich,1200,800);
1264 can->Divide(6,3,0,0);
1265 can->SetMargin(0.,0.,0.,0.);
1266 canList.AddAt(can,ican);
1269 for (
Int_t idetel=firstDetEl; idetel<=lastDetEl; idetel++ ) {
1270 Int_t currDE = ( perRPC ) ? idetel : boards[idetel];
1274 trendGraph->GetYaxis()->SetRangeUser(minEff,maxEff);
1277 gPad->SetTicks(1,1);
1278 gPad->SetMargin(0.08,0.,0.08,0.);
1279 TString drawOpt = ( gPad->GetListOfPrimitives()->GetEntries() == 0 ) ?
"ap" :
"p";
1281 TString legendName = Form(
"%s_%i",can->GetName(),currDE);
1282 TLegend* leg =
static_cast<TLegend*
>(gPad->GetListOfPrimitives()->FindObject(legendName.Data()));
1284 leg =
new TLegend(0.2,0.15,0.8,0.4);
1285 leg->SetHeader(Form(
"%s %i",perRPC?
"RPC":
"Board",currDE));
1286 leg->SetName(legendName.Data());
1290 Int_t icolor = ich+1;
1291 trendGraph->SetLineColor(icolor);
1292 trendGraph->SetMarkerColor(icolor);
1293 trendGraph->SetMarkerStyle(24+ich);
1294 TF1* func =
static_cast<TF1*
>(trendGraph->GetListOfFunctions()->At(0));
1296 func->SetLineWidth(2);
1297 func->SetLineColor(icolor);
1300 trendGraph->GetXaxis()->SetLabelSize(0.07);
1301 trendGraph->SetTitle(
"");
1303 trendGraph->Draw(drawOpt.Data());
1304 leg->AddEntry(trendGraph,Form(
"Chamber %i",11+ich),
"lp");
1306 for (
Int_t ichange=2; ichange<range.GetSize(); ichange++ ) {
1308 if ( ichange%2 == 1 )
continue;
1309 Int_t runIdx = range[ichange];
1311 TLine* line =
new TLine(runIdx,minEff,runIdx,maxEff);
1312 line->SetLineStyle(2);
1317 hRunChangeCount->Fill(runIdx);
1318 if ( hRunChangeCount->GetBinContent(runIdx+1) == 1 ) {
1319 TString infoMsg = Form(
"Efficiency change in %i triggered by ch %i RPC %i",
GetRunNumber(runIdx),11+ich,irpc);
1320 if ( ! perRPC ) infoMsg += Form(
" Board %i",currDE);
1321 AliInfo(infoMsg.Data());
1330 TArrayI runChangeClust(nRuns);
1333 for (
Int_t irun=0; irun<=nRuns; irun++ ) {
1334 if ( irun == nRuns || hRunChangeCount->GetBinContent(irun+1) == 0 ) {
1335 if ( sumWgt > 0. ) {
1336 Int_t averageRun = TMath::Nint(sumWgtRun / sumWgt);
1337 AliDebug(2,Form(
"Average run: %i => %i",averageRun,
GetRunNumber(averageRun)));
1338 runChangeClust[averageRun]++;
1343 if ( irun == nRuns )
break;
1345 AliDebug(2,Form(
"irun %i => %i: wgt %g",irun,
GetRunNumber(irun),hRunChangeCount->GetBinContent(irun+1)));
1348 Double_t wgt = hRunChangeCount->GetBinContent(irun+1);
1349 if ( forcedChanges ) {
1350 for (
Int_t ichange=0; ichange<forcedChanges->GetSize(); ichange++ ) {
1351 if (
GetRunNumber(irun) == forcedChanges->At(ichange) ) wgt *= 10.;
1358 TCanvas* summaryCan =
new TCanvas(
"effChangeSummary",
"effChangeSummary",50,50,600,600);
1359 summaryCan->SetLogy();
1360 hRunChangeCount->GetXaxis()->LabelsOption(
"v");
1361 hRunChangeCount->Draw();
1366 for (
Int_t irun=1; irun<nRuns; irun++ ) {
1367 if ( runChangeClust[irun] > 0 ) {
1373 runRanges.Set(ientry);
1386 if ( forcedChanges ) {
1387 forcedChangesBin.Set(forcedChanges->GetSize());
1388 for (
Int_t ichange=0; ichange<forcedChanges->GetSize(); ichange++ ) {
1390 if ( idx >= 0 ) forcedChangesBin[nForced++] = (
Double_t)idx;
1391 else AliWarning(Form(
"Cannot find run %i",forcedChanges->At(ichange)));
1396 Int_t minNormChi2Step = -1;
1402 for (
Int_t istep=0; istep<maxNRanges; istep++ ) {
1403 Int_t nPars = 2*(istep+1);
1404 Double_t xMin = trendGraph->GetXaxis()->GetXmin();
1405 Double_t xMax = trendGraph->GetXaxis()->GetXmax();
1407 func->FixParameter(0,istep);
1408 for (
Int_t ipar=1; ipar<nPars; ipar++ ) {
1416 func->SetParameter(ipar,val);
1417 if ( ipar%2 == 0 ) func->SetParLimits(ipar,xMin,xMax);
1420 TFitResultPtr fitResult = trendGraph->Fit(func,fitOpt.Data());
1423 if ( forcedChanges ) {
1424 Bool_t hasFixedPars = kFALSE;
1425 for (
Int_t iforced=0; iforced<nForced; iforced++ ) {
1426 for (
Int_t jstep=0; jstep<istep; jstep++ ) {
1427 Int_t ipar = 2*(jstep+1);
1428 if ( TMath::Abs(forcedChangesBin[iforced]-func->GetParameter(ipar)) > 2. )
continue;
1429 func->FixParameter(ipar,forcedChangesBin[iforced]);
1430 hasFixedPars = kTRUE;
1433 if ( hasFixedPars ) fitResult = trendGraph->Fit(func,fitOpt.Data());
1441 if ( normChi2 < minNormChi2 ) {
1442 minNormChi2 = normChi2;
1443 minNormChi2Step = istep;
1446 if ( normChi2 < chi2Cut )
break;
1452 trendGraph->GetListOfFunctions()->Add(func->Clone());
1458 Int_t nPoints = nSteps+1;
1461 for (
Int_t ipar=0; ipar<func->GetNpar(); ipar++ ) {
1462 Int_t istep = ipar/2;
1463 if ( ipar%2 == 0 ) parRunIdx[istep] = func->GetParameter(ipar);
1464 else parEff[istep] = func->GetParameter(ipar);
1468 TMath::Sort(nPoints,parRunIdx.GetArray(),sortIdx.GetArray(),kFALSE);
1470 runRanges.Set(2*nPoints);
1473 for (
Int_t ipoint=1; ipoint<nPoints; ipoint++ ) {
1474 Double_t deltaEff = TMath::Abs(parEff[sortIdx[ipoint]]-parEff[sortIdx[ipoint-1]]);
1476 if ( deltaEff < minEffVariation ) {
1477 AliWarning(Form(
"Efficiency variation for %s is %g => consider uniform",trendGraph->GetName(),deltaEff));
1480 Int_t runChangeIdx = TMath::Nint(parRunIdx[sortIdx[ipoint]]);
1481 AliDebug(1,Form(
"Change run: %s => %g => %i %i",trendGraph->GetName(),parRunIdx[sortIdx[ipoint]],runChangeIdx,
GetRunNumber(runChangeIdx)));
1482 runRanges[irun++] = returnIndex ? runChangeIdx-1 :
GetRunNumber(runChangeIdx-1);
1483 runRanges[irun++] = returnIndex ? runChangeIdx :
GetRunNumber(runChangeIdx);
1485 Int_t lastPt = trendGraph->GetN()-1;
1486 runRanges[irun++] = returnIndex ? lastPt :
GetRunNumber(lastPt);
1487 runRanges.Set(irun);
1490 AliWarning(Form(
"Fit did not converge for %s (minimum chi2 %g for step %i)",trendGraph->GetName(),minNormChi2,minNormChi2Step));
1499 if ( maxRun < minRun ) maxRun = minRun;
1500 return Form(
"%s_%i_%i",condition,minRun,maxRun);
1508 if ( obj->GetMinRun() == runNumber ) {
1509 return obj->GetUniqueID();
1522 outliers->SetHistogram(static_cast<TH1F*>(graph->GetHistogram()->Clone(Form(
"%s_outliers",graph->GetHistogram()->GetName()))));
1524 if ( graph->GetListOfFunctions()->GetEntries() == 0 ) graph->Fit(
"pol0",
"Q0");
1525 TF1* func =
static_cast<TF1*
>(graph->GetListOfFunctions()->At(0));
1529 for (
Int_t ipt=0; ipt<graph->GetN(); ipt++ ) {
1530 graph->GetPoint(ipt,xpt,ypt);
1531 Double_t diff = ypt - func->Eval(xpt);
1532 Double_t err = ( diff > 0. ) ? graph->GetErrorYlow(ipt) : graph->GetErrorYhigh(ipt);
1533 if ( err < 0. || TMath::Abs(diff)/err > maxNsigmas )
continue;
1534 outliers->RemovePoint(ipt-nremoved);
1545 if ( ipt < 0 || ipt >=
fRunMap.size() )
return -1;
1546 return fRunMap[ipt]->GetMinRun();
1556 if (
gSystem->AccessPathName(sRunList) || sRunList.EndsWith(
".root") ) {
1557 sRunList.ReplaceAll(
",",
" ");
1558 if ( sRunList.IsDigit() ) {
1559 TObjArray* arr = sRunList.Tokenize(
" ");
1560 for (
Int_t iarr=0; iarr<arr->GetEntries(); iarr++ ) {
1561 rl->Add(
new TObjString(arr->At(iarr)->GetName()));
1567 ifstream inFile(sRunList.Data());
1569 while ( ! inFile.eof() ) {
1570 currLine.ReadLine(inFile);
1571 TString currRun = AliAnalysisMuonUtility::GetRunNumberAsString(currLine);
1572 if ( ! currRun.IsNull() ) rl->Add(
new TObjString(currRun));
1587 TString sRef(refCondition->GetName());
1591 if ( ! condition || sCond == sRef ) {
1595 for (
Int_t ic=0; ic<condition->GetEntriesFast(); ic++ ) {
1596 TString currCond =
static_cast<TObjString*
>(condition->UncheckedAt(ic))->String();
1597 TString refCond =
static_cast<TObjString*
>(refCondition->UncheckedAt(ic))->String();
1598 if ( currCond == refCond )
continue;
1599 title +=
";" + currCond;
1601 title.Remove(TString::kLeading,
';');
1603 title.ReplaceAll(
",",
"+");
1613 for (
Int_t ic=3; ic<6; ic++ ) {
1614 objName += condition->UncheckedAt(ic)->GetName();
1616 return static_cast<TH1*
>(trigOut->GetSum(condition->At(0)->GetName(),condition->At(1)->GetName(),condition->At(2)->GetName(),objName));
1624 if ( idetelem < 0 && ichamber >=0 ) idetelem = 11+ichamber;
1626 TH1* outHisto = 0x0;
1633 TList* effHistoList = obj->GetEffHistoList(
fConditions->UncheckedAt(0)->GetName());
1636 TString outName = Form(
"histo_type%i_count%i_ch%i_",itype,icount,11+ichamber);
1638 outName += Form(
"%i_trend",idetelem);
1639 outHisto =
new TH1D(outName.Data(),outName.Data(),nRuns,0.,(
Double_t)nRuns);
1640 outHisto->SetDirectory(0);
1641 outHisto->GetXaxis()->SetTitle(
"Run num.");
1643 Int_t run = obj->GetMinRun();
1644 outHisto->GetXaxis()->SetBinLabel(ibin,Form(
"%i",run));
1645 TH1* histo =
GetHisto(effHistoList,itype,icount,ichamber);
1646 Int_t currBin = histo->GetXaxis()->FindBin(idetelem);
1647 outHisto->SetBinContent(ibin,histo->GetBinContent(currBin));
1648 outHisto->SetBinError(ibin,histo->GetBinError(currBin));
1650 if ( outHisto ) outHisto->GetXaxis()->LabelsOption(
"v");
1659 AliWarning(
"Chose either bending plane, non-bending plane or both planes");
1662 TH1* histoNum =
GetTrend(itype,icount,ichamber,idetelem);
1666 histoNum->SetStats(kFALSE);
1668 graph->SetHistogram(
new TH1F(*static_cast<TH1F*>(histoNum)));
1669 graph->GetYaxis()->SetTitle(
"Efficiency");
1670 graph->SetMarkerSize(0.5);
1685 for (
Int_t jch=-1; jch<4; jch++ ) {
1688 for (
Int_t ich=0; ich<4; ich++ ) {
1689 Double_t currEff = ( ich == jch ) ? 1.-eff[ich] : eff[ich];
1691 Double_t relErr = ( currEff>0. ) ? effErr[ich]/currEff : 0.;
1692 prodErr2 += relErr*relErr;
1694 binomialEff += prodEff;
1695 sumErr2 += prodEff*prodEff*prodErr2;
1697 probErr = TMath::Sqrt(sumErr2);
1706 AliError(
"You first need to merge efficiency objects with MergeOutput");
1717 if ( runRanges.GetSize()%2 == 1 ) {
1718 AliError(
"Run ranges expected in the form: start_period1,end_period1,start_period2,end_period2... => even number expected");
1724 AliInfo(
"Merging efficiencies");
1726 Int_t nRanges = mergedRanges.GetSize()/2;
1734 for (
Int_t irange=0; irange<nRanges; irange++ ) {
1735 Int_t firstRun = mergedRanges[2*irange];
1736 Int_t lastRun = mergedRanges[2*irange+1];
1744 TFileMerger fileMerger;
1746 Int_t run = obj->GetMinRun();
1747 if ( run < firstRun || run > lastRun )
continue;
1748 filename = obj->GetFilename();
1749 outputname = obj->GetOutputname();
1750 if ( firstRun == lastRun )
continue;
1751 fileMerger.AddFile(filename.Data(),kFALSE);
1754 TString sRange = Form(
"%i_%i",firstRun,lastRun);
1755 TString mergedFilename = Form(
"mergedTrigEff_runs_%s.root",sRange.Data());
1757 if ( firstRun == lastRun ) TFile::Cp(filename.Data(),mergedFilename.Data(),kFALSE);
1759 fileMerger.OutputFile(mergedFilename.Data());
1778 if ( averageStatError <= 0. || averageStatError >= 1. )
return runRanges;
1786 Double_t averageStatNeeded = effForStatCalc*(1.-effForStatCalc)/(averageStatError*averageStatError);
1788 AliInfo(Form(
"Average statistics needed to reach precision of %g : %g",averageStatError,averageStatNeeded));
1790 Int_t nRanges = runRanges.GetSize()/2;
1794 for (
Int_t irange=0; irange<nRanges; irange++ ) {
1796 fullStat += averageStat[irange];
1799 TArrayI mergedRanges(runRanges.GetSize());
1801 mergedRanges[imerged++] = runRanges[0];
1802 Double_t mergedAverageStat = 0., remainingStat = fullStat;
1803 for (
Int_t irange=0; irange<nRanges; irange++ ) {
1804 Int_t istart = 2*irange;
1805 Int_t iend = istart+1;
1806 mergedAverageStat += averageStat[irange];
1807 remainingStat -= averageStat[irange];
1809 AliInfo(Form(
"%i - %i => stat %g",runRanges[2*irange],runRanges[2*irange+1],averageStat[irange]));
1811 if ( ( mergedAverageStat >= averageStatNeeded && remainingStat >= averageStatNeeded ) || iend == runRanges.GetSize()-1 ) {
1812 mergedRanges[imerged++] = runRanges[iend];
1813 AliInfo(Form(
" merged range %i - %i => stat %g",mergedRanges[imerged-2],mergedRanges[imerged-1],mergedAverageStat));
1814 mergedAverageStat = 0.;
1815 Int_t nextRun = iend+1;
1816 if ( nextRun < runRanges.GetSize() ) mergedRanges[imerged++] = runRanges[nextRun];
1819 mergedRanges.Set(imerged);
1820 return mergedRanges;
1841 TString trigEffCDBdir =
"MUON/Calib/TriggerEfficiency";
1843 if ( currSrc.BeginsWith(
"alien") && ! gGrid ) TGrid::Connect(
"alien://");
1845 AliMUONTriggerEfficiencyCells* effMap = 0x0;
1846 Bool_t deleteMap = kTRUE;
1847 if ( currSrc.EndsWith(
".root") ) effMap =
new AliMUONTriggerEfficiencyCells(currSrc.Data());
1849 TObjArray* dirRun = currSrc.Tokenize(
"?");
1851 TString runNum = ( dirRun->GetEntriesFast() > 1 ) ? dirRun->UncheckedAt(1)->GetName() :
"";
1852 AliCDBManager* mgr = AliCDBManager::Instance();
1853 if ( ! mgr->GetDefaultStorage() ) mgr->SetDefaultStorage(
"local://$ALICE_ROOT/OCDB");
1854 if ( mgr->GetEntryCache()->Contains(trigEffCDBdir.Data()) ) mgr->UnloadFromCache(trigEffCDBdir.Data());
1855 mgr->SetSpecificStorage(trigEffCDBdir.Data(),cdbPath.Data());
1856 Int_t runNumber = 0;
1857 if ( runNum.IsNull() ) {
1858 cout <<
"Please enter run number: " << endl;
1861 else runNumber = runNum.Atoi();
1862 mgr->SetRun(runNumber);
1863 AliCDBEntry* cdbEntry = mgr->Get(trigEffCDBdir.Data());
1868 effMap =
static_cast<AliMUONTriggerEfficiencyCells*
>(cdbEntry->GetObject());
1872 AliError(Form(
"Cannot find effieciency map in %s",src));
1877 if ( deleteMap )
delete effMap;
1879 return effHistoList;
1895 AliInfo(
"Check for local boards where the efficiency could not be computed and recover it from other maps");
1898 std::vector<TList*> readEffLists;
1899 std::vector<TList*> systLists;
1902 if ( referenceRun >= 0 ) refRun = Form(
"%i",referenceRun);
1903 TList *refRead = 0x0, *refSyst = 0x0;
1908 TList* effList = obj->GetEffHistoList(
fConditions->UncheckedAt(0)->GetName());
1909 std::vector<TH1*> histoList;
1910 histoList.reserve(16);
1911 for (
Int_t ich=0; ich<4; ich++ ) {
1912 for (
Int_t icount=0; icount<4; icount++ ) {
1914 histoList[4*ich+icount] =
static_cast<TH1*
>(effList->FindObject(currName.Data()));
1917 for (
Int_t ibin=1; ibin<=histoList[0]->GetXaxis()->GetNbins(); ibin++ ) {
1918 Bool_t isUnknown[4] = {0,0,0,0};
1919 Int_t nDead = 0, nUnknown = 0;
1920 for (
Int_t ich=0; ich<4; ich++ ) {
1922 if ( countAll > 10 ) {
1924 if ( eff<0.1 ) nDead++;
1932 if ( nUnknown == 3 ) {
1933 for (
Int_t ich=0; ich<4; ich++ ) {
1934 AliInfo(Form(
"Recovering board %i in ch %i",ibin,11+ich));
1935 if ( ! isUnknown[ich] )
continue;
1936 if ( readEffLists.size() == 0 ) {
1939 if ( rList->GetEntries() == 0 ) {
1940 AliError(
"A recovery is needed, but no run list is specified: please specify it");
1943 if ( refRun.IsNull() ) refRun = rList->Last()->GetName();
1944 else if ( ! rList->FindObject(refRun.Data()) ) rList->Add(
new TObjString(refRun));
1945 AliInfo(Form(
"Using efficiency of run %s",refRun.Data()));
1946 for (
Int_t itype=0; itype<2; itype++ ) {
1948 TString currOcdb = ( itype == 0 ) ? ocdb : systOcdb;
1949 TString baseName = ( itype == 0 ) ?
"RecoveredFrom" :
"RecoveredSystFrom";
1951 TObjString* runObj = 0x0;
1952 while ( (runObj = static_cast<TObjString*>(next())) ) {
1953 Bool_t isRefRun = ( runObj->String() == refRun );
1955 if ( itype == 1 && ! isRefRun )
continue;
1957 readEffLists.push_back(readList);
1962 systEffList->SetName(Form(
"%s_%s",baseName.Data(),runObj->GetName()));
1963 systLists.push_back(systEffList);
1965 if ( isRefRun && itype == 0 ) {
1967 refSyst = systEffList;
1972 for (
Int_t imap=0; imap<readEffLists.size(); imap++ ) {
1973 TList* readList = readEffLists[imap];
1974 for (
Int_t icount=0; icount<4; icount++ ) {
1976 TH1* histoFrom =
static_cast<TH1*
>(readList->FindObject(currName.Data()));
1977 TH1* histoTo = ( readList == refRead ) ? histoList[4*ich+icount] : static_cast<TH1*>(systLists[imap]->
FindObject(currName.Data()));
1978 histoTo->SetBinContent(ibin,histoFrom->GetBinContent(ibin));
1983 else AliWarning(Form(
"Local board %i: unknown efficiency: %i %i %i %i",ibin,isUnknown[0],isUnknown[1],isUnknown[2],isUnknown[3]));
1986 for (
TList* systEffHistoList : systLists ) {
1987 if ( systEffHistoList == refSyst )
continue;
1988 obj->AddEffHistoList(systEffHistoList->GetName(),systEffHistoList);
1993 for (
TList* obj : systLists )
delete obj;
1994 readEffLists.clear();
2010 TString sCondition = Form(
"%s;%s;%s",physSel,trigClassName,centrality);
2020 if ( foundCondition ) {
2022 if ( foundCondition == basicCondition )
return kFALSE;
2025 addCondition = foundCondition;
2029 AliInfo(
"Systematic condition already added");
2034 addCondition = sCondition.Tokenize(
";");
2035 addCondition->SetName(sCondition.Data());
2036 addCondition->UncheckedAt(3)->SetUniqueID(itrackSel);
2037 addCondition->UncheckedAt(4)->SetUniqueID(imatch);
2038 addCondition->UncheckedAt(5)->SetUniqueID(imethod);
2043 if ( basicCondition ) {
2044 AliInfo(Form(
"Changing current eff. condition: %s",basicCondition->GetName()));
2046 delete basicCondition;
2053 obj->RemoveEffHistoList(sCondition.Data());
2054 AddToList(obj->GetFilename(), obj->GetOutputname());
2074 return SetCondition(physSel, trigClassName, centrality, itrackSel, imatch, imethod, kTRUE);
2082 AliInfo(
"Reading efficiency objects");
2087 gSystem->ExpandPathName(filename);
2088 if (
gSystem->AccessPathName(filename.Data()) ) {
2089 AliWarning(Form(
"Cannot find %s",filename.Data()));
2092 if ( filename.EndsWith(
".root") )
return AddToList(filename.Data(),outputName);
2095 ifstream inFile(filename.Data());
2097 while ( ! inFile.eof() ) {
2098 currLine.ReadLine(inFile);
2099 if ( currLine.IsNull() )
continue;
2100 if (
gSystem->AccessPathName(currLine.Data()) )
continue;
2101 if ( !
AddToList(currLine.Data(), outputName) ) isOk = kFALSE;
2112 CopyLocally(runList,path,pattern,localFileList,outDir,directory);
2120 CopyLocally(runList,path,
"",localFileList,outDir,directory);
2130 AliInfo(
"Writing merged efficiencies to OCDB");
2133 if ( ! outCDB.Contains(
"://") || outCDB ==
"raw://" ) {
2134 AliError(
"Invalid CDB output dir");
2139 if ( outCDB.BeginsWith(
"alien://") && ! gGrid ) {
2140 TGrid::Connect(
"alien://");
2141 rmCommand =
"alien_rm";
2143 AliError(
"Cannot open grid connection");
2148 AliCDBManager* mgr = AliCDBManager::Instance();
2149 if ( ! mgr->GetDefaultStorage() ) mgr->SetDefaultStorage(
"local://$ALICE_ROOT/OCDB");
2151 TString trigEffCDBdir =
"MUON/Calib/TriggerEfficiency";
2153 mgr->SetSpecificStorage(trigEffCDBdir.Data(),outCDB.Data());
2155 AliCDBStorage* specificStorage = mgr->GetSpecificStorage(trigEffCDBdir.Data());
2156 TString baseOutDir = specificStorage->GetBaseFolder();
2158 TString condName = ( writeSystematics ) ?
"Systematics" :
fConditions->UncheckedAt(0)->GetName();
2161 TList* effHistos = obj->GetEffHistoList(condName.Data());
2162 if ( ! effHistos ) {
2163 AliWarning(
"No systematic condition found: you should first run BuildSystematicMap");
2168 Int_t firstRun = obj->GetMinRun();
2169 Int_t lastRun = obj->GetMaxRun();
2172 for (
Int_t irun=0; irun<2; irun++ ) {
2173 Int_t runnr = ( irun == 0 ) ? firstRun : lastRun;
2174 specificStorage->QueryCDB(runnr);
2175 TObjArray* allIdsForRun = specificStorage->GetQueryCDBList();
2176 TIter nextId(allIdsForRun);
2178 while ((
id = static_cast<AliCDBId*>(nextId()))) {
2180 Int_t foundFirst =
id->GetFirstRun();
2181 Int_t foundLast =
id->GetLastRun();
2182 Int_t version =
id->GetVersion();
2183 Int_t subversion = TMath::Max(id->GetSubVersion(),0);
2184 TString fullPath = Form(
"%s/%s/Run%d_%d_v%d_s%d.root",baseOutDir.Data(),path.Data(),foundFirst,foundLast,version,subversion);
2185 ExecCommand(Form(
"%s %s",rmCommand.Data(),fullPath.Data()), kTRUE);
2190 AliMUONTriggerEfficiencyCells* effMap =
new AliMUONTriggerEfficiencyCells(
CloneEffHistoList(effHistos));
2191 AliMUONCDB::WriteToCDB(effMap,
"MUON/Calib/TriggerEfficiency", firstRun, lastRun,
"Measured efficiencies");
2200 fFilename(filename),
2201 fOutputname(outputname),
2213 for (
auto& mapEntry : fEffLists )
delete mapEntry.second;
2221 auto const& mapEntry = fEffLists.find(condition);
2222 if ( mapEntry == fEffLists.end() )
return 0x0;
2223 return mapEntry->second;
2230 if ( fEffLists.find(condition) != fEffLists.end() ) {
2231 AliWarning(Form(
"Condition %s already present: nothing done",condition));
2234 fEffLists.insert({condition,effHistoList});
2235 fSortKeys.push_back(condition);
2243 auto const& mapEntry = fEffLists.find(condition);
2244 if ( mapEntry == fEffLists.end() )
return kFALSE;
2245 delete mapEntry->second;
2246 return fEffLists.erase(condition);
Counts per cathode histogram index.
return jsonbuilder str().c_str()
TList * GetEffHistoList(TString physSel, TString trigClassNames, TString centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
void CompareMergedEfficiencies(const char *opt) const
void CopyDir(TDirectory *source) const
Double_t GetError(Double_t errLow, Double_t errHigh) const
tracks used for calculation
Bool_t CopyLocally(const char *runList, const char *path, const char *pattern, const char *localFileList, const char *outDir, const char *directory) const
Hit pattern from tracker track extrapolation.
Double_t GetThreeOfFour(TArrayD eff, TArrayD effErr, Double_t &probErr) const
TGraphAsymmErrors * GetTrendEff(Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem) const
Bool_t RemoveEffHistoList(const char *condition)
AliMTRChEffInnerObj(const char *filename, const char *outputname, Int_t minRun, Int_t maxRun=-1)
TArrayI MergeRangesForStat(TArrayI runRanges, Double_t averageStatError, Bool_t excludePeriphericBoards=kTRUE) const
Int_t ComputeAndCompareEfficiencies(const char *sources, const char *titles, const char *opt, const char *canvasNameSuffix="") const
Counts per slat histogram index.
Int_t CompareEfficiencies(const char *sources, const char *titles, const char *opt, const char *canvasNameSuffix="") const
TList * GetEffHistoList(const char *condition) const
Bool_t SetResultsFromGrid(const char *runList, const char *path, const char *pattern, const char *localFileList="localFileList.txt", const char *outDir="", const char *directory="MTR_ChamberEffMap", const char *outputName="testMTRChamberEff")
UShort_t T(UShort_t m, UShort_t t)
TList * GetEffHistoList(AliTrigChEffOutput *trigOut, TObjArray *condition) const
Bool_t WriteMergedToOCDB(const char *outputCDB="CDB", Bool_t writeSystematics=kFALSE) const
Bool_t AddToList(const char *filename, const char *outputName)
virtual ~AliMTRChEffAnalysis()
Int_t CompareEfficiencyMethods(const char *source, const char *opt, const char *canvasNameSuffix="") const
Output for Trig chamber effieincy.
virtual ~AliMTRChEffInnerObj()
Bool_t AddEffHistoList(const char *condition, TList *effHistoList)
TArrayI GetHomogeneousRanges(Double_t chi2Cut=3, Int_t maxNRanges=4, Double_t minEffVariation=0.005, Bool_t perRPC=kTRUE, TArrayI *forcedChanges=0x0, Double_t minEff=0.85, Double_t maxEff=1.01)
Bool_t SetEffConditions(const char *physSel, const char *trigClassName, const char *centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
Output for Trig chamber effieincy.
AliTrigChEffOutput * fNamer
! Namer for histograms
void DrawStatContribution(Int_t itype, Int_t irpc, Double_t maxNsigmaOutliers=-1., Double_t minY=0., Double_t maxY=0.15) const
Double_t GetAverageStat(Int_t firstRun, Int_t lastRun, Int_t itype=AliTrigChEffOutput::kHboardEff, Bool_t excludePeriphericBoards=kTRUE) const
Bool_t SetOutList(const char *localFileList, const char *outputName)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
TString GetId(const char *condition, Int_t minRun, Int_t maxRun=-1) const
TObject * FindObject(int bin, const char *nameH, const TList *lst, Bool_t normPerEvent=kTRUE)
AliTrigChEffOutput * Namer() const
std::vector< AliMTRChEffAnalysis::AliMTRChEffInnerObj * > fRunMap
! Map of internal objects per run
std::vector< AliMTRChEffAnalysis::AliMTRChEffInnerObj * > fMergedMap
! Map of merged internal objects
TH1 * GetHisto(TList *effHistoList, Int_t itype, Int_t icount, Int_t ichamber) const
Bool_t SetCondition(const char *physSel, const char *trigClassName, const char *centrality, Int_t itrackSel, Int_t imatch, Int_t imethod, Bool_t isBasic)
TList * GetRunList(const char *runList) const
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
Int_t GetRunNumber(Int_t ipt) const
Bool_t HasMergedResults() const
Bool_t ExecCommand(TString command, Bool_t prompt) const
TArrayI BoardsInRPC(Int_t irpc) const
Bool_t RecoverEfficiency(const char *runList, const char *ocdb, const char *systOcdb, Int_t referenceRun=-1)
Int_t GetIndexFromRun(Int_t runNumber) const
Double_t FitRangesFunc(Double_t *x, Double_t *par)
Counts per board histogram index.
Int_t GetRunNumber(TString)
void DrawEffTrend(Int_t itype, Int_t irpc, Double_t maxNsigmasOutliers=-1., Double_t minEff=0.8, Double_t maxEff=1.01) const
TObjArray * fConditions
! List of conditions for trigger efficiency
TList * CloneEffHistoList(TList *effHistos) const
TGraphAsymmErrors * GetOutliers(TGraphAsymmErrors *graph, Double_t maxNsigmas=3.) const
Bool_t AddSystematicCondition(const char *physSel, const char *trigClassName, const char *centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
TString GetShortConditionTitle(const char *conditionName) const
Bool_t SetResultsFromWeb(const char *runList, const char *path, const char *localFileList="localFileList.txt", const char *outDir="", const char *directory="MTR_ChamberEffMap", const char *outputName="testMTRChamberEff")
Bool_t DrawSystematicEnvelope(Bool_t perRPC=kFALSE) const
Bool_t MergeOutput(TArrayI runRanges, Double_t averageStatError=0.01, Bool_t isIndex=kFALSE)
TString GetHistoName(Int_t itype, Int_t icount, Int_t ichamber, Int_t itrackSel, Int_t imatch, Int_t imethod)
Bool_t SetDefaultEffConditions()
Bool_t BuildSystematicMap()
TH1 * GetSum(AliTrigChEffOutput *trigOut, TObjArray *condition, Int_t itype, Int_t icount, Int_t ichamber) const
TList * ReadEffHistoList(const char *src) const
TH1 * GetTrend(Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem) const