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"
32 #include "nusimdata/SimulationBase/MCGeneratorInfo.h"
33 #include "nusimdata/SimulationBase/MCTruth.h"
34 #include "nusimdata/SimulationBase/MCParticle.h"
77 void analyze(art::Event
const&
e)
override;
81 const double LAR_PROP_DELAY = 1.0/(30.0/1.38);
83 bool HitCompare(
const art::Ptr<CRTHit>& h1,
const art::Ptr<CRTHit>& h2);
177 fGenLabel(
p.get<art::InputTag>(
"GenLabel",
"generator")),
178 fSimLabel(
p.get<art::InputTag>(
"SimLabel",
"largeant")),
179 fOpHitModuleLabel(
p.get<art::InputTag>(
"OpHitModuleLabel",
"ophit")),
180 fOpFlashModuleLabel0(
p.get<art::InputTag>(
"OpFlashModuleLabel0",
"opflashTPC0")),
181 fOpFlashModuleLabel1(
p.get<art::InputTag>(
"OpFlashModuleLabel1",
"opflashTPC1")),
182 fOpFlashModuleLabel2(
p.get<art::InputTag>(
"OpFlashModuleLabel2",
"opflashTPC2")),
183 fOpFlashModuleLabel3(
p.get<art::InputTag>(
"OpFlashModuleLabel3",
"opflashTPC3")),
184 fCrtHitModuleLabel(
p.get<art::InputTag>(
"CrtHitModuleLabel",
"crthit")),
185 fCrtTrackModuleLabel(
p.get<art::InputTag>(
"CrtTrackModuleLabel",
"crttrack")),
186 fCoinWindow(
p.get<
double>(
"CoincidenceWindow",60.0)),
187 fOpDelay(
p.get<
double>(
"OpDelay",55.1)),
188 fCrtDelay(
p.get<
double>(
"CrtDelay",1.6e6)),
189 fFlashPeThresh(
p.get<
int>(
"FlashPeThresh",9000)),
190 fHitPeThresh(
p.get<
int>(
"HitPeThresh",700)),
191 fFlashVelocity(
p.get<
double>(
"FlashVelocityThresh",-40.)),
192 fFlashZOffset(
p.get<
double>(
"FlashZOffset",0.)),
193 fHitVelocityMax(
p.get<
double>(
"HitVelocityMax",20.)),
194 fHitVelocityMin(
p.get<
double>(
"HitVelocityMin",1.)),
198 fFlashLabels[0] = fOpFlashModuleLabel0;
199 fFlashLabels[1] = fOpFlashModuleLabel1;
200 fFlashLabels[2] = fOpFlashModuleLabel2;
201 fFlashLabels[3] = fOpFlashModuleLabel3;
204 fGeometryService = lar::providerFrom<geo::Geometry>();
206 art::ServiceHandle<art::TFileService>
tfs;
208 fMatchTree = tfs->make<TTree>(
"matchTree",
"CRTHit - OpHit/Flash matching analysis");
209 fHitTree = tfs->make<TTree>(
"hitTree",
"OpHit info");
210 fFlashTree = tfs->make<TTree>(
"flashTree",
"OpFlash info");
212 fHitTree->Branch(
"nhit", &fNHit,
"nOpHit/I");
213 fHitTree->Branch(
"xyzt", &fHitXYZT);
214 fHitTree->Branch(
"pe", &fHitPE);
215 fHitTree->Branch(
"chan", &fHitChan);
217 fFlashTree->Branch(
"nflash", &fNFlash,
"nOpFlash/I");
218 fFlashTree->Branch(
"tpc", &fFlashTPC);
219 fFlashTree->Branch(
"xyzt", &fFlashXYZT);
220 fFlashTree->Branch(
"totpe", &fFlashPE);
221 fFlashTree->Branch(
"nhit", &fFlashNHit);
222 fFlashTree->Branch(
"meanpe", &fFlashMeanPE);
223 fFlashTree->Branch(
"rmspe", &fFlashRmsPE);
224 fFlashTree->Branch(
"delta", &fFlashDelta);
226 fMatchTree->Branch(
"ncrt", &fNCrt,
"nCrtHit/I");
227 fMatchTree->Branch(
"crtXYZT", &fCrtXYZT);
228 fMatchTree->Branch(
"crtXYZErr", &fCrtXYZErr);
229 fMatchTree->Branch(
"crtPE", &fCrtPE);
230 fMatchTree->Branch(
"crtRegion", &fCrtRegion);
231 fMatchTree->Branch(
"tofHit", &fTofHit);
232 fMatchTree->Branch(
"tofFlash", &fTofFlash);
233 fMatchTree->Branch(
"tofFlashHit", &fTofFlashHit);
234 fMatchTree->Branch(
"peHit", &fTofPeHit);
235 fMatchTree->Branch(
"peFlash", &fTofPeFlash);
236 fMatchTree->Branch(
"peFlashHit", &fTofPeFlashHit);
237 fMatchTree->Branch(
"xyztHit", &fTofXYZTHit);
238 fMatchTree->Branch(
"xyztFlash", &fTofXYZTFlash);
239 fMatchTree->Branch(
"xyztFlashHit", &fTofXYZTFlashHit);
240 fMatchTree->Branch(
"distHit", &fDistHit);
241 fMatchTree->Branch(
"distFlash", &fDistFlash);
242 fMatchTree->Branch(
"distFlashHit", &fDistFlashHit);
243 fMatchTree->Branch(
"tpcHit", &fTofTpcHit);
244 fMatchTree->Branch(
"tpcFlash", &fTofTpcFlash);
245 fMatchTree->Branch(
"matchHit", &fMatchHit);
246 fMatchTree->Branch(
"matchFlash", &fMatchFlash);
247 fMatchTree->Branch(
"distTrue", &fTrueDist);
248 fMatchTree->Branch(
"tofTrue", &fTrueTOF);
249 fMatchTree->Branch(
"enterXYZT", &fEnterXYZT);
250 fMatchTree->Branch(
"pmtXYZT", &fPMTXYZT);
251 fMatchTree->Branch(
"crtPDG", &fHitPDG);
252 fMatchTree->Branch(
"crtIV", &fIV);
253 fMatchTree->Branch(
"crtAV", &fAV);
254 fMatchTree->Branch(
"crtFV", &fFV);
255 fMatchTree->Branch(
"nu", &fNu,
"nu/O");
256 fMatchTree->Branch(
"nuCC", &fNuCC,
"nuCC/O");
257 fMatchTree->Branch(
"nuE", &fNuE,
"nuE/D");
258 fMatchTree->Branch(
"nuXYZT", fNuXYZT,
"nuXYZT[4]/D");
259 fMatchTree->Branch(
"nuIV", &fNuIV,
"nuIV/O");
260 fMatchTree->Branch(
"nuAV", &fNuAV,
"nuAV/O");
261 fMatchTree->Branch(
"nuFV", &fNuFV,
"nuFV/O");
262 fMatchTree->Branch(
"trackfilt", &fTrackFilt);
280 auto const& mctruths =
281 *e.getValidHandle<vector<simb::MCTruth>>(
fGenLabel);
288 auto const&
nu = mctruths[0].GetNeutrino();
289 const TLorentzVector xyzt =
nu.Nu().Position(0);
297 for(
int i=0; i<3; i++) point[i] =
fNuXYZT[i];
315 for(
int i=0; i<4; i++)
319 auto const& simparticles =
320 *e.getValidHandle<vector<simb::MCParticle>>(
fSimLabel);
323 map<int,const simb::MCParticle*> particleMap;
324 for(
auto const& particle : simparticles){
326 particleMap[particle.TrackId()] = &particle;
331 art::Handle< std::vector<recob::OpHit> > opHitListHandle;
332 std::vector< art::Ptr<recob::OpHit> > opHitList;
334 art::fill_ptr_vector(opHitList, opHitListHandle);
336 fNHit = opHitList.size();
337 for(
auto const&
ophit : opHitList){
343 vector<double> xyzt = {pos[0],pos[1],pos[2],t};
350 map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
351 std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
353 for(
int i=0; i<4; i++) {
355 art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
358 for(
auto const& flashList : opFlashLists) {
359 fNFlash += flashList.second.size();
361 for(
size_t iflash=0; iflash<flashList.second.size(); iflash++) {
362 auto const& flash = flashList.second[iflash];
366 xyzt.push_back(flash->YCenter());
367 xyzt.push_back(flash->ZCenter());
368 xyzt.push_back(flash->Time()*1e3-
fOpDelay);
370 fFlashPE.push_back(flash->TotalPE());
372 auto const& pes = flash->PEs();
376 for(
auto const& pe : pes)
380 vector<double> delta = {0., flash->YWidth(),flash->ZWidth(),flash->TimeWidth()};
411 art::Handle< std::vector<sbn::crt::CRTTrack> > crtTrackListHandle;
412 std::vector< art::Ptr<sbn::crt::CRTTrack> > crtTrackList;
414 art::fill_ptr_vector(crtTrackList, crtTrackListHandle);
416 art::FindManyP<CRTHit> findManyHits(
421 std::vector<std::vector<art::Ptr<CRTHit>>> trackhits;
422 for(
size_t itrk=0; itrk<crtTrackList.size(); itrk++){
424 std::vector<art::Ptr<CRTHit>> trkhits = findManyHits.at(itrk);
425 std::sort(trkhits.begin(),trkhits.end(),
426 [](
const art::Ptr<CRTHit>&
a,
const art::Ptr<CRTHit>& b)->
bool
428 return a->ts0_ns < b->ts0_ns;
431 trackhits.push_back(trkhits);
437 art::Handle< std::vector<CRTHit> > crtHitListHandle;
438 std::vector< art::Ptr<CRTHit> > crtHitList;
440 art::fill_ptr_vector(crtHitList, crtHitListHandle);
442 fNCrt = crtHitList.size();
444 for(
auto const&
crt : crtHitList){
446 bool trackfilt=
false;
447 for(
auto const& trkhits: trackhits){
448 for(
size_t ihit=1; ihit<trkhits.size(); ihit++) {
459 vector<double> xyzt, xyzerr;
460 TVector3 rcrt(
crt->x_pos,
crt->y_pos,
crt->z_pos);
462 xyzt.push_back(rcrt.X());
463 xyzt.push_back(rcrt.Y());
464 xyzt.push_back(rcrt.Z());
466 xyzt.push_back(tcrt);
469 xyzerr.push_back(
crt->x_err);
470 xyzerr.push_back(
crt->y_err);
471 xyzerr.push_back(
crt->z_err);
480 bool firstIV=
false, firstAV=
false, firstFV=
false;
483 if(particleMap.find(
abs(trackID))!=particleMap.end()){
484 auto const& particle = particleMap[
abs(trackID)];
485 fHitPDG.push_back(particle->PdgCode());
486 for(
size_t i=0; i<particle->NumberTrajectoryPoints(); i++){
487 const TLorentzVector& pos = particle->Position(i);
488 double point[3] = {pos.X(),pos.Y(),pos.Z()};
495 double ddirect = sqrt(pow(opDetPos[0]-rcrt.X(),2)
496 + pow(opDetPos[1]-rcrt.Y(),2)
497 + pow(opDetPos[2]-rcrt.Z(),2));
498 double dprop = sqrt(pow(opDetPos[0]-pos[0],2)
499 + pow(opDetPos[1]-pos[1],2)
500 + pow(opDetPos[2]-pos[2],2));
504 vector<double> tmp1 = {pos.X(),pos.Y(),pos.Z(),pos.T()};
505 vector<double> tmp2 = {opDetPos[0],opDetPos[1],opDetPos[2],tprop};
518 double ddirect = sqrt(pow(opDetPos[0]-rcrt.X(),2)
519 + pow(opDetPos[1]-rcrt.Y(),2)
520 + pow(opDetPos[2]-rcrt.Z(),2));
521 double dprop = sqrt(pow(opDetPos[0]-pos[0],2)
522 + pow(opDetPos[1]-pos[1],2)
523 + pow(opDetPos[2]-pos[2],2));
527 vector<double> tmp1 = {pos.X(),pos.Y(),pos.Z(),pos.T()};
528 vector<double> tmp2 = {opDetPos[0],opDetPos[1],opDetPos[2],tprop};
540 std::cout <<
"CRTHit trackID " << trackID <<
" not found in particle map!" << std::endl;
544 fEnterXYZT.push_back({DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX});
545 fPMTXYZT.push_back({DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX});
547 fIV.push_back(firstIV);
548 fAV.push_back(firstAV);
549 fFV.push_back(firstFV);
550 if(!firstAV&&
fHitPDG.back()!=INT_MAX){
553 fEnterXYZT.push_back({DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX});
554 fPMTXYZT.push_back({DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX});
559 double tdiff = DBL_MAX, rdiff=DBL_MAX, peflash=DBL_MAX;
562 double flashHitT = DBL_MAX, flashHitPE=DBL_MAX, flashHitDiff=DBL_MAX;
563 vector<double> flashHitxyzt;
565 for(
auto const& flashList : opFlashLists) {
567 art::FindManyP<recob::OpHit> findManyHits(
568 flashHandles[flashList.first], e,
fFlashLabels[flashList.first]);
570 for(
size_t iflash=0; iflash<flashList.second.size(); iflash++) {
572 auto const& flash = flashList.second[iflash];
577 double tflash = flash->Time()*1e3-
fOpDelay;
578 TVector3 rflash(0,flash->YCenter(),flash->ZCenter());
579 TVector3 vdiff = rcrt-rflash;
580 if(
abs(tcrt-tflash)<
abs(tdiff)) {
581 peflash = flash->TotalPE();
585 xyzt.push_back(rflash.X());
586 xyzt.push_back(rflash.Y());
587 xyzt.push_back(rflash.Z());
588 xyzt.push_back(tflash);
590 matchtpc = flashList.first;
592 vector<art::Ptr<recob::OpHit>> hits = findManyHits.at(iflash);
593 for(
auto const&
hit : hits) {
595 if( tPmt < flashHitT) {
597 flashHitPE =
hit->PE();
602 flashHitxyzt.clear();
603 for(
int i=0; i<3; i++) flashHitxyzt.push_back(pos[i]);
604 flashHitxyzt.push_back(flashHitT);
607 TVector3 rflashHit(pos[0],pos[1],pos[2]);
608 TVector3 vdiffHit = rcrt-rflashHit;
609 flashHitDiff = vdiffHit.Mag();
618 for(
int i=0; i<4; i++) xyzt.push_back(DBL_MAX);
640 for(
auto const&
hit : opHitList) {
655 TVector3 rhit (pos[0],pos[1],pos[2]);
656 TVector3 vdiff = rcrt-rhit;
665 for(
int i=0; i<3; i++) xyzt.push_back(pos[i]);
666 xyzt.push_back(thit);
677 for(
int i=0; i<4; i++) xyzt.push_back(DBL_MAX);
743 if(hit1->ts1_ns != hit2->ts1_ns)
return false;
744 if(hit1->plane != hit2->plane)
return false;
745 if(hit1->x_pos != hit2->x_pos)
return false;
746 if(hit1->y_pos != hit2->y_pos)
return false;
747 if(hit1->z_pos != hit2->z_pos)
return false;
748 if(hit1->x_err != hit2->x_err)
return false;
749 if(hit1->y_err != hit2->y_err)
return false;
750 if(hit1->z_err != hit2->z_err)
return false;
751 if(hit1->tagger != hit2->tagger)
return false;
unsigned int GetClosestOpDet(geo::Point_t const &point) const
process_name opflashCryo1 flashfilter analyze
vector< double > fDistHit
Utilities related to art service access.
void analyze(art::Event const &e) override
art::InputTag fOpFlashModuleLabel2
vector< vector< double > > fPMTXYZT
art::InputTag fOpFlashModuleLabel1
Geometry information for a single TPC.
vector< double > fTrueDist
vector< vector< double > > fCrtXYZErr
art::InputTag fOpFlashModuleLabel3
art::InputTag fCrtHitModuleLabel
Geometry information for a single cryostat.
vector< vector< double > > fHitXYZT
const double LAR_PROP_DELAY
art::InputTag fOpFlashModuleLabel0
int AuxDetRegionNameToNum(string reg)
vector< double > fTrueTOF
vector< bool > fTrackFilt
vector< double > fFlashPE
vector< double > fDistFlash
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
vector< double > fTofFlashHit
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet'th optical detector in the cryostat.
vector< double > fTofPeFlash
map< int, art::InputTag > fFlashLabels
vector< double > fDistFlashHit
vector< double > fFlashMeanPE
bool HitCompare(const art::Ptr< CRTHit > &h1, const art::Ptr< CRTHit > &h2)
vector< vector< double > > fTofXYZTHit
art::InputTag fCrtTrackModuleLabel
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
vector< double > fTofFlash
Description of geometry of one entire detector.
vector< vector< double > > fCrtXYZT
vector< vector< double > > fEnterXYZT
vector< vector< double > > fTofXYZTFlashHit
vector< vector< double > > fFlashDelta
art::InputTag fOpHitModuleLabel
BEGIN_PROLOG opflashCryoW opflashCryoW triggerfilterBNB triggerfilterNuMI triggerfilterOffbeamBNB triggerfilterOffbeamNuMI triggerfilterUnknown roifinder roifinder2d gaushitTPCEE gaushitTPCWE purityana1 ophit
CrtOpHitMatchAnalysis(fhicl::ParameterSet const &p)
vector< vector< double > > fFlashXYZT
vector< double > fTofPeFlashHit
vector< double > fTofPeHit
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
static double tdiff(const art::Timestamp &ts1, const art::Timestamp &ts2)
int TrueIdFromTotalEnergy(const art::Event &event, const CRTData &data)
vector< bool > fMatchFlash
geo::GeometryCore const * fGeometryService
pointer to Geometry provider
art::ServiceHandle< art::TFileService > tfs
vector< double > fFlashRmsPE
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
vector< vector< double > > fTofXYZTFlash
bool ContainsPosition(geo::Point_t const &point, double wiggle=1.0) const
Returns whether this volume contains the specified point.
vector< int > fTofTpcFlash
art framework interface to geometry description
BEGIN_PROLOG could also be cout