00001 #include "VisReco/VisMuonCSC/interface/VisCSCStackPlots.h"
00002 #include "VisReco/VisMuonCSC/interface/VisCSCPlotWidget.h"
00003 #include "VisReco/VisMuonCSC/interface/VisCSCPlotWidgetAxisX.h"
00004 #include "VisReco/VisMuonCSC/interface/VisCSCPlotWidgetAxisY.h"
00005 #include "VisReco/VisMuonCSC/interface/VisCSCChamberSelectorImpl.h"
00006 #include "VisReco/VisMuonCSC/interface/VisCSCChamberSelectorImplService.h"
00007
00008 #include "DataFormats/CSCDigi/interface/CSCStripDigi.h"
00009
00010 #include "Iguana/Framework/interface/IgState.h"
00011
00012 #include <qlayout.h>
00013 #include <qlabel.h>
00014 #include <qfont.h>
00015 #include <qapplication.h>
00016 #include <iostream>
00017
00018 namespace
00019 {
00020
00021
00022 bool CSCDetCmp(const CSCDetId l, const CSCDetId r)
00023 {
00024 return
00025 (l.layer() == r.layer() || l.layer() ==0 || r.layer() ==0 ) &&
00026 (l.chamber() == r.chamber() || l.chamber() ==0 || r.chamber() ==0 ) &&
00027 (l.ring() == r.ring() || l.ring() ==0 || r.ring() ==0 ) &&
00028 (l.station() == r.station() || l.station() ==0 || r.station() ==0 ) &&
00029 (l.endcap() == r.endcap() || l.endcap() ==0 || r.endcap() ==0 );
00030 }
00031 }
00032
00033
00034 VisCSCStackPlots::VisCSCStackPlots(IgState* state, int np, int nb, QWidget* parent, const char* name, WFlags f):
00035 QWidget(parent, name, f), m_widgets(np), m_np(np)
00036 {
00037 m_did = CSCDetId(0, 0, 0, 0);
00038
00039
00040 VisCSCChamberSelectorImplService *selSvc = VisCSCChamberSelectorImplService::get(state);
00041 if (! selSvc)
00042 {
00043 selSvc = new VisCSCChamberSelectorImplService (state);
00044 }
00045 m_selector = selSvc->selector();
00046 connect(m_selector, SIGNAL(selectionChange(uint32_t)), this, SLOT(newSelector(uint32_t)));
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 QGridLayout *l = new QGridLayout( this, 1, 1, 0, 0 );
00061 QLabel *label = new QLabel(name, this);
00062 QFont fnt("Helvetica");
00063 label->setFont(fnt);
00064 label->setAlignment(Qt::AlignCenter);
00065
00066 l->addWidget(label, 0, 1);
00067 l->setColSpacing( 2, 10 );
00068 l->setColStretch( 1, 1 );
00069
00070 for (int i=0; i < m_np; i++)
00071 {
00072 VisCSCPlotWidget *pn = new VisCSCPlotWidget( nb, this, "plot" );
00073 m_widgets[i] = pn;
00074 pn->setAutoScale(true);
00075 VisCSCPlotWidgetAxisY *y = new VisCSCPlotWidgetAxisY(pn, this);
00076 l->addWidget( y, i+1, 0 );
00077 l->addWidget( pn, i+1, 1 );
00078 connect(this,SIGNAL(newData(void)),y,SLOT(update()));
00079 }
00080 VisCSCPlotWidgetAxisX *xaxis= new VisCSCPlotWidgetAxisX( nb, this );
00081 l->addWidget( xaxis, m_np+1, 1 );
00082 }
00083
00084 VisCSCStackPlots::~VisCSCStackPlots(void)
00085 {
00086 }
00087 void VisCSCStackPlots::setData(const int plot, const std::vector<dataPt> &data)
00088 {
00089 if (plot >= m_np)
00090 {
00091
00092 return;
00093 }
00094 m_widgets[plot]->setData(data);
00095 }
00096 void VisCSCStackPlots::setData(std::vector< std::pair<CSCDetId, CSCStripDigi> >& digis)
00097 {
00098 m_digis = digis;
00099 newSelector(m_did);
00100 }
00101 void VisCSCStackPlots::newSelector(uint32_t id)
00102 {
00103 m_did = id;
00104
00105
00106
00107
00108
00109
00110
00111
00112 const int n_tick = 8;
00113 const int n_layer = 6;
00114
00115 std::vector<int> dummy6(n_layer,0);
00116 std::vector<int> dummy8(n_tick,0);
00117
00118
00119 std::map<uint64_t, std::vector<std::vector<int> > > buff;
00120 std::vector< std::vector<int > > dummy68(n_layer, dummy8);
00121
00122
00123 for (std::vector<std::pair<CSCDetId, CSCStripDigi> >::const_iterator i = m_digis.begin (), iEnd = m_digis.end (); i != iEnd; ++i)
00124 {
00125 if (CSCDetCmp((*i).first, m_did))
00126 {
00127 uint64_t tid = (*i).first.chamberId().rawId();
00128 tid <<= 32;
00129 tid |= (*i).second.getStrip();
00130 if (buff.find(tid) == buff.end()) buff[tid] = dummy68;
00131
00132
00133
00134
00135
00136
00137
00138 buff[tid][(*i).first.layer()-1] = (*i).second.getADCCounts();
00139 }
00140 }
00141
00142 std::vector<std::vector<int> > obuf(n_tick, dummy6);
00143 std::vector<dataPt> ddummy;
00144 std::vector<std::vector<dataPt> > final(n_tick,ddummy);
00145 int iout = 1;
00146 for (std::map<uint64_t, std::vector<std::vector<int> > >::const_iterator im = buff.begin(); im != buff.end(); ++im, ++iout)
00147 {
00148 for (std::vector<std::vector<int> >::const_iterator in = (*im).second.begin(); in != (*im).second.end(); ++in)
00149 {
00150 for (std::vector<int>::const_iterator it = (*in).begin(); it != (*in).end(); ++it)
00151 {
00152
00153 int itd = static_cast<int>(std::distance((*in).begin(),it));
00154 int ind = static_cast<int>(std::distance((*im).second.begin(),in));
00155 obuf[itd][ind] = (*it);
00156 }
00157 }
00158 for (std::vector<std::vector<dataPt > >::iterator o = final.begin(); o != final.end(); ++o )
00159 {
00160 (*o).push_back(dataPt((*im).first, obuf[std::distance(final.begin(), o)]));
00161
00162
00163
00164
00165 }
00166 }
00167 int plot=0;
00168 for (std::vector<std::vector<dataPt> >::iterator it=final.begin(); it != final.end(); ++it, ++plot)
00169 {
00170 m_widgets[plot]->setData(*it);
00171 }
00172 newData();
00173 for (std::vector<VisCSCPlotWidget*>::iterator it=m_widgets.begin(); it != m_widgets.end(); ++it)
00174 {
00175 (*it)->update();
00176 }
00177
00178 }
00179 void VisCSCStackPlots::show( void )
00180 {
00181 this->QWidget::show();
00182 m_selector->show();
00183 }