3 if (typeof
JSROOT !=
"object") {
4 var e1 =
new Error(
"condition.js requires JSROOT to be already loaded");
5 e1.source =
"condition.js";
9 if (typeof
GO4 !=
"object") {
10 var e1 =
new Error(
"condition.js requires GO4 to be already loaded");
11 e1.source =
"condition.js";
19 GO4.ConditionEditor =
function(divid, cond) {
20 BasePainter.call(
this, divid);
21 if (this.SetDivId) this.SetDivId(divid);
23 this.changes = [
"dummy",
"init"];
27 GO4.ConditionEditor.prototype = Object.create(BasePainter.prototype);
29 GO4.ConditionEditor.prototype.isPolyCond =
function() {
30 return ((this.cond._typename ==
"TGo4PolyCond") || (this.cond._typename ==
"TGo4ShapedCond"));
33 GO4.ConditionEditor.prototype.isEllipseCond =
function() {
34 return (this.cond._typename ==
"TGo4ShapedCond");
38 GO4.ConditionEditor.prototype.MarkChanged =
function(key) {
40 for (var index = 0; index < this.changes.length; index++) {
41 if (this.changes[index]== key)
return;
43 this.changes.push(key);
44 console.log(
"Mark changed :%s", key);
45 var
id =
"#" + this.get_main_id();
47 $(
id+
" .buttonChangeLabel").show();
51 GO4.ConditionEditor.prototype.ClearChanges =
function() {
52 for (var index = 0; index < this.changes.length ; index++) {
53 var removed=this.changes.pop();
54 console.log(
"Clear changes removed :%s", removed);
56 var
id = this.get_main_id();
57 if (
id) $(
"#" +
id +
" .buttonChangeLabel").hide();
61 GO4.ConditionEditor.prototype.EvaluateChanges =
function(optionstring) {
62 var
id =
"#" + this.get_main_id();
64 var len=this.changes.length;
65 for (index = 0; index < len ; index++) {
67 var key=this.changes[index];
73 var xmin=$(
id+
" .cond_xmin")[0].value;
74 var xmax=$(
id+
" .cond_xmax")[0].value;
75 optionstring +=
"&xmin="+xmin+
"&xmax="+xmax;
76 this.cond.fLow1 = xmin;
77 this.cond.fUp1 = xmax;
78 if (this.cond.fiDim==2) {
79 var ymin=$(
id+
" .cond_ymin")[0].value;
80 var ymax=$(
id+
" .cond_ymax")[0].value;
81 this.cond.fLow2 = xmin;
82 this.cond.fUp2 = xmax;
83 optionstring +=
"&ymin="+ymin+
"&ymax="+ymax;
86 else if(key==
"polygon")
88 var npoints=$(
id+
" .cut_points")[0].value;
89 optionstring +=
"&npolygon="+npoints;
91 for(i=0; i<npoints; ++i)
93 var x = $(
id +
" .cut_values input").eq(2*i)[0].value;
94 var y = $(
id +
" .cut_values input").eq(2*i+1)[0].value;
95 optionstring +=
"&x"+i+
"="+x+
"&y"+i+
"="+y;
98 else if (key==
"ellinpts"){
99 var val=$(
id+
" .cond_ellipse_points")[0].value;
100 optionstring +=
"&"+key+
"="+val;
102 else if (key==
"ellicx"){
103 var val=$(
id+
" .cond_ellipse_cx")[0].value;
104 optionstring +=
"&"+key+
"="+val;
106 else if (key==
"ellicy"){
107 var val=$(
id+
" .cond_ellipse_cy")[0].value;
108 optionstring +=
"&"+key+
"="+val;
110 else if (key==
"ellia1"){
111 var val=$(
id+
" .cond_ellipse_a1")[0].value;
112 optionstring +=
"&"+key+
"="+val;
114 else if (key==
"ellia2"){
115 var val=$(
id+
" .cond_ellipse_a2")[0].value;
116 optionstring +=
"&"+key+
"="+val;
118 else if (key==
"ellishape"){
119 var arg=$(
id+
" .cond_ellipse_iscircle")[0].value;
120 optionstring +=
"&"+key+
"="+arg;
122 else if (key==
"ellith"){
123 var val=$(
id+
" .cond_ellipse_theta")[0].value;
124 optionstring +=
"&"+key+
"="+val;
126 else if (key==
"resultmode"){
127 var selected=$(
id+
" .cond_execmode")[0].value;
128 optionstring +=
"&"+key+
"="+selected;
130 else if (key==
"invertmode"){
131 var selected=$(
id+
" .cond_invertmode")[0].value;
132 optionstring +=
"&"+key+
"="+selected;
134 else if (key==
"visible"){
135 var checked=$(
id+
" .cond_visible")[0].checked;
136 var arg= (checked ?
"1" :
"0");
137 optionstring +=
"&"+key+
"="+arg;
139 else if (key==
"labeldraw"){
140 var checked=$(
id+
" .cond_label")[0].checked;
141 var arg= (checked ?
"1" :
"0");
142 this.cond.fbLabelDraw=arg;
143 optionstring +=
"&"+key+
"="+arg;
145 else if (key==
"limitsdraw"){
146 var checked=$(
id+
" .cond_limits")[0].checked;
147 var arg= (checked ?
"1" :
"0");
148 this.cond.fbLimitsDraw=arg;
149 optionstring +=
"&"+key+
"="+arg;
151 else if (key==
"intdraw"){
152 var checked=$(
id+
" .cond_integr")[0].checked;
153 var arg= (checked ?
"1" :
"0");
154 this.cond.fbIntDraw=arg;
155 optionstring +=
"&"+key+
"="+arg;
157 else if (key==
"xmeandraw"){
158 var checked=$(
id+
" .cond_xmean")[0].checked;
159 var arg= (checked ?
"1" :
"0");
160 this.cond.fbXMeanDraw=arg;
161 optionstring +=
"&"+key+
"="+arg;
163 else if (key==
"xrmsdraw"){
164 var checked=$(
id+
" .cond_xrms")[0].checked;
165 var arg= (checked ?
"1" :
"0");
166 this.cond.fbXRMSDraw=arg;
167 optionstring +=
"&"+key+
"="+arg;
169 else if (key==
"ymeandraw"){
170 var checked=$(
id+
" .cond_ymean")[0].checked;
171 var arg= (checked ?
"1" :
"0");
172 this.cond.fbYMeanDraw=arg;
173 optionstring +=
"&"+key+
"="+arg;
175 else if (key==
"yrmsdraw"){
176 var checked=$(
id+
" .cond_yrms")[0].checked;
177 var arg= (checked ?
"1" :
"0");
178 this.cond.fbYRMSDraw=arg;
179 optionstring +=
"&"+key+
"="+arg;
181 else if (key==
"xmaxdraw"){
182 var checked=$(
id+
" .cond_maxx")[0].checked;
183 var arg= (checked ?
"1" :
"0");
184 this.cond.fbXMaxDraw=arg;
185 optionstring +=
"&"+key+
"="+arg;
187 else if (key==
"ymaxdraw"){
188 var checked=$(
id+
" .cond_maxy")[0].checked;
189 var arg= (checked ?
"1" :
"0");
190 this.cond.fbYMaxDraw=arg;
191 optionstring +=
"&"+key+
"="+arg;
193 else if (key==
"cmaxdraw"){
194 var checked=$(
id+
" .cond_max")[0].checked;
195 var arg= (checked ?
"1" :
"0");
196 this.cond.fbCMaxDraw=arg;
197 optionstring +=
"&"+key+
"="+arg;
200 console.log(
"Warning: EvaluateChanges found unknown key:%s", key);
204 console.log(
"Resulting option string:%s", optionstring);
208 GO4.ConditionEditor.prototype.CheckResize =
function() {}
209 GO4.ConditionEditor.prototype.checkResize =
function() {}
212 GO4.ConditionEditor.prototype.ChangePolygonDimension =
function() {
218 var
id =
"#" + this.get_main_id();
219 var oldpoints=this.cond.fxCut.fNpoints;
220 var npoints=$(
id+
" .cut_points")[0].value;
221 console.log(
"ChangePolygonDimension with numpoints="+npoints+
", oldpoints="+oldpoints);
223 if (this.cond.fxCut != null) {
225 $(
id +
" .cut_values tbody").html(
"");
226 if (npoints > oldpoints) {
229 for (i = 0; i < oldpoints - 1; i++) {
230 var x = this.cond.fxCut.fX[i];
231 var y = this.cond.fxCut.fY[i];
232 $(
id +
" .cut_values tbody")
234 "<tr><td><input type='text' value='"
236 +
"'/></td> <td> <input type='text' value='"
237 + y +
"'/> </td></tr>");
238 console.log(
"i:" + i +
", X=" + x +
" Y=" + y);
241 var insx = this.cond.fxCut.fX[oldpoints - 2];
242 var insy = this.cond.fxCut.fY[oldpoints - 2];
243 for (i = oldpoints - 1; i < npoints - 1; i++) {
244 $(
id +
" .cut_values tbody")
246 "<tr><td><input type='text' value='"
248 +
"'/></td> <td> <input type='text' value='"
249 + insy +
"'/> </td></tr>");
250 console.log(
"i:" + i +
", X=" + insx +
" Y=" + insy);
254 var lastx = this.cond.fxCut.fX[oldpoints - 1];
255 var lasty = this.cond.fxCut.fY[oldpoints - 1];
256 $(
id +
" .cut_values tbody").append(
257 "<tr><td><input type='text' value='" + lastx
258 +
"'/></td> <td> <input type='text' value='"
259 + lasty +
"'/> </td></tr>");
260 console.log(
"i:" + (npoints - 1) +
", X=" + lastx +
" Y=" + lasty);
266 for (i = 0; i < npoints - 1; i++) {
267 var x = this.cond.fxCut.fX[i];
268 var y = this.cond.fxCut.fY[i];
269 $(
id +
" .cut_values tbody")
271 "<tr><td><input type='text' value='"
273 +
"'/></td> <td> <input type='text' value='"
274 + y +
"'/> </td></tr>");
275 console.log(
"i:" + i +
", X=" + x +
" Y=" + y);
279 var lastx = this.cond.fxCut.fX[oldpoints - 1];
280 var lasty = this.cond.fxCut.fY[oldpoints - 1];
281 $(
id +
" .cut_values tbody").append(
282 "<tr><td><input type='text' value='" + lastx
283 +
"'/></td> <td> <input type='text' value='"
284 + lasty +
"'/> </td></tr>");
285 console.log(
"i:" + (npoints - 1) +
", X=" + lastx +
" Y=" + lasty);
292 GO4.ConditionEditor.prototype.refreshEditor =
function() {
294 var
id =
"#" + this.get_main_id();
295 var cond = this.cond;
297 $(
id+
" .cond_name").text(cond.fName);
298 $(
id+
" .cond_type").text(cond._typename);
302 $(
id+
" .cond_execmode").val(0);
306 $(
id+
" .cond_execmode").val(1);
308 $(
id+
" .cond_execmode").val(2);
310 $(
id+
" .cond_execmode").selectmenu(
"refresh");
311 $(
id+
" .cond_execmode").selectmenu(
"option",
"width",
"100%");
313 $(
id+
" .cond_invertmode").val(0);
315 $(
id+
" .cond_invertmode").val(1);
317 $(
id+
" .cond_invertmode").selectmenu(
"refresh");
318 $(
id+
" .cond_invertmode").selectmenu(
"option",
"width",
"100%");
321 $(
id+
" .cond_xmin").val(cond.fLow1).change(
function(){ editor.MarkChanged(
"limits")});
322 $(
id+
" .cond_xmax").val(cond.fUp1).change(
function(){ editor.MarkChanged(
"limits")});
324 $(
id+
" .cond_ymin").val(cond.fLow2).change(
function(){editor.MarkChanged(
"limits")});
325 $(
id+
" .cond_ymax").val(cond.fUp2).change(
function(){ editor.MarkChanged(
"limits")});
327 $(
id+
" .cond_ymin").prop(
'disabled',
true);
328 $(
id+
" .cond_ymax").prop(
'disabled',
true);
332 $(
id+
" .cond_tabs").tabs(
"disable", 0 );
333 $(
id+
" .cond_tabs").tabs(
"enable", 1 );
334 if (this.cond.fxCut != null) {
335 var numpoints=this.cond.fxCut.fNpoints;
336 console.log(
"refreshEditor: npoints="+numpoints);
337 $(
id+
" .cut_points").val(numpoints);
338 $(
id +
" .cut_values tbody").html(
"");
341 for(i = 0; i < numpoints; i++) {
342 var x= this.cond.fxCut.fX[i];
343 var y= this.cond.fxCut.fY[i];
344 $(
id +
" .cut_values tbody").append(
"<tr><td><input type='text' value='" + x +
"'/></td> <td> <input type='text' value='" + y +
"'/> </td></tr>");
345 console.log(
"i:"+i+
", X="+x+
" Y="+y);
347 $(
id +
" .cut_values tbody").change(
function(){ editor.MarkChanged(
"polygon")});
350 if(this.isEllipseCond()) {
351 $(
id+
" .cond_tabs").tabs(
"enable", 2 );
352 var numpoints=this.cond.fiResolution;
353 $(
id+
" .cond_ellipse_points").val(numpoints);
354 $(
id+
" .cond_ellipse_cx").val(cond.fdCenterX).change(
function(){ editor.MarkChanged(
"ellicx")});
355 $(
id+
" .cond_ellipse_cy").val(cond.fdCenterY).change(
function(){ editor.MarkChanged(
"ellicy")});
356 $(
id+
" .cond_ellipse_a1").val(cond.fdRadius1).change(
function(){ editor.MarkChanged(
"ellia1")});
357 $(
id+
" .cond_ellipse_a2").val(cond.fdRadius2).prop(
'disabled', cond.fbIsCircle).change(
function(){ editor.MarkChanged(
"ellia2")});
358 $(
id+
" .cond_ellipse_theta").val(cond.fdTheta).prop(
'disabled', cond.fbIsCircle).change(
function(){
359 editor.MarkChanged(
"ellith");
360 $(
id+
" .cond_ellipse_theta_slider").slider(
"option",
"value", $(
this)[0].value % 360);
361 console.log(
"ellipse theta value="+$(
this)[0].value);
365 var options = $(
id+
" .cond_ellipse_iscircle")[0].options;
366 for ( var i = 0; i < options.length; i++){
367 options[i].selected = (options[i].value == cond.fiShapeType);
369 $(
id+
" .cond_ellipse_iscircle").selectmenu(
'refresh',
true).selectmenu(
"option",
"width",
"80%");;
372 $(
id +
" .cond_ellipse_theta_slider")
378 disabled: cond.fbIsCircle,
379 change :
function(event, ui) {
380 editor.MarkChanged(
"ellith");
381 $(
id +
" .cond_ellipse_theta").val(ui.value);
382 console.log(
"slider changed to" + ui.value);
384 stop :
function(event, ui) {
385 editor.MarkChanged(
"ellith");
386 console.log(
"sliderstopped.");
397 console.log(
"refreshEditor: - NO POLYGON CUT");
398 $(
id+
" .cond_tabs").tabs(
"enable", 0 );
399 $(
id+
" .cond_tabs").tabs(
"disable", 1 );
400 $(
id+
" .cond_tabs").tabs(
"disable", 2 );
404 $(
id+
" .cond_counts").text(cond.fiCounts);
405 $(
id+
" .cond_true").text(cond.fiTrueCounts);
406 $(
id+
" .cond_percent").text((cond.fiCounts > 0 ? 100. * cond.fiTrueCounts / cond.fiCounts : 0.).toFixed(2) +
"%");
412 $(
id+
" .cond_visible")
413 .prop(
'checked', cond.fbVisible)
414 .click(
function() { cond.fbVisible = this.checked; editor.MarkChanged(
"visible")});
415 $(
id+
" .cond_limits")
416 .prop(
'checked', cond.fbLimitsDraw)
417 .click(
function() { cond.fbLimitsDraw = this.checked; editor.MarkChanged(
"limitsdraw")});
420 .prop(
'checked', cond.fbLabelDraw)
421 .click(
function() { cond.fbLabelDraw = this.checked; editor.MarkChanged(
"labeldraw")});
424 $(
id+
" .cond_integr")
425 .prop(
'checked', cond.fbIntDraw)
426 .click(
function() { cond.fbIntDraw = this.checked; editor.MarkChanged(
"intdraw")});
429 .prop(
'checked', cond.fbXMaxDraw)
430 .click(
function() { cond.fbXMaxDraw = this.checked; editor.MarkChanged(
"xmaxdraw")});
433 .prop(
'checked', cond.fbCMaxDraw)
434 .click(
function() { cond.fbCMaxDraw = this.checked; editor.MarkChanged(
"cmaxdraw")});
437 .prop(
'checked', cond.fbYMaxDraw)
438 .click(
function() { cond.fbYMaxDraw = this.checked; editor.MarkChanged(
"ymaxdraw")});
441 .prop(
'checked', cond.fbXMeanDraw)
442 .click(
function() { cond.fbXMeanDraw = this.checked; editor.MarkChanged(
"xmeandraw")});
445 .prop(
'checked', cond.fbXRMSDraw)
446 .click(
function() { cond.fbXRMSDraw = this.checked; editor.MarkChanged(
"xrmsdraw")});
449 .prop(
'checked', cond.fbYMeanDraw)
450 .click(
function() { cond.fbYMeanDraw = this.checked; editor.MarkChanged(
"ymeandraw")});
453 .prop(
'checked', cond.fbYRMSDraw)
454 .click(
function() { cond.fbYRMSDraw = this.checked; editor.MarkChanged(
"yrmsdraw")});
457 editor.ClearChanges();
463 GO4.ConditionEditor.prototype.fillEditor =
function(divid, resolve) {
465 this.setTopPainter();
467 this.SetDivId(divid);
469 var
id =
"#" + divid;
471 var cond = this.cond;
472 console.log(
"GO4.ConditionEditor.prototype.fillEditor " + this.cond.fName);
475 $(
id+
" .cond_tabs").tabs();
477 $(
id +
" .cond_execmode").selectmenu({
478 change :
function(event, ui) {
479 editor.MarkChanged(
"resultmode");
482 $(
id +
" .cond_invertmode").selectmenu({
483 change :
function(event, ui) {
484 editor.MarkChanged(
"invertmode");
488 if(this.isEllipseCond()) {
489 $(
id+
" .cond_ellipse_iscircle").selectmenu({
490 change :
function(event, ui) {
491 cond.fiShapeType = ui.item.value;
492 if(cond.fiShapeType == 2)
495 $(
id+
" .cond_ellipse_a2").prop(
'disabled',
true);
496 $(
id+
" .cond_ellipse_theta").prop(
'disabled',
true);
497 $(
id +
" .cond_ellipse_theta_slider").slider(
"disable");
498 $(
id +
"cond_ellipse_points").prop(
'disabled',
false);
500 else if(cond.fiShapeType == 3)
503 $(
id+
" .cond_ellipse_a2").prop(
'disabled',
false);
504 $(
id+
" .cond_ellipse_theta").prop(
'disabled',
false);
505 $(
id +
" .cond_ellipse_theta_slider").slider(
"enable");
506 $(
id +
"cond_ellipse_points").prop(
'disabled',
false);
510 else if(cond.fiShapeType == 4)
513 $(
id+
" .cond_ellipse_a2").prop(
'disabled',
false);
514 $(
id+
" .cond_ellipse_theta").prop(
'disabled',
false);
515 $(
id +
" .cond_ellipse_theta_slider").slider(
"enable");
516 $(
id +
"cond_ellipse_points").prop(
'disabled',
true);
521 $(
id+
" .cond_ellipse_a2").prop(
'disabled',
true);
522 $(
id+
" .cond_ellipse_theta").prop(
'disabled',
true);
523 $(
id +
" .cond_ellipse_theta_slider").slider(
"disable");
524 $(
id +
"cond_ellipse_points").prop(
'disabled',
false);
528 editor.MarkChanged(
"ellishape");
534 $(
id+
" .buttonGetCondition")
535 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}})
537 console.log(
"update item = " + editor.getItemName());
538 if (
JSROOT.hpainter)
JSROOT.hpainter.display(editor.getItemName());
539 else console.log(
"hierarhy painter object not found!");
542 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/right.png)");
546 $(
id+
" .buttonSetCondition")
547 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}})
550 options=editor.EvaluateChanges(options);
551 console.log(
"set - condition "+ editor.getItemName()+
", options="+options);
552 GO4.ExecuteMethod(editor,
"UpdateFromUrl",options,
function(result) {
553 console.log(result ?
"set condition done. " :
"set condition FAILED.");
554 if(result) editor.ClearChanges();
558 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/left.png)");
561 $(
id+
" .buttonChangeLabel")
562 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}})
565 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/info1.png)");
567 $(
id+
" .buttonDrawCondition")
568 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}})
573 editor.EvaluateChanges(
"");
575 if (
JSROOT.hpainter.updateOnOtherFrames(editor, editor.cond))
return;
577 JSROOT.hpainter.drawOnSuitableHistogram(editor, editor.cond, editor.cond.fiDim==2);
585 var baseurl = editor.getItemName() +
"/";
586 var drawurl = baseurl +
"draw.htm", editorurl = baseurl +
"draw.htm?opt=editor";
587 console.log(
"draw condition to next window with url="+drawurl);
589 window.open(drawurl,
'_blank');
603 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/chart.png)");
606 $(
id+
" .buttonClearCondition")
607 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}})
609 console.log(
"clearing counters...");
610 var options=
"&resetcounters=1";
611 GO4.ExecuteMethod(editor,
"UpdateFromUrl",options,
function(result) {
612 console.log(result ?
"reset condition counters done. " :
"reset condition counters FAILED.");
614 if(
JSROOT.hpainter)
JSROOT.hpainter.display(editor.getItemName());
615 else console.log(
"hpainter object not found!");
620 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/clear.png)");
622 $(
id+
" .cut_points").spinner({
627 change:
function( event, ui ) {editor.ChangePolygonDimension();
629 stop:
function( event, ui ) {editor.ChangePolygonDimension();
633 $(
id+
" .cond_ellipse_points").spinner({
638 change:
function( event, ui ) {editor.MarkChanged(
"ellinpts");console.log(
"ellipse points changed.");
640 stop:
function( event, ui ) {editor.MarkChanged(
"ellinpts");console.log(
"ellipse points stopped.");
644 this.refreshEditor();
646 if (resolve) resolve(
this);
647 else this.DrawingReady();
653 GO4.ConditionEditor.prototype.drawEditor =
function(divid, resolve) {
656 .load(
GO4.source_dir +
"html/condeditor.htm",
"", () =>
this.fillEditor(divid, resolve));
661 GO4.ConditionEditor.prototype.redrawObject =
function(obj) {
662 if (obj._typename !=
this.cond._typename)
return false;
663 this.cond =
JSROOT.clone(obj);
664 this.refreshEditor();
669 GO4.ConditionEditor.prototype.RedrawPad =
function(resize) {
670 this.refreshEditor();
673 GO4.ConditionEditor.prototype.UpdateObject =
function(obj) {
674 if (obj._typename !=
this.cond._typename)
return false;
675 this.cond =
JSROOT.clone(obj);
GO4 AnalysisStatusEditor prototype MarkChanged
GO4 ConditionEditor prototype isPolyCond