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