Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 269 → Rev 270

/belle2/masterclass/index.php
31,15 → 31,13
 
<!-- <script type="text/javascript" src="js/JSRootCore.js?2d&onload=startGUI""></script> -->
<script type="text/javascript" src="https://root.cern/js/latest/scripts/JSRootCore.js?more2d&math&onload=startGUI"></script>
<script type="text/javascript" src="https://root.cern/js/latest/scripts/JSRootCore.js?2d&onload=startGUI"></script>
<script type = "text/javascript" language = "javascript">
var es;
function addLog(message) {
var r = document.getElementById('results');
//r.innerHTML += message + '<br>';
var r = document.getElementById('results');
r.insertAdjacentHTML('beforeend', message +'<br/>');
// r.scrollTop = r.scrollHeight;
}
 
function showStat(message) {
52,10 → 50,11
function startGUI() {
// d3.select('html').style('height','100%');
// d3.select('body').style({'min-height':'100%', 'margin':'0px', "overflow" :"hidden"});
// var r = document.getElementById('results');
// r.style.display = 'none';
// var r = document.getElementById('results');
// r.style.display = 'none';
var r0 = document.getElementById('sbar');
r0.style.display = 'none';
JSROOT.gStyle.fOptFit = 1111;
 
}
 
65,38 → 64,25
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
var event = JSON.parse(xhr.responseText);
var result = event.data;
var th1 = JSROOT.parse(result.message);
var hname = th1.fName;
var r = document.getElementById('drawing');
if (document.getElementById(hname) == null ){
r.insertAdjacentHTML('beforeend', '<div id="' + hname +'" style="width:80%; height:80%;"></div><br/>');
}
var hframe = document.getElementById(hname);
hframe.innerHTML = '';
// https://github.com/root-project/jsroot/issues/42
JSROOT.draw(hname, th1, "hist");
JSROOT.gStyle.fOptFit = 1111;
JSROOT.draw(hname, th1, "func");
 
var event = JSON.parse(xhr.responseText);
var result =event.data;
var jsonobj = JSROOT.parse(result.message);
var sframe = jsonobj.fName;
var tf1 = jsonobj.fFunctions.arr[0];
var tformula = tf1.fFormula;
var len = tf1.fNpar;
// addLog('#TF1 ' +JSON.stringify(tf1, null, '\t')+ '$$$<br>');
mtext = '<br/>' + "Fit Function: " + tformula.fFormula+ '<br/>';
mtext +="Chi2/NDF: " + tf1.fChisquare.toPrecision(2) + " / "+ tf1.fNDF+ '<br/>';
mtext +='<table border="0" width="50%" >';
for ( var i = 0;i <len;i++){
var name = tformula.fParams[i].first;
var val = tformula.fClingParameters[i];
var err = tf1.fParErrors[i];
mtext += "<tr><td>" + name + " <td> " + val.toPrecision(4) + " <td>+-<td>" + err.toPrecision(2) + '<br/>';
}
mtext +="</table><br/>";
var mdiv = document.getElementById('param' + sframe);
mdiv.innerHTML = mtext;
var r = document.getElementById('drawing');
if (document.getElementById(sframe) == null ){
r.insertAdjacentHTML('beforeend', '<div id="' + sframe +'" style="width:80%; height:80%;"></div><br/>');
}
var frame = document.getElementById(sframe);
frame.innerHTML = '';
JSROOT.draw(sframe, jsonobj, "hist");
JSROOT.draw(sframe, jsonobj, "func");
document.getElementById('data'+ sframe).value=result.message;
frame.scrollIntoView();
document.getElementById('data'+ hname).value=result.message;
//frame.scrollIntoView();
}
}
xhr.open (oFormElement.method, oFormElement.action, true);
165,13 → 151,13
r.insertAdjacentHTML('beforeend', '<div id="fit' + sframe +'" style="display: none"></div><br/>');
var fit = document.getElementById('fit'+ sframe);
mform ='<form method="post" action="th1fit.php" onsubmit="return fitpanel(this);">';
mform += ' <input class="mybutton" type="submit" value=" Fit "/>';
mform += ' Function:<input type="text" size="20" value="gaus" name="fitfun" /><br/>';
mform += ' Range: min=<input type="text" size="2" value="0" name="min" />';
mform += ' max:<input type="text" size="2" value="20" name="max" />';
mform += ' Function:<input type="text" size="5" value="gaus" name="fitfun" />';
mform += ' Initial parameters<input type="text" size="5" value="" name="prm" />';
mform += ' max=<input type="text" size="2" value="20" name="max" /><br/>';
mform += ' Initial parameters (separated by ,)<input type="text" size="20" value="" name="prm" /><br/>';
mform += ' <input id="data'+ sframe +'" type="hidden" value="'+ result.message +'" name="data" />';
mform += ' <input type="hidden" value="'+ sframe +'" name="name" />';
mform += ' <input class="mybutton" type="submit" value=" Fit "/>';
mform += '</form>';
fit.insertAdjacentHTML('beforeend', '<div id="param' + sframe +'"></div><br/>');
fit.insertAdjacentHTML('beforeend', mform);
180,7 → 166,7
//r.insertAdjacentHTML('beforeend', JSON.stringify(result.message));
}
var frame = document.getElementById(sframe);
JSROOT.redraw(sframe, jsonobj, "hist");
 
/belle2/masterclass/th1fit.cc
34,8 → 34,6
TH1F *h = new TH1F(name,title,xbins, xmin,xmax);
for (int i=0;i<xbins+2;i++) h->SetBinContent(i,data[i]);
 
gStyle->SetOptFit(1111);
TF1 *f = new TF1("f",func,min,max);
 
char *s = (char *)pars;
65,7 → 63,6
 
 
h->Fit(f,"RQ");
h->Draw();
 
send_message(1,TBufferJSON::ConvertToJSON(h),0 );
return 0;