KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVOldINDRASelector.cpp
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"
19#include "KVINDRAReconDataAnalyser.h"
20
21#include <KVINDRADB.h>
22
24using namespace std;
25
27
28
29
30
31
33
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
67{
68 //dtor
69 //delete global variable list if it belongs to us, i.e. if created by a
70 //call to GetGVList
72 delete gvlist;
73 gvlist = 0;
75 }
76 delete fTimer;
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
93 gDataAnalyser->DeleteBatchStatusFile();
94
95 if (!tree) return;
96
97 // Set branch addresses
98 fChain = tree;
100
101 if (fChain->InheritsFrom("TChain"))
102 fTreeOffset = ((TChain*) fChain)->GetTreeOffset();
103 else
104 fTreeOffset = 0;
105
106 data = 0;
107 b_data = 0;
109
110//
111// Builds a TEventList by adding the contents of the lists for each run
112//
114 if (fKVDataSelector) { // Init of the KVDataSelector if needed
116 }
117 // tell the data analyser who we are
118 gDataAnalyser->RegisterUserClass(this);
119 gDataAnalyser->preInitAnalysis();
120 InitAnalysis(); //user initialisations for analysis
121 gDataAnalyser->postInitAnalysis();
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;
143
145
146 if (fEvtList)
148 else
150
151 gDataAnalyser->preInitRun(); // will initialize fCurrentRun
152
153 if (needToSelect) {
154 if (!fKVDataSelector) {
156 }
158 cout << " Building new TEventList : " << fKVDataSelector->
159 GetTEventList()->GetName()
160 << endl;
161 }
162
163 InitRun(); //user initialisations for run
164 gDataAnalyser->postInitRun();
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
186
187 totentry = 0;
188
189 //start stopwatch, after first resetting it (in case this is not the first time the analysis is run)
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
230Bool_t KVOldINDRASelector::Process(Int_t entry) //for ROOT versions < 4.01/01
231#else
232Bool_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
247 if (gDataAnalyser->AbortProcessingLoop()) {
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
255 if (gDataAnalyser->CheckStatusUpdateInterval(totentry)) gDataAnalyser->DoStatusUpdate(totentry);
256
257 // read event
258 fChain->GetTree()->GetEntry(fTreeEntry);
259 // read raw data associated to event
260 gDataAnalyser->preAnalysis();
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
295 gDataAnalyser->postAnalysis();
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
304 gDataAnalyser->preEndRun();
305 EndRun(); //user routine end of run
306 gDataAnalyser->postEndRun();
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) {
346 gDataAnalyser->preEndRun();
347 EndRun();
348 gDataAnalyser->postEndRun();
349 }
350
351 if (needToSelect) {
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) {
369 delete fEvtList;
370 fEvtList = 0;
371 }
372
373 gDataAnalyser->preEndAnalysis();
374 EndAnalysis(); //user end of analysis routine
375 gDataAnalyser->postEndAnalysis();
376
377 //delete job status file from $HOME directory
378 gDataAnalyser->DeleteBatchStatusFile();
379}
380
381
382
385
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;
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
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\".",
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",
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 }
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\".",
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\".",
856 }
857 if (fileDataSelector) {
858 fileDataSelector->Close();
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",
871 Form("%s.cpp+",
873 Form("%s()",
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",
882 }
883 else {
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.",
896 }
897 else {
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)
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;
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;
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\".",
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\".",
980 mh.Write();
981 }
982#endif
983
984 cout << "Done" << endl;
985 fileDataSelector->Close();
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", ... )
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
1397void KVOldINDRASelector::SetOpt(const Char_t* option, const Char_t* value)
1398{
1399 //Set a value for an option
1400 KVString tmp(value);
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
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
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
1478}
1479
1480
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: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)
virtual Int_t GetNumber() const
Definition KVDBRecord.h:73
Fill 3D observables in a dalitz plot ,.
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.
virtual const TEventList * GetTEventList(void)
virtual void Reset(Int_t nrun)
virtual void Init(void)
virtual void SetKVSelector(KVOldINDRASelector *kvs=0)
Pilots user analysis of experimental data.
#define KVGVLIST_OPTIMIZE_GVLIST
Definition KVGVList.h:227
void Init(void)
Definition KVGVList.cpp:66
void CalculateGlobalVariables(KVEvent *e)
Definition KVGVList.cpp:206
virtual void Add(TObject *obj)
Definition KVGVList.cpp:336
Extended version of ROOT THashList.
Definition KVHashList.h:29
Bool_t Release()
Bool_t Lock(const Char_t *filename="")
virtual void Print(Option_t *opt="") const
void SetValue(const Char_t *name, value_type value)
void RemoveParameter(const Char_t *name)
virtual void Clear(Option_t *opt="")
Bool_t HasParameter(const Char_t *name) const
TString GetTStringValue(const Char_t *name) const
Description of properties and kinematics of atomic nuclei.
Definition KVNucleus.h:126
Former base analysis class for INDRA data.
KVINDRADBRun * fCurrentRun
current run
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)
KVINDRAReconEvent * data
Declaration of leaves types.
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)
KVNameValueList fOptionList
parsed list of options given to TTree::Process
void FillTH2(TH2 *h2, Double_t one, Double_t two, Double_t three)
virtual void AddGV(KVVarGlob *)
Long64_t fTreeEntry
this is the current TTree entry number, i.e. the argument passed to TSelector::Process(Long64_t entry...
Int_t fCurrentTreeNumber
This is the current tree number.
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
KVGVList * gvlist
List of global variables.
TString fDataSelector
Name of the KVDataSelector.
UInt_t fNewMassFormula
new mass formula to apply to fragments, if required
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
TTree * fChain
pointer to the analyzed TTree or TChain
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.
KVDataSelector * fKVDataSelector
KVDataSelector.
TStopwatch * fTimer
used to time analysis
KVINDRAReconEvent * GetEvent()
void SlaveTerminate()
Function called at the end of the event loop in each PROOF slave.
virtual void ChangeFragmentMasses(UInt_t mass_formula)
virtual const Char_t * GetDataSelector(void)
TEventList * fEvtList
this is the current event list.
Bool_t * fTEVLexist
tells if the TEventList exist for each run
virtual Long64_t GetTreeEntry() const
Long64_t * fTreeOffset
this is the current TTree offset table
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 void SetDataSelector(const Char_t *dataSel="")
virtual KVVarGlob * GetGV(const Char_t *) const
Bool_t needToSelect
tells if one needs to build the TEventList
TBranch * b_data
List of branches.
KVParticleCondition * fPartCond
(optional) conditions for selecting particles
void Begin(TTree *tree)
virtual void EndAnalysis()
KVLockfile dataselector_lock
for locking user's data selector file
void SlaveBegin(TTree *tree)
virtual void WriteHistoToFile(KVString filename="FileFromKVOldINDRASelector.root", Option_t *option="recreate")
virtual void InitAnalysis()
virtual void BuildEventList(void)
Bool_t needToCallEndRun
tells if one needs to call EndRun
void SetIsOK(Bool_t flag=kTRUE)
virtual TObject * FindObject(const char *name) const
virtual void Clear(Option_t *option="")
virtual void Execute(const char *method, const char *params, Int_t *error=0)
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
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)
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
T * Get(const char *namecycle)
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void Reset(Option_t *option="")
virtual Long64_t GetEntry(Int_t index) const
virtual Int_t GetIndex(Long64_t entry) const
virtual Int_t GetN() const
virtual void Enter(Long64_t entry)
void Close(Option_t *option="") 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)
TClass * IsA() const override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
virtual const char * GetName() const
void SetBit(UInt_t f)
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual const char * ClassName() const
virtual void Warning(const char *method, const char *msgfmt,...) 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
virtual void Error(const char *method, const char *msgfmt,...) const
void ResetBit(UInt_t f)
virtual void Info(const char *method, const char *msgfmt,...) 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 * GetOption() const override
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
Ssiz_t Length() const
const char * Data() const
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
virtual const char * WorkingDirectory()
TFile * GetCurrentFile() const
virtual void SetMakeClass(Int_t make)
virtual void SetEventList(TEventList *list)
virtual Long64_t GetEntries() const
virtual TTree * GetTree() const
virtual Int_t GetTreeNumber() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
long long Long64_t
TH1F * h1
CPYCPPYY_EXTERN bool Exec(const std::string &cmd)
str tree_name
void Info(const char *location, const char *fmt,...)
Add
auto * tt
ClassImp(TPyArg)