Пример #1
0
void one_page_plot(int test_number, string test_name, string sub_test_name,
                   float y_min, float y_max, string summary_title,
                   string chamber_type, float lower_limit, float upper_limit,
                   int bins, int febs_per_layer, int layers, const vector<vector<float > > data,
                   string output_filename) {

  TCanvas canvas("canvas_name", "canvas title");
  vector<TH1F *> * histograms = new vector<TH1F *>();

  // Split the canvas in two, one 2/3's of the width.
  TPad layer_histograms_pad("layer_histograms_pad",
			    "Layer Histograms Pad",
			    0, 0, .66, 1);
  TPad summary_pad("summary_pad",
		   "Summary Histogram Pad",
		   .66, 0, 1, 1);

  layer_histograms_pad.SetRightMargin(0);
  summary_pad.SetLeftMargin(0.05);

  canvas.cd(0);
  // add the histograms to the current pad, which the previous line set to the
  // canvas
  layer_histograms_pad.Draw();
  summary_pad.Draw();

  // break the layer side into six horizontal sections
  layer_histograms_pad.Divide(1, layers, 0, 0);

  layer_histograms_pad.GetPad(layers)->SetBottomMargin(.3);

  histograms = create_histograms(layers, bins);
  fill_histograms(histograms, data, bins, layers);
  configure_style_of_histograms(histograms, y_min, y_max, bins, febs_per_layer);

  vector<vector<TObject *> * > * overflow_markers_vector = new vector<vector<TObject *> * >();
  // this produces a vector of drawable overflow marks for each histogram,
  // thus producing a vector of vector of drawable overflow marks
  vector_map(histograms, overflow_markers_vector, mark_overflows);

  vector<vector<TObject *> * > * layer_limit_lines = create_layer_limit_lines(histograms, lower_limit, upper_limit);

  // synchronously loop over the histograms and the overflow markers
  for(int i = 0; i < histograms->size() && i < overflow_markers_vector->size(); ++i) {
    // [1, size] are the sub-pads we want, 0 is the containing pad
    layer_histograms_pad.cd(i + 1);
    gPad->SetGridx(1);
    gPad->SetRightMargin(.05);

    // draw the histograms and the markers on the current (i.e. (i+1)th) pad
    (*histograms)[i]->Draw("P");
    draw_all_vector_members((*overflow_markers_vector)[i]);
    draw_all_vector_members((*layer_limit_lines)[i]);
  }

  int number_of_out_of_limits_points;

  TH1F * summary_histogram = create_summary_histogram_and_count_out_of_limits(histograms, summary_title, y_min, y_max,
									      lower_limit, upper_limit, number_of_out_of_limits_points);
  vector<TObject *> * summary_limit_lines = create_summary_limit_lines(summary_histogram, lower_limit, upper_limit);

  summary_pad.Divide(1, 2, 0.05, 0.02);
  TVirtualPad & summary_histogram_pad = * summary_pad.GetPad(1);
  TVirtualPad & summary_text_pad = * summary_pad.GetPad(2);

  summary_histogram_pad.cd(0);
  summary_histogram->Draw();
  draw_all_vector_members(summary_limit_lines);

  int overflowbin = summary_histogram->GetNbinsX() + 1;
  float * summary_bins = summary_histogram->GetArray();

  TPaveText * information_box = create_information_box(chamber_type,
                                                       test_number,
                                                       test_name,
                                                       sub_test_name,
                                                       number_of_out_of_limits_points);
  summary_text_pad.cd(0);
  information_box->Draw();

  // turn on underflows and overflows
  gStyle->SetOptStat(111111);

  canvas.Print(output_filename.c_str());

  // return to default stat box style
  gStyle->SetOptStat(1111);

  delete information_box;
  delete summary_histogram;
  delete_vector_of_pointers(histograms);
  delete_vector_of_vectors_of_pointers(overflow_markers_vector);
  delete_vector_of_vectors_of_pointers(layer_limit_lines);
  delete_vector_of_pointers(summary_limit_lines);

  return;
}
Пример #2
0
/* segment using HMM and then histogram clustering */
void cluster_segment(int* q, double** features, int frames_read, int feature_length, int nHMM_states, 
					 int histogram_length, int nclusters, int neighbour_limit)
{
	int i, j;
	
	/*****************************/
	if (0) {
	/* try just using the predominant bin number as a 'decoded state' */
	nHMM_states = feature_length + 1;	/* allow a 'zero' state */
	double chroma_thresh = 0.05;
	double maxval;
	int maxbin;
	for (i = 0; i < frames_read; i++)
	{
		maxval = 0;
		for (j = 0; j < feature_length; j++)
		{
			if (features[i][j] > maxval) 
			{
				maxval = features[i][j];
				maxbin = j;
			}				
		}
		if (maxval > chroma_thresh)
			q[i] = maxbin;
		else
			q[i] = feature_length;
	}
	
	}
	if (1) {
	/*****************************/
		
	
	/* scale all the features to 'balance covariances' during HMM training */
	double scale = 10;
	for (i = 0; i < frames_read; i++)
		for (j = 0; j < feature_length; j++)
			features[i][j] *= scale;
	
	/* train an HMM on the features */
	
	/* create a model */
	model_t* model = hmm_init(features, frames_read, feature_length, nHMM_states);
	
	/* train the model */
	hmm_train(features, frames_read, model);
/*	
	printf("\n\nafter training:\n");
	hmm_print(model);
*/	
	/* decode the hidden state sequence */
	viterbi_decode(features, frames_read, model, q);  
	hmm_close(model);
	
	/*****************************/
	}
	/*****************************/
	
    
/*
	fprintf(stderr, "HMM state sequence:\n");
	for (i = 0; i < frames_read; i++)
		fprintf(stderr, "%d ", q[i]);
	fprintf(stderr, "\n\n");
*/
	
	/* create histograms of states */
	double* h = (double*) malloc(frames_read*nHMM_states*sizeof(double));	/* vector in row major order */
	create_histograms(q, frames_read, nHMM_states, histogram_length, h);
	
	/* cluster the histograms */
	int nbsched = 20;	/* length of inverse temperature schedule */
	double* bsched = (double*) malloc(nbsched*sizeof(double));	/* inverse temperature schedule */
	double b0 = 100;
	double alpha = 0.7;
	bsched[0] = b0;
	for (i = 1; i < nbsched; i++)
		bsched[i] = alpha * bsched[i-1];
	cluster_melt(h, nHMM_states, frames_read, bsched, nbsched, nclusters, neighbour_limit, q);
	
	/* now q holds a sequence of cluster assignments */
	
	free(h);  
	free(bsched);
}