KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVOldINDRASelector.cpp
Go to the documentation of this file.
1 #define KVOldINDRASelector_cxx
2 #include "KVOldINDRASelector.h"
3 #include "TH2.h"
4 #include "TStyle.h"
5 #include "TString.h"
6 #include "TEnv.h"
7 #include "TSystem.h"
8 #include "TClass.h"
9 #include "TMacro.h"
10 #include "TROOT.h"
11 #include "KVBase.h"
12 #include "KVDataSet.h"
13 #include "KVAvailableRunsFile.h"
14 #include "TPluginManager.h"
15 #include "KVClassFactory.h"
16 #include "KVDataAnalyser.h"
17 #include "KVDataAnalysisTask.h"
18 #include "KVINDRAReconNuc.h"
20 
21 #include <KVINDRADB.h>
22 
23 KVString KVOldINDRASelector::fBranchName = "INDRAReconEvent";
24 using namespace std;
25 
27 
28 
29 
30 
31 
35 {
36  //ctor
37  fChain = 0;
38  callnotif = 0;
39  gvlist = 0; // Global variable list set to nul.
40  lhisto = new KVHashList();
41  ltree = new KVHashList();
42  //create stopwatch
43  fTimer = new TStopwatch;
44  // event list
45  fEvtList = 0;
46  fTEVLexist = 0;
47  fKVDataSelector = 0;
48  fDataSelector = "";
49  needToSelect = kFALSE;
50  needToCallEndRun = kFALSE;
51  fCurrentRun = 0;
52  fPartCond = 0;
53  data = 0;
54  dataselector_lock.SetTimeout(60); // 60-second timeout in case of problems
55  dataselector_lock.SetSuspend(5); // suspension after timeout
56  dataselector_lock.SetSleeptime(1); // try lock every second
57 }
58 
59 
60 
65 
66 KVOldINDRASelector::~KVOldINDRASelector()
67 {
68  //dtor
69  //delete global variable list if it belongs to us, i.e. if created by a
70  //call to GetGVList
71  if (gvlist && TestBit(kDeleteGVList)) {
72  delete gvlist;
73  gvlist = 0;
74  ResetBit(kDeleteGVList);
75  }
76  delete fTimer;
77  SafeDelete(fPartCond);
78  lhisto->Clear();
79  delete lhisto;
80  ltree->Clear();
81  delete ltree;
82 }
83 
84 
85 
87 
89 {
90  if (fChain) return; //Init has already been called
91 
92  //delete any status file from previous job with same name from launch directory
94 
95  if (!tree) return;
96 
97  // Set branch addresses
98  fChain = tree;
99  fChain->SetMakeClass(1);
100 
101  if (fChain->InheritsFrom("TChain"))
102  fTreeOffset = ((TChain*) fChain)->GetTreeOffset();
103  else
104  fTreeOffset = 0;
105 
106  data = 0;
107  b_data = 0;
108  fChain->SetBranchAddress(fBranchName.Data(), &data, &b_data);
109 
110 //
111 // Builds a TEventList by adding the contents of the lists for each run
112 //
113  BuildEventList();
114  if (fKVDataSelector) { // Init of the KVDataSelector if needed
115  fKVDataSelector->Init();
116  }
117  // tell the data analyser who we are
120  InitAnalysis(); //user initialisations for analysis
122 
123  if (gvlist) {
124  gvlist->Init();
125  }
126 }
127 
128 
129 
133 
135 {
136  // Called when loading a new file.
137  // Get branch pointers.
138 
139  cout << "Analyse du fichier " << fChain->GetCurrentFile()->GetName()
140  << " : " << fChain->GetTree()->GetEntries() << endl;
141  NbTreeEntry = (Int_t) fChain->GetTree()->GetEntries();
142  fCurrentTreeNumber = fChain->GetTreeNumber();
143 
144  needToCallEndRun = kTRUE;
145 
146  if (fEvtList)
147  needToSelect = !(fTEVLexist[fCurrentTreeNumber]);
148  else
149  needToSelect = kFALSE;
150 
151  gDataAnalyser->preInitRun(); // will initialize fCurrentRun
152 
153  if (needToSelect) {
154  if (!fKVDataSelector) {
155  LoadDataSelector();
156  }
157  fKVDataSelector->Reset(fCurrentRun->GetNumber());
158  cout << " Building new TEventList : " << fKVDataSelector->
159  GetTEventList()->GetName()
160  << endl;
161  }
162 
163  InitRun(); //user initialisations for run
165  return kTRUE;
166 }
167 
168 
169 
174 
176 {
177  // Function called before starting the event loop.
178  // When running with PROOF Begin() is only called in the client.
179 
180  // Get the option and the name of the DataSelector if needed
181  ParseOptions();
182 
183  if (IsOptGiven("DataSelector")) SetDataSelector(GetOpt("DataSelector"));
184  else
185  SetDataSelector();
186 
187  totentry = 0;
188 
189  //start stopwatch, after first resetting it (in case this is not the first time the analysis is run)
190  fTimer->Start(kTRUE);
191 }
192 
193 
194 
201 
203 {
204  // Function called before starting the event loop.
205  // When running with PROOF SlaveBegin() is called in each slave
206  // Initialize the tree branches.
207 
208  /* Init(tree);
209 
210  TString option = GetOption();
211  */
212 }
213 
214 
215 #ifdef __WITHOUT_TSELECTOR_LONG64_T
216 
229 
230 Bool_t KVOldINDRASelector::Process(Int_t entry) //for ROOT versions < 4.01/01
231 #else
232 Bool_t KVOldINDRASelector::Process(Long64_t entry) //for ROOT versions > 4.00/08
233 #endif
234 {
235  //Here the event is read into memory and checks are made on the number
236  //of events read.
237  //Particles not having the correct identification and calibration quality codes
238  //are excluded from the analysis (IsOK()=kFALSE).
239  //Particles which do not satisfy the additional selection criteria set with
240  //SetParticleConditions() are excluded from the analysis (IsOK()=kFALSE).
241  //If ChangeFragmentMasses() was called in InitAnalysis() or InitRun()
242  //then the non-measured fragment masses will be recalculated with the
243  //new mass formula and laboratory energies adjusted accordingly.
244  //Then the reaction CM momenta of all "OK" particles are calculated and
245  //the list of global variables (if one is defined) is filled.
246 
248  // abort requested by batch system
249  Abort(Form("Aborting analysis after %d events", totentry), kAbortFile);
250  return kFALSE;
251  }
252 
253  fTreeEntry = entry;
254 
256 
257  // read event
258  fChain->GetTree()->GetEntry(fTreeEntry);
259  // read raw data associated to event
261 
262  //additional selection criteria ?
263  if (fPartCond) {
264  KVNucleus* part = 0;
265  while ((part = (KVNucleus*)GetEvent()->GetNextParticle("ok"))) {
266 
267  part->SetIsOK(fPartCond->Test(part));
268 
269  }
270  }
271 
272  //change masses ?
273  if (TestBit(kChangeMasses)) GetEvent()->ChangeFragmentMasses(fNewMassFormula);
274 
275  totentry++;
276 
277  //calculate momenta of particles in reaction cm frame
278  if (fCurrentRun->GetSystem() && fCurrentRun->GetSystem()->GetKinematics()) {
279 
280  GetEvent()->SetFrame("CM",
281  fCurrentRun->GetSystem()->GetKinematics()->GetCMVelocity());
282 
283  }
284 
285  RecalculateGlobalVariables();
286 
287 
288  Bool_t ok_anal = kTRUE;
289 
290  if (needToSelect) {
291  ok_anal = fKVDataSelector->ProcessCurrentEntry(); //Data Selection and user analysis
292  }
293  else
294  ok_anal = Analysis(); //user analysis
296 
297  // Testing whether EndRun() should be called
298  if (AtEndOfRun()) {
299  TString mes("End of run after ");
300  mes += (totentry);
301  mes += " events.";
302  Info("Process", "%s", mes.Data());
303 
305  EndRun(); //user routine end of run
307  needToCallEndRun = kFALSE;
308 
309  // save the new Built TEventList
310  if (needToSelect) {
311  SaveCurrentDataSelection();
312  needToSelect = kFALSE;
313  }
314  }
315 
316  return ok_anal;
317 }
318 
319 
320 
323 
325 {
326  // Function called at the end of the event loop in each PROOF slave.
327 
328 
329 }
330 
331 
332 
336 
338 {
339  // Function called at the end of the event loop.
340  // When running with PROOF Terminate() is only called in the client.
341 
342  fTimer->Stop();//stop stopwatch straight away so that 'Events/CPU sec' etc. only
343  //includes time actually spent analysing data
344 
345  if (needToCallEndRun) {
347  EndRun();
349  }
350 
351  if (needToSelect) {
352  SaveCurrentDataSelection();
353  }
354 
355  cout << endl << " ====================== END ====================== " <<
356  endl << endl;
357  cout << " Total number of events read = " << totentry << endl;
358  cout << " Real time = " << fTimer->RealTime() << " sec." << endl;
359  cout << " CPU time = " << fTimer->CpuTime() << " sec." << endl;
360  cout << " Events/Real sec. = " << totentry /
361  fTimer->RealTime() << endl;
362  cout << " Events/CPU sec. = " << totentry /
363  fTimer->CpuTime() << endl;
364  cout << endl << " ====================== END ====================== " <<
365  endl << endl;
366 
367  if (fEvtList) {
368  fChain->SetEventList(0);
369  delete fEvtList;
370  fEvtList = 0;
371  }
372 
374  EndAnalysis(); //user end of analysis routine
376 
377  //delete job status file from $HOME directory
379 }
380 
381 
382 
385 
386 void KVOldINDRASelector::Make(const Char_t* kvsname)
387 {
388  // Automatic generation of KVOldINDRASelector-derived class for KaliVeda analysis
389  KVClassFactory cf(kvsname, "User analysis class", "KVOldINDRASelector", kTRUE);
390  cf.AddImplIncludeFile("KVINDRAReconNuc.h");
391  cf.AddImplIncludeFile("KVBatchSystem.h");
392  cf.AddImplIncludeFile("KVINDRA.h");
393  cf.GenerateCode();
394 }
395 
396 
397 
402 
404 {
405  //Use a user-defined list of global variables for the analysis.
406  //In this case it is the user's responsibility to delete the list
407  //at the end of the analysis.
408  gvlist = list;
409 }
410 
411 
412 
417 
419 {
420  //Access to the internal list of global variables
421  //If the list does not exist, it is created.
422  //In this case it will be automatically deleted with the KVOldINDRASelector object.
423  if (!gvlist) {
424  gvlist = new KVGVList;
425  SetBit(kDeleteGVList);
426  }
427  return gvlist;
428 }
429 
430 
431 
435 
437 {
438  //Add the global variable "vg" to the list of variables for the analysis.
439  //This is equivalent to GetGVList()->Add( vg ).
440  if (!vg)
441  Error("AddGV(KVVarGlob*)", "KVVarGlob pointer is null");
442  else
443  GetGVList()->Add(vg);
444 }
445 
446 
447 
452 
454 {
455  //Access the global variable with name "name" in the list of variables
456  //for the analysis.
457  //This is equivalent to GetGVList()->GetGV( name ).
458 
459  return (const_cast < KVOldINDRASelector* >(this)->GetGVList()->GetGV(name));
460 }
461 
462 
463 
491 
493  const Char_t* name)
494 {
495  //Add a global variable to the list of variables for the analysis.
496  //
497  //"class_name" must be the name of a valid class inheriting from KVVarGlob, e.g. any of the default global
498  //variable classes defined as part of the standard KaliVeda package (in libKVvVarGlob.so). See
499  //"Class Reference" page on website for the available classes (listed by category under "Global Variables: ...").
500  //
501  //USER-DEFINED GLOBAL VARIABLES
502  //The user may use her own global variables in an analysis class, without having to add them to the main libraries.
503  //If the given class name is not known, it is assumed to be a user-defined class and we attempt to compile and load
504  //the class from the user's source code. For this to work, the user must:
505  //
506  // (1) add to the ROOT macro path the directory where her class's source code is kept, e.g. in $HOME/.rootrc
507  // add the following line:
508  //
509  // +Unix.*.Root.MacroPath: $(HOME)/myVarGlobs
510  //
511  // (2) for each user-defined class, add a line to $HOME/.kvrootrc to define a "plugin". E.g. for a class called MyNewVarGlob,
512  //
513  // +Plugin.KVVarGlob: MyNewVarGlob MyNewVarGlob MyNewVarGlob.cpp+ "MyNewVarGlob()"
514  //
515  // It is assumed that MyNewVarGlob.h and MyNewVarGlob.cpp will be found in $HOME/myVarGlobs (in this example).
516  //
517  //"name" is a unique name for the new global variable object which will be created and added to the internal
518  //list of global variables. This name can be used to retrieve the object (see GetGV) in the user's analysis.
519  //
520  //Returns pointer to new global variable object in case more than the usual default initialisation is necessary.
521 
522  KVVarGlob* vg = 0;
523  TClass* clas = gROOT->GetClass(class_name);
524  if (!clas) {
525  //class not in dictionary - user-defined class ? Look for plugin.
526  TPluginHandler* ph = KVBase::LoadPlugin("KVVarGlob", class_name);
527  if (!ph) {
528  //not found
529  Error("AddGV(const Char_t*,const Char_t*)",
530  "Called with class_name=%s.\nClass is unknown: not in standard libraries, and plugin (user-defined class) not found",
531  class_name);
532  return 0;
533  }
534  else {
535  vg = (KVVarGlob*) ph->ExecPlugin(0);
536  }
537  }
538  else if (!clas->InheritsFrom("KVVarGlob")) {
539  Error("AddGV(const Char_t*,const Char_t*)",
540  "%s is not a valid class deriving from KVVarGlob.",
541  class_name);
542  return 0;
543  }
544  else {
545  vg = (KVVarGlob*) clas->New();
546  }
547  vg->SetName(name);
548  AddGV(vg);
549  return vg;
550 }
551 
552 
553 
554 
583 
585 {
586  //Use this method if you change e.g. the acceptable particle identification codes in your
587  //Analysis() method and want to recalculate the values of all global variables
588  //for your new selection.
589  //
590  //WARNING: the global variables are calculated automatically for you for each event
591  //before method Analysis() is called. In order for the correct particles to be included in
592  //this calculation, make sure that at the END of Analysis() you reset the selection
593  //criteria.
594  //
595  //i.e. if in your InitAnalysis() you have:
596  // GetEvent()->AcceptIDCodes(kIDCode2|kIDCode3|kIDCode4);
597  //
598  //at the beginning of Analysis() the variables have been calculated for all particles
599  //with codes 2-4. If you store these values somewhere and then change the code mask:
600  //
601  // GetEvent()->AcceptIDCodes(kIDCode2|kIDCode3|kIDCode4|kIDCode6);
602  //
603  //you can recalculate the global variable list for particles with codes 2-4 & 6:
604  //
605  // RecalculateGlobalVariables();
606  //
607  //then at the end of Analysis(), after storing the new values of the variables, you
608  //should reset the code mask:
609  //
610  // GetEvent()->AcceptIDCodes(kIDCode2|kIDCode3|kIDCode4);
611  //
612  //which will be used for the next event read for processing.
613 
614  if (gvlist) gvlist->CalculateGlobalVariables(GetEvent());
615 }
616 
617 
618 
619 #ifdef __WITHOUT_TSELECTOR_LONG64_T
620 
624 
626 #else
628 #endif
629 {
630  //During event analysis (i.e. inside the Analysis() method), this gives the current TTree
631  //entry number, in other words the argument passed to TSelector::Process(Long64_t entry).
632 
633  return fTreeEntry;
634 }
635 
636 
637 
643 
645 {
646 //
647 // Builds the event list of the TChain by adding the event lists of each TTree.
648 // The event list contain the entry number of the TChain
649 //
650 
651  if (fEvtList) {
652  fEvtList->Reset();
653  delete fEvtList;
654  fEvtList = 0;
655  }
656  if (fKVDataSelector) {
657  delete fKVDataSelector;
658  fKVDataSelector = 0;
659  }
660  if (fTEVLexist) {
661  delete[]fTEVLexist;
662  fTEVLexist = 0;
663  }
664 
665  if (fDataSelector.Length()) {
666  Info("BuildEventList()",
667  "Building TEventList for the KVDataSelector \"%s\".",
668  GetDataSelector());
669  TObjArray* lof = 0;
670  Long64_t* toff = 0;
671  if (fTreeOffset) {
672  cout << "Analysis from a chain of trees." << endl;
673  lof = ((TChain*) fChain)->GetListOfFiles();
674  toff = fTreeOffset;
675  }
676  else {
677  cout << "Analysis from a single tree." << endl;
678  lof = new TObjArray();
679  lof->
680  Add(new
681  TNamed("SingleRun", fChain->GetCurrentFile()->GetName()));
682  toff = new Long64_t[2];
683  toff[0] = 0;
684  toff[1] = fChain->GetEntries();
685  }
686 
687  fEvtList =
688  new TEventList("chainEventList", "TEvent list for this TChain");
689 
690 
691  // Opening the file which contains the TEventLists
692  TString searchname(GetDataSelectorFileName());
693  TString fname = searchname;
694  cout << "File to open : " << fname.Data() << endl;
695  TFile* fileDataSelector = 0;
696  if (KVBase::FindFile("", searchname)) {
697  //get lock on file to avoid interference with other processes
698  if (dataselector_lock.Lock(fname.Data())) fileDataSelector = new TFile(fname.Data());
699  }
700  else {
701  cout << "The file \"" << fname.
702  Data() << "\" does not exist." << endl;
703  }
704 
705  fTEVLexist = new Bool_t[lof->GetEntries()];
706  for (Int_t tn = 0; tn < lof->GetEntries(); tn++) {
707  fTEVLexist[tn] = kFALSE;
708  TString fname(((TNamed*) lof->At(tn))->GetTitle());
709  cout << fname.Data() << endl;
710  Int_t nrun = dynamic_cast<KVDataSetAnalyser*>(gDataAnalyser)->GetRunNumberFromFileName(fname.Data());
711  if (nrun) {
712  cout << "Numero de run " << nrun << endl;
713  cout << "Recherche de " << Form("%s_run%d;1",
714  GetDataSelector(),
715  nrun) << endl;
716  TEventList* revtList = 0;
717  if (fileDataSelector) {
718  revtList =
719  (TEventList*) fileDataSelector->
720  Get(Form("%s_run%d;1", GetDataSelector(), nrun));
721  }
722  if (revtList) {
723  for (Int_t i = 0; i < revtList->GetN(); i++) {
724  fEvtList->Enter(fTreeOffset[tn] + revtList->GetEntry(i));
725  }
726  fTEVLexist[tn] = kTRUE;
727  }
728  else {
729  cout << "Liste introuvable..." << endl;
730  for (Int_t i = fTreeOffset[tn]; i < fTreeOffset[tn + 1];
731  i++) {
732  fEvtList->Enter(i);
733  }
734  }
735  }
736  else {
737  cout << "Run inconnu..." << endl;
738  }
739  }
740  if (fileDataSelector) {
741  cout << "Closing " << fileDataSelector->GetName() << endl;
742  fileDataSelector->Close();
743  dataselector_lock.Release();//unlock file
744  }
745 
746  if (!fTreeOffset) {
747  delete[]toff;
748  lof->SetOwner(kTRUE);
749  delete lof;
750  }
751  // Check if the TEventList is empty. If yes, all events will be read
752  if (!fEvtList->GetN()) {
753  Warning("BuildEventList()", "The TEventList is empty...");
754  delete fEvtList;
755  fEvtList = 0;
756  }
757  }
758  fChain->SetEventList(fEvtList);
759 }
760 
761 
762 
767 
769 {
770 //
771 // Check whether the end of run is reached for the current tree
772 //
773 
774  Bool_t ok = (fTreeEntry + 1 == fChain->GetTree()->GetEntries());
775 
776  if (fEvtList) {
777  Long64_t globEntry = 0;
778  if (fTreeOffset)
779  globEntry = ((TChain*) fChain)->GetChainEntryNumber(fTreeEntry);
780  else
781  globEntry = fTreeEntry;
782  Int_t index = fEvtList->GetIndex(globEntry);
783  Long64_t nextEntry = (fEvtList->GetEntry(index + 1));
784  ok = ok || (nextEntry == -1);
785  if (fTreeOffset) {
786  ok = ok || (nextEntry >= fTreeOffset[fCurrentTreeNumber + 1]);
787  }
788  }
789 
790  return ok;
791 }
792 
793 
794 
799 
801 {
802 //
803 // Set the pointer of the KVDataSelector according to its name
804 //
805  cout << "Loading KVDataSelector..." << endl;
806  Bool_t deleteSources = kFALSE;
807  if (fDataSelector.Length()) {
808  fKVDataSelector = 0;
809  TClass* clas = gROOT->GetClass(fDataSelector.Data());
810  cout << clas << " / " << fDataSelector.Data() << endl;
811  if (!clas) {
812  //if the class is not present, first check whether the declaration and
813  //the implementation files are present in the user's working directory
814  TString fileC(Form("%s.cpp", fDataSelector.Data()));
815  TString fileh(Form("%s.h", fDataSelector.Data()));
816 
817 #ifdef __WITHOUT_TMACRO
818  if (gSystem->AccessPathName(fileC.Data()) || gSystem->AccessPathName(fileh.Data())) {
819  Warning("LoadDataSelector(void)",
820  Form
821  ("No implementation and/or declaration file found for \"%s\".",
822  fDataSelector.Data()));
823 #else
824  TMacro mC;
825  if (!mC.ReadFile(fileC.Data()) || !mC.ReadFile(fileh.Data())) {
826 
827  // Load .cpp and .h files from the TEventList's root file
828  TString searchname(GetDataSelectorFileName());
829  TString fname = searchname;
830  TFile* fileDataSelector = 0;
831 
832  if (KVBase::FindFile("", fname)) {
833  if (dataselector_lock.Lock(fname.Data())) fileDataSelector = new TFile(fname.Data());
834  }
835  else {
836  cout << "The file \"" << fname.
837  Data() << "\" does not exist." << endl;
838  }
839  TMacro* macC = 0;
840  TMacro* mach = 0;
841  if (fileDataSelector) {
842  macC = (TMacro*) fileDataSelector->Get(fileC.Data());
843  mach = (TMacro*) fileDataSelector->Get(fileh.Data());
844  }
845  if (macC && mach) {
846  macC->SaveSource(fileC.Data());
847  cout << fileC.Data() << " re-generated" << endl;
848  mach->SaveSource(fileh.Data());
849  cout << fileh.Data() << " re-generated." << endl;
850  deleteSources = kTRUE;
851  }
852  else {
853  Warning("LoadDataSelector(void)",
854  "No implementation and/or declaration file found for \"%s\".",
855  fDataSelector.Data());
856  }
857  if (fileDataSelector) {
858  fileDataSelector->Close();
859  dataselector_lock.Release();
860  }
861 #endif
862  }
863  else {
864  cout << "Files " << fileC.Data() << " and " << fileh.Data() <<
865  " found." << endl;
866  }
867  //class not in dictionary - user-defined class ? Add a plugin.
868  gROOT->GetPluginManager()->AddHandler("KVDataSelector",
869  fDataSelector.Data(),
870  fDataSelector.Data(),
871  Form("%s.cpp+",
872  fDataSelector.Data()),
873  Form("%s()",
874  fDataSelector.Data()));
875  TPluginHandler* ph =
876  KVBase::LoadPlugin("KVDataSelector", fDataSelector.Data());
877  if (!ph) {
878  //not found
879  Error("LoadDataSelector(void)",
880  "Called with class_name=%s.\nClass is unknown: not in standard libraries, and plugin (user-defined class) not found",
881  fDataSelector.Data());
882  }
883  else {
884  fKVDataSelector = (KVDataSelector*) ph->ExecPlugin(0);
885  fKVDataSelector->SetKVSelector(this);
886  cout << "Apres Plugin " << fKVDataSelector->IsA()->
887  GetName() << " : " << fKVDataSelector->
888  GetKVSelector() << endl;
889  }
890 
891  }
892  else if (!clas->InheritsFrom("KVDataSelector")) {
893  Error("LoadDataSelector(void)",
894  "%s is not a valid class deriving from KVDataSelector.",
895  fDataSelector.Data());
896  }
897  else {
898  fKVDataSelector = (KVDataSelector*) clas->New();
899  fKVDataSelector->SetKVSelector(this);
900  cout << "Apres clas->New() " << fKVDataSelector->IsA()->
901  GetName() << " : " << fKVDataSelector->
902  GetKVSelector() << endl;
903  }
904  if (deleteSources) {
905  cout << "Removing files \"" << fDataSelector.
906  Data() << "*.*\" ..." << endl;
907  gSystem->
908  Exec(Form
909  ("rm %s.[c,h]*", fDataSelector.Data()));
910  }
911  }
912  else {
913  fKVDataSelector = 0;
914  }
915  if (fKVDataSelector)
916  fKVDataSelector->Init();
917 }
918 
919 
920 
925 
927 {
928 //
929 // Save the newly built TEventList in the DataSelection root file
930 //
931  if (fKVDataSelector) {
932  TFile* curfile = gFile;
933  TString option;
934  TString searchname(GetDataSelectorFileName());
935  TString fname = searchname;
936  if (KVBase::FindFile("", searchname)) {
937  option = "update";
938  }
939  else {
940  option = "recreate";
941  }
942  cout << "File to open : " << fname.Data() << " : " << option.
943  Data() << endl;
944  TFile* fileDataSelector = 0;
945  if (dataselector_lock.Lock(fname.Data())) fileDataSelector = new TFile(fname.Data(), option.Data());
946  if (!fileDataSelector || (fileDataSelector && fileDataSelector->IsZombie())) {
947  Error("SaveCurrentDataSelection(void)",
948  "Opening the file \"%s\" with the option \"%s\" is not possible.\nNothing saved.",
949  fname.Data(), option.Data());
950  gFile = curfile;
951  return;
952  }
953  cout << "Saving the TEventList \"" << fKVDataSelector->
954  GetTEventList()->GetName() << "\"..." << endl;
955  cout << fKVDataSelector->GetTEventList()->
956  GetN() << " entries selected." << endl;
957  fKVDataSelector->GetTEventList()->Write();
958 
959 #ifndef __WITHOUT_TMACRO
960  TObject
961  * oC =
962  fileDataSelector->
963  Get(Form("%s.cpp;1", fKVDataSelector->IsA()->GetName()));
964  TObject* oh =
965  fileDataSelector->
966  Get(Form("%s.h;1", fKVDataSelector->IsA()->GetName()));
967  if (!oC || !oh) {
968  cout << "Saving the source files..." << endl;
969  TMacro mC(Form("%s.cpp", fKVDataSelector->IsA()->GetName()));
970  mC.SetName(Form("%s.cpp", fKVDataSelector->IsA()->GetName()));
971  mC.SetTitle(Form
972  ("Implementation file for the KVDataSelector \"%s\".",
973  fKVDataSelector->IsA()->GetName()));
974  mC.Write();
975  TMacro mh(Form("%s.h", fKVDataSelector->IsA()->GetName()));
976  mh.SetName(Form("%s.h", fKVDataSelector->IsA()->GetName()));
977  mh.SetTitle(Form
978  ("Declaration file for the KVDataSelector \"%s\".",
979  fKVDataSelector->IsA()->GetName()));
980  mh.Write();
981  }
982 #endif
983 
984  cout << "Done" << endl;
985  fileDataSelector->Close();
986  dataselector_lock.Release();
987  gFile = curfile;
988  }
989  else {
990  cout << "No TEventList to save..." << endl;
991  }
992 }
993 
994 
995 
1001 
1003 {
1004 //
1005 // Gets the name of the file where the TEventLists and the KVDataSelectors
1006 // are stored.
1007 //
1008  static TString fname;
1009  fname = "";
1010  fname =
1011  gEnv->GetValue("DataSelector.directory",
1013  fname += "/";
1014  fname +=
1015  gEnv->GetValue("DataSelector.fileName", "ListOfDataSelector.root");
1016  cout << "List Of Data Selectors : " << fname.Data() << endl;
1017  return fname.Data();
1018 }
1019 
1020 
1021 
1022 
1037 
1039 {
1040  //Call this method in your InitAnalysis() if you want to replace the masses of nuclei
1041  //in each event with masses calculated from the given formula (see KVNucleus::GetAFromZ).
1042  //
1043  //As each event is read, the masses of nuclei with calculated (not measured) masses
1044  //will be replaced with the new value, and the energy of the nucleus will be replaced with
1045  //a new value taking into account the effect of the change in mass on the CsI energy
1046  //calibration (if the particle stops in a CsI detector).
1047  //
1048  //NB: the "CM" frame momenta/energies/angles calculated automatically before your
1049  //Analysis() method is called will be calculated using the new masses and lab energies.
1050  //Any subsequent change to the masses and/or energies you make in Analysis() will not
1051  //change the "CM" momenta. If you change the laboratory energies etc. you must recalculate
1052  //the c.m. momenta by calling e.g. GetEvent()->SetFrame("CM", ... )
1053  SetBit(kChangeMasses);
1054  fNewMassFormula = mass_formula;
1055 }
1056 
1057 
1058 
1059 
1089 
1091 {
1092  //Use this method to set criteria for selecting particles (other than the identification
1093  //or calibration quality codes - see KVINDRAReconEvent::AcceptIDCodes and
1094  //KVINDRAReconEvent::AcceptECodes).
1095  //
1096  //The criteria defined in the KVParticleCondition object will be applied to every
1097  //particle which has the right quality codes and if they are not satisfied the particle's
1098  //"OK" flag will be set to false, i.e. the particle's IsOK() method will return kFALSE,
1099  //and the particle will not be included in iterations such as GetEvent()->GetNextParticle("OK").
1100  //Neither will the particle be included in the evaluation of any global variables or event
1101  //selection criteria (see KVDataSelector).
1102  //
1103  //This method must be called in the user's InitAnalysis() or InitRun() method.
1104  //
1105  //EXAMPLES:
1106  //To include only particles having a time marker between 90 and 110:
1107  //
1108  // KVParticleCondition cd("_NUC_->GetTimeMarker()>=90 && _NUC_->GetTimeMarker()<=110");
1109  // SetParticleConditions( cd );
1110  //
1111  //To include only Z=1 particles having a time marker between 90 and 110, Z>1 particles
1112  //with time markers between 80 and 120:
1113  //
1114  // KVParticleCondition tm1("_NUC_->GetTimeMarker()>=90 && _NUC_->GetTimeMarker()<=110");
1115  // KVParticleCondition tm2("_NUC_->GetTimeMarker()>=80 && _NUC_->GetTimeMarker()<=120");
1116  // KVParticleCondition z1("_NUC_->GetZ()==1");
1117  // KVParticleCondition zgt1("_NUC_->GetZ()>1");
1118  // KVParticleCondition cd = (z1 && tm1) || (zgt1 && tm2);
1119  // SetParticleConditions( cd );
1120  if (!fPartCond) fPartCond = new KVParticleCondition(cond);
1121  else *fPartCond = cond;
1122  //set name of class to which we cast. this is for optimization to work
1123  fPartCond->SetParticleClassName("KVINDRAReconNuc");
1124 }
1125 
1126 
1127 
1128 
1130 
1132 {
1133 
1134  return lhisto;
1135 
1136 }
1137 
1138 
1139 
1140 
1142 
1144 {
1145 
1146  return (TH1*)lhisto->FindObject(histo_name);
1147 
1148 }
1149 
1150 
1151 
1152 
1158 
1160 {
1161 
1162  //Find in the list, if there is an histogram named "sname"
1163  //If not print an error message
1164  //If yes redirect to the right method according to its closest mother class
1165  //to fill it
1166  TH1* h1 = 0;
1167  if ((h1 = GetHisto(sname.Data()))) {
1168  if (h1->InheritsFrom("TH3"))
1169  FillTH3((TH3*)h1, one, two, three, four);
1170  else if (h1->InheritsFrom("TProfile2D"))
1171  FillTProfile2D((TProfile2D*)h1, one, two, three, four);
1172  else if (h1->InheritsFrom("KVDalitzPlot"))
1173  FillKVDalitz((KVDalitzPlot*)h1, one, two, three);
1174  else if (h1->InheritsFrom("TH2"))
1175  FillTH2((TH2*)h1, one, two, three);
1176  else if (h1->InheritsFrom("TProfile"))
1177  FillTProfile((TProfile*)h1, one, two, three);
1178  else if (h1->InheritsFrom("TH1"))
1179  FillTH1(h1, one, two);
1180  else
1181  Warning("FillHisto", "%s -> Classe non prevue ...", lhisto->FindObject(sname.Data())->ClassName());
1182  }
1183  else {
1184  Warning("FillHisto", "%s introuvable", sname.Data());
1185  }
1186 
1187 }
1188 
1189 
1190 
1191 
1193 
1195 {
1196 
1197  h1->Fill(one, two);
1198 
1199 }
1200 
1201 
1202 
1203 
1205 
1207 {
1208 
1209  h1->Fill(one, two, three);
1210 
1211 }
1212 
1213 
1214 
1215 
1217 
1219 {
1220 
1221  h2->Fill(one, two, three);
1222 
1223 }
1224 
1225 
1226 
1227 
1229 
1231 {
1232 
1233  h2->Fill(one, two, three, four);
1234 }
1235 
1236 
1237 
1238 
1240 
1242 {
1243 
1244  h2->FillAsDalitz(one, two, three);
1245 }
1246 
1247 
1248 
1249 
1251 
1253 {
1254 
1255  h3->Fill(one, two, three, four);
1256 }
1257 
1258 
1259 
1260 
1261 
1263 
1265 {
1266 
1267  Warning("CreateHistos", "To be redefined child class");
1268 
1269 }
1270 
1271 
1272 
1273 
1279 
1281 {
1282 
1283  //If no filename is specified, assume that the current directory is writable
1284  //if filename correspond to an already opened file, write in it
1285  //if not open/create it, depending on the option ("recreate" by default)
1286  //and write in it
1287  Bool_t IsCreated = kFALSE;
1288  if (filename == "") {
1289  GetHistoList()->Write();
1290  }
1291  else {
1292  TFile* file = 0;
1293  if (!(file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename.Data()))) {
1294  IsCreated = kTRUE;
1295  file = new TFile(filename.Data(), option);
1296  }
1297  file->cd();
1298  GetHistoList()->Write();
1299  if (IsCreated) file->Close();
1300  }
1301 
1302 }
1303 
1304 
1305 
1306 
1308 
1310 {
1311 
1312  return ltree;
1313 
1314 }
1315 
1316 
1317 
1318 
1320 
1322 {
1323 
1324  return (TTree*)ltree->FindObject(tree_name);
1325 
1326 }
1327 
1328 
1329 
1331 
1333 {
1334 
1335  Warning("CreateTrees", "To be redefined child class");
1336 
1337 }
1338 
1339 
1340 
1341 
1343 
1345 {
1346 
1347  if (sname == "") {
1348  ltree->Execute("Fill", "");
1349  }
1350  else {
1351  TTree* tt = 0;
1352  if ((tt = GetTree(sname.Data()))) {
1353  tt->Fill();
1354  }
1355  else {
1356  Warning("FillTree", "%s introuvable", sname.Data());
1357  }
1358  }
1359 
1360 }
1361 
1362 
1363 
1364 
1367 
1369 {
1370 
1371  //If no filename is specified, assume that the current directory is writable
1372  Bool_t IsCreated = kFALSE;
1373  if (filename == "") {
1374  GetTreeList()->Write();
1375  }
1376  else {
1377  TFile* file = 0;
1378  //if filename correspond to an already opened file, write in it
1379  //if not open/create it, depending on the option ("recreate" by default)
1380  //and write in it
1381  if (!(file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename.Data()))) {
1382  IsCreated = kTRUE;
1383  file = new TFile(filename.Data(), option);
1384  }
1385  file->cd();
1386  GetTreeList()->Write();
1387  if (IsCreated) file->Close();
1388  }
1389 
1390 }
1391 
1392 
1393 
1396 
1397 void KVOldINDRASelector::SetOpt(const Char_t* option, const Char_t* value)
1398 {
1399  //Set a value for an option
1400  KVString tmp(value);
1401  fOptionList.SetValue(option, tmp);
1402 }
1403 
1404 
1405 
1406 
1409 
1411 {
1412  // Returns kTRUE if the option 'opt' has been set
1413 
1414  return fOptionList.HasParameter(opt);
1415 }
1416 
1417 
1418 
1419 
1423 
1425 {
1426  // Returns the value of the option
1427  // Only use after checking existence of option with IsOptGiven(const Char_t* opt)
1428 
1429  return fOptionList.GetTStringValue(opt);
1430 }
1431 
1432 
1433 
1434 
1437 
1439 {
1440  // Removes the option 'opt' from the internal lists, as if it had never been set
1441 
1442  fOptionList.RemoveParameter(opt);
1443 }
1444 
1445 
1446 
1452 
1454 {
1455  // Analyse comma-separated list of options given to TTree::Process
1456  // and store all "option=value" pairs in fOptionList.
1457  // Options can then be accessed using IsOptGiven(), GetOptString(), etc.
1458  // This method is called by Begin
1459 
1460  fOptionList.Clear(); // clear list
1461  KVString option = GetOption();
1462  option.Begin(",");
1463  while (!option.End()) {
1464 
1465  KVString opt = option.Next();
1466  opt.Begin("=");
1467  KVString param = opt.Next();
1468  KVString val = opt.Next();
1469  while (!opt.End()) {
1470  val += "=";
1471  val += opt.Next();
1472  }
1473 
1474  SetOpt(param.Data(), val.Data());
1475  }
1476 
1477  fOptionList.Print();
1478 }
1479 
1480 
int Int_t
unsigned int UInt_t
KVDataAnalyser * gDataAnalyser
KVTemplateParticleCondition< KVNucleus > KVParticleCondition
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define SafeDelete(p)
char Char_t
const Bool_t kFALSE
bool Bool_t
double Double_t
const Bool_t kTRUE
const char Option_t
R__EXTERN TEnv * gEnv
#define gFile
#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:1060
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:793
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:27
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.
Manage a list of global variables.
Definition: KVGVList.h:122
Extended version of ROOT THashList.
Definition: KVHashList.h:28
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:125
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.
void Init(TTree *tree)
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)
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 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
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
Bool_t Process(Long64_t entry)
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()
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.
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
void Begin(TTree *tree)
void SlaveBegin(TTree *tree)
virtual void WriteHistoToFile(KVString filename="FileFromKVOldINDRASelector.root", Option_t *option="recreate")
virtual void BuildEventList(void)
void SetIsOK(Bool_t flag=kTRUE)
Definition: KVParticle.cpp:339
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
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:231
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Bool_t InheritsFrom(const char *cl) const
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
virtual TObject * FindObject(const char *name) const
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 const char * GetName() const
virtual void SetTitle(const char *title="")
virtual void SetName(const char *name)
Int_t GetEntries() const
TObject * At(Int_t idx) const
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
virtual TObject * FindObject(const char *name) const
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual Bool_t InheritsFrom(const char *classname) const
Longptr_t ExecPlugin(int nargs, const T &... params)
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)
void Add(RHist< DIMENSIONS, PRECISION, STAT_TO... > &to, const RHist< DIMENSIONS, PRECISION, STAT_FROM... > &from)
void Info(const char *location, const char *va_(fmt),...)
void Error(const char *location, const char *va_(fmt),...)
void Warning(const char *location, const char *va_(fmt),...)
TH1 * GetHisto(const std::string file, const std::string path, const std::string obj)
auto * tt