StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makePlots.C
1 void verticleRapidity(TH2F* h){
2 
3  for(int ix=1;ix<=h->GetNbinsX();ix++){
4  for(int iy=1;iy<=h->GetNbinsY();iy++){
5  float xval=h->GetBinContent(ix,iy);
6  float zval=log(sqrt(1+xval*xval/0.01)+xval/0.1);
7  h->SetBinContent(ix,iy,zval);
8  }
9  }
10 
11  return;
12 }
13 
14 int findAxisNames(const char* hname, int& prefixid, int* varid, int* combid){
15 
16  // A name manipulation routine ... should be done in perl! but oh well
17 
18  // 1st strip off and id any prefix
19  char* prenames[]={"LS","US","CD","CI","pp"};
20  char* newname=NULL;
21  char* preptr;
22  for(int i=0;i<5;i++){
23  if((preptr=strstr(hname,prenames[i]))) break;
24  }
25  // all have 2 prefix chars that I strip here
26  prefixid=i;
27  preptr++; preptr++;
28  newname=new char[strlen(preptr)+1];
29  strcpy(newname,preptr);
30 
31 
32  // now find the type
33  char* tnames[]={"Yt","Eta","Phi","Pt","Xt"};
34  char* ptr[5];
35  char* ptr1[2]={NULL,NULL};
36  int icount=0;
37  int nameid[2]={-1,-1};
38 
39  for(int i=0;i<5;i++){
40  ptr[i]=strstr(newname,tnames[i]);
41  if(ptr[i]){
42  ptr1[icount]=ptr[i];
43  nameid[icount]=i;
44  icount++;
45  }
46  }
47 
48  if(icount==0) return 1;
49 
50  if(icount==1){
51  char* tmpstr=ptr1[0];
52  tmpstr++;
53  ptr1[1]=strstr(tmpstr,tnames[nameid[0]]);
54  if(ptr1[1])nameid[1]=nameid[0];
55  icount++;
56  }
57  if(icount==1)return 1;
58 
59  if(ptr1[0]>ptr1[1]){
60  char* tmpptr=ptr1[1];
61  ptr1[1]=ptr1[0];
62  ptr1[0]=tmpptr;
63  int tmpid=nameid[1];
64  nameid[1]=nameid[0];
65  nameid[0]=tmpid;
66  }
67 
68  for(int i=0;i<2;i++)varid[i]=nameid[i];
69 
70  // okay we've got it as (e.g.) XEtaYPhi where X,Y is either S, D, or nothing
71  // so find them....
72 
73  char* n2names[]={NULL,"D","S"};
74  int n2id[2]={-1,-1};
75  if(strcmp(ptr1[0],newname)==0){ // X=Y=nothing (we don't yet have EtaDPhi)
76  n2id[0]=n2id[1]=0;
77 
78  } else {
79  for(int k=0;k<2;k++){
80  char* tmp2=ptr1[k];
81  tmp2--;
82  for(int i=1;i<3;i++){
83  char* tmp3;
84  if((tmp3=strstr(tmp2,n2names[i])) && tmp3==tmp2){
85  n2id[k]=i;
86  break;
87  }
88  }
89  }
90  }
91  for(int i=0;i<2;i++) {
92  if(n2id[i]==-1) return 2;
93  combid[i]=n2id[i];
94  }
95 }
96 
97 //------------------------------------------------------------------
98 bool makePlots4P(TH2F** hists, const char* plttype, int opt=0){
99 
100  int prefixid;
101  int varid[2];
102  int combid[2];
103  int itest=findAxisNames(hists[0]->GetName(),prefixid,varid,combid);
104 
105  if(itest){
106  cout<<"Failed to find valid name from "<<hists[0]->GetName();
107  cout<<" errorid="<<itest<<endl;
108  return false;
109  }
110 
111  c1 = new TCanvas();
112  c1->Divide(2,2);
113 
114 
115  int ititle=0;
116  if(prefixid>3)ititle=1;
117 
118  TLatex tl;
119  tl.SetTextFont(12);
120  char* tlNames[]={"y_{t,", "#eta_{", "#phi_{", "p_{t,", "X_{t,"};
121  char* tl2Names[]={"#Delta}","#Sigma}"};
122  char* xvsy[]={"1}","2}"};
123 
124  TString* axislabel[2];
125  for(int i=0;i<2;i++){
126  axislabel[i]=new TString(tlNames[varid[i]]);
127  if(combid[i]<1){
128  *axislabel[i]+=xvsy[i];
129  } else {
130  *axislabel[i]+=tl2Names[combid[i]-1];
131  }
132  }
133 
134  char* atitle[]={"Like-sign (LS)","Unlike-sign (US)"," CD=LS-US"," CI=LS+US"};
135  char* btitle[]={"Pos.Pairs (++)","Unlike Sign (US)"," Neg.Pairs (--)","LS diff. = ++ - --"};
136 
137  float xvl[4]={0.01,0.5,0.28,0.8};
138  float yvl[4]={0.5,0.02,0.12,0.15};
139  int ivl=0;
140  for(int i=0;i<4;i++){
141  TH2F* h=(TH2F*)hists[i]->Clone();
142  cout<<"hist ="<<h->GetName();
143  cout<<" max = "<<h->GetMaximum()<<" min = "<<h->GetMinimum()<<endl;
144 
145  if(opt>0)verticleRapidity(h);
146 
147  tl.SetTextSize(0.05);
148  h->SetNdivisions(5,"Z");
149  h->SetStats(0);
150  c1->cd(i+1);
151  if(strstr(plttype,"surf")){
152  c1->SetPhi(50);
153  c1->SetTheta(50);
154  ivl=2;
155  }
156  h->Draw(plttype);
157  tl.SetNDC();
158  if(0==ititle){
159  tl.DrawLatex(0.31,0.91,atitle[i]);
160  } else {
161  tl.DrawLatex(0.31,0.91,btitle[i]);
162  }
163 
164  tl.SetTextSize(0.08);
165 
166  tl.DrawLatex(xvl[ivl],yvl[ivl],axislabel[1]->Data());
167  tl.DrawLatex(xvl[ivl+1],yvl[ivl+1],axislabel[0]->Data());
168 
169  }
170 
171  return true;
172 }
173 
174 
175 //-------------------------------------------------------------------------
176 void makePlots(TH2F** hists, int itype=0){
177 
178  /********************************************
179  itype=0 surface plots
180  =1 colz plots
181  =2 colz with rapidity verticle scale
182  **********************************************/
183 
184  if(!hists) {
185  cout<<"What? input NULL ** hists? we'll give this back to you"<<endl;
186  return;
187  }
188 
189 
190  bool isok=false;
191 
192  if(itype==0){
193  const char* plttype="surf1";
194  isok=makePlots4P(hists,plttype);
195  } else if(itype==1){
196  isok=makePlots4P(hists,"colz");
197  } else if(itype==2){
198  isok=makePlots4P(hists,"colz",1);
199  } else {
200  cout<<" undefined itype="<<itype<<endl;
201  }
202 
203  if(!isok)cout<<"plotting failed "<<endl;
204 
205 };
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222