KaliVeda
Toolkit for HIC analysis
KVIDGraph.cpp
1 /*
2 $Id: KVIDGraph.cpp,v 1.9 2009/04/28 09:07:47 franklan Exp $
3 $Revision: 1.9 $
4 $Date: 2009/04/28 09:07:47 $
5 */
6 
7 //Created by KVClassFactory on Mon Apr 14 13:42:47 2008
8 //Author: franklan
9 
10 #include "KVIDGraph.h"
11 #include "TObjString.h"
12 #include "TObjArray.h"
13 #include "TRandom.h"
14 #include "TClass.h"
15 #include "TCanvas.h"
16 #include "TSystem.h"
17 #include "TROOT.h"
18 #include "KVIDGridManager.h"
19 #include "KVBase.h"
20 #include "TEnv.h"
21 #include "TPluginManager.h"
22 #include "TTree.h"
23 #include "TROOT.h"
24 #include "KVIdentificationResult.h"
25 
26 #include <KVDatime.h>
27 
28 using namespace std;
29 
31 
32 
33 
35 void KVIDGraph::ResetPad()
36 {
37  cout << "The pad showing graph " << GetName() << " has been closed !" << endl;
38 
39  if (fPad) {
40  fPad->Disconnect("Closed()", this, "ResetPad()");
41  if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect("Cleared(TVirtualPad*)", this, "ClearPad(TVirtualPad*)");
42  }
43  fPad = 0;
44 
45 }
46 
47 
48 
50 
52 {
53  if (fPad == pad) {
54  cout << "The pad showing graph " << GetName() << " has been cleared" << endl;
55  fPad->Disconnect("Closed()", this, "ResetPad()");
56  if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect("Cleared(TVirtualPad*)", this, "ClearPad(TVirtualPad*)");
57  fPad = 0;
58  }
59 }
60 
61 
63 
64 
68 
70 {
71  // Initialisations, used by constructors
72  // All graphs are added to gIDGridManager (if it exists).
73 
74  fIdentifiers.SetCleanup();
75  fCuts.SetCleanup();
76  fInfoZones.SetCleanup();
77  fXmin = fYmin = fXmax = fYmax = 0;
78  fLastScaleX = 1.0;
79  fLastScaleY = 1.0;
80  fOnlyZId = kFALSE;
81  fPad = 0;
82  SetName("");
83  SetEditable(kFALSE);
84  if (fAutoAddGridManager && gIDGridManager) gIDGridManager->AddGrid(this);
85  fMassFormula = 0;
86  fLastSavedVersion = NULL;
87 }
88 
89 
90 
91 // void KVIDGraph::Browse(TBrowser* b)
92 // {
93 // // This method is executed when an object is double-clicked in a browser
94 // // such as the list of grids in KVIDGridManagerGUI
95 // //
96 // // Overrides default TGraph::Browse (which calls Draw()) in order to open
97 // // the grid in the KVIDGridEditor canvas (if one exists).
98 // // If no KVIDGridEditor exists, we perform the default action (Draw()).
99 // //
100 //
101 // if( gIDGridEditor ){
102 // // avant d'editer la grille, on en fait une copie pour
103 // // pouvoir revenir en arriere
104 // UpdateLastSavedVersion();
105 // if(gIDGridEditor->IsClosed()) gIDGridEditor->StartViewer();
106 // gIDGridEditor->SetGrid(this);
107 // }
108 // else
109 // TGraph::Browse(b);
110 // }
111 
112 
113 
116 
117 void KVIDGraph::Copy(TObject& obj) const
118 {
119  //Copy this to 'obj'
120  TNamed::Copy(obj);
121  TAttLine::Copy((TAttLine&)obj);
122  TAttFill::Copy((TAttFill&)obj);
124  ((TCutG&)obj).SetVarX(GetVarX());
125  ((TCutG&)obj).SetVarY(GetVarY());
126  KVIDGraph& grid = (KVIDGraph&) obj;
127  grid.fOnlyZId = const_cast <KVIDGraph*>(this)->fOnlyZId;
128  grid.SetPattern(fPattern);
129  //as in WriteAsciiFile, we need to remove any scaling factors from the coordinates
130  //before copying the coordinates, then we set the scaling factors at the end
131 
132  //remove scaling if there is one
133  if (fLastScaleX != 1 || fLastScaleY != 1)
134  const_cast < KVIDGraph* >(this)->ScaleXY(1. / fLastScaleX,
135  1. / fLastScaleY);
136 
137  fIdentifiers.Copy(grid.fIdentifiers);
138  fCuts.Copy(grid.fCuts);
139  fInfoZones.Copy(grid.fInfoZones);
140  // set mass formula of grid (and identifiers)
141  grid.SetMassFormula(GetMassFormula());
142  //copy all parameters EXCEPT scaling parameters
143  KVNamedParameter* par = 0;
144  for (int i = 0; i < fPar.GetNpar(); i++) { //loop over all parameters
145  par = fPar.GetParameter(i);
146  TString parname(par->GetName());
147  if (!parname.Contains("ScaleFactor") && !parname.Contains("FileWrite"))// do not copy file write date
148  grid.fPar.SetValue(*par);
149  }
150  //restore scaling to this grid if there was one, and apply it to the copied grid
151  if (fLastScaleX != 1 || fLastScaleY != 1) {
152  const_cast < KVIDGraph* >(this)->ScaleXY(fLastScaleX, fLastScaleY);
153  grid.SetXScaleFactor(fLastScaleX);
154  grid.SetYScaleFactor(fLastScaleY);
155  }
156 }
157 
158 
159 
160 KVIDGraph::KVIDGraph() : fRunList(""), fDyName(""), fPattern("")
161 
162 
165 
166 {
167  // Default constructor
168  init();
169 }
170 
171 
172 
173 
176 
177 KVIDGraph::KVIDGraph(const KVIDGraph& grid) : TCutG(), fRunList(""), fDyName(""), fPattern("")
178 {
179  //Copy constructor
180  init();
181  grid.Copy(*this);
182 }
183 
184 
185 
189 
191 {
192  // Destructor
193  // remove from grid manager
194  if (gIDGridManager) gIDGridManager->GetGrids()->RecursiveRemove(this);
195 }
196 
197 
198 
199 
204 
206 {
207  // reset the grid (destroying any previously defined identifiers) ready to start anew.
208  // resets axis limits
209  // scaling factors (if any) are removed
210 
212  fCuts.Delete();
213  fInfoZones.Delete();
214  fXmin = fYmin = fXmax = fYmax = 0;
215  SetXScaleFactor();
216  SetYScaleFactor();
217  Modified();
218 }
219 
220 
222 
223 
227 
229 {
230  //Set scaling factor for X-axis - rescales all objects with this factor
231  //SetXScaleFactor() or SetXScaleFactor(0) removes scale factor
232  if (s > 0) {
233  fPar.SetValue("XScaleFactor", s);
234  ScaleXY(s / fLastScaleX);
235  fLastScaleX = s;
236  }
237  else {
238  fPar.RemoveParameter("XScaleFactor");
239  ScaleXY(1.0 / fLastScaleX);
240  fLastScaleX = 1.0;
241  }
242 }
243 
244 
246 
247 
251 
253 {
254  //Set scaling factor for Y-axis - rescales all objects with this factor
255  //SetYScaleFactor() or SetYScaleFactor(0) removes scale factor
256  if (s > 0) {
257  fPar.SetValue("YScaleFactor", s);
258  ScaleXY(-1.0, s / fLastScaleY);
259  fLastScaleY = s;
260  }
261  else {
262  fPar.RemoveParameter("YScaleFactor");
263  ScaleXY(-1.0, 1.0 / fLastScaleY);
264  fLastScaleY = 1.0;
265  }
266 }
267 
268 
270 
271 
275 
277 {
278  //Return scaling factor for X-axis
279  //If factor not defined, returns 1
280  Double_t s = fPar.GetDoubleValue("XScaleFactor");
281  if (s > 0)
282  return s;
283  return 1.0;
284 }
285 
286 
288 
289 
293 
295 {
296  //Return scaling factor for Y-axis
297  //If factor not defined, returns 1
298  Double_t s = fPar.GetDoubleValue("YScaleFactor");
299  if (s > 0)
300  return s;
301  return 1.0;
302 }
303 
304 
306 
307 
311 
313 {
314  // Return pointer to identifier with atomic number Z and mass number A.
315  // If this is a 'OnlyZId()' graph we ignore A.
316 
317  KVIDentifier* id = 0;
318  if (!IsOnlyZId()) {
319  unique_ptr<KVSeqCollection> isotopes(fIdentifiers.GetSubListWithMethod(Form("%d", Z), "GetZ"));
320  TIter next(isotopes.get());
321  while ((id = (KVIDentifier*)next())) if (id->GetA() == A) break;
322  }
323  else {
324  TIter next(&fIdentifiers);
325  while ((id = (KVIDentifier*)next())) if (id->GetZ() == Z) break;
326  }
327  return id;
328 }
329 
330 
332 
333 
336 
338 {
339  // Remove and destroy identifier
340  fIdentifiers.Remove(id);
341  delete id;
342  Modified();
343 }
344 
345 
347 
348 
351 
353 {
354  // Remove and destroy cut
355  fCuts.Remove(cut);
356  delete cut;
357  Modified();
358 }
359 
360 
361 
364 
366 {
367  // Remove and destroy cut
368  fInfoZones.Remove(info);
369  delete info;
370  Modified();
371 }
372 
373 
375 
376 
383 
385 {
386  // Fill parameter "IDTelescopes" with list of names of telescopes associated
387  // with this grid, ready to write in ascii file
388 
389  // if list of telescope pointers is empty, do nothing
390  // this is in case there are telescope names already in the IDTelescopes parameter
391  // but they are not telescopes in the current multi det array
392  if (!fTelescopes.GetEntries()) return;
393  fPar.SetValue("IDTelescopes", "");
394  KVString tel_list = GetNamesOfIDTelescopes();
395  fPar.SetValue("IDTelescopes", tel_list);
396 }
397 
398 
400 
401 
402 
405 
406 void KVIDGraph::WriteAsciiFile(const Char_t* filename)
407 {
408  //Open, write and close ascii file containing this grid.
409 
410  ofstream gridfile(filename);
411  WriteToAsciiFile(gridfile);
412  gridfile.close();
413 }
414 
415 
416 
417 
443 
444 void KVIDGraph::WriteToAsciiFile(ofstream& gridfile)
445 {
446  //Write info on this grid in already-open ascii file stream 'gridfile'.
447  //This begins with the line
448  //++ClassName
449  //where '"ClassName'" is the name of the class of the actual instance of this object
450  //followed by informations on the grid and its objects.
451  //
452  //The names associated to the X & Y axis of the identification map are written
453  //on lines beginning with
454  //<VARX>
455  //<VARY>
456  //Any associated parameters are written before the objects, starting with
457  //<PARAMETER>
458  //then the name of the parameter and its value
459  //e.e.
460  //<PARAMETER> ChIo pressure=45.5
461  //A single '!' on a line by itself signals the end of the informations for this grid.
462  //
463  //Scaling factors
464  //Any scaling factors are written in the file as
465  //<PARAMETER> XScaleFactor=...
466  //<PARAMETER> YScaleFactor=...
467  //However the coordinates written in the file are the unscaled factors
468  //When the file is read back again, the unscaled coordinates are read in and
469  //then the scaling is applied.
470 
471  gridfile << "# ASCII file generated by " << ClassName() <<
472  "::WriteToAsciiFile" << endl;
473  gridfile << "# ID Graph Name : " << GetName() << endl;
474  gridfile << "# This file can be read using " << ClassName() <<
475  "::ReadFromAsciiFile" << endl;
476  gridfile << "# " << endl;
477  gridfile << "++" << ClassName() << endl;
478 
479  // write name if given
480  if (fName != "") gridfile << "<NAME> " << fName.Data() << endl;
481  //write X & Y axis names
482  gridfile << "<VARX> " << GetVarX() << endl;
483  gridfile << "<VARY> " << GetVarY() << endl;
484  //write parameters
485  KVDatime filewrite;
486  GetParameters()->SetValue("FileWrite",filewrite.AsSQLString());
487  GetParameters()->RemoveParameter("Timestamp");
488  Emit("Modified");
489  KVNamedParameter* par = 0;
490  for (int i = 0; i < fPar.GetNpar(); i++) { //loop over all parameters
491  par = fPar.GetParameter(i);
492  gridfile << "<PARAMETER> " << par->GetName() << "=" << par->GetString() << endl;
493  }
494 
495  //write fOnlyZId & mass formula
496  if (IsOnlyZId()) gridfile << "OnlyZId " << GetMassFormula() << endl;
497 
498  //remove scaling if there is one
499  if (fLastScaleX != 1 || fLastScaleY != 1)
500  ScaleXY(1. / fLastScaleX, 1. / fLastScaleY);
501 
502  //Write identifiers
503  TIter next_IDline(&fIdentifiers);
505  while ((line = (KVIDentifier*) next_IDline())) {
506  line->WriteAsciiFile(gridfile, "ID");
507  }
508  //Write cuts
509  TIter next_OKline(&fCuts);
510  while ((line = (KVIDentifier*) next_OKline())) {
511  line->WriteAsciiFile(gridfile, "OK");
512  }
513  //Write cuts
514  TIter next_INFOline(&fInfoZones);
515  while ((line = (KVIDentifier*) next_INFOline())) {
516  line->WriteAsciiFile(gridfile, "INFO");
517  }
518 // //Write info zones
519 // TIter next_OKline(fInfoZones);
520 // while ((line = (KVIDentifier*) next_OKline())) {
521 // line->WriteAsciiFile(gridfile, "INFO");
522 // }
523  gridfile << "!" << endl;
524 
525  //restore scaling if there is one
526  if (fLastScaleX != 1 || fLastScaleY != 1)
528 
529  // if a back-up copy had previously been created (by starting the editor)
530  // we replace it by the version read from file
532 }
533 
534 
535 
538 
540 {
541  //update last saved version. mkae copy of current state of graph.
542  if (!fLastSavedVersion) {
543  SetAutoAdd(kFALSE); // disable auto add to grid manager - or we'll have every grid appearing twice!
545  SetAutoAdd(); // re-enable auto add
546  }
548  fLastSavedVersion->GetIdentifiers()->Execute("SetLineColor", "kBlack");
549  fLastSavedVersion->GetIdentifiers()->Execute("SetMarkerColor", "kBlack");
550 }
551 
552 
553 
558 
560 {
561  // \returns date & time of last modification
562  //
563  // Value is stored in parameter 'Timestamp'. If no parameter defined, returns '?'
564 
565  if(GetParameters()->HasParameter("Timestamp"))
566  return GetParameters()->GetStringValue("Timestamp");
567  return "?";
568 }
569 
570 
571 
576 
578 {
579  // \returns date & time of last write to file
580  //
581  // Value is stored in parameter 'FileWrite'. If no parameter defined, returns '?'
582 
583  if(GetParameters()->HasParameter("FileWrite"))
584  return GetParameters()->GetStringValue("FileWrite");
585  return "?";
586 }
587 
588 
589 
595 
597 {
598  // Revert to last saved version of grid
599  // this will destroy any existing lines in the grid and replace them with
600  // copies of the lines as they were at the last moment the grid was saved
601  // If the grid is (was) visible in a pad, we redraw the new lines.
602 
603  if (!fLastSavedVersion) {
604  Info("RevertToLastSavedVersion", "No saved version to revert to! (Sorry)");
605  return;
606  }
607  Bool_t wasDrawn = kFALSE;
608  if (fPad) {
609  // if grid was visible, remove it from pad before modifying (deleting) lines
610  wasDrawn = kTRUE;
611  fPad->cd();// make sure pad with grid is active (gPad) pad
612  UnDraw();
613  }
614  Clear();
615  fLastSavedVersion->Copy(*this);
616  if (wasDrawn) {
617  // if grid was visible, redraw it with new lines
618  Draw();
619  }
620 }
621 
622 
623 
624 
655 
656 void KVIDGraph::ReadFromAsciiFile(ifstream& gridfile)
657 {
658  // Read info from already open ascii file stream containing each line of this grid.
659  //
660  // Any previous lines in the grid are destroyed.
661  //
662  // Comment lines begin with `#`
663  //
664  // Grid info begins with
665  //
666  //~~~
667  //++ClassName
668  //~~~
669  //
670  // where ClassName is actual class name of instance of this object
671  //
672  // The names associated to the X & Y axis of the identification map are written
673  // on lines beginning with
674  //
675  //~~~
676  //<VARX>
677  //<VARY>
678  //~~~
679  //
680  // Parameter lines begin with `<PARAMETER>`
681  //
682  // New lines begin with `+name_of_class`
683  //
684  // `!` signals end of grid info
685  //
686  // Any scaling factors are applied once the coordinates have been read
687 
688  Clear();//reset grid - destroy old lines, axis limits...
689  //clear parameters
690  fPar.Clear();
691 
692  KVString s;
693  int line_no = 0; // counter for lines read
695  Int_t mass_formula = -1;
696 
697  while (gridfile.good()) {
698  //read a line
699  s.ReadLine(gridfile);
700  if (s.BeginsWith('!')) {
701  //end of grid signalled
702  break;
703  }
704  else if (s.BeginsWith("++")) { //will only happen if we are reading a file using ReadAsciiFile(const char*)
705  //check classname
706  s.Remove(0, 2);
707  s.Remove(TString::kBoth, ' '); //remove whitespace
708  if (s != ClassName()) {
709  KVError::Warning(this, "ReadFromAsciiFile(ofstream&)",
710  "Class name in file %s does not correspond to this class (%s)",
711  s.Data(), ClassName());
712  }
713  }
714  else if (s.BeginsWith("<NAME>")) {
715  //name of grid
716  s.Remove(0, 7);
717  s.Remove(TString::kBoth, ' '); //remove whitespace
718  SetName(s.Data());
719  }
720  else if (s.BeginsWith("<VARX>")) {
721  //x-axis definition
722  s.Remove(0, 7);
723  s.Remove(TString::kBoth, ' '); //remove whitespace
724  SetVarX(s.Data());
725  }
726  else if (s.BeginsWith("<VARY>")) {
727  //y-axis definition
728  s.Remove(0, 7);
729  s.Remove(TString::kBoth, ' '); //remove whitespace
730  SetVarY(s.Data());
731  }
732  else if (s.BeginsWith("<PARAMETER>")) {
733  //parameter definition
734  s.Remove(0, 11);
735  //split into tokens separated by '='
736  if (s.GetNValues("=") == 2) {
737  s.Begin("=");
738  auto name = s.Next(kTRUE);
739  auto value = s.Next(kTRUE);
740  if (name != "" && value != "") {
741  if (value.IsDigit())
742  fPar.SetValue(name.Data(), value.Atoi());
743  else if (value.IsFloat())
744  fPar.SetValue(name.Data(), value.Atof());
745  else
746  fPar.SetValue(name.Data(), value.Data());
747  }
748  }
749  }
750  else if (s.BeginsWith("<LIST>")) { // number list definition
751  s.Remove(0, 6); // get rid of "<LIST>"
752  //split into tokens separated by '='
753  if (s.GetNValues("=") == 2) {
754  s.Begin("=");
755  auto name = s.Next(kTRUE);
756  auto list = s.Next();
757  //set appropriate list
758  if (name == "Runs")
759  SetRuns(list.Data());
760  else
761  fPar.SetValue(name.Data(), list.Data());
762  }
763  }
764  else if (s.BeginsWith("OnlyZId")) {
765  SetOnlyZId(kTRUE);
766  s.ReplaceAll("OnlyZId", "");
767  s.Remove(TString::kBoth, ' ');
768  if (s != "") { //older versions did not write mass formula after OnlyZId
769  mass_formula = s.Atoi();
770  if (mass_formula > -1) SetMassFormula(mass_formula);
771  }
772  }
773  else if (s.BeginsWith('+')) {
774  //New line
775  line_no++;
776  //Get name of class by stripping off the '+' at the start of the line
777  s.Remove(0, 1);
778  TString lineclass = s;
779  //next line is type ("ID" or "OK") followed by ':', followed by name of line
780  s.ReadLine(gridfile);
781  //split into tokens separated by ':'
782  s.Begin(":");
783  auto type = s.Next(kTRUE);
784  TString name = "";
785  // make sure the line actually has a name !
786  if (!s.End()) name = s.Next(kTRUE);
787  else {
788  // print warning allowing to find nameless line in file
789  {
790  KVError::Warning(this, "KVIDGraph::ReadFromAsciiFile",
791  "In grid %s : identifier with no name. Identifier type = %s. Line number in grid = %d",
792  GetName(), type.Data(), line_no);
793  }
794  }
795  ReadIdentifierFromAsciiFile(name, type, lineclass, gridfile);
796  }
797  }
800  if (fLastScaleX != 1 || fLastScaleY != 1) {
802  }
804  //set runlist
805  if (fPar.HasParameter("Runlist")) {
806  SetRuns(fPar.GetStringValue("Runlist"));
807  }
808  else SetRuns("");
809  // check for ID telescopes parameter
810  if(!fPar.HasStringParameter("IDTelescopes"))
811  {
812  KVError::Warning(this, "KVIDGraph::ReadFromAsciiFile()",
813  "Grid %s is not associated with any IDTelescopes!", GetName());
814  }
815 
816  // if a back-up copy had previously been created (by starting the editor)
817  // we replace it by the version read from file
819 
820  // reset timestamp of last modification
821  GetParameters()->RemoveParameter("Timestamp");
822 }
823 
824 
825 
826 
829 
830 void KVIDGraph::ReadIdentifierFromAsciiFile(TString& name, TString& type, TString& cl, ifstream& gridfile)
831 {
832  // Read in new identifier object from file
833 
834  KVIDentifier* line = New(cl.Data());
835  line->SetName(name.Data());
836  Add(type, line);
837  //now use ReadAscii method of class to read coordinates and other informations
838  line->ReadAsciiFile(gridfile);
839 }
840 
841 
842 
843 
853 
854 void KVIDGraph::ReadAsciiFile(const Char_t* filename)
855 {
856  //Open, read and close ascii file containing this grid.
857  //Any previous lines in the grid are destroyed.
858  //Comment lines begin with #
859  //Grid info begins with
860  //++ClassName
861  //where ClassName is actual class name of instance of this object
862  //New lines begin with +name_of_class
863  //'!' signals end of grid
864 
865  ifstream gridfile(filename);
866 
867  if (gridfile.good()) {
868  ReadFromAsciiFile(gridfile);
869  }
870  else {
871  KVError::Warning(this, "ReadAsciiFile", "Could not find file %s. Check filename.", filename);
872  }
873  gridfile.close();
874 }
875 
876 
877 
878 
881 
883 {
884  //Create new object of class "id_class" which derives from KVIDentifier
885 
886  KVIDentifier* line = 0;
887  TClass* clas = TClass::GetClass(id_class);
888  if (!clas) {
889  KVError::Error(this, "New",
890  "%s is not a valid classname. No known class.", id_class);
891  }
892  else {
893  if (!clas->InheritsFrom(KVIDentifier::Class())) {
894  KVError::Error(this, "New",
895  "%s is not a valid class deriving from KVIDentifier",
896  id_class);
897  }
898  else {
899  line = (KVIDentifier*) clas->New();
900  }
901  }
902  return line;
903 }
904 
905 
906 
907 
912 
914 {
915  // Add the object to the list of cuts or identifiers:
916  // type = "ID" --> calls AddIdentifier(id)
917  // type = "OK" or "cut" --> calls AddCut(id)
918 
919  type.ToUpper();
920  if (type == "ID") AddIdentifier(id);
921  else if (type == "OK" || type == "CUT") AddCut(id);
922  else if (type == "INFO") AddInfo(id);
923 }
924 
925 
926 
927 
932 
934 {
935  // Create and add the object to the list of cuts or identifiers:
936  // type = "ID" --> calls AddIdentifier(id)
937  // type = "OK" or "cut" --> calls AddCut(id)
938 
939  type.ToUpper();
940  KVIDentifier* id = New(classname);
941  if (!id) return 0;
942  if (type == "ID") AddIdentifier(id);
943  else if (type == "OK" || type == "CUT") AddCut(id);
944  else if (type == "INFO") AddInfo(id);
945  return id;
946 }
947 
948 
949 
950 
962 
964 {
965  //Draw all objects in graph on the current display, if one exists: i.e. in order to superimpose the grid
966  //on a 2D display of data, use KVIDGraph::Draw() (no option "same" needed).
967  //
968  //If no TCanvas exists, or if one exists but it is empty, a frame large enough to display all
969  //the objects in the graph will be generated.
970  //
971  //The title of the canvas is set to the name of the graph
972  //
973  //If the graph is already displayed (i.e. if fPad!=0), we call UnDraw() in order to remove it from the display.
974  //This is so that double-clicking a graph in the IDGridManagerGUI list makes it disappear if it is already drawn.
975 
976  if (fPad) { /* graph already displayed. undraw it! */
977  UnDraw();
978  return;
979  }
980 
981  if (!gPad) {
982  fPad = new TCanvas("c1", GetName());
983  }
984  else {
985  fPad = (TPad*)gPad;
986  gPad->SetTitle(GetName());
987  }
988  if (!gPad->GetListOfPrimitives()->GetSize()) {
989  //calculate size of pad necessary to show graph
990  if (GetXmin() == GetXmax())
991  const_cast < KVIDGraph* >(this)->FindAxisLimits();
992  gPad->DrawFrame(GetXmin(), GetYmin(), GetXmax(), GetYmax());
993  }
994  {
995  fIdentifiers.R__FOR_EACH(KVIDentifier, Draw)("PL");
996  }
997  {
998  fCuts.R__FOR_EACH(KVIDentifier, Draw)("PL");
999  }
1000  {
1001  fInfoZones.R__FOR_EACH(KVIDentifier, Draw)("PL");
1002  }
1003  gPad->Modified();
1004  gPad->Update();
1005  // connect canvas' Closed() signal to KVIDGraph::ResetPad so that if the
1006  // canvas GUI is closed (thereby deleting the fPad object), we reset fPad
1007  // and do not try to Undraw in a non-existent canvas
1008 // fPad->Connect("Closed()", "KVIDGraph", this, "ResetPad()");
1009 // if (fPad->GetCanvas()) fPad->GetCanvas()->Connect("Cleared(TVirtualPad*)", "KVIDGraph", this, "ClearPad(TVirtualPad*)");
1010 }
1011 
1012 
1013 
1014 
1040 
1042 {
1043  //Make the graph disappear from the current canvas/pad
1044  //In case any objects have (accidentally) been drawn more than once, we keep calling
1045  //gPad->GetListOfPrimitives()->Remove() as long as gPad->GetListOfPrimitives()->FindObject()
1046  //returns kTRUE for each identifier.
1047 
1048 // if (!fPad) {
1049 // Error("UnDraw", "Cannot undraw, no pad stored ??");
1050 // return;
1051 // }
1052 // TIter next_id(fIdentifiers);
1053 // KVIDentifier* line;
1054 // //remove the rest of the lines
1055 // while ((line = (KVIDentifier*) next_id())) {
1056 // while (fPad->GetListOfPrimitives()->FindObject(line))
1057 // fPad->GetListOfPrimitives()->Remove(line);
1058 // }
1059 // TIter next_ok(fCuts);
1060 // while ((line = (KVIDentifier*) next_ok())) {
1061 // while (fPad->GetListOfPrimitives()->FindObject(line))
1062 // fPad->GetListOfPrimitives()->Remove(line);
1063 // }
1064 // fPad->Modified();
1065 // fPad->Update();
1066 // fPad->Disconnect("Closed()", this, "ResetPad()");
1067 // if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect("Cleared(TVirtualPad*)", this, "ClearPad(TVirtualPad*)");
1068  fPad = 0;
1069 }
1070 
1071 
1072 
1073 
1077 
1079 {
1080  // In case the graph can no longer be drawn/undrawn (because fPad contains address of a canvas
1081  // which died unexpectedly), use this method to reset fPad=0 and hopefully start afresh.
1082  fPad = 0;
1083 }
1084 
1085 
1086 
1091 
1093 {
1094  // Extend the first segment of each identification line back to new coordinate newX
1095  //
1096  // See KVIDentifier::ExtendLine()
1097 
1098  fIdentifiers.R__FOR_EACH(KVIDentifier, ExtendLine)(true, newX, Direction);
1099 }
1100 
1101 
1102 
1107 
1109 {
1110  // Extend the last segment of each identification line to new coordinate newX
1111  //
1112  // See KVIDentifier::ExtendLine()
1113  fIdentifiers.R__FOR_EACH(KVIDentifier, ExtendLine)(false, newX, Direction);
1114 }
1115 
1116 
1117 
1118 
1121 
1123 {
1124  //Print out all objects in graph
1125 
1126  cout << ClassName() << " : " << GetName() << endl;
1127  cout << "Title : " << GetTitle() << endl;
1128  //print list of parameters
1129  fPar.Print();
1130  KVIDentifier* line = 0;
1131  TIter nextOK(&fCuts);
1132  while ((line = (KVIDentifier*) nextOK()))
1133  line->ls();
1134  TIter nextID(&fIdentifiers);
1135  while ((line = (KVIDentifier*) nextID()))
1136  line->ls();
1137  TIter nextInfo(&fInfoZones);
1138  while ((line = (KVIDentifier*) nextInfo()))
1139  line->ls();
1140 }
1141 
1142 
1143 
1144 
1147 
1149 {
1150  //Calculate X/Y min/max of all objects in graph
1151 
1152  KVIDentifier* line;
1153  Double_t x, y, xmin, ymin, xmax, ymax;
1154  xmax = ymax = -999999;
1155  xmin = ymin = 999999;
1156  TIter nextOK(&fCuts);
1157  while ((line = (KVIDentifier*) nextOK())) {
1158  for (int i = 0; i < line->GetN(); i++) {
1159  line->GetPoint(i, x, y);
1160  xmin = (x < xmin ? x : xmin);
1161  xmax = (x > xmax ? x : xmax);
1162  ymin = (y < ymin ? y : ymin);
1163  ymax = (y > ymax ? y : ymax);
1164  }
1165  }
1166  TIter nextID(&fIdentifiers);
1167  while ((line = (KVIDentifier*) nextID())) {
1168  for (int i = 0; i < line->GetN(); i++) {
1169  line->GetPoint(i, x, y);
1170  xmin = (x < xmin ? x : xmin);
1171  xmax = (x > xmax ? x : xmax);
1172  ymin = (y < ymin ? y : ymin);
1173  ymax = (y > ymax ? y : ymax);
1174  }
1175  }
1176  fXmin = xmin;
1177  fYmin = ymin;
1178  fXmax = xmax;
1179  fYmax = ymax;
1180  // Info("FindAxisLimits()", "Xmin=%f Ymin=%f Xmax=%f Ymax=%f", GetXmin(), GetYmin(), GetXmax(), GetYmax());
1181 }
1182 
1183 
1184 
1185 
1192 
1193 void KVIDGraph::Scale(TF1* sx, TF1* sy)
1194 {
1195  // Rescale coordinates of every object in graph according to arbitrary functions
1196  // of the coordinates (sx & sy can be 1-dimensional or 2-dimensional functions).
1197  //
1198  // If sy is a TF1 function f(x), then the 'x' in this function refers to the y-coordinate.
1199  // If sy is a TF2 function f(x,y), 'x' and 'y' refer to the x & y-coordinates.
1200 
1201  if (!sx && !sy)
1202  return;
1203  if (GetNumberOfIdentifiers() > 0) {
1204  fIdentifiers.R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1205  }
1206  if (GetNumberOfCuts() > 0) {
1207  fCuts.R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1208  }
1209  if (GetNumberOfInfos() > 0) {
1210  fInfoZones.R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1211  }
1212  Modified();
1213 }
1214 
1215 
1216 
1217 
1220 
1222 {
1223  // Called by SetX/YScaleFactor methods to rescale every point of every object in the grid
1224 
1225  if (TMath::Abs(sx) == 1 && TMath::Abs(sy) == 1)
1226  return;
1227  if (GetNumberOfIdentifiers() > 0) {
1228  fIdentifiers.R__FOR_EACH(KVIDentifier, ScaleXY)(sx, sy);
1229  }
1230  if (GetNumberOfCuts() > 0) {
1231  fCuts.R__FOR_EACH(KVIDentifier, ScaleXY)(sx, sy);
1232  }
1233  if (GetNumberOfInfos() > 0) {
1234  fInfoZones.R__FOR_EACH(KVIDentifier, ScaleXY)(sx, sy);
1235  }
1236  Modified();
1237 }
1238 
1239 
1240 
1241 
1251 
1252 void KVIDGraph::DrawAndAdd(const TString& Type, const TString& Classname)
1253 {
1254  //Use this method to add objects to a grid which is drawn in the current pad gPad.
1255  //
1256  //We wait for the user to draw the line with the graphical editor
1257  //(we put the pad automatically into this mode,
1258  //there is no need to use the Editor toolbar).
1259  //
1260  //Then we retrieve this TGraph, create a new KVIDentifier-derived object of
1261  //class "classname", and add it to the "type" list (= "OK"/"cut" or "ID").
1262 
1263  if (!fPad && !gPad) return;
1264  // if grid already drawn somewhere, make grid's pad active
1265  if (fPad && fPad != gPad) {
1266  fPad->cd();
1267  KVError::Warning(this, "DrawAndAdd", "Changed active pad to pad containing this graph");
1268  }
1269  if (!fPad) fPad = gPad;
1270 
1271  TString type(Type);
1272  TString classname(Classname);
1273  //create new ID line
1274  KVIDentifier* line = New(classname);
1275  //wait for user to draw object
1276  line->WaitForPrimitive();
1277  if(Type == "ID")
1279  //add line to list
1280  Add(type, line);
1281  Modified();
1282 }
1283 
1284 
1285 
1286 
1287 
1288 
1300 
1302  KVIDGraph* g2, Int_t id2_min, Int_t id2_max)
1303 {
1304  //Static method taking lines id1_min to id2_min from grid g1 and lines id2_min to id2_max from
1305  //grid g2 and making a new grid containing them. Returns the pointer to the new grid.
1306  //
1307  //It is assumed that g1 and g2 are grids of the same class. The new grid will be an object of the
1308  //same class as g1.
1309  //
1310  //Any scaling factors are applied to the line coordinates as they are copied from their parent grids.
1311  //As scaling may be different in g1 and g2, the resulting grid has no scaling factor, but the coordinates
1312  //of all its lines result from application of the different scaling factors of the two grids.
1313 
1314  //make new grid
1315  KVIDGraph* merger = (KVIDGraph*) g1->IsA()->New();
1316 
1317  //loop over lines in first grid
1318  TIter next_id1(g1->GetIdentifiers());
1319  KVIDentifier* line;
1320  while ((line = (KVIDentifier*) next_id1())) {
1321  if (line->GetID() >= id1_min && line->GetID() <= id1_max)
1322  merger->Add("ID", (KVIDentifier*) line->Clone()); //add clone of lines with right ID
1323  }
1324 
1325  //loop over lines in second grid
1326  TIter next_id2(g2->GetIdentifiers());
1327  while ((line = (KVIDentifier*) next_id2())) {
1328  if (line->GetID() >= id2_min && line->GetID() <= id2_max)
1329  merger->Add("ID", (KVIDentifier*) line->Clone());
1330  }
1331 
1332  //just in case any of the lines were highlighted...
1333  merger->SetLineColor(kBlack);
1334 
1335  return merger;
1336 }
1337 
1338 
1339 
1340 
1350 
1352 {
1353  // Default method for deciding if point (x,y) corresponds to an identifiable
1354  // particle or not: we loop over the list of cuts and test the
1355  // point with the method TestPoint(x,y).
1356  //
1357  // If the point is accepted by all cuts, then (x,y) is identifiable (return kTRUE).
1358  //
1359  // If the point is rejected by a cut we return kFALSE.
1360  // If rejected_by contains a valid pointer, we set it to the name of the rejecting cut.
1361 
1362  TIter next(&fCuts);
1363  KVIDentifier* id = 0;
1364  if (rejected_by) *rejected_by = "";
1365  while ((id = (KVIDentifier*)next())) {
1366  if (!id->TestPoint(x, y)) {
1367  if (rejected_by) *rejected_by = id->GetName();
1368  return kFALSE;
1369  }
1370  }
1371  return kTRUE;
1372 }
1373 
1374 
1375 
1378 
1380 {
1381  // loop over KVIDGraph::fInfoZones to set flags in KVIdentificationResult
1382 
1383  TIter next(&fInfoZones);
1384  KVIDentifier* id = 0;
1385  while ((id = (KVIDentifier*)next())) {
1386  if (id->TestPoint(x, y)) {
1387  idr->AddFlag(GetName(), id->GetName());
1388  }
1389  }
1390 }
1391 
1392 
1393 
1394 
1397 
1399 {
1400  // Set list of runs for which grid is valid
1401  fRunList = runs;
1402  fPar.SetValue("Runlist", fRunList.AsString());
1403  Modified();
1404 }
1405 
1406 
1407 
1408 
1413 
1415 {
1416  // If name of grid is not set explicitly with SetName(const Char_t*),
1417  // we return the name of the first ID telescope in the list of telescopes
1418  // with which this grid is associated.
1419 
1420  if (fName != "") return fName;
1421  fDyName = "";
1422  if (fTelescopes.At(0)) fDyName = fTelescopes.At(0)->GetName();
1423  else {
1424  if (fPar.HasParameter("IDTelescopes")) {
1425  KVString tel_list = fPar.GetStringValue("IDTelescopes");
1426  tel_list.Begin(",");
1427  fDyName = tel_list.Next();
1428  }
1429  }
1430  return fDyName;
1431 }
1432 
1433 
1434 
1435 
1442 
1444 {
1445  // Called after reading a grid from an ascii file.
1446  // Tries to convert information written by an old version of the class:
1447  //
1448  //<PARAMETER> First run=... ----> <PARAMETER> Runlist=...
1449  //<PARAMETER> Last run=...
1450 
1451  if (fPar.HasParameter("Runlist")) return;
1452  if (fPar.HasParameter("First run") && fPar.HasParameter("Last run")) {
1453  fRunList.SetMinMax(fPar.GetIntValue("First run"), fPar.GetIntValue("Last run"));
1454  fPar.SetValue("Runlist", fRunList.AsString());
1455  fPar.RemoveParameter("First run");
1456  fPar.RemoveParameter("Last run");
1457  }
1458 }
1459 
1460 
1468 
1470 {
1471  // ecriture des grilles avec version suivant un modele de fichier (fPattern)
1472  // fPattern_v%d.grid
1473  // le modele doit etre initialiser par la methode SetPattern(TString)
1474  // la valeur par default version=-1 permet l ecriture de la derniere version
1475  // apres un check des versions existantes (methode CheckVersion)
1476  // la premiere version est indexee v0
1477  Int_t vv = 0;
1478  if (version == -1) vv = CheckVersion(version) + 1;
1479  WriteAsciiFile(fPattern + "_v" + Form("%d", vv) + ".grid");
1480 }
1481 
1482 
1485 
1487 {
1488  // lecture des grilles avec version suivant un modele de fichier
1489  Int_t vv = CheckVersion(version);
1490  if (vv == -1) {
1491  if (version == -1) cout << "no file " + fPattern + "_v%d.grid" << endl;
1492  else cout << "no file " + fPattern + Form("_v%d.grid", version) << endl;
1493  }
1494  else ReadAsciiFile(fPattern + "_v" + Form("%d", vv) + ".grid");
1495 }
1496 
1497 
1504 
1506 {
1507  // version>=0 check si la version demandee du fichier grille existe
1508  // version-1 renvoie la derniere version existante
1509  // si la version demandee n existe pas return -1
1510  // creation d un fichier tampon dans le repertoire ou se situe les fichiers grilles
1511  // efface a la fin de la methode
1512  Int_t temoin = -1;
1513  TString pbis = fPattern, chemin = "";
1514  TObjArray* tok = NULL;
1515  if (fPattern.Contains("/")) { // prise en compte de fPattern contenant un chemin pour les fichiers
1516  tok = fPattern.Tokenize("/");
1517  Int_t nb = tok->GetEntries();
1518  pbis = ((TObjString*)(*tok)[nb - 1])->GetString();
1519  chemin = "";
1520  for (Int_t ii = 0; ii < nb - 1; ii += 1) chemin += ((TObjString*)(*tok)[ii])->GetString();
1521  chemin += "/";
1522  }
1523  gROOT->ProcessLine(".! ls " + fPattern + "_v*.grid >> " + chemin + "listKVIDGraph_" + pbis);
1524  ifstream f_in(chemin + "listKVIDGraph_" + pbis);
1525  TString line = "";
1526  Int_t num = -2;
1527  while (f_in.good() && num != version) {
1528  line.ReadLine(f_in);
1529  if (line.Contains(fPattern + "_v") && line.Contains(".grid")) {
1530  tok = line.Tokenize(".");
1531  line = ((TObjString*)(*tok)[0])->GetString();
1532  line.ReplaceAll(fPattern + "_v", "template");
1533  tok = line.Tokenize("template");
1534  num = ((TObjString*)(*tok)[0])->GetString().Atoi();
1535  if (num > temoin) temoin = num;
1536  }
1537  }
1538  f_in.close();
1539  gROOT->ProcessLine(".! rm -f " + chemin + "listKVIDGraph_" + pbis);
1540  delete tok;
1541  if (version == -1) return temoin;
1542  else if (temoin != version) {
1543  return -1;
1544  }
1545  else return temoin;
1546 }
1547 
1548 
1549 
1550 
1554 
1556 {
1557  // Set mass formula for all identifiers if graph has OnlyZId()=kTRUE.
1558  // This will change the mass (A) of each identifier.
1559 
1560  fMassFormula = mass;
1561  if (IsOnlyZId()) {
1562  if (GetNumberOfIdentifiers() > 0) {
1563  fIdentifiers.R__FOR_EACH(KVIDentifier, SetMassFormula)(mass);
1564  }
1565  }
1566  Modified();
1567 }
1568 
1569 
1570 
1571 
1577 
1579 {
1580  // Use this method if the graph is only to be used for Z identification
1581  // (no isotopic information). Default is to identify both Z & A
1582  // (fOnlyZid = kFALSE). Note that setting fOnlyZid=kTRUE changes the way line
1583  // widths are calculated (see KVIDGrid::CalculateLineWidths)
1584  fOnlyZId = yes;
1585  if (GetNumberOfIdentifiers() > 0) {
1586  fIdentifiers.R__FOR_EACH(KVIDentifier, SetOnlyZId)(yes);
1587  }
1588  Modified();
1589 }
1590 
1591 
1592 
1593 
1594 
1597 
1599 {
1600  // Associate this graph with all ID telescopes in list
1601 
1602  TIter next(tels);
1603  KVBase* tel;
1604  while ((tel = (KVBase*)next())) AddIDTelescope(tel);
1605  Modified();
1606  if (gIDGridManager) gIDGridManager->Modified();
1607 }
1608 
1609 
1610 
1611 
1617 
1619 {
1620  // Static function which will create and 'Build' the identification graph of
1621  // class 'class_name', one of the plugins defined in either $KVROOT/KVFiles/.kvrootrc,
1622  // or in the user's .kvrootrc file.
1623 
1624  //check and load plugin library
1625  TPluginHandler* ph;
1626  if (!(ph = KVBase::LoadPlugin("KVIDGraph", class_name)))
1627  return 0;
1628 
1629  //execute constructor/macro for graph - assumed without arguments
1630  KVIDGraph* gr = (KVIDGraph*) ph->ExecPlugin(0);
1631  return gr;
1632 }
1633 
1634 
1635 
1636 
1643 
1645 {
1646  // Toggles 'editable' status of all lines/contours in graph
1647  // If editable = kTRUE this makes it possible to modify the graph
1648  // we then take a snapshot of the graph before editing begins
1649  // and store it in fLastSavedVersion. we can always revert to
1650  // this version if we want
1651 
1652  if (editable && !GetEditable()) UpdateLastSavedVersion();
1653 
1654  TCutG::SetEditable(editable);
1655  if (GetNumberOfIdentifiers() > 0) {
1656  fIdentifiers.R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1657  }
1658  if (GetNumberOfCuts() > 0) {
1659  fCuts.R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1660  }
1661  if (GetNumberOfInfos() > 0) {
1662  fInfoZones.R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1663  }
1664 }
1665 
1666 
1667 
1668 
1669 
1670 
1673 
1674 void KVIDGraph::SetIDTelescopes(const TString& idt_names)
1675 {
1676  // Set value of "IDTelescopes" parameter with comma-separated list of ID telescope names
1677  fPar.SetValue("IDTelescopes", idt_names);
1678 }
1679 
1680 
1681 
1682 
1686 
1687 void KVIDGraph::Streamer(TBuffer& R__b)
1688 {
1689  // Stream an object of class KVIDGraph.
1690  // Resets the 'fParent' pointer of each KVIDentifier after reading them in.
1691 
1692  if (R__b.IsReading()) {
1693  R__b.ReadClassBuffer(KVIDGraph::Class(), this);
1694  TIter nxt_id(&fIdentifiers);
1695  KVIDentifier* id;
1696  while ((id = (KVIDentifier*)nxt_id())) id->fParent = this;
1697  TIter nxt_cut(&fCuts);
1698  while ((id = (KVIDentifier*)nxt_cut())) id->fParent = this;
1699  TIter nxt_info(&fInfoZones);
1700  while ((id = (KVIDentifier*)nxt_info())) id->fParent = this;
1701  }
1702  else {
1703  R__b.WriteClassBuffer(KVIDGraph::Class(), this);
1704  }
1705 }
1706 
1707 
1708 
1710 
1714 
1716  : histos(h), histo_names(n)
1717  {}
1718  void fill(const char* name, double x, double y = 0., double w = 0.)
1719  {
1721  if (h) {
1722  if (w > 0)((TH2*)h)->Fill(x, y, w);
1723  else h->Fill(x, y);
1724  }
1725  }
1726 };
1727 
1728 
1729 
1754 
1756 {
1757  //This method allows to test the identification capabilities of the grid using data in a TH2F.
1758  //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1759  //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1760  //IsIdentifiable() returns kTRUE) and fill the histograms with the results of the identification
1761  //
1762  //The "identification" or PID we represent is the result of the KVReconstructedNucleus::GetPID()
1763  //method for the identified nucleus.
1764  //
1765  // The KVHashList contains histograms to be filled with results
1766  // The KVNameValueList histo_names contains the name of each histogram passed in the KVHashList
1767  // i.e. it may have any of the following parameters
1768  //
1769  // "ID_REAL"="[name of histo to fill with PID spectrum]"
1770  // "ID_REAL_AIDENT"="[name of histo to fill with PID spectrum]" Z&A identification
1771  // "ID_REAL_ZIDENT"="[name of histo to fill with PID spectrum]" Only Z identification
1772  // "ID_REAL_VS_ERES" - PID vs. Eres (X) histo
1773  // "ID_REAL_VS_DE" - PID vs. DeltaE (Y) histo
1774  // "ID_REAL_VS_ERES_AIDENT" - PID vs. Eres histo, Z&A identification
1775  // "ID_REAL_VS_ERES_ZIDENT" - PID vs. Eres histo, only Z identification
1776  // - only for isotopic identificiation:
1777  // "Z_A_REAL" - 2D map (nuclear chart)
1778  // "ZADIST_AIDENT" - integer A vs. integer Z distribution for isotopically-identified particles
1779 
1780  //Initialize the grid: calculate line widths etc.
1781  Initialize();
1782 
1783  kvidgraph_idresult_filler idresults(histos, histo_names);
1784 
1785  // reset contents of all histos
1786  histos.Execute("Reset", "");
1787 
1788  Int_t tot_events = (Int_t) data->GetSum();
1789  Int_t events_read = 0;
1790  Int_t percent = 0, cumul = 0;
1791 
1793 
1794  for (int i = 1; i <= data->GetNbinsX(); ++i) {
1795  for (int j = 1; j <= data->GetNbinsY(); j++) {
1796 
1797  Stat_t poids = data->GetBinContent(i, j);
1798  if (poids == 0)
1799  continue;
1800 
1801  Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1802  Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1803  Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1804  Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1805  //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1806  //randomly-drawn x and y coordinates inside this bin
1807  //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1808  //a weight poids/20
1809  Int_t kmax = (Int_t) TMath::Min(20., poids);
1810  Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1811  for (int k = 0; k < kmax; k++) {
1812  double x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1813  double y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1814  if (IsIdentifiable(x, y)) {
1815  idr.Clear();
1816  Identify(x, y, &idr);
1817  if (AcceptIDForTest(idr)) {
1818  Float_t PID = idr.PID;
1819  if (idr.Aident) PID = (idr.Z + 0.1 * (idr.PID - 2. * idr.Z));
1820  Float_t RealA, RealZ;
1821  RealA = (idr.Aident ? idr.PID : (Float_t)idr.A);
1822  RealZ = (idr.Aident ? (Float_t)idr.Z : idr.PID);
1823  idresults.fill("ID_REAL", PID, weight);
1824  idresults.fill("ID_REAL_VS_DE", y, PID, weight);
1825  idresults.fill("ID_REAL_VS_ERES", x, PID, weight);
1826  if (idr.Aident) {
1827  idresults.fill("Z_A_REAL", RealA - RealZ, gRandom->Gaus(RealZ, 0.15), weight);
1828  idresults.fill("ZADIST_AIDENT", idr.Z, idr.A, weight);
1829  idresults.fill("ID_REAL_AIDENT", PID, weight);
1830  idresults.fill("ID_REAL_VS_DE_AIDENT", y, PID, weight);
1831  idresults.fill("ID_REAL_VS_ERES_AIDENT", x, PID, weight);
1832  }
1833  else if (idr.Zident) {
1834  idresults.fill("ID_REAL_ZIDENT", PID, weight);
1835  idresults.fill("ID_REAL_VS_DE_ZIDENT", y, PID, weight);
1836  idresults.fill("ID_REAL_VS_ERES_ZIDENT", x, PID, weight);
1837  }
1838  }
1839  }
1840  }
1841  events_read += (Int_t) poids;
1842  percent = (1. * events_read / tot_events) * 100.;
1843  if (percent > cumul) {
1844  Increment((Float_t) events_read); //sends signal to GUI progress bar
1846  cumul = percent;
1847  }
1848 
1849  }
1850  }
1851 }
1852 
1853 
int Int_t
bool Bool_t
char Char_t
float Float_t
double Axis_t
constexpr Bool_t kFALSE
double Double_t
double Stat_t
constexpr Bool_t kTRUE
const char Option_t
kBlack
winID w
winID h TVirtualViewer3D vv
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint percent
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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
float xmin
float ymin
float xmax
float ymax
#define gROOT
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
#define gPad
Base class for KaliVeda framework.
Definition: KVBase.h:140
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:795
Extension of TDatime to handle various useful date formats.
Definition: KVDatime.h:35
Extended version of ROOT THashList.
Definition: KVHashList.h:29
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:31
KVNumberList fRunList
runs for which grid is valid
Definition: KVIDGraph.h:48
void Add(TString, KVIDentifier *)
Definition: KVIDGraph.cpp:913
Axis_t GetYmax() const
Definition: KVIDGraph.h:470
Double_t GetYScaleFactor()
Definition: KVIDGraph.cpp:294
TString fDyName
dynamically generated name
Definition: KVIDGraph.h:50
void Draw(Option_t *opt="") override
Definition: KVIDGraph.cpp:963
virtual void ReadAsciiFile_WP(Int_t version=-1)
lecture des grilles avec version suivant un modele de fichier
Definition: KVIDGraph.cpp:1486
KVIDGraph * fLastSavedVersion
copy of last save version of grid, used for 'undo'
Definition: KVIDGraph.h:53
Int_t GetNumberOfCuts() const
Definition: KVIDGraph.h:401
void ExtendBeginningAllIdentLines(Double_t, Option_t *="")
Definition: KVIDGraph.cpp:1092
KVNameValueList fPar
parameters associated to grid
Definition: KVIDGraph.h:44
void ReadAsciiFile(const Char_t *filename)
Definition: KVIDGraph.cpp:854
void RemoveIdentifier(KVIDentifier *)
Remove and destroy identifier.
Definition: KVIDGraph.cpp:337
Double_t GetXScaleFactor()
Definition: KVIDGraph.cpp:276
void Clear(Option_t *opt="") override
Definition: KVIDGraph.cpp:205
virtual void TestIdentification(TH2F *data, KVHashList &histos, KVNameValueList &histo_names)
Definition: KVIDGraph.cpp:1755
KVList fCuts
cuts used to define area in which identification is possible
Definition: KVIDGraph.h:40
KVList fIdentifiers
list of identification objects
Definition: KVIDGraph.h:39
Double_t fLastScaleY
last applied scaling factor on Y
Definition: KVIDGraph.h:46
void SetVarY(const char *v) override
Definition: KVIDGraph.h:637
Double_t fLastScaleX
last applied scaling factor on X
Definition: KVIDGraph.h:45
void SetEditable(Bool_t editable=kTRUE) override
Definition: KVIDGraph.cpp:1644
void UpdateLastSavedVersion()
update last saved version. mkae copy of current state of graph.
Definition: KVIDGraph.cpp:539
Axis_t GetXmax() const
Definition: KVIDGraph.h:466
const Char_t * GetFileWrite() const
Definition: KVIDGraph.cpp:577
void ExtendEndAllIdentLines(Double_t, Option_t *="")
Definition: KVIDGraph.cpp:1108
void RemoveInfo(KVIDentifier *)
Remove and destroy cut.
Definition: KVIDGraph.cpp:365
virtual void WriteToAsciiFile(std::ofstream &gridfile)
Definition: KVIDGraph.cpp:444
const Char_t * GetNamesOfIDTelescopes() const
Definition: KVIDGraph.h:490
const Char_t * GetTimestamp() const
Definition: KVIDGraph.cpp:559
static void SetAutoAdd(Bool_t yes=kTRUE)
Definition: KVIDGraph.h:156
void init()
Definition: KVIDGraph.cpp:69
virtual void AddInfo(KVIDentifier *info)
Definition: KVIDGraph.h:437
void Increment(Float_t x)
Definition: KVIDGraph.h:307
Int_t GetNumberOfIdentifiers() const
Definition: KVIDGraph.h:397
virtual void ReadIdentifierFromAsciiFile(TString &name, TString &type, TString &cl, std::ifstream &gridfile)
Read in new identifier object from file.
Definition: KVIDGraph.cpp:830
Axis_t fXmin
Definition: KVIDGraph.h:42
Bool_t IsOnlyZId() const
Definition: KVIDGraph.h:57
Int_t GetMassFormula() const
Definition: KVIDGraph.h:548
void MakeBestGuessForNewIDLineZandA(KVIDentifier *idline)
Definition: KVIDGraph.h:73
void RevertToLastSavedVersion()
Definition: KVIDGraph.cpp:596
void UnDraw()
Definition: KVIDGraph.cpp:1041
void SetVarX(const char *v) override
Definition: KVIDGraph.h:633
virtual void ReadFromAsciiFile(std::ifstream &gridfile)
Definition: KVIDGraph.cpp:656
void ClearPad(TVirtualPad *)
Definition: KVIDGraph.cpp:51
void WriteParameterListOfIDTelescopes()
Definition: KVIDGraph.cpp:384
virtual void Identify(Double_t, Double_t, KVIdentificationResult *) const =0
TString fPattern
pattern of filenames used to write or read grid
Definition: KVIDGraph.h:51
const Char_t * GetName() const override
Definition: KVIDGraph.cpp:1414
virtual void DrawAndAdd(const TString &type="ID", const TString &classname="KVIDentifier")
Definition: KVIDGraph.cpp:1252
virtual void WriteAsciiFile_WP(Int_t version=-1)
Definition: KVIDGraph.cpp:1469
KVIDentifier * GetIdentifier(Int_t Z, Int_t A) const
Definition: KVIDGraph.cpp:312
virtual ~KVIDGraph()
Definition: KVIDGraph.cpp:190
void AddIDTelescope(const TString &t)
Definition: KVIDGraph.h:500
virtual Bool_t IsIdentifiable(Double_t, Double_t, TString *rejected_by=nullptr) const
Definition: KVIDGraph.cpp:1351
void FindAxisLimits()
Calculate X/Y min/max of all objects in graph.
Definition: KVIDGraph.cpp:1148
Axis_t GetYmin() const
Definition: KVIDGraph.h:462
const KVNameValueList * GetParameters() const
Definition: KVIDGraph.h:357
static KVIDGraph * AddGraphs(KVIDGraph *g1, Int_t id1_min, Int_t id1_max, KVIDGraph *g2, Int_t id2_min, Int_t id2_max)
Definition: KVIDGraph.cpp:1301
void SetName(const Char_t *nome="") override
Definition: KVIDGraph.h:108
virtual void AddCut(KVIDentifier *cut)
Definition: KVIDGraph.h:422
void SetMassFormula(Int_t)
Definition: KVIDGraph.cpp:1555
TList fTelescopes
ID telescopes for which grid is valid.
Definition: KVIDGraph.h:49
static Bool_t fAutoAddGridManager
if =kTRUE, grids are automatically added to ID grid manager on creation (default)
Definition: KVIDGraph.h:54
void WriteAsciiFile(const Char_t *filename)
Open, write and close ascii file containing this grid.
Definition: KVIDGraph.cpp:406
virtual KVIDentifier * New(const Char_t *)
Create new object of class "id_class" which derives from KVIDentifier.
Definition: KVIDGraph.cpp:882
void Scale(Double_t c1=1., Option_t *option="y") override
Definition: KVIDGraph.h:181
virtual void BackwardsCompatibilityFix()
Definition: KVIDGraph.cpp:1443
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
Definition: KVIDGraph.cpp:1598
virtual void AddIdentifier(KVIDentifier *id)
Definition: KVIDGraph.h:409
virtual void SetInfos(Double_t, Double_t, KVIdentificationResult *) const
loop over KVIDGraph::fInfoZones to set flags in KVIdentificationResult
Definition: KVIDGraph.cpp:1379
static KVIDGraph * MakeIDGraph(const Char_t *)
Definition: KVIDGraph.cpp:1618
void SetLineColor(Color_t lcolor) override
Definition: KVIDGraph.h:249
Axis_t GetXmin() const
Definition: KVIDGraph.h:458
void SetXScaleFactor(Double_t=0)
Definition: KVIDGraph.cpp:228
Int_t GetNumberOfInfos() const
Definition: KVIDGraph.h:405
void SetIDTelescopes(const TString &)
Set value of "IDTelescopes" parameter with comma-separated list of ID telescope names.
Definition: KVIDGraph.cpp:1674
TVirtualPad * fPad
pad in which graph is drawn
Definition: KVIDGraph.h:47
virtual Bool_t AcceptIDForTest(const KVIdentificationResult &idr)
Definition: KVIDGraph.h:131
Axis_t fYmax
min/max Y coordinates of graph
Definition: KVIDGraph.h:43
void SetRuns(const KVNumberList &nl)
Set list of runs for which grid is valid.
Definition: KVIDGraph.cpp:1398
virtual Int_t CheckVersion(Int_t version)
Definition: KVIDGraph.cpp:1505
void SetYScaleFactor(Double_t=0)
Definition: KVIDGraph.cpp:252
virtual void Initialize()=0
Axis_t fXmax
min/max X coordinates of graph
Definition: KVIDGraph.h:42
Bool_t fOnlyZId
set to kTRUE when only to be used to give Z identification of nuclei, no mass info
Definition: KVIDGraph.h:38
Int_t fMassFormula
OPTION={GetMethod="GetMassFormula";SetMethod="SetMassFormula";Items=(0="Beta-stability",...
Definition: KVIDGraph.h:52
void ResetDraw()
Definition: KVIDGraph.cpp:1078
void SetPattern(TString pattern)
Definition: KVIDGraph.h:297
Axis_t fYmin
Definition: KVIDGraph.h:43
void Copy(TObject &) const override
Copy this to 'obj'.
Definition: KVIDGraph.cpp:117
void RemoveCut(KVIDentifier *)
Remove and destroy cut.
Definition: KVIDGraph.cpp:352
void Print(Option_t *opt="") const override
Print out all objects in graph.
Definition: KVIDGraph.cpp:1122
KVList fInfoZones
contours/lines used to add info to particles (ex: punch-through)
Definition: KVIDGraph.h:41
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1578
void Modified()
Definition: KVIDGraph.h:313
void ScaleXY(Double_t sx=-1, Double_t sy=-1)
Called by SetX/YScaleFactor methods to rescale every point of every object in the grid.
Definition: KVIDGraph.cpp:1221
const KVList * GetIdentifiers() const
Definition: KVIDGraph.h:367
KVSeqCollection * GetGrids()
void AddGrid(KVIDGraph *)
Add a grid to the collection.
Base class for graphical cuts used in particle identification.
Definition: KVIDentifier.h:28
Full result of one attempted particle identification.
void AddFlag(std::string grid_name, TString flag)
Bool_t Aident
= kTRUE if A of particle established
Double_t PID
= "real" Z if Zident==kTRUE and Aident==kFALSE, "real" A if Zident==Aident==kTRUE
Int_t A
A of particle found (if Aident==kTRUE)
Int_t Z
Z of particle found (if Zident==kTRUE)
void Clear(Option_t *opt="") override
Reset to initial values.
Bool_t Zident
=kTRUE if Z of particle established
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Int_t GetIntValue(const Char_t *name) const
Double_t GetDoubleValue(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
void RemoveParameter(const Char_t *name)
Int_t GetNpar() const
return the number of stored parameters
Bool_t HasStringParameter(const Char_t *name) const
void Clear(Option_t *opt="") override
const Char_t * GetStringValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
void Print(Option_t *opt="") const override
A generic named parameter storing values of different types.
const Char_t * GetString() const
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
void SetMinMax(Int_t min, Int_t max, Int_t pas=1)
Set list with all values from 'min' to 'max'.
const Char_t * AsString(Int_t maxchars=0) const
void Execute(const char *method, const char *params, Int_t *error=0) override
KVSeqCollection * GetSubListWithMethod(const Char_t *retvalue, const Char_t *method) const
T * get_object(const TString &name) const
TObject * Remove(TObject *obj) override
Remove object from list.
void RecursiveRemove(TObject *obj) override
void Delete(Option_t *option="") override
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
void Copy(TAttFill &attfill) const
void Copy(TAttLine &attline) const
void Copy(TAttMarker &attmarker) const
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
Bool_t InheritsFrom(const char *cl) const override
virtual Int_t GetEntries() const
void Streamer(TBuffer &) override
const char * GetVarX() const
static TClass * Class()
TClass * IsA() const override
const char * GetVarY() const
const char * AsSQLString() const
Bool_t GetEditable() const
virtual void SetEditable(Bool_t editable=kTRUE)
virtual Int_t Fill(const char *name, Double_t w)
void ls(Option_t *option="") const override
TObject * At(Int_t idx) const override
void Copy(TObject &named) const override
const char * GetName() const override
const char * GetTitle() const override
TString fName
Int_t GetEntries() const override
virtual const char * GetName() const
virtual TObject * Clone(const char *newname="") const
virtual const char * ClassName() const
virtual void Info(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
virtual Double_t Uniform(Double_t x1, Double_t x2)
const char * Data() const
TObjArray * Tokenize(const TString &delim) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Bool_t ProcessEvents()
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
TLine * line
Type
Double_t y[n]
Double_t x[n]
gr SetName("gr")
const Int_t n
TGraphErrors * gr
TH1 * h
void Error(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:116
void Warning(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:125
Double_t Min(Double_t a, Double_t b)
Double_t Abs(Double_t d)
void fill(const char *name, double x, double y=0., double w=0.)
Definition: KVIDGraph.cpp:1718
KVNameValueList & histo_names
Definition: KVIDGraph.cpp:1713
kvidgraph_idresult_filler(KVHashList &h, KVNameValueList &n)
Definition: KVIDGraph.cpp:1715
ClassImp(TPyArg)