All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ICARUSFlashFinder_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ICARUSFlashFinder
3 // Module Type: producer
4 // File: ICARUSFlashFinder_module.cc
5 //
6 // Generated at Tue Sep 13 22:30:26 2016 by Kazuhiro Terao using artmod
7 // from cetpkgsupport v1_10_02.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 
23 
24 #include <memory>
25 #include <string>
26 #include "FlashFinderManager.h"
28 #include "PECalib.h"
29 
30 class ICARUSFlashFinder;
31 
32 class ICARUSFlashFinder : public art::EDProducer {
33 public:
34  explicit ICARUSFlashFinder(fhicl::ParameterSet const & p);
35  // The destructor generated by the compiler is fine for classes
36  // without bare pointers or other resource use.
37 
38  // Plugins should not be copied or assigned.
39  ICARUSFlashFinder(ICARUSFlashFinder const &) = delete;
43 
44  // Required functions.
45  void produce(art::Event & e) override;
46 
47 
48 private:
49 
50  // Declare member data here.
53  std::string _hit_producer;
54 
55  void GetFlashLocation(std::vector<double>, double&, double&, double&, double&);
56 
57 };
58 
59 
61  : EDProducer{p}
62 // Initialize member data here.
63 {
64  _hit_producer = p.get<std::string>("OpHitProducer");
65 
66  auto const flash_algo = p.get<std::string>("FlashFinderAlgo");
67  auto const flash_pset = p.get<pmtana::Config_t>("AlgoConfig");
68  auto algo_ptr = ::pmtana::FlashAlgoFactory::get().create(flash_algo,flash_algo);
69  algo_ptr->Configure(flash_pset);
70  _mgr.SetFlashAlgo(algo_ptr);
71 
72  _pecalib.Configure(p.get<pmtana::Config_t>("PECalib"));
73 
74  produces< std::vector<recob::OpFlash> >();
75  produces< art::Assns <recob::OpHit, recob::OpFlash> >();
76 }
77 
78 void ICARUSFlashFinder::produce(art::Event & e)
79 {
80 
81  // produce OpFlash data-product to be filled within module
82  std::unique_ptr< std::vector<recob::OpFlash> > opflashes(new std::vector<recob::OpFlash>);
83  std::unique_ptr< art::Assns <recob::OpHit, recob::OpFlash> > flash2hit_assn_v ( new art::Assns<recob::OpHit, recob::OpFlash> );
84  // load OpHits previously created
85  art::Handle<std::vector<recob::OpHit> > ophit_h;
86  e.getByLabel(_hit_producer,ophit_h);
87 
88  // make sure hits look good
89  if(!ophit_h.isValid()) {
90  std::cerr<<"\033[93m[ERROR]\033[00m ... could not locate OpHit!"<<std::endl;
91  throw std::exception();
92  }
93 
95  double trigger_time=1.1e20;
96  for(auto const& oph : *ophit_h) {
98  if(trigger_time > 1.e20) trigger_time = oph.PeakTimeAbs() - oph.PeakTime();
99  loph.peak_time = oph.PeakTime();
100 
101  size_t opdet = ::pmtana::OpDetFromOpChannel(oph.OpChannel());
102  loph.pe = _pecalib.Calibrate(opdet,oph.Area());
103  loph.channel = oph.OpChannel();
104  ophits.emplace_back(std::move(loph));
105  }
106 
107  auto const flash_v = _mgr.RecoFlash(ophits);
108 
109  for(const auto& lflash : flash_v) {
110 
111  double Ycenter, Zcenter, Ywidth, Zwidth;
112  GetFlashLocation(lflash.channel_pe, Ycenter, Zcenter, Ywidth, Zwidth);
113 
114  recob::OpFlash flash(lflash.time, lflash.time_err,
115  trigger_time + lflash.time,
116  (trigger_time + lflash.time) / 1600.,
117  lflash.channel_pe,
118  0, 0, 1, // this are just default values
119  Ycenter, Ywidth, Zcenter, Zwidth);
120  opflashes->emplace_back(std::move(flash));
121 
122  for(auto const& hitidx : lflash.asshit_idx) {
123  const art::Ptr<recob::OpHit> hit_ptr(ophit_h, hitidx);
124  util::CreateAssn(*this, e, *opflashes, hit_ptr, *flash2hit_assn_v);
125  }
126  }
127 
128  e.put(std::move(opflashes));
129  e.put(std::move(flash2hit_assn_v));
130 }
131 
132 void ICARUSFlashFinder::GetFlashLocation(std::vector<double> pePerOpChannel,
133  double& Ycenter,
134  double& Zcenter,
135  double& Ywidth,
136  double& Zwidth)
137 {
138 
139  // Reset variables
140  Ycenter = Zcenter = 0.;
141  Ywidth = Zwidth = -999.;
142  double totalPE = 0.;
143  double sumy = 0., sumz = 0., sumy2 = 0., sumz2 = 0.;
144 
145  for (unsigned int opch = 0; opch < pePerOpChannel.size(); opch++) {
146  /*
147  if (opch > 31 && opch < 200){
148  // std::cout << "Ignoring channel " << opch << " as it's not a real channel" << std::endl;
149  continue;
150  }
151  */
152  // Get physical detector location for this opChannel
153  double PMTxyz[3];
155 
156  // Add up the position, weighting with PEs
157  sumy += pePerOpChannel[opch]*PMTxyz[1];
158  sumy2 += pePerOpChannel[opch]*PMTxyz[1]*PMTxyz[1];
159  sumz += pePerOpChannel[opch]*PMTxyz[2];
160  sumz2 += pePerOpChannel[opch]*PMTxyz[2]*PMTxyz[2];
161 
162  totalPE += pePerOpChannel[opch];
163  }
164 
165  Ycenter = sumy/totalPE;
166  Zcenter = sumz/totalPE;
167 
168  // This is just sqrt(<x^2> - <x>^2)
169  if ( (sumy2*totalPE - sumy*sumy) > 0. )
170  Ywidth = std::sqrt(sumy2*totalPE - sumy*sumy)/totalPE;
171 
172  if ( (sumz2*totalPE - sumz*sumz) > 0. )
173  Zwidth = std::sqrt(sumz2*totalPE - sumz*sumz)/totalPE;
174 }
175 
176 DEFINE_ART_MODULE(ICARUSFlashFinder)
std::vector< pmtana::LiteOpHit_t > LiteOpHitArray_t
FlashAlgoBase * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
BEGIN_PROLOG could also be cerr
::pmtana::PECalib _pecalib
pdgs p
Definition: selectors.fcl:22
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
double Calibrate(const size_t opdet, const double area) const
ICARUSFlashFinder(fhicl::ParameterSet const &p)
void produce(art::Event &e) override
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
virtual void Configure(const Config_t &p)=0
do i e
static FlashAlgoFactory & get()
Static sharable instance getter.
ICARUSFlashFinder & operator=(ICARUSFlashFinder const &)=delete
::pmtana::FlashFinderManager _mgr
void GetFlashLocation(std::vector< double >, double &, double &, double &, double &)
LiteOpFlashArray_t RecoFlash(const LiteOpHitArray_t &ophits) const