Esempio n. 1
0
void tst_QFontMetrics::same()
{
    QFont font;
    font.setBold(true);
    QFontMetrics fm(font);
    const QString text = QLatin1String("Some stupid STRING");
    QCOMPARE(fm.size(0, text), fm.size(0, text)) ;

    for (int i = 10; i <= 32; ++i) {
        font.setPixelSize(i);
        QFontMetrics fm1(font);
        QCOMPARE(fm1.size(0, text), fm1.size(0, text));
    }

    {
        QImage image;
        QFontMetrics fm2(font, &image);
        QString text2 =  QLatin1String("Foo Foo");
        QCOMPARE(fm2.size(0, text2), fm2.size(0, text2));  //used to crash
    }

    {
        QImage image;
        QFontMetricsF fm3(font, &image);
        QString text2 =  QLatin1String("Foo Foo");
        QCOMPARE(fm3.size(0, text2), fm3.size(0, text2));  //used to crash
    }
}
void
CQPropertyDelegate::
drawFont(QPainter *painter, const QStyleOptionViewItem &option,
         const QFont &f, const QModelIndex &index) const
{
  QItemDelegate::drawBackground(painter, option, index);

  QRect rect = option.rect;

  rect.setWidth(option.rect.height());

  rect.adjust(0, 1, -3, -2);

  QFont f1 = f;
  QFont f2 = painter->font();

  QFontMetrics fm1(f1);
  QFontMetrics fm2(f2);

  int fw = fm1.width("Abc");
  int fh = fm1.height();

  if (fh > rect.height()) {
    f1.setPixelSize(rect.height());

    fm1 = QFontMetrics(f1);

    fw = fm1.width("Abc");
  }

  int x1 = rect.left();
  int y1 = rect.top() + fm1.ascent();

  painter->save();

  painter->setFont(f1);
  painter->setPen(QColor(0,0,0));

  painter->drawText(x1, y1, "Abc");

  painter->restore();

  int x2 = x1 + fw + 4;
//int y2 = rect.top() + fm2.ascent();

  QRect rect1;

  rect1.setCoords(x2, option.rect.top(), option.rect.right(), option.rect.bottom());

//painter->drawText(x2, y2, f.toString());
  QItemDelegate::drawDisplay(painter, option, rect1, f.toString());
}
Esempio n. 3
0
QSize ItemDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const {
  if (!index.isValid()) return QSize();

  QFont normalfont = option.font;
  QFont boldfont = normalfont;
  boldfont.setBold(true);
  // Extract the items we want to measure
  QString firstRow = firstLine(index);
  QString secondRow = secondLine(index);
  // Compute the height
  QFontMetrics fm1(boldfont);
  QFontMetrics fm2(normalfont);
  int height = fm1.lineSpacing() + fm2.lineSpacing();
  height = qMax(height, option.decorationSize.height());
  // Compute the text width
  int width = fm1.width(firstRow);
  width = qMax(width, fm2.width(secondRow));
  // Add decoration width + margin
  width += option.decorationSize.width()+decorationMargin;
  return QSize(width, height+16);
}
void ArtistListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QString artistName = index.data(Qt::DisplayRole).toString();

    QString albumSongCount;
    albumSongCount.append(tr("%n album(s)", "", index.data(UserRoleAlbumCount).toInt()));
    albumSongCount.append(", ");
    albumSongCount.append(tr("%n song(s)", "", index.data(UserRoleSongCount).toInt()));

    painter->save();
    QRect r = option.rect;

    if (option.state & QStyle::State_Selected)
        QStyledItemDelegate::paint(painter, option, QModelIndex());

    QColor secondaryColor = QMaemo5Style::standardColor("SecondaryTextColor");

    painter->drawPixmap(r.right()-70+3, r.top()+3, 64, 64,
                        qvariant_cast<QIcon>(index.data(Qt::DecorationRole)).pixmap(64));

    int textWidth = r.width() - (15+70+15);

    QFont f = painter->font();

    f.setPointSize(18);
    painter->setFont(f);
    QFontMetrics fm1(f);
    artistName = fm1.elidedText(artistName, Qt::ElideRight, textWidth);
    painter->drawText(15, r.top()+5, textWidth, r.height(), Qt::AlignTop|Qt::AlignLeft, artistName);

    r.setBottom(r.bottom()-10);
    f.setPointSize(13);
    painter->setFont(f);
    painter->setPen(QPen(secondaryColor));
    QFontMetrics fm2(f);
    artistName = fm2.elidedText(albumSongCount, Qt::ElideRight, textWidth);
    painter->drawText(15, r.top(), textWidth, r.height(), Qt::AlignBottom|Qt::AlignLeft, albumSongCount);

    painter->restore();
}
Esempio n. 5
0
Int_t main(Int_t argc, Char_t *argv[])
{
   ROOT::Mpi::TEnvironment env(argc, argv);
   ROOT::Mpi::TIntraCommunicator world;
//    MpiInitTest(world, 2, ROOT::Mpi::GreaterIqual);
   TMatrixT<Double_t> mResult;
   TMatrixT<Double_t> m1(rowm1, colm1);
   TMatrixT<Double_t> m2(rowm2, colm2);

   TMatrixT<Double_t> m1square(side, side);
   TMatrixT<Double_t> m2square(side, side);

   for (Int_t i = 0; i < rowm1; i++)
      for (Int_t j = 0; j < colm1; j++)
         m1[i][j] = i + j;

   for (Int_t i = 0; i < rowm2; i++)
      for (Int_t j = 0; j < colm2; j++)
         m2[i][j] = j;

   for (Int_t i = 0; i < side; i++)
      for (Int_t j = 0; j < side; j++) {
         m1square[i][j] = j;
         m2square[i][j] = i;
      }

///////////////////////////////////////////////
//Testing methdos with results in single Rank//
///////////////////////////////////////////////
   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mul(m1);
   mul.Mult(m2, root);

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> add(m1square);
   add.Addition(m2square, root);

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> sub(m1square);
   sub.Subtraction(m2square, root);

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> trans(m2);
   trans.Transpose(root);

   if (world.Rank() == root) {
      mul.GetResult(mResult);
      MpiCompareTMatrixTest(mResult, m1 * m2, world.Rank(), "Matrix Multiplication Single");
      add.GetResult(mResult);
      MpiCompareTMatrixTest(mResult, m1square + m2square, world.Rank(), "Matrix Addition Single");
      sub.GetResult(mResult);
      MpiCompareTMatrixTest(mResult, m1square - m2square, world.Rank(), "Matrix Subtraction Single");
      trans.GetResult(mResult);
      MpiCompareTMatrixTest(mResult, TMatrixT<Double_t>(m2.GetNcols(), m2.GetNrows()).Transpose(m2), world.Rank(), "Matrix Transpose Single");
   }

///////////////////////////////////////////////
//Testing methdos with results in all ranks  //
///////////////////////////////////////////////

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulAll(m1);//return the results in all ranks
   mulAll.Mult(m2);
   mulAll.GetResult(mResult);
   MpiCompareTMatrixTest(mResult, m1 * m2, world.Rank(), "Matrix Multiplication All");

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> addAll(m1square);
   addAll.Addition(m2square);

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> subAll(m1square);
   subAll.Subtraction(m2square);

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> transAll(m2);
   transAll.Transpose();
   addAll.GetResult(mResult);
   MpiCompareTMatrixTest(mResult, m1square + m2square, world.Rank(), "Matrix Addition All");
   subAll.GetResult(mResult);
   MpiCompareTMatrixTest(mResult, m1square - m2square, world.Rank(), "Matrix Subtraction All");
   transAll.GetResult(mResult);
   MpiCompareTMatrixTest(mResult, TMatrixT<Double_t>(m2.GetNcols(), m2.GetNrows()).Transpose(m2), world.Rank(), "Matrix Transpose All");

//////////////////////////////////////////////////
//Testing methdos with multiple matrices types  //
//////////////////////////////////////////////////

   THilbertMatrixT<Double_t> him(side, side);
   TMatrixTSparse<Double_t>  sm1(rowm1, colm1);
   TMatrixTSparse<Double_t>  sm2(rowm2, colm2);
   TMatrixTFlat<Double_t>    fm1(m1);
   TMatrixTFlat<Double_t>    fm2(m2);
   TMatrixTSparse<Double_t>  smResult;

   for (Int_t i = 0; i < rowm1; i++)
      for (Int_t j = 0; j < colm1; j++) {
         sm1[i][j] = i * j;
      }
   for (Int_t i = 0; i < rowm2; i++)
      for (Int_t j = 0; j < colm2; j++) {
         sm2[i][j] = i * j;
      }



   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulHim(m1square);//return the results in all ranks
   mulHim.Mult(him);
   mulHim.GetResult(mResult);
   MpiCompareTMatrixTest(mResult, m1square * TMatrixT<Double_t>(him), world.Rank(), "Matrix Multiplication HilbertMatrix");

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulHim2(him);//return the results in all ranks
   mulHim2.Mult(m1square);
   mulHim2.GetResult(mResult);
   MpiCompareTMatrixTest(mResult, TMatrixT<Double_t>(him)*m1square, world.Rank(), "Matrix Multiplication HilbertMatrix In Constructor");

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulSm(m1);//return the results in all ranks
   mulSm.Mult(sm2);
   mulSm.GetResult(smResult);
   MpiCompareTMatrixTest(smResult, m1 * sm2, world.Rank(), "Matrix Multiplication SparseMatrix");

   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulSm2(sm1);//return the results in all ranks
   mulSm2.Mult(m2);
   mulSm2.GetResult(smResult);
   MpiCompareTMatrixTest(smResult, sm1 * m2, world.Rank(), "Matrix Multiplication SparseMatrix In Constructor");

   //
   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulFm(m1);//return the results in all ranks
   mulFm.Mult(fm2);
   mulFm.GetResult(mResult);
   MpiCompareTMatrixTest(mResult, m1 * TMatrixT<Double_t>(fm2.GetMatrix()->GetNrows(), fm2.GetMatrix()->GetNcols(), fm2.GetMatrix()->GetMatrixArray()), world.Rank(), "Matrix Multiplication FlatMatrix");


   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulFm2(fm1);//return the results in all ranks
   mulFm2.Mult(m2);
   mulFm2.GetResult(mResult);
   //NOTE fm matrix have data from m2, is the same tell m1*m2, just change the representation in memory
   MpiCompareTMatrixTest(mResult, m1 * m2, world.Rank(), "Matrix Multiplication FlatMatrix In Constructor");


   TVectorT<Double_t>        vec(rowv);
   for (Int_t i = 0; i < rowv; i++) vec[i] = i;
   ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulVec(m1);//return the results in all ranks
   mulVec.Mult(vec);
   mulVec.GetResult(mResult);
   TMatrixT<Double_t> mr((m1 * vec).GetNrows(), 1, (m1 * vec).GetMatrixArray());
//    mResult.Print();
//    mr.Print();
   MpiCompareTMatrixTest(mResult, mr, world.Rank(), "Matrix Multiplication with Vector");

   return 0;
}
void UBGraphicsProtractor::paintGraduations(QPainter *painter)
{
    painter->save();

    const int  tenDegreeGraduationLength = 15;
    const int fiveDegreeGraduationLength = 10;
    const int  oneDegreeGraduationLength = 5;

    QFont font1 = painter->font();
#ifdef Q_WS_MAC
    font1.setPointSizeF(font1.pointSizeF() - 3);
#endif
    QFontMetricsF fm1(font1);

    //Font for internal arc
    QFont font2 = painter->font();
    font2.setPointSizeF(font1.pointSizeF()/1.5);
    QFontMetricsF fm2(font2);

    qreal rad = radius();

    QPointF center = rect().center();
    painter->drawArc(QRectF(center.x() - rad/2, center.y() - rad/2, rad, rad), mStartAngle*16, mSpan*16);

    for (int angle = 1; angle < mSpan; angle++)
    {
        int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength);
        qreal co = cos(((qreal)angle + mStartAngle) * PI/180);
        qreal si = sin(((qreal)angle + mStartAngle) * PI/180);
        if (0 == angle % 90)
            painter->drawLine(QLineF(QPointF(center.x(), center.y()), QPointF(center.x() + co*tenDegreeGraduationLength, center.y() - si*tenDegreeGraduationLength)));

        //external arc
        painter->drawLine(QLineF(QPointF(center.x()+ rad*co, center.y() - rad*si),
                                 QPointF(center.x()+ (rad - graduationLength)*co, center.y() - (rad - graduationLength)*si)));
        //internal arc
        painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si),
                                 QPointF(center.x()+ (rad/2 + graduationLength)*co,
                                         center.y() - (rad/2 + graduationLength)*si)));

        if (0 == angle % 10)
        {
            //external arc
            painter->setFont(font1);
            QString grad = QString("%1").arg((int)(angle));
            QString grad2 = QString("%1").arg((int)(mSpan - angle));

            painter->drawText(QRectF(center.x() + (rad - graduationLength*1.5)*co  - fm1.width(grad)/2,
                                     center.y() - (rad - graduationLength*1.5)*si - fm1.height()/2,
                                     fm1.width(grad), fm1.height()), Qt::AlignTop, grad);

            //internal arc
            painter->setFont(font2);
            painter->drawText(QRectF(center.x() + (rad/2 + graduationLength*1.5)*co  - fm2.width(grad2)/2,
                                     center.y() - (rad/2 + graduationLength*1.5)*si - fm2.height()/2,
                                     fm2.width(grad2), fm2.height()), Qt::AlignTop, grad2);
            painter->setFont(font1);

        }
    }

    painter->restore();
}
Esempio n. 7
0
addrbook_entry::addrbook_entry(QWidget* parent, const QString email) :
  QWidget(parent)
{
  m_addr.fetchDetails(email);

  setWindowTitle(QString(tr("Details for %1")).arg(email));
  QVBoxLayout* top_layout = new QVBoxLayout(this);
  top_layout->setMargin (4);

  QWidget* cont = new QWidget();
  top_layout->addWidget(cont);

  int row=0;
  QGridLayout* grid = new QGridLayout(cont);
  //  top_layout->addLayout(grid);

  grid->addWidget(new QLabel(tr("Name:"), cont), row, 0);
  m_qlname = new QLineEdit(cont);
  grid->addWidget(m_qlname, row, 1);
  m_qlname->setText(m_addr.name());
  row++;

  grid->addWidget(new QLabel(tr("Email:"), cont), row, 0);
  m_qlemail = new QLineEdit(cont);
  m_qlemail->setText(email);
  m_qlemail->setReadOnly(true);
  grid->addWidget(m_qlemail, row, 1);
  row++;

  grid->addWidget(new QLabel(tr("Alias:"), cont), row, 0);
  m_qlalias = new QLineEdit(cont);
  m_qlalias->setText(m_addr.nickname());
  grid->addWidget(m_qlalias, row, 1);
  row++;

  grid->addWidget(new QLabel(tr("Priority:"), cont), row, 0);
  //  QHBoxLayout* pri_box = new QHBoxLayout(cont);
  m_prio = new QSpinBox();
  //  pri_box->addWidget(m_prio);
  //  pri_box->setStretchFactor(new Q3HBox(pri_box), 1);
  m_prio->setMinimum(-32768);
  m_prio->setMaximum(32767);
  m_prio->setValue(m_addr.recv_pri());
  grid->addWidget(m_prio, row, 1);
  row++;

  grid->addWidget(new QLabel(tr("Notes:"), cont), row, 0);
  m_notes = new QTextEdit(cont);
  m_notes->setText(m_addr.m_notes);
  grid->addWidget(m_notes, row, 1);
  row++;

  grid->addWidget(new QLabel(tr("Incoming (From):"), cont), row, 0);
  QLineEdit* ql_sent = new QLineEdit(cont);
  ql_sent->setReadOnly(true);
  QString msg_string = QString(tr("%1 email(s)")).arg(m_addr.nb_from());
  if (!m_addr.last_recv().is_null()) {
    msg_string += QString(tr(", last: %1")).arg(m_addr.last_recv().OutputHM(1));
  }
  QFontMetrics fm(ql_sent->font());
  ql_sent->setMinimumWidth(fm.width(msg_string)+15);
  ql_sent->setText(msg_string);
  grid->addWidget(ql_sent, row, 1);
  row++;

  grid->addWidget(new QLabel(tr("Outgoing (To):"), cont), row, 0);
  QLineEdit* ql_sent1 = new QLineEdit(cont);
  ql_sent1->setReadOnly(true);
  msg_string = QString(tr("%1 email(s)")).arg(m_addr.nb_to());
  if (!m_addr.last_sent().is_null()) {
    msg_string += QString(tr(", last: %1")).arg(m_addr.last_sent().OutputHM(1));
  }
  QFontMetrics fm1(ql_sent1->font());
  ql_sent1->setMinimumWidth(fm1.width(msg_string)+15);
  ql_sent1->setText(msg_string);
  grid->addWidget(ql_sent1, row, 1);
  row++;

  QHBoxLayout* hbl = new QHBoxLayout();
  top_layout->addLayout(hbl);
  hbl->setSpacing(20);
  hbl->setMargin(20);
  QPushButton* btn_ok = new QPushButton(tr("OK"), this);
  QPushButton* btn_cancel = new QPushButton(tr("Cancel"), this);
  connect(btn_ok, SIGNAL(clicked()), this, SLOT(ok()));
  connect(btn_cancel, SIGNAL(clicked()), this, SLOT(cancel()));
  //  hbl->addStretch(1);
  hbl->addWidget(btn_ok);
  hbl->addWidget(btn_cancel);
  //  hbl->addStretch(1);
}
Esempio n. 8
0
int main() try 
{
    // Several ways to create and initialize band matrices:

    // Create with uninitialized values
    tmv::BandMatrix<double> m1(6,6,1,2);
    for(int i=0;i<m1.nrows();i++) 
        for(int j=0;j<m1.ncols();j++) 
            if (i<=j+m1.nlo() && j<=i+m1.nhi())
                m1(i,j) = 3.*i-j*j+7.; 
    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )

    // Create with all 2's.
    tmv::BandMatrix<double> m2(6,6,1,3,2.);
    std::cout<<"m2 =\n"<<m2;
    //! m2 =
    //! 6  6  
    //! ( 2  2  2  2  0  0 )
    //! ( 2  2  2  2  2  0 )
    //! ( 0  2  2  2  2  2 )
    //! ( 0  0  2  2  2  2 )
    //! ( 0  0  0  2  2  2 )
    //! ( 0  0  0  0  2  2 )

    // A BandMatrix can be non-square:
    tmv::BandMatrix<double> m3(6,8,1,3,2.);
    std::cout<<"m3 =\n"<<m3;
    //! m3 =
    //! 6  8  
    //! ( 2  2  2  2  0  0  0  0 )
    //! ( 2  2  2  2  2  0  0  0 )
    //! ( 0  2  2  2  2  2  0  0 )
    //! ( 0  0  2  2  2  2  2  0 )
    //! ( 0  0  0  2  2  2  2  2 )
    //! ( 0  0  0  0  2  2  2  2 )

    // Create from given elements:
    double mm[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    tmv::BandMatrix<double,tmv::ColMajor> m4(6,6,2,1);
    std::copy(mm,mm+20,m4.colmajor_begin());
    std::cout<<"m4 (ColMajor) =\n"<<m4;
    //! m4 (ColMajor) =
    //! 6  6  
    //! ( 1  4  0  0  0  0 )
    //! ( 2  5  8  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  7  10  13  16  0 )
    //! ( 0  0  11  14  17  19 )
    //! ( 0  0  0  15  18  20 )
    tmv::BandMatrix<double,tmv::RowMajor> m5(6,6,2,1);
    std::copy(mm,mm+20,m5.rowmajor_begin());
    std::cout<<"m5 (RowMajor) =\n"<<m5;
    //! m5 (RowMajor) =
    //! 6  6  
    //! ( 1  2  0  0  0  0 )
    //! ( 3  4  5  0  0  0 )
    //! ( 6  7  8  9  0  0 )
    //! ( 0  10  11  12  13  0 )
    //! ( 0  0  14  15  16  17 )
    //! ( 0  0  0  18  19  20 )
    tmv::BandMatrix<double,tmv::DiagMajor> m6(6,6,2,1);
    std::copy(mm,mm+20,m6.diagmajor_begin());
    std::cout<<"m6 (DiagMajor) =\n"<<m6;
    //! m6 (DiagMajor) =
    //! 6  6  
    //! ( 10  16  0  0  0  0 )
    //! ( 5  11  17  0  0  0 )
    //! ( 1  6  12  18  0  0 )
    //! ( 0  2  7  13  19  0 )
    //! ( 0  0  3  8  14  20 )
    //! ( 0  0  0  4  9  15 )

    // Can make from the banded portion of a regular Matrix:
    tmv::Matrix<double> xm(6,6);
    for(int i=0;i<xm.nrows();i++) 
        for(int j=0;j<xm.ncols();j++) 
            xm(i,j) = 5.*i-j*j+3.; 
    tmv::BandMatrix<double> m7(xm,3,2);
    std::cout<<"m7 =\n"<<m7;
    //! m7 =
    //! 6  6  
    //! ( 3  2  -1  0  0  0 )
    //! ( 8  7  4  -1  0  0 )
    //! ( 13  12  9  4  -3  0 )
    //! ( 18  17  14  9  2  -7 )
    //! ( 0  22  19  14  7  -2 )
    //! ( 0  0  24  19  12  3 )
    // Or from a wider BandMatrix:
    tmv::BandMatrix<double> m8(m7,3,0);
    std::cout<<"m8 =\n"<<m8;
    //! m8 =
    //! 6  6  
    //! ( 3  0  0  0  0  0 )
    //! ( 8  7  0  0  0  0 )
    //! ( 13  12  9  0  0  0 )
    //! ( 18  17  14  9  0  0 )
    //! ( 0  22  19  14  7  0 )
    //! ( 0  0  24  19  12  3 )

    // Shortcuts to Bi- and Tri-diagonal matrices:
    tmv::Vector<double> v1(5,1.);
    tmv::Vector<double> v2(6,2.);
    tmv::Vector<double> v3(5,3.);
    tmv::BandMatrix<double> m9 = LowerBiDiagMatrix(v1,v2);
    tmv::BandMatrix<double> m10 = UpperBiDiagMatrix(v2,v3);
    tmv::BandMatrix<double> m11 = TriDiagMatrix(v1,v2,v3);
    std::cout<<"LowerBiDiagMatrix(v1,v2) =\n"<<m9;
    //! LowerBiDiagMatrix(v1,v2) =
    //! 6  6  
    //! ( 2  0  0  0  0  0 )
    //! ( 1  2  0  0  0  0 )
    //! ( 0  1  2  0  0  0 )
    //! ( 0  0  1  2  0  0 )
    //! ( 0  0  0  1  2  0 )
    //! ( 0  0  0  0  1  2 )
    std::cout<<"UpperBiDiagMatrix(v2,v3) =\n"<<m10;
    //! UpperBiDiagMatrix(v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 0  2  3  0  0  0 )
    //! ( 0  0  2  3  0  0 )
    //! ( 0  0  0  2  3  0 )
    //! ( 0  0  0  0  2  3 )
    //! ( 0  0  0  0  0  2 )
    std::cout<<"TriDiagMatrix(v1,v2,v3) =\n"<<m11;
    //! TriDiagMatrix(v1,v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 1  2  3  0  0  0 )
    //! ( 0  1  2  3  0  0 )
    //! ( 0  0  1  2  3  0 )
    //! ( 0  0  0  1  2  3 )
    //! ( 0  0  0  0  1  2 )


    // Norms, etc. 

    std::cout<<"Norm1(m1) = "<<Norm1(m1)<<std::endl;
    //! Norm1(m1) = 30
    std::cout<<"Norm2(m1) = "<<Norm2(m1)<<std::endl;
    //! Norm2(m1) = 24.0314
    std::cout<<"NormInf(m1) = "<<NormInf(m1)<<std::endl;
    //! NormInf(m1) = 28
    std::cout<<"NormF(m1) = "<<NormF(m1)<<" = "<<Norm(m1)<<std::endl;
    //! NormF(m1) = 32.0312 = 32.0312
    std::cout<<"MaxAbsElement(m1) = "<<MaxAbsElement(m1)<<std::endl;
    //! MaxAbsElement(m1) = 12
    std::cout<<"Trace(m1) = "<<Trace(m1)<<std::endl;
    //! Trace(m1) = 32
    std::cout<<"Det(m1) = "<<Det(m1)<<std::endl;
    //! Det(m1) = 67635


    // Views:

    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"m1.diag() = "<<m1.diag()<<std::endl;
    //! m1.diag() = 6  ( 7  9  9  7  3  -3 )
    std::cout<<"m1.diag(1) = "<<m1.diag(1)<<std::endl;
    //! m1.diag(1) = 5  ( 6  6  4  0  -6 )
    std::cout<<"m1.diag(-1) = "<<m1.diag(-1)<<std::endl;
    //! m1.diag(-1) = 5  ( 10  12  12  10  6 )
    std::cout<<"m1.subBandMatrix(0,3,0,3,1,1) =\n"<<
        m1.subBandMatrix(0,3,0,3,1,1);
    //! m1.subBandMatrix(0,3,0,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"m1.transpose() =\n"<<m1.transpose();
    //! m1.transpose() =
    //! 6  6  
    //! ( 7  10  0  0  0  0 )
    //! ( 6  9  12  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  1  4  7  10  0 )
    //! ( 0  0  -3  0  3  6 )
    //! ( 0  0  0  -9  -6  -3 )

    // rowRange, colRange shrink both dimensions of the matrix to include only
    // the portions that are in those rows or columns:
    std::cout<<"m1.rowRange(0,4) =\n"<<m1.rowRange(0,4);
    //! m1.rowRange(0,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"m1.colRange(1,4) =\n"<<m1.colRange(1,4);
    //! m1.colRange(1,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"m1.diagRange(0,2) =\n"<<m1.diagRange(0,2);
    //! m1.diagRange(0,2) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"m1.diagRange(-1,1) =\n"<<m1.diagRange(-1,1);
    //! m1.diagRange(-1,1) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Fortran Indexing:

    tmv::BandMatrix<double,tmv::FortranStyle> fm1 = m1;
    std::cout<<"fm1 = m1 =\n"<<fm1;
    //! fm1 = m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"fm1(1,1) = "<<fm1(1,1)<<std::endl;
    //! fm1(1,1) = 7
    std::cout<<"fm1(4,3) = "<<fm1(4,3)<<std::endl;
    //! fm1(4,3) = 12
    std::cout<<"fm1.subBandMatrix(1,3,1,3,1,1) =\n"<<
        fm1.subBandMatrix(1,3,1,3,1,1);
    //! fm1.subBandMatrix(1,3,1,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"fm1.rowRange(1,4) =\n"<<fm1.rowRange(1,4);
    //! fm1.rowRange(1,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"fm1.colRange(2,4) =\n"<<fm1.colRange(2,4);
    //! fm1.colRange(2,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"fm1.diagRange(0,1) =\n"<<fm1.diagRange(0,1);
    //! fm1.diagRange(0,1) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"fm1.diagRange(-1,0) =\n"<<fm1.diagRange(-1,0);
    //! fm1.diagRange(-1,0) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Matrix arithmetic:

    tmv::BandMatrix<double> m1pm2 = m1 + m2;
    std::cout<<"m1 + m2 =\n"<<m1pm2;
    //! m1 + m2 =
    //! 6  6  
    //! ( 9  8  5  2  0  0 )
    //! ( 12  11  8  3  2  0 )
    //! ( 0  14  11  6  -1  2 )
    //! ( 0  0  14  9  2  -7 )
    //! ( 0  0  0  12  5  -4 )
    //! ( 0  0  0  0  8  -1 )
    // Works correctly even if matrices are stored in different order:
    tmv::BandMatrix<double> m5pm6 = m5 + m6; 
    std::cout<<"m5 + m6 =\n"<<m5pm6;
    //! m5 + m6 =
    //! 6  6  
    //! ( 11  18  0  0  0  0 )
    //! ( 8  15  22  0  0  0 )
    //! ( 7  13  20  27  0  0 )
    //! ( 0  12  18  25  32  0 )
    //! ( 0  0  17  23  30  37 )
    //! ( 0  0  0  22  28  35 )
    // Also expands the number of off-diagonals appropriately as needed:
    tmv::BandMatrix<double> m2pm4 = m2 + m4; 
    std::cout<<"m2 + m4 =\n"<<m2pm4;
    //! m2 + m4 =
    //! 6  6  
    //! ( 3  6  2  2  0  0 )
    //! ( 4  7  10  2  2  0 )
    //! ( 3  8  11  14  2  2 )
    //! ( 0  7  12  15  18  2 )
    //! ( 0  0  11  16  19  21 )
    //! ( 0  0  0  15  20  22 )

    m1 *= 2.;
    std::cout<<"m1 *= 2 =\n"<<m1;
    //! m1 *= 2 =
    //! 6  6  
    //! ( 14  12  6  0  0  0 )
    //! ( 20  18  12  2  0  0 )
    //! ( 0  24  18  8  -6  0 )
    //! ( 0  0  24  14  0  -18 )
    //! ( 0  0  0  20  6  -12 )
    //! ( 0  0  0  0  12  -6 )

    m2 += m1;
    std::cout<<"m2 += m1 =\n"<<m2;
    //! m2 += m1 =
    //! 6  6  
    //! ( 16  14  8  2  0  0 )
    //! ( 22  20  14  4  2  0 )
    //! ( 0  26  20  10  -4  2 )
    //! ( 0  0  26  16  2  -16 )
    //! ( 0  0  0  22  8  -10 )
    //! ( 0  0  0  0  14  -4 )

    tmv::Vector<double> v = xm.col(0);
    std::cout<<"v = "<<v<<std::endl;
    //! v = 6  ( 3  8  13  18  23  28 )
    std::cout<<"m1 * v = "<<m1*v<<std::endl;
    //! m1 * v = 6  ( 216  396  432  60  162  108 )
    std::cout<<"v * m1 = "<<v*m1<<std::endl;
    //! v * m1 = 6  ( 202  492  780  832  396  -768 )

    // Matrix * matrix product also expands bands appropriately:
    tmv::BandMatrix<double> m1m2 = m1 * m2; 
    std::cout<<"m1 * m2 =\n"<<m1m2;
    //! m1 * m2 =
    //! 6  6  
    //! ( 488  592  400  136  0  12 )
    //! ( 716  952  704  264  -8  -8 )
    //! ( 528  948  904  272  -56  -32 )
    //! ( 0  624  844  464  -320  -104 )
    //! ( 0  0  520  452  -80  -332 )
    //! ( 0  0  0  264  12  -96 )

    // Can mix BandMatrix with other kinds of matrices:
    std::cout<<"xm * m1 =\n"<<xm*m1;
    //! xm * m1 =
    //! 6  6  
    //! ( 82  48  -120  -348  -336  396 )
    //! ( 252  318  180  -128  -276  216 )
    //! ( 422  588  480  92  -216  36 )
    //! ( 592  858  780  312  -156  -144 )
    //! ( 762  1128  1080  532  -96  -324 )
    //! ( 932  1398  1380  752  -36  -504 )
    tmv::UpperTriMatrix<double> um(xm);
    std::cout<<"um + m1 =\n"<<um+m1;
    //! um + m1 =
    //! 6  6  
    //! ( 17  14  5  -6  -13  -22 )
    //! ( 20  25  16  1  -8  -17 )
    //! ( 0  24  27  12  -9  -12 )
    //! ( 0  0  24  23  2  -25 )
    //! ( 0  0  0  20  13  -14 )
    //! ( 0  0  0  0  12  -3 )
    tmv::LowerTriMatrix<double> lm(xm);
    lm *= m8;
    std::cout<<"lm *= m8 =\n"<<lm;
    //! lm *= m8 =
    //! 6  6  
    //! ( 9  0  0  0  0  0 )
    //! ( 80  49  0  0  0  0 )
    //! ( 252  192  81  0  0  0 )
    //! ( 534  440  252  81  0  0 )
    //! ( 744  774  500  224  49  0 )
    //! ( 954  1064  782  396  120  9 )
    tmv::DiagMatrix<double> dm(xm);
    m1 *= dm;
    std::cout<<"m1 *= dm =\n"<<m1;
    //! m1 *= dm =
    //! 6  6  
    //! ( 42  84  54  0  0  0 )
    //! ( 60  126  108  18  0  0 )
    //! ( 0  168  162  72  -42  0 )
    //! ( 0  0  216  126  0  -54 )
    //! ( 0  0  0  180  42  -36 )
    //! ( 0  0  0  0  84  -18 )
    return 0;
} catch (tmv::Error& e) {
    std::cerr<<e<<std::endl;
    return 1;
}
Esempio n. 9
0
Arranger::Arranger(ArrangerView* parent, const char* name)
   : QWidget(parent)
      {
      setObjectName(name);
      _raster  = 0;      // measure
      selected = 0;
      showTrackinfoFlag = true;
      
      cursVal = INT_MAX;
      
      _parentWin=parent;
      
      setFocusPolicy(Qt::NoFocus);
      
      //---------------------------------------------------
      //  ToolBar
      //    create toolbar in toplevel widget
      //---------------------------------------------------

      parent->addToolBarBreak();
      QToolBar* toolbar = parent->addToolBar(tr("Arranger"));
      toolbar->setObjectName("ArrangerToolbar");
      
      QLabel* label = new QLabel(tr("Cursor"));
      label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
      label->setIndent(3);
      toolbar->addWidget(label);
      cursorPos = new PosLabel(0);
      cursorPos->setEnabled(false);
      cursorPos->setFixedHeight(22);
      toolbar->addWidget(cursorPos);

      label = new QLabel(tr("Snap"));
      label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
      label->setIndent(3);
      toolbar->addWidget(label);
      _rasterCombo = new QComboBox();
      for (int i = 0; i < 6; i++)
            _rasterCombo->insertItem(i, tr(gArrangerRasterStrings[i]), gArrangerRasterTable[i]);
      _rasterCombo->setCurrentIndex(1);
      // Set the audio record part snapping. Set to 0 (bar), the same as this combo box intial raster.
      MusEGlobal::song->setArrangerRaster(0);
      toolbar->addWidget(_rasterCombo);
      connect(_rasterCombo, SIGNAL(activated(int)), SLOT(rasterChanged(int)));
      _rasterCombo->setFocusPolicy(Qt::TabFocus);

      // Song len
      label = new QLabel(tr("Len"));
      label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
      label->setIndent(3);
      toolbar->addWidget(label);

      // song length is limited to 10000 bars; the real song len is limited
      // by overflows in tick computations
      lenEntry = new SpinBox(1, 10000, 1);
      lenEntry->setFocusPolicy(Qt::StrongFocus);
      lenEntry->setValue(MusEGlobal::song->len());
      lenEntry->setToolTip(tr("song length - bars"));
      lenEntry->setWhatsThis(tr("song length - bars"));
      toolbar->addWidget(lenEntry);
      connect(lenEntry, SIGNAL(valueChanged(int)), SLOT(songlenChanged(int)));

      label = new QLabel(tr("Pitch"));
      label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
      label->setIndent(3);
      toolbar->addWidget(label);
      
      globalPitchSpinBox = new SpinBox(-127, 127, 1);
      globalPitchSpinBox->setFocusPolicy(Qt::StrongFocus);
      globalPitchSpinBox->setValue(MusEGlobal::song->globalPitchShift());
      globalPitchSpinBox->setToolTip(tr("midi pitch"));
      globalPitchSpinBox->setWhatsThis(tr("global midi pitch shift"));
      toolbar->addWidget(globalPitchSpinBox);
      connect(globalPitchSpinBox, SIGNAL(valueChanged(int)), SLOT(globalPitchChanged(int)));
      
      label = new QLabel(tr("Tempo"));
      label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
      label->setIndent(3);
      toolbar->addWidget(label);
      
      globalTempoSpinBox = new SpinBox(50, 200, 1, toolbar);
      globalTempoSpinBox->setFocusPolicy(Qt::StrongFocus);
      globalTempoSpinBox->setSuffix(QString("%"));
      globalTempoSpinBox->setValue(MusEGlobal::tempomap.globalTempo());
      globalTempoSpinBox->setToolTip(tr("midi tempo"));
      globalTempoSpinBox->setWhatsThis(tr("midi tempo"));
      toolbar->addWidget(globalTempoSpinBox);
      connect(globalTempoSpinBox, SIGNAL(valueChanged(int)), SLOT(globalTempoChanged(int)));
      
      QToolButton* tempo50  = new QToolButton();
      tempo50->setText(QString("50%"));
      tempo50->setFocusPolicy(Qt::NoFocus);
      toolbar->addWidget(tempo50);
      connect(tempo50, SIGNAL(clicked()), SLOT(setTempo50()));
      
      QToolButton* tempo100 = new QToolButton();
      tempo100->setText(tr("N"));
      tempo100->setFocusPolicy(Qt::NoFocus);
      toolbar->addWidget(tempo100);
      connect(tempo100, SIGNAL(clicked()), SLOT(setTempo100()));
      
      QToolButton* tempo200 = new QToolButton();
      tempo200->setText(QString("200%"));
      tempo200->setFocusPolicy(Qt::NoFocus);
      toolbar->addWidget(tempo200);
      connect(tempo200, SIGNAL(clicked()), SLOT(setTempo200()));

      QVBoxLayout* box  = new QVBoxLayout(this);
      box->setContentsMargins(0, 0, 0, 0);
      box->setSpacing(0);
      box->addWidget(MusECore::hLine(this), Qt::AlignTop);

      //---------------------------------------------------
      //  Tracklist
      //---------------------------------------------------

      int xscale = -100;
      int yscale = 1;

      split  = new Splitter(Qt::Horizontal, this, "split");
      split->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
      box->addWidget(split, 1000);

      tracklist = new QWidget(split);

      split->setStretchFactor(split->indexOf(tracklist), 0);
      QSizePolicy tpolicy = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
      tpolicy.setHorizontalStretch(0);
      tpolicy.setVerticalStretch(100);
      tracklist->setSizePolicy(tpolicy);

      editor = new QWidget(split);
      split->setStretchFactor(split->indexOf(editor), 1);
      QSizePolicy epolicy = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
      epolicy.setHorizontalStretch(255);
      epolicy.setVerticalStretch(100);
      editor->setSizePolicy(epolicy);

      //---------------------------------------------------
      //    Track Info
      //---------------------------------------------------

      infoScroll = new ScrollBar(Qt::Vertical, true, tracklist);
      infoScroll->setObjectName("infoScrollBar");
      //genTrackInfo(tracklist); // Moved below

      // Track-Info Button
      ib  = new QToolButton(tracklist);
      ib->setText(tr("TrackInfo"));
      ib->setCheckable(true);
      ib->setChecked(showTrackinfoFlag);
      ib->setFocusPolicy(Qt::NoFocus);
      connect(ib, SIGNAL(toggled(bool)), SLOT(showTrackInfo(bool)));
      
      // set up the header
      header = new Header(tracklist, "header");
      header->setFixedHeight(30);

      QFontMetrics fm1(header->font());
      int fw = 11;

      header->setColumnLabel(tr("R"), COL_RECORD, fm1.width('R')+fw);
      header->setColumnLabel(tr("M"), COL_MUTE, fm1.width('M')+fw);
      header->setColumnLabel(tr("S"), COL_SOLO, fm1.width('S')+fw);
      header->setColumnLabel(tr("C"), COL_CLASS, fm1.width('C')+fw);
      header->setColumnLabel(tr("Track"), COL_NAME, 100);
      header->setColumnLabel(tr("Port"), COL_OPORT, 60);
      header->setColumnLabel(tr("Ch"), COL_OCHANNEL, 30);
      header->setColumnLabel(tr("T"), COL_TIMELOCK, fm1.width('T')+fw);
      header->setColumnLabel(tr("Automation"), COL_AUTOMATION, 75);
      header->setColumnLabel(tr("Clef"), COL_CLEF, 75);
      for (unsigned i=0;i<custom_columns.size();i++)
        header->setColumnLabel(custom_columns[i].name, COL_CUSTOM_MIDICTRL_OFFSET+i, MAX(fm1.width(custom_columns[i].name)+fw, 30));
      header->setSectionResizeMode(COL_RECORD, QHeaderView::Fixed);
      header->setSectionResizeMode(COL_MUTE, QHeaderView::Fixed);
      header->setSectionResizeMode(COL_SOLO, QHeaderView::Fixed);
      header->setSectionResizeMode(COL_CLASS, QHeaderView::Fixed);
      header->setSectionResizeMode(COL_NAME, QHeaderView::Interactive);
      header->setSectionResizeMode(COL_OPORT, QHeaderView::Interactive);
      header->setSectionResizeMode(COL_OCHANNEL, QHeaderView::Fixed);
      header->setSectionResizeMode(COL_TIMELOCK, QHeaderView::Fixed);
      header->setSectionResizeMode(COL_AUTOMATION, QHeaderView::Interactive);
      header->setSectionResizeMode(COL_CLEF, QHeaderView::Interactive);
      for (unsigned i=0;i<custom_columns.size();i++)
        header->setSectionResizeMode(COL_CUSTOM_MIDICTRL_OFFSET+i, QHeaderView::Interactive);

      setHeaderToolTips();
      setHeaderWhatsThis();
      header->setSectionsMovable (true);
      header->restoreState(header_state);

      list = new TList(header, tracklist, "tracklist");
      
      // Do this now that the list is available.
      genTrackInfo(tracklist);
      
      connect(list, SIGNAL(selectionChanged(MusECore::Track*)), SLOT(trackSelectionChanged()));
      connect(list, SIGNAL(selectionChanged(MusECore::Track*)), SIGNAL(selectionChanged()));
      connect(list, SIGNAL(selectionChanged(MusECore::Track*)), midiTrackInfo, SLOT(setTrack(MusECore::Track*)));
      connect(header, SIGNAL(sectionResized(int,int,int)), list, SLOT(redraw()));
      connect(header, SIGNAL(sectionMoved(int,int,int)), list, SLOT(redraw()));

      //  tracklist:
      //
      //         0         1         2
      //   +-----------+--------+---------+
      //   | Trackinfo | scroll | Header  | 0
      //   |           | bar    +---------+
      //   |           |        | TList   | 1
      //   +-----------+--------+---------+
      //   |             hline            | 2
      //   +-----+------------------------+
      //   | ib  |                        | 3
      //   +-----+------------------------+

      connect(infoScroll, SIGNAL(valueChanged(int)), SLOT(trackInfoScroll(int)));
      tgrid  = new TLLayout(tracklist); // layout manager for this
      tgrid->wadd(0, trackInfo);
      tgrid->wadd(1, infoScroll);
      tgrid->wadd(2, header);
      tgrid->wadd(3, list);
      tgrid->wadd(4, MusECore::hLine(tracklist));
      tgrid->wadd(5, ib);

      //---------------------------------------------------
      //    Editor
      //---------------------------------------------------

      int offset = AL::sigmap.ticksMeasure(0);
      hscroll = new ScrollScale(-2000, -5, xscale, MusEGlobal::song->len(), Qt::Horizontal, editor, -offset);
      hscroll->setFocusPolicy(Qt::NoFocus);
      ib->setFixedHeight(hscroll->sizeHint().height());

      vscroll = new QScrollBar(editor);
      vscroll->setMinimum(0);
      vscroll->setMaximum(20*20);
      vscroll->setSingleStep(5);
      vscroll->setPageStep(25); // FIXME: too small steps here for me (flo), better control via window height?
      vscroll->setValue(0);
      vscroll->setOrientation(Qt::Vertical);      

      list->setScroll(vscroll);

      QList<int> vallist;
      vallist.append(tgrid->maximumSize().width());
      split->setSizes(vallist);

      QGridLayout* egrid  = new QGridLayout(editor);
      egrid->setColumnStretch(0, 50);
      egrid->setRowStretch(2, 50);
      egrid->setContentsMargins(0, 0, 0, 0);  
      egrid->setSpacing(0);  

      time = new MTScale(&_raster, editor, xscale);
      time->setOrigin(-offset, 0);
      canvas = new PartCanvas(&_raster, editor, xscale, yscale);
      canvas->setBg(MusEGlobal::config.partCanvasBg);
      canvas->setCanvasTools(arrangerTools);
      canvas->setOrigin(-offset, 0);
      canvas->setFocus();

      list->setFocusProxy(canvas); // Make it easy for track list popup line editor to give focus back to canvas.

      connect(canvas, SIGNAL(setUsedTool(int)), this, SIGNAL(setUsedTool(int)));
      connect(canvas, SIGNAL(trackChanged(MusECore::Track*)), list, SLOT(selectTrack(MusECore::Track*)));
      connect(list, SIGNAL(keyPressExt(QKeyEvent*)), canvas, SLOT(redirKeypress(QKeyEvent*)));
      connect(canvas, SIGNAL(selectTrackAbove()), list, SLOT(selectTrackAbove()));
      connect(canvas, SIGNAL(selectTrackBelow()), list, SLOT(selectTrackBelow()));
      connect(canvas, SIGNAL(editTrackNameSig()), list, SLOT(editTrackNameSlot()));

      connect(canvas, SIGNAL(muteSelectedTracks()), list, SLOT(muteSelectedTracksSlot()));
      connect(canvas, SIGNAL(soloSelectedTracks()), list, SLOT(soloSelectedTracksSlot()));

      connect(canvas, SIGNAL(horizontalZoom(bool, const QPoint&)), SLOT(horizontalZoom(bool, const QPoint&)));
      connect(canvas, SIGNAL(horizontalZoom(int, const QPoint&)), SLOT(horizontalZoom(int, const QPoint&)));
      connect(lenEntry,           SIGNAL(returnPressed()), SLOT(focusCanvas()));
      connect(lenEntry,           SIGNAL(escapePressed()), SLOT(focusCanvas()));
      connect(globalPitchSpinBox, SIGNAL(returnPressed()), SLOT(focusCanvas()));
      connect(globalPitchSpinBox, SIGNAL(escapePressed()), SLOT(focusCanvas()));
      connect(globalTempoSpinBox, SIGNAL(returnPressed()), SLOT(focusCanvas()));
      connect(globalTempoSpinBox, SIGNAL(escapePressed()), SLOT(focusCanvas()));
      connect(midiTrackInfo,      SIGNAL(returnPressed()), SLOT(focusCanvas()));
      connect(midiTrackInfo,      SIGNAL(escapePressed()), SLOT(focusCanvas()));
      
      //connect(this,      SIGNAL(redirectWheelEvent(QWheelEvent*)), canvas, SLOT(redirectedWheelEvent(QWheelEvent*)));
      connect(list,      SIGNAL(redirectWheelEvent(QWheelEvent*)), canvas, SLOT(redirectedWheelEvent(QWheelEvent*)));
      connect(trackInfo, SIGNAL(redirectWheelEvent(QWheelEvent*)), infoScroll, SLOT(redirectedWheelEvent(QWheelEvent*)));
      
      egrid->addWidget(time, 0, 0, 1, 2);
      egrid->addWidget(MusECore::hLine(editor), 1, 0, 1, 2);

      egrid->addWidget(canvas,  2, 0);
      egrid->addWidget(vscroll, 2, 1);
      egrid->addWidget(hscroll, 3, 0, Qt::AlignBottom);

      connect(vscroll, SIGNAL(valueChanged(int)), canvas, SLOT(setYPos(int)));
      connect(hscroll, SIGNAL(scrollChanged(int)), canvas, SLOT(setXPos(int)));
      connect(hscroll, SIGNAL(scaleChanged(int)),  canvas, SLOT(setXMag(int)));
      connect(vscroll, SIGNAL(valueChanged(int)), list,   SLOT(setYPos(int)));
      connect(hscroll, SIGNAL(scrollChanged(int)), time,   SLOT(setXPos(int)));
      connect(hscroll, SIGNAL(scaleChanged(int)),  time,   SLOT(setXMag(int)));
      connect(canvas,  SIGNAL(timeChanged(unsigned)),   SLOT(setTime(unsigned)));
      connect(canvas,  SIGNAL(verticalScroll(unsigned)),SLOT(verticalScrollSetYpos(unsigned)));
      connect(canvas,  SIGNAL(horizontalScroll(unsigned)),hscroll, SLOT(setPos(unsigned)));
      connect(canvas,  SIGNAL(horizontalScrollNoLimit(unsigned)),hscroll, SLOT(setPosNoLimit(unsigned))); 
      connect(time,    SIGNAL(timeChanged(unsigned)),   SLOT(setTime(unsigned)));

      connect(list, SIGNAL(verticalScrollSetYpos(int)), vscroll, SLOT(setValue(int)));

      connect(canvas, SIGNAL(tracklistChanged()), list, SLOT(tracklistChanged()));
      connect(canvas, SIGNAL(dclickPart(MusECore::Track*)), SIGNAL(editPart(MusECore::Track*)));
      connect(canvas, SIGNAL(startEditor(MusECore::PartList*,int)),   SIGNAL(startEditor(MusECore::PartList*, int)));

      connect(MusEGlobal::song,   SIGNAL(songChanged(MusECore::SongChangedFlags_t)), SLOT(songChanged(MusECore::SongChangedFlags_t)));
      connect(canvas, SIGNAL(followEvent(int)), hscroll, SLOT(setOffset(int)));
      connect(canvas, SIGNAL(selectionChanged()), SIGNAL(selectionChanged()));
      connect(canvas, SIGNAL(dropSongFile(const QString&)), SIGNAL(dropSongFile(const QString&)));
      connect(canvas, SIGNAL(dropMidiFile(const QString&)), SIGNAL(dropMidiFile(const QString&)));

      connect(canvas, SIGNAL(toolChanged(int)), SIGNAL(toolChanged(int)));
      connect(MusEGlobal::song,   SIGNAL(controllerChanged(MusECore::Track*, int)), SLOT(controllerChanged(MusECore::Track*, int)));

      configChanged();  // set configuration values
      if(canvas->part())
        midiTrackInfo->setTrack(canvas->part()->track());   
      showTrackInfo(showTrackinfoFlag);
      
      // Take care of some tabbies!
      setTabOrder(tempo200, trackInfo);
      setTabOrder(trackInfo, infoScroll);
      setTabOrder(infoScroll, list);
      setTabOrder(list, canvas);
      //setTabOrder(canvas, ib);
      //setTabOrder(ib, hscroll);
      }
Esempio n. 10
0
void BehavePlusApp::drawSplashPage( void )
{
    // If unable to load the picture, make a plain cyan backdrop instead
    if ( m_pixmap.isNull() )
    // This code block should never be executed!
    {
        m_pixmap.resize( 700, 500 );
        QPainter paint( &m_pixmap );
        paint.fillRect( 0, 0, 700, 500, QBrush( "cyan", SolidPattern ) );
        paint.end();
    }

    // Painter attributes
    int align = Qt::AlignHCenter | Qt::AlignTop ;
    //static QString fontName( "Times New Roman" );
    static QString fontName( "Arial" );
    QFont fnt1( fontName, 48, QFont::Bold, false );
    QFont fnt2( fontName, 24, QFont::Bold, false );
    QFont fnt3( fontName, 16, QFont::Bold, false );
    QFontMetrics fm1( fnt1 );
    QFontMetrics fm2( fnt2 );
    QFontMetrics fm3( fnt3 );
    QPen blackPen( black );
    QPen grayPen( gray );
    QPen redPen( red );
    QPen whitePen( white );

    // Draw shadowed name
    QPainter paint( &m_pixmap );
    int wd = m_pixmap.width();
    int ht = m_pixmap.height() + 3 * fm3.lineSpacing();
    paint.setFont( fnt1 );
    paint.setPen( grayPen );
    int y0 = fm1.lineSpacing()/8;
    paint.drawText( 4, y0+4, wd, ht, align, m_program );
    paint.setPen( blackPen );
    paint.drawText( 2, y0+2, wd, ht, align, m_program );
    paint.setPen( whitePen );
    paint.drawText( 0, y0,   wd, ht, align, m_program );

    // Draw sub name and version
    y0 += 3*fm1.lineSpacing()/4;
    paint.setFont( fnt2 );
    paint.drawText( 0, y0, wd, ht-y0, align, "fire modeling system" );
    y0 += 3*fm2.lineSpacing()/4;
    paint.drawText( 0, y0, wd, ht-y0, align, "Version " + m_version );

    // Warning
    if ( ShowWarning )
    {
        y0 += 3 * fm2.lineSpacing();
        paint.setFont( fnt2 );
        paint.setPen( redPen );
        paint.drawText( 0, y0, wd, ht-y0, align,
            "This is pre-release software" );
        y0 += fm2.lineSpacing();
        paint.drawText( 0, y0, wd, ht-y0, align,
            "for testing purposes only!" );
        y0 += fm2.lineSpacing();
        paint.drawText( 0, y0, wd, ht-y0, align,
            "Use at Your Own Risk!" );
    }

    // Authors
    y0 = ht - 6 * fm3.lineSpacing();
    paint.setFont( fnt3 );
    paint.setPen( whitePen );
    paint.drawText( 0, y0, wd, ht-y0, align,
        "US Forest Service, Rocky Mountain Research Station" );
    y0 += fm3.lineSpacing();
    paint.drawText( 0, y0, wd, ht-y0, align,
        "& Systems for Environmental Management" );
    paint.end();

    // Status message display area
    m_statusLine = ht - 2 * fm3.lineSpacing();
    return;
}
Esempio n. 11
0
// ----------------------------------------------------------------------
void fitCombinatorial(string era = "2016BF", float bdt = -99.) {
  if ("all" == era) {
    fitCombinatorial("2016BF");
    fitCombinatorial("2016GH");
    fitCombinatorial("2012");
    return;
  }

  if ("scan2012" == era) {
    fitCombinatorial("2012", 0.30);
    fitCombinatorial("2012", 0.25);
    fitCombinatorial("2012", 0.20);
    fitCombinatorial("2012", 0.15);
    return;
  }


  TFile *fd(0), *fm0(0), *fm1(0);
  float bdtcut(0.);
  cout << "======================================================================" << endl;
  if (era == "2016BF") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016BF-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.30;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2016GH") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016GH-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.31;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2012") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2012-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.34;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2011") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2011-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.28;
    } else {
      bdtcut = bdt;
    }
  }

  TTree *td = (TTree*)fd->Get("candAnaMuMu/events");

  TH1D *hd0 = new TH1D("hd0", "mass", 60, 4.8, 6.0);
  string cut(Form("chan==0 && !gmuid &&hlt1&&tos&&l1t &&bdt>%4.3f && m < 6 && m > 4.8", bdtcut));
  cout << cut << endl;
  td->Draw("m>>hd0", cut.c_str());

  TH1D *hd1 = (TH1D*)hd0->Clone("hd1");
  TH1D *hd2 = (TH1D*)hd0->Clone("hd2");

  TCanvas *c1 = new TCanvas("c1", "", 900, 300);
  c1->Modified();
  c1->Update();
  c1->Divide(3,1);

  c1->cd(1);
  hd0->Fit("pol0", "rl", "", 5.5, 6.0);
  float hd0chi2 = hd0->GetFunction("pol0")->GetChisquare();
  tl->SetTextSize(0.06);
  tl->DrawLatexNDC(0.4, 0.92, Form("#chi^{2} = %3.2f", hd0chi2));


  c1->cd(2);
  hd1->Fit("pol1", "rl", "", 5.5, 6.0);
  float hd1chi2 = hd1->GetFunction("pol1")->GetChisquare();
  tl->DrawLatexNDC(0.4, 0.92, Form("#chi^{2} = %3.2f", hd1chi2));

  c1->cd(3);
  hd2->Fit("expo", "rl", "", 5.5, 6.0);
  float hd2chi2 = hd2->GetFunction("expo")->GetChisquare();
  tl->DrawLatexNDC(0.4, 0.92, Form("#chi^{2} = %3.2f", hd2chi2));

  c1->SaveAs(Form("bg-fitting-%s-%3.2f.pdf", era.c_str(), bdtcut));
}
Esempio n. 12
0
// ----------------------------------------------------------------------
void invertedMuonID(string era = "2016BF", float bdt = -99., TH1D *hresult = 0) {
  if ("all" == era) {
    invertedMuonID("2016BF");
    invertedMuonID("2016GH");
    return;
  }

  TFile *fd(0), *fm0(0), *fm1(0);
  float bdtcut(0.);
  cout << "======================================================================" << endl;
  if (era == "2016BF") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016BF-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016BF-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016BF-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.30;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2016GH") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016GH-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016GH-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016GH-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.31;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2012") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2012-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.34;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2011") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2011-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.28;
    } else {
      bdtcut = bdt;
    }
  }

  TTree *td = (TTree*)fd->Get("candAnaMuMu/events");
  TTree *tm0 = (TTree*)fm0->Get("candAnaMuMu/events");
  TTree *tm1 = (TTree*)fm1->Get("candAnaMuMu/events");

  TH1D *hd0 = new TH1D("hd0", "mass", 60, 4.8, 6.0);
  TH1D *hm0 = new TH1D("hm0", "mass", 60, 4.8, 6.0);
  TH1D *hm1 = new TH1D("hm1", "mass", 60, 4.8, 6.0);
  string cut(Form("chan==0 && !gmuid &&hlt1&&tos&&l1t &&bdt>%4.3f && m < 6 && m > 4.8", bdtcut));
  cout << cut << endl;
  td->Draw("m>>hd0", cut.c_str());
  tm0->Draw("m>>hm0", cut.c_str());
  tm1->Draw("m>>hm1", cut.c_str());

  c0->Clear();
  // c0->Divide(2,2);
  // c0->cd(1);
  hd0->Draw("hist");
  // B0 -> mu mu
  // c0->cd(2);
  hm0->Fit("gaus");
  double p0 = hm0->GetFunction("gaus")->GetParameter(1);
  double s0 = hm0->GetFunction("gaus")->GetParameter(2);
  cout << "p0: " << p0 << " s0: " << s0 << endl;
  // Bs -> mu mu
  // c0->cd(3);
  hm1->Fit("gaus");
  double p1 = hm1->GetFunction("gaus")->GetParameter(1);
  double s1 = hm1->GetFunction("gaus")->GetParameter(2);
  cout << "p1: " << p1 << " s1: " << s1 << endl;

  // c0->cd(4);
  TH1D *hFit = (TH1D*)hd0->Clone("hFit");
  hFit->SetTitle("");
  hFit->SetMinimum(0.);
  TF1 *f1 = new TF1("f1", adhocfunction, 4.8, 6.0, 7);
  f1->SetParameter(0, 1);  f1->SetParLimits(0, 0., 1000.);
  f1->SetParameter(1, p0); f1->FixParameter(1, p0);
  f1->SetParameter(2, s0); f1->FixParameter(2, s0);
  f1->SetParameter(3, 1);  f1->SetParLimits(3, 0., 1000.);
  f1->SetParameter(4, p1); f1->FixParameter(4, p1);
  f1->SetParameter(5, s1); f1->FixParameter(5, s1);
  f1->SetParameter(6, 1);

  hFit->Fit(f1, "RL", "", 5.1, 6.0);

  double nb0 = hFit->GetFunction("f1")->GetParameter(0);
  double eb0 = hFit->GetFunction("f1")->GetParError(0);
  double nbs = hFit->GetFunction("f1")->GetParameter(3);
  double ebs = hFit->GetFunction("f1")->GetParError(3);

  TF1 *f0 = (TF1*)hm0->GetFunction("gaus")->Clone("f0");
  TF1 *fs = (TF1*)hm1->GetFunction("gaus")->Clone("fs");

  f0->SetParameter(0, nb0); f0->SetLineColor(kRed+2);
  fs->SetParameter(0, nbs); fs->SetLineColor(kBlue);
  f0->Draw("same");
  fs->Draw("same");
  tl->DrawLatexNDC(0.10, 0.92, era.c_str());
  tl->DrawLatexNDC(0.40, 0.92, Form("BDT > %3.2f", bdtcut));
  double iB0 = f0->Integral(5.1, 5.6);
  double iBs = fs->Integral(5.1, 5.6);
  double ratioV(0.);
  double relErr(0.);
  double ratioE(0.01);
  if (iBs > 1.e-3) {
    ratioV = iB0/iBs;
    relErr = TMath::Sqrt((eb0/nb0)*(eb0/nb0) + (ebs/nbs)*(ebs/nbs));
    ratioE = relErr * ratioV;
  }

  cout << "ratio of B0 and Bs: " << iB0 << "/" << iBs << " = " << ratioV << " +/- " << ratioE << " relErr: " << relErr << endl;

  c0->SaveAs(Form("invertedMuonID-%s-%3.2f.pdf", era.c_str(), bdtcut));

  if (hresult) {
    hresult->SetBinContent(hresult->FindBin(bdtcut), ratioV);
    hresult->SetBinError(hresult->FindBin(bdtcut), ratioE);
  }
}
Esempio n. 13
0
// ----------------------------------------------------------------------
void invertedMuonID2Comb(string era = "2016BF", float bdt = -99., TH1D *hBd = 0,  TH1D *hBs = 0) {
  if ("all" == era) {
    invertedMuonID2Comb("2016BF");
    invertedMuonID2Comb("2016GH");
    invertedMuonID2Comb("2011");
    invertedMuonID2Comb("2012");
    return;
  }

  TFile *fd(0), *fm0(0), *fm1(0);
  float bdtcut(0.);
  cout << "======================================================================" << endl;
  if (era == "2016BF") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016BF-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016BF-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016BF-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.30;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2016GH") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016GH-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016GH-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016GH-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.31;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2012") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2012-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.34;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2011") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2011-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.28;
    } else {
      bdtcut = bdt;
    }
  }

  TTree *td = (TTree*)fd->Get("candAnaMuMu/events");
  TTree *tm0 = (TTree*)fm0->Get("candAnaMuMu/events");
  TTree *tm1 = (TTree*)fm1->Get("candAnaMuMu/events");

  TH1D *hd0 = new TH1D("hd0", "mass", 60, 4.8, 6.0);
  TH1D *hm0 = new TH1D("hm0", "mass", 60, 4.8, 6.0);
  TH1D *hm1 = new TH1D("hm1", "mass", 60, 4.8, 6.0);
  int ichan(0);
  string cut(Form("chan==%d && !gmuid &&hlt1&&tos&&l1t &&bdt>%4.3f && m < 6 && m > 4.8", ichan, bdtcut));
  cout << cut << endl;
  td->Draw("m>>hd0", cut.c_str());
  tm0->Draw("m>>hm0", cut.c_str());
  tm1->Draw("m>>hm1", cut.c_str());

  c0->Clear();
  // c0->Divide(2,2);
  // c0->cd(1);
  hd0->Draw("hist");
  // B0 -> mu mu
  // c0->cd(2);
  hm0->Fit("gaus");
  double p0 = hm0->GetFunction("gaus")->GetParameter(1);
  double s0 = hm0->GetFunction("gaus")->GetParameter(2);
  cout << "p0: " << p0 << " s0: " << s0 << endl;
  // Bs -> mu mu
  // c0->cd(3);
  hm1->Fit("gaus");
  double p1 = hm1->GetFunction("gaus")->GetParameter(1);
  double s1 = hm1->GetFunction("gaus")->GetParameter(2);
  cout << "p1: " << p1 << " s1: " << s1 << endl;

  // c0->cd(4);
  TH1D *hFit = (TH1D*)hd0->Clone("hFit");
  hFit->SetTitle("");
  hFit->SetMinimum(0.);
  TF1 *f1 = new TF1("f1", adhocfunction, 4.8, 6.0, 7);
  f1->SetParameter(0, 1);  f1->SetParLimits(0, 0., 1000.);
  f1->SetParameter(1, p0); f1->FixParameter(1, p0);
  f1->SetParameter(2, s0); f1->FixParameter(2, s0);
  f1->SetParameter(3, 1);  f1->SetParLimits(3, 0., 1000.);
  f1->SetParameter(4, p1); f1->FixParameter(4, p1);
  f1->SetParameter(5, s1); f1->FixParameter(5, s1);
  f1->SetParameter(6, 1);

  hFit->Fit(f1, "RL", "", 5.1, 6.0);

  double nb0 = hFit->GetFunction("f1")->GetParameter(0);
  double eb0 = hFit->GetFunction("f1")->GetParError(0);
  double nbs = hFit->GetFunction("f1")->GetParameter(3);
  double ebs = hFit->GetFunction("f1")->GetParError(3);
  double nco = hFit->GetFunction("f1")->GetParameter(6);
  double eco = hFit->GetFunction("f1")->GetParError(6);

  TF1 *f0 = (TF1*)hm0->GetFunction("gaus")->Clone("f0");
  TF1 *fs = (TF1*)hm1->GetFunction("gaus")->Clone("fs");

  f0->SetParameter(0, nb0); f0->SetLineColor(kRed+2);
  fs->SetParameter(0, nbs); fs->SetLineColor(kBlue);
  f0->Draw("same");
  fs->Draw("same");
  tl->DrawLatexNDC(0.10, 0.92, era.c_str());
  tl->DrawLatexNDC(0.40, 0.92, Form("BDT > %3.2f", bdtcut));
  double iB0   = f0->Integral(5.1, 5.6);
  double iBs   = fs->Integral(5.1, 5.6);
  float  nB0   = f0->Integral(5.2, 5.3)/hFit->GetBinWidth(1);
  float  nB0E  = eb0/nb0*nB0;
  float  nBs   = fs->Integral(5.3, 5.45)/hFit->GetBinWidth(1);
  float  nBsE  = ebs/nbs*nBs;
  double iComb = nco*(6.0-5.6);
  double ratioVs(0.);
  double relErrs(0.);
  double ratioEs(0.01);
  double ratioVd(0.);
  double relErrd(0.);
  double ratioEd(0.01);
  if (iComb > 1.e-3) {
    ratioVs = iBs/iComb;
    relErrs = TMath::Sqrt((ebs/nbs)*(ebs/nbs) + (eco/nco)*(eco/nco));
    ratioEs = relErrs * ratioVs;

    ratioVd = iB0/iComb;
    relErrd = TMath::Sqrt((eb0/nb0)*(eb0/nb0) + (eco/nco)*(eco/nco));
    ratioEd = relErrd * ratioVd;
 }

  cout << "ratio of B0/comb: " << iB0 << "/" << iComb << " = " << ratioVd << " +/- " << ratioEd << " relErr: " << relErrd << endl;
  cout << "ratio of Bs/comb: " << iBs << "/" << iComb << " = " << ratioVs << " +/- " << ratioEs << " relErr: " << relErrs << endl;

  ofstream TEX(Form("invertedMuonIDStudies.tex"), ios::app);
  TEX << Form("\\vdef{%ss01:nb0:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nB0) << endl;
  TEX << Form("\\vdef{%ss01:eb0:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nB0E) << endl;
  TEX << Form("\\vdef{%ss01:nbs:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nBs) << endl;
  TEX << Form("\\vdef{%ss01:ebs:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nBsE) << endl;
  TEX.close();

  c0->SaveAs(Form("invertedMuonIDcomb-%s-%3.2f.pdf", era.c_str(), bdtcut));

  if (hBd) {
    hBd->SetBinContent(hBd->FindBin(bdtcut), ratioVd);
    hBd->SetBinError(hBd->FindBin(bdtcut), ratioEd);
  }
  if (hBs) {
    hBs->SetBinContent(hBs->FindBin(bdtcut), ratioVs);
    hBs->SetBinError(hBs->FindBin(bdtcut), ratioEs);
  }
}