10 #include "art/Framework/Core/EDAnalyzer.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 "fhiclcpp/types/Table.h"
19 #include "fhiclcpp/types/Atom.h"
20 #include "cetlib/pow.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
22 #include "art/Framework/Services/Registry/ServiceHandle.h"
23 #include "art_root_io/TFileService.h"
24 #include "canvas/Persistency/Common/FindManyP.h"
25 #include "canvas/Utilities/Exception.h"
38 #include "nusimdata/SimulationBase/MCParticle.h"
50 #include "canvas/Persistency/Common/FindMany.h"
51 #include "canvas/Persistency/Common/FindManyP.h"
52 #include "canvas/Persistency/Common/FindOne.h"
53 #include "canvas/Persistency/Common/FindOneP.h"
54 #include "canvas/Persistency/Common/Ptr.h"
55 #include "canvas/Persistency/Common/PtrVector.h"
72 class CRTTPCMatchingAna;
92 virtual void analyze(
const art::Event& event)
override;
95 virtual void endJob()
override;
139 std::map<std::string, TH1F*>
hDCA;
143 std::map<std::string, TH1F*>
hDoL;
147 std::map<std::string, TH1F*>
hT0;
156 , t0Alg(
p.get<fhicl::ParameterSet>(
"t0Alg"))
163 fGeometryService = lar::providerFrom<geo::Geometry>();
169 fCRTHitLabel = p.get<art::InputTag> (
"CRTHitLabel",
"crthit");
170 fTPCTrackLabel = p.get< std::vector<art::InputTag> >(
"TPCTrackLabel", {
""});
171 fPFParticleLabel = p.get< std::vector<art::InputTag> >(
"PFParticleLabel", {
""});
172 fTriggerLabel = p.get<art::InputTag>(
"TriggerLabel",
"daqTrigger");
174 fVerbose = p.get<
bool>(
"Verbose");
181 art::ServiceHandle<art::TFileService>
tfs;
183 fTree = tfs->make<TTree>(
"matchTree",
"CRTHit - TPC track matching analysis");
185 fTree->Branch(
"Event", &fEvent,
"Event/I");
186 fTree->Branch(
"SubRun", &fSubRun,
"SubRun/I");
187 fTree->Branch(
"Run", &fRun,
"Run/I");
188 fTree->Branch(
"cryo",
"std::vector<int>", &fcryo);
189 fTree->Branch(
"pandorat0",
"std::vector<double>", &fpandorat0);
190 fTree->Branch(
"crtRegion",
"std::vector<int>",&fCrtRegion);
191 fTree->Branch(
"DCA",
"std::vector<double>", &fDCA);
192 fTree->Branch(
"DOL",
"std::vector<double>", &fDOL);
193 fTree->Branch(
"t0",
"std::vector<double>", &
fT0);
194 fTree->Branch(
"gate_type", &m_gate_type,
"gate_type/b");
195 fTree->Branch(
"gate_name", &m_gate_name);
196 fTree->Branch(
"trigger_timestamp", &m_trigger_timestamp,
"trigger_timestamp/l");
197 fTree->Branch(
"gate_start_timestamp", &m_gate_start_timestamp,
"gate_start_timestamp/l");
198 fTree->Branch(
"trigger_gate_diff", &m_trigger_gate_diff,
"trigger_gate_diff/l");
199 fTree->Branch(
"gate_crt_diff", &m_gate_crt_diff,
"gate_crt_diff/l");
202 for(
int i = 30; i < 50 + 1; i++){
203 std::string
tagger =
"All";
204 if (i >= 35 && i < 40)
continue;
205 if (i==48 || i==49)
continue;
207 tagger = fCrtutils->GetRegionNameFromNum(i);
209 hDCA[tagger] = tfs->make<TH1F>(Form(
"DCA_%s", tagger.c_str()),
"", 50, 0, 100);
210 hDoL[tagger] = tfs->make<TH1F>(Form(
"DoL_%s", tagger.c_str()),
"", 100, 0, 0.25);
211 hT0[tagger] = tfs->make<TH1F>(Form(
"T0_%s", tagger.c_str()),
"", 600, -3000, 3000);
227 std::cout<<
"============================================"<<std::endl
228 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
229 <<
"============================================"<<std::endl;
232 fEvent =
event.id().event();
234 fSubRun =
event.subRun();
240 if( !fTriggerLabel.empty() ) {
242 art::Handle<sbn::ExtraTriggerInfo> trigger_handle;
243 event.getByLabel( fTriggerLabel, trigger_handle );
244 if( trigger_handle.isValid() ) {
246 m_gate_type = (
unsigned int)bit;
248 m_trigger_timestamp = trigger_handle->triggerTimestamp;
249 m_gate_start_timestamp = trigger_handle->beamGateTimestamp;
250 m_trigger_gate_diff = trigger_handle->triggerTimestamp - trigger_handle->beamGateTimestamp;
253 mf::LogError(
"CRTTPCMatchingAna:") <<
"No raw::Trigger associated to label: " << fTriggerLabel.label() <<
"\n" ;
257 mf::LogError(
"CRTTPCMatchingAna:") <<
"Trigger Data product " << fTriggerLabel.label() <<
" not found!\n" ;
262 art::Handle< std::vector<sbn::crt::CRTHit>> crtHitHandle;
263 std::vector<art::Ptr<sbn::crt::CRTHit> > crtHitList;
264 if (event.getByLabel(fCRTHitLabel, crtHitHandle))
265 art::fill_ptr_vector(crtHitList, crtHitHandle);
271 std::vector<sbn::crt::CRTHit> crtHits;
273 double minHitTime = 99999;
274 double maxHitTime = -99999;
276 for(
auto const&
hit : (*crtHitHandle)){
277 double hitTime = double(
hit.ts0_ns - (m_gate_start_timestamp%1
'000'000
'000))/1e3;
279 if(hitTime<-0.5e6) hitTime+=1e6;
280 else if(hitTime>0.5e6) hitTime-=1e6;
284 if(hitTime < minHitTime) minHitTime = hitTime;
285 if(hitTime > maxHitTime) maxHitTime = hitTime;
287 crtHits.push_back(
hit);
291 mf::LogError(
"CRTTPCMatchingAna:") <<
"# of TPC tracks: " << fTPCTrackLabel.size()
292 <<
" \t # of CRT Hits: " << crtHits.size() <<
"\n" ;
298 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
299 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
304 for(
const auto& trackLabel : fTPCTrackLabel)
306 auto it = &trackLabel - fTPCTrackLabel.data();
310 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(trackLabel);
311 if (!tpcTrackHandle.isValid())
continue;
314 auto pfpListHandle =
event.getValidHandle<std::vector<recob::PFParticle> >(fPFParticleLabel[it]);
315 if (!pfpListHandle.isValid())
continue;
321 art::FindManyP<recob::PFParticle> fmpfp(tpcTrackHandle, event, trackLabel);
324 art::FindManyP<anab::T0> fmt0pandora(pfpListHandle, event, fPFParticleLabel[it]);
327 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event, trackLabel);
330 for (
auto const& tpcTrack : (*tpcTrackHandle)){
331 auto idx = &tpcTrack - (*tpcTrackHandle).data();
333 double t0 = -9999999;
336 auto pfps = fmpfp.at(tpcTrack.ID());
340 auto t0s = fmt0pandora.at(pfps[0].key());
351 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
352 if (hits.size() == 0)
continue;
356 int const cryoNumber = hits[0]->WireID().Cryostat;
364 matchCand closest = t0Alg.GetClosestCRTHit(
detProp, tpcTrack, hits, crtHits, m_trigger_timestamp);
366 mf::LogInfo(
"CRTTPCMatchingAna")
367 <<
"Track # " << idx <<
" Matched time = "<<closest.
t0<<
" [us] to track "<< tpcTrack.ID()<<
" with DCA = "<<closest.
dca
374 double sin_angle = -99999;
375 if(closest.
dca != -99999){
382 fDCA.push_back(closest.
dca);
383 fDOL.push_back(sin_angle);
384 fT0.push_back(closest.
t0);
385 fcryo.push_back(cryoNumber);
386 fpandorat0.push_back(t0);
388 fCrtRegion.push_back(fCrtutils->AuxDetRegionNameToNum(closest.
thishit.
tagger));
virtual void endJob() override
std::map< std::string, TH1F * > hNoMatchDCA
Functions to help with numbers.
int fEvent
number of the event being processed
Utilities related to art service access.
CRTTPCMatchingAna(fhicl::ParameterSet const &p)
std::vector< art::InputTag > fPFParticleLabel
labels for source of PFParticle
Declaration of signal hit object.
std::map< std::string, TH1F * > hMatchDoL
int fSubRun
number of the sub-run being processed
std::map< std::string, TH1F * > hMatchT0
int fRun
number of the run being processed
geo::GeometryCore const * fGeometryService
pointer to Geometry provider
std::vector< art::InputTag > fTPCTrackLabel
labels for source of tracks
vector< int > fCrtRegion
CRT hit region code.
std::map< std::string, TH1F * > hT0
std::map< std::string, TH1F * > hNoMatchDoL
std::string bitName(triggerSource bit)
Returns a mnemonic short name of the beam type.
vector< double > fDCA
Distance of closest approach between CRT hit and extended TPC track.
vector< double > fpandorat0
Track T0 based on Pandora (Cathode Crossing Track)
virtual void beginJob() override
std::map< std::string, TH1F * > hDoL
virtual void analyze(const art::Event &event) override
uint64_t m_trigger_timestamp
vector< int > fcryo
cryo number
std::map< std::string, TH1F * > hMatchDCA
Description of geometry of one entire detector.
Definition of data types for geometry description.
Provides recob::Track data product.
CRTTPCMatchingAna & operator=(CRTTPCMatchingAna const &)=delete
vector< double > fT0
Track T0 based on CRT hit and extended TPC Track match.
icarus::crt::CRTCommonUtils * fCrtutils
bool fVerbose
print information about what's going on
object containing MC truth information necessary for making RawDigits and doing back tracking ...
uint64_t m_trigger_gate_diff
uint64_t m_gate_start_timestamp
triggerSource
Type of beam or beam gate or other trigger source.
void reconfigure(fhicl::ParameterSet const &p)
art::ServiceHandle< art::TFileService > tfs
art::InputTag fCRTHitLabel
name of CRT producer
std::map< std::string, TH1F * > hNoMatchT0
std::string tagger
Name of the CRT wall (in the form of strings).
std::map< std::string, TH1F * > hDCA
BEGIN_PROLOG could also be cout
double DistToCrtHit(TVector3 trackPos, sbn::crt::CRTHit crtHit)
art::InputTag fTriggerLabel
labels for trigger