Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 267 → Rev 268

/belle2/masterclass/index.php
31,7 → 31,7
 
<!-- <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?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" language = "javascript">
var es;
52,8 → 52,8
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';
 
60,7 → 60,55
}
 
 
var cnt=0;
function fitpanel(oFormElement)
{
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 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" >';
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();
}
}
xhr.open (oFormElement.method, oFormElement.action, true);
 
var data = new FormData (oFormElement);
xhr.send (data);
return false; // Markus had to return true
}
 
 
 
function startTask() {
var r = document.getElementById('results');
86,6 → 134,8
}
 
function EventListener(e) {
//addLog(JSON.stringify(e) );
 
var result = JSON.parse( e.data );
 
if(e.lastEventId == 'CLOSE') {
104,16 → 154,36
showStat(result.message);
} else {
var jsonobj = JSROOT.parse(result.message);
var sframe = 'rh'+ (cnt++);
addLog('ROOT_JSON object '+ sframe );
//var r = document.getElementById('results');
var r = document.getElementById('drawing');
r.insertAdjacentHTML('beforeend', '<div id="' + sframe +'" style="width:60%; height:60%;"></div><br/>');
var sframe = jsonobj.fName;
addLog('Histogram :'+ sframe );
var r = document.getElementById('results');
//var r = document.getElementById('drawing');
if (document.getElementById(sframe) == null ){
r.insertAdjacentHTML('beforeend', '<div id="' + sframe +'" style="width:1000px; height:600px"></div><br/>');
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 += ' Range: min=<input type="text" size="2" value="0" name="min" />';
mform += ' max:<input type="text" size="2" value="10" name="max" />';
mform += ' Function:<input type="text" size="5" value="gaus" name="fitfun" />';
mform += ' Initial parameters<input type="text" size="5" value="1;2;3" name="prm" />';
mform += ' <input id="data'+ sframe +'" type="hidden" value="'+ result.message +'" name="data" />';
mform += ' <input type="hidden" value="'+ sframe +'" name="name" />';
mform += '</form>';
 
fit.insertAdjacentHTML('beforeend', mform);
fit.insertAdjacentHTML('beforeend', '<div id="param' + sframe +'"></div><br/>');
r.insertAdjacentHTML('beforeend','<input type="button" onclick="togglevisibility(\'fit'+sframe+'\');" class="mybutton" value="Show/Hide Fit Panel" /><hr/>' );
document.getElementById('data'+ sframe).value=result.message;
//r.insertAdjacentHTML('beforeend', JSON.stringify(result.message));
}
var frame = document.getElementById(sframe);
//JSROOT.draw(frame, jsonobj, "hist");
JSROOT.draw(sframe, jsonobj, "hist");
//addLog('JSON :' + JSON.stringify(jsonobj)+ '<br>');
JSROOT.redraw(sframe, jsonobj, "hist");
 
frame.scrollIntoView();
}
134,7 → 204,7
}
 
/*
function switchTask() {
var div = document.getElementById('results');
var divs = document.getElementById('sbar');
152,12 → 222,24
}
 
}
*/
 
 
function togglevisibility( name ) {
var div = document.getElementById(name);
if (div.style.display !== 'none') {
div.style.display = 'none';
}
else {
div.style.display = 'block';
}
}
 
 
function readSingleFile(e) {
 
var div0 = document.getElementById('blocklyDiv');
if (div0.style.display === 'none') switchTask();
//if (div0.style.display === 'none') switchTask();
 
var file = e.target.files[0];
if (!file) {
239,31 → 321,23
}
 
 
 
 
 
</script>
</head>
<body>
<h1>Belle II Masterclass: Define process &rarr;Analyse data &rarr;Visualise results &rarr;Save/load process locally</h1>
<h1>Belle II Masterclass: Describe process &rarr;Run analysis &rarr;Fit results &rarr;Save/load process locally</h1>
<!-- <input type="button" onclick="showCode();" class="mybutton" value="Show JavaScript" /> -->
<input type="button" onclick="startTask();" class="mybutton" value="Run Analysis" />
<input type="button" onclick="stopTask();" class="mybutton" value="Interrupt" />
<input type="button" onclick="switchTask();" class="mybutton" value="Switch between Diagram and Results" />
<!-- <input type="button" onclick="switchTask();" class="mybutton" value="Switch between Diagram and Results" /> -->
<input type="button" onclick="saveBlockly();" class="mybutton" value="Save Diagram" />
<form style="display:inline;"><label for="file-input" class="mybutton" style="">Load Diagram</label>
<input type="file" style="visibility:hidden;" id="file-input" onClick="this.form.reset()" data-buttonText="Load Diagram"/></form>
<br />
 
<input type="file" style="visibility:hidden;" id="file-input" onClick="this.form.reset()" data-buttonText="Load Diagram"/></form>
<br/>
<progress id='progressor' value="0" max='100' style="width:95%"></progress>
<span id="percentage" style="text-align:right; display:block; margin-top:5px;">0</span>
<p id="sbar" ></div>
 
<br />
 
<div id="blocklyDiv" style="height:500px; width:95%"></div><br />
334,6 → 408,6
 
 
</script>
<div id="drawing" style="width:800px; height:600px"></div>
<div id="drawing"></div>
</body>
</html>
/belle2/masterclass/src/Blab2.cc
205,9 → 205,12
}
 
send_message(2, TString::Format("Number of events processed %d\n", i ),100);
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
 
send_message(1,TBufferJSON::ConvertToJSON(fHnprt),100 );
send_message(1,TBufferJSON::ConvertToJSON(fHid),100 );
 
for (int i=0;i<100;i++) if (fH[i]!=0) send_message(1,TBufferJSON::ConvertToJSON(fH[i]),100 );
 
TDatime d;
timer.Stop();
send_message(3, TString::Format("'%s', %d, %f, %f", d.AsSQLString(),i, timer.RealTime(), timer.CpuTime() ),100);
/belle2/masterclass/th1fit.cc
0,0 → 1,44
#include <stdlib.h>
#include <stdio.h>
#include <TH1F.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TStyle.h>
#include <TBufferJSON.h>
//#include <TBufferXML.h>
class Hdr{
public:
int id;
int len;
int progress;
};
 
void send_message(int id, TString msg, int progress){
static Hdr hdr;
 
hdr.id = id;
hdr.len= msg.Length();
hdr.progress= progress;
fwrite(&hdr,3*sizeof(int),1,stdout);
fwrite(msg.Data(),hdr.len,1,stdout);
fflush(stdout);
 
}
 
 
 
int th1fit(Double_t *data, const char *name, const char *title, int xbins, double xmin, double xmax, double min=0, double max=1,const char *func=NULL, const char *pars=NULL){
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);
//TCanvas *v =new TCanvas();
h->Fit(f,"RQ");
h->Draw();
//v->Modified();
//v->Update();
send_message(1,TBufferJSON::ConvertToJSON(h),0 );
return 0;
}
/belle2/masterclass/th1fit.php
0,0 → 1,117
<?php
 
function send_message($id, $message, $progress) {
$d = array('message' => $message , 'progress' => $progress); //prepare json
$x = array('id' => $id, 'data' => $d );
echo json_encode($x) . PHP_EOL;
/*
if (PHP_SAPI !== 'cli') {
echo PHP_EOL;
ob_flush();
}
flush();
*/
}
 
 
function executeCmd($commandLine) {
$pipe = popen("$commandLine" , 'r');
 
if (!$pipe) {
print "pipe failed.";
return "";
}
$output = '';
$out = '';
while(!feof($pipe)) {
$contents = fread($pipe, 12);
$unpacked = unpack("l*",$contents);
$len0 = sizeof($unpacked);
if ($len0 > 2) {
$id = $unpacked[1];
$len = $unpacked[2];
$progress = $unpacked[3];
if ($len>0){
$out= fread($pipe, $len);
send_message($id,$out,$progress);
}
$output .=$out;
}
}
pclose($pipe);
return $output;
}
 
if (isset($_POST["min"])){
$min = $_POST["min"];
} else {
$min = 0;
}
 
if (isset($_POST["max"])){
$max = $_POST["max"];
} else {
$max = 10;
}
 
if (isset($_POST["fitfun"])){
$fitfun = $_POST["fitfun"];
} else {
$fitfun = "gaus";
}
 
if (isset($_POST["prm"])){
$prm = $_POST["prm"];
} else {
$prm = "0;1;2";
}
 
if (isset($_POST["name"])){
$name = $_POST["name"];
} else {
$name = "h101";
}
 
if (isset($_POST["data"])){
$data = $_POST["data"];
} else {
$data = '{ "_typename" : "TH1F", "fUniqueID" : 0, "fBits" : 50331656, "fName" : "h100", "fTitle" : "Number of particles in the event", "fLineColor" : 602, "fLineStyle" : 1, "fLineWidth" : 1, "fFillColor" : 0, "fFillStyle" : 1001, "fMarkerColor" : 1, "fMarkerStyle" : 1, "fMarkerSize" : 1, "fNcells" : 52, "fXaxis" : { "_typename" : "TAxis", "fUniqueID" : 0, "fBits" : 50331648, "fName" : "xaxis", "fTitle" : "N particles", "fNdivisions" : 510, "fAxisColor" : 1, "fLabelColor" : 1, "fLabelFont" : 42, "fLabelOffset" : 0.005, "fLabelSize" : 0.035, "fTickLength" : 0.03, "fTitleOffset" : 1, "fTitleSize" : 0.035, "fTitleColor" : 1, "fTitleFont" : 42, "fNbins" : 50, "fXmin" : -0.5, "fXmax" : 49.5, "fXbins" : [], "fFirst" : 0, "fLast" : 0, "fBits2" : 0, "fTimeDisplay" : false, "fTimeFormat" : "", "fLabels" : null, "fModLabs" : null }, "fYaxis" : { "_typename" : "TAxis", "fUniqueID" : 0, "fBits" : 50331648, "fName" : "yaxis", "fTitle" : "N events", "fNdivisions" : 510, "fAxisColor" : 1, "fLabelColor" : 1, "fLabelFont" : 42, "fLabelOffset" : 0.005, "fLabelSize" : 0.035, "fTickLength" : 0.03, "fTitleOffset" : 0, "fTitleSize" : 0.035, "fTitleColor" : 1, "fTitleFont" : 42, "fNbins" : 1, "fXmin" : 0, "fXmax" : 1, "fXbins" : [], "fFirst" : 0, "fLast" : 0, "fBits2" : 0, "fTimeDisplay" : false, "fTimeFormat" : "", "fLabels" : null, "fModLabs" : null }, "fZaxis" : { "_typename" : "TAxis", "fUniqueID" : 0, "fBits" : 50331648, "fName" : "zaxis", "fTitle" : "", "fNdivisions" : 510, "fAxisColor" : 1, "fLabelColor" : 1, "fLabelFont" : 42, "fLabelOffset" : 0.005, "fLabelSize" : 0.035, "fTickLength" : 0.03, "fTitleOffset" : 1, "fTitleSize" : 0.035, "fTitleColor" : 1, "fTitleFont" : 42, "fNbins" : 1, "fXmin" : 0, "fXmax" : 1, "fXbins" : [], "fFirst" : 0, "fLast" : 0, "fBits2" : 0, "fTimeDisplay" : false, "fTimeFormat" : "", "fLabels" : null, "fModLabs" : null }, "fBarOffset" : 0, "fBarWidth" : 1000, "fEntries" : 10000, "fTsumw" : 9983, "fTsumw2" : 9983, "fTsumwx" : 175205, "fTsumwx2" : 3620667, "fMaximum" : -1111, "fMinimum" : -1111, "fNormFactor" : 0, "fContour" : [], "fSumw2" : [], "fOption" : "", "fFunctions" : { "_typename" : "TList", "name" : "TList", "arr" : [], "opt" : [] }, "fBufferSize" : 0, "fBuffer" : [], "fBinStatErrOpt" : 0, "fArray" : [0, 0, 0, 0, 86, 122, 117, 135, 176, 263, 306, 367, 412, 508, 596, 643, 618, 566, 524, 552, 503, 439, 418, 374, 333, 311, 229, 222, 188, 172, 123, 120, 92, 82, 81, 53, 47, 32, 36, 28, 27, 17, 14, 9, 10, 6, 8, 6, 4, 5, 3, 17] }';
}
 
$json = json_decode($data, true);
$class = $json['_typename'];
$hname = $json['fName'];
$htitle= $json['fTitle'];
$xaxis = $json['fXaxis'];
$xtitle= $xaxis['fTitle'];
$xbins = $xaxis['fNbins'];
$xmin = $xaxis['fXmin'];
$xmax = $xaxis['fXmax'];
$yaxis = $json['fYaxis'];
$ytitle= $yaxis['fTitle'];
 
 
$hdata='';
foreach( $json['fArray'] as $key => $value){
if($key != "0"){
$hdata .= ", ";
}
$hdata .= $value;
}
 
$cmd0 = ".L th1fit.cc+". PHP_EOL;
$cmd0 .= "double data[]={". $hdata . "};" .PHP_EOL;
$cmd0 .= "th1fit(data, \"$hname\",\"$htitle;$xtitle;$ytitle\", $xbins , $xmin, $xmax, $min ,$max ,\"$fitfun\");". PHP_EOL;
 
if (file_exists('/opt/root/bin/thisroot.sh')){
$profile ='/opt/root/bin/thisroot.sh';
}
$cmd ="bash -c 'source $profile ; root -b -l <<EOL" . PHP_EOL;
$cmd .= $cmd0. PHP_EOL;
$cmd .= "EOL'". PHP_EOL;
executeCmd($cmd);
//echo $cmd0;
//echo "name=$name min=$min max=$max func=$fitfun data=$data";
?>