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 using namespace std;
27 
29 
30 
31 
33 void KVIDGraph::ResetPad()
34 {
35  cout << "The pad showing graph " << GetName() << " has been closed !" << endl;
36 
37  if (fPad) {
38  fPad->Disconnect("Closed()", this, "ResetPad()");
39  if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect("Cleared(TVirtualPad*)", this, "ClearPad(TVirtualPad*)");
40  }
41  fPad = 0;
42 
43 }
44 
45 
46 
48 
50 {
51  if (fPad == pad) {
52  cout << "The pad showing graph " << GetName() << " has been cleared" << endl;
53  fPad->Disconnect("Closed()", this, "ResetPad()");
54  if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect("Cleared(TVirtualPad*)", this, "ClearPad(TVirtualPad*)");
55  fPad = 0;
56  }
57 }
58 
59 
61 
62 
66 
68 {
69  // Initialisations, used by constructors
70  // All graphs are added to gIDGridManager (if it exists).
71 
72  fIdentifiers.SetCleanup();
73  fCuts.SetCleanup();
74  fInfoZones.SetCleanup();
75  fXmin = fYmin = fXmax = fYmax = 0;
76  fLastScaleX = 1.0;
77  fLastScaleY = 1.0;
78  fOnlyZId = kFALSE;
79  fPad = 0;
80  SetName("");
81  SetEditable(kFALSE);
82  if (fAutoAddGridManager && gIDGridManager) gIDGridManager->AddGrid(this);
83  fMassFormula = 0;
84  fLastSavedVersion = NULL;
85 }
86 
87 
88 
89 // void KVIDGraph::Browse(TBrowser* b)
90 // {
91 // // This method is executed when an object is double-clicked in a browser
92 // // such as the list of grids in KVIDGridManagerGUI
93 // //
94 // // Overrides default TGraph::Browse (which calls Draw()) in order to open
95 // // the grid in the KVIDGridEditor canvas (if one exists).
96 // // If no KVIDGridEditor exists, we perform the default action (Draw()).
97 // //
98 //
99 // if( gIDGridEditor ){
100 // // avant d'editer la grille, on en fait une copie pour
101 // // pouvoir revenir en arriere
102 // UpdateLastSavedVersion();
103 // if(gIDGridEditor->IsClosed()) gIDGridEditor->StartViewer();
104 // gIDGridEditor->SetGrid(this);
105 // }
106 // else
107 // TGraph::Browse(b);
108 // }
109 
110 
111 
114 
115 void KVIDGraph::Copy(TObject& obj) const
116 {
117  //Copy this to 'obj'
118  TNamed::Copy(obj);
119  TAttLine::Copy((TAttLine&)obj);
120  TAttFill::Copy((TAttFill&)obj);
122  ((TCutG&)obj).SetVarX(GetVarX());
123  ((TCutG&)obj).SetVarY(GetVarY());
124  KVIDGraph& grid = (KVIDGraph&) obj;
125  grid.fOnlyZId = const_cast <KVIDGraph*>(this)->fOnlyZId;
126  grid.SetPattern(fPattern);
127  //as in WriteAsciiFile, we need to remove any scaling factors from the coordinates
128  //before copying the coordinates, then we set the scaling factors at the end
129 
130  //remove scaling if there is one
131  if (fLastScaleX != 1 || fLastScaleY != 1)
132  const_cast < KVIDGraph* >(this)->ScaleXY(1. / fLastScaleX,
133  1. / fLastScaleY);
134 
135  fIdentifiers.Copy(grid.fIdentifiers);
136  fCuts.Copy(grid.fCuts);
137  fInfoZones.Copy(grid.fInfoZones);
138  // set mass formula of grid (and identifiers)
139  grid.SetMassFormula(GetMassFormula());
140  //copy all parameters EXCEPT scaling parameters
141  KVNamedParameter* par = 0;
142  for (int i = 0; i < fPar.GetNpar(); i++) { //loop over all parameters
143  par = fPar.GetParameter(i);
144  TString parname(par->GetName());
145  if (!parname.Contains("ScaleFactor"))
146  grid.fPar.SetValue(*par);
147  }
148  //restore scaling to this grid if there was one, and apply it to the copied grid
149  if (fLastScaleX != 1 || fLastScaleY != 1) {
150  const_cast < KVIDGraph* >(this)->ScaleXY(fLastScaleX, fLastScaleY);
151  grid.SetXScaleFactor(fLastScaleX);
152  grid.SetYScaleFactor(fLastScaleY);
153  }
154 }
155 
156 
157 
158 KVIDGraph::KVIDGraph() : fRunList(""), fDyName(""), fPattern("")
159 
160 
163 
164 {
165  // Default constructor
166  init();
167 }
168 
169 
170 
171 
174 
175 KVIDGraph::KVIDGraph(const KVIDGraph& grid) : TCutG(), fRunList(""), fDyName(""), fPattern("")
176 {
177  //Copy constructor
178  init();
179  grid.Copy(*this);
180 }
181 
182 
183 
187 
189 {
190  // Destructor
191  // remove from grid manager
192  if (gIDGridManager) gIDGridManager->GetGrids()->RecursiveRemove(this);
193 }
194 
195 
196 
197 
202 
204 {
205  // reset the grid (destroying any previously defined identifiers) ready to start anew.
206  // resets axis limits
207  // scaling factors (if any) are removed
208 
210  fCuts.Delete();
211  fInfoZones.Delete();
212  fXmin = fYmin = fXmax = fYmax = 0;
213  SetXScaleFactor();
214  SetYScaleFactor();
215  Modified();
216 }
217 
218 
220 
221 
225 
227 {
228  //Set scaling factor for X-axis - rescales all objects with this factor
229  //SetXScaleFactor() or SetXScaleFactor(0) removes scale factor
230  if (s > 0) {
231  fPar.SetValue("XScaleFactor", s);
232  ScaleXY(s / fLastScaleX);
233  fLastScaleX = s;
234  }
235  else {
236  fPar.RemoveParameter("XScaleFactor");
237  ScaleXY(1.0 / fLastScaleX);
238  fLastScaleX = 1.0;
239  }
240 }
241 
242 
244 
245 
249 
251 {
252  //Set scaling factor for Y-axis - rescales all objects with this factor
253  //SetYScaleFactor() or SetYScaleFactor(0) removes scale factor
254  if (s > 0) {
255  fPar.SetValue("YScaleFactor", s);
256  ScaleXY(-1.0, s / fLastScaleY);
257  fLastScaleY = s;
258  }
259  else {
260  fPar.RemoveParameter("YScaleFactor");
261  ScaleXY(-1.0, 1.0 / fLastScaleY);
262  fLastScaleY = 1.0;
263  }
264 }
265 
266 
268 
269 
273 
275 {
276  //Return scaling factor for X-axis
277  //If factor not defined, returns 1
278  Double_t s = fPar.GetDoubleValue("XScaleFactor");
279  if (s > 0)
280  return s;
281  return 1.0;
282 }
283 
284 
286 
287 
291 
293 {
294  //Return scaling factor for Y-axis
295  //If factor not defined, returns 1
296  Double_t s = fPar.GetDoubleValue("YScaleFactor");
297  if (s > 0)
298  return s;
299  return 1.0;
300 }
301 
302 
304 
305 
309 
311 {
312  // Return pointer to identifier with atomic number Z and mass number A.
313  // If this is a 'OnlyZId()' graph we ignore A.
314 
315  KVIDentifier* id = 0;
316  if (!IsOnlyZId()) {
317  unique_ptr<KVSeqCollection> isotopes(fIdentifiers.GetSubListWithMethod(Form("%d", Z), "GetZ"));
318  TIter next(isotopes.get());
319  while ((id = (KVIDentifier*)next())) if (id->GetA() == A) break;
320  }
321  else {
322  TIter next(&fIdentifiers);
323  while ((id = (KVIDentifier*)next())) if (id->GetZ() == Z) break;
324  }
325  return id;
326 }
327 
328 
330 
331 
334 
336 {
337  // Remove and destroy identifier
338  fIdentifiers.Remove(id);
339  delete id;
340  Modified();
341 }
342 
343 
345 
346 
349 
351 {
352  // Remove and destroy cut
353  fCuts.Remove(cut);
354  delete cut;
355  Modified();
356 }
357 
358 
359 
362 
364 {
365  // Remove and destroy cut
366  fInfoZones.Remove(info);
367  delete info;
368  Modified();
369 }
370 
371 
373 
374 
381 
383 {
384  // Fill parameter "IDTelescopes" with list of names of telescopes associated
385  // with this grid, ready to write in ascii file
386 
387  // if list of telescope pointers is empty, do nothing
388  // this is in case there are telescope names already in the IDTelescopes parameter
389  // but they are not telescopes in the current multi det array
390  if (!fTelescopes.GetEntries()) return;
391  fPar.SetValue("IDTelescopes", "");
392  KVString tel_list = GetNamesOfIDTelescopes();
393  fPar.SetValue("IDTelescopes", tel_list);
394 }
395 
396 
398 
399 
400 
403 
404 void KVIDGraph::WriteAsciiFile(const Char_t* filename)
405 {
406  //Open, write and close ascii file containing this grid.
407 
408  ofstream gridfile(filename);
409  WriteToAsciiFile(gridfile);
410  gridfile.close();
411 }
412 
413 
414 
415 
441 
442 void KVIDGraph::WriteToAsciiFile(ofstream& gridfile)
443 {
444  //Write info on this grid in already-open ascii file stream 'gridfile'.
445  //This begins with the line
446  //++ClassName
447  //where '"ClassName'" is the name of the class of the actual instance of this object
448  //followed by informations on the grid and its objects.
449  //
450  //The names associated to the X & Y axis of the identification map are written
451  //on lines beginning with
452  //<VARX>
453  //<VARY>
454  //Any associated parameters are written before the objects, starting with
455  //<PARAMETER>
456  //then the name of the parameter and its value
457  //e.e.
458  //<PARAMETER> ChIo pressure=45.5
459  //A single '!' on a line by itself signals the end of the informations for this grid.
460  //
461  //Scaling factors
462  //Any scaling factors are written in the file as
463  //<PARAMETER> XScaleFactor=...
464  //<PARAMETER> YScaleFactor=...
465  //However the coordinates written in the file are the unscaled factors
466  //When the file is read back again, the unscaled coordinates are read in and
467  //then the scaling is applied.
468 
469  gridfile << "# ASCII file generated by " << ClassName() <<
470  "::WriteToAsciiFile" << endl;
471  gridfile << "# ID Graph Name : " << GetName() << endl;
472  gridfile << "# This file can be read using " << ClassName() <<
473  "::ReadFromAsciiFile" << endl;
474  gridfile << "# " << endl;
475  gridfile << "++" << ClassName() << endl;
476 
477  // write name if given
478  if (fName != "") gridfile << "<NAME> " << fName.Data() << endl;
479  //write X & Y axis names
480  gridfile << "<VARX> " << GetVarX() << endl;
481  gridfile << "<VARY> " << GetVarY() << endl;
482  //write parameters
484  KVNamedParameter* par = 0;
485  for (int i = 0; i < fPar.GetNpar(); i++) { //loop over all parameters
486  par = fPar.GetParameter(i);
487  gridfile << "<PARAMETER> " << par->GetName() << "=" << par->GetString() << endl;
488  }
489 
490  //write fOnlyZId & mass formula
491  if (IsOnlyZId()) gridfile << "OnlyZId " << GetMassFormula() << endl;
492 
493  //remove scaling if there is one
494  if (fLastScaleX != 1 || fLastScaleY != 1)
495  ScaleXY(1. / fLastScaleX, 1. / fLastScaleY);
496 
497  //Write identifiers
498  TIter next_IDline(&fIdentifiers);
500  while ((line = (KVIDentifier*) next_IDline())) {
501  line->WriteAsciiFile(gridfile, "ID");
502  }
503  //Write cuts
504  TIter next_OKline(&fCuts);
505  while ((line = (KVIDentifier*) next_OKline())) {
506  line->WriteAsciiFile(gridfile, "OK");
507  }
508  //Write cuts
509  TIter next_INFOline(&fInfoZones);
510  while ((line = (KVIDentifier*) next_INFOline())) {
511  line->WriteAsciiFile(gridfile, "INFO");
512  }
513 // //Write info zones
514 // TIter next_OKline(fInfoZones);
515 // while ((line = (KVIDentifier*) next_OKline())) {
516 // line->WriteAsciiFile(gridfile, "INFO");
517 // }
518  gridfile << "!" << endl;
519 
520  //restore scaling if there is one
521  if (fLastScaleX != 1 || fLastScaleY != 1)
523 
524  // if a back-up copy had previously been created (by starting the editor)
525  // we replace it by the version read from file
527 }
528 
529 
530 
533 
535 {
536  //update last saved version. mkae copy of current state of graph.
537  if (!fLastSavedVersion) {
538  SetAutoAdd(kFALSE); // disable auto add to grid manager - or we'll have every grid appearing twice!
540  SetAutoAdd(); // re-enable auto add
541  }
543  fLastSavedVersion->GetIdentifiers()->Execute("SetLineColor", "kBlack");
544  fLastSavedVersion->GetIdentifiers()->Execute("SetMarkerColor", "kBlack");
545 }
546 
547 
548 
554 
556 {
557  // Revert to last saved version of grid
558  // this will destroy any existing lines in the grid and replace them with
559  // copies of the lines as they were at the last moment the grid was saved
560  // If the grid is (was) visible in a pad, we redraw the new lines.
561 
562  if (!fLastSavedVersion) {
563  Info("RevertToLastSavedVersion", "No saved version to revert to! (Sorry)");
564  return;
565  }
566  Bool_t wasDrawn = kFALSE;
567  if (fPad) {
568  // if grid was visible, remove it from pad before modifying (deleting) lines
569  wasDrawn = kTRUE;
570  fPad->cd();// make sure pad with grid is active (gPad) pad
571  UnDraw();
572  }
573  Clear();
574  fLastSavedVersion->Copy(*this);
575  if (wasDrawn) {
576  // if grid was visible, redraw it with new lines
577  Draw();
578  }
579 }
580 
581 
582 
583 
600 
601 void KVIDGraph::ReadFromAsciiFile(ifstream& gridfile)
602 {
603  //Read info from already open ascii file stream containing each line of this grid.
604  //Any previous lines in the grid are destroyed.
605  //Comment lines begin with #
606  //Grid info begins with
607  //++ClassName
608  //where ClassName is actual class name of instance of this object
609  //The names associated to the X & Y axis of the identification map are written
610  //on lines beginning with
611  //<VARX>
612  //<VARY>
613  //Parameter lines begin with <PARAMETER>
614  //New lines begin with +name_of_class
615  //'!' signals end of grid info
616  //Any scaling factors are applied once the coordinates have been read
617 
618  //reset grid - destroy old lines, axis limits...
619  Clear();
620  //clear parameters
621  fPar.Clear();
622 
623  KVString s;
624  int line_no = 0; // counter for lines read
626  Int_t mass_formula = -1;
627 
628  while (gridfile.good()) {
629  //read a line
630  s.ReadLine(gridfile);
631  if (s.BeginsWith('!')) {
632  //end of grid signalled
633  break;
634  }
635  else if (s.BeginsWith("++")) { //will only happen if we are reading a file using ReadAsciiFile(const char*)
636  //check classname
637  s.Remove(0, 2);
638  s.Remove(TString::kBoth, ' '); //remove whitespace
639  if (s != ClassName()) {
640  KVBase b;
641  b.Warning("ReadFromAsciiFile(ofstream&)",
642  "Class name in file %s does not correspond to this class (%s)",
643  s.Data(), ClassName());
644  }
645  }
646  else if (s.BeginsWith("<NAME>")) {
647  //name of grid
648  s.Remove(0, 7);
649  s.Remove(TString::kBoth, ' '); //remove whitespace
650  SetName(s.Data());
651  }
652  else if (s.BeginsWith("<VARX>")) {
653  //x-axis definition
654  s.Remove(0, 7);
655  s.Remove(TString::kBoth, ' '); //remove whitespace
656  SetVarX(s.Data());
657  }
658  else if (s.BeginsWith("<VARY>")) {
659  //y-axis definition
660  s.Remove(0, 7);
661  s.Remove(TString::kBoth, ' '); //remove whitespace
662  SetVarY(s.Data());
663  }
664  else if (s.BeginsWith("<PARAMETER>")) {
665  //parameter definition
666  s.Remove(0, 11);
667  //split into tokens separated by '='
668  if (s.GetNValues("=") == 2) {
669  s.Begin("=");
670  auto name = s.Next(kTRUE);
671  auto value = s.Next(kTRUE);
672  if (name != "" && value != "") {
673  if (value.IsDigit())
674  fPar.SetValue(name.Data(), value.Atoi());
675  else if (value.IsFloat())
676  fPar.SetValue(name.Data(), value.Atof());
677  else
678  fPar.SetValue(name.Data(), value.Data());
679  }
680  }
681  }
682  else if (s.BeginsWith("<LIST>")) { // number list definition
683  s.Remove(0, 6); // get rid of "<LIST>"
684  //split into tokens separated by '='
685  if (s.GetNValues("=") == 2) {
686  s.Begin("=");
687  auto name = s.Next(kTRUE);
688  auto list = s.Next();
689  //set appropriate list
690  if (name == "Runs")
691  SetRuns(list.Data());
692  else
693  fPar.SetValue(name.Data(), list.Data());
694  }
695  }
696  else if (s.BeginsWith("OnlyZId")) {
697  SetOnlyZId(kTRUE);
698  s.ReplaceAll("OnlyZId", "");
699  s.Remove(TString::kBoth, ' ');
700  if (s != "") { //older versions did not write mass formula after OnlyZId
701  mass_formula = s.Atoi();
702  if (mass_formula > -1) SetMassFormula(mass_formula);
703  }
704  }
705  else if (s.BeginsWith('+')) {
706  //New line
707  line_no++;
708  //Get name of class by stripping off the '+' at the start of the line
709  s.Remove(0, 1);
710  TString lineclass = s;
711  //next line is type ("ID" or "OK") followed by ':', followed by name of line
712  s.ReadLine(gridfile);
713  //split into tokens separated by ':'
714  s.Begin(":");
715  auto type = s.Next(kTRUE);
716  TString name = "";
717  // make sure the line actually has a name !
718  if (!s.End()) name = s.Next(kTRUE);
719  else {
720  // print warning allowing to find nameless line in file
721  {
722  KVBase b;
723  b.Warning("ReadFromAsciiFile",
724  "In graph : %s\nIdentifier with no name. Identifier type = %s. Line number in graph = %d",
725  GetName(), type.Data(), line_no);
726  }
727  }
728  ReadIdentifierFromAsciiFile(name, type, lineclass, gridfile);
729  }
730  }
733  if (fLastScaleX != 1 || fLastScaleY != 1) {
735  }
737  //set runlist
738  if (fPar.HasParameter("Runlist")) {
739  SetRuns(fPar.GetStringValue("Runlist"));
740  }
741  else SetRuns("");
742 
743  // if a back-up copy had previously been created (by starting the editor)
744  // we replace it by the version read from file
746 }
747 
748 
749 
750 
753 
754 void KVIDGraph::ReadIdentifierFromAsciiFile(TString& name, TString& type, TString& cl, ifstream& gridfile)
755 {
756  // Read in new identifier object from file
757 
758  KVIDentifier* line = New(cl.Data());
759  line->SetName(name.Data());
760  Add(type, line);
761  //now use ReadAscii method of class to read coordinates and other informations
762  line->ReadAsciiFile(gridfile);
763 }
764 
765 
766 
767 
777 
778 void KVIDGraph::ReadAsciiFile(const Char_t* filename)
779 {
780  //Open, read and close ascii file containing this grid.
781  //Any previous lines in the grid are destroyed.
782  //Comment lines begin with #
783  //Grid info begins with
784  //++ClassName
785  //where ClassName is actual class name of instance of this object
786  //New lines begin with +name_of_class
787  //'!' signals end of grid
788 
789  ifstream gridfile(filename);
790 
791  if (gridfile.good()) {
792  ReadFromAsciiFile(gridfile);
793  }
794  else {
795  KVBase b;
796  b.Warning("ReadAsciiFile", "Could not find file %s. Check filename.", filename);
797  }
798  gridfile.close();
799 }
800 
801 
802 
803 
806 
808 {
809  //Create new object of class "id_class" which derives from KVIDentifier
810 
811  KVIDentifier* line = 0;
812  TClass* clas = TClass::GetClass(id_class);
813  if (!clas) {
814  Error("New",
815  "%s is not a valid classname. No known class.", id_class);
816  }
817  else {
818  if (!clas->InheritsFrom(KVIDentifier::Class())) {
819  Error("New",
820  "%s is not a valid class deriving from KVIDentifier",
821  id_class);
822  }
823  else {
824  line = (KVIDentifier*) clas->New();
825  }
826  }
827  return line;
828 }
829 
830 
831 
832 
837 
839 {
840  // Add the object to the list of cuts or identifiers:
841  // type = "ID" --> calls AddIdentifier(id)
842  // type = "OK" or "cut" --> calls AddCut(id)
843 
844  type.ToUpper();
845  if (type == "ID") AddIdentifier(id);
846  else if (type == "OK" || type == "CUT") AddCut(id);
847  else if (type == "INFO") AddInfo(id);
848 }
849 
850 
851 
852 
857 
859 {
860  // Create and add the object to the list of cuts or identifiers:
861  // type = "ID" --> calls AddIdentifier(id)
862  // type = "OK" or "cut" --> calls AddCut(id)
863 
864  type.ToUpper();
865  KVIDentifier* id = New(classname);
866  if (!id) return 0;
867  if (type == "ID") AddIdentifier(id);
868  else if (type == "OK" || type == "CUT") AddCut(id);
869  else if (type == "INFO") AddInfo(id);
870  return id;
871 }
872 
873 
874 
875 
887 
889 {
890  //Draw all objects in graph on the current display, if one exists: i.e. in order to superimpose the grid
891  //on a 2D display of data, use KVIDGraph::Draw() (no option "same" needed).
892  //
893  //If no TCanvas exists, or if one exists but it is empty, a frame large enough to display all
894  //the objects in the graph will be generated.
895  //
896  //The title of the canvas is set to the name of the graph
897  //
898  //If the graph is already displayed (i.e. if fPad!=0), we call UnDraw() in order to remove it from the display.
899  //This is so that double-clicking a graph in the IDGridManagerGUI list makes it disappear if it is already drawn.
900 
901  if (fPad) { /* graph already displayed. undraw it! */
902  UnDraw();
903  return;
904  }
905 
906  if (!gPad) {
907  fPad = new TCanvas("c1", GetName());
908  }
909  else {
910  fPad = (TPad*)gPad;
911  gPad->SetTitle(GetName());
912  }
913  if (!gPad->GetListOfPrimitives()->GetSize()) {
914  //calculate size of pad necessary to show graph
915  if (GetXmin() == GetXmax())
916  const_cast < KVIDGraph* >(this)->FindAxisLimits();
917  gPad->DrawFrame(GetXmin(), GetYmin(), GetXmax(), GetYmax());
918  }
919  {
920  fIdentifiers.R__FOR_EACH(KVIDentifier, Draw)("PL");
921  }
922  {
923  fCuts.R__FOR_EACH(KVIDentifier, Draw)("PL");
924  }
925  {
926  fInfoZones.R__FOR_EACH(KVIDentifier, Draw)("PL");
927  }
928  gPad->Modified();
929  gPad->Update();
930  // connect canvas' Closed() signal to KVIDGraph::ResetPad so that if the
931  // canvas GUI is closed (thereby deleting the fPad object), we reset fPad
932  // and do not try to Undraw in a non-existent canvas
933 // fPad->Connect("Closed()", "KVIDGraph", this, "ResetPad()");
934 // if (fPad->GetCanvas()) fPad->GetCanvas()->Connect("Cleared(TVirtualPad*)", "KVIDGraph", this, "ClearPad(TVirtualPad*)");
935 }
936 
937 
938 
939 
965 
967 {
968  //Make the graph disappear from the current canvas/pad
969  //In case any objects have (accidentally) been drawn more than once, we keep calling
970  //gPad->GetListOfPrimitives()->Remove() as long as gPad->GetListOfPrimitives()->FindObject()
971  //returns kTRUE for each identifier.
972 
973 // if (!fPad) {
974 // Error("UnDraw", "Cannot undraw, no pad stored ??");
975 // return;
976 // }
977 // TIter next_id(fIdentifiers);
978 // KVIDentifier* line;
979 // //remove the rest of the lines
980 // while ((line = (KVIDentifier*) next_id())) {
981 // while (fPad->GetListOfPrimitives()->FindObject(line))
982 // fPad->GetListOfPrimitives()->Remove(line);
983 // }
984 // TIter next_ok(fCuts);
985 // while ((line = (KVIDentifier*) next_ok())) {
986 // while (fPad->GetListOfPrimitives()->FindObject(line))
987 // fPad->GetListOfPrimitives()->Remove(line);
988 // }
989 // fPad->Modified();
990 // fPad->Update();
991 // fPad->Disconnect("Closed()", this, "ResetPad()");
992 // if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect("Cleared(TVirtualPad*)", this, "ClearPad(TVirtualPad*)");
993  fPad = 0;
994 }
995 
996 
997 
998 
1002 
1004 {
1005  // In case the graph can no longer be drawn/undrawn (because fPad contains address of a canvas
1006  // which died unexpectedly), use this method to reset fPad=0 and hopefully start afresh.
1007  fPad = 0;
1008 }
1009 
1010 
1011 
1016 
1018 {
1019  // Extend the first segment of each identification line back to new coordinate newX
1020  //
1021  // See KVIDentifier::ExtendLine()
1022 
1023  fIdentifiers.R__FOR_EACH(KVIDentifier, ExtendLine)(true, newX, Direction);
1024 }
1025 
1026 
1027 
1032 
1034 {
1035  // Extend the last segment of each identification line to new coordinate newX
1036  //
1037  // See KVIDentifier::ExtendLine()
1038  fIdentifiers.R__FOR_EACH(KVIDentifier, ExtendLine)(false, newX, Direction);
1039 }
1040 
1041 
1042 
1043 
1046 
1048 {
1049  //Print out all objects in graph
1050 
1051  cout << ClassName() << " : " << GetName() << endl;
1052  cout << "Title : " << GetTitle() << endl;
1053  //print list of parameters
1054  fPar.Print();
1055  KVIDentifier* line = 0;
1056  TIter nextOK(&fCuts);
1057  while ((line = (KVIDentifier*) nextOK()))
1058  line->ls();
1059  TIter nextID(&fIdentifiers);
1060  while ((line = (KVIDentifier*) nextID()))
1061  line->ls();
1062  TIter nextInfo(&fInfoZones);
1063  while ((line = (KVIDentifier*) nextInfo()))
1064  line->ls();
1065 }
1066 
1067 
1068 
1069 
1072 
1074 {
1075  //Calculate X/Y min/max of all objects in graph
1076 
1077  KVIDentifier* line;
1078  Double_t x, y, xmin, ymin, xmax, ymax;
1079  xmax = ymax = -999999;
1080  xmin = ymin = 999999;
1081  TIter nextOK(&fCuts);
1082  while ((line = (KVIDentifier*) nextOK())) {
1083  for (int i = 0; i < line->GetN(); i++) {
1084  line->GetPoint(i, x, y);
1085  xmin = (x < xmin ? x : xmin);
1086  xmax = (x > xmax ? x : xmax);
1087  ymin = (y < ymin ? y : ymin);
1088  ymax = (y > ymax ? y : ymax);
1089  }
1090  }
1091  TIter nextID(&fIdentifiers);
1092  while ((line = (KVIDentifier*) nextID())) {
1093  for (int i = 0; i < line->GetN(); i++) {
1094  line->GetPoint(i, x, y);
1095  xmin = (x < xmin ? x : xmin);
1096  xmax = (x > xmax ? x : xmax);
1097  ymin = (y < ymin ? y : ymin);
1098  ymax = (y > ymax ? y : ymax);
1099  }
1100  }
1101  fXmin = xmin;
1102  fYmin = ymin;
1103  fXmax = xmax;
1104  fYmax = ymax;
1105  // Info("FindAxisLimits()", "Xmin=%f Ymin=%f Xmax=%f Ymax=%f", GetXmin(), GetYmin(), GetXmax(), GetYmax());
1106 }
1107 
1108 
1109 
1110 
1117 
1118 void KVIDGraph::Scale(TF1* sx, TF1* sy)
1119 {
1120  // Rescale coordinates of every object in graph according to arbitrary functions
1121  // of the coordinates (sx & sy can be 1-dimensional or 2-dimensional functions).
1122  //
1123  // If sy is a TF1 function f(x), then the 'x' in this function refers to the y-coordinate.
1124  // If sy is a TF2 function f(x,y), 'x' and 'y' refer to the x & y-coordinates.
1125 
1126  if (!sx && !sy)
1127  return;
1128  if (GetNumberOfIdentifiers() > 0) {
1129  fIdentifiers.R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1130  }
1131  if (GetNumberOfCuts() > 0) {
1132  fCuts.R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1133  }
1134  if (GetNumberOfInfos() > 0) {
1135  fInfoZones.R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1136  }
1137  Modified();
1138 }
1139 
1140 
1141 
1142 
1145 
1147 {
1148  // Called by SetX/YScaleFactor methods to rescale every point of every object in the grid
1149 
1150  if (TMath::Abs(sx) == 1 && TMath::Abs(sy) == 1)
1151  return;
1152  if (GetNumberOfIdentifiers() > 0) {
1153  fIdentifiers.R__FOR_EACH(KVIDentifier, ScaleXY)(sx, sy);
1154  }
1155  if (GetNumberOfCuts() > 0) {
1156  fCuts.R__FOR_EACH(KVIDentifier, ScaleXY)(sx, sy);
1157  }
1158  if (GetNumberOfInfos() > 0) {
1159  fInfoZones.R__FOR_EACH(KVIDentifier, ScaleXY)(sx, sy);
1160  }
1161 }
1162 
1163 
1164 
1165 
1175 
1176 void KVIDGraph::DrawAndAdd(const Char_t* Type, const Char_t* Classname)
1177 {
1178  //Use this method to add objects to a grid which is drawn in the current pad gPad.
1179  //
1180  //We wait for the user to draw the line with the graphical editor
1181  //(we put the pad automatically into this mode,
1182  //there is no need to use the Editor toolbar).
1183  //
1184  //Then we retrieve this TGraph, create a new KVIDentifier-derived object of
1185  //class "classname", and add it to the "type" list (= "OK"/"cut" or "ID").
1186 
1187  if (!fPad && !gPad) return;
1188  // if grid already drawn somewhere, make grid's pad active
1189  if (fPad && fPad != gPad) {
1190  fPad->cd();
1191  KVBase b;
1192  b.Warning("DrawAndAdd", "Changed active pad to pad containing this graph");
1193  }
1194  if (!fPad) fPad = gPad;
1195 
1196  TString type(Type);
1197  TString classname(Classname);
1198  //create new ID line
1199  KVIDentifier* line = New(classname);
1200  //wait for user to draw object
1201  line->WaitForPrimitive();
1203  //add line to list
1204  Add(type, line);
1205  Modified();
1206 }
1207 
1208 
1209 
1210 
1211 
1212 
1224 
1226  KVIDGraph* g2, Int_t id2_min, Int_t id2_max)
1227 {
1228  //Static method taking lines id1_min to id2_min from grid g1 and lines id2_min to id2_max from
1229  //grid g2 and making a new grid containing them. Returns the pointer to the new grid.
1230  //
1231  //It is assumed that g1 and g2 are grids of the same class. The new grid will be an object of the
1232  //same class as g1.
1233  //
1234  //Any scaling factors are applied to the line coordinates as they are copied from their parent grids.
1235  //As scaling may be different in g1 and g2, the resulting grid has no scaling factor, but the coordinates
1236  //of all its lines result from application of the different scaling factors of the two grids.
1237 
1238  //make new grid
1239  KVIDGraph* merger = (KVIDGraph*) g1->IsA()->New();
1240 
1241  //loop over lines in first grid
1242  TIter next_id1(g1->GetIdentifiers());
1243  KVIDentifier* line;
1244  while ((line = (KVIDentifier*) next_id1())) {
1245  if (line->GetID() >= id1_min && line->GetID() <= id1_max)
1246  merger->Add("ID", (KVIDentifier*) line->Clone()); //add clone of lines with right ID
1247  }
1248 
1249  //loop over lines in second grid
1250  TIter next_id2(g2->GetIdentifiers());
1251  while ((line = (KVIDentifier*) next_id2())) {
1252  if (line->GetID() >= id2_min && line->GetID() <= id2_max)
1253  merger->Add("ID", (KVIDentifier*) line->Clone());
1254  }
1255 
1256  //just in case any of the lines were highlighted...
1257  merger->SetLineColor(kBlack);
1258 
1259  return merger;
1260 }
1261 
1262 
1263 
1264 
1274 
1276 {
1277  // Default method for deciding if point (x,y) corresponds to an identifiable
1278  // particle or not: we loop over the list of cuts and test the
1279  // point with the method TestPoint(x,y).
1280  //
1281  // If the point is accepted by all cuts, then (x,y) is identifiable (return kTRUE).
1282  //
1283  // If the point is rejected by a cut we return kFALSE.
1284  // If rejected_by contains a valid pointer, we set it to the name of the rejecting cut.
1285 
1286  TIter next(&fCuts);
1287  KVIDentifier* id = 0;
1288  if (rejected_by) *rejected_by = "";
1289  while ((id = (KVIDentifier*)next())) {
1290  if (!id->TestPoint(x, y)) {
1291  if (rejected_by) *rejected_by = id->GetName();
1292  return kFALSE;
1293  }
1294  }
1295  return kTRUE;
1296 }
1297 
1298 
1299 
1302 
1304 {
1305  // loop over KVIDGraph::fInfoZones to set flags in KVIdentificationResult
1306 
1307  TIter next(&fInfoZones);
1308  KVIDentifier* id = 0;
1309  while ((id = (KVIDentifier*)next())) {
1310  if (id->TestPoint(x, y)) {
1311  idr->AddFlag(GetName(), id->GetName());
1312  }
1313  }
1314 }
1315 
1316 
1317 
1318 
1321 
1323 {
1324  // Set list of runs for which grid is valid
1325  fRunList = runs;
1326  fPar.SetValue("Runlist", fRunList.AsString());
1327  Modified();
1328 }
1329 
1330 
1331 
1332 
1337 
1339 {
1340  // If name of grid is not set explicitly with SetName(const Char_t*),
1341  // we return the name of the first ID telescope in the list of telescopes
1342  // with which this grid is associated.
1343 
1344  if (fName != "") return fName;
1345  fDyName = "";
1346  if (fTelescopes.At(0)) fDyName = fTelescopes.At(0)->GetName();
1347  else {
1348  if (fPar.HasParameter("IDTelescopes")) {
1349  KVString tel_list = fPar.GetStringValue("IDTelescopes");
1350  tel_list.Begin(",");
1351  fDyName = tel_list.Next();
1352  }
1353  }
1354  return fDyName;
1355 }
1356 
1357 
1358 
1359 
1366 
1368 {
1369  // Called after reading a grid from an ascii file.
1370  // Tries to convert information written by an old version of the class:
1371  //
1372  //<PARAMETER> First run=... ----> <PARAMETER> Runlist=...
1373  //<PARAMETER> Last run=...
1374 
1375  if (fPar.HasParameter("Runlist")) return;
1376  if (fPar.HasParameter("First run") && fPar.HasParameter("Last run")) {
1377  fRunList.SetMinMax(fPar.GetIntValue("First run"), fPar.GetIntValue("Last run"));
1378  fPar.SetValue("Runlist", fRunList.AsString());
1379  fPar.RemoveParameter("First run");
1380  fPar.RemoveParameter("Last run");
1381  }
1382 }
1383 
1384 
1392 
1394 {
1395  // ecriture des grilles avec version suivant un modele de fichier (fPattern)
1396  // fPattern_v%d.grid
1397  // le modele doit etre initialiser par la methode SetPattern(TString)
1398  // la valeur par default version=-1 permet l ecriture de la derniere version
1399  // apres un check des versions existantes (methode CheckVersion)
1400  // la premiere version est indexee v0
1401  Int_t vv = 0;
1402  if (version == -1) vv = CheckVersion(version) + 1;
1403  WriteAsciiFile(fPattern + "_v" + Form("%d", vv) + ".grid");
1404 }
1405 
1406 
1409 
1411 {
1412  // lecture des grilles avec version suivant un modele de fichier
1413  Int_t vv = CheckVersion(version);
1414  if (vv == -1) {
1415  if (version == -1) cout << "no file " + fPattern + "_v%d.grid" << endl;
1416  else cout << "no file " + fPattern + Form("_v%d.grid", version) << endl;
1417  }
1418  else ReadAsciiFile(fPattern + "_v" + Form("%d", vv) + ".grid");
1419 }
1420 
1421 
1428 
1430 {
1431  // version>=0 check si la version demandee du fichier grille existe
1432  // version-1 renvoie la derniere version existante
1433  // si la version demandee n existe pas return -1
1434  // creation d un fichier tampon dans le repertoire ou se situe les fichiers grilles
1435  // efface a la fin de la methode
1436  Int_t temoin = -1;
1437  TString pbis = fPattern, chemin = "";
1438  TObjArray* tok = NULL;
1439  if (fPattern.Contains("/")) { // prise en compte de fPattern contenant un chemin pour les fichiers
1440  tok = fPattern.Tokenize("/");
1441  Int_t nb = tok->GetEntries();
1442  pbis = ((TObjString*)(*tok)[nb - 1])->GetString();
1443  chemin = "";
1444  for (Int_t ii = 0; ii < nb - 1; ii += 1) chemin += ((TObjString*)(*tok)[ii])->GetString();
1445  chemin += "/";
1446  }
1447  gROOT->ProcessLine(".! ls " + fPattern + "_v*.grid >> " + chemin + "listKVIDGraph_" + pbis);
1448  ifstream f_in(chemin + "listKVIDGraph_" + pbis);
1449  TString line = "";
1450  Int_t num = -2;
1451  while (f_in.good() && num != version) {
1452  line.ReadLine(f_in);
1453  if (line.Contains(fPattern + "_v") && line.Contains(".grid")) {
1454  tok = line.Tokenize(".");
1455  line = ((TObjString*)(*tok)[0])->GetString();
1456  line.ReplaceAll(fPattern + "_v", "template");
1457  tok = line.Tokenize("template");
1458  num = ((TObjString*)(*tok)[0])->GetString().Atoi();
1459  if (num > temoin) temoin = num;
1460  }
1461  }
1462  f_in.close();
1463  gROOT->ProcessLine(".! rm -f " + chemin + "listKVIDGraph_" + pbis);
1464  delete tok;
1465  if (version == -1) return temoin;
1466  else if (temoin != version) {
1467  return -1;
1468  }
1469  else return temoin;
1470 }
1471 
1472 
1473 
1474 
1478 
1480 {
1481  // Set mass formula for all identifiers if graph has OnlyZId()=kTRUE.
1482  // This will change the mass (A) of each identifier.
1483 
1484  fMassFormula = mass;
1485  if (IsOnlyZId()) {
1486  if (GetNumberOfIdentifiers() > 0) {
1487  fIdentifiers.R__FOR_EACH(KVIDentifier, SetMassFormula)(mass);
1488  }
1489  }
1490  Modified();
1491 }
1492 
1493 
1494 
1495 
1501 
1503 {
1504  // Use this method if the graph is only to be used for Z identification
1505  // (no isotopic information). Default is to identify both Z & A
1506  // (fOnlyZid = kFALSE). Note that setting fOnlyZid=kTRUE changes the way line
1507  // widths are calculated (see KVIDGrid::CalculateLineWidths)
1508  fOnlyZId = yes;
1509  if (GetNumberOfIdentifiers() > 0) {
1510  fIdentifiers.R__FOR_EACH(KVIDentifier, SetOnlyZId)(yes);
1511  }
1512  Modified();
1513 }
1514 
1515 
1516 
1517 
1518 
1521 
1523 {
1524  // Associate this graph with all ID telescopes in list
1525 
1526  TIter next(tels);
1527  KVBase* tel;
1528  while ((tel = (KVBase*)next())) AddIDTelescope(tel);
1529  Modified();
1530  if (gIDGridManager) gIDGridManager->Modified();
1531 }
1532 
1533 
1534 
1535 //void KVIDGraph::SetIDTelescopes()
1536 //{
1537 // // Opens dialog box to view and/or choose ID telescopes associated with this
1538 // // identification graph
1539 
1540 // Bool_t cancel;
1541 // TString old_label = GetIDTelescopeLabel();
1542 // new KVIDGUITelescopeChooserDialog(gMultiDetArray, &fTelescopes, &cancel,
1543 // gClient->GetRoot(), gClient->GetRoot());
1544 // if(!cancel){
1545 // // if type of associated id telescope has changed, we need to
1546 // // update the grid manager and associated gui (grid will appear
1547 // // on a different tab).
1548 // if(old_label != GetIDTelescopeLabel()) gIDGridManager->Modified();
1549 // else // same type; just the grid changes
1550 // Modified();
1551 // }
1552 //}
1553 
1554 
1555 
1561 
1563 {
1564  // Static function which will create and 'Build' the identification graph of
1565  // class 'class_name', one of the plugins defined in either $KVROOT/KVFiles/.kvrootrc,
1566  // or in the user's .kvrootrc file.
1567 
1568  //check and load plugin library
1569  TPluginHandler* ph;
1570  if (!(ph = KVBase::LoadPlugin("KVIDGraph", class_name)))
1571  return 0;
1572 
1573  //execute constructor/macro for graph - assumed without arguments
1574  KVIDGraph* gr = (KVIDGraph*) ph->ExecPlugin(0);
1575  return gr;
1576 }
1577 
1578 
1579 
1580 
1587 
1589 {
1590  // Toggles 'editable' status of all lines/contours in graph
1591  // If editable = kTRUE this makes it possible to modify the graph
1592  // we then take a snapshot of the graph before editing begins
1593  // and store it in fLastSavedVersion. we can always revert to
1594  // this version if we want
1595 
1596  if (editable && !GetEditable()) UpdateLastSavedVersion();
1597 
1598  TCutG::SetEditable(editable);
1599  if (GetNumberOfIdentifiers() > 0) {
1600  fIdentifiers.R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1601  }
1602  if (GetNumberOfCuts() > 0) {
1603  fCuts.R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1604  }
1605  if (GetNumberOfInfos() > 0) {
1606  fInfoZones.R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1607  }
1608 }
1609 
1610 
1611 
1612 
1616 
1618 {
1619  // Returns a comma-separated list of the names of all ID telescopes for which
1620  // this grid is valid.
1621 
1622  static TString tel_list;
1623  if (!fTelescopes.GetEntries()) {
1624  // case of grid with "unknown" ID telescopes
1625  // we return the value of the IDTelescopes parameter (if defined)
1626  if (fPar.HasParameter("IDTelescopes")) {
1627  tel_list = fPar.GetStringValue("IDTelescopes");
1628  return tel_list.Data();
1629  }
1630  }
1631  TIter next(&fTelescopes);
1632  TObject* id = next();
1633  if (id) tel_list = id->GetName();
1634  while ((id = next())) tel_list += Form(",%s", id->GetName());
1635  return tel_list;
1636 }
1637 
1638 
1639 
1642 
1644 {
1645  // Set value of "IDTelescopes" parameter with comma-separated list of ID telescope names
1646  fPar.SetValue("IDTelescopes", idt_names);
1647 }
1648 
1649 
1650 
1651 
1655 
1656 void KVIDGraph::Streamer(TBuffer& R__b)
1657 {
1658  // Stream an object of class KVIDGraph.
1659  // Resets the 'fParent' pointer of each KVIDentifier after reading them in.
1660 
1661  if (R__b.IsReading()) {
1662  R__b.ReadClassBuffer(KVIDGraph::Class(), this);
1663  TIter nxt_id(&fIdentifiers);
1664  KVIDentifier* id;
1665  while ((id = (KVIDentifier*)nxt_id())) id->fParent = this;
1666  TIter nxt_cut(&fCuts);
1667  while ((id = (KVIDentifier*)nxt_cut())) id->fParent = this;
1668  TIter nxt_info(&fInfoZones);
1669  while ((id = (KVIDentifier*)nxt_info())) id->fParent = this;
1670  }
1671  else {
1672  R__b.WriteClassBuffer(KVIDGraph::Class(), this);
1673  }
1674 }
1675 
1676 
1677 
1679 
1683 
1685  : histos(h), histo_names(n)
1686  {}
1687  void fill(const char* name, double x, double y = 0., double w = 0.)
1688  {
1690  if (h) {
1691  if (w > 0)((TH2*)h)->Fill(x, y, w);
1692  else h->Fill(x, y);
1693  }
1694  }
1695 };
1696 
1697 
1698 
1723 
1725 {
1726  //This method allows to test the identification capabilities of the grid using data in a TH2F.
1727  //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1728  //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1729  //IsIdentifiable() returns kTRUE) and fill the histograms with the results of the identification
1730  //
1731  //The "identification" or PID we represent is the result of the KVReconstructedNucleus::GetPID()
1732  //method for the identified nucleus.
1733  //
1734  // The KVHashList contains histograms to be filled with results
1735  // The KVNameValueList histo_names contains the name of each histogram passed in the KVHashList
1736  // i.e. it may have any of the following parameters
1737  //
1738  // "ID_REAL"="[name of histo to fill with PID spectrum]"
1739  // "ID_REAL_AIDENT"="[name of histo to fill with PID spectrum]" Z&A identification
1740  // "ID_REAL_ZIDENT"="[name of histo to fill with PID spectrum]" Only Z identification
1741  // "ID_REAL_VS_ERES" - PID vs. Eres (X) histo
1742  // "ID_REAL_VS_DE" - PID vs. DeltaE (Y) histo
1743  // "ID_REAL_VS_ERES_AIDENT" - PID vs. Eres histo, Z&A identification
1744  // "ID_REAL_VS_ERES_ZIDENT" - PID vs. Eres histo, only Z identification
1745  // - only for isotopic identificiation:
1746  // "Z_A_REAL" - 2D map (nuclear chart)
1747  // "ZADIST_AIDENT" - integer A vs. integer Z distribution for isotopically-identified particles
1748 
1749  //Initialize the grid: calculate line widths etc.
1750  Initialize();
1751 
1752  kvidgraph_idresult_filler idresults(histos, histo_names);
1753 
1754  // reset contents of all histos
1755  histos.Execute("Reset", "");
1756 
1757  Int_t tot_events = (Int_t) data->GetSum();
1758  Int_t events_read = 0;
1759  Int_t percent = 0, cumul = 0;
1760 
1762 
1763  for (int i = 1; i <= data->GetNbinsX(); ++i) {
1764  for (int j = 1; j <= data->GetNbinsY(); j++) {
1765 
1766  Stat_t poids = data->GetBinContent(i, j);
1767  if (poids == 0)
1768  continue;
1769 
1770  Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1771  Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1772  Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1773  Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1774  //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1775  //randomly-drawn x and y coordinates inside this bin
1776  //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1777  //a weight poids/20
1778  Int_t kmax = (Int_t) TMath::Min(20., poids);
1779  Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1780  for (int k = 0; k < kmax; k++) {
1781  double x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1782  double y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1783  if (IsIdentifiable(x, y)) {
1784  idr.Clear();
1785  Identify(x, y, &idr);
1786  if (AcceptIDForTest(idr)) {
1787  Float_t PID = idr.PID;
1788  if (idr.Aident) PID = (idr.Z + 0.1 * (idr.PID - 2. * idr.Z));
1789  Float_t RealA, RealZ;
1790  RealA = (idr.Aident ? idr.PID : (Float_t)idr.A);
1791  RealZ = (idr.Aident ? (Float_t)idr.Z : idr.PID);
1792  idresults.fill("ID_REAL", PID, weight);
1793  idresults.fill("ID_REAL_VS_DE", y, PID, weight);
1794  idresults.fill("ID_REAL_VS_ERES", x, PID, weight);
1795  if (idr.Aident) {
1796  idresults.fill("Z_A_REAL", RealA - RealZ, gRandom->Gaus(RealZ, 0.15), weight);
1797  idresults.fill("ZADIST_AIDENT", idr.Z, idr.A, weight);
1798  idresults.fill("ID_REAL_AIDENT", PID, weight);
1799  idresults.fill("ID_REAL_VS_DE_AIDENT", y, PID, weight);
1800  idresults.fill("ID_REAL_VS_ERES_AIDENT", x, PID, weight);
1801  }
1802  else if (idr.Zident) {
1803  idresults.fill("ID_REAL_ZIDENT", PID, weight);
1804  idresults.fill("ID_REAL_VS_DE_ZIDENT", y, PID, weight);
1805  idresults.fill("ID_REAL_VS_ERES_ZIDENT", x, PID, weight);
1806  }
1807  }
1808  }
1809  }
1810  events_read += (Int_t) poids;
1811  percent = (1. * events_read / tot_events) * 100.;
1812  if (percent > cumul) {
1813  Increment((Float_t) events_read); //sends signal to GUI progress bar
1815  cumul = percent;
1816  }
1817 
1818  }
1819  }
1820 }
1821 
1822 
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 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 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:139
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:796
Extended version of ROOT THashList.
Definition: KVHashList.h:29
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:32
KVNumberList fRunList
runs for which grid is valid
Definition: KVIDGraph.h:49
void Add(TString, KVIDentifier *)
Definition: KVIDGraph.cpp:838
Axis_t GetYmax() const
Definition: KVIDGraph.h:423
void SetName(const char *name) override
Definition: KVIDGraph.h:166
Double_t GetYScaleFactor()
Definition: KVIDGraph.cpp:292
TString fDyName
dynamically generated name
Definition: KVIDGraph.h:51
void Draw(Option_t *opt="") override
Definition: KVIDGraph.cpp:888
virtual void ReadAsciiFile_WP(Int_t version=-1)
lecture des grilles avec version suivant un modele de fichier
Definition: KVIDGraph.cpp:1410
KVIDGraph * fLastSavedVersion
copy of last save version of grid, used for 'undo'
Definition: KVIDGraph.h:54
Int_t GetNumberOfCuts() const
Definition: KVIDGraph.h:358
void ExtendBeginningAllIdentLines(Double_t, Option_t *="")
Definition: KVIDGraph.cpp:1017
KVNameValueList fPar
parameters associated to grid
Definition: KVIDGraph.h:45
void ReadAsciiFile(const Char_t *filename)
Definition: KVIDGraph.cpp:778
void RemoveIdentifier(KVIDentifier *)
Remove and destroy identifier.
Definition: KVIDGraph.cpp:335
Double_t GetXScaleFactor()
Definition: KVIDGraph.cpp:274
void Clear(Option_t *opt="") override
Definition: KVIDGraph.cpp:203
virtual void TestIdentification(TH2F *data, KVHashList &histos, KVNameValueList &histo_names)
Definition: KVIDGraph.cpp:1724
KVList fCuts
cuts used to define area in which identification is possible
Definition: KVIDGraph.h:41
void SetNamesOfIDTelescopes(const TString &)
Set value of "IDTelescopes" parameter with comma-separated list of ID telescope names.
Definition: KVIDGraph.cpp:1643
KVList fIdentifiers
list of identification objects
Definition: KVIDGraph.h:40
Double_t fLastScaleY
last applied scaling factor on Y
Definition: KVIDGraph.h:47
void SetVarY(const char *v) override
Definition: KVIDGraph.h:556
Double_t fLastScaleX
last applied scaling factor on X
Definition: KVIDGraph.h:46
void SetEditable(Bool_t editable=kTRUE) override
Definition: KVIDGraph.cpp:1588
void UpdateLastSavedVersion()
update last saved version. mkae copy of current state of graph.
Definition: KVIDGraph.cpp:534
Axis_t GetXmax() const
Definition: KVIDGraph.h:419
void ExtendEndAllIdentLines(Double_t, Option_t *="")
Definition: KVIDGraph.cpp:1033
void RemoveInfo(KVIDentifier *)
Remove and destroy cut.
Definition: KVIDGraph.cpp:363
virtual void WriteToAsciiFile(std::ofstream &gridfile)
Definition: KVIDGraph.cpp:442
static void SetAutoAdd(Bool_t yes=kTRUE)
Definition: KVIDGraph.h:125
void init()
Definition: KVIDGraph.cpp:67
virtual void AddInfo(KVIDentifier *info)
Definition: KVIDGraph.h:390
void Increment(Float_t x)
Definition: KVIDGraph.h:275
void AddIDTelescope(KVBase *t)
Definition: KVIDGraph.h:433
Int_t GetNumberOfIdentifiers() const
Definition: KVIDGraph.h:354
virtual void ReadIdentifierFromAsciiFile(TString &name, TString &type, TString &cl, std::ifstream &gridfile)
Read in new identifier object from file.
Definition: KVIDGraph.cpp:754
Axis_t fXmin
Definition: KVIDGraph.h:43
Bool_t IsOnlyZId() const
Definition: KVIDGraph.h:57
void Scale(TF1 *sx, TF1 *sy)
Definition: KVIDGraph.cpp:1118
Int_t GetMassFormula() const
Definition: KVIDGraph.h:464
void MakeBestGuessForNewIDLineZandA(KVIDentifier *idline)
Definition: KVIDGraph.h:72
void RevertToLastSavedVersion()
Definition: KVIDGraph.cpp:555
void UnDraw()
Definition: KVIDGraph.cpp:966
void SetVarX(const char *v) override
Definition: KVIDGraph.h:552
virtual void ReadFromAsciiFile(std::ifstream &gridfile)
Definition: KVIDGraph.cpp:601
void ClearPad(TVirtualPad *)
Definition: KVIDGraph.cpp:49
void WriteParameterListOfIDTelescopes()
Definition: KVIDGraph.cpp:382
virtual void Identify(Double_t, Double_t, KVIdentificationResult *) const =0
TString fPattern
pattern of filenames used to write or read grid
Definition: KVIDGraph.h:52
const Char_t * GetName() const override
Definition: KVIDGraph.cpp:1338
virtual void WriteAsciiFile_WP(Int_t version=-1)
Definition: KVIDGraph.cpp:1393
KVIDentifier * GetIdentifier(Int_t Z, Int_t A) const
Definition: KVIDGraph.cpp:310
virtual ~KVIDGraph()
Definition: KVIDGraph.cpp:188
virtual Bool_t IsIdentifiable(Double_t, Double_t, TString *rejected_by=nullptr) const
Definition: KVIDGraph.cpp:1275
void FindAxisLimits()
Calculate X/Y min/max of all objects in graph.
Definition: KVIDGraph.cpp:1073
Axis_t GetYmin() const
Definition: KVIDGraph.h:415
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:1225
virtual void DrawAndAdd(const Char_t *type="ID", const Char_t *classname="KVIDentifier")
Definition: KVIDGraph.cpp:1176
virtual void AddCut(KVIDentifier *cut)
Definition: KVIDGraph.h:379
void SetMassFormula(Int_t)
Definition: KVIDGraph.cpp:1479
TList fTelescopes
ID telescopes for which grid is valid.
Definition: KVIDGraph.h:50
static Bool_t fAutoAddGridManager
if =kTRUE, grids are automatically added to ID grid manager on creation (default)
Definition: KVIDGraph.h:55
void WriteAsciiFile(const Char_t *filename)
Open, write and close ascii file containing this grid.
Definition: KVIDGraph.cpp:404
virtual KVIDentifier * New(const Char_t *)
Create new object of class "id_class" which derives from KVIDentifier.
Definition: KVIDGraph.cpp:807
virtual void BackwardsCompatibilityFix()
Definition: KVIDGraph.cpp:1367
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
Definition: KVIDGraph.cpp:1522
virtual void AddIdentifier(KVIDentifier *id)
Definition: KVIDGraph.h:366
virtual void SetInfos(Double_t, Double_t, KVIdentificationResult *) const
loop over KVIDGraph::fInfoZones to set flags in KVIdentificationResult
Definition: KVIDGraph.cpp:1303
static KVIDGraph * MakeIDGraph(const Char_t *)
Definition: KVIDGraph.cpp:1562
void SetLineColor(Color_t lcolor) override
Definition: KVIDGraph.h:213
const Char_t * GetNamesOfIDTelescopes() const
Definition: KVIDGraph.cpp:1617
Axis_t GetXmin() const
Definition: KVIDGraph.h:411
void SetXScaleFactor(Double_t=0)
Definition: KVIDGraph.cpp:226
Int_t GetNumberOfInfos() const
Definition: KVIDGraph.h:362
TVirtualPad * fPad
pad in which graph is drawn
Definition: KVIDGraph.h:48
virtual Bool_t AcceptIDForTest(const KVIdentificationResult &idr)
Definition: KVIDGraph.h:100
Axis_t fYmax
min/max Y coordinates of graph
Definition: KVIDGraph.h:44
void SetRuns(const KVNumberList &nl)
Set list of runs for which grid is valid.
Definition: KVIDGraph.cpp:1322
virtual Int_t CheckVersion(Int_t version)
Definition: KVIDGraph.cpp:1429
void SetYScaleFactor(Double_t=0)
Definition: KVIDGraph.cpp:250
virtual void Initialize()=0
Axis_t fXmax
min/max X coordinates of graph
Definition: KVIDGraph.h:43
Bool_t fOnlyZId
set to kTRUE when only to be used to give Z identification of nuclei, no mass info
Definition: KVIDGraph.h:39
Int_t fMassFormula
OPTION={GetMethod="GetMassFormula";SetMethod="SetMassFormula";Items=(0="Beta-stability",...
Definition: KVIDGraph.h:53
void ResetDraw()
Definition: KVIDGraph.cpp:1003
void SetPattern(TString pattern)
Definition: KVIDGraph.h:261
Axis_t fYmin
Definition: KVIDGraph.h:44
void Copy(TObject &) const override
Copy this to 'obj'.
Definition: KVIDGraph.cpp:115
void RemoveCut(KVIDentifier *)
Remove and destroy cut.
Definition: KVIDGraph.cpp:350
void Print(Option_t *opt="") const override
Print out all objects in graph.
Definition: KVIDGraph.cpp:1047
KVList fInfoZones
contours/lines used to add info to particles (ex: punch-through)
Definition: KVIDGraph.h:42
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1502
void Modified()
Definition: KVIDGraph.h:281
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:1146
const KVList * GetIdentifiers() const
Definition: KVIDGraph.h:324
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
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
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 Error(const char *method, const char *msgfmt,...) 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
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:1687
KVNameValueList & histo_names
Definition: KVIDGraph.cpp:1682
kvidgraph_idresult_filler(KVHashList &h, KVNameValueList &n)
Definition: KVIDGraph.cpp:1684
ClassImp(TPyArg)