OpDetDivRec.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // File: OpDetDivRec.h
4 // Author: Jason Stock (jason.stock@mines.sdsmt.edu)
5 // This file is a set of classes for writeout of data relative to
6 // OpticalChannels in the DUNE detectors.
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 //includes
11 #ifndef DUNE_DUNEOBJBASE_SIM_H
12 #define DUNE_DUNEOBJBASE_SIM_H
13 #include <vector>
14 #include <TObject.h>
15 #include <map>
16 #include <utility>
17 #include <algorithm>
18 
19 namespace sim {
20  //these records already exist tied to optical detectors (as they are made tied to the BTRs. No need to be OpDet wise.
21  //Remember these are not per sdp smart, just per opchan smart. The normalization is per opchan at each unit time. We will assume the SDPs are split uniformly according to how everything over the time time was split.
22 
23  struct Chan_Phot{
24  int opChan;
25  int trackID;
26  double phot;
28  opChan(-1)
29  {}
30  Chan_Phot(int opChanIn, int tid=-999999):
31  opChan(opChanIn),
32  trackID(tid),
33  phot(1.0)
34  {}
35  void AddPhoton(){
36  phot+=1.0;
37  }
38  };
40  // std::pair<double, std:vector<Chan_Phot>>
41  typedef double stored_time_t;
42  stored_time_t time;
44  {}
45  OpDet_Time_Chans(stored_time_t& timeIn);
46  OpDet_Time_Chans(stored_time_t& timeIn, std::vector<Chan_Phot> photIn);
47  std::vector<Chan_Phot> phots;
48 
49  std::vector<std::pair<int, double>> GetFracs(int tid) const{
50  double total=0.0;
51  std::vector<std::pair<int, double>> ret;
52  for(auto& a : phots){ total += (a.trackID==tid)?a.phot:0;}
53  for(auto& a : phots){ ret.emplace_back(a.opChan, (a.phot / total));}
54  return ret;
55  }
56  std::vector<std::pair<int, double>> GetFracs() const{
57  double total=0.0;
58  std::vector<std::pair<int, double>> ret;
59  for(auto& a : phots){ total += a.phot;}
60  for(auto& a : phots){ ret.emplace_back(a.opChan, (a.phot / total));}
61  return ret;
62  }
63  double GetFrac(int opChanIn, int tid) const{
64  double ret=0.0;
65  std::vector<std::pair<int, double>> fracs = GetFracs(tid);
66  for(auto pair : fracs){
67  if(pair.first==opChanIn){
68  ret=pair.second;
69  break;
70  }
71  }
72  return ret;
73  }
74  double GetFrac(int opChanIn) const{
75  double ret=0.0;
76  std::vector<std::pair<int, double>> fracs = GetFracs();
77  for(auto pair : fracs){
78  if(pair.first==opChanIn){
79  ret=pair.second;
80  break;
81  }
82  }
83  return ret;
84  }
85  };
86 
87  class OpDetDivRec{
88  public:
89  typedef std::vector<OpDet_Time_Chans> Time_Chans_t;
90  struct time_slice{
93  };
94 
95  private:
96  int fOpDetNum; //Move this to be private.
97  Time_Chans_t time_chans; //Move this to private //This must be filled with emplace to keep it sorted.
98  public:
99  OpDetDivRec();
100  OpDetDivRec(int det);
101  Time_Chans_t const& GetTimeChans() const {return time_chans;}
102  int OpDetNum() const{ return fOpDetNum; }
103  void AddPhoton(int opchan, int tid, OpDet_Time_Chans::stored_time_t pdTime);
104  std::vector<std::pair<int, double>> GetFracs(OpDet_Time_Chans::stored_time_t time);
105  std::vector<std::pair<int, double>> GetFracs(OpDet_Time_Chans::stored_time_t time, int tid);
107 
108  // double GetFras(OpDet_Time_Chans::stored_time_t, OpChan);
109  // Time_Chans_t::iterator priv_FindClosestTimeChan(const OpDet_Time_Chans::stored_time_t& pdTime);
110  std::pair<OpDetDivRec::Time_Chans_t::const_iterator, bool> FindClosestTimeChan( OpDet_Time_Chans::stored_time_t pdTime) const;
111  void clear();
112  template <typename Stream>
113  void Dump(Stream&& out, std::string indent, std::string first_indent) const;
114 
115  /// Documentation at `Dump(Stream&&, std::string, std::string) const`.
116  template <typename Stream>
117  void Dump(Stream&& out, std::string indent = "") const
118  { Dump(std::forward<Stream>(out), indent, indent); }
119 
120  private:
121  // struct CompareByPdTime ;
123  bool operator()
124  (OpDet_Time_Chans const& a, OpDet_Time_Chans const& b) const
125  {return a.time<b.time;}
126  bool operator()
128  {return a<b.time;}
129  bool operator()
131  {return a.time<b;}
132  };
133 
134  private:
135  Time_Chans_t::iterator priv_FindClosestTimeChan(OpDet_Time_Chans::stored_time_t pdTime);
136  Time_Chans_t::const_iterator priv_FindClosestTimeChan( OpDet_Time_Chans::stored_time_t pdTime) const;
137 
138  };
139 
140 }
141 
142 // -----------------------------------------------------------------------------
143 // --- template implementation
144 // ---
145 template <class Stream>
147 (Stream&& out, std::string indent, std::string first_indent) const
148 {
149  out << first_indent << "OpDet #" << OpDetNum() << " read " << time_chans.size()
150  << " time_chans:\n";
151  for (const auto& tc: time_chans) {
152  auto time = tc.time;
153  out << indent << " time " << time
154  << " with " << tc.phots.size() << " Photon deposits\n";
155  for (const auto& photr: tc.phots) {
156  out << indent
157  << "OpChan: "<<photr.opChan <<" with "<<photr.phot<<" photons from particle with TrackID"<<photr.trackID<<"\n";
158  } // for SDPs
159  } // for timePDclocks
160 } // sim::OpDetBacktrackerRecord::Dump<>()
161 
162 
163 ////////////////////////////////////////////////////////////////////////
164 #endif //DUNE_DUNEOBJBASE_SIM_H
intermediate_table::iterator iterator
double GetFrac(int opChanIn) const
Definition: OpDetDivRec.h:74
Time_Chans_t::const_iterator lower
Definition: OpDetDivRec.h:91
stored_time_t time
Definition: OpDetDivRec.h:42
std::string string
Definition: nybbler.cc:12
void Dump(Stream &&out, std::string indent="") const
Documentation at Dump(Stream&&, std::string, std::string) const.
Definition: OpDetDivRec.h:117
std::vector< Chan_Phot > phots
Definition: OpDetDivRec.h:47
intermediate_table::const_iterator const_iterator
Chan_Phot(int opChanIn, int tid=-999999)
Definition: OpDetDivRec.h:30
void AddPhoton()
Definition: OpDetDivRec.h:35
double GetFrac(int opChanIn, int tid) const
Definition: OpDetDivRec.h:63
std::vector< OpDet_Time_Chans > Time_Chans_t
Definition: OpDetDivRec.h:89
Time_Chans_t const & GetTimeChans() const
Definition: OpDetDivRec.h:101
const double a
int OpDetNum() const
Definition: OpDetDivRec.h:102
Code to link reconstructed objects back to the MC truth information.
Time_Chans_t time_chans
Definition: OpDetDivRec.h:97
std::vector< std::pair< int, double > > GetFracs(int tid) const
Definition: OpDetDivRec.h:49
static bool * b
Definition: config.cpp:1043
vector< vector< double > > clear
std::vector< std::pair< int, double > > GetFracs() const
Definition: OpDetDivRec.h:56
Time_Chans_t::const_iterator upper
Definition: OpDetDivRec.h:92
void Dump(Stream &&out, std::string indent, std::string first_indent) const
Definition: OpDetDivRec.h:147