Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:57

0001 #include "HcalVisualSelector.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 HcalVisualSelector::HcalVisualSelector(Callbacks* cb,
0013                        int ieta_lo, int ieta_hi,
0014                        int iphi_lo, int iphi_hi)
0015 {
0016   m_cb=cb;
0017   m_canvas=new TCanvas("HcalSelector");
0018   m_canvas->Divide(2,2);
0019   
0020   int ieta_bins=ieta_hi-ieta_lo+1;
0021   int iphi_bins=iphi_hi-iphi_lo+1;
0022 
0023   char name[10];
0024   char title[256];
0025   for(int i=0;i<4;i++) {
0026     sprintf(title,"iEta/iPhi Space Depth %d",i+1);
0027     sprintf(name,"Depth %d",i+1);
0028     TH2F* h = new TH2F(title,name,
0029                ieta_bins, ieta_lo-0.5, ieta_hi+0.5,
0030                iphi_bins, iphi_lo-0.5, iphi_hi+0.5);
0031     h->GetXaxis()->SetTitle("IETA");
0032     h->GetYaxis()->SetTitle("IPHI");
0033     h->SetStats(0);
0034     // Set bins to a 'badval' in order to distinguish
0035     // between zero-mean cells and unconnected cells
0036     //
0037     for (int binx=1; binx<=h->GetNbinsX(); binx++)
0038       for (int biny=1; biny<=h->GetNbinsY(); biny++)
0039     h->SetBinContent(binx,biny,BADVAL);
0040     m_hist[i] = h;
0041   }
0042 
0043   TStyle* ms=new TStyle("hvs","hvs");
0044   ms->SetPalette(1,0);
0045   ms->cd();
0046 
0047   for(int i=0;i<4;i++) {
0048     m_canvas->cd(i+1);
0049     m_hist[i]->Draw("COLZ");
0050     m_canvas->Update();
0051   }
0052   m_canvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
0053             "HcalVisualSelector", this,
0054             "onEvent(Int_t,Int_t,Int_t,TObject*)");
0055   
0056   m_canvas->cd();
0057 }
0058 
0059 void HcalVisualSelector::onEvent(Int_t event, Int_t x, Int_t y, TObject *selected) {
0060   if(event!=kButton1Double) return;
0061   TPad *pad=(TPad*) m_canvas->GetSelectedPad();
0062   if(selected==0) return; // this is to suppress "Unused" message
0063   //  printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n",
0064   //         m_canvas->GetName(),event, x, y, selected->IsA()->GetName());
0065   
0066 
0067    char padname[256];
0068    strcpy(padname,m_canvas->GetSelectedPad()->GetName());
0069 
0070    if (strstr(padname,"_"))
0071      *(strstr(padname,"_"))=' ';
0072 
0073    char canvasname[40];
0074    int padnum;
0075 
0076    sscanf(padname,"%s %d",canvasname,&padnum);
0077 
0078    Float_t px= pad->AbsPixeltoX(x);
0079    Float_t py= pad->AbsPixeltoY(y);
0080 
0081    px=pad->PadtoX(px);
0082    py=pad->PadtoY(py);
0083 
0084    //printf("x=%.3g,y=%.3g\n",px,py);
0085 
0086    int Xbin=m_hist[padnum-1]->GetXaxis()->FindBin(px);
0087    int Ybin=m_hist[padnum-1]->GetYaxis()->FindBin(py);
0088 
0089    //printf("Xbin=%d,Ybin=%d\n",Xbin,Ybin);
0090    if (Xbin==0 || Ybin==0 || 
0091        Xbin>m_hist[padnum-1]->GetXaxis()->GetNbins() ||
0092        Ybin>m_hist[padnum-1]->GetYaxis()->GetNbins()) {
0093      printf("Please select a location within the graph boundaries.\n");
0094      return;
0095    }
0096    // convert to ieta/iphi
0097    int ieta=(int)(px+(sign(px)*0.5));
0098    int iphi=(int)(py+(sign(py)*0.5));
0099    int depth=padnum;
0100    printf("ieta=%d iphi=%d depth=%d\n",ieta,iphi,depth);
0101    if (m_cb==0) return; // need a callback
0102 
0103    // figure out Subdetector
0104    MyHcalSubdetector sd=m_cb->getSubdet(ieta,depth);
0105       
0106    MyHcalDetId id = {sd,ieta,iphi,depth};
0107    m_cb->plot(id);
0108 }
0109 
0110 void HcalVisualSelector::fill(const MyHcalDetId& id, double value) {
0111   //if (id.depth!=1) return;
0112   // what about depth?
0113   TH2* h = m_hist[id.depth-1];
0114   h->SetBinContent(h->FindBin(id.ieta*1.0,id.iphi*1.0,0.0),value);
0115 }
0116 
0117 void HcalVisualSelector::Update() {
0118   m_canvas->Flush();
0119   m_canvas->Update();
0120   m_canvas->Paint();
0121 }