1 #include "KVDataSetAnalyser.h"
2 #define KVOldINDRASelector_cxx
3 #include "KVOldINDRASelector.h"
11 #include "TPluginManager.h"
12 #include "KVClassFactory.h"
13 #include "KVDataAnalyser.h"
14 #include <KVINDRADB.h>
15 #ifndef __WITHOUT_TMACRO
18 KVString KVOldINDRASelector::fBranchName =
"INDRAReconEvent";
36 fTimer =
new TStopwatch;
42 needToSelect = kFALSE;
43 needToCallEndRun = kFALSE;
47 dataselector_lock.SetTimeout(60);
48 dataselector_lock.SetSuspend(5);
49 dataselector_lock.SetSleeptime(1);
59 KVOldINDRASelector::~KVOldINDRASelector()
64 if (gvlist && TestBit(kDeleteGVList)) {
67 ResetBit(kDeleteGVList);
70 SafeDelete(fPartCond);
92 fChain->SetMakeClass(1);
94 if (fChain->InheritsFrom(
"TChain"))
95 fTreeOffset = ((TChain*) fChain)->GetTreeOffset();
101 fChain->SetBranchAddress(fBranchName.Data(), &data, &b_data);
107 if (fKVDataSelector) {
108 fKVDataSelector->Init();
132 cout <<
"Analyse du fichier " << fChain->GetCurrentFile()->GetName()
133 <<
" : " << fChain->GetTree()->GetEntries() << endl;
134 NbTreeEntry = (Int_t) fChain->GetTree()->GetEntries();
135 fCurrentTreeNumber = fChain->GetTreeNumber();
137 needToCallEndRun = kTRUE;
140 needToSelect = !(fTEVLexist[fCurrentTreeNumber]);
142 needToSelect = kFALSE;
147 if (!fKVDataSelector) {
150 fKVDataSelector->Reset(fCurrentRun->GetNumber());
151 cout <<
" Building new TEventList : " << fKVDataSelector->
152 GetTEventList()->GetName()
176 if (IsOptGiven(
"DataSelector")) SetDataSelector(GetOpt(
"DataSelector"));
183 fTimer->Start(kTRUE);
208 #ifdef __WITHOUT_TSELECTOR_LONG64_T
242 Abort(Form(
"Aborting analysis after %d events", totentry), kAbortFile);
251 fChain->GetTree()->GetEntry(fTreeEntry);
258 while ((part = (
KVNucleus*)GetEvent()->GetNextParticle(
"ok"))) {
260 part->
SetIsOK(fPartCond->Test(part));
266 if (TestBit(kChangeMasses)) GetEvent()->ChangeFragmentMasses(fNewMassFormula);
271 if (fCurrentRun->GetSystem() && fCurrentRun->GetSystem()->GetKinematics()) {
273 GetEvent()->SetFrame(
"CM",
274 fCurrentRun->GetSystem()->GetKinematics()->GetCMVelocity());
278 RecalculateGlobalVariables();
281 Bool_t ok_anal = kTRUE;
284 ok_anal = fKVDataSelector->ProcessCurrentEntry();
287 ok_anal = Analysis();
292 TString mes(
"End of run after ");
295 Info(
"Process",
"%s", mes.Data());
300 needToCallEndRun = kFALSE;
304 SaveCurrentDataSelection();
305 needToSelect = kFALSE;
338 if (needToCallEndRun) {
345 SaveCurrentDataSelection();
348 cout << endl <<
" ====================== END ====================== " <<
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 ====================== " <<
361 fChain->SetEventList(0);
382 KVClassFactory cf(kvsname,
"User analysis class",
"KVOldINDRASelector", kTRUE);
418 SetBit(kDeleteGVList);
434 KVError::Error(
this,
"AddGV(KVVarGlob*)",
"KVVarGlob pointer is null");
436 GetGVList()->Add(vg);
516 TClass* clas = gROOT->GetClass(class_name);
523 "Called with class_name=%s.\nClass is unknown: not in standard libraries, and plugin (user-defined class) not found",
531 else if (!clas->InheritsFrom(
"KVVarGlob")) {
533 "%s is not a valid class deriving from KVVarGlob.",
607 if (gvlist) gvlist->CalculateGlobalVariables(GetEvent());
612 #ifdef __WITHOUT_TSELECTOR_LONG64_T
649 if (fKVDataSelector) {
650 delete fKVDataSelector;
658 if (fDataSelector.Length()) {
659 Info(
"BuildEventList()",
660 "Building TEventList for the KVDataSelector \"%s\".",
665 cout <<
"Analysis from a chain of trees." << endl;
666 lof = ((TChain*) fChain)->GetListOfFiles();
670 cout <<
"Analysis from a single tree." << endl;
671 lof =
new TObjArray();
674 TNamed(
"SingleRun", fChain->GetCurrentFile()->GetName()));
675 toff =
new Long64_t[2];
677 toff[1] = fChain->GetEntries();
681 new TEventList(
"chainEventList",
"TEvent list for this TChain");
685 TString searchname(GetDataSelectorFileName());
686 TString fname = searchname;
687 cout <<
"File to open : " << fname.Data() << endl;
688 TFile* fileDataSelector = 0;
691 if (dataselector_lock.Lock(fname.Data())) fileDataSelector =
new TFile(fname.Data());
694 cout <<
"The file \"" << fname.
695 Data() <<
"\" does not exist." << endl;
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;
705 cout <<
"Numero de run " << nrun << endl;
706 cout <<
"Recherche de " << Form(
"%s_run%d;1",
709 TEventList* revtList = 0;
710 if (fileDataSelector) {
712 (TEventList*) fileDataSelector->
713 Get(Form(
"%s_run%d;1", GetDataSelector(), nrun));
716 for (Int_t i = 0; i < revtList->GetN(); i++) {
717 fEvtList->Enter(fTreeOffset[tn] + revtList->GetEntry(i));
719 fTEVLexist[tn] = kTRUE;
722 cout <<
"Liste introuvable..." << endl;
723 for (Int_t i = fTreeOffset[tn]; i < fTreeOffset[tn + 1];
730 cout <<
"Run inconnu..." << endl;
733 if (fileDataSelector) {
734 cout <<
"Closing " << fileDataSelector->GetName() << endl;
735 fileDataSelector->Close();
736 dataselector_lock.Release();
741 lof->SetOwner(kTRUE);
745 if (!fEvtList->GetN()) {
751 fChain->SetEventList(fEvtList);
767 Bool_t ok = (fTreeEntry + 1 == fChain->GetTree()->GetEntries());
770 Long64_t globEntry = 0;
772 globEntry = ((TChain*) fChain)->GetChainEntryNumber(fTreeEntry);
774 globEntry = fTreeEntry;
775 Int_t index = fEvtList->GetIndex(globEntry);
776 Long64_t nextEntry = (fEvtList->GetEntry(index + 1));
777 ok = ok || (nextEntry == -1);
779 ok = ok || (nextEntry >= fTreeOffset[fCurrentTreeNumber + 1]);
798 cout <<
"Loading KVDataSelector..." << endl;
799 Bool_t deleteSources = kFALSE;
800 if (fDataSelector.Length()) {
802 TClass* clas = gROOT->GetClass(fDataSelector.Data());
803 cout << clas <<
" / " << fDataSelector.Data() << endl;
807 TString fileC(Form(
"%s.cpp", fDataSelector.Data()));
808 TString fileh(Form(
"%s.h", fDataSelector.Data()));
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());
817 if (!mC.ReadFile(fileC.Data()) || !mC.ReadFile(fileh.Data())) {
820 TString searchname(GetDataSelectorFileName());
821 TString fname = searchname;
822 TFile* fileDataSelector = 0;
825 if (dataselector_lock.Lock(fname.Data())) fileDataSelector =
new TFile(fname.Data());
828 cout <<
"The file \"" << fname.
829 Data() <<
"\" does not exist." << endl;
833 if (fileDataSelector) {
834 macC = (TMacro*) fileDataSelector->Get(fileC.Data());
835 mach = (TMacro*) fileDataSelector->Get(fileh.Data());
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;
846 "No implementation and/or declaration file found for \"%s\".",
847 fDataSelector.Data());
849 if (fileDataSelector) {
850 fileDataSelector->Close();
851 dataselector_lock.Release();
856 cout <<
"Files " << fileC.Data() <<
" and " << fileh.Data() <<
860 gROOT->GetPluginManager()->AddHandler(
"KVDataSelector",
861 fDataSelector.Data(),
862 fDataSelector.Data(),
864 fDataSelector.Data()),
866 fDataSelector.Data()));
872 "Called with class_name=%s.\nClass is unknown: not in standard libraries, and plugin (user-defined class) not found",
873 fDataSelector.Data());
877 fKVDataSelector->SetKVSelector(
this);
878 cout <<
"Apres Plugin " << fKVDataSelector->IsA()->
879 GetName() <<
" : " << fKVDataSelector->
880 GetKVSelector() << endl;
884 else if (!clas->InheritsFrom(
"KVDataSelector")) {
886 "%s is not a valid class deriving from KVDataSelector.",
887 fDataSelector.Data());
891 fKVDataSelector->SetKVSelector(
this);
892 cout <<
"Apres clas->New() " << fKVDataSelector->IsA()->
893 GetName() <<
" : " << fKVDataSelector->
894 GetKVSelector() << endl;
897 cout <<
"Removing files \"" << fDataSelector.
898 Data() <<
"*.*\" ..." << endl;
901 (
"rm %s.[c,h]*", fDataSelector.Data()));
908 fKVDataSelector->Init();
923 if (fKVDataSelector) {
924 TFile* curfile = gFile;
926 TString searchname(GetDataSelectorFileName());
927 TString fname = searchname;
934 cout <<
"File to open : " << fname.Data() <<
" : " << option.
936 TFile* fileDataSelector = 0;
937 if (dataselector_lock.Lock(fname.Data())) fileDataSelector =
new TFile(fname.Data(), option.Data());
938 if (!fileDataSelector || (fileDataSelector && fileDataSelector->IsZombie())) {
940 "Opening the file \"%s\" with the option \"%s\" is not possible.\nNothing saved.",
941 fname.Data(), option.Data());
945 cout <<
"Saving the TEventList \"" << fKVDataSelector->
946 GetTEventList()->GetName() <<
"\"..." << endl;
947 cout << fKVDataSelector->GetTEventList()->
948 GetN() <<
" entries selected." << endl;
949 fKVDataSelector->GetTEventList()->Write();
951 #ifndef __WITHOUT_TMACRO
955 Get(Form(
"%s.cpp;1", fKVDataSelector->IsA()->GetName()));
958 Get(Form(
"%s.h;1", fKVDataSelector->IsA()->GetName()));
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()));
964 (
"Implementation file for the KVDataSelector \"%s\".",
965 fKVDataSelector->IsA()->GetName()));
967 TMacro mh(Form(
"%s.h", fKVDataSelector->IsA()->GetName()));
968 mh.SetName(Form(
"%s.h", fKVDataSelector->IsA()->GetName()));
970 (
"Declaration file for the KVDataSelector \"%s\".",
971 fKVDataSelector->IsA()->GetName()));
976 cout <<
"Done" << endl;
977 fileDataSelector->Close();
978 dataselector_lock.Release();
982 cout <<
"No TEventList to save..." << endl;
1000 static TString fname;
1003 gEnv->GetValue(
"DataSelector.directory",
1004 gSystem->WorkingDirectory());
1007 gEnv->GetValue(
"DataSelector.fileName",
"ListOfDataSelector.root");
1008 cout <<
"List Of Data Selectors : " << fname.Data() << endl;
1009 return fname.Data();
1045 SetBit(kChangeMasses);
1046 fNewMassFormula = mass_formula;
1113 else *fPartCond = cond;
1115 fPartCond->SetParticleClassName(
"KVINDRAReconNuc");
1138 return (TH1*)lhisto->FindObject(histo_name);
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"))
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);
1173 KVError::Warning(
this,
"FillHisto",
"%s -> Classe non prevue ...", lhisto->FindObject(sname.Data())->ClassName());
1186 void KVOldINDRASelector::FillTH1(TH1* h1, Double_t one, Double_t two)
1198 void KVOldINDRASelector::FillTProfile(TProfile* h1, Double_t one, Double_t two, Double_t three)
1201 h1->Fill(one, two, three);
1210 void KVOldINDRASelector::FillTH2(TH2* h2, Double_t one, Double_t two, Double_t three)
1213 h2->Fill(one, two, three);
1222 void KVOldINDRASelector::FillTProfile2D(TProfile2D* h2, Double_t one, Double_t two, Double_t three, Double_t four)
1225 h2->Fill(one, two, three, four);
1233 void KVOldINDRASelector::FillKVDalitz(
KVDalitzPlot* h2, Double_t one, Double_t two, Double_t three)
1244 void KVOldINDRASelector::FillTH3(TH3* h3, Double_t one, Double_t two, Double_t three, Double_t four)
1247 h3->Fill(one, two, three, four);
1279 Bool_t IsCreated = kFALSE;
1280 if (filename ==
"") {
1281 GetHistoList()->Write();
1285 if (!(file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename.Data()))) {
1287 file =
new TFile(filename.Data(), option);
1290 GetHistoList()->Write();
1291 if (IsCreated) file->Close();
1316 return (TTree*)ltree->FindObject(tree_name);
1340 ltree->Execute(
"Fill",
"");
1344 if ((tt = GetTree(sname.Data()))) {
1364 Bool_t IsCreated = kFALSE;
1365 if (filename ==
"") {
1366 GetTreeList()->Write();
1373 if (!(file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename.Data()))) {
1375 file =
new TFile(filename.Data(), option);
1378 GetTreeList()->Write();
1379 if (IsCreated) file->Close();
1393 fOptionList.SetValue(option, tmp);
1406 return fOptionList.HasParameter(opt);
1421 return fOptionList.GetTStringValue(opt);
1434 fOptionList.RemoveParameter(opt);
1445 void KVOldINDRASelector::ParseOptions()
1452 fOptionList.Clear();
1455 while (!option.
End()) {
1461 while (!opt.
End()) {
1466 SetOpt(param.Data(), val.Data());
1469 fOptionList.Print();
static const Char_t * FindFile(const Char_t *search, TString &wfil)
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
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 ,.
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()
const KVString & GetDataType() const
virtual Bool_t CheckStatusUpdateInterval(Long64_t nevents) const
virtual void preAnalysis()
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.
std::optional< run_index_t > GetRunNumberFromFileName(const TString &datatype, const TString &filename)
Manage a list of global variables.
Extended version of ROOT THashList.
Description of properties and kinematics of atomic nuclei.
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 SlaveBegin(TTree *tree) override
virtual TString GetOpt(const Char_t *option) const
TH1 * GetHisto(const Char_t *name)
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()
virtual void CreateHistos()
Bool_t Process(Long64_t entry) override
virtual KVGVList * GetGVList(void)
virtual void SetParticleConditions(const KVParticleCondition &)
virtual Bool_t AtEndOfRun(void)
virtual void SetGVList(KVGVList *list)
handling global variables for analysis
void FillTree(KVString sname="")
TTree * GetTree(const Char_t *name)
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.
KVHashList * GetHistoList()
virtual void CreateTrees()
virtual void ChangeFragmentMasses(UInt_t mass_formula)
virtual Long64_t GetTreeEntry() const
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
KVHashList * GetTreeList()
virtual void WriteHistoToFile(KVString filename="FileFromKVOldINDRASelector.root", Option_t *option="recreate")
void Init(TTree *tree) override
virtual void BuildEventList(void)
Implement selections for KVNucleus objects.
void SetIsOK(Bool_t flag=kTRUE)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
Base class for all global variable implementations.
void Error(UserClass p, const char *location, const char *va_(fmt),...)
void Warning(UserClass p, const char *location, const char *va_(fmt),...)