All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
hit::MCHitFinder Class Reference
Inheritance diagram for hit::MCHitFinder:

Public Member Functions

 MCHitFinder (fhicl::ParameterSet const &p)
 

Private Member Functions

void produce (art::Event &e) override
 

Private Attributes

std::string fLArG4ModuleName
 
bool fVerbose
 
bool fMakeMCWire
 

Detailed Description

Definition at line 30 of file MCHitFinder_module.cc.

Constructor & Destructor Documentation

hit::MCHitFinder::MCHitFinder ( fhicl::ParameterSet const &  p)
explicit

Definition at line 44 of file MCHitFinder_module.cc.

45  : EDProducer{p}
46  {
47  fLArG4ModuleName = p.get<std::string>("LArG4ModuleName");
48  fMakeMCWire = p.get<bool>("MakeMCWire");
49  fVerbose = p.get<bool>("Verbose");
50  produces< std::vector< sim::MCHitCollection> >();
51  if(fMakeMCWire)
52  produces< std::vector< sim::MCWireCollection> >();
53  }
pdgs p
Definition: selectors.fcl:22
std::string fLArG4ModuleName

Member Function Documentation

void hit::MCHitFinder::produce ( art::Event &  e)
overrideprivate

Definition at line 55 of file MCHitFinder_module.cc.

56  {
57 
58  art::ServiceHandle<geo::Geometry const> geo;
59 
60  const unsigned int nch = geo->Nchannels();
61 
62  std::unique_ptr< std::vector<sim::MCHitCollection> > hits_v ( new std::vector<sim::MCHitCollection>() );
63  std::unique_ptr< std::vector<sim::MCWireCollection> > wires_v ( new std::vector<sim::MCWireCollection>() );
64 
65  hits_v->reserve(nch);
66  wires_v->reserve(nch);
67  for(size_t ch=0; ch<nch; ++ch) {
68 
69  hits_v->push_back(sim::MCHitCollection(ch));
70  wires_v->push_back(sim::MCWireCollection(ch));
71 
72  }
73 
74  art::Handle< std::vector<sim::SimChannel> > simchArray;
75  e.getByLabel(fLArG4ModuleName,simchArray);
76  if(!simchArray.isValid())
77  throw cet::exception(__PRETTY_FUNCTION__)
78  << "Did not find sim::SimChannel with a label: " << fLArG4ModuleName.c_str() << std::endl;
79 
80  // Loop over SimChannel
81  for(size_t simch_index=0; simch_index<simchArray->size(); ++simch_index) {
82 
83  const art::Ptr<sim::SimChannel> simch_ptr(simchArray,simch_index);
84 
85  size_t ch = simch_ptr->Channel();
86 
87  if(ch >= hits_v->size())
88 
89  throw cet::exception(__PRETTY_FUNCTION__)
90  << "Channel number " << ch << " exceeds total # of channels: " << nch << std::endl;
91 
92  auto &mchits = hits_v->at(ch);
93  auto &mcwires = wires_v->at(ch);
94 
95  std::map<sim::MCEnDep,sim::MCWire> edep_wire_map;
96  auto tdc_ide_map = simch_ptr->TDCIDEMap();
97 
98  ////////////////////////////////////////////////////////////
99  // Loop over stored data for a particular sim::SimChannel //
100  ////////////////////////////////////////////////////////////
101 
102  //
103  // Read & Convert
104  //
105  if(fVerbose)
106  std::cout<<std::endl<<"Processing Ch: "<<ch<<std::endl;
107 
108  for(auto const& tdc_ide_pair : tdc_ide_map) {
109 
110  auto const& tdc = tdc_ide_pair.first;
111  auto const& ide_v = tdc_ide_pair.second;
112 
113  for(auto const& ide : ide_v) {
114  sim::MCEnDep edep;
115  edep.SetVertex(ide.x,ide.y,ide.z);
116  edep.SetEnergy(ide.energy);
117  edep.SetTrackId(ide.trackID);
118 
119  sim::MCWire wire;
120  wire.SetStartTDC(tdc);
121 
122  auto edep_iter = edep_wire_map.insert(std::make_pair(edep,wire));
123 
124  //auto edep_iter = edep_wire_map.find(edep);
125 
126  auto last_tdc = (edep_iter).first->second.StartTDC() + (edep_iter).first->second.size() - 1;
127 
128  if(fVerbose) {
129 
130  if( edep_iter.second ) std::cout<<std::endl;
131 
132  std::cout<<" Track: "<<ide.trackID
133  <<" Vtx: " <<ide.x << " " << ide.y << " " <<ide.z << " " <<ide.energy
134  << " ... @ TDC = "<<tdc<<" ... "<<ide.numElectrons << std::endl;
135  }
136 
137  if( !(edep_iter.second) ) {
138 
139  if( last_tdc+1 != tdc ) {
140  /*
141  std::cerr
142  << "Found discontinuous TDC! "
143  << " Last (ADC @ TDC): " << (*(edep_iter.first->second.rbegin())) << " @ " << last_tdc
144  << " while current (ADC @ TDC): " << (ide.numElectrons * detp->ElectronsToADC()) << " @ " << tdc
145  << " ... skipping to store!"
146  << std::endl;
147  */
148  continue;
149  }
150  }
151  (edep_iter).first->second.push_back(ide.numElectrons);
152  }// Done looping over IDEs in a particular TDC
153  }// Done looping over TDC
154 
155  //
156  // Store
157  //
158  for(auto const& edep_wire_pair : edep_wire_map) {
159 
160  auto const& edep = edep_wire_pair.first;
161  auto const& wire = edep_wire_pair.second;
162 
163  // Create MCHit
165  float vtx[3] = {float(edep.Vertex()[0]),
166  float(edep.Vertex()[1]),
167  float(edep.Vertex()[2])};
168  hit.SetParticleInfo(vtx, edep.Energy(), edep.TrackId());
169 
170  double max_time = 0;
171  double qsum = 0;
172  double qmax = 0;
173  for(size_t wire_index=0; wire_index < wire.size(); ++wire_index) {
174 
175  auto q = wire.at(wire_index);
176 
177  qsum += q;
178 
179  if( q > qmax) { qmax = q; max_time = wire.StartTDC() + wire_index; }
180 
181  }
182  hit.SetCharge(qsum,qmax);
183  hit.SetTime(max_time,0);
184 
185  mchits.push_back(hit);
186 
187  if(!fMakeMCWire) continue;
188 
189  mcwires.push_back(wire);
190  } // End looping over all MCEnDep-MCWire pairs
191  } // End looping over all SimChannels
192 
193  e.removeCachedProduct(simchArray);
194 
195  std::sort((*hits_v).begin(),(*hits_v).end());
196  e.put(std::move(hits_v));
197 
198  if(fMakeMCWire) {
199  std::sort((*wires_v).begin(),(*wires_v).end());
200  e.put(std::move(wires_v));
201  }
202 
203  }
void SetCharge(float qsum, float amp)
Setter function for charge/amplitude.
Definition: MCHit.h:54
void SetEnergy(float e)
Definition: MCDataHolder.h:39
void SetParticleInfo(const float vtx[], const float energy, const int trackId)
Setter function for partile info.
Definition: MCHit.h:64
void SetTime(const float peak, const float width)
Setter function for time.
Definition: MCHit.h:57
void SetStartTDC(const unsigned int start)
Setter function for time.
Definition: MCWire.h:42
void SetTrackId(unsigned int id)
Definition: MCDataHolder.h:41
process_name hit
Definition: cheaterreco.fcl:51
unsigned int StartTDC() const
Getter for start time.
Definition: MCWire.h:56
unsigned int TrackId() const
Definition: MCDataHolder.h:47
void SetVertex(float x, float y, float z)
Definition: MCDataHolder.h:32
std::string fLArG4ModuleName
float Energy() const
Definition: MCDataHolder.h:45
do i e
BEGIN_PROLOG could also be cout
const std::array< float, 3 > & Vertex() const
Definition: MCDataHolder.h:43

Member Data Documentation

std::string hit::MCHitFinder::fLArG4ModuleName
private

Definition at line 37 of file MCHitFinder_module.cc.

bool hit::MCHitFinder::fMakeMCWire
private

Definition at line 39 of file MCHitFinder_module.cc.

bool hit::MCHitFinder::fVerbose
private

Definition at line 38 of file MCHitFinder_module.cc.


The documentation for this class was generated from the following file: