23 #include "art/Framework/Core/EDAnalyzer.h"
24 #include "art/Framework/Principal/Event.h"
25 #include "art/Framework/Principal/Handle.h"
26 #include "art/Framework/Services/Registry/ServiceHandle.h"
27 #include "art_root_io/TFileService.h"
28 #include "art/Framework/Core/ModuleMacros.h"
29 #include "canvas/Persistency/Common/FindManyP.h"
30 #include "canvas/Utilities/Exception.h"
33 #include "messagefacility/MessageLogger/MessageLogger.h"
34 #include "fhiclcpp/ParameterSet.h"
35 #include "fhiclcpp/types/Table.h"
36 #include "fhiclcpp/types/Atom.h"
37 #include "cetlib/pow.h"
43 #include "TLorentzVector.h"
45 #include "TGeoManager.h"
92 Comment(
"tag of the input data product with reconstructed CRT hits")
97 Comment(
"tag of the input data product with calibrated CRT data")
101 Name(
"TriggerLabel"),
102 Comment(
"Label for the Trigger fragment label")
107 Comment(
"Pedestal offset [ADC]")
111 Comment(
"Pedestal slope [ADC/photon]")
116 Comment(
"threshold in photoelectrons above which charge amplitudes used in hit reco")
121 Comment(
"window for looking data [ns]")
136 virtual void beginRun(
const art::Run& run)
override;
137 virtual void analyze (
const art::Event& event)
override;
158 static map<int, vector<pair<int,int>>>
fFebMap;
244 , fTriggerLabel( config().TriggerLabel() )
245 , fCRTHitProducerLabel(config().CRTHitLabel())
246 , fCRTDAQProducerLabel(config().CRTDAQLabel())
247 , fQPed(config().QPed())
248 , fQSlope(config().QSlope())
249 , fPEThresh(config().PEThresh())
250 , fCrtWindow(config().CrtWindow())
256 fChannelMap = art::ServiceHandle<icarusDB::IICARUSChannelMap const>{}.get();
259 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
267 std::string fullFileName;
268 cet::search_path searchPath(
"FW_SEARCH_PATH");
269 searchPath.find_file(
"feb_map.txt",fullFileName);
272 if(fin.good()) mf::LogError(
"CRTDataAnalysis") <<
"opened file 'feb_map.txt' for reading..." << std::endl;
274 throw cet::exception(
"CRTDataAnalysis::FillFebMap") <<
"Unable to find/open file 'feb_map.txt'" << std::endl;
275 std::vector<std::string>
row;
276 std::string line, word;
277 while(getline(fin,line)) {
279 std::stringstream
s(line);
281 while (std::getline(s, word,
',')) {
284 mod = std::stoi(row[0]);
285 (this->
fFebMap)[mod].push_back(std::make_pair(std::stoi(row[1]),std::stoi(row[2])));
287 (this->
fFebMap)[mod].push_back(std::make_pair(std::stoi(row[3]),std::stoi(row[4])));
297 mf::LogError(
"CRTDataAnalysis") <<
" starting analysis job" << std::endl;
301 art::ServiceHandle<art::TFileService>
tfs;
304 fDAQNtuple = tfs->make<TTree>(
"DAQTree",
"MyCRTDAQ");
305 fHitNtuple = tfs->make<TTree>(
"HitTree",
"MyCRTHit");
326 fHitNtuple->Branch(
"event", &
fHitEvent,
"event/I");
327 fHitNtuple->Branch(
"nHit", &
fNHit,
"nHit/I");
328 fHitNtuple->Branch(
"x", &
fXHit,
"x/F");
329 fHitNtuple->Branch(
"y", &
fYHit,
"y/F");
330 fHitNtuple->Branch(
"z", &
fZHit,
"z/F");
331 fHitNtuple->Branch(
"xErr", &
fXErrHit,
"xErr/F");
332 fHitNtuple->Branch(
"yErr", &
fYErrHit,
"yErr/F");
333 fHitNtuple->Branch(
"zErr", &
fZErrHit,
"zErr/F");
334 fHitNtuple->Branch(
"t0", &
fT0Hit,
"t0/l");
335 fHitNtuple->Branch(
"t1", &
fT1Hit,
"t1/L");
336 fHitNtuple->Branch(
"region", &
fHitReg,
"region/I");
338 fHitNtuple->Branch(
"subSys", &
fHitSubSys,
"subSys/I");
339 fHitNtuple->Branch(
"modID", &
fHitMod,
"modID/I");
340 fHitNtuple->Branch(
"stripID", &
fHitStrip,
"stripID/I");
341 fHitNtuple->Branch(
"nFeb", &
fNHitFeb,
"nFeb/I");
342 fHitNtuple->Branch(
"totPe", &
fHitTotPe,
"totPe/F");
343 fHitNtuple->Branch(
"gate_type", &
m_gate_type,
"gate_type/b");
348 fHitNtuple->Branch(
"gate_crt_diff",&
m_gate_crt_diff,
"gate_crt_diff/l");
358 MF_LOG_DEBUG(
"CRTDataAnalysis") <<
"beginning analyis" <<
'\n';
361 fEvent =
event.id().event();
370 art::Handle<sbn::ExtraTriggerInfo> trigger_handle;
372 if( trigger_handle.isValid() ) {
378 m_trigger_gate_diff = trigger_handle->triggerTimestamp - trigger_handle->beamGateTimestamp;
382 mf::LogError(
"CRTDataAnalysis") <<
"No raw::Trigger associated to label: " <<
fTriggerLabel.label() <<
"\n" ;
386 mf::LogError(
"CRTDataAnalysis") <<
"Trigger Data product " <<
fTriggerLabel.label() <<
" not found!\n" ;
389 art::Handle<vector<icarus::crt::CRTData>> crtDAQHandle;
390 vector<art::Ptr<icarus::crt::CRTData> > crtList;
392 art::fill_ptr_vector(crtList, crtDAQHandle);
394 vector<art::Ptr<icarus::crt::CRTData>> crtData;
397 for (
size_t febdat_i=0; febdat_i<crtList.size(); febdat_i++) {
399 uint8_t mac = crtList[febdat_i]->fMac5;
412 for(
int chan=0; chan<32; chan++) {
414 float pe = (crtList[febdat_i]->fAdc[chan]-chg_cal.second)/chg_cal.first;
422 if(pe<=
fPEThresh && !crtList[febdat_i]->IsReference_TS1())
continue;
425 }
else if ( type ==
'c' ) {
429 }
else if ( type ==
'd'){
430 for(
int chan=0; chan<64; chan++) {
431 float pe = (crtList[febdat_i]->fAdc[chan]-
fQPed)/
fQSlope;
437 if (presel) crtData.push_back(crtList[febdat_i]);
444 for (
size_t febdat_i=0; febdat_i<crtData.size(); febdat_i++) {
450 fMac5 = crtData[febdat_i]->fMac5;
451 fEntry = crtData[febdat_i]->fEntry;
455 fT0 = crtData[febdat_i]->fTs0;
456 fT1 = crtData[febdat_i]->fTs1;
457 fFlags = crtData[febdat_i]->fFlags;
462 for(
int ch=0; ch<maxchan; ch++) {
463 fADC[ch] = crtData[febdat_i]->fAdc[ch];
466 float pe = (
fADC[ch]-chg_cal.second)/chg_cal.first;
467 if (pe < 0)
continue;
471 if (pe < 0)
continue;
485 art::Handle<std::vector<sbn::crt::CRTHit>> crtHitHandle;
488 std::vector<int> ids;
492 mf::LogError(
"CRTDataAnalysis") <<
"looping over reco hits..." << std::endl;
493 for (
auto const&
hit : *crtHitHandle )
508 int mactmp =
hit.feb_id[0];
514 auto ittmp =
hit.pesmap.find(mactmp);
515 if (ittmp==
hit.pesmap.end()) {
516 mf::LogError(
"CRTDataAnalysis") <<
"hitreg: " <<
fHitReg << std::endl;
517 mf::LogError(
"CRTDataAnalysis") <<
"fHitSubSys: "<<
fHitSubSys << std::endl;
518 mf::LogError(
"CRTDataAnalysis") <<
"mactmp = " << mactmp << std::endl;
519 mf::LogError(
"CRTDataAnalysis") <<
"could not find mac in pesmap!" << std::endl;
522 int chantmp = (*ittmp).second[0].first;
531 else mf::LogError(
"CRTDataAnalysis") <<
"CRTHit products not found! (expected if decoder step)" << std::endl;
string MacToRegion(uint8_t mac)
CRTCommonUtils * fCrtutils
fhicl::Atom< double > QSlope
float fXHit
reconstructed X position of CRT hit (cm)
int fRun
number of the run being processed
then if[["$THISISATEST"==1]]
float fXErrHit
stat error of CRT hit reco X (cm)
Utilities related to art service access.
float fZErrHit
stat error of CRT hit reco Z (cm)
float fYErrHit
stat error of CRT hit reco Y (cm)
int fEntry
front-end board entry number (reset for each event)
static const int LAR_PROP_DELAY
vector< vector< int > > fTrackID
track ID(s) of particle that produced the signal
int fMac5
Mac5 address for this front-end board.
This provides an art tool interface definition for tools which "decode" artdaq fragments into LArSoft...
Declaration of signal hit object.
int fNHit
number of CRT hits for this event
size_t MacToAuxDetID(uint8_t mac, int chan)
double fQSlope
Pedestal slope of SiPMs [ADC/photon].
int fHitEvent
signal inducing particle(s)' PDG code
float fYHit
reconstructed Y position of CRT hit (cm)
virtual void analyze(const art::Event &event) override
virtual void beginRun(const art::Run &run) override
art::InputTag fCRTHitProducerLabel
The name of the producer that created hits.
int AuxDetRegionNameToNum(string reg)
uint64_t fT1
signal time w.r.t. global event time
uint64_t fCrtWindow
Looking data window within trigger timestamp [ns].
fhicl::Atom< double > QPed
int fHitReg
region code of CRT hit
std::string bitName(triggerSource bit)
Returns a mnemonic short name of the beam type.
Access the description of auxiliary detector geometry.
fhicl::Atom< art::InputTag > CRTHitLabel
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
geo::GeometryCore const * fGeometryService
pointer to Geometry provider
object containing MC truth information necessary for making RawDigits and doing back tracking ...
uint64_t fT0
signal time w.r.t. PPS
uint64_t m_trigger_gate_diff
fhicl::Atom< art::InputTag > TriggerLabel
virtual std::pair< double, double > getSideCRTCalibrationMap(int mac5, int chan) const =0
fhicl::Atom< double > PEThresh
double fPEThresh
threshold[PE] above which charge amplitudes used in hit reco
const icarusDB::IICARUSChannelMap * fChannelMap
BEGIN_PROLOG vertical distance to the surface Name
int fEvent
number of the event being processed
uint64_t fT0Hit
hit time w.r.t. PPS
Description of geometry of one entire detector.
Declaration of cluster object.
static map< int, vector< pair< int, int > > > fFebMap
uint64_t m_trigger_timestamp
Definition of data types for geometry description.
art::InputTag fTriggerLabel
char GetAuxDetType(size_t adid)
int fNChan
number of channels above threshold for this front-end board readout
float fZHit
reconstructed Z position of CRT hit (cm)
fhicl::Atom< art::InputTag > CRTDAQLabel
vector< vector< int > > fDetPDG
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
then echo File list $list not found else cat $list while read file do echo $file sed s
int MacToTypeCode(uint8_t mac)
int ChannelToAuxDetSensitiveID(uint8_t mac, int chan)
art::EDAnalyzer::Table< Config > Parameters
CRTDataAnalysis(Parameters const &config)
Constructor: configures the module (see the Config structure above)
int trigger_offset(DetectorClocksData const &data)
triggerSource
Type of beam or beam gate or other trigger source.
art::InputTag fCRTDAQProducerLabel
Long64_t fT1Hit
hit time w.r.t. global trigger
art::ServiceHandle< art::TFileService > tfs
uint64_t m_gate_start_timestamp
int fADC[64]
Max number of channel.
double fQPed
Pedestal offset of SiPMs [ADC].
float fPE[64]
signal amplitude
int fFEBReg
CRT region for this front-end board.
int fTriggerOffset
(units of ticks) time of expected neutrino event
art framework interface to geometry description
fhicl::Atom< uint64_t > CrtWindow
virtual void beginJob() override