Example #1
3
MainWindow::MainWindow()
{
    outputLog = new QTextEdit(this);
    outputLog->setReadOnly(true);
    outputLog->append("MTG log \n-------\n");



    //to be created a central widget
    //setCentralWidget(new QWidget());
    setCentralWidget(outputLog);
    setWindowIcon(QIcon(":/images/MTG.png"));
    //creating the menu titles
    fileMenu = menuBar()->addMenu(tr("&File"));
    //editMenu = menuBar()->addMenu(tr("&Edit"));
    analyzerMenu = menuBar()->addMenu(tr("Analyzer"));
    DMmenu = menuBar()->addMenu(tr("DataManager"));
    MMmenu = menuBar()->addMenu(tr("MaskManager"));
    viewMenu = menuBar()->addMenu(tr("&View"));
    menuBar()->addSeparator();
    helpMenu = menuBar()->addMenu(tr("&Help"));

    // creating stuff
    //warning: take care of the order you call these functions
    createDockWindows();
    createActions();
    createMenus();
    createToolBars();
    createStatusBar();

    QFile file(":/styles.qss");
    file.open(QFile::ReadOnly);
    QString styleSheet = QLatin1String(file.readAll());
    qApp->setStyleSheet(styleSheet);

    setWindowTitle(tr("Matrix Tool GUI"));
    setIconSize(QSize(35,35));

    desktop = qApp->desktop();

    connect(desktop, SIGNAL(resized(int)), this, SLOT(centerMainWindowGeometry()));

    //connect(dataManager, SIGNAL(plotHisto(QPair<matrixData*, QString>)), this, SLOT(raisePlotDock()));
    connect(dataManager, SIGNAL(plotHisto(QPair<matrixData*, QString>)), plotWidget, SLOT(histoMatrix(QPair<matrixData*, QString>)));

    //connect(dataManager, SIGNAL(inspectMatrixData(QPair<matrixData*, QString>)), this, SLOT(raiseEVDock()));
    connect(dataManager, SIGNAL(inspectMatrixData(QPair<matrixData*, QString>)),eventViewer, SLOT(attachMatrixData(QPair<matrixData*, QString>)));

    //raise the involved dock when action is triggered
    connect(newDataSetAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
    connect(rmDataSetAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
    connect(rmAllDataSetAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
    connect(plotDataSetAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
        connect(plotDataSetAct, SIGNAL(triggered()), this, SLOT(raisePlotDock()));
    connect(saveDataSetAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
    connect(inspectEventAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
        connect(inspectEventAct, SIGNAL(triggered()), this, SLOT(raiseEVDock()));
    connect(renameDataSetAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
    //
    connect(newMaskSetAct, SIGNAL(triggered()), this, SLOT(raiseMMDock()));
    connect(printMaskAct, SIGNAL(triggered()), this, SLOT(raiseMMDock()));
    connect(rmMaskSetAct, SIGNAL(triggered()), this, SLOT(raiseMMDock()));
    connect(renameMaskSetAct, SIGNAL(triggered()), this, SLOT(raiseMMDock()));
    connect(editMaskAct, SIGNAL(triggered()), this, SLOT(raiseMMDock()));


    //raise the involved dock when made visible
    connect(DMviewAct, SIGNAL(triggered()), this, SLOT(raiseDMDock()));
    connect(MMviewAct, SIGNAL(triggered()), this, SLOT(raiseMMDock()));
    connect(plotViewAct, SIGNAL(triggered()), this, SLOT(raisePlotDock()));
    connect(EVviewAct, SIGNAL(triggered()), this, SLOT(raiseEVDock()));

    //connect the log output signals
    connect(dataManager, SIGNAL(outputLog(QString)), outputLog, SLOT(append(QString)));
    connect(maskManager, SIGNAL(outputLog(QString)), outputLog, SLOT(append(QString)));
    connect(plotWidget, SIGNAL(outputLog(QString)), outputLog, SLOT(append(QString)));
    connect(eventViewer, SIGNAL(outputLog(QString)), outputLog, SLOT(append(QString)));


    setUnifiedTitleAndToolBarOnMac(true);

}
Example #2
0
void plotYield(int ele=1)
{
  if (ele==1) {
    TString fname="cs_DYee_13TeV_El3.root";
    TH1D *h1Yield=loadHisto(fname,"h1Yield","h1Yield",h1dummy);
    TH1D *h1Signal=loadHisto(fname,"h1Signal","h1Signal",h1dummy);
    hsBlue.SetStyle(h1Yield);
    h1Yield->SetMarkerStyle(5);
    hsGreen.SetStyle(h1Signal);
    h1Yield->GetYaxis()->SetRangeUser(1e-2,1e6);
    h1Yield->GetYaxis()->SetTitleOffset(1.5);
    logAxis(h1Yield,1,niceMassAxisLabel(0,"",0),"count","");
    plotHisto(h1Yield,"cYield_EE",1,1,"LPE","yield");
    plotHistoSame(h1Signal,"cYield_EE","LPE1","signal");
    //printHisto(h1Yield);
    //printHisto(h1Signal);
  }
  else if ((ele==0) || (ele==-1)) {
    TString tag=(ele==0) ? "csA" : "csB";
    TString fname="cs_DYmm_13TeVMuApproved_" + tag + ".root";
    TH1D *h1Yield=loadHisto(fname,"h1Yield","h1Yield",h1dummy);
    TH1D *h1Signal=loadHisto(fname,"h1Signal","h1Signal",h1dummy);
    hsBlue.SetStyle(h1Yield);
    h1Yield->SetMarkerStyle(5);
    hsGreen.SetStyle(h1Signal);
    h1Yield->GetYaxis()->SetRangeUser(1e-2,1e6);
    h1Yield->GetYaxis()->SetTitleOffset(1.5);
    logAxis(h1Yield,1,niceMassAxisLabel(1,"",0),"count","");
    plotHisto(h1Yield,"cYield_MM_"+tag,1,1,"LPE","yield " + tag);
    plotHistoSame(h1Signal,"cYield_MM_"+tag,"LPE1","signal " + tag);
  }
}
Example #3
0
void checkInputs()
{
  TFile fin("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1steps.root");
  TH1D *h1effPass_new= loadHisto(fin,"h1_eff_sumPass","h1effPass_new",1,h1dummy);
  TH1D *h1effPass_chk= loadHisto(fin,"h1_eff_sumPass_chk","h1effPass_chk",1,h1dummy);
  TH1D *h1effPass_noTrigNoPU= loadHisto(fin,"h1_eff_sumPass_noTrigNoPU","h1effPass_noTrigNoPU",1,h1dummy);
  TH1D *h1effTot_new= loadHisto(fin, "h1_eff_sumTot", "h1effTot_new",1,h1dummy);
  fin.Close();
  if (!h1effPass_new || !h1effPass_chk || !h1effPass_noTrigNoPU || !h1effTot_new) return;

  TFile fin2("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1.root");
  TH1D *h1effPass_old= loadHisto(fin2,"h1_eff_sumPass","h1effPass_old",1,h1dummy);
  TH1D *h1effTot_old= loadHisto(fin2,"h1_eff_sumTot","h1effTot_old",1,h1dummy);
  fin2.Close();
  if (!h1effPass_old || !h1effTot_old) return;

  histoStyle(h1effPass_chk,kRed,5,1);
  histoStyle(h1effPass_old,kBlue,7,1);

  plotHisto(h1effPass_new,"cCheck",1,0,"LPE1","new effPass");
  plotHistoSame(h1effPass_chk,"cCheck","LPE1","new effPass (control)");
  printRatio(h1effPass_chk,h1effPass_new);

  //plotHisto(h1effPass_noTrigNoPU,"cCmpOld",1,0,"LPE1","noTrigNoPU");
  //plotHistoSame(h1effPass_old,"cCmpOld","LPE1","old effPass");
  //printRatio(h1effPass_old,h1effPass_noTrigNoPU);

  plotHisto(h1effTot_new,"cCmpTot",1,0,"LPE1","new effTot");
  plotHistoSame(h1effTot_old,"cCmpTot","LPE1","old effTot");
  printRatio(h1effTot_old,h1effTot_new);
}
Example #4
0
void plotSteps()
{

  //checkInputs(); return;

  TFile fin("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1steps.root");
  TH1D *h1effPass_new= loadHisto(fin,"h1_eff_sumPass","h1effPass_new",1,h1dummy);
  TH1D *h1effPass_noPU= loadHisto(fin,"h1_eff_sumPass_noPU","h1effPass_noPU",1,h1dummy);
  TH1D *h1effPass_noTrigObjMatching= loadHisto(fin,"h1_eff_sumPass_noTrigObjMatching","h1effPass_noTrigObjMatching",1,h1dummy);
  TH1D *h1effPass_matchDR3= loadHisto(fin,"h1_eff_sumPass_matchDR3","h1effPass_matchDR3",1,h1dummy);
  TH1D *h1effPass_noTrig= loadHisto(fin,"h1_eff_sumPass_noTrig","h1effPass_noTrig",1,h1dummy);
  TH1D *h1effPass_noTrigNoPU= loadHisto(fin,"h1_eff_sumPass_noTrigNoPU","h1effPass_noTrigNoPU",1,h1dummy);
  //TH1D *h1effTot_new= loadHisto(fin, "h1_eff_sumTot", "h1effTot_new",1,h1dummy);
  fin.Close();
  if (!h1effPass_new  || !h1effPass_noPU || !h1effPass_noTrigObjMatching ||
      !h1effPass_matchDR3 || !h1effPass_noTrig || !h1effPass_noTrigNoPU) {
    std::cout << "null ptr\n";
    return;
  }

  std::vector<TH1D*> h1InfoV;
  std::vector<TString> infoLabelV;

  histoStyle(h1effPass_noPU,kRed,5,1);
  histoStyle(h1effPass_noTrig,kBlue,7,2);
  histoStyle(h1effPass_matchDR3,kGreen+1,5,1);
  histoStyle(h1effPass_noTrigObjMatching,kOrange,20,2);

  std::cout << "\nwPU effect on new effPass distribution\n";
  plotHisto(h1effPass_new,"cPUnew",1,0,"LPE1","new wPU");
  plotHistoSame(h1effPass_noPU,"cPUnew","LPE1","new noPU");
  printRatio(h1effPass_new,h1effPass_noPU);
  addRatio(h1effPass_noPU,h1effPass_new,"no PU rew.",h1InfoV,infoLabelV);

  std::cout << "\nwPU effect on old effPass distribution\n";
  plotHisto(h1effPass_noTrig,"cPUold",1,0,"LPE1","old wPU");
  plotHistoSame(h1effPass_noTrigNoPU,"cPUold","LPE1","old noPU");
  printRatio(h1effPass_noTrig,h1effPass_noTrigNoPU);

  std::cout << "\ntriggering\n";
  plotHisto(h1effPass_new,"cTrig",1,0,"LPE1","new wPU");
  plotHistoSame(h1effPass_noTrig,"cTrig","LPE1","no event trigger");
  printRatio(h1effPass_new,h1effPass_noTrig);
  addRatio(h1effPass_noTrig,h1effPass_new,"no trigger",h1InfoV,infoLabelV);

  std::cout << "\ntrigger object matching\n";
  plotHisto(h1effPass_new,"cTrigObjMatch",1,0,"LPE1","new wPU");
  plotHistoSame(h1effPass_noTrigObjMatching,"cTrigObjMatch","LPE1","new, noTrigObjMatch");
  printRatio(h1effPass_new,h1effPass_noTrigObjMatching);
  addRatio(h1effPass_noTrigObjMatching,h1effPass_new,"no trig.obj.match.",h1InfoV,infoLabelV);

  std::cout << "\nDR effect on new effPass distribution\n";
  plotHisto(h1effPass_new,"cDR",1,0,"LPE1","new wPU, match DR1");
  plotHistoSame(h1effPass_matchDR3,"cDR","LPE1","new wPU, match DR3");
  printRatio(h1effPass_new,h1effPass_matchDR3);
  addRatio(h1effPass_matchDR3,h1effPass_new,"#DeltaR<0.3",h1InfoV,infoLabelV);

  //printLatex("effPassSteps.tex",h1InfoV,infoLabelV,1);
  plotRatios(h1InfoV,infoLabelV);
}
Example #5
0
void plotRatios(std::vector<TH1D*> &h1RatioV, const std::vector<TString> &labelV)
{
  for (unsigned int ih=0; ih<h1RatioV.size(); ih++) {
    removeError(h1RatioV[ih]);
    h1RatioV[ih]->SetStats(0);
  }

  TH1D *h1=h1RatioV[0];
  h1->SetTitle("Ratio of the modified selection to the new selection");
  h1->SetTitleSize(24);
  h1->GetXaxis()->SetNoExponent();
  h1->GetXaxis()->SetMoreLogLabels();
  h1->GetXaxis()->SetTitleSize(0.05);
  h1->GetYaxis()->SetRangeUser(0.95,1.15);
  h1->GetYaxis()->SetTitle("ratio");
  h1->GetYaxis()->SetTitleSize(0.05);
  h1->GetYaxis()->SetTitleOffset(1.38);

  TString cName="cRatio";
  TCanvas *c=plotHisto(h1RatioV[0],cName,1,0,"LP",labelV[0]);
  gPad->SetGridx();
  gPad->SetGridy();
  for (unsigned int ih=1; ih<h1RatioV.size(); ih++) {
    plotHistoSame(h1RatioV[ih],cName,"LP",labelV[ih]);
  }
}
Example #6
0
void analyseFitToystudiesB0(string filename, bool justTau = false)
{
    fileprefix = "fitToyStudiesB0";
    TTree *t = new TTree;
    t->ReadFile(filename.c_str(),"tau:tau_err:mass_peak:mass_peak_err:m_sigma1:m_sigma1_err:m_sigma2:m_sigma2_err:frac_m_gauss:frac_m_gauss_err:core_frac:core_frac_err:tau_bk:tau_bk_err:n_nonprompt:n_nonprompt_err:n_prompt:n_prompt_err:n_signal:n_signal_err:prompt_p1:prompt_p1_err:prompt_sigma_core:prompt_sigma_core_err:prompt_sigma_tail:prompt_sigma_tail_err");

    if (!justTau)
    {
	plotPulls(t, "tau_pulls", "#tau(B^{0})", "tau", 1.529, 100, 5.0);
	plotPulls(t, "mass_pulls", "m(B^{0})", "mass_peak", 5.27950, 100, 5.0);
	plotPulls(t, "tau_bk_pulls", "#tau_{bgr}(B^{0})", "tau_bk", 0.750, 100, 5.0);
	plotPulls(t, "nsig_pulls", "n_{sig}", "n_signal", 6750, 100, 5.0);
	plotPulls(t, "npr_pulls", "n_{prompt}", "n_prompt", 3375, 100, 10);
	plotPulls(t, "nnpr_pulls", "n_{nonprompt}", "n_nonprompt", 1125, 100, 10);
    }

    plotHisto(t, "tau_histo", "#tau(B^{0})", "ps", "tau", 100, 1.30, 1.70);
    if (!justTau)
    {
	plotHisto(t, "mass_histo", "m(B^{0})", "GeV", "mass_peak", 100, 5.2785, 5.281);
	plotHisto(t, "tau_bk_histo", "#tau_{bgr}(B^{0})", "ps", "tau_bk", 100, 0.5, 0.9);
	plotHisto(t, "nsig_histo", "n_{sig}", "", "n_signal", 100, 6500, 7000);
	plotHisto(t, "npr_histo", "n_{prompt}", "", "n_prompt", 100, 2900, 3900);
	plotHisto(t, "nnpr_histo", "n_{nonprompt}", "", "n_nonprompt", 100, 950, 1450);
    }
}
Example #7
0
void analyseFitToystudiesLb(string filename, bool justTau = false)
{
    fileprefix = "fitToyStudiesLb";
    TTree *t = new TTree;
    //t->ReadFile(filename.c_str(),"tau:tau_err:mass_peak:mass_peak_err:m_sigma1:m_sigma1_err:m_sigma2:m_sigma2_err:frac_m_gauss:frac_m_gauss_err:core_frac:core_frac_err:tau_bk:tau_bk_err:n_nonprompt:n_nonprompt_err:n_prompt:n_prompt_err:n_signal:n_signal_err:prompt_p1:prompt_p1_err:prompt_sigma_core:prompt_sigma_core_err:prompt_sigma_tail:prompt_sigma_tail_err"); // alter Fit
    //t->ReadFile(filename.c_str(),"tau:tau_err:mass_peak:mass_peak_err:m_sigma1:m_sigma1_err:m_sigma2:m_sigma2_err:frac_m_gauss:frac_m_gauss_err:core_frac:core_frac_err:tau_bk:tau_bk_err:n_nonprompt:n_nonprompt_err:n_prompt:n_prompt_err:n_signal:n_signal_err:prompt_p1:prompt_p1_err:prompt_sigma_core:prompt_sigma_core_err:prompt_sigma_tail:prompt_sigma_tail_err:npr_reso_sigma:npr_reso_sigma_err:sig_reso_sigma:sig_reso_sigma_err"); // Fit ohne PEE
    //t->ReadFile(filename.c_str(),"tau:tau_err:mass_peak:mass_peak_err:m_sigma1:m_sigma1_err:m_sigma2:m_sigma2_err:frac_m_gauss:frac_m_gauss_err:tau_bk:tau_bk_err:n_nonprompt:n_nonprompt_err:n_prompt:n_prompt_err:n_signal:n_signal_err:prompt_p1:prompt_p1_err:reso_bias:reso_bias_err:reso_sigma:reso_sigma_err"); // Fit mit PEE 1 Gauss
    t->ReadFile(filename.c_str(),"tau:tau_err:mass_peak:mass_peak_err:m_sigma1:m_sigma1_err:m_sigma2:m_sigma2_err:frac_m_gauss:frac_m_gauss_err:tau_bk:tau_bk_err:n_nonprompt:n_nonprompt_err:n_prompt:n_prompt_err:n_signal:n_signal_err:prompt_p1:prompt_p1_err:reso_bias:reso_bias_err:reso_sigma:reso_sigma_err:npr_reso_bias:npr_reso_bias_err:npr_reso_sigma:npr_reso_sigma_err:sig_reso_bias:sig_reso_bias_err:sig_reso_sigma:sig_reso_sigma_err"); // Fit mit PEE 3 Gauss
    //t.Draw("tau>>htau");
    //t->Draw("(tau-1.507)/tau_err>>htau_pulls(100,-5,5)");
    if (!justTau)
    {
	const int Nevents = 5000;
	const double bgrfrac = 0.8;
	const double nonprfrac = 0.25;
	const int Nsig = Nevents * (1-bgrfrac);
	const int Npr = Nevents * bgrfrac * ( 1-nonprfrac);
	const int Nnpr = Nevents * bgrfrac * nonprfrac;
	plotPulls(t, "tau_pulls", "#tau(#Lambda_{b})", "tau", 1.507, 100, 5.0);
	plotPulls(t, "mass_pulls", "m(#Lambda_{b})", "mass_peak", 5.6202, 100, 5.0);
	plotPulls(t, "tau_bk_pulls", "#tau_{bgr}(#Lambda_{b})", "tau_bk", 0.750, 100, 5.0);
	plotPulls(t, "nsig_pulls", "n_{sig}", "n_signal", Nsig, 100, 5.0);
	plotPulls(t, "npr_pulls", "n_{prompt}", "n_prompt", Npr, 100, 10.0);
	plotPulls(t, "nnpr_pulls", "n_{nonprompt}", "n_nonprompt", Nnpr, 100, 10.0);
    }

    plotHisto(t, "tau_histo", "#tau(#Lambda_{b})", "ps", "tau", 100, 1.30, 1.70);
    if (!justTau)
    {
	plotHisto(t, "mass_histo", "m(#Lambda_{b})", "GeV", "mass_peak", 100, 5.615, 5.625);
	plotHisto(t, "tau_bk_histo", "#tau_{bgr}(#Lambda_{b})", "ps", "tau_bk", 100, 0.5, 0.9);
	plotHisto(t, "nsig_histo", "n_{sig}", "", "n_signal", 100, .8*Nsig, 1.2*Nsig);
	plotHisto(t, "npr_histo", "n_{prompt}", "", "n_prompt", 100, .8*Npr, 1.2*Npr);
	plotHisto(t, "nnpr_histo", "n_{nonprompt}", "", "n_nonprompt", 100, 0.8*Nnpr, 1.2*Nnpr);
    }
}
Example #8
0
int main(int argc, char *argv[])
{
  int i,j,n;
  FILE *inputfile,*outputfile;
  
  // mwd parameters
  int k;                   // integration time
  int l = WINDOW_WIDTH;    // l is fixed
  int m;                   // decay constant

  int min;
  int max;
  int chan;

  double fwhm;                 // FWHM = 2.35 * sigma
  double fwhm_min = 100000;    // to keep track of the minimum FWHM
  int k_min;                   // to keep track of the k param for which fwhm is minimized
  int m_min;                   // to keep track of the m param for which fwhm is minimized

  int num_waveforms;
  int good_waveforms = 0;

  double p[NUM_PARAMS];
  double *histData = NULL;
  double peakData[2*GAUSSIAN_PEAK_WIDTH+1];

  int peak_centre, peak_start;
  double peak_amp;

  /* Read in waveform data from input file*/
  if ((inputfile = fopen(argv[1],"r")) == NULL)
    {
      fprintf(stdout, "Input file does not exist.\n");
    }
  else
    {
      // check if output file already exists
      if ((outputfile = fopen(argv[2],"wx")) == NULL)
	{
	  fprintf(stdout, "Could not open output file or file already exists.\n");
	}
      else
	{
	  fclose(outputfile);
	  // count the total number of waveforms in file
	  char c;
	  long total_waveforms;
	  long lines;
	  
	  while ((c=getc(inputfile)) != EOF)
	    {
	      if (c=='\n')
		{
		  lines++;
		}
	    }
	  total_waveforms = (long) (lines/NUM_SAMPLES*1.0 + 0.5);
	  num_waveforms = MIN(MAX_WAVEFORMS, total_waveforms);
	  for (k=K_MIN;k<=K_MAX;k+=K_STEP)
	    {
	      outputfile = fopen(argv[2],"a");
	      fprintf(outputfile, "\n");
	      for (m=M_MIN;m<=M_MAX;m+=M_STEP)
		{
		  printf("k = %d, m = %d\n", k, m);
		  good_waveforms = 0;
		  fseek(inputfile, 0, SEEK_SET);
		  for (i=0;i<num_waveforms;i++)
		    {
		      for (j=0;j<NUM_SAMPLES;j++)
			{
			  fscanf(inputfile, "%f\n", &v[j]);
			}
		      // filter waveform with MWD and evaluate pulse height
		      differenceFilterFloat(l, v, y);
		      deconvolutionFilterFloat(l, m, y, y);
		      pulseHeights[i] = (int) (pulseHeightFloat(y, k) + 0.5);
		      //plotLine(v, NUM_SAMPLES, 0);
		      // plotLine(y, NUM_SAMPLES, 0);
		    }
		  
		  /* Plot Energy Spectrum */
		  // Find minimum and maximum pulse heights   
		  max = 0;
		  min = 100000;
		 
		  for (i=0;i<num_waveforms;i++)
		    {
		      if (pulseHeights[i] > max)
			{
			  max = pulseHeights[i];
			}
		    }
		  for (i=0;i<num_waveforms;i++)
		    {
		      if (pulseHeights[i] > 0 && pulseHeights[i] < min)
			{
			  min = pulseHeights[i];
			}
		    }
		  histData = (double*)calloc(max+1, sizeof(double));

		  for (i=0;i<num_waveforms;i++)
		    {
		      if (pulseHeights[i] > 0)
		  	{
		  	  good_waveforms++;
		  	  chan = pulseHeights[i];
		  	  histData[chan] += 1.0;
		  	}
		    }
		  plotHisto(histData, max, 0, 1500);
	  
		  /* Fit peak to find FWHM */
		  // we only want to fit the peak, not the whole spectrum 	  
		  // find the peak we want to fit
		  peak_start = peakFind(histData, max, PEAK_NUM, 300, 50);
		  peak_amp = 0;
		  for (i=peak_start;i<peak_start+GAUSSIAN_PEAK_WIDTH+1;i++)
		    {
		      if (histData[i] > peak_amp)
		  	{
		  	  peak_amp = histData[i];
		  	  peak_centre = i;
		  	}
		    }
		  free(histData);
		  for (i=0;i<GAUSSIAN_PEAK_WIDTH*2+1;i++)
		    {
		      peakData[i] = histData[(peak_centre-GAUSSIAN_PEAK_WIDTH)+i];
		  }
		  p[0] = peak_amp*5.5;
		  p[1] = GAUSSIAN_PEAK_WIDTH;
		  p[2] = 0.5;
		  fitData(peakData, GAUSSIAN_PEAK_WIDTH*2+1, p, 0, 0);
		  // calculate the fwhm from fit parameters and keep track of the minimum value
		  if (2.35*p[2]<fwhm_min)
		    {
		      fwhm_min = 2.35*p[2];
		      k_min = k;
		      m_min = m;
		    }
		  fprintf(outputfile, "%d\t%d\t%g\n", k, m, 2.35*p[2]*PEAK_ENERGY/(p[1]-GAUSSIAN_PEAK_WIDTH+peak_centre));
		  printf("Processed %d waveforms, %d counts in spectrum\n", num_waveforms, good_waveforms);
		}
	      fclose(outputfile);
	    }
	  fclose(inputfile);
	  //print summary to screen
	  printf("Finished processing file %s\n", argv[1]);
	  printf("Mminimum energy resolution: %g channels and %g keV at k = %d and m = %d\n", fwhm_min, fwhm_min*PEAK_ENERGY/(p[1]-GAUSSIAN_PEAK_WIDTH+peak_centre), k_min, m_min);
	}
    }
  return 0;
}
Example #9
0
void work(TVersion_t inpVer,
	  CrossSection_t &eeCS, TVaried_t var, int nSample, int doSave)
{
  std::vector<TH1D*> rndCSVec;
  int res=1;
  int removeNegativeSignal=1;
  if ((var!=_varRhoFile) && (var!=_varRhoSystFile) &&(var!=_varRhoSystFileSymm))
    res=eeCS.sampleRndVec(var,nSample,removeNegativeSignal,rndCSVec);
  else if (var==_varRhoFile) {
    TString inpVerTag=versionName(inpVer);
    TString loadFName=Form("dir-Rho%s/dyee_rhoRndVec_%s_%d.root",
			   inpVerTag.Data(),inpVerTag.Data(),
			   nSample);
    RndVecInfo_t info(loadFName,"h1rho_var");
    res=eeCS.sampleRndVec(var,nSample,info,removeNegativeSignal, rndCSVec);
  }
  else if (var==_varRhoSystFile) {
    TString inpVerTag=versionName(inpVer);
    TString loadFName=Form("dir-RhoSyst%s/dyee_rhoRndSystVec_%s_%d.root",
			   inpVerTag.Data(),inpVerTag.Data(),
			   nSample);
    RndVecInfo_t info(loadFName,"rhoRndSyst/h1rho_rnd");
    res=eeCS.sampleRndVec(var,nSample,info,removeNegativeSignal, rndCSVec);
  }
  else if (var==_varRhoSystFileSymm) {
    TString inpVerTag=versionName(inpVer);
    TString loadFName=Form("dir-RhoSystSymm-%s/dyee_rhoRndSystVec_%s_%d.root",
			   inpVerTag.Data(),inpVerTag.Data(),
			   nSample);
    RndVecInfo_t info(loadFName,"rhoRndSyst/h1rho_rnd");
    res=eeCS.sampleRndVec(var,nSample,info,removeNegativeSignal, rndCSVec);
  }
  else {
    std::cout << "code error: this branch should not be reached\n";
    res=0;
  }
  if (!res) return;
  TH1D* h1Avg=NULL;
  TH2D* h2Cov=NULL;
  if (!eeCS.deriveCov(rndCSVec,&h1Avg,&h2Cov)) return;

  TString massLabel= niceMassAxisLabel(leptonIdx(inpVer),"",0);
  h2Cov->GetXaxis()->SetTitle(massLabel);
  h2Cov->GetYaxis()->SetTitle(massLabel);
  h2Cov->SetTitle("h2cov " + variedVarName(var));

  PlotCovCorrOpt_t ccOpt;
  ccOpt.yTitleOffset=1.8;

  
  TCanvas *c= eeCS.plotCrossSection("cs");
  if (!c) return;
  h1Avg->SetLineColor(kGreen+1);
  h1Avg->SetMarkerColor(kGreen+1);
  plotHistoSame(h1Avg,"cs","LPE","rnd avg");
  printRatio(eeCS.h1PreFsrCS(), h1Avg);

  TH2D* h2Corr=NULL;
  TCanvas *cx= plotCovCorr(h2Cov,"ccov",ccOpt,&h2Corr);
  if (!cx) std::cout << "cx is null\n";

  TH1D *h1uncFromCov= uncFromCov(h2Cov);
  TH1D *h1relUncFromCov= uncFromCov(h2Cov,eeCS.h1PreFsrCS());

  if (!doSave) {
    std::cout << "Comparing uncertainty from covariance to the uncertainty "
	      << "in the provided cross-section\n";
    std::cout << "Expectation is that the covariance uncertainties will not "
	      << "exceed those from the cross-section\n";
    TH1D *h1CSUnc= errorAsCentral(eeCS.h1PreFsrCS(),0);
    TH1D *h1CSRelUnc= errorAsCentral(eeCS.h1PreFsrCS(),1);
    histoStyle(h1CSUnc,kBlue,24);
    histoStyle(h1CSRelUnc,kBlue,24);
    plotHisto(h1uncFromCov,"cUncCmp",1,1,"hist","uncFromCov");
    plotHistoSame(h1CSUnc,"cUncCmp","P","csUnc");

    plotHisto(h1relUncFromCov,"cRelUncCmp",1,1,"hist","rel.unc.from.cov");
    plotHistoSame(h1CSRelUnc,"cRelUncCmp","P","cs.rel.unc");
  }

  if (doSave) {
    TString fname="cov_ee_" + versionName(inpVer) + "_" +
      variedVarName(var) + Form("_%d.root",nSample);
    if ((inpVer==_verEl3mb41) || (inpVer==_verEl3mb42)) {
      fname.ReplaceAll("ee_",Form("ee%d_",DYtools::nMassBins));
    }
    if (doSave==2) fname.ReplaceAll(".root","_slim.root");
    if (var==_varFSRRes_Poisson) fname.ReplaceAll(".root","-Poisson.root");
    TFile fout(fname,"RECREATE");
    if (!fout.IsOpen()) {
      std::cout << "file <" << fname << "> could not be created\n";
      return;
    }
    std::vector<TString> dirs;
    std::vector<std::vector<TH1D*>*> hVs;
    if (doSave!=2) {
      dirs.push_back("rnd_CStot");
      hVs.push_back(&rndCSVec);
    }
    for (unsigned int iDir=0; iDir<dirs.size(); iDir++) {
      std::vector<TH1D*> *hV= hVs[iDir];
      if (hV->size()) {
	fout.mkdir(dirs[iDir]);
	fout.cd(dirs[iDir]);
	for (unsigned int ih=0; ih<hV->size(); ih++) {
	  hV->at(ih)->Write();
	}
	fout.cd("");
      }
    }
    if (eeCS.h1PreFsrCS()) eeCS.h1PreFsrCS()->Write("xsec");
    if (eeCS.h1Theory()) eeCS.h1Theory()->Write("xsec_RC");
    if (h1Avg) h1Avg->Write("h1xsecAvg");
    if (h2Cov) h2Cov->Write("h2Cov");
    if (h2Corr) h2Corr->Write("h2Corr");
    if (h1uncFromCov) h1uncFromCov->Write("h1uncFromCov");
    if (h1relUncFromCov) h1relUncFromCov->Write("h1relUncFromCov");
    if (c) c->Write();
    if (cx) cx->Write();
    std::vector<TCanvas*> canvV;
    TString canvList;
    if (doSave==2) canvList="";
    canvList+=" cVaried_" + variedVarName(var) + "_" + versionName(inpVer);
    std::cout << "canvList=" << canvList << "\n";
    if (canvList.Length() && findCanvases(canvList,canvV)) {
      for (unsigned int ic=0; ic<canvV.size(); ic++) {
	canvV[ic]->Write();
      }
    }
    TObjString timeTag(DayAndTimeTag(0));
    timeTag.Write("timeTag");
    fout.Close();
    std::cout << "file <" << fout.GetName() << "> created\n";
  }
}
Example #10
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;
}
Example #11
0
void processDYmm(Int_t maxEntries=-1)
{
  std::cout << "DY range=" << DYtools::minMass << " .. " << DYtools::maxMass << "\n";

  TVersion_t inpVersion=_verMu1;
  inpVersion=_verMu76X;
  inpVersion=_verMuApproved;

  if (inpVersion!=_verMu1) {
    if (DYtools::nMassBins!=DYtools::nMassBins43) {
      std::cout << "a potential DYbinning.h problem\n";
      return;
    }
  }

  TString srcPath="/media/ssd/v20160214_1st_CovarianceMatrixInputs/";
  srcPath="/mnt/sdb/andriusj/v20160214_1st_CovarianceMatrixInputs/";
  TString dataFName=srcPath + "Input3/ROOTFile_ntuple_CovarianceMatrixInput.root";

  if (inpVersion==_verMu76X) {
    srcPath="/mnt/sdb/andriusj/v20160527_1st_CovarianceMatrixInputs_76X/";
    dataFName=srcPath + "Input3/ROOTFile_Input_CovarianceMatrix.root";
  }
  else if (inpVersion==_verMuApproved) {
    srcPath="/mnt/sdb/andriusj/v20160915_CovInput_ApprovedResults/";
    dataFName=srcPath + "ROOTFile_Input_CovarianceMatrix.root";
  }

  DYmm13TeV_t data(dataFName);
  data.DeactivateBranches();
  data.ActivateBranches("Momentum_postFSR_Lead  Momentum_postFSR_Sub  Momentum_preFSR_Lead  Momentum_preFSR_Sub  Weight_Norm  Weight_Gen Weight_PU");
  data.ActivateBranches("Flag_EventSelection");

  TH1D *h1postFsrInAccSel_M= new TH1D("h1_postFsrInAccSel_M", "postFSR selected events in acceptance;M_{gen,postFSR} [GeV];count",DYtools::nMassBins,DYtools::massBinEdges);
  TH1D *h1postFsrInAccSel_MW= new TH1D("h1_postFsrInAccSel_MW", "postFSR selected events in acceptance (weighted);M_{gen,postFSR} [GeV];weighted count",DYtools::nMassBins,DYtools::massBinEdges);
  TH1D *h1postFsrInAccSel_MWPU= new TH1D("h1_postFsrInAccSel_MWPU", "postFSR selected events in acceptance (weighted wPU);M_{gen,postFSR} [GeV];weighted (wPU) count",DYtools::nMassBins,DYtools::massBinEdges);
  TH1D *h1postFsrInAcc_M= new TH1D("h1_postFsrInAcc_M", "postFSR in acceptace;M_{gen,postFSR} [GeV];count",DYtools::nMassBins,
			    DYtools::massBinEdges);
  TH1D *h1postFsrInAcc_MW= new TH1D("h1_postFsrInAcc_Mweighted", "postFSR in acceptance;M_{gen,postFSR} [GeV];weighted count", DYtools::nMassBins,
			    DYtools::massBinEdges);
  TH1D *h1postFsrInAcc_MWPU= new TH1D("h1_postFsrInAcc_MweightedPU", "postFSR in acceptance (weighted wPU);M_{gen,postFSR} [GeV];weighted (wPU) count", DYtools::nMassBins,
			    DYtools::massBinEdges);
  TH1D *h1postFsr_M= new TH1D("h1_postFsr_M", "postFSR;M_{gen,postFSR} [GeV];count",DYtools::nMassBins,
			    DYtools::massBinEdges);
  TH1D *h1postFsr_MW= new TH1D("h1_postFsr_Mweighted", "postFSR;M_{gen,postFSR} [GeV];weighted count", DYtools::nMassBins,
			    DYtools::massBinEdges);
  TH1D *h1preFsr_M= new TH1D("h1_preFsr_M", "preFSR;M_{gen,preFSR} [GeV];count",DYtools::nMassBins,
			   DYtools::massBinEdges);
  TH1D *h1preFsr_MW= new TH1D("h1_preFsr_Mweighted", "preFSR;M_{gen,preFSR} [GeV];weighted count", DYtools::nMassBins,
			   DYtools::massBinEdges);
  prepareHisto(h1postFsrInAccSel_M);
  prepareHisto(h1postFsrInAccSel_MW);
  prepareHisto(h1postFsrInAccSel_MWPU);
  prepareHisto(h1postFsrInAcc_M);
  prepareHisto(h1postFsrInAcc_MW);
  prepareHisto(h1postFsrInAcc_MWPU);
  prepareHisto(h1postFsr_M);
  prepareHisto(h1postFsr_MW);
  prepareHisto(h1preFsr_M);
  prepareHisto(h1preFsr_MW);

  TH2D* h2FSRmig= new TH2D("h2FSRmig","FSR migration", DYtools::nMassBins, DYtools::massBinEdges, DYtools::nMassBins, DYtools::massBinEdges);
  h2FSRmig->Sumw2();
  RooUnfoldResponse fsrResp(h1postFsr_MW,h1preFsr_MW,h2FSRmig,"rooUnf_fsrResp","fsrResp;M_{#mu#mu} [GeV];FSR unfolded yield");
  fsrResp.UseOverflow();

  TH2D* h2effAccFSRmig= new TH2D("h2effAccFSRmig","eff x Acc x FSR migration", DYtools::nMassBins, DYtools::massBinEdges, DYtools::nMassBins, DYtools::massBinEdges);
  h2effAccFSRmig->Sumw2();
  RooUnfoldResponse effAccFsrResp(h1postFsrInAccSel_MW,h1preFsr_MW,h2effAccFSRmig,"rooUnf_effAccFsrResp","effAccFsrResp;M_{#mu#mu} [GeV];eff Acc FSR unfolded yield");
  effAccFsrResp.UseOverflow();


  UInt_t nEvents= data.GetEntries();

  std::cout << "process data\n";
  for (UInt_t iEntry=0; iEntry<nEvents; iEntry++) {
    if (data.GetEntry(iEntry)<0) break;
    if (iEntry%100000==0) std::cout << "iEntry=" << iEntry << Form("(%4.2lf%%)\n",iEntry*100/double(nEvents));
    if ((maxEntries>0) && (iEntry>UInt_t(maxEntries))) {
      std::cout << "debug run\n";
      break;
    }
    double w= data.Weight_Norm * data.Weight_Gen;
    if (iEntry<100) std::cout << "w=" << w << ": weight_norm=" << data.Weight_Norm << ", gen=" << data.Weight_Gen << "\n";
    double mPostFsr= (*data.Momentum_postFSR_Lead + *data.Momentum_postFSR_Sub).M();
    double mPreFsr= (*data.Momentum_preFSR_Lead + *data.Momentum_preFSR_Sub).M();
    if (DYtools::InAcceptance_mm(data.Momentum_postFSR_Lead,data.Momentum_postFSR_Sub)) {
      if (data.Flag_EventSelection) {
	h1postFsrInAccSel_M->Fill( mPostFsr, 1. );
	h1postFsrInAccSel_MW->Fill( mPostFsr, w );
	h1postFsrInAccSel_MWPU->Fill( mPostFsr, w * data.Weight_PU );
      }
      h1postFsrInAcc_M->Fill( mPostFsr, 1. );
      h1postFsrInAcc_MW->Fill( mPostFsr, w );
      h1postFsrInAcc_MWPU->Fill( mPostFsr, w * data.Weight_PU );
    }
    h1postFsr_M->Fill( mPostFsr, 1. );
    h1postFsr_MW->Fill( mPostFsr, w );
    h1preFsr_M->Fill( mPreFsr, 1. );
    h1preFsr_MW->Fill( mPreFsr, w );
    h2FSRmig->Fill( mPostFsr, mPreFsr, w );

    if (0) {
      if ( ! DYtools::InsideMassRange(mPreFsr) )
	std::cout << "preFSR mass " << mPreFsr << ", postFSR mass " << mPostFsr << "\n";
    }

    if ( ! DYtools::InsideMassRange(mPreFsr) &&
	 DYtools::InsideMassRange(mPostFsr) ) {
      std::cout << "fake detected\n";
      fsrResp.Fake(mPostFsr,w);
    }
    else if ( DYtools::InsideMassRange(mPreFsr) &&
	      ! DYtools::InsideMassRange(mPostFsr) ) {
      fsrResp.Miss(mPreFsr,w);
    }
    else {
      fsrResp.Fill(mPostFsr,mPreFsr,w);
    }

    int sel=(DYtools::InAcceptance_mm(data.Momentum_postFSR_Lead,data.Momentum_postFSR_Sub) && data.Flag_EventSelection && DYtools::InsideMassRange(mPostFsr)) ? 1:0;
    if (sel) h2effAccFSRmig->Fill(mPostFsr,mPreFsr,w);
    if ( ! DYtools::InsideMassRange(mPreFsr) && sel ) {
      effAccFsrResp.Fake(mPostFsr,w);
    }
    else if ( DYtools::InsideMassRange(mPreFsr) && ! sel ) {
      effAccFsrResp.Miss(mPreFsr,w);
    }
    else {
      effAccFsrResp.Fill(mPostFsr,mPreFsr,w);
    }
  }

  RooUnfoldBayes bayesFSR( &fsrResp, h1postFsr_MW, 4 );
  TH1D *h1preFsrUnf= (TH1D*) bayesFSR.Hreco()->Clone("h1preFsrUnf");
  h1preFsrUnf->SetTitle("unfolded postFSR->preFSR");
  h1preFsrUnf->SetDirectory(0);
  histoStyle(h1preFsrUnf,kRed,24);
  h1preFsrUnf->GetXaxis()->SetMoreLogLabels();
  h1preFsrUnf->GetXaxis()->SetNoExponent();
  TCanvas *cFSRTest=plotHisto(h1preFsrUnf,"cFSRTest",1,1,"LPE1");
  plotHistoSame(h1preFsr_MW,"cFSRTest","LPE");

  RooUnfoldBayes bayesEffAccFsr( &effAccFsrResp, h1postFsrInAccSel_MW, 4 );
  TH1D *h1EffAccFsrUnf= (TH1D*) bayesEffAccFsr.Hreco()->Clone("h1EffAccFsrUnf");
  h1EffAccFsrUnf->SetTitle("unfolded postFsrInAccSel -> preFSR");
  h1EffAccFsrUnf->SetDirectory(0);
  histoStyle(h1EffAccFsrUnf,kRed,24);
  h1EffAccFsrUnf->GetXaxis()->SetMoreLogLabels();
  h1EffAccFsrUnf->GetXaxis()->SetNoExponent();
  TCanvas *cScaleToPreFsrTest= plotHisto(h1EffAccFsrUnf,"cScaleToPreFsrTest",1,1,"LPE1");
  histoStyle(h1preFsr_MW,kBlue,5);
  plotHistoSame(h1preFsr_MW,"cScaleToPreFsrTest","LPE");

  TH1D* h1Eff=(TH1D*)h1postFsrInAccSel_MW->Clone("h1Eff");
  h1Eff->SetDirectory(0);
  if (!h1Eff->GetSumw2()) h1Eff->Sumw2();
  h1Eff->SetTitle("Efficiency;M_{#mu#mu,GEN postFSR} [GeV];postFSR_inAcc_Sel/postFSR_inAcc");
  h1Eff->Divide(h1postFsrInAccSel_MW,h1postFsrInAcc_MW,1,1,"B");

  TH1D* h1EffPU=(TH1D*)h1postFsrInAccSel_MWPU->Clone("h1EffPU");
  h1EffPU->SetDirectory(0);
  if (!h1EffPU->GetSumw2()) h1EffPU->Sumw2();
  h1EffPU->SetTitle("Efficiency (wPU);M_{#mu#mu,GEN postFSR} [GeV];postFSR_inAcc_Sel(wPU)/postFSR_inAcc(wPU)");
  h1EffPU->Divide(h1postFsrInAccSel_MWPU,h1postFsrInAcc_MWPU,1,1,"B");

  histoStyle(h1EffPU,kBlue,24);
  TCanvas *cEffCmp=plotHisto(h1Eff,"cEff_noPU_vs_wPU",1,0,"LPE1");
  plotHistoSame(h1EffPU,"cEff_noPU_vs_wPU","LPE");

  TH1D* h1Acc=(TH1D*)h1postFsrInAcc_MW->Clone("h1Acc");
  h1Acc->SetDirectory(0);
  if (!h1Acc->GetSumw2()) h1Acc->Sumw2();
  h1Acc->SetTitle("Acceptance;M_{#mu#mu,GEN postFSR} [GeV];postFSR_inAcc/postFSR");
  h1Acc->Divide(h1postFsrInAcc_MW,h1postFsr_MW,1,1,"B");

  TH1D* h1EffPUAcc=(TH1D*)h1postFsrInAccSel_MWPU->Clone("h1EffPUAcc");
  h1EffPUAcc->SetDirectory(0);
  if (!h1EffPUAcc->GetSumw2()) h1EffPUAcc->Sumw2();
  h1EffPUAcc->SetTitle("Efficiency(wPU) x Acc;M_{#mu#mu,GEN postFSR} [GeV];postFSR_inAccSel(wPU)/h1postFsr_MW(noPU)");
  h1EffPUAcc->Divide(h1postFsrInAccSel_MWPU,h1postFsr_MW,1,1,"B");

  TH1D *h1FSRCorr_binByBin=(TH1D*)h1preFsr_MW->Clone("h1FSRCorr_binByBin");
  h1FSRCorr_binByBin->SetDirectory(0);
  if (!h1FSRCorr_binByBin->GetSumw2()) h1FSRCorr_binByBin->Sumw2();
  h1FSRCorr_binByBin->SetTitle("FSR correction bin-by-bin;M_{#mu#mu} [GeV];preFSR/postFSR");
  h1FSRCorr_binByBin->Divide(h1preFsr_MW,h1postFsr_MW,1.,1.,"B");

  TString fname="dymm_test_" + versionName(inpVersion) + TString(".root");
  if (maxEntries>0) fname.ReplaceAll(".root","_debug.root");
  TFile fout(fname,"RECREATE");
  h1Eff->Write();
  h1EffPU->Write();
  h1Acc->Write();
  h1EffPUAcc->Write();
  h1FSRCorr_binByBin->Write();
  fsrResp.Write();
  effAccFsrResp.Write();
  h1postFsrInAccSel_M->Write();
  h1postFsrInAccSel_MW->Write();
  h1postFsrInAcc_M->Write();
  h1postFsrInAcc_MW->Write();
  h1postFsr_M->Write();
  h1postFsr_MW->Write();
  h1preFsr_M->Write();
  h1preFsr_MW->Write();
  h1preFsrUnf->Write();
  h2FSRmig->Write();
  h1EffAccFsrUnf->Write();
  h2effAccFSRmig->Write();
  cEffCmp->Write();
  cFSRTest->Write();
  cScaleToPreFsrTest->Write();
  TObjString timeTag(DayAndTimeTag(0));
  timeTag.Write("timeTag");
  fout.Close();
  std::cout << "file <" << fout.GetName() << "> created\n";
}