File indexing completed on 2026-10-15 08:17:25
0001 #ifndef ETALABELS_H
0002 #define ETALABELS_H
0003
0004
0005
0006 #include <TString.h>
0007 #include <TVirtualPad.h>
0008 #include <TList.h>
0009 #include <TH1.h>
0010 #include <TGraph.h>
0011 #include <TText.h>
0012 #include <TPaveText.h>
0013 #include <TLegend.h>
0014 #include <TLegendEntry.h>
0015
0016
0017 inline bool IsHPairType(int ipaty){ return IsHadronParticleID(PairTypes_Info[ipaty][0]) || IsHadronParticleID(PairTypes_Info[ipaty][1]); }
0018
0019 inline TString YToEta(const TString& in){
0020 static const char* MAP[][2] = { {"R_{2yy}","R_{2#eta#eta}"}, {"#Deltay","#Delta#eta"}, {"y_{1}","#eta_{1}"}, {"y_{2}","#eta_{2}"},
0021 {"dy","d#eta"}, {"y1","#eta_{1}"}, {"y2","#eta_{2}"} };
0022 auto word = [](char c){ return isalnum((unsigned char)c) || c=='_'; };
0023 TString out;
0024 const int n = in.Length();
0025 for (int i=0;i<n;){
0026 bool done = false;
0027 for (auto &m : MAP){
0028 const int l = strlen(m[0]);
0029 if (i+l>n || TString(in(i,l))!=m[0]) continue;
0030 const bool startOK = (m[0][0]=='#' || m[0][0]=='R') || i==0 || !word(in[i-1]);
0031 const bool endOK = (m[0][l-1]=='}') || i+l==n || !word(in[i+l]);
0032 if (!startOK || !endOK) continue;
0033 out += m[1]; i += l; done = true; break;
0034 }
0035 if (!done){ out += in[i]; ++i; }
0036 }
0037 return out;
0038 }
0039
0040 inline void EtaLabelsH(TH1* h){
0041 if (!h) return;
0042 h->SetTitle(YToEta(h->GetTitle()));
0043 h->GetXaxis()->SetTitle(YToEta(h->GetXaxis()->GetTitle()));
0044 h->GetYaxis()->SetTitle(YToEta(h->GetYaxis()->GetTitle()));
0045 }
0046
0047
0048 inline void EtaLabels(TVirtualPad* pad){
0049 if (!pad || !pad->GetListOfPrimitives()) return;
0050 TIter next(pad->GetListOfPrimitives());
0051 while (TObject* o = next()){
0052 if (o->InheritsFrom(TVirtualPad::Class())) EtaLabels((TVirtualPad*)o);
0053 else if (o->InheritsFrom(TH1::Class())) EtaLabelsH((TH1*)o);
0054 else if (o->InheritsFrom(TGraph::Class())){ TGraph *g = (TGraph*)o; g->SetTitle(YToEta(g->GetTitle())); if (g->GetHistogram()) EtaLabelsH(g->GetHistogram()); }
0055 else if (o->InheritsFrom(TLegend::Class())){ TIter nl(((TLegend*)o)->GetListOfPrimitives()); while (TObject* e = nl()) ((TLegendEntry*)e)->SetLabel(YToEta(((TLegendEntry*)e)->GetLabel())); }
0056 else if (o->InheritsFrom(TPaveText::Class())){ TIter nl(((TPaveText*)o)->GetListOfLines()); while (TObject* t = nl()) if (t->InheritsFrom(TText::Class())) ((TText*)t)->SetTitle(YToEta(((TText*)t)->GetTitle())); }
0057 else if (o->InheritsFrom(TText::Class())) ((TText*)o)->SetTitle(YToEta(((TText*)o)->GetTitle()));
0058 }
0059 pad->Modified();
0060 }
0061 inline void EtaLabelsIf(TVirtualPad* pad, int ipaty){ if (IsHPairType(ipaty)){ EtaLabels(pad); pad->Update(); } }
0062 #endif