예제 #1
0
int problem3_main(){
    std::ofstream fout1("problem3.30.txt");
    solve(30.0 / 180.0 * acos(-1), fout1);
    fout1.close();
    
    std::ofstream fout2("problem3.40.txt");
    solve(40.0 / 180.0 * acos(-1), fout2);
    fout2.close();
    
    std::ofstream fout3("problem3.50.txt");
    solve(50.0 / 180.0 * acos(-1), fout3);
    fout3.close();
    
    B2_M = 0.0;
    
    std::ofstream fout4("problem3-no-air.30.txt");
    solve(30.0 / 180.0 * acos(-1), fout4);
    fout4.close();
    
    std::ofstream fout5("problem3-no-air.40.txt");
    solve(40.0 / 180.0 * acos(-1), fout5);
    fout5.close();
    
    std::ofstream fout6("problem3-no-air.50.txt");
    solve(50.0 / 180.0 * acos(-1), fout6);
    fout6.close();
    return 0;
}
예제 #2
0
int main ()
{
  string inVec1, inVec2;
  
  ShiftRegister UUT1;
  ShiftRegHuff  UUT2;

  ifstream finp1 ("indata1.tst");
  ofstream fout1 ("outdata1.tst");

  ifstream finp2 ("indata2.tst");
  ofstream fout2 ("outdata2.tst");

  char stop_in1 ('0');
  char stop_in2 ('0');

  finp1 >> inVec1;              // Read in first line of testbench data

  while (stop_in1 != '.')
  {
    UUT1.load_input(inVec1);    // Load inputs into ShiftRegister
    UUT1.update_reg();         // Compute operation based on mode
    UUT1.set_output();         // Set DFFs based on computed values

    fout1 << UUT1.output_reg(); // Output data to external file

    // Gather next data input:

    finp1 >> inVec1;
    stop_in1 = inVec1[0];
  }

  fout1 << "END FILESTREAM";

  /// Now for the Huffman Model (with the worst case delays):

  finp2 >> inVec2;              // Read in first line of testbench data

  CombLogic CL;                 // Define combinational logic class

  while (stop_in2 != '.')
  {
    UUT2.load_input(inVec2);    // Load inputs into ShiftRegister
    CL.update_reg(UUT2);        // Apply combinational logic
    UUT2.set_output();          // Set DFFs based on computed values

    fout2 << UUT2.output_reg(); // Output data to external file

    // Gather next data input:

    finp2 >> inVec2;
    stop_in2 = inVec2[0];
  }

  return 0;
}
예제 #3
0
파일: lsh_dfe.cpp 프로젝트: Terranlee/LSH
    void LSH_DFE::compare_hash_result(){
        assert(m_new_grid_dfe.size() == m_new_grid_cpu.size());
        int counter = 0;
        for(unsigned int i=0; i<m_new_grid_dfe.size(); i++){
            if((m_new_grid_dfe[i].first == m_new_grid_cpu[i].first) && (m_new_grid_dfe[i].second == m_new_grid_cpu[i].second))
                counter++;
        }
        cout<<counter<<" same over "<<m_new_grid_cpu.size()<<endl;
        if(counter != m_new_grid_cpu.size()){
            cout<<"result is not the same, write result to answer_cpu/dfe"<<endl;
			std::ofstream fout0("answer_cpu");
            for(unsigned int i=0; i<m_new_grid_cpu.size(); i++)
                fout0<<m_new_grid_cpu[i].first<<" "<<m_new_grid_cpu[i].second<<endl;
            fout0.close();
			std::ofstream fout1("answer_dfe");
            for(unsigned int i=0; i<m_new_grid_dfe.size(); i++)
                fout1<<m_new_grid_dfe[i].first<<" "<<m_new_grid_dfe[i].second<<endl;
            fout1.close();
        }
    }
예제 #4
0
// protected
void
FileOutputStreamTestCase::ctors (void)
{

    File f1 (TEST_FILE_NAME);
    if (f1.exists () == false)
        f1.create ();

    // open mode
    FileOutputStream fout (TEST_FILE_NAME, OPEN_MODE);
    fout.close ();


    // open or create mode
    File file (TEST_FILE_NAME);
    FileOutputStream fout1 (file, OPEN_OR_CREATE_MODE);
    fout1.close ();


    // read_share
    FileOutputStream fout2(TEST_FILE_NAME, CREATE_MODE, READ_SHARE);
    fout2.close ();
}
//vector<double> DefaultVector; // just used to free memory from vectors.
int tracking(string thestring, double iterNbX, double iterNbY){
  double PI=TMath::Pi();
  //string thestring = "Position_REF2X_42_48";
  string txtfilename = thestring + ".txt";
  string residualHead = "rPhi_residual_";
  string residualMeanHead = "rPhi_residualMean_";
  string residualSigmaHead="rPhi_residualSigma_";
  string chi2Head = "rPhi_trackChi2_";
  string iterHead = "Iteration_";

  //fstream fout2("myresidual.txt",ios::out); 
  double pREF2X=0.0, pREF2Y=0.0;
  double pREF3X=0.0, pREF3Y=0.0;
  double pUVA3X=0.0, pUVA3Y=0.0;
  double pREF1X=0.0, pREF1Y=0.0;
  //double pZZ1=0.0, pZZ2=0.0;
  double pEta5=0.0;
  const int NNNNN = 6447;
  double vpREF2X[NNNNN]; double vpREF2Y[NNNNN];
  double vpREF3X[NNNNN]; double vpREF3Y[NNNNN];
  double vpUVA3X[NNNNN]; double vpUVA3Y[NNNNN];
  double vpREF1X[NNNNN]; double vpREF1Y[NNNNN];
  //vector<double> vpZZ1; vector<double> vpZZ2;
  double vpEta5[NNNNN];
  double shiREF2X=12.26791212, shiREF2Y=2.02708225;
  double shiREF3X=7.4824985, shiREF3Y=-2.35562;
  double shiUVA3X=-0.7097, shiUVA3Y=15.75778;
  double shiREF1X=-9.92822, shiREF1Y=-0.68756;
  double shiEta5=0.0;//0.01509;
  double preshiREF2X=-2265, preshiREF2Y=-32;  //2127.4275
  double preshiREF3X=-2265, preshiREF3Y=-32;
  double preshiUVA3X=-2265, preshiUVA3Y=-32;
  double preshiREF1X=-2265, preshiREF1Y=-32;  
  double aREF3REF2=0.0056995;//start angle: 0.01197;
  double aUVA3REF2=-0.013489;//0.02807;//start angle: 0.01102
  double aREF1REF2=-0.044254312;//-0.0171;//start angle: 0.008273;
  double aEta5REF2=0.0;//0.008098; 
  double tempREF2X, tempREF2Y, tempREF3X, tempREF3Y, tempUVA3X, tempUVA3Y, tempREF1X, tempREF1Y, tempEta5;
  double meanREF2X=0.0, meanREF2Y=0.0, meanREF3X=0.0, meanREF3Y=0.0, meanUVA3X=0.0, meanUVA3Y=0.0, meanREF1X=0.0, meanREF1Y=0.0, meanEta5=0.0;
  double sigmaREF2X=0.0,sigmaREF2Y=0.0,sigmaREF3X=0.0,sigmaREF3Y=0.0,sigmaUVA3X=0.0,sigmaUVA3Y=0.0,sigmaREF1X=0.0,sigmaREF1Y=0.0,sigmaEta5=0.0;
  double meanXChi2=0.0,meanYChi2=0.0, totalChi2=0.0; // chi square of tracks.
  double maximum=0.0, rms=0.0, lRange=0.0, hRange=0.0;  

  TH1D* hpREF2X=0;
  TH1D* hpREF2Y = 0;
  TH1D* hpREF3X = 0;
  TH1D* hpREF3Y = 0; 
  TH1D* hpUVA3X = 0;
  TH1D* hpUVA3Y = 0;  
  TH1D* hpREF1X = 0;
  TH1D* hpREF1Y = 0;  
  TH1D* hpEta5 =0;
  
  TH1D* residualREF2X = 0;
  TH1D* residualREF2Y = 0;
  TH1D* residualREF3X = 0;
  TH1D* residualREF3Y = 0;
  TH1D* residualUVA3X = 0;
  TH1D* residualUVA3Y = 0;
  TH1D* residualREF1X = 0;
  TH1D* residualREF1Y = 0;
  TH1D* residualEta5 = 0;
  
  TH1D* angleREF3=0;
  TH1D* angleUVA3=0;
  TH1D* angleREF1=0;
  TH1D* angleEta5=0;
  TH1D* xTrackChi2=0;
  TH1D* yTrackChi2=0;
  
  preshiREF2X = -1810-iterNbX;// - iterNbX*2;
  preshiREF3X=preshiREF2X; preshiUVA3X=preshiREF2X; preshiREF1X=preshiREF2X;
  preshiREF2Y = -40.0 + iterNbY*0.2;
  preshiREF3Y = preshiREF2Y; preshiUVA3Y = preshiREF2Y; preshiREF1Y = preshiREF2Y;
  
  char cp2x[20]; sprintf(cp2x,"%.2f",preshiREF2X);
  char cp2y[20]; sprintf(cp2y,"%.2f",preshiREF2Y);

  string fout1name = iterHead + thestring + "_inclusive_X_" + cp2x + ".txt"; //TString::Itoa(preshiREF2X,10).Data()
  //string fout3name = residualSigmaHead+ thestring + "_inclusive_X_" + cp2x + ".txt"; //TString::Itoa(preshiREF2X,10).Data()
  //string fout2name = chi2Head + thestring + "_inclusive_X_" + cp2x  + ".txt"; //TString::Itoa(preshiREF2X,10).Data()
  fstream fout1(fout1name.c_str(),ios::out|ios::app);
  //fstream fout3(fout3name.c_str(),ios::out|ios::app);
  //fstream fout2(fout2name.c_str(),ios::out|ios::app);
   	
      fstream fin(txtfilename.c_str(),ios::in);
      //if(!fin){cout<<"file not read"<<endl; return;}
      //else cout<<"processing "<<txtfilename<<endl;
        
      cout<<iterNbX<<"\t"<<iterNbY<<"\tX "<<preshiREF2X<<"\tY "<<preshiREF2Y<<endl;
      
      int nbLines=0;
      while(fin>>pREF2X>>pREF2Y>>pREF3X>>pREF3Y>>pUVA3X>>pUVA3Y>>pREF1X>>pREF1Y>>pEta5){
        vpREF2X[nbLines]=pREF2X; vpREF2Y[nbLines]=pREF2Y; vpREF3X[nbLines]=pREF3X; vpREF3Y[nbLines]=pREF3Y;
        vpUVA3X[nbLines]=pUVA3X; vpUVA3Y[nbLines]=pUVA3Y; vpREF1X[nbLines]=pREF1X; vpREF1Y[nbLines]=pREF1Y;
        vpEta5[nbLines]=pEta5;
        //shift
        vpREF2X[nbLines] -= shiREF2X; vpREF2Y[nbLines] -= shiREF2Y;
        vpREF3X[nbLines] -= shiREF3X; vpREF3Y[nbLines] -= shiREF3Y;
        vpUVA3X[nbLines] -= shiUVA3X; vpUVA3Y[nbLines] -= shiUVA3Y;
        vpREF1X[nbLines] -= shiREF1X; vpREF1Y[nbLines] -= shiREF1Y; 
//        vpEta5[nbLines] ;
        //rotate
        tempREF2X=vpREF2X[nbLines]; tempREF2Y=vpREF2Y[nbLines]; tempREF3X=vpREF3X[nbLines]; tempREF3Y=vpREF3Y[nbLines]; 
        tempUVA3X=vpUVA3X[nbLines]; tempUVA3Y=vpUVA3Y[nbLines]; tempREF1X=vpREF1X[nbLines]; tempREF1Y=vpREF1Y[nbLines]; 
        vpREF3X[nbLines]=tempREF3X*cos(aREF3REF2)-tempREF3Y*sin(aREF3REF2);
        vpREF3Y[nbLines]=tempREF3X*sin(aREF3REF2)+tempREF3Y*cos(aREF3REF2);
        vpUVA3X[nbLines]=tempUVA3X*cos(aUVA3REF2)-tempUVA3Y*sin(aUVA3REF2);
        vpUVA3Y[nbLines]=tempUVA3X*sin(aUVA3REF2)+tempUVA3Y*cos(aUVA3REF2);
        vpREF1X[nbLines]=tempREF1X*cos(aREF1REF2)-tempREF1Y*sin(aREF1REF2);
        vpREF1Y[nbLines]=tempREF1X*sin(aREF1REF2)+tempREF1Y*cos(aREF1REF2);
    
        vpEta5[nbLines] -= aEta5REF2;

        //change origin, move in X and Y
        vpREF2X[nbLines] -= preshiREF2X; vpREF2Y[nbLines] -= preshiREF2Y;
        vpREF3X[nbLines] -= preshiREF3X; vpREF3Y[nbLines] -= preshiREF3Y;
        vpUVA3X[nbLines] -= preshiUVA3X; vpUVA3Y[nbLines] -= preshiUVA3Y;
        vpREF1X[nbLines] -= preshiREF1X; vpREF1Y[nbLines] -= preshiREF1Y; 

        //transfer to (r,phi) position
        double rREF2 = sqrt(vpREF2X[nbLines]*vpREF2X[nbLines]+vpREF2Y[nbLines]*vpREF2Y[nbLines]);
        double phiREF2 = 0.0; if(vpREF2X[nbLines]!=0.0) phiREF2 = atan(vpREF2Y[nbLines]/vpREF2X[nbLines]);
        double rREF3 = sqrt(vpREF3X[nbLines]*vpREF3X[nbLines]+vpREF3Y[nbLines]*vpREF3Y[nbLines]);
        double phiREF3 = 0.0; if(vpREF3X[nbLines]!=0.0) phiREF3 = atan(vpREF3Y[nbLines]/vpREF3X[nbLines]);
        double rUVA3 = sqrt(vpUVA3X[nbLines]*vpUVA3X[nbLines]+vpUVA3Y[nbLines]*vpUVA3Y[nbLines]);
        double phiUVA3 = 0.0; if(vpUVA3X[nbLines]!=0.0) phiUVA3 = atan(vpUVA3Y[nbLines]/vpUVA3X[nbLines]);
        double rREF1 = sqrt(vpREF1X[nbLines]*vpREF1X[nbLines]+vpREF1Y[nbLines]*vpREF1Y[nbLines]);
        double phiREF1 = 0.0; if(vpREF1X[nbLines]!=0.0) phiREF1 = atan(vpREF1Y[nbLines]/vpREF1X[nbLines]);
 
        //asignment new r, phi position values to the vector. Note that from now on the vectors vp.. cantains r and phi values
        vpREF2X[nbLines]=rREF2; vpREF2Y[nbLines]=phiREF2;
        vpREF3X[nbLines]=rREF3; vpREF3Y[nbLines]=phiREF3;
        vpUVA3X[nbLines]=rUVA3; vpUVA3Y[nbLines]=phiUVA3;
        vpREF1X[nbLines]=rREF1; vpREF1Y[nbLines]=phiREF1;    
    
        nbLines++;
        //if(nbLines%10000==0) cout<<nbLines<<endl;
      }
      fin.close();
      //end of reading file

      char rootfile[50]; sprintf(rootfile,"_X_%.2f_Y_%.2f_inclusive_doubleGaussian.root",preshiREF2X,preshiREF2Y);
      string newhead = "./RootFiles/";
      string outputrootname=newhead+residualHead+thestring+rootfile;
      TFile* f = new TFile(outputrootname.c_str(),"recreate");
/*
      char name2X[50];sprintf(name2X,"rREF2_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y); char name2Y[50];sprintf(name2Y,"phiREF2_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char name3X[50];sprintf(name3X,"rREF3_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y); char name3Y[50];sprintf(name3Y,"phiREF3_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameu3X[50];sprintf(nameu3X,"rUVA3_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);char nameu3Y[50];sprintf(nameu3Y,"phiUVA3_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char name1X[50];sprintf(name1X,"rREF1_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y); char name1Y[50];sprintf(name1Y,"phiREF1_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameEta5[50];sprintf(nameEta5,"phiEta5_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y); 
      hpREF2X = new TH1D(name2X,"",1500,1950,2100); hpREF2X->SetXTitle("r [mm]"); hpREF2X->SetYTitle("Frequency");hpREF2X->SetLabelSize(0.05,"XY");hpREF2X->SetTitleSize(0.05,"XY");
       hpREF2Y = new TH1D(name2Y,"",200,-0.1,0.1); hpREF2Y->SetXTitle("#phi [rad]"); hpREF2Y->SetYTitle("Frequency");hpREF2Y->SetLabelSize(0.05,"XY");hpREF2Y->SetTitleSize(0.05,"XY");  
       hpREF3X = new TH1D(name3X,"",1500,1950,2100); hpREF3X->SetXTitle("r [mm]"); hpREF3X->SetYTitle("Frequency");hpREF3X->SetLabelSize(0.05,"XY");hpREF3X->SetTitleSize(0.05,"XY");
       hpREF3Y = new TH1D(name3Y,"",200,-0.1,0.1); hpREF3Y->SetXTitle("#phi [rad]"); hpREF3Y->SetYTitle("Frequency");hpREF3Y->SetLabelSize(0.05,"XY");hpREF3Y->SetTitleSize(0.05,"XY");  
       hpUVA3X = new TH1D(nameu3X,"",1500,1950,2100); hpUVA3X->SetXTitle("r [mm]"); hpUVA3X->SetYTitle("Frequency");hpUVA3X->SetLabelSize(0.05,"XY");hpUVA3X->SetTitleSize(0.05,"XY");
       hpUVA3Y = new TH1D(nameu3Y,"",200,-0.1,0.1); hpUVA3Y->SetXTitle("#phi [rad]"); hpUVA3Y->SetYTitle("Frequency");hpUVA3Y->SetLabelSize(0.05,"XY");hpUVA3Y->SetTitleSize(0.05,"XY");  
       hpREF1X = new TH1D(name1X,"",1500,1950,2100); hpREF1X->SetXTitle("r [mm]"); hpREF1X->SetYTitle("Frequency");hpREF1X->SetLabelSize(0.05,"XY");hpREF1X->SetTitleSize(0.05,"XY");
       hpREF1Y = new TH1D(name1Y,"",200,-0.1,0.1); hpREF1Y->SetXTitle("#phi [rad]"); hpREF1Y->SetYTitle("Frequency");hpREF1Y->SetLabelSize(0.05,"XY");hpREF1Y->SetTitleSize(0.05,"XY");  
       hpEta5 = new TH1D(nameEta5,"",200,-0.1,0.1); hpEta5->SetXTitle("#phi [rad]"); hpEta5->SetYTitle("Frequency"); hpEta5->SetLabelSize(0.05,"XY");hpEta5->SetTitleSize(0.05,"XY");
*/
      char nameRes2X[50];sprintf(nameRes2X,"residualREF2_r_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);char nameRes2Y[50];sprintf(nameRes2Y,"residualREF2_phi_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameRes3X[50];sprintf(nameRes3X,"residualREF3_r_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);char nameRes3Y[50];sprintf(nameRes3Y,"residualREF3_phi_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameResu3X[50];sprintf(nameResu3X,"residualUVA3_r_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);char nameResu3Y[50];sprintf(nameResu3Y,"residualUVA3_phi_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameRes1X[50];sprintf(nameRes1X,"residualREF1_r_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);char nameRes1Y[50];sprintf(nameRes1Y,"residualREF1_phi_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
    //char nameResZZ1[50];sprintf(nameResZZ1,"residualZZ1_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);char nameResZZ2[50];sprintf(nameResZZ2,"residualZZ2_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameResEta5[50];sprintf(nameResEta5,"residualEta5_phi_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      residualREF2X = new TH1D(nameRes2X,"",1000,-2,2); residualREF2X->SetXTitle("Residual in r [mm]"); residualREF2X->SetYTitle("Frequency");residualREF2X->SetLabelSize(0.05,"XY");residualREF2X->SetTitleSize(0.05,"XY");
      residualREF2Y = new TH1D(nameRes2Y,"",1000,-0.005,0.005); residualREF2Y->SetXTitle("Residual in #phi [rad]"); residualREF2Y->SetYTitle("Frequency");residualREF2Y->SetLabelSize(0.05,"XY");residualREF2Y->SetTitleSize(0.05,"XY");
      residualREF3X = new TH1D(nameRes3X,"",1000,-2,2); residualREF3X->SetXTitle("Residual in r [mm]"); residualREF3X->SetYTitle("Frequency");residualREF3X->SetLabelSize(0.05,"XY");residualREF3X->SetTitleSize(0.05,"XY");
      residualREF3Y = new TH1D(nameRes3Y,"",1000,-0.005,0.005); residualREF3Y->SetXTitle("Residual in #phi [rad]"); residualREF3Y->SetYTitle("Frequency");residualREF3Y->SetLabelSize(0.05,"XY");residualREF3Y->SetTitleSize(0.05,"XY");
      residualUVA3X = new TH1D(nameResu3X,"",1000,-2,2); residualUVA3X->SetXTitle("Residual in r [mm]"); residualUVA3X->SetYTitle("Frequency");residualUVA3X->SetLabelSize(0.05,"XY");residualUVA3X->SetTitleSize(0.05,"XY");
      residualUVA3Y = new TH1D(nameResu3Y,"",1000,-0.005,0.005); residualUVA3Y->SetXTitle("Residual in #phi [rad]"); residualUVA3Y->SetYTitle("Frequency");residualUVA3Y->SetLabelSize(0.05,"XY");residualUVA3Y->SetTitleSize(0.05,"XY");
      residualREF1X = new TH1D(nameRes1X,"",1000,-2,2); residualREF1X->SetXTitle("Residual in r [mm]"); residualREF1X->SetYTitle("Frequency");residualREF1X->SetLabelSize(0.05,"XY");residualREF1X->SetTitleSize(0.05,"XY");
      residualREF1Y = new TH1D(nameRes1Y,"",1000,-0.005,0.005); residualREF1Y->SetXTitle("Residual in #phi [rad]"); residualREF1Y->SetYTitle("Frequency");residualREF1Y->SetLabelSize(0.05,"XY");residualREF1Y->SetTitleSize(0.05,"XY");
      residualEta5 = new TH1D(nameResEta5,"",1000,-0.02,0.02); residualEta5->SetXTitle("Residual in #phi [rad]"); residualEta5->SetYTitle("Frequency");residualEta5->SetLabelSize(0.05,"XY");residualEta5->SetTitleSize(0.05,"XY");
/*    
      char nameAngleREF3[50]; sprintf(nameAngleREF3,"angleREF3_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameAngleUVA3[50]; sprintf(nameAngleUVA3,"angleUVA3_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameAngleREF1[50]; sprintf(nameAngleREF1,"angleREF1_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameAngleEta5[50]; sprintf(nameAngleEta5,"angleEta5_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
       angleREF3 = new TH1D(nameAngleREF3,"Rotation angle distribution of REF3 and REF2",1000,-0.005,0.005); angleREF3->SetXTitle("Angle [rad]"); angleREF3->SetYTitle("Frequency");
       angleUVA3 = new TH1D(nameAngleUVA3,"Rotation angle distribution of UVA3 and REF2",1000,-0.005,0.005); angleUVA3->SetXTitle("Angle [rad]"); angleUVA3->SetYTitle("Frequency");
       angleREF1 = new TH1D(nameAngleREF1,"Rotation angle distribution of REF1 and REF2",1000,-0.005,0.005); angleREF1->SetXTitle("Angle [rad]"); angleREF1->SetYTitle("Frequency");
       angleEta5 = new TH1D(nameAngleEta5,"Rotation Eta5 and REF2",500,-0.2,0.2);
*/    
      char nameChi2X[50]; sprintf(nameChi2X,"XTrackChi2_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
      char nameChi2Y[50]; sprintf(nameChi2Y,"YTrackChi2_X_%.1f_Y_%.1f",preshiREF2X, preshiREF2Y);
       xTrackChi2 = new TH1D(nameChi2X,"Chi square of tracks in X projection",1000,0,0.2); xTrackChi2->SetXTitle("#chi^{2} of track in r"); xTrackChi2->SetYTitle("Frequency");
       xTrackChi2->SetTitleSize(0.04,"XY"); xTrackChi2->SetLabelSize(0.04,"XY");
       yTrackChi2 = new TH1D(nameChi2Y,"Chi square of tracks in Y projection",1000,0,0.00002); yTrackChi2->SetXTitle("#chi^{2} of track in #phi"); yTrackChi2->SetYTitle("Frequency");
       yTrackChi2->SetTitleSize(0.04,"XY"); yTrackChi2->SetLabelSize(0.04,"XY");
    
      //fill histograms first
/*
      for(Int_t i=0;i<NNNNN;i++){
      	hpREF2X->Fill(vpREF2X[i]); hpREF2Y->Fill(vpREF2Y[i]);
      	hpREF3X->Fill(vpREF3X[i]); hpREF3Y->Fill(vpREF3Y[i]);
      	hpUVA3X->Fill(vpUVA3X[i]); hpUVA3Y->Fill(vpUVA3Y[i]);
      	hpREF1X->Fill(vpREF1X[i]); hpREF1Y->Fill(vpREF1Y[i]);
      	hpEta5->Fill(vpEta5[i]);
    	
        angleREF3->Fill(vpREF3Y[i]-vpREF2Y[i]);
        angleUVA3->Fill(vpUVA3Y[i]-vpREF2Y[i]);
        angleREF1->Fill(vpREF1Y[i]-vpREF2Y[i]);
        angleEta5->Fill(vpEta5[i]-vpREF2Y[i]);
      }
*/      
/*
      I2GFvalues myValues;
      myValues = I2GFmainLoop(angleREF3,1,10,1);  double meanAngleREF3 = myValues.mean;
      myValues = I2GFmainLoop(angleUVA3,1,10,1);  double meanAngleUVA3 = myValues.mean;
      myValues = I2GFmainLoop(angleREF1,1,10,1);  double meanAngleREF1 = myValues.mean;
      myValues = I2GFmainLoop(angleEta5,1,10,1);  double meanAngleEta5 = myValues.mean;
*//* 
      double maximum = angleREF3->GetXaxis()->GetBinCenter(angleREF3->GetMaximumBin());   
      double rms = angleREF3->GetRMS(1); 
      double lRange = maximum - rms*2; 
      double hRange = maximum + rms*2;
      TF1* funAngleREF3 = new TF1("funAngleREF3","gaus",lRange,hRange); angleREF3->Fit("funAngleREF3","RQ");
      double meanAngleREF3=funAngleREF3->GetParameter(1);
      maximum = angleUVA3->GetXaxis()->GetBinCenter(angleUVA3->GetMaximumBin());
      rms = angleUVA3->GetRMS(1);
      lRange = maximum - rms*2; hRange = maximum + rms*2;
      TF1* funAngleUVA3 = new TF1("funAngleUVA3","gaus",lRange,hRange); angleUVA3->Fit("funAngleUVA3","RQ");
      double meanAngleUVA3=funAngleUVA3->GetParameter(1);
      maximum = angleREF1->GetXaxis()->GetBinCenter(angleREF1->GetMaximumBin());
      rms = angleREF1->GetRMS(1);
      lRange = maximum - rms*2; hRange = maximum + rms*2;
      TF1* funAngleREF1 = new TF1("funAngleREF1","gaus",lRange,hRange); angleREF1->Fit("funAngleREF1","RQ");
      double meanAngleREF1=funAngleREF1->GetParameter(1);
      maximum = angleEta5->GetXaxis()->GetBinCenter(angleEta5->GetMaximumBin());
      rms = angleEta5->GetRMS(1);
      lRange = maximum - rms*2; hRange = maximum + rms*2;
      TF1* funAngleEta5 = new TF1("funAngleEta5","gaus",lRange,hRange); angleEta5->Fit("funAngleEta5","RQ");
      double meanAngleEta5=funAngleEta5->GetParameter(1);
      delete funAngleREF3; delete funAngleUVA3; delete funAngleREF1; delete funAngleEta5;
*/
      //track fitting
      for(Int_t i=0;i<NNNNN;i++){
        
        double rREF2=vpREF2X[i], phiREF2=vpREF2Y[i];
        double rREF3=vpREF3X[i], phiREF3=vpREF3Y[i];//-meanAngleREF3;
        double rUVA3=vpUVA3X[i], phiUVA3=vpUVA3Y[i];//-meanAngleUVA3;
        double rREF1=vpREF1X[i], phiREF1=vpREF1Y[i];//-meanAngleREF1;
        double phiEta5=vpEta5[i];//-meanAngleEta5;

        //fill track in r direction
        TGraph* g1 = new TGraph();
        g1->SetPoint(0,0,     rREF2);
        g1->SetPoint(1,1143.5,rREF3);
        g1->SetPoint(2,2686.5,rUVA3);
        g1->SetPoint(3,3169.5,rREF1);
        g1->GetXaxis()->SetRangeUser(-1000,3300);
        TF1* f1 = new TF1("line1","pol1",0,3200);
        g1->Fit("line1","Q");
        double intercept1 = f1->GetParameter(0);
        double slope1     = f1->GetParameter(1);
        double MeasuredREF2X = intercept1 + slope1*0.0;
        double MeasuredREF3X = intercept1 + slope1*1143.5;
        double MeasuredUVA3X = intercept1 + slope1*2686.5;
        double MeasuredREF1X = intercept1 + slope1*3169.5;
        residualREF2X->Fill(MeasuredREF2X-rREF2);
        residualREF3X->Fill(MeasuredREF3X-rREF3);
        residualUVA3X->Fill(MeasuredUVA3X-rUVA3);
        residualREF1X->Fill(MeasuredREF1X-rREF1);
        xTrackChi2->Fill(f1->GetChisquare());
        totalChi2 += f1->GetChisquare();
        delete f1; delete g1;
      
        //fill track in phi direction
        TGraph* g2 = new TGraph();
        g2->SetPoint(0,0,     phiREF2);
        g2->SetPoint(1,1143.5,phiREF3);
        g2->SetPoint(2,2011.5,phiEta5);
        g2->SetPoint(3,2686.5,phiUVA3);
        g2->SetPoint(4,3169.5,phiREF1);
        g2->GetXaxis()->SetRangeUser(-1000,3300);
        // inclusive
        //g2->SetPoint(2,2305.5,vpZZ2[i]); //inclusive 1
        //g2->SetPoint(2,2327.5,vpZZ1[i]);  //inclusive 2
        TF1* f2 = new TF1("line2","pol1",0,3200);
        g2->Fit("line2","Q");
        double intercept2 = f2->GetParameter(0);
        double slope2     = f2->GetParameter(1);
        double MeasuredREF2Y = intercept2 + slope2*0.0;
        double MeasuredREF3Y = intercept2 + slope2*1143.5;
        double MeasuredUVA3Y = intercept2 + slope2*2686.5;
        double MeasuredREF1Y = intercept2 + slope2*3169.5;
        //double MeasuredZZ1  = intercept2 + slope2*2327.5;
        //double MeasuredZZ2  = intercept2 + slope2*2305.5;
        double MeasuredEta5 = intercept2 + slope2*2011.5;
        residualREF2Y->Fill((MeasuredREF2Y-phiREF2));
        residualREF3Y->Fill((MeasuredREF3Y-phiREF3));
        residualUVA3Y->Fill((MeasuredUVA3Y-phiUVA3));
        residualREF1Y->Fill((MeasuredREF1Y-phiREF1));
        residualEta5->Fill((MeasuredEta5-phiEta5));
        //residualZZ1->Fill(MeasuredZZ1-vpZZ1[i]);
        //residualZZ2->Fill(MeasuredZZ2-vpZZ2[i]);
        yTrackChi2->Fill(f2->GetChisquare());
        totalChi2 += f2->GetChisquare();
        delete f2; delete g2;
  
        //nnnn++;
      } //end for loop of filling histograms and fitting tracks
      //cout<<"after for loop"<<endl;
      //going to fit residual histograms
      gStyle->SetOptFit(1111);
    
/*
      myValues = I2GFmainLoop(residualREF2X,1,10,1);  meanREF2X = myValues.mean; sigmaREF2X=myValues.sigma;
      myValues = I2GFmainLoop(residualREF2Y,1,10,1);  meanREF2Y = myValues.mean; sigmaREF2Y=myValues.sigma;
      myValues = I2GFmainLoop(residualREF3X,1,10,1);  meanREF3X = myValues.mean; sigmaREF3X=myValues.sigma;
      myValues = I2GFmainLoop(residualREF3Y,1,10,1);  meanREF3Y = myValues.mean; sigmaREF3Y=myValues.sigma;
      myValues = I2GFmainLoop(residualUVA3X,1,10,1);  meanUVA3X = myValues.mean; sigmaUVA3X=myValues.sigma;
      myValues = I2GFmainLoop(residualUVA3Y,1,10,1);  meanUVA3Y = myValues.mean; sigmaUVA3Y=myValues.sigma;
      myValues = I2GFmainLoop(residualREF1X,1,10,1);  meanREF1X = myValues.mean; sigmaREF1X=myValues.sigma;
      myValues = I2GFmainLoop(residualREF1Y,1,10,1);  meanREF1Y = myValues.mean; sigmaREF1Y=myValues.sigma;
*/      
      I2GFvalues myValues;
      myValues = I2GFmainLoop(residualEta5,1,10,1);
      meanEta5 = myValues.mean; sigmaEta5=myValues.sigma;
/*
      maximum = residualEta5->GetXaxis()->GetBinCenter(residualEta5->GetMaximumBin());
      rms = residualEta5->GetRMS(1);
      lRange = maximum - rms*1.5; hRange = maximum + rms*1.5;
      TF1* funResidualEta5 = new TF1("funResidualEta5","gaus",lRange,hRange); residualEta5->Fit("funResidualEta5","RQ");
      meanEta5=funResidualEta5->GetParameter(1);
      sigmaEta5=funResidualEta5->GetParameter(2);
      delete funResidualEta5;
*/
      meanXChi2=xTrackChi2->GetMean();
      meanYChi2=yTrackChi2->GetMean();
      

      f->Write();
      f->Close();

      fout1<<preshiREF2X<<"\t"<<preshiREF2Y<<"\t"<<meanEta5<<"\t"<<sigmaEta5<<"\t"<<meanXChi2<<"\t"<<meanYChi2<<"\t"<<totalChi2<<endl;
      //fout3<<preshiREF2X<<"\t"<<preshiREF2Y<<"\t"<<sigmaREF2X<<"\t"<<sigmaREF2Y<<"\t"<<sigmaREF3X<<"\t"<<sigmaREF3Y<<"\t"<<sigmaUVA3X<<"\t"<<sigmaUVA3Y<<"\t"<<sigmaREF1X<<"\t"<<sigmaREF1Y<<"\t"<<sigmaEta5<<endl;
      //fout2<<preshiREF2X<<"\t"<<preshiREF2Y<<"\t"<<meanXChi2<<"\t"<<meanYChi2<<endl;
      //clear the vectors for next loop
      //vpREF2X.clear(); vpREF2Y.clear();
      //vpREF3X.clear(); vpREF3Y.clear();
      //vpUVA3X.clear(); vpUVA3Y.clear();
      //vpREF1X.clear(); vpREF1Y.clear();
      //vpEta5.clear();
      //vpREF2X.swap(DefaultVector); vpREF2Y.swap(DefaultVector); vpREF3X.swap(DefaultVector); vpREF3Y.swap(DefaultVector); 
      //vpUVA3X.swap(DefaultVector); vpUVA3Y.swap(DefaultVector); vpREF1X.swap(DefaultVector); vpREF1Y.swap(DefaultVector); vpEta5.swap(DefaultVector);
    
     // cout<<residualEta5->GetEntries()<<"TTTTTTTTTTTT"<<endl;
     //gDirectory->GetList()->Delete();
      //hpREF2X=NULL; hpREF2Y=NULL; hpREF3X=NULL; hpREF3Y=NULL;
      //hpUVA3X=NULL; hpUVA3Y=NULL; hpREF1X=NULL; hpREF1Y=NULL;
      //residualREF2X=NULL; residualREF2Y=NULL; residualREF3X=NULL; residualREF3Y=NULL;
      //residualUVA3X=NULL; residualUVA3Y=NULL; residualREF1X=NULL; residualREF1Y=NULL;
      //residualEta5=NULL;
      //funResidualEta5=NULL;
      //angleREF3=NULL; angleUVA3=NULL; angleREF1=NULL; angleEta5=NULL;

      //myValues.fit_func=NULL; 
     // delete myValues.fit_func;
     // f=NULL; delete f;
   //}//for-loop instead of while(1)
   //   delete hpREF2X; delete hpREF2Y; delete hpREF3X; delete hpREF3Y;
   //   delete hpUVA3X; delete hpUVA3Y; delete hpREF1X; delete hpREF1Y;
   //   delete residualREF2X; delete residualREF2Y; delete residualREF3X; delete residualREF3Y;
   //   delete residualUVA3X; delete residualUVA3Y; delete residualREF1X; delete residualREF1Y;
   //   delete residualEta5;
      //delete funResidualEta5;
   //   delete angleREF3; delete angleUVA3; delete angleREF1;
   //   delete angleEta5;
  //}
 fout1.close();
 //fout3.close();
 //fout2.close();
 return 0;
} // entire script
예제 #6
0
파일: dmake.cpp 프로젝트: tota/cppcheck
int main(int argc, char **argv)
{
    const bool release(argc >= 2 && std::string(argv[1]) == "--release");

    // Get files..
    std::vector<std::string> libfiles;
    getCppFiles(libfiles, "lib/");

    std::vector<std::string> clifiles;
    getCppFiles(clifiles, "cli/");

    std::vector<std::string> testfiles;
    getCppFiles(testfiles, "test/");

    if (libfiles.empty() && clifiles.empty() && testfiles.empty()) {
        std::cerr << "No files found. Are you in the correct directory?" << std::endl;
        return EXIT_FAILURE;
    }

    std::vector<std::string> externalfiles;
    getCppFiles(externalfiles, "externals/");


    // QMAKE - lib/lib.pri
    {
        std::ofstream fout1("lib/lib.pri");
        if (fout1.is_open()) {
            fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
            fout1 << "include($$PWD/pcrerules.pri)\n";
            fout1 << "BASEPATH = ../externals/tinyxml/\n";
            fout1 << "include($$PWD/../externals/tinyxml/tinyxml.pri)\n";
            fout1 << "BASEPATH = ../lib/\n";
            fout1 << "INCLUDEPATH += ../externals/tinyxml\n";
            fout1 << "HEADERS += $${BASEPATH}check.h \\\n";
            for (unsigned int i = 0; i < libfiles.size(); ++i) {
                std::string fname(libfiles[i].substr(4));
                if (fname.find(".cpp") == std::string::npos)
                    continue;   // shouldn't happen
                fname.erase(fname.find(".cpp"));
                fout1 << std::string(11, ' ') << "$${BASEPATH}" << fname << ".h";
                if (i + 1 < testfiles.size())
                    fout1 << " \\\n";
            }
            fout1 << "\n\nSOURCES += ";
            for (unsigned int i = 0; i < libfiles.size(); ++i) {
                fout1 << "$${BASEPATH}" << libfiles[i].substr(4);
                if (i < libfiles.size() - 1)
                    fout1 << " \\\n" << std::string(11, ' ');
            }
            fout1 << "\n";
        }
    }

    // QMAKE - test/testfiles.pri
    {
        std::ofstream fout1("test/testfiles.pri");
        if (fout1.is_open()) {
            fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
            fout1 << "INCLUDEPATH += ../externals/tinyxml\n";
            fout1 << "\n\nSOURCES += ";
            for (unsigned int i = 0; i < testfiles.size(); ++i) {
                const std::string filename(testfiles[i].substr(5));
                // Include only files containing tests in this listing.
                // I.e. filenames beginning with "test".
                if (filename.compare(0, 4, "test") == 0) {
                    fout1 << "$${BASEPATH}/" << filename;
                    if (i + 1 < testfiles.size())
                        fout1 << " \\\n" << std::string(11, ' ');
                }
            }
            fout1 << "\n";
        }
    }

    static const char makefile[] = "Makefile";
    std::ofstream fout(makefile, std::ios_base::trunc);
    if (!fout.is_open()) {
        std::cerr << "An error occurred while trying to open "
                  << makefile
                  << ".\n";
        return EXIT_FAILURE;
    }

    fout << "# This file is generated by tools/dmake, do not edit.\n\n";
    fout << "# To compile with rules, use 'make HAVE_RULES=yes'\n";
    makeConditionalVariable(fout, "HAVE_RULES", "no");

    // compiled patterns..
    fout << "# folder where lib/*.cpp files are located\n";
    makeConditionalVariable(fout, "SRCDIR", "lib");
    fout << "ifeq ($(SRCDIR),build)\n"
         << "    ifdef VERIFY\n"
         << "        matchcompiler_S := $(shell python tools/matchcompiler.py --verify)\n"
         << "    else\n"
         << "        matchcompiler_S := $(shell python tools/matchcompiler.py)\n"
         << "    endif\n"
         << "endif\n\n";

    // explicit cfg dir..
    fout << "ifdef CFGDIR\n"
         << "    CFG=-DCFGDIR=\\\"$(CFGDIR)\\\"\n"
         << "else\n"
         << "    CFG=\n"
         << "endif\n\n";

    // The _GLIBCXX_DEBUG doesn't work in cygwin or other Win32 systems.
    fout << "# Set the CPPCHK_GLIBCXX_DEBUG flag. This flag is not used in release Makefiles.\n"
         << "# The _GLIBCXX_DEBUG define doesn't work in Cygwin or other Win32 systems.\n"
         << "ifndef COMSPEC\n"
         << "    ifdef ComSpec\n"
         << "        #### ComSpec is defined on some WIN32's.\n"
         << "        COMSPEC=$(ComSpec)\n"
         << "    endif # ComSpec\n"
         << "endif # COMSPEC\n"
         << "\n"
         << "ifdef COMSPEC\n"
         << "    #### Maybe Windows\n"
         << "    ifndef CPPCHK_GLIBCXX_DEBUG\n"
         << "        CPPCHK_GLIBCXX_DEBUG=\n"
         << "    endif # !CPPCHK_GLIBCXX_DEBUG\n"
         << "\n"
         << "    ifeq ($(MSYSTEM),MINGW32)\n"
         << "        LDFLAGS=-lshlwapi\n"
         << "    endif\n"
         << "else # !COMSPEC\n"
         << "    uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')\n"
         << "\n"
         << "    ifeq ($(uname_S),Linux)\n"
         << "        ifndef CPPCHK_GLIBCXX_DEBUG\n"
         << "            CPPCHK_GLIBCXX_DEBUG=-D_GLIBCXX_DEBUG\n"
         << "        endif # !CPPCHK_GLIBCXX_DEBUG\n"
         << "    endif # Linux\n"
         << "\n"
         << "    ifeq ($(uname_S),GNU/kFreeBSD)\n"
         << "        ifndef CPPCHK_GLIBCXX_DEBUG\n"
         << "            CPPCHK_GLIBCXX_DEBUG=-D_GLIBCXX_DEBUG\n"
         << "        endif # !CPPCHK_GLIBCXX_DEBUG\n"
         << "    endif # GNU/kFreeBSD\n"
         << "\n"
         << "endif # COMSPEC\n"
         << "\n";

    // Makefile settings..
    if (release) {
        makeConditionalVariable(fout, "CXXFLAGS", "-O2 -DNDEBUG -Wall");
    } else {
        // TODO: add more compiler warnings.
        // -Wlogical-op       : doesn't work on older GCC
        // -Wsign-conversion  : too many warnings
        // -Wunreachable-code : some GCC versions report lots of warnings
        makeConditionalVariable(fout, "CXXFLAGS",
                                "-pedantic "
                                "-Wall "
                                "-Wextra "
                                "-Wabi "
                                "-Wcast-qual "
                                "-Wconversion "
                                "-Wfloat-equal "
                                "-Winline "
//                                "-Wlogical-op "
                                "-Wmissing-declarations "
                                "-Wmissing-format-attribute "
                                "-Wno-long-long "
                                "-Woverloaded-virtual "
                                "-Wpacked "
                                "-Wredundant-decls "
                                "-Wshadow "
//                                "-Wsign-conversion "
                                "-Wsign-promo "
//                                "-Wunreachable-code "
                                "$(CPPCHK_GLIBCXX_DEBUG) "
                                "-g");
    }

    fout << "ifeq ($(HAVE_RULES),yes)\n"
         << "    CXXFLAGS += -DHAVE_RULES -DTIXML_USE_STL $(shell pcre-config --cflags)\n"
         << "    ifdef LIBS\n"
         << "        LIBS += $(shell pcre-config --libs)\n"
         << "    else\n"
         << "        LIBS=$(shell pcre-config --libs)\n"
         << "    endif\n"
         << "endif\n\n";

    makeConditionalVariable(fout, "CXX", "g++");
    makeConditionalVariable(fout, "PREFIX", "/usr");
    makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -Iexternals -Iexternals/tinyxml");
    makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -Iexternals -Iexternals/tinyxml");
    makeConditionalVariable(fout, "INCLUDE_FOR_TEST", "-Ilib -Icli -Iexternals -Iexternals/tinyxml");

    fout << "BIN=$(DESTDIR)$(PREFIX)/bin\n\n";
    fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml on Linux\n";
    fout << "DB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl\n";
    fout << "XP=xsltproc -''-nonet -''-param man.charmap.use.subset \"0\"\n";
    fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";

    fout << "\n###### Object Files\n\n";
    fout << "LIBOBJ =      " << objfile(libfiles[0]);
    for (unsigned int i = 1; i < libfiles.size(); ++i)
        fout << " \\\n" << std::string(14, ' ') << objfile(libfiles[i]);
    fout << "\n\n";
    fout << "CLIOBJ =      " << objfile(clifiles[0]);
    for (unsigned int i = 1; i < clifiles.size(); ++i)
        fout << " \\\n" << std::string(14, ' ') << objfile(clifiles[i]);
    fout << "\n\n";
    fout << "TESTOBJ =     " << objfile(testfiles[0]);
    for (unsigned int i = 1; i < testfiles.size(); ++i)
        fout << " \\\n" << std::string(14, ' ') << objfile(testfiles[i]);
    fout << "\n\n";

    makeExtObj(fout, externalfiles);

    fout << "\n###### Targets\n\n";
    fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
    fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -std=c++0x -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) $(LIBS) $(LDFLAGS)\n\n";
    fout << "all:\tcppcheck testrunner\n\n";
    fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/pathmatch.o\n";
    fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -std=c++0x -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cppcheckexecutor.o cli/cmdlineparser.o cli/filelister.o cli/pathmatch.o $(EXTOBJ) $(LIBS) $(LDFLAGS)\n\n";
    fout << "test:\tall\n";
    fout << "\t./testrunner\n\n";
    fout << "check:\tall\n";
    fout << "\t./testrunner -g -q\n\n";
    fout << "dmake:\ttools/dmake.cpp\n";
    fout << "\t$(CXX) -std=c++0x -o dmake tools/dmake.cpp cli/filelister.cpp lib/path.cpp -Ilib $(LDFLAGS)\n\n";
    fout << "reduce:\ttools/reduce.cpp\n";
    fout << "\t$(CXX) -std=c++0x -g -o reduce tools/reduce.cpp -Ilib -Iexternals/tinyxml lib/*.cpp externals/tinyxml/tinyxml2.cpp\n\n";
    fout << "clean:\n";
    fout << "\trm -f build/*.o lib/*.o cli/*.o test/*.o externals/tinyxml/*.o testrunner reduce cppcheck cppcheck.1\n\n";
    fout << "man:\tman/cppcheck.1\n\n";
    fout << "man/cppcheck.1:\t$(MAN_SOURCE)\n\n";
    fout << "\t$(XP) $(DB2MAN) $(MAN_SOURCE)\n\n";
    fout << "tags:\n";
    fout << "\tctags -R --exclude=doxyoutput .\n\n";
    fout << "install: cppcheck\n";
    fout << "\tinstall -d ${BIN}\n";
    fout << "\tinstall cppcheck ${BIN}\n";
    fout << "\tinstall htmlreport/cppcheck-htmlreport ${BIN}\n\n";

    fout << "\n###### Build\n\n";

    compilefiles(fout, libfiles, "${INCLUDE_FOR_LIB}");
    compilefiles(fout, clifiles, "${INCLUDE_FOR_CLI}");
    compilefiles(fout, testfiles, "${INCLUDE_FOR_TEST}");

    return 0;
}
예제 #7
0
파일: pagie2.cpp 프로젝트: Ambrosys/gpcxx
int main( int argc , char *argv[] )
{
    rng_type rng;

    trainings_data_type c = gpcxx::generate_evenly_spaced_test_data< 3 >( -5.0 , 5.0 + 0.1 , 0.4 , []( double x1 , double x2 , double x3 ) {
                        return  1.0 / ( 1.0 + pow( x1 , -4.0 ) ) + 1.0 / ( 1.0 + pow( x2 , -4.0 ) ) + 1.0 / ( 1.0 + pow( x3 , -4.0 ) ); } );
    gpcxx::normalize( c.y );
    

    std::ofstream fout1( "testdata.dat" );
    for( size_t i=0 ; i<c.x[0].size() ; ++i )
        fout1 << c.y[i] << " " << c.x[0][i] << " " << c.x[1][i] << " " << c.x[2][i] << "\n";
    fout1.close();
    
    auto eval = gpcxx::make_static_eval< value_type , symbol_type , eval_context_type >(
        fusion::make_vector(
            fusion::make_vector( 'x' , []( eval_context_type const& t ) { return t[0]; } )
          , fusion::make_vector( 'y' , []( eval_context_type const& t ) { return t[1]; } )
          , fusion::make_vector( 'z' , []( eval_context_type const& t ) { return t[2]; } )          
          ) ,
        fusion::make_vector(
            fusion::make_vector( 's' , []( double v ) -> double { return std::sin( v ); } )
          , fusion::make_vector( 'c' , []( double v ) -> double { return std::cos( v ); } ) 
          , fusion::make_vector( 'e' , []( double v ) -> double { return std::exp( v ); } ) 
          , fusion::make_vector( 'l' , []( double v ) -> double { return ( std::abs( v ) < 1.0e-20 ) ? log( 1.0e-20 ) : std::log( std::abs( v ) ); } ) 
          ) ,
        fusion::make_vector(
            fusion::make_vector( '+' , std::plus< double >() )
          , fusion::make_vector( '-' , std::minus< double >() )
          , fusion::make_vector( '*' , std::multiplies< double >() ) 
          , fusion::make_vector( '/' , std::divides< double >() ) 
          ) );
    typedef decltype( eval ) eval_type;
    typedef eval_type::node_attribute_type node_attribute_type;
    
    typedef gpcxx::basic_tree< node_attribute_type > tree_type;
    typedef std::vector< tree_type > population_type;
    typedef gpcxx::static_pipeline< population_type , fitness_type , rng_type > evolver_type;

    
    size_t population_size = 1000;
    size_t generation_size = 20;
    double number_elite = 1;
    double mutation_rate = 0.0;
    double crossover_rate = 0.6;
    double reproduction_rate = 0.3;
    size_t min_tree_height = 8 , max_tree_height = 8;
    size_t tournament_size = 15;


    // generators< rng_type > gen( rng );
    auto terminal_gen = eval.get_terminal_symbol_distribution();
    auto unary_gen = eval.get_unary_symbol_distribution();
    auto binary_gen = eval.get_binary_symbol_distribution();
    gpcxx::node_generator< node_attribute_type , rng_type , 3 > node_generator {
        { 2.0 * double( terminal_gen.num_symbols() ) , 0 , terminal_gen } ,
        { double( unary_gen.num_symbols() ) , 1 , unary_gen } ,
        { double( binary_gen.num_symbols() ) , 2 , binary_gen } };

    auto tree_generator = gpcxx::make_ramp( rng , node_generator , min_tree_height , max_tree_height , 0.5 );
    

    evolver_type evolver( number_elite , mutation_rate , crossover_rate , reproduction_rate , rng );
    std::vector< double > fitness( population_size , 0.0 );
    std::vector< tree_type > population( population_size );


    auto fitness_f = gpcxx::regression_fitness< eval_type >( eval );
    evolver.mutation_function() = gpcxx::make_mutation(
        gpcxx::make_simple_mutation_strategy( rng , node_generator ) ,
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    evolver.crossover_function() = gpcxx::make_crossover( 
        gpcxx::make_one_point_crossover_strategy( rng , max_tree_height ) ,
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    evolver.reproduction_function() = gpcxx::make_reproduce( gpcxx::make_tournament_selector( rng , tournament_size ) );
    
    gpcxx::timer timer;



    // initialize population with random trees and evaluate fitness
    timer.restart();
    for( size_t i=0 ; i<population.size() ; ++i )
    {
        tree_generator( population[i] );
        fitness[i] = fitness_f( population[i] , c );
    }
    std::cout << gpcxx::indent( 0 ) << "Generation time " << timer.seconds() << std::endl;
    std::cout << gpcxx::indent( 1 ) << "Best individuals" << std::endl << gpcxx::best_individuals( population , fitness , 1 , 10 ) << std::endl;
    std::cout << gpcxx::indent( 1 ) << "Statistics : " << gpcxx::calc_population_statistics( population ) << std::endl;
    std::cout << gpcxx::indent( 1 ) << std::endl << std::endl;

    timer.restart();
    for( size_t generation=1 ; generation<=generation_size ; ++generation )
    {
        gpcxx::timer iteration_timer;
        iteration_timer.restart();
        evolver.next_generation( population , fitness );
        double evolve_time = iteration_timer.seconds();
        iteration_timer.restart();
        std::transform( population.begin() , population.end() , fitness.begin() , [&]( tree_type const &t ) { return fitness_f( t , c ); } );
        double eval_time = iteration_timer.seconds();
        
        std::cout << gpcxx::indent( 0 ) << "Generation " << generation << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Evolve time " << evolve_time << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Eval time " << eval_time << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Best individuals" << std::endl << gpcxx::best_individuals( population , fitness , 2 , 10 ) << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Statistics : " << gpcxx::calc_population_statistics( population ) << std::endl << std::endl;
    }
    std::cout << "Overall time : " << timer.seconds() << std::endl;

    return 0;
}
예제 #8
0
파일: plot0v2new.C 프로젝트: XuQiao/phenix
void plot0v2new(){
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(1);
  gStyle->SetOptTitle(0);
  gStyle->SetCanvasBorderMode(0);
  gStyle->SetStatColor(10);
  gStyle->SetTitleFillColor(10);

  const int nrun=339;

//  ifstream fin1("fvtx0s_v2_cent_0.dat");
  ifstream fin1("bbcs_v2_cent_0.dat");
//  ifstream fin2("../../final06/rp/fvtx0s_v2_cent_0.dat");
  ifstream fin2("../Run15pAu200GeVlowRun1.Lst");
  int runlow[92];
  ofstream fout1("goodrun_lowlumi.dat");
 // ofstream fout1("goodrun_bbcs_v2_cent_0.dat");
//  ofstream fout2("goodrun_fvtx1s_v2_cent_0.dat");


  float run[nrun];
  float par1[nrun], par2[nrun], par3[nrun], par4[nrun];
  for(int irun=0;irun<92;irun++)
    fin2>>runlow[irun];
  for(int irun=0; irun<nrun; irun++){
    fin1>>run[irun]>>par1[irun];
//    fin2>>run[irun]>>par2[irun];
   // if(par1[irun]>0.2&&par1[irun]<3.0){
        int flag=0;
        for(int j=0;j<92;j++){
            if(run[irun]==runlow[j])
                flag=1;
        }
        if(flag==1)
        fout1<<run[irun]<<endl;
    //    }
   // else 
        cout<<"bbc"<<run[irun]<<endl;

//    if(par2[irun]>0.2&&par2[irun]<3.0) fout2<<run[irun]<<endl;
//    else cout<<"mpc"<<run[irun]<<endl;

  }
  fin1.close();
//  fin2.close();

  fout1.close();
//  fout2.close();

  //cnt
  //for(int irun=0; irun<nrun; irun++){
  //fin4>>run[irun]>>par4[irun];
  //if(par4[irun]>0.2&&par4[irun]<5.0) fout4<<run[irun]<<endl;
  //}
  
  //fin4.close();
  //fout4.close();

  TGraph *gr1 = new TGraph(nrun,run,par1);
//  TGraph *gr2 = new TGraph(nrun,run,par2);

  c=new TCanvas("c","c",800,500);
  c->SetFillColor(10);
 // TH1F *h=new TH1F("h","RP QA for FVTXs Psi2",436017-432637+20,432637-10,436017+10);
  TH1F *h=new TH1F("h","RP QA for bbcs Psi2",436017-432637+20,432637-10,436017+10);
  h->SetMaximum(2.0);
  h->SetMinimum(-1.0);
  h->GetXaxis()->SetTitle("#run");
  h->GetYaxis()->SetTitle("#chi^{2}/NDF");
  h->GetYaxis()->CenterTitle(kTRUE);
  h->Draw();
  
  gr1->SetMarkerStyle(20);
  gr1->SetMarkerSize(1.0);
  gr1->SetMarkerColor(2);
  gr1->Draw("P");
  
/*  
  gr2->SetMarkerStyle(22);
  gr2->SetMarkerSize(1.0);
  gr2->SetMarkerColor(6);
  gr2->Draw("P");
*/  

  TLegend *leg2 = new TLegend(0.62,0.87,0.85,0.67);
  leg2->SetFillColor(10);
  leg2->SetLineStyle(4000);
  leg2->SetLineColor(10);
  leg2->SetLineWidth(0.);
  leg2->SetTextSize(0.04);
  leg2->SetBorderSize(0);
//  leg2->AddEntry(gr1,"Psi2 FVTXs:0~5%","");
  leg2->AddEntry(gr1,"Psi2 BBCs:0~5%","");
//  leg2->AddEntry(gr2,"eta:-2.5,-1.5","P");
  leg2->AddEntry(gr1,"eta:-3.0,-1.0","P");
  //leg2->AddEntry(gr3,"SMDs","P");
  //leg2->AddEntry(gr4,"CNT","P");

  leg2->Draw();

  //c->Print("ReactionPlane_cent0_10.eps");
  //c->Print("ReactionPlane_cent0_10.gif");
}
int main()
{
    std::ofstream fout1("test1.dat");  // Flat Sky
    std::ofstream fout2("test2.dat");  // Spherical near equator
    std::ofstream fout3("test3.dat");  // Spherical around N pole.
    std::ofstream fout4("test4.dat");  // Test1 with random offsets
    std::ofstream fout4c("test4_centers.dat");  // Corresponding centers for test4.dat
    fout1.precision(12);
    fout2.precision(12);
    fout3.precision(12);
    fout4.precision(12);
    fout4c.precision(12);

    double ra0 = 0.; // RA, Dec of center for test2.
    double dec0 = 80.;

    const long ngal = 100000;
    const double rscale = 1.; // Scale radius in degrees.
    const double rmax = 5.; // In units of rscale

    // The functional form imprinted is purely radial:
    // gamma_t(r) = gamma0/r
    // kappa(r) = kappa0/r
    // n(r) ~ exp(-r^2/2)
    // where r is in units of rscale
    const double gamma0 = 1.e-3;
    const double kappa0 = 3.e-3;
    // Make sure gamma_t < 0.5
    const double rmin = gamma0/0.5;

    srand(1234); // To make it deterministic.
    // Normally for the Box-Muller Transformation, one would restrict rsq < 1
    // But we then want to clip the resulting distribution at rmax, so
    // rsq * fac^2 < rmax^2
    // rsq * (-2.*log(rsq)/rsq) < rmax^2
    // -2. * log(rsq) < rmax^2
    // rsq > exp(-rmax^2/2)
    const double rsqmin = exp(-rmax*rmax/2.);
    const double rsqmax = exp(-rmin*rmin/2.);
    //std::cout<<"rsq min/max = "<<rsqmin<<','<<rsqmax<<std::endl;

    double xdeg_min=0., xdeg_max=0., var_xdeg=0.;
    double ydeg_min=0., ydeg_max=0., var_ydeg=0.;

    for (long n=0; n<ngal; ++n) {
        double x,y,rsq;
        do {
            x = double(rand()) / RAND_MAX; // Random number from 0..1
            y = double(rand()) / RAND_MAX;
            //std::cout<<"x,y = "<<x<<','<<y<<std::endl;
            x = 2.*x-1.; // Now from -1..1
            y = 2.*y-1.;
            //std::cout<<"x,y => "<<x<<','<<y<<std::endl;
            rsq = x*x+y*y;
            //std::cout<<"rsq = "<<rsq<<std::endl;
        } while (rsq <= rsqmin || rsq >= rsqmax);
        // Use Box-Muller Transformation to convert to Gaussian distribution in x,y.
        double fac = sqrt(-2.*log(rsq)/rsq);
        x *= fac;
        y *= fac;

        double r = fac*sqrt(rsq);
        double theta = atan2(y,x);
        double g = gamma0 / r;
        double k = kappa0 / r;
        assert(g < 0.5);

        double xdeg = x*rscale;
        double ydeg = y*rscale;
        double rdeg = r*rscale;

        // Do some sanity checks:
        if (xdeg < xdeg_min) xdeg_min = xdeg;
        if (xdeg > xdeg_max) xdeg_max = xdeg;
        if (ydeg < ydeg_min) ydeg_min = ydeg;
        if (ydeg > ydeg_max) ydeg_max = ydeg;
        var_xdeg += xdeg*xdeg;
        var_ydeg += ydeg*ydeg;

        //
        // Flat sky:
        // 
        double g1 = -g * cos(2.*theta);
        double g2 = -g * sin(2.*theta);
        fout1 << xdeg <<"  "<< ydeg <<"  "<< g1 <<"  "<< g2 <<"  "<< k <<std::endl;


        // With offsets in position:
        double dx = 2.*double(rand()) / RAND_MAX - 1.; // Random number from -1..1
        double dy = 2.*double(rand()) / RAND_MAX - 1.;
        dx *= rscale;
        dy *= rscale;
        fout4 << xdeg + dx <<"  "<< ydeg + dy <<"  "<< g1 <<"  "<< g2 <<"  "<< k <<std::endl;
        fout4c << dx <<"  "<< dy <<"  1. "<<std::endl;

        // 
        // Spherical near equator:
        //

        // Use spherical triangle with A = point, B = (ra0,dec0), C = N. pole
        // a = Pi/2-dec0
        // c = 2*atan(r/2)
        // B = Pi/2 - theta

        // Solve the rest of the triangle with spherical trig:
        double c = 2.*atan( (rdeg*M_PI/180.) / 2.);
        double a = M_PI/2. - (dec0*M_PI/180.);
        double B = x > 0 ? M_PI/2. - theta : theta - M_PI/2.;
        if (B < 0) B += 2.*M_PI;
        if (B > 2.*M_PI) B -= 2.*M_PI;
        double cosb = cos(a)*cos(c) + sin(a)*sin(c)*cos(B);
        double b = std::abs(cosb) < 1. ? acos(cosb) : 0.;
        double cosA = (cos(a) - cos(b)*cos(c)) / (sin(b)*sin(c));
        double A = std::abs(cosA) < 1. ? acos(cosA) : 0.;
        double cosC = (cos(c) - cos(a)*cos(b)) / (sin(a)*sin(b));
        double C = std::abs(cosC) < 1. ? acos(cosC) : 0.;

        //std::cout<<"x,y = "<<x<<','<<y<<std::endl;
        //std::cout<<"a = "<<a<<std::endl;
        //std::cout<<"b = "<<b<<std::endl;
        //std::cout<<"c = "<<c<<std::endl;
        //std::cout<<"A = "<<A<<std::endl;
        //std::cout<<"B = "<<B<<std::endl;
        //std::cout<<"C = "<<C<<std::endl;

        // Compute ra,dec from these.
        // Note: increasing x is decreasing ra.  East is left on the sky!
        double ra = x>0 ? -C : C;
        double dec = M_PI/2. - b;
        ra *= 180. / M_PI;
        dec *= 180. / M_PI;
        ra += ra0;
        //std::cout<<"ra = "<<ra<<std::endl;
        //std::cout<<"dec = "<<dec<<std::endl;

        // Rotate shear relative to local west
        std::complex<double> gamma(g1,g2);
        double beta = M_PI - (A+B);
        if (x > 0) beta = -beta;
        //std::cout<<"gamma = "<<gamma<<std::endl;
        //std::cout<<"beta = "<<beta<<std::endl;
        std::complex<double> exp2ibeta(cos(2.*beta),sin(2.*beta));
        gamma *= exp2ibeta;
        //std::cout<<"gamma => "<<gamma<<std::endl;
        fout2 << ra <<"  "<< dec <<"  "<< real(gamma) <<"  "<<imag(gamma) <<"  "<<k <<std::endl;

        //
        // Spherical around N pole
        //

        dec = 90. - c * 180./M_PI;
        ra = theta * 12. / M_PI;
        fout3 << ra <<"  "<< dec <<"  "<< g <<"  "<<0. <<"  "<<k <<std::endl;
    }
    var_xdeg /= ngal;
    var_ydeg /= ngal;
    std::cout<<"Min/Max x = "<<xdeg_min<<"  "<<xdeg_max<<std::endl;;
    std::cout<<"Min/Max y = "<<ydeg_min<<"  "<<ydeg_max<<std::endl;;
    std::cout<<"sqrt(Var(x)) = "<<sqrt(var_xdeg)<<std::endl;
    std::cout<<"sqrt(Var(y)) = "<<sqrt(var_ydeg)<<std::endl;

    // Make random catalogs
    std::ofstream foutr1("rand1.dat");
    std::ofstream foutr2("rand2.dat");
    std::ofstream foutr3("rand3.dat");
    foutr1.precision(12);
    foutr2.precision(12);
    foutr3.precision(12);
    xdeg_min=xdeg_max=var_xdeg=0.;
    ydeg_min=ydeg_max=var_ydeg=0.;
    for (long n=0; n<10*ngal; ++n) {
        double x,y,rsq;
        do {
            x = double(rand()) / RAND_MAX; // Random number from 0..1
            y = double(rand()) / RAND_MAX;
            x = 2.*x-1.; // Now from -1..1
            y = 2.*y-1.;
            rsq = x*x+y*y;
        } while (rsq >= 1.);
        x *= rmax;
        y *= rmax;

        double r = rmax*sqrt(rsq);
        double theta = atan2(y,x);
        double xdeg = x*rscale;
        double ydeg = y*rscale;
        double rdeg = r*rscale;

        // Do some sanity checks:
        if (xdeg < xdeg_min) xdeg_min = xdeg;
        if (xdeg > xdeg_max) xdeg_max = xdeg;
        if (ydeg < ydeg_min) ydeg_min = ydeg;
        if (ydeg > ydeg_max) ydeg_max = ydeg;
        var_xdeg += xdeg*xdeg;
        var_ydeg += ydeg*ydeg;


        //
        // flat sky:
        // 
        foutr1 << xdeg <<"  "<< ydeg << std::endl;

        // 
        // Spherical near equator:
        //

        double c = 2.*atan( (rdeg*M_PI/180.) / 2.);
        double a = M_PI/2. - (dec0*M_PI/180.);
        double B = x > 0 ? M_PI/2. - theta : theta - M_PI/2.;
        if (B < 0) B += 2.*M_PI;
        if (B > 2.*M_PI) B -= 2.*M_PI;
        double cosb = cos(a)*cos(c) + sin(a)*sin(c)*cos(B);
        double b = std::abs(cosb) < 1. ? acos(cosb) : 0.;
        double cosC = (cos(c) - cos(a)*cos(b)) / (sin(a)*sin(b));
        double C = std::abs(cosC) < 1. ? acos(cosC) : 0.;

        double ra = x>0 ? -C : C;
        double dec = M_PI/2. - b;
        ra *= 180. / M_PI;
        dec *= 180. / M_PI;
        ra += ra0;

        foutr2 << ra <<"  "<< dec <<std::endl;

        //
        // Spherical around N pole
        //

        dec = 90. - c * 180./M_PI;
        ra = theta * 12. / M_PI;
        foutr3 << ra <<"  "<< dec <<std::endl;
    }
    var_xdeg /= ngal;
    var_ydeg /= ngal;
    std::cout<<"For randoms:\n";
    std::cout<<"Min/Max x = "<<xdeg_min<<"  "<<xdeg_max<<std::endl;;
    std::cout<<"Min/Max y = "<<ydeg_min<<"  "<<ydeg_max<<std::endl;;
    std::cout<<"sqrt(Var(x)) = "<<sqrt(var_xdeg)<<std::endl;
    std::cout<<"sqrt(Var(y)) = "<<sqrt(var_ydeg)<<std::endl;
    return 0;
}
예제 #10
0
int main( int argc , char *argv[] )
{
    rng_type rng;
    
    trainings_data_type c;
    generate_test_data( c , -5.0 , 5.0 + 0.1 , 0.4 , []( double x1 , double x2 , double x3 ) {
                        return  1.0 / ( 1.0 + pow( x1 , -4.0 ) ) + 1.0 / ( 1.0 + pow( x2 , -4.0 ) ) + 1.0 / ( 1.0 + pow( x3 , -4.0 ) ); } );
    gpcxx::normalize( c.y );
    

    std::ofstream fout1( "testdata.dat" );
    for( size_t i=0 ; i<c.x[0].size() ; ++i )
        fout1 << c.y[i] << " " << c.x[0][i] << " " << c.x[1][i] << " " << c.x[2][i] << "\n";
    fout1.close();
    

	gpcxx::uniform_symbol< node_type > terminal_gen { std::vector< node_type >{
        node_type { gpcxx::array_terminal< 0 >{} , "x" } ,
        node_type { gpcxx::array_terminal< 1 >{} , "y" } ,
        node_type { gpcxx::array_terminal< 2 >{} , "z" } } };
    gpcxx::uniform_symbol< node_type > unary_gen { std::vector< node_type >{
        node_type { gpcxx::sin_func{} , "s" } ,
        node_type { gpcxx::cos_func{} , "c" } ,
        node_type { gpcxx::exp_func{} , "e" } ,
        node_type { gpcxx::log_func{} , "l" } } };
    gpcxx::uniform_symbol< node_type > binary_gen { std::vector< node_type > {
        node_type { gpcxx::plus_func{} , "+" } ,
        node_type { gpcxx::minus_func{} , "-" } ,
        node_type { gpcxx::multiplies_func{} , "*" } ,
        node_type { gpcxx::divides_func{} , "/" }    
    } };
    
    gpcxx::node_generator< node_type , rng_type , 3 > node_generator {
        { double ( terminal_gen.num_symbols() ) , 0 , terminal_gen } ,
        { double ( unary_gen.num_symbols() ) , 1 , unary_gen } ,
        { double ( binary_gen.num_symbols() ) , 2 , binary_gen } };
    
    size_t population_size = 512;
    size_t generation_size = 20;
    double number_elite = 1;
    double mutation_rate = 0.0;
    double crossover_rate = 0.6;
    double reproduction_rate = 0.3;
    size_t max_tree_height = 8;
    size_t tournament_size = 15;
    

    auto tree_generator = gpcxx::make_basic_generate_strategy( rng , node_generator , max_tree_height , max_tree_height );
    // size_t min_tree_height = 1
    // auto new_tree_generator = gpcxx::make_ramp( rng , node_generator , min_tree_height , max_tree_height , 0.5 );


    typedef gpcxx::static_pipeline< population_type , fitness_type , rng_type > evolver_type;
    evolver_type evolver( number_elite , mutation_rate , crossover_rate , reproduction_rate , rng );
    std::vector< double > fitness( population_size , 0.0 );
    std::vector< tree_type > population( population_size );


    evolver.mutation_function() = gpcxx::make_mutation(
        gpcxx::make_simple_mutation_strategy( rng , node_generator ) ,
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    evolver.crossover_function() = gpcxx::make_crossover( 
        gpcxx::make_one_point_crossover_strategy( rng , max_tree_height ) ,
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    evolver.reproduction_function() = gpcxx::make_reproduce(
        gpcxx::make_tournament_selector( rng , tournament_size ) );
    
    gpcxx::timer timer;
    auto fitness_f = gpcxx::make_regression_fitness( evaluator() );

    // initialize population with random trees and evaluate fitness
    timer.restart();
    for( size_t i=0 ; i<population.size() ; ++i )
    {
        tree_generator( population[i] );
        fitness[i] = fitness_f( population[i] , c );
    }
    std::cout << gpcxx::indent( 0 ) << "Generation time " << timer.seconds() << std::endl;
    std::cout << gpcxx::indent( 1 ) << "Best individuals" << std::endl << gpcxx::best_individuals( population , fitness , 1 , 10 ) << std::endl;
    std::cout << gpcxx::indent( 1 ) << "Statistics : " << gpcxx::calc_population_statistics( population ) << std::endl;
    std::cout << gpcxx::indent( 1 ) << std::endl << std::endl;
    
    write_height_hist( population , "initial_height.hist" );
    write_size_hist( population , "initial_size.hist" );
    
    timer.restart();
    for( size_t generation=1 ; generation<=generation_size ; ++generation )
    {
        gpcxx::timer iteration_timer;
        iteration_timer.restart();
        evolver.next_generation( population , fitness );
        double evolve_time = iteration_timer.seconds();
        iteration_timer.restart();
        std::transform( population.begin() , population.end() , fitness.begin() , [&]( tree_type const &t ) { return fitness_f( t , c ); } );
        double eval_time = iteration_timer.seconds();
        
        write_height_hist( population , "height_" + std::to_string( generation ) + ".hist" );
        write_size_hist( population , "size_" + std::to_string( generation ) + ".hist" );
        
        std::cout << gpcxx::indent( 0 ) << "Generation " << generation << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Evolve time " << evolve_time << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Eval time " << eval_time << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Best individuals" << std::endl << gpcxx::best_individuals( population , fitness , 2 , 10 ) << std::endl;
        std::cout << gpcxx::indent( 1 ) << "Statistics : " << gpcxx::calc_population_statistics( population ) << std::endl << std::endl;
    }
    std::cout << "Overall time : " << timer.seconds() << std::endl;


// 	generate_data();
// 	init_constants();
// 	init_node_types();   // init generators
// 	init_population();
// 	evolve();
// 	report();

    return 0;
}
예제 #11
0
	bool FilterMatchList(const char *sift_list, const char *match_list, const char *output, size_t num_matches)
	{		
		std::vector<std::string> sift_filenames;
		tw::IO::ExtractLines(sift_list, sift_filenames);
		size_t image_num = sift_filenames.size();
		num_matches = num_matches > image_num ? image_num : num_matches;

	    std::ifstream fin(match_list);
	    if(!fin.is_open())
	    {
	        std::cout << "[FilterMatchList] Fail to open the vocabulary tree match output\n";
	        return false;
	    }
	    else 
	    {
	        std::cout << "[FilterMatchList] Read the vocabulary tree match file: " << match_list << '\n';
	    }

	    std::string line;
	    size_t index0, index1;
	    float score;
	    std::vector<std::vector<size_t> > top_matches;
	    top_matches.resize(image_num);
	    while(!fin.eof())
	    {
	    	std::getline(fin, line);
	    	if(line == "")
	    		continue;
	    	std::stringstream line_stream;
	    	line_stream << line;
	    	line_stream >> index0 >> index1 >> score;
	        if(index0 >= sift_filenames.size() || index1 >= sift_filenames.size())
	        {
	            std::cout << "[FilterMatchList] Invalid index pair: " << index0 << " " << index1 << '\n';
	            continue;
	        }
	        // find top-'num_matches' pairs
	        if(top_matches[index0].size() < num_matches && index0 != index1 && score > 0)
	        {
	        	top_matches[index0].push_back(index1);
	        }
	    }
	    fin.close();

	    std::vector<std::vector<size_t> > filtered_matches;
	    filtered_matches.resize(image_num);
	    for(size_t i = 0; i < image_num; i++)
	    {
	    	for(size_t j = 0; j < top_matches[i].size(); j++)
	    	{
	    		index0 = i; 
	    		index1 = top_matches[i][j];
	    		if(index0 > index1)
		    		std::swap(index0, index1);
	    		filtered_matches[index0].push_back(index1);
	    	}
	    }

	    // get unique match pairs
	    for(size_t i = 0; i < image_num; i++)
	    {
	    	std::sort(filtered_matches[i].begin(), filtered_matches[i].end());
	    	filtered_matches[i].erase(std::unique(filtered_matches[i].begin(), filtered_matches[i].end()), filtered_matches[i].end());
	    }

	    // write match pairs (names and indexes) to two files
	    std::string sift_index_file(output);
	    std::string sift_name_file = sift_index_file+".txt";
		std::ofstream fout(sift_name_file);				// used for match (sift filenames pairs)
		std::ofstream fout1(sift_index_file);			// used for query expansion (sift index pairs)
		if(!fout.is_open() || !fout1.is_open())
	    {
	        std::cout << "[FilterMatchList] Fail to open the filtered match file\n";
	        return false;
	    }
	    else 
	    {
	        std::cout << "[FilterMatchList] Write the filtered index file " << sift_index_file << '\n';
	    }

	    for(size_t i = 0; i < image_num; i++)
	    {
	    	for(size_t j = 0; j < filtered_matches[i].size(); j++)
	    	{
	    		fout << sift_filenames[i] << " " << sift_filenames[filtered_matches[i][j]] << '\n';
	    	}
	    } 
	    fout.close();

	    for(size_t i = 0; i < image_num; i++)
	    {
	    	for(size_t j = 0; j < top_matches[i].size(); j++)
	    	{
	    		fout1 << i << " " << top_matches[i][j] << '\n';
	    	}
	    }
	    fout1.close();

		return true;	
	}
void main(){
  string thestring = "Position";
  string txtfilename = thestring + ".txt";
  string shiftHead = "shiftParameters_";
  string residualHead = "residuals_";
  string ResidualRHead="Residual_";
  string foutname = shiftHead+thestring+"_alignTrackers.txt";
  string fout1name = residualHead+thestring+"_alignTrackers.txt";
  fstream fin(txtfilename.c_str(),ios::in);
  if(!fin){cout<<"file not read"<<endl; return;}
  fstream fout(foutname.c_str(),ios::out);
  fstream fout1(fout1name.c_str(),ios::out);
  double pREF2X=0.0, pREF2Y=0.0;
  double pREF3X=0.0, pREF3Y=0.0;
  double pUVA3X=0.0, pUVA3Y=0.0;
  double pREF1X=0.0, pREF1Y=0.0;
  //double pZZ1=0.0, pZZ2=0.0;
  double pEta5=0.0;
  vector<double> vpREF2X; vector<double> vpREF2Y;
  vector<double> vpREF3X; vector<double> vpREF3Y;
  vector<double> vpUVA3X; vector<double> vpUVA3Y;
  vector<double> vpREF1X; vector<double> vpREF1Y;
  //vector<double> vpZZ1; vector<double> vpZZ2;
 // vector<double> vpEta5;
  Int_t nbLines=0;
  while(fin>>pREF2X>>pREF2Y>>pREF3X>>pREF3Y>>pUVA3X>>pUVA3Y>>pREF1X>>pREF1Y/*>>pEta5*/){
    vpREF2X.push_back(pREF2X); vpREF2Y.push_back(pREF2Y); vpREF3X.push_back(pREF3X); vpREF3Y.push_back(pREF3Y);
    vpUVA3X.push_back(pUVA3X); vpUVA3Y.push_back(pUVA3Y); vpREF1X.push_back(pREF1X); vpREF1Y.push_back(pREF1Y);
    //vpZZ1.push_back(pZZ1); vpZZ2.push_back(pZZ2);
   // vpEta5.push_back(pEta5);
    nbLines++;
  }
  fin.close();
  /*
  REF2X:
      [-30,-20]: -22.98, 1.089, -28.29, -3.209, -37.22, 14.88, -46.62, -2.411, 29.84
      [-20,-15]: -17.07, 0.4154, -22.27, -3.92, -31.12, 14.55, -40.55, -2.637, 29.48
  */
  double shiREF2X=12.25640557, shiREF2Y=2.03531933;
  double shiREF3X=7.467908772, shiREF3Y=-2.35761;
  double shiUVA3X=-0.73056, shiUVA3Y=15.74758;
  double shiREF1X=-9.94956, shiREF1Y=-0.70242;
  //double shiZZ1=0,   shiZZ2=0;
  //double shiEta5=30.1;


  double meanREF2X=0.0, meanREF2Y=0.0;
  double meanREF3X=0.0, meanREF3Y=0.0;
  double meanUVA3X=0.0, meanUVA3Y=0.0;
  double meanREF1X=0.0, meanREF1Y=0.0;
  //double meanZZ1=0.0, meanZZ2=0.0;
  //double meanEta5=0;

  Int_t iterNb=0;
  while(1){
    char rootfile[50]; sprintf(rootfile,"_iter_%i.root",iterNb);
    string outputrootname=ResidualRHead+thestring+rootfile;
    TFile* f = new TFile(outputrootname.c_str(),"recreate");  
    iterNb++;
    char name2X[15];sprintf(name2X,"posREF2X_%i",iterNb); char name2Y[15];sprintf(name2Y,"posREF2Y_%i",iterNb);
    char name3X[15];sprintf(name3X,"posREF3X_%i",iterNb); char name3Y[15];sprintf(name3Y,"posREF3Y_%i",iterNb);
    char nameu3X[15];sprintf(nameu3X,"posUVA3X_%i",iterNb);char nameu3Y[15];sprintf(nameu3Y,"posUVA3Y_%i",iterNb);
    char name1X[15];sprintf(name1X,"posREF1X_%i",iterNb); char name1Y[15];sprintf(name1Y,"posREF1Y_%i",iterNb);
    //char nameZZ1[15];sprintf(nameZZ1,"pos10cmZZ1_%i",iterNb); char nameZZ2[15];sprintf(nameZZ2,"pos10cmZZ2_%i",iterNb);
    //char nameEta5[15];sprintf(nameEta5,"posEta5_%i",iterNb); 
    TH1F* hpREF2X = new TH1F(name2X,"",500,-50,50); hpREF2X->SetXTitle("mm"); hpREF2X->SetYTitle("Frequency");hpREF2X->SetLabelSize(0.045,"XY");hpREF2X->SetTitleSize(0.045,"XY");
    TH1F* hpREF2Y = new TH1F(name2Y,"",500,-50,50); hpREF2Y->SetXTitle("mm"); hpREF2Y->SetYTitle("Frequency");hpREF2Y->SetLabelSize(0.045,"XY");hpREF2Y->SetTitleSize(0.045,"XY");  
    TH1F* hpREF3X = new TH1F(name3X,"",500,-50,50); hpREF3X->SetXTitle("mm"); hpREF3X->SetYTitle("Frequency");hpREF3X->SetLabelSize(0.045,"XY");hpREF3X->SetTitleSize(0.045,"XY");
    TH1F* hpREF3Y = new TH1F(name3Y,"",500,-50,50); hpREF3Y->SetXTitle("mm"); hpREF3Y->SetYTitle("Frequency");hpREF3Y->SetLabelSize(0.045,"XY");hpREF3Y->SetTitleSize(0.045,"XY");  
    TH1F* hpUVA3X = new TH1F(nameu3X,"",500,-50,50); hpUVA3X->SetXTitle("mm"); hpUVA3X->SetYTitle("Frequency");hpUVA3X->SetLabelSize(0.045,"XY");hpUVA3X->SetTitleSize(0.045,"XY");
    TH1F* hpUVA3Y = new TH1F(nameu3Y,"",500,-50,50); hpUVA3Y->SetXTitle("mm"); hpUVA3Y->SetYTitle("Frequency");hpUVA3Y->SetLabelSize(0.045,"XY");hpUVA3Y->SetTitleSize(0.045,"XY");  
    TH1F* hpREF1X = new TH1F(name1X,"",500,-50,50); hpREF1X->SetXTitle("mm"); hpREF1X->SetYTitle("Frequency");hpREF1X->SetLabelSize(0.045,"XY");hpREF1X->SetTitleSize(0.045,"XY");
    TH1F* hpREF1Y = new TH1F(name1Y,"",500,-50,50); hpREF1Y->SetXTitle("mm"); hpREF1Y->SetYTitle("Frequency");hpREF1Y->SetLabelSize(0.045,"XY");hpREF1Y->SetTitleSize(0.045,"XY");  
    //TH1F* hpZZ1 = new TH1F(nameZZ1,"",600,-150,150); hpZZ1->SetXTitle("mm"); hpZZ1->SetYTitle("Frequency"); hpZZ1->SetLabelSize(0.045,"XY");hpZZ1->SetTitleSize(0.045,"XY");
    //TH1F* hpZZ2 = new TH1F(nameZZ2,"",600,-150,150); hpZZ2->SetXTitle("mm"); hpZZ2->SetYTitle("Frequency"); hpZZ2->SetLabelSize(0.045,"XY");hpZZ2->SetTitleSize(0.045,"XY");
    //TH1F* hpEta5 = new TH1F(nameEta5,"",600,-150,150); hpEta5->SetXTitle("mm"); hpEta5->SetYTitle("Frequency"); hpEta5->SetLabelSize(0.045,"XY");hpEta5->SetTitleSize(0.045,"XY");
    char nameRes2X[20];sprintf(nameRes2X,"residualREF2X_%i",iterNb);char nameRes2Y[20];sprintf(nameRes2Y,"residualREF2Y_%i",iterNb);
    char nameRes3X[20];sprintf(nameRes3X,"residualREF3X_%i",iterNb);char nameRes3Y[20];sprintf(nameRes3Y,"residualREF3Y_%i",iterNb);
    char nameResu3X[20];sprintf(nameResu3X,"residualUVA3X_%i",iterNb);char nameResu3Y[20];sprintf(nameResu3Y,"residualUVA3Y_%i",iterNb);
    char nameRes1X[20];sprintf(nameRes1X,"residualREF1X_%i",iterNb);char nameRes1Y[20];sprintf(nameRes1Y,"residualREF1Y_%i",iterNb);
    //char nameResZZ1[20];sprintf(nameResZZ1,"residualZZ1_%i",iterNb);char nameResZZ2[20];sprintf(nameResZZ2,"residualZZ2_%i",iterNb);
    //char nameResEta5[20];sprintf(nameResEta5,"residualEta5_%i",iterNb);
    TH1F* residualREF2X = new TH1F(nameRes2X,"",800,-8,8); residualREF2X->SetXTitle("Residual [mm]"); residualREF2X->SetYTitle("Frequency");residualREF2X->SetLabelSize(0.045,"XY");residualREF2X->SetTitleSize(0.045,"XY");
    TH1F* residualREF2Y = new TH1F(nameRes2Y,"",800,-8,8); residualREF2Y->SetXTitle("Residual [mm]"); residualREF2Y->SetYTitle("Frequency");residualREF2Y->SetLabelSize(0.045,"XY");residualREF2Y->SetTitleSize(0.045,"XY");
    TH1F* residualREF3X = new TH1F(nameRes3X,"",800,-8,8); residualREF3X->SetXTitle("Residual [mm]"); residualREF3X->SetYTitle("Frequency");residualREF3X->SetLabelSize(0.045,"XY");residualREF3X->SetTitleSize(0.045,"XY");
    TH1F* residualREF3Y = new TH1F(nameRes3Y,"",800,-8,8); residualREF3Y->SetXTitle("Residual [mm]"); residualREF3Y->SetYTitle("Frequency");residualREF3Y->SetLabelSize(0.045,"XY");residualREF3Y->SetTitleSize(0.045,"XY");
    TH1F* residualUVA3X = new TH1F(nameResu3X,"",800,-8,8); residualUVA3X->SetXTitle("Residual [mm]"); residualUVA3X->SetYTitle("Frequency");residualUVA3X->SetLabelSize(0.045,"XY");residualUVA3X->SetTitleSize(0.045,"XY");
    TH1F* residualUVA3Y = new TH1F(nameResu3Y,"",800,-8,8); residualUVA3Y->SetXTitle("Residual [mm]"); residualUVA3Y->SetYTitle("Frequency");residualUVA3Y->SetLabelSize(0.045,"XY");residualUVA3Y->SetTitleSize(0.045,"XY");
    TH1F* residualREF1X = new TH1F(nameRes1X,"",800,-8,8); residualREF1X->SetXTitle("mm"); residualREF1X->SetYTitle("Frequency");residualREF1X->SetLabelSize(0.045,"XY");residualREF1X->SetTitleSize(0.045,"XY");
    TH1F* residualREF1Y = new TH1F(nameRes1Y,"",800,-8,8); residualREF1Y->SetXTitle("mm"); residualREF1Y->SetYTitle("Frequency");residualREF1Y->SetLabelSize(0.045,"XY");residualREF1Y->SetTitleSize(0.045,"XY");
    //TH1F* residualZZ1 = new TH1F(nameResZZ1,"",320,-16,16); residualZZ1->SetXTitle("Residual [mm]"); residualZZ1->SetYTitle("Frequency");residualZZ1->SetLabelSize(0.045,"XY");residualZZ1->SetTitleSize(0.045,"XY");
    //TH1F* residualZZ2 = new TH1F(nameResZZ2,"",320,-16,16); residualZZ2->SetXTitle("Residual [mm]"); residualZZ2->SetYTitle("Frequency");residualZZ2->SetLabelSize(0.045,"XY");residualZZ2->SetTitleSize(0.045,"XY");
    //TH1F* residualEta5 = new TH1F(nameResEta5,"",320,-16,16); residualEta5->SetXTitle("Residual [mm]"); residualEta5->SetYTitle("Frequency");residualEta5->SetLabelSize(0.045,"XY");residualEta5->SetTitleSize(0.045,"XY");
    /*
    char nameDxREF3X[20]; sprintf(nameDxREF3X,"REF3X_REF2X_%i",iterNb); char nameDyREF3Y[20]; sprintf(nameDyREF3Y,"REF3Y_REF2Y_%i",iterNb); 
    char nameDxUVA3X[20]; sprintf(nameDxUVA3X,"UVA3X_REF2X_%i",iterNb); char nameDyUVA3Y[20]; sprintf(nameDyUVA3Y,"UVA3Y_REF2Y_%i",iterNb); 
    char nameDxREF1X[20]; sprintf(nameDxREF1X,"REF1X_REF2X_%i",iterNb); char nameDyREF1Y[20]; sprintf(nameDyREF1Y,"REF1Y_REF2Y_%i",iterNb); 
    TH1F* dxREF3X = new TH1F(nameDxREF3X,"",400,-4,4); dxREF3X->SetXTitle("Delta_X_REF3X_REF2X [mm]"); dxREF3X->SetYTitle("Frequency");dxREF3X->SetLabelSize(0.045,"XY"); dxREF3X->SetTitleSize(0.045,"XY");
    TH1F* dxUVA3X = new TH1F(nameDxUVA3X,"",400,-4,4); dxUVA3X->SetXTitle("Delta_X_UVA3X_REF2X [mm]"); dxUVA3X->SetYTitle("Frequency");dxUVA3X->SetLabelSize(0.045,"XY"); dxUVA3X->SetTitleSize(0.045,"XY");
    TH1F* dxREF1X = new TH1F(nameDxREF1X,"",400,-4,4); dxREF1X->SetXTitle("Delta_X_REF1X_REF2X [mm]"); dxREF1X->SetYTitle("Frequency");dxREF1X->SetLabelSize(0.045,"XY"); dxREF1X->SetTitleSize(0.045,"XY");
    TH1F* dyREF3Y = new TH1F(nameDyREF3Y,"",400,-4,4); dyREF3Y->SetXTitle("Delta_Y_REF3Y_REF2Y [mm]"); dyREF3Y->SetYTitle("Frequency");dyREF3Y->SetLabelSize(0.045,"XY"); dyREF3Y->SetTitleSize(0.045,"XY");
    TH1F* dyUVA3Y = new TH1F(nameDyUVA3Y,"",400,-4,4); dyUVA3Y->SetXTitle("Delta_Y_UVA3Y_REF2Y [mm]"); dyUVA3Y->SetYTitle("Frequency");dyUVA3Y->SetLabelSize(0.045,"XY"); dyUVA3Y->SetTitleSize(0.045,"XY");
    TH1F* dyREF1Y = new TH1F(nameDyREF1Y,"",400,-4,4); dyREF1Y->SetXTitle("Delta_Y_REF1Y_REF2Y [mm]"); dyREF1Y->SetYTitle("Frequency");dyREF1Y->SetLabelSize(0.045,"XY"); dyREF1Y->SetTitleSize(0.045,"XY");
    
    char nameDxUVA3REF3[20]; sprintf(nameDxUVA3REF3,"UVA3X_REF3X_%i",iterNb);
    char nameDxREF1UVA3[20]; sprintf(nameDxREF1UVA3,"REF1X_UVA3X_%i",iterNb);
    char nameDyUVA3REF3[20]; sprintf(nameDyUVA3REF3,"UVA3Y_REF3Y_%i",iterNb);
    char nameDyREF1UVA3[20]; sprintf(nameDyREF1UVA3,"REF1Y_UVA3Y_%i",iterNb);
    TH1F* dxUVA3REF3 = new TH1F(nameDxUVA3REF3,"",400,-4,4); dxUVA3REF3->SetXTitle("Delta_X_UVA3X_REF3X [mm]"); dxUVA3REF3->SetYTitle("Frequency"); dxUVA3REF3->SetLabelSize(0.045,"XY"); dxUVA3REF3->SetTitleSize(0.045,"XY");
    TH1F* dxREF1UVA3 = new TH1F(nameDxREF1UVA3,"",400,-4,4); dxREF1UVA3->SetXTitle("Delta_X_REF1X_UVA3X [mm]"); dxREF1UVA3->SetYTitle("Frequency"); dxREF1UVA3->SetLabelSize(0.045,"XY"); dxUVA3REF3->SetTitleSize(0.045,"XY");
    TH1F* dyUVA3REF3 = new TH1F(nameDyUVA3REF3,"",400,-4,4); dyUVA3REF3->SetXTitle("Delta_Y_UVA3Y_REF3Y [mm]"); dyUVA3REF3->SetYTitle("Frequency"); dyUVA3REF3->SetLabelSize(0.045,"XY"); dyUVA3REF3->SetTitleSize(0.045,"XY");
    TH1F* dyREF1UVA3 = new TH1F(nameDyREF1UVA3,"",400,-4,4); dyREF1UVA3->SetXTitle("Delta_Y_REF1Y_UVA3Y [mm]"); dyREF1UVA3->SetYTitle("Frequency"); dyREF1UVA3->SetLabelSize(0.045,"XY"); dxUVA3REF3->SetTitleSize(0.045,"XY");
    */
    //delta-y up: 200,-4,4
    //TH1F* deltayZZ = new TH1F("deltaY","",200,-4,4); deltayZZ->SetXTitle("Position difference [mm]");deltayZZ->SetYTitle("Frequency");
    //deltayZZ->SetLabelSize(0.045,"XY");deltayZZ->SetTitleSize(0.045,"XY");
    //cout<<"shift: "<<shiREF2X<<"\t"<<shiREF2Y<<"\t"<<shiREF3X<<"\t"<<shiREF3Y<<"\t"<<shiUVA3X<<"\t"<<shiUVA3Y<<"\t"<<shiREF1X<<"\t"<<shiREF1Y<<"\t"<<shiEta5<<endl;
    fout<<shiREF2X<<"\t"<<shiREF2Y<<"\t"<<shiREF3X<<"\t"<<shiREF3Y<<"\t"<<shiUVA3X<<"\t"<<shiUVA3Y<<"\t"<<shiREF1X<<"\t"<<shiREF1Y<<endl;
    int nnnn=0;
    for(Int_t i=0;i<vpREF2X.size();i++){
      vpREF2X[i] = vpREF2X[i] - shiREF2X; vpREF2Y[i] = vpREF2Y[i] - shiREF2Y;      
      vpREF3X[i] = vpREF3X[i] - shiREF3X; vpREF3Y[i] = vpREF3Y[i] - shiREF3Y;
      vpUVA3X[i] = vpUVA3X[i] - shiUVA3X; vpUVA3Y[i] = vpUVA3Y[i] - shiUVA3Y;
      vpREF1X[i] = vpREF1X[i] - shiREF1X; vpREF1Y[i] = vpREF1Y[i] - shiREF1Y;
     // vpZZ1[i] = vpZZ1[i] - shiZZ1; vpZZ2[i] = vpZZ2[i] - shiZZ2;
      //vpEta5[i] = vpEta5[i] - shiEta5; 
      hpREF2X->Fill(vpREF2X[i]); hpREF2Y->Fill(vpREF2Y[i]);
      hpREF3X->Fill(vpREF3X[i]); hpREF3Y->Fill(vpREF3Y[i]);
      hpUVA3X->Fill(vpUVA3X[i]); hpUVA3Y->Fill(vpUVA3Y[i]);
      hpREF1X->Fill(vpREF1X[i]); hpREF1Y->Fill(vpREF1Y[i]);
      //hpZZ1->Fill(vpZZ1[i]); hpZZ2->Fill(vpZZ2[i]);
     // hpEta5->Fill(vpEta5[i]); //cout<<vpEta5[i]<<endl;
      
      //dxREF3X->Fill(vpREF3X[i]-vpREF2X[i]); dyREF3Y->Fill(vpREF3Y[i]-vpREF2Y[i]);
      //dxUVA3X->Fill(vpUVA3X[i]-vpREF2X[i]); dyUVA3Y->Fill(vpUVA3Y[i]-vpREF2Y[i]);
      //dxREF1X->Fill(vpREF1X[i]-vpREF2X[i]); dyREF1Y->Fill(vpREF1Y[i]-vpREF2Y[i]);
      //dxUVA3REF3->Fill(vpUVA3X[i]-vpREF3X[i]); dyUVA3REF3->Fill(vpUVA3Y[i]-vpREF3Y[i]);
      //dxREF1UVA3->Fill(vpREF1X[i]-vpUVA3X[i]); dyREF1UVA3->Fill(vpREF1Y[i]-vpUVA3Y[i]);

      TGraph* g1 = new TGraph();
      g1->SetPoint(0,0,     vpREF2X[i]);
      g1->SetPoint(1,1143.5,vpREF3X[i]);
      g1->SetPoint(2,2686.5,vpUVA3X[i]);
      g1->SetPoint(3,3169.5,vpREF1X[i]);
      TF1* f1 = new TF1("line1","[0]+[1]*x",0,3200);
      g1->Fit("line1","Q");
      double intercept1 = f1->GetParameter(0);
      double slope1     = f1->GetParameter(1);
      double MeasuredREF2X = intercept1 + slope1*0.0;
      double MeasuredREF3X = intercept1 + slope1*1143.5;
      double MeasuredUVA3X = intercept1 + slope1*2686.5;
      double MeasuredREF1X = intercept1 + slope1*3169.5;
      residualREF2X->Fill(MeasuredREF2X-vpREF2X[i]);
      residualREF3X->Fill(MeasuredREF3X-vpREF3X[i]);
      residualUVA3X->Fill(MeasuredUVA3X-vpUVA3X[i]);
      residualREF1X->Fill(MeasuredREF1X-vpREF1X[i]);
      delete f1; delete g1;

      TGraph* g2 = new TGraph();
      g2->SetPoint(0,0,     vpREF2Y[i]);
      g2->SetPoint(1,1143.5,vpREF3Y[i]);
      // exclusive
       g2->SetPoint(2,2686.5,vpUVA3Y[i]);
       g2->SetPoint(3,3169.5,vpREF1Y[i]);
      // inclusive
      //g2->SetPoint(2,2305.5,vpZZ2[i]); //inclusive 1
      //g2->SetPoint(2,2327.5,vpZZ1[i]);  //inclusive 2
      //g2->SetPoint(3,2686.5,vpUVA3Y[i]);


      //g2->SetPoint(4,3169.5,vpREF1Y[i]);
      //g2->SetPoint(3,3169.5,vpREF1Y[i]);    
      TF1* f2 = new TF1("line2","[0]+[1]*x",0,3200);
      g2->Fit("line2","Q");
      double intercept2 = f2->GetParameter(0);
      double slope2     = f2->GetParameter(1);
      double MeasuredREF2Y = intercept2 + slope2*0.0;
      double MeasuredREF3Y = intercept2 + slope2*1143.5;
      double MeasuredUVA3Y = intercept2 + slope2*2686.5;
      double MeasuredREF1Y = intercept2 + slope2*3169.5;
      //double MeasuredZZ1  = intercept2 + slope2*2327.5;
      //double MeasuredZZ2  = intercept2 + slope2*2305.5;
      //double MeasuredEta5 = intercept2 + slope2*2011.5;
      residualREF2Y->Fill(MeasuredREF2Y-vpREF2Y[i]);
      residualREF3Y->Fill(MeasuredREF3Y-vpREF3Y[i]);
      residualUVA3Y->Fill(MeasuredUVA3Y-vpUVA3Y[i]);
      residualREF1Y->Fill(MeasuredREF1Y-vpREF1Y[i]);
      //residualZZ1->Fill(MeasuredZZ1-vpZZ1[i]);
      //residualZZ2->Fill(MeasuredZZ2-vpZZ2[i]);
      //residualEta5->Fill(MeasuredEta5-vpEta5[i]);
      //deltayZZ->Fill(vpZZ1[i]-vpZZ2[i]);
      delete f2; delete g2;
      nnnn++;
      //if(nnnn%1000==0) cout<<nnnn<<"......"<<endl;
      //if(nnnn>1000) break;
    } //for loop
    //cout<<"after for loop"<<endl;
    gStyle->SetOptFit(1111);
    
    I2GFvalues myValues;
    myValues = I2GFmainLoop(residualREF2X,1,10,1);
    meanREF2X = myValues.mean; //sigmaEta5=myValues.sigma;
    myValues = I2GFmainLoop(residualREF2Y,1,10,1);
    meanREF2Y = myValues.mean; //
    myValues = I2GFmainLoop(residualREF3X,1,10,1);
    meanREF3X = myValues.mean; //
    myValues = I2GFmainLoop(residualREF3Y,1,10,1);
    meanREF3Y = myValues.mean;
    myValues = I2GFmainLoop(residualUVA3X,1,10,1);
    meanUVA3X = myValues.mean; //
    myValues = I2GFmainLoop(residualUVA3Y,1,10,1);
    meanUVA3Y = myValues.mean;
    myValues = I2GFmainLoop(residualREF1X,1,10,1);
    meanREF1X = myValues.mean; //
    myValues = I2GFmainLoop(residualREF1Y,1,10,1);
    meanREF1Y = myValues.mean;
    /*
    double maximum = residualREF2X->GetMean();
    double rms = residualREF2X->GetRMS(1);
    double lRange = maximum - rms*0.75; 
    double hRange = maximum + rms*0.75;
    TF1* funResidualREF2X = new TF1("funResidualREF2X","gaus",lRange,hRange);funResidualREF2X->SetLineColor(kBlue); residualREF2X->Fit("funResidualREF2X","RQ");
    meanREF2X = funResidualREF2X->GetParameter(1);
    maximum = residualREF2Y->GetMean();
    rms = residualREF2Y->GetRMS(1);
    lRange = maximum - rms*0.75; hRange = maximum + rms*0.75;
    TF1* funResidualREF2Y = new TF1("funResidualREF2Y","gaus",lRange,hRange);funResidualREF2Y->SetLineColor(kBlue); residualREF2Y->Fit("funResidualREF2Y","RQ");
    meanREF2Y = funResidualREF2Y->GetParameter(1);
    maximum = residualREF3X->GetMean();
    rms = residualREF3X->GetRMS(1);
    lRange = maximum - rms*0.75; hRange = maximum + rms*0.75;
    TF1* funResidualREF3X = new TF1("funResidualREF3X","gaus",lRange,hRange);funResidualREF3X->SetLineColor(kBlue); residualREF3X->Fit("funResidualREF3X","RQ");
    meanREF3X = funResidualREF3X->GetParameter(1);
    maximum = residualREF3Y->GetMean();
    rms = residualREF3Y->GetRMS(1);
    lRange = maximum - rms*0.75; hRange = maximum + rms*0.75;
    TF1* funResidualREF3Y = new TF1("funResidualREF3Y","gaus",lRange,hRange);funResidualREF3Y->SetLineColor(kBlue); residualREF3Y->Fit("funResidualREF3Y","RQ");
    meanREF3Y = funResidualREF3Y->GetParameter(1);
    maximum = residualUVA3X->GetMean();
    rms = residualUVA3X->GetRMS(1);
    lRange = maximum - rms*0.75; hRange = maximum + rms*0.75;
    TF1* funResidualUVA3X = new TF1("funResidualUVA3X","gaus",lRange,hRange);funResidualUVA3X->SetLineColor(kBlue); residualUVA3X->Fit("funResidualUVA3X","RQ");
    meanUVA3X = funResidualUVA3X->GetParameter(1);
    maximum = residualUVA3Y->GetMean();
    rms = residualUVA3Y->GetRMS(1);
    lRange = maximum - rms*0.75; hRange = maximum + rms*0.75;
    TF1* funResidualUVA3Y = new TF1("funResidualUVA3Y","gaus",lRange,hRange);funResidualUVA3Y->SetLineColor(kBlue); residualUVA3Y->Fit("funResidualUVA3Y","RQ");
    meanUVA3Y = funResidualUVA3Y->GetParameter(1);
    maximum = residualREF1X->GetMean();
    rms = residualREF1X->GetRMS(1);
    lRange = maximum - rms*0.75; hRange = maximum + rms*0.75;
    TF1* funResidualREF1X = new TF1("funResidualREF1X","gaus",lRange,hRange);funResidualREF1X->SetLineColor(kBlue); residualREF1X->Fit("funResidualREF1X","RQ");
    meanREF1X = funResidualREF1X->GetParameter(1);
    maximum = residualREF1Y->GetMean();
    rms = residualREF1Y->GetRMS(1);
    lRange = maximum - rms*0.75; hRange = maximum + rms*0.75;
    TF1* funResidualREF1Y = new TF1("funResidualREF1Y","gaus",lRange,hRange);funResidualREF1Y->SetLineColor(kBlue); residualREF1Y->Fit("funResidualREF1Y","RQ");
    meanREF1Y = funResidualREF1Y->GetParameter(1);
    //maximum = residualEta5->GetMean();
    maximum=residualEta5->GetXaxis()->GetBinCenter(residualEta5->GetMaximumBin());
    rms = residualEta5->GetRMS(1);
    lRange = maximum - rms*0.15; hRange = maximum + rms*0.15;
    TF1* funResidualEta5 = new TF1("funResidualEta5","gaus",lRange,hRange);funResidualEta5->SetLineColor(kBlue); residualEta5->Fit("funResidualEta5","RQ");
    meanEta5 = funResidualEta5->GetParameter(1);
    */
    //maximum = residualZZ1->GetMean();
    /*
    maximum = residualZZ1->GetXaxis()->GetBinCenter(residualZZ1->GetMaximumBin());//cout<<"...."<<maximum<<"...";
    rms = residualZZ1->GetRMS(1);
    lRange = maximum - rms*0.1; hRange = maximum + rms*0.1;
    TF1* funResidualZZ1 = new TF1("funResidualZZ1","gaus",lRange,hRange);funResidualZZ1->SetLineColor(kBlue); residualZZ1->Fit("funResidualZZ1","RQ");
    meanZZ1 = funResidualZZ1->GetParameter(1);
    maximum = residualZZ2->GetXaxis()->GetBinCenter(residualZZ2->GetMaximumBin());//cout<<"...."<<maximum<<"..."<<endl;
    //maximum = residualZZ2->GetMean();
    rms = residualZZ2->GetRMS(1);
    lRange = maximum - rms*0.1; hRange = maximum + rms*0.1;//1.4
    TF1* funResidualZZ2 = new TF1("funResidualZZ2","gaus",lRange,hRange);funResidualZZ2->SetLineColor(kBlue); residualZZ2->Fit("funResidualZZ2","RQ");
    meanZZ2 = funResidualZZ2->GetParameter(1);
    maximum = deltayZZ->GetMean();
    rms = deltayZZ->GetRMS(1);
    lRange = maximum - rms*1.4; hRange = maximum + rms*1.4;//1.4
    TF1* funDeltaYZZ = new TF1("funDeltaYZZ","gaus",lRange,hRange);funDeltaYZZ->SetLineColor(kBlue); deltayZZ->Fit("funDeltaYZZ","RQ");
    */
    cout<<"residual mean: "<<meanREF2X<<"\t"<<meanREF2Y<<"\t"<<meanREF3X<<"\t"<<meanREF3Y<<"\t"<<meanUVA3X<<"\t"<<meanUVA3Y<<"\t"<<meanREF1X<<"\t"<<meanREF1Y<<endl;
        //<<meanZZ1<<"\t"<<meanZZ2<<endl;
    fout1<<"residual mean: "<<meanREF2X<<"\t"<<meanREF2Y<<"\t"<<meanREF3X<<"\t"<<meanREF3Y<<"\t"<<meanUVA3X<<"\t"<<meanUVA3Y<<"\t"<<meanREF1X<<"\t"<<meanREF1Y<<endl;
        //<<meanZZ1<<"\t"<<meanZZ2<<endl;
    /*    
    maximum = dxREF3X->GetMean(); rms=dxREF3X->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.10*rms;
    TF1* funDxREF3X=new TF1("funDxREF3X","gaus",lRange,hRange); funDxREF3X->SetLineColor(kBlue); dxREF3X->Fit("funDxREF3X","RQ");
    maximum = dxUVA3X->GetMean(); rms=dxUVA3X->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.10*rms;
    TF1* funDxUVA3X=new TF1("funDxUVA3X","gaus",lRange,hRange); funDxUVA3X->SetLineColor(kBlue); dxUVA3X->Fit("funDxUVA3X","RQ");
    maximum = dxREF1X->GetMean(); rms=dxREF1X->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.10*rms;
    TF1* funDxREF1X=new TF1("funDxREF1X","gaus",lRange,hRange); funDxREF1X->SetLineColor(kBlue); dxREF1X->Fit("funDxREF1X","RQ");
    maximum = dyREF3Y->GetMean(); rms=dyREF3Y->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.10*rms;
    TF1* funDyREF3Y=new TF1("funDyREF3Y","gaus",lRange,hRange); funDyREF3Y->SetLineColor(kBlue); dyREF3Y->Fit("funDyREF3Y","RQ");
    maximum = dyUVA3Y->GetMean(); rms=dyUVA3Y->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.10*rms;
    TF1* funDyUVA3Y=new TF1("funDyUVA3Y","gaus",lRange,hRange); funDyUVA3Y->SetLineColor(kBlue); dyUVA3Y->Fit("funDyUVA3Y","RQ");
    maximum = dyREF1Y->GetMean(); rms=dyREF1Y->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.10*rms;
    TF1* funDyREF1Y=new TF1("funDyREF1Y","gaus",lRange,hRange); funDyREF1Y->SetLineColor(kBlue); dyREF1Y->Fit("funDyREF1Y","RQ");
    maximum = dxUVA3REF3->GetMean(); rms=dxUVA3REF3->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.1*rms;
    TF1* funDxUVA3REF3=new TF1("funDxUVA3REF3","gaus",lRange,hRange); funDxUVA3REF3->SetLineColor(kBlue); dxUVA3REF3->Fit("funDxUVA3REF3","RQ");
    maximum = dxREF1UVA3->GetMean(); rms=dxREF1UVA3->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.1*rms;
    TF1* funDxREF1UVA3=new TF1("funDxREF1UVA3","gaus",lRange,hRange); funDxREF1UVA3->SetLineColor(kBlue); dxREF1UVA3->Fit("funDxREF1UVA3","RQ");
    maximum = dyUVA3REF3->GetMean(); rms=dyUVA3REF3->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.1*rms;
    TF1* funDyUVA3REF3=new TF1("funDyUVA3REF3","gaus",lRange,hRange); funDyUVA3REF3->SetLineColor(kBlue); dyUVA3REF3->Fit("funDyUVA3REF3","RQ");
    maximum = dyREF1UVA3->GetMean(); rms=dyREF1UVA3->GetRMS(1); lRange=maximum-rms*1.1; hRange=maximum+1.1*rms;
    TF1* funDyREF1UVA3=new TF1("funDyREF1UVA3","gaus",lRange,hRange); funDyREF1UVA3->SetLineColor(kBlue); dyREF1UVA3->Fit("funDyREF1UVA3","RQ");
    */
    f->Write();
    f->Close();
    //delete funPosEta5; delete funPosREF1Y; delete funPosUVA3Y; delete funPosREF3Y; delete funPosREF2Y;
    //delete funResidualREF2X; delete funResidualREF2Y; delete funResidualREF3X; delete funResidualREF3Y;  
    //delete funResidualUVA3X; delete funResidualUVA3Y; delete funResidualREF1X; delete funResidualREF1Y; delete funResidualEta5; //delete funResidualZZ1;delete funResidualZZ2;
    //delete funDxREF3X; delete funDxUVA3X; delete funDxREF1X; delete funDyREF3Y; delete funDyUVA3Y; delete funDyREF1Y; 
    //delete funDxUVA3REF3; delete funDxREF1UVA3; delete funDyUVA3REF3; delete funDyREF1UVA3;
    double factor = -0.1;
    shiREF2X = meanREF2X*factor; shiREF2Y = meanREF2Y*factor; 
    shiREF3X = meanREF3X*factor; shiREF3Y = meanREF3Y*factor; 
    shiUVA3X = meanUVA3X*factor; shiUVA3Y = meanUVA3Y*factor; 
    shiREF1X = meanREF1X*factor; shiREF1Y = meanREF1Y*factor; 
    //shiZZ1 = meanZZ1*factor; shiZZ2 = meanZZ2*factor; 
    //shiEta5 = meanEta5*factor;

    //break;
    if((meanREF2X>=-0.0005 && meanREF2X<=0.0005) && (meanREF2Y>=-0.0005 && meanREF2Y<=0.0005))
      if((meanREF3X>=-0.0005 && meanREF3X<=0.0005) && (meanREF3Y>=-0.0005 && meanREF3Y<=0.0005))
        if((meanUVA3X>=-0.0005 && meanUVA3X<=0.0005) && (meanUVA3Y>=-0.0005 && meanUVA3Y<=0.0005))
        	if((meanREF1X>=-0.0005 && meanREF1X<=0.0005) && (meanREF1Y>=-0.0005 && meanREF1Y<=0.0005))
          {
            cout<<"find it...iterating "<<iterNb<<" times."<<endl;
            break;
          }
    if(iterNb>500) break;
 }//while(1)
 fout.close();
 fout1.close();
} // entire script
예제 #13
0
int main(int argc, char **argv)
{
    const bool release(argc >= 2 && std::string(argv[1]) == "--release");

    // Get files..
    std::vector<std::string> libfiles;
    getCppFiles(libfiles, "lib/", false);

    std::vector<std::string> extfiles;
    extfiles.push_back("externals/simplecpp/simplecpp.cpp");
    extfiles.push_back("externals/tinyxml/tinyxml2.cpp");

    std::vector<std::string> clifiles;
    getCppFiles(clifiles, "cli/", false);

    std::vector<std::string> testfiles;
    getCppFiles(testfiles, "test/", false);

    std::vector<std::string> toolsfiles;
    getCppFiles(toolsfiles, "tools/", false);

    if (libfiles.empty() && clifiles.empty() && testfiles.empty()) {
        std::cerr << "No files found. Are you in the correct directory?" << std::endl;
        return EXIT_FAILURE;
    }

    // QMAKE - lib/lib.pri
    {
        std::ofstream fout1("lib/lib.pri");
        if (fout1.is_open()) {
            fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
            fout1 << "include($$PWD/pcrerules.pri)\n";
            fout1 << "include($$PWD/../externals/externals.pri)\n";
            fout1 << "INCLUDEPATH += $$PWD\n";
            fout1 << "HEADERS += $${PWD}/check.h \\\n";
            for (unsigned int i = 0; i < libfiles.size(); ++i) {
                std::string fname(libfiles[i].substr(4));
                if (fname.find(".cpp") == std::string::npos)
                    continue;   // shouldn't happen
                fname.erase(fname.find(".cpp"));
                fout1 << std::string(11, ' ') << "$${PWD}/" << fname << ".h";
                if (i + 1 < testfiles.size())
                    fout1 << " \\\n";
            }
            fout1 << "\n\nSOURCES += ";
            for (unsigned int i = 0; i < libfiles.size(); ++i) {
                fout1 << "$${PWD}/" << libfiles[i].substr(4);
                if (i < libfiles.size() - 1)
                    fout1 << " \\\n" << std::string(11, ' ');
            }
            fout1 << "\n";
        }
    }

    // QMAKE - test/testfiles.pri
    {
        std::ofstream fout1("test/testfiles.pri");
        if (fout1.is_open()) {
            fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
            fout1 << "INCLUDEPATH += ../externals/tinyxml\n";
            fout1 << "\n\nSOURCES += ";
            for (unsigned int i = 0; i < testfiles.size(); ++i) {
                const std::string filename(testfiles[i].substr(5));
                // Include only files containing tests in this listing.
                // I.e. filenames beginning with "test".
                if (filename.compare(0, 4, "test") == 0) {
                    fout1 << "$${BASEPATH}/" << filename;
                    if (i + 1 < testfiles.size())
                        fout1 << " \\\n" << std::string(11, ' ');
                }
            }
            fout1 << "\n";
        }
    }

    static const char makefile[] = "Makefile";
    std::ofstream fout(makefile, std::ios_base::trunc);
    if (!fout.is_open()) {
        std::cerr << "An error occurred while trying to open "
                  << makefile
                  << ".\n";
        return EXIT_FAILURE;
    }

    fout << "# This file is generated by tools/dmake, do not edit.\n\n";
    fout << "# To compile with rules, use 'make HAVE_RULES=yes'\n";
    makeConditionalVariable(fout, "HAVE_RULES", "no");

    // compiled patterns..
    fout << "# folder where lib/*.cpp files are located\n";
    makeConditionalVariable(fout, "SRCDIR", "lib");
    fout << "ifeq ($(SRCDIR),build)\n"
         << "    ifdef VERIFY\n"
         << "        matchcompiler_S := $(shell python tools/matchcompiler.py --verify)\n"
         << "    else\n"
         << "        matchcompiler_S := $(shell python tools/matchcompiler.py)\n"
         << "    endif\n"
         << "endif\n\n";

    // explicit cfg dir..
    fout << "ifdef CFGDIR\n"
         << "    CFG=-DCFGDIR=\\\"$(CFGDIR)\\\"\n"
         << "else\n"
         << "    CFG=\n"
         << "endif\n\n";

    // enable backtrac
    fout << "RDYNAMIC=-rdynamic\n";

    // The _GLIBCXX_DEBUG doesn't work in cygwin or other Win32 systems.
    fout << "# Set the CPPCHK_GLIBCXX_DEBUG flag. This flag is not used in release Makefiles.\n"
         << "# The _GLIBCXX_DEBUG define doesn't work in Cygwin or other Win32 systems.\n"
         << "ifndef COMSPEC\n"
         << "    ifdef ComSpec\n"
         << "        #### ComSpec is defined on some WIN32's.\n"
         << "        COMSPEC=$(ComSpec)\n"
         << "    endif # ComSpec\n"
         << "endif # COMSPEC\n"
         << "\n"
         << "ifdef COMSPEC\n"
         << "    #### Maybe Windows\n"
         << "    ifndef CPPCHK_GLIBCXX_DEBUG\n"
         << "        CPPCHK_GLIBCXX_DEBUG=\n"
         << "    endif # !CPPCHK_GLIBCXX_DEBUG\n"
         << "\n"
         << "    ifeq ($(MSYSTEM),MINGW32)\n"
         << "        LDFLAGS=-lshlwapi\n"
         << "    else\n"
         << "        RDYNAMIC=-lshlwapi\n"
         << "    endif\n"
         << "else # !COMSPEC\n"
         << "    uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')\n"
         << "\n"
         << "    ifeq ($(uname_S),Linux)\n"
         << "        ifndef CPPCHK_GLIBCXX_DEBUG\n"
         << "            CPPCHK_GLIBCXX_DEBUG=-D_GLIBCXX_DEBUG\n"
         << "        endif # !CPPCHK_GLIBCXX_DEBUG\n"
         << "    endif # Linux\n"
         << "\n"
         << "    ifeq ($(uname_S),GNU/kFreeBSD)\n"
         << "        ifndef CPPCHK_GLIBCXX_DEBUG\n"
         << "            CPPCHK_GLIBCXX_DEBUG=-D_GLIBCXX_DEBUG\n"
         << "        endif # !CPPCHK_GLIBCXX_DEBUG\n"
         << "    endif # GNU/kFreeBSD\n"
         << "\n"
         << "endif # COMSPEC\n"
         << "\n";

    // tinymxl2 requires __STRICT_ANSI__ to be undefined to compile under CYGWIN.
    fout << "# Set the UNDEF_STRICT_ANSI flag to address compile time warnings\n"
         << "# with tinyxml2 and Cygwin.\n"
         << "ifdef COMSPEC\n"
         << "    uname_S := $(shell uname -s)\n"
         << "\n"
         << "    ifneq (,$(findstring CYGWIN,$(uname_S)))\n"
         << "        UNDEF_STRICT_ANSI=-U__STRICT_ANSI__\n"
         << "    endif # CYGWIN\n"
         << "endif # COMSPEC\n"
         << "\n";

    // skip "-D_GLIBCXX_DEBUG" if clang, since it breaks the build
    makeConditionalVariable(fout, "CXX", "g++");
    fout << "ifeq ($(CXX), clang++)\n"
         << "    CPPCHK_GLIBCXX_DEBUG=\n"
         << "endif\n";

    // Makefile settings..
    if (release) {
        makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -include lib/cxx11emu.h -DNDEBUG -Wall -Wno-sign-compare");
    } else {
        // TODO: add more compiler warnings.
        // -Wlogical-op       : doesn't work on older GCC
        // -Wsign-conversion  : too many warnings
        // -Wunreachable-code : some GCC versions report lots of warnings
        makeConditionalVariable(fout, "CXXFLAGS",
                                "-include lib/cxx11emu.h "
                                "-pedantic "
                                "-Wall "
                                "-Wextra "
                                "-Wabi "
                                "-Wcast-qual "
//                                "-Wconversion "  // danmar: gives fp. for instance: unsigned int sizeof_pointer = sizeof(void *);
                                "-Wfloat-equal "
                                "-Winline "
//                                "-Wlogical-op "
                                "-Wmissing-declarations "
                                "-Wmissing-format-attribute "
                                "-Wno-long-long "
//                                "-Woverloaded-virtual "  // danmar: we get fp when overloading analyseWholeProgram()
                                "-Wpacked "
                                "-Wredundant-decls "
                                "-Wshadow "
//                                "-Wsign-conversion "
//                                "-Wsign-promo "
                                "-Wno-missing-field-initializers "
                                "-Wno-missing-braces "
//                                "-Wunreachable-code "
                                "-Wno-sign-compare "  // danmar: I don't like this warning, it's very rarelly a bug
                                "-Wno-multichar "
                                "$(CPPCHK_GLIBCXX_DEBUG) "
                                "-g");
    }

    fout << "ifeq ($(CXX), g++)\n"
         << "    override CXXFLAGS += -std=c++0x\n"
         << "else ifeq ($(CXX), clang++)\n"
         << "    override CXXFLAGS += -std=c++0x\n"
         << "else ifeq ($(CXX), c++)\n"
         << "    ifeq ($(shell uname -s), Darwin)\n"
         << "        override CXXFLAGS += -std=c++0x\n"
         << "    endif\n"
         << "endif\n"
         << "\n";

    fout << "ifeq ($(HAVE_RULES),yes)\n"
         << "    override CXXFLAGS += -DHAVE_RULES -DTIXML_USE_STL $(shell pcre-config --cflags)\n"
         << "    ifdef LIBS\n"
         << "        LIBS += $(shell pcre-config --libs)\n"
         << "    else\n"
         << "        LIBS=$(shell pcre-config --libs)\n"
         << "    endif\n"
         << "endif\n\n";

    makeConditionalVariable(fout, "PREFIX", "/usr");
    makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -Iexternals/simplecpp -Iexternals/tinyxml");
    makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -Iexternals/simplecpp -Iexternals/tinyxml");
    makeConditionalVariable(fout, "INCLUDE_FOR_TEST", "-Ilib -Icli -Iexternals/simplecpp -Iexternals/tinyxml");

    fout << "BIN=$(DESTDIR)$(PREFIX)/bin\n\n";
    fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml on Linux\n";
    fout << "DB2MAN?=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl\n";
    fout << "XP=xsltproc -''-nonet -''-param man.charmap.use.subset \"0\"\n";
    fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";

    fout << "\n###### Object Files\n\n";
    fout << "LIBOBJ =      " << objfile(libfiles[0]);
    for (size_t i = 1; i < libfiles.size(); ++i)
        fout << " \\\n" << std::string(14, ' ') << objfile(libfiles[i]);
    fout << "\n\n";
    fout << "EXTOBJ =      " << objfile(extfiles[0]);
    for (size_t i = 1; i < extfiles.size(); ++i)
        fout << " \\\n" << std::string(14, ' ') << objfile(extfiles[i]);
    fout << "\n\n";
    fout << "CLIOBJ =      " << objfile(clifiles[0]);
    for (size_t i = 1; i < clifiles.size(); ++i)
        fout << " \\\n" << std::string(14, ' ') << objfile(clifiles[i]);
    fout << "\n\n";
    fout << "TESTOBJ =     " << objfile(testfiles[0]);
    for (size_t i = 1; i < testfiles.size(); ++i)
        fout << " \\\n" << std::string(14, ' ') << objfile(testfiles[i]);
    fout << "\n\n";

    fout << ".PHONY: run-dmake\n\n";
    fout << "\n###### Targets\n\n";
    fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
    fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
    fout << "all:\tcppcheck testrunner\n\n";
    fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/pathmatch.o\n";
    fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cppcheckexecutor.o cli/cmdlineparser.o cli/filelister.o cli/pathmatch.o $(EXTOBJ) $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
    fout << "test:\tall\n";
    fout << "\t./testrunner\n\n";
    fout << "check:\tall\n";
    fout << "\t./testrunner -g -q\n\n";
    fout << "checkcfg:\tcppcheck\n";
    fout << "\t./test/cfg/runtests.sh\n\n";
    fout << "dmake:\ttools/dmake.o cli/filelister.o cli/pathmatch.o lib/path.o\n";
    fout << "\t$(CXX) $(CXXFLAGS) -o dmake tools/dmake.o cli/filelister.o cli/pathmatch.o lib/path.o -Ilib $(LDFLAGS)\n\n";
    fout << "run-dmake: dmake\n";
    fout << "\t./dmake\n\n";
    fout << "reduce:\ttools/reduce.o $(LIBOBJ) $(EXTOBJ)\n";
    fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -g -o reduce tools/reduce.o $(INCLUDE_FOR_LIB) $(LIBOBJ) $(LIBS) $(EXTOBJ) $(LDFLAGS) $(RDYNAMIC)\n\n";
    fout << "clean:\n";
    fout << "\trm -f build/*.o lib/*.o cli/*.o test/*.o tools/*.o externals/*/*.o testrunner reduce dmake cppcheck cppcheck.1\n\n";
    fout << "man:\tman/cppcheck.1\n\n";
    fout << "man/cppcheck.1:\t$(MAN_SOURCE)\n\n";
    fout << "\t$(XP) $(DB2MAN) $(MAN_SOURCE)\n\n";
    fout << "tags:\n";
    fout << "\tctags -R --exclude=doxyoutput --exclude=test/cfg cli externals gui lib test\n\n";
    fout << "install: cppcheck\n";
    fout << "\tinstall -d ${BIN}\n";
    fout << "\tinstall cppcheck ${BIN}\n";
    fout << "\tinstall addons/*.py ${BIN}\n";
    fout << "\tinstall addons/*/*.py ${BIN}\n";
    fout << "\tinstall htmlreport/cppcheck-htmlreport ${BIN}\n";
    fout << "ifdef CFGDIR \n";
    fout << "\tinstall -d ${DESTDIR}${CFGDIR}\n";
    fout << "\tinstall -m 644 cfg/* ${DESTDIR}${CFGDIR}\n";
    fout << "endif\n\n";

    fout << "\n###### Build\n\n";

    compilefiles(fout, libfiles, "${INCLUDE_FOR_LIB}");
    compilefiles(fout, clifiles, "${INCLUDE_FOR_CLI}");
    compilefiles(fout, testfiles, "${INCLUDE_FOR_TEST}");
    compilefiles(fout, extfiles, "");
    compilefiles(fout, toolsfiles, "${INCLUDE_FOR_LIB}");

    return 0;
}
예제 #14
0
void CProteinInference::_Score_Normalization(
		const map<string, vector<SPECTRAINFO> > & HaveToInterData_peptide_spec)
{
	map<string, vector<SPECTRAINFO> > peptide_spec = HaveToInterData_peptide_spec;
	/*同一个肽段,可能来自不同的引擎,可能来自同一个引擎
	 *
	 */
	double Max[20] =
	{ -1.0e100, -1.0e100, -1.0e100, -1.0e100, -1.0e100, -1.0e100, -1.0e100, -1.0e100, -1.0e100,
			-1.0e100, -1.0e100, -1.0e100, -1.0e100, -1.0e100, -1.0e100 };
	double Min[20] =
	{ 1.0e100, 1.0e100, 1.0e100, 1.0e100, 1.0e100, 1.0e100, 1.0e100, 1.0e100, 1.0e100, 1.0e100,
			1.0e100, 1.0e100, 1.0e100, 1.0e100, 1.0e100 };

	map<string, vector<pair<double, int> > > Peptide_Score_Engine;//记录某个肽段在各个搜索引擎下的分数

	for (map<string, vector<SPECTRAINFO> >::iterator it = peptide_spec.begin(); it
			!= peptide_spec.end(); it++)
	{
		vector<pair<double, int> > vectorTemp;
		for (size_t t = 0; t < it->second.size(); t++)
		{
			CMatchSpectraInfo SpectraTemp;
			ReadSingeSpectraFisrtPep(it->second[t].first, SpectraTemp);
			pair<double, int> pairTemp;
			pairTemp.first = SpectraTemp.m_vPeptides[0].m_vlfScores[0];
			pairTemp.second = SpectraTemp.m_nDataSetID;
			if (pairTemp.first > Max[pairTemp.second])
				Max[pairTemp.second] = pairTemp.first;
			if (pairTemp.first < Min[pairTemp.second])
				Min[pairTemp.second] = pairTemp.first;
			vectorTemp.push_back(pairTemp);
		}
		Peptide_Score_Engine[it->first] = vectorTemp;
	}

	double sum[20] =
	{ 0 };
	for (map<string, vector<pair<double, int> > >::iterator it = Peptide_Score_Engine.begin(); it
			!= Peptide_Score_Engine.end(); it++)
	{
		for (size_t t = 0; t < it->second.size(); t++)
		{
			double tmp = (it->second[t].first - Min[it->second[t].second])
					/ (Max[it->second[t].second] - Min[it->second[t].second]);
			sum[it->second[t].second] += tmp;
			it->second[t].first = tmp;
		}
	}

	for (map<string, vector<pair<double, int> > >::iterator it = Peptide_Score_Engine.begin(); it
			!= Peptide_Score_Engine.end(); it++)
	{
		for (size_t t = 0; t < it->second.size(); t++)
		{
			it->second[t].first = it->second[t].first / sum[it->second[t].second];
		}
	}

	for (map<string, vector<pair<double, int> > >::iterator it = Peptide_Score_Engine.begin(); it
			!= Peptide_Score_Engine.end(); it++)
	{
		double score = 1.0;
		for (size_t t = 0; t < it->second.size(); t++)
		{
			score *= it->second[t].first;
		}
		score = pow(score, 1.0 / it->second.size());

		peptide_score[it->first] = score;

		/*这里的公式还得再讨论,暂时参考
		 *  Improving sensitivity in proteome studies by analysis of false discovery rates for multiple search engines
		 */
	}

	double max = -1.0e100, min = 1.0e100;
	for (map<string, double>::iterator it = peptide_score.begin(); it != peptide_score.end(); it++)
	{
		if (it->second > max)
			max = it->second;
		if (it->second < min)
			min = it->second;
	}

	ofstream fout1("peptide_score1.txt");
	double sum_2 = 0;
	for (map<string, double>::iterator it = peptide_score.begin(); it != peptide_score.end(); it++)
	{
		fout1 << it->first << " " << it->second << endl;
		if (it->second > 0.1)
			fout1 << endl;
		sum_2 += it->second;
	}
	fout1 << sum_2 << " " << sum_2 / peptide_score.size() << endl;
	fout1.close();

	double sum_score = 0.0;
	for (map<string, double>::iterator it = peptide_score.begin(); it != peptide_score.end(); it++)
	{
		it->second = (it->second - min) / (max - min);
		sum_score += it->second;
	}

	for (map<string, double>::iterator it = peptide_score.begin(); it != peptide_score.end(); it++)
	{
		it->second /= sum_score;
	}
	ofstream fout("peptide_score.txt");
	double sum_1 = 0;
	for (map<string, double>::iterator it = peptide_score.begin(); it != peptide_score.end(); it++)
	{
		fout << it->first << " " << it->second << endl;
		if (it->second > 0.1)
			fout << endl;
		sum_1 += it->second;
	}
	fout << sum_1 << " " << sum_1 / peptide_score.size() << endl;
	fout.close();
}
void tracking(string thestring){
  //string thestring = "Position_REF2X_42_48";
  string txtfilename = thestring + ".txt";
  string shiftHead = "RotationBack_shiftParameters_";
  string rotateHead = "RotationBack_angles_";
  string residualHead = "RotationBack_residuals_";
  string ResidualRHead="RotationBack_Residual_";
  string chi2Head = "ResolutionChi2Angle_";
  string foutname = shiftHead+thestring+"_exclusive.txt";
  string fout1name = residualHead+thestring+"_exclusive.txt";
  string foutchi2name = chi2Head + thestring + "_exclusive.txt";
  string foutRotationName = rotateHead + thestring + "_exclusive.txt";
  fstream fin(txtfilename.c_str(),ios::in);
  if(!fin){cout<<"file not read"<<endl; return;}
  else cout<<"processing "<<txtfilename<<endl;
  fstream fout(foutname.c_str(),ios::out);
  fstream fout1(fout1name.c_str(),ios::out);
  fstream fout2(foutRotationName.c_str(),ios::out);
  fstream fout3(foutchi2name.c_str(),ios::out|ios::app);
  double pREF2X=0.0, pREF2Y=0.0;
  double pREF3X=0.0, pREF3Y=0.0;
  double pUVA3X=0.0, pUVA3Y=0.0;
  double pREF1X=0.0, pREF1Y=0.0;
  //double pZZ1=0.0, pZZ2=0.0;
  //double pEta5=0.0;
  vector<double> vpREF2X; vector<double> vpREF2Y;
  vector<double> vpREF3X; vector<double> vpREF3Y;
  vector<double> vpUVA3X; vector<double> vpUVA3Y;
  vector<double> vpREF1X; vector<double> vpREF1Y;
  //vector<double> vpZZ1; vector<double> vpZZ2;
  //vector<double> vpEta5;
  Int_t nbLines=0;
  while(fin>>pREF2X>>pREF2Y>>pREF3X>>pREF3Y>>pUVA3X>>pUVA3Y>>pREF1X>>pREF1Y/*>>pEta5*/){
    vpREF2X.push_back(pREF2X); vpREF2Y.push_back(pREF2Y); vpREF3X.push_back(pREF3X); vpREF3Y.push_back(pREF3Y);
    vpUVA3X.push_back(pUVA3X); vpUVA3Y.push_back(pUVA3Y); vpREF1X.push_back(pREF1X); vpREF1Y.push_back(pREF1Y);
    //vpZZ1.push_back(pZZ1); vpZZ2.push_back(pZZ2);
    //vpEta5.push_back(pEta5);
    nbLines++;
  }
  fin.close();
  /*
  REF2X:
      [-30,-20]: -22.98, 1.089, -28.29, -3.209, -37.22, 14.88, -46.62, -2.411, 29.84
      [-20,-15]: -17.07, 0.4154, -22.27, -3.92, -31.12, 14.55, -40.55, -2.637, 29.48
  */
  /* coarse alignment parameters
  double shiREF2X=10.72, shiREF2Y=1.048;
  double shiREF3X=6.162, shiREF3Y=-3.395;
  double shiUVA3X=-1.489, shiUVA3Y=15.05;
  double shiREF1X=-10.46, shiREF1Y=-1.496;
  //double shiZZ1=0,   shiZZ2=0;
  double shiEta5=29.5;
 */
 //fine alignment parameters
 /*
  double shiREF2X=3.656, shiREF2Y=1.865;
  double shiREF3X=-1.781, shiREF3Y=-2.415;
  double shiUVA3X=-8.389, shiUVA3Y=15.779;
  double shiREF1X=-17.504, shiREF1Y=-0.844;
  double aREF3REF2=0.009499;
  double aUVA3REF2=-0.004731;
  double aREF1REF2=-0.02473;
  */
  
  double shiREF2X=12.26791212, shiREF2Y=2.02708225;
  double shiREF3X=7.4824985, shiREF3Y=-2.35562;
  double shiUVA3X=-0.7097, shiUVA3Y=15.75778;
  double shiREF1X=-9.92822, shiREF1Y=-0.68756;
  double shiEta5=29.47;
  double aREF3REF2=-0.02;//0.0037;//0.01254602;//start angle: 0.01197;
  double aUVA3REF2=-0.004971;//-0.017;//0.00203396;//0.02807;//start angle: 0.01102
  double aREF1REF2=-0.02446;//-0.0486;//-0.0171;//start angle: 0.008273;
  
  //double aEta5REF2;
  double tempREF2X, tempREF2Y, tempREF3X, tempREF3Y, tempUVA3X, tempUVA3Y, tempREF1X, tempREF1Y, tempEta5;

  double meanREF2X=0.0, meanREF2Y=0.0;
  double meanREF3X=0.0, meanREF3Y=0.0;
  double meanUVA3X=0.0, meanUVA3Y=0.0;
  double meanREF1X=0.0, meanREF1Y=0.0;
  //double meanZZ1=0.0, meanZZ2=0.0;
  //double meanEta5=0;
  double meanAngleREF3=0.0;
  double meanAngleUVA3=0.0;
  double meanAngleREF1=0.0;
  //double meanAngleEta5=0.0;
  double sigmaREF2X=0.0,sigmaREF2Y=0.0,sigmaREF3X=0.0,sigmaREF3Y=0.0,sigmaUVA3X=0.0,sigmaUVA3Y=0.0,sigmaREF1X=0.0,sigmaREF1Y=0.0;
  double totalAngleREF3=0.0, totalAngleUVA3=0.0, totalAngleREF1=0.0;
  double meanXChi2=0.0,meanYChi2=0.0; // chi square for tracks.

  Int_t iterNb=0;
  while(1){
    char rootfile[50]; sprintf(rootfile,"_iter%i_exclusive.root",iterNb);
    string outputrootname=ResidualRHead+thestring+rootfile;
    TFile* f = new TFile(outputrootname.c_str(),"recreate");
    iterNb++;
    char name2X[15];sprintf(name2X,"posREF2X_%i",iterNb); char name2Y[15];sprintf(name2Y,"posREF2Y_%i",iterNb);
    char name3X[15];sprintf(name3X,"posREF3X_%i",iterNb); char name3Y[15];sprintf(name3Y,"posREF3Y_%i",iterNb);
    char nameu3X[15];sprintf(nameu3X,"posUVA3X_%i",iterNb);char nameu3Y[15];sprintf(nameu3Y,"posUVA3Y_%i",iterNb);
    char name1X[15];sprintf(name1X,"posREF1X_%i",iterNb); char name1Y[15];sprintf(name1Y,"posREF1Y_%i",iterNb);
    //char nameZZ1[15];sprintf(nameZZ1,"pos10cmZZ1_%i",iterNb); char nameZZ2[15];sprintf(nameZZ2,"pos10cmZZ2_%i",iterNb);
    //char nameEta5[15];sprintf(nameEta5,"posEta5_%i",iterNb); 
    TH1F* hpREF2X = new TH1F(name2X,"",500,-50,50); hpREF2X->SetXTitle("mm"); hpREF2X->SetYTitle("Frequency");hpREF2X->SetLabelSize(0.045,"XY");hpREF2X->SetTitleSize(0.045,"XY");
    TH1F* hpREF2Y = new TH1F(name2Y,"",500,-50,50); hpREF2Y->SetXTitle("mm"); hpREF2Y->SetYTitle("Frequency");hpREF2Y->SetLabelSize(0.045,"XY");hpREF2Y->SetTitleSize(0.045,"XY");  
    TH1F* hpREF3X = new TH1F(name3X,"",500,-50,50); hpREF3X->SetXTitle("mm"); hpREF3X->SetYTitle("Frequency");hpREF3X->SetLabelSize(0.045,"XY");hpREF3X->SetTitleSize(0.045,"XY");
    TH1F* hpREF3Y = new TH1F(name3Y,"",500,-50,50); hpREF3Y->SetXTitle("mm"); hpREF3Y->SetYTitle("Frequency");hpREF3Y->SetLabelSize(0.045,"XY");hpREF3Y->SetTitleSize(0.045,"XY");  
    TH1F* hpUVA3X = new TH1F(nameu3X,"",500,-50,50); hpUVA3X->SetXTitle("mm"); hpUVA3X->SetYTitle("Frequency");hpUVA3X->SetLabelSize(0.045,"XY");hpUVA3X->SetTitleSize(0.045,"XY");
    TH1F* hpUVA3Y = new TH1F(nameu3Y,"",500,-50,50); hpUVA3Y->SetXTitle("mm"); hpUVA3Y->SetYTitle("Frequency");hpUVA3Y->SetLabelSize(0.045,"XY");hpUVA3Y->SetTitleSize(0.045,"XY");  
    TH1F* hpREF1X = new TH1F(name1X,"",500,-50,50); hpREF1X->SetXTitle("mm"); hpREF1X->SetYTitle("Frequency");hpREF1X->SetLabelSize(0.045,"XY");hpREF1X->SetTitleSize(0.045,"XY");
    TH1F* hpREF1Y = new TH1F(name1Y,"",500,-50,50); hpREF1Y->SetXTitle("mm"); hpREF1Y->SetYTitle("Frequency");hpREF1Y->SetLabelSize(0.045,"XY");hpREF1Y->SetTitleSize(0.045,"XY");  
    //TH1F* hpZZ1 = new TH1F(nameZZ1,"",600,-150,150); hpZZ1->SetXTitle("mm"); hpZZ1->SetYTitle("Frequency"); hpZZ1->SetLabelSize(0.045,"XY");hpZZ1->SetTitleSize(0.045,"XY");
    //TH1F* hpZZ2 = new TH1F(nameZZ2,"",600,-150,150); hpZZ2->SetXTitle("mm"); hpZZ2->SetYTitle("Frequency"); hpZZ2->SetLabelSize(0.045,"XY");hpZZ2->SetTitleSize(0.045,"XY");
    //TH1F* hpEta5 = new TH1F(nameEta5,"",600,-150,150); hpEta5->SetXTitle("mm"); hpEta5->SetYTitle("Frequency"); hpEta5->SetLabelSize(0.045,"XY");hpEta5->SetTitleSize(0.045,"XY");
    char nameRes2X[20];sprintf(nameRes2X,"residualREF2X_%i",iterNb);char nameRes2Y[20];sprintf(nameRes2Y,"residualREF2Y_%i",iterNb);
    char nameRes3X[20];sprintf(nameRes3X,"residualREF3X_%i",iterNb);char nameRes3Y[20];sprintf(nameRes3Y,"residualREF3Y_%i",iterNb);
    char nameResu3X[20];sprintf(nameResu3X,"residualUVA3X_%i",iterNb);char nameResu3Y[20];sprintf(nameResu3Y,"residualUVA3Y_%i",iterNb);
    char nameRes1X[20];sprintf(nameRes1X,"residualREF1X_%i",iterNb);char nameRes1Y[20];sprintf(nameRes1Y,"residualREF1Y_%i",iterNb);
    //char nameResZZ1[20];sprintf(nameResZZ1,"residualZZ1_%i",iterNb);char nameResZZ2[20];sprintf(nameResZZ2,"residualZZ2_%i",iterNb);
    //char nameResEta5[20];sprintf(nameResEta5,"residualEta5_%i",iterNb);
    TH1F* residualREF2X = new TH1F(nameRes2X,"",200,-2,2); residualREF2X->SetXTitle("Residual [mm]"); residualREF2X->SetYTitle("Frequency");residualREF2X->SetLabelSize(0.045,"XY");residualREF2X->SetTitleSize(0.045,"XY");
    TH1F* residualREF2Y = new TH1F(nameRes2Y,"",200,-2,2); residualREF2Y->SetXTitle("Residual [mm]"); residualREF2Y->SetYTitle("Frequency");residualREF2Y->SetLabelSize(0.045,"XY");residualREF2Y->SetTitleSize(0.045,"XY");
    TH1F* residualREF3X = new TH1F(nameRes3X,"",200,-2,2); residualREF3X->SetXTitle("Residual [mm]"); residualREF3X->SetYTitle("Frequency");residualREF3X->SetLabelSize(0.045,"XY");residualREF3X->SetTitleSize(0.045,"XY");
    TH1F* residualREF3Y = new TH1F(nameRes3Y,"",200,-2,2); residualREF3Y->SetXTitle("Residual [mm]"); residualREF3Y->SetYTitle("Frequency");residualREF3Y->SetLabelSize(0.045,"XY");residualREF3Y->SetTitleSize(0.045,"XY");
    TH1F* residualUVA3X = new TH1F(nameResu3X,"",200,-2,2); residualUVA3X->SetXTitle("Residual [mm]"); residualUVA3X->SetYTitle("Frequency");residualUVA3X->SetLabelSize(0.045,"XY");residualUVA3X->SetTitleSize(0.045,"XY");
    TH1F* residualUVA3Y = new TH1F(nameResu3Y,"",200,-2,2); residualUVA3Y->SetXTitle("Residual [mm]"); residualUVA3Y->SetYTitle("Frequency");residualUVA3Y->SetLabelSize(0.045,"XY");residualUVA3Y->SetTitleSize(0.045,"XY");
    TH1F* residualREF1X = new TH1F(nameRes1X,"",200,-2,2); residualREF1X->SetXTitle("mm"); residualREF1X->SetYTitle("Frequency");residualREF1X->SetLabelSize(0.045,"XY");residualREF1X->SetTitleSize(0.045,"XY");
    TH1F* residualREF1Y = new TH1F(nameRes1Y,"",200,-2,2); residualREF1Y->SetXTitle("mm"); residualREF1Y->SetYTitle("Frequency");residualREF1Y->SetLabelSize(0.045,"XY");residualREF1Y->SetTitleSize(0.045,"XY");
    //TH1F* residualZZ1 = new TH1F(nameResZZ1,"",320,-16,16); residualZZ1->SetXTitle("Residual [mm]"); residualZZ1->SetYTitle("Frequency");residualZZ1->SetLabelSize(0.045,"XY");residualZZ1->SetTitleSize(0.045,"XY");
    //TH1F* residualZZ2 = new TH1F(nameResZZ2,"",320,-16,16); residualZZ2->SetXTitle("Residual [mm]"); residualZZ2->SetYTitle("Frequency");residualZZ2->SetLabelSize(0.045,"XY");residualZZ2->SetTitleSize(0.045,"XY");
    //TH1F* residualEta5 = new TH1F(nameResEta5,"",320,-16,16); residualEta5->SetXTitle("Residual [mm]"); residualEta5->SetYTitle("Frequency");residualEta5->SetLabelSize(0.045,"XY");residualEta5->SetTitleSize(0.045,"XY");
    /*
    char nameDxREF3X[20]; sprintf(nameDxREF3X,"REF3X_REF2X_%i",iterNb); char nameDyREF3Y[20]; sprintf(nameDyREF3Y,"REF3Y_REF2Y_%i",iterNb); 
    char nameDxUVA3X[20]; sprintf(nameDxUVA3X,"UVA3X_REF2X_%i",iterNb); char nameDyUVA3Y[20]; sprintf(nameDyUVA3Y,"UVA3Y_REF2Y_%i",iterNb); 
    char nameDxREF1X[20]; sprintf(nameDxREF1X,"REF1X_REF2X_%i",iterNb); char nameDyREF1Y[20]; sprintf(nameDyREF1Y,"REF1Y_REF2Y_%i",iterNb); 
    TH1F* dxREF3X = new TH1F(nameDxREF3X,"",400,-4,4); dxREF3X->SetXTitle("Delta_X_REF3X_REF2X [mm]"); dxREF3X->SetYTitle("Frequency");dxREF3X->SetLabelSize(0.045,"XY"); dxREF3X->SetTitleSize(0.045,"XY");
    TH1F* dxUVA3X = new TH1F(nameDxUVA3X,"",400,-4,4); dxUVA3X->SetXTitle("Delta_X_UVA3X_REF2X [mm]"); dxUVA3X->SetYTitle("Frequency");dxUVA3X->SetLabelSize(0.045,"XY"); dxUVA3X->SetTitleSize(0.045,"XY");
    TH1F* dxREF1X = new TH1F(nameDxREF1X,"",400,-4,4); dxREF1X->SetXTitle("Delta_X_REF1X_REF2X [mm]"); dxREF1X->SetYTitle("Frequency");dxREF1X->SetLabelSize(0.045,"XY"); dxREF1X->SetTitleSize(0.045,"XY");
    TH1F* dyREF3Y = new TH1F(nameDyREF3Y,"",400,-4,4); dyREF3Y->SetXTitle("Delta_Y_REF3Y_REF2Y [mm]"); dyREF3Y->SetYTitle("Frequency");dyREF3Y->SetLabelSize(0.045,"XY"); dyREF3Y->SetTitleSize(0.045,"XY");
    TH1F* dyUVA3Y = new TH1F(nameDyUVA3Y,"",400,-4,4); dyUVA3Y->SetXTitle("Delta_Y_UVA3Y_REF2Y [mm]"); dyUVA3Y->SetYTitle("Frequency");dyUVA3Y->SetLabelSize(0.045,"XY"); dyUVA3Y->SetTitleSize(0.045,"XY");
    TH1F* dyREF1Y = new TH1F(nameDyREF1Y,"",400,-4,4); dyREF1Y->SetXTitle("Delta_Y_REF1Y_REF2Y [mm]"); dyREF1Y->SetYTitle("Frequency");dyREF1Y->SetLabelSize(0.045,"XY"); dyREF1Y->SetTitleSize(0.045,"XY");
    
    char nameDxUVA3REF3[20]; sprintf(nameDxUVA3REF3,"UVA3X_REF3X_%i",iterNb);
    char nameDxREF1UVA3[20]; sprintf(nameDxREF1UVA3,"REF1X_UVA3X_%i",iterNb);
    char nameDxREF1REF3[20]; sprintf(nameDxREF1REF3,"REF1X_REF3X_%i",iterNb);
    char nameDyUVA3REF3[20]; sprintf(nameDyUVA3REF3,"UVA3Y_REF3Y_%i",iterNb);
    char nameDyREF1UVA3[20]; sprintf(nameDyREF1UVA3,"REF1Y_UVA3Y_%i",iterNb);
    char nameDyREF1REF3[20]; sprintf(nameDyREF1REF3,"REF1Y_REF3Y_%i",iterNb);
    TH1F* dxUVA3REF3 = new TH1F(nameDxUVA3REF3,"",400,-4,4); dxUVA3REF3->SetXTitle("Delta_X_UVA3X_REF3X [mm]"); dxUVA3REF3->SetYTitle("Frequency"); dxUVA3REF3->SetLabelSize(0.045,"XY"); dxUVA3REF3->SetTitleSize(0.045,"XY");
    TH1F* dxREF1UVA3 = new TH1F(nameDxREF1UVA3,"",400,-4,4); dxREF1UVA3->SetXTitle("Delta_X_REF1X_UVA3X [mm]"); dxREF1UVA3->SetYTitle("Frequency"); dxREF1UVA3->SetLabelSize(0.045,"XY"); dxUVA3REF3->SetTitleSize(0.045,"XY");
    TH1F* dxREF1REF3 = new TH1F(nameDxREF1REF3,"",400,-4,4); dxREF1REF3->SetXTitle("Delta_X_REF1X_REF3X [mm]"); dxREF1REF3->SetYTitle("Frequency"); dxREF1REF3->SetLabelSize(0.045,"XY"); dxREF1REF3->SetTitleSize(0.045,"XY");
    TH1F* dyUVA3REF3 = new TH1F(nameDyUVA3REF3,"",400,-4,4); dyUVA3REF3->SetXTitle("Delta_Y_UVA3Y_REF3Y [mm]"); dyUVA3REF3->SetYTitle("Frequency"); dyUVA3REF3->SetLabelSize(0.045,"XY"); dyUVA3REF3->SetTitleSize(0.045,"XY");
    TH1F* dyREF1UVA3 = new TH1F(nameDyREF1UVA3,"",400,-4,4); dyREF1UVA3->SetXTitle("Delta_Y_REF1Y_UVA3Y [mm]"); dyREF1UVA3->SetYTitle("Frequency"); dyREF1UVA3->SetLabelSize(0.045,"XY"); dyREF1UVA3->SetTitleSize(0.045,"XY");
    TH1F* dyREF1REF3 = new TH1F(nameDyREF1REF3,"",400,-4,4); dyREF1REF3->SetXTitle("Delta_Y_REF1Y_REF3Y [mm]"); dyREF1REF3->SetYTitle("Frequency"); dyREF1REF3->SetLabelSize(0.045,"XY"); dyREF1REF3->SetTitleSize(0.045,"XY");
    */
    TH1F* angleREF3 = new TH1F("angleREF3","Rotation angle distribution of REF3 and REF2",1000,-0.5,0.5); angleREF3->SetXTitle("Angle [radian]"); angleREF3->SetYTitle("Frequency");
    //TH1F* angleREF3_2 = new TH1F("angleREF3","Get From Delta_y",2000,-0.5,3.5); angleREF3_2->SetXTitle("Rotation angle of ERF3 and REF2 [radian]"); angleREF3_2->SetYTitle("Frequency");
    TH1F* angleUVA3 = new TH1F("angleUVA3","Rotation angle distribution of UVA3 and REF2",1000,-0.5,0.5); angleUVA3->SetXTitle("Angle [radian]"); angleUVA3->SetYTitle("Frequency");
    //TH1F* angleUVA3_2 = new TH1F("angleUVA3_2","Get From Delta_y",2000,-0.5,3.5); angleUVA3_2->SetXTitle("Rotation angle of UVA3 and REF2 [radian]"); angleUVA3_2->SetYTitle("Frequency");
    TH1F* angleREF1 = new TH1F("angleREF1","Rotation angle distribution of REF1 and REF2",1000,-0.5,0.5); angleREF1->SetXTitle("Angle [radian]"); angleREF1->SetYTitle("Frequency");
    //TH1F* angleREF1_2 = new TH1F("angleREF1_2","Get From Delta_y",2000,-0.5,3.5); angleREF1_2->SetXTitle("Rotation angle of ERF1 and REF2 [radian]"); angleREF1_2->SetYTitle("Frequency");
    //TH1F* angleEta5 = new TH1F("angleEta5","Rotation Eta5 and REF2",1000,-0.5,0.5);
    //delta-y up: 200,-4,4
    //TH1F* deltayZZ = new TH1F("deltaY","",200,-4,4); deltayZZ->SetXTitle("Position difference [mm]");deltayZZ->SetYTitle("Frequency");
    //deltayZZ->SetLabelSize(0.045,"XY");deltayZZ->SetTitleSize(0.045,"XY");
    //cout<<"shift: "<<shiREF2X<<"\t"<<shiREF2Y<<"\t"<<shiREF3X<<"\t"<<shiREF3Y<<"\t"<<shiUVA3X<<"\t"<<shiUVA3Y<<"\t"<<shiREF1X<<"\t"<<shiREF1Y<<endl;
    
    TH1F* xTrackChi2 = new TH1F("XTrackChi2","Chi square of tracks in X projection",1000,0,0.2); xTrackChi2->SetXTitle("#chi^{2} of track in X"); xTrackChi2->SetYTitle("Frequency");
    xTrackChi2->SetTitleSize(0.04,"XY"); xTrackChi2->SetLabelSize(0.04,"XY");
    TH1F* yTrackChi2 = new TH1F("YTrackChi2","Chi square of tracks in Y projection",1000,0,0.2); yTrackChi2->SetXTitle("#chi^{2} of track in Y"); yTrackChi2->SetYTitle("Frequency");
    yTrackChi2->SetTitleSize(0.04,"XY"); yTrackChi2->SetLabelSize(0.04,"XY");
    
    fout<<"shift: "<<shiREF2X<<"\t"<<shiREF2Y<<"\t"<<shiREF3X<<"\t"<<shiREF3Y<<"\t"<<shiUVA3X<<"\t"<<shiUVA3Y<<"\t"<<shiREF1X<<"\t"<<shiREF1Y<<endl;
    fout2<<"rotation: "<<aREF3REF2<<"\t"<<aUVA3REF2<<"\t"<<aREF1REF2<<endl;
    int nnnn=0;
    for(Int_t i=0;i<vpREF2X.size();i++){
    	//shift
      vpREF2X[i] = vpREF2X[i] - shiREF2X; vpREF2Y[i] = vpREF2Y[i] - shiREF2Y;      
      vpREF3X[i] = vpREF3X[i] - shiREF3X; vpREF3Y[i] = vpREF3Y[i] - shiREF3Y;
      vpUVA3X[i] = vpUVA3X[i] - shiUVA3X; vpUVA3Y[i] = vpUVA3Y[i] - shiUVA3Y;
      vpREF1X[i] = vpREF1X[i] - shiREF1X; vpREF1Y[i] = vpREF1Y[i] - shiREF1Y;
     // vpZZ1[i] = vpZZ1[i] - shiZZ1; vpZZ2[i] = vpZZ2[i] - shiZZ2;
      //vpEta5[i] = vpEta5[i] - shiEta5; 
      tempREF2X=vpREF2X[i]; tempREF2Y=vpREF2Y[i]; tempREF3X=vpREF3X[i]; tempREF3Y=vpREF3Y[i]; 
      tempUVA3X=vpUVA3X[i]; tempUVA3Y=vpUVA3Y[i]; tempREF1X=vpREF1X[i]; tempREF1Y=vpREF1Y[i]; 
      //tempEta5=vpEta5[i];
      //rotate back
      vpREF3X[i]=tempREF3X*cos(aREF3REF2)-tempREF3Y*sin(aREF3REF2);
      vpREF3Y[i]=tempREF3X*sin(aREF3REF2)+tempREF3Y*cos(aREF3REF2);
      vpUVA3X[i]=tempUVA3X*cos(aUVA3REF2)-tempUVA3Y*sin(aUVA3REF2);
      vpUVA3Y[i]=tempUVA3X*sin(aUVA3REF2)+tempUVA3Y*cos(aUVA3REF2);
      vpREF1X[i]=tempREF1X*cos(aREF1REF2)-tempREF1Y*sin(aREF1REF2);
      vpREF1Y[i]=tempREF1X*sin(aREF1REF2)+tempREF1Y*cos(aREF1REF2);
      //vpEta5[i]=tempREF2X*sin(aEta5REF2)+tempEta5*cos(aEta5REF2);
      
      hpREF2X->Fill(vpREF2X[i]); hpREF2Y->Fill(vpREF2Y[i]);
      hpREF3X->Fill(vpREF3X[i]); hpREF3Y->Fill(vpREF3Y[i]);
      hpUVA3X->Fill(vpUVA3X[i]); hpUVA3Y->Fill(vpUVA3Y[i]);
      hpREF1X->Fill(vpREF1X[i]); hpREF1Y->Fill(vpREF1Y[i]);
      //hpZZ1->Fill(vpZZ1[i]); hpZZ2->Fill(vpZZ2[i]);
      //hpEta5->Fill(vpEta5[i]); //cout<<vpEta5[i]<<endl;
      /*
      dxREF3X->Fill(vpREF3X[i]-vpREF2X[i]); dyREF3Y->Fill(vpREF3Y[i]-vpREF2Y[i]);
      dxUVA3X->Fill(vpUVA3X[i]-vpREF2X[i]); dyUVA3Y->Fill(vpUVA3Y[i]-vpREF2Y[i]);
      dxREF1X->Fill(vpREF1X[i]-vpREF2X[i]); dyREF1Y->Fill(vpREF1Y[i]-vpREF2Y[i]);
      dxUVA3REF3->Fill(vpUVA3X[i]-vpREF3X[i]); dyUVA3REF3->Fill(vpUVA3Y[i]-vpREF3Y[i]);
      dxREF1UVA3->Fill(vpREF1X[i]-vpUVA3X[i]); dyREF1UVA3->Fill(vpREF1Y[i]-vpUVA3Y[i]);
      dxREF1REF3->Fill(vpREF1X[i]-vpREF3X[i]); dyREF1REF3->Fill(vpREF1Y[i]-vpREF3Y[i]);
      */
      TGraph* g1 = new TGraph();
      g1->SetPoint(0,0,     vpREF2X[i]);
      g1->SetPoint(1,1143.5,vpREF3X[i]);
      g1->SetPoint(2,2686.5,vpUVA3X[i]);
      g1->SetPoint(3,3169.5,vpREF1X[i]);
      TF1* f1 = new TF1("line1","[0]+[1]*x",0,3200);
      g1->Fit("line1","Q");
      double intercept1 = f1->GetParameter(0);
      double slope1     = f1->GetParameter(1);
      double MeasuredREF2X = intercept1 + slope1*0.0;
      double MeasuredREF3X = intercept1 + slope1*1143.5;
      double MeasuredUVA3X = intercept1 + slope1*2686.5;
      double MeasuredREF1X = intercept1 + slope1*3169.5;
      residualREF2X->Fill(MeasuredREF2X-vpREF2X[i]);
      residualREF3X->Fill(MeasuredREF3X-vpREF3X[i]);
      residualUVA3X->Fill(MeasuredUVA3X-vpUVA3X[i]);
      residualREF1X->Fill(MeasuredREF1X-vpREF1X[i]);
      xTrackChi2->Fill(f1->GetChisquare());
      //cout<<f1->GetChisquare()<<"\t";
      delete f1; delete g1;

      TGraph* g2 = new TGraph();
      g2->SetPoint(0,0,     vpREF2Y[i]);
      g2->SetPoint(1,1143.5,vpREF3Y[i]);
      // exclusive
      g2->SetPoint(2,2686.5,vpUVA3Y[i]);
      g2->SetPoint(3,3169.5,vpREF1Y[i]);
      // inclusive
      //g2->SetPoint(2,2305.5,vpZZ2[i]); //inclusive 1
      //g2->SetPoint(2,2327.5,vpZZ1[i]);  //inclusive 2
      //g2->SetPoint(3,2686.5,vpUVA3Y[i]);


      //g2->SetPoint(4,3169.5,vpREF1Y[i]);
      //g2->SetPoint(3,3169.5,vpREF1Y[i]);    
      TF1* f2 = new TF1("line2","[0]+[1]*x",0,3200);
      g2->Fit("line2","Q");
      double intercept2 = f2->GetParameter(0);
      double slope2     = f2->GetParameter(1);
      double MeasuredREF2Y = intercept2 + slope2*0.0;
      double MeasuredREF3Y = intercept2 + slope2*1143.5;
      double MeasuredUVA3Y = intercept2 + slope2*2686.5;
      double MeasuredREF1Y = intercept2 + slope2*3169.5;
      //double MeasuredZZ1  = intercept2 + slope2*2327.5;
      //double MeasuredZZ2  = intercept2 + slope2*2305.5;
      //double MeasuredEta5 = intercept2 + slope2*2011.5;
      residualREF2Y->Fill(MeasuredREF2Y-vpREF2Y[i]);
      residualREF3Y->Fill(MeasuredREF3Y-vpREF3Y[i]);
      residualUVA3Y->Fill(MeasuredUVA3Y-vpUVA3Y[i]);
      residualREF1Y->Fill(MeasuredREF1Y-vpREF1Y[i]);
      //residualZZ1->Fill(MeasuredZZ1-vpZZ1[i]);
      //residualZZ2->Fill(MeasuredZZ2-vpZZ2[i]);
      //residualEta5->Fill(MeasuredEta5-vpEta5[i]);
      //deltayZZ->Fill(vpZZ1[i]-vpZZ2[i]);
      yTrackChi2->Fill(f2->GetChisquare());
      //cout<<f2->GetChisquare()<<endl;
      delete f2; delete g2;
      
      double cosineREF3 = CalculateCosTheta1(vpREF2X[i],vpREF2Y[i],vpREF3X[i],vpREF3Y[i]);
      double cosineUVA3 = CalculateCosTheta1(vpREF2X[i],vpREF2Y[i],vpUVA3X[i],vpREF3Y[i]);
      double cosineREF1 = CalculateCosTheta1(vpREF2X[i],vpREF2Y[i],vpREF1X[i],vpREF3Y[i]);
     // double cosineEta5 = CalculateCosTheta1(vpREF2X[i],vpREF2Y[i],vpREF2X[i],vpEta5[i]);
      angleREF3->Fill(cosineREF3);   //angleREF3_2->Fill(cosineREF3_2);
      angleUVA3->Fill(cosineUVA3); //angleUVA3_2->Fill(cosineUVA3_2);
      angleREF1->Fill(cosineREF1); //angleREF1_2->Fill(cosineREF1_2);
      //angleEta5->Fill(cosineEta5);
      
      nnnn++;
      //if(nnnn%1000==0) cout<<nnnn<<"......"<<endl;
      //if(nnnn>1000) break;
    } //for loop
    //cout<<"after for loop"<<endl;
    gStyle->SetOptFit(1111);

    I2GFvalues myValues;
    myValues = I2GFmainLoop(residualREF2X, 1, 10 , 1);
    meanREF2X = myValues.mean; sigmaREF2X=myValues.sigma;
    myValues = I2GFmainLoop(residualREF2Y, 1, 10 , 1);
    meanREF2Y = myValues.mean; sigmaREF2Y=myValues.sigma;
    myValues = I2GFmainLoop(residualREF3X, 1, 10 , 1);
    meanREF3X = myValues.mean; sigmaREF3X=myValues.sigma;
    myValues = I2GFmainLoop(residualREF3Y, 1, 10 , 1);
    meanREF3Y = myValues.mean; sigmaREF3Y=myValues.sigma;
    myValues = I2GFmainLoop(residualUVA3X, 1, 10 , 1);
    meanUVA3X = myValues.mean; sigmaUVA3X=myValues.sigma;
    myValues = I2GFmainLoop(residualUVA3Y, 1, 10 , 1);
    meanUVA3Y = myValues.mean; sigmaUVA3Y=myValues.sigma;
    myValues = I2GFmainLoop(residualREF1X, 1, 10 , 1);
    meanREF1X = myValues.mean; sigmaREF1X=myValues.sigma;
    myValues = I2GFmainLoop(residualREF1Y, 1, 10 , 1);
    meanREF1Y = myValues.mean; sigmaREF1Y=myValues.sigma;

    cout<<"residual mean: "<<meanREF2X<<"\t"<<meanREF2Y<<"\t"<<meanREF3X<<"\t"<<meanREF3Y<<"\t"<<meanUVA3X<<"\t"<<meanUVA3Y<<"\t"<<meanREF1X<<"\t"<<meanREF1Y<<endl;
        //<<meanZZ1<<"\t"<<meanZZ2<<endl;
    fout1<<"residual mean: "<<meanREF2X<<"\t"<<meanREF2Y<<"\t"<<meanREF3X<<"\t"<<meanREF3Y<<"\t"<<meanUVA3X<<"\t"<<meanUVA3Y<<"\t"<<meanREF1X<<"\t"<<meanREF1Y<<endl;
        //<<meanZZ1<<"\t"<<meanZZ2<<endl;
    /*
    myValues = I2GFmainLoop(dxREF3X, 1, 10 , 1);
    myValues = I2GFmainLoop(dxUVA3X, 1, 10 , 1);
    myValues = I2GFmainLoop(dxREF1X, 1, 10 , 1);
    myValues = I2GFmainLoop(dyREF3Y, 1, 10 , 1);
    myValues = I2GFmainLoop(dyUVA3Y, 1, 10 , 1);
    myValues = I2GFmainLoop(dyREF1Y, 1, 10 , 1);
    myValues = I2GFmainLoop(dxUVA3REF3, 1, 10 , 1);
    myValues = I2GFmainLoop(dxREF1UVA3, 1, 10 , 1);
    myValues = I2GFmainLoop(dxREF1REF3, 1, 10 , 1);
    myValues = I2GFmainLoop(dyUVA3REF3, 1, 10 , 1);
    myValues = I2GFmainLoop(dyREF1UVA3, 1, 10 , 1);
    myValues = I2GFmainLoop(dyREF1REF3, 1, 10 , 1);
    */
    myValues = I2GFmainLoop(angleREF3, 1, 10 , 1);
    meanAngleREF3=myValues.mean;
    myValues = I2GFmainLoop(angleUVA3, 1, 10 , 1);
    meanAngleUVA3=myValues.mean;
    myValues = I2GFmainLoop(angleREF1, 1, 10 , 1);
    meanAngleREF1=myValues.mean;
    //maximum=angleEta5->GetMean(); rms=angleEta5->GetRMS(1); lRange=maximum-rms*0.7; hRange=maximum+rms*0.7;
    //TF1* funAngleEta5=new TF1("funAngleEta5","gaus",lRange,hRange); angleEta5->Fit("funAngleEta5","RQ");
    //meanAngleEta5=funAngleEta5->GetParameter(1);
    //maximum=xTrackChi2->GetMean(); rms=xTrackChi2->GetRMS(1); lRange=maximum-rms*0.5; hRange=maximum+rms*0.5;
    //TF1* funXTrackChi2=new TF1("funXTrackChi2","gaus",lRange,hRange); xTrackChi2->Fit("funXTrackChi2","RQ");
    meanXChi2=xTrackChi2->GetMean();
    //maximum=yTrackChi2->GetMean(); rms=yTrackChi2->GetRMS(1); lRange=maximum-rms*0.5; hRange=maximum+rms*0.5;
    //TF1* funYTrackChi2=new TF1("funYTrackChi2","gaus",lRange,hRange); yTrackChi2->Fit("funYTrackChi2","RQ");
    meanYChi2=yTrackChi2->GetMean();
    
    totalAngleREF3 += aREF3REF2;
    totalAngleUVA3 += aUVA3REF2;
    totalAngleREF1 += aREF1REF2;
    fout3<<sigmaREF2X<<"\t"<<sigmaREF2Y<<"\t"<<sigmaREF3X<<"\t"<<sigmaREF3Y<<"\t"<<sigmaUVA3X<<"\t"<<sigmaUVA3Y<<"\t"<<sigmaREF1X<<"\t"<<sigmaREF1Y<<"\t"<<totalAngleREF3<<"\t"<<totalAngleUVA3<<"\t"<<totalAngleREF1<<"\t"<<meanXChi2<<"\t"<<meanYChi2<<endl;
    
    f->Write();
    f->Close();
    //delete funPosEta5; delete funPosREF1Y; delete funPosUVA3Y; delete funPosREF3Y; delete funPosREF2Y;
    
    double factor = -0.2;
    //shiREF2X = meanREF2X*factor; shiREF2Y = meanREF2Y*factor; 
    //shiREF3X = meanREF3X*factor; shiREF3Y = meanREF3Y*factor; 
    //shiUVA3X = meanUVA3X*factor; shiUVA3Y = meanUVA3Y*factor; 
    //shiREF1X = meanREF1X*factor; shiREF1Y = meanREF1Y*factor; 
    //shiZZ1 = meanZZ1*factor; shiZZ2 = meanZZ2*factor; 
    //shiEta5 = meanEta5*factor;
    factor=0.2;
    shiREF2X=0.0; shiREF2Y=0.0;
    shiREF3X=0.0; shiREF3Y=0.0;
    shiUVA3X=0.0; shiUVA3Y=0.0;
    shiREF1X=0.0; shiREF1Y=0.0;
    
    aREF3REF2 = 0.001 ;
    aUVA3REF2 = 0.0;
    aREF1REF2 = 0.0;
    //aUVA3REF2 = meanAngleUVA3*factor;
    //aREF1REF2 = meanAngleREF1*factor;
   // aEta5REF2 = meanAngleEta5*factor;
   // if(iterNb>0) break; // only cylce once.
    //if((meanREF2X>=-0.001 && meanREF2X<=0.001) && (meanREF2Y>=-0.001 && meanREF2Y<=0.001))
    //  if((meanREF3X>=-0.001 && meanREF3X<=0.001) && (meanREF3Y>=-0.001 && meanREF3Y<=0.001))
    //    if((meanUVA3X>=-0.001 && meanUVA3X<=0.001) && (meanUVA3Y>=-0.001 && meanUVA3Y<=0.001))
    //    	if((meanREF1X>=-0.001 && meanREF1X<=0.001) && (meanREF1Y>=-0.001 && meanREF1Y<=0.001) && meanEta5<=0.005)
    //if(meanAngleREF3>=-0.001 && meanAngleREF3<=0.001 && meanAngleUVA3>=-0.001 && meanAngleUVA3<=0.001 && meanAngleREF1>=-0.001 && meanAngleREF1<=0.001)
    //      {
    //        cout<<"find it...iterating "<<iterNb<<" times."<<endl;
    //        break;
    //      }
  // break;
    if(iterNb==41) break;
 }//while(1)
 fout.close();
 fout1.close();
 fout2.close();
} // entire script
예제 #16
0
int main(int argc, char * argv[])
{
    int width = 640;
    int height = 480;

    Resolution::getInstance(width, height);

    Intrinsics::getInstance(528, 528, 320, 240);

    cv::Mat intrinsicMatrix = cv::Mat(3,3,CV_64F);

    intrinsicMatrix.at<double>(0,0) = Intrinsics::getInstance().fx();
    intrinsicMatrix.at<double>(1,1) = Intrinsics::getInstance().fy();

    intrinsicMatrix.at<double>(0,2) = Intrinsics::getInstance().cx();
    intrinsicMatrix.at<double>(1,2) = Intrinsics::getInstance().cy();

    intrinsicMatrix.at<double>(0,1) =0;
    intrinsicMatrix.at<double>(1,0) =0;

    intrinsicMatrix.at<double>(2,0) =0;
    intrinsicMatrix.at<double>(2,1) =0;
    intrinsicMatrix.at<double>(2,2) =1;

    Bytef * decompressionBuffer = new Bytef[Resolution::getInstance().numPixels() * 2];
    IplImage * deCompImage = 0;

    std::string logFile="/home/lili/Kinect_Logs/2015-11-05.00.klg";
   // assert(pcl::console::parse_argument(argc, argv, "-l", logFile) > 0 && "Please provide a log file");

    RawLogReader logReader(decompressionBuffer,
                           deCompImage,
                           logFile,
                           true);


    cv::Mat1b tmp(height, width);
    cv::Mat3b depthImg(height, width);

    PlaceRecognition placeRecognition(&intrinsicMatrix);

    iSAMInterface iSAM;

    //Keyframes
    KeyframeMap map(true);
    Eigen::Vector3f lastPlaceRecognitionTrans = Eigen::Vector3f::Zero();
    Eigen::Matrix3f lastPlaceRecognitionRot = Eigen::Matrix3f::Identity();
    int64_t lastTime = 0;

    OdometryProvider * odom = 0;


    //int frame_index = 0;

   // uint64_t timestamp;

    /*if(true)
    {
        odom = new FOVISOdometry;
        if(logReader.hasMore())
        {
            logReader.getNext();

            Eigen::Matrix3f Rcurr = Eigen::Matrix3f::Identity();
            Eigen::Vector3f tcurr = Eigen::Vector3f::Zero();

            odom->getIncrementalTransformation(tcurr,
                                               Rcurr,
                                               logReader.timestamp,
                                               (unsigned char *)logReader.deCompImage->imageData,
                                               (unsigned short *)&decompressionBuffer[0]);
        }

    }*/
    //else
   // {
        odom = new DVOdometry;

        if(logReader.hasMore())
        {
            logReader.getNext();

            DVOdometry * dvo = static_cast<DVOdometry *>(odom);

            dvo->firstRun((unsigned char *)logReader.deCompImage->imageData,
                          (unsigned short *)&decompressionBuffer[0]);
        }
    //}

    ofstream fout1("camera_pose_DVOMarch28.txt");
    ofstream fout2("camera_pose_KeyframeMotionMetric0.1March28.txt");
    ofstream fout3("loop_closure_transformationMarch28.txt");
    ofstream fout4("camera_pose_after_optimizationMarch28.txt");
    ofstream fout5("camera_pose_after_optimizationMarch28DVOCov.txt");
    ofstream fout6("camera_pose_after_optimizationMarch28DVOLoopTransCov.txt");

    /*
    pcl::visualization::PCLVisualizer cloudViewer;

    cloudViewer.setBackgroundColor(1, 1, 1);
    cloudViewer.initCameraParameters();
    cloudViewer.addCoordinateSystem(0.1, 0, 0, 0);
    */
    //pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> color(cloud->makeShared());
    //cloudViewer.addPointCloud<pcl::PointXYZRGB>(cloud->makeShared(), color, "Cloud Viewer");


    int loopClosureCount=0;

    while(logReader.hasMore())
    {
        logReader.getNext();

        cv::Mat3b rgbImg(height, width, (cv::Vec<unsigned char, 3> *)logReader.deCompImage->imageData);

        cv::Mat1w depth(height, width, (unsigned short *)&decompressionBuffer[0]);

        cv::normalize(depth, tmp, 0, 255, cv::NORM_MINMAX, 0);

        cv::cvtColor(tmp, depthImg, CV_GRAY2RGB);

        cv::imshow("RGB", rgbImg);

        cv::imshow("Depth", depthImg);

        char key = cv::waitKey(1);

        if(key == 'q')
        {
            break;
        }
        else if(key == ' ')
        {
            key = cv::waitKey(0);
        }
        if(key == 'q')
        {
            break;
        }

        Eigen::Matrix3f Rcurr = Eigen::Matrix3f::Identity();
        Eigen::Vector3f tcurr = Eigen::Vector3f::Zero();



//        #1
        odom->getIncrementalTransformation(tcurr,
                                          Rcurr,
                                          logReader.timestamp,
                                          (unsigned char *)logReader.deCompImage->imageData,
                                          (unsigned short *)&decompressionBuffer[0]);


       fout1<<tcurr[0]<<" "<<tcurr[1]<<" "<<tcurr[2]<<" "<<Rcurr(0,0)<<" "<<Rcurr(0,1)<<" "<<Rcurr(0,2)<<" "<<Rcurr(1,0)<<" "<<Rcurr(1,1)<<" "<<Rcurr(1,2)<<" "<<Rcurr(2,0)<<" "<<Rcurr(2,1)<<" "<<Rcurr(2,2)<<endl;

        Eigen::Matrix3f Rdelta = Rcurr.inverse() * lastPlaceRecognitionRot;
        Eigen::Vector3f tdelta = tcurr - lastPlaceRecognitionTrans;

        //Eigen::MatrixXd covariance = odom->getCovariance();
         //Eigen::MatrixXd covariance=Eigen::Matrix<double, 6, 6>::Identity()* 1e-3;

        if((Projection::rodrigues2(Rdelta).norm() + tdelta.norm())  >= 0.1)
        {
            Eigen::MatrixXd covariance = odom->getCovariance();
            iSAM.addCameraCameraConstraint(lastTime,
                                           logReader.timestamp,
                                           lastPlaceRecognitionRot,
                                           lastPlaceRecognitionTrans,
                                           Rcurr,
                                           tcurr);
                                           //covariance);

            printCovariance(fout5,  covariance);

            lastTime = logReader.timestamp;

            lastPlaceRecognitionRot = Rcurr;
            lastPlaceRecognitionTrans = tcurr;

            cout<<"before add keyframe"<<endl;

//            #2
            map.addKeyframe((unsigned char *)logReader.deCompImage->imageData,
                            (unsigned short *)&decompressionBuffer[0],
                            Rcurr,
                            tcurr,
                            logReader.timestamp);

           fout2<<tcurr[0]<<" "<<tcurr[1]<<" "<<tcurr[2]<<" "<<Rcurr(0,0)<<" "<<Rcurr(0,1)<<" "<<Rcurr(0,2)<<" "<<Rcurr(1,0)<<" "<<Rcurr(1,1)<<" "<<Rcurr(1,2)<<" "<<Rcurr(2,0)<<" "<<Rcurr(2,1)<<" "<<Rcurr(2,2)<<endl;

           /*
            //Save keyframe
           {
            cv::Mat3b rgbImgKeyframe(height, width, (cv::Vec<unsigned char, 3> *)logReader.deCompImage->imageData);

            cv::Mat1w depthImgKeyframe(height, width, (unsigned short *)&decompressionBuffer[0]);

            //save keyframe depth
            char fileName[1024] = {NULL};
            sprintf(fileName, "keyframe_depth_%06d.png", frame_index);
            cv::imwrite(fileName, depthImgKeyframe);

            //save keyframe rgb

            sprintf(fileName, "keyframe_rgb_%06d.png", frame_index);
            cv::imwrite(fileName, rgbImgKeyframe);
            frame_index ++;

           }
        */

            int64_t matchTime;
            Eigen::Matrix4d transformation;
           // Eigen::MatrixXd cov(6,6);
            //isam::Covariance(0.001 * Eigen::Matrix<double, 6, 6>::Identity()))
            Eigen::MatrixXd cov=0.001 * Eigen::Matrix<double, 6, 6>::Identity();


            cout<<"map.addKeyframe is OK"<<endl;

//            #3
            if(placeRecognition.detectLoop((unsigned char *)logReader.deCompImage->imageData,
                                           (unsigned short *)&decompressionBuffer[0],
                                           logReader.timestamp,
                                           matchTime,
                                           transformation,
                                           cov,
                                           loopClosureCount))
            {

                //printCovariance(fout6,  cov);
               cout<<"logReader.timestamp "<<logReader.timestamp<<endl;
               cout<<"matchTime "<<matchTime<<endl;

               /*
               transformation << -0.2913457145219732, 0.228056050293173, -0.9290361201559172, 2.799184934345601,
                                0.6790194052589797, 0.7333821627861707, -0.03291277242681545, 1.310438143604587,
                                0.673832562222562, -0.6404225489719699, -0.3685222338703895, 6.988973505496276,
                                0, 0, 0, 0.999999999999998;
                */
                /*
              transformation << 0.9998996846969838, 0.003948215234314986, -0.01360265192291004, 0.05847011404293689,
                              -0.004032877285312574, 0.9999726343121815, -0.006202138950136233, 0.04528938486109094,
                                0.01357779229749574, 0.006256374606648019, 0.9998882444218992, 0.02203456132723125,
                                0, 0, 0, 1;
                */
              iSAM.addLoopConstraint(logReader.timestamp, matchTime, transformation);//, cov);
              fout3<<transformation(0,0)<<" "<<transformation(0,1)<<" "<<transformation(0,2)<<" "<<transformation(0,3)<<" "<<transformation(1,0)<<" "<<transformation(1,1)<<" "<<transformation(1,2)<<" "<<transformation(1,3)<<" "<<transformation(2,0)<<" "<<transformation(2,1)<<" "<<transformation(2,2)<<" "<<transformation(2,3)<<" "<<transformation(3,0)<<" "<<transformation(3,1)<<" "<<transformation(3,2)<<" "<<transformation(3,3)<<endl;
              loopClosureCount++;


            }

        }

        if(loopClosureCount>=1)
        {
            break;
        }
    }
    /*
    for(int i=0; i<loopClosureCount;i++)
    {

     iSAM.addLoopConstraint(placeRecognition.loopClosureConstraints.at(i)->time1,
                            placeRecognition.loopClosureConstraints.at(i)->time2,
                            placeRecognition.loopClosureConstraints.at(i)->constraint);

    }*/

    std::vector<std::pair<uint64_t, Eigen::Matrix4f> > posesBefore;
    iSAM.getCameraPoses(posesBefore);

    cout<<"It works good before optimization"<<endl;

//    #4
    double residual =iSAM.optimise();

    cout<<"It works good after optimize and before map.applyPoses"<<endl;

   // map.applyPoses(isam);
    //cout<<"It works good before *cloud=map.getMap and after map.applyPoses(isam)"<<endl;

    /*
    pcl::PointCloud<pcl::PointXYZRGB> *cloud = map.getMap();


     // Write it back to disk under a different name.
	// Another possibility would be "savePCDFileBinary()".
	cout<<"before storing the point cloud map"<<endl;
	pcl::io::savePCDFileASCII ("outputCloudMap03DVODensity005.pcd", *cloud);

    cout << "Saved data points to outputMap.pcd." << std::endl;


    cout<<"copy data into octomap..."<<endl;

    octomap::ColorOcTree tree( 0.05 );

    for (size_t i=0; i<(*cloud).points.size(); i++)
    {
        // 将点云里的点插入到octomap中
        tree.updateNode( octomap::point3d((*cloud).points[i].x, (*cloud).points[i].y, (*cloud).points[i].z), true );
    }

    for (size_t i=0; i<(*cloud).points.size(); i++)
    {
        tree.integrateNodeColor( (*cloud).points[i].x, (*cloud).points[i].y, (*cloud).points[i].z, (*cloud).points[i].r, (*cloud).points[i].g, (*cloud).points[i].b);
    }

    tree.updateInnerOccupancy();
    tree.write("OctomapColorLab03DVODensity005.ot");
    cout<<"please see the done."<<endl;
   */

    //pcl::visualization::PCLVisualizer cloudViewer;

   // cloudViewer.setBackgroundColor(1, 1, 1);
    //cloudViewer.initCameraParameters();
   // cloudViewer.addCoordinateSystem(0.1, 0, 0, 0);

    //pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> color(cloud->makeShared());
    //cloudViewer.addPointCloud<pcl::PointXYZRGB>(cloud->makeShared(), color, "Cloud Viewer");

    std::vector<std::pair<uint64_t, Eigen::Matrix4f> > newPoseGraph;

    iSAM.getCameraPoses(newPoseGraph);


    /*
    for(unsigned int i = 0; i < newPoseGraph.size(); i++)
    {
       // file << std::setprecision(6) << std::fixed << (double)newPoseGraph.at(i).first / 1000000.0 << " ";

        Eigen::Vector3f trans = newPoseGraph.at(i).second.topRightCorner(3, 1);
        Eigen::Matrix3f rot = newPoseGraph.at(i).second.topLeftCorner(3, 3);

        fout4 << trans(0) << " " << trans(1) << " " << trans(2) << " ";

        Eigen::Quaternionf currentCameraRotation(rot);

        //file << currentCameraRotation.x() << " " << currentCameraRotation.y() << " " << currentCameraRotation.z() << " " << currentCameraRotation.w() << "\n";
    }*/



    for(std::vector<std::pair<uint64_t, Eigen::Matrix4f> >::iterator ite=newPoseGraph.begin(); ite!=newPoseGraph.end(); ite++)
    {
        Eigen::Matrix3f Roptimized;
        Roptimized<<ite->second(0,0), ite->second(0,1), ite->second(0,2),
                    ite->second(1,0), ite->second(1,1), ite->second(1,2),
                    ite->second(2,0), ite->second(2,1), ite->second(2,2);

         Eigen::Quaternionf quatOptimized(Roptimized);

         fout4<<ite->second(0,3)<<" "<<ite->second(1,3)<<" "<<ite->second(2,3)<<" "<<quatOptimized.w()<<" "<<quatOptimized.x()<<" "<<quatOptimized.y()<<" "<<quatOptimized.z()<<endl;

    }

    cout<<"The number of optimized poses"<<newPoseGraph.size()<<endl;


   // drawPoses(poses, cloudViewer, 1.0, 0, 0);
    //drawPoses(posesBefore, cloudViewer, 0, 0, 1.0);







    //cloudViewer.spin();

    delete [] decompressionBuffer;

    return 0;
}