KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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#include "TProofOutputFile.h"
18#include "KVDataAnalyser.h"
19
192
193protected :
196
200
203
207
209
211
213
217
220
223
226
228 TFile* writeFile = nullptr;
230
231 void add_histo(TH1* histo);
232 void add_tree(TTree* tree);
233 void FillTH1(TH1* h1, Double_t one, Double_t two);
238
239 void SetUpAuxEventChain();
241 void SetCombinedOutputFile(const TString& filename)
242 {
258
261 }
262 void create_output_file();
263 virtual void CheckEndOfRun();
265 {
266 Event = e;
267 }
268 virtual void ParseOptions();
270 {
272 return (fTreeEntry + 1 == fChain->GetTree()->GetEntries());
273 }
276 {
280 if (gDataAnalyser->GetKinematics())
281 GetEvent()->SetFrame("CM", gDataAnalyser->GetKinematics()->GetCMVelocity());
282 }
283
284
285public:
286 Bool_t CreateTreeFile(const Char_t* filename = "");
287
297 virtual Int_t Version() const
298 {
299 return 3;
300 }
301 virtual void Begin(TTree* tree);
302 virtual void SlaveBegin(TTree* tree);
303 virtual void Init(TTree* tree);
304
305 virtual Bool_t Notify();
306 virtual Bool_t Process(Long64_t entry);
308 {
309 return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0;
310 }
316 {
317 return AuxEvent;
318 }
319 virtual void SetObject(TObject* obj)
320 {
321 fObject = obj;
322 }
323 virtual void SetInputList(TList* input)
324 {
325 fInput = input;
326 }
327 virtual TList* GetOutputList() const
328 {
329 return fOutput;
330 }
331 virtual void SlaveTerminate();
332 virtual void Terminate();
333
334 void SetBranchName(const Char_t* n)
335 {
336 fBranchName = n;
337 }
338 const Char_t* GetBranchName() const
339 {
340 return fBranchName.Data();
341 }
342 virtual void SetCurrentRun(KVDBRun*) {}
343
350 {
351 return Event;
352 }
357 {
358 if (!GetEvent()) {
359 Error("GetEventNumber", "No event defined!!!");
360 return -1;
361 }
362 return GetEvent()->GetNumber();
363 }
364
397 virtual void InitAnalysis()
398 {
399 AbstractMethod("InitAnalysis");
400 }
418 virtual void InitRun()
419 {
420 AbstractMethod("InitRun");
421 }
453 virtual Bool_t Analysis()
454 {
455 return kTRUE;
456 }
457 virtual void EndRun()
458 {
459 AbstractMethod("EndRun");
460 }
461 virtual void EndAnalysis()
462 {
463 AbstractMethod("EndAnalysis");
464 }
465
474 {
475 if (list_name != "" && GetGVList(list_name)) {
476 Error("AddGVList", "You tried to add a list with the same name '%s' as an existing list: no list created",
477 list_name.Data());
478 return nullptr;
479 }
480 auto gvl = new KVGVList(list_name, selection);
482 return gvl;
483 }
500 {
502 if (!l) {
503 if (list_name == "default") {
504 l = new KVGVList("default");
506 }
507 else if (list_name == "__internal__") {
508 l = new KVGVList("__internal__", KVParticleCondition());
510 }
511 }
512 return l;
513 }
514
519 const KVGVList* GetGVList(const KVString& list_name = "default") const
520 {
522 }
531 {
532 if (!vg)
533 Error("AddGV(KVVarGlob*)", "KVVarGlob pointer is null");
534 else
535 GetGVList()->Add(vg);
536 }
545 KVVarGlob* AddGV(const Char_t* class_name, const Char_t* name)
546 {
547 return GetGVList()->AddGV(class_name, name);
548 }
549
558 KVVarGlob* GetGV(const Char_t* name) const
559 {
560 auto gv = GetGVList()->GetGV(name);
561 if (!gv) {
562 Error("GetGV(const Char_t* name)", "Request for undefined global variable name=%s", name);
563 }
564 return gv;
565 }
566
579
580 void AddHisto(TH1* histo)
581 {
582 Deprecate(Form("You should use e.g. 'auto h = AddHisto<%s>(\"%s\",\"%s\",%d,...);' to add histograms to your analysis.",
583 histo->ClassName(), histo->GetName(), histo->GetTitle(), histo->GetNbinsX()));
584 add_histo(histo);
585 }
586
602 template<typename HistoType, typename... Args>
604 {
605 auto h = new HistoType(std::forward<Args>(args)...);
606 add_histo(h);
607 return h;
608 }
609
611 {
612 Deprecate(Form("You should use e.g. 'auto t = AddTree(\"%s\", \"%s\");' to add a TTree to your analysis",
613 tree->GetName(), tree->GetTitle()));
614 add_tree(tree);
615 }
616
625 TTree* AddTree(const TString& name, const TString& title = "");
626
627 void FillHisto(const Char_t* sname, Double_t one, Double_t two = 1, Double_t three = 1, Double_t four = 1);
628 void FillHisto(const Char_t* sname, const Char_t* label, Double_t weight = 1);
629
635 void FillTree(const Char_t* tree_name = "");
636
641 {
642 return &lhisto;
643 }
644
649 const KVHashList* GetTreeList() const
650 {
651 return &ltree;
652 }
653
658 TH1* GetHisto(const Char_t* name) const
659 {
660 return lhisto.get_object<TH1>(name);
661 }
662
667 TTree* GetTree(const Char_t* name) const
668 {
670 if (!t) Fatal("GetTree", "Tree %s not found: is this the right name?", name);
671 return t;
672 }
673
674 virtual void SaveHistos(const Char_t* = "", Option_t* = "recreate", Bool_t = kFALSE)
675 {
676 Error("SaveHistos", "Method no longer implemented. Does nothing.");
677 }
678
679 void SetOpt(const Char_t* option, const Char_t* value)
680 {
682 }
683 Bool_t IsOptGiven(const Char_t* option)
684 {
686 }
687 TString GetOpt(const Char_t* option) const
688 {
689 return fOptionList.GetOpt(option);
690 }
691 void UnsetOpt(const Char_t* opt)
692 {
694 }
695
703 {
704 }
705
715 void SetJobOutputFileName(const TString& filename)
716 {
718 SetCombinedOutputFile(Form("%s.root", gDataAnalyser->GetBatchSystem()->GetJobName()));
719 else
721 }
722
730 {
731 gDataAnalyser->SetTriggerConditionsForRun(run);
732 }
733 ClassDef(KVEventSelector, 0)//General purpose analysis class for TTrees containing KVEvent objects
734};
735
740#define AddVar(var,type) Branch(dadastr(var), &var, didixstr(duduvartype(var,type)))
741#define AddVarBranch(var,branch,type) Branch(dadastr(branch), &var, didixstr(duduvartype(branch,type)))
742#define duduvartype(var,type) var/type
743#define didixstr(s) dadastr(s)
744#define dadastr(s) #s
745
746#endif
int Int_t
#define e(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
#define ClassDef(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:572
UInt_t GetNumber() const
Definition KVBase.h:220
virtual const Char_t * GetJobName() const
Description of an experimental run in database ,,.
Definition KVDBRun.h:36
virtual void SetTriggerConditionsForRun(int)
virtual const KV2Body * GetKinematics() const
virtual const KVBatchSystem * GetBatchSystem()
EProofMode GetProofMode() const
static Bool_t IsRunningBatchAnalysis()
General purpose analysis base class for TTree containing KVEvent objects.
virtual void SetInputList(TList *input)
void FillTProfile2D(TProfile2D *h2, Double_t one, Double_t two, Double_t three, Double_t four)
virtual Int_t Version() const
virtual void SaveHistos(const Char_t *="", Option_t *="recreate", Bool_t=kFALSE)
void AddGV(KVVarGlob *vg)
const KVHashList * GetTreeList() const
GetTreeList.
Bool_t fDisableCreateTreeFile
used with PROOF
KVEventSelector(TTree *=0)
Bool_t fFirstEvent
set to kFALSE after first event is read
Int_t GetFriendTreeEntry(Long64_t entry, Int_t getall=0)
TH1 * GetHisto(const Char_t *name) const
TProofOutputFile * mergeFile
output file for trees and histos
KVHashList lhisto
list of histograms added with AddHisto
virtual void InitAnalysis()
KVHashList ltree
list of trees added with AddTree
KVVarGlob * AddGV(const Char_t *class_name, const Char_t *name)
void InitFriendTree(TTree *tree, const TString &branchname)
void SetParticleConditions(const KVParticleCondition &cond)
void SetOpt(const Char_t *option, const Char_t *value)
virtual void EndRun()
TTree * fAuxChain
[optional] pointer to another TTree or TChain which may be used during analysis
const KVHashList * GetHistoList() const
void SetCombinedOutputFile(const TString &filename)
virtual Bool_t Analysis()
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
KVEvent * Event
Declaration of leaf types.
TTree * GetTree(const Char_t *name) const
Long64_t fEventsRead
number of events read
virtual void CheckEndOfRun()
void FillTH2(TH2 *h2, Double_t one, Double_t two, Double_t three)
KVEvent * GetEvent() const
virtual void Begin(TTree *tree)
Long64_t fTreeEntry
current tree entry number
virtual TList * GetOutputList() const
TTree * fChain
pointer to the analyzed TTree or TChain
KVVarGlob * GetGV(const Char_t *name) const
Bool_t CreateTreeFile(const Char_t *filename="")
KVString fCombinedOutputFile
name for ROOT file containing histos and/or trees produced by analysis
void AddTree(TTree *tree)
KVString fBranchName
name of branch which contains events to analyse
virtual void SlaveBegin(TTree *tree)
virtual void SlaveTerminate()
virtual void Terminate()
virtual Bool_t Notify()
void SetEventsReadInterval(Long64_t N)
void SetJobOutputFileName(const TString &filename)
void add_histo(TH1 *histo)
for merging with PROOF
void AddHisto(TH1 *histo)
void FillHisto(const Char_t *sname, Double_t one, Double_t two=1, Double_t three=1, Double_t four=1)
Bool_t AtEndOfRun(void)
KVUniqueNameList fGlobalVariables
Lists of global variables with different selection criteria.
TBranch * b_Event
List of branches.
void SetBranchName(const Char_t *n)
virtual void SetAdditionalBranchAddress()
Bool_t IsOptGiven(const Char_t *option)
void FillTProfile(TProfile *h1, Double_t one, Double_t two, Double_t three)
virtual void SetCurrentRun(KVDBRun *)
KVParticleCondition fPartCond
(optional) conditions for selecting particles
void FillTH1(TH1 *h1, Double_t one, Double_t two)
virtual void SetObject(TObject *obj)
void add_tree(TTree *tree)
void RecalculateGlobalVariables()
void SetTriggerConditionsForRun(int run)
const KVGVList * GetGVList(const KVString &list_name="default") const
virtual Bool_t Process(Long64_t entry)
Bool_t fNotifyCalled
avoid multiple calls to Notify/InitRun
TString GetOpt(const Char_t *option) const
const Char_t * GetBranchName() const
virtual void EndAnalysis()
virtual void ParseOptions()
void SetEvent(KVEvent *e)
Bool_t fGlobalVariableAbortEventAnalysis
KVEvent * AuxEvent
[optional] events in fAuxChain
KVGVList * AddGVList(const KVString &list_name, const KVParticleCondition &selection=KVParticleCondition())
Long64_t fEventsReadInterval
interval at which to print number of events read
KVGVList * GetGVList(const KVString &list_name="default")
virtual void InitRun()
Int_t GetEventNumber() const
void FillTH3(TH3 *h3, Double_t one, Double_t two, Double_t three, Double_t four)
void FillTree(const Char_t *tree_name="")
KVEvent * GetFriendEvent() const
void UnsetOpt(const Char_t *opt)
HistoType * AddHisto(Args &&... args)
KVUserAnalysisOptionList fOptionList
parsed list of options given to TTree::Process
Abstract base class container for multi-particle events.
Definition KVEvent.h:67
virtual void SetFrame(const Char_t *, const KVFrameTransform &)=0
#define KVGVLIST_OPTIMIZE_GVLIST
Definition KVGVList.h:227
KVVarGlob * AddGV(const Char_t *class_name, const Char_t *name)
Definition KVGVList.cpp:705
virtual void Add(TObject *obj)
Definition KVGVList.cpp:336
KVVarGlob * GetGV(const Char_t *nom) const
Return pointer to global variable in list with name 'nom'.
Definition KVGVList.cpp:319
Extended version of ROOT THashList.
Definition KVHashList.h:29
virtual TObject * FindObject(const char *name) const
virtual void SetOwner(Bool_t enable=kTRUE)
T * get_object(const TString &name) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
Optimised list in which named objects can only be placed once.
virtual void Add(TObject *obj)
virtual void AddFirst(TObject *obj)
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
virtual Int_t GetNbinsX() const
const char * GetName() const override
const char * GetTitle() const override
void AbstractMethod(const char *method) const
virtual const char * ClassName() const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Fatal(const char *method, const char *msgfmt,...) 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
TH1 * h
TLine l