KaliVeda
Toolkit for HIC analysis
KVEventSelector.h
1 #ifndef KVEventSelector_h
2 #define KVEventSelector_h
3 
4 #include <TROOT.h>
5 #include <TChain.h>
6 #include <TFile.h>
7 #include <TSelector.h>
8 #include "KVEvent.h"
9 #include "KVGVList.h"
10 #include "KVString.h"
11 #include "KVParticleCondition.h"
12 #include "KVHashList.h"
13 #include <TH3.h>
14 #include <TH2.h>
15 #include <TProfile2D.h>
16 #include "KVUserAnalysisOptionList.h"
17 #ifdef WITH_PROOF
18 #include "TProofOutputFile.h"
19 #endif
20 #include "KVDataAnalyser.h"
21 #include "KVTreeVectorBranchHandler.h"
22 #include "KVDataAnalysisTreeHistoHandler.h"
23 
202 class KVEventSelector : public TSelector,
203  protected KVTreeVectorBranchHandler,
204  public KVDataAnalysisTreeHistoHandler<KVEventSelector>
205 {
206 
208 protected :
209  TTree* fChain;
210  TTree* fAuxChain;
211 
213  KVEvent* Event;
214  KVEvent* AuxEvent;
215 
217  TBranch* b_Event;
218 
220  KVUniqueNameList fGlobalVariables;
221  Bool_t fGlobalVariableAbortEventAnalysis;
222 
223  KVString fBranchName;
224 
225  KVParticleCondition fPartCond;
226 
227  Bool_t fFirstEvent;
228 
229  Long64_t fEventsRead;
230  Long64_t fEventsReadInterval;
231  Long64_t fTreeEntry;
232 
233  Bool_t fNotifyCalled;
234  KVString fCombinedOutputFile;
235 
237  KVUserAnalysisOptionList fOptionList;
238 
239  Bool_t fDisableCreateTreeFile;
240  TFile* writeFile = nullptr;
241 #ifdef WITH_PROOF
242  TProofOutputFile* mergeFile = nullptr;
243 #endif
244  void add_histo(TH1* histo);
245  void add_tree(TTree* tree);
246 
247  void SetUpAuxEventChain();
248  void InitFriendTree(TTree* tree, const TString& branchname);
249  void SetCombinedOutputFile(const TString& filename)
250  {
265  fCombinedOutputFile = filename;
266 
268  create_output_file();
269  }
270  void create_output_file();
271  virtual void CheckEndOfRun();
272  void SetEvent(KVEvent* e)
273  {
274  Event = e;
275  }
276  virtual void ParseOptions();
277  Bool_t AtEndOfRun(void)
278  {
280  return (fTreeEntry + 1 == fChain->GetTree()->GetEntries());
281  }
282  void RecalculateGlobalVariables();
283  void SetAnalysisFrame()
284  {
288  if (gDataAnalyser->GetKinematics())
289  GetEvent()->SetFrame("CM", gDataAnalyser->GetKinematics()->GetCMVelocity());
290  }
291 
292 
293 public:
294  KVEventSelector(TTree* /*tree*/ = 0) : fChain(0), fAuxChain(0), fBranchName("data"), fFirstEvent(kTRUE),
295  fEventsRead(0), fEventsReadInterval(100), fNotifyCalled(kFALSE), fDisableCreateTreeFile(kFALSE)
296  {
297  fGlobalVariables.SetOwner();
298  }
300  {
301  fEventsReadInterval = N;
302  }
303  Int_t Version() const override
304  {
305  return 3;
306  }
307  void Begin(TTree* tree) override;
308  void SlaveBegin(TTree* tree) override;
309  void Init(TTree* tree) override;
310 
311  Bool_t Notify() override;
312  Bool_t Process(Long64_t entry) override;
313  Int_t GetEntry(Long64_t entry, Int_t getall = 0) override
314  {
315  return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0;
316  }
318  {
319  return fAuxChain ? fAuxChain->GetTree()->GetEntry(entry, getall) : 0;
320  }
322  {
323  return AuxEvent;
324  }
325  void SetObject(TObject* obj) override
326  {
327  fObject = obj;
328  }
329  void SetInputList(TList* input) override
330  {
331  fInput = input;
332  }
333  TList* GetOutputList() const override
334  {
335  return fOutput;
336  }
337  void SlaveTerminate() override;
338  void Terminate() override;
339 
340  void SetBranchName(const Char_t* n)
341  {
342  fBranchName = n;
343  }
344  const Char_t* GetBranchName() const
345  {
346  return fBranchName.Data();
347  }
348  virtual void SetCurrentRun(KVDBRun*) {}
349 
355  KVEvent* GetEvent() const
356  {
357  return Event;
358  }
363  {
364  if (!GetEvent()) {
365  KVError::Error(this, "GetEventNumber", "No event defined!!!");
366  return -1;
367  }
368  return GetEvent()->GetNumber();
369  }
370 
405  virtual void InitAnalysis()
406  {
407  AbstractMethod("InitAnalysis");
408  }
426  virtual void InitRun()
427  {
428  AbstractMethod("InitRun");
429  }
461  virtual Bool_t Analysis()
462  {
463  return kTRUE;
464  }
465  virtual void EndRun()
466  {
467  AbstractMethod("EndRun");
468  }
469  virtual void EndAnalysis()
470  {
471  AbstractMethod("EndAnalysis");
472  }
473 
481  KVGVList* AddGVList(const KVString& list_name, const KVParticleCondition& selection = KVParticleCondition())
482  {
483  if (list_name != "" && GetGVList(list_name)) {
484  KVError::Error(this, "AddGVList", "You tried to add a list with the same name '%s' as an existing list: no list created",
485  list_name.Data());
486  return nullptr;
487  }
488  auto gvl = new KVGVList(list_name, selection);
489  fGlobalVariables.Add(gvl);
490  return gvl;
491  }
507  KVGVList* GetGVList(const KVString& list_name = "default")
508  {
509  auto l = (KVGVList*)fGlobalVariables.FindObject(list_name);
510  if (!l) {
511  if (list_name == "default") {
512  l = new KVGVList("default");
513  fGlobalVariables.Add(l);
514  }
515  else if (list_name == "__internal__") {
516  l = new KVGVList("__internal__", KVParticleCondition());
517  fGlobalVariables.AddFirst(l);
518  }
519  }
520  return l;
521  }
522 
527  const KVGVList* GetGVList(const KVString& list_name = "default") const
528  {
529  return (KVGVList*)fGlobalVariables.FindObject(list_name);
530  }
538  void AddGV(KVVarGlob* vg)
539  {
540  if (!vg)
541  KVError::Error(this, "AddGV(KVVarGlob*)", "KVVarGlob pointer is null");
542  else
543  GetGVList()->Add(vg);
544  }
553  KVVarGlob* AddGV(const Char_t* class_name, const Char_t* name)
554  {
555  return GetGVList()->AddGV(class_name, name);
556  }
557 
566  KVVarGlob* GetGV(const Char_t* name) const
567  {
568  auto gv = GetGVList()->GetGV(name);
569  if (!gv) {
570  KVError::Error(this, "GetGV(const Char_t* name)", "Request for undefined global variable name=%s", name);
571  }
572  return gv;
573  }
574 
584  {
585  fPartCond = cond;
586  }
587 
588  virtual void SaveHistos(const Char_t* = "", Option_t* = "recreate", Bool_t = kFALSE)
589  {
590  KVError::Info(this, "SaveHistos", "Method no longer implemented. Does nothing.");
591  }
592 
593  void SetOpt(const Char_t* option, const Char_t* value)
594  {
595  fOptionList.SetOpt(option, value);
596  }
597  Bool_t IsOptGiven(const Char_t* option)
598  {
599  return fOptionList.IsOptGiven(option);
600  }
601  TString GetOpt(const Char_t* option) const
602  {
603  return fOptionList.GetOpt(option);
604  }
605  void UnsetOpt(const Char_t* opt)
606  {
607  fOptionList.UnsetOpt(opt);
608  }
609 
617  {
618  }
619 
629  void SetJobOutputFileName(const TString& filename)
630  {
631  if (KVDataAnalyser::IsRunningBatchAnalysis() && (gDataAnalyser->GetProofMode() == KVDataAnalyser::EProofMode::None))
632  SetCombinedOutputFile(Form("%s.root", gDataAnalyser->GetBatchSystem()->GetJobName()));
633  else
634  SetCombinedOutputFile(filename);
635  }
636 
644  {
645  gDataAnalyser->SetTriggerConditionsForRun(run);
646  }
647  ClassDefOverride(KVEventSelector, 0)//General purpose analysis class for TTrees containing KVEvent objects
648 };
649 
654 #define AddVar(var,type) Branch(dadastr(var), &var, didixstr(duduvartype(var,type)))
655 #define AddVarBranch(var,branch,type) Branch(dadastr(branch), &var, didixstr(duduvartype(branch,type)))
656 #define duduvartype(var,type) var/type
657 #define didixstr(s) dadastr(s)
658 #define dadastr(s) #s
659 
660 #endif
int Int_t
#define e(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
#define ClassDefOverride(name, id)
#define N
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
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 value
char name[80]
char * Form(const char *fmt,...)
TVector3 GetCMVelocity() const
Return vector velocity of centre of mass of reaction (units: cm/ns)
Definition: KV2Body.cpp:583
UInt_t GetNumber() const
Definition: KVBase.h:220
virtual const Char_t * GetJobName() const
Description of an experimental run in database ,,.
Definition: KVDBRun.h:41
virtual void SetTriggerConditionsForRun(int)
virtual const KVBatchSystem * GetBatchSystem()
virtual const KV2Body * GetKinematics() const
EProofMode GetProofMode() const
static Bool_t IsRunningBatchAnalysis()
Methods to facilitate creation and use of histograms and TTrees in user analysis.
General purpose analysis base class for TTree containing KVEvent objects.
Bool_t Process(Long64_t entry) override
virtual void SaveHistos(const Char_t *="", Option_t *="recreate", Bool_t=kFALSE)
void AddGV(KVVarGlob *vg)
KVVarGlob * GetGV(const Char_t *name) const
void SetObject(TObject *obj) override
KVEventSelector(TTree *=0)
Int_t GetFriendTreeEntry(Long64_t entry, Int_t getall=0)
const Char_t * GetBranchName() const
virtual void InitAnalysis()
void SetParticleConditions(const KVParticleCondition &cond)
void SetOpt(const Char_t *option, const Char_t *value)
virtual void EndRun()
void Init(TTree *tree) override
virtual Bool_t Analysis()
void SetInputList(TList *input) override
Bool_t Notify() override
Int_t GetEntry(Long64_t entry, Int_t getall=0) override
Int_t Version() const override
void SetEventsReadInterval(Long64_t N)
void SetJobOutputFileName(const TString &filename)
const KVGVList * GetGVList(const KVString &list_name="default") const
void SetBranchName(const Char_t *n)
KVGVList * GetGVList(const KVString &list_name="default")
virtual void SetAdditionalBranchAddress()
Bool_t IsOptGiven(const Char_t *option)
virtual void SetCurrentRun(KVDBRun *)
KVEvent * GetFriendEvent() const
KVEvent * GetEvent() const
void SlaveTerminate() override
void SlaveBegin(TTree *tree) override
void SetTriggerConditionsForRun(int run)
KVVarGlob * AddGV(const Char_t *class_name, const Char_t *name)
KVGVList * AddGVList(const KVString &list_name, const KVParticleCondition &selection=KVParticleCondition())
TString GetOpt(const Char_t *option) const
virtual void EndAnalysis()
TList * GetOutputList() const override
virtual void InitRun()
Int_t GetEventNumber() const
void Terminate() override
void Begin(TTree *tree) override
void UnsetOpt(const Char_t *opt)
Abstract base class container for multi-particle events.
Definition: KVEvent.h:67
virtual void SetFrame(const Char_t *, const KVFrameTransform &)=0
Manage a list of global variables.
Definition: KVGVList.h:225
void Add(TObject *obj) override
Definition: KVGVList.cpp:336
KVVarGlob * AddGV(const Char_t *class_name, const Char_t *name)
Definition: KVGVList.cpp:705
KVVarGlob * GetGV(const Char_t *nom) const
Return pointer to global variable in list with name 'nom'.
Definition: KVGVList.cpp:319
Implement selections for KVNucleus objects.
TObject * FindObject(const char *name) const override
void SetOwner(Bool_t enable=kTRUE) override
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
Facilitate use of std::vector branches in data analysis.
Optimised list in which named objects can only be placed once.
void AddFirst(TObject *obj) override
void Add(TObject *obj) override
Handle list of options and input parameters for user analyis .
void SetOpt(const Char_t *option, const Char_t *value)
TString GetOpt(const Char_t *opt) const
Bool_t IsOptGiven(const Char_t *opt)
void UnsetOpt(const Char_t *opt)
Base class for all global variable implementations.
Definition: KVVarGlob.h:233
void AbstractMethod(const char *method) const
TList * fInput
TSelectorList * fOutput
TObject * fObject
const char * Data() const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntries() const
virtual TTree * GetTree() const
long long Long64_t
const Int_t n
void Error(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:116
void Info(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:134
TLine l