CMS 3D CMS Logo

VisCSCStackPlots.cc

Go to the documentation of this file.
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 // could probably do a lot simply in the class, esp if use asymmetric test
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); // accept all by default
00038         
00039         // Create the selector widget
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         /* 3 columns by np+2 rows:
00049 
00050               x | label  |
00051          y-axis | p0     |
00052          y-axis | p1     | spacer
00053          :        :        :
00054          y-axis | pn-1   |
00055                 | x-axis |
00056          
00057          if we decide later to add labels to axis, will increase size
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 ); // insert spacer on right: 10 px
00068         l->setColStretch( 1, 1 );  // default is zero, so only col 1 likes to stretch
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); // do this before adding data
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             // issue warning and reject
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 //      need to sort the digis by strip, then re-assemble in groups of layers and times ticks:
00106 //      final:          layers (6)
00107 //                   +--------------------
00108 //                0  |                    |
00109 //      ticks (8) 1  |                    |    repeated number of strips
00110 //                2  |                    |
00111 
00112         const int n_tick = 8; // 8 time ticks per strip is standard
00113         const int n_layer = 6;
00114         //one bin will have six layer values, a single tick
00115         std::vector<int> dummy6(n_layer,0);
00116         std::vector<int> dummy8(n_tick,0);
00117         
00118         // get block of chamber/layer/ticks and generate a unique index based on chamber+strip
00119         std::map<uint64_t, std::vector<std::vector<int> > > buff;
00120         std::vector< std::vector<int > > dummy68(n_layer, dummy8);      // will use this to initialize 
00121 
00122         // stuff the digis in 
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)) //filter
00126             {
00127                 uint64_t tid = (*i).first.chamberId().rawId(); //chamberId strips off the layer
00128                 tid <<= 32;
00129                 tid |= (*i).second.getStrip();
00130                 if (buff.find(tid) == buff.end()) buff[tid] = dummy68;
00131 //                int i1 = (*i).second.getStrip();
00132 //                int i2 = (*i).first.layer();
00133 //                std::cout << " To buff: strip/layer/tid: " << i1 << " " << i2 << " " << std::hex << tid << std::endl;
00134 //                std::vector<int> i3 = (*i).second.getADCCounts();
00135 //                std::ostream_iterator<int> o(std::cout, " ");
00136 //                std::copy(i3.begin(), i3.end(), o);  
00137 //                std::cout << std::endl;
00138                 buff[tid][(*i).first.layer()-1] = (*i).second.getADCCounts();  // strips are 1-biased
00139              }
00140         }        
00141         // now should be roughly in chamber/strip order. pull data and put in output array.
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                     // transpose and store     
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 //                 std::cout << "Putting point " << iout << std::endl;
00162 //                 std::ostream_iterator<float> oi(std::cout, " ");
00163 //                 std::copy(id.begin(), id.end(), oi);
00164 //                 std::cout << std::endl;
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(); // reset the y-axis, then update the plots
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 }

Generated on Tue Jun 9 17:50:21 2009 for CMSSW by  doxygen 1.5.4