20#include "RBDSException.hh"
21#include "RebdsimTypes.hh"
23#include "BDSOutputROOTEventAperture.hh"
24#include "BDSOutputROOTEventCollimator.hh"
25#include "BDSOutputROOTEventCoords.hh"
26#include "BDSOutputROOTEventHistograms.hh"
27#include "BDSOutputROOTEventInfo.hh"
28#include "BDSOutputROOTEventLoss.hh"
29#include "BDSOutputROOTEventLossWorld.hh"
30#include "BDSOutputROOTEventTrajectory.hh"
31#include "BDSOutputROOTEventSampler.hh"
32#include "BDSOutputROOTEventSamplerC.hh"
33#include "BDSOutputROOTEventSamplerS.hh"
45 processSamplers(false),
52Event::Event(
bool debugIn,
53 bool processSamplersIn,
57 processSamplers(processSamplersIn),
58 dataVersion(dataVersionIn),
80 delete ApertureImpacts;
91void Event::CommonCtor()
121 auto found = samplerMap.find(name);
122 if (found != samplerMap.end())
123 {
return found->second;}
128 auto branch = tree->GetBranch(name.c_str());
138 samplerNames.push_back(name);
139 samplerMap[name] = Samplers.back();
140 tree->SetBranchStatus((name+
"*").c_str(),
true);
142 return Samplers.back();
156 return index >= (int) Samplers.size() ? nullptr : Samplers[index];
161 auto found = samplerCMap.find(name);
162 return found != samplerCMap.end() ? found->second :
nullptr;
172 auto found = samplerSMap.find(name);
173 return found != samplerSMap.end() ? found->second :
nullptr;
185 std::vector<std::string> variations = {name,
187 "COLL_" + name +
"_0"};
188 for (
const auto& var : variations)
190 std::cout << (var == collimatorNames[0]) << std::endl;
191 auto found = collimatorMap.find(var);
192 if (found != collimatorMap.end())
193 {
return found->second;}
207 const RBDS::VectorString* samplerNamesIn,
209 const RBDS::VectorString* branchesToTurnOn,
210 const RBDS::VectorString* collimatorNamesIn,
211 const RBDS::VectorString* samplerCNamesIn,
212 const RBDS::VectorString* samplerSNamesIn)
215 {std::cout <<
"Event::SetBranchAddress" << std::endl;}
221 t->SetBranchStatus(
"*",
false);
223 int nCollimatorsToTurnOn = 0;
224 int ithCollimator = 0;
226 RBDS::VectorString bToTurnOn;
227 if (branchesToTurnOn)
228 {bToTurnOn = RBDS::VectorString(*branchesToTurnOn);}
231 bToTurnOn.push_back(
"Primary");
232 bToTurnOn.push_back( dataVersion < 4 ?
"Info" :
"Summary" );
233 bToTurnOn.push_back(
"PrimaryFirstHit");
234 bToTurnOn.push_back(
"PrimaryLastHit");
238 t->SetBranchStatus(
"*",
true);
239 bToTurnOn.push_back(
"Eloss");
240 bToTurnOn.push_back(
"Histos");
241 bToTurnOn.push_back( dataVersion > 4 ?
"ElossTunnel" :
"TunnelHit" );
242 bToTurnOn.push_back(
"Trajectory");
246 bToTurnOn.push_back(
"PrimaryGlobal");
247 bToTurnOn.push_back(
"ElossVacuum");
248 bToTurnOn.push_back(
"ElossWorld");
249 bToTurnOn.push_back(
"ElossWorldContents");
250 bToTurnOn.push_back(
"ElossWorldExit");
252 if (collimatorNamesIn)
254 bToTurnOn.insert(bToTurnOn.end(), collimatorNamesIn->begin(), collimatorNamesIn->end());
259 {bToTurnOn.push_back(
"ApertureImpacts");}
267 for (
const auto& name : bToTurnOn)
269 if (name.substr(0,4) ==
"COLL")
270 {nCollimatorsToTurnOn++;}
274 for (
const auto& name : bToTurnOn)
277 {std::cerr <<
"empty string given as argument for branch name";
continue;}
278 std::string nameStar = name +
"*";
279 std::string nameDot = name.back() !=
'.' ? name +
"." : name;
281 {std::cout <<
"Event::SetBranchAddress> Turning on branch \"" << nameStar <<
"\"" << std::endl;}
283 bool condition1 = ((*t).GetListOfBranches()->FindObject(name.c_str())) !=
nullptr;
284 bool condition2 = ((*t).GetListOfBranches()->FindObject(nameDot.c_str())) !=
nullptr;
286 if (! (condition1 || condition2) )
289 {std::cout <<
"Unknown branch name \"" + name +
"\"" << std::endl;}
293 t->SetBranchStatus(nameStar.c_str(),
true);
302 Int_t addressSetResult = 0;
303 if (name ==
"Primary")
306 addressSetResult = t->SetBranchAddress(
"Primary.", &
Primary);
308 else if (name ==
"ApertureImpacts")
309 {addressSetResult = t->SetBranchAddress(
"ApertureImpacts.", &ApertureImpacts);}
310 else if (name ==
"Eloss")
311 {addressSetResult = t->SetBranchAddress(
"Eloss.", &
Eloss);}
312 else if (name ==
"ElossVacuum")
313 {addressSetResult = t->SetBranchAddress(
"ElossVacuum.", &
ElossVacuum);}
314 else if (name ==
"ElossTunnel")
315 {addressSetResult = t->SetBranchAddress(
"ElossTunnel.", &
ElossTunnel);}
316 else if (name ==
"ElossWorld")
317 {addressSetResult = t->SetBranchAddress(
"ElossWorld.", &
ElossWorld);}
318 else if (name ==
"ElossWorldContents")
320 else if (name ==
"ElossWorldExit")
321 {addressSetResult = t->SetBranchAddress(
"ElossWorldExit.", &
ElossWorldExit);}
322 else if (name ==
"Histos")
323 {addressSetResult = t->SetBranchAddress(
"Histos.", &
Histos);}
324 else if (name ==
"Info")
325 {addressSetResult = t->SetBranchAddress(
"Info.", &
Info);}
326 else if (name ==
"Summary")
327 {addressSetResult = t->SetBranchAddress(
"Summary.", &
Summary);}
328 else if (name ==
"PrimaryGlobal")
329 {addressSetResult = t->SetBranchAddress(
"PrimaryGlobal.", &
PrimaryGlobal);}
330 else if (name ==
"PrimaryFirstHit")
331 {addressSetResult = t->SetBranchAddress(
"PrimaryFirstHit.", &
PrimaryFirstHit);}
332 else if (name ==
"PrimaryLastHit")
333 {addressSetResult = t->SetBranchAddress(
"PrimaryLastHit.", &
PrimaryLastHit);}
334 else if (name ==
"TunnelHit")
335 {addressSetResult = t->SetBranchAddress(
"TunnelHit.", &
TunnelHit);}
336 else if (name ==
"Trajectory")
337 {addressSetResult = t->SetBranchAddress(
"Trajectory.", &
Trajectory);}
338 else if (name.substr(0,4) ==
"COLL")
344 {std::cout <<
"SetBranchAddress result: " << addressSetResult << std::endl;}
349 std::cout <<
"Event::SetBranchAddress> Primary. " <<
Primary << std::endl;
350 std::cout <<
"Event::SetBranchAddress> PrimaryGlobal. " <<
PrimaryGlobal << std::endl;
351 std::cout <<
"Event::SetBranchAddress> Eloss. " <<
Eloss << std::endl;
352 std::cout <<
"Event::SetBranchAddress> ElossTunnel. " <<
ElossTunnel << std::endl;
353 std::cout <<
"Event::SetBranchAddress> ElossVacuum. " <<
ElossVacuum << std::endl;
354 std::cout <<
"Event::SetBranchAddress> ElossWorld. " <<
ElossWorld << std::endl;
355 std::cout <<
"Event::SetBranchAddress> ElossWorldContents. " <<
ElossWorldContents << std::endl;
356 std::cout <<
"Event::SetBranchAddress> ElossWorldExit. " <<
ElossWorldExit << std::endl;
357 std::cout <<
"Event::SetBranchAddress> PrimaryFirstHit. " <<
PrimaryFirstHit << std::endl;
358 std::cout <<
"Event::SetBranchAddress> PrimaryLastHit. " <<
PrimaryLastHit << std::endl;
359 std::cout <<
"Event::SetBranchAddress> TunnelHit. " <<
TunnelHit << std::endl;
360 std::cout <<
"Event::SetBranchAddress> Trajectory. " <<
Trajectory << std::endl;
361 std::cout <<
"Event::SetBranchAddress> Histos. " <<
Histos << std::endl;
362 std::cout <<
"Event::SetBranchAddress> Info. " <<
Info << std::endl;
365 if (processSamplers || samplerNamesIn)
367 unsigned int nrSamplers = samplerNamesIn->size();
369 for (
unsigned int i=0; i < nrSamplers; ++i)
371 const auto sampName = (*samplerNamesIn)[i];
377 samplerNames.push_back(sampName);
380 t->SetBranchAddress(sampName.c_str(), &
Samplers[i]);
381 t->SetBranchStatus((sampName+
"*").c_str(),
true);
383 {std::cout <<
"Event::SetBranchAddress> " << (*samplerNamesIn)[i] <<
" " <<
Samplers[i] << std::endl;}
387 if (processSamplers || samplerCNamesIn)
389 unsigned int nrSamplers = samplerCNamesIn->size();
391 for (
unsigned int i=0; i < nrSamplers; ++i)
393 const auto sampName = (*samplerCNamesIn)[i];
395 samplerCNames.push_back(sampName);
398 t->SetBranchAddress(sampName.c_str(), &
SamplersC[i]);
399 t->SetBranchStatus((sampName+
"*").c_str(),
true);
401 {std::cout <<
"Event::SetBranchAddress> " << (*samplerCNamesIn)[i] <<
" " <<
SamplersC[i] << std::endl;}
405 if (processSamplers || samplerSNamesIn)
407 unsigned int nrSamplers = samplerSNamesIn->size();
409 for (
unsigned int i=0; i < nrSamplers; ++i)
411 const auto sampName = (*samplerSNamesIn)[i];
413 samplerSNames.push_back(sampName);
416 t->SetBranchAddress(sampName.c_str(), &
SamplersC[i]);
417 t->SetBranchStatus((sampName+
"*").c_str(),
true);
419 {std::cout <<
"Event::SetBranchAddress> " << (*samplerSNamesIn)[i] <<
" " <<
SamplersS[i] << std::endl;}
427 {
throw RBDSException(
"Event::RelinkSamplers>",
"no tree from set branch address");}
428 for (
const auto& item : samplerMap)
429 {tree->SetBranchAddress(item.first.c_str(), (
void*)&item.second);}
434 std::set<std::string> namesSet(namesIn.begin(), namesIn.end());
435 auto namesUnique = RBDS::VectorString(namesSet.begin(), namesSet.end());
444 collimatorNames.push_back(collimatorName);
446 collimatorMap[collimatorName] = collimator;
453 samplerNames.push_back(samplerName);
455 samplerMap[samplerName] = sampler;
458 samplerNames.push_back(samplerName);
460 samplerMap[samplerName] = sampler;
465 const RBDS::VectorString* collimatorNamesIn)
467 if (collimatorNamesIn)
470 for (
const auto& name : *collimatorNamesIn)
472 collimators.resize((
unsigned int)collimatorNamesIn->size());
480 const std::string& name,
486 collimatorNames.push_back(name);
490 Int_t addressSetResult = t->SetBranchAddress(name.c_str(), &
collimators[i]);
492 {std::cout <<
"Event::SetBranchAddress> " << name <<
" " <<
collimators[i] << std::endl;}
493 return addressSetResult;
513 ApertureImpacts->Fill(other->ApertureImpacts);
515 for (
unsigned long i = 0; i <
Samplers.size(); i++)
518 for (
unsigned long i = 0; i <
SamplersC.size(); i++)
521 for (
unsigned long i = 0; i <
SamplersS.size(); i++)
524 for (
unsigned long i = 0; i <
collimators.size(); i++)
545 ApertureImpacts->Flush();
Data stored for energy deposition hits per event.
Data stored for each collimator per event.
void Fill(const BDSOutputROOTEventCoords *other)
Fill from another instance.
Holder for a set of histograms to be stored.
virtual void Flush()
Flush the contents.
void FillSimple(const BDSOutputROOTEventHistograms *rhs)
Copy (without using the TH->Clone) method from another instance. (Quicker).
Information pertaining to an individual event.
void Fill(const BDSOutputROOTEventInfo *other)
Fill from another instance.
Data stored for world hits per event.
Data stored for energy deposition hits per event.
void Fill(const BDSOutputROOTEventLoss *other)
Fill from another instance.
Information stored per cylindrical sampler per event.
Information stored per spherical sampler per event.
virtual void Flush()
Clean Sampler.
Structure to record a trajectory.
void Flush()
add comment to avoid warning (no need to make persistent, see issue #191)
BDSOutputROOTEventLoss * PrimaryLastHit
Local variable ROOT data is mapped to.
BDSOutputROOTEventLoss * TunnelHit
Local variable ROOT data is mapped to.
void FlushSamplers()
Flushing functions.
BDSOutputROOTEventLoss * ElossVacuum
Local variable ROOT data is mapped to.
BDSOutputROOTEventSampler< double > * GetSampler(const std::string &name)
Accessor.
BDSOutputROOTEventHistograms * Histos
Local variable ROOT data is mapped to.
BDSOutputROOTEventCollimator * GetCollimator(const std::string &name)
Accessor.
BDSOutputROOTEventLossWorld * ElossWorldExit
Local variable ROOT data is mapped to.
void RegisterCollimator(std::string collimatorName)
Utility method for interface building events.
RBDS::VectorString RemoveDuplicates(const RBDS::VectorString &namesIn) const
Utility method.
BDSOutputROOTEventLossWorld * ElossWorld
Local variable ROOT data is mapped to.
BDSOutputROOTEventLossWorld * ElossWorldContents
Local variable ROOT data is mapped to.
void FlushCollimators()
Flushing functions.
BDSOutputROOTEventLoss * ElossTunnel
Local variable ROOT data is mapped to.
BDSOutputROOTEventSampler< double > * Primary
Local variable ROOT data is mapped to.
BDSOutputROOTEventSamplerC * GetSamplerC(const std::string &name)
Accessor.
std::vector< BDSOutputROOTEventSamplerC * > SamplersC
Local variable ROOT data is mapped to.
BDSOutputROOTEventSamplerS * GetSamplerS(const std::string &name)
Accessor.
void Flush()
Flushing functions.
BDSOutputROOTEventTrajectory * Trajectory
Local variable ROOT data is mapped to.
BDSOutputROOTEventLoss * PrimaryFirstHit
Local variable ROOT data is mapped to.
void SetBranchAddressCollimators(TTree *t, const RBDS::VectorString *collimatorNames)
Utility function to avoid repetition of code.
std::vector< BDSOutputROOTEventSampler< double > * > Samplers
Local variable ROOT data is mapped to.
void Fill(Event *other)
Copy data from another event into this event.
Int_t SetBranchAddressCollimatorSingle(TTree *t, const std::string &name, int i)
Utility function to avoid repetition of code.
BDSOutputROOTEventInfo * Summary
Local variable ROOT data is mapped to.
std::vector< BDSOutputROOTEventSamplerS * > SamplersS
Local variable ROOT data is mapped to.
void RegisterSampler(std::string samplerName)
Utility method for interface building events.
BDSOutputROOTEventLoss * Eloss
Local variable ROOT data is mapped to.
BDSOutputROOTEventCoords * PrimaryGlobal
Local variable ROOT data is mapped to.
BDSOutputROOTEventInfo * Info
For backwards compatibility.
std::vector< BDSOutputROOTEventCollimator * > collimators
Local variable ROOT data is mapped to.
void SetBranchAddress(TTree *t, const RBDS::VectorString *samplerNames=nullptr, bool allBranchesOn=false, const RBDS::VectorString *branchesToTurnOn=nullptr, const RBDS::VectorString *collimatorNamesIn=nullptr, const RBDS::VectorString *samplerCNamesIn=nullptr, const RBDS::VectorString *samplerSNamesIn=nullptr)
General exception with possible name of object and message.