11 #include "art/Framework/Core/EDAnalyzer.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "art/Framework/Principal/Run.h"
16 #include "art/Framework/Principal/SubRun.h"
17 #include "canvas/Utilities/InputTag.h"
18 #include "fhiclcpp/ParameterSet.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "art_root_io/TFileService.h"
21 #include "art/Framework/Services/Registry/ServiceHandle.h"
22 #include "canvas/Persistency/Common/FindManyP.h"
26 #include "nusimdata/SimulationBase/MCTruth.h"
27 #include "nusimdata/SimulationBase/MCParticle.h"
63 void analyze(art::Event
const&
e)
override;
103 unsigned int GetMaxChan(vector<double>
const& pes);
112 fGenLabel(
p.get<art::InputTag>(
"GenLabel",
"generator")),
113 fPhotLabel(
p.get<art::InputTag>(
"PhotLabel",
"largeant")),
114 fFlashLabel0(
p.get<art::InputTag>(
"FlashLabel0",
"opflashTPC0")),
115 fFlashLabel1(
p.get<art::InputTag>(
"FlashLabel1",
"opflashTPC1")),
116 fFlashLabel2(
p.get<art::InputTag>(
"FlashLabel2",
"opflashTPC2")),
117 fFlashLabel3(
p.get<art::InputTag>(
"FlashLabel3",
"opflashTPC3")),
118 fHitLabel(
p.get<art::InputTag>(
"HitLabel",
"ophit"))
120 fFlashLabels[0] = fFlashLabel0;
121 fFlashLabels[1] = fFlashLabel1;
122 fFlashLabels[2] = fFlashLabel2;
123 fFlashLabels[3] = fFlashLabel3;
125 art::ServiceHandle<art::TFileService>
tfs;
127 fTree = tfs->make<TTree>(
"anatree",
"OpFlash resolution");
128 fTree->Branch(
"nFlash", &fNFlash,
"nFlash/I");
129 fTree->Branch(
"nuE", &fNuE,
"nuE/D");
130 fTree->Branch(
"cc", &fCC,
"cc/O");
131 fTree->Branch(
"nuXYZT", fNuXYZT,
"nuXYZT[4]/D");
132 fTree->Branch(
"flashXYZT", fFlashXYZT,
"flashXYZT[4]/D");
133 fTree->Branch(
"flashXYZTMin", fFlashXYZTMin,
"flashXYZTMin[4]/D");
134 fTree->Branch(
"flashXYZTMax", fFlashXYZTMax,
"flashXYZTMax[4]/D");
135 fTree->Branch(
"flashWidth",fFlashWidth,
"flashWidth[4]/D");
136 fTree->Branch(
"flashPE", &fFlashPE,
"flashPE/D");
137 fTree->Branch(
"flashTPC", &fFlashTPC,
"flashTPC/I");
138 fTree->Branch(
"maxChan", &fMaxChan,
"maxChan/i");
139 fTree->Branch(
"maxPE", &fMaxPE,
"maxPE/D");
140 fTree->Branch(
"delta", fDelta,
"delta[4]/D");
141 fTree->Branch(
"inFrame", &fInFrame,
"inFrame/O");
142 fTree->Branch(
"deltaPmt", &fDeltaPmt,
"deltaPmt/D");
143 fTree->Branch(
"nPmtFlash", &fNPmtFlash,
"nPmtFlash/I");
144 fTree->Branch(
"hitXYZT", fHitXYZT,
"hittXYZT[4]/D");
145 fTree->Branch(
"hitDist", &fHitDist,
"hitDist/D");
146 fTree->Branch(
"hitTof", &fHitTof,
"hitTof/D");
147 fTree->Branch(
"nHit", &fNHit,
"nHit/I");
148 fTree->Branch(
"hitPE", &fHitPE,
"hitPE/D");
149 fTree->Branch(
"tPhot", &fTPhot,
"tPhot/D");
151 fDeltaTFlash = tfs->make<TH1F>(
"dtflash",
"delay between flashes;#Delta t [ns];",25000,0,500000);
153 fGeometryService = lar::providerFrom<geo::Geometry>();
173 for(
size_t i=0; i<4; i++) {
176 fFlashXYZTMin[i] = dt;
177 fFlashXYZTMax[i] = dt;
184 auto const& mctruths =
185 *e.getValidHandle<vector<simb::MCTruth>>(fGenLabel);
187 auto const&
nu = mctruths[0].GetNeutrino();
192 const TLorentzVector nuxyzt = nu.Nu().Position(0);
193 fNuXYZT[0] = nuxyzt.X();
194 fNuXYZT[1] = nuxyzt.Y();
195 fNuXYZT[2] = nuxyzt.Z();
196 fNuXYZT[3] = nuxyzt.T();
199 art::Handle< std::vector<sim::SimPhotons>> photHandle;
200 std::vector< art::Ptr<sim::SimPhotons> > photList;
201 if( e.getByLabel(fPhotLabel, photHandle) )
202 art::fill_ptr_vector(photList, photHandle);
204 double tphotmin = DBL_MAX;
205 for(
auto const& phot : photList){
206 for(
size_t i=0; i<phot->size(); i++) {
207 if ((phot->at(i)).Time < tphotmin)
208 tphotmin = (phot->at(i)).Time;
214 map<int,art::Handle< std::vector<recob::OpFlash> > > flashHandles;
215 map<int,vector< art::Ptr<recob::OpFlash> >> flashLists;
216 if( e.getByLabel(fFlashLabel0,flashHandles[0]) )
217 art::fill_ptr_vector(flashLists[0], flashHandles[0]);
218 if( e.getByLabel(fFlashLabel1,flashHandles[1]) )
219 art::fill_ptr_vector(flashLists[1], flashHandles[1]);
220 if( e.getByLabel(fFlashLabel2,flashHandles[2]) )
221 art::fill_ptr_vector(flashLists[2], flashHandles[2]);
222 if( e.getByLabel(fFlashLabel3,flashHandles[3]) )
223 art::fill_ptr_vector(flashLists[3], flashHandles[3]);
225 for(
auto flashList : flashLists) {
227 int tpc = flashList.first;
228 size_t nflashtpc = flashList.second.size();
229 if(nflashtpc==0)
continue;
230 fNFlash += nflashtpc;
232 std::sort(flashList.second.begin(),flashList.second.end(),
233 [](art::Ptr<recob::OpFlash> f1, art::Ptr<recob::OpFlash> f2)
234 {
return f1->Time()<f2->Time();}
237 art::FindManyP<recob::OpHit> findManyHits(
238 flashHandles[tpc], e, fFlashLabels[tpc]);
241 for(
size_t iflash=0; iflash < nflashtpc; iflash++) {
242 auto const& flash0 = flashList.second[iflash];
243 if(
abs(fNuXYZT[3]-flash0->Time()*1.0e3)<
abs(dt)) {
244 dt = flash0->Time()*1.0e3 - fNuXYZT[3];
246 fFlashXYZT[1] = flash0->YCenter();
247 fFlashXYZT[2] = flash0->ZCenter();
248 fFlashXYZT[3] = flash0->Time()*1.0e3;
250 fFlashWidth[1] = flash0->YWidth();
251 fFlashWidth[2] = flash0->ZWidth();
252 fFlashWidth[3] = flash0->TimeWidth();
253 fFlashPE = flash0->TotalPE();
255 auto const& pes= flash0->PEs();
256 fNPmtFlash = pes.size();
257 fMaxChan = GetMaxChan(pes);
258 fMaxPE = flash0->PE(fMaxChan);
259 fInFrame = flash0->InBeamFrame();
260 for(
size_t i=0; i<4; i++)
261 fDelta[i] = fFlashXYZT[i] - fNuXYZT[i];
263 double tPmtMax=-DBL_MAX, tPmtMin=DBL_MAX;
264 vector<art::Ptr<recob::OpHit>> hits = findManyHits.at(iflash);
265 for(
auto const&
hit : hits) {
266 if(
hit->OpChannel() == fMaxChan){
267 fDeltaPmt =
hit->PeakTime()*1.0e3 - fNuXYZT[3];
269 if(
hit->PeakTime()<tPmtMin){
270 tPmtMin =
hit->PeakTime();
274 for(
int i=0; i<3; i++) fFlashXYZTMin[i] = pos[i];
275 fFlashXYZTMin[3] = tPmtMin;
277 if(
hit->PeakTime()>tPmtMax){
278 tPmtMax =
hit->PeakTime();
282 for(
int i=0; i<3; i++) fFlashXYZTMax[i] = pos[i];
283 fFlashXYZTMax[3] = tPmtMax;
290 for(
size_t i=0; i<nflashtpc-1; i++) {
291 auto const& flash = flashList.second.at(i);
292 auto const& flashnext = flashList.second.at(i+1);
293 fDeltaTFlash->Fill((flashnext->Time()-flash->Time())*1.0e3);
298 art::Handle< std::vector<recob::OpHit> > opHitHandle;
299 std::vector< art::Ptr<recob::OpHit> > opHitList;
301 if( e.getByLabel(fHitLabel,opHitHandle) ) {
303 art::fill_ptr_vector(opHitList, opHitHandle);
304 fNHit = opHitList.size();
306 std::cout <<
"empty OpHit vector!" << std::endl;
307 for(
int i=0; i<4; i++) fHitXYZT[i] = DBL_MAX;
314 std::sort(opHitList.begin(),opHitList.end(),
315 [](art::Ptr<recob::OpHit> h1, art::Ptr<recob::OpHit> h2)
316 {
return h1->PeakTime()<h2->PeakTime();}
318 if(opHitList.size()>1 && opHitList[0]->PeakTime()>opHitList.back()->PeakTime())
319 std::cout <<
"OpHits time sort failed!" << std::endl;
324 for(
int i=0; i<3; i++) fHitXYZT[i] = pos[i];
325 fHitXYZT[3] = opHitList[0]->PeakTime()*1.0e3;
327 for(
int i=0; i<3; i++)
328 fHitDist+=pow(fHitXYZT[i]-fNuXYZT[i],2);
329 fHitDist = sqrt(fHitDist);
330 fHitTof = fHitXYZT[3] - fNuXYZT[3];
331 fHitPE = opHitList[0]->PE();
335 std::cout <<
"no OpHit handle found!" << std::endl;
346 for(
size_t i=0; i<pes.size(); i++){
void analyze(art::Event const &e) override
geo::GeometryCore const * fGeometryService
pointer to Geometry provider
Utilities related to art service access.
art::InputTag fFlashLabel1
art::InputTag fFlashLabel0
void GetCenter(double *xyz, double localz=0.0) const
Geometry information for a single cryostat.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
Simulation objects for optical detectors.
map< int, art::InputTag > fFlashLabels
art::InputTag fFlashLabel3
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet'th optical detector in the cryostat.
Description of geometry of one entire detector.
FlashResAna(fhicl::ParameterSet const &p)
FlashResAna & operator=(FlashResAna const &)=delete
unsigned int GetMaxChan(vector< double > const &pes)
art::InputTag fFlashLabel2
art::ServiceHandle< art::TFileService > tfs
art framework interface to geometry description
BEGIN_PROLOG could also be cout