KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVIDGraph.cpp
Go to the documentation of this file.
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 = new KVList;
73  fCuts = new KVList;
74  fInfoZones = new KVList;
75  fIdentifiers->SetCleanup();
76  fCuts->SetCleanup();
77  fInfoZones->SetCleanup();
78  fXmin = fYmin = fXmax = fYmax = 0;
79  fPar = new KVNameValueList;
80  fLastScaleX = 1.0;
81  fLastScaleY = 1.0;
82  fOnlyZId = kFALSE;
83  fPad = 0;
84  SetName("");
85  SetEditable(kFALSE);
86  if (fAutoAddGridManager && gIDGridManager) gIDGridManager->AddGrid(this);
87  fMassFormula = 0;
88  fLastSavedVersion = NULL;
89 }
90 
91 
92 
93 // void KVIDGraph::Browse(TBrowser* b)
94 // {
95 // // This method is executed when an object is double-clicked in a browser
96 // // such as the list of grids in KVIDGridManagerGUI
97 // //
98 // // Overrides default TGraph::Browse (which calls Draw()) in order to open
99 // // the grid in the KVIDGridEditor canvas (if one exists).
100 // // If no KVIDGridEditor exists, we perform the default action (Draw()).
101 // //
102 //
103 // if( gIDGridEditor ){
104 // // avant d'editer la grille, on en fait une copie pour
105 // // pouvoir revenir en arriere
106 // UpdateLastSavedVersion();
107 // if(gIDGridEditor->IsClosed()) gIDGridEditor->StartViewer();
108 // gIDGridEditor->SetGrid(this);
109 // }
110 // else
111 // TGraph::Browse(b);
112 // }
113 
114 
115 #if ROOT_VERSION_CODE >= ROOT_VERSION(3,4,0)
116 
119 
120 void KVIDGraph::Copy(TObject& obj) const
121 #else
122 void KVIDGraph::Copy(TObject& obj)
123 #endif
124 {
125  //Copy this to 'obj'
126  TNamed::Copy(obj);
127  TAttLine::Copy((TAttLine&)obj);
128  TAttFill::Copy((TAttFill&)obj);
130  ((TCutG&)obj).SetVarX(GetVarX());
131  ((TCutG&)obj).SetVarY(GetVarY());
132  KVIDGraph& grid = (KVIDGraph&) obj;
133  grid.fOnlyZId = const_cast <KVIDGraph*>(this)->fOnlyZId;
134  grid.SetPattern(fPattern);
135  //as in WriteAsciiFile, we need to remove any scaling factors from the coordinates
136  //before copying the coordinates, then we set the scaling factors at the end
137 
138  //remove scaling if there is one
139  if (fLastScaleX != 1 || fLastScaleY != 1)
140  const_cast < KVIDGraph* >(this)->Scale(1. / fLastScaleX,
141  1. / fLastScaleY);
142 
143  fIdentifiers->Copy((TObject&)(*grid.GetIdentifiers()));
144  fCuts->Copy((TObject&)(*grid.GetCuts()));
145  fInfoZones->Copy((TObject&)(*grid.GetInfos()));
146  // set mass formula of grid (and identifiers)
147  grid.SetMassFormula(GetMassFormula());
148  //copy all parameters EXCEPT scaling parameters
149  KVNamedParameter* par = 0;
150  for (int i = 0; i < fPar->GetNpar(); i++) { //loop over all parameters
151  par = fPar->GetParameter(i);
152  TString parname(par->GetName());
153  if (!parname.Contains("ScaleFactor"))
154  grid.fPar->SetValue(*par);
155  }
156  //restore scaling to this grid if there was one, and apply it to the copied grid
157  if (fLastScaleX != 1 || fLastScaleY != 1) {
158  const_cast < KVIDGraph* >(this)->Scale(fLastScaleX, fLastScaleY);
159  grid.SetXScaleFactor(fLastScaleX);
160  grid.SetYScaleFactor(fLastScaleY);
161  }
162 }
163 
164 
165 
166 KVIDGraph::KVIDGraph() : fRunList(""), fDyName(""), fPattern("")
167 
168 
171 
172 {
173  // Default constructor
174  init();
175 }
176 
177 
178 
179 
182 
183 KVIDGraph::KVIDGraph(const KVIDGraph& grid) : TCutG(), fRunList(""), fDyName(""), fPattern("")
184 {
185  //Copy constructor
186  init();
187 #if ROOT_VERSION_CODE >= ROOT_VERSION(3,4,0)
188  grid.Copy(*this);
189 #else
190  ((KVIDGraph&) grid).Copy(*this);
191 #endif
192 }
193 
194 
195 
198 
200 {
201  // Destructor
202 
203  fIdentifiers->Delete();
204  delete fIdentifiers;
205  fCuts->Delete();
206  delete fCuts;
207  fInfoZones->Delete();
208  delete fInfoZones;
209  delete fPar;
210 }
211 
212 
213 
214 
219 
221 {
222  // reset the grid (destroying any previously defined identifiers) ready to start anew.
223  // resets axis limits
224  // scaling factors (if any) are removed
225 
226  fIdentifiers->Delete();
227  fCuts->Delete();
228  fInfoZones->Delete();
229  fXmin = fYmin = fXmax = fYmax = 0;
230  SetXScaleFactor();
231  SetYScaleFactor();
232  Modified();
233 }
234 
235 
237 
238 
242 
244 {
245  //Set scaling factor for X-axis - rescales all objects with this factor
246  //SetXScaleFactor() or SetXScaleFactor(0) removes scale factor
247  if (s > 0) {
248  fPar->SetValue("XScaleFactor", s);
249  Scale(s / fLastScaleX);
250  fLastScaleX = s;
251  }
252  else {
253  fPar->RemoveParameter("XScaleFactor");
254  Scale(1.0 / fLastScaleX);
255  fLastScaleX = 1.0;
256  }
257 }
258 
259 
261 
262 
266 
268 {
269  //Set scaling factor for Y-axis - rescales all objects with this factor
270  //SetYScaleFactor() or SetYScaleFactor(0) removes scale factor
271  if (s > 0) {
272  fPar->SetValue("YScaleFactor", s);
273  Scale(-1.0, s / fLastScaleY);
274  fLastScaleY = s;
275  }
276  else {
277  fPar->RemoveParameter("YScaleFactor");
278  Scale(-1.0, 1.0 / fLastScaleY);
279  fLastScaleY = 1.0;
280  }
281 }
282 
283 
285 
286 
290 
292 {
293  //Return scaling factor for X-axis
294  //If factor not defined, returns 1
295  Double_t s = fPar->GetDoubleValue("XScaleFactor");
296  if (s > 0)
297  return s;
298  return 1.0;
299 }
300 
301 
303 
304 
308 
310 {
311  //Return scaling factor for Y-axis
312  //If factor not defined, returns 1
313  Double_t s = fPar->GetDoubleValue("YScaleFactor");
314  if (s > 0)
315  return s;
316  return 1.0;
317 }
318 
319 
321 
322 
326 
328 {
329  // Return pointer to identifier with atomic number Z and mass number A.
330  // If this is a 'OnlyZId()' graph we ignore A.
331 
332  KVIDentifier* id = 0;
333  if (!IsOnlyZId()) {
334  unique_ptr<KVSeqCollection> isotopes(fIdentifiers->GetSubListWithMethod(Form("%d", Z), "GetZ"));
335  TIter next(isotopes.get());
336  while ((id = (KVIDentifier*)next())) if (id->GetA() == A) break;
337  }
338  else {
339  TIter next(fIdentifiers);
340  while ((id = (KVIDentifier*)next())) if (id->GetZ() == Z) break;
341  }
342  return id;
343 }
344 
345 
347 
348 
351 
353 {
354  // Remove and destroy identifier
355  fIdentifiers->Remove(id);
356  delete id;
357  Modified();
358 }
359 
360 
362 
363 
366 
368 {
369  // Remove and destroy cut
370  fCuts->Remove(cut);
371  delete cut;
372  Modified();
373 }
374 
375 
376 
379 
381 {
382  // Remove and destroy cut
383  fInfoZones->Remove(info);
384  delete info;
385  Modified();
386 }
387 
388 
390 
391 
398 
400 {
401  // Fill parameter "IDTelescopes" with list of names of telescopes associated
402  // with this grid, ready to write in ascii file
403 
404  // if list of telescope pointers is empty, do nothing
405  // this is in case there are telescope names already in the IDTelescopes parameter
406  // but they are not telescopes in the current multi det array
407  if (!fTelescopes.GetEntries()) return;
408  fPar->SetValue("IDTelescopes", "");
409  KVString tel_list = GetNamesOfIDTelescopes();
410  fPar->SetValue("IDTelescopes", tel_list);
411 }
412 
413 
415 
416 
417 
420 
421 void KVIDGraph::WriteAsciiFile(const Char_t* filename)
422 {
423  //Open, write and close ascii file containing this grid.
424 
425  ofstream gridfile(filename);
426  WriteToAsciiFile(gridfile);
427  gridfile.close();
428 }
429 
430 
431 
432 
458 
459 void KVIDGraph::WriteToAsciiFile(ofstream& gridfile)
460 {
461  //Write info on this grid in already-open ascii file stream 'gridfile'.
462  //This begins with the line
463  //++ClassName
464  //where '"ClassName'" is the name of the class of the actual instance of this object
465  //followed by informations on the grid and its objects.
466  //
467  //The names associated to the X & Y axis of the identification map are written
468  //on lines beginning with
469  //<VARX>
470  //<VARY>
471  //Any associated parameters are written before the objects, starting with
472  //<PARAMETER>
473  //then the name of the parameter and its value
474  //e.e.
475  //<PARAMETER> ChIo pressure=45.5
476  //A single '!' on a line by itself signals the end of the informations for this grid.
477  //
478  //Scaling factors
479  //Any scaling factors are written in the file as
480  //<PARAMETER> XScaleFactor=...
481  //<PARAMETER> YScaleFactor=...
482  //However the coordinates written in the file are the unscaled factors
483  //When the file is read back again, the unscaled coordinates are read in and
484  //then the scaling is applied.
485 
486  gridfile << "# ASCII file generated by " << ClassName() <<
487  "::WriteToAsciiFile" << endl;
488  gridfile << "# ID Graph Name : " << GetName() << endl;
489  gridfile << "# This file can be read using " << ClassName() <<
490  "::ReadFromAsciiFile" << endl;
491  gridfile << "# " << endl;
492  gridfile << "++" << ClassName() << endl;
493 
494  // write name if given
495  if (fName != "") gridfile << "<NAME> " << fName.Data() << endl;
496  //write X & Y axis names
497  gridfile << "<VARX> " << GetVarX() << endl;
498  gridfile << "<VARY> " << GetVarY() << endl;
499  //write parameters
501  KVNamedParameter* par = 0;
502  for (int i = 0; i < fPar->GetNpar(); i++) { //loop over all parameters
503  par = fPar->GetParameter(i);
504  gridfile << "<PARAMETER> " << par->GetName() << "=" << par->GetString() << endl;
505  }
506 
507  //write fOnlyZId & mass formula
508  if (IsOnlyZId()) gridfile << "OnlyZId " << GetMassFormula() << endl;
509 
510  //remove scaling if there is one
511  if (fLastScaleX != 1 || fLastScaleY != 1)
512  Scale(1. / fLastScaleX, 1. / fLastScaleY);
513 
514  //Write identifiers
515  TIter next_IDline(fIdentifiers);
517  while ((line = (KVIDentifier*) next_IDline())) {
518  line->WriteAsciiFile(gridfile, "ID");
519  }
520  //Write cuts
521  TIter next_OKline(fCuts);
522  while ((line = (KVIDentifier*) next_OKline())) {
523  line->WriteAsciiFile(gridfile, "OK");
524  }
525  //Write cuts
526  TIter next_INFOline(fInfoZones);
527  while ((line = (KVIDentifier*) next_INFOline())) {
528  line->WriteAsciiFile(gridfile, "INFO");
529  }
530 // //Write info zones
531 // TIter next_OKline(fInfoZones);
532 // while ((line = (KVIDentifier*) next_OKline())) {
533 // line->WriteAsciiFile(gridfile, "INFO");
534 // }
535  gridfile << "!" << endl;
536 
537  //restore scaling if there is one
538  if (fLastScaleX != 1 || fLastScaleY != 1)
540 
541  // if a back-up copy had previously been created (by starting the editor)
542  // we replace it by the version read from file
544 }
545 
546 
547 
550 
552 {
553  //update last saved version. mkae copy of current state of graph.
554  if (!fLastSavedVersion) {
555  SetAutoAdd(kFALSE); // disable auto add to grid manager - or we'll have every grid appearing twice!
556  fLastSavedVersion = (KVIDGraph*)IsA()->New();
557  SetAutoAdd(); // re-enable auto add
558  }
560 }
561 
562 
563 
569 
571 {
572  // Revert to last saved version of grid
573  // this will destroy any existing lines in the grid and replace them with
574  // copies of the lines as they were at the last moment the grid was saved
575  // If the grid is (was) visible in a pad, we redraw the new lines.
576 
577  if (!fLastSavedVersion) {
578  Info("RevertToLastSavedVersion", "No saved version to revert to! (Sorry)");
579  return;
580  }
581  Bool_t wasDrawn = kFALSE;
582  if (fPad) {
583  // if grid was visible, remove it from pad before modifying (deleting) lines
584  wasDrawn = kTRUE;
585  fPad->cd();// make sure pad with grid is active (gPad) pad
586  UnDraw();
587  }
588  Clear();
589  fLastSavedVersion->Copy(*this);
590  if (wasDrawn) {
591  // if grid was visible, redraw it with new lines
592  Draw();
593  }
594 }
595 
596 
597 
598 
615 
616 void KVIDGraph::ReadFromAsciiFile(ifstream& gridfile)
617 {
618  //Read info from already open ascii file stream containing each line of this grid.
619  //Any previous lines in the grid are destroyed.
620  //Comment lines begin with #
621  //Grid info begins with
622  //++ClassName
623  //where ClassName is actual class name of instance of this object
624  //The names associated to the X & Y axis of the identification map are written
625  //on lines beginning with
626  //<VARX>
627  //<VARY>
628  //Parameter lines begin with <PARAMETER>
629  //New lines begin with +name_of_class
630  //'!' signals end of grid info
631  //Any scaling factors are applied once the coordinates have been read
632 
633  //reset grid - destroy old lines, axis limits...
634  Clear();
635  //clear parameters
636  fPar->Clear();
637 
638  KVString s;
639  int line_no = 0; // counter for lines read
641  Int_t mass_formula = -1;
642 
643  while (gridfile.good()) {
644  //read a line
645  s.ReadLine(gridfile);
646  if (s.BeginsWith('!')) {
647  //end of grid signalled
648  break;
649  }
650  else if (s.BeginsWith("++")) { //will only happen if we are reading a file using ReadAsciiFile(const char*)
651  //check classname
652  s.Remove(0, 2);
653  s.Remove(TString::kBoth, ' '); //remove whitespace
654  if (s != ClassName())
655  Warning("ReadFromAsciiFile(ofstream&)",
656  "Class name in file %s does not correspond to this class (%s)",
657  s.Data(), ClassName());
658  }
659  else if (s.BeginsWith("<NAME>")) {
660  //name of grid
661  s.Remove(0, 7);
662  s.Remove(TString::kBoth, ' '); //remove whitespace
663  SetName(s.Data());
664  }
665  else if (s.BeginsWith("<VARX>")) {
666  //x-axis definition
667  s.Remove(0, 7);
668  s.Remove(TString::kBoth, ' '); //remove whitespace
669  SetVarX(s.Data());
670  }
671  else if (s.BeginsWith("<VARY>")) {
672  //y-axis definition
673  s.Remove(0, 7);
674  s.Remove(TString::kBoth, ' '); //remove whitespace
675  SetVarY(s.Data());
676  }
677  else if (s.BeginsWith("<PARAMETER>")) {
678  //parameter definition
679  s.Remove(0, 11);
680  //split into tokens separated by '='
681  TObjArray* toks = s.Tokenize('=');
682  if (toks->GetEntries() > 1) {
683  TString name =
684  ((TObjString*) toks->At(0))->GetString().
686  KVString value(((TObjString*) toks->At(1))->GetString());
687  value.Remove(TString::kBoth, ' '); //remove whitespace
688  if (name != "" && value != "") {
689  if (value.IsFloat())
690  fPar->SetValue(name.Data(), value.Atof());
691  else if (value.IsDigit())
692  fPar->SetValue(name.Data(), value.Atoi());
693  else
694  fPar->SetValue(name.Data(), value.Data());
695  }
696  }
697  delete toks; //must clean up
698  }
699  else if (s.BeginsWith("<LIST>")) { // number list definition
700  s.Remove(0, 6); // get rid of "<LIST>"
701  //split into tokens separated by '='
702  TObjArray* toks = s.Tokenize('=');
703  if (toks->GetEntries() > 1) {
704  TString name =
705  ((TObjString*) toks->At(0))->GetString().
707  TString list(((TObjString*) toks->At(1))->GetString());
708  //set appropriate list
709  if (name == "Runs")
710  SetRuns(list.Data());
711  else
712  fPar->SetValue(name.Data(), list.Data());
713  }
714  delete toks; //must clean up
715  }
716  else if (s.BeginsWith("OnlyZId")) {
717  SetOnlyZId(kTRUE);
718  s.ReplaceAll("OnlyZId", "");
719  s.Remove(TString::kBoth, ' ');
720  if (s != "") { //older versions did not write mass formula after OnlyZId
721  mass_formula = s.Atoi();
722  if (mass_formula > -1) SetMassFormula(mass_formula);
723  }
724  }
725  else if (s.BeginsWith('+')) {
726  //New line
727  line_no++;
728  //Get name of class by stripping off the '+' at the start of the line
729  s.Remove(0, 1);
730  TString lineclass = s;
731  //next line is type ("ID" or "OK") followed by ':', followed by name of line
732  s.ReadLine(gridfile);
733  //split into tokens separated by ':'
734  TObjArray* toks = s.Tokenize(':');
735  TString type = ((TObjString*) toks->At(0))->GetString();
736  TString name = "";
737  // make sure the line actually has a name !
738  if (toks->GetEntries() > 1) name = ((TObjString*) toks->At(1))->GetString();
739  else {
740  // print warning allowing to find nameless line in file
741  Warning("ReadFromAsciiFile",
742  "In graph : %s\nIdentifier with no name. Identifier type = %s. Line number in graph = %d",
743  GetName(), type.Data(), line_no);
744  }
745  delete toks; //must clean up
746  ReadIdentifierFromAsciiFile(name, type, lineclass, gridfile);
747  }
748  }
751  if (fLastScaleX != 1 || fLastScaleY != 1) {
753  }
755  //set runlist
756  if (fPar->HasParameter("Runlist")) SetRuns(fPar->GetStringValue("Runlist"));
757  else SetRuns("");
758 
759  // if a back-up copy had previously been created (by starting the editor)
760  // we replace it by the version read from file
762 }
763 
764 
765 
766 
769 
770 void KVIDGraph::ReadIdentifierFromAsciiFile(TString& name, TString& type, TString& cl, ifstream& gridfile)
771 {
772  // Read in new identifier object from file
773 
774  KVIDentifier* line = New(cl.Data());
775  line->SetName(name.Data());
776  Add(type, line);
777  //now use ReadAscii method of class to read coordinates and other informations
778  line->ReadAsciiFile(gridfile);
779 }
780 
781 
782 
783 
793 
794 void KVIDGraph::ReadAsciiFile(const Char_t* filename)
795 {
796  //Open, read and close ascii file containing this grid.
797  //Any previous lines in the grid are destroyed.
798  //Comment lines begin with #
799  //Grid info begins with
800  //++ClassName
801  //where ClassName is actual class name of instance of this object
802  //New lines begin with +name_of_class
803  //'!' signals end of grid
804 
805  ifstream gridfile(filename);
806 
807  if (gridfile.good()) {
808  ReadFromAsciiFile(gridfile);
809  }
810  else {
811  Warning("ReadAsciiFile", "Could not find file %s. Check filename.", filename);
812  }
813  gridfile.close();
814 }
815 
816 
817 
818 
821 
823 {
824  //Create new object of class "id_class" which derives from KVIDentifier
825 
826  KVIDentifier* line = 0;
827  TClass* clas = TClass::GetClass(id_class);
828  if (!clas) {
829  Error("New",
830  "%s is not a valid classname. No known class.", id_class);
831  }
832  else {
833  if (!clas->InheritsFrom(KVIDentifier::Class())) {
834  Error("New",
835  "%s is not a valid class deriving from KVIDentifier",
836  id_class);
837  }
838  else {
839  line = (KVIDentifier*) clas->New();
840  }
841  }
842  return line;
843 }
844 
845 
846 
847 
852 
854 {
855  // Add the object to the list of cuts or identifiers:
856  // type = "ID" --> calls AddIdentifier(id)
857  // type = "OK" or "cut" --> calls AddCut(id)
858 
859  type.ToUpper();
860  if (type == "ID") AddIdentifier(id);
861  else if (type == "OK" || type == "CUT") AddCut(id);
862  else if (type == "INFO") AddInfo(id);
863 }
864 
865 
866 
867 
872 
874 {
875  // Create and add the object to the list of cuts or identifiers:
876  // type = "ID" --> calls AddIdentifier(id)
877  // type = "OK" or "cut" --> calls AddCut(id)
878 
879  type.ToUpper();
880  KVIDentifier* id = New(classname);
881  if (!id) return 0;
882  if (type == "ID") AddIdentifier(id);
883  else if (type == "OK" || type == "CUT") AddCut(id);
884  else if (type == "INFO") AddInfo(id);
885  return id;
886 }
887 
888 
889 
890 
902 
904 {
905  //Draw all objects in graph on the current display, if one exists: i.e. in order to superimpose the grid
906  //on a 2D display of data, use KVIDGraph::Draw() (no option "same" needed).
907  //
908  //If no TCanvas exists, or if one exists but it is empty, a frame large enough to display all
909  //the objects in the graph will be generated.
910  //
911  //The title of the canvas is set to the name of the graph
912  //
913  //If the graph is already displayed (i.e. if fPad!=0), we call UnDraw() in order to remove it from the display.
914  //This is so that double-clicking a graph in the IDGridManagerGUI list makes it disappear if it is already drawn.
915 
916  if (fPad) { /* graph already displayed. undraw it! */
917  UnDraw();
918  return;
919  }
920 
921  if (!gPad) {
922  fPad = new TCanvas("c1", GetName());
923  }
924  else {
925  fPad = (TPad*)gPad;
926  gPad->SetTitle(GetName());
927  }
928  if (!gPad->GetListOfPrimitives()->GetSize()) {
929  //calculate size of pad necessary to show graph
930  if (GetXmin() == GetXmax())
931  const_cast < KVIDGraph* >(this)->FindAxisLimits();
932  gPad->DrawFrame(GetXmin(), GetYmin(), GetXmax(), GetYmax());
933  }
934  {
935  fIdentifiers->R__FOR_EACH(KVIDentifier, Draw)("PL");
936  }
937  {
938  fCuts->R__FOR_EACH(KVIDentifier, Draw)("PL");
939  }
940  {
941  fInfoZones->R__FOR_EACH(KVIDentifier, Draw)("PL");
942  }
943  gPad->Modified();
944  gPad->Update();
945  // connect canvas' Closed() signal to KVIDGraph::ResetPad so that if the
946  // canvas GUI is closed (thereby deleting the fPad object), we reset fPad
947  // and do not try to Undraw in a non-existent canvas
948 // fPad->Connect("Closed()", "KVIDGraph", this, "ResetPad()");
949 // if (fPad->GetCanvas()) fPad->GetCanvas()->Connect("Cleared(TVirtualPad*)", "KVIDGraph", this, "ClearPad(TVirtualPad*)");
950 }
951 
952 
953 
954 
980 
982 {
983  //Make the graph disappear from the current canvas/pad
984  //In case any objects have (accidentally) been drawn more than once, we keep calling
985  //gPad->GetListOfPrimitives()->Remove() as long as gPad->GetListOfPrimitives()->FindObject()
986  //returns kTRUE for each identifier.
987 
988 // if (!fPad) {
989 // Error("UnDraw", "Cannot undraw, no pad stored ??");
990 // return;
991 // }
992 // TIter next_id(fIdentifiers);
993 // KVIDentifier* line;
994 // //remove the rest of the lines
995 // while ((line = (KVIDentifier*) next_id())) {
996 // while (fPad->GetListOfPrimitives()->FindObject(line))
997 // fPad->GetListOfPrimitives()->Remove(line);
998 // }
999 // TIter next_ok(fCuts);
1000 // while ((line = (KVIDentifier*) next_ok())) {
1001 // while (fPad->GetListOfPrimitives()->FindObject(line))
1002 // fPad->GetListOfPrimitives()->Remove(line);
1003 // }
1004 // fPad->Modified();
1005 // fPad->Update();
1006 // fPad->Disconnect("Closed()", this, "ResetPad()");
1007 // if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect("Cleared(TVirtualPad*)", this, "ClearPad(TVirtualPad*)");
1008  fPad = 0;
1009 }
1010 
1011 
1012 
1013 
1017 
1019 {
1020  // In case the graph can no longer be drawn/undrawn (because fPad contains address of a canvas
1021  // which died unexpectedly), use this method to reset fPad=0 and hopefully start afresh.
1022  fPad = 0;
1023 }
1024 
1025 
1026 
1027 
1030 
1032 {
1033  //Print out all objects in graph
1034 
1035  cout << ClassName() << " : " << GetName() << endl;
1036  cout << "Title : " << GetTitle() << endl;
1037  //print list of parameters
1038  fPar->Print();
1039  KVIDentifier* line = 0;
1040  TIter nextOK(fCuts);
1041  while ((line = (KVIDentifier*) nextOK()))
1042  line->ls();
1043  TIter nextID(fIdentifiers);
1044  while ((line = (KVIDentifier*) nextID()))
1045  line->ls();
1046  TIter nextInfo(fInfoZones);
1047  while ((line = (KVIDentifier*) nextInfo()))
1048  line->ls();
1049 }
1050 
1051 
1052 
1053 
1056 
1058 {
1059  //Calculate X/Y min/max of all objects in graph
1060 
1061  KVIDentifier* line;
1062  Double_t x, y, xmin, ymin, xmax, ymax;
1063  xmax = ymax = -999999;
1064  xmin = ymin = 999999;
1065  TIter nextOK(fCuts);
1066  while ((line = (KVIDentifier*) nextOK())) {
1067  for (int i = 0; i < line->GetN(); i++) {
1068  line->GetPoint(i, x, y);
1069  xmin = (x < xmin ? x : xmin);
1070  xmax = (x > xmax ? x : xmax);
1071  ymin = (y < ymin ? y : ymin);
1072  ymax = (y > ymax ? y : ymax);
1073  }
1074  }
1075  TIter nextID(fIdentifiers);
1076  while ((line = (KVIDentifier*) nextID())) {
1077  for (int i = 0; i < line->GetN(); i++) {
1078  line->GetPoint(i, x, y);
1079  xmin = (x < xmin ? x : xmin);
1080  xmax = (x > xmax ? x : xmax);
1081  ymin = (y < ymin ? y : ymin);
1082  ymax = (y > ymax ? y : ymax);
1083  }
1084  }
1085  fXmin = xmin;
1086  fYmin = ymin;
1087  fXmax = xmax;
1088  fYmax = ymax;
1089  // Info("FindAxisLimits()", "Xmin=%f Ymin=%f Xmax=%f Ymax=%f", GetXmin(), GetYmin(), GetXmax(), GetYmax());
1090 }
1091 
1092 
1093 
1094 
1101 
1102 void KVIDGraph::Scale(TF1* sx, TF1* sy)
1103 {
1104  // Rescale coordinates of every object in graph according to arbitrary functions
1105  // of the coordinates (sx & sy can be 1-dimensional or 2-dimensional functions).
1106  //
1107  // If sy is a TF1 function f(x), then the 'x' in this function refers to the y-coordinate.
1108  // If sy is a TF2 function f(x,y), 'x' and 'y' refer to the x & y-coordinates.
1109 
1110  if (!sx && !sy)
1111  return;
1112  if (GetNumberOfIdentifiers() > 0) {
1113  fIdentifiers->R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1114  }
1115  if (GetNumberOfCuts() > 0) {
1116  fCuts->R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1117  }
1118  if (GetNumberOfInfos() > 0) {
1119  fInfoZones->R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1120  }
1121  Modified();
1122 }
1123 
1124 
1125 
1126 
1129 
1131 {
1132  // Called by SetX/YScaleFactor methods to rescale every point of every object in the grid
1133 
1134  if (TMath::Abs(sx) == 1 && TMath::Abs(sy) == 1)
1135  return;
1136  if (GetNumberOfIdentifiers() > 0) {
1137  fIdentifiers->R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1138  }
1139  if (GetNumberOfCuts() > 0) {
1140  fCuts->R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1141  }
1142  if (GetNumberOfInfos() > 0) {
1143  fInfoZones->R__FOR_EACH(KVIDentifier, Scale)(sx, sy);
1144  }
1145 }
1146 
1147 
1148 
1149 
1150 
1151 
1152 
1153 
1161 
1162 void KVIDGraph::DrawAndAdd(const Char_t* Type, const Char_t* Classname)
1163 {
1164  //Use this method to add objects to a grid which is drawn in the current pad gPad.
1165  //We wait for the user to draw the line with the graphical editor
1166  //(we put the pad automatically into this mode,
1167  //there is no need to use the Editor toolbar).
1168  //Then we retrieve this TGraph, create a new KVIDentifier-derived object of
1169  //class "classname", and add it to the "type" list (= "OK"/"cut" or "ID").
1170 
1171  if (!fPad && !gPad) return;
1172  // if grid already drawn somewhere, make grid's pad active
1173  if (fPad && fPad != gPad) {
1174  fPad->cd();
1175  Warning("DrawAndAdd", "Changed active pad to pad containing this graph");
1176  }
1177  if (!fPad) fPad = gPad;
1178 
1179  TString type(Type);
1180  TString classname(Classname);
1181  //create new ID line
1182  KVIDentifier* line = New(classname);
1183  //wait for user to draw object
1184  line->WaitForPrimitive();
1185  //add line to list
1186  Add(type, line);
1187  Modified();
1188 }
1189 
1190 
1191 
1192 
1193 
1194 
1206 
1208  KVIDGraph* g2, Int_t id2_min, Int_t id2_max)
1209 {
1210  //Static method taking lines id1_min to id2_min from grid g1 and lines id2_min to id2_max from
1211  //grid g2 and making a new grid containing them. Returns the pointer to the new grid.
1212  //
1213  //It is assumed that g1 and g2 are grids of the same class. The new grid will be an object of the
1214  //same class as g1.
1215  //
1216  //Any scaling factors are applied to the line coordinates as they are copied from their parent grids.
1217  //As scaling may be different in g1 and g2, the resulting grid has no scaling factor, but the coordinates
1218  //of all its lines result from application of the different scaling factors of the two grids.
1219 
1220  //make new grid
1221  KVIDGraph* merger = (KVIDGraph*) g1->IsA()->New();
1222 
1223  //loop over lines in first grid
1224  TIter next_id1(g1->GetIdentifiers());
1225  KVIDentifier* line;
1226  while ((line = (KVIDentifier*) next_id1())) {
1227  if (line->GetID() >= id1_min && line->GetID() <= id1_max)
1228  merger->Add("ID", (KVIDentifier*) line->Clone()); //add clone of lines with right ID
1229  }
1230 
1231  //loop over lines in second grid
1232  TIter next_id2(g2->GetIdentifiers());
1233  while ((line = (KVIDentifier*) next_id2())) {
1234  if (line->GetID() >= id2_min && line->GetID() <= id2_max)
1235  merger->Add("ID", (KVIDentifier*) line->Clone());
1236  }
1237 
1238  //just in case any of the lines were highlighted...
1239  merger->SetLineColor(kBlack);
1240 
1241  return merger;
1242 }
1243 
1244 
1245 
1246 
1256 
1258 {
1259  // Default method for deciding if point (x,y) corresponds to an identifiable
1260  // particle or not: we loop over the list of cuts and test the
1261  // point with the method TestPoint(x,y).
1262  //
1263  // If the point is accepted by all cuts, then (x,y) is identifiable (return kTRUE).
1264  //
1265  // If the point is rejected by a cut we return kFALSE.
1266  // If rejected_by contains a valid pointer, we set it to the name of the rejecting cut.
1267 
1268  TIter next(fCuts);
1269  KVIDentifier* id = 0;
1270  if (rejected_by) *rejected_by = "";
1271  while ((id = (KVIDentifier*)next())) {
1272  if (!id->TestPoint(x, y)) {
1273  if (rejected_by) *rejected_by = id->GetName();
1274  return kFALSE;
1275  }
1276  }
1277  return kTRUE;
1278 }
1279 
1280 
1281 
1284 
1286 {
1287  // loop over KVIDGraph::fInfoZones to set flags in KVIdentificationResult
1288 
1289  TIter next(fInfoZones);
1290  KVIDentifier* id = 0;
1291  while ((id = (KVIDentifier*)next())) {
1292  if (id->TestPoint(x, y)) {
1293  idr->AddFlag(GetName(), id->GetName());
1294  }
1295  }
1296 }
1297 
1298 
1299 
1300 
1303 
1305 {
1306  // Set list of runs for which grid is valid
1307  fRunList = runs;
1308  fPar->SetValue("Runlist", fRunList.AsString());
1309  Modified();
1310 }
1311 
1312 
1313 
1314 
1319 
1321 {
1322  // If name of grid is not set explicitly with SetName(const Char_t*),
1323  // we return the name of the first ID telescope in the list of telescopes
1324  // with which this grid is associated.
1325 
1326  if (fName != "") return fName;
1327  fDyName = "";
1328  if (fTelescopes.At(0)) fDyName = fTelescopes.At(0)->GetName();
1329  else {
1330  if (fPar->HasParameter("IDTelescopes")) {
1331  KVString tel_list = fPar->GetStringValue("IDTelescopes");
1332  tel_list.Begin(",");
1333  fDyName = tel_list.Next();
1334  }
1335  }
1336  return fDyName;
1337 }
1338 
1339 
1340 
1341 
1348 
1350 {
1351  // Called after reading a grid from an ascii file.
1352  // Tries to convert information written by an old version of the class:
1353  //
1354  //<PARAMETER> First run=... ----> <PARAMETER> Runlist=...
1355  //<PARAMETER> Last run=...
1356 
1357  if (fPar->HasParameter("Runlist")) return;
1358  if (fPar->HasParameter("First run") && fPar->HasParameter("Last run")) {
1359  fRunList.SetMinMax(fPar->GetIntValue("First run"), fPar->GetIntValue("Last run"));
1360  fPar->SetValue("Runlist", fRunList.AsString());
1361  fPar->RemoveParameter("First run");
1362  fPar->RemoveParameter("Last run");
1363  }
1364 }
1365 
1366 
1374 
1376 {
1377  // ecriture des grilles avec version suivant un modele de fichier (fPattern)
1378  // fPattern_v%d.grid
1379  // le modele doit etre initialiser par la methode SetPattern(TString)
1380  // la valeur par default version=-1 permet l ecriture de la derniere version
1381  // apres un check des versions existantes (methode CheckVersion)
1382  // la premiere version est indexee v0
1383  Int_t vv = 0;
1384  if (version == -1) vv = CheckVersion(version) + 1;
1385  WriteAsciiFile(fPattern + "_v" + Form("%d", vv) + ".grid");
1386 }
1387 
1388 
1391 
1393 {
1394  // lecture des grilles avec version suivant un modele de fichier
1395  Int_t vv = CheckVersion(version);
1396  if (vv == -1) {
1397  if (version == -1) cout << "no file " + fPattern + "_v%d.grid" << endl;
1398  else cout << "no file " + fPattern + Form("_v%d.grid", version) << endl;
1399  }
1400  else ReadAsciiFile(fPattern + "_v" + Form("%d", vv) + ".grid");
1401 }
1402 
1403 
1410 
1412 {
1413  // version>=0 check si la version demandee du fichier grille existe
1414  // version-1 renvoie la derniere version existante
1415  // si la version demandee n existe pas return -1
1416  // creation d un fichier tampon dans le repertoire ou se situe les fichiers grilles
1417  // efface a la fin de la methode
1418  Int_t temoin = -1;
1419  TString pbis = fPattern, chemin = "";
1420  TObjArray* tok = NULL;
1421  if (fPattern.Contains("/")) { // prise en compte de fPattern contenant un chemin pour les fichiers
1422  tok = fPattern.Tokenize("/");
1423  Int_t nb = tok->GetEntries();
1424  pbis = ((TObjString*)(*tok)[nb - 1])->GetString();
1425  chemin = "";
1426  for (Int_t ii = 0; ii < nb - 1; ii += 1) chemin += ((TObjString*)(*tok)[ii])->GetString();
1427  chemin += "/";
1428  }
1429  gROOT->ProcessLine(".! ls " + fPattern + "_v*.grid >> " + chemin + "listKVIDGraph_" + pbis);
1430  ifstream f_in(chemin + "listKVIDGraph_" + pbis);
1431  TString line = "";
1432  Int_t num = -2;
1433  while (f_in.good() && num != version) {
1434  line.ReadLine(f_in);
1435  if (line.Contains(fPattern + "_v") && line.Contains(".grid")) {
1436  tok = line.Tokenize(".");
1437  line = ((TObjString*)(*tok)[0])->GetString();
1438  line.ReplaceAll(fPattern + "_v", "template");
1439  tok = line.Tokenize("template");
1440  num = ((TObjString*)(*tok)[0])->GetString().Atoi();
1441  if (num > temoin) temoin = num;
1442  }
1443  }
1444  f_in.close();
1445  gROOT->ProcessLine(".! rm -f " + chemin + "listKVIDGraph_" + pbis);
1446  delete tok;
1447  if (version == -1) return temoin;
1448  else if (temoin != version) {
1449  return -1;
1450  }
1451  else return temoin;
1452 }
1453 
1454 
1455 
1456 
1460 
1462 {
1463  // Set mass formula for all identifiers if graph has OnlyZId()=kTRUE.
1464  // This will change the mass (A) of each identifier.
1465 
1466  fMassFormula = mass;
1467  if (IsOnlyZId()) {
1468  if (GetNumberOfIdentifiers() > 0) {
1469  fIdentifiers->R__FOR_EACH(KVIDentifier, SetMassFormula)(mass);
1470  }
1471  }
1472  Modified();
1473 }
1474 
1475 
1476 
1477 
1483 
1485 {
1486  // Use this method if the graph is only to be used for Z identification
1487  // (no isotopic information). Default is to identify both Z & A
1488  // (fOnlyZid = kFALSE). Note that setting fOnlyZid=kTRUE changes the way line
1489  // widths are calculated (see KVIDGrid::CalculateLineWidths)
1490  fOnlyZId = yes;
1491  if (GetNumberOfIdentifiers() > 0) {
1492  fIdentifiers->R__FOR_EACH(KVIDentifier, SetOnlyZId)(yes);
1493  }
1494  Modified();
1495 }
1496 
1497 
1498 
1499 
1500 
1503 
1505 {
1506  // Associate this graph with all ID telescopes in list
1507 
1508  TIter next(tels);
1509  KVBase* tel;
1510  while ((tel = (KVBase*)next())) AddIDTelescope(tel);
1511  Modified();
1513 }
1514 
1515 
1516 
1517 //void KVIDGraph::SetIDTelescopes()
1518 //{
1519 // // Opens dialog box to view and/or choose ID telescopes associated with this
1520 // // identification graph
1521 
1522 // Bool_t cancel;
1523 // TString old_label = GetIDTelescopeLabel();
1524 // new KVIDGUITelescopeChooserDialog(gMultiDetArray, &fTelescopes, &cancel,
1525 // gClient->GetRoot(), gClient->GetRoot());
1526 // if(!cancel){
1527 // // if type of associated id telescope has changed, we need to
1528 // // update the grid manager and associated gui (grid will appear
1529 // // on a different tab).
1530 // if(old_label != GetIDTelescopeLabel()) gIDGridManager->Modified();
1531 // else // same type; just the grid changes
1532 // Modified();
1533 // }
1534 //}
1535 
1536 
1537 
1543 
1545 {
1546  // Static function which will create and 'Build' the identification graph of
1547  // class 'class_name', one of the plugins defined in either $KVROOT/KVFiles/.kvrootrc,
1548  // or in the user's .kvrootrc file.
1549 
1550  //check and load plugin library
1551  TPluginHandler* ph;
1552  if (!(ph = KVBase::LoadPlugin("KVIDGraph", class_name)))
1553  return 0;
1554 
1555  //execute constructor/macro for graph - assumed without arguments
1556  KVIDGraph* gr = (KVIDGraph*) ph->ExecPlugin(0);
1557  return gr;
1558 }
1559 
1560 
1561 
1562 
1569 
1571 {
1572  // Toggles 'editable' status of all lines/contours in graph
1573  // If editable = kTRUE this makes it possible to modify the graph
1574  // we then take a snapshot of the graph before editing begins
1575  // and store it in fLastSavedVersion. we can always revert to
1576  // this version if we want
1577 
1578  if (editable && !GetEditable()) UpdateLastSavedVersion();
1579 
1580  TCutG::SetEditable(editable);
1581  if (GetNumberOfIdentifiers() > 0) {
1582  fIdentifiers->R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1583  }
1584  if (GetNumberOfCuts() > 0) {
1585  fCuts->R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1586  }
1587  if (GetNumberOfInfos() > 0) {
1588  fInfoZones->R__FOR_EACH(KVIDentifier, SetEditable)(editable);
1589  }
1590 }
1591 
1592 
1593 
1594 
1598 
1600 {
1601  // Returns a comma-separated list of the names of all ID telescopes for which
1602  // this grid is valid.
1603 
1604  static TString tel_list;
1605  if (!fTelescopes.GetEntries()) {
1606  // case of grid with "unknown" ID telescopes
1607  // we return the value of the IDTelescopes parameter (if defined)
1608  if (fPar->HasParameter("IDTelescopes")) {
1609  tel_list = fPar->GetStringValue("IDTelescopes");
1610  return tel_list.Data();
1611  }
1612  }
1613  TIter next(&fTelescopes);
1614  TObject* id = next();
1615  if (id) tel_list = id->GetName();
1616  while ((id = next())) tel_list += Form(",%s", id->GetName());
1617  return tel_list;
1618 }
1619 
1620 
1621 
1622 
1626 
1627 void KVIDGraph::Streamer(TBuffer& R__b)
1628 {
1629  // Stream an object of class KVIDGraph.
1630  // Resets the 'fParent' pointer of each KVIDentifier after reading them in.
1631 
1632  if (R__b.IsReading()) {
1633  R__b.ReadClassBuffer(KVIDGraph::Class(), this);
1634  TIter nxt_id(fIdentifiers);
1635  KVIDentifier* id;
1636  while ((id = (KVIDentifier*)nxt_id())) id->fParent = this;
1637  TIter nxt_cut(fCuts);
1638  while ((id = (KVIDentifier*)nxt_cut())) id->fParent = this;
1639  TIter nxt_info(fInfoZones);
1640  while ((id = (KVIDentifier*)nxt_info())) id->fParent = this;
1641  }
1642  else {
1643  R__b.WriteClassBuffer(KVIDGraph::Class(), this);
1644  }
1645 }
1646 
1647 
1648 
1650 
1654 
1656  : histos(h), histo_names(n)
1657  {}
1658  void fill(const char* name, double x, double y = 0., double w = 0.)
1659  {
1661  if (h) {
1662  if (w > 0)((TH2*)h)->Fill(x, y, w);
1663  else h->Fill(x, y);
1664  }
1665  }
1666 };
1667 
1668 
1669 
1690 
1692 {
1693  //This method allows to test the identification capabilities of the grid using data in a TH2F.
1694  //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1695  //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1696  //IsIdentifiable() returns kTRUE) and fill the histograms with the results of the identification
1697  //
1698  //The "identification" or PID we represent is the result of the KVReconstructedNucleus::GetPID()
1699  //method for the identified nucleus.
1700  //
1701  // The KVHashList contains histograms to be filled with results
1702  // The KVNameValueList histo_names contains the name of each histogram passed in the KVHashList
1703  // i.e. it may have any of the following parameters
1704  //
1705  // "ID_REAL"="[name of histo to fill with PID spectrum]"
1706  // "ID_REAL_VS_ERES" - PID vs. Eres histo
1707  // "Z_A_REAL" - 2D map (nuclear chart)
1708  // "ZADIST_AIDENT" - integer A vs. integer Z distribution for isotopically-identified particles
1709  // "ZIDENT_ICODE0" - map of points leading to Z-only identification with quality code 0
1710  // "ZIDENT_ICODES_1_2" - map of points leading to Z-only identification with quality codes 1 or 2
1711 
1712  //Initialize the grid: calculate line widths etc.
1713  Initialize();
1714 
1715  kvidgraph_idresult_filler idresults(histos, histo_names);
1716 
1717  // reset contents of all histos
1718  histos.Execute("Reset", "");
1719 
1720  Int_t tot_events = (Int_t) data->GetSum();
1721  Int_t events_read = 0;
1722  Int_t percent = 0, cumul = 0;
1723 
1724  //loop over data in histo
1725  for (int i = 1; i <= data->GetNbinsX(); i++) {
1726  for (int j = 1; j <= data->GetNbinsY(); j++) {
1727 
1728  Stat_t poids = data->GetBinContent(i, j);
1729  if (poids == 0)
1730  continue;
1731 
1732  Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1733  Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1734  Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1735  Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1736  //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1737  //randomly-drawn x and y coordinates inside this bin
1738  //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1739  //a weight poids/20
1740  Int_t kmax = (Int_t) TMath::Min(20., poids);
1741  Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1742  for (int k = 0; k < kmax; k++) {
1743  double x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1744  double y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1745  if (IsIdentifiable(x, y)) {
1747  Identify(x, y, &idr);
1748  if (AcceptIDForTest(idr)) {
1749  Float_t PID = idr.PID;
1750  if (idr.Aident) PID = (idr.Z + 0.1 * (idr.PID - 2. * idr.Z));
1751  Float_t RealA, RealZ;
1752  RealA = (idr.Aident ? idr.PID : (Float_t)idr.A);
1753  RealZ = (idr.Aident ? (Float_t)idr.Z : idr.PID);
1754  idresults.fill("ID_REAL", PID, weight);
1755  idresults.fill("ID_REAL_VS_ERES", x, PID, weight);
1756  if (idr.Aident) {
1757  idresults.fill("Z_A_REAL", RealA - RealZ, gRandom->Gaus(RealZ, 0.15), weight);
1758  idresults.fill("ZADIST_AIDENT", idr.Z, idr.A, weight);
1759  switch (idr.IDquality) {
1760  case 0:
1761  idresults.fill("AIDENT_ICODE0", x, y, weight);
1762  break;
1763  case 1:
1764  case 2:
1765  case 3:
1766  idresults.fill("AIDENT_ICODE123", x, y, weight);
1767  break;
1768  default:
1769  break;
1770  }
1771  }
1772  else if (idr.Zident) {
1773  switch (idr.IDquality) {
1774  case 0:
1775  idresults.fill("ZIDENT_ICODE0", x, y, weight);
1776  break;
1777  case 1:
1778  case 2:
1779  case 3:
1780  idresults.fill("ZIDENT_ICODE123", x, y, weight);
1781  break;
1782  default:
1783  break;
1784  }
1785  }
1786  }
1787  else {
1788  if (idr.Aident) {
1789  switch (idr.IDquality) {
1790  case 4:
1791  idresults.fill("AIDENT_ICODE4", x, y, weight);
1792  break;
1793  case 5:
1794  idresults.fill("AIDENT_ICODE5", x, y, weight);
1795  break;
1796  case 6:
1797  idresults.fill("AIDENT_ICODE6", x, y, weight);
1798  break;
1799  case 7:
1800  idresults.fill("AIDENT_ICODE7", x, y, weight);
1801  break;
1802  default:
1803  break;
1804  }
1805  }
1806  else if (idr.Zident) {
1807  switch (idr.IDquality) {
1808  case 4:
1809  idresults.fill("ZIDENT_ICODE4", x, y, weight);
1810  break;
1811  case 5:
1812  idresults.fill("ZIDENT_ICODE5", x, y, weight);
1813  break;
1814  case 6:
1815  idresults.fill("ZIDENT_ICODE6", x, y, weight);
1816  break;
1817  case 7:
1818  idresults.fill("ZIDENT_ICODE7", x, y, weight);
1819  break;
1820  default:
1821  break;
1822  }
1823  }
1824 
1825  }
1826  }
1827  }
1828  events_read += (Int_t) poids;
1829  percent = (1. * events_read / tot_events) * 100.;
1830  if (percent > cumul) {
1831  Increment((Float_t) events_read); //sends signal to GUI progress bar
1833  cumul = percent;
1834  }
1835  }
1836  }
1837 }
1838 
1839 
int Int_t
KVIDGridManager * gIDGridManager
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
bool Bool_t
double Axis_t
double Double_t
double Stat_t
float Float_t
const Bool_t kTRUE
const char Option_t
kBlack
int type
float xmin
float ymin
float xmax
float ymax
#define gROOT
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
char * Strip(const char *str, char c=' ')
R__EXTERN TSystem * gSystem
#define gPad
Base class for KaliVeda framework.
Definition: KVBase.h:135
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:756
Extended version of ROOT THashList.
Definition: KVHashList.h:28
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:853
Axis_t GetYmax() const
Definition: KVIDGraph.h:369
Double_t GetYScaleFactor()
Definition: KVIDGraph.cpp:309
TString fDyName
dynamically generated name
Definition: KVIDGraph.h:50
virtual void ReadAsciiFile_WP(Int_t version=-1)
lecture des grilles avec version suivant un modele de fichier
Definition: KVIDGraph.cpp:1392
KVIDGraph * fLastSavedVersion
copy of last save version of grid, used for 'undo'
Definition: KVIDGraph.h:53
Int_t GetNumberOfCuts() const
Definition: KVIDGraph.h:304
virtual void SetVarX(const char *v)
Definition: KVIDGraph.h:506
void ReadAsciiFile(const Char_t *filename)
Definition: KVIDGraph.cpp:794
void RemoveIdentifier(KVIDentifier *)
Remove and destroy identifier.
Definition: KVIDGraph.cpp:352
Double_t GetXScaleFactor()
Definition: KVIDGraph.cpp:291
virtual void TestIdentification(TH2F *data, KVHashList &histos, KVNameValueList &histo_names)
Definition: KVIDGraph.cpp:1691
Double_t fLastScaleY
last applied scaling factor on Y
Definition: KVIDGraph.h:46
Double_t fLastScaleX
last applied scaling factor on X
Definition: KVIDGraph.h:45
void UpdateLastSavedVersion()
update last saved version. mkae copy of current state of graph.
Definition: KVIDGraph.cpp:551
virtual void SetName(const char *name)
Definition: KVIDGraph.h:134
Axis_t GetXmax() const
Definition: KVIDGraph.h:365
void Scale(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:1130
void RemoveInfo(KVIDentifier *)
Remove and destroy cut.
Definition: KVIDGraph.cpp:380
virtual void WriteToAsciiFile(std::ofstream &gridfile)
Definition: KVIDGraph.cpp:459
static void SetAutoAdd(Bool_t yes=kTRUE)
Definition: KVIDGraph.h:100
void init()
Definition: KVIDGraph.cpp:67
virtual void AddInfo(KVIDentifier *info)
Definition: KVIDGraph.h:336
void Increment(Float_t x)
Definition: KVIDGraph.h:241
void Draw(Option_t *opt="")
Definition: KVIDGraph.cpp:903
void AddIDTelescope(KVBase *t)
Definition: KVIDGraph.h:379
Int_t GetNumberOfIdentifiers() const
Definition: KVIDGraph.h:300
virtual void Copy(TObject &) const
virtual void Browse(TBrowser* b);
Definition: KVIDGraph.cpp:120
virtual void ReadIdentifierFromAsciiFile(TString &name, TString &type, TString &cl, std::ifstream &gridfile)
Read in new identifier object from file.
Definition: KVIDGraph.cpp:770
Axis_t fXmin
Definition: KVIDGraph.h:42
Bool_t IsOnlyZId() const
Definition: KVIDGraph.h:56
Int_t GetMassFormula() const
Definition: KVIDGraph.h:410
KVNameValueList * fPar
parameters associated to grid
Definition: KVIDGraph.h:44
void RevertToLastSavedVersion()
Definition: KVIDGraph.cpp:570
void UnDraw()
Definition: KVIDGraph.cpp:981
virtual void ReadFromAsciiFile(std::ifstream &gridfile)
Definition: KVIDGraph.cpp:616
void ClearPad(TVirtualPad *)
Definition: KVIDGraph.cpp:49
void WriteParameterListOfIDTelescopes()
Definition: KVIDGraph.cpp:399
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
void SetLineColor(Color_t lcolor)
Definition: KVIDGraph.h:181
KVList * fIdentifiers
list of identification objects
Definition: KVIDGraph.h:39
void Print(Option_t *opt="") const
Print out all objects in graph.
Definition: KVIDGraph.cpp:1031
KVList * fCuts
cuts used to define area in which identification is possible
Definition: KVIDGraph.h:40
virtual void WriteAsciiFile_WP(Int_t version=-1)
Definition: KVIDGraph.cpp:1375
KVIDentifier * GetIdentifier(Int_t Z, Int_t A) const
Definition: KVIDGraph.cpp:327
KVList * GetInfos() const
Definition: KVIDGraph.h:295
KVList * fInfoZones
contours/lines used to add info to particles (ex: punch-through)
Definition: KVIDGraph.h:41
virtual ~KVIDGraph()
Destructor.
Definition: KVIDGraph.cpp:199
virtual Bool_t IsIdentifiable(Double_t, Double_t, TString *rejected_by=nullptr) const
Definition: KVIDGraph.cpp:1257
void FindAxisLimits()
Calculate X/Y min/max of all objects in graph.
Definition: KVIDGraph.cpp:1057
Axis_t GetYmin() const
Definition: KVIDGraph.h:361
virtual void SetVarY(const char *v)
Definition: KVIDGraph.h:510
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:1207
virtual void DrawAndAdd(const Char_t *type="ID", const Char_t *classname="KVIDentifier")
Definition: KVIDGraph.cpp:1162
virtual void AddCut(KVIDentifier *cut)
Definition: KVIDGraph.h:325
void SetMassFormula(Int_t)
Definition: KVIDGraph.cpp:1461
const Char_t * GetName() const
Definition: KVIDGraph.cpp:1320
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:421
virtual KVIDentifier * New(const Char_t *)
Create new object of class "id_class" which derives from KVIDentifier.
Definition: KVIDGraph.cpp:822
virtual void BackwardsCompatibilityFix()
Definition: KVIDGraph.cpp:1349
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
Definition: KVIDGraph.cpp:1504
virtual void AddIdentifier(KVIDentifier *id)
Definition: KVIDGraph.h:312
virtual void SetInfos(Double_t, Double_t, KVIdentificationResult *) const
loop over KVIDGraph::fInfoZones to set flags in KVIdentificationResult
Definition: KVIDGraph.cpp:1285
static KVIDGraph * MakeIDGraph(const Char_t *)
Definition: KVIDGraph.cpp:1544
const Char_t * GetNamesOfIDTelescopes() const
Definition: KVIDGraph.cpp:1599
Axis_t GetXmin() const
Definition: KVIDGraph.h:357
void SetXScaleFactor(Double_t=0)
Definition: KVIDGraph.cpp:243
Int_t GetNumberOfInfos() const
Definition: KVIDGraph.h:308
TVirtualPad * fPad
pad in which graph is drawn
Definition: KVIDGraph.h:47
virtual Bool_t AcceptIDForTest(const KVIdentificationResult &idr)
Definition: KVIDGraph.h:74
Axis_t fYmax
min/max Y coordinates of graph
Definition: KVIDGraph.h:43
KVList * GetCuts() const
Definition: KVIDGraph.h:290
void SetRuns(const KVNumberList &nl)
Set list of runs for which grid is valid.
Definition: KVIDGraph.cpp:1304
virtual Int_t CheckVersion(Int_t version)
Definition: KVIDGraph.cpp:1411
virtual void SetEditable(Bool_t editable=kTRUE)
Definition: KVIDGraph.cpp:1570
void SetYScaleFactor(Double_t=0)
Definition: KVIDGraph.cpp:267
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
virtual void Clear(Option_t *opt="")
Definition: KVIDGraph.cpp:220
Int_t fMassFormula
OPTION={GetMethod="GetMassFormula";SetMethod="SetMassFormula";Items=(0="Beta-stability",...
Definition: KVIDGraph.h:52
void ResetDraw()
Definition: KVIDGraph.cpp:1018
void SetPattern(TString pattern)
Definition: KVIDGraph.h:227
Axis_t fYmin
Definition: KVIDGraph.h:43
KVList * GetIdentifiers() const
Definition: KVIDGraph.h:285
void RemoveCut(KVIDentifier *)
Remove and destroy cut.
Definition: KVIDGraph.cpp:367
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1484
void Modified()
Definition: KVIDGraph.h:247
void AddGrid(KVIDGraph *)
Add a grid to the collection. It will be deleted by the manager.
Base class for graphical cuts used in particle identification.
Definition: KVIDentifier.h:27
KVIDGraph * fParent
parent identification map or grid
Definition: KVIDentifier.h:31
virtual Int_t GetA() const
Definition: KVIDentifier.h:74
virtual Int_t GetZ() const
Definition: KVIDentifier.h:78
virtual Bool_t TestPoint(Double_t, Double_t)
Definition: KVIDentifier.h:119
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)
Int_t IDquality
specific quality code returned by identification procedure
Bool_t Zident
=kTRUE if Z of particle established
Extended TList class which owns its objects by default.
Definition: KVList.h:27
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
virtual void Print(Option_t *opt="") const
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)
virtual void Clear(Option_t *opt="")
Int_t GetNpar() const
return the number of stored parameters
const Char_t * GetStringValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
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:83
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
KVSeqCollection * GetSubListWithMethod(const Char_t *retvalue, const Char_t *method) const
T * get_object(const char *name) const
virtual void Execute(const char *method, const char *params, Int_t *error=0)
virtual void SetCleanup(Bool_t enable=kTRUE)
virtual TObject * Remove(TObject *obj)
Remove object from list.
virtual void Delete(Option_t *option="")
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
void Begin(TString delim) const
Definition: KVString.cpp:562
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:675
Stat_t GetSum() const
void Copy(TAttFill &attfill) const
void Copy(TAttLine &attline) const
void Copy(TAttMarker &attmarker) const
virtual Double_t GetBinCenter(Int_t bin) const
virtual Double_t GetBinWidth(Int_t bin) const
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=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
virtual Int_t GetEntries() const
const char * GetVarY() const
const char * GetVarX() const
Bool_t GetEditable() const
virtual void SetEditable(Bool_t editable=kTRUE)
virtual Int_t GetNbinsY() const
TAxis * GetXaxis()
TAxis * GetYaxis()
virtual Int_t GetNbinsX() const
virtual Int_t Fill(const char *name, Double_t w)
virtual Double_t GetBinContent(Int_t bin) const
virtual void ls(Option_t *option="") const
virtual TObject * At(Int_t idx) const
virtual const char * GetName() const
virtual void Copy(TObject &named) const
virtual const char * GetTitle() const
TString fName
Int_t GetEntries() const
TObject * At(Int_t idx) const
virtual const char * GetName() const
virtual TObject * Clone(const char *newname="") const
virtual const char * ClassName() const
virtual void Warning(const char *method, const char *msgfmt,...) 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, const T &... params)
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
virtual Double_t Uniform(Double_t x1, Double_t x2)
Int_t Atoi() const
Double_t Atof() const
Bool_t IsFloat() const
Bool_t IsDigit() const
TObjArray * Tokenize(const TString &delim) const
const char * Data() const
TString & Remove(EStripType s, char c)
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]
const Int_t n
gr SetName("gr")
TGraphErrors * gr
TH1 * h
const long double s
Definition: KVUnits.h:94
const long double cl
Definition: KVUnits.h:85
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:1658
KVNameValueList & histo_names
Definition: KVIDGraph.cpp:1653
kvidgraph_idresult_filler(KVHashList &h, KVNameValueList &n)
Definition: KVIDGraph.cpp:1655