19#include "RBDSException.hh"
20#include "RebdsimTypes.hh"
22#include "BDSOutputROOTEventAperture.hh"
23#include "BDSOutputROOTEventCollimator.hh"
24#include "BDSOutputROOTEventCoords.hh"
25#include "BDSOutputROOTEventHistograms.hh"
26#include "BDSOutputROOTEventInfo.hh"
27#include "BDSOutputROOTEventLoss.hh"
28#include "BDSOutputROOTEventLossWorld.hh"
29#include "BDSOutputROOTEventTrajectory.hh"
30#include "BDSOutputROOTEventSampler.hh"
31#include "BDSOutputROOTEventSamplerC.hh"
32#include "BDSOutputROOTEventSamplerS.hh"
44 processSamplers(false),
51Event::Event(
bool debugIn,
52 bool processSamplersIn,
56 processSamplers(processSamplersIn),
57 dataVersion(dataVersionIn),
79 delete ApertureImpacts;
90void Event::CommonCtor()
120 auto found = samplerMap.find(name);
121 if (found != samplerMap.end())
122 {
return found->second;}
127 auto branch = tree->GetBranch(name.c_str());
137 samplerNames.push_back(name);
138 samplerMap[name] = Samplers.back();
139 tree->SetBranchStatus((name+
"*").c_str(),
true);
141 return Samplers.back();
155 return index >= (int) Samplers.size() ? nullptr : Samplers[index];
160 auto found = samplerCMap.find(name);
161 return found != samplerCMap.end() ? found->second :
nullptr;
171 auto found = samplerSMap.find(name);
172 return found != samplerSMap.end() ? found->second :
nullptr;
184 std::vector<std::string> variations = {name,
186 "COLL_" + name +
"_0"};
187 for (
const auto& var : variations)
189 std::cout << (var == collimatorNames[0]) << std::endl;
190 auto found = collimatorMap.find(var);
191 if (found != collimatorMap.end())
192 {
return found->second;}
206 const RBDS::VectorString* samplerNamesIn,
208 const RBDS::VectorString* branchesToTurnOn,
209 const RBDS::VectorString* collimatorNamesIn,
210 const RBDS::VectorString* samplerCNamesIn,
211 const RBDS::VectorString* samplerSNamesIn)
214 {std::cout <<
"Event::SetBranchAddress" << std::endl;}
220 t->SetBranchStatus(
"*",
false);
222 int nCollimatorsToTurnOn = 0;
223 int ithCollimator = 0;
225 RBDS::VectorString bToTurnOn;
226 if (branchesToTurnOn)
227 {bToTurnOn = RBDS::VectorString(*branchesToTurnOn);}
230 bToTurnOn.emplace_back(
"Primary");
231 bToTurnOn.emplace_back( dataVersion < 4 ?
"Info" :
"Summary" );
232 bToTurnOn.emplace_back(
"PrimaryFirstHit");
233 bToTurnOn.emplace_back(
"PrimaryLastHit");
237 t->SetBranchStatus(
"*",
true);
238 bToTurnOn.emplace_back(
"Eloss");
239 bToTurnOn.emplace_back(
"Histos");
240 bToTurnOn.emplace_back( dataVersion > 4 ?
"ElossTunnel" :
"TunnelHit" );
241 bToTurnOn.emplace_back(
"Trajectory");
245 bToTurnOn.emplace_back(
"PrimaryGlobal");
246 bToTurnOn.emplace_back(
"ElossVacuum");
247 bToTurnOn.emplace_back(
"ElossWorld");
248 bToTurnOn.emplace_back(
"ElossWorldContents");
249 bToTurnOn.emplace_back(
"ElossWorldExit");
251 if (collimatorNamesIn)
253 bToTurnOn.insert(bToTurnOn.end(), collimatorNamesIn->begin(), collimatorNamesIn->end());
258 {bToTurnOn.emplace_back(
"ApertureImpacts");}
266 for (
const auto& name : bToTurnOn)
268 if (name.substr(0,4) ==
"COLL")
269 {nCollimatorsToTurnOn++;}
273 for (
const auto& name : bToTurnOn)
276 {std::cerr <<
"empty string given as argument for branch name";
continue;}
277 std::string nameStar = name +
"*";
278 std::string nameDot = name.back() !=
'.' ? name +
"." : name;
280 {std::cout <<
"Event::SetBranchAddress> Turning on branch \"" << nameStar <<
"\"" << std::endl;}
282 bool condition1 = ((*t).GetListOfBranches()->FindObject(name.c_str())) !=
nullptr;
283 bool condition2 = ((*t).GetListOfBranches()->FindObject(nameDot.c_str())) !=
nullptr;
285 if (! (condition1 || condition2) )
288 {std::cout <<
"Unknown branch name \"" + name +
"\"" << std::endl;}
292 t->SetBranchStatus(nameStar.c_str(),
true);
301 Int_t addressSetResult = 0;
302 if (name ==
"Primary")
305 addressSetResult = t->SetBranchAddress(
"Primary.", &
Primary);
307 else if (name ==
"ApertureImpacts")
308 {addressSetResult = t->SetBranchAddress(
"ApertureImpacts.", &ApertureImpacts);}
309 else if (name ==
"Eloss")
310 {addressSetResult = t->SetBranchAddress(
"Eloss.", &
Eloss);}
311 else if (name ==
"ElossVacuum")
312 {addressSetResult = t->SetBranchAddress(
"ElossVacuum.", &
ElossVacuum);}
313 else if (name ==
"ElossTunnel")
314 {addressSetResult = t->SetBranchAddress(
"ElossTunnel.", &
ElossTunnel);}
315 else if (name ==
"ElossWorld")
316 {addressSetResult = t->SetBranchAddress(
"ElossWorld.", &
ElossWorld);}
317 else if (name ==
"ElossWorldContents")
319 else if (name ==
"ElossWorldExit")
320 {addressSetResult = t->SetBranchAddress(
"ElossWorldExit.", &
ElossWorldExit);}
321 else if (name ==
"Histos")
322 {addressSetResult = t->SetBranchAddress(
"Histos.", &
Histos);}
323 else if (name ==
"Info")
324 {addressSetResult = t->SetBranchAddress(
"Info.", &
Info);}
325 else if (name ==
"Summary")
326 {addressSetResult = t->SetBranchAddress(
"Summary.", &
Summary);}
327 else if (name ==
"PrimaryGlobal")
328 {addressSetResult = t->SetBranchAddress(
"PrimaryGlobal.", &
PrimaryGlobal);}
329 else if (name ==
"PrimaryFirstHit")
330 {addressSetResult = t->SetBranchAddress(
"PrimaryFirstHit.", &
PrimaryFirstHit);}
331 else if (name ==
"PrimaryLastHit")
332 {addressSetResult = t->SetBranchAddress(
"PrimaryLastHit.", &
PrimaryLastHit);}
333 else if (name ==
"TunnelHit")
334 {addressSetResult = t->SetBranchAddress(
"TunnelHit.", &
TunnelHit);}
335 else if (name ==
"Trajectory")
336 {addressSetResult = t->SetBranchAddress(
"Trajectory.", &
Trajectory);}
337 else if (name.substr(0,4) ==
"COLL")
343 {std::cout <<
"SetBranchAddress result: " << addressSetResult << std::endl;}
348 std::cout <<
"Event::SetBranchAddress> Primary. " <<
Primary << std::endl;
349 std::cout <<
"Event::SetBranchAddress> PrimaryGlobal. " <<
PrimaryGlobal << std::endl;
350 std::cout <<
"Event::SetBranchAddress> Eloss. " <<
Eloss << std::endl;
351 std::cout <<
"Event::SetBranchAddress> ElossTunnel. " <<
ElossTunnel << std::endl;
352 std::cout <<
"Event::SetBranchAddress> ElossVacuum. " <<
ElossVacuum << std::endl;
353 std::cout <<
"Event::SetBranchAddress> ElossWorld. " <<
ElossWorld << std::endl;
354 std::cout <<
"Event::SetBranchAddress> ElossWorldContents. " <<
ElossWorldContents << std::endl;
355 std::cout <<
"Event::SetBranchAddress> ElossWorldExit. " <<
ElossWorldExit << std::endl;
356 std::cout <<
"Event::SetBranchAddress> PrimaryFirstHit. " <<
PrimaryFirstHit << std::endl;
357 std::cout <<
"Event::SetBranchAddress> PrimaryLastHit. " <<
PrimaryLastHit << std::endl;
358 std::cout <<
"Event::SetBranchAddress> TunnelHit. " <<
TunnelHit << std::endl;
359 std::cout <<
"Event::SetBranchAddress> Trajectory. " <<
Trajectory << std::endl;
360 std::cout <<
"Event::SetBranchAddress> Histos. " <<
Histos << std::endl;
361 std::cout <<
"Event::SetBranchAddress> Info. " <<
Info << std::endl;
364 if (processSamplers || samplerNamesIn)
366 unsigned int nrSamplers = samplerNamesIn->size();
368 for (
unsigned int i=0; i < nrSamplers; ++i)
370 const auto sampName = (*samplerNamesIn)[i];
376 samplerNames.push_back(sampName);
379 t->SetBranchAddress(sampName.c_str(), &
Samplers[i]);
380 t->SetBranchStatus((sampName+
"*").c_str(),
true);
382 {std::cout <<
"Event::SetBranchAddress> " << (*samplerNamesIn)[i] <<
" " <<
Samplers[i] << std::endl;}
386 if (processSamplers || samplerCNamesIn)
388 unsigned int nrSamplers = samplerCNamesIn->size();
390 for (
unsigned int i=0; i < nrSamplers; ++i)
392 const auto sampName = (*samplerCNamesIn)[i];
394 samplerCNames.push_back(sampName);
397 t->SetBranchAddress(sampName.c_str(), &
SamplersC[i]);
398 t->SetBranchStatus((sampName+
"*").c_str(),
true);
400 {std::cout <<
"Event::SetBranchAddress> " << (*samplerCNamesIn)[i] <<
" " <<
SamplersC[i] << std::endl;}
404 if (processSamplers || samplerSNamesIn)
406 unsigned int nrSamplers = samplerSNamesIn->size();
408 for (
unsigned int i=0; i < nrSamplers; ++i)
410 const auto sampName = (*samplerSNamesIn)[i];
412 samplerSNames.push_back(sampName);
415 t->SetBranchAddress(sampName.c_str(), &
SamplersS[i]);
416 t->SetBranchStatus((sampName+
"*").c_str(),
true);
418 {std::cout <<
"Event::SetBranchAddress> " << (*samplerSNamesIn)[i] <<
" " <<
SamplersS[i] << std::endl;}
426 {
throw RBDSException(
"Event::RelinkSamplers>",
"no tree from set branch address");}
427 for (
const auto& item : samplerMap)
428 {tree->SetBranchAddress(item.first.c_str(), (
void*)&item.second);}
433 std::set<std::string> namesSet(namesIn.begin(), namesIn.end());
434 auto namesUnique = RBDS::VectorString(namesSet.begin(), namesSet.end());
443 collimatorNames.push_back(collimatorName);
445 collimatorMap[collimatorName] = collimator;
452 samplerNames.push_back(samplerName);
454 samplerMap[samplerName] = sampler;
457 samplerNames.push_back(samplerName);
459 samplerMap[samplerName] = sampler;
464 const RBDS::VectorString* collimatorNamesIn)
466 if (collimatorNamesIn)
469 for (
const auto& name : *collimatorNamesIn)
471 collimators.resize((
unsigned int)collimatorNamesIn->size());
479 const std::string& name,
485 collimatorNames.push_back(name);
489 Int_t addressSetResult = t->SetBranchAddress(name.c_str(), &
collimators[i]);
491 {std::cout <<
"Event::SetBranchAddress> " << name <<
" " <<
collimators[i] << std::endl;}
492 return addressSetResult;
512 ApertureImpacts->Fill(other->ApertureImpacts);
514 for (
unsigned long i = 0; i <
Samplers.size(); i++)
517 for (
unsigned long i = 0; i <
SamplersC.size(); i++)
520 for (
unsigned long i = 0; i <
SamplersS.size(); i++)
523 for (
unsigned long i = 0; i <
collimators.size(); i++)
544 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.
Information stored per sampler per event.
virtual void Flush()
Clean Sampler.
Structure to record a trajectory.
virtual 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.
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 RegisterCollimator(const std::string &collimatorName)
Utility method for interface building events.
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.
BDSOutputROOTEventLoss * Eloss
Local variable ROOT data is mapped to.
void RegisterSampler(const std::string &samplerName)
Utility method for interface building events.
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.