void rd51_TrackFinder_Launcher(TString InputRootFile, TString Options = "RecoRoot", Int_t TotalEntries = 0, Int_t FirstEntry = 0)
{
gROOT->ProcessLine(".x Load_TrackFinder.cpp");
TFile file0(InputRootFile); 
rd51tbgeo->MakeSelector("rd51_EventBuilder_Class");
gROOT->ProcessLine(".L rd51_EventBuilder_Class.C++");
rd51tbgeo->Process("rd51_TrackFinder.C+", Options);
}
Exemplo n.º 2
0
void overlay_plots(const string& fFile0, const string& fFile1, const double fYmax, const string& fPlot, const string& fLegendEnt1, const string& fLegendEnt2, const string& fName) {
  
   TProfile *p[2];
 
   TFile file0(fFile0.c_str());
   TDirectoryFile *subDir = (TDirectoryFile*)file0.Get("offsetAnalysis");
   p[0] = (TProfile*)subDir->Get(fPlot.c_str());

   TFile file1(fFile1.c_str());
   subDir = (TDirectoryFile*)file1.Get("offsetAnalysis");
   p[1] = (TProfile*)subDir->Get(fPlot.c_str()); 

   p[0]->SetTitleOffset(1.5,"Y");
   p[0]->GetXaxis()->SetTitleSize(0.04);
   p[0]->GetYaxis()->SetTitleSize(0.04);
   
   double ymax = ((p[0]->GetMaximum())>(p[1]->GetMaximum())) ? p[0]->GetMaximum() : p[1]->GetMaximum();
   
   p[0]->GetYaxis()->SetRangeUser(0.,fYmax);
   
   TCanvas *c = new TCanvas("c","",800,800);
   c->cd();
  
   p[0]->SetLineWidth(3);
   p[0]->SetLineColor(kRed);
   p[0]->SetFillColor(kRed);
   p[0]->Draw("hist");
   p[1]->SetLineWidth(3);
   p[1]->SetLineColor(kBlack);
   p[1]->SetMarkerStyle(20);
   p[1]->SetMarkerColor(kBlack);
   p[1]->Draw("sames");
   
   TLegend *legend = new TLegend(.57,.77,.9,.87);
   legend->SetBorderSize(1);
   legend->SetFillColor(0);
//    legend->SetFillStyle(0);
   legend->SetMargin(0.12);
   legend->AddEntry(p[0],fLegendEnt1.c_str(),"l");
   legend->AddEntry(p[1],fLegendEnt2.c_str(),"l");
   legend->Draw();
   
   TLatex l;
   l.SetTextAlign(12);
   l.SetTextSize(0.04);
   l.SetTextFont(62);
   l.SetNDC();
   l.DrawLatex(0.15,0.85,"CMS 2009 Preliminary");
   
   string fileName = fName;
   c->SetGridy();
   c->SaveAs(fileName.c_str());
   
   delete legend;
   delete c;
}
Exemplo n.º 3
0
void FileKindTestCase::Pipe()
{
    int afd[2];
#ifdef __UNIX__
    pipe(afd);
#else
    _pipe(afd, 256, O_BINARY);
#endif

    wxFile file0(afd[0]);
    wxFile file1(afd[1]);
    TestFd(file0, false);
    file0.Detach();

    wxFFile ffile(fdopen(afd[0], "r"));
    TestFILE(ffile, false);
}
Exemplo n.º 4
0
int
main
	(
	int argc,
	char** argv
	)
{
	JInitCore();

	JString fileName;
	if (!(JGetChooseSaveFile())->SaveFile("Save file as:", NULL, "junk", &fileName))
		{
		return 0;
		}

	ofstream file0(fileName);
	file0 << "0123456789";
	file0.close();		// force write to disk
	fstream file1(fileName, kJTextFile);
	cout << "Length of file (10): " << JGetFStreamLength(file1) << endl;

	fstream* file2 = JSetFStreamLength(fileName, file1, 20, kJTextFile);
	cout << "Old fstream open? (0) " << (file1.rdbuf())->is_open() << endl;
	cout << "Length of file (20): " << JGetFStreamLength(*file2) << endl;

	fstream* file3 = JSetFStreamLength(fileName, *file2, 5, kJTextFile);
	cout << "Old fstream open? (0) " << (file2->rdbuf())->is_open() << endl;
	cout << "Length of file (5): " << JGetFStreamLength(*file3) << endl;

	file3->close();

	ofstream file4(fileName);
	file4.close();

	file1.open(fileName, kJTextFile);
	cout << "default open of ofstream should erase file" << endl;
	cout << "Length of file (0): " << JGetFStreamLength(file1) << endl;
	file1.close();

	remove(fileName);

	return 0;
}
Exemplo n.º 5
0
void FileKindTestCase::Pipe()
{
    int afd[2];
    int rc;
#ifdef __UNIX__
    rc = pipe(afd);
#else
    rc = _pipe(afd, 256, O_BINARY);
#endif
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to create pipe", 0, rc);

    wxFile file0(afd[0]);
    wxFile file1(afd[1]);
    TestFd(file0, false);
    file0.Detach();

    wxFFile ffile(fdopen(afd[0], "r"));
    TestFILE(ffile, false);
}
Exemplo n.º 6
0
HokuyoHandler::HokuyoHandler(RoboCompLaser::LaserConfData &config, RoboCompGenericBase::GenericBasePrx base_prx, QObject *_parent) : GenericLaserHandler (base_prx, _parent)
{
	if (config.device.size() == 0)
	{
		qDebug() << "LaserComp::HokuyoHandler::HokuyoHandler(): Warning: Laser device configuration is empty! Trying to guess...";
		// Setting up lase
		QFile file0( "/dev/ttyACM0");
		if (file0.exists())
		{
			config.device = "/dev/ttyACM0";
			qDebug() << "LaserComp::HokuyoHandler::HokuyoHandler(): Lets try with" << QString::fromStdString(config.device);
		}
		else
		{
			QFile file1("/dev/ttyACM1");
			if (file1.exists())
			{
				config.device = "/dev/ttyACM1";
				qDebug() << "LaserComp::HokuyoHandler::HokuyoHandler(): Lets try with" << QString::fromStdString(config.device);
			}
			else
			{
				qFatal("LaserComp::HokuyoHandler::HokuyoHandler(): Error: Laser device configuration is empty. It could not be detected automatically.");
			}
		}
	}

	laserDevice.setName(config.device.c_str());
qDebug()<<"name"<<config.device.c_str();
	// Create the sampling timer
	timer = new QTimer(this );
	pm_timer = NULL;
	powerOn = FALSE;

	setConfig(config);
}
Exemplo n.º 7
0
void overlay_plots(const string& fFile0, const string& fFile1, const string& fPlot, 
		   const double fXmin, const double fXmax,
		   const double fYmin, const double fYmax,
		   const string& fXAxisLabel, const string& fYAxisLabel, const string& fName) {
  
  // TGraphErrors *calometPtRMS_vs_ieta = new TGraphErrors(n_ieta,x_ieta,yR_ieta,ex_ieta,eyR_ieta);

   TGraphErrors *g[2];
 
   TFile file0(fFile0.c_str());
   g[0] = (TGraphErrors*)file0.Get(fPlot.c_str()); 

   TFile file1(fFile1.c_str());
   g[1] = (TGraphErrors*)file1.Get(fPlot.c_str()); 
   
   //    double ymax = (g[0]->GetMaximum()>g[1]->GetMaximum()) ? g[0]->GetMaximum() : g[1]->GetMaximum();
   
   g[0]->GetXaxis()->SetTitle(fXAxisLabel.c_str());
   g[0]->GetYaxis()->SetTitle(fYAxisLabel.c_str());
   g[0]->GetXaxis()->SetRangeUser(fXmin,fXmax);
   g[0]->GetYaxis()->SetRangeUser(fYmin,fYmax);
   g[0]->GetXaxis()->SetLabelSize(0.03);
   g[0]->GetYaxis()->SetLabelSize(0.03);

   //g[0]->SetTitleOffset(1.2,"X");
   g[0]->GetXaxis()->SetTitleSize(0.03);
   g[0]->GetYaxis()->SetTitleSize(0.03);

   g[0]->GetYaxis()->SetTitleOffset(1.5);
   

   //    double scale = g[1]->GetEntries()/g[0]->GetEntries();
   //    g[0]->Scale(scale);
   
   TCanvas *c = new TCanvas("c","",800,800);
   c->cd();
  
   g[0]->SetLineWidth(3);
   //    g[0]->SetLineStyle(4);
   g[0]->SetLineColor(kRed);
   g[0]->SetFillColor(kRed);
   //    g[0]->SetMarkerSize(.6);
   g[0]->SetMarkerStyle(26);
   g[0]->SetMarkerColor(kRed);
   g[0]->Draw("ap");
   g[1]->SetLineWidth(3);
   //    g[1]->SetLineStyle(3);
   g[1]->SetLineColor(kBlack);
   //    g[1]->SetMarkerSize(.8);
   g[1]->SetMarkerStyle(20);
   g[1]->SetMarkerSize(0.5);
   g[1]->SetMarkerColor(kBlack);
   g[1]->Draw("psames");
   
   //update the current pad, needed to modify statboxes
   gPad->Update();
   
   // get the statboxes and set color
   //    TPaveStats *st1 = (TPaveStats*)g[0]->GetListOfFunctions()->FindObject("stats");
   //    st1->SetTextColor(kRed);
   //    st1->SetLineColor(kRed);
   //    st1->SetOptStat(1111111);
   //    TPaveStats *st2 = (TPaveStats*)g[1]->GetListOfFunctions()->FindObject("stats");
   //    st2->SetTextColor(kBlack);
   //    st2->SetLineColor(kBlack);
   //    st2->SetOptStat(1111111);

   // set the position of the statboxes
   //    double x1 = st1->GetX1NDC();
   //    double y1 = st1->GetY1NDC();
   //    double x2 = st1->GetX2NDC();
   //    double y2 = st1->GetY2NDC();
   //    //double xx = x2-x1;
   //    double yy = y2-y1;
   //    st2->SetX1NDC(x1);
   //    st2->SetY1NDC(y1-yy);
   //    st2->SetX2NDC(x2);
   //    st2->SetY2NDC(y1);
   gPad->Modified();
   
   TLegend *legend = new TLegend(.4,.91,.75,.99);
   legend->SetBorderSize(1);
   legend->SetFillColor(0);
   //    legend->SetFillStyle(0);
   legend->AddEntry(g[0],"MC","lp");
   legend->AddEntry(g[1],"Data","lp");
   legend->Draw();
   
   TLatex l;
   l.SetTextAlign(12);
   l.SetTextSize(0.04);
   l.SetTextFont(62);
   l.SetNDC();
   //l.DrawLatex(0.20,0.15,"CMS 2009 Preliminary - 900 GeV");
   l.DrawLatex(0.20,0.15,"CMS 2009 Preliminary - 2360 GeV");

   //c->SetLogy();
   c->SetGridx();
   c->SetGridy();
   
   string fileName = fName;
   c->SaveAs(fileName.c_str());
   
   delete legend;
   delete c;
}
void MiniTreeSignalProducerVV13TeV(int samplemin, int samplemax){

 string dir = "/usr/users/dschaefer/CMSSW_7_4_7/src/DijetCombineLimitCode/";
  double mgg, mjj,evWeight, mtot, normWeight;
 int categories;

 evWeight = 1.0;
 normWeight = 1;

 for (int iSample = samplemin; iSample < samplemax; iSample++){
   
   string inFile("WprimeToWZ");
   if (iSample == 1) inFile = string("RS1WW");
   if (iSample == 2) inFile = string("RS1ZZ"); // Fake ZZ signal
   if (iSample == 3) inFile = string("QstarQW");
   if (iSample == 4) inFile = string("QstarQZ");
   if (iSample == 5) inFile = string("BulkWW");
   if (iSample == 6) inFile = string("BulkZZ");
   if (iSample == 7) inFile = string("ZprimeWW");
   if (iSample == 8) inFile = string("WprimeWZ");

   string outFile("dijetVV_13TeV_WZ");
   if (iSample == 1) outFile = string("dijetVV_13TeV_RS1WW");
   if (iSample == 2) outFile = string("dijetVV_13TeV_RS1ZZ");
   if (iSample == 3) outFile = string("dijetVV_13TeV_QstarQW");
   if (iSample == 4) outFile = string("dijetVV_13TeV_QstarQZ");
   if (iSample == 5) outFile = string("dijetVV_13TeV_BulkWW");
   if (iSample == 6) outFile = string("dijetVV_13TeV_BulkZZ");
   if (iSample == 7) outFile = string("dijetVV_13TeV_ZprimeWW");
   if (iSample == 8) outFile = string("dijetVV_13TeV_WZ");
   
   int massrange=36;

   for (int iMass = 0; iMass<massrange; iMass++){

     string sInFile = dir+"input/" + inFile + "_13TeV_" + Form("10k_OUT%dGeV.root", 1000+iMass*100);
     cout << sInFile.c_str() << endl;
     TFile file0(sInFile.c_str(), "read");

     string sOutFile = dir+"MiniTrees/Signal_VV_13TeV/" + outFile + Form("OUT%d_miniTree.root", 1000+iMass*100);
     TFile f1(sOutFile.c_str(), "recreate");
     f1.cd();

     TTree *TCVARS = new TTree("TCVARS", "VV selection");
     TCVARS->Branch("mgg13TeV",&mgg,"mgg/D");

     TCVARS->Branch("evWeight",&evWeight,"evWeight/D");
     TCVARS->Branch("normWeight",&normWeight,"normWeight/D");
     
     TCVARS->Branch("categories",&categories,"categories/I");

  
     double dMass = 1000.+iMass*100.;

     
     for (int iCat = 2; iCat < 8; iCat++){
       TH1D* hMass = (TH1D*) file0.Get("DijetMassHighPuriVV;1");
       if (iCat == 1) hMass = (TH1D*) file0.Get("DijetMassLowPuriVV;1");
       
       if (iCat == 2) hMass = (TH1D*) file0.Get("DijetMassHighPuriWW;1");
       if (iCat == 3) hMass = (TH1D*) file0.Get("DijetMassLowPuriWW;1");
       
       if (iCat == 4) hMass = (TH1D*) file0.Get("DijetMassHighPuriWZ;1");
       if (iCat == 5) hMass = (TH1D*) file0.Get("DijetMassLowPuriWZ;1");
       
       if (iCat == 6) hMass = (TH1D*) file0.Get("DijetMassHighPuriZZ;1");
       if (iCat == 7) hMass = (TH1D*) file0.Get("DijetMassLowPuriZZ;1");
    
       if (iCat == 8) hMass = (TH1D*) file0.Get("DijetMassHighPuriqV;1");
       if (iCat == 9) hMass = (TH1D*) file0.Get("DijetMassLowPuriqV;1");

       if (iCat == 10) hMass = (TH1D*) file0.Get("DijetMassHighPuriqW;1");
       if (iCat == 11) hMass = (TH1D*) file0.Get("DijetMassLowPuriqW;1");

       if (iCat == 12) hMass = (TH1D*) file0.Get("DijetMassHighPuriqZ;1");
       if (iCat == 13) hMass = (TH1D*) file0.Get("DijetMassLowPuriqZ;1");

       if (iCat == 14) hMass = (TH1D*) file0.Get("DijetMassNoPuriVV;1");
       if (iCat == 15) hMass = (TH1D*) file0.Get("DijetMassNoPuriWW;1");
       if (iCat == 16) hMass = (TH1D*) file0.Get("DijetMassNoPuriWZ;1");
       if (iCat == 17) hMass = (TH1D*) file0.Get("DijetMassNoPuriZZ;1");
       if (iCat == 18) hMass = (TH1D*) file0.Get("DijetMassNoPuriqV;1");
       if (iCat == 19) hMass = (TH1D*) file0.Get("DijetMassNoPuriqW;1");
       if (iCat == 20) hMass = (TH1D*) file0.Get("DijetMassNoPuriqZ;1");
       // TH1D* hMass = (TH1D*) file0.Get("DijetMassHighPuriVV"); // WW high purity
//        if (iCat == 1) hMass = (TH1D*) file0.Get("DijetMassLowPuriVV"); // WW low purity
//        if (iCat == 2) hMass = (TH1D*) file0.Get("DijetMassHighPuriWW"); // WW high purity
//        if (iCat == 3) hMass = (TH1D*) file0.Get("DijetMassLowPuriWW"); // WW low purity
//        if (iCat == 4) hMass = (TH1D*) file0.Get("DijetMassHighPuriWZ"); // WZ high purity
//        if (iCat == 5) hMass = (TH1D*) file0.Get("DijetMassLowPuriWZ"); // WZ low purity
//        if (iCat == 6) hMass = (TH1D*) file0.Get("DijetMassHighPuriZZ"); // ZZ high purity
//        if (iCat == 7) hMass = (TH1D*) file0.Get("DijetMassLowPuriZZ"); // ZZ low purity
       
       if(!hMass) continue;
       
       TAxis* Axis =   hMass->GetXaxis();
       for (int i = 1 ; i < hMass->GetNbinsX()+1; i++){
	 //if (hMass->GetBinCenter(i) < dMass*0.75 || hMass->GetBinCenter(i) > dMass*1.25) continue;
	 int N = abs(hMass->GetBinContent(i));
	 if (i%1000 == 0) cout << "i = " << i << " N = " << N << endl;
	 
	 mgg = Axis->GetBinCenter(i);
	 
         categories = iCat;
	 for (int k = 0; k < N; k++) {
	   TCVARS->Fill();
	 }
       }
     }
		 TCVARS->Write();
     f1.Close();
     file0.Close();
     
   }

 }


}
Exemplo n.º 9
0
int main(int argc, char** argv) {

    SQLite::Database db("corpus.db", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
    db.exec("PRAGMA temp_store_directory = '/data1/marcinjd';");

    db.exec("drop table if exists lines");
    db.exec("create table lines (_id integer, line0 text, line1 text);");

    boost::timer::auto_cpu_timer total;

    std::unique_ptr<boost::timer::auto_cpu_timer> t(new boost::timer::auto_cpu_timer());

    SQLite::Statement ps(db, "insert into lines values (?, ?, ?)");

    std::string line0, line1;
    size_t lines = 0;

    std::cerr << "Reading from " << argv[1] << " and " << argv[2] << std::endl;

    std::ifstream file0(argv[1]);
    std::ifstream file1(argv[2]);

    db.exec("begin;");
    while(marian::utils::GetLine(file0, line0)
          && marian::utils::GetLine(file1, line1)) {
      ps.bind(1, (int)lines);
      ps.bind(2, line0);
      ps.bind(3, line1);

      ps.exec();
      ps.reset();

      lines++;
      if(lines % 1000000 == 0) {
        std::cerr << "[" << lines << "]" << std::endl;
        t.reset(new boost::timer::auto_cpu_timer());

        db.exec("commit;");
        db.exec("begin;");
      }
    }
    db.exec("commit;");

    std::cerr << "[" << lines << "]" << std::endl;

    t.reset(new boost::timer::auto_cpu_timer());
    std::cerr << "creating index" << std::endl;
    db.exec("create unique index idx_line on lines (_id);");

    t.reset(new boost::timer::auto_cpu_timer());

    std::cout << "count : " << db.execAndGet("select count(*) from lines").getInt() << std::endl;
    t.reset(new boost::timer::auto_cpu_timer());

    int count = 0;
    SQLite::Statement sel(db, "select * from lines order by random();");
    t.reset(new boost::timer::auto_cpu_timer());
    while(sel.executeStep()) {
        // Demonstrate how to get some typed column value
        int id = sel.getColumn(0);
        std::string value0 = sel.getColumn(1);
        std::string value1 = sel.getColumn(2);

        if(count % 1000000 == 0)
            std::cout << count << " " << id << "\t" << value0 << "\t" << value1 << std::endl;
        count++;
    }

    return 0;
}
Exemplo n.º 10
0
void ThroughPut::InputManagement(){
    //QFile file("datain.txt");
    QFile file0("./Pilot_send_data/pilot_1200_im.txt");
    if (!file0.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug() << file0.errorString();
        qDebug() << "Last sentence is in QPSK Inputmanagement." << endl;

    }
    //qDebug() << QObject::tr("file text:") << endl << file.readAll();
    //char str[100];
    char str6[100];
    for( int i = 0 ; i < 1200 ; i++ ){
        file0.readLine(str6,100);
        double crr = 0;
        crr = char2int(str6);
        //qDebug() << "pilot2[ "<< i <<"][0] is :"<<crr;
        pilot2[i][1] = crr;
    }
  file0.close();

  QFile file5("./Pilot_send_data/pilot_1200_re.txt");
  if (!file5.open(QIODevice::ReadOnly | QIODevice::Text)){
      qDebug() << file5.errorString();
      qDebug() << "Last sentence is in QPSK Inputmanagement." << endl;

  }
  //qDebug() << QObject::tr("file text:") << endl << file.readAll();
  //char str[100];

  for( int i = 0 ; i < 1200 ; i++ ){
      file5.readLine(str6,100);
      double crr = 0;
      crr = char2int(str6);
      //qDebug() << "pilot2[ "<< i <<"][0] is :"<<crr;
      pilot2[i][0] = crr;
  }
file5.close();

    //QFile file("./pilot4_send_data/pilot4_1200_re.txt");
    QFile file("./16qam_data_new/data_im.txt");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug() << file.errorString();
        qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl;

    }
    //qDebug() << QObject::tr("file text:") << endl << file.readAll();
    //char str[100];
    char str[100];
    for( int i = 0 ; i < 1200 ; i++ ){
        file.readLine(str,100);
        double crr = 0;
        crr = char2int(str);
        //qDebug() << "pilot4[ "<< i <<"][0] is :"<<crr;
        pilot4[i][0] = crr;
    }

    //qDebug() << "last one is :"<< ThroughPut[9][0] ;
    file.close();

    //QFile file2("./pilot4_send_data/pilot4_1200_im.txt");
    QFile file2("./16qam_data_new/data_re.txt");
    if (!file2.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug() << file2.errorString();
        qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl;
    }
    //qDebug() << QObject::tr("file text:") << endl << file2.readAll();
    //char str[100];
    for( int i = 0 ; i < 1200 ; i++ ){
        file2.readLine(str,100);
        double crr = 0;
        crr = char2int(str);
        //qDebug() << "pilot4[ "<< i <<"][1] is :"<<crr;
        pilot4[i][1] = crr;
    }


    //qDebug() <<"apsk[0][0] is :"<< *(pdata) << endl;
    file2.close();


   // QFile file3("./16qam_data/data_re.txt");
    QFile file3("./16qam_data_new/data_re.txt");
    if (!file3.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug() << file3.errorString();
        qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl;

    }
    //qDebug() << QObject::tr("file text:") << endl << file.readAll();
    //char str[100];
    int cnt_2_500=0;
    for( int i = 0 ; i < 600 ; i++ ){
        file3.readLine(str,100);
        double crr = 0;
        if(i%6!=0){
        crr = char2double(str);
       // qDebug() << "re[ "<< i <<"][0] is :"<<crr;
        qam16_3[cnt_2_500][0] = crr;
        cnt_2_500++;
        }
    }

    //qDebug() << "last one is :"<< ThroughPut[9][0] ;
    file3.close();

   // QFile file4("./16qam_data/data_im.txt");
    QFile file4("./16qam_data_new/data_im.txt");
    if (!file4.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug() << file4.errorString();
        qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl;

    }
    //qDebug() << QObject::tr("file text:") << endl << file.readAll();
    //char str[100];
    int cnt_2_500_2;
    for( int i = 0 ; i < 600 ; i++ ){
        file4.readLine(str,100);
        double crr = 0;
        if(i%6!=0){
        crr = char2double(str);
        //qDebug() << "im[ "<< i <<"][0] is :"<<crr;
        qam16_3[cnt_2_500_2][1] = crr;
        cnt_2_500_2++;
        }
    }

    //qDebug() << "last one is :"<< ThroughPut[9][0] ;
    file4.close();







}
Exemplo n.º 11
0
void overlay_plots(const string& fFile0, const string& fFile1, const string& fPlot, const double fXmin, const double fXmax, const string& fXAxisLabel, const string& fName, const int logY) {
  
   TH1F *h[2];
 
   TFile file0(fFile0.c_str());
   h[0] = (TH1F*)file0.Get(fPlot.c_str()); 

   TFile file1(fFile1.c_str());
   h[1] = (TH1F*)file1.Get(fPlot.c_str()); 
   
//    double ymax = (h[0]->GetMaximum()>h[1]->GetMaximum()) ? h[0]->GetMaximum() : h[1]->GetMaximum();
   
   h[0]->GetXaxis()->SetTitle(fXAxisLabel.c_str());
   h[0]->GetXaxis()->SetRangeUser(fXmin,fXmax);
//    h[0]->GetYaxis()->SetRangeUser(0.5,1.25*ymax);

   h[0]->SetTitleOffset(1.2,"X");
   h[0]->GetXaxis()->SetTitleSize(0.04);
   h[0]->GetYaxis()->SetTitleSize(0.04);
   
   double scale = h[1]->GetEntries()/h[0]->GetEntries();
   h[0]->Scale(scale);
   
   TCanvas *c = new TCanvas("c","",800,800);
   c->cd();
  
   h[0]->SetLineWidth(3);
//    h[0]->SetLineStyle(4);
   h[0]->SetLineColor(kRed);
   h[0]->SetFillColor(kRed);
//    h[0]->SetMarkerSize(.6);
//    h[0]->SetMarkerStyle(26);
//    h[0]->SetMarkerColor(kRed);
   h[0]->Draw("hist");
   h[1]->SetLineWidth(3);
//    h[1]->SetLineStyle(3);
   h[1]->SetLineColor(kBlack);
//    h[1]->SetMarkerSize(.8);
   h[1]->SetMarkerStyle(20);
   h[1]->SetMarkerColor(kBlack);
   h[1]->Draw("sames");
   
   //update the current pad, needed to modify statboxes
   gPad->Update();
   
   // get the statboxes and set color
   TPaveStats *st1 = (TPaveStats*)h[0]->GetListOfFunctions()->FindObject("stats");
   st1->SetTextColor(kRed);
   st1->SetLineColor(kRed);
   st1->SetOptStat(1111111);
   TPaveStats *st2 = (TPaveStats*)h[1]->GetListOfFunctions()->FindObject("stats");
   st2->SetTextColor(kBlack);
   st2->SetLineColor(kBlack);
   st2->SetOptStat(1111111);

   // set the position of the statboxes
   double x1 = st1->GetX1NDC();
   double y1 = st1->GetY1NDC();
   double x2 = st1->GetX2NDC();
   double y2 = st1->GetY2NDC();
   //double xx = x2-x1;
   double yy = y2-y1;
   st2->SetX1NDC(x1);
   st2->SetY1NDC(y1-yy);
   st2->SetX2NDC(x2);
   st2->SetY2NDC(y1);
   gPad->Modified();
   
   TLegend *legend = new TLegend(.4,.91,.75,.99);
   legend->SetBorderSize(1);
   legend->SetFillColor(0);
   //    legend->SetFillStyle(0);
   legend->AddEntry(h[0],"MC","l");
   legend->AddEntry(h[1],"Data","l");
   legend->Draw();
   
   TLatex l;
   l.SetTextAlign(12);
   l.SetTextSize(0.04);
   l.SetTextFont(62);
   l.SetNDC();
   l.DrawLatex(0.40,0.15,"CMS 2009 Preliminary");

   if(logY==1)
     c->SetLogy();
   
   string fileName = fName;
   c->SaveAs(fileName.c_str());
   
   delete legend;
   delete c;
}
Exemplo n.º 12
0
void scaling_by_n( std::string prefix, size_t dim, bool is_periodic,  Search_Factory::Search_Type search_type,
                  bool do_spoke = true, bool do_favored = false, bool do_two = false,
                  const double cutoff_t = 2., const size_t min_iter = 1, const size_t cutoff_n = 0,
                  bool do_bridson = false)
{
  // vary r, collect timings for each algorithm
  
  // Do at least min_iter runs of MPS   (set to 0 if no requirements)
  // Continue to do iterations until the time it takes is greater than cutoff_t              (set to 0 if no requirements)
  //   "  "  "                           number of samples produced is greater than cutoff_n (set to 0 if no requirements)
  //
  // Iterations will stop only when *all three* conditions are met
  
  Timing_Stats run_time;
  run_time.start_clock();

  // get file names
  std::stringstream file0ss, file1ss, file2ss, file3ss;
  
  // junk filenames in order to not overwrite any interesting data
  if (!do_spoke)
    file0ss << "00empty_";
  if (!do_favored)
    file1ss << "00empty_";
  if (!do_two)
    file2ss << "00empty_";
  if (!do_bridson)
    file3ss << "00empty_";
  
  file0ss << prefix << dim;
  file1ss << prefix << dim;
  file2ss << prefix << dim;
  file3ss << prefix << dim;
  if (is_periodic)
  {
    file0ss << "_P_";
    file1ss << "_P_";
    file2ss << "_P_";
    file3ss << "_P_";
  }
  else
  {
    file0ss << "_n_";
    file1ss << "_n_";
    file2ss << "_n_";
    file3ss << "_n_";
  }
  std::string search_s;
  switch (search_type)
  {
    case Search_Factory::ARRAY:
      search_s = "a";
      break;
    case Search_Factory::GRID:
      search_s = "g";
      break;
    case Search_Factory::RANGE:
      search_s = "r";
      break;
    case Search_Factory::TREE:
      search_s = "t";
      break;
    case Search_Factory::UNSPECIFIED:
      search_s = "u";
      break;
  }
  file0ss << search_s << "_0spoke.txt";
  file1ss << search_s << "_1favored.txt";
  file2ss << search_s << "_2two.txt";
  file3ss << search_s << "_3bridson.txt";
  
  // open files
  std::fstream file0( file0ss.str().c_str(), std::ios::out);
  std::fstream file1( file1ss.str().c_str(), std::ios::out);
  std::fstream file2( file2ss.str().c_str(), std::ios::out);
  std::fstream file3( file3ss.str().c_str(), std::ios::out);

  // header
  file0 << "0 " << dim << " " << is_periodic << " " << search_s <<   " spoke "     << dim << "d" << std::endl;
  file1 << "1 " << dim << " " << is_periodic << " " << search_s << " favored "     << dim << "d" << std::endl;
  file2 << "2 " << dim << " " << is_periodic << " " << search_s <<     " two "     << dim << "d" << std::endl;
  file3 << "3 " << dim << " " << is_periodic << " " << search_s <<     " bridson " << dim << "d" << std::endl;
  write_header(file0);
  write_header(file1);
  write_header(file2);
  write_header(file3);
  
  // number of seconds allowed
  // do one iteration past this value, which could take up to 4x as long if O(n^2)
//  const double cutoff = 540; // three minutes
//    const double cutoff = 180; // three minutes
//  const double cutoff = 24; // 2 seconds
//  const double cutoff = 4;
//  const double cutoff = 0.01; // testing
  
  // time taken last iter
  double t_spoke = 0.;
  double t_favored = 0.;
  double t_two = 0.;
  double t_bridson = 0.;
  
  // number of real samples produced last iter
  size_t n_spoke(0), n_favored(0), n_two(0), n_bridson(0);
  
  const double min_r0 = 1.; // MPS_Spoke::max_radius( is_periodic ); //  0.161;
  const double min_r1 = 1.; // MPS_Favored::max_radius( is_periodic ); // 0.102;
  const double min_r2 = 1.; // MPS_Two_Spoke::max_radius( is_periodic); // 0.071;
  const double min_r3 = 1.; // MPS_Bridson::max_radius( is_periodic); // 0.071;

//  double first_n = 10;
//  double r = 1. / ( pow( first_n, 1. / (double) (dim) ));
//  double r = 1. - (1. / (4. * (double) dim ) );
//  if ( r > min_r0 )
    double r = min_r0;
  
  size_t spoke_iter(0), favored_iter(0), two_iter(0), bridson_iter(0);
  
  for (int i=0; i<1000; ++i)
  {
    std::cout << std::endl << "scaling_by_n r = " << r  << std::endl;
    {
      if ( do_spoke && (r <= min_r0) && (more_t( t_spoke, cutoff_t) || more_n( n_spoke, cutoff_n ) || more_n( spoke_iter, min_iter)) )
      {
        t_spoke = run_spokes(file0, dim, is_periodic, r, search_type, n_spoke);
        spoke_iter++;
      }
      if ( do_favored && (r <= min_r1) && (more_t( t_favored, cutoff_t) || more_n( n_favored, cutoff_n ) || more_n( favored_iter, min_iter)))
      {
        t_favored = run_favored(file1, dim, is_periodic, r, search_type, n_favored);
        favored_iter++;
      }
      if ( do_two && (r <= min_r2) && (more_t( t_two, cutoff_t) || more_n( n_two, cutoff_n ) || more_n( two_iter, min_iter)) )
      {
        t_two = run_two(file2, dim, is_periodic, r, search_type, n_two);
        two_iter++;
      }
      if ( do_bridson && (r <= min_r3) && (more_t( t_bridson, cutoff_t) || more_n( n_bridson, cutoff_n ) || more_n( bridson_iter, min_iter)) )
      {
        t_bridson = run_bridson(file3, dim, is_periodic, r, search_type, n_bridson);
        bridson_iter++;
      }
    }
    
    // double n each time
    // this could quadruple time
    //    r *= 1./sqrt(2);
    r *= 1./ pow(2., 1./double(dim));
    
    if ( 1/r > 20000 )
      break;
  }
  
  file0.close();
  file1.close();
  file2.close();
  file3.close();  
  
  run_time.collect_stats();
  std::cout << "scaling_by_n runtime = " << run_time.cpu_time << std::endl;
}
Exemplo n.º 13
0
void Reprojector::load(IPC& ipc, bool flipped)
{
	bool serial_first_non_zero = false;
	string serial = "";

	for (int i = 4; i < 10; ++i)
	{
		string str_temp = "";
		str_temp += serial_number[i];

		if (!serial_first_non_zero && str_temp != "0")
			serial_first_non_zero = true;

		if (serial_first_non_zero)
			serial += serial_number[i];
	}

	bool has_complete_calib_data = false;

	if (directory_exists(data_path_current_module))
		if (file_exists(data_path_current_module + "\\0.jpg"))
			if (file_exists(data_path_current_module + "\\1.jpg"))
				if (file_exists(data_path_current_module + "\\stereoCalibData.txt"))
					if (file_exists(data_path_current_module + "\\rect0.txt"))
						if (file_exists(data_path_current_module + "\\rect1.txt"))
							has_complete_calib_data = true;

	if (!has_complete_calib_data)
	{
		static bool block_thread = true;
		ipc.send_message("menu_plus", "show window", "");
		ipc.get_response("menu_plus", "show download", "", [](const string message_body)
		{
			COUT << "unblock" << endl;
			block_thread = false;
		});
		
		while (block_thread)
		{
			ipc.update();
			Sleep(100);
		}

        create_directory(data_path);
        create_directory(data_path_current_module);

		copy_file(executable_path + "\\rectifier.exe", data_path_current_module + "\\rectifier.exe");
		copy_file(executable_path + "\\opencv_core249.dll", data_path_current_module + "\\opencv_core249.dll");
		copy_file(executable_path + "\\opencv_highgui249.dll", data_path_current_module + "\\opencv_highgui249.dll");
		copy_file(executable_path + "\\opencv_imgproc249.dll", data_path_current_module + "\\opencv_imgproc249.dll");
		copy_file(executable_path + "\\opencv_calib3d249.dll", data_path_current_module + "\\opencv_calib3d249.dll");
		copy_file(executable_path + "\\opencv_flann249.dll", data_path_current_module + "\\opencv_flann249.dll");
		copy_file(executable_path + "\\opencv_features2d249.dll", data_path_current_module + "\\opencv_features2d249.dll");

		//http://s3-us-west-2.amazonaws.com/ractiv.com/data/
		//http://d2i9bzz66ghms6.cloudfront.net/data/

		string param0 = "http://s3-us-west-2.amazonaws.com/ractiv.com/data/" + serial + "/0.jpg";
		string param1 = data_path_current_module + "\\0.jpg";

		string* serial_ptr = &serial;
		IPC* ipc_ptr = &ipc;
		ipc.get_response("menu_plus", "download", param0 + "`" + param1, [serial_ptr, ipc_ptr](const string message_body)
		{
			if (message_body == "false")
				ipc_ptr->send_message("daemon_plus", "exit", "");
			else
			{
				string param0 = "http://s3-us-west-2.amazonaws.com/ractiv.com/data/" + *serial_ptr + "/1.jpg";
				string param1 = data_path_current_module + "\\1.jpg";

				ipc_ptr->get_response("menu_plus", "download", param0 + "`" + param1, [serial_ptr, ipc_ptr](const string message_body)
				{
					if (message_body == "false")
						ipc_ptr->send_message("daemon_plus", "exit", "");
					else
					{
						string param0 = "http://s3-us-west-2.amazonaws.com/ractiv.com/data/" + *serial_ptr + "/stereoCalibData.txt";
						string param1 = data_path_current_module + "\\stereoCalibData.txt";

						ipc_ptr->get_response("menu_plus", "download", param0 + "`" + param1, [serial_ptr, ipc_ptr](const string message_body)
						{
							if (message_body == "false")
								ipc_ptr->send_message("daemon_plus", "exit", "");
							else
							{
								bool has_complete_calib_data = false;
								while (!has_complete_calib_data)
								{
									system(("cd " + cmd_quote + data_path_current_module + cmd_quote + " && rectifier.exe").c_str());

									if (directory_exists(data_path_current_module))
										if (file_exists(data_path_current_module + "\\0.jpg"))
											if (file_exists(data_path_current_module + "\\1.jpg"))
												if (file_exists(data_path_current_module + "\\stereoCalibData.txt"))
													if (file_exists(data_path_current_module + "\\rect0.txt"))
														if (file_exists(data_path_current_module + "\\rect1.txt"))
															has_complete_calib_data = true;
								}

								block_thread = false;
							}
						});
					}
				});
			}
		});

		block_thread = true;

		while (block_thread)
		{
			ipc.update();
			Sleep(100);
		}
	}

	ifstream file_stereo_calib_data(data_path_current_module + "\\stereoCalibData.txt");

	bool is_number_new = false;
	bool is_number_old = false;

	int block_count = 0;
	int block[4];

	vector<Point> disparity_data;

	string str_num_temp = "";
	string disparities_string = "";
	
	while (getline(file_stereo_calib_data, disparities_string))
	{
		const int i_max = disparities_string.length();
		for (int i = 0; i < i_max; ++i)
		{
			string str_temp = "";
			str_temp += disparities_string[i];

			if (str_temp != "," && str_temp != ";")
				is_number_new = true;
			else
				is_number_new = false;

			if (is_number_new)
			{
				if (!is_number_old)
					str_num_temp = str_temp;
				else
					str_num_temp += str_temp;
			}
			else if (is_number_old)
			{
				block[block_count] = stoi(str_num_temp);
				++block_count;
			}

			if (block_count == 3)
			{
				bool found = false;

				for (int a = 0; a < disparity_data.size(); ++a)
				{
					if (disparity_data[a].x == block[0])
					{
						found = true;
						disparity_data[a].y = (disparity_data[a].y + abs(block[1] - block[2])) / 2;
					}
					else if (disparity_data[a].y == abs(block[1] - block[2]))
					{
						found = true;
						disparity_data[a].x = min(disparity_data[a].x, block[0]);
					}
				}
				if (!found)
					disparity_data.push_back(Point(block[0], abs(block[1] - block[2])));

				block_count = 0;
			}

			is_number_old = is_number_new;
		}
	}
	sort(disparity_data.begin(), disparity_data.end(), compare_point_x());

	double *t, *y;

	t = new double[disparity_data.size()];
	y = new double[disparity_data.size()];

	for (unsigned int a = 0; a < disparity_data.size(); a++)
	{
		t[a] = (double)(disparity_data[a].y);
		y[a] = (double)(disparity_data[a].x);
	}
	CCurveFitting cf;
	cf.curve_fitting4(t, disparity_data.size(), y, &a_out, &b_out, &c_out, &d_out);

	delete []t;
	delete []y;

	ifstream file0(data_path_current_module + "\\rect0.txt");
	is_number_new = false;
	is_number_old = false;
	block_count = 0;

	rect_mat0 = new Point*[WIDTH_LARGE];
	for (int i = 0; i < WIDTH_LARGE; ++i)
		rect_mat0[i] = new Point[HEIGHT_LARGE];

	string rect0_string = "";
	while (getline(file0, rect0_string))
	{
		const int i_max = rect0_string.length();
		for (int i = 0; i < i_max; ++i)
		{
			string str_temp = "";
			str_temp += rect0_string[i];

			if (str_temp != " " && str_temp != "," && str_temp != ";")
				is_number_new = true;
			else
				is_number_new = false;

			if (is_number_new)
			{
				if (!is_number_old)
					str_num_temp = str_temp;
				else
					str_num_temp += str_temp;
			}
			else if (is_number_old)
			{
				block[block_count] = stoi(str_num_temp);
				++block_count;
			}
			if (block_count == 4)
			{
				if (!flipped)
					rect_mat0[block[0]][block[1]] = Point(block[2], block[3]);
				else
					rect_mat0[block[0]][HEIGHT_LARGE_MINUS - block[1]] = Point(block[2], block[3]);

				block_count = 0;
			}
			is_number_old = is_number_new;
		}
	}
	ifstream file1(data_path_current_module + "\\rect1.txt");
	is_number_new = false;
	is_number_old = false;
	block_count = 0;

	rect_mat1 = new Point*[WIDTH_LARGE];
	for (int i = 0; i < WIDTH_LARGE; ++i)
		rect_mat1[i] = new Point[HEIGHT_LARGE];

	string rect1_string = "";
	while (getline(file1, rect1_string))
	{
		const int i_max = rect1_string.length();
		for (int i = 0; i < i_max; ++i)
		{
			string str_temp = "";
			str_temp += rect1_string[i];

			if (str_temp != " " && str_temp != "," && str_temp != ";")
				is_number_new = true;
			else
				is_number_new = false;

			if (is_number_new)
			{
				if (!is_number_old)
					str_num_temp = str_temp;
				else
					str_num_temp += str_temp;
			}
			else if (is_number_old)
			{
				block[block_count] = stoi(str_num_temp);
				++block_count;
			}
			if (block_count == 4)
			{
				if (!flipped)
					rect_mat1[block[0]][block[1]] = Point(block[2], block[3]);
				else
					rect_mat1[block[0]][HEIGHT_LARGE_MINUS - block[1]] = Point(block[2], block[3]);

				block_count = 0;
			}
			is_number_old = is_number_new;
		}
	}
}
Exemplo n.º 14
0
void overlay_plotsPAS(const string& fFile0, const string& fFile1, const string& fPlot0, const string& fPlot1, const double fXmin, const double fXmax, const double fYmin, const double fYmax,const string& fXAxisLabel, const string& fYAxisLabel, const string& fTitle, const string& fName, const int doFit) {
  
   gStyle->SetOptStat(kTRUE);
   gStyle->SetOptTitle(1);
 
   TH2F *h2[4];
   TH1F *h[2];
   
   TFile file0(fFile0.c_str());
   h2[0] = (TH2F*)file0.Get(fPlot0.c_str()); 
   h2[1] = (TH2F*)file0.Get(fPlot1.c_str()); 
   
   h2[0]->Add(h2[1],1.0);
   
   TFile file1(fFile1.c_str());
   h2[2] = (TH2F*)file1.Get(fPlot0.c_str()); 
   h2[3] = (TH2F*)file1.Get(fPlot1.c_str()); 
   
   h2[2]->Add(h2[3],1.0);
   
   h[0] = new TH1F("h0","h0",h2[0]->GetXaxis()->GetNbins(),h2[0]->GetXaxis()->GetXmin(),h2[0]->GetXaxis()->GetXmax());
   h[1] = new TH1F("h1","h1",h2[2]->GetXaxis()->GetNbins(),h2[2]->GetXaxis()->GetXmin(),h2[2]->GetXaxis()->GetXmax());
   
   TCanvas *c0 = new TCanvas("c0");
   c0->cd();
   
//    for(Int_t i=1; i<=h2[0]->GetNbinsX(); i++) {
   for(Int_t i=1; i<=14; i++) {

     string title;
    
     if( fTitle.find("900") != string::npos ) title = Form("h_SIM_900GeV_%i",i);
     else if( fTitle.find("2360") != string::npos ) title = Form("h_SIM_2360GeV_%i",i);
    
     TH1D* h_temp = h2[0]->ProjectionY(title.c_str(), i, i, "e");
     h_temp->SetTitle(title.c_str());
     h_temp->GetXaxis()->SetTitle("#slash{E}_{x,y}");
     
     Int_t ngroup = 1;

     if( fTitle.find("900") != string::npos ) {
       if(i==10) ngroup = 2;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     } else if( fTitle.find("2360") != string::npos ) {
       if(i==10) ngroup = 4;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     }
     
     h_temp->Rebin(ngroup);
     
     TF1* f1= new TF1("f1", "gaus", h_temp->GetXaxis()->GetXmin(), h_temp->GetXaxis()->GetXmax());
     f1->SetParameters(h_temp->GetBinContent(h_temp->GetMaximumBin()),h_temp->GetMean(),h_temp->GetRMS());
     h_temp->Fit("f1","R", "",h_temp->GetXaxis()->GetXmin(),h_temp->GetXaxis()->GetXmax());

//      h_temp->Draw();
//      c0->SetLogy();
//      c0->SaveAs((title+".png").c_str());
     
     h[0]->SetBinContent(i, f1->GetParameter(2));
     h[0]->SetBinError(i, f1->GetParError(2));
      
     delete f1;
     delete h_temp;
   }
   
//    for(Int_t i=1; i<=h2[2]->GetNbinsX(); i++) {
   for(Int_t i=1; i<=14; i++) {
    
     string title;
    
     if( fTitle.find("900") != string::npos ) title = Form("h_DATA_900GeV_%i",i);
     else if( fTitle.find("2360") != string::npos ) title = Form("h_DATA_2360GeV_%i",i);
    
     TH1D* h_temp = h2[2]->ProjectionY(title.c_str(), i, i, "e");
     h_temp->SetTitle(title.c_str());
     h_temp->GetXaxis()->SetTitle("#slash{E}_{x,y}");
          
     Int_t ngroup = 1;

     if( fTitle.find("900") != string::npos ) {
       if(i==10) ngroup = 2;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     } else if( fTitle.find("2360") != string::npos ) {
       if(i==10) ngroup = 4;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     }
     
     h_temp->Rebin(ngroup);
  
     TF1* f1= new TF1("f1", "gaus", h_temp->GetXaxis()->GetXmin(), h_temp->GetXaxis()->GetXmax());
     f1->SetParameters(h_temp->GetBinContent(h_temp->GetMaximumBin()),h_temp->GetMean(),h_temp->GetRMS());
     h_temp->Fit("f1","R", "",h_temp->GetXaxis()->GetXmin(),h_temp->GetXaxis()->GetXmax());
  
//      h_temp->Draw();
//      c0->SetLogy();
//      c0->SaveAs((title+".png").c_str());
     
     h[1]->SetBinContent(i, f1->GetParameter(2));
     h[1]->SetBinError(i, f1->GetParError(2));
      
     delete f1;
     delete h_temp;
   }
   
   h[0]->SetTitle(fTitle.c_str());
   h[0]->GetXaxis()->SetTitle(fXAxisLabel.c_str());
   h[0]->GetYaxis()->SetTitle(fYAxisLabel.c_str());
   h[0]->GetXaxis()->SetRangeUser(fXmin,fXmax);
   h[0]->GetYaxis()->SetRangeUser(fYmin,fYmax);

   h[0]->SetTitleOffset(1.,"X");
   h[0]->SetTitleOffset(1.,"Y");
//    h[0]->GetXaxis()->SetTitleSize(0.04);
//    h[0]->GetYaxis()->SetTitleSize(0.04);

   gStyle->SetOptStat(kFALSE);
   gStyle->SetOptTitle(0);

//    TCanvas *c = new TCanvas("c","",1200,800);
   TCanvas *c = new TCanvas("c");
   c->cd();
  
   h[0]->SetLineWidth(2);
   h[0]->SetLineStyle(2);
   h[0]->SetLineColor(kRed);
   h[0]->SetFillColor(kRed);
   h[0]->SetMarkerSize(1.);
   h[0]->SetMarkerStyle(26);
   h[0]->SetMarkerColor(kRed);
   h[0]->Draw("");
   h[1]->SetLineWidth(2);
//    h[1]->SetLineStyle(3);
   h[1]->SetLineColor(kBlack);
   h[1]->SetMarkerSize(1.);
   h[1]->SetMarkerStyle(20);
   h[1]->SetMarkerColor(kBlack);
   h[1]->Draw("same");
   
   TLegend *legend = new TLegend(.61,.26,.91,.41);
   legend->SetBorderSize(1);
   legend->SetFillColor(0);
//    legend->SetFillStyle(0);
   legend->SetTextFont(42);
   legend->AddEntry(h[1],"Data","lp");
   legend->AddEntry(h[0],"Simulation","lp");
   legend->Draw();
   
   TLatex l;
   l.SetTextAlign(12);
   l.SetTextSize(0.04);
   l.SetTextFont(62);
   l.SetNDC();
   l.DrawLatex(0.15,0.88,("#splitline{CMS Preliminary 2009}{#sqrt{s}="+fTitle+"}").c_str());

   c->SetGridx();
   c->SetGridy();
   
   string fileName = fName;
   c->SaveAs(fileName.c_str());
   
   delete legend;
   delete h[0];
   delete h[1];
   delete c0;
   delete c;
}
Exemplo n.º 15
0
void overlay_plots(const string& fFile0, const string& fFile1, const string& fPlot0, const string& fPlot1, const double fXmin, const double fXmax, const double fYmin, const double fYmax,const string& fXAxisLabel, const string& fYAxisLabel, const string& fTitle, const string& fName, const int doFit) {
  
   gStyle->SetOptStat(kFALSE);
 
   TH2F *h2[4];
   TH1F *h[2];
   
   TFile file0(fFile0.c_str());
   h2[0] = (TH2F*)file0.Get(fPlot0.c_str()); 
   h2[1] = (TH2F*)file0.Get(fPlot1.c_str()); 
   
   h2[0]->Add(h2[1],1.0);
   
   TFile file1(fFile1.c_str());
   h2[2] = (TH2F*)file1.Get(fPlot0.c_str()); 
   h2[3] = (TH2F*)file1.Get(fPlot1.c_str()); 
   
   h2[2]->Add(h2[3],1.0);
   
   h[0] = new TH1F("h0","h0",h2[0]->GetXaxis()->GetNbins(),h2[0]->GetXaxis()->GetXmin(),h2[0]->GetXaxis()->GetXmax());
   h[1] = new TH1F("h1","h1",h2[2]->GetXaxis()->GetNbins(),h2[2]->GetXaxis()->GetXmin(),h2[2]->GetXaxis()->GetXmax());
   
//    for(Int_t i=1; i<=h2[0]->GetNbinsX(); i++) {
     for(Int_t i=1; i<=14; i++) {

     TH1D* h_temp = h2[0]->ProjectionY("h_temp", i, i, "e");

     Int_t ngroup = 1;

     if( fTitle.find("900") != string::npos ) {
       if(i==10) ngroup = 2;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     } else if( fTitle.find("2360") != string::npos ) {
       if(i==10) ngroup = 4;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     }
     
     h_temp->Rebin(ngroup);
     
     TF1* f1= new TF1("f1", "gaus", h_temp->GetXaxis()->GetXmin(), h_temp->GetXaxis()->GetXmax());
     f1->SetParameters(h_temp->GetBinContent(h_temp->GetMaximumBin()),h_temp->GetMean(),h_temp->GetRMS());
     
     h_temp->Fit("f1","R", "",h_temp->GetXaxis()->GetXmin(),h_temp->GetXaxis()->GetXmax());
  
     h[0]->SetBinContent(i, f1->GetParameter(2));
     h[0]->SetBinError(i, f1->GetParError(2));
      
     delete f1;
     delete h_temp;
   }
   
//    for(Int_t i=1; i<=h2[2]->GetNbinsX(); i++) {
   for(Int_t i=1; i<=14; i++) {
    
     TH1D* h_temp = h2[2]->ProjectionY("h_temp", i, i, "e");
     
     Int_t ngroup = 1;

     if( fTitle.find("900") != string::npos ) {
       if(i==10) ngroup = 2;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     } else if( fTitle.find("2360") != string::npos ) {
       if(i==10) ngroup = 4;
       else if(i==11) ngroup = 4;
       else if(i==12) ngroup = 4;
       else if(i==13) ngroup = 4;
       else if(i==14) ngroup = 8;
       else if(i==15) ngroup = 8;
     }
     
     h_temp->Rebin(ngroup);
  
     TF1* f1= new TF1("f1", "gaus", h_temp->GetXaxis()->GetXmin(), h_temp->GetXaxis()->GetXmax());
     f1->SetParameters(h_temp->GetBinContent(h_temp->GetMaximumBin()),h_temp->GetMean(),h_temp->GetRMS());
     h_temp->Fit("f1","R", "",h_temp->GetXaxis()->GetXmin(),h_temp->GetXaxis()->GetXmax());
  
     h[1]->SetBinContent(i, f1->GetParameter(2));
     h[1]->SetBinError(i, f1->GetParError(2));
      
     delete f1;
     delete h_temp;
   }
   
   h[1]->SetTitle(fTitle.c_str());
   h[1]->GetXaxis()->SetTitle(fXAxisLabel.c_str());
   h[1]->GetYaxis()->SetTitle(fYAxisLabel.c_str());
   h[1]->GetXaxis()->SetRangeUser(fXmin,fXmax);
   h[1]->GetYaxis()->SetRangeUser(fYmin,fYmax);

   h[1]->SetTitleOffset(1.,"X");
   h[1]->SetTitleOffset(1.,"Y");
//    h[1]->GetXaxis()->SetTitleSize(0.04);
//    h[1]->GetYaxis()->SetTitleSize(0.04);
   
   TCanvas *c = new TCanvas("c","",1200,800);
//    TCanvas *c = new TCanvas("c");
   c->cd();

   TF1 *fit = new TF1("fit","sqrt(pow([0],2)+pow([1],2)*(x-[3])+pow([2]*(x-[3]),2))",fXmin,(fXmax+1));
   fit->SetParName(0, "A");
   fit->SetParameter(0, 0.5);
   fit->SetParLimits(0, 0.1, 2);
   fit->SetParName(1, "B");
   fit->SetParameter(1, 0.5);
   fit->SetParLimits(1, 0, 1.5);
   fit->SetParName(2, "C");
   fit->SetParameter(2, 0.02);
   fit->SetParLimits(2, 0, 0.2);
   fit->SetParName(3, "D");
   fit->SetParameter(3, 3);
   fit->SetParLimits(3, 2, 5);
//    fit->FixParameter(3, 0);

   if(doFit==1) h[1]->Fit("fit","RV");

   h[0]->SetLineWidth(2);
   h[0]->SetLineStyle(2);
   h[0]->SetLineColor(kRed);
   h[0]->SetFillColor(kRed);
//    h[0]->SetMarkerSize(.6);
   h[0]->SetMarkerStyle(26);
   h[0]->SetMarkerColor(kRed);
   h[1]->SetLineWidth(2);
//    h[1]->SetLineStyle(3);
   h[1]->SetLineColor(kBlack);
//    h[1]->SetMarkerSize(.8);
   h[1]->SetMarkerStyle(20);
   h[1]->SetMarkerColor(kBlack);
   h[1]->Draw("");
   h[0]->Draw("same");
   if(doFit==1) fit->Draw("same");
   
   TLegend *legend = new TLegend(.65,.25,.95,.4);
   legend->SetBorderSize(0);
   legend->SetFillColor(0);
   legend->SetFillStyle(0);
   legend->SetTextFont(62);
   legend->AddEntry(h[1],"Data","lp");
   legend->AddEntry(h[0],"Simulation","lp");
   legend->Draw();
   
   TLatex l;
   l.SetTextAlign(12);
   l.SetTextSize(0.05);
   l.SetTextFont(62);
   l.SetNDC();
   l.DrawLatex(0.14,0.84,"CMS 2009 Preliminary");
   l.DrawLatex(0.14,0.79,("#sqrt{s}="+fTitle).c_str());
   l.DrawLatex(0.12,0.5,"f(x)=#sqrt{A^{2}+B^{2}(x-D)+C^{2}(x-D)^{2}}");

   c->SetGridx();
   c->SetGridy();

   c->SaveAs(fName.c_str());
   
   delete legend;
   delete h[0];
   delete h[1];
   delete c;
}
Exemplo n.º 16
0
void overlay_plots(const string& fFile0, const string& fFile1, const string& fFile2, const string& fFile3, const string& fFile4, const string& fPlot0, const string& fPlot1, const string& fPlot2, const string& fPlot3, const string& fPlot4, const double fXmin, const double fXmax, const string& fXAxisLabel, const string& fName, const int logY, const int rescale, const double cutValue0, const double cutValue1, const string& label) {
  
  TH1F *h[5];
 
  TFile file0(fFile0.c_str());
  h[0] = (TH1F*)file0.Get(fPlot0.c_str()); 

  TFile file1(fFile1.c_str());
  h[1] = (TH1F*)file1.Get(fPlot1.c_str()); 

  TFile file2(fFile2.c_str());
  h[2] = (TH1F*)file2.Get(fPlot2.c_str()); 

  TFile file3(fFile3.c_str());
  h[3] = (TH1F*)file3.Get(fPlot3.c_str()); 
   
  TFile file4(fFile4.c_str());
  h[4] = (TH1F*)file4.Get(fPlot4.c_str()); 

  h[0]->Rebin(1);
  h[1]->Rebin(1);
  h[2]->Rebin(1);
  h[3]->Rebin(1);
  h[4]->Rebin(1);

  //    double ymax = (h[0]->GetMaximum()>h[1]->GetMaximum()) ? h[0]->GetMaximum() : h[1]->GetMaximum();
   
  h[0]->GetXaxis()->SetTitle(fXAxisLabel.c_str());
  h[0]->GetXaxis()->SetRangeUser(fXmin,fXmax);
  //    h[0]->GetYaxis()->SetRangeUser(0.5,1.25*ymax);

  h[0]->SetTitleOffset(1.2,"X");
  h[0]->GetXaxis()->SetTitleSize(0.04);
  h[0]->GetYaxis()->SetTitleSize(0.04);

  if(rescale) 
    {  

       if (h[0]->Integral()!=0)
	h[0]->Scale(1/h[0]->Integral());

       //----------------------------       
//        if (h[1]->Integral()!=0)
// 	 h[1]->Scale(1/h[1]->Integral());

//        if (h[2]->Integral()!=0)
// 	 h[2]->Scale(1/h[2]->Integral());
       //----------------------------       

       if (h[3]->Integral()!=0)
	 h[3]->Scale(1/h[3]->Integral());
 
       if (h[4]->Integral()!=0)
	 h[4]->Scale(1/h[4]->Integral());

    }

  TCanvas *c = new TCanvas("c","",800,800);
  c->cd();
  c->Range(-0.4638998,-0.01028103,4.210331,0.09111118);
  c->SetRightMargin(0.2286432);

  h[0]->SetLineWidth(3);
  //    h[0]->SetLineStyle(4);
  h[0]->SetLineColor(kRed);
  h[0]->SetFillColor(kRed);
  h[0]->SetFillStyle(3002);
  //    h[0]->SetMarkerSize(.6);
  //    h[0]->SetMarkerStyle(26);
  //    h[0]->SetMarkerColor(kRed);
  h[0]->Draw("hist");

  h[1]->SetLineWidth(3);
  //    h[1]->SetLineStyle(3);
  h[1]->SetLineColor(kBlack);
  //    h[1]->SetMarkerSize(.8);
  h[1]->SetMarkerStyle(20);
  h[1]->SetMarkerColor(kBlack);
  //----------------------------       
  //h[1]->Draw("sameshist");
  //----------------------------       

  h[2]->SetLineWidth(3);
  h[2]->SetLineStyle(3);
  h[2]->SetLineColor(kBlack);
  //    h[1]->SetMarkerSize(.8);
  h[2]->SetMarkerStyle(20);
  h[2]->SetMarkerColor(kBlack);
  //----------------------------       
  //h[2]->Draw("sameshist");
  //----------------------------       

  h[3]->SetLineWidth(3);
  h[3]->SetLineStyle(4);
  h[3]->SetLineColor(kBlack);
  //    h[1]->SetMarkerSize(.8);
  h[3]->SetMarkerStyle(20);
  h[3]->SetMarkerColor(kBlack);
  h[3]->Draw("sameshist");

  h[4]->SetLineWidth(3);
  h[4]->SetLineStyle(5);
  h[4]->SetLineColor(kBlack);
  //    h[1]->SetMarkerSize(.8);
  h[4]->SetMarkerStyle(20);
  h[4]->SetMarkerColor(kBlack);
  h[4]->Draw("sameshist");
    
  double maximum = 0;
  if( h[0]->GetMaximum() > maximum )
    maximum = h[0]->GetMaximum() ;
  //-------------------------------
  //   if( h[1]->GetMaximum() > maximum )
  //     maximum = h[1]->GetMaximum();
  //   if( h[2]->GetMaximum() > maximum )
  //     maximum = h[2]->GetMaximum();
  //-------------------------------
  if( h[3]->GetMaximum() > maximum )
    maximum = h[3]->GetMaximum();
  if( h[4]->GetMaximum() > maximum )
    maximum = h[4]->GetMaximum();
  
  h[0]->GetYaxis()->SetRangeUser(0,maximum+maximum*0.1);

  //update the current pad, needed to modify statboxes
  gPad->Update();
   
  // get the statboxes and set color
  TPaveStats *st1 = (TPaveStats*)h[0]->GetListOfFunctions()->FindObject("stats");
  st1->SetTextColor(kRed);
    st1->SetLineColor(kRed);
  st1->SetOptStat(1111111);
  //------------------------------
  //   TPaveStats *st2 = (TPaveStats*)h[1]->GetListOfFunctions()->FindObject("stats");
  //   st2->SetTextColor(kBlack);
  //   st2->SetLineColor(kBlack);
  //   st2->SetOptStat(1111111);
  //   TPaveStats *st3 = (TPaveStats*)h[2]->GetListOfFunctions()->FindObject("stats");
  //   st3->SetTextColor(kBlack);
  //   st3->SetLineColor(kBlack);
  //   st3->SetOptStat(1111111);
  //------------------------------
  TPaveStats *st4 = (TPaveStats*)h[3]->GetListOfFunctions()->FindObject("stats");
  st4->SetTextColor(kBlack);
  st4->SetLineColor(kBlack);
  st4->SetOptStat(1111111);
  TPaveStats *st5 = (TPaveStats*)h[4]->GetListOfFunctions()->FindObject("stats");
  st5->SetTextColor(kBlack);
  st5->SetLineColor(kBlack);
  st5->SetOptStat(1111111);


  // set the position of the statboxes
  double x1 = st1->GetX1NDC();
  double y1 = st1->GetY1NDC();
  double x2 = st1->GetX2NDC();
  double y2 = st1->GetY2NDC();
  //double xx = x2-x1;
  double yy = y2-y1;
  //--------------------------
  //   st2->SetX1NDC(x1);
  //   st2->SetY1NDC(y1-yy);
  //   st2->SetX2NDC(x2);
  //   st2->SetY2NDC(y1);
  //   st3->SetX1NDC(x1);
  //   st3->SetY1NDC(y1-yy-yy);
  //   st3->SetX2NDC(x2);
  //   st3->SetY2NDC(y1-yy);
  //--------------------------
  st4->SetX1NDC(x1);
  st4->SetY1NDC(y1-yy-yy-yy);
  st4->SetX2NDC(x2);
  st4->SetY2NDC(y1-yy-yy);
  st5->SetX1NDC(x1);
  st5->SetY1NDC(y1-yy-yy-yy-yy);
  st5->SetX2NDC(x2);
  st5->SetY2NDC(y1-yy-yy-yy);
  gPad->Modified();
   
  TLegend *legend = new TLegend(.4,.91,.75,.99);
  legend->SetBorderSize(1);
  legend->SetFillColor(0);
  //    legend->SetFillStyle(0);
  legend->AddEntry(h[0],"SM background","l");
  //--------------------------
  //   legend->AddEntry(h[1],"Axigluon + W , M = 150 GeV","l");
  //   legend->AddEntry(h[2],"Axigluon + W , M = 500 GeV","l");
  //--------------------------
  legend->AddEntry(h[3],"Axigluon + W , M = 1000 GeV","l");
  legend->AddEntry(h[4],"Axigluon + W , M = 1500 GeV","l");
  legend->Draw();

  //   TLine line0(cutValue0,0,cutValue0,h[1]->GetMaximum());
  //   line0.SetLineColor(kRed);
  //   line0.Draw("same");
  
  //   TLine line1(cutValue1,0,cutValue1,h[1]->GetMaximum());
  //   line1.SetLineColor(kRed);
  //   line1.Draw("same");
   
  TLatex l;
  l.SetTextAlign(12);
  l.SetTextSize(0.04);
  l.SetTextFont(62);
  l.SetNDC();
  l.DrawLatex(0.6,0.8,label.c_str());

  if(logY==1)
    c->SetLogy();
   
  string fileName = fName;
  c->SaveAs(fileName.c_str());
   
  delete legend;
  delete c;
}