17 #include "art/Framework/Core/EDProducer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "canvas/Persistency/Common/FindManyP.h"
20 #include "art/Framework/Principal/Handle.h"
21 #include "art/Framework/Principal/Event.h"
22 #include "canvas/Persistency/Common/Ptr.h"
23 #include "canvas/Persistency/Common/PtrVector.h"
24 #include "art/Framework/Principal/Run.h"
25 #include "art/Framework/Principal/SubRun.h"
26 #include "art_root_io/TFileService.h"
27 #include "art_root_io/TFileDirectory.h"
29 #include "canvas/Utilities/InputTag.h"
30 #include "fhiclcpp/ParameterSet.h"
31 #include "messagefacility/MessageLogger/MessageLogger.h"
83 void produce(art::Event &
e)
override;
135 std::map<std::string, TH1F*>
hDCA;
139 std::map<std::string, TH1F*>
hDoL;
143 std::map<std::string, TH1F*>
hT0;
150 : EDProducer(p), t0Alg(p.
get<fhicl::ParameterSet>(
"T0Alg"))
151 , fCrtutils(new icarus::
crt::CRTCommonUtils())
156 produces< std::vector<anab::T0> >();
157 produces< art::Assns<recob::Track , anab::T0> >();
158 produces< art::Assns<sbn::crt::CRTHit, anab::T0> >();
168 fTpcTrackModuleLabel = p.get< std::vector<art::InputTag>>(
"TpcTrackModuleLabel", {
"pandoraTrackGausCryoE"});
170 fPFParticleLabel = p.get< std::vector<art::InputTag> >(
"PFParticleLabel", {
""});
171 fTriggerLabel = p.get<art::InputTag>(
"TriggerLabel",
"daqTrigger");
178 art::ServiceHandle<art::TFileService>
tfs;
180 fTree = tfs->make<TTree>(
"matchTree",
"CRTHit - TPC track matching analysis");
186 fTree->Branch(
"DCA",
"std::vector<double>", &
fDCA);
187 fTree->Branch(
"DOL",
"std::vector<double>", &
fDOL);
188 fTree->Branch(
"t0",
"std::vector<double>", &
fT0);
189 fTree->Branch(
"tpcx",
"std::vector<double>", &
ftpcx);
190 fTree->Branch(
"tpcy",
"std::vector<double>", &
ftpcy);
191 fTree->Branch(
"tpcz",
"std::vector<double>", &
ftpcz);
192 fTree->Branch(
"crtx",
"std::vector<double>", &
fcrtx);
193 fTree->Branch(
"crty",
"std::vector<double>", &
fcrty);
194 fTree->Branch(
"crtz",
"std::vector<double>", &
fcrtz);
195 fTree->Branch(
"cryo",
"std::vector<int>", &
fcryo);
205 for(
int i = 30; i < 50 + 1; i++){
206 std::string
tagger =
"All";
207 if (i >= 35 && i < 40)
continue;
208 if (i==48 || i==49)
continue;
212 hDCA[tagger] = tfs->make<TH1F>(Form(
"DCA_%s", tagger.c_str()),
"", 50, 0, 100);
213 hDoL[tagger] = tfs->make<TH1F>(Form(
"DoL_%s", tagger.c_str()),
"", 100, 0, 0.25);
214 hT0[tagger] = tfs->make<TH1F>(Form(
"T0_%s", tagger.c_str()),
"", 600, -3000, 3000);
234 fEvent =
event.id().event();
239 std::unique_ptr< std::vector<anab::T0> > T0col(
new std::vector<anab::T0>);
240 std::unique_ptr< art::Assns<recob::Track, anab::T0> > Trackassn(
new art::Assns<recob::Track, anab::T0>);
241 std::unique_ptr< art::Assns <sbn::crt::CRTHit, anab::T0> > t0_crthit_assn(
new art::Assns<sbn::crt::CRTHit, anab::T0> );
246 art::Handle<sbn::ExtraTriggerInfo> trigger_handle;
248 if( trigger_handle.isValid() ) {
254 m_trigger_gate_diff = trigger_handle->triggerTimestamp - trigger_handle->beamGateTimestamp;
258 mf::LogError(
"CRTT0Matching:") <<
"No raw::Trigger associated to label: " <<
fTriggerLabel.label() <<
"\n" ;
262 mf::LogError(
"CRTT0Matching:") <<
"Trigger Data product " <<
fTriggerLabel.label() <<
" not found!\n" ;
266 art::Handle<std::vector<sbn::crt::CRTHit>> crtListHandle;
267 std::vector<art::Ptr<sbn::crt::CRTHit>> crtList;
269 art::fill_ptr_vector(crtList, crtListHandle);
271 std::vector<sbn::crt::CRTHit> crtHits;
272 for (
auto const& crtHit : crtList){
273 crtHits.push_back(*crtHit);
279 auto it = &trackLabel - fTpcTrackModuleLabel.data();
281 art::Handle< std::vector<recob::Track> > trackListHandle;
282 std::vector<art::Ptr<recob::Track> > trackList;
283 if (event.getByLabel(trackLabel,trackListHandle))
284 art::fill_ptr_vector(trackList, trackListHandle);
289 mf::LogInfo(
"CRTT0Matching")
290 <<
"Number of reconstructed tracks = "<<trackList.size()<<
"\n"
291 <<
"Number of CRT hits = "<<crtList.size();
293 fntracks.push_back(trackList.size());
295 auto pfpListHandle =
event.getValidHandle<std::vector<recob::PFParticle> >(
fPFParticleLabel[it]);
296 if (!pfpListHandle.isValid())
continue;
299 art::FindManyP<recob::PFParticle> fmpfp(trackListHandle, event, trackLabel);
302 art::FindManyP<anab::T0> fmt0pandora(pfpListHandle, event,
fPFParticleLabel[it]);
305 if (trackListHandle.isValid() && crtListHandle.isValid() ){
307 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event);
308 art::FindManyP<recob::Hit> findManyHits(trackListHandle, event, trackLabel);
311 for(
size_t track_i = 0; track_i < trackList.size(); track_i++) {
313 double t0 = -99999999;
316 auto pfps = fmpfp.at(trackList[track_i]->ID());
320 auto t0s = fmt0pandora.at(pfps[0].key());
327 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(trackList[track_i]->ID());
328 if (hits.size() == 0)
continue;
329 int const cryoNumber = hits[0]->WireID().Cryostat;
335 if(closest.
dca >=0 ){
336 mf::LogInfo(
"CRTT0Matching")
337 <<
"Matched time = "<<closest.
t0<<
" [us] to track "<<trackList[track_i]->ID()<<
" with DCA = "<<closest.
dca;
342 double sin_angle = -99999;
343 if(closest.
dca != -99999){
344 auto start = trackList[track_i]->Vertex<TVector3>();
353 fDOL.push_back(sin_angle);
354 fT0.push_back(closest.
t0);
355 fcryo.push_back(cryoNumber);
357 ftpcx.push_back(start.X());
358 ftpcy.push_back(start.Y());
359 ftpcz.push_back(start.Z());
368 unsigned CRThitIndex = std::numeric_limits<unsigned>::max();
369 for (
int ic=0; ic<(int)crtList.size(); ++ic){
374 if (CRThitIndex != std::numeric_limits<unsigned>::max()){
376 util::CreateAssn(*
this, event, *T0col, crtList[CRThitIndex], *t0_crthit_assn);
385 event.put(std::move(T0col));
386 event.put(std::move(Trackassn));
387 event.put(std::move(t0_crthit_assn));
vector< double > fpandorat0
Track T0 based on Pandora (Cathode Crossing Track)
std::map< std::string, TH1F * > hT0
Utilities related to art service access.
int fEvent
number of the event being processed
std::map< std::string, TH1F * > hDoL
std::vector< art::InputTag > fTpcTrackModuleLabel
name of track producer
int plane
Name of the CRT wall (in the form of numbers).
float peshit
Total photo-electron (PE) in a crt hit.
Declaration of signal hit object.
art::InputTag fCrtHitModuleLabel
name of crt producer
art::InputTag fTriggerLabel
labels for trigger
std::map< std::string, TH1F * > hMatchT0
uint64_t m_gate_start_timestamp
std::map< std::string, TH1F * > hNoMatchT0
int fRun
number of the run being processed
int AuxDetRegionNameToNum(string reg)
CRTT0Matching & operator=(CRTT0Matching const &)=delete
std::string bitName(triggerSource bit)
Returns a mnemonic short name of the beam type.
std::vector< art::InputTag > fPFParticleLabel
labels for source of PFParticle
float z_pos
position in z-direction (cm).
double ts0_ns
Timestamp T0 (from White Rabbit), in UTC absolute time scale in nanoseconds from the Epoch...
Access the description of detector geometry.
string GetRegionNameFromNum(int num)
std::map< std::string, TH1F * > hMatchDCA
icarus::crt::CRTCommonUtils * fCrtutils
void produce(art::Event &e) override
Description of geometry of one entire detector.
vector< int > fntracks
total number of tracks
Provides recob::Track data product.
uint64_t m_trigger_timestamp
Encapsulate the geometry of a wire.
CRTT0Matching(fhicl::ParameterSet const &p)
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.
float y_pos
position in y-direction (cm).
std::map< std::string, TH1F * > hNoMatchDCA
std::map< std::string, TH1F * > hNoMatchDoL
Encapsulate the construction of a single detector plane.
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection, uint64_t &trigger_timestamp)
float x_pos
position in x-direction (cm).
geo::GeometryCore const * fGeometryService
pointer to Geometry provider
vector< int > fcryo
cryo number
void reconfigure(fhicl::ParameterSet const &p)
uint64_t m_trigger_gate_diff
triggerSource
Type of beam or beam gate or other trigger source.
art::ServiceHandle< art::TFileService > tfs
std::map< std::string, TH1F * > hDCA
Collection of Physical constants used in LArSoft.
std::string tagger
Name of the CRT wall (in the form of strings).
std::map< std::string, TH1F * > hMatchDoL
art framework interface to geometry description
int fSubRun
number of the sub-run being processed