Exemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    qDebug() << "MainWindow::MainWindow() - ThreadId: " << QThread::currentThreadId();

    x1 = new QVector<double>(INIT_DATA_SIZE);
    y1 = new QVector<double>(INIT_DATA_SIZE);
    y2 = new QVector<double>(INIT_DATA_SIZE);
    y3 = new QVector<double>(INIT_DATA_SIZE);
    y4 = new QVector<double>(INIT_DATA_SIZE);

    ui->setupUi(this);
    m_kldatabase = new KLDatabase(this);

    m_updatePlotTimer = new QTimer(this);
    m_updatePlotTimer->setInterval(5000);

    m_startAquisitionTimer = new QTimer(this);
    m_startAquisitionTimer->setSingleShot(true);


    m_acquisitionThread = new QThread(this);
    m_reader = new ReadDataWorker(m_kldatabase);

    m_reader->moveToThread(m_acquisitionThread);

    QObject::connect(m_startAquisitionTimer, SIGNAL(timeout()), this, SLOT(startAquisition()) );

    QObject::connect(m_acquisitionThread, SIGNAL(started()), m_reader, SLOT(process()) );
    QObject::connect(m_acquisitionThread, SIGNAL(finished()), m_reader, SLOT(deleteLater()) );
    QObject::connect(m_acquisitionThread, SIGNAL(finished()), m_acquisitionThread, SLOT(deleteLater()));

    QObject::connect(m_reader, SIGNAL(newData()), this, SLOT(newData()) );
    QObject::connect(m_reader, SIGNAL(readErrno(int)), this, SLOT(handleErrNo(int)) );

    QObject::connect(m_updatePlotTimer, SIGNAL(timeout()), this, SLOT(onDrawPlot()) );

    QObject::connect(ui->pushButton_1, SIGNAL(clicked()), this, SLOT(selectLongTimespan()) );
    QObject::connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(selectMediumTimespan()) );
    QObject::connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(selectShortTimespan()) );
    QObject::connect(this,SIGNAL(drawPlot()),this,SLOT(onDrawPlot()) );

    QObject::connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(onMenuExit()) );

    m_initKl = new InitWidget(this);
    m_initKl->show();
    m_pressUsb = new PressUsb(this);
    m_pressUsb->hide();
    m_timeInterval = TimeInterval::LONG;
    m_tickSpacing = TickSpacing::DAYS;

    setButtonActive(ui->pushButton_1);

    // initialize plot
    makePlot();

    m_startAquisitionTimer->start(500);

}
Exemplo n.º 2
0
void ofApp::draw(){

	//plots
	int yy;;
	int xx = 30;
	int size = 70; //of each plot
	int rowPad = 40;
	int colPad = 35;
	int vOffset = 13;
	int numCol = (ofGetWidth() - xx) / (size + colPad);
	yy = numCol * vOffset;
	int x = 0;
	int row = 0;
	int col = 0;
	for ( int i = 0 ; i < NUM_ANIM_CURVES; i++ ){
		ofColor c = ofColor::red;
		c.setHsb(fmod(128 + 3 * 255.0f * i/float(NUM_ANIM_CURVES), 255), 255, 255);
		AnimCurve curve = (AnimCurve) (EASE_IN_EASE_OUT + i);
		string curveName = ofxAnimatable::getCurveName((AnimCurve)i);
		drawPlot( xx + x, yy + row * (size + rowPad) - vOffset * col, size, curve, curveName, c );
		x += size + colPad;
		col ++;
		if (  x > ofGetWidth() -  1.0f * size - xx){
			row++;
			col = 0;
			x = 0;
		}
	}
}
Exemplo n.º 3
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    //all left animation plots
    int vOff = 8;
    for ( int i = 0 ; i < NUM_ANIM_CURVES; i++ ){
        float lineHeight = 1.35f;
        float yy = vOff + i * lineHeight * width;
        glColor4ub(255,255,255,64);
        ofLine(xMargin, yy + width * 0.5, xMargin + widthCol + width, yy + width * 0.5);
        ofColor c = ofColor::red;
        c.setHsb(fmod(128 + 3 * 255.0f * i/float(NUM_ANIM_CURVES), 255), 255, 255);
        ofSetColor(c);
        ofRect( pos[i].val(), yy, width, width);
        ofDrawBitmapString( curveNames[i] /*+ " vel: " + ofToString( pos[i].getCurrentSpeed(), 1)*/, xMargin + widthCol + 20, yy + 10);
    }
    
    //ball and floor
    colorAnim.applyCurrentColor();
    ofCircle( ( 2 * ofGetFrameNum() )%ofGetWidth(), ball.val(), width);
    
    glColor4ub(255,255,255,255);
    ofRect(0, floorLine + width, ofGetWidth(), 1);
    
    //vertical lines
    ofRect(xMargin, 0, 1, floorLine + width);
    ofRect(xMargin + widthCol + width, 0, 1, floorLine + width);
    
    glColor4f( pointAnim.getPercentDone(), 1 - pointAnim.getPercentDone() , 0, 1);
    glPointSize(10);
    pointAnim.draw();
    
    
    //plots
    int yy;;
    int xx = 300;
    int size = 70; //of each plot
    int rowPad = 30;
    int colPad = 25;
    int vOffset = 13;
    int numCol = (ofGetWidth() - xx) / (size + colPad);
    yy = numCol * vOffset;
    int x = 0;
    int row = 0;
    int col = 0;
    for ( int i = 0 ; i < NUM_ANIM_CURVES; i++ ){
        ofColor c = ofColor::red;
        c.setHsb(fmod(128 + 3 * 255.0f * i/float(NUM_ANIM_CURVES), 255), 255, 255);
        AnimCurve curve = (AnimCurve) (EASE_IN_EASE_OUT + i);
        string curveName = ofxAnimatable::getCurveName((AnimCurve)i);
        drawPlot( xx + x, yy + row * (size + rowPad) - vOffset * col, size, curve, curveName, c );
        x += size + colPad;
        col ++;
        if (  x > ofGetWidth() -  1.0f * size - xx){
            row++;
            col = 0;
            x = 0;
        }
    }
    
}
Exemplo n.º 4
0
void Experiment2D22::parallelPlot() {

	viewer->clear();
	drawaxis();
	scaling();
	drawPlot();
	viewer->refresh();
}
Exemplo n.º 5
0
 void SurfacePlot::draw(Frame *frame, int dir)
 {
   HLayout hl(*frame,.9);
   Frame f = hl.getFrame(0);
   drawPlot(&f);
   f = hl.getFrame(1);
   BorderLayout bl(f,0,0,0,
       (ylabel.size()?label_style.getPointSize():0)+axis_bottom.label_style.getPointSize()+5);
   f = bl.getFrame(0);
   drawKey(&f); // ,dir);
 }
Exemplo n.º 6
0
/**
 *	x - argument vetor
 *	y - value vector (calculated according to script)
 */
void Snakes::on_drawButton_clicked()
{
	double xMin = ui.xMinBox->value();
	double xMax = ui.xMaxBox->value();

	if (xMin >= xMax)
	{
		QMessageBox msgBox;
		msgBox.setText("Error: Xmin > Xmax !");
		msgBox.exec();
		return;
	}
	int pointsCounter = ui.pointsCounterBox->value();
	if (pointsCounter < 1)
	{
		QMessageBox msgBox;
		msgBox.setText("Error: Points counter < 1 !");
		msgBox.exec();
		return;
	}

	//Aquiring and calculating data
	double increment = (xMax - xMin) / pointsCounter;
	std::vector<double> x;
	x.push_back(xMin);
	for (int i=1; i<pointsCounter; i++)
	{
		x.push_back(x.back() + increment);
	}
	
	//TODO name of plot
	//Drawing plot
	for (std::list<QString>::iterator it = scriptFileNames.begin(); it != scriptFileNames.end(); ++it)
	{
		try {
			std::vector<double> y = calculateOutput(x, *it);
			drawPlot(x, y);
		}
		catch (ScriptException ex) {
			//Removing corrupted script file
			QByteArray byteArray = it->toLatin1();
			const char *filename = byteArray.data();
			remove(filename);
			//Removing corrupted script reference
			scriptFileNames.erase(it);

			//Error message
			QMessageBox msgBox;
			msgBox.setText("Error: failed to load script");
			msgBox.exec();
		}
	}
}
Exemplo n.º 7
0
SensorGraph::SensorGraph(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SensorGraph)
{
    ui->setupUi(this);

    this->setWindowTitle("Sensor Data");

    ui->qwtPlot->setAxisTitle(QwtPlot::yLeft, "Temperature");
    ui->qwtPlot->setAxisScale(QwtPlot::yLeft, 40, 140);

    drawPlot();
}
Exemplo n.º 8
0
//--------------------------------------------------------------
void testApp::draw(){


	int vOff = 10;
	for ( int i = 0 ; i < NUM_ANIM_CURVES; i++ ){
		float lineHeight = 2.0;
		float yy = vOff + i * lineHeight * width;
		glColor4ub(255,255,255,64);
		ofLine(300, yy + width * 0.5, 500 + width, yy + width * 0.5);
		glColor4ub(255,255,255,255);
		ofRect( pos[i].val(), yy, width, width);
		ofDrawBitmapString(  curveNames[i] + "  vel: " + ofToString( pos[i].getCurrentSpeed(), 2), 515, yy + 10);
	}

	//ball and floor
	colorAnim.applyCurrentColor();
	ofCircle( ( 2 * ofGetFrameNum() )%ofGetWidth(), ball.val(), width);
	
	glColor4ub(255,255,255,255);
	ofRect(0, 400 + width, ofGetWidth(), 1);

	//vertical lines
	ofRect(300, 0, 1, 400 + width);
	ofRect(500+width, 0, 1, 400 + width);
	
	glColor4f( pointAnim.getPercentDone(), 1 - pointAnim.getPercentDone() , 0, 1);
	glPointSize(10);
	pointAnim.draw();

	glColor4ub(255,255,255,255);
	ofDrawBitmapString( ofToString( ofGetFrameRate()),  10, 10);
	
	int c = 0;
	int size = 130;
	int yy = 450;
	int rowHeight = 180;
	int xx = 50;
	int off = size/2.5;
	int x = 0;
	int row = 0;
	for ( int i = 0 ; i < NUM_ANIM_CURVES; i++ ){
		AnimCurve curve = (AnimCurve) (EASE_IN_EASE_OUT + i);		
		drawPlot( xx + x, yy + row * rowHeight, size, curve, ofxAnimatable::getCurveName(curve) );		
		x += (size + off);
		if (  x > ofGetWidth() - 2 * size){
			row++;
			x = 0;
		}
	}
}
  void PieChartDisplay::processMessage(const std_msgs::Float32::ConstPtr& msg)
  {
    boost::mutex::scoped_lock lock(mutex_);

    if (!overlay_->isVisible()) {
      return;
    }

    overlay_->updateTextureSize(texture_size_, texture_size_ + caption_offset_);
    drawPlot(msg->data);
    overlay_->setPosition(left_, top_);
    overlay_->setDimensions(overlay_->getTextureWidth(),
                            overlay_->getTextureHeight());
  }
Exemplo n.º 10
0
void MainWindow::selectShortTimespan()
{
    //qDebug() << "15 Minuten";

    setButtonNormal(ui->pushButton_1);
    setButtonNormal(ui->pushButton_2);
    setButtonActive(ui->pushButton_3);

    setTimeInterval(TimeInterval::SHORT);
    setTickSpacing(TickSpacing::MINUTES);
    ui->customPlot->xAxis->setSubTickCount(4);
    ui->customPlot->xAxis->setDateTimeFormat("dd.MM.yy hh:mm");

    emit drawPlot();
}
Exemplo n.º 11
0
void MainWindow::selectLongTimespan()
{
    //qDebug() << "7 Tage";

    setButtonActive(ui->pushButton_1);
    setButtonNormal(ui->pushButton_2);
    setButtonNormal(ui->pushButton_3);

    setTimeInterval(TimeInterval::LONG);
    setTickSpacing(TickSpacing::DAYS);
    ui->customPlot->xAxis->setSubTickCount(3);
    ui->customPlot->xAxis->setDateTimeFormat("dd.MM.yy");

    emit drawPlot();
}
Exemplo n.º 12
0
void MainWindow::selectMediumTimespan()
{
    //qDebug() << "24 Stunden";

    setButtonNormal(ui->pushButton_1);
    setButtonActive(ui->pushButton_2);
    setButtonNormal(ui->pushButton_3);

    setTimeInterval(TimeInterval::MEDIUM);
    setTickSpacing(TickSpacing::HOURS);
    ui->customPlot->xAxis->setSubTickCount(3);
    ui->customPlot->xAxis->setDateTimeFormat("dd.MM.yy hh:mm");

    emit drawPlot();
}
 void Plotter2DDisplay::update(float wall_dt, float ros_dt)
 {
   if (draw_required_) {
     if (wall_dt + last_time_ > update_interval_) {
       overlay_->updateTextureSize(texture_width_,
                                   texture_height_ + caption_offset_);
       overlay_->setPosition(left_, top_);
       overlay_->setDimensions(overlay_->getTextureWidth(), overlay_->getTextureHeight());
       last_time_ = 0;
       drawPlot();
       draw_required_ = false;
     }
     else {
       last_time_ = last_time_ + wall_dt;
     }
   }
 }
Exemplo n.º 14
0
int SensorGraph::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0:
            drawPlot();
            break;
        default:
            ;
        }
        _id -= 1;
    }
    return _id;
}
Exemplo n.º 15
0
Histogram::Histogram(string fl) : filename(fl), ignoreZero(0), numComponents(0), xmax(0), ymax(0) {
    
    reader = vtkSmartPointer<vtkDICOMImageReader>::New() ;
    reader->SetDirectoryName(filename.c_str()) ;
    plot = vtkSmartPointer<vtkXYPlotActor>::New() ;
    numComponents = reader->GetOutput()->GetNumberOfScalarComponents() ;

    drawPlot() ;

    renderer = vtkSmartPointer<vtkRenderer>::New() ;
    renderer->AddActor(plot) ;
    renderWindow = vtkSmartPointer<vtkRenderWindow>::New() ;
    renderWindow->AddRenderer(renderer) ;
    renderWindow->SetSize(600,480) ;
    iren = new QVTKWidget ;
    iren->SetRenderWindow(renderWindow) ;

    //iren->Initialize() ;
    //interactor->Start() ;
}
Exemplo n.º 16
0
/*
 * objective : get the gray level map of the input image and rescale it to the range [0-255] if rescale0_255=TRUE, simply trunks else
 */
static void rescaleGrayLevelMat(const cv::Mat &inputMat, cv::Mat &outputMat, const float histogramClippingLimit, const bool rescale0_255)
{
    // adjust output matrix wrt the input size but single channel
    std::cout<<"Input image rescaling with histogram edges cutting (in order to eliminate bad pixels created during the HDR image creation) :"<<std::endl;
    //std::cout<<"=> image size (h,w,channels) = "<<inputMat.size().height<<", "<<inputMat.size().width<<", "<<inputMat.channels()<<std::endl;
    //std::cout<<"=> pixel coding (nbchannel, bytes per channel) = "<<inputMat.elemSize()/inputMat.elemSize1()<<", "<<inputMat.elemSize1()<<std::endl;

    // get min and max values to use afterwards if no 0-255 rescaling is used
    double maxInput, minInput, histNormRescalefactor=1.f;
    double histNormOffset=0.f;
    minMaxLoc(inputMat, &minInput, &maxInput);
    histNormRescalefactor=255.f/(maxInput-minInput);
    histNormOffset=minInput;
    std::cout<<"Hist max,min = "<<maxInput<<", "<<minInput<<" => scale, offset = "<<histNormRescalefactor<<", "<<histNormOffset<<std::endl;
    // rescale between 0-255, keeping floating point values
    cv::Mat normalisedImage;
    cv::normalize(inputMat, normalisedImage, 0.f, 255.f, cv::NORM_MINMAX);
    if (rescale0_255)
        normalisedImage.copyTo(outputMat);
    // extract a 8bit image that will be used for histogram edge cut
    cv::Mat intGrayImage;
    if (inputMat.channels()==1)
    {
        normalisedImage.convertTo(intGrayImage, CV_8U);
    } else
    {
        cv::Mat rgbIntImg;
        normalisedImage.convertTo(rgbIntImg, CV_8UC3);
        cv::cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY);
    }

    // get histogram density probability in order to cut values under above edges limits (here 5-95%)... usefull for HDR pixel errors cancellation
    cv::Mat dst, hist;
    int histSize = 256;
    calcHist(&intGrayImage, 1, 0, cv::Mat(), hist, 1, &histSize, 0);
    cv::Mat normalizedHist;

    normalize(hist, normalizedHist, 1.f, 0.f, cv::NORM_L1, CV_32F); // normalize histogram so that its sum equals 1

    // compute density probability
    cv::Mat denseProb=cv::Mat::zeros(normalizedHist.size(), CV_32F);
    denseProb.at<float>(0)=normalizedHist.at<float>(0);
    int histLowerLimit=0, histUpperLimit=0;
    for (int i=1; i<normalizedHist.size().height; ++i)
    {
        denseProb.at<float>(i)=denseProb.at<float>(i-1)+normalizedHist.at<float>(i);
        //std::cout<<normalizedHist.at<float>(i)<<", "<<denseProb.at<float>(i)<<std::endl;
        if ( denseProb.at<float>(i)<histogramClippingLimit)
            histLowerLimit=i;
        if ( denseProb.at<float>(i)<1.f-histogramClippingLimit)
            histUpperLimit=i;
    }
    // deduce min and max admitted gray levels
    float minInputValue = (float)histLowerLimit/histSize*255.f;
    float maxInputValue = (float)histUpperLimit/histSize*255.f;

    std::cout<<"=> Histogram limits "
             <<"\n\t"<<histogramClippingLimit*100.f<<"% index = "<<histLowerLimit<<" => normalizedHist value = "<<denseProb.at<float>(histLowerLimit)<<" => input gray level = "<<minInputValue
             <<"\n\t"<<(1.f-histogramClippingLimit)*100.f<<"% index = "<<histUpperLimit<<" => normalizedHist value = "<<denseProb.at<float>(histUpperLimit)<<" => input gray level = "<<maxInputValue
             <<std::endl;
    //drawPlot(denseProb, "input histogram density probability", histLowerLimit, histUpperLimit);
    drawPlot(normalizedHist, "input histogram", histLowerLimit, histUpperLimit);

    if(rescale0_255) // rescale between 0-255 if asked to
    {
        cv::threshold( outputMat, outputMat, maxInputValue, maxInputValue, 2 ); //THRESH_TRUNC, clips values above maxInputValue
        cv::threshold( outputMat, outputMat, minInputValue, minInputValue, 3 ); //THRESH_TOZERO, clips values under minInputValue
        // rescale image range [minInputValue-maxInputValue] to [0-255]
        outputMat-=minInputValue;
        outputMat*=255.f/(maxInputValue-minInputValue);
    } else
    {
        inputMat.copyTo(outputMat);
        // update threshold in the initial input image range
        maxInputValue=(float)((maxInputValue-255.f)/histNormRescalefactor+maxInput);
        minInputValue=(float)(minInputValue/histNormRescalefactor+minInput);
        std::cout<<"===> Input Hist clipping values (max,min) = "<<maxInputValue<<", "<<minInputValue<<std::endl;
        cv::threshold( outputMat, outputMat, maxInputValue, maxInputValue, 2 ); //THRESH_TRUNC, clips values above maxInputValue
        cv::threshold( outputMat, outputMat, minInputValue, minInputValue, 3 ); //
    }
}
Exemplo n.º 17
0
void RDK2AnalysisPlotter::makeEPGPlot(CoDet detType)
{
     gROOT->cd();
    TCanvas* theCanvas;
    TPad* mainPad;
    TPad* titlePad;
    TPad* gEPad;
    TPad* detPad;
    TPad* gEPadSubs[3];


    int numTitleLines=getTitleBoxLines( detType);
    int canvasNumPixelsYPlot=600;
    int canvasNumPixelsYPlots=2*canvasNumPixelsYPlot;
    int canvasNumPixelsYTitle=40*numTitleLines;
    int canvasNumPixelsY=canvasNumPixelsYPlots+canvasNumPixelsYTitle;

    theCanvas = new TCanvas("EPGExpMCAnalysisComparisonPlot","EPGExpMCAnalysisComparisonPlot",10,10,1200,canvasNumPixelsY);
     mainPad=(TPad*) theCanvas->GetPad(0);


    double ylow,yhigh;

    yhigh=1;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    titlePad=new TPad("titlePad", "titlePad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=ylow;
    ylow=ylow-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    gEPad=new TPad("gEPad", "gEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=ylow;
    ylow=0;
    detPad=new TPad("detPad", "detPad", 0., ylow, 1., yhigh, -1, 1, 1);

    titlePad->Draw();
    gEPad->Draw();
    detPad->Draw();



//    titlePad=(TPad*) theCanvas->GetPad(1);
//    gEPad=(TPad*) theCanvas->GetPad(2);
//    detPad=(TPad*) theCanvas->GetPad(3);
//    egTPad=(TPad*) theCanvas->GetPad(4);

    titlePad->SetMargin(0.05,0.0,0.0,0.0);
    gEPad->SetMargin(0.05,0.0,0.0,0.05);

    if(numExp>1 && numMC>1)
    {
        gEPad->Divide(2);

        gEPadSubs[0]=(TPad*) gEPad->GetPad(1);

        TPad* tempPad;
        tempPad=(TPad*) gEPad->GetPad(2);
        tempPad->Divide(1,2);
        gEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        gEPadSubs[2]=(TPad*) tempPad->GetPad(2);


        TPad* allBasePads[5]={titlePad,gEPadSubs[0],gEPadSubs[1],gEPadSubs[2],detPad};
         for (int i = 1;i< 5;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }

        gEPadSubs[2]->SetLogx();

        gEPadSubs[0]->SetMargin(0.15,0.1,.1,0.1);
        gEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        gEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);

        //Plot gE

        gEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_COMP);
        gEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_RESID);
        gEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_GEVAR,PLOT_NORMRESID);

    }
    else
    {

        TPad* allBasePads[3]={titlePad,gEPad,detPad};
        for (int i = 1;i< 3;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }

        gEPad->SetMargin(0.13,0.1,.1,0.1);


        //Plot gE

        gEPad->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_COMP);
    }
    mainPad->SetFillColor(kGray);

    ///Make Title box
    titlePad->cd();
    titlePad->SetFillColor(kGray);
    TPaveText* titleBox = makeTitleBox( detType);
    titleBox->Draw();

    detPad->SetMargin(0.1,0.05,.1,0.1);

    //Plot det
     detPad->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_DETS);

    TString coTypeString;
    if(detType==DET_EP)
    {
        coTypeString="EP";
    }
    else if(detType==DET_EPG)
    {
        coTypeString="EPG";
    }
    else if(detType==DET_EPBG)
    {
        coTypeString="EPBG";
    }
    TString imagePath=GRAPHS_DIR;
    imagePath+="layouts/PlotLayout";
    if(numMC) imagePath+="_MC";
    for (int i = 0;i< numMC;i++)
    {
        imagePath+=TString("_")+mc[i]->GetName();
    }
    if(numExp) imagePath+="_Exp";
    for (int i = 0;i< numExp;i++)
    {
        imagePath+=TString("_")+exp[i]->GetName();
    }

    imagePath+="_"+coTypeString+"_EPGPlots.pdf";
    theCanvas->SaveAs(imagePath);

    delete theCanvas;
    clearPlotHists();

}
Exemplo n.º 18
0
void RDK2AnalysisPlotter::makeEPPlot(CoDet detType)
{
    gROOT->cd();
    TCanvas* theCanvas;
    TPad* mainPad;
    TPad* titlePad;
    TPad* pTPad;
    TPad* eEPad;
    TPad* pEPad;
    TPad* pTPadSubs[3];
    TPad* eEPadSubs[3];
    TPad* pEPadSubs[3];


    int numTitleLines=getTitleBoxLines( detType);
    int canvasNumPixelsYPlot=600;
    int canvasNumPixelsYPlots=3*canvasNumPixelsYPlot;
    int canvasNumPixelsYTitle=40*numTitleLines;
    int canvasNumPixelsY=canvasNumPixelsYPlots+canvasNumPixelsYTitle;

    theCanvas = new TCanvas("EPExpMCAnalysisComparisonPlot","EPExpMCAnalysisComparisonPlot",10,10,1200,canvasNumPixelsY);
     mainPad=(TPad*) theCanvas->GetPad(0);


    double ylow,yhigh;

    yhigh=1;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    titlePad=new TPad("titlePad", "titlePad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    pTPad=new TPad("pTPad", "pTPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY- 2*canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    eEPad=new TPad("eEPad", "eEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-2*canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    ylow=0;
    pEPad=new TPad("pEPad", "pEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    titlePad->Draw();
    pTPad->Draw();
    eEPad->Draw();
    pEPad->Draw();



//    titlePad=(TPad*) theCanvas->GetPad(1);
//    pTPad=(TPad*) theCanvas->GetPad(2);
//    eEPad=(TPad*) theCanvas->GetPad(3);
//    pEPad=(TPad*) theCanvas->GetPad(4);

    titlePad->SetMargin(0.05,0.0,0.0,0.0);
    pTPad->SetMargin(0.05,0.0,0.0,0.05);
    pEPad->SetMargin(0.05,0.0,0.0,0.05);
    eEPad->SetMargin(0.05,0.0,0.0,0.05);


    if(numExp+numMC >1)
    {
        pTPad->Divide(2);
        eEPad->Divide(2);
        pEPad->Divide(2);

        pTPadSubs[0]=(TPad*) pTPad->GetPad(1);
        eEPadSubs[0]=(TPad*) eEPad->GetPad(1);
        pEPadSubs[0]=(TPad*) pEPad->GetPad(1);

        TPad* tempPad;
        tempPad=(TPad*) pTPad->GetPad(2);
        tempPad->Divide(1,2);
        pTPadSubs[1]=(TPad*) tempPad->GetPad(1);
        pTPadSubs[2]=(TPad*) tempPad->GetPad(2);

        tempPad=(TPad*) pEPad->GetPad(2);
        tempPad->Divide(1,2);
        pEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        pEPadSubs[2]=(TPad*) tempPad->GetPad(2);

        tempPad=(TPad*) eEPad->GetPad(2);
        tempPad->Divide(1,2);
        eEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        eEPadSubs[2]=(TPad*) tempPad->GetPad(2);

        TPad* allBasePads[10]={titlePad,pTPadSubs[0],pTPadSubs[1],pTPadSubs[2],eEPadSubs[0],eEPadSubs[1],eEPadSubs[2],pEPadSubs[0],pEPadSubs[1],pEPadSubs[2]};
        for (int i = 1;i< 10;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }
        pTPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);
        pEPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);
        eEPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);

        pTPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        pEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        eEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);

        pTPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        pEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        eEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        //Plot pT

        pTPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_COMP);
        pTPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_RESID);
        pTPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_NORMRESID);


        //Plot eE
        eEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_COMP);
        eEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_RESID);
        eEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_NORMRESID);

        //Plot pE
        pEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_COMP);
        pEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_RESID);
        pEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_NORMRESID);
    }
    else
    {
        TPad* allBasePads[4]={titlePad,pTPad,eEPad,pEPad};
        for (int i = 1;i< 4;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }
        pTPad->SetMargin(0.13,0.1,.1,0.1);
        pEPad->SetMargin(0.13,0.1,.1,0.1);
        eEPad->SetMargin(0.13,0.1,.1,0.1);
        pTPad->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_COMP);
        eEPad->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_COMP);
        pEPad->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_COMP);

    }
    mainPad->SetFillColor(kGray);

    ///Make Title box
    titlePad->cd();
    titlePad->SetFillColor(kGray);
    TPaveText* titleBox = makeTitleBox( detType);
    titleBox->Draw();





    TString coTypeString;
    if(detType==DET_EP)
    {
        coTypeString="EP";
    }
    else if(detType==DET_EPG)
    {
        coTypeString="EPG";
    }
    else if(detType==DET_EPBG)
    {
        coTypeString="EPBG";
    }
     TString imagePath=GRAPHS_DIR;
    imagePath+="layouts/PlotLayout";
    if(numMC>0) imagePath+="_MC";
    for (int i = 0;i< numMC;i++)
    {
        imagePath+=TString("_")+mc[i]->GetName();
    }
    if(numExp>0) imagePath+="_Exp";
    for (int i = 0;i< numExp;i++)
    {
        imagePath+=TString("_")+exp[i]->GetName();
    }

    imagePath+="_"+coTypeString+"_EPPlots.pdf";
    theCanvas->SaveAs(imagePath);

    delete theCanvas;
    clearPlotHists();

}
Exemplo n.º 19
0
/// recalculate and redraw everything that needs it, based on dirty flags
void QUProfileController::redrawAllNow()
{
    dbg(1) << "Redrawing quprofile #" << m_myId
           << " " << m_buffer.width() << "x" << m_buffer.height();

    double dotSize = m_vars.dotSize-> get();

//    bool updateDc = false;

    // helper function to format a double to a string
    auto fmtDouble = [](double x)->QString {
        if( std::isnan(x)) return "nan";
        if( std::isinf(x)) return "inf";
        return QString::number( x, 'g', 6);
    };

    int labelFontHeight = m_labelFontMetrics-> height();

    // apply autozoom
    if( m_autoZoom) {
        m_zoomX1 = m_qmin;
        m_zoomX2 = m_qmax;
        m_zoomY1 = m_umax; // max is at the top
        m_zoomY2 = m_umin;

        // make sure we are displaying something (cannot have x1==x2)
        if( m_zoomX2 - m_zoomX1 < 1e-9) {
            m_zoomX1 -= 1;
            m_zoomX2 += 1;
        }
        if( m_zoomY1 - m_zoomY2 < 1e-9) {
            m_zoomY2 -= 1;
            m_zoomY1 += 1;
        }
    }

    // if we are showing grid, make a first (bad) estimate for margins
    // so that we can adjust vertical zoom
    if( m_vars.showGrid-> get() && m_autoZoom) {
        m_x1 = 5; m_x2 = m_buffer.width() - measureLabelX( "0.0000001");
        m_y1 = 5; m_y2 = m_buffer.height() - labelFontHeight;
        double dw = std::fabs(m_zoomX2 - m_zoomX1);
        double dh = std::fabs(m_zoomY1 - m_zoomY2);
        double ww = std::fabs(m_x1 - m_x2);
        double wh = std::fabs(m_y1 - m_y2);
        // dw/dh = ww/wh
        if( std::fabs( dw/dh - ww/wh) > 1e-6) {
            if( dw/dh > ww/wh) {
                // a1 is wider, so make it taller
                double s = dw * wh / ww - dh;
                m_zoomY1 += s/2;
                m_zoomY2 -= s/2;
            } else {
                double s = ww * dh / wh - dw;
                m_zoomX1 -= s/2;
                m_zoomX2 += s/2;
            }
        }
    }



    // setup margins (m_x* and m_y*) & labels
    // note: this must happen simultaneously because the sizes of the
    // vertical axis labels will influence the drawing area...
    // ================================================================

    // start with vertical margins, they only depend on the font height, which does not change
    if( m_vars.showGrid-> get()) {
        m_y1 = 5;
        m_y2 = m_buffer.height() - labelFontHeight; // make room for bottom labels

        // update tty - it won't change anymore
        m_ty1 = LinearMap1D( m_zoomY1, m_zoomY2, m_y1+dotSize, m_y2-dotSize);

        // now calculate vertical labels
        // dont forget y1 = top, y2 = bottom
        m_vertLabeler-> setZoom( tty1inv( m_y2), tty1inv( m_y1));
        m_vertLabeler-> setPixels( m_y2 - m_y1 + 1);
        m_vertLabels = m_vertLabeler-> compute(
                    std::bind(& QUProfileController::measureLabelY, this,
                              std::placeholders::_1));

        // calculate the maximum width of all vertical labels
        double maxw = measureLabelX( "0");
        for( auto label : m_vertLabels) {
            maxw = std::max( maxw, measureLabelX( label.txt1));
        }
        maxw += measureLabelX( "0");

        // now we can set the horizontal margins
        m_x1 = 5;
        m_x2 = m_buffer.width() - maxw;
    }
    else {
        m_x1 = 1; m_x2 = m_buffer.width()-2;
        m_y1 = 1; m_y2 = m_buffer.height()-2;
        // update tty
        m_ty1 = LinearMap1D( m_zoomY1, m_zoomY2, m_y1+dotSize, m_y2-dotSize);
    }

    // fix aspect ratio by adjusting zoom x1,x2
    double dw = std::fabs(m_zoomX2 - m_zoomX1);
    double dh = std::fabs(m_zoomY1 - m_zoomY2);
    double ww = std::fabs(m_x1 - m_x2);
    double wh = std::fabs(m_y1 - m_y2);
    // dw/dh = ww/wh
    if( std::fabs( dw/dh - ww/wh) > 1e-6) {
        if( m_vars.showGrid-> get()) {
            // note: do not change y-zoom as we already used it to calculate vertical labels
            double s = ww * dh / wh - dw;
            m_zoomX1 -= s/2;
            m_zoomX2 += s/2;
        }
        else {
            // if we are not showing grid, we can decide if we adjust x or y zoom
            if( dw/dh > ww/wh) {
                // a1 is wider, so make it taller
                double s = dw * wh / ww - dh;
                m_zoomY1 += s/2;
                m_zoomY2 -= s/2;
                // re-update tty
                m_ty1 = LinearMap1D( m_zoomY1, m_zoomY2, m_y1+dotSize, m_y2-dotSize);
            } else {
                double s = ww * dh / wh - dw;
                m_zoomX1 -= s/2;
                m_zoomX2 += s/2;
            }
        }
    }

    // at this point margins are set, so update ttx*() functions
    m_tx1 = LinearMap1D( m_zoomX1, m_zoomX2, m_x1+dotSize, m_x2-dotSize);

    // calculate labels for the horizontal axis
    if( m_vars.showGrid-> get()) {
        m_horizLabeler-> setZoom( ttx1inv( m_x1), ttx1inv(m_x2));
        m_horizLabeler-> setPixels( m_x2 - m_x1 + 1);
        m_horizLabels = m_horizLabeler-> compute(
                    std::bind(& QUProfileController::measureLabelX, this,
                              std::placeholders::_1));
    }

    // do the drawing
    if( m_dirtyFlags.graph) {
        m_buffer.fill( 0xffffff);
        QPainter p( & m_buffer);
        p.setRenderHint( p.Antialiasing, true);
        p.setRenderHint( p.TextAntialiasing, true);
        p.setRenderHint( p.SmoothPixmapTransform, true);

        // set up clipping to only draw within the main plot area
        p.setClipRect( QRectF( QPointF(m_x1, m_y1), QPointF(m_x2, m_y2)));
        p.setClipping( true);

        // draw the grid
        drawGrid(p);

        // draw the plot
        drawPlot(p);

        // draw mean
        if( m_vars.showMean-> get()) {
            if( std::isfinite(m_meanQ) && std::isfinite(m_meanU)) {
                double x = ttx1( m_meanQ);
                double y = tty1( m_meanU);
                double s = 5;
                p.setPen( QPen( QColor(255,255,255,200), 5));
                p.drawLine( QPointF( x - s, y), QPointF( x + s, y));
                p.drawLine( QPointF( x , y - s), QPointF( x, y + s));
                s -= 1;
                if( m_vars.showSunbow-> get())
                    p.setPen( QPen( QColor(255,0,0), 3));
                else
                    p.setPen( QPen( QColor(0,0,128), 3));
                p.drawLine( QPointF( x - s, y), QPointF( x + s, y));
                p.drawLine( QPointF( x , y - s), QPointF( x, y + s));
            }
        }

        // draw cursor
//        if( m_showCursor && m_cursorIndex >= 0 && m_cursorIndex < avail()) {
        if( getShowCursor() && m_cursorIndex >= 0 && m_cursorIndex < avail()) {
            double x = m_dataQ[ m_cursorIndex];
            double y = m_dataU[ m_cursorIndex];
            x = ttx1(x);
            y = tty1(y);
            if( std::isfinite(x) && std::isfinite(y)) {
                p.setPen( QPen(QColor( 0,255,0), 2));
                p.setBrush( Qt::NoBrush);
                p.drawEllipse( QPointF(x,y), 6, 6);
            }
        }

        // if data is not complete yet, show a text
        p.setClipping( false);

        // let the clients know the mean
        m_vars.qMean-> set( fmtDouble( m_meanQ));
        m_vars.uMean-> set( fmtDouble( m_meanU));
//        updateDc = true;
    }

    // draw loading message if appropriate
    QPainter p( & m_buffer);
    drawLoadingMessage(p);

    // tell clients about the cursor
    if( m_dirtyFlags.cursor1) {
        if( m_cursorIndex >= 0 && m_cursorIndex < avail()) {
            m_vars.qVal-> set( fmtDouble( m_dataQ[ m_cursorIndex]));
            m_vars.uVal-> set( fmtDouble( m_dataU[ m_cursorIndex]));
        }
        else {
            m_vars.qVal-> set( "");
            m_vars.uVal-> set( "");
        }
        if( m_cursorIndex >= 0) {
            m_vars.frame-> set( QString::number( m_cursorIndex + 1));
        }
        else {
            m_vars.frame-> set( "");
        }
    }

//    // send additional info to render by the client
//    if( updateDc ){
//        pwsetdc( m_pwPrefix + "dc", qrand());
//    }

    //    dbg(1) << "... RedrawAllNow() done in " << debugTimer.elapsed() / 1000.0 << "s\n";
}
Exemplo n.º 20
0
 /// Draw the Plot to this frame
 inline void drawPlot(Frame& frame)
 {
     drawPlot(&frame);
 }
Exemplo n.º 21
0
void drawSinglePtBin( DrawBase* db, QGLikelihoodCalculator* qglc, TTree* tree, float ptMin, float ptMax ) {

  std::cout << "-> Processing pt bin: " << ptMin << "-" << ptMax << " GeV..." << std::endl;

  bool doFwd = (ptMin<100.);


  float pt;
  tree->SetBranchAddress("ptJet0", &pt);
  float eta;
  tree->SetBranchAddress("etaJet0", &eta);
  int pdgId;
  tree->SetBranchAddress("pdgIdPartJet0", &pdgId);
  float rho;
  tree->SetBranchAddress("rhoPF", &rho);
  int nCharged;
  tree->SetBranchAddress("nChargedJet0", &nCharged);
  int nNeutral;
  tree->SetBranchAddress("nNeutralJet0", &nNeutral);
  float ptD;
  tree->SetBranchAddress("ptDJet0", &ptD);
  float ptD_QC;
  tree->SetBranchAddress("ptD_QCJet0", &ptD_QC);
  float axis2_QC;
  tree->SetBranchAddress("axis2_QCJet0", &axis2_QC);
  int nCharged_QC;
  tree->SetBranchAddress("nChg_QCJet0", &nCharged_QC);
  int nNeutral_ptCut;
  tree->SetBranchAddress("nNeutral_ptCutJet0", &nNeutral_ptCut);
  float qglMLPJet0;
  tree->SetBranchAddress("QGLMLP", &qglMLPJet0);
  float qglJet0;
  tree->SetBranchAddress("qglJet0", &qglJet0);


  TH1D* h1_qgl_old_gluon = new TH1D("qgl_old_gluon", "", 100, 0., 1.0001);
  TH1D* h1_qgl_old_quark = new TH1D("qgl_old_quark", "", 100, 0., 1.0001);

  TH1D* h1_qgl_new_gluon = new TH1D("qgl_new_gluon", "", 100, 0., 1.0001);
  TH1D* h1_qgl_new_quark = new TH1D("qgl_new_quark", "", 100, 0., 1.0001);

  TH1D* h1_qgMLP_gluon = new TH1D("qgMLP_gluon", "", 100, 0., 1.);
  TH1D* h1_qgMLP_quark = new TH1D("qgMLP_quark", "", 100, 0., 1.);


  // in the forward:
  TH1D* h1_qgl_new_F_gluon = new TH1D("qgl_new_F_gluon", "", 100, 0., 1.0001);
  TH1D* h1_qgl_new_F_quark = new TH1D("qgl_new_F_quark", "", 100, 0., 1.0001);

  TH1D* h1_qgMLP_F_gluon = new TH1D("qgMLP_F_gluon", "", 100, 0., 1.);
  TH1D* h1_qgMLP_F_quark = new TH1D("qgMLP_F_quark", "", 100, 0., 1.);


  int nentries = tree->GetEntries();

  for( unsigned int ientry=0; ientry<nentries; ++ientry ) {

    tree->GetEntry(ientry);

    if( pt<ptMin || pt>ptMax ) continue;
    //if( rho>22. ) continue;

    float qgl_new = qglJet0;

    if( fabs(eta)<2.5 && h1_qgl_old_gluon->GetEntries()<10000 && h1_qgl_old_quark->GetEntries()<10000 ) { //save time

      float qgl_old = qglc->computeQGLikelihoodPU( pt, rho, nCharged, nNeutral, ptD);

      if( fabs(pdgId)<5 ) {
        h1_qgl_old_quark->Fill( qgl_old );
        h1_qgl_new_quark->Fill( qgl_new );
        h1_qgMLP_quark->Fill( qglMLPJet0 );
      }
      if( pdgId==21 ) {
        h1_qgl_old_gluon->Fill( qgl_old );
        h1_qgl_new_gluon->Fill( qgl_new );
        h1_qgMLP_gluon->Fill( qglMLPJet0 );
      }

    } else if( fabs(eta)>3. ) {

      if( fabs(pdgId)<5 ) {
        h1_qgl_new_F_quark->Fill( qgl_new );
        h1_qgMLP_F_quark->Fill( qglMLPJet0 );
      }
      if( pdgId==21 ) {
        h1_qgl_new_F_gluon->Fill( qgl_new );
        h1_qgMLP_F_gluon->Fill( qglMLPJet0 );
      }

    }
    
    if( h1_qgl_old_gluon->GetEntries()>10000 
     && h1_qgl_old_quark->GetEntries()>10000 
     && ( !doFwd || (h1_qgl_new_F_quark->GetEntries()>10000
     && h1_qgl_new_F_gluon->GetEntries()>10000) ) ) break;


  }


  drawPlot( db, h1_qgl_old_gluon, h1_qgl_old_quark, "old", ptMin, ptMax, "|#eta| < 2.5" );
  drawPlot( db, h1_qgl_new_gluon, h1_qgl_new_quark, "new", ptMin, ptMax, "|#eta| < 2.5" );
  drawPlot( db, h1_qgMLP_gluon, h1_qgMLP_quark, "MLP", ptMin, ptMax, "|#eta| < 2.5" );

  drawPlot( db, h1_qgl_new_F_gluon, h1_qgl_new_F_quark, "new_F", ptMin, ptMax, "3 < |#eta| < 5" );
  drawPlot( db, h1_qgMLP_F_gluon, h1_qgMLP_F_quark, "MLP_F", ptMin, ptMax, "3 < |#eta| < 5" );

  drawRoC(db, ptMin, ptMax, "", h1_qgl_new_gluon, h1_qgl_new_quark, h1_qgl_old_gluon, h1_qgl_old_quark, 0, 0, "|#eta| < 2.5");
  drawRoC(db, ptMin, ptMax, "_withMLP", h1_qgl_new_gluon, h1_qgl_new_quark, h1_qgl_old_gluon, h1_qgl_old_quark, h1_qgMLP_gluon, h1_qgMLP_quark, "|#eta| < 2.5");
  drawRoC(db, ptMin, ptMax, "_F", h1_qgl_new_F_gluon, h1_qgl_new_F_quark, 0, 0, h1_qgMLP_F_gluon, h1_qgMLP_F_quark, "3 < |#eta| < 5");

  delete h1_qgl_old_gluon;
  delete h1_qgl_old_quark;

  delete h1_qgl_new_gluon;
  delete h1_qgl_new_quark;

  delete h1_qgMLP_gluon;
  delete h1_qgMLP_quark;

  delete h1_qgl_new_F_gluon;
  delete h1_qgl_new_F_quark;

  delete h1_qgMLP_F_gluon;
  delete h1_qgMLP_F_quark;


}
Exemplo n.º 22
0
void fit2015(
             TString FileName ="/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/ppData/OniaTree_262163_262328.root", 
             int  oniamode  = 2,        // oniamode-> 3: Z,  2: Upsilon and 1: J/Psi
             bool isData    = true,     // isData = false for MC, true for Data
             bool isPbPb    = false,    // isPbPb = false for pp, true for PbPb
	     bool doFit = false ,
             bool inExcStat = true      // if inExcStat is true, then the excited states are fitted
             ) {

  InputOpt opt;
  SetOptions(&opt, isData, isPbPb, oniamode,inExcStat);

  if (isPbPb) {
    FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/PbPbData/OniaTree_262548_262893.root";
  } else {
    FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/ppData/OniaTree_262163_262328.root";
  }
    
  int nbins = 1; //ceil((opt.dMuon->M->Max - opt.dMuon->M->Min)/binw);
  if (oniamode==1){
    nbins = 140;
  } else if (oniamode==2) {
    nbins = 70; 
  } else if (oniamode==3) {
    nbins = 40;
  } 
 
  RooWorkspace myws;
  TH1F* hDataOS =  new TH1F("hDataOS","hDataOS", nbins, opt.dMuon.M.Min, opt.dMuon.M.Max);
  makeWorkspace2015(myws, FileName, opt, hDataOS);

  RooRealVar* mass      = (RooRealVar*) myws.var("invariantMass"); 
  RooDataSet* dataOS_fit = (RooDataSet*) myws.data("dataOS");
  RooDataSet* dataSS_fit = (RooDataSet*) myws.data("dataSS");
  RooAbsPdf*  pdf = NULL;

  if (oniamode==3) { doFit=false; }
  if (doFit) {
    int sigModel=0, bkgModel=0;  
    if (isData) {
      if (oniamode==1){
        sigModel = inExcStat ? 2 : 3;
        bkgModel = 1;
      } else {
        sigModel = inExcStat ? 1 : 3; // gaussian   
        bkgModel = 2;
      }      
    } else {
      if (oniamode==1){
        sigModel = inExcStat ? 2 : 3; // gaussian   
        bkgModel = 2;
      } else {
        sigModel = inExcStat ? 2 : 3; // gaussian   
        bkgModel = 3;
      }
    }

    if (opt.oniaMode==1) buildModelJpsi2015(myws, sigModel, bkgModel,inExcStat);
    else if (opt.oniaMode==2) buildModelUpsi2015(myws, sigModel, bkgModel,inExcStat);

    pdf       =(RooAbsPdf*)  myws.pdf("pdf");
    RooFitResult* fitObject = pdf->fitTo(*dataOS_fit,Save(),Hesse(kTRUE),Extended(kTRUE)); // Fit
  }

  RooPlot* frame = mass->frame(Bins(nbins),Range(opt.dMuon.M.Min, opt.dMuon.M.Max));  
  RooPlot* frame2 = NULL;
  dataSS_fit->plotOn(frame, Name("dataSS_FIT"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); 
  dataOS_fit->plotOn(frame, Name("dataOS_FIT"), MarkerColor(kBlue), LineColor(kBlue), MarkerSize(1.2));
  

  if (doFit) {
     pdf->plotOn(frame,Name("thePdf"),Normalization(dataOS_fit->sumEntries(),RooAbsReal::NumEvent));
     RooHist *hpull = frame -> pullHist(0,0,true);
     hpull -> SetName("hpull");
     frame2 = mass->frame(Title("Pull Distribution"),Bins(nbins),Range(opt.dMuon.M.Min,opt.dMuon.M.Max));
     frame2 -> addPlotable(hpull,"PX");  
     } 
  drawPlot(frame,frame2, pdf, opt, doFit,inExcStat);

  TString OutputFileName = "";
  if (isPbPb) {
    FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/PbPbData/OniaTree_262548_262893.root";
    opt.RunNb.Start=262548;
    opt.RunNb.End=262893;
    if (oniamode==1) {OutputFileName = (TString)("JPSIPbPbDataset.root");}
    if (oniamode==2) {OutputFileName = (TString)("YPbPbDataset.root");}
    if (oniamode==3) {OutputFileName = (TString)("ZPbPbDataset.root");}
  } else {
    FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/ppData/OniaTree_262163_262328.root";
    opt.RunNb.Start=262163;
    opt.RunNb.End=262328;
    if (oniamode==1) {OutputFileName = (TString)("JPSIppDataset.root");}
    if (oniamode==2) {OutputFileName = (TString)("YppDataset.root");}
    if (oniamode==3) {OutputFileName = (TString)("ZppDataset.root");}
  }
  
  TFile* oFile =  new TFile(OutputFileName,"RECREATE");
  oFile->cd();
  hDataOS->Write("hDataOS");
  dataOS_fit->Write("dataOS_FIT");
  oFile->Write();
  oFile->Close();

}
/*
 * objective : get the gray level map of the input image and rescale it to the range [0-255]
 */
 static void rescaleGrayLevelMat(const cv::Mat &inputMat, cv::Mat &outputMat, const float histogramClippingLimit)
 {

     // adjust output matrix wrt the input size but single channel
     std::cout<<"Input image rescaling with histogram edges cutting (in order to eliminate bad pixels created during the HDR image creation) :"<<std::endl;
     //std::cout<<"=> image size (h,w,channels) = "<<inputMat.size().height<<", "<<inputMat.size().width<<", "<<inputMat.channels()<<std::endl;
     //std::cout<<"=> pixel coding (nbchannel, bytes per channel) = "<<inputMat.elemSize()/inputMat.elemSize1()<<", "<<inputMat.elemSize1()<<std::endl;

     // rescale between 0-255, keeping floating point values
     cv::normalize(inputMat, outputMat, 0.0, 255.0, cv::NORM_MINMAX);

     // extract a 8bit image that will be used for histogram edge cut
     cv::Mat intGrayImage;
     if (inputMat.channels()==1)
     {
         outputMat.convertTo(intGrayImage, CV_8U);
     }else
     {
         cv::Mat rgbIntImg;
         outputMat.convertTo(rgbIntImg, CV_8UC3);
         cv::cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY);
     }

     // get histogram density probability in order to cut values under above edges limits (here 5-95%)... usefull for HDR pixel errors cancellation
     cv::Mat dst, hist;
     int histSize = 256;
     calcHist(&intGrayImage, 1, 0, cv::Mat(), hist, 1, &histSize, 0);
     cv::Mat normalizedHist;
     normalize(hist, normalizedHist, 1, 0, cv::NORM_L1, CV_32F); // normalize histogram so that its sum equals 1

     double min_val, max_val;
     minMaxLoc(normalizedHist, &min_val, &max_val);
     //std::cout<<"Hist max,min = "<<max_val<<", "<<min_val<<std::endl;

     // compute density probability
     cv::Mat denseProb=cv::Mat::zeros(normalizedHist.size(), CV_32F);
     denseProb.at<float>(0)=normalizedHist.at<float>(0);
     int histLowerLimit=0, histUpperLimit=0;
     for (int i=1;i<normalizedHist.size().height;++i)
     {
         denseProb.at<float>(i)=denseProb.at<float>(i-1)+normalizedHist.at<float>(i);
         //std::cout<<normalizedHist.at<float>(i)<<", "<<denseProb.at<float>(i)<<std::endl;
         if ( denseProb.at<float>(i)<histogramClippingLimit)
             histLowerLimit=i;
         if ( denseProb.at<float>(i)<1-histogramClippingLimit)
             histUpperLimit=i;
     }
     // deduce min and max admitted gray levels
     float minInputValue = (float)histLowerLimit/histSize*255;
     float maxInputValue = (float)histUpperLimit/histSize*255;

     std::cout<<"=> Histogram limits "
             <<"\n\t"<<histogramClippingLimit*100<<"% index = "<<histLowerLimit<<" => normalizedHist value = "<<denseProb.at<float>(histLowerLimit)<<" => input gray level = "<<minInputValue
             <<"\n\t"<<(1-histogramClippingLimit)*100<<"% index = "<<histUpperLimit<<" => normalizedHist value = "<<denseProb.at<float>(histUpperLimit)<<" => input gray level = "<<maxInputValue
             <<std::endl;
     //drawPlot(denseProb, "input histogram density probability", histLowerLimit, histUpperLimit);
     drawPlot(normalizedHist, "input histogram", histLowerLimit, histUpperLimit);

     // rescale image range [minInputValue-maxInputValue] to [0-255]
     outputMat-=minInputValue;
     outputMat*=255.0/(maxInputValue-minInputValue);
     // cut original histogram and back project to original image
     cv::threshold( outputMat, outputMat, 255.0, 255.0, 2 ); //THRESH_TRUNC, clips values above 255
     cv::threshold( outputMat, outputMat, 0.0, 0.0, 3 ); //THRESH_TOZERO, clips values under 0

 }