void MainWindow::contextMenuRequest(QPoint pos)
{
    if (ui->customPlot->legend->selectTest(pos, false) >= 0) // context menu on legend requested
    {
        QMenu *menu = new QMenu(this);
        menu->setAttribute(Qt::WA_DeleteOnClose);
        menu->addAction("Move to top left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignLeft));
        menu->addAction("Move to top center", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignHCenter));
        menu->addAction("Move to top right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignRight));
        menu->addAction("Move to bottom right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignRight));
        menu->addAction("Move to bottom left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignLeft));
        menu->popup(ui->customPlot->mapToGlobal(pos));
    }
}
Exemple #2
0
void createSystFile(TVersion_t inpVer,
		    CrossSection_t &eeCS, TVaried_t var, int doSave)
{
  std::cout << "createSystFile for inpVer=" << versionName(inpVer) << "\n";

  if (var!=_varRhoSyst) {
    std::cout << "createSystFile is not ready for var="
	      << variedVarName(var) << "\n";
    return;
  }

  TCanvas *c= eeCS.plotCrossSection("cs");
  c->Update();
  TH1D *h1cs_file= cloneHisto(eeCS.h1PreFsrCS(),"h1cs_file","h1cs_file");

  std::vector<TH1D*> h1RhoV;
  TString fname="dyee-rho-syst2.root";
  TFile fin(fname);
  if (!fin.IsOpen()) {
    std::cout << "failed to open the file <" << fin.GetName() << ">\n";
    return;
  }
  for (TTnPSystType_t syst= _tnpSyst_none; syst!=_tnpSyst_last; next(syst)) {
    TString hname="h1rho_";
    if (syst==_tnpSyst_none) hname.Append("stat");
    else hname.Append(tnpSystName(syst,1));
    TString newHName=hname;
    if (syst==_tnpSyst_none) newHName.ReplaceAll("stat","orig");
    TH1D *h1= loadHisto(fin,hname,newHName,1,h1dummy);
    h1RhoV.push_back(h1);
  }
  fin.Close();

  TCanvas *cRho=NULL;
  if (1) {
    //plotHisto(eeCS.h1Rho(),"cRho",1,0,"LPE","cs version");
    h1RhoV[0]->GetYaxis()->SetTitleOffset(1.6);
    logAxis(h1RhoV[0],1,"M_{ee} [GeV]","","\\langle\\rho\\rangle\\text{ with alt.effs}");
    cRho=plotHisto(h1RhoV[0],"cRho",1,0,"LP","orig");
    setLeftRightMargins(cRho,0.14,0.05);
    for (unsigned int i=1; i<h1RhoV.size(); i++) {
      TString legStr=h1RhoV[i]->GetName();
      legStr.ReplaceAll("h1rho_","");
      plotHistoSame(h1RhoV[i],"cRho","LP",legStr);
    }
    moveLegend(cRho,0.45,0);
  }

  std::vector<TH1D*> h1rhoRelDiffV;
  int absValues=1;
  int relativeDiff=1;
  deriveRelSyst(NULL,h1RhoV,h1rhoRelDiffV,relativeDiff,absValues);
  if (0) {
    std::cout << " : " << h1RhoV.size() << ", " << h1rhoRelDiffV.size() << "\n";
    for (unsigned int i=0; i<h1rhoRelDiffV.size(); i++) {
      printRatio(h1RhoV[0], h1RhoV[i+1]);
      printHisto(h1rhoRelDiffV[i]);
    }
    return;
  }

  TCanvas *cRhoSyst=NULL;
  if (1) {
    TString title="uncertainty";
    if (relativeDiff) title.Prepend("relative ");
    //h1rhoRelDiffV[0]->SetTitle(title);
    h1rhoRelDiffV[0]->GetYaxis()->SetRangeUser(0,0.12);
    h1rhoRelDiffV[0]->GetYaxis()->SetTitleOffset(1.6);
    TString ytitle="\\delta\\langle\\rho\\rangle";
    if (relativeDiff) ytitle= "(" + ytitle + ")_{rel}";
    //h1rhoRelDiffV[0]->GetYaxis()->SetTitle(ytitle);
    logAxis(h1rhoRelDiffV[0],3,"M_{ee} [GeV]",ytitle,title);
    cRhoSyst=plotHisto(h1rhoRelDiffV[0],"cRhoRelDiff",1,0,"LP",
				tnpSystName(TTnPSystType_t(1),1));
    setLeftRightMargins(cRhoSyst,0.14,0.05);
    for (TTnPSystType_t syst=TTnPSystType_t(2); syst!=_tnpSyst_last; next(syst))
      {
	plotHistoSame(h1rhoRelDiffV[syst-1],"cRhoRelDiff","LP",tnpSystName(syst,1));
      }
    moveLegend(cRhoSyst,0.45,0.47);
  }

  std::vector<TH1D*> h1csV;
  eeCS.var(_varRho);
  for (unsigned int i=0; i<h1RhoV.size(); i++) {
    eeCS.h1Rho(h1RhoV[i]);
    TString hname="h1cs_" + tnpSystName(TTnPSystType_t(i));
    TH1D *h1cs= cloneHisto(eeCS.calcCrossSection(0),hname,hname);
    copyStyle(h1cs,h1RhoV[i]);
    h1csV.push_back(h1cs);
  }
  std::cout << "h1csV.size=" << h1csV.size() << "\n";

  if (1) {
    TCanvas *cRhoCS= plotHisto(h1cs_file,"cRhoCS",1,1,"LP","cs_file");
    for (unsigned int i=0; i<h1csV.size(); i++) {
      plotHistoSame(h1csV[i],"cRhoCS","LP",h1csV[i]->GetName());
    }
    cRhoCS->Update();
  }

  std::vector<TH1D*> h1csRelDiffV;
  deriveRelSyst(NULL,h1csV,h1csRelDiffV,relativeDiff,absValues);
  TCanvas *cCSRhoUnc=NULL;
  if (1) {
    logAxis(h1csRelDiffV[0],3,"M_{ee} [GeV]",
	    "(\\delta\\sigma)_{\\langle\\rho\\rangle\\,syst;rel}",
	    "relative uncertainty of the cross section");
    h1csRelDiffV[0]->GetYaxis()->SetRangeUser(0,0.15);
    h1csRelDiffV[0]->GetYaxis()->SetTitleOffset(1.6);
    cCSRhoUnc= plotHisto(h1csRelDiffV[0],"cCSRhoUnc",1,0,"LP",
			 tnpSystName(TTnPSystType_t(1),1));
    setLeftRightMargins(cCSRhoUnc,0.14,0.05);
    for (TTnPSystType_t syst=TTnPSystType_t(2); syst!=_tnpSyst_last; next(syst))
      {
	plotHistoSame(h1csRelDiffV[syst-1],"cCSRhoUnc","LP",tnpSystName(syst,1));
      }
    moveLegend(cCSRhoUnc,0.45,0.47);
  }

  if (1) {
    for (unsigned int i=0; i<h1csRelDiffV.size(); i++) {
      std::cout << "\n\ni=" << i << "\n";
      printRatio(h1csRelDiffV[i],h1rhoRelDiffV[i]);
    }
  }

  if (doSave) {
    TString fname="dyeeCS-rhoSyst2.root";
    TFile fout(fname,"RECREATE");
    if (!fout.IsOpen()) {
      std::cout << "failed to create a file <" << fout.GetName() << ">\n";
      return;
    }
    for (unsigned int ih=0; ih<h1RhoV.size(); ih++) {
      h1RhoV[ih]->Write();
    }
    for (unsigned int ih=0; ih<h1rhoRelDiffV.size(); ih++) {
      h1rhoRelDiffV[ih]->Write();
    }
    for (unsigned int ih=0; ih<h1csRelDiffV.size(); ih++) {
      h1csRelDiffV[ih]->Write();
    }
    if (cRho) cRho->Write();
    if (cRhoSyst) cRhoSyst->Write();
    if (cCSRhoUnc) cCSRhoUnc->Write();
    TObjString timeTag(DayAndTimeTag(0));
    timeTag.Write("timeTag");
    fout.Close();
    std::cout << "file <" << fout.GetName() << "> created\n";
  }


  return;
}
Exemple #3
0
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: SendTotalSamples((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: on_butAppBck_clicked(); break;
        case 2: on_butRefresh_clicked(); break;
        case 3: on_butStop_clicked(); break;
        case 4: on_butStart_clicked(); break;
        case 5: on_butZoomIn_clicked(); break;
        case 6: on_butZoomOut_clicked(); break;
        case 7: on_butExit_clicked(); break;
        case 8: on_butRemoveAll_clicked(); break;
        case 9: on_butRemoveSelected_clicked(); break;
        case 10: on_butSine_clicked(); break;
        case 11: on_butSquare_clicked(); break;
        case 12: on_butTriangle_clicked(); break;
        case 13: on_butSawtooth_clicked(); break;
        case 14: on_butPulse_clicked(); break;
        case 15: on_butRandom_clicked(); break;
        case 16: on_butMergeAll_clicked(); break;
        case 17: on_actionZoom_Out_triggered(); break;
        case 18: on_actionZoomin_triggered(); break;
        case 19: on_actionRemove_Selected_triggered(); break;
        case 20: on_actionRemove_All_triggered(); break;
        case 21: on_actionRandom_triggered(); break;
        case 22: on_actionMerge_All_triggered(); break;
        case 23: on_actionPulse_triggered(); break;
        case 24: on_actionSAwtooth_triggered(); break;
        case 25: on_actionTriangle_triggered(); break;
        case 26: on_actionSquare_triggered(); break;
        case 27: on_actionSine_triggered(); break;
        case 28: titleDoubleClick((*reinterpret_cast< QMouseEvent*(*)>(_a[1])),(*reinterpret_cast< QCPPlotTitle*(*)>(_a[2]))); break;
        case 29: axisLabelDoubleClick((*reinterpret_cast< QCPAxis*(*)>(_a[1])),(*reinterpret_cast< QCPAxis::SelectablePart(*)>(_a[2]))); break;
        case 30: legendDoubleClick((*reinterpret_cast< QCPLegend*(*)>(_a[1])),(*reinterpret_cast< QCPAbstractLegendItem*(*)>(_a[2]))); break;
        case 31: selectionChanged(); break;
        case 32: mousePress(); break;
        case 33: mouseWheel(); break;
        case 34: addRandomGraph(); break;
        case 35: addSineGraph(); break;
        case 36: addSquareGraph(); break;
        case 37: addTriangleGraph(); break;
        case 38: addSawtoothGraph(); break;
        case 39: addPulseGraph(); break;
        case 40: removeSelectedGraph(); break;
        case 41: removeAllGraphs(); break;
        case 42: contextMenuRequest((*reinterpret_cast< QPoint(*)>(_a[1]))); break;
        case 43: moveLegend(); break;
        case 44: graphClicked((*reinterpret_cast< QCPAbstractPlottable*(*)>(_a[1]))); break;
        case 45: receiveValue((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 46: receiveValue((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 47: receiveValue((*reinterpret_cast< uint(*)>(_a[1]))); break;
        case 48: callLineEditInput((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 49: openWaveDataWindow(); break;
        case 50: RxSamples((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 51: RxStartTick((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 52: RxStopTick((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 53: RxDutyCycle((*reinterpret_cast< int(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 54;
    }
    return _id;
}
Exemple #4
0
void plotDYSignal(int print=0)
{
  TH1D *h1signalMM4p2= loadHisto("cs_DYmm_13TeVMuApproved_csA.root","h1Signal",
				 "h1signalMM4p2",1,h1dummy);
  TH1D *h1signalMM4p3= loadHisto("cs_DYmm_13TeVMuApproved_csB.root","h1Signal",
				 "h1signalMM4p2",1,h1dummy);
  TH1D *h1signalEE= loadHisto("cs_DYee_13TeV_El3.root","h1Signal",
			      "h1signalEE",1,h1dummy);

  double lumiMM4p2= 865.919;
  double lumiMM4p3= 2832.673 - lumiMM4p2;
  double lumiEE= 2316.969;

  h1signalMM4p2->Scale(1/lumiMM4p2);
  h1signalMM4p3->Scale(1/lumiMM4p3);
  h1signalEE->Scale(1/lumiEE);

  TString massStr= niceMassAxisLabel(2,"");
  //TString eemassStr= niceMassAxisLabel(0,"");
  //TString mmmassStr= niceMassAxisLabel(1,"");
  TString axisStr= ";" + massStr + ";signal yield/Lumi";

  TGraphErrors *grEE= createGraph(h1signalEE,"grEE", 0);
  TGraphErrors *grMM4p2= createGraph(h1signalMM4p2, "grMM4p2", -1);
  TGraphErrors *grMM4p3= createGraph(h1signalMM4p3, "grMM4p3",  1);

  printHisto(h1signalEE);
  printHisto(h1signalMM4p2);

  graphStyle(grEE, kGreen+1, 7, 1, 0.8);
  graphStyle(grMM4p2, 46, 24, 1, 0.8);
  graphStyle(grMM4p3, kBlack, 20, 1, 0.8);

  std::vector<TCanvas*> canvasV;
  for (int i=0; i<5; i++) {
    TString canvName="";
    TH2D *h2frame=NULL;
    TCanvas *cx= createMassFrame(i,"cSignal_",
				 "signal" + axisStr, 2,
				 &canvName,&h2frame);
    canvasV.push_back(cx);
    //plotHistoSame(h1csEE,canvName,"LPE1", "DY#rightarrowee");
    //plotHistoSame(h1csMM,canvName,"LPE1", "DY#rightarrow#mu#mu");
    plotGraphSame(grEE,canvName,"PE1", "DY#rightarrowee");
    plotGraphSame(grMM4p2,canvName,"PE1", "DY#rightarrow#mu#mu (HLT4.2)");
    plotGraphSame(grMM4p3,canvName,"PE1", "DY#rightarrow#mu#mu (HLT4.3)");
    if (i==1) {
      h2frame->GetYaxis()->SetTitleOffset(1.5);
      setLeftMargin(cx,0.11);
      moveLegend(cx,0.45,0.);
    }
    if (i==4) {
      h2frame->GetYaxis()->SetNoExponent(false);
      h2frame->GetYaxis()->SetTitleOffset(1.5);
      setLeftMargin(cx,0.15);
      moveLegend(cx,0.45,0.55);
    }
    if (i==5) moveLegend(cx,0.45,0.55);
  }


  if (print==1) {
    TFile fout("foutCanvas_DYSignal.root","RECREATE");
    SaveCanvases(canvasV,"dir-plot-DYSignal",&fout);
    writeTimeTag();
    fout.Close();
    std::cout << "file <" << fout.GetName() << "> created\n";
  }
}