void HeapInspection::heap_inspection(outputStream* st, bool need_prologue) {
  ResourceMark rm;

  KlassInfoTable cit(start_of_perm_gen());
  if (!cit.allocation_failed()) {
    size_t missed_count = populate_table(&cit, need_prologue);
    if (missed_count != 0) {
      st->print_cr("WARNING: Ran out of C-heap; undercounted " SIZE_FORMAT
                   " total instances in data below",
                   missed_count);
    }

    KlassInfoHisto histo("\n"
                     " num     #instances         #bytes  class name\n"
                     "----------------------------------------------");
    HistoClosure hc(&histo);

    cit.iterate(&hc);

    histo.sort();
    histo.print_on(st);
  } else {
    st->print_cr("WARNING: Ran out of C-heap; histogram not generated");
  }
  st->flush();
}
示例#2
0
int main() { 
  typedef funct::Product<funct::Parameter, funct::BreitWigner>::type FitFunction;
  typedef fit::HistoChiSquare<FitFunction> ChiSquared;
  try {
    funct::Parameter yield("Yield", 1000);
    funct::Parameter mass("Mass", 91.2);
    funct::Parameter gamma("Gamma", 2.50);
    funct::BreitWigner bw(mass, gamma);
    
    FitFunction f = yield * bw;
    TF1 startFun = root::tf1("startFun", f, 0, 200, yield, mass, gamma);
    TH1D histo("histo", "Z mass (GeV/c)", 200, 0, 200);
    histo.FillRandom("startFun", yield);
    ChiSquared chi2(f, &histo, 80, 120);
    fit::RootMinuit<ChiSquared> minuit(chi2, true);
    minuit.addParameter(yield, 100, 0, 10000);
    minuit.addParameter(mass, 2, 70, 120);
    minuit.addParameter(gamma, 1, 0, 5);
    minuit.minimize();
    minuit.migrad();
  } catch(std::exception & err){
    std::cerr << "Exception caught:\n" << err.what() << std::endl;
    return 1;
  }
  
  return 0;
}
示例#3
0
	void SO2HBondingAnalysis::Analysis () {
		// find the locatin of the surface of the water slab and the distance of the so2 to it
		h2os.Reload();
		//h2os.FindWaterSurfaceLocation(true);	// top surface
		h2os.FindWaterSurfaceLocation();	// bottom surface
		//double distance = system_t::Position(so2s.S()) - h2os.SurfaceLocation();	// top surface
		double distance;
		if (h2os.TopSurface())
			distance = system_t::Position(so2s.S()) - h2os.SurfaceLocation();	// bottom surface
		else
			distance = h2os.SurfaceLocation() - system_t::Position(so2s.S());	// top surface

		this->LoadAll();
		// sort the atoms in the system in order of distance from the SO2
		std::sort(
				this->begin(), 
				this->end(), 
				typename system_t::atomic_distance_cmp (so2s.S()));

		//nearest.clear();
		//std::copy (this->begin(), this->begin+20, std::back_inserter(nearest));
		// build the graph using a handful of the closest atoms
		graph.UpdateGraph(this->begin(), this->begin() + 20);

		// grab the number of atoms connected to the reference atom through bonding, and check if the bond looks right.
		bonded.clear();

		// check for when the so2 has a single bond on the S and no other bonds
		// O2S-OH2
		/*
			 bonded = graph.BondedAtoms (so2s.S(), bondgraph::interaction, Atom::O);
			 bool good = false;
			 if (bonded.size() == 1 && bonded[0]->ParentMolecule()->MolType() == Molecule::H2O) {
			 good = true;
			 }
			 bonded = graph.BondedAtoms (so2s.O1(), bondgraph::hbond, Atom::H);
			 if (bonded.size() >= 1)
			 good = false;
			 bonded = graph.BondedAtoms (so2s.O2(), bondgraph::hbond, Atom::H);
			 if (bonded.size() >= 1)
			 good = false;

			 if (good)
			 histo(distance);
			 */

		// checking for the OSO--HOH interaction on a single water - only a 1:1 interaction
		// One O bond, and no S bonds
		int bonds = 0;
		bonded = graph.BondedAtoms (so2s.O1(), bondgraph::hbond, Atom::H);
		if (bonded.size() == 1 && bonded[0]->ParentMolecule()->MolType() == Molecule::H2O)
			++bonds;
		bonded = graph.BondedAtoms (so2s.O2(), bondgraph::hbond, Atom::H);
		if (bonded.size() == 1 && bonded[0]->ParentMolecule()->MolType() == Molecule::H2O)
			++bonds;
		bonded = graph.BondedAtoms (so2s.S(), bondgraph::hbond, Atom::H);
		if (bonds == 1 && bonded.empty())
			histo(distance);

	}	// so2 h bonding analysis
示例#4
0
int main ( int argc, char **argv )
{
	Argvs cmd = ParseCommandLine ( argc, argv );
	if ( cmd.mode == OP_KEYGEN ) {
		if ( keygen ( cmd.t ) != 0 ) {
			printerror ( "Unknown keygen error" );
		}
	} else if ( cmd.mode == OP_CRYPT ) {
		if ( crypt ( cmd.file1, cmd.file2 ) != 0 ) {
			printerror ( "Unknown crypt error" );
		}
		free ( cmd.file1 );
		free ( cmd.file2 );
	} else if ( cmd.mode == OP_INVKEY ) {
		if ( invkey ( cmd.file1 ) != 0 ) {
			printerror ( "unknown invkey error" );
		}
		free ( cmd.file1 );
	} else if ( cmd.mode == OP_HISTO ) {
		if ( histo ( cmd.t, cmd.i, cmd.file1 ) != 0 ) {
			printerror ( "unknown histo error" );
		}
		free ( cmd.file1 );
	} else if ( cmd.mode == OP_SOLVE ) {
		if ( solve ( cmd.l, cmd.file1 ) != 0 ) {
			printerror ( "unknown solve error" );
		}
		free ( cmd.file1 );
	}
	return 0;
}
double RocCurves::get_presel_effy(DataChain* data_chain, std::string preselection, Variable* var, std::vector<Variable*>* variables)
{
	 TH1F* remaining_histo = histo(data_chain, var, preselection);
  TH1F* total_histo = HistoPlot::build_1d_histo(data_chain, var, true, false, "goff", variables,"");

  return remaining_histo->GetEntries() / total_histo->GetEntries();
}
示例#6
0
int main(int argc, char* argv[])
{
	char cNomImgLue[250];
	char out[250] = "out.pgm";

	int lignes, colonnes, nTaille, S;

	if (argc == 1) {
		sscanf (out, "%s", cNomImgLue);
	} else if (argc == 2) {
		sscanf (argv[1],"%s",cNomImgLue);
	} else {
		printf("to many arguments");
	}


	OCTET *ImgIn, *ImgOut, *ImgOut1;

	lire_nb_lignes_colonnes_image_pgm(cNomImgLue, &lignes, &colonnes);
	nTaille = lignes * colonnes;

	allocation_tableau(ImgIn, OCTET, nTaille);
	lire_image_pgm(cNomImgLue, ImgIn, lignes * colonnes);
	allocation_tableau(ImgOut, OCTET, nTaille);


	histo(ImgIn, lignes, colonnes);
	egalisation(ImgIn, ImgOut, lignes, colonnes);

	ecrire_image_pgm(out, ImgOut,  lignes, colonnes);
	free(ImgIn);

	return 1;
}
void HeapInspection::heap_inspection() {
  ResourceMark rm;
  HeapWord* permgen_bottom = NULL;

  if (Universe::heap()->kind() == CollectedHeap::GenCollectedHeap) {
    GenCollectedHeap* gch = GenCollectedHeap::heap();
    gch->gc_prologue(false /* !full */); // get any necessary locks
    permgen_bottom = gch->perm_gen()->used_region().start();
  } else {
    return;
  }

  // Collect klass instance info

  // Iterate over objects in the heap
  KlassInfoTable cit(KlassInfoTable::cit_size, permgen_bottom);
  RecordInstanceClosure ric(&cit);
  Universe::heap()->object_iterate(&ric);

  // Sort and print klass instance info
  KlassInfoHisto histo("\n"
                   "num   #instances    #bytes  class name\n"
                   "--------------------------------------",
                   KlassInfoHisto::histo_initial_size);
  HistoClosure hc(&histo);
  cit.iterate(&hc);
  histo.sort();
  histo.print_on(gclog_or_tty);
  gclog_or_tty->flush();

  if (Universe::heap()->kind() == CollectedHeap::GenCollectedHeap) {
    GenCollectedHeap* gch = GenCollectedHeap::heap();
    gch->gc_epilogue(false /* !full */); // release all acquired locks
  }
}
StudentHistogram ImageUtils::histogram_from_x_axis(const IntensityImage * image, int y)
{
	StudentHistogram histo(image->getWidth());
	for (int x = 0; x < image->getWidth(); x++) {
		histo.set_value(x, 255 - image->getPixel(x, y));
	}
	return histo;
}
示例#9
0
int main(void) {
  int values[] = { 3, 8, 0, 1, 5 };

  char *s = histo(values, 5);
  printf("%s", s);
  free(s);

  return 0;
}
示例#10
0
void define_histogram(char const *type_name)
{
  typedef vsip::Histogram<vsip::const_Vector, T> histo_type;

  bpl::class_<histo_type> histo(type_name,
				bpl::init<T, T, int>());
  histo.def(bpl::init<T, T, vsip::Vector<int, Block<1, int> > >());
  histo.def("__call__", histogram1<T>, bpl::arg("accumulate") = false);
  histo.def("__call__", histogram2<T>, bpl::arg("accumulate") = false);
}
示例#11
0
qreal PasswordChecker::entropy(const QString &str) {
    static const int Range = 256;
    const QByteArray &sample = str.toLatin1();
    QVector<int> histo(Range, 0);
    for (int i = 0; i < sample.size(); ++i) {
        ++histo[static_cast<uchar>(sample.at(i))];
    }
    qreal ent = 0;
    const qreal l = sample.size();
    for (int i = 0; i < Range; ++i) {
        const qreal p = qreal(histo[i]) / l;
        if (p > 0)
            ent += p * M_LOG2E * qLn(1.0 / p);
    }
    const qreal bitsPerVariate = qLn(qreal(Range)) * M_LOG2E;
    return ent / bitsPerVariate;
}
void HeapInspection::heap_inspection(outputStream* st) {
  ResourceMark rm;

  if (_print_help) {
    for (int c=0; c<KlassSizeStats::_num_columns; c++) {
      st->print("%s:\n\t", name_table[c]);
      const int max_col = 60;
      int col = 0;
      for (const char *p = help_table[c]; *p; p++,col++) {
        if (col >= max_col && *p == ' ') {
          st->print("\n\t");
          col = 0;
        } else {
          st->print("%c", *p);
        }
      }
      st->print_cr(".\n");
    }
    return;
  }

  KlassInfoTable cit(_print_class_stats);
  if (!cit.allocation_failed()) {
    size_t missed_count = populate_table(&cit);
    if (missed_count != 0) {
      st->print_cr("WARNING: Ran out of C-heap; undercounted " SIZE_FORMAT
                   " total instances in data below",
                   missed_count);
    }

    // Sort and print klass instance info
    const char *title = "\n"
              " num     #instances         #bytes  class name\n"
              "----------------------------------------------";
    KlassInfoHisto histo(&cit, title);
    HistoClosure hc(&histo);

    cit.iterate(&hc);

    histo.sort();
    histo.print_histo_on(st, _print_class_stats, _csv_format, _columns);
  } else {
    st->print_cr("WARNING: Ran out of C-heap; histogram not generated");
  }
  st->flush();
}
示例#13
0
int main()
{
  double maxdc = 0.0;
  double maxds = 0.0;
  double maxdca = 0.0;
  double maxdsa = 0.0;
  nt2::int32_t i = 0;
  nt2::int32_t j = 0;
  nt2::int32_t di = 0;
  float thresh = 0.0f;
  for(float a0 = nt2::Zero<float>(); a0 < 100*nt2::Pi<float>(); a0 = nt2::successor(a0, 1))
    {
      float s, c;
      nt2::sinecosine<nt2::direct_small>(a0, s, c);
      float scrm =  nt2::crlibm::sin_rn(a0);
      float ccrm =  nt2::crlibm::cos_rn(a0);
      double ds = nt2::ulpdist(s, scrm);
      maxds =  nt2::max(maxds, ds);
//       double dc = nt2::ulpdist(c, ccrm);
//       maxdc =  nt2::max(maxdc, dc);
//       histo(nt2::max(dc, ds));
//       get_thresh(nt2::max(dc, ds), a0);
      histo(ds);
      get_thresh(ds, a0);
      ++i;
    }
  std::cout << "nb values " << i << std::endl;
  std::cout << "ulp cos   " << maxdc << std::endl;
  std::cout << "ulp sin   " << maxds << std::endl;
  std::cout << std::setprecision(7) << "thresh    " << thresh<< std::endl;

  for(nt2::int32_t i=0; i < NB; i++)
   {
     std::cout << i << " -> " << h[i] << std::endl;
   }
  for(nt2::int32_t i=0; i < NB; i++)
   {
     std::cout << i << " -> " << thresh_at[i] << std::endl;
   }
  return 0;
}
示例#14
0
std::unique_ptr<TH1D> get_histogram(
    const std::string& FILE_NAME,
    const std::string& HISTOGRAM_NAME
) {
    // Open the file
    TFile tfile(FILE_NAME.c_str(), "READ");
    if (tfile.IsZombie()) {
        throw std::runtime_error("Could not open file " + FILE_NAME);
    }

    // Get the histogram
    std::unique_ptr<TH1D> histo(static_cast<TH1D*>(tfile.Get(HISTOGRAM_NAME.c_str())));
    if (histo.get() == nullptr || histo->IsZombie()) {
        throw std::runtime_error("Could not load histogram " + HISTOGRAM_NAME);
    }

    // Set weights
    histo->Sumw2();

    return histo;
}
示例#15
0
BOOL LAShistogram::parse(int argc, char* argv[])
{
  int i;
  for (i = 1; i < argc; i++)
  {
    if (argv[i][0] == '\0')
    {
      continue;
    }
    else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"-help") == 0)
    {
      return TRUE;
    }
    else if (strcmp(argv[i],"-histo") == 0)
    {
      if ((i+2) >= argc)
      {
        fprintf(stderr,"ERROR: '%s' needs 2 arguments: name step\n", argv[i]);
        return FALSE;
      }
      if (!histo(argv[i+1], (F32)atof(argv[i+2]))) return FALSE;
      *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; i+=2; 
    }
    else if (strcmp(argv[i],"-histo_avg") == 0)
    {
      if ((i+3) >= argc)
      {
        fprintf(stderr,"ERROR: '%s' needs 3 arguments: name step name_avg\n", argv[i]);
        return FALSE;
      }
      if (!histo_avg(argv[i+1], (F32)atof(argv[i+2]), argv[i+3])) return FALSE;
      *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; i+=3; 
    }
  }
  return TRUE;
}
示例#16
0
/*
 * Main function
 */
int main (int argc, char **argv)
{
	FILE *fp = NULL;

	if(argc < 2)
	{
		fprintf(stderr, "Please specify the programs keygen/crypt/invkey/histo/solve and try again\n");
	}
	else
	{
		if(strcmp(argv[1], "keygen") == 0) //Processing keygen command
		{
			if (argc != 4)
			{
				fprintf(stderr,"Please double check your arguments. The keygen function expects to have exactly 2 arguments -p=pphrase and -t=period\n");
			}
			else
			{
				char *pphrase = "";
				int period = 0;
				//Use for loop to go through all arguments
				for (int index = argc-1; index > 1; index--)
				{
					//find '=' at each argument
					char *val = strchr(argv[index], '=');
					if (val == NULL)
					{
						//malformed command
						fprintf(stderr,"Please double check your arguments. The keygen function expects to have exactly 2 arguments in following format: -p=pphrase and -t=period\n");
						exit(1);
					}
					else
					{
						char *key = argv[index];
						*val = '\0'; //replace '=' by NULL character to separate key and val pointers
						val++;
						//compare to see which key is it
						if (strncmp(key, "-p", 2) == 0)
						{
							//passphrase
							pphrase = val;
						}
						else if(strncmp(key, "-t", 2) == 0)
						{
							//key length
							period = atoi(val);
						}
						else
						{
							//malformed command
							fprintf(stderr,"Please double check your arguments. The keygen function expects to have exactly 2 arguments in following format: -p=pphrase and -t=period\n");
							exit(1);
						}
					}
				}
				//Check if we have value for pphrase and len before calling keygen function
				if (strncmp(pphrase, "",1) != 0 && *pphrase != '\0' && period > 0)
				{
					//call keygen function
					generate_key(pphrase, period);
				}
				else
				{
					//malformed command
					fprintf(stderr,"Please double check your arguments. The keygen function expects to have exactly 2 arguments in following format: -p=pphrase and -t=period\n");
					exit(1);
				}
			}
		}
		else if(strcmp(argv[1], "crypt") == 0) //processing crypt command
		{
			if (argc < 3 || argc > 4)
			{
				fprintf (stderr, "Please double check your arguments. The crypt function expects to have at least 1 argument in following format: -k=keyfile and an optional file to encrypt/decrypt\n");
				exit(1);
			}
			else if (argc == 3)
			{
				//Check if there is a -k argument. If so, read the file from stdin
				char *keyfile = "";
				char *checkArgs = "";
				//find '=' at argument
				char *val = strchr(argv[2], '=');
				if (val == NULL)
				{
					//malformed command
					fprintf(stderr,"Please double check your arguments. The crypt function expects to have at least 1 argument in following format: -k=keyfile and an optional file to encrypt/decrypt\n");
					exit(1);
				}
				else
				{
					checkArgs = argv[2];
					if (strncmp(checkArgs, "-k", 2) != 0)
					{
						//malformed command
						fprintf(stderr,"Please double check your arguments. The crypt function expects to have at least 1 argument in following format: -k=keyfile and an optional file to encrypt/decrypt\n");
						exit(1);
					}
					else
					{
						*val = '\0';
						val++;
						keyfile = val;
						//Now try to open the key file, if open successfully, continue. Else, exit with error
						fp = fopen(keyfile,"r");
						if (fp == NULL)
						{
							fprintf (stderr, "Keyfile %s does not exist\n", keyfile);
							exit(1);
						}
						//Now call crypt function with fp to read keyfile and stdin to read file to be encrypted/decrypted
						crypt(fp, keyfile, stdin);
						fclose(fp);
					}
				}
			}
			else if (argc == 4)
			{
				char *keyfile = "";
				char *file = "";
				char *checkArgs = "";
				FILE *fp2;
				//Use for loop to go through all arguments
				for (int index = argc-1; index > 1; index--)
				{
					//find '=' at each argument
					char *val = strchr(argv[index], '=');
					if (val == NULL)
					{
						//This must be the file name. Let try to open this argument to see if file exists
						file = argv[index];
					}
					else
					{
						checkArgs = argv[index];
						*val = '\0'; //replace '=' by NULL character to separate key and val pointers
						val++;
						//compare to see which key is it
						if (strncmp(checkArgs, "-k", 2) == 0)
						{
							//keyfile
							keyfile = val;
						}
						else
						{
							//malformed command
							fprintf(stderr,"Please double check your arguments. The crypt function expects to have at least 1 argument in following format: -k=keyfile and an optional file to encrypt/decrypt\n");
							exit(1);
						}
					}
				}
				if (strcmp(file,"") == 0 || strcmp(keyfile,"") == 0)
				{
					fprintf(stderr, "Either keyfile or file is missing. Please double check your arguments\n");
					exit(1);
				}
				//Now try to open both file and keyfile to see both exist
				fp = fopen(keyfile, "r");
				if (fp == NULL)
				{
					fprintf (stderr, "Keyfile %s does not exist\n", keyfile);
					exit(1);
				}

				fp2 = fopen(file, "r");
				if (fp2 == NULL)
				{
					fprintf (stderr, "File %s does not exist\n", file);
					//close fp
					fclose(fp);
					exit(1);
				}
				//Call crypt function with fp for keyfile and fp2 for file to be encrypted/decrypted
				crypt(fp, keyfile, fp2);
				fclose(fp);
				fclose(fp2);
			}
		}
		else if(strcmp(argv[1], "invkey") == 0) //process invkey
		{
			if (argc == 3)
			{
				//printf("my letter a number = %d\n",'z');
				fp = fopen(argv[2], "r");
				if(fp == NULL)
				{
					fprintf(stderr, "File %s does not exist.\n", argv[2]);
					exit(1);
				}
				invkey(fp);
				fclose(fp);
			}
			else
			{
				fprintf(stderr, "Please double check your arguments. The invkey function expects to have only 1 argument which is the keyfile\n");
				exit(1);
			}
		}
		else if(strcmp(argv[1], "histo") == 0) //processing histo command
		{
			if (argc == 4 || argc == 5) //expect to have 2 or 3 argument on top of the executable name and function name
			{
				int which = 0;
				int period = 0;
				char *filename = "";
				//Use for loop to go through all arguments
				for (int index = argc-1; index > 1; index--)
				{
					//find '=' at each argument
					char *val = strchr(argv[index], '=');
					if (val == NULL)
					{
						if (argc == 5)
						{
							//Must be the input file
							filename = argv[index];
						}
						else
						{
							//malformed command
							fprintf(stderr,"Please double check your arguments. The histo function expects to have at least 2 arguments in following format: -t=period and -i=which, and an optional input file\n");
							exit(1);
						}
					}
					else
					{
						char *checkArgs = argv[index];
						*val = '\0'; //replace '=' by NULL character to separate key and val pointers
						val++;
						//compare to see which key is it
						if (strncmp(checkArgs, "-t", 2) == 0)
						{
							//period
							period = atoi(val);
						}
						else if(strncmp(checkArgs, "-i", 2) == 0)
						{
							//which
							which = atoi(val);
						}
						else
						{
							//malformed command
							fprintf(stderr,"Please double check your arguments. The histo function expects to have at least 2 arguments in following format: -t=period and -i=which, and an optional input file\n");
							exit(1);
						}
					}
				}

				if (which <= 0 || period <= 0)
				{
					//malformed command
					fprintf(stderr,"Please double check your arguments. The histo function expects to have at least 2 arguments in following format: -t=period and -i=which, and an optional input file\n");
					exit(1);
				}
				else if (argc == 5 && strcmp(filename,"") == 0)
				{
					//malformed command
					fprintf(stderr,"Please double check your arguments. The histo function expects to have at least 2 arguments in following format: -t=period and -i=which, and an optional input file\n");
					exit(1);
				}
				//Check if we have which is greater than the period. If so, return error
				if (which > period)
				{
					//malformed command
					fprintf(stderr,"Please double check your arguments. The histo function does not allow --which value is greater than --period value\n");
					exit(1);
				}
				//Now call histo function with period, which, and input file from stdin or from input file
				if (argc == 4)
				{
					histo(period,which,stdin);
				}
				else
				{
					fp = fopen(filename,"r");
					if (fp == NULL)
					{
						fprintf(stderr,"File %s does not exist.\n", filename);
						exit(1);
					}
					histo(period,which,fp);
					fclose(fp);
				}

			}
			else
			{
				//malformed command
				fprintf(stderr,"Please double check your arguments. The histo function expects to have at least 2 arguments in following format: -t=period and -i=which, and an optional input file\n");
				exit(1);
			}
		}
		else if(strcmp(argv[1], "solve") == 0) //processing solve command
		{
			if (argc == 4)
			{
				char *filename = "";
				int max_t = 0;
				//Use for loop to go through all arguments
				for (int index = argc-1; index > 1; index--)
				{
					//find '=' at each argument
					char *val = strchr(argv[index], '=');
					if (val == NULL)
					{
						//Must be file name
						filename = argv[index];
					}
					else
					{
						char *checkArgs = argv[index];
						*val = '\0'; //replace '=' by NULL character to separate key and val pointers
						val++;
						//compare to see which key is it
						if (strncmp(checkArgs, "-l", 2) == 0)
						{
							//max_t period
							max_t = atoi(val);
						}
						else
						{
							//malformed command
							fprintf(stderr,"Please double check your arguments. The solve function expects to have exactly 2 arguments in following format: -l=max_t and input file\n");
							exit(1);
						}
					}
				}
				if (strcmp(filename,"") == 0 || max_t == 0)
				{
					//malformed command
					fprintf(stderr,"Please double check your arguments. The solve function expects to have exactly 2 arguments in following format: -l=max_t and input file\n");
					exit(1);
				}
				else
				{
					fp = fopen(filename, "r");
					if(fp == NULL)
					{
						fprintf(stderr,"File %s does not exist\n", filename);
						exit(1);
					}
					//Call solve function
					solve(fp,max_t);
					fclose(fp);
				}
			}
			else
			{
				//malformed command
				fprintf(stderr,"Please double check your arguments. The solve function expects to have exactly 2 arguments in following format: -l=max_t and input file\n");
				exit(1);
			}
		}
		else
		{
			fprintf(stderr, "Please enter the correct program name and try again\n");
		}
	}
}
示例#17
0
std::vector<int>
create_histogram(const C3t3& c3t3, double& min_value, double& max_value)
{
  typedef typename C3t3::Triangulation::Point Point_3;

  std::vector<int> histo(181, 0);

  min_value = 180.;
  max_value = 0.;

  for (typename C3t3::Cells_in_complex_iterator cit = c3t3.cells_in_complex_begin();
    cit != c3t3.cells_in_complex_end();
    ++cit)
  {
    if (!c3t3.is_in_complex(cit))
      continue;

#ifdef CGAL_MESH_3_DEMO_DONT_COUNT_TETS_ADJACENT_TO_SHARP_FEATURES_FOR_HISTOGRAM
    if (c3t3.in_dimension(cit->vertex(0)) <= 1
      || c3t3.in_dimension(cit->vertex(1)) <= 1
      || c3t3.in_dimension(cit->vertex(2)) <= 1
      || c3t3.in_dimension(cit->vertex(3)) <= 1)
      continue;
#endif //CGAL_MESH_3_DEMO_DONT_COUNT_TETS_ADJACENT_TO_SHARP_FEATURES_FOR_HISTOGRAM

    const Point_3& p0 = cit->vertex(0)->point();
    const Point_3& p1 = cit->vertex(1)->point();
    const Point_3& p2 = cit->vertex(2)->point();
    const Point_3& p3 = cit->vertex(3)->point();

    double a = CGAL::to_double(CGAL::abs(CGAL::Mesh_3::dihedral_angle(p0, p1, p2, p3)));
    histo[static_cast<int>(std::floor(a))] += 1;
    min_value = (std::min)(min_value, a);
    max_value = (std::max)(max_value, a);

    a = CGAL::to_double(CGAL::abs(CGAL::Mesh_3::dihedral_angle(p0, p2, p1, p3)));
    histo[static_cast<int>(std::floor(a))] += 1;
    min_value = (std::min)(min_value, a);
    max_value = (std::max)(max_value, a);

    a = CGAL::to_double(CGAL::abs(CGAL::Mesh_3::dihedral_angle(p0, p3, p1, p2)));
    histo[static_cast<int>(std::floor(a))] += 1;
    min_value = (std::min)(min_value, a);
    max_value = (std::max)(max_value, a);

    a = CGAL::to_double(CGAL::abs(CGAL::Mesh_3::dihedral_angle(p1, p2, p0, p3)));
    histo[static_cast<int>(std::floor(a))] += 1;
    min_value = (std::min)(min_value, a);
    max_value = (std::max)(max_value, a);

    a = CGAL::to_double(CGAL::abs(CGAL::Mesh_3::dihedral_angle(p1, p3, p0, p2)));
    histo[static_cast<int>(std::floor(a))] += 1;
    min_value = (std::min)(min_value, a);
    max_value = (std::max)(max_value, a);

    a = CGAL::to_double(CGAL::abs(CGAL::Mesh_3::dihedral_angle(p2, p3, p0, p1)));
    histo[static_cast<int>(std::floor(a))] += 1;
    min_value = (std::min)(min_value, a);
    max_value = (std::max)(max_value, a);

  }

  return histo;
}
示例#18
0
int main(int argc, char** argv)
{
 
 gROOT->Reset();
 gROOT->SetStyle("Plain");
 gStyle->SetPalette(1);
 gStyle->SetOptStat(1111);
 gStyle->SetOptFit(111);
 
 TF1 gaussian("gaussian","-exp(-0.1*x) + exp(-0.2 * x)",0,50);
 
 TH1F histo("histo","histo",1000,0,50);
 histo.FillRandom("gaussian",100000);
 
 TCanvas cc("cc","cc",400,400);
 
 histo.SetLineColor(kRed);
 histo.Draw();
 
 std::cerr << "===== Get Neyman intervals ====" << std::endl;

 std::vector<double> band = getSigmaBands_FeldmanCousins (histo) ;
 
 
 std::cerr << "=======================" << std::endl;
 std::cerr << " " << band.at(0) << " <<  " << band.at(1) << " << " << band.at(2) << " << " << band.at(3) << " << " << band.at(4) << std::endl;
 std::cerr << "=======================" << std::endl;
 
 TLine* lVertLeft95 = new TLine(band.at(0),0,band.at(0),1000);
 lVertLeft95->SetLineColor(kBlue);
 lVertLeft95->SetLineWidth(2);
 lVertLeft95->SetLineStyle(5);
 
 TLine* lVertLeft68 = new TLine(band.at(1),0,band.at(1),1000);
 lVertLeft68->SetLineColor(kMagenta);
 lVertLeft68->SetLineWidth(2);
 lVertLeft68->SetLineStyle(5);
 
 TLine* lVertMiddle = new TLine(band.at(2),0,band.at(2),1000);
 lVertMiddle->SetLineColor(kGreen);
 lVertMiddle->SetLineWidth(2);
 lVertMiddle->SetLineStyle(5);
 
 TLine* lVertRight68 = new TLine(band.at(3),0,band.at(3),1000);
 lVertRight68->SetLineColor(kMagenta);
 lVertRight68->SetLineWidth(2);
 lVertRight68->SetLineStyle(5);

 TLine* lVertRight95 = new TLine(band.at(4),0,band.at(4),1000);
 lVertRight95->SetLineColor(kBlue);
 lVertRight95->SetLineWidth(2);
 lVertRight95->SetLineStyle(5);
 
 
 lVertLeft95->Draw();
 lVertLeft68->Draw();
 lVertMiddle->Draw();
 lVertRight68->Draw();
 lVertRight95->Draw();
 
 cc.SaveAs("exampleBand.png");
 
 
 
  
  return 0;
}
示例#19
0
//=============================================================================
//  Finalize
//=============================================================================
StatusCode VertexCompare::finalize() {

  if(msgLevel(MSG::DEBUG)) debug() << "==> Finalize" << endmsg;


  info() << " ============================================" << endmsg;
  info() << " Efficiencies for reconstructed vertices:    " << endmsg;
  info() << " ============================================" << endmsg;
  info() << " " << endmsg;

  info() << " There are " << m_nVtx
         << " pairs of vertices in processed events" << endmsg;
//   info() << " PV is isolated if dz to closest reconstructible MC PV >  "
//          << m_dzIsolated << " mm" << endmsg;
//   std::string ff = "by counting tracks";
// /*  if ( !m_matchByTracks )*/ ff = "by dz distance";
//   info() << " Two splited vertices matched:  "
//          <<  ff << endmsg;


//   info() << " " << endmsg;
//     printRat("All",       m_nPartVtx,       m_nVtx );

  const AIDA::IHistogram1D* dx = histo( HistoID(1021) ) ;
  const AIDA::IHistogram1D* pullx = histo( HistoID(1031) ) ;
  const AIDA::IHistogram1D* dy = histo( HistoID(1022) ) ;
  const AIDA::IHistogram1D* pully = histo( HistoID(1032) ) ;
  const AIDA::IHistogram1D* dz = histo( HistoID(1023) ) ;
  const AIDA::IHistogram1D* pullz = histo( HistoID(1033) ) ;
  if( dx ) {
    info() << "      ---------------------------------------" << endmsg;
    info() << "dx:    "
     << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f",
          dx->mean(), Gaudi::Utils::HistoStats::meanErr(dx),
          dx->rms(), Gaudi::Utils::HistoStats::rmsErr(dx)) << endmsg ;
  }
  if( dy ) {
    info() << "dy:    "
     << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f",
          dy->mean(), Gaudi::Utils::HistoStats::meanErr(dy),
          dy->rms(), Gaudi::Utils::HistoStats::rmsErr(dy)) << endmsg ;
  }
  if( dz ) {
    info() << "dz:    "
     << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f",
          dz->mean(), Gaudi::Utils::HistoStats::meanErr(dz),
          dz->rms(), Gaudi::Utils::HistoStats::rmsErr(dz)) << endmsg ;
  }
  info() << "      ---------------------------------------" << endmsg;
  if( pullx ) {
    info() << "pullx: "
     << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f",
          pullx->mean(), Gaudi::Utils::HistoStats::meanErr(pullx),
          pullx->rms(), Gaudi::Utils::HistoStats::rmsErr(pullx)) << endmsg ;
  }
  if( pully ) {
    info() << "pully: "
     << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f",
          pully->mean(), Gaudi::Utils::HistoStats::meanErr(pully),
          pully->rms(), Gaudi::Utils::HistoStats::rmsErr(pully)) << endmsg ;
  }
  if( pullz ) {
    info() << "pullz: "
     << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f",
          pullz->mean(), Gaudi::Utils::HistoStats::meanErr(pullz),
          pullz->rms(), Gaudi::Utils::HistoStats::rmsErr(pullz)) << endmsg ;
  }
  info() << " ============================================" << endmsg;
//
  return GaudiTupleAlg::finalize();  // Must be called after all other actions
}
示例#20
0
void HeapInspection::heap_inspection(outputStream* st, bool need_prologue) {
  ResourceMark rm;
  HeapWord* ref;

  CollectedHeap* heap = Universe::heap();
  bool is_shared_heap = false;
  switch (heap->kind()) {
    case CollectedHeap::G1CollectedHeap:
    case CollectedHeap::GenCollectedHeap: {
      is_shared_heap = true;
      SharedHeap* sh = (SharedHeap*)heap;
      if (need_prologue) {
        sh->gc_prologue(false /* !full */); // get any necessary locks, etc.
      }
      ref = sh->perm_gen()->used_region().start();
      break;
    }
#ifndef SERIALGC
    case CollectedHeap::ParallelScavengeHeap: {
      ParallelScavengeHeap* psh = (ParallelScavengeHeap*)heap;
      ref = psh->perm_gen()->object_space()->used_region().start();
      break;
    }
#endif // SERIALGC
    default:
      ShouldNotReachHere(); // Unexpected heap kind for this op
  }
  // Collect klass instance info
  KlassInfoTable cit(KlassInfoTable::cit_size, ref);
  if (!cit.allocation_failed()) {
    // Iterate over objects in the heap
    RecordInstanceClosure ric(&cit);
    // If this operation encounters a bad object when using CMS,
    // consider using safe_object_iterate() which avoids perm gen
    // objects that may contain bad references.
    Universe::heap()->object_iterate(&ric);

    // Report if certain classes are not counted because of
    // running out of C-heap for the histogram.
    size_t missed_count = ric.missed_count();
    if (missed_count != 0) {
      st->print_cr("WARNING: Ran out of C-heap; undercounted " SIZE_FORMAT
                   " total instances in data below",
                   missed_count);
    }
    // Sort and print klass instance info
    KlassInfoHisto histo("\n"
                     " num     #instances         #bytes  class name\n"
                     "----------------------------------------------",
                     KlassInfoHisto::histo_initial_size);
    HistoClosure hc(&histo);
    cit.iterate(&hc);
    histo.sort();
    histo.print_on(st);
  } else {
    st->print_cr("WARNING: Ran out of C-heap; histogram not generated");
  }
  st->flush();

  if (need_prologue && is_shared_heap) {
    SharedHeap* sh = (SharedHeap*)heap;
    sh->gc_epilogue(false /* !full */); // release all acquired locks, etc.
  }
}
示例#21
0
文件: main.c 项目: cadizm/crypto
int main(int argc, char** argv)
{
    if (argc < 3) {
        usage();
        exit(-1);
    }

    if (strcmp(argv[1], "keygen") && strcmp(argv[1], "crypt") &&
        strcmp(argv[1], "invkey") && strcmp(argv[1], "histo") &&
        strcmp(argv[1], "solve")) {
        usage();
        exit(-1);
    }

    if (!strcmp(argv[1], "keygen")) {
        optind = 2;
        int c = 0;
        int option_index = 0;

        int nPeriod = 0;

        while (1) {
            struct option long_options[] = {
                {"t", required_argument, 0, 't'},
                {0, 0, 0, 0}
            };

            c = getopt_long_only(argc, argv, "t:",
                    long_options, &option_index);

            if (c == -1) {
                if (optind != 3) {
                    usage();
                    exit(-1);
                }
                break;
            }

            switch (c) {
                case 't': {
                    for (int i = 0; i < strlen(optarg); ++i) {
                        if (!isdigit(optarg[i])) {
                            fprintf(stderr, "Error: argument `%s' is invalid\n", optarg);
                            exit(-1);
                        }
                    }
                    nPeriod = atoi(optarg);
                    break;
                }

                case '?':
                    break;

                default:
                    usage();
                    exit(-1);
            }
        }

        if (nPeriod > 0) {
            keygen(nPeriod);
        }
        else {
            usage();
            exit(-1);
        }
    }

    else if (!strcmp(argv[1], "crypt")) {
        optind = 2;
        int c = 0;
        int option_index = 0;

        char keyfile[CHAR_BUF_LEN];
        FILE* fp = NULL;

        memset(keyfile, '\0', CHAR_BUF_LEN * sizeof(char));

        while (1) {
            struct option long_options[] = {
                {"k", required_argument, 0, 'k'},
                {0, 0, 0, 0}
            };

            c = getopt_long_only(argc, argv, "k:",
                    long_options, &option_index);

            if (c == -1) {
                if (optind < 3) {
                    usage();
                    exit(-1);
                }
                break;
            }

            switch (c) {
                case 'k':
                    strcpy(keyfile, optarg);
                    break;

                case '?':
                    break;

                default:
                    usage();
                    exit(-1);
            }
        }

        if (strlen(keyfile) < 1) {
            usage();
            exit(-1);
        }

        if (optind < argc) {
            if (!(fp = fopen(argv[optind], "r"))) {
                char errorMsg[CHAR_BUF_LEN];
                sprintf(errorMsg, "Error opening %s", argv[optind]);
                perror(errorMsg);
                exit(-1);
            }
        }
        else {
            fp = stdin;
        }

        crypt_(keyfile, fp);
    }

    else if (!strcmp(argv[1], "invkey")) {
        if (argc != 3) {
            usage();
            exit(-1);
        }

        invkey(argv[2]);
    }

    else if (!strcmp(argv[1], "histo")) {
        optind = 2;
        int c = 0;
        int option_index = 0;

        int nPeriod = 0;
        int nWhich = 0;
        FILE* fp = NULL;

        while (1) {
            struct option long_options[] = {
                {"t", required_argument, 0, 't'},
                {"i", required_argument, 0, 'i'},
                {0, 0, 0, 0}
            };

            c = getopt_long_only(argc, argv, "t:i:",
                    long_options, &option_index);

            if (c == -1) {
                if (optind < 4) {
                    usage();
                    exit(-1);
                }
                break;
            }

            switch (c) {
                case 't':
                    for (int i = 0; i < strlen(optarg); ++i) {
                        if (!isdigit(optarg[i])) {
                            fprintf(stderr, "Error: argument `%s' is invalid\n", optarg);
                            exit(-1);
                        }
                    }
                    nPeriod = atoi(optarg);
                    break;

                case 'i':
                    for (int i = 0; i < strlen(optarg); ++i) {
                        if (!isdigit(optarg[i])) {
                            fprintf(stderr, "Error: argument `%s' is invalid\n", optarg);
                            exit(-1);
                        }
                    }
                    nWhich = atoi(optarg);
                    break;

                case '?':
                    break;

                default:
                    usage();
                    exit(-1);
            }
        }

        if (nPeriod < 1 || nWhich < 1) {
            usage();
            exit(-1);
        }

        if (optind < argc) {
            if (!(fp = fopen(argv[optind], "r"))) {
                char errorMsg[CHAR_BUF_LEN];
                sprintf(errorMsg, "Error opening %s", argv[optind]);
                perror(errorMsg);
                exit(-1);
            }
        }
        else {
            fp = stdin;
        }

        histo(nPeriod, nWhich, fp);
    }

    else if (!strcmp(argv[1], "solve")) {
        optind = 2;
        int c = 0;
        int option_index = 0;

        int nMax_t = 0;
        FILE* fp = NULL;

        if (argc != 4) {
            usage();
            exit(-1);
        }

        while (1) {
            struct option long_options[] = {
                {"l", required_argument, 0, 'l'},
                {0, 0, 0, 0}
            };

            c = getopt_long_only(argc, argv, "l:",
                    long_options, &option_index);

            if (c == -1) {
                break;
            }

            switch (c) {
                case 'l':
                    for (int i = 0; i < strlen(optarg); ++i) {
                        if (!isdigit(optarg[i])) {
                            fprintf(stderr, "Error: argument `%s' is invalid\n", optarg);
                            exit(-1);
                        }
                    }
                    nMax_t = atoi(optarg);
                    break;

                case '?':
                    break;

                default:
                    usage();
                    exit(-1);
            }
        }

        if (nMax_t < 1) {
            usage();
            exit(-1);
        }

        if (!(fp = fopen(argv[optind], "r"))) {
            char errorMsg[CHAR_BUF_LEN];
            sprintf(errorMsg, "Error opening %s", argv[optind]);
            perror(errorMsg);
            exit(-1);
        }

        solve(nMax_t, fp);
    }

    return 0;
}