12 #include "art/Framework/Core/EDProducer.h"
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Principal/Event.h"
15 #include "art/Framework/Principal/Handle.h"
16 #include "art/Framework/Principal/Run.h"
17 #include "art/Framework/Principal/SubRun.h"
18 #include "art_root_io/TFileService.h"
23 #include "fhiclcpp/ParameterSet.h"
54 void produce(art::Event &
e)
override;
55 void beginRun(art::Run& run)
override;
98 produces< std::vector<sim::SimChannel> >();
99 produces< std::vector<sim::SimEnergyDeposit> >();
100 produces< std::vector<raw::Trigger> >();
101 produces< sumdata::RunData, art::InRun >();
103 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataForJob();
104 fTriggerTime = clockData.TriggerTime();
107 fWiresByPlaneVec.resize(3);
108 fPlaneChannelVec.resize(3);
109 fPlanePositionVecVec.resize(3);
112 fSimTime_v =
p.get< std::vector<double> >(
"SimTimeArray_us");
113 fCryostat =
p.get<
unsigned int >(
"Cryostat");
114 fTPC =
p.get<
unsigned int >(
"TPC");
115 fWiresByPlaneVec[0] =
p.get< WireVec >(
"Plane0Wires");
116 fWiresByPlaneVec[1] =
p.get< WireVec >(
"Plane1Wires");
117 fWiresByPlaneVec[2] =
p.get< WireVec >(
"Plane2Wires");
118 fNumElectrons_v =
p.get< std::vector<double> >(
"NumElectronsArray");
119 fVerbose =
p.get<
bool> (
"Verbose",
false);
121 assert( fSimTime_v.size() == fWiresByPlaneVec[0].size() &&
122 fSimTime_v.size() == fWiresByPlaneVec[1].size() &&
123 fSimTime_v.size() == fWiresByPlaneVec[2].size() &&
124 fSimTime_v.size() == fNumElectrons_v.size() );
129 art::ServiceHandle<art::TFileService>
tfs;
131 fTupleTree = tfs->make<TTree>(
"SimTestPulseWire",
"Tree by SimTestPulseWire_module");
140 fTupleTree->Branch(
"e_v",
"std::vector<double>",&fNumElectrons_v);
146 fTupleTree->Branch(
"wire_plane0",
"std::vector<int>",&fWiresByPlaneVec[0]);
147 fTupleTree->Branch(
"wire_plane1",
"std::vector<int>",&fWiresByPlaneVec[1]);
148 fTupleTree->Branch(
"wire_plane2",
"std::vector<int>",&fWiresByPlaneVec[2]);
159 art::ServiceHandle<geo::Geometry> geo;
161 std::unique_ptr<sumdata::RunData> runData(
new sumdata::RunData(geo->DetectorName()));
163 run.put(std::move(runData));
170 std::unique_ptr<std::vector<raw::Trigger> > trigger_v(
new std::vector<raw::Trigger> );
173 std::unique_ptr<std::vector<sim::SimChannel> > simch_v(
new std::vector<sim::SimChannel> );
175 std::unique_ptr<std::vector<sim::SimEnergyDeposit>> simDep_v(
new std::vector<sim::SimEnergyDeposit>);
179 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(e);
180 art::ServiceHandle<geo::Geometry> geo;
182 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
195 for(
size_t index=0; index <
fSimTime_v.size(); ++index) {
197 int tdc =
fSimTime_v[index] / clockData.TPCClock().TickPeriod();
198 fTick_v.push_back(clockData.TPCTDC2Tick(tdc));
201 std::cout <<
"[BUFFOON!] Charge injection id " << index <<
" @ TDC=" << tdc
203 <<
" with " << fNumElectrons_v[index] <<
" electrons " << std::endl;
207 <<
" as it results in negative TDC (invalid)" << std::endl;
213 TVector3 planeCoords = planeGeo.
GetCenter();
217 chargeDepCoords =
geo::Point_t(planeCoords[0] + 1. * planeNormal[0],planeCoords[1],planeCoords[2]);
220 pulse_record.
tdc = tdc;
222 pulse_record.
tick = clockData.TPCTDC2Tick(tdc);
224 double nElecADC =
detProp.ElectronsToADC() * fNumElectrons_v[index];
226 std::cout <<
"==> x position of plane 0: " << planeCoords[0] <<
", normal: " << planeNormal[0] <<
", nElec: " << fNumElectrons_v[index] <<
", nElecADC: " << nElecADC << std::endl;
228 simDep_v->emplace_back(0,fNumElectrons_v[index],0.,nElecADC,chargeDepCoords,chargeDepCoords);
230 for(
size_t plane=0; plane<3; ++plane)
232 int wire = fWiresByPlaneVec[plane][index];
241 std::vector<geo::WireID> wireIDVec = geo->ChannelToWire(channel);
244 <<
" returns " << wireIDVec.size() <<
" IDs, C/T/P/W: " << wireIDVec.front().Cryostat <<
"/" << wireIDVec.front().TPC <<
"/" << wireIDVec.front().Plane <<
"/" << wireIDVec.front().Wire << std::endl;
253 xyz[0] = chargeDepCoords.X();
255 Position position = {xyz[0],xyz[1],xyz[2]};
259 if(fVerbose)
std::cout <<
"[BUFFOON!] plane " << plane <<
" channel " << channel <<
" ... wire " << wire << std::endl;
267 fNumElectrons_v[index],
270 simch_v->emplace_back(std::move(sch));
273 pholder.Register(std::move(pulse_record));
281 e.put(std::move(simch_v));
282 e.put(std::move(simDep_v));
283 e.put(std::move(trigger_v));
WireVecVec fWiresByPlaneVec
For each plane the wires to deposit charge on.
std::vector< PositionVec > PositionVecVec
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
static ParamHolder & get()
Energy deposited on a readout channel by simulated tracks.
BEGIN_PROLOG could also be cerr
unsigned int fTPC
TPC in that cryostat (0-3 for split wire)
The data type to uniquely identify a Plane.
CryostatID_t Cryostat
Index of cryostat.
WireID_t Wire
Index of the wire within its plane.
Vector GetNormalDirection() const
Returns the direction normal to the plane.
WireVec fTick_v
Corresponding tick.
Access the description of detector geometry.
std::vector< WireVec > WireVecVec
void produce(art::Event &e) override
std::vector< int > WireVec
PositionVecVec fPlanePositionVecVec
Keep track of positions for each wire on each plane.
SimTestPulseWire & operator=(SimTestPulseWire const &)=delete
SimTestPulseWire(fhicl::ParameterSet const &p)
Point GetCenter() const
Returns the centre of the wire plane in world coordinates [cm].
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
std::vector< Position > PositionVec
WireVecVec fPlaneChannelVec
Keep track of wires for each plane.
void beginRun(art::Run &run) override
PlaneID_t Plane
Index of the plane within its TPC.
std::array< int, 3 > channel_list
std::vector< double > Position
unsigned int fCryostat
Cryostat to consider.
contains information for a single step in the detector simulation
object containing MC truth information necessary for making RawDigits and doing back tracking ...
art::ServiceHandle< art::TFileService > tfs
double fTriggerTime
Trigger timing in electronics clock [us].
void AddIonizationElectrons(TrackID_t trackID, TDC_t tdc, double numberElectrons, double const *xyz, double energy, TrackID_t origTrackID=util::kBogusI)
Add ionization electrons and energy to this channel.
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
TPCID_t TPC
Index of the TPC within its cryostat.
TTree * fTupleTree
output analysis tree
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::vector< double > fNumElectrons_v
Charge amount in electron count.
std::vector< double > fSimTime_v
Charge timing in electronics clock [us].