KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVEventSelector.cpp
Go to the documentation of this file.
1 #define KVEventSelector_cxx
2 #include "KVEventSelector.h"
3 #include <KVClassMonitor.h>
4 #include <TStyle.h>
5 #include "TPluginManager.h"
6 #include "TSystem.h"
8 #include "KVDataRepository.h"
9 #include "KVDataSetManager.h"
10 #include "TProof.h"
11 #include "KVDataSetAnalyser.h"
12 
13 using namespace std;
14 
16 
17 
18 
19 
20 
25 void KVEventSelector::Begin(TTree* /*tree*/)
26 {
27  // Need to parse options here for use in Terminate
28  // Also, on PROOF, any KVDataAnalyser instance has to be passed to the workers
29  // via the TSelector input list.
30 
31  ParseOptions();
32 
33  if (IsOptGiven("CombinedOutputFile")) {
34  fCombinedOutputFile = GetOpt("CombinedOutputFile");
35  }
36  else if (gProof) {
37  // when running with PROOF, if the user calls SetCombinedOutputFile()
38  // in InitAnalysis(), it will only be executed on the workers (in SlaveBegin()).
39  // therefore we call InitAnalysis() here, but deactivate CreateTreeFile(),
40  // AddTree() and AddHisto() in order to avoid interference with workers
41  fDisableCreateTreeFile = kTRUE;
42  if (gDataAnalyser) {
45  }
46  InitAnalysis(); //user initialisations for analysis
48  fDisableCreateTreeFile = kFALSE;
49  }
50 
51  if (gDataAnalyser) {
52  if (GetInputList()) {
53  gDataAnalyser->AddJobDescriptionList(GetInputList());
54  //GetInputList()->ls();
55  }
56  }
57  if (IsOptGiven("AuxFiles")) {
58  SetUpAuxEventChain();
59  if (GetInputList()) GetInputList()->Add(fAuxChain);
60  }
61 }
62 
63 
64 
78 
80 {
81  // The SlaveBegin() function is called after the Begin() function.
82  // When running with PROOF SlaveBegin() is called on each slave server.
83  // The tree argument is deprecated (on PROOF 0 is passed).
84  //
85  // ParseOptions : Manage options passed as arguments
86  //
87  // Called user method InitAnalysis where users can create trees or histos
88  // using the appropiate methods :
89  // CreateTrees and CreateMethods
90  //
91  // Test the presence or not of such histo or tree
92  // to manage it properly
93 
94  if (GetInputList() && GetInputList()->FindObject("JobDescriptionList")) {
95  KVNameValueList* jdl = dynamic_cast<KVNameValueList*>(GetInputList()->FindObject("JobDescriptionList"));
96  if (jdl) {
97  KVDataAnalysisTask* task = nullptr;
98  if (jdl->HasParameter("DataRepository")) {
102  }
103  gDataRepositoryManager->GetRepository(jdl->GetStringValue("DataRepository"))->cd();
104  gDataSetManager->GetDataSet(jdl->GetStringValue("DataSet"))->cd();
105  task = gDataSet->GetAnalysisTask(jdl->GetStringValue("AnalysisTask"));
106  }
107  else {
108  if (!gDataSetManager) {
111  }
112  task = gDataSetManager->GetAnalysisTaskAny(jdl->GetStringValue("AnalysisTask"));
113  }
115  if (gDataSet && gDataAnalyser->InheritsFrom("KVDataSetAnalyser"))
116  dynamic_cast<KVDataSetAnalyser*>(gDataAnalyser)->SetDataSet(gDataSet);
120  }
121  }
122 
123  ParseOptions();
124 
125  if (IsOptGiven("CombinedOutputFile")) {
126  fCombinedOutputFile = GetOpt("CombinedOutputFile");
127  Info("SlaveBegin", "Output file name = %s", fCombinedOutputFile.Data());
128  }
129 
130  // tell the data analyser who we are
131  if (gDataAnalyser) {
134  }
135  // make sure histo/tree creation are enabled
136  fDisableCreateTreeFile = kFALSE;
137  InitAnalysis(); //user initialisations for analysis
139 
140  if (ltree->GetEntries() > 0) {
141  for (Int_t ii = 0; ii < ltree->GetEntries(); ii += 1) {
142  TTree* tt = (TTree*)ltree->At(ii);
143  tt->SetDirectory(writeFile);
144  tt->AutoSave();
145  }
146  }
147 
148  if (IsOptGiven("AuxFiles")) {
149  // auxiliary files with PROOF
150  if (GetInputList()) {
151  fAuxChain = (TTree*)GetInputList()->FindObject(GetOpt("AuxTreeName"));
152  InitFriendTree(fAuxChain, GetOpt("AuxBranchName"));
153  }
154  }
155  Info("SlaveBegin", "fOutput->ls()");
156  GetOutputList()->ls();
157 }
158 
159 
164 
166 {
167  // For PROOF:
168  // This method must be called before creating any user TTree in InitAnalysis().
169  // If no filename is given, default name="TreeFileFrom[name of selector class].root"
170 
171  if (fDisableCreateTreeFile) return kTRUE;
172 
173  TString tree_file_name;
174  if (!strcmp(filename, ""))
175  tree_file_name.Form("TreeFileFrom%s.root", ClassName());
176  else
177  tree_file_name = filename;
178 
179  mergeFile = new TProofOutputFile(tree_file_name.Data(), "M");
180  mergeFile->SetOutputFileName(tree_file_name.Data());
181 
182  TDirectory* savedir = gDirectory;
183  writeFile = mergeFile->OpenFile("RECREATE");
184  if (writeFile && writeFile->IsZombie()) SafeDelete(writeFile);
185  savedir->cd();
186 
187  // Cannot continue
188  if (!writeFile) {
189  Info("CreateTreeFile", "could not create '%s': instance is invalid!", filename);
190  return kFALSE;
191  }
192  return kTRUE;
193 
194 }
195 
196 
197 
217 
219 {
220  // The Process() function is called for each entry in the tree (or possibly
221  // keyed object in the case of PROOF) to be processed. The entry argument
222  // specifies which entry in the currently loaded tree is to be processed.
223  // It can be passed to either KVEventSelector::GetEntry() or TBranch::GetEntry()
224  // to read either all or the required parts of the data. When processing
225  // keyed objects with PROOF, the object is already loaded and is available
226  // via the fObject pointer.
227  //
228  // This function should contain the "body" of the analysis. It can contain
229  // simple or elaborate selection criteria, run algorithms on the data
230  // of the event and typically fill histograms.
231  //
232  // Processing will abort cleanly if static flag fCleanAbort has been set
233  // by some external controlling process.
234  //
235  // Use fStatus to set the return value of TTree::Process().
236  //
237  // The return value is currently not used.
238 
240  // abort requested by external process
241  Abort(Form("Job received KILL signal from batch system after %lld events - batch job probably needs more CPU time (see end of job statistics)", fEventsRead), kAbortFile);
242  return kFALSE;
243  }
244 
245  fTreeEntry = entry;
246 
248  gDataAnalyser->DoStatusUpdate(fEventsRead);
249 
250  GetEntry(entry);
252  fEventsRead++;
253  if (GetEvent()) {
254  KVNucleus* part = 0;
255  //apply particle selection criteria
256  if (fPartCond.IsSet()) {
257  part = 0;
258  GetEvent()->ResetGetNextParticle();
259  while ((part = GetEvent()->GetNextParticle("ok"))) {
260  part->SetIsOK(fPartCond.Test(part));
261  }
262  }
263  GetEvent()->ResetGetNextParticle();
264  SetAnalysisFrame();//let user define any necessary reference frames for OK particles
265 
266  // initialise global variables at first event
267  if (fFirstEvent && !gvlist.IsEmpty()) {
268  gvlist.Init();
269  fFirstEvent = kFALSE;
270  }
271  RecalculateGlobalVariables();
272  }
273 
274  Bool_t ok_anal = kTRUE;
275  if (gvlist.IsEmpty() || !gvlist.AbortEventAnalysis()) {
276  // if global variables are defined, events are only analysed if no global variables
277  // in the list have failed an event selection condition
278  ok_anal = Analysis(); //user analysis
280  }
281  CheckEndOfRun();
282 
283  return ok_anal;
284 }
285 
286 
287 
290 
292 {
293  // Testing whether EndRun() should be called
294  if (AtEndOfRun()) {
295  Info("Process", "End of file reached after %lld events", fEventsRead);
297  EndRun();
299  fNotifyCalled = kFALSE;//Notify will be called when next file is opened (in TChain)
300  }
301 
302 }
303 
304 
305 
313 
315 {
316  // The SlaveTerminate() function is called after all entries or objects
317  // have been processed. When running with PROOF SlaveTerminate() is called
318  // on each slave server.
319  // if tree have been defined in the CreateTrees method
320  // manage the merge of them in ProofLite session
321  //
322 
323  if (ltree->GetEntries() > 0) {
324 
325  if (writeFile) {
326  TDirectory* savedir = gDirectory;
327  TTree* tt = 0;
328  for (Int_t ii = 0; ii < ltree->GetEntries(); ii += 1) {
329  tt = (TTree*)ltree->At(ii);
330  writeFile->cd();
331  tt->Write();
332  }
333  mergeFile->Print();
334  fOutput->Add(mergeFile);
335 
336  for (Int_t ii = 0; ii < ltree->GetEntries(); ii += 1) {
337  tt = (TTree*)ltree->At(ii);
338  tt->SetDirectory(0);
339  }
340 
341  gDirectory = savedir;
342  writeFile->Close();
343  }
344 
345  }
346 
347  fOutput->ls();
348 }
349 
350 
351 
360 
362 {
363  // The Terminate() function is the last function to be called during
364  // a query. It always runs on the client, it can be used to present
365  // the results graphically or save the results to file.
366  //
367  // This method call the user defined EndAnalysis
368  // where user can do what she wants
369  //
370 
371  TDatime now;
372  Info("Terminate", "Analysis ends at %s", now.AsString());
373 
374  if (fCombinedOutputFile != "") {
375  Info("Terminate", "combine = %s", fCombinedOutputFile.Data());
376  // combine histograms and trees from analysis into one file
377  TString file1, file2;
378  file1.Form("HistoFileFrom%s.root", ClassName());
379  file2.Form("TreeFileFrom%s.root", ClassName());
380  GetOutputList()->ls();
381  if (GetOutputList()->FindObject("ThereAreHistos")) {
382  if (GetOutputList()->FindObject(file2)) {
383  Info("Terminate", "both");
384  SaveHistos();
385  KVBase::CombineFiles(file1, file2, fCombinedOutputFile, kFALSE);
386  }
387  else {
388  // no trees - just rename histo file
389  Info("Terminate", "histo");
390  SaveHistos(fCombinedOutputFile);
391  }
392  }
393  else if (GetOutputList()->FindObject(file2)) {
394  // no histos - just rename tree file
395  Info("Terminate", "tree");
396  gSystem->Rename(file2, fCombinedOutputFile);
397  }
398  else Info("Terminate", "none");
399  }
400 
402  EndAnalysis(); //user end of analysis routine
404 
405  if (GetInputList() && fAuxChain) GetInputList()->Remove(fAuxChain);
406  SafeDelete(fAuxChain);
407 }
408 
409 
410 
441 
443  const Char_t* name)
444 {
445  //Add a global variable to the list of variables for the analysis.
446  //
447  //`"class_name"` must be the name of a valid class inheriting from KVVarGlob, e.g. any of the default global
448  //variable classes defined as part of the standard KaliVeda package (see the [global variables module](group__Globvars.html)),
449  //or the name of a user-defined class (see below).
450  //
451  //`"name"` is a unique name for the new global variable object which will be created and added to the internal
452  //list of global variables. This name can be used to retrieve the object (see GetGV()) in the user's analysis.
453  //
454  //Returns pointer to new global variable object in case more than the usual default initialisation is necessary.
455  //
456  //### User-defined global variables
457  //The user may use her own global variables in an analysis class, without having to add them to the main libraries.
458  //If the given class name is not known, it is assumed to be a user-defined class and we attempt to compile and load
459  //the class from the user's source code. For this to work, the user must:
460  //
461  // 1. add to the ROOT macro path the directory where her class's source code is kept, e.g. in `$HOME/.rootrc` add the following line:
462  //
463  //~~~~~~~~~~~~~~~
464  // +Unix.*.Root.MacroPath: $(HOME)/myVarGlobs
465  //~~~~~~~~~~~~~~~
466  //
467  // 2. for each user-defined class, add a line to $HOME/.kvrootrc to define a "plugin". E.g. for a class called MyNewVarGlob,
468  //
469  //~~~~~~~~~~~~~~~
470  // +Plugin.KVVarGlob: MyNewVarGlob MyNewVarGlob MyNewVarGlob.cpp+ "MyNewVarGlob()"
471  //~~~~~~~~~~~~~~~
472  //
473  // It is assumed that `MyNewVarGlob.h` and `MyNewVarGlob.cpp` will be found in `$HOME/myVarGlobs` (in this example).
474 
475  KVVarGlob* vg = GetGVList()->AddGV(class_name, name);
476  return vg;
477 }
478 
479 
480 
481 
491 
493 {
494  //Use this method if you change e.g. the particle selection criteria in your
495  //Analysis() method and want to recalculate the values of all global variables
496  //for your new selection.
497  //
498  //WARNING: the global variables are calculated automatically for you for each event
499  //before method Analysis() is called. In order for the correct particles to be included in
500  //this calculation, make sure that at the END of Analysis() you reset the selection
501  //criteria.
502 
503  if (!gvlist.IsEmpty()) gvlist.CalculateGlobalVariables(GetEvent());
504 }
505 
506 
507 
508 
522 
524 {
525  //Use this method to set criteria for selecting particles to include in analysis.
526  //The criteria defined in the KVParticleCondition object will be applied to every
527  //particle and if they are not satisfied the particle's
528  //"OK" flag will be set to false, i.e. the particle's IsOK() method will return kFALSE,
529  //and the particle will not be included in iterations such as GetEvent()->GetNextParticle("OK").
530  //Neither will the particle be included in the evaluation of any global variables.
531  //
532  //This method must be called in the user's InitAnalysis() or InitRun() method.
533  //
534  //If the methods used in the condition are not defined for KVNucleus, you can give the
535  //name of the class to which the methods refer (upcast_class), or you can set it before
536  //hand (SetParticleConditionsParticleClassName)
537 
538  fPartCond = cond;
539  if (upcast_class != "") fPartCond.SetParticleClassName(upcast_class);
540  else if (fPartName != "") fPartCond.SetParticleClassName(fPartName);
541 }
542 
543 
544 
545 
548 
550 {
551 
552  //return the list of created trees
553  return lhisto;
554 
555 }
556 
557 
558 
559 
561 
562 TH1* KVEventSelector::GetHisto(const Char_t* histo_name) const
563 {
564 
565  return lhisto->get_object<TH1>(histo_name);
566 
567 }
568 
569 
570 
571 
575 
577 {
578  // Declare a histogram to be used in analysis.
579  // This method must be called when using PROOF.
580 
581  if (fDisableCreateTreeFile) return;
582  histo->SetDirectory(nullptr);
583  lhisto->Add(histo);
584  fOutput->Add(histo);
585  if (!fOutput->FindObject("ThereAreHistos")) fOutput->Add(new TNamed("ThereAreHistos", "...so save them!"));
586 }
587 
588 
589 
592 
593 TTree* KVEventSelector::AddTree(const TString& name, const TString& title, Int_t splitLevel, TDirectory* dir)
594 {
595  // Add TTree with given name and title to list of TTree to be filled by user's analysis
596 
597  auto t = new TTree(name, title, splitLevel, dir);
598  add_tree(t);
599  return t;
600 }
601 
602 
603 
604 
610 
611 void KVEventSelector::FillHisto(const Char_t* histo_name, Double_t one, Double_t two, Double_t three, Double_t four)
612 {
613 
614  //Find in the list, if there is an histogram named "sname"
615  //If not print an error message
616  //If yes redirect to the right method according to its closest mother class
617  //to fill it
618  TH1* h1 = 0;
619  if ((h1 = GetHisto(histo_name))) {
620  if (h1->InheritsFrom("TH3"))
621  FillTH3((TH3*)h1, one, two, three, four);
622  else if (h1->InheritsFrom("TProfile2D"))
623  FillTProfile2D((TProfile2D*)h1, one, two, three, four);
624  else if (h1->InheritsFrom("TH2"))
625  FillTH2((TH2*)h1, one, two, three);
626  else if (h1->InheritsFrom("TProfile"))
627  FillTProfile((TProfile*)h1, one, two, three);
628  else if (h1->InheritsFrom("TH1"))
629  FillTH1(h1, one, two);
630  else
631  Warning("FillHisto", "%s -> Classe non prevue ...", lhisto->FindObject(histo_name)->ClassName());
632  }
633  else {
634  Warning("FillHisto", "%s introuvable", histo_name);
635  }
636 
637 }
638 
639 
640 
643 
644 void KVEventSelector::FillHisto(const Char_t* histo_name, const Char_t* label, Double_t weight)
645 {
646  // Fill 1D histogram with named bins
647  TH1* h1 = 0;
648  if ((h1 = GetHisto(histo_name))) {
649  h1->Fill(label, weight);
650  }
651  else {
652  Warning("FillHisto", "%s introuvable", histo_name);
653  }
654 
655 }
656 
657 
658 
659 
661 
663 {
664 
665  h1->Fill(one, two);
666 
667 }
668 
669 
670 
671 
673 
675 {
676 
677  h1->Fill(one, two, three);
678 
679 }
680 
681 
682 
683 
685 
687 {
688 
689  h2->Fill(one, two, three);
690 
691 }
692 
693 
694 
695 
697 
699 {
700 
701  h2->Fill(one, two, three, four);
702 }
703 
704 
705 
706 
708 
710 {
711 
712  h3->Fill(one, two, three, four);
713 }
714 
715 
716 
726 
728 {
729  // Called by SlaveBegin() when user gives the following options:
730  //
731  //~~~~~~~~~~~~~~~~
732  // AuxFiles: list of files containing "friend" TTrees to be made available during analysis
733  // AuxDir: directory in which to find AuxFiles
734  // AuxTreeName: name of tree in AuxFiles containing KVEvent objects
735  // AuxBranchName: name of branch in AuxFiles containing KVEvent objects
736  //~~~~~~~~~~~~~~~~
737 
738  if (!IsOptGiven("AuxDir") || !IsOptGiven("AuxTreeName") || !IsOptGiven("AuxBranchName")) {
739  Error("SetUpAuxEventChain", "if AuxFiles option given, you must define AuxDir, AuxTreeName and AuxBranchName");
740  return;
741  }
742  KVString filelist = GetOpt("AuxFiles");
743  KVString filedir = GetOpt("AuxDir");
744  if (!filedir.EndsWith("/")) filedir += "/";
745  TChain* auxchain = new TChain(GetOpt("AuxTreeName"));
746  filelist.Begin("|");
747  while (!filelist.End()) {
748  KVString path = filedir + filelist.Next();
749  auxchain->Add(path);
750  }
751  InitFriendTree(auxchain, GetOpt("AuxBranchName"));
752 }
753 
754 
755 
756 
771 
772 void KVEventSelector::SaveHistos(const Char_t* filename, Option_t* option, Bool_t onlyfilled)
773 {
774  // Write in file all histograms declared with AddHisto(TH1*)
775  // This method works with PROOF.
776  //
777  // If no filename is specified, set default name : HistoFileFrom[KVEvenSelector::GetName()].root
778  //
779  // If a filename is specified, search in gROOT->GetListOfFiles() if
780  // this file has been already opened
781  // - if yes write in it
782  // - if not, create it with the corresponding option, write in it
783  // and close it just after
784  //
785  // onlyfilled flag allow to write all (onlyfilled=kFALSE, default)
786  // or only histograms (onlyfilled=kTRUE) those have been filled
787 
788  TString histo_file_name = "";
789  if (!strcmp(filename, ""))
790  histo_file_name.Form("HistoFileFrom%s.root", GetName());
791  else
792  histo_file_name = filename;
793 
794  Bool_t justopened = kFALSE;
795 
796  TFile* file = 0;
797  TDirectory* pwd = gDirectory;
798  //if filename correspond to an already opened file, write in it
799  //if not open/create it, depending on the option ("recreate" by default)
800  //and write in it
801  if (!(file = (TFile*)gROOT->GetListOfFiles()->FindObject(histo_file_name.Data()))) {
802  file = new TFile(histo_file_name.Data(), option);
803  justopened = kTRUE;
804  }
805  file->cd();
806  TIter next(GetOutputList());
807  TObject* obj = 0;
808  while ((obj = next())) {
809  if (obj->InheritsFrom("TH1")) {
810  if (onlyfilled) {
811  if (((TH1*)obj)->GetEntries() > 0) {
812  obj->Write();
813  }
814  }
815  else {
816  obj->Write();
817  }
818  }
819  }
820  if (justopened)
821  file->Close();
822  pwd->cd();
823 
824 }
825 
826 
827 
828 
831 
833 {
834  //return the list of created trees
835  return ltree;
836 
837 }
838 
839 
840 
841 
844 
845 TTree* KVEventSelector::GetTree(const Char_t* tree_name) const
846 {
847  //return the tree named tree_name
848  TTree* t = ltree->get_object<TTree>(tree_name);
849  if (!t) Fatal("GetTree", "Tree %s not found: is this the right name?", tree_name);
850  return t;
851 }
852 
853 
854 
855 
862 
863 void KVEventSelector::FillTree(const Char_t* tree_name)
864 {
865  //Filltree method, the tree named tree_name
866  //has to be declared with AddTTree(TTree*) method
867  //
868  //if no sname="", all trees in the list is filled
869  //
870  if (!strcmp(tree_name, "")) {
871  ltree->Execute("Fill", "");
872  }
873  else {
874  TTree* tt = 0;
875  if ((tt = GetTree(tree_name))) {
876  tt->Fill();
877  }
878  else {
879  Warning("FillTree", "%s introuvable", tree_name);
880  }
881  }
882 
883 }
884 
885 
886 
889 
890 void KVEventSelector::SetOpt(const Char_t* option, const Char_t* value)
891 {
892  //Set a value for an option
893  KVString tmp(value);
894  fOptionList.SetValue(option, tmp);
895 }
896 
897 
898 
899 
902 
904 {
905  // Returns kTRUE if the option 'opt' has been set
906 
907  return fOptionList.HasParameter(opt);
908 }
909 
910 
911 
912 
917 
919 {
920  // Returns the value of the option
921  //
922  // Only use after checking existence of option with IsOptGiven(const Char_t* opt)
923 
924  return fOptionList.GetTStringValue(opt);
925 }
926 
927 
928 
929 
932 
934 {
935  // Removes the option 'opt' from the internal lists, as if it had never been set
936 
937  fOptionList.RemoveParameter(opt);
938 }
939 
940 
944 
945 #ifdef USING_ROOT6
947 {
948  // Call this method in your InitRun() method with the current run number in order to
949  // automatically reject events which are not consistent with the acquisition trigger.
951 }
952 
953 
966 
967 #endif
969 {
970  // Analyse comma-separated list of options given to TTree::Process
971  // and store all `"option=value"` pairs in fOptionList.
972  // Options can then be accessed using IsOptGiven(), GetOptString(), etc.
973  //
974  //~~~~~~~~~~~~~~~
975  // BranchName=xxxx : change name of branch in TTree containing data
976  // EventsReadInterval=N: print "+++ 12345 events processed +++" every N events
977  //~~~~~~~~~~~~~~~
978  //
979  // This method is called by SlaveBegin
980  //
981 
982  fOptionList.Clear(); // clear list
983  KVString option = GetOption();
984  option.Begin(",");
985  while (!option.End()) {
986 
987  KVString opt = option.Next();
988  opt.Begin("=");
989  KVString param = opt.Next();
990  KVString val = opt.Next();
991  while (!opt.End()) {
992  val += "=";
993  val += opt.Next();
994  }
995 
996  SetOpt(param.Data(), val.Data());
997  }
998 
999  fOptionList.Print();
1000  // check for branch name
1001  if (IsOptGiven("BranchName")) SetBranchName(GetOpt("BranchName"));
1002  // check for events read interval
1003  if (IsOptGiven("EventsReadInterval")) SetEventsReadInterval(GetOpt("EventsReadInterval").Atoi());
1004 }
1005 
1006 
1007 
1017 
1019 {
1020  // The Init() function is called when the selector needs to initialize
1021  // a new tree or chain. Typically here the branch addresses and branch
1022  // pointers of the tree will be set.
1023  // It is normally not necessary to make changes to the generated
1024  // code, but the routine can be extended by the user if needed.
1025  // Init() will be called many times when running on PROOF
1026  // (once per file to be processed).
1027 
1028  // Set object pointer
1029  Event = nullptr;
1030  // Set branch addresses and branch pointers
1031  if (!tree) return;
1032  fChain = tree;
1033  fChain->SetMakeClass(1);
1034 
1035  if (strcmp(GetBranchName(), "") && fChain->GetBranch(GetBranchName())) {
1036  Info("Init", "Analysing data in branch : %s", GetBranchName());
1037  fChain->SetBranchAddress(GetBranchName(), &Event, &b_Event);
1038  }
1039  else {
1040  Error("Init", "Failed to link KVEvent object with a branch. Expected branch name=%s",
1041  GetBranchName());
1042  }
1043  //user additional branches addressing
1044  SetAdditionalBranchAddress();
1045  fEventsRead = 0;
1046 
1047 }
1048 
1049 
1050 
1063 
1065 {
1066  // Set up a "friend" TTree/TChain containing KVEvent-derived objects in branch 'branchname'
1067  // N.B. this is not a "friend" in the sense of TTree::AddFriend, the main TTree and the
1068  // "friend" TTree can have different numbers of entries
1069  //
1070  // After calling this method at the beginning of the analysis, you can
1071  // access any of the events stored in the "friend" by doing:
1072  //
1073  //~~~~~~~~~~~~
1074  // GetFriendTreeEntry(entry_number);
1075  // KVEvent* friend_event = GetFriendEvent();
1076  //~~~~~~~~~~~~
1077 
1078  AuxEvent = 0;
1079  fAuxChain = tree;
1080  fAuxChain->SetBranchAddress(branchname, &AuxEvent);
1081  fAuxChain->Print();
1082  fAuxChain->GetEntry(0);
1083  fAuxChain->GetTree()->GetEntry(0);
1084 }
1085 
1086 
1087 
1094 
1096 {
1097  // The Notify() function is called when a new file is opened. This
1098  // can be either for a new TTree in a TChain or when when a new TTree
1099  // is started when using PROOF. It is normally not necessary to make changes
1100  // to the generated code, but the routine can be extended by the
1101  // user if needed. The return value is currently not used.
1102 
1103  if (fNotifyCalled) return kTRUE; // avoid multiple calls at beginning of analysis
1104  fNotifyCalled = kTRUE;
1105 
1106  Info("Notify", "Beginning analysis of file %s (%lld events)", fChain->GetCurrentFile()->GetName(), fChain->GetTree()->GetEntries());
1107 
1109  InitRun(); //user initialisations for run
1111 
1113 
1114  return kTRUE;
1115 }
1116 
1117 
int Int_t
KVDataAnalyser * gDataAnalyser
KVDataRepositoryManager * gDataRepositoryManager
KVDataSetManager * gDataSetManager
KVDataSet * gDataSet
Definition: KVDataSet.cpp:30
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
#define gDirectory
R__EXTERN TProof * gProof
#define gROOT
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
static void CombineFiles(const Char_t *file1, const Char_t *file2, const Char_t *newfilename, Bool_t keep=kTRUE)
Definition: KVBase.cpp:1490
static KVClassMonitor * GetInstance()
Return pointer to unique instance of class monitor class.
void SetInitStatistics()
virtual void SetTriggerConditionsForRun(int)
virtual void postEndRun()
void DoStatusUpdate(Long64_t nevents) const
Print infos on events treated, disk usage, memory usage.
virtual void AddJobDescriptionList(TList *)
virtual void preInitAnalysis()
virtual void postAnalysis()
void SetAnalysisTask(KVDataAnalysisTask *at)
void SetProofMode(EProofMode e)
virtual Bool_t CheckStatusUpdateInterval(Long64_t nevents) const
virtual void preAnalysis()
static KVDataAnalyser * GetAnalyser(const Char_t *plugin)
virtual void preEndRun()
virtual void postInitRun()
static Bool_t AbortProcessingLoop()
virtual void postEndAnalysis()
virtual void preEndAnalysis()
virtual void preInitRun()
virtual void RegisterUserClass(TObject *)
virtual void postInitAnalysis()
Define and manage data analysis tasks.
virtual const Char_t * GetDataAnalyser() const
Manages access to one or more data repositories.
KVDataRepository * GetRepository(const Char_t *name) const
Pilots user analysis of experimental data.
Manage all datasets contained in a given data repository.
virtual Bool_t Init(KVDataRepository *=0)
KVDataAnalysisTask * GetAnalysisTaskAny(const Char_t *keywords) const
KVDataSet * GetDataSet(Int_t) const
Return pointer to DataSet using index in list of all datasets, index>=0.
virtual KVDataAnalysisTask * GetAnalysisTask(Int_t) const
Definition: KVDataSet.cpp:588
General purpose analysis class for TTree containing KVEvent objects.
virtual void SaveHistos(const Char_t *filename="", Option_t *option="recreate", Bool_t onlyfilled=kFALSE)
void FillTProfile2D(TProfile2D *h2, Double_t one, Double_t two, Double_t three, Double_t four)
void AddGV(KVVarGlob *vg)
const KVHashList * GetTreeList() const
return the list of created trees
TH1 * GetHisto(const Char_t *name) const
void SetParticleConditions(const KVParticleCondition &, const KVString &="")
void FillTree(const Char_t *sname="")
void InitFriendTree(TTree *tree, const TString &branchname)
virtual void SetOpt(const Char_t *option, const Char_t *value)
Set a value for an option.
const KVHashList * GetHistoList() const
return the list of created trees
TTree * GetTree(const Char_t *name) const
return the tree named tree_name
virtual void CheckEndOfRun()
Testing whether EndRun() should be called.
void FillTH2(TH2 *h2, Double_t one, Double_t two, Double_t three)
Bool_t CreateTreeFile(const Char_t *filename="")
void AddTree(TTree *tree)
virtual void SlaveBegin(TTree *tree)
virtual void SlaveTerminate()
virtual void Terminate()
virtual Bool_t Notify()
void add_histo(TH1 *histo)
void FillHisto(const Char_t *sname, Double_t one, Double_t two=1, Double_t three=1, Double_t four=1)
virtual Bool_t IsOptGiven(const Char_t *option)
Returns kTRUE if the option 'opt' has been set.
void FillTProfile(TProfile *h1, Double_t one, Double_t two, Double_t three)
void SetTriggerConditionsForRun(int)
void FillTH1(TH1 *h1, Double_t one, Double_t two)
virtual void Init(TTree *tree)
virtual void RecalculateGlobalVariables()
virtual Bool_t Process(Long64_t entry)
virtual TString GetOpt(const Char_t *option) const
virtual void ParseOptions()
void FillTH3(TH3 *h3, Double_t one, Double_t two, Double_t three, Double_t four)
virtual void UnsetOpt(const Char_t *opt)
Removes the option 'opt' from the internal lists, as if it had never been set.
Extended version of ROOT THashList.
Definition: KVHashList.h:28
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Int_t GetIntValue(const Char_t *name) const
const Char_t * GetStringValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:125
Handles particle selection criteria for data analysis classes ,.
void SetParticleClassName(const Char_t *cl)
void SetIsOK(Bool_t flag=kTRUE)
Definition: KVParticle.cpp:333
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
void Begin(TString delim) const
Definition: KVString.cpp:562
Bool_t End() const
Definition: KVString.cpp:625
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:675
Base class for all global variable implementations.
Definition: KVVarGlob.h:217
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
const char * AsString() const
virtual void Close(Option_t *option="")
virtual Bool_t cd(const char *path=nullptr)
virtual void SetDirectory(TDirectory *dir)
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 Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
virtual Bool_t InheritsFrom(const char *classname) const
virtual Int_t Fill(const char *namex, const char *namey, Double_t z, Double_t w=1.)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
void Form(const char *fmt,...)
virtual int Rename(const char *from, const char *to)
long long Long64_t
RooCmdArg ClassName(const char *name)
TH1F * h1
void Info(const char *location, const char *va_(fmt),...)
void Error(const char *location, const char *va_(fmt),...)
void Fatal(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