Пример #1
0
uint32_t TmpSndDawAudioProcessorEditor::Initialize()
{
  uint32_t maxParams = InitializeParams();
  uint32_t instCount = mInstLabels.size();
  uint32_t w = instCount * (horizontalPadding + instWidth);
  uint32_t h = maxParams * (verticalPadding + paramHeight) + paramHeight;
  // a cute little square window when we haven't received configuration data
  if (maxParams == 0 && instCount == 0) {
    w = 200;
    h = 200;
  }
  setSize (w + verticalPadding, h + horizontalPadding);
  return maxParams;
}
RollPitchYawrateThrustControllerNode::RollPitchYawrateThrustControllerNode() {
  google::InitGoogleLogging("rotors_control_glogger");
  InitializeParams();

  ros::NodeHandle nh;

  cmd_roll_pitch_yawrate_thrust_sub_ = nh.subscribe(kDefaultCommandRollPitchYawrateThrustTopic, 10,
                                     &RollPitchYawrateThrustControllerNode::CommandRollPitchYawrateThrustCallback, this);
  odometry_sub_ = nh.subscribe(kDefaultOdometryTopic, 10,
                               &RollPitchYawrateThrustControllerNode::OdometryCallback, this);

  motor_velocity_reference_pub_ = nh.advertise<mav_msgs::CommandMotorSpeed>(
      kDefaultMotorSpeedTopic, 10);
}
LeePositionControllerNode::LeePositionControllerNode() {
    InitializeParams();

    ros::NodeHandle nh;

    cmd_pose_sub_ = nh.subscribe(
                        mav_msgs::default_topics::COMMAND_POSE, 1,
                        &LeePositionControllerNode::CommandPoseCallback, this);

    cmd_multi_dof_joint_trajectory_sub_ = nh.subscribe(
            mav_msgs::default_topics::COMMAND_TRAJECTORY, 1,
            &LeePositionControllerNode::MultiDofJointTrajectoryCallback, this);

    odometry_sub_ = nh.subscribe(mav_msgs::default_topics::ODOMETRY, 10,
                                 &LeePositionControllerNode::OdometryCallback, this);

    motor_velocity_reference_pub_ = nh.advertise<mav_msgs::Actuators>(
                                        mav_msgs::default_topics::COMMAND_ACTUATORS, 10);

    command_timer_ = nh.createTimer(ros::Duration(0), &LeePositionControllerNode::TimedCommandCallback, this,
                                    true, false);
}
void trisCheckCorrection_unbinnedfit(Char_t* EBEE = 0,
                         Int_t evtsPerPoint = 0,
                         float laserCorrMin = -1.,
                         float laserCorrMax = -1.)
{
  // Set style options
  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetPadTickX(1);
  gStyle->SetPadTickY(1);
  gStyle->SetOptTitle(0); 
  gStyle->SetOptStat(1110); 
  gStyle->SetOptFit(1); 
  
  
  
  // Check qualifiers
  if ( strcmp(EBEE,"EB")!=0 && strcmp(EBEE,"EE")!=0 )
  {
    std::cout << "CHK-STB Error: unknown partition " << EBEE << std::endl;
    std::cout << "CHK-STB Select either EB or EE ! " << std::endl;
    return;
  }
  
  if ( strcmp(EBEE,"EB") == 0 )
  {
    lcMin = 0.99;
    lcMax = 1.05;
  }
  else
  {
    lcMin = 0.99;
    lcMax = 1.11;
  }
  
  if( (laserCorrMin != -1.) && (laserCorrMax != -1.) )
  {
    lcMin = laserCorrMin;
    lcMax = laserCorrMax;
  }
  
  
  
  // Get trees
  std::cout << std::endl;
  
  TChain* ntu_DA = new TChain("ntu");
  FillChain(ntu_DA,"inputDATA.txt");
  std::cout << "     DATA: " << std::setw(8) << ntu_DA->GetEntries() << " entries" << std::endl;
  
  TChain* ntu_MC = new TChain("ntu");
  FillChain(ntu_MC,"inputMC.txt");
  std::cout << "REFERENCE: " << std::setw(8) << ntu_MC->GetEntries() << " entries" << std::endl;
  
  if (ntu_DA->GetEntries() == 0 || ntu_MC->GetEntries() == 0 )
  {
    std::cout << "CHK-STB Error: At least one file is empty" << std::endl; 
    return;
  }  
  
  
  
  // Set branch addresses
  int runId;
  int isW, isZ;
  int timeStampHigh;
  float seedLaserAlpha;
  float avgLaserCorrection, scCrackCorrection;
  float EoP;
  float scE, scERaw, scEta, scEtaWidth, scPhiWidth;
  int seedIeta,seedIphi;
  int seedIx,seedIy,seedZside;
  float esE;
  float seedLaserCorrection;
  int iPhi,iEta;
  
  ntu_DA->SetBranchAddress("runId", &runId);  
  ntu_DA->SetBranchAddress("isW", &isW);
  //ntu_DA->SetBranchAddress("isZ", &isZ);
  ntu_DA->SetBranchAddress("timeStampHigh", &timeStampHigh);
  ntu_DA->SetBranchAddress("ele1_scCrackCorr", &scCrackCorrection);
  ntu_DA->SetBranchAddress("ele1_scLaserCorr", &avgLaserCorrection);
  ntu_DA->SetBranchAddress("ele1_seedLaserCorr", &seedLaserCorrection);
  ntu_DA->SetBranchAddress("ele1_seedLaserAlpha", &seedLaserAlpha);
  ntu_DA->SetBranchAddress("ele1_es", &esE);
  ntu_DA->SetBranchAddress("ele1_scE", &scE);
  ntu_DA->SetBranchAddress("ele1_scERaw", &scERaw);
  ntu_DA->SetBranchAddress("ele1_scEta", &scEta);
  ntu_DA->SetBranchAddress("ele1_scEtaWidth", &scEtaWidth);
  ntu_DA->SetBranchAddress("ele1_scPhiWidth", &scPhiWidth);
  ntu_DA->SetBranchAddress("ele1_EOverP", &EoP);
  ntu_DA->SetBranchAddress("ele1_seedIphi", &iPhi);
  ntu_DA->SetBranchAddress("ele1_seedIeta", &iEta);
  ntu_DA->SetBranchAddress("ele1_seedIeta",       &seedIeta);
  ntu_DA->SetBranchAddress("ele1_seedIphi",       &seedIphi);
  ntu_DA->SetBranchAddress("ele1_seedIx",         &seedIx);
  ntu_DA->SetBranchAddress("ele1_seedIy",         &seedIy);
  ntu_DA->SetBranchAddress("ele1_seedZside",      &seedZside);
  
  ntu_MC->SetBranchAddress("isW", &isW);
  ntu_MC->SetBranchAddress("isZ", &isZ);
  ntu_MC->SetBranchAddress("ele1_scEta", &scEta);
  ntu_MC->SetBranchAddress("ele1_EOverP", &EoP);
  
  

  float params[42];
  InitializeParams(params);
  
  
  // Build the reference from 'infile2'
  std::cout << std::endl;
  std::cout << "***** Build reference for " << EBEE << " *****" << std::endl;
  
  templateHisto = new TH1F("templateHisto", "", 1200, 0., 5.);

  for(int ientry = 0; ientry < ntu_MC->GetEntries(); ++ientry)
  {
    if( (ientry%100000 == 0) ) std::cout << "reading MC entry " << ientry << std::endl;
    ntu_MC->GetEntry(ientry);
    
    if (strcmp(EBEE,"EB")==0 && fabs(scEta) > 1.4442) continue;                       // barrel
    if (strcmp(EBEE,"EE")==0 && (fabs(scEta) < 1.56 || fabs(scEta) > 2.5 )) continue; // endcap
    
    //if( seedLaserAlpha > 1.5 ) continue;
        
    //if( fabs(scEta) > 0.44 ) continue;
    //if( fabs(scEta) < 0.44 || fabs(scEta) > 0.77 ) continue;
    //if( fabs(scEta) < 0.77 || fabs(scEta) > 1.10 ) continue;
    //if( fabs(scEta) < 1.10 || fabs(scEta) > 1.56 ) continue;
    //if( fabs(scEta) < 1.56 || fabs(scEta) > 2.00 ) continue;
    //if( fabs(scEta) < 2.00 ) continue;
        
    templateHisto -> Fill(EoP);
  }

  int rebin = 4;
  if (strcmp(EBEE,"EB")==0) rebin = 2;
  templateHisto -> Rebin(rebin);  
  FitTemplate();
  
  std::cout << "Reference built for " << EBEE << " - " << templateHisto->GetEntries() << " events" << std::endl;
  
  
  
  // Loop and sort events
  std::cout << std::endl;
  std::cout << "***** Sort events and define bins *****" << std::endl;
  
  int nEntries = ntu_DA -> GetEntriesFast(); 
  int nSavePts = 0; 
  std::vector<bool> isSavedEntries(nEntries);
  std::vector<SorterLC> sortedEntries;
  
  for(int ientry = 0; ientry < nEntries; ++ientry)
  {
    ntu_DA -> GetEntry(ientry); 
    isSavedEntries.at(ientry) = false;
    
    // save only what is needed for the analysis!!!
    if (strcmp(EBEE,"EB")==0 && fabs(scEta) > 1.4442) continue;                       // barrel
    if (strcmp(EBEE,"EE")==0 && (fabs(scEta) < 1.56 || fabs(scEta) > 2.5 )) continue; // endcap
    
    //if( fabs(scEta) > 0.44 ) continue;
    //if( fabs(scEta) < 0.44 || fabs(scEta) > 0.77 ) continue;
    //if( fabs(scEta) < 0.77 || fabs(scEta) > 1.10 ) continue;
    //if( fabs(scEta) < 1.10 || fabs(scEta) > 1.56 ) continue;
    //if( fabs(scEta) < 1.56 || fabs(scEta) > 2.00 ) continue;
    //if( fabs(scEta) < 2.00 ) continue;
    
        
    if( seedLaserCorrection <= 1.) continue;   
    if( seedLaserAlpha < 1.5 ) continue;
    //if( timeStampHigh > 1303862400 ) continue;
    
    if( seedZside < 0 )
      if( (seedIx > 20 ) && (seedIx < 50) && (seedIy > 85) && (seedIy < 92) ) continue;
    if( seedZside == -1 )
      if( (seedIx > 35 ) && (seedIx < 55) && (seedIy > 80) && (seedIy < 87) ) continue;
    if( seedZside > 0 )
      if( (seedIx > 65 ) && (seedIx < 77) && (seedIy > 33) && (seedIy < 57) ) continue;
    if( seedZside > 0 )
      if( (seedIx > 75 ) && (seedIx < 93) && (seedIy > 18) && (seedIy < 37) ) continue;    
    
    //if ( runId < 163045 ) continue;
    //if ( runId >= 163232 ) continue;
    //if ( runId < 163232 ) continue;
    
    
    //*********************** CLUSTER CORR *****************************
    //if( (ientry%1 == 0) ) std::cout << "\n\n\nreading entry " << ientry << std::endl;    
    //Ediff -> Fill( ( (scCrackCorrection*fClusterCorrections(scERaw+esE,scEta,scPhiWidth/scEtaWidth,params))-scE)/scE );
    //Ediff_vsEta -> Fill( scEta, ( (esE+scCrackCorrection*fClusterCorrections(scERaw,scEta,scPhiWidth/scEtaWidth,params))-scE)/scE );
    //if( fabs(fClusterCorrections(scERaw,scEta,scPhiWidth/scEtaWidth,params)-scE) > 0.001 )
    //{
    //  std::cout << "\n\n" << std::endl;
    //  std::cout << "scEta = " << scEta << "   scE = " << scE << "   scERaw = " << scERaw << std::endl;
    //  std::cout << "scERaw_corr = " << fClusterCorrections(scERaw,scEta,scPhiWidth/scEtaWidth,params) << std::endl;
    //}
    //*********************** CLUSTER CORR *****************************
        
    isSavedEntries.at(ientry) = true;
    
    SorterLC dummy;
    dummy.laserCorr = avgLaserCorrection;
    dummy.entry = ientry;
    sortedEntries.push_back(dummy);
    
    nSavePts++; 
  }
  std::sort(sortedEntries.begin(),sortedEntries.end(),SorterLC());
  std::cout << "Data sorted in " << EBEE << " - " << nSavePts << " events" << std::endl;
  
  //TCanvas* c_diff = new TCanvas("c_diff","c_diff");
  //c_diff -> cd();
  //Ediff -> Draw();
  //
  //TCanvas* c_diff_vsEta = new TCanvas("c_diff_vsEta","c_diff");
  //c_diff_vsEta -> cd();
  //Ediff_vsEta -> Draw("colz");
  
  // bins with evtsPerPoint events per bin
  int nBins = std::max(1,int(nSavePts/evtsPerPoint));
  int nBinPts = int( nSavePts/nBins );
  int nBinTempPts = 0;
  
  std::vector<int> binEntryMax;
  binEntryMax.push_back(0);
  for(int iSaved = 0; iSaved < nSavePts; ++iSaved)
  {
    ++nBinTempPts;
    
    if( nBinTempPts == nBinPts )
    {
      binEntryMax.push_back( iSaved );      
      nBinTempPts = 0;
    }
  }
  binEntryMax.at(nBins) = nSavePts;
  
  std::cout << "nBins = " << nBins << std::endl;
  for(int bin = 0; bin < nBins; ++bin)
    std::cout << "bin: " << bin
              << "   entry min: " << setw(6) << binEntryMax.at(bin)
              << "   entry max: " << setw(6) << binEntryMax.at(bin+1)
              << "   events: "    << setw(6) << binEntryMax.at(bin+1)-binEntryMax.at(bin)
              << std::endl;
  TVirtualFitter::SetDefaultFitter("Fumili2");
  
  
  
  // histogram definition
  
  TH1F* h_EoP_spread;
  TH1F* h_EoC_spread;
  TH2F* h_LC_map = new TH2F("h_LC_map","",360,0.,360,170,-85,85);
  
  if ( strcmp(EBEE,"EB")==0 )
  {  
    h_EoP_spread = new TH1F("h_EoP_spread","",100,0.95,1.01);
    h_EoC_spread = new TH1F("h_EoC_spread","",100,0.95,1.01);    
  }
  else 
  {  
    h_EoP_spread = new TH1F("h_EoP_spread","",100,0.91,1.03);
    h_EoC_spread = new TH1F("h_EoC_spread","",100,0.91,1.03);    
  }
  
  h_EoP_spread -> SetLineColor(kRed+2);
  h_EoP_spread -> SetLineWidth(2);
  h_EoP_spread -> GetXaxis() -> SetTitle("Relative E/p scale");

  h_EoC_spread -> SetLineColor(kGreen+2);
  h_EoC_spread -> SetLineWidth(2);
  h_EoC_spread -> GetXaxis() -> SetTitle("Relative E/p scale");  
  
  
  TH1F** h_EoP = new TH1F*[nBins];
  TH1F** h_EoC = new TH1F*[nBins];
  TH1F** h_Las = new TH1F*[nBins];

  for(int i = 0; i < nBins; ++i)
  {
    char histoName[80];
    
    sprintf(histoName, "EoP_%d", i);
    h_EoP[i] = new TH1F(histoName, histoName, 1200, 0., 3.);
    h_EoP[i] -> SetFillColor(kRed+2);
    h_EoP[i] -> SetFillStyle(3004);
    h_EoP[i] -> SetMarkerStyle(7);
    h_EoP[i] -> SetMarkerColor(kRed+2); 
    h_EoP[i] -> SetLineColor(kRed+2); 
    
    sprintf(histoName, "EoC_%d", i);
    h_EoC[i] = new TH1F(histoName, histoName, 1200, 0., 3.);
    h_EoC[i] -> SetFillColor(kGreen+2);
    h_EoC[i] -> SetFillStyle(3004);
    h_EoC[i] -> SetMarkerStyle(7);
    h_EoC[i] -> SetMarkerColor(kGreen+2);
    h_EoC[i] -> SetLineColor(kGreen+2);
    
    sprintf(histoName, "Las_%d", i);
    h_Las[i] = new TH1F(histoName, histoName, 100, 0.5, 1.5);
  }
  
  
  // data definition
  std::vector< std::vector<double>* > dataEoP;
  std::vector< std::vector<double>* > dataEoC;
  
  for (int jbin = 0; jbin< nBins; jbin++){
    dataEoP.push_back(new std::vector<double>);
    dataEoC.push_back(new std::vector<double>);
  }


  // function definition
  TF1** f_EoP = new TF1*[nBins];
  TF1** f_EoC = new TF1*[nBins];
  
  
    
  // loop on the saved and sorted events
  std::cout << std::endl;
  std::cout << "***** Fill and fit histograms *****" << std::endl;

  
  for(int ientry = 0; ientry < nEntries; ++ientry)
  {
    if( (ientry%10000 == 0) ) std::cout << "reading entry " << ientry << std::endl;
    
    if( isSavedEntries.at(ientry) == false ) continue;
    
    int iSaved = -1;
    for(iSaved = 0; iSaved < nSavePts; ++iSaved)
      if( ientry == sortedEntries[iSaved].entry ) break;
    
    int bin = -1;
    for(bin = 0; bin < nBins; ++bin)
      if( iSaved >= binEntryMax.at(bin) && iSaved < binEntryMax.at(bin+1) )
        break;
    
    //std::cout << "ientry = " << ientry << "   iSaved: " << iSaved << "   bin: " << bin << std::endl;
    
    ntu_DA->GetEntry(ientry);
    
    float scale = 1.;
    //scale = sqrt( pow(avgLaserCorrection,((1.52-0.7843)/1.52)-1.) );
    //scale = 1. / (0.1811 + 0.7843*avgLaserCorrection);
    
        
    //// fill the bins 
    (h_Las[bin]) -> Fill(avgLaserCorrection);
    (h_EoP[bin]) -> Fill(EoP/avgLaserCorrection);
    (h_EoC[bin]) -> Fill(EoP * scale);
    h_LC_map->Fill(iPhi,iEta,seedLaserCorrection);

    // fill te vectors data E/p 
    dataEoP[bin]->push_back(EoP/avgLaserCorrection);
    dataEoC[bin]->push_back(EoP);

  }
  

  // Define graph and histograms
  TGraphAsymmErrors* g_fit   = new TGraphAsymmErrors();
  TGraphAsymmErrors* g_c_fit   = new TGraphAsymmErrors();
  
  
  
  // define the fitting function
  // N.B. [0] * ( [1] * f( [1]*(x-[2]) ) )
  histoFunc* templateHistoFunc = new histoFunc(templateHisto);
   
  //templateFunc = new TF1("templateFunc", templateHistoFunc, 0., 5., 3, "histoFunc");
  //templateFunc -> SetParName(0,"Norm"); 
  //templateFunc -> SetParName(1,"Scale factor"); 
  //templateFunc -> SetLineWidth(1); 
  //templateFunc -> SetNpx(10000);
  //templateFunc -> SetParameter(0, 1 );
  //templateFunc -> SetParameter(1, 1);
  //templateFunc -> FixParameter(2, 0.);
  //templateFunc -> FixParameter(0, 1./templateFunc ->Integral(0.,5.) ); // normalized to 1. BUT will be renormalized to 1 at each iteration!
  
  TFitterMinuit* myfit = new TFitterMinuit(1);
  myfit->SetFCN(mylike);
  myfit->SetPrintLevel(-1);
  
  
  
  for(int i = 0; i < nBins; ++i)
  {
    h_EoP[i] -> Rebin(rebin*4);    
    h_EoC[i] -> Rebin(rebin*4);    
    
    
    //------------------------------------
    // Fill the graph for uncorrected data
    
    // fit uncorrected data
    mydata = dataEoP.at(i);
    
    myfit->Clear();
    myfit->SetParameter(0, "scale", 1.,0.0005,0.50,1.50);
    
    double arglist[2];
    arglist[0] = 10000; // Max number of function calls
    arglist[1] = 1e-5;  // Tolerance on likelihood ?????????

    int fStatus = myfit->ExecuteCommand("MIGRAD",arglist,2); 
    
    double amin,edm,errdef;
    int nvpar,nparx;
    myfit->GetStats(amin, edm, errdef, nvpar, nparx);
    double bestScale = myfit->GetParameter(0);
    double eee       = myfit->GetParError(0);
    
    char funcName[50];
    sprintf(funcName,"f_EoP_%d",i);
    f_EoP[i] = (TF1*)(templateFunc->Clone());
    f_EoP[i] -> SetParameter(0,h_EoP[i]->GetEntries());
    f_EoP[i] -> SetParameter(7,1.5);
    f_EoP[i] -> SetParName(0,"Norm"); 
    f_EoP[i] -> SetParName(1,"Scale factor"); 
    f_EoP[i] -> SetLineWidth(1); 
    f_EoP[i] -> SetNpx(10000);
    
    double xNorm = h_EoP[i]->GetEntries()/templateHisto->GetEntries() *
                   h_EoP[i]->GetBinWidth(1)/templateHisto->GetBinWidth(1); 
    
    //f_EoP[i] -> FixParameter(0, xNorm);
    //f_EoP[i] -> SetParameter(1, bestScale);
    //f_EoP[i] -> FixParameter(2, 0.);
    f_EoP[i] -> SetLineColor(kRed+2); 
    
    // Fill the graph
    if( fStatus == 0 && eee > 0. )
    {
      g_fit -> SetPoint(i,  h_Las[i]->GetMean() , 1./bestScale);
      g_fit -> SetPointError(i, h_Las[i]->GetRMS(), h_Las[i]->GetRMS(), eee, eee);
      h_EoP_spread -> Fill(1./bestScale);
    }
    else
      std::cout << "Fitting uncorrected time bin: " << i << "   Fail status: " << fStatus << "   sigma: " << eee << endl;
    
    
    
    //----------------------------------
    // Fill the graph for corrected data

    // fit uncorrected data
    
    mydata = dataEoC.at(i);
    
    myfit->Clear();
    myfit->SetParameter(0, "scale", 1.,0.0005,0.50,1.50);
    
    arglist[0] = 10000; // Max number of function calls
    arglist[1] = 1e-5;  // Tolerance on likelihood ?????????

    fStatus = myfit->ExecuteCommand("MIGRAD",arglist,2); 
    
    myfit->GetStats(amin, edm, errdef, nvpar, nparx);
    bestScale = myfit->GetParameter(0);
    eee       = myfit->GetParError(0);    
    
    
    sprintf(funcName,"f_EoC_%d",i);
    f_EoC[i] = (TF1*)(templateFunc->Clone());
    f_EoC[i] -> SetParameter(0,h_EoC[i]->GetEntries());
    f_EoC[i] -> SetParameter(7,bestScale);
    f_EoC[i] -> SetParName(0,"Norm"); 
    f_EoC[i] -> SetParName(1,"Scale factor"); 
    f_EoC[i] -> SetLineWidth(1); 
    f_EoC[i] -> SetNpx(10000);

    xNorm = h_EoC[i]->GetEntries()/templateHisto->GetEntries() *
            h_EoC[i]->GetBinWidth(1)/templateHisto->GetBinWidth(1); 
    //
    //f_EoC[i] -> SetParameter(1, bestScale);
    //f_EoC[i] -> FixParameter(2, 0.);
    f_EoC[i] -> SetLineColor(kGreen+2); 

    // fill the graph
    if( fStatus == 0 && eee > 0. )
    {        
      g_c_fit -> SetPoint(i,  h_Las[i]->GetMean() , 1./bestScale);
      g_c_fit -> SetPointError(i, h_Las[i]->GetRMS() , h_Las[i]->GetRMS() , eee, eee);
      h_EoC_spread -> Fill(1./bestScale);
    }
    else 
      std::cout << "Fitting corrected time bin: " << i << "   Fail status: " << fStatus << "   sigma: " << eee << endl;
    
    
    
  }
  
  TF1* pol0 = new TF1("pol0","pol0");
  pol0 -> SetLineColor(kGreen+2);
  pol0 -> SetLineWidth(3);
  pol0 -> SetLineStyle(2);
  g_c_fit -> Fit("pol0","Q+");
  
  
  // Drawings
  TPaveStats** s_EoP = new TPaveStats*[nBins];
  TPaveStats** s_EoC = new TPaveStats*[nBins];
  
  TCanvas *c1[100]; 
  for(int i = 0; i < nBins; ++i)
  {
    char canvasName[50];
    if (i%2==0) {
      sprintf(canvasName, "Fits-%0d", i/2); 
      c1[i/2] = new TCanvas(canvasName, canvasName);
      c1[i/2] -> Divide(2,1);
    }
    c1[i/2] -> cd (i%2+1);

    h_EoP[i] -> GetXaxis() -> SetTitle("E/p");  
    h_EoP[i] -> GetXaxis() -> SetRangeUser(0.5,1.5); 
    h_EoP[i] -> Draw("e");
    gPad->Update();
    s_EoP[i]= (TPaveStats*)(h_EoP[i]->GetListOfFunctions()->FindObject("stats"));
    s_EoP[i]->SetTextColor(kRed+2);

    h_EoC[i] -> Draw("esames");
    gPad->Update(); 
    s_EoC[i]= (TPaveStats*)(h_EoC[i]->GetListOfFunctions()->FindObject("stats"));
    s_EoC[i]->SetY1NDC(0.59); //new x start position
    s_EoC[i]->SetY2NDC(0.79); //new x end position
    s_EoC[i]->SetTextColor(kGreen+2);
    s_EoC[i]->Draw();
    
    f_EoP[i]->Draw("same");
    f_EoC[i]->Draw("same");    
  }

  /*  
  TCanvas *c2[100]; 
  for(int i = 0; i < nBins; ++i)
  {
    char canvasName[50];
    if (i%6==0) {
      sprintf(canvasName, "LaserCorr-%0d", i/6); 
      c2[i/6] = new TCanvas(canvasName, canvasName);
      c2[i/6] -> Divide(3,2);
    }
        
    c2[i/6] -> cd (i%6+1);
    h_Las[i] -> GetXaxis() -> SetTitle("laser correction");
    h_Las[i] -> GetXaxis() -> SetRangeUser(0.5,1.5); 
    h_Las[i] -> Draw("");
    gPad->Update();
    s_Las[i]= (TPaveStats*)(h_Las[i]->GetListOfFunctions()->FindObject("stats"));
    s_Las[i]->SetTextColor(kBlack);
  }
  */

  /*  
  TCanvas *cmap = new TCanvas("cmap","cmap");
  cmap->cd();
  gStyle->SetPalette(1);
  h_LC_map->Draw("colz");
  */
  
  // Final plots
  TCanvas* cplot = new TCanvas("gplot", "gplot",100,100,725,500);
  cplot->cd();

  TPad *cLeft  = new TPad("pad_0","pad_0",0.00,0.00,0.64,1.00);
  TPad *cRight = new TPad("pad_1","pad_1",0.64,0.00,1.00,1.00);

  cLeft->SetLeftMargin(0.15); 
  cLeft->SetRightMargin(0.025); 
  cRight->SetLeftMargin(0.025); 

  cLeft->Draw();
  cRight->Draw();

  float tYoffset = 1.5; 
  float labSize = 0.04;
  float labSize2 = 0.07;

  cLeft->cd(); 

  cLeft->SetGridx();
  cLeft->SetGridy();
  
  // pad settings
  TH1F *hPad = (TH1F*)gPad->DrawFrame(lcMin,0.9,lcMax,1.05);
  hPad->GetXaxis()->SetTitle("Laser correction");
  hPad->GetYaxis()->SetTitle("Relative E/p scale"); 
  hPad->GetYaxis()->SetTitleOffset(tYoffset);
  hPad->GetXaxis()->SetLabelSize(labSize);
  hPad->GetXaxis()->SetTitleSize(labSize);
  hPad->GetYaxis()->SetLabelSize(labSize);
  hPad->GetYaxis()->SetTitleSize(labSize);
  if ( strcmp(EBEE,"EB")==0 )
  {  
    hPad -> SetMinimum(0.950);
    hPad -> SetMaximum(1.010);
  }
  else 
  {  
    hPad -> SetMinimum(0.910);
    hPad -> SetMaximum(1.030);
  }
    
  // draw trend plot
  g_fit -> SetMarkerStyle(20);
  g_fit -> SetMarkerSize(0.75);
  g_fit -> SetMarkerColor(kRed+2);
  g_fit -> SetLineColor(kRed+2);
  g_fit -> Draw("P");
  g_c_fit -> SetMarkerStyle(20);
  g_c_fit -> SetMarkerColor(kGreen+2);
  g_c_fit -> SetLineColor(kGreen+2);
  g_c_fit -> SetMarkerSize(0.75);
  g_c_fit -> Draw("P,same");
  
  
  cRight -> cd();

  TPaveStats* s_EoP_spread = new TPaveStats();
  TPaveStats* s_EoC_spread = new TPaveStats();
  
  h_EoC_spread -> SetFillStyle(3001);
  h_EoC_spread -> SetFillColor(kGreen+2);
  h_EoC_spread->GetYaxis()->SetLabelSize(labSize2);
  h_EoC_spread->GetYaxis()->SetTitleSize(labSize2);
  h_EoC_spread->GetYaxis()->SetNdivisions(505);
  h_EoC_spread->GetYaxis()->SetLabelOffset(-0.02);
  h_EoC_spread->GetXaxis()->SetLabelOffset(1000);

  h_EoC_spread -> Draw("hbar");
  gPad -> Update();
  s_EoC_spread = (TPaveStats*)(h_EoC_spread->GetListOfFunctions()->FindObject("stats"));
  s_EoC_spread ->SetTextColor(kGreen+2);
  s_EoC_spread ->SetTextSize(0.06);
  s_EoC_spread->SetX1NDC(0.49); //new x start position
  s_EoC_spread->SetX2NDC(0.99); //new x end position
  s_EoC_spread->SetY1NDC(0.875); //new x start position
  s_EoC_spread->SetY2NDC(0.990); //new x end position
  s_EoC_spread -> SetOptStat(1100);
  s_EoC_spread -> Draw("sames");

  h_EoP_spread -> SetFillStyle(3001);
  h_EoP_spread -> SetFillColor(kRed+2);
  h_EoP_spread -> Draw("hbarsames");
  gPad -> Update();
  s_EoP_spread = (TPaveStats*)(h_EoP_spread->GetListOfFunctions()->FindObject("stats"));
  s_EoP_spread->SetX1NDC(0.49); //new x start position
  s_EoP_spread->SetX2NDC(0.99); //new x end position
  s_EoP_spread->SetY1NDC(0.750); //new x start position
  s_EoP_spread->SetY2NDC(0.875); //new x end position
  s_EoP_spread ->SetOptStat(1100);
  s_EoP_spread ->SetTextColor(kRed+2);
  s_EoP_spread ->SetTextSize(0.06);
  s_EoP_spread -> Draw("sames");
}
Пример #5
0
bool
RedQueue::DoEnqueue (Ptr<Packet> p)
{
  NS_LOG_FUNCTION (this << p);

  if (!m_hasRedStarted )
    {
      NS_LOG_INFO ("Initializing RED params.");
      InitializeParams ();
      m_hasRedStarted = true;
    }

  uint32_t nQueued = 0;

  if (GetMode () == QUEUE_MODE_BYTES)
    {
      NS_LOG_DEBUG ("Enqueue in bytes mode");
      nQueued = m_bytesInQueue;
    }
  else if (GetMode () == QUEUE_MODE_PACKETS)
    {
      NS_LOG_DEBUG ("Enqueue in packets mode");
      nQueued = m_packets.size ();
    }

  // simulate number of packets arrival during idle period
  uint32_t m = 0;

  if (m_idle == 1)
    {
      NS_LOG_DEBUG ("RED Queue is idle.");
      Time now = Simulator::Now ();

      if (m_cautious == 3)
        {
          double ptc = m_ptc * m_meanPktSize / m_idlePktSize;
          m = uint32_t (ptc * (now - m_idleTime).GetSeconds ());
        }
      else
        {
          m = uint32_t (m_ptc * (now - m_idleTime).GetSeconds ());
        }

      m_idle = 0;
    }

  m_qAvg = Estimator (nQueued, m + 1, m_qAvg, m_qW);

  NS_LOG_DEBUG ("\t bytesInQueue  " << m_bytesInQueue << "\tQavg " << m_qAvg);
  NS_LOG_DEBUG ("\t packetsInQueue  " << m_packets.size () << "\tQavg " << m_qAvg);

  m_count++;
  m_countBytes += p->GetSize ();

  uint32_t dropType = DTYPE_NONE;
  if (m_qAvg >= m_minTh && nQueued > 1)
    {
      if ((!m_isGentle && m_qAvg >= m_maxTh) ||
          (m_isGentle && m_qAvg >= 2 * m_maxTh))
        {
          NS_LOG_DEBUG ("adding DROP FORCED MARK");
          dropType = DTYPE_FORCED;
        }
      else if (m_old == 0)
        {
          /* 
           * The average queue size has just crossed the
           * threshold from below to above "minthresh", or
           * from above "minthresh" with an empty queue to
           * above "minthresh" with a nonempty queue.
           */
          m_count = 1;
          m_countBytes = p->GetSize ();
          m_old = 1;
        }
      else if (DropEarly (p, nQueued))
        {
          NS_LOG_LOGIC ("DropEarly returns 1");
          dropType = DTYPE_UNFORCED;
        }
    }
  else 
    {
      // No packets are being dropped
      m_vProb = 0.0;
      m_old = 0;
    }

  if (nQueued >= m_queueLimit)
    {
      NS_LOG_DEBUG ("\t Dropping due to Queue Full " << nQueued);
      dropType = DTYPE_FORCED;
      m_stats.qLimDrop++;
    }

  if (dropType == DTYPE_UNFORCED)
    {
      NS_LOG_DEBUG ("\t Dropping due to Prob Mark " << m_qAvg);
      m_stats.unforcedDrop++;
      Drop (p);
      return false;
    }
  else if (dropType == DTYPE_FORCED)
    {
      NS_LOG_DEBUG ("\t Dropping due to Hard Mark " << m_qAvg);
      m_stats.forcedDrop++;
      Drop (p);
      if (m_isNs1Compat)
        {
          m_count = 0;
          m_countBytes = 0;
        }
      return false;
    }

  m_bytesInQueue += p->GetSize ();
  m_packets.push_back (p);

  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);

  return true;
}
Пример #6
0
int _main_(int /*_argc*/, char** /*_argv*/)
{
	uint32_t width  = 1280;
	uint32_t height = 720;
	uint32_t debug  = BGFX_DEBUG_TEXT;
	uint32_t reset  = BGFX_RESET_VSYNC;

	bgfx::init();
	bgfx::reset(width, height, reset);

	// Enable debug text.
	bgfx::setDebug(debug);

	// Set view 0 clear state.
	bgfx::setViewClear(0
		, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
		, 0x303030ff
		, 1.0f
		, 0
		);

	const bgfx::Caps* caps = bgfx::getCaps();
	const bool computeSupported  = !!(caps->supported & BGFX_CAPS_COMPUTE);
	const bool indirectSupported = !!(caps->supported & BGFX_CAPS_DRAW_INDIRECT);

	if (computeSupported)
	{
		// Imgui.
		imguiCreate();

		bgfx::VertexDecl quadVertexDecl;
		quadVertexDecl.begin()
			.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
			.end();

		// Create static vertex buffer.
		bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(
				// Static data can be passed with bgfx::makeRef
				bgfx::makeRef(s_quadVertices, sizeof(s_quadVertices) )
				, quadVertexDecl
				);

		// Create static index buffer.
		bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(
				// Static data can be passed with bgfx::makeRef
				bgfx::makeRef(s_quadIndices, sizeof(s_quadIndices) )
				);

		// Create particle program from shaders.
		bgfx::ProgramHandle particleProgram = loadProgram("vs_particle", "fs_particle");

		// Setup compute buffers
		bgfx::VertexDecl computeVertexDecl;
		computeVertexDecl.begin()
			.add(bgfx::Attrib::TexCoord0, 4, bgfx::AttribType::Float)
			.end();

		const uint32_t threadGroupUpdateSize = 512;
		const uint32_t maxParticleCount = 32 * 1024;

		bgfx::DynamicVertexBufferHandle currPositionBuffer0 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE);
		bgfx::DynamicVertexBufferHandle currPositionBuffer1 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE);
		bgfx::DynamicVertexBufferHandle prevPositionBuffer0 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE);
		bgfx::DynamicVertexBufferHandle prevPositionBuffer1 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE);

		bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4, 3);

		bgfx::ProgramHandle initInstancesProgram   = bgfx::createProgram(loadShader("cs_init_instances"), true);
		bgfx::ProgramHandle updateInstancesProgram = bgfx::createProgram(loadShader("cs_update_instances"), true);

		bgfx::ProgramHandle indirectProgram       = BGFX_INVALID_HANDLE;
		bgfx::IndirectBufferHandle indirectBuffer = BGFX_INVALID_HANDLE;

		if (indirectSupported)
		{
			indirectProgram = bgfx::createProgram(loadShader("cs_indirect"), true);
			indirectBuffer  = bgfx::createIndirectBuffer(2);
		}

		u_paramsDataStruct u_paramsData;
		InitializeParams(0, &u_paramsData);

		bgfx::setUniform(u_params, &u_paramsData, 3);
		bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write);
		bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write);
		bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1);

		float view[16];
		float initialPos[3] = { 0.0f, 0.0f, -45.0f };
		cameraCreate();
		cameraSetPosition(initialPos);
		cameraSetVerticalAngle(0.0f);
		cameraGetViewMtx(view);

		int32_t scrollArea = 0;

		bool useIndirect = false;

		entry::MouseState mouseState;
		while (!entry::processEvents(width, height, debug, reset, &mouseState) )
		{
			int64_t now = bx::getHPCounter();
			static int64_t last = now;
			const int64_t frameTime = now - last;
			last = now;
			const double freq = double(bx::getHPFrequency() );
			const float deltaTime = float(frameTime/freq);

			if (deltaTime > 1000.0)
			{
				abort();
			}

			// Set view 0 default viewport.
			bgfx::setViewRect(0, 0, 0, width, height);

			// Use debug font to print information about this example.
			bgfx::dbgTextClear();
			bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/24-nbody");
			bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: N-body simulation with compute shaders using buffers.");

			imguiBeginFrame(mouseState.m_mx
					, mouseState.m_my
					, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT  : 0)
					| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
					, mouseState.m_mz
					, width
					, height
					);
			imguiBeginScrollArea("Settings", width - width / 4 - 10, 10, width / 4, 500, &scrollArea);
			imguiSlider("Random seed", u_paramsData.baseSeed, 0, 100);
			int32_t shape = imguiChoose(u_paramsData.initialShape, "Point", "Sphere", "Box", "Donut");
			imguiSlider("Initial speed", u_paramsData.initialSpeed, 0.0f, 300.0f, 0.1f);
			bool defaults = imguiButton("Reset");
			imguiSeparatorLine();
			imguiSlider("Particle count (x512)", u_paramsData.dispatchSize, 1, 64);
			imguiSlider("Gravity", u_paramsData.gravity, 0.0f, 0.3f, 0.001f);
			imguiSlider("Damping", u_paramsData.damping, 0.0f, 1.0f, 0.01f);
			imguiSlider("Max acceleration", u_paramsData.maxAccel, 0.0f, 100.0f, 0.01f);
			imguiSlider("Time step", u_paramsData.timeStep, 0.0f, 0.02f, 0.0001f);
			imguiSeparatorLine();
			imguiSlider("Particle intensity", u_paramsData.particleIntensity, 0.0f, 1.0f, 0.001f);
			imguiSlider("Particle size", u_paramsData.particleSize, 0.0f, 1.0f, 0.001f);
			imguiSlider("Particle power", u_paramsData.particlePower, 0.001f, 16.0f, 0.01f);
			imguiSeparatorLine();
			if (imguiCheck("Use draw/dispatch indirect", useIndirect, indirectSupported) )
			{
				useIndirect = !useIndirect;
			}
			imguiEndScrollArea();
			imguiEndFrame();

			// Modify parameters and reset if shape is changed
			if (shape != u_paramsData.initialShape)
			{
				defaults = true;
				InitializeParams(shape, &u_paramsData);
			}

			if (defaults)
			{
				bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write);
				bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write);
				bgfx::setUniform(u_params, &u_paramsData, 3);
				bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1);
			}

			if (useIndirect)
			{
				bgfx::setUniform(u_params, &u_paramsData, 3);
				bgfx::setBuffer(0, indirectBuffer, bgfx::Access::Write);
				bgfx::dispatch(0, indirectProgram);
			}

			bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Read);
			bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Read);
			bgfx::setBuffer(2, prevPositionBuffer1, bgfx::Access::Write);
			bgfx::setBuffer(3, currPositionBuffer1, bgfx::Access::Write);
			bgfx::setUniform(u_params, &u_paramsData, 3);

			if (useIndirect)
			{
				bgfx::dispatch(0, updateInstancesProgram, indirectBuffer, 1);
			}
			else
			{
				bgfx::dispatch(0, updateInstancesProgram, u_paramsData.dispatchSize, 1, 1);
			}

			bx::xchg(currPositionBuffer0, currPositionBuffer1);
			bx::xchg(prevPositionBuffer0, prevPositionBuffer1);

			// Update camera.
			cameraUpdate(deltaTime, mouseState);
			cameraGetViewMtx(view);

			// Set view and projection matrix for view 0.
			const bgfx::HMD* hmd = bgfx::getHMD();
			if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) )
			{
				float viewHead[16];
				float eye[3] = {};
				bx::mtxQuatTranslationHMD(viewHead, hmd->eye[0].rotation, eye);

				float tmp[16];
				bx::mtxMul(tmp, view, viewHead);

				float proj[16];
				bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 10000.0f);

				bgfx::setViewTransform(0, tmp, proj);

				// Set view 0 default viewport.
				//
				// Use HMD's width/height since HMD's internal frame buffer size
				// might be much larger than window size.
				bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height);
			}
			else
			{
				float proj[16];
				bx::mtxProj(proj, 90.0f, float(width)/float(height), 0.1f, 10000.0f);
				bgfx::setViewTransform(0, view, proj);

				// Set view 0 default viewport.
				bgfx::setViewRect(0, 0, 0, width, height);
			}

			// Set vertex and index buffer.
			bgfx::setVertexBuffer(vbh);
			bgfx::setIndexBuffer(ibh);
			bgfx::setInstanceDataBuffer(currPositionBuffer0, 0, u_paramsData.dispatchSize * threadGroupUpdateSize);

			// Set render states.
			bgfx::setState(0
					| BGFX_STATE_RGB_WRITE
					| BGFX_STATE_BLEND_ADD
					| BGFX_STATE_DEPTH_TEST_ALWAYS
					);

			// Submit primitive for rendering to view 0.
			if (useIndirect)
			{
				bgfx::submit(0, particleProgram, indirectBuffer, 0);
			}
			else
			{
				bgfx::submit(0, particleProgram);
			}

			// Advance to next frame. Rendering thread will be kicked to
			// process submitted rendering primitives.
			bgfx::frame();
		}

		// Cleanup.
		cameraDestroy();
		imguiDestroy();

		if (indirectSupported)
		{
			bgfx::destroyProgram(indirectProgram);
			bgfx::destroyIndirectBuffer(indirectBuffer);
		}


		bgfx::destroyUniform(u_params);
		bgfx::destroyDynamicVertexBuffer(currPositionBuffer0);
		bgfx::destroyDynamicVertexBuffer(currPositionBuffer1);
		bgfx::destroyDynamicVertexBuffer(prevPositionBuffer0);
		bgfx::destroyDynamicVertexBuffer(prevPositionBuffer1);
		bgfx::destroyProgram(updateInstancesProgram);
		bgfx::destroyProgram(initInstancesProgram);
		bgfx::destroyIndexBuffer(ibh);
		bgfx::destroyVertexBuffer(vbh);
		bgfx::destroyProgram(particleProgram);
	}
	else
	{
		int64_t timeOffset = bx::getHPCounter();

		entry::MouseState mouseState;
		while (!entry::processEvents(width, height, debug, reset, &mouseState) )
		{
			int64_t now = bx::getHPCounter();
			float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) );

			bgfx::setViewRect(0, 0, 0, width, height);

			bgfx::dbgTextClear();
			bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/24-nbody");
			bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: N-body simulation with compute shaders using buffers.");

			bool blink = uint32_t(time*3.0f)&1;
			bgfx::dbgTextPrintf(0, 5, blink ? 0x1f : 0x01, " Compute is not supported by GPU. ");

			bgfx::touch(0);
			bgfx::frame();
		}
	}

	// Shutdown bgfx.
	bgfx::shutdown();

	return 0;
}