1 |
andersj |
1.1 |
#include "HcalVisualSelector.h"
|
2 |
|
|
#include "MyHcalClasses.h"
|
3 |
|
|
#include "TCanvas.h"
|
4 |
|
|
#include "TH2.h"
|
5 |
|
|
#include "TRandom.h"
|
6 |
|
|
#include "TStyle.h"
|
7 |
|
|
|
8 |
|
|
inline double sign(double x) { return (x < 0.0) ? -1.0 : 1.0; }
|
9 |
|
|
|
10 |
|
|
static const float BADVAL = -1e99;
|
11 |
|
|
|
12 |
|
|
HcalVisualSelector::HcalVisualSelector(Callbacks* cb,
|
13 |
|
|
int ieta_lo, int ieta_hi,
|
14 |
|
|
int iphi_lo, int iphi_hi)
|
15 |
|
|
{
|
16 |
|
|
m_cb=cb;
|
17 |
|
|
m_canvas=new TCanvas("HcalSelector");
|
18 |
|
|
m_canvas->Divide(2,2);
|
19 |
|
|
|
20 |
|
|
int ieta_bins=ieta_hi-ieta_lo+1;
|
21 |
|
|
int iphi_bins=iphi_hi-iphi_lo+1;
|
22 |
|
|
|
23 |
|
|
char name[10];
|
24 |
|
|
char title[256];
|
25 |
|
|
for(int i=0;i<4;i++) {
|
26 |
|
|
sprintf(title,"iEta/iPhi Space Depth %d",i+1);
|
27 |
|
|
sprintf(name,"Depth %d",i+1);
|
28 |
|
|
TH2F* h = new TH2F(title,name,
|
29 |
|
|
ieta_bins, ieta_lo-0.5, ieta_hi+0.5,
|
30 |
|
|
iphi_bins, iphi_lo-0.5, iphi_hi+0.5);
|
31 |
|
|
h->GetXaxis()->SetTitle("IETA");
|
32 |
|
|
h->GetYaxis()->SetTitle("IPHI");
|
33 |
|
|
h->SetStats(0);
|
34 |
|
|
// Set bins to a 'badval' in order to distinguish
|
35 |
|
|
// between zero-mean cells and unconnected cells
|
36 |
|
|
//
|
37 |
|
|
for (int binx=1; binx<=h->GetNbinsX(); binx++)
|
38 |
|
|
for (int biny=1; biny<=h->GetNbinsY(); biny++)
|
39 |
|
|
h->SetBinContent(binx,biny,BADVAL);
|
40 |
|
|
m_hist[i] = h;
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
TStyle* ms=new TStyle("hvs","hvs");
|
44 |
|
|
ms->SetPalette(1,0);
|
45 |
|
|
ms->cd();
|
46 |
|
|
|
47 |
|
|
for(int i=0;i<4;i++) {
|
48 |
|
|
m_canvas->cd(i+1);
|
49 |
|
|
m_hist[i]->Draw("COLZ");
|
50 |
|
|
m_canvas->Update();
|
51 |
|
|
}
|
52 |
|
|
m_canvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
|
53 |
|
|
"HcalVisualSelector", this,
|
54 |
|
|
"onEvent(Int_t,Int_t,Int_t,TObject*)");
|
55 |
|
|
|
56 |
|
|
m_canvas->cd();
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
void HcalVisualSelector::onEvent(Int_t event, Int_t x, Int_t y, TObject *selected) {
|
60 |
|
|
if(event!=kButton1Double) return;
|
61 |
|
|
TPad *pad=(TPad*) m_canvas->GetSelectedPad();
|
62 |
|
|
if(selected==0) return; // this is to suppress "Unused" message
|
63 |
|
|
// printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n",
|
64 |
|
|
// m_canvas->GetName(),event, x, y, selected->IsA()->GetName());
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
char padname[256];
|
68 |
|
|
strcpy(padname,m_canvas->GetSelectedPad()->GetName());
|
69 |
|
|
|
70 |
|
|
if (strstr(padname,"_"))
|
71 |
|
|
*(strstr(padname,"_"))=' ';
|
72 |
|
|
|
73 |
|
|
char canvasname[40];
|
74 |
|
|
int padnum;
|
75 |
|
|
|
76 |
|
|
sscanf(padname,"%s %d",canvasname,&padnum);
|
77 |
|
|
|
78 |
|
|
Float_t px= pad->AbsPixeltoX(x);
|
79 |
|
|
Float_t py= pad->AbsPixeltoY(y);
|
80 |
|
|
|
81 |
|
|
px=pad->PadtoX(px);
|
82 |
|
|
py=pad->PadtoY(py);
|
83 |
|
|
|
84 |
|
|
//printf("x=%.3g,y=%.3g\n",px,py);
|
85 |
|
|
|
86 |
|
|
int Xbin=m_hist[padnum-1]->GetXaxis()->FindBin(px);
|
87 |
|
|
int Ybin=m_hist[padnum-1]->GetYaxis()->FindBin(py);
|
88 |
|
|
|
89 |
|
|
//printf("Xbin=%d,Ybin=%d\n",Xbin,Ybin);
|
90 |
|
|
if (Xbin==0 || Ybin==0 ||
|
91 |
|
|
Xbin>m_hist[padnum-1]->GetXaxis()->GetNbins() ||
|
92 |
|
|
Ybin>m_hist[padnum-1]->GetYaxis()->GetNbins()) {
|
93 |
|
|
printf("Please select a location within the graph boundaries.\n");
|
94 |
|
|
return;
|
95 |
|
|
}
|
96 |
|
|
// convert to ieta/iphi
|
97 |
|
|
int ieta=(int)(px+(sign(px)*0.5));
|
98 |
|
|
int iphi=(int)(py+(sign(py)*0.5));
|
99 |
|
|
int depth=padnum;
|
100 |
|
|
printf("ieta=%d iphi=%d depth=%d\n",ieta,iphi,depth);
|
101 |
|
|
if (m_cb==0) return; // need a callback
|
102 |
|
|
|
103 |
|
|
// figure out Subdetector
|
104 |
|
|
MyHcalSubdetector sd=m_cb->getSubdet(ieta,depth);
|
105 |
|
|
|
106 |
|
|
MyHcalDetId id = {sd,ieta,iphi,depth};
|
107 |
|
|
m_cb->plot(id);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
void HcalVisualSelector::fill(const MyHcalDetId& id, double value) {
|
111 |
|
|
//if (id.depth!=1) return;
|
112 |
|
|
// what about depth?
|
113 |
|
|
TH2* h = m_hist[id.depth-1];
|
114 |
|
|
h->SetBinContent(h->FindBin(id.ieta*1.0,id.iphi*1.0,0.0),value);
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
void HcalVisualSelector::Update() {
|
118 |
|
|
m_canvas->Flush();
|
119 |
|
|
m_canvas->Update();
|
120 |
|
|
m_canvas->Paint();
|
121 |
|
|
}
|