KaliVeda
Toolkit for HIC analysis
KVIDentifier.cpp
1 /*
2 $Id: KVIDentifier.cpp,v 1.8 2009/04/20 12:16:50 ebonnet Exp $
3 $Revision: 1.8 $
4 $Date: 2009/04/20 12:16:50 $
5 */
6 
7 //Created by KVClassFactory on Mon Apr 14 14:25:38 2008
8 //Author: franklan
9 
10 #include "KVIDentifier.h"
11 #include "KVIDGraph.h"
12 #include "TF1.h"
13 #include "TPad.h"
14 #include "TClass.h"
15 
16 using namespace std;
17 
19 
20 
21 
22 
23 
30 void KVIDentifier::init()
31 {
32  // Default initialisations
33  // We set marker size and style for the underlying TGraph,
34  // this way a small circle is drawn at each point.
35  // Also SetEditable(kFALSE) is used to stop it being modified using the mouse.
36 
37 // SetMarkerStyle(kCircle);
38  SetMarkerStyle(20);
39  SetMarkerSize(1);
40  SetLineWidth(2);
41  SetEditable(kFALSE);
42  fParent = 0;
43  fGridOnlyZId = kFALSE;
44 }
45 
46 
47 
50 
52  : TCutG(), fIon(1, 1)
53 {
54  // Default constructor
55  init();
56 }
57 
58 
59 
62 
64 {
65  // Destructor
66 }
67 
68 
69 
72 
74  : TCutG(gr), fIon(1, 1)
75 {
76  //copy a TCutG
77  init();
78 }
79 
80 
81 
84 
86  : TCutG(), fIon(1, 1)
87 {
88  //copy a TGraph
89  init();
90  CopyGraph(gr);
91 }
92 
93 
94 
99 
101  : TCutG(), fIon(1, 1)
102 {
103  // copy constructor
104  // we do not copy the fParent pointer to parent grid,
105  // it is left NULL.
106  init();
107  gr.Copy(*this);
108 }
109 
110 
111 
114 
115 void KVIDentifier::Copy(TObject& obj) const
116 {
117  // Copy attributes of this identifier into 'obj'
118  TNamed::Copy(obj);
119  TAttLine::Copy((TAttLine&)obj);
120  TAttFill::Copy((TAttFill&)obj);
122  ((KVIDentifier&)obj).CopyGraph((TGraph*)this);
123  ((TCutG&)obj).SetVarX(GetVarX());
124  ((TCutG&)obj).SetVarY(GetVarY());
125  ((KVIDentifier&)obj).SetZ(GetZ());
126  ((KVIDentifier&)obj).SetA(GetA());
127  ((KVIDentifier&)obj).SetOnlyZId(OnlyZId());
128  ((KVIDentifier&)obj).SetMassFormula(GetMassFormula());
129 }
130 
131 
132 
135 
137 {
138  // Get pointer to parent ID graph
139  return fParent;
140 }
141 
142 
143 
146 
148 {
149  // Set pointer to parent ID graph
150  fParent = p;
151 }
152 
153 
154 
157 
159 {
160  // If identifier belongs to a graph/grid, send signal to say it has been modified
161  if(GetParent()) GetParent()->Modified();
162 }
163 
164 
165 
166 
169 
171 {
172  // Copy coordinates of points from the TGraph
173 
174  Double_t x, y;
175  //change number of points
176  Set(graph->GetN());
177  for (int i = 0; i < GetN(); i++) {
178  graph->GetPoint(i, x, y);
179  SetPoint(i, x, y);
180  }
181 }
182 
183 
184 
185 
188 
190 {
191  // Copy coordinates of points from the TGraph
192 
193  Double_t x, y;
194  //change number of points
195  Set(graph.GetN());
196  for (int i = 0; i < GetN(); i++) {
197  graph.GetPoint(i, x, y);
198  SetPoint(i, x, y);
199  }
200 }
201 
202 
203 
204 
217 
218 void KVIDentifier::WriteAsciiFile(ofstream& file, const Char_t* name_prefix)
219 {
220  //Write name and coordinates of identifier in file buffer stream
221  //Optional string name_prefix will be written just in front of the name of the object.
222  //Format is :
223  //
224  //+classname
225  //name_prefix:name_of_object
226  //number_of_points
227  //x1 y1
228  //x2 y2
229  //...
230  //etc. etc.
231 
232  file << '+' << ClassName() << endl;
233  if (name_prefix)
234  file << name_prefix << ":";
235  file << GetName() << endl;
236  //any extra stuff defined in child class ?
237  WriteAsciiFile_extras(file, name_prefix);
238  file << GetN() << endl;
239  for (Int_t i = 0; i < GetN(); i++) {
240  Double_t x, y;
241  GetPoint(i, x, y);
242  file << x << " " << y << endl;
243  }
244 }
245 
246 
247 
248 
258 
260 {
261  //Read coordinates of identifier in file buffer stream
262  //Format is :
263  //
264  //number_of_points
265  //x1 y1
266  //x2 y2
267  //...
268  //etc. etc.
269 
270  ReadAsciiFile_extras(file);//any extra stuff defined in child class ?
271  Int_t N;
272  file >> N;
273  for (Int_t i = 0; i < N; i++) {
274  Double_t x, y;
275  file >> x >> y;
276  SetPoint(i, x, y);
277  }
278 }
279 
280 
281 
282 
286 
288 {
289  //Dummy method used for sorting, can be redefined in more specific implementations.
290  //A priori we don't know how to "order" the identification cuts.
291 
292  return 0;
293 }
294 
295 
296 
297 
303 
305 {
306  // Print out for identification cut
307  // The optional "opt" string, if given, is printed in parentheses after the line's name
308  // This is used by KVIDGraph in order to show which are "ID" cuts and which are
309  // "OK" cuts (i.e. used to define an identifiable area in a data map).
310 
311  cout << ClassName() << " : " << GetName() << "(" << opt << ")" << endl;
312  TCutG::Print();
313 }
314 
315 
316 
317 
323 
325 {
326  //Scale the coordinates of every point of the cut according to
327  // X_0 ---> sx*X_0
328  // Y_0 ---> sy*Y_0
329  //Default argument value '-1' means leave coordinate unchanged
330  if (TMath::Abs(sx) == 1 && TMath::Abs(sy) == 1)
331  return;
332  for (int i = 0; i < fNpoints; i++) {
333  if (sx > 0.)
334  fX[i] *= sx;
335  if (sy > 0.)
336  fY[i] *= sy;
337  }
338 }
339 
340 
341 
342 
352 
354 {
355  // Apply to the coordinates of every point the transformation
356  // X_0 ---> sx(X_0,Y_0)
357  // Y_0 ---> sy(X_0,Y_0)
358  // if sx & sy are two-dimensional functions (inherits from TF2),
359  // otherwise we apply the transformation
360  // X_0 ---> sx(X_0)
361  // Y_0 ---> sy(Y_0)
362  // for sx & sy one-dimensionsal (TF1) functions.
363 
364  if (!sx && !sy) return; // if the two functions are NULL we leave coordinate unchanged
365  Bool_t sx_2d, sy_2d;
366  sx_2d = (sx && sx->InheritsFrom("TF2"));
367  sy_2d = (sy && sy->InheritsFrom("TF2"));
368  if (sx && sy) {
369  for (Int_t ii = 0; ii < fNpoints; ii++) {
370  Double_t fXp = 0.; // valeur intermediaire pour calculer X' et Y'
371  Double_t fYp = 0.; //a partir des coordonnees initiales
372  if (sx_2d) fXp = sx->Eval(fX[ii], fY[ii]);
373  else fXp = sx->Eval(fX[ii]);
374  if (sy_2d) fYp = sy->Eval(fX[ii], fY[ii]);
375  else fYp = sy->Eval(fY[ii]);
376  fX[ii] = fXp;
377  fY[ii] = fYp;
378  }
379  }
380  else if (sx) {
381  for (Int_t ii = 0; ii < fNpoints; ii++) {
382  if (sx_2d) fX[ii] = sx->Eval(fX[ii], fY[ii]);
383  else fX[ii] = sx->Eval(fX[ii]);
384  }
385  }
386  else {
387  for (Int_t ii = 0; ii < fNpoints; ii++) {
388  if (sy_2d) fY[ii] = sy->Eval(fX[ii], fY[ii]);
389  else fY[ii] = sy->Eval(fY[ii]);
390  }
391  }
392 }
393 
394 
395 
396 
400 
402 {
403  // Method used to draw a new identifier in the active pad
404  // Override in child classes so that gPad->WaitPrimitive has correct arguments
405 
406  if (!gPad) return;
407  TGraph* gr = (TGraph*) gPad->WaitPrimitive("CUTG", "CutG");
408  //copy coordinates of user's line
409  CopyGraph(gr);
410  //remove TGraph and draw the KVIDentifier in its place
411  gPad->GetListOfPrimitives()->Remove(gr);
412  delete gr;
413  Draw("PL");
414 }
415 
416 
417 
418 
427 
429 {
430  // Right-clicking an identifier and selecting this method from the context
431  // menu allows to add a straight-line segment at the end or the beginning
432  // of the line (whichever is closest to the mouse).
433  //
434  // - Direction = "" (default) - continue in the direction of first/last segment
435  // - Direction = "H", "h", "hori", "HORI" etc. - add horizontal segment
436  // - Direction = "v", "V", "vert", "VERT" etc. - add vertical segment
437 
438  if (!GetEditable()) return;
439 
440  // find closest point
441  Int_t px = gPad->GetEventX(); // mouse position
442  Int_t py = gPad->GetEventY(); // mouse position
443  Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[0])); // first point
444  Int_t dpy = py - gPad->YtoAbsPixel(gPad->XtoPad(fY[0])); // first point
445  Int_t dist_1 = dpx * dpx + dpy * dpy;
446  dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[fNpoints - 1])); // last point
447  dpy = py - gPad->YtoAbsPixel(gPad->XtoPad(fY[fNpoints - 1])); // last point
448  Int_t dist_N = dpx * dpx + dpy * dpy;
449  Int_t ipoint = (dist_N < dist_1 ? fNpoints - 1 : 0);
450 
451  // are we looking at beginning or end of line? (don't assume points are sorted in ascending X)
452  bool first_point = (ipoint == 0 && fX[0] < fX[fNpoints - 1]);
453  ExtendLine(first_point, Limit, Direction);
454 }
455 
456 
457 
464 
465 void KVIDentifier::ExtendLine(bool fromBeginning, Double_t Limit, Option_t* Direction)
466 {
467  // Add a straight-line segment at the end or the beginning of the line depending on fromBeginning.
468  //
469  // - Direction = "" (default) - continue in the direction of first/last segment
470  // - Direction = "H", "h", "hori", "HORI" etc. - add horizontal segment
471  // - Direction = "v", "V", "vert", "VERT" etc. - add vertical segment
472 
473  Int_t ipoint = (fromBeginning && (fX[0] < fX[fNpoints - 1]) ? 0 : fNpoints - 1);
474 
475  TString opt(Direction);// coordinates of new point
476  opt.ToUpper();
477  Double_t newX = fX[ipoint];
478  Double_t newY = fY[ipoint];
479  if (opt.BeginsWith("H")) newX = Limit;
480  else if (opt.BeginsWith("V")) newY = Limit;
481  else {
482  if (fNpoints < 2) {
483  KVError::Error(this, "ExtendLine", "Cannot extend line, need at least one segment!");
484  return;
485  }
486  // find equation y = ax+b of last/first segment
487  Double_t u, v, uu, vv;
488  Int_t iipoint = (ipoint == 0 ? 1 : fNpoints - 2);
489  u = fX[ipoint];
490  uu = fX[iipoint];
491  v = fY[ipoint];
492  vv = fY[iipoint];
493  Double_t a = (vv - v) / (uu - u);
494  Double_t b = (uu * v - u * vv) / (uu - u);
495  // Check that 'Limit' the x-coordinate of the new point is larger than the x-coordinate of the
496  // last existing point, or smaller than that of the first, in order to avoid issues
497  if ((fromBeginning && Limit > u) || (!fromBeginning && Limit < u)) {
498  KVError::Error(this, "ExtendLine", "Cannot extend line, with x-coordinate wanted %s than the one of the existing %s point!",
499  (fromBeginning ? "greater" : "smaller"), (fromBeginning ? "first" : "last"));
500  return;
501  }
502  //
503  // use 'Limit' as x-coordinate of new point
504  newX = Limit;
505  newY = a * newX + b;
506  }
507 
508  // add point
509  Int_t iend = (ipoint > 0 ? fNpoints : 0);
510  Double_t** ps = ExpandAndCopy(fNpoints + 1, iend);
511  CopyAndRelease(ps, ipoint, fNpoints++, ipoint + 1);
512 
513  // To avoid redefinitions in descendant classes
514  FillZero(iend, iend + 1);
515 
516  if (ipoint > 0) ipoint = fNpoints - 1;
517  fX[ipoint] = newX;
518  fY[ipoint] = newY;
519  if (gPad) {
520  gPad->Modified();
521  gPad->Update();
522  }
524 }
525 
526 
527 
534 
536 {
537  // Create a new line from the selected one
538  // with a new Z and A (optional)
539  // this new line is scale from the selected one with a vertical sy
540  // and horizontal sx (optional) factor
541  // you need to undraw and draw the grid to see its implementation
542 
543  if (!gPad) {
544  KVError::Error(this, "CloneScaleStore", "This method should be called using the interactive menu.");
545  return;
546  }
547 
548  TClass* cl = new TClass(IsA()->GetName());
549  KVIDentifier* idbis = (KVIDentifier*)cl->New();
550  Double_t xx, yy;
551  for (Int_t nn = 0; nn < GetN(); nn += 1) {
552  GetPoint(nn, xx, yy);
553  idbis->SetPoint(nn, xx, yy + dy);
554  }
555  idbis->SetOnlyZId(OnlyZId());
556  idbis->SetZ(newzt);
557  idbis->SetMassFormula(GetMassFormula());
558  idbis->SetEditable(IsEditable());
559  if (newar != -1) {
560  idbis->SetA(newar);
561  }
562  if ((sx > 0.) && (sy > 0.)) idbis->ScaleXY(sx, sy);
563  GetParent()->AddIdentifier(idbis);
564 
565  GetParent()->UnDraw();
566  GetParent()->Draw();
567 
568 
569  delete cl;
570 }
571 
572 
573 
576 
578 {
579  // Insert a new point at the mouse position
580  if (!GetEditable()) return -2;
581  if (!gPad) {
582  KVError::Error(this, "InsertPoint", "This method should be called using the interactive menu.");
583  return -1;
584  }
585 
586  Int_t px = gPad->GetEventX();
587  //Int_t py = gPad->GetEventY();
588 
589 // Info("InsertPoint", "x=%d y=%d", px, py);
590  Int_t ifound = -1;
591  //while ( gPad->XtoAbsPixel(gPad->XtoPad(fX[ii]))>px && ii<fNpoints-1) ii+=1;
592  //Recherche en pixel absolu
593  //pour trouver le point a partir duquel le TGraph
594  //doit bouger
595 // Print("");
596  for (Int_t ii = 0; ii < fNpoints; ii += 1) {
597 // Info("InsertPoint", "np=%d ii=%d %lf %lf %d\n",
598 // fNpoints,
599 // ii,
600 // fX[ii],
601 // gPad->XtoPad(fX[ii]),
602 // gPad->XtoAbsPixel(gPad->XtoPad(fX[ii]))
603 // );
604  if (gPad->XtoAbsPixel(gPad->XtoPad(fX[ii])) > px) {
605  ifound = ii;
606  break;
607  }
608  }
609 
610 // Info("InsertPoint", "point ifound=%d", ifound);
611 
612  Double_t deltaX = fX[ifound] - fX[ifound - 1];
613  Double_t aa = (fY[ifound] - fY[ifound - 1]) / (deltaX);
614  Double_t bb = fY[ifound] - fX[ifound] * aa;
615  //Conversion du px pour le TGraph et extrapole le new Y
616  Double_t newX = gPad->PadtoX(gPad->AbsPixeltoX(px));
617  Double_t newY = aa * newX + bb;
618 // Info("InsertPoint", "nouveau point %lf %lf", newX, newY);
619 
620  //Dernier point du graph
621  Double_t lastX = fX[fNpoints - 1];
622  Double_t lastY = fY[fNpoints - 1];
623  //Le dernier point est ajoute en fin de graph
624  //fNpoint -> fNpoint+1
625  SetPoint(fNpoints, lastX, lastY);
626  //On deplace les autres points
627  for (Int_t ii = fNpoints - 2; ii >= ifound; ii -= 1)
628  SetPoint(ii, fX[ii - 1], fY[ii - 1]);
629  //Ajout du nouveau point
630  SetPoint(ifound, newX, newY);
631 
632 // Print("");
633 
634  if (gPad) gPad->Modified();
635 
637 
638  return ifound;
639 }
640 
641 
642 
645 
647 {
648  // Insert a new point at the mouse X position using a smooth evaluation of the Y
649  if (!GetEditable()) return -2;
650  if (!gPad) {
651  KVError::Error(this, "InsertSmoothPoint", "This method should be called using the interactive menu.");
652  return -1;
653  }
654 
655  Int_t px = gPad->GetEventX();
656 
657  Int_t ifound = -1;
658  for (Int_t ii = 0; ii < fNpoints; ii += 1) {
659  if (gPad->XtoAbsPixel(gPad->XtoPad(fX[ii])) > px) {
660  ifound = ii;
661  break;
662  }
663  }
664 
665  Double_t newX = gPad->PadtoX(gPad->AbsPixeltoX(px));
666  Double_t newY = Eval(newX, 0, "S");
667 
668  Double_t lastX = fX[fNpoints - 1];
669  Double_t lastY = fY[fNpoints - 1];
670  SetPoint(fNpoints, lastX, lastY);
671  for (Int_t ii = fNpoints - 2; ii >= ifound; ii -= 1) SetPoint(ii, fX[ii - 1], fY[ii - 1]);
672 
673  SetPoint(ifound, newX, newY);
674  if (gPad) gPad->Modified();
676 
677  return ifound;
678 }
679 
680 
681 
684 
686 {
687  // Continue to draw an existing the line
688  if (!GetEditable()) return -2;
689  if (!gPad) {
690  KVError::Error(this, "ContinueDrawing", "This method should be called using the interactive menu.");
691  return -1;
692  }
693 
694  KVIDentifier* gr = (KVIDentifier*)this->IsA()->New();
695  gr->WaitForPrimitive();
697 
698  Int_t np = gr->GetN();
699 
700  Double_t last, first, yy;
701  gr->GetPoint(np - 1, last, yy);
702  gr->GetPoint(0, first, yy);
703 
704  Double_t xmax = fX[fNpoints - 1];
705  Double_t xmin = fX[0];
706 
707 // Info("ContinueDrawing", "Existing Line %lf %lf, Added line %lf %lf", xmin, xmax, last, first);
708 
709  if (first > xmax) {
710  //A rajouter apres (a droite) de la ligne existante
711  Double_t xx;
712  for (Int_t ii = 0; ii < np; ii += 1) {
713  gr->GetPoint(ii, xx, yy);
714  this->SetPoint(fNpoints, xx, yy);
715  }
716  }
717  else if (last < xmin) {
718  //A rajouter avant (a gauche) la ligne existante
719  Double_t xx;
720  for (Int_t ii = 0; ii < fNpoints; ii += 1) {
721  this->GetPoint(ii, xx, yy);
722  gr->SetPoint(gr->GetN(), xx, yy);
723  }
724 
725  for (Int_t ii = 0; ii < gr->GetN(); ii += 1) {
726  gr->GetPoint(ii, xx, yy);
727  this->SetPoint(ii, xx, yy);
728  }
729  }
730  else {
731 // Info("ContinueDrawing", "Faire une extension a droite ou a gauche\nsans recouvrement avec la ligne existante");
732  }
733 
734  delete gr;
735  gPad->Modified();
736 
738 
739  return np;
740 }
741 
742 
743 
748 
750 {
751  //Check if the line has been draw from left to right
752  //or right to left
753  //In this last case, we invert the filling order
754 
755  Int_t np = gr->GetN();
756  Double_t* xx = gr->GetX();
757  Double_t* yy = gr->GetY();
758  Double_t Delta = xx[np - 1] - xx[0];
759  if (Delta > 0) return;
760 
761  Info("ChechHierarchy", "Invert filling order");
762  Double_t* xp = new Double_t[np];
763  Double_t* yp = new Double_t[np];
764  for (Int_t nn = 0; nn < np; nn += 1) {
765  xp[nn] = xx[nn];
766  yp[nn] = yy[nn];
767  }
768 
769  for (Int_t ii = 1; ii <= np; ii += 1) {
770  gr->SetPoint(ii - 1, xp[np - ii], yp[np - ii]);
771  }
772  delete [] xp;
773  delete [] yp;
774 
775 }
776 
777 
778 
780 
782 {
783  if (!GetEditable()) return -1;
784 
785  if (!gPad) {
786  KVError::Error(this, "RemovePoint", "Cannot be used without gPad, requires last mouse position");
787  return -1;
788  }
789 
790  Int_t px = gPad->GetEventX();
791  Int_t py = gPad->GetEventY();
792 
793  //localize closest point to be deleted
794  Int_t ipoint = -2;
795  Int_t mindist = 2147483647;
796 
797  for (Int_t i = 0; i < fNpoints; i++) {
798  Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
799  Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
800  Int_t dist = dpx * dpx + dpy * dpy;
801  if (dist < mindist) {
802  mindist = dist;
803  ipoint = i;
804  }
805  }
807  return TCutG::RemovePoint(ipoint);
808 }
809 
810 
811 
817 
819 {
820  // Insert a new point at the end
821  // its position is extrapolated from the two last points
822  // assuming linear evolution (yy = a*xx + bb)
823  // The KVIDentifier has to have at least 2 points
824  if (!GetEditable()) return -2;
825  if (fNpoints < 2) return -3;
826 
827  Int_t np = fNpoints;
828  Double_t deltaX = fX[np - 1] - fX[np - 2];
829  Double_t aa = (fY[np - 1] - fY[np - 2]) / (deltaX);
830  Double_t bb = fY[np - 1] - fX[np - 1] * aa;
831  //yy = aa*xx+bb -> bb = yy-aa*xx
832  Double_t newX = fX[np - 1] + deltaX;
833  Double_t newY = aa * newX + bb;
834  SetPoint(np, newX, newY);
835  if (gPad) gPad->Modified();
837  return np + 1;
838 
839 }
840 
841 
845 
847 {
848  // Remove the first point
849  // The KVIDentifier has to have at least 2 points
850  if (!GetEditable()) return -2;
851  if (fNpoints < 2) return -3;
852 
853  RemovePoint(0);
854  if (gPad) gPad->Modified();
855  return fNpoints - 1;
856 
857 }
858 
859 
860 
864 
866 {
867  // Remove the first point
868  // The KVIDentifier has to have at least 2 points
869  if (!GetEditable()) return -2;
870  if (fNpoints < 2) return -3;
871 
872  RemovePoint(GetN() - 1);
873  if (gPad) gPad->Modified();
874  return fNpoints - 1;
875 }
876 
877 
878 
880 
882 {
883  if (!GetEditable()) return -2;
884  if (fNpoints < 2) return -1;
885 
886  Int_t nNpoints = (fNpoints - 1) * 2 + 1;
887  Double_t* nX = new Double_t[nNpoints];
888  Double_t* nY = new Double_t[nNpoints];
889 
890  for (int ii = 0; ii < nNpoints; ii++) {
891  if (!(ii % 2)) {
892  nX[ii] = fX[ii / 2];
893  nY[ii] = fY[ii / 2];
894  }
895  else {
896  nX[ii] = 0.5 * (fX[(ii - 1) / 2] + fX[(ii + 1) / 2]);
897  nY[ii] = Eval(nX[ii], 0, "S");
898  }
899  }
900 
901  Set(0);
902  for (int ii = 0; ii < nNpoints; ii++) SetPoint(ii, nX[ii], nY[ii]);
903 
904  delete[] nX;
905  delete[] nY;
906 
907  if (gPad) gPad->Modified();
909 
910  return fNpoints;
911 }
912 
913 
914 
916 
918 {
919  if (!GetEditable()) return -2;
920  if (fNpoints < 2) return -1;
921 
922  Int_t nNpoints = fNpoints / 2 + 1; //(fNpoints%2)?(fNpoints/2):((fNpoints+1)/2);
923  Double_t* nX = new Double_t[nNpoints];
924  Double_t* nY = new Double_t[nNpoints];
925 
926  nX[0] = fX[0];
927  nY[0] = fY[0];
928 
929  for (int ii = 1; ii < nNpoints - 1; ii++) {
930  nX[ii] = fX[ii * 2];
931  nY[ii] = fY[ii * 2];
932  }
933 
934  nX[nNpoints - 1] = fX[fNpoints - 1];
935  nY[nNpoints - 1] = fY[fNpoints - 1];
936 
937  Set(0);
938  for (int ii = 0; ii < nNpoints; ii++) SetPoint(ii, nX[ii], nY[ii]);
939 
940  delete[] nX;
941  delete[] nY;
942 
943  if (gPad) gPad->Modified();
944 
946  return fNpoints;
947 }
948 
949 
950 
952 
954 {
955  Sort(&TGraph::CompareX, ascending);
956  if (gPad) gPad->Modified();
958  return 0;
959 }
960 
961 
962 
964 
966 {
967  if (OnlyZId()) return (Double_t)GetZ();
968  return (GetZ() + 0.1 * (GetA() - 2.*GetZ()));
969 }
970 
971 
int Int_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
const char Option_t
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
winID h TVirtualViewer3D vv
Option_t Option_t SetLineWidth
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t SetMarkerStyle
float xmin
float xmax
#define gPad
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:31
void Draw(Option_t *opt="") override
Definition: KVIDGraph.cpp:963
void UnDraw()
Definition: KVIDGraph.cpp:1041
virtual void AddIdentifier(KVIDentifier *id)
Definition: KVIDGraph.h:409
void Modified()
Definition: KVIDGraph.h:313
Base class for graphical cuts used in particle identification.
Definition: KVIDentifier.h:28
virtual void SetOnlyZId(Bool_t onlyz=kTRUE)
Definition: KVIDentifier.h:100
virtual void ReadAsciiFile_extras(std::ifstream &)
Definition: KVIDentifier.h:46
virtual void SetMassFormula(Int_t mf)
Definition: KVIDentifier.h:108
virtual Int_t RemoveFirstPoint()
virtual Int_t DecreaseNumberOfPoints()
virtual Double_t GetPID() const
virtual Int_t AddPointAtTheEnd()
Int_t Compare(const TObject *) const override
virtual Int_t RemovePoint() override
KVIDGraph * fParent
parent identification map or grid
Definition: KVIDentifier.h:32
virtual Int_t GetA() const
Definition: KVIDentifier.h:76
virtual void WriteAsciiFile_extras(std::ofstream &, const Char_t *="")
Definition: KVIDentifier.h:42
void Copy(TObject &obj) const override
Copy attributes of this identifier into 'obj'.
virtual Int_t RemoveLastPoint()
virtual Int_t InsertSmoothPoint()
Insert a new point at the mouse X position using a smooth evaluation of the Y.
virtual Int_t IncreaseNumberOfPoints()
void ExtendLine(Double_t, Option_t *Direction="")
virtual void WaitForPrimitive()
Int_t InsertPoint() override
Insert a new point at the mouse position.
virtual Int_t GetZ() const
Definition: KVIDentifier.h:80
void ScaleXY(Double_t sx=-1, Double_t sy=-1)
void SetParent(KVIDGraph *)
Set pointer to parent ID graph.
virtual void ChechHierarchy(KVIDentifier *gr)
virtual ~KVIDentifier()
Destructor.
void CopyGraph(TGraph *)
Copy coordinates of points from the TGraph.
virtual Bool_t OnlyZId() const
Definition: KVIDentifier.h:104
virtual Int_t GetMassFormula() const
Definition: KVIDentifier.h:116
void NotifyParentOfModification()
If identifier belongs to a graph/grid, send signal to say it has been modified.
virtual void CloneScaleStore(Int_t newzt, Int_t newat, Double_t dy=0., Double_t sx=1., Double_t sy=1.)
virtual void WriteAsciiFile(std::ofstream &, const Char_t *name_prefix="")
virtual Int_t SortPoints(Bool_t ascending=kTRUE)
virtual void SetA(Int_t atnum)
Definition: KVIDentifier.h:89
KVIDGraph * GetParent() const
Get pointer to parent ID graph.
KVIDentifier()
Default constructor.
void Print(Option_t *opt) const override
virtual void ReadAsciiFile(std::ifstream &)
virtual void SetZ(Int_t ztnum)
Definition: KVIDentifier.h:84
virtual Int_t ContinueDrawing()
Continue to draw an existing the line.
void Scale(TF1 *sx, TF1 *sy)
void Copy(TAttFill &attfill) const
void Copy(TAttLine &attline) const
void Copy(TAttMarker &attmarker) const
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
const char * GetVarX() const
TClass * IsA() const override
const char * GetVarY() const
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Int_t fNpoints
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Double_t * GetY() const
virtual Bool_t IsEditable() const
virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
void Print(Option_t *chopt="") const override
static Bool_t CompareX(const TGraph *gr, Int_t left, Int_t right)
Int_t GetN() const
Double_t * fY
virtual void Sort(Bool_t(*greater)(const TGraph *, Int_t, Int_t)=&TGraph::CompareX, Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111)
Double_t * GetX() const
virtual Double_t Eval(Double_t x, TSpline *spline=nullptr, Option_t *option="") const
virtual Int_t RemovePoint()
void Draw(Option_t *chopt="") override
Bool_t GetEditable() const
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
Double_t ** ExpandAndCopy(Int_t size, Int_t iend)
Double_t * fX
virtual void Set(Int_t n)
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
virtual void SetEditable(Bool_t editable=kTRUE)
void Copy(TObject &named) const override
const char * GetName() const override
virtual const char * ClassName() const
virtual Bool_t InheritsFrom(const char *classname) const
virtual void Info(const char *method, const char *msgfmt,...) const
void ToUpper()
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Double_t y[n]
Double_t x[n]
gr SetMarkerSize(1.3)
TGraphErrors * gr
void Error(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:116
double dist(AxisAngle const &r1, AxisAngle const &r2)
Double_t Abs(Double_t d)
v
TArc a
ClassImp(TPyArg)