-
Notifications
You must be signed in to change notification settings - Fork 67
All in One
gavalian edited this page May 5, 2017
·
3 revisions
This example is for those that want to see everything having to do with H1Fs all in one place!
//Create JFrame and set to a nice size and aspect ratio
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
JFrame frame = new JFrame("GROOT DEMO");
frame.setSize((int)(screensize.getHeight()*.75*1.618), (int) (screensize.getHeight()*.75));
//Initialize EmbeddedCanvas and divide it
EmbeddedCanvas c1 = new EmbeddedCanvas();
c1.divide(4, 4);
Random rand = new Random(); //For random means/sigmas
H1F[] h1 = new H1F[16];
for (int i = 0; i < h1.length-1; i++) {
h1[i] = new H1F("h" + i, "", 200, -5.0, 5.0);
h1[i].setTitleX("Randomly Generated Function");
h1[i].setTitleY("Counts");
h1[i].setOptStat(0110); //Each IDataSet has it's own OptStat
h1[i].setLineWidth(2);
h1[i].setLineColor(21);
h1[i].setFillColor(30 + (i % 4) + 2);
F1D f1 = new F1D("f1","[amp]*gaus(x,[mean],[sigma])", -5.0, 5.0);
f1.setParameter(0, 120.0);
f1.setParameter(1, (-3.0 + rand.nextDouble() * 6));
f1.setParameter(2, .4 + (rand.nextDouble() * 1));
RandomFunc rndm = new RandomFunc(f1);
for (int j = 0; j < 34000; j++) {
h1[i].fill(rndm.random());
}
//Build OptStat settings for each pad to demonstrate how to set up the StatBox
String optStatString = "";
for(int j=0; j<3-i%4; j++){
optStatString +="1";
}
optStatString+="00";
f1.setOptStat(Integer.parseInt(optStatString));
c1.cd(i);
c1.draw(h1[i]);
c1.getPad(i).getAxisX().setRange(-6.0, 5.0); //Works for any Axis, this turns off autoscale
//Set up the F1D for use with the Fitter
f1.setParameter(0, h1[i].getEntries()); //Due to initial parameter estimates not existing
DataFitter.fit(f1, h1[i], "Q"); //No options uses error for sigma
c1.draw(f1,"same");
f1.setLineColor(30 + (i % 4) + 2);
f1.setLineWidth(3);
f1.setLineStyle(i%4);
}
c1.showFPS(true); //For debug use, shows frames/sec in the upper left corner
frame.add(c1);
frame.setLocationRelativeTo(null);
frame.setVisible(true);