File indexing completed on 2024-04-06 12:27:57
0001 #include "HcalElectronicsSelector.h"
0002 #include "MyHcalClasses.h"
0003 #include "TCanvas.h"
0004 #include "TH2.h"
0005 #include "TRandom.h"
0006 #include "TStyle.h"
0007
0008 inline double sign(double x) { return (x < 0.0) ? -1.0 : 1.0; }
0009
0010 static const float BADVAL = -1e99;
0011
0012 HcalElectronicsSelector::HcalElectronicsSelector(Callbacks* cb,
0013 int htrChan_lo, int htrChan_hi,
0014 int fpga_lo, int fpga_hi,int crate)
0015 {
0016 m_crate=crate;
0017 m_cb=cb;
0018 m_canvas=new TCanvas("HcalSelector");
0019
0020
0021 int htrChan_bins=htrChan_hi-htrChan_lo+1;
0022 int fpga_bins=(fpga_hi-fpga_lo+1)*2;
0023
0024 char name[10];
0025 char title[256];
0026
0027 sprintf(title,"htrChan/fpga Space Crate %d",crate);
0028 sprintf(name,"Crate %d",crate);
0029 TH2F* h = new TH2F(title,name,
0030 fpga_bins, fpga_lo-0.25, fpga_hi+0.75,
0031 htrChan_bins, htrChan_lo-0.5, htrChan_hi+0.5);
0032
0033 h->GetYaxis()->SetTitle("HTR CHANNEL");
0034 h->GetXaxis()->SetTitle("Slot");
0035 h->SetStats(0);
0036
0037
0038
0039 for (int binx=1; binx<=h->GetNbinsX(); binx++)
0040 for (int biny=1; biny<=h->GetNbinsY(); biny++)
0041 h->SetBinContent(binx,biny,BADVAL);
0042 m_hist = h;
0043
0044 TStyle* ms=new TStyle("hvs","hvs");
0045 ms->SetPalette(1,0);
0046 ms->cd();
0047
0048
0049 m_canvas->cd();
0050 m_hist->Draw("COLZ");
0051 m_canvas->Update();
0052
0053 m_canvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
0054 "HcalElectronicsSelector", this,
0055 "onEvent(Int_t,Int_t,Int_t,TObject*)");
0056
0057 m_canvas->cd();
0058 }
0059
0060 void HcalElectronicsSelector::onEvent(Int_t event, Int_t x, Int_t y, TObject *selected)
0061 {
0062 if(event!=kButton1Double) return;
0063 TPad *pad=(TPad*) m_canvas->GetSelectedPad();
0064 if(selected==0) return;
0065
0066
0067
0068
0069 char padname[256];
0070 strcpy(padname,m_canvas->GetSelectedPad()->GetName());
0071
0072 char canvasname[40];
0073
0074 Float_t px= pad->AbsPixeltoX(x);
0075 Float_t py= pad->AbsPixeltoY(y);
0076
0077 px=pad->PadtoX(px);
0078 py=pad->PadtoY(py);
0079
0080
0081
0082 int Xbin=m_hist->GetXaxis()->FindBin(px);
0083 int Ybin=m_hist->GetYaxis()->FindBin(py);
0084
0085
0086 if (Xbin==0 || Ybin==0 ||
0087 Xbin>m_hist->GetXaxis()->GetNbins() ||
0088 Ybin>m_hist->GetYaxis()->GetNbins()) {
0089 printf("Please select a location within the graph boundaries.\n");
0090 return;
0091 }
0092
0093 int htrChan=(int)(py+(sign(py)*0.5));
0094 int fpga=(int)(px*2);
0095
0096 int crate=m_crate;
0097
0098 printf("htrChan=%d fpga=%d Crate=%d\n",htrChan,fpga,crate);
0099 if (m_cb==0) return;
0100
0101 int fbr=((htrChan-1)/3)+1;
0102 int fbrchan=(htrChan-1)%3;
0103 int slt=(fpga/2);
0104 int tb=(fpga%2)?(1):(0);
0105
0106 MyElectronicsId id = {fbr,fbrchan,crate,slt,tb};
0107 m_cb->plot(id);
0108 }
0109
0110 void HcalElectronicsSelector::fill(const MyElectronicsId& id, double value) {
0111
0112 TH2* h = m_hist;
0113 int htrChan=(id.fiber-1)*3+1+id.fiberChan;
0114 double fpga= (id.tb==1)?(id.Slot+0.5):(id.Slot);
0115
0116 h->SetBinContent(h->FindBin(fpga*1.0,htrChan*1.0,0.0),value);
0117 }
0118
0119 void HcalElectronicsSelector::Update() {
0120 m_canvas->Flush();
0121 m_canvas->Update();
0122 m_canvas->Paint();
0123 }
0124
0125