KaliVeda
Toolkit for HIC analysis
KVOldINDRASelector.cpp
1 #include "KVDataSetAnalyser.h"
2 #define KVOldINDRASelector_cxx
3 #include "KVOldINDRASelector.h"
4 #include "TH2.h"
5 #include "TString.h"
6 #include "TEnv.h"
7 #include "TSystem.h"
8 #include "TClass.h"
9 #include "TROOT.h"
10 #include "KVBase.h"
11 #include "TPluginManager.h"
12 #include "KVClassFactory.h"
13 #include "KVDataAnalyser.h"
14 #include <KVINDRADB.h>
15 #ifndef __WITHOUT_TMACRO
16 #include <TMacro.h>
17 #endif
18 KVString KVOldINDRASelector::fBranchName = "INDRAReconEvent";
19 using namespace std;
20 
22 
23 
24 
28 {
29  //ctor
30  fChain = 0;
31  callnotif = 0;
32  gvlist = 0; // Global variable list set to nul.
33  lhisto = new KVHashList();
34  ltree = new KVHashList();
35  //create stopwatch
36  fTimer = new TStopwatch;
37  // event list
38  fEvtList = 0;
39  fTEVLexist = 0;
40  fKVDataSelector = 0;
41  fDataSelector = "";
42  needToSelect = kFALSE;
43  needToCallEndRun = kFALSE;
44  fCurrentRun = 0;
45  fPartCond = 0;
46  data = 0;
47  dataselector_lock.SetTimeout(60); // 60-second timeout in case of problems
48  dataselector_lock.SetSuspend(5); // suspension after timeout
49  dataselector_lock.SetSleeptime(1); // try lock every second
50 }
51 
52 
53 
58 
59 KVOldINDRASelector::~KVOldINDRASelector()
60 {
61  //dtor
62  //delete global variable list if it belongs to us, i.e. if created by a
63  //call to GetGVList
64  if (gvlist && TestBit(kDeleteGVList)) {
65  delete gvlist;
66  gvlist = 0;
67  ResetBit(kDeleteGVList);
68  }
69  delete fTimer;
70  SafeDelete(fPartCond);
71  lhisto->Clear();
72  delete lhisto;
73  ltree->Clear();
74  delete ltree;
75 }
76 
77 
78 
80 
82 {
83  if (fChain) return; //Init has already been called
84 
85  //delete any status file from previous job with same name from launch directory
86  gDataAnalyser->DeleteBatchStatusFile();
87 
88  if (!tree) return;
89 
90  // Set branch addresses
91  fChain = tree;
92  fChain->SetMakeClass(1);
93 
94  if (fChain->InheritsFrom("TChain"))
95  fTreeOffset = ((TChain*) fChain)->GetTreeOffset();
96  else
97  fTreeOffset = 0;
98 
99  data = 0;
100  b_data = 0;
101  fChain->SetBranchAddress(fBranchName.Data(), &data, &b_data);
102 
103 //
104 // Builds a TEventList by adding the contents of the lists for each run
105 //
106  BuildEventList();
107  if (fKVDataSelector) { // Init of the KVDataSelector if needed
108  fKVDataSelector->Init();
109  }
110  // tell the data analyser who we are
111  gDataAnalyser->RegisterUserClass(this);
112  gDataAnalyser->preInitAnalysis();
113  InitAnalysis(); //user initialisations for analysis
114  gDataAnalyser->postInitAnalysis();
115 
116  if (gvlist) {
117  gvlist->Init();
118  }
119 }
120 
121 
122 
126 
128 {
129  // Called when loading a new file.
130  // Get branch pointers.
131 
132  cout << "Analyse du fichier " << fChain->GetCurrentFile()->GetName()
133  << " : " << fChain->GetTree()->GetEntries() << endl;
134  NbTreeEntry = (Int_t) fChain->GetTree()->GetEntries();
135  fCurrentTreeNumber = fChain->GetTreeNumber();
136 
137  needToCallEndRun = kTRUE;
138 
139  if (fEvtList)
140  needToSelect = !(fTEVLexist[fCurrentTreeNumber]);
141  else
142  needToSelect = kFALSE;
143 
144  gDataAnalyser->preInitRun(); // will initialize fCurrentRun
145 
146  if (needToSelect) {
147  if (!fKVDataSelector) {
148  LoadDataSelector();
149  }
150  fKVDataSelector->Reset(fCurrentRun->GetNumber());
151  cout << " Building new TEventList : " << fKVDataSelector->
152  GetTEventList()->GetName()
153  << endl;
154  }
155 
156  InitRun(); //user initialisations for run
157  gDataAnalyser->postInitRun();
158  return kTRUE;
159 }
160 
161 
162 
167 
169 {
170  // Function called before starting the event loop.
171  // When running with PROOF Begin() is only called in the client.
172 
173  // Get the option and the name of the DataSelector if needed
174  ParseOptions();
175 
176  if (IsOptGiven("DataSelector")) SetDataSelector(GetOpt("DataSelector"));
177  else
178  SetDataSelector();
179 
180  totentry = 0;
181 
182  //start stopwatch, after first resetting it (in case this is not the first time the analysis is run)
183  fTimer->Start(kTRUE);
184 }
185 
186 
187 
194 
196 {
197  // Function called before starting the event loop.
198  // When running with PROOF SlaveBegin() is called in each slave
199  // Initialize the tree branches.
200 
201  /* Init(tree);
202 
203  TString option = GetOption();
204  */
205 }
206 
207 
208 #ifdef __WITHOUT_TSELECTOR_LONG64_T
209 
222 
223 Bool_t KVOldINDRASelector::Process(Int_t entry) //for ROOT versions < 4.01/01
224 #else
225 Bool_t KVOldINDRASelector::Process(Long64_t entry) //for ROOT versions > 4.00/08
226 #endif
227 {
228  //Here the event is read into memory and checks are made on the number
229  //of events read.
230  //Particles not having the correct identification and calibration quality codes
231  //are excluded from the analysis (IsOK()=kFALSE).
232  //Particles which do not satisfy the additional selection criteria set with
233  //SetParticleConditions() are excluded from the analysis (IsOK()=kFALSE).
234  //If ChangeFragmentMasses() was called in InitAnalysis() or InitRun()
235  //then the non-measured fragment masses will be recalculated with the
236  //new mass formula and laboratory energies adjusted accordingly.
237  //Then the reaction CM momenta of all "OK" particles are calculated and
238  //the list of global variables (if one is defined) is filled.
239 
240  if (gDataAnalyser->AbortProcessingLoop()) {
241  // abort requested by batch system
242  Abort(Form("Aborting analysis after %d events", totentry), kAbortFile);
243  return kFALSE;
244  }
245 
246  fTreeEntry = entry;
247 
248  if (gDataAnalyser->CheckStatusUpdateInterval(totentry)) gDataAnalyser->DoStatusUpdate(totentry);
249 
250  // read event
251  fChain->GetTree()->GetEntry(fTreeEntry);
252  // read raw data associated to event
253  gDataAnalyser->preAnalysis();
254 
255  //additional selection criteria ?
256  if (fPartCond) {
257  KVNucleus* part = 0;
258  while ((part = (KVNucleus*)GetEvent()->GetNextParticle("ok"))) {
259 
260  part->SetIsOK(fPartCond->Test(part));
261 
262  }
263  }
264 
265  //change masses ?
266  if (TestBit(kChangeMasses)) GetEvent()->ChangeFragmentMasses(fNewMassFormula);
267 
268  totentry++;
269 
270  //calculate momenta of particles in reaction cm frame
271  if (fCurrentRun->GetSystem() && fCurrentRun->GetSystem()->GetKinematics()) {
272 
273  GetEvent()->SetFrame("CM",
274  fCurrentRun->GetSystem()->GetKinematics()->GetCMVelocity());
275 
276  }
277 
278  RecalculateGlobalVariables();
279 
280 
281  Bool_t ok_anal = kTRUE;
282 
283  if (needToSelect) {
284  ok_anal = fKVDataSelector->ProcessCurrentEntry(); //Data Selection and user analysis
285  }
286  else
287  ok_anal = Analysis(); //user analysis
288  gDataAnalyser->postAnalysis();
289 
290  // Testing whether EndRun() should be called
291  if (AtEndOfRun()) {
292  TString mes("End of run after ");
293  mes += (totentry);
294  mes += " events.";
295  Info("Process", "%s", mes.Data());
296 
297  gDataAnalyser->preEndRun();
298  EndRun(); //user routine end of run
299  gDataAnalyser->postEndRun();
300  needToCallEndRun = kFALSE;
301 
302  // save the new Built TEventList
303  if (needToSelect) {
304  SaveCurrentDataSelection();
305  needToSelect = kFALSE;
306  }
307  }
308 
309  return ok_anal;
310 }
311 
312 
313 
316 
318 {
319  // Function called at the end of the event loop in each PROOF slave.
320 
321 
322 }
323 
324 
325 
329 
331 {
332  // Function called at the end of the event loop.
333  // When running with PROOF Terminate() is only called in the client.
334 
335  fTimer->Stop();//stop stopwatch straight away so that 'Events/CPU sec' etc. only
336  //includes time actually spent analysing data
337 
338  if (needToCallEndRun) {
339  gDataAnalyser->preEndRun();
340  EndRun();
341  gDataAnalyser->postEndRun();
342  }
343 
344  if (needToSelect) {
345  SaveCurrentDataSelection();
346  }
347 
348  cout << endl << " ====================== END ====================== " <<
349  endl << endl;
350  cout << " Total number of events read = " << totentry << endl;
351  cout << " Real time = " << fTimer->RealTime() << " sec." << endl;
352  cout << " CPU time = " << fTimer->CpuTime() << " sec." << endl;
353  cout << " Events/Real sec. = " << totentry /
354  fTimer->RealTime() << endl;
355  cout << " Events/CPU sec. = " << totentry /
356  fTimer->CpuTime() << endl;
357  cout << endl << " ====================== END ====================== " <<
358  endl << endl;
359 
360  if (fEvtList) {
361  fChain->SetEventList(0);
362  delete fEvtList;
363  fEvtList = 0;
364  }
365 
366  gDataAnalyser->preEndAnalysis();
367  EndAnalysis(); //user end of analysis routine
368  gDataAnalyser->postEndAnalysis();
369 
370  //delete job status file from $HOME directory
371  gDataAnalyser->DeleteBatchStatusFile();
372 }
373 
374 
375 
378 
379 void KVOldINDRASelector::Make(const Char_t* kvsname)
380 {
381  // Automatic generation of KVOldINDRASelector-derived class for KaliVeda analysis
382  KVClassFactory cf(kvsname, "User analysis class", "KVOldINDRASelector", kTRUE);
383  cf.AddImplIncludeFile("KVINDRAReconNuc.h");
384  cf.AddImplIncludeFile("KVBatchSystem.h");
385  cf.AddImplIncludeFile("KVINDRA.h");
386  cf.GenerateCode();
387 }
388 
389 
390 
395 
397 {
398  //Use a user-defined list of global variables for the analysis.
399  //In this case it is the user's responsibility to delete the list
400  //at the end of the analysis.
401  gvlist = list;
402 }
403 
404 
405 
410 
412 {
413  //Access to the internal list of global variables
414  //If the list does not exist, it is created.
415  //In this case it will be automatically deleted with the KVOldINDRASelector object.
416  if (!gvlist) {
417  gvlist = new KVGVList;
418  SetBit(kDeleteGVList);
419  }
420  return gvlist;
421 }
422 
423 
424 
428 
430 {
431  //Add the global variable "vg" to the list of variables for the analysis.
432  //This is equivalent to GetGVList()->Add( vg ).
433  if (!vg)
434  Error("AddGV(KVVarGlob*)", "KVVarGlob pointer is null");
435  else
436  GetGVList()->Add(vg);
437 }
438 
439 
440 
445 
447 {
448  //Access the global variable with name "name" in the list of variables
449  //for the analysis.
450  //This is equivalent to GetGVList()->GetGV( name ).
451 
452  return (const_cast < KVOldINDRASelector* >(this)->GetGVList()->GetGV(name));
453 }
454 
455 
456 
484 
486  const Char_t* name)
487 {
488  //Add a global variable to the list of variables for the analysis.
489  //
490  //"class_name" must be the name of a valid class inheriting from KVVarGlob, e.g. any of the default global
491  //variable classes defined as part of the standard KaliVeda package (in libKVvVarGlob.so). See
492  //"Class Reference" page on website for the available classes (listed by category under "Global Variables: ...").
493  //
494  //USER-DEFINED GLOBAL VARIABLES
495  //The user may use her own global variables in an analysis class, without having to add them to the main libraries.
496  //If the given class name is not known, it is assumed to be a user-defined class and we attempt to compile and load
497  //the class from the user's source code. For this to work, the user must:
498  //
499  // (1) add to the ROOT macro path the directory where her class's source code is kept, e.g. in $HOME/.rootrc
500  // add the following line:
501  //
502  // +Unix.*.Root.MacroPath: $(HOME)/myVarGlobs
503  //
504  // (2) for each user-defined class, add a line to $HOME/.kvrootrc to define a "plugin". E.g. for a class called MyNewVarGlob,
505  //
506  // +Plugin.KVVarGlob: MyNewVarGlob MyNewVarGlob MyNewVarGlob.cpp+ "MyNewVarGlob()"
507  //
508  // It is assumed that MyNewVarGlob.h and MyNewVarGlob.cpp will be found in $HOME/myVarGlobs (in this example).
509  //
510  //"name" is a unique name for the new global variable object which will be created and added to the internal
511  //list of global variables. This name can be used to retrieve the object (see GetGV) in the user's analysis.
512  //
513  //Returns pointer to new global variable object in case more than the usual default initialisation is necessary.
514 
515  KVVarGlob* vg = 0;
516  TClass* clas = gROOT->GetClass(class_name);
517  if (!clas) {
518  //class not in dictionary - user-defined class ? Look for plugin.
519  TPluginHandler* ph = KVBase::LoadPlugin("KVVarGlob", class_name);
520  if (!ph) {
521  //not found
522  Error("AddGV(const Char_t*,const Char_t*)",
523  "Called with class_name=%s.\nClass is unknown: not in standard libraries, and plugin (user-defined class) not found",
524  class_name);
525  return 0;
526  }
527  else {
528  vg = (KVVarGlob*) ph->ExecPlugin(0);
529  }
530  }
531  else if (!clas->InheritsFrom("KVVarGlob")) {
532  Error("AddGV(const Char_t*,const Char_t*)",
533  "%s is not a valid class deriving from KVVarGlob.",
534  class_name);
535  return 0;
536  }
537  else {
538  vg = (KVVarGlob*) clas->New();
539  }
540  vg->SetName(name);
541  AddGV(vg);
542  return vg;
543 }
544 
545 
546 
547 
576 
578 {
579  //Use this method if you change e.g. the acceptable particle identification codes in your
580  //Analysis() method and want to recalculate the values of all global variables
581  //for your new selection.
582  //
583  //WARNING: the global variables are calculated automatically for you for each event
584  //before method Analysis() is called. In order for the correct particles to be included in
585  //this calculation, make sure that at the END of Analysis() you reset the selection
586  //criteria.
587  //
588  //i.e. if in your InitAnalysis() you have:
589  // GetEvent()->AcceptIDCodes(kIDCode2|kIDCode3|kIDCode4);
590  //
591  //at the beginning of Analysis() the variables have been calculated for all particles
592  //with codes 2-4. If you store these values somewhere and then change the code mask:
593  //
594  // GetEvent()->AcceptIDCodes(kIDCode2|kIDCode3|kIDCode4|kIDCode6);
595  //
596  //you can recalculate the global variable list for particles with codes 2-4 & 6:
597  //
598  // RecalculateGlobalVariables();
599  //
600  //then at the end of Analysis(), after storing the new values of the variables, you
601  //should reset the code mask:
602  //
603  // GetEvent()->AcceptIDCodes(kIDCode2|kIDCode3|kIDCode4);
604  //
605  //which will be used for the next event read for processing.
606 
607  if (gvlist) gvlist->CalculateGlobalVariables(GetEvent());
608 }
609 
610 
611 
612 #ifdef __WITHOUT_TSELECTOR_LONG64_T
613 
617 
619 #else
621 #endif
622 {
623  //During event analysis (i.e. inside the Analysis() method), this gives the current TTree
624  //entry number, in other words the argument passed to TSelector::Process(Long64_t entry).
625 
626  return fTreeEntry;
627 }
628 
629 
630 
636 
638 {
639 //
640 // Builds the event list of the TChain by adding the event lists of each TTree.
641 // The event list contain the entry number of the TChain
642 //
643 
644  if (fEvtList) {
645  fEvtList->Reset();
646  delete fEvtList;
647  fEvtList = 0;
648  }
649  if (fKVDataSelector) {
650  delete fKVDataSelector;
651  fKVDataSelector = 0;
652  }
653  if (fTEVLexist) {
654  delete[]fTEVLexist;
655  fTEVLexist = 0;
656  }
657 
658  if (fDataSelector.Length()) {
659  Info("BuildEventList()",
660  "Building TEventList for the KVDataSelector \"%s\".",
661  GetDataSelector());
662  TObjArray* lof = 0;
663  Long64_t* toff = 0;
664  if (fTreeOffset) {
665  cout << "Analysis from a chain of trees." << endl;
666  lof = ((TChain*) fChain)->GetListOfFiles();
667  toff = fTreeOffset;
668  }
669  else {
670  cout << "Analysis from a single tree." << endl;
671  lof = new TObjArray();
672  lof->
673  Add(new
674  TNamed("SingleRun", fChain->GetCurrentFile()->GetName()));
675  toff = new Long64_t[2];
676  toff[0] = 0;
677  toff[1] = fChain->GetEntries();
678  }
679 
680  fEvtList =
681  new TEventList("chainEventList", "TEvent list for this TChain");
682 
683 
684  // Opening the file which contains the TEventLists
685  TString searchname(GetDataSelectorFileName());
686  TString fname = searchname;
687  cout << "File to open : " << fname.Data() << endl;
688  TFile* fileDataSelector = 0;
689  if (KVBase::FindFile("", searchname)) {
690  //get lock on file to avoid interference with other processes
691  if (dataselector_lock.Lock(fname.Data())) fileDataSelector = new TFile(fname.Data());
692  }
693  else {
694  cout << "The file \"" << fname.
695  Data() << "\" does not exist." << endl;
696  }
697 
698  fTEVLexist = new Bool_t[lof->GetEntries()];
699  for (Int_t tn = 0; tn < lof->GetEntries(); tn++) {
700  fTEVLexist[tn] = kFALSE;
701  TString fname(((TNamed*) lof->At(tn))->GetTitle());
702  cout << fname.Data() << endl;
703  Int_t nrun = dynamic_cast<KVDataSetAnalyser*>(gDataAnalyser)->GetRunNumberFromFileName(fname.Data());
704  if (nrun) {
705  cout << "Numero de run " << nrun << endl;
706  cout << "Recherche de " << Form("%s_run%d;1",
707  GetDataSelector(),
708  nrun) << endl;
709  TEventList* revtList = 0;
710  if (fileDataSelector) {
711  revtList =
712  (TEventList*) fileDataSelector->
713  Get(Form("%s_run%d;1", GetDataSelector(), nrun));
714  }
715  if (revtList) {
716  for (Int_t i = 0; i < revtList->GetN(); i++) {
717  fEvtList->Enter(fTreeOffset[tn] + revtList->GetEntry(i));
718  }
719  fTEVLexist[tn] = kTRUE;
720  }
721  else {
722  cout << "Liste introuvable..." << endl;
723  for (Int_t i = fTreeOffset[tn]; i < fTreeOffset[tn + 1];
724  i++) {
725  fEvtList->Enter(i);
726  }
727  }
728  }
729  else {
730  cout << "Run inconnu..." << endl;
731  }
732  }
733  if (fileDataSelector) {
734  cout << "Closing " << fileDataSelector->GetName() << endl;
735  fileDataSelector->Close();
736  dataselector_lock.Release();//unlock file
737  }
738 
739  if (!fTreeOffset) {
740  delete[]toff;
741  lof->SetOwner(kTRUE);
742  delete lof;
743  }
744  // Check if the TEventList is empty. If yes, all events will be read
745  if (!fEvtList->GetN()) {
746  Warning("BuildEventList()", "The TEventList is empty...");
747  delete fEvtList;
748  fEvtList = 0;
749  }
750  }
751  fChain->SetEventList(fEvtList);
752 }
753 
754 
755 
760 
762 {
763 //
764 // Check whether the end of run is reached for the current tree
765 //
766 
767  Bool_t ok = (fTreeEntry + 1 == fChain->GetTree()->GetEntries());
768 
769  if (fEvtList) {
770  Long64_t globEntry = 0;
771  if (fTreeOffset)
772  globEntry = ((TChain*) fChain)->GetChainEntryNumber(fTreeEntry);
773  else
774  globEntry = fTreeEntry;
775  Int_t index = fEvtList->GetIndex(globEntry);
776  Long64_t nextEntry = (fEvtList->GetEntry(index + 1));
777  ok = ok || (nextEntry == -1);
778  if (fTreeOffset) {
779  ok = ok || (nextEntry >= fTreeOffset[fCurrentTreeNumber + 1]);
780  }
781  }
782 
783  return ok;
784 }
785 
786 
787 
792 
794 {
795 //
796 // Set the pointer of the KVDataSelector according to its name
797 //
798  cout << "Loading KVDataSelector..." << endl;
799  Bool_t deleteSources = kFALSE;
800  if (fDataSelector.Length()) {
801  fKVDataSelector = 0;
802  TClass* clas = gROOT->GetClass(fDataSelector.Data());
803  cout << clas << " / " << fDataSelector.Data() << endl;
804  if (!clas) {
805  //if the class is not present, first check whether the declaration and
806  //the implementation files are present in the user's working directory
807  TString fileC(Form("%s.cpp", fDataSelector.Data()));
808  TString fileh(Form("%s.h", fDataSelector.Data()));
809 
810 #ifdef __WITHOUT_TMACRO
811  if (gSystem->AccessPathName(fileC.Data()) || gSystem->AccessPathName(fileh.Data())) {
812  Warning("LoadDataSelector(void)",
813  "No implementation and/or declaration file found for \"%s\".",
814  fDataSelector.Data());
815 #else
816  TMacro mC;
817  if (!mC.ReadFile(fileC.Data()) || !mC.ReadFile(fileh.Data())) {
818 
819  // Load .cpp and .h files from the TEventList's root file
820  TString searchname(GetDataSelectorFileName());
821  TString fname = searchname;
822  TFile* fileDataSelector = 0;
823 
824  if (KVBase::FindFile("", fname)) {
825  if (dataselector_lock.Lock(fname.Data())) fileDataSelector = new TFile(fname.Data());
826  }
827  else {
828  cout << "The file \"" << fname.
829  Data() << "\" does not exist." << endl;
830  }
831  TMacro* macC = 0;
832  TMacro* mach = 0;
833  if (fileDataSelector) {
834  macC = (TMacro*) fileDataSelector->Get(fileC.Data());
835  mach = (TMacro*) fileDataSelector->Get(fileh.Data());
836  }
837  if (macC && mach) {
838  macC->SaveSource(fileC.Data());
839  cout << fileC.Data() << " re-generated" << endl;
840  mach->SaveSource(fileh.Data());
841  cout << fileh.Data() << " re-generated." << endl;
842  deleteSources = kTRUE;
843  }
844  else {
845  Warning("LoadDataSelector(void)",
846  "No implementation and/or declaration file found for \"%s\".",
847  fDataSelector.Data());
848  }
849  if (fileDataSelector) {
850  fileDataSelector->Close();
851  dataselector_lock.Release();
852  }
853 #endif
854  }
855  else {
856  cout << "Files " << fileC.Data() << " and " << fileh.Data() <<
857  " found." << endl;
858  }
859  //class not in dictionary - user-defined class ? Add a plugin.
860  gROOT->GetPluginManager()->AddHandler("KVDataSelector",
861  fDataSelector.Data(),
862  fDataSelector.Data(),
863  Form("%s.cpp+",
864  fDataSelector.Data()),
865  Form("%s()",
866  fDataSelector.Data()));
867  TPluginHandler* ph =
868  KVBase::LoadPlugin("KVDataSelector", fDataSelector.Data());
869  if (!ph) {
870  //not found
871  Error("LoadDataSelector(void)",
872  "Called with class_name=%s.\nClass is unknown: not in standard libraries, and plugin (user-defined class) not found",
873  fDataSelector.Data());
874  }
875  else {
876  fKVDataSelector = (KVDataSelector*) ph->ExecPlugin(0);
877  fKVDataSelector->SetKVSelector(this);
878  cout << "Apres Plugin " << fKVDataSelector->IsA()->
879  GetName() << " : " << fKVDataSelector->
880  GetKVSelector() << endl;
881  }
882 
883  }
884  else if (!clas->InheritsFrom("KVDataSelector")) {
885  Error("LoadDataSelector(void)",
886  "%s is not a valid class deriving from KVDataSelector.",
887  fDataSelector.Data());
888  }
889  else {
890  fKVDataSelector = (KVDataSelector*) clas->New();
891  fKVDataSelector->SetKVSelector(this);
892  cout << "Apres clas->New() " << fKVDataSelector->IsA()->
893  GetName() << " : " << fKVDataSelector->
894  GetKVSelector() << endl;
895  }
896  if (deleteSources) {
897  cout << "Removing files \"" << fDataSelector.
898  Data() << "*.*\" ..." << endl;
899  gSystem->
900  Exec(Form
901  ("rm %s.[c,h]*", fDataSelector.Data()));
902  }
903  }
904  else {
905  fKVDataSelector = 0;
906  }
907  if (fKVDataSelector)
908  fKVDataSelector->Init();
909 }
910 
911 
912 
917 
919 {
920 //
921 // Save the newly built TEventList in the DataSelection root file
922 //
923  if (fKVDataSelector) {
924  TFile* curfile = gFile;
925  TString option;
926  TString searchname(GetDataSelectorFileName());
927  TString fname = searchname;
928  if (KVBase::FindFile("", searchname)) {
929  option = "update";
930  }
931  else {
932  option = "recreate";
933  }
934  cout << "File to open : " << fname.Data() << " : " << option.
935  Data() << endl;
936  TFile* fileDataSelector = 0;
937  if (dataselector_lock.Lock(fname.Data())) fileDataSelector = new TFile(fname.Data(), option.Data());
938  if (!fileDataSelector || (fileDataSelector && fileDataSelector->IsZombie())) {
939  Error("SaveCurrentDataSelection(void)",
940  "Opening the file \"%s\" with the option \"%s\" is not possible.\nNothing saved.",
941  fname.Data(), option.Data());
942  gFile = curfile;
943  return;
944  }
945  cout << "Saving the TEventList \"" << fKVDataSelector->
946  GetTEventList()->GetName() << "\"..." << endl;
947  cout << fKVDataSelector->GetTEventList()->
948  GetN() << " entries selected." << endl;
949  fKVDataSelector->GetTEventList()->Write();
950 
951 #ifndef __WITHOUT_TMACRO
952  TObject
953  * oC =
954  fileDataSelector->
955  Get(Form("%s.cpp;1", fKVDataSelector->IsA()->GetName()));
956  TObject* oh =
957  fileDataSelector->
958  Get(Form("%s.h;1", fKVDataSelector->IsA()->GetName()));
959  if (!oC || !oh) {
960  cout << "Saving the source files..." << endl;
961  TMacro mC(Form("%s.cpp", fKVDataSelector->IsA()->GetName()));
962  mC.SetName(Form("%s.cpp", fKVDataSelector->IsA()->GetName()));
963  mC.SetTitle(Form
964  ("Implementation file for the KVDataSelector \"%s\".",
965  fKVDataSelector->IsA()->GetName()));
966  mC.Write();
967  TMacro mh(Form("%s.h", fKVDataSelector->IsA()->GetName()));
968  mh.SetName(Form("%s.h", fKVDataSelector->IsA()->GetName()));
969  mh.SetTitle(Form
970  ("Declaration file for the KVDataSelector \"%s\".",
971  fKVDataSelector->IsA()->GetName()));
972  mh.Write();
973  }
974 #endif
975 
976  cout << "Done" << endl;
977  fileDataSelector->Close();
978  dataselector_lock.Release();
979  gFile = curfile;
980  }
981  else {
982  cout << "No TEventList to save..." << endl;
983  }
984 }
985 
986 
987 
993 
995 {
996 //
997 // Gets the name of the file where the TEventLists and the KVDataSelectors
998 // are stored.
999 //
1000  static TString fname;
1001  fname = "";
1002  fname =
1003  gEnv->GetValue("DataSelector.directory",
1005  fname += "/";
1006  fname +=
1007  gEnv->GetValue("DataSelector.fileName", "ListOfDataSelector.root");
1008  cout << "List Of Data Selectors : " << fname.Data() << endl;
1009  return fname.Data();
1010 }
1011 
1012 
1013 
1014 
1029 
1031 {
1032  //Call this method in your InitAnalysis() if you want to replace the masses of nuclei
1033  //in each event with masses calculated from the given formula (see KVNucleus::GetAFromZ).
1034  //
1035  //As each event is read, the masses of nuclei with calculated (not measured) masses
1036  //will be replaced with the new value, and the energy of the nucleus will be replaced with
1037  //a new value taking into account the effect of the change in mass on the CsI energy
1038  //calibration (if the particle stops in a CsI detector).
1039  //
1040  //NB: the "CM" frame momenta/energies/angles calculated automatically before your
1041  //Analysis() method is called will be calculated using the new masses and lab energies.
1042  //Any subsequent change to the masses and/or energies you make in Analysis() will not
1043  //change the "CM" momenta. If you change the laboratory energies etc. you must recalculate
1044  //the c.m. momenta by calling e.g. GetEvent()->SetFrame("CM", ... )
1045  SetBit(kChangeMasses);
1046  fNewMassFormula = mass_formula;
1047 }
1048 
1049 
1050 
1051 
1081 
1083 {
1084  //Use this method to set criteria for selecting particles (other than the identification
1085  //or calibration quality codes - see KVINDRAReconEvent::AcceptIDCodes and
1086  //KVINDRAReconEvent::AcceptECodes).
1087  //
1088  //The criteria defined in the KVParticleCondition object will be applied to every
1089  //particle which has the right quality codes and if they are not satisfied the particle's
1090  //"OK" flag will be set to false, i.e. the particle's IsOK() method will return kFALSE,
1091  //and the particle will not be included in iterations such as GetEvent()->GetNextParticle("OK").
1092  //Neither will the particle be included in the evaluation of any global variables or event
1093  //selection criteria (see KVDataSelector).
1094  //
1095  //This method must be called in the user's InitAnalysis() or InitRun() method.
1096  //
1097  //EXAMPLES:
1098  //To include only particles having a time marker between 90 and 110:
1099  //
1100  // KVParticleCondition cd("_NUC_->GetTimeMarker()>=90 && _NUC_->GetTimeMarker()<=110");
1101  // SetParticleConditions( cd );
1102  //
1103  //To include only Z=1 particles having a time marker between 90 and 110, Z>1 particles
1104  //with time markers between 80 and 120:
1105  //
1106  // KVParticleCondition tm1("_NUC_->GetTimeMarker()>=90 && _NUC_->GetTimeMarker()<=110");
1107  // KVParticleCondition tm2("_NUC_->GetTimeMarker()>=80 && _NUC_->GetTimeMarker()<=120");
1108  // KVParticleCondition z1("_NUC_->GetZ()==1");
1109  // KVParticleCondition zgt1("_NUC_->GetZ()>1");
1110  // KVParticleCondition cd = (z1 && tm1) || (zgt1 && tm2);
1111  // SetParticleConditions( cd );
1112  if (!fPartCond) fPartCond = new KVParticleCondition(cond);
1113  else *fPartCond = cond;
1114  //set name of class to which we cast. this is for optimization to work
1115  fPartCond->SetParticleClassName("KVINDRAReconNuc");
1116 }
1117 
1118 
1119 
1120 
1122 
1124 {
1125 
1126  return lhisto;
1127 
1128 }
1129 
1130 
1131 
1132 
1134 
1136 {
1137 
1138  return (TH1*)lhisto->FindObject(histo_name);
1139 
1140 }
1141 
1142 
1143 
1144 
1150 
1152 {
1153 
1154  //Find in the list, if there is an histogram named "sname"
1155  //If not print an error message
1156  //If yes redirect to the right method according to its closest mother class
1157  //to fill it
1158  TH1* h1 = 0;
1159  if ((h1 = GetHisto(sname.Data()))) {
1160  if (h1->InheritsFrom("TH3"))
1161  FillTH3((TH3*)h1, one, two, three, four);
1162  else if (h1->InheritsFrom("TProfile2D"))
1163  FillTProfile2D((TProfile2D*)h1, one, two, three, four);
1164  else if (h1->InheritsFrom("KVDalitzPlot"))
1165  FillKVDalitz((KVDalitzPlot*)h1, one, two, three);
1166  else if (h1->InheritsFrom("TH2"))
1167  FillTH2((TH2*)h1, one, two, three);
1168  else if (h1->InheritsFrom("TProfile"))
1169  FillTProfile((TProfile*)h1, one, two, three);
1170  else if (h1->InheritsFrom("TH1"))
1171  FillTH1(h1, one, two);
1172  else
1173  Warning("FillHisto", "%s -> Classe non prevue ...", lhisto->FindObject(sname.Data())->ClassName());
1174  }
1175  else {
1176  Warning("FillHisto", "%s introuvable", sname.Data());
1177  }
1178 
1179 }
1180 
1181 
1182 
1183 
1185 
1187 {
1188 
1189  h1->Fill(one, two);
1190 
1191 }
1192 
1193 
1194 
1195 
1197 
1199 {
1200 
1201  h1->Fill(one, two, three);
1202 
1203 }
1204 
1205 
1206 
1207 
1209 
1211 {
1212 
1213  h2->Fill(one, two, three);
1214 
1215 }
1216 
1217 
1218 
1219 
1221 
1223 {
1224 
1225  h2->Fill(one, two, three, four);
1226 }
1227 
1228 
1229 
1230 
1232 
1234 {
1235 
1236  h2->FillAsDalitz(one, two, three);
1237 }
1238 
1239 
1240 
1241 
1243 
1245 {
1246 
1247  h3->Fill(one, two, three, four);
1248 }
1249 
1250 
1251 
1252 
1253 
1255 
1257 {
1258 
1259  Warning("CreateHistos", "To be redefined child class");
1260 
1261 }
1262 
1263 
1264 
1265 
1271 
1273 {
1274 
1275  //If no filename is specified, assume that the current directory is writable
1276  //if filename correspond to an already opened file, write in it
1277  //if not open/create it, depending on the option ("recreate" by default)
1278  //and write in it
1279  Bool_t IsCreated = kFALSE;
1280  if (filename == "") {
1281  GetHistoList()->Write();
1282  }
1283  else {
1284  TFile* file = 0;
1285  if (!(file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename.Data()))) {
1286  IsCreated = kTRUE;
1287  file = new TFile(filename.Data(), option);
1288  }
1289  file->cd();
1290  GetHistoList()->Write();
1291  if (IsCreated) file->Close();
1292  }
1293 
1294 }
1295 
1296 
1297 
1298 
1300 
1302 {
1303 
1304  return ltree;
1305 
1306 }
1307 
1308 
1309 
1310 
1312 
1314 {
1315 
1316  return (TTree*)ltree->FindObject(tree_name);
1317 
1318 }
1319 
1320 
1321 
1323 
1325 {
1326 
1327  Warning("CreateTrees", "To be redefined child class");
1328 
1329 }
1330 
1331 
1332 
1333 
1335 
1337 {
1338 
1339  if (sname == "") {
1340  ltree->Execute("Fill", "");
1341  }
1342  else {
1343  TTree* tt = 0;
1344  if ((tt = GetTree(sname.Data()))) {
1345  tt->Fill();
1346  }
1347  else {
1348  Warning("FillTree", "%s introuvable", sname.Data());
1349  }
1350  }
1351 
1352 }
1353 
1354 
1355 
1356 
1359 
1361 {
1362 
1363  //If no filename is specified, assume that the current directory is writable
1364  Bool_t IsCreated = kFALSE;
1365  if (filename == "") {
1366  GetTreeList()->Write();
1367  }
1368  else {
1369  TFile* file = 0;
1370  //if filename correspond to an already opened file, write in it
1371  //if not open/create it, depending on the option ("recreate" by default)
1372  //and write in it
1373  if (!(file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename.Data()))) {
1374  IsCreated = kTRUE;
1375  file = new TFile(filename.Data(), option);
1376  }
1377  file->cd();
1378  GetTreeList()->Write();
1379  if (IsCreated) file->Close();
1380  }
1381 
1382 }
1383 
1384 
1385 
1388 
1389 void KVOldINDRASelector::SetOpt(const Char_t* option, const Char_t* value)
1390 {
1391  //Set a value for an option
1392  KVString tmp(value);
1393  fOptionList.SetValue(option, tmp);
1394 }
1395 
1396 
1397 
1398 
1401 
1403 {
1404  // Returns kTRUE if the option 'opt' has been set
1405 
1406  return fOptionList.HasParameter(opt);
1407 }
1408 
1409 
1410 
1411 
1415 
1417 {
1418  // Returns the value of the option
1419  // Only use after checking existence of option with IsOptGiven(const Char_t* opt)
1420 
1421  return fOptionList.GetTStringValue(opt);
1422 }
1423 
1424 
1425 
1426 
1429 
1431 {
1432  // Removes the option 'opt' from the internal lists, as if it had never been set
1433 
1434  fOptionList.RemoveParameter(opt);
1435 }
1436 
1437 
1438 
1444 
1446 {
1447  // Analyse comma-separated list of options given to TTree::Process
1448  // and store all "option=value" pairs in fOptionList.
1449  // Options can then be accessed using IsOptGiven(), GetOptString(), etc.
1450  // This method is called by Begin
1451 
1452  fOptionList.Clear(); // clear list
1453  KVString option = GetOption();
1454  option.Begin(",");
1455  while (!option.End()) {
1456 
1457  KVString opt = option.Next();
1458  opt.Begin("=");
1459  KVString param = opt.Next();
1460  KVString val = opt.Next();
1461  while (!opt.End()) {
1462  val += "=";
1463  val += opt.Next();
1464  }
1465 
1466  SetOpt(param.Data(), val.Data());
1467  }
1468 
1469  fOptionList.Print();
1470 }
1471 
1472 
int Int_t
unsigned int UInt_t
#define SafeDelete(p)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
R__EXTERN TEnv * gEnv
#define gFile
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
#define gROOT
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
static const Char_t * FindFile(const Char_t *search, TString &wfil)
Definition: KVBase.cpp:1030
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:772
Factory class for generating skeleton files for new classes.
void GenerateCode()
Generate header and implementation file for currently-defined class.
void AddImplIncludeFile(const Char_t *filename)
Fill 3D observables in a dalitz plot ,.
Definition: KVDalitzPlot.h:28
Int_t FillAsDalitz(Double_t a1, Double_t a2, Double_t a3)
virtual void postEndRun()
void DoStatusUpdate(Long64_t nevents) const
Print infos on events treated, disk usage, memory usage.
virtual void preInitAnalysis()
virtual void postAnalysis()
virtual Bool_t CheckStatusUpdateInterval(Long64_t nevents) const
virtual void preAnalysis()
virtual void preEndRun()
virtual void postInitRun()
static Bool_t AbortProcessingLoop()
virtual void postEndAnalysis()
virtual void preEndAnalysis()
void DeleteBatchStatusFile() const
Delete batch status file (and backup - '.bak') for batch job.
virtual void preInitRun()
virtual void RegisterUserClass(TObject *)
virtual void postInitAnalysis()
Class handling event lists for KVOldINDRASelector analysis of data chains.
Pilots user analysis of experimental data.
#define KVGVLIST_OPTIMIZE_GVLIST
Definition: KVGVList.h:227
Extended version of ROOT THashList.
Definition: KVHashList.h:29
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:123
Former base analysis class for INDRA data.
virtual const Char_t * GetDataSelectorFileName(void)
virtual void WriteTreeToFile(KVString filename="FileFromKVOldINDRASelector.root", Option_t *option="recreate")
If no filename is specified, assume that the current directory is writable.
virtual void UnsetOpt(const Char_t *opt)
Removes the option 'opt' from the internal lists, as if it had never been set.
void FillTH3(TH3 *h3, Double_t one, Double_t two, Double_t three, Double_t four)
void SlaveBegin(TTree *tree) override
virtual TString GetOpt(const Char_t *option) const
TH1 * GetHisto(const Char_t *name)
void FillTH2(TH2 *h2, Double_t one, Double_t two, Double_t three)
virtual void AddGV(KVVarGlob *)
void Terminate() override
void FillHisto(KVString sname, Double_t one, Double_t two=1, Double_t three=1, Double_t four=1)
virtual void SaveCurrentDataSelection(void)
virtual void RecalculateGlobalVariables()
static KVString fBranchName
name of branch which contains KVINDRAReconEvent objects in the TTree
Bool_t Process(Long64_t entry) override
virtual KVGVList * GetGVList(void)
void FillKVDalitz(KVDalitzPlot *h2, Double_t one, Double_t two, Double_t three)
virtual void SetParticleConditions(const KVParticleCondition &)
virtual Bool_t AtEndOfRun(void)
void FillTProfile2D(TProfile2D *h2, Double_t one, Double_t two, Double_t three, Double_t four)
virtual void SetGVList(KVGVList *list)
handling global variables for analysis
void FillTree(KVString sname="")
TTree * GetTree(const Char_t *name)
void FillTH1(TH1 *h1, Double_t one, Double_t two)
virtual void SetOpt(const Char_t *option, const Char_t *value)
Set a value for an option.
void SlaveTerminate() override
Function called at the end of the event loop in each PROOF slave.
virtual void ChangeFragmentMasses(UInt_t mass_formula)
virtual Long64_t GetTreeEntry() const
void FillTProfile(TProfile *h1, Double_t one, Double_t two, Double_t three)
static void Make(const Char_t *kvsname="MyOwnKVOldINDRASelector")
Automatic generation of KVOldINDRASelector-derived class for KaliVeda analysis.
void Begin(TTree *tree) override
virtual Bool_t IsOptGiven(const Char_t *option)
Returns kTRUE if the option 'opt' has been set.
virtual void LoadDataSelector(void)
virtual KVVarGlob * GetGV(const Char_t *) const
virtual void WriteHistoToFile(KVString filename="FileFromKVOldINDRASelector.root", Option_t *option="recreate")
void Init(TTree *tree) override
virtual void BuildEventList(void)
Bool_t Notify() override
void SetIsOK(Bool_t flag=kTRUE)
Definition: KVParticle.cpp:371
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
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
void SetParticleClassName(const Char_t *cl)
Base class for all global variable implementations.
Definition: KVVarGlob.h:233
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Bool_t InheritsFrom(const char *cl) const override
virtual void SetOwner(Bool_t enable=kTRUE)
T * Get(const char *namecycle)
virtual const char * GetValue(const char *name, const char *dflt) const
virtual Long64_t GetEntry(Int_t index) const
virtual Int_t GetN() const
void Close(Option_t *option="") override
TObject * FindObject(const char *name) const override
virtual Int_t Fill(const char *name, Double_t w)
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
virtual Int_t Fill(const char *namex, const char *namey, const char *namez, Double_t w)
virtual void SaveSource(const char *filename)
virtual Int_t ReadFile(const char *filename)
virtual void SetTitle(const char *title="")
const char * GetName() const override
virtual void SetName(const char *name)
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
virtual TObject * FindObject(const char *name) const
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
virtual Bool_t InheritsFrom(const char *classname) const
Longptr_t ExecPlugin(int nargs)
virtual Int_t Fill(const char *namex, const char *namey, Double_t z, Double_t w=1.)
const char * Data() const
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
virtual const char * WorkingDirectory()
long long Long64_t
TH1F * h1
CPYCPPYY_EXTERN bool Exec(const std::string &cmd)
str tree_name
void Error(const char *location, const char *fmt,...)
void Info(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
Add
auto * tt
ClassImp(TPyArg)