示例#1
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int main(int argc, char** argv)
{
  qDebug() << "Starting Ph to HDF5 Merging...";

// Instantiate the QCoreApplication that we need to get the current path and load plugins.
  QCoreApplication app(argc, argv);
  QCoreApplication::setOrganizationName("BlueQuartz Software");
  QCoreApplication::setOrganizationDomain("bluequartz.net");
  QCoreApplication::setApplicationName("PhToHDF5");

  std::cout << "PhToHDF5 Starting. Version " << SIMPLib::Version::PackageComplete().toStdString() << std::endl;


  // Register all the filters including trying to load those from Plugins
  FilterManager::Pointer fm = FilterManager::Instance();
  SIMPLibPluginLoader::LoadPluginFilters(fm.get());

  // Send progress messages from PipelineBuilder to this object for display
  QMetaObjectUtilities::RegisterMetaTypes();

  try
  {
    // Handle program options passed on command line.
    TCLAP::CmdLine cmd("PhToHDF5", ' ', SIMPLib::Version::Complete().toStdString());

    TCLAP::ValueArg<std::string> phFileArg( "p", "phfile", "Ph Input File", true, "", "Ph Input File");
    cmd.add(phFileArg);

    TCLAP::ValueArg<std::string> angleFileArg( "e", "eulerfile", "Euler Angle File", false, "", "Euler Angle File");
    cmd.add(angleFileArg);

    TCLAP::ValueArg<std::string> h5InputFileArg( "t", "h5file", "Target HDF5 File", true, "", "Target HDF5 File");
    cmd.add(h5InputFileArg);

    // Parse the argv array.
    cmd.parse(argc, argv);
    if (argc == 1)
    {
      qDebug() << "PhToHDF5 program was not provided any arguments. Use the --help argument to show the help listing.";
      return EXIT_FAILURE;
    }


    QString phFile = QString::fromStdString(phFileArg.getValue());
    QString h5File = QString::fromStdString(h5InputFileArg.getValue());

    QVector<int> voxels;
    int nx = 0;
    int ny = 0;
    int nz = 0;

    qDebug() << "Merging the FeatureID data from " << phFile;
    qDebug() << "  into";
    qDebug() << "file: " << h5File;


    qDebug() << "Reading the Ph data file....";
    int err = ReadPHFile(phFile, voxels, nx, ny, nz);
    if (err < 0)
    {
      return EXIT_FAILURE;
    }
    qDebug() << "Ph File has dimensions: " << nx << " x " << ny << " x " << nz;


    qDebug() << "Now Overwriting the FeatureID data set in the HDF5 file....";
    err = writePhDataToHDF5File(h5File, voxels, nz, ny, nz);
    if (err < 0)
    {
      qDebug() << "There was an error writing the feature id data. Check other errors for possible clues.";
      return EXIT_FAILURE;
    }
    qDebug() << "+ Done Writing the Feature ID Data.";


    QMap<int, EulerSet> gidToEulerMap;
    if (angleFileArg.getValue().empty() == false)
    {
      qDebug() << "Reading the Euler Angle Data....";
      err = ReadEulerFile(QString::fromStdString(angleFileArg.getValue()), gidToEulerMap);
      if (err < 0)
      {
        qDebug() << "Error Reading the Euler Angle File";
        return EXIT_FAILURE;
      }

      // Over Write the Euler Angles if the Euler File was supplied

      qDebug() << "Now Over Writing the Euler Angles data in the HDF5 file.....";
      int totalPoints = nx * ny * nz;
      int numComp = 3;
      // Loop over each Voxel getting its Feature ID and then setting the Euler Angle
      QVector<float> dataf(totalPoints * 3);
      for (int i = 0; i < totalPoints; ++i)
      {
        EulerSet& angle = gidToEulerMap[voxels[i]];
        dataf[i * 3] = angle.e0;
        dataf[i * 3 + 1] = angle.e1;
        dataf[i * 3 + 2] = angle.e2;
      }
      // This is going to be a 2 Dimension Table Data set.
      int32_t rank = 2;
      hsize_t dims[2] = {totalPoints, numComp};
      err = writeEulerDataToHDF5File(h5File, dataf, numComp, rank, dims);
      if (err < 0)
      {
        qDebug() << "There was an error writing the Euler Angle data. Check other errors for possible clues.";
        return EXIT_FAILURE;
      }
      qDebug() << "+ Done Writing the Euler Angle Data.";
    }

  }
  catch (TCLAP::ArgException& e) // catch any exceptions
  {
    std::cerr << " error: " << e.error() << " for arg " << e.argId();
    return EXIT_FAILURE;
  }
  qDebug() << "Successfully completed the merge.";

  return EXIT_SUCCESS;
}
void computeSmearingConstants(TString data, TString nonqcd, TString smeared) {

	//define signal and control regions
	vector<scaleFactor> m_regions;
	/*
	m_regions.push_back(scaleFactor("4jet_meff500_2","4jet_meff500noratio_2_qcdcontrol"));
	m_regions.push_back(scaleFactor("4jet_meff500_2_70","4jet_meff500noratio_2_qcdcontrol_70"));
	m_regions.push_back(scaleFactor("6jet_meff500_2_70","6jet_meff500noratio_2_qcdcontrol_70"));
	m_regions.push_back(scaleFactor("6jet_meff500_2_75","6jet_meff500noratio_2_qcdcontrol_75"));
	
	m_regions.push_back(scaleFactor("4jet_meff500_3","4jet_meff500noratio_3_qcdcontrol"));
	m_regions.push_back(scaleFactor("4jet_meff700_3","4jet_meff500noratio_3_qcdcontrol"));
	m_regions.push_back(scaleFactor("4jet_meff900_3_70","4jet_meff500noratio_3_qcdcontrol_70"));
	m_regions.push_back(scaleFactor("6jet_meff700_3_70","6jet_meff500noratio_3_qcdcontrol_70"));
	m_regions.push_back(scaleFactor("6jet_meff900_3_75","6jet_meff500noratio_3_qcdcontrol_75"));
	*/
	m_regions.push_back(scaleFactor("sr1_mct150","sr1_revertdphi"));
	m_regions.push_back(scaleFactor("sr1_mct200","sr1_revertdphi"));
	m_regions.push_back(scaleFactor("sr1_mct250","sr1_revertdphi"));
	m_regions.push_back(scaleFactor("sr2_50ht2","sr2_revertdphi"));
	m_regions.push_back(scaleFactor("sr3_50ht3","sr3_revertdphi"));
	m_regions.push_back(scaleFactor("sr3_met250_j150","sr3_revertdphi"));
	
	TFile dataf(data,"READ");
	TFile nonqcdf(nonqcd,"READ");
	TFile smearedf(smeared,"READ");
	
	TString prefix("nom/");
	TString suffix("_cutflow");
	
    ofstream afh("scaleFactors_smearing.h");
    if (!afh.is_open()) {
      cout << "ERROR opening scaleFactors_smearing.h" << endl;
      return;
    }

    afh << "map<TString,float> getSmearingSFs() {" << endl;    
    afh << "	map<TString,float> scaleFactors;" << endl;
	
	for(unsigned int i = 0; i< m_regions.size(); ++i) {
		TH1D* datacf = (TH1D*)dataf.Get(prefix+m_regions.at(i).CR()+suffix);
		TH1D* nonqcdcf = (TH1D*)nonqcdf.Get(prefix+m_regions.at(i).CR()+suffix);
		TH1D* smearedcf = (TH1D*)smearedf.Get(prefix+m_regions.at(i).CR()+suffix);
		
		if(!datacf) {
			cout << "Missing histograms for region " << m_regions.at(i).CR() << " in data input file." << endl;
			continue;
		}
		else if(!nonqcdcf) {
			cout << "Missing histograms for region " << m_regions.at(i).CR() << " in nonqcd input file." << endl;
			continue;
		}
		else if(!smearedcf) {
			cout << "Missing histograms for region " << m_regions.at(i).CR() << " in smeared input file." << endl;
			continue;
		}
		
		m_regions.at(i).Data(datacf->GetBinContent(1));
		m_regions.at(i).NonQCD(nonqcdcf->GetBinContent(1));
		m_regions.at(i).Smear(smearedcf->GetBinContent(1));
		
		m_regions.at(i).WriteScaleFactor(afh);
		m_regions.at(i).WriteScaleFactor(cout);
	}
	
	afh << "	return scaleFactors;" << endl;
	afh << "};" << endl;
	afh.close();
	
	dataf.Close();
	nonqcdf.Close();
	smearedf.Close();
}
示例#3
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int main(int argc, char **argv)
{
  std::cout << "Starting Ph to HDF5 Merging..." << std::endl;

  try
  {
    // Handle program options passed on command line.
    TCLAP::CmdLine cmd("PhToHDF5", ' ', DREAM3DLib::Version::Complete());

    TCLAP::ValueArg<std::string> phFileArg( "p", "phfile", "Ph Input File", true, "", "Ph Input File");
    cmd.add(phFileArg);

    TCLAP::ValueArg<std::string> angleFileArg( "e", "eulerfile", "Euler Angle File", false, "", "Euler Angle File");
    cmd.add(angleFileArg);

    TCLAP::ValueArg<std::string> h5InputFileArg( "t", "h5file", "Target HDF5 File", true, "", "Target HDF5 File");
    cmd.add(h5InputFileArg);

    // Parse the argv array.
    cmd.parse(argc, argv);
    if (argc == 1)
    {
      std::cout << "PhToHDF5 program was not provided any arguments. Use the --help argument to show the help listing." << std::endl;
      return EXIT_FAILURE;
    }


    std::string phFile = phFileArg.getValue();
    std::string h5File = h5InputFileArg.getValue();

    std::vector<int> voxels;
    int nx = 0;
    int ny = 0;
    int nz = 0;

    std::cout << "Merging the GrainID data from " << phFile << std::endl;
    std::cout << "  into" << std::endl;
    std::cout << "file: " << h5File << std::endl;


    std::cout << "Reading the Ph data file...." << std::endl;
    int err = ReadPHFile(phFile, voxels, nx, ny, nz);
    if (err < 0)
    {
     return EXIT_FAILURE;
    }
    std::cout << "Ph File has dimensions: " << nx << " x " << ny << " x " << nz << std::endl;


    std::cout << "Now Overwriting the GrainID data set in the HDF5 file...." << std::endl;
    err = writePhDataToHDF5File(h5File, voxels, nz, ny, nz);
    if (err < 0)
    {
     std::cout << "There was an error writing the grain id data. Check other errors for possible clues." << std::endl;
     return EXIT_FAILURE;
    }
    std::cout << "+ Done Writing the Grain ID Data." << std::endl;


    std::map<int, EulerSet> gidToEulerMap;
    if (angleFileArg.getValue().empty() == false)
    {
      std::cout << "Reading the Euler Angle Data...." << std::endl;
      err = ReadEulerFile(angleFileArg.getValue(), gidToEulerMap);
      if (err < 0)
      {
        std::cout << "Error Reading the Euler Angle File" << std::endl;
        return EXIT_FAILURE;
      }

    // Over Write the Euler Angles if the Euler File was supplied

      std::cout << "Now Over Writing the Euler Angles data in the HDF5 file....." << std::endl;
      int totalPoints = nx * ny * nz;
      int numComp = 3;
      // Loop over each Voxel getting its Grain ID and then setting the Euler Angle
      std::vector<float> dataf(totalPoints * 3);
      for (int i = 0; i < totalPoints; ++i)
      {
        EulerSet& angle = gidToEulerMap[voxels[i]];
        dataf[i * 3] = angle.e0;
        dataf[i * 3 + 1] = angle.e1;
        dataf[i * 3 + 2] = angle.e2;
      }
      // This is going to be a 2 Dimension Table Data set.
      int32_t rank = 2;
      hsize_t dims[2] = {totalPoints, numComp};
      err = writeEulerDataToHDF5File(h5File, dataf, numComp, rank, dims);
      if (err < 0)
      {
       std::cout << "There was an error writing the Euler Angle data. Check other errors for possible clues." << std::endl;
       return EXIT_FAILURE;
      }
      std::cout << "+ Done Writing the Euler Angle Data." << std::endl;
    }

  }
  catch (TCLAP::ArgException &e) // catch any exceptions
  {
    std::cerr << logTime() << " error: " << e.error() << " for arg " << e.argId() << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "Successfully completed the merge." << std::endl;

  return EXIT_SUCCESS;
}