KaliVeda
Toolkit for HIC analysis
KVSimDirFilterAnalyser.cpp
1 //Created by KVClassFactory on Thu Mar 23 14:02:40 2017
2 //Author: John Frankland,,,
3 
4 #include "KVSimDirFilterAnalyser.h"
5 #include <KVClassFactory.h>
6 #include <KVDataSetManager.h>
7 #include <KVExpDB.h>
8 #include <KVTriggerConditions.h>
9 #include "KVMultiDetArray.h"
10 #include "KVNucleusEvent.h"
11 
13 
14 
15 
20 {
21  // Default constructor
22 }
23 
24 
25 
26 
29 
31 {
32  // Destructor
33 
34  if (fKinematics->TestBit(kCanDelete)) delete fKinematics;
35 }
36 
37 
38 
41 
43 {
44  // Use options passed to KVEventSelector to initialise dataset used for filter
45 
46  if (!gDataSetManager) {
47  gDataSetManager = new KVDataSetManager;
48  gDataSetManager->Init();
49  }
50  if (!gDataSet) gDataSetManager->GetDataSet(fAnalysisClass->GetOpt("DataSet"))->cd();
51 }
52 
53 
54 
58 
60 {
61  // Use options passed to KVEventSelector to initialise kinematics for reaction
62  // and build experimental set-up
63 
64  KVString system = fAnalysisClass->GetOpt("System");
65  fSystem = gExpDB->GetSystem(system);
66  bool adhoc_system=false;
67  if (fSystem) {
68  fKinematics = fSystem->GetKinematics();
69  }
70  else {
71  adhoc_system=true;
72  fKinematics = new KV2Body(system);
73  fKinematics->SetBit(kCanDelete); // clean up in destructor
74  fKinematics->CalculateKinematics();
75  }
76  fRun = nullptr;
77  if(fAnalysisClass->IsOptGiven("Run"))
78  {
79  KVString run = fAnalysisClass->GetOpt("Run");
80  fRun = gExpDB->GetDBRun(run.Atoi());
81  }
82  else if(adhoc_system)
83  {
84  // ad hoc systems are not in the database and not associated to any run
85  // we take first run of first physical (reaction) system (?)
86  KVDBSystem* sys;
87  TIter nxt_sys(gExpDB->GetSystems());
88  while((sys = (KVDBSystem*)nxt_sys()))
89  {
90  if(sys->IsCollision())
91  {
92  fRun = (KVDBRun*)sys->GetRuns().First();
93  break;
94  }
95  }
96  }
97  if(fRun)
98  fAnalysisClass->SetCurrentRun(fRun);
99 
100  KVMultiDetArray::MakeMultiDetector(gDataSet->GetName(), fRun ? fRun->GetNumber() : -1);
101  // put detector array in simulation mode
102  gMultiDetArray->SetSimMode();
103 }
104 
105 
106 
111 
113 {
114  // Called by KVEventSelector just after reading new event and just before calling user analysis
115  //
116  // Copy calculated energy losses of all particles into the detectors
117 
118  for (auto& n : EventIterator(fAnalysisClass->GetEvent())) {
119  for (auto& p : *n.GetParameters()) {
120  auto d = gMultiDetArray->GetDetector(p.GetName());
121  if (d) {
122  // sum up energy losses in each detector
123  d->SetEnergyLoss(p.GetDouble() + d->GetEnergyLoss());
124  }
125  }
126  }
127 }
128 
129 
130 
133 
135 {
136  // Generate a new filtered analysis selector class
137 
138  KVClassFactory cf(kvsname, "Analysis of filtered simulated events", "",
139  kTRUE, "ROOT6FilteredEventAnalysisTemplate");
140  cf.AddImplIncludeFile("KVReconstructedNucleus.h");
141  cf.AddImplIncludeFile("KVBatchSystem.h");
142 
143  cf.GenerateCode();
144 }
145 
146 
147 
164 
166 {
167  // When called from the InitRun() method of a user's analysis class, this method will ensure that only data
168  // compatible with the experimental trigger will be provided for analysis in the user's Analysis() method.
169  //
170  // This will be done by searching for a KVTriggerConditions plugin class defined for the currently-analysed
171  // dataset, defined like so:
172  //
173  //~~~~
174  //+Plugin.KVTriggerConditions: [dataset] [classname] [libname] "[default constructor]()"
175  //~~~~
176  //
177  // An object of the plugin class will be instantiated, and then its overridden
178  // KVTriggerConditions::SetTriggerConditionsForRun() method will be called with 3 arguments:
179  // - a pointer to the user's analysis class derived from KVEventSelector;
180  // - the number of the run currently being analysed
181  // - the 3rd optional argument will be set to kTRUE to indicate that we are analysing filtered simulated data
182 
183  TPluginHandler* ph = KVBase::LoadPlugin("KVTriggerConditions", gDataSet->GetName());
184  if (!ph) {
185  Info("SetTriggerConditionsForRun",
186  "No definition of trigger conditions available for dataset %s",
187  gDataSet->GetName());
188  return;
189  }
190  std::unique_ptr<KVTriggerConditions> trig((KVTriggerConditions*) ph->ExecPlugin(0));
191  trig->SetTriggerConditionsForRun(fAnalysisClass, run, kTRUE);
192 }
193 
194 //____________________________________________________________________________//
195 
196 
#define d(i)
char Char_t
constexpr Bool_t kTRUE
winID h TVirtualViewer3D TVirtualGLPainter p
Class for iterating over nuclei in events accessed through base pointer/reference.
Relativistic binary kinematics calculator.
Definition: KV2Body.h:178
void CalculateKinematics()
Definition: KV2Body.cpp:693
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:795
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
Description of an experimental run in database ,,.
Definition: KVDBRun.h:41
Database class used to store information on different colliding systems studied during an experiment....
Definition: KVDBSystem.h:51
Bool_t IsCollision() const
retourne kTRUE, si le systeme est une collision ie projectile+cible
Definition: KVDBSystem.cpp:128
KV2Body * GetKinematics()
Definition: KVDBSystem.cpp:103
KVUnownedList GetRuns() const
Returns a sorted list of all the runs associated with this system.
Definition: KVDBSystem.cpp:139
Manage all datasets contained in a given data repository.
Bool_t Init(KVDataSetRepository *=0)
KVDataSet * GetDataSet(Int_t) const
Return pointer to DataSet using index in list of all datasets, index>=0.
void cd() const
Definition: KVDataSet.cpp:778
Bool_t IsOptGiven(const Char_t *option)
virtual void SetCurrentRun(KVDBRun *)
KVEvent * GetEvent() const
TString GetOpt(const Char_t *option) const
virtual KVDBSystem * GetSystem(const Char_t *system) const
Definition: KVExpDB.h:164
KVDBRun * GetDBRun(Int_t number) const
Definition: KVExpDB.h:144
virtual KVSeqCollection * GetSystems() const
Definition: KVExpDB.h:168
virtual KVDetector * GetDetector(const Char_t *name) const
Return detector in this structure with given name.
static KVMultiDetArray * MakeMultiDetector(const Char_t *dataset_name, Int_t run=-1, TString classname="KVMultiDetArray", KVExpDB *db=nullptr)
virtual void SetSimMode(Bool_t on=kTRUE)
TObject * First() const override
Class piloting analyses of simulated data.
Manage user analysis of filtered simulation data.
void SetTriggerConditionsForRun(int run) override
void preInitAnalysis() override
Use options passed to KVEventSelector to initialise dataset used for filter.
virtual ~KVSimDirFilterAnalyser()
Destructor.
static void Make(const Char_t *kvsname="MyFilteredAnalysis")
Generate a new filtered analysis selector class.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
Set trigger conditions for analysis of reconstructed data.
const char * GetName() const override
virtual const char * GetName() const
void SetBit(UInt_t f)
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Info(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
Int_t Atoi() const
const Int_t n
ClassImp(TPyArg)