Пример #1
0
std::vector< classification > ofxDarknet::classify( ofPixels & pix, int count )
{
	int *indexes = ( int* ) calloc( count, sizeof( int ) );

    ofPixels  pix2( pix );
    if (pix2.getImageType() != OF_IMAGE_COLOR) {
        pix2.setImageType(OF_IMAGE_COLOR);
    }
	if( pix2.getWidth() != net.w && pix2.getHeight() != net.h ) {
		pix2.resize( net.w, net.h );
	}

	image im = convert( pix2 );

	float *predictions = network_predict( net, im.data1 );

	top_k( predictions, net.outputs, count, indexes );
	std::vector< classification > classifications;
	for( int i = 0; i < count; ++i ) {
		int index = indexes[ i ];
		classification c;
        c.label = labelsAvailable ? names[ index ] : ofToString(index);
		c.probability = predictions[ index ];
		classifications.push_back( c );
	}
	free_image( im );
    free(indexes);
	return classifications;
}
QVariant QgsSymbolV2LegendNode::data( int role ) const
{
  if ( role == Qt::DisplayRole )
  {
    return mLabel;
  }
  else if ( role == Qt::EditRole )
  {
    return mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
  }
  else if ( role == Qt::DecorationRole )
  {
    QSize iconSize( 16, 16 ); // TODO: configurable
    const int indentSize = 20;
    if ( mPixmap.isNull() )
    {
      QPixmap pix;
      if ( mItem.symbol() )
        pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( mItem.symbol(), iconSize );
      else
      {
        pix = QPixmap( iconSize );
        pix.fill( Qt::transparent );
      }

      if ( mItem.level() == 0 )
        mPixmap = pix;
      else
      {
        // ident the symbol icon to make it look like a tree structure
        QPixmap pix2( pix.width() + mItem.level() * indentSize, pix.height() );
        pix2.fill( Qt::transparent );
        QPainter p( &pix2 );
        p.drawPixmap( mItem.level() * indentSize, 0, pix );
        p.end();
        mPixmap = pix2;
      }
    }
    return mPixmap;
  }
  else if ( role == Qt::CheckStateRole )
  {
    if ( !mItem.isCheckable() )
      return QVariant();

    QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
    if ( !vlayer || !vlayer->rendererV2() )
      return QVariant();

    return vlayer->rendererV2()->legendSymbolItemChecked( mItem.ruleKey() ) ? Qt::Checked : Qt::Unchecked;
  }
  else if ( role == RuleKeyRole )
  {
    return mItem.ruleKey();
  }

  return QVariant();
}
Пример #3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QPixmap pix("/home/baigoo365/Downloads/IMG_5497.png");
    QPixmap pix2("/home/baigoo365/Downloads/IMG_5498.png");
    ui->label_pic->setPixmap(pix);
    ui->label_jalebi->setPixmap(pix2);
}
Пример #4
0
admin::admin(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::admin)
{
    ui->setupUi(this);

    QPixmap pix2("C:/Users/carlosa/Documents/UNITEC/Año 2014/Semestre 1/Parcial 1/Estructura de Datos/PROYECTO2/SistemaBNJI/logo2.png");
    ui->label_logoadmin->setPixmap(pix2);

    ui->label_error->setVisible(false);
}
Пример #5
0
void Profile::on_pushButton_clicked()
{
    QString set1[3];
        set1[0] = "Leo Messi";
        set1[1] = "2014 BoD FTW!";
        set1[2] = "10:33am";

    QString set2[3];
            set2[0] = "Wenger";
            set2[1] = "Needs some trophies";
            set2[2] = "09:3pm";

    QString set3[3];
                set3[0] = "Moyes";
                set3[1] = "Let me win.";
                set3[2] = "7:33pm";

    QString set4[3];
                set4[0] = "Ribery";
                set4[1] = "I should've won it!";
                set4[2] = "5:15pm";

    ui->CS1_Name_label->setText(set1[0]);
    ui->CS1_LastMess_label  ->setText(set1[1]);
    ui->CS1_LastSeen_label  ->setText("Last seen: " + set1[2]);

    ui->CS2_Name_label->setText(set2[0]);
    ui->CS2_LastMess_label  ->setText(set2[1]);
    ui->CS2_LastSeen_label  ->setText("Last seen: " + set2[2]);

    ui->CS3_Name_label->setText(set3[0]);
    ui->CS3_LastMess_label  ->setText(set3[1]);
    ui->CS3_LastSeen_label  ->setText("Last seen: " + set3[2]);

    ui->CS4_Name_label->setText(set4[0]);
    ui->CS4_LastMess_label  ->setText(set4[1]);
    ui->CS4_LastSeen_label  ->setText("Last seen: " + set4[2]);


    QPixmap pix2("C:\\img\\messi.png");
    ui->lbl_FirstContactSlot->setPixmap(pix2);

    QPixmap pix3("C:\\img\\wenger.png");
    ui->lbl_SecondContactSlot->setPixmap(pix3);

    QPixmap pix4("C:\\img\\moyes.png");
    ui->lbl_ThirdContactSlot->setPixmap(pix4);

    QPixmap pix5("C:\\img\\ribery.png");
    ui->lbl_FourthContactSlot->setPixmap(pix5);
}
Пример #6
0
QPixmap ImageProcessorPrivate::processImage(const QString &url, int width, int height)
{
    QPixmap pix(url);

    if (pix.isNull())
        return pix;

    // If the image is better displayed in "portrait mode", rotate it.
    if ((pix.width() < pix.height() && width >= height) || (pix.width() >= pix.height() && width < height))
    {
        pix = pix.scaledToHeight(width);
        QPixmap pix2(pix.height(), pix.width());
        QPainter p;
        p.begin(&pix2);
        p.rotate(-90);
        p.translate(- pix2.height(), 0);
        p.drawPixmap(0, 0, pix);
        p.end();
        pix = pix2;
    }

    // Scale it to our width
    if (pix.width() - 1 > width || pix.width() + 1 < width)
        pix = pix.scaledToWidth(width);

    // If still not good enough, just crop it
    if (pix.height() > height)
    {
        QPixmap pix2(width, height);
        QPainter p;
        p.begin(&pix2);
        p.drawPixmap(0, 0, pix, 0, (pix.height() - height) / 2, pix.width(), pix.height());
        p.end();
        pix = pix2;
    }

    return pix;
}
Пример #7
0
void Profile::on_Prev_pushButton_clicked()
{
    QString set1[3];
        set1[0] = "David Berry";
        set1[1] = "Going to Costa!";
        set1[2] = "8:19am";

    QString set2[3];
            set2[0] = "Dom Santiago";
            set2[1] = "Shooting the Locust";
            set2[2] = "12:19pm";

    QString set3[3];
                set3[0] = "Trevor";
                set3[1] = "Riding my Bike.";
                set3[2] = "7:55am";

    QString set4[3];
                set4[0] = "Jesse";
                set4[1] = "It's Science !";
                set4[2] = "2:10am";

                QPixmap pix2("C:\\img\\david.png");
                ui->lbl_FirstContactSlot->setPixmap(pix2);

                QPixmap pix3("C:\\img\\dom.png");
                ui->lbl_SecondContactSlot->setPixmap(pix3);

                QPixmap pix4("C:\\img\\trevor.png");
                ui->lbl_ThirdContactSlot->setPixmap(pix4);

                QPixmap pix5("C:\\img\\jesse.png");
                ui->lbl_FourthContactSlot->setPixmap(pix5);

    ui->CS1_Name_label->setText(set1[0]);
    ui->CS1_LastMess_label  ->setText(set1[1]);
    ui->CS1_LastSeen_label  ->setText("Last seen: " + set1[2]);

    ui->CS2_Name_label->setText(set2[0]);
    ui->CS2_LastMess_label  ->setText(set2[1]);
    ui->CS2_LastSeen_label  ->setText("Last seen: " + set2[2]);

    ui->CS3_Name_label->setText(set3[0]);
    ui->CS3_LastMess_label  ->setText(set3[1]);
    ui->CS3_LastSeen_label  ->setText("Last seen: " + set3[2]);

    ui->CS4_Name_label->setText(set4[0]);
    ui->CS4_LastMess_label  ->setText(set4[1]);
    ui->CS4_LastSeen_label  ->setText("Last seen: " + set4[2]);
}
Пример #8
0
int ctkThumbnailListWidgetTest1( int argc, char * argv [] )
{
  QApplication app(argc, argv);

  ctkThumbnailListWidget widget;

  QPixmap pix1(QSize(128, 128));;
  QPixmap pix2(QSize(64, 64));
  QPixmap pix3(QSize(256, 256));
  QPixmap pix4(QSize(256, 128));


  pix1.fill(Qt::green);
  pix2.fill(Qt::yellow);
  pix3.fill(Qt::blue);
  pix4.fill(Qt::red);

  QList<QPixmap> pixList;

  widget.setThumbnailSize(QSize(128, 128));
  if(widget.thumbnailSize() != QSize(128, 128))
    {
      std::cerr << "ctkThumbnailListWidget::setThumbnailWidth failed."
        << " size: " << widget.thumbnailSize().width()
        << "," << widget.thumbnailSize().height()
        << " expected: 128" << std::endl;
      return EXIT_FAILURE;
    }

  pixList.append(pix1);
  pixList.append(pix2);
  pixList.append(pix3);
  pixList.append(pix4);

  widget.addThumbnails(pixList);

  widget.show();

  if (argc <= 1 || QString(argv[1]) != "-I")
    {
    QTimer::singleShot(200, &app, SLOT(quit()));
    }

  return app.exec();
}
Пример #9
0
void Field::slot_change_icon(){
    if(scene->get_count() == 1){
        QPixmap pixhh(PALADIN_ICON);
        whose_turn_wgt->setIcon(pixhh);
        whose_turn_wgt->setIconSize(pixhh.size());
    }
    else if(scene->get_count() == 2){
        QPixmap pixoh(OGRE_ICON);
        whose_turn_wgt->setIcon(pixoh);
        whose_turn_wgt->setIconSize(pixoh.size());
    }
    else if(scene->get_count() == 3){
        QPixmap pix1(ARCHER_ICON);
        whose_turn_wgt->setIcon(pix1);
        whose_turn_wgt->setIconSize(pix1.size());
    }
    else if(scene->get_count() == 4){
        QPixmap pix2(TROLL_ICON);
        whose_turn_wgt->setIcon(pix2);
        whose_turn_wgt->setIconSize(pix2.size());
    }
    else if(scene->get_count() == 5){
        QPixmap pix3(FOOTMAN_ICON);
        whose_turn_wgt->setIcon(pix3);
        whose_turn_wgt->setIconSize(pix3.size());
    }
    else if(scene->get_count() == 6){
        QPixmap pix4(GRUNT_ICON);
        whose_turn_wgt->setIcon(pix4);
        whose_turn_wgt->setIconSize(pix4.size());
    }
    else if(scene->get_count() == 7){
        QPixmap pix5(BALLISTA_ICON);
        whose_turn_wgt->setIcon(pix5);
        whose_turn_wgt->setIconSize(pix5.size());
    }
    else if(scene->get_count() == 8){
        QPixmap pix6(CATAPULT_ICON);
        whose_turn_wgt->setIcon(pix6);
        whose_turn_wgt->setIconSize(pix6.size());
    }
}
Пример #10
0
ButtonBar::ButtonBar(QWidget *parent) : QWidget(parent)
{
    controller = new ButtonController();
    QHBoxLayout *layout = new QHBoxLayout();

    runButton = new QPushButton();
    runButton->setText("Run");
    runButton->setMaximumSize(50, 22);
    runButton->setMinimumSize(50, 22);
    QPixmap pix(":/Images/Images/RunButtonIcon.png");
    QIcon icon(pix);
    runButton->setIcon(icon);
    runButton->setIconSize(pix.size());

    buildButton = new QPushButton();
    buildButton->setText("Build");
    buildButton->setMaximumSize(50, 22);
    buildButton->setMinimumSize(50, 22);
    QPixmap pix2(":/Images/Images/BuildButtonIcon.png");
    QIcon icon2(pix2);
    buildButton->setIcon(icon2);
    buildButton->setIconSize(pix2.size());

    connect(runButton, SIGNAL(released()), this, SLOT(runButtonClicked()));
    connect(buildButton, SIGNAL(released()), this, SLOT(buildButtonClicked()));

    layout->addWidget(runButton);
    layout->addWidget(buildButton);
    layout->setContentsMargins(5, 5, 0, 5);
    layout->setAlignment(Qt::AlignLeft);
    setLayout(layout);

    QPalette Pal(palette());
    Pal.setColor(QPalette::Background, "#323232");
    setAutoFillBackground(true);
    setPalette(Pal);

    //background color for all buttons inside the buttonbar
    setStyleSheet("QPushButton { color: white; background-color: #2D2D2F; border: none; border-color: black; } QPushButton:hover{ background-color: #1E1E1F; } QPushButton:pressed{ border-left: 2px solid grey; border-top: 2px solid grey; border-right: 2px solid black; border-bottom: 2px solid black; }");
}
Пример #11
0
void echequier::display(){
    position p;
    for(int i = 0; i < 16; i++){
        //QString name = QString::fromStdString(A.idToDesc(i+1));
        p = A.get_piece_pos(i);
        //ui->tableWidget->item(p.y, p.x)->setText(name);
        if(p.x!=-1 && p.y!=-1){
            ui->tableWidget->item(p.y, p.x)->setToolTip(QString::fromStdString(A.idToDesc(i+1)));
            QPixmap pix(QString::fromStdString(A.idToPath(i+1)));
            QPixmap resPix = pix.scaled(30,30, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
            QLabel *lblTest = new QLabel;
            lblTest->setPixmap(resPix);
            lblTest->setAlignment(Qt::AlignCenter);
            ui->tableWidget->setCellWidget(p.y, p.x, lblTest);
            //delete lblTest;
        }

        //QString name2 = QString::fromStdString(B.idToDesc(i+1));
        p = B.get_piece_pos(i);
        //ui->tableWidget->item(p.y, p.x)->setText(name2);
        if(p.x!=-1 && p.y!=-1){
            ui->tableWidget->item(p.y, p.x)->setToolTip(QString::fromStdString(B.idToDesc(i+1)));
            QPixmap pix2(QString::fromStdString(B.idToPath(i+1)));
            QPixmap resPix2 = pix2.scaled(30,30, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
            QLabel *lblTest2 = new QLabel;
            lblTest2->setPixmap(resPix2);
            lblTest2->setAlignment(Qt::AlignCenter);
            ui->tableWidget->setCellWidget(p.y, p.x, lblTest2);
            //delete lblTest;
        }
    }
    QLabel *emptylabel = new QLabel;
    for(int i = 0; i < 8; i++){
        for(int j = 0; j < 8; j++){
            if(C[j][i].plein==false) ui->tableWidget->setCellWidget(i, j, emptylabel);
        }
    }
    ui->lcdNumber->display(nbtour);
}
Пример #12
0
/* See task: 41469
   Problem is that the state is not properly restored if the basestate of
   the painter is different when the picture data was created compared to
   the base state of the painter when it is played back.
 */
void tst_QPicture::save_restore()
{
    QPicture pic;
    QPainter p;
    p.begin(&pic);
    paintStuff(&p);
    p.end();

    QPixmap pix1(300, 300);
    pix1.fill(Qt::white);
    p.begin(&pix1);
    p.drawPicture(50, 50, pic);
    p.end();

    QPixmap pix2(300, 300);
    pix2.fill(Qt::white);
    p.begin(&pix2);
    p.translate(50, 50);
    paintStuff(&p);
    p.end();

    QVERIFY( pix1.toImage() == pix2.toImage() );
}
Пример #13
0
int main_alt()
{
  in_head.Register("/egomap/i:head");
  in_img.Register("/egomap/i:img");
  out_img.Register("/egomap/o:img");
  out_cmd.Register("/egomap/o:cmd");
  in_voice.Register("/egomap/i:cmd");

  while (1)
    {
      JointPos joints;
      in_img.Read();
      state_mutex.Wait();
      joints = state_joint;
      CogGaze gaze;
      gaze.Apply(joints);
      double roll = gaze.roll_right;
      double theta = gaze.theta_right;
      double phi = gaze.phi_right;
      //printf("DIR %g %g %g\n", theta, phi, roll);
      global_theta = theta;
      global_phi = phi;
      global_roll = roll;
      state_mutex.Post();
      double z_x = gaze.z_right[0];
      double z_y = gaze.z_right[1];
      YARPImageOf<YarpPixelBGR> img;
      img.Refer(in_img.Content());
      int width = img.GetWidth();
      int height = img.GetHeight();
      float s = 50;
      for (int i=0; i<width; i++)
	{
	  YarpPixelBGR pix0(0,255,0);
	  img(i,width/2) = pix0;
	}
      for (int i=0; i<width; i++)
	{
	  float s2 = (i-width/2.0);
	  float x = cos(roll)*s2;
	  float y = -sin(roll)*s2;
	  YarpPixelBGR pix(255,0,0);
	  img.SafePixel((int)(0.5+x+(width+1)/2.0),(int)(0.5+y+(width+1)/2.0)) = pix;	
	}
      int step = 500;
      for (int i=0; i<step; i++)
	{
	  float theta = i*M_PI*2.0/step;
	  YarpPixelBGR pix(255,0,0);
	  float x = cos(theta)*s;
	  float y = sin(theta)*s;
	  //printf("%g %g %g\n", theta, x, y);
	  img.SafePixel(x+width/2,y+width/2) = pix;	
	}
      for (int i=0; i<MAX_TARGETS; i++)
	{
	  if (target_manager.Exists(i))
	    {
	      TargetLocation& loc = target_manager.Get(i);
	      float target_theta = loc.theta;
	      float target_phi = loc.phi;
	      float z_y = loc.phi/(M_PI/2);
	      float z_x = loc.theta/(M_PI/2);
	      //printf("Drawing circle for %g %g\n", loc.theta, loc.phi);
	      float x = z_x*s;
	      float y = z_y*s;
	      // YarpPixelBGR pix0(0,128,255);
	      // AddCircle(img,pix0,(int)x+width/2,(int)y+height/2,4);
	      // We now try to map back 
	      // onto approximate retinotopic coordinates.
	      
	      // current x, y, z available in gaze::x_right,y_right,z_right
	      double x_vis, y_vis;
	      int visible;
	      visible = gaze.Intersect(target_theta,target_phi,x_vis,y_vis,
				       CAMERA_SOURCE_RIGHT_WIDE);
	      
	      /*
	      float zt[3];
	      zt[0] = sin(target_theta);
	      zt[1] = -cos(target_phi)*cos(target_theta);
	      zt[2] = sin(target_phi)*cos(target_theta);
	      
	      float delta_theta = zt[0]*gaze.x_right[0] +
		 zt[1]*gaze.x_right[1] + zt[2]*gaze.x_right[2];
	      float delta_phi = zt[0]*gaze.y_right[0] +
		 zt[1]*gaze.y_right[1] + zt[2]*gaze.y_right[2];
	      float sanity = zt[0]*gaze.z_right[0] +
		 zt[1]*gaze.z_right[1] + zt[2]*gaze.z_right[2];
	      //float delta_theta = zt[0];  //target_theta - global_theta;
	      //float delta_phi = zt[1];    //target_phi - global_phi;
	      float factor_theta = 67;  // just guessed these numbers
	      float factor_phi = 67;    // so far, not linear in reality
	      float nx = delta_theta;
	      float ny = delta_phi;
	      float r = global_roll;
	      float sinr = sin(r);
	      float cosr = cos(r);
	      float fx = factor_theta;
	      float fy = factor_phi;
	      //delta_theta = nx*cosr - ny*sinr;  // just guessed the signs here
	      //delta_phi   = nx*sinr + ny*cosr;  // so far
	      //delta_theta = nx*cosr - ny*sinr;  // just guessed the signs here
	      //delta_phi   = nx*sinr + ny*cosr;  // so far
	      delta_theta *= factor_theta;
	      delta_phi *= factor_phi;
	      delta_phi *= 4.0/3.0;
	      float len = sqrt(delta_theta*delta_theta+delta_phi*delta_phi);
	      delta_theta += img.GetWidth()/2;
	      delta_phi += img.GetHeight()/2;
	       */
	      
	      int sanity = visible;
	      double delta_theta = x_vis;
	      double delta_phi = y_vis;
	      delta_theta -= 64;
	      delta_phi -= 64;
	      float len = sqrt(delta_theta*delta_theta+delta_phi*delta_phi);
	      delta_theta += 64;
	      delta_phi += 64;
	      
	      if (sanity>0)
		{
		  YarpPixelBGR pix1((len<50)?255:0,128,0);
		  AddCircle(img,pix1,(int)(delta_theta+0.5),
			    (int)(delta_phi+0.5),4);
		}
	      else
		{
		  //printf("Object occluded\n");
		}
	    }
	}
      z_y = phi/(M_PI/2);
      z_x = theta/(M_PI/2);
      if (0)
      for (int i=0; i<5; i++)
	{
	  float x = z_x*s;
	  float y = z_y*s;
	  YarpPixelBGR pix(255,0,0);
	  YarpPixelBGR pix2(0,0,255);
	  img.SafePixel(i+x+width/2,y+width/2) = pix;	
	  img.SafePixel(-i+x+width/2,y+width/2) = pix;	
	  img.SafePixel(i+x+width/2,y+width/2-1) = pix2;	
	  img.SafePixel(-i+x+width/2,y+width/2+1) = pix2;	
	  img.SafePixel(x+width/2,i+y+width/2) = pix;	
	  img.SafePixel(x+width/2,-i+y+width/2) = pix;
	  img.SafePixel(x+width/2+1,i+y+width/2) = pix2;	
	  img.SafePixel(x+width/2-1,-i+y+width/2) = pix2;	
	}
      out_img.Content().PeerCopy(in_img.Content());
      out_img.Write();
    }

  return 0;
}
Пример #14
0
QVariant QgsSymbolLegendNode::data( int role ) const
{
  if ( role == Qt::DisplayRole )
  {
    return mLabel;
  }
  else if ( role == Qt::EditRole )
  {
    return mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
  }
  else if ( role == Qt::DecorationRole )
  {
    if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
    {
      QPixmap pix;
      if ( mItem.symbol() )
      {
        std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
        pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), mIconSize, 0, context.get() );

        if ( !mTextOnSymbolLabel.isEmpty() && context )
        {
          QPainter painter( &pix );
          painter.setRenderHint( QPainter::Antialiasing );
          context->setPainter( &painter );
          QFontMetricsF fm( mTextOnSymbolTextFormat.scaledFont( *context ) );
          qreal yBaselineVCenter = ( mIconSize.height() + fm.ascent() - fm.descent() ) / 2;
          QgsTextRenderer::drawText( QPointF( mIconSize.width() / 2, yBaselineVCenter ), 0, QgsTextRenderer::AlignCenter,
                                     QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
        }
      }
      else
      {
        pix = QPixmap( mIconSize );
        pix.fill( Qt::transparent );
      }

      if ( mItem.level() == 0 || ( model() && model()->testFlag( QgsLayerTreeModel::ShowLegendAsTree ) ) )
        mPixmap = pix;
      else
      {
        // ident the symbol icon to make it look like a tree structure
        QPixmap pix2( pix.width() + mItem.level() * INDENT_SIZE, pix.height() );
        pix2.fill( Qt::transparent );
        QPainter p( &pix2 );
        p.drawPixmap( mItem.level() * INDENT_SIZE, 0, pix );
        p.end();
        mPixmap = pix2;
      }
    }
    return mPixmap;
  }
  else if ( role == Qt::CheckStateRole )
  {
    if ( !mItem.isCheckable() )
      return QVariant();

    QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
    if ( !vlayer || !vlayer->renderer() )
      return QVariant();

    return vlayer->renderer()->legendSymbolItemChecked( mItem.ruleKey() ) ? Qt::Checked : Qt::Unchecked;
  }
  else if ( role == RuleKeyRole )
  {
    return mItem.ruleKey();
  }
  else if ( role == ParentRuleKeyRole )
  {
    return mItem.parentRuleKey();
  }

  return QVariant();
}
QVariant QgsSymbolV2LegendNode::data( int role ) const
{
    if ( role == Qt::DisplayRole )
    {
        return mLabel;
    }
    else if ( role == Qt::EditRole )
    {
        return mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
    }
    else if ( role == Qt::DecorationRole )
    {
        if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
        {
            QPixmap pix;
            if ( mItem.symbol() )
            {
                QScopedPointer<QgsRenderContext> context( createTemporaryRenderContext() );
                pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( mItem.symbol(), mIconSize, context.data() );
            }
            else
            {
                pix = QPixmap( mIconSize );
                pix.fill( Qt::transparent );
            }

            if ( mItem.level() == 0 || ( model() && model()->testFlag( QgsLayerTreeModel::ShowLegendAsTree ) ) )
                mPixmap = pix;
            else
            {
                // ident the symbol icon to make it look like a tree structure
                QPixmap pix2( pix.width() + mItem.level() * indentSize, pix.height() );
                pix2.fill( Qt::transparent );
                QPainter p( &pix2 );
                p.drawPixmap( mItem.level() * indentSize, 0, pix );
                p.end();
                mPixmap = pix2;
            }
        }
        return mPixmap;
    }
    else if ( role == Qt::CheckStateRole )
    {
        if ( !mItem.isCheckable() )
            return QVariant();

        QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
        if ( !vlayer || !vlayer->rendererV2() )
            return QVariant();

        return vlayer->rendererV2()->legendSymbolItemChecked( mItem.ruleKey() ) ? Qt::Checked : Qt::Unchecked;
    }
    else if ( role == RuleKeyRole )
    {
        return mItem.ruleKey();
    }
    else if ( role == SymbolV2LegacyRuleKeyRole )
    {
        return QVariant::fromValue<void*>( mItem.legacyRuleKey() );
    }
    else if ( role == ParentRuleKeyRole )
    {
        return mItem.parentRuleKey();
    }

    return QVariant();
}
Пример #16
0
void infoView::initComponent()
{
    colorP1 = new QLabel( "" );
    colorP2 = new QLabel( "" );
    scoreP1Label = new QLabel( tr("Score") );
    scoreP2Label = new QLabel( tr("Score") );
    movesP1Label = new QLabel( tr("Moves") );
    movesP2Label = new QLabel( tr("Moves") );
    nameP1 = new QLabel( "" );
    nameP2 = new QLabel( "" );
    scoreP1 = new QLabel( "" );
    scoreP2 = new QLabel( "" );
    movesP1 = new QLabel( "" );
    movesP2 = new QLabel( "" );
    typeP1 = new QLabel("( )");
    typeP2 = new QLabel("( )");
    namepar1 = new QLabel("Name ");
    namepar2 = new QLabel("Name ");
    levelpar1  = new QLabel("Level ");
    levelpar2 = new QLabel("level ");

    dot1 = new QLabel(":");
    dot2 = new QLabel(":");
    dot3 = new QLabel(":");
    dot4 = new QLabel(":");
    dot5 = new QLabel(":");

    QPixmap pix(60,60);
    pix.fill(Qt::transparent);
    hit= new QPainter(&pix);
    hit->setBrush(QBrush(Qt::black));
    hit->drawEllipse(5.0, 5.0, 50.0, 50.0);
    delete hit;
    pawnBlack = new QLabel("Black");
    pawnBlack->setAlignment(Qt::AlignCenter);
    pawnBlack->setPixmap(pix);
    pawnBlack->setStyleSheet("QLabel { color : black; }");

    QPixmap pix2(60,60);
    pix2.fill(Qt::transparent);
    hit2= new QPainter(&pix2);
    hit2->setBrush(QBrush(Qt::white));
    hit2->drawEllipse(5.0, 5.0, 50.0, 50.0);
    delete hit2;
    pawnWhite = new QLabel("");
    pawnWhite->setAlignment(Qt::AlignCenter);
    pawnWhite->setPixmap(pix2);
    pawnWhite->setStyleSheet("QLabel { color : black; }");

    colorP1->setAlignment(Qt::AlignCenter);
    colorP2->setAlignment(Qt::AlignCenter);
    nameP1->setAlignment(Qt::AlignCenter);
    nameP2->setAlignment(Qt::AlignCenter);
    typeP1->setAlignment(Qt::AlignCenter);
    typeP2->setAlignment(Qt::AlignCenter);
    scoreP1->setAlignment(Qt::AlignCenter);
    QFont f( "Verdana", 35, QFont::Bold);
    scoreP1->setFont(f);
    scoreP1->setText("0");
    scoreP2->setAlignment(Qt::AlignCenter);
    scoreP2->setFont(f);
    scoreP2->setText("0");
    movesP1->setAlignment(Qt::AlignCenter);
    movesP1->setText("0");
    movesP2->setAlignment(Qt::AlignCenter);
    movesP2->setText("0");
    dot5->setAlignment(Qt::AlignCenter);
    dot5->setFont(f);
    QFont f2( "Audiowide", 15, QFont::Bold);
    scoreP1Label->setFont(f2);
    infosGame = new QLabel( "" );
    infosGame->setAlignment(Qt::AlignCenter);
    infosGame->setFrameStyle(QFrame::Box|QFrame::Raised);
    infosGame->setFixedSize(350,50);
    infosGame->setLineWidth(3);
    infosGame->setAutoFillBackground(true);
    infosGame->setText("Good Luck!");
    QPalette palette=infosGame->palette();
    palette.setColor(QPalette::Window,QColor(Qt::green));
    infosGame->setPalette(palette);

    topLayout = new QGridLayout;
    topLayout->addWidget(namepar1,1,0);
    topLayout->addWidget(levelpar1,2,0);
    topLayout->addWidget(movesP1Label,3,0);
    topLayout->addWidget(scoreP1Label,4,0);
    topLayout->addWidget(dot1,1,1);
    topLayout->addWidget(dot2,2,1);
    topLayout->addWidget(dot3,3,1);
    topLayout->addWidget(dot4,4,1);

    topLayout->addWidget(pawnBlack,0,2);
    topLayout->addWidget(nameP1,1,2);
    topLayout->addWidget(typeP1,2,2);
    topLayout->addWidget(movesP1,3,2);
    topLayout->addWidget(scoreP1,4,2);

    topLayout->addWidget(dot5, 4,3);

    topLayout->addWidget(pawnWhite,0,4);
    topLayout->addWidget(nameP2,1,4);
    topLayout->addWidget(typeP2,2,4);
    topLayout->addWidget(movesP2,3,4);
    topLayout->addWidget(scoreP2,4,4);

    toptopLayout = new QHBoxLayout;
    toptopLayout->addLayout(topLayout);
    toptopLayout->addStretch();

    mainLayout = new QVBoxLayout;
    mainLayout->addStretch();
    mainLayout->addLayout(toptopLayout);
    mainLayout->addStretch();
    mainLayout->addStretch();
    mainLayout->addWidget(infosGame);
    mainLayout->addStretch();
    mainLayout->addStretch();

}
Пример #17
0
std::vector< detected_object > ofxDarknet::yolo( ofPixels & pix, float threshold /*= 0.24f */, float maxOverlap /*= 0.5f */ )
{
	int originalWidth = pix.getWidth();
	int originalHeight = pix.getHeight();
	ofPixels  pix2( pix );
    if (pix2.getImageType() != OF_IMAGE_COLOR) {
        pix2.setImageType(OF_IMAGE_COLOR);
    }
    if( pix2.getWidth() != net.w && pix2.getHeight() != net.h ) {
        pix2.resize( net.w, net.h );
    }
	image im = convert( pix2 );
	layer l = net.layers[ net.n - 1 ];

	box *boxes = ( box* ) calloc( l.w*l.h*l.n, sizeof( box ) );
	float **probs = ( float** ) calloc( l.w*l.h*l.n, sizeof( float * ) );
	for( int j = 0; j < l.w*l.h*l.n; ++j ) probs[ j ] = ( float* ) calloc( l.classes, sizeof( float * ) );

	network_predict( net, im.data1 );
	get_region_boxes( l, 1, 1, threshold, probs, boxes, 0, 0 );
	do_nms_sort( boxes, probs, l.w*l.h*l.n, l.classes, 0.4 );
	free_image( im );

    std::vector< detected_object > detections;
    int num = l.w*l.h*l.n;
    
    int feature_layer = net.n - 2;
    layer l1 = net.layers[ feature_layer ];
    float * features = get_network_output_layer_gpu(feature_layer);
    
    vector<size_t> sorted(num);
    iota(sorted.begin(), sorted.end(), 0);
    sort(sorted.begin(), sorted.end(), [&probs, &l](int i1, int i2) {
        return probs[i1][max_index(probs[i1], l.classes)] > probs[i2][max_index(probs[i2], l.classes)];
    });
    
	for( int i = 0; i < num; ++i ) {
        int idx = sorted[i];
		int class1 = max_index( probs[ idx ], l.classes );
		float prob = probs[ idx ][ class1 ];

        if( prob < threshold ) {
            continue;
        }

        int offset = class1 * 123457 % l.classes;
        float red = get_color( 2, offset, l.classes );
        float green = get_color( 1, offset, l.classes );
        float blue = get_color( 0, offset, l.classes );

        box b = boxes[ idx ];

        int left = ( b.x - b.w / 2. )*im.w;
        int right = ( b.x + b.w / 2. )*im.w;
        int top = ( b.y - b.h / 2. )*im.h;
        int bot = ( b.y + b.h / 2. )*im.h;

        if( left < 0 ) left = 0;
        if( right > im.w - 1 ) right = im.w - 1;
        if( top < 0 ) top = 0;
        if( bot > im.h - 1 ) bot = im.h - 1;

        left = ofMap( left, 0, net.w, 0, originalWidth );
        top = ofMap( top, 0, net.h, 0, originalHeight );
        right = ofMap( right, 0, net.w, 0, originalWidth );
        bot = ofMap( bot, 0, net.h, 0, originalHeight );

        ofRectangle rect = ofRectangle( left, top, right - left, bot - top );
        int rect_idx = floor(idx / l.n);
        
        float overlap = 0.0;
        for (auto d : detections) {
            float left = max(rect.x, d.rect.x);
            float right = min(rect.x+rect.width, d.rect.x+d.rect.width);
            float bottom = min(rect.y+rect.height, d.rect.y+d.rect.height);
            float top = max(rect.y, d.rect.y);
            float area_intersection = max(0.0f, right-left) * max(0.0f, bottom-top);
            overlap = max(overlap, area_intersection / (rect.getWidth() * rect.getHeight()));
        }
        if (overlap > maxOverlap) {
            continue;
        }

        detected_object detection;
        detection.label = names[ class1 ];
        detection.probability = prob;
        detection.rect = rect;
        detection.color = ofColor( red * 255, green * 255, blue * 255);

        for (int f=0; f<l1.c; f++) {
            detection.features.push_back(features[rect_idx + l1.w * l1.h * f]);
        }
        
        detections.push_back( detection );
    }
    
    free_ptrs((void**) probs, num);
    free(boxes);

	return detections;
}
Пример #18
0
void EfficiencyLxy(){

  TString fname = "mGamma_0250_ctau1";
  TFile *f = new TFile(fname+".root");

  f->cd("Analysis");
  f->ls();

  Int_t ev;
  Int_t run;
  Int_t lumi;
  Int_t   genm;
  Int_t   trig;
  Float_t ptgenm[20];
  Float_t etagenm[20];
  Int_t recm;
  Float_t ptrecm[20];
  Float_t etarecm[20];
  Float_t phirecm[20];
  Int_t mjets;
  Int_t mj1mu;
  Int_t mj2mu;
  Float_t ptmumj1[20];
  Float_t ptmumj2[20];
  Float_t etamumj1[20];
  Float_t etamumj2[20];
  Int_t vtx;
  Float_t gen_dzmj1_0;
  Float_t gen_dzmj1_1;
  Float_t gen_mj1_0_pt;
  Float_t gen_mj1_1_pt;
  Float_t gen_mj1_0_eta;
  Float_t gen_mj1_1_eta;
  Float_t gen_mj1_0_phi;
  Float_t gen_mj1_1_phi;
  Float_t gen_dzmj2_0;
  Float_t gen_dzmj2_1;
  Float_t gen_mj2_0_pt;
  Float_t gen_mj2_1_pt;
  Float_t gen_mj2_0_eta;
  Float_t gen_mj2_1_eta;
  Float_t gen_mj2_0_phi;
  Float_t gen_mj2_1_phi;
  Float_t lxy_ge_1_0;
  Float_t lxy_ge_1_1;
  Float_t lxy_ge_2_0;
  Float_t lxy_ge_2_1;

  TTree *t = (TTree*)f->Get("Analysis/Events");

  TCanvas* c1 = new TCanvas("c1","Example",800,600);  

  c1->SetFillColor(0);
  gStyle->SetPalette(1);
  gStyle->SetOptStat(0);  
  // SetPlotStyle();

  t->SetBranchAddress("lxy_ge_1_0", &lxy_ge_1_0);
  t->SetBranchAddress("lxy_ge_1_1", &lxy_ge_1_1);
  t->SetBranchAddress("lxy_ge_2_0", &lxy_ge_2_0);
  t->SetBranchAddress("lxy_ge_2_1", &lxy_ge_2_1);

  t->SetBranchAddress("gen_dzmj1_0", &gen_dzmj1_0);
  t->SetBranchAddress("gen_dzmj1_1", &gen_dzmj1_1);
  t->SetBranchAddress("gen_mj1_0_pt", &gen_mj1_0_pt);
  t->SetBranchAddress("gen_mj1_1_pt", &gen_mj1_1_pt);
  t->SetBranchAddress("gen_mj1_0_eta", &gen_mj1_0_eta);
  t->SetBranchAddress("gen_mj1_1_eta", &gen_mj1_1_eta);

  t->SetBranchAddress("gen_mj1_0_phi", &gen_mj1_0_phi);
  t->SetBranchAddress("gen_mj1_1_phi", &gen_mj1_1_phi);

  t->SetBranchAddress("gen_dzmj2_0", &gen_dzmj2_0);
  t->SetBranchAddress("gen_dzmj2_1", &gen_dzmj2_1);
  t->SetBranchAddress("gen_mj2_0_pt", &gen_mj2_0_pt);
  t->SetBranchAddress("gen_mj2_1_pt", &gen_mj2_1_pt);
  t->SetBranchAddress("gen_mj2_0_eta", &gen_mj2_0_eta);
  t->SetBranchAddress("gen_mj2_1_eta", &gen_mj2_1_eta);
  t->SetBranchAddress("gen_mj2_0_phi", &gen_mj2_0_phi);
  t->SetBranchAddress("gen_mj2_1_phi", &gen_mj2_1_phi);

  t->SetBranchAddress("event",&ev);
  t->SetBranchAddress("run",&run);
  t->SetBranchAddress("lumi",&lumi);
  t->SetBranchAddress("trigger",&trig);
  t->SetBranchAddress("isVtx",&vtx);

  t->SetBranchAddress("genmuons",&genm);
  t->SetBranchAddress("ptgenMuons",&ptgenm);
  t->SetBranchAddress("etagenMuons",&etagenm);
  
  t->SetBranchAddress("recmuons",&recm);
  t->SetBranchAddress("ptrecMuons",&ptrecm);
  t->SetBranchAddress("etarecMuons",&etarecm);
  t->SetBranchAddress("phirecMuons",&phirecm);

  t->SetBranchAddress("recmujets",&mjets);
  t->SetBranchAddress("mj1muons",&mj1mu);
  t->SetBranchAddress("mj2muons",&mj2mu);

  t->SetBranchAddress("ptmj1muons",&ptmumj1);
  t->SetBranchAddress("ptmj2muons",&ptmumj2);
  t->SetBranchAddress("etamj1muons",&etamumj1);
  t->SetBranchAddress("etamj2muons",&etamumj2);

  Float_t bin_edges[19]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36};
  Float_t bin_center[18];
  Float_t errbin_center[18];
  Float_t erry[18];

  Float_t bin_edges_lxy[19]={0,2,4,6,8,10,12,14,16,18,20,25,30,35,40,45,50,60,80};
  Float_t bin_center_lxy[18];
  Float_t errbin_center_lxy[18];
  Float_t erry_lxy[18];


  for(int k=0;k<18;k++){
    bin_center[k] = bin_edges[k] + ( (bin_edges[k+1]-bin_edges[k])/2.0);
    errbin_center[k] = ( (bin_edges[k+1]-bin_edges[k])/2.0);
    erry[k] = 0.0;
    bin_center_lxy[k] = bin_edges_lxy[k] + ( (bin_edges_lxy[k+1]-bin_edges_lxy[k])/2.0);
    errbin_center_lxy[k] = ( (bin_edges_lxy[k+1]-bin_edges_lxy[k])/2.0);
    erry_lxy[k] = 0.0;
  }


  //===============================================
  Float_t count_barrel_muonPair_1_0[18]={0.0};
  Float_t count_rec_barrel_muonPair_1_0[18]={0.0};
  Float_t count_barrel_muonPair_1_1[18]={0.0};
  Float_t count_rec_barrel_muonPair_1_1[18]={0.0};
  Float_t count_endcap_muonPair_1_0[18]={0.0};
  Float_t count_rec_endcap_muonPair_1_0[18]={0.0};
  Float_t count_endcap_muonPair_1_1[18]={0.0};
  Float_t count_rec_endcap_muonPair_1_1[18]={0.0};

  Float_t count_barrel_muonPair_2_0[18]={0.0};
  Float_t count_rec_barrel_muonPair_2_0[18]={0.0};
  Float_t count_barrel_muonPair_2_1[18]={0.0};
  Float_t count_rec_barrel_muonPair_2_1[18]={0.0};
  Float_t count_endcap_muonPair_2_0[18]={0.0};
  Float_t count_rec_endcap_muonPair_2_0[18]={0.0};
  Float_t count_endcap_muonPair_2_1[18]={0.0};
  Float_t count_rec_endcap_muonPair_2_1[18]={0.0};

  Float_t count_lxy_barrel_muonPair_1_0[18]={0.0};
  Float_t count_lxy_rec_barrel_muonPair_1_0[18]={0.0};
  Float_t count_lxy_barrel_muonPair_1_1[18]={0.0};
  Float_t count_lxy_rec_barrel_muonPair_1_1[18]={0.0};
  Float_t count_lxy_endcap_muonPair_1_0[18]={0.0};
  Float_t count_lxy_rec_endcap_muonPair_1_0[18]={0.0};
  Float_t count_lxy_endcap_muonPair_1_1[18]={0.0};
  Float_t count_lxy_rec_endcap_muonPair_1_1[18]={0.0};

  Float_t count_lxy_barrel_muonPair_2_0[18]={0.0};
  Float_t count_lxy_rec_barrel_muonPair_2_0[18]={0.0};
  Float_t count_lxy_barrel_muonPair_2_1[18]={0.0};
  Float_t count_lxy_rec_barrel_muonPair_2_1[18]={0.0};
  Float_t count_lxy_endcap_muonPair_2_0[18]={0.0};
  Float_t count_lxy_rec_endcap_muonPair_2_0[18]={0.0};
  Float_t count_lxy_endcap_muonPair_2_1[18]={0.0};
  Float_t count_lxy_rec_endcap_muonPair_2_1[18]={0.0};



  Int_t nentries = t->GetEntries();

  Int_t mcount[4]={0};
  Int_t rmcount[4]={0};


  bool verbose = false;
  int entries = 0;
  for(int k=0;k<nentries;k++){
    t->GetEntry(k);
    entries++;
    if (entries % 500 == 0) std::cout << "entries: " << entries << ", " << (entries*1.0/80000.0)*100.0 << " % " << std::endl;

    verbose = false;
    

    Int_t hptm_count=0;
    Int_t m_count=0;
    for(int j=0;j<genm;j++){
      if(ptgenm[j]>17.0 && fabs(etagenm[j])<0.9) hptm_count++;
      if(ptgenm[j]>8.0 && fabs(etagenm[j])<2.4) m_count++;
      if (verbose) std::cout << "ptgenm[j]: " << ptgenm[j] << ", fabs(etagenm[j]): " << fabs(etagenm[j]) << std::endl;
    }

    if(hptm_count>0){
      mcount[0]++;
      if(m_count>1) mcount[1]++;
      if(m_count>2) mcount[2]++;
      if(m_count>3) mcount[3]++;
    }

    if(hptm_count>0 && mcount>3){

      bool lxy = true;
      bool dz = false;

      if (gen_mj1_0_pt > 8 && gen_mj1_1_pt > 8 && gen_mj2_1_pt > 8 && gen_mj2_1_pt > 8){

        bool matchRec11 = false;
        double dphi11 = 1000.0;
        double deta11 = 1000.0;
        double dR11 = 1000.0;
        int match11 = 100;

        bool matchRec12 = false;
        double dphi12 = 1000.0;
        double deta12 = 1000.0;
        double dR12 = 1000.0;
        int match12 = 100;

        bool matchRec21 = false;
        double dphi21 = 1000.0;
        double deta21 = 1000.0;
        double dR21 = 1000.0;
        int match21 = 100;

        bool matchRec22 = false;
        double dphi22 = 1000.0;
        double deta22 = 1000.0;
        double dR22 = 1000.0;
        int match22 = 100;

        for(int j=0;j<recm;j++){

          if(ptrecm[j]<8.0 || fabs(etarecm[j])>2.4) continue;
    
          dphi11 = My_dPhi(phirecm[j], gen_mj1_0_phi); 
          dphi12 = My_dPhi(phirecm[j], gen_mj1_1_phi); 
          deta11 = (etarecm[j] - gen_mj1_0_eta); 
          deta12 = (etarecm[j] - gen_mj1_1_eta); 
          dR11 = sqrt(dphi11*dphi11+deta11*deta11);
          dR12 = sqrt(dphi12*dphi12+deta12*deta12);
          if(dR11<0.5){
            matchRec11 = true;
            match11 = j;
          }
          if(dR12<0.5){
            matchRec12 = true;
            match12 = j;
          }

          dphi21 = My_dPhi(phirecm[j], gen_mj2_0_phi); 
          dphi22 = My_dPhi(phirecm[j], gen_mj2_1_phi); 
          deta21 = (etarecm[j] - gen_mj2_0_eta); 
          deta22 = (etarecm[j] - gen_mj2_1_eta); 
          dR21 = sqrt(dphi21*dphi21+deta21*deta21);
          dR22 = sqrt(dphi22*dphi22+deta22*deta22);
          if(dR21<0.5){
            matchRec21 = true;
            match21 = j;
          }
          if(dR22<0.5){
            matchRec22 = true;
            match22 = j;
          }

        }

        for(int m=0;m<18;m++){

          if(fabs(lxy_ge_1_0)>bin_edges_lxy[m] && fabs(lxy_ge_1_0)<bin_edges_lxy[m+1]){
            if (fabs(gen_mj1_0_eta) < 0.8){
              count_lxy_barrel_muonPair_1_0[m]++;
            }
            if (fabs(gen_mj1_0_eta) > 0.8) count_lxy_endcap_muonPair_1_0[m]++;
            if (matchRec11){
              if (fabs(gen_mj1_0_eta) < 0.8){
                count_lxy_rec_barrel_muonPair_1_0[m]++;
              }
              if (fabs(gen_mj1_0_eta) > 0.8) count_lxy_rec_endcap_muonPair_1_0[m]++;
              if (verbose) std::cout << "event: " << ev << " gen1 pt: " << gen_mj1_0_pt << ", gen1 eta: " << gen_mj1_0_eta << ", rec match pt: " << ptrecm[match11] << ", rec match eta " << etarecm[match11] << ", lxy: " << lxy_ge_1_0 << std::endl; 
            }
          }
          if(fabs(lxy_ge_1_1)>bin_edges_lxy[m] && fabs(lxy_ge_1_1)<bin_edges_lxy[m+1]){
            if (fabs(gen_mj1_1_eta) < 0.8) count_lxy_barrel_muonPair_1_1[m]++;
            if (fabs(gen_mj1_1_eta) > 0.8) count_lxy_endcap_muonPair_1_1[m]++;
            if (matchRec12){
              if (fabs(gen_mj1_1_eta) < 0.8) count_lxy_rec_barrel_muonPair_1_1[m]++;
              if (fabs(gen_mj1_1_eta) > 0.8) count_lxy_rec_endcap_muonPair_1_1[m]++;
              if (verbose) std::cout << "event: " << ev << " gen1 pt: " << gen_mj1_1_pt << ", gen1 eta: " << gen_mj1_1_eta << ", rec match pt: " << ptrecm[match12] << ", rec match eta " << etarecm[match12] << ", lxy: " << lxy_ge_1_1 << std::endl; 
            }
          }
          if(fabs(lxy_ge_2_0)>bin_edges_lxy[m] && fabs(lxy_ge_2_0)<bin_edges_lxy[m+1]){
            if (fabs(gen_mj2_0_eta) < 0.8){
              count_lxy_barrel_muonPair_2_0[m]++;
            }
            if (fabs(gen_mj2_0_eta) > 0.8) count_lxy_endcap_muonPair_2_0[m]++;
            if (matchRec21){
              if (fabs(gen_mj2_0_eta) < 0.8){
                count_lxy_rec_barrel_muonPair_2_0[m]++;
              }
              if (fabs(gen_mj2_0_eta) > 0.8) count_lxy_rec_endcap_muonPair_2_0[m]++;
              if (verbose) std::cout << "event: " << ev << " gen1 pt: " << gen_mj2_0_pt << ", gen1 eta: " << gen_mj2_0_eta << ", rec match pt: " << ptrecm[match21] << ", rec match eta " << etarecm[match21] << ", lxy: " << lxy_ge_2_0 << std::endl; 
            }
          }
          if(fabs(lxy_ge_2_1)>bin_edges_lxy[m] && fabs(lxy_ge_2_1)<bin_edges_lxy[m+1]){
            if (fabs(gen_mj2_1_eta) < 0.8){
              count_lxy_barrel_muonPair_2_1[m]++;
            }
            if (fabs(gen_mj2_1_eta) > 0.8) count_lxy_endcap_muonPair_2_1[m]++;
            if (matchRec22){
              if (fabs(gen_mj2_1_eta) < 0.8){
                count_lxy_rec_barrel_muonPair_2_1[m]++;
              }
              if (fabs(gen_mj2_1_eta) > 0.8) count_lxy_rec_endcap_muonPair_2_1[m]++;
              if (verbose) std::cout << "event: " << ev << " gen1 pt: " << gen_mj2_1_pt << ", gen1 eta: " << gen_mj2_1_eta << ", rec match pt: " << ptrecm[match22] << ", rec match eta " << etarecm[match22] << ", lxy: " << lxy_ge_2_1 << std::endl; 
            }
          }
        }
      }
    }
  }
      

  std::cout << "entries: " << entries << std::endl;

  std::cout << "Entries loop finished" << std::endl;

  Float_t rval_barrel_lxy_muonPair_1_0[30]={0.0};
  Float_t rval_endcap_lxy_muonPair_1_0[30]={0.0};
  Float_t rval_barrel_lxy_muonPair_1_1[30]={0.0};
  Float_t rval_endcap_lxy_muonPair_1_1[30]={0.0};

  Float_t erval_barrel_lxy_muonPair_1_0[30]={0.0};
  Float_t erval_endcap_lxy_muonPair_1_0[30]={0.0};
  Float_t erval_barrel_lxy_muonPair_1_1[30]={0.0};
  Float_t erval_endcap_lxy_muonPair_1_1[30]={0.0};

  Float_t rval_barrel_lxy_muonPair_2_0[30]={0.0};
  Float_t rval_endcap_lxy_muonPair_2_0[30]={0.0};
  Float_t rval_barrel_lxy_muonPair_2_1[30]={0.0};
  Float_t rval_endcap_lxy_muonPair_2_1[30]={0.0};

  Float_t erval_barrel_lxy_muonPair_2_0[30]={0.0};
  Float_t erval_endcap_lxy_muonPair_2_0[30]={0.0};
  Float_t erval_barrel_lxy_muonPair_2_1[30]={0.0};
  Float_t erval_endcap_lxy_muonPair_2_1[30]={0.0};



  std::cout << "Starting fill" << std::endl;
  for(int k=0;k<18;k++) {

    if(count_lxy_barrel_muonPair_1_0[k]!=0) rval_barrel_lxy_muonPair_1_0[k] = count_lxy_rec_barrel_muonPair_1_0[k]/count_lxy_barrel_muonPair_1_0[k];
    if(count_lxy_endcap_muonPair_1_0[k]!=0) rval_endcap_lxy_muonPair_1_0[k] = count_lxy_rec_endcap_muonPair_1_0[k]/count_lxy_endcap_muonPair_1_0[k];

    if(count_lxy_barrel_muonPair_1_1[k]!=0) rval_barrel_lxy_muonPair_1_1[k] = count_lxy_rec_barrel_muonPair_1_1[k]/count_lxy_barrel_muonPair_1_1[k];
    if(count_lxy_endcap_muonPair_1_1[k]!=0) rval_endcap_lxy_muonPair_1_1[k] = count_lxy_rec_endcap_muonPair_1_1[k]/count_lxy_endcap_muonPair_1_1[k];

    if(count_lxy_barrel_muonPair_1_0[k]!=0 ) erval_barrel_lxy_muonPair_1_0[k] = sqrt( (rval_barrel_lxy_muonPair_1_0[k]*(1-rval_barrel_lxy_muonPair_1_0[k]))/count_lxy_barrel_muonPair_1_0[k]);
    if(count_lxy_endcap_muonPair_1_0[k]!=0) erval_endcap_lxy_muonPair_1_0[k] = sqrt( (rval_endcap_lxy_muonPair_1_0[k]*(1-rval_endcap_lxy_muonPair_1_0[k]))/count_lxy_endcap_muonPair_1_0[k]);

    if(count_lxy_barrel_muonPair_1_1[k]!=0 ) erval_barrel_lxy_muonPair_1_1[k] = sqrt( (rval_barrel_lxy_muonPair_1_1[k]*(1-rval_barrel_lxy_muonPair_1_1[k]))/count_lxy_barrel_muonPair_1_1[k]);
    if(count_lxy_endcap_muonPair_1_1[k]!=0) erval_endcap_lxy_muonPair_1_1[k] = sqrt( (rval_endcap_lxy_muonPair_1_1[k]*(1-rval_endcap_lxy_muonPair_1_1[k]))/count_lxy_endcap_muonPair_1_1[k]);


    if(count_lxy_barrel_muonPair_2_0[k]!=0) rval_barrel_lxy_muonPair_2_0[k] = count_lxy_rec_barrel_muonPair_2_0[k]/count_lxy_barrel_muonPair_2_0[k];
    if(count_lxy_endcap_muonPair_2_0[k]!=0) rval_endcap_lxy_muonPair_2_0[k] = count_lxy_rec_endcap_muonPair_2_0[k]/count_lxy_endcap_muonPair_2_0[k];

    if(count_lxy_barrel_muonPair_2_1[k]!=0) rval_barrel_lxy_muonPair_2_1[k] = count_lxy_rec_barrel_muonPair_2_1[k]/count_lxy_barrel_muonPair_2_1[k];
    if(count_lxy_endcap_muonPair_2_1[k]!=0) rval_endcap_lxy_muonPair_2_1[k] = count_lxy_rec_endcap_muonPair_2_1[k]/count_lxy_endcap_muonPair_2_1[k];

    if(count_lxy_barrel_muonPair_2_0[k]!=0 ) erval_barrel_lxy_muonPair_2_0[k] = sqrt( (rval_barrel_lxy_muonPair_2_0[k]*(1-rval_barrel_lxy_muonPair_2_0[k]))/count_lxy_barrel_muonPair_2_0[k]);
    if(count_lxy_endcap_muonPair_2_0[k]!=0) erval_endcap_lxy_muonPair_2_0[k] = sqrt( (rval_endcap_lxy_muonPair_2_0[k]*(1-rval_endcap_lxy_muonPair_2_0[k]))/count_lxy_endcap_muonPair_2_0[k]);

    if(count_lxy_barrel_muonPair_2_1[k]!=0 ) erval_barrel_lxy_muonPair_2_1[k] = sqrt( (rval_barrel_lxy_muonPair_2_1[k]*(1-rval_barrel_lxy_muonPair_2_1[k]))/count_lxy_barrel_muonPair_2_1[k]);
    if(count_lxy_endcap_muonPair_2_1[k]!=0) erval_endcap_lxy_muonPair_2_1[k] = sqrt( (rval_endcap_lxy_muonPair_2_1[k]*(1-rval_endcap_lxy_muonPair_2_1[k]))/count_lxy_endcap_muonPair_2_1[k]);

  }


  std::cout << "Starting TGraphs:" << std::endl;

  TGraphErrors *gr_r_barrel_lxy_muonPair_1_0 = new TGraphErrors(18,bin_center_lxy,rval_barrel_lxy_muonPair_1_0,errbin_center_lxy,erval_barrel_lxy_muonPair_1_0);
  TGraphErrors *gr_r_endcap_lxy_muonPair_1_0 = new TGraphErrors(18,bin_center_lxy,rval_endcap_lxy_muonPair_1_0,errbin_center_lxy,erval_endcap_lxy_muonPair_1_0);
  TGraphErrors *gr_r_barrel_lxy_muonPair_1_1 = new TGraphErrors(18,bin_center_lxy,rval_barrel_lxy_muonPair_1_1,errbin_center_lxy,erval_barrel_lxy_muonPair_1_1);
  TGraphErrors *gr_r_endcap_lxy_muonPair_1_1 = new TGraphErrors(18,bin_center_lxy,rval_endcap_lxy_muonPair_1_1,errbin_center_lxy,erval_endcap_lxy_muonPair_1_1);

  TGraphErrors *gr_r_barrel_lxy_muonPair_2_0 = new TGraphErrors(18,bin_center_lxy,rval_barrel_lxy_muonPair_2_0,errbin_center_lxy,erval_barrel_lxy_muonPair_2_0);
  TGraphErrors *gr_r_endcap_lxy_muonPair_2_0 = new TGraphErrors(18,bin_center_lxy,rval_endcap_lxy_muonPair_2_0,errbin_center_lxy,erval_endcap_lxy_muonPair_2_0);
  TGraphErrors *gr_r_barrel_lxy_muonPair_2_1 = new TGraphErrors(18,bin_center_lxy,rval_barrel_lxy_muonPair_2_1,errbin_center_lxy,erval_barrel_lxy_muonPair_2_1);
  TGraphErrors *gr_r_endcap_lxy_muonPair_2_1 = new TGraphErrors(18,bin_center_lxy,rval_endcap_lxy_muonPair_2_1,errbin_center_lxy,erval_endcap_lxy_muonPair_2_1);



  TCanvas *c = new TCanvas("c","c");

  TLegend *leg3 = new TLegend(0.7,0.65,0.825,0.85);

  gr_r_barrel_lxy_muonPair_2_0->GetXaxis()->SetTitle("Lxy [cm]");
  gr_r_barrel_lxy_muonPair_2_0->GetYaxis()->SetTitle("efficiency");
  gr_r_barrel_lxy_muonPair_2_0->SetTitle("");

  gr_r_barrel_lxy_muonPair_2_0->SetLineColor(kRed);
  gr_r_barrel_lxy_muonPair_2_0->SetMarkerColor(kRed);
  gr_r_barrel_lxy_muonPair_2_0->Draw("APL");
  gr_r_barrel_lxy_muonPair_2_0->GetYaxis()->SetRangeUser(0.0,1.0);
  gr_r_barrel_lxy_muonPair_2_1->GetYaxis()->SetRangeUser(0.0,1.0);
  // gr_r_barrel_lxy_muonPair_2_0->GetXaxis()->SetRangeUser(0.0,30.0);
  // gr_r_barrel_lxy_muonPair_2_0->GetXaxis()->SetRangeUser(0.0,30.0);

  gr_r_endcap_lxy_muonPair_2_0->SetLineColor(kRed);
  gr_r_endcap_lxy_muonPair_2_0->SetMarkerColor(kRed);
  gr_r_endcap_lxy_muonPair_2_0->SetLineStyle(2);
  gr_r_endcap_lxy_muonPair_2_0->Draw("PLsame");

  gr_r_barrel_lxy_muonPair_2_1->SetLineColor(kBlack);
  gr_r_barrel_lxy_muonPair_2_1->SetMarkerColor(kBlack);
  gr_r_endcap_lxy_muonPair_2_1->SetLineColor(kBlack);
  gr_r_endcap_lxy_muonPair_2_1->SetMarkerColor(kBlack);
  gr_r_endcap_lxy_muonPair_2_1->SetLineStyle(2);
  gr_r_endcap_lxy_muonPair_2_1->Draw("PLsame");
  gr_r_barrel_lxy_muonPair_2_1->Draw("PLsame");


  TLine pix1(4.4, 1e-8, 4.4,1.0);
  pix1.SetLineStyle(2); pix1.SetLineWidth(1); pix1.SetLineColor(kBlue);
  pix1.Draw("same");
  TLine pix2(7.3, 1e-8, 7.3,1.0);
  pix2.SetLineStyle(2); pix2.SetLineWidth(1); pix2.SetLineColor(kBlue);
  pix2.Draw("same");
  TLine pix3(10.2, 1e-8, 10.2,1.0);
  pix3.SetLineStyle(2); pix3.SetLineWidth(1); pix3.SetLineColor(kBlue);
  pix3.Draw("same");
  TLine trk1(22,1e-8,22,1.0);
  trk1.SetLineStyle(2); trk1.SetLineWidth(1); trk1.SetLineColor(kGreen);
  trk1.Draw("same");
  TLine trk2(60, 1e-8, 60,1.0);
  trk2.SetLineStyle(2); trk2.SetLineWidth(1); trk2.SetLineColor(kGreen);
  trk2.Draw("same");



  leg3->SetBorderSize(0);
  leg3->SetFillColor(0);
  leg3->SetTextSize(0.036);
  leg3->AddEntry(gr_r_barrel_lxy_muonPair_2_0,"|#eta_{#gamma D}|<0.8 A1 #mu_{0}","PL");
  leg3->AddEntry(gr_r_endcap_lxy_muonPair_2_0,"|#eta_{#gamma D}|>0.8 A1 #mu_{0}","PL");
  leg3->AddEntry(gr_r_barrel_lxy_muonPair_2_1,"|#eta_{#gamma D}|<0.8 A1 #mu_{1}","PL");
  leg3->AddEntry(gr_r_endcap_lxy_muonPair_2_1,"|#eta_{#gamma D}|>0.8 A1 #mu_{1}","PL");

  leg3->Draw("same");
  c->SaveAs(fname+"_eff_eta_lxy_1D_A1.pdf","recreate");
  c->Clear();

  TLegend *leg4 = new TLegend(0.7,0.65,0.825,0.85);

  gr_r_barrel_lxy_muonPair_1_0->GetXaxis()->SetTitle("Lxy [cm]");
  gr_r_barrel_lxy_muonPair_1_0->GetYaxis()->SetTitle("efficiency");
  gr_r_barrel_lxy_muonPair_1_0->SetTitle("");

  gr_r_barrel_lxy_muonPair_1_0->SetLineColor(kRed);
  gr_r_barrel_lxy_muonPair_1_0->SetMarkerColor(kRed);
  gr_r_barrel_lxy_muonPair_1_0->Draw("APL");
  gr_r_barrel_lxy_muonPair_1_0->GetYaxis()->SetRangeUser(0.0,1.0);
  gr_r_barrel_lxy_muonPair_1_1->GetYaxis()->SetRangeUser(0.0,1.0);
  // gr_r_barrel_lxy_muonPair_1_0->GetXaxis()->SetRangeUser(0.0,30.0);
  // gr_r_barrel_lxy_muonPair_1_0->GetXaxis()->SetRangeUser(0.0,30.0);

  gr_r_endcap_lxy_muonPair_1_0->SetLineColor(kRed);
  gr_r_endcap_lxy_muonPair_1_0->SetMarkerColor(kRed);
  gr_r_endcap_lxy_muonPair_1_0->SetLineStyle(2);
  gr_r_endcap_lxy_muonPair_1_0->Draw("PLsame");

  gr_r_barrel_lxy_muonPair_1_1->SetLineColor(kBlack);
  gr_r_barrel_lxy_muonPair_1_1->SetMarkerColor(kBlack);
  gr_r_endcap_lxy_muonPair_1_1->SetLineColor(kBlack);
  gr_r_endcap_lxy_muonPair_1_1->SetMarkerColor(kBlack);
  gr_r_endcap_lxy_muonPair_1_1->SetLineStyle(2);
  gr_r_endcap_lxy_muonPair_1_1->Draw("PLsame");
  gr_r_barrel_lxy_muonPair_1_1->Draw("PLsame");

  pix1.Draw("same");
  pix2.Draw("same");
  pix3.Draw("same");
  trk1.Draw("same");
  trk2.Draw("same");

  leg4->SetBorderSize(0);
  leg4->SetFillColor(0);
  leg4->SetTextSize(0.036);
  leg4->AddEntry(gr_r_barrel_lxy_muonPair_1_0,"|#eta_{#gamma D}|<0.8 A0 #mu_{0}","PL");
  leg4->AddEntry(gr_r_endcap_lxy_muonPair_1_0,"|#eta_{#gamma D}|>0.8 A0 #mu_{0}","PL");
  leg4->AddEntry(gr_r_barrel_lxy_muonPair_1_1,"|#eta_{#gamma D}|<0.8 A0 #mu_{1}","PL");
  leg4->AddEntry(gr_r_endcap_lxy_muonPair_1_1,"|#eta_{#gamma D}|>0.8 A0 #mu_{1}","PL");

  leg4->Draw("same");
  c->SaveAs(fname+"_eff_eta_lxy_1D_A0.pdf","recreate");
  c->Clear();



}
Пример #19
0
QVariant QgsSymbolV2LegendNode::data( int role ) const
{
  if ( role == Qt::DisplayRole )
  {
    return mLabel;
  }
  else if ( role == Qt::EditRole )
  {
    return mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
  }
  else if ( role == Qt::DecorationRole )
  {
    QSize iconSize( 16, 16 ); // TODO: configurable
    const int indentSize = 20;
    if ( mPixmap.isNull() )
    {
      QPixmap pix;
      if ( mItem.symbol() )
      {
        double scale = 0.0;
        double mupp = 0.0;
        int dpi = 0;
        if ( model() )
          model()->legendMapViewData( &mupp, &dpi, &scale );
        bool validData = mupp != 0 && dpi != 0 && scale != 0;

        // setup temporary render context
        QgsRenderContext context;
        context.setScaleFactor( dpi / 25.4 );
        context.setRendererScale( scale );
        context.setMapToPixel( QgsMapToPixel( mupp ) ); // hope it's ok to leave out other params

        pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( mItem.symbol(), iconSize, validData ? &context : 0 );
      }
      else
      {
        pix = QPixmap( iconSize );
        pix.fill( Qt::transparent );
      }

      if ( mItem.level() == 0 )
        mPixmap = pix;
      else
      {
        // ident the symbol icon to make it look like a tree structure
        QPixmap pix2( pix.width() + mItem.level() * indentSize, pix.height() );
        pix2.fill( Qt::transparent );
        QPainter p( &pix2 );
        p.drawPixmap( mItem.level() * indentSize, 0, pix );
        p.end();
        mPixmap = pix2;
      }
    }
    return mPixmap;
  }
  else if ( role == Qt::CheckStateRole )
  {
    if ( !mItem.isCheckable() )
      return QVariant();

    QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
    if ( !vlayer || !vlayer->rendererV2() )
      return QVariant();

    return vlayer->rendererV2()->legendSymbolItemChecked( mItem.ruleKey() ) ? Qt::Checked : Qt::Unchecked;
  }
  else if ( role == RuleKeyRole )
  {
    return mItem.ruleKey();
  }
  else if ( role == SymbolV2LegacyRuleKeyRole )
  {
    return QVariant::fromValue<void*>( mItem.legacyRuleKey() );
  }

  return QVariant();
}