10 #include "art_root_io/TFileService.h" 30 #include "artdaq-core/Data/Fragment.hh" 31 #include "lbne-raw-data/Services/ChannelMap/ChannelMapService.h" 71 struct LoadedWaveforms {
73 LoadedWaveforms() : waveforms() {}
74 vector<OpDetWaveform> waveforms;
76 void load( vector<OpDetWaveform>
const & v,
int fDebugLevel ) {
82 if (waveforms.size() == 0)
return true;
87 void clear(
int fDebugLevel) {
88 if (fDebugLevel > 3) std::cout <<
"Clearing LoadedWaveforms." <<
std::endl;
93 std::vector<OpDetWaveform> TakeAll() {
97 void findinrange(std::vector<OpDetWaveform> &wbo,
98 lbne::TpcNanoSlice::Header::nova_timestamp_t first_timestamp,
99 lbne::TpcNanoSlice::Header::nova_timestamp_t last_timestamp,
100 lbne::TpcNanoSlice::Header::nova_timestamp_t event_timestamp,
101 double NovaTicksPerSSPTick,
104 for (
auto wf : waveforms) {
105 lbne::TpcNanoSlice::Header::nova_timestamp_t WaveformTimestamp = wf.TimeStamp() * NovaTicksPerSSPTick;
106 if ( hh < 5 && fDebugLevel > 2) {
107 std::cout <<
"Looking at waveform number " << hh <<
". It was on channel " << wf.ChannelNumber() <<
" at time " << WaveformTimestamp
108 <<
". The times I passed were " << first_timestamp <<
" and " << last_timestamp
111 if (WaveformTimestamp <= last_timestamp && WaveformTimestamp >= first_timestamp) {
112 lbne::TpcNanoSlice::Header::nova_timestamp_t NewNovaTime = WaveformTimestamp - event_timestamp;
113 double NewTime = NewNovaTime / NovaTicksPerSSPTick;
116 std::cout <<
"Pushing back waveform " << hh <<
" on channel " << odw.
ChannelNumber() <<
" at time " << odw.TimeStamp() <<
" ("<< odw.TimeStamp()*NovaTicksPerSSPTick <<
")" <<
std::endl;
117 for (
size_t WaveSize = 0; WaveSize < wf.size(); ++WaveSize ) {
118 odw.emplace_back(wf[WaveSize]);
124 if (fDebugLevel > 1) std::cout <<
"At the end of Waveform findinrange, wbo has size " << wbo.size() <<
std::endl;
128 bool PhotonTrigger(lbne::TpcNanoSlice::Header::nova_timestamp_t this_timestamp,
double fWaveformADCThreshold,
int fWaveformADCsOverThreshold,
129 double fWaveformADCWidth,
double NovaTicksPerSSPTick,
int fDebugLevel,
bool CheatTrigger ) {
130 int HighADCWaveforms = 0;
132 double SumWaveforms = 0;
139 for (
auto wf : waveforms) {
140 lbne::TpcNanoSlice::Header::nova_timestamp_t WaveformTimestamp = wf.TimeStamp() * NovaTicksPerSSPTick;
141 lbne::TpcNanoSlice::Header::nova_timestamp_t StartTimestamp = WaveformTimestamp - ( fWaveformADCWidth * NovaTicksPerSSPTick * 0.5);
142 lbne::TpcNanoSlice::Header::nova_timestamp_t EndTimestamp = WaveformTimestamp + ( fWaveformADCWidth * NovaTicksPerSSPTick * 0.5);
143 if (this_timestamp <= EndTimestamp && this_timestamp >= StartTimestamp) {
144 for (
int ii=0;ii<(
int)wf.size();++ii) {
145 if ((
int)wf.Waveform()[ii] > fWaveformADCThreshold) {
148 SumWaveforms += (
int)wf.Waveform()[ii];
149 if ( wf.Waveform()[ii] < Lowest ) Lowest = wf.Waveform()[ii];
150 if ( wf.Waveform()[ii] > Biggest) Biggest= wf.Waveform()[ii];
151 if ( wf.Waveform()[ii] > 1550 ) ++More1550;
152 if ( wf.Waveform()[ii] > 1750 ) ++More1750;
153 if ( wf.Waveform()[ii] > 2000 ) ++More2000;
159 if (fDebugLevel > 3) {
160 std::cout <<
"Lowest " << Lowest <<
", Biggest " << Biggest <<
", Average " << SumWaveforms / ADCs
161 <<
", Total " << ADCs <<
", More1550 " << More1550 <<
", More1750 " << More1750 <<
", More2000 " << More2000
164 if ( HighADCWaveforms > fWaveformADCsOverThreshold )
return true;
170 struct LoadedOpHits {
172 LoadedOpHits() : ophits() {}
173 vector<recob::OpHit> ophits;
175 void load( vector<recob::OpHit>
const & v,
int fDebugLevel ) {
181 if (ophits.size() == 0)
return true;
186 void clear(
int fDebugLevel) {
187 if (fDebugLevel > 3) std::cout <<
"Clearing LoadedOphits." <<
std::endl;
192 std::vector<recob::OpHit> TakeAll() {
196 void findinrange(std::vector<recob::OpHit> &obo,
197 lbne::TpcNanoSlice::Header::nova_timestamp_t first_timestamp,
198 lbne::TpcNanoSlice::Header::nova_timestamp_t last_timestamp,
199 lbne::TpcNanoSlice::Header::nova_timestamp_t event_timestamp,
200 double NovaTicksPerSSPTick,
203 for (
auto wf : ophits) {
204 lbne::TpcNanoSlice::Header::nova_timestamp_t HitTimestamp = wf.PeakTime() * NovaTicksPerSSPTick;
205 if ( hh < 5 && fDebugLevel > 2) {
206 std::cout <<
"Looking at waveform number " << hh <<
". It was on channel " << wf.OpChannel() <<
" at time " << HitTimestamp
207 <<
". The times I passed were " << first_timestamp <<
" and " << last_timestamp
210 if (HitTimestamp <= last_timestamp && HitTimestamp >= first_timestamp) {
211 double NewTime = wf.PeakTime() - (event_timestamp/NovaTicksPerSSPTick);
212 double NewAbsTime = wf.PeakTimeAbs() - (event_timestamp/NovaTicksPerSSPTick);
213 recob::OpHit newHit( wf.OpChannel(), NewTime, NewAbsTime, wf.Frame(), wf.Width(), wf.Area(), wf.Amplitude(), wf.PE(), wf.FastToTotal() );
217 std::cout <<
"Pushing back waveform " << hh <<
" on channel " << wf.OpChannel() <<
" at corrected time " << NewTime <<
"("<<HitTimestamp
218 <<
"). The times I passed were " << first_timestamp <<
" and " << last_timestamp <<
", event_timestamp " << event_timestamp <<
std::endl;
222 if (fDebugLevel > 1) std::cout <<
"At the end of OpHit findinrange, obo has size " << obo.size() <<
std::endl;
226 bool OpHitTrigger(lbne::TpcNanoSlice::Header::nova_timestamp_t this_timestamp,
double fOpHitADCThreshold,
int fOpHitADCsOverThreshold,
227 double fOpHitADCWidth,
double NovaTicksPerSSPTick,
int fDebugLevel ) {
230 for (
auto wf : ophits) {
231 std::cout <<
"Looping through ophits, looking at element " << hh <<
". It is channel " << wf.OpChannel() <<
" at time " << wf.PeakTime()
232 <<
", it has Amplitude " << wf.Amplitude() <<
" and " << wf.PE() <<
" PE's." <<
std::endl;
234 if ( wf.Amplitude() > fOpHitADCThreshold ) ++HighADCHits;
236 if ( HighADCHits > fOpHitADCsOverThreshold )
return true;
242 struct LoadedDigits {
244 LoadedDigits() : digits(),
index(), firstTimestamp(0) {}
246 vector<RawDigit> digits;
248 lbne::TpcNanoSlice::Header::nova_timestamp_t firstTimestamp;
250 void loadTimestamp(lbne::TpcNanoSlice::Header::nova_timestamp_t ts) {
255 void clear(
int fDebugLevel) {
256 if (fDebugLevel > 3) std::cout <<
"Clearing LoadedDigits." <<
std::endl;
261 unsigned int size() {
262 return digits.size();
266 void load( vector<RawDigit>
const & v,
int fDebugLevel ) {
267 if (v.size() == 0 || v.back().Compression() ==
raw::kNone) {
269 if (fDebugLevel > 1) std::cout <<
"RCE information is not compressed." <<
std::endl;
272 if (fDebugLevel > 1) std::cout <<
"RCE information is compressed." <<
std::endl;
275 digits = std::vector<RawDigit>();
276 for (
auto idigit = v.begin(); idigit != v.end(); ++idigit) {
277 std::vector<short> uncompressed;
278 int pedestal = (
int)idigit->GetPedestal();
282 idigit->Compression()
288 digit.
SetPedestal( idigit->GetPedestal(), idigit->GetSigma() );
289 if (fDebugLevel > 3) std::cout <<
"Setting defualt pedestal values on channel " << digit.Channel() <<
" to " << digit.GetPedestal() <<
" and sigma " << digit.GetSigma() <<
std::endl;
290 digits.push_back(digit);
294 for (
unsigned int j=0; j<digits.size(); j=j+128) {
295 if ( digits[0].NADC() - digits[j].NADC() ) GoodDig =
false;
297 std::cout <<
"digits[0] has " << digits[0].NADC() <<
" ADC's, whilst digits["<<j<<
"] has " << digits[j].NADC() <<
" ADCs. Still a good digit? " << GoodDig <<
std::endl;
300 if (fDebugLevel) std::cout <<
"Got a bad digit, so want to clear it...\n" <<
std::endl;
307 bool empty(
int fDebugLevel)
const {
308 if (digits.size() == 0) {
309 if (fDebugLevel > 3) std::cout <<
"digits.size is 0" <<
std::endl;
312 if (digits[0].Samples() == 0) {
313 if (fDebugLevel > 3) std::cout <<
"digits[0].samples is 0" <<
std::endl;
316 if (index >= digits[0].Samples()) {
317 if (fDebugLevel > 3) std::cout <<
"The index is more than the number of samples" <<
std::endl;
323 RawDigit::ADCvector_t next() {
325 RawDigit::ADCvector_t digitsatindex;
326 for (
size_t ichan=0; ichan<digits.size(); ichan++) {
327 digitsatindex.push_back(digits[ichan].ADC(index-1));
329 return digitsatindex;
332 lbne::TpcNanoSlice::Header::nova_timestamp_t getTimeStampAtIndex(
size_t index_local,
double novatickspertpctick)
334 return firstTimestamp + index_local*novatickspertpctick;
339 struct LoadedCounters {
341 LoadedCounters() : counters(),
index() {}
343 vector<ExternalTrigger> counters;
346 void load( vector<ExternalTrigger>
const & v,
int fDebugLevel ) {
353 counters = std::vector<ExternalTrigger>();
355 for (
auto icounter = v.begin(); icounter != v.end(); ++icounter) {
356 std::vector<short> uncompressed;
358 icounter->GetTrigTime() );
368 if (counters.size() == 0)
return true;
372 lbne::TpcNanoSlice::Header::nova_timestamp_t ConvCounterTick(lbne::TpcNanoSlice::Header::nova_timestamp_t TrigTime,
double novatickspercounttick) {
373 return TrigTime*novatickspercounttick;
376 std::vector<ExternalTrigger> TakeAll() {
380 void clear(
int fDebugLevel) {
381 if (fDebugLevel > 3) std::cout <<
"Clearing LoadedCounters." <<
std::endl;
386 void findinrange(std::vector<ExternalTrigger> &cbo,
387 lbne::TpcNanoSlice::Header::nova_timestamp_t first_timestamp,
388 lbne::TpcNanoSlice::Header::nova_timestamp_t last_timestamp,
389 lbne::TpcNanoSlice::Header::nova_timestamp_t event_timestamp,
390 unsigned int novatickspercounttick,
393 for (
auto count : counters) {
394 lbne::TpcNanoSlice::Header::nova_timestamp_t TimeStamp = ConvCounterTick(count.GetTrigTime(), novatickspercounttick);
395 if ( hh < 5 && fDebugLevel > 2) {
396 std::cout <<
"Looking at muon counter " << hh <<
" It has ID " << count.GetTrigID() <<
" and time " << TimeStamp <<
"." 397 <<
" The times I passed were " << first_timestamp <<
" and " << last_timestamp <<
std::endl;
399 if (TimeStamp <= last_timestamp && TimeStamp >= first_timestamp) {
400 lbne::TpcNanoSlice::Header::nova_timestamp_t NewTime = TimeStamp - (event_timestamp/novatickspercounttick);
403 if (fDebugLevel > 3 )
404 std::cout <<
"Pushing back counter, channel " << ET.GetTrigID() <<
"(" << count.GetTrigID() <<
") and corrected time " << ET.GetTrigTime() <<
" (" << count.GetTrigTime() <<
")" <<
std::endl;
409 if (fDebugLevel > 1) std::cout <<
"At the end of Counter findinrange, cbo has size " << cbo.size() <<
std::endl;
413 bool PTBTrigger(lbne::TpcNanoSlice::Header::nova_timestamp_t this_timestamp,
double NovaTicksPerCountTick,
double NovaTicksPerTPCTick,
int fDebugLevel, std::vector<unsigned int> SpecialChan,
bool CheatTrigger ) {
414 for (
auto count : counters ) {
415 for (
size_t ChanLoop = 0; ChanLoop < SpecialChan.size(); ++ChanLoop) {
416 if ( SpecialChan[ChanLoop] == count.GetTrigID() ) {
417 if (CheatTrigger)
return true;
418 lbne::TpcNanoSlice::Header::nova_timestamp_t EffecTimeStamp = ConvCounterTick( count.GetTrigTime(), NovaTicksPerCountTick );
419 if ( EffecTimeStamp > this_timestamp
420 && EffecTimeStamp < (this_timestamp+NovaTicksPerTPCTick)
423 std::cout <<
"Triggering on Counter " << count.GetTrigID() <<
", " << EffecTimeStamp <<
", TPC tick " << this_timestamp <<
std::endl;
436 MonteCarlo() : MCParts() {}
438 vector<simb::MCParticle> MCParts;
439 vector<sim::SimChannel> SimChans;
443 void loadMCParts( vector<simb::MCParticle>
const & v ) {
447 void loadSimChans( vector<sim::SimChannel>
const &
b ) {
451 vector<simb::MCParticle> TakeMCParts(lbne::TpcNanoSlice::Header::nova_timestamp_t event_timestamp,
double fNanoSecondsPerNovaTick,
int fDebugLevel) {
452 vector<simb::MCParticle> retParts;
454 unsigned short TimeCorrec = ( event_timestamp / (2*fNanoSecondsPerNovaTick) ) - 1;
456 std::cout <<
"\n\nIn TakeMCParts....MCParts has size " << MCParts.size() <<
", event timestamp is " << event_timestamp <<
" meaning the time correction is " << TimeCorrec <<
std::endl;
458 for (
auto part: MCParts) {
460 newPart.
SetGvtx( part.GetGvtx() );
465 for (
size_t qq=0; qq < part.NumberTrajectoryPoints(); ++qq) {
466 const TLorentzVector
pos = TLorentzVector( part.Vx(qq), part.Vy(qq), part.Vz(qq), part.T(qq) - TimeCorrec );
467 const TLorentzVector mom = TLorentzVector( part.Px(qq), part.Py(qq), part.Pz(qq), part.E(qq) );
470 std::cout <<
"New Traj point...\nNew part is;" 471 << newPart.
Vx(qq) <<
" " << newPart.
Vy(qq) <<
" " << newPart.
Vz(qq) <<
" " << newPart.
T(qq) <<
" " 472 << newPart.
Px(qq) <<
" " << newPart.
Py(qq) <<
" " << newPart.
Pz(qq) <<
" " << newPart.
T(qq) <<
" " << newPart.
P(qq) <<
" " << newPart.
Pt(qq) <<
" " << newPart.
E(qq)
474 << part.Vx(qq) <<
" " << part.Vy(qq) <<
" " << part.Vz(qq) <<
" " << part.T(qq) <<
" " 475 << part.Px(qq) <<
" " << part.Py(qq) <<
" " << part.Pz(qq) <<
" " << part.T(qq) <<
" " << part.P(qq) <<
" " << part.Pt(qq) <<
" " << part.E(qq)
478 for (
int dd=0; dd<part.NumberDaughters(); ++dd)
480 retParts.emplace_back(newPart);
482 std::cout <<
"Made a new MCParticle" 484 <<
", time " << newPart.
T() <<
" " << part.T()
485 <<
", TrackID " << newPart.
TrackId() <<
" " << part.TrackId()
486 <<
", Energy " << newPart.
E() <<
" " << part.E()
487 <<
", NDaughters " << newPart.
NumberDaughters() <<
" " << part.NumberDaughters()
492 if (fDebugLevel > 1) std::cout <<
"At the end of TakeMCParts I am returning a vector of MCParticles with size " << retParts.size() <<
std::endl;
496 vector<sim::SimChannel> TakeSimChans(lbne::TpcNanoSlice::Header::nova_timestamp_t event_timestamp,
double fNovaTicksPerTPCTick,
int fDebugLevel) {
497 vector<sim::SimChannel> retSimChans;
499 unsigned short TimeCorrec = ( event_timestamp / fNovaTicksPerTPCTick ) - 1;
501 std::cout <<
"\n\nIn TakeSimChans....SimChans has size " << MCParts.size() <<
", event timestamp is " << event_timestamp <<
" meaning the time correction is " << TimeCorrec <<
std::endl;
503 for (
auto LoopSimChan: SimChans) {
505 for (
auto const& ideMap : LoopSimChan.TDCIDEMap()) {
506 unsigned short NewTime = ideMap.first - TimeCorrec;
507 for (
auto const& ide : ideMap.second) {
508 double IDEPos[3] = { ide.x, ide.y, ide.z };
513 retSimChans.emplace_back(newSimChan);
515 std::cout <<
"Added a newSimChan with size " << newSimChan.
TDCIDEMap().size() <<
", " << LoopSimChan.TDCIDEMap().size()
516 <<
". Channel " << newSimChan.
Channel() <<
", " << LoopSimChan.Channel()
517 <<
". Charge on tdc(0) " << newSimChan.
Charge(0) <<
", " << LoopSimChan.Charge(0)
518 <<
". Energy on tdc(0) " << newSimChan.
Energy(0) <<
", " << LoopSimChan.Energy(0)
519 <<
". TrackIDEs(-10000,100000) " << newSimChan.
TrackIDEs(0,100000).size() <<
" " << LoopSimChan.TrackIDEs(0,100000).size()
523 if (fDebugLevel > 1) std::cout <<
"At the end of TakeSimChans I am returning a vector of SimChannels with size " << retSimChans.size() <<
std::endl;
529 const char* getBranchName(
art::InputTag const &
tag,
const string inputDataProduct ) {
530 std::ostringstream pat_s;
531 pat_s << inputDataProduct <<
"s" 540 return pat_s.str().data();
544 getFragments( TBranch* br,
unsigned entry ) {
545 br->GetEntry( entry );
546 return reinterpret_cast<artdaq::Fragments*
>( br->GetAddress() );
549 vector<raw::RawDigit>*
550 getRawDigits( TBranch* br,
unsigned entry ) {
551 br->GetEntry( entry );
552 return reinterpret_cast<vector<raw::RawDigit>*
>( br->GetAddress() );
555 vector<raw::OpDetWaveform>*
556 getSSPWaveforms( TBranch* br,
unsigned entry ) {
557 br->GetEntry( entry );
558 return reinterpret_cast<vector<raw::OpDetWaveform>*
>( br->GetAddress() );
561 vector<recob::OpHit>*
562 getOpHits( TBranch* br,
unsigned entry ) {
563 br->GetEntry( entry );
564 return reinterpret_cast<vector<recob::OpHit>*
>( br->GetAddress() );
567 vector<raw::ExternalTrigger>*
568 getRawExternalTriggers( TBranch* br,
unsigned entry ) {
569 br->GetEntry( entry );
570 return reinterpret_cast<vector<raw::ExternalTrigger>*
>( br->GetAddress() );
573 vector<simb::MCParticle>* getMCParticles(TBranch* br,
unsigned entry) {
574 br->GetEntry( entry );
575 return reinterpret_cast<vector<simb::MCParticle>*
>(br->GetAddress() );
578 vector<simb::MCTruth>* getMCTruths(TBranch* br,
unsigned entry) {
579 br->GetEntry( entry );
580 return reinterpret_cast<vector<simb::MCTruth>*
>(br->GetAddress() );
583 vector<sim::SimChannel>* getMCSimChans(TBranch* br,
unsigned entry) {
584 br->GetEntry( entry );
585 return reinterpret_cast<vector<sim::SimChannel>*
>(br->GetAddress() );
622 void closeCurrentFile();
685 std::vector<RawDigit::ADCvector_t>
dbuf_;
693 unsigned int fChansPresent = 0;
695 bool fTrigger =
false;
696 bool fCheatPTBTrig =
false;
697 bool fCheatSSPTrig =
false;
698 size_t fLastTriggerIndex = 0;
699 size_t fLastEventIndex = 0;
700 size_t fLastEvent = 0;
701 int fDiffFromLastTrig = 0;
702 lbne::TpcNanoSlice::Header::nova_timestamp_t fLastTimeStamp = 0;
703 lbne::TpcNanoSlice::Header::nova_timestamp_t first_timestamp=0;
704 lbne::TpcNanoSlice::Header::nova_timestamp_t Event_timestamp=0;
705 lbne::TpcNanoSlice::Header::nova_timestamp_t last_timestamp=0;
706 lbne::TpcNanoSlice::Header::nova_timestamp_t this_timestamp=0;
707 lbne::TpcNanoSlice::Header::nova_timestamp_t prev_timestamp=0;
723 std::vector<std::pair< std::pair<unsigned int,unsigned int>, lbne::TpcNanoSlice::Header::nova_timestamp_t > > &,
724 lbne::TpcNanoSlice::Header::nova_timestamp_t&,
729 bool loadEvents_(
size_t &InputTree );
730 bool LoadPTBInformation(
size_t LoadTree );
731 void LoadSSPInformation(
size_t LoadTree );
732 void LoadRCEInformation(
size_t LoadTree );
738 void CheckTimestamps(
bool &JumpEvent,
size_t &JumpNADC );
742 void Triggering(std::map<int,int> &PrevChanADC, std::vector<short> ADCdigits,
bool NewTree);
746 bool TicklerTrigger( std::map<int,int> &PrevChanADC, std::vector<short> ADCdigits );
784 bool RCEsPresent =
true;
785 int gSkippedOuputEvents = 0;
786 std::vector<std::pair<std::pair<unsigned int,unsigned int>, lbne::TpcNanoSlice::Header::nova_timestamp_t > >
DigitsIndexList;
788 std::map<uint16_t, std::map <size_t, std::pair<float,float> > >
AllPedMap;
797 sourceName_(
"SplitterInput"),
842 std::placeholders::_1,
843 std::placeholders::_2,
844 std::placeholders::_3,
845 std::placeholders::_4,
846 ps.get<
bool>(
"UseRCEChanMap",
true),
847 ps.get<
bool>(
"debug",
false),
849 ps.get<
unsigned>(
"zeroThreshold",0) ) ),
865 fPTBTrigs (
ps.get<std::vector<unsigned int> >(
"PTBTrigs")),
905 file_.reset(
new TFile(filename.data()) );
924 if (
fDebugLevel) std::cout <<
"There is data on the Sparsified branch, so using that." <<
std::endl;
929 size_t nevt_penn = 0;
932 if (nevt_ssp !=
nInputEvts_&& nevt_ssp)
throw cet::exception(
"35-ton SplitterInput: Different numbers of RCE and SSP input events in file");
933 if (nevt_penn !=
nInputEvts_&& nevt_penn)
throw cet::exception(
"35-ton SplitterInput: Different numbers of RCE and Penn input events in file");
952 IntRunNumber = (
int)TreeRunNumber; TreeSubRunNumber =
evAux_.
subRun(); IntSubRunNumber = (
int)TreeSubRunNumber;
953 TreeEventNumber =
evAux_.
event(); IntEventNumber = (
int)TreeEventNumber;
954 CombinedInt = (
uint64_t) IntRunNumber << 16 | IntSubRunNumber << 16 | IntEventNumber;
956 std::cout <<
"Looking at Tree " << Tree <<
", RunNumber " << IntRunNumber <<
", SubRunNumber " << IntSubRunNumber <<
", EventNumber " << IntEventNumber <<
", CrazyNumber " << CombinedInt <<
std::endl;
960 if (ThisNumber != PrevRunNumber ) {
981 std::cout <<
"SplitterStitcher: Setting CSVFileName to " << fullname <<
std::endl;
986 pedestals.
Update(ThisNumber);
987 for (
size_t ichan=0;ichan<2048;ichan++) {
991 std::cout <<
"AllPedMap["<<ThisNumber<<
"]["<<ichan<<
"] has mean " << pedestals.
PedMean(ichan) <<
" (" <<
AllPedMap[ThisNumber][ichan].first <<
")" 995 PrevRunNumber = ThisNumber;
1002 if ( fb ==
nullptr ) {
1004 <<
"Unable to open file " << filename <<
".\n";
1008 fTree = tfs->make<TTree>(
"EventInfo",
"Split event information");
1012 fTree->Branch(
"GivenRunNum" ,&
GivenRunNum ,
"GivenRunNum[AttemptedEvents]/I" );
1034 std::cout <<
"Entering NoRCEsCase" <<
std::endl;
1036 std::cout <<
"Left NoRCEsCase" <<
std::endl;
1044 size_t FirstDigIndex;
1045 size_t FirstDigEventIndex;
1046 size_t FirstDigEvent;
1047 bool first_tick =
true;
1049 bool JumpEvent =
false;
1050 size_t JumpNADC = 0;
1052 std::map<int,int> PrevChanADC;
1070 std::cout <<
"Loaded digits was empty, will be refilled..." 1081 if (
fDebugLevel) std::cout <<
"\nThe RCEs aren't present, so switching to the don't require RCEs case...." <<
std::endl;
1099 std::cout <<
"\nThere are inconsistent numbers of digits between this millislice and the previous millislice: " 1130 for (
unsigned int IndexListLoop = 1; IndexListLoop<
DigitsIndexList.size(); ++IndexListLoop ) {
1132 if (
fDebugLevel) std::cout <<
"\nI am looking at loadedDigitsIndex " <<
loadedDigits_.index <<
". This is the index where the jump occurs so I want to reset stuff." <<
std::endl;
1137 if (
fDebugLevel) std::cout <<
"I have reset the event... and loaded a new timestamp " << NewStamp <<
" as opposed to " <<
DigitsIndexList[IndexListLoop].second <<
std::endl;
1148 Triggering (PrevChanADC, nextdigits, NewTree);
1160 std::cout <<
"\nThe trigger is good so triggering on, EventIndex " <<
fLastEventIndex <<
" corresponding to event " <<
fLastEvent 1162 <<
"\nThe first tick in this event is in EventIndex " << FirstDigEventIndex <<
", event " << FirstDigEvent <<
", loadedDigits index " <<
loadedDigits_.index
1174 if (
dbuf_.size() == 0) {
1175 RawDigit::ADCvector_t emptyvector;
1176 for (
size_t ichan=0;ichan<nextdigits.size();ichan++)
dbuf_.push_back(emptyvector);
1178 for (
size_t ichan=0;ichan<nextdigits.size();ichan++) {
1179 dbuf_[ichan].push_back(nextdigits[ichan]);
1233 for (
size_t ichan=0;ichan<
dbuf_.size();ichan++) {
1240 std::cout <<
"digit[0] corresponding to channel " <<
d.Channel() <<
" ("<<ichan<<
") has ADC value " <<
d.ADC(0)
1249 std::cout <<
"Looking at Monte Carlo, so using pedestals loaded from event, channel " << ichan
1250 <<
", pedestal " <<
d.GetPedestal() <<
" ("<<
loadedDigits_.digits[ichan].GetPedestal()<<
")" 1270 <<
"It went from EventIndex " << FirstDigEventIndex <<
", event " << FirstDigEvent <<
", tick " << FirstDigIndex
1272 <<
"I want to reset the tick value for sure, but do I need to reload the digits because EventIndex is different?" <<
std::endl;
1275 if (
fDebugLevel) std::cout <<
"Yes I do! Changing EventIndex_ to fLastEventIndex...Also want to clear loadedDigits." <<
std::endl;
1291 file_.reset(
nullptr);
1307 bool GoodTree =
false;
1308 size_t LoadTree = 0;
1310 int LookingAtIndex = 0;
1313 if ( LookingAtIndex == (
int)LoadEventIndex ) {
1316 LoadTree = it->second;
1323 std::cout <<
"Looking for event " << LoadEventIndex <<
", it was found at TreeIndex " << LookingAtIndex <<
" but I want to skip " <<
fSkipNInputEvents <<
". Do I load this tree? " << GoodTree <<
std::endl;
1324 if (!GoodTree) ++LoadEventIndex;
1334 std::cout <<
"\nLoading event " <<
inputEventNumber_ <<
" at EventIndex " << LoadEventIndex <<
" on TreeIndex " << LoadTree <<
std::endl;
1336 bool PTBTrigPresent =
false;
1342 if ( PTBTrigPresent ||
fTrigger ) {
1371 bool TrigPresent =
false;
1374 lbne::PennMicroSlice::Payload_Timestamp *FirstPTBTimestamp =
nullptr;
1379 for (
size_t CountLoop = 0; CountLoop < counters.size(); ++CountLoop) {
1381 std::cout <<
"Looking at counters[" << CountLoop <<
"] has CounterID " << counters[CountLoop].GetTrigID() <<
" and Timestamp " << counters[CountLoop].GetTrigTime() <<
std::endl;
1382 for (
size_t PTB = 0; PTB <
fPTBTrigs.size(); ++PTB) {
1383 if ( counters[CountLoop].GetTrigID() ==
fPTBTrigs[PTB] ) {
1384 if (
fDebugLevel) std::cout <<
"\nThere is a trigger on channel " << counters[CountLoop].GetTrigID() <<
" at time " << counters[CountLoop].GetTrigTime() <<
" in event " <<
inputEventNumber_ <<
std::endl;
1393 std::cout <<
"Counters has size" << counters->size() <<
std::endl;
1396 for (
auto count: *counters) {
1398 std::cout <<
"Looking at a counter which has CounterID " << count.GetTrigID() <<
" and Timestamp " << count.GetTrigTime() <<
std::endl;
1399 for (
size_t PTB = 0; PTB <
fPTBTrigs.size(); ++PTB) {
1400 if ( count.GetTrigID() ==
fPTBTrigs[PTB] ) {
1413 std::vector<raw::OpDetWaveform> waveforms;
1414 std::vector<recob::OpHit> hits;
1417 for (
size_t WaveLoop=0; WaveLoop < waveforms.size(); ++WaveLoop ) {
1419 std::cout <<
"Looking at waveform[" << WaveLoop <<
"] it has channel number " << waveforms[WaveLoop].ChannelNumber()
1420 <<
" and timestamp " << SSPTime <<
", and size " << waveforms[WaveLoop].size() <<
std::endl;
1422 for (
size_t HitLoop=0; HitLoop < hits.size(); ++HitLoop ) {
1424 std::cout <<
"Looking at waveform[" << HitLoop <<
"] it is on channel number " << hits[HitLoop].OpChannel() <<
" at timestamp " << OpHitTime <<
std::endl;
1429 std::cout <<
"Loaded waveforms has size " << waveforms.size() <<
", and OpHits has size " << hits.size() <<
std::endl;
1430 if (waveforms.size() && hits.size()) std::cout <<
"\n They Both have non-zero size!!!!\n\n\n" <<
std::endl;
1436 if (
fDebugLevel > 1) std::cout <<
"Loaded waveforms has size " << waveforms->size() <<
std::endl;
1443 std::vector<recob::OpHit> hits;
1454 lbne::TpcNanoSlice::Header::nova_timestamp_t firstTimestamp = 0;
1464 if (
fDebugLevel > 1) std::cout <<
"Loaded RCE information with timestamp " << firstTimestamp <<
std::endl;
1478 for (
size_t TrigSize = 0; TrigSize <
fWhichTrigger.size(); ++TrigSize) {
1480 std::cout <<
"\n\n\nI hope you know that you are triggering on a random number of ticks and not any sort of data! Check that fwhichTrigger is set correctly.\n\n\n" <<
std::endl;
1533 wbuf_.size() <<
" SSP waveforms, " <<
hbuf_.size() <<
" OpHits and " <<
cbuf_.size() <<
" External Triggers (muon counters)";
1539 for (
size_t ichan=0;ichan<
dbuf_.size();ichan++) {
dbuf_[ichan].clear(); }
1549 if (
fDebugLevel > 1) std::cout <<
"Resetting everything (dbuf, cbuf, wbuf, hbuf, Trigger, etc)" <<
std::endl;
1558 if ( StampDiff < 0 ) {
1559 if (
fDebugLevel) std::cout <<
"Stamp diff is negative...need to figure out how to try and fix..." <<
std::endl;
1562 if (
fDebugLevel) std::cout <<
"Stamp diff is positive...need to figure out how to try and fix..." <<
std::endl;
1566 if (
fDebugLevel) std::cout <<
"\nCan't reconcile the timestamps, so voiding this trigger :( \n" <<
std::endl;
1577 if (
fDebugLevel) std::cout <<
"\nRectified the timestamps, carry on building event :D\n" <<
std::endl;
1580 if (
fDebugLevel) std::cout <<
"\nTimestamps lead on from each other, carry on :)" <<
std::endl;
1587 bool NewTree =
false;
1596 }
else NewTree =
true;
1598 std::map<int,int> PrevChanADC;
1599 std::vector<short> ADCdigits;
1647 lbne::TpcNanoSlice::Header::nova_timestamp_t TempTimeStamp =
this_timestamp;
1654 if ( BufferResidual > 0 ) {
1656 std::cout <<
"I have enough previous digits in this event for the prebuffer (" << BufferResidual <<
" = " <<
loadedDigits_.index <<
" - " <<
fPreTriggerTicks 1657 <<
")! Moving loadedDigits_.index to " << BufferResidual <<
std::endl;
1662 BufferResidual = -BufferResidual;
1665 std::cout <<
"I don't have enough previous digits :(, I need an extra " << BufferResidual <<
" ticks from previous events. TrigEvStart = " << TrigEvStart
1666 <<
". I'm going to have to load the previous event to try and find these ticks..." 1671 std::cout <<
"No previous event to load, so can't get a good event. Voiding the trigger." <<
std::endl;
1678 if ( BufferResidual - (
int)
loadedDigits_.digits[0].NADC() < 0 ) {
1681 std::cout <<
"I have satisfied the pretrigger conditions, on the previous EventIndex " <<
EventIndex_-1 <<
" corresponding to event " <<
inputEventNumber_ <<
". It has " <<
loadedDigits_.digits[0].NADC()
1685 std::cout <<
"I can't satisfy the pretrigger conditions, on the previous event. So loading old event :(" <<
std::endl;
1692 std::cout <<
"Have I reloaded everything properly?" 1693 <<
"\nEventIndex " << TempEventIndex <<
", Event " << TempEventNumber <<
", Index " << TempTriggerIndex <<
", NADCs " << TempNADCs
1710 std::cout <<
"Trigger isn't good so I'm going back to where I triggered..." 1711 <<
"Attempted trigger was in EventIndex " << TempEventIndex <<
", event " << TempEventNumber <<
" at index " << TempTriggerIndex
1712 <<
" at timestamp " << TempTimeStamp <<
", it had " << TempNADCs <<
" ADCs." 1724 for (
size_t TrigSize = 0; TrigSize <
fWhichTrigger.size(); ++TrigSize) {
1752 int HitsOverThreshold = 0;
1753 if (PrevChanADC.size() != 0) {
1754 for (
unsigned int achan=0; achan<ADCdigits.size(); ++achan)
1756 ++HitsOverThreshold;
1758 std::cout <<
"Looking at index " <<
loadedDigits_.index <<
" channel " << achan <<
"..." << ADCdigits[achan] <<
" - " 1759 << PrevChanADC[achan] <<
" = " << fabs( ADCdigits[achan] - PrevChanADC[achan] ) <<
" > " <<
fADCdiffThreshold 1763 if ( HitsOverThreshold != 0 )
1764 if (
fDebugLevel > 2) std::cout <<
" after looking through all the channels ("<<ADCdigits.size()<<
") I had " << HitsOverThreshold <<
" ticks with diff more than " <<
fADCdiffThreshold <<
std::endl;
1770 for (
unsigned int bchan=0; bchan<ADCdigits.size(); ++bchan)
1771 PrevChanADC[bchan] = ADCdigits[bchan];
double E(const int i=0) const
void Triggering(std::map< int, int > &PrevChanADC, std::vector< short > ADCdigits, bool NewTree)
SubRunNumber_t subRun() const noexcept
lbne::TpcNanoSlice::Header::nova_timestamp_t last_timestamp
EventID const & eventID() const
unsigned int NumberTrajectoryPoints() const
std::pair< lbne::PennMicroSlice::Payload_Header::short_nova_timestamp_t, std::bitset< TypeSizes::TriggerWordSize > > PTBTrigger
void AddDaughter(const int trackID)
art::InputTag TPCinputTag_
enum raw::_compress Compress_t
double Py(const int i=0) const
Collection of charge vs time digitized from a single readout channel.
int TreeIndexStart[ArraySize]
Energy deposited on a readout channel by simulated tracks.
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
std::string fPedestalFile
void SetUseDefaults(bool f)
art::SubRunNumber_t inputSubRunNumber_
bool loadEvents_(size_t &InputTree)
LoadedCounters loadedCounters_
bool readFile(string const &filename, art::FileBlock *&fb)
double Energy(TDC_t tdc) const
Returns the total energy on this channel in the specified TDC [MeV].
art::InputTag SSPinputTag_
EventNumber_t event() const noexcept
std::unique_ptr< TFile > file_
string MCTruthinputDataProduct_
void LoadRCEInformation(size_t LoadTree)
TBranch * MCTruthinputBranch_
void BuildPTBChannelMap(std::string MapDir, std::string MapFile, std::map< int, int > &channelMap)
double Px(const int i=0) const
art::SubRunNumber_t subRunNumber_
TBranch * SparseinputBranch_
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
vector< sim::SimChannel > MCSimChan_t
vector< simb::MCParticle > MCPart_t
Definition of basic raw digits.
string SSPinputDataProduct_
vector< ExternalTrigger > PennCounters_t
TBranch * MCPartinputBranch_
art::SourceHelper const & sh_
art::EventAuxiliary evAux_
int GivenEventNum[ArraySize]
art::InputTag MCSimChaninputTag_
art::EventNumber_t inputEventNumber_
art::SubRunNumber_t cachedSubRunNumber_
std::vector< unsigned int > fPTBTrigs
std::map< uint64_t, size_t > EventTreeMap
int NumberDaughters() const
constexpr TimeValue_t value() const
bool NoRCEsCase(art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
art::EventNumber_t eventNumber_
void decode(std::any const &, std::string &)
std::vector< raw::RawDigit > tpcFragmentToRawDigits(artdaq::Fragments const &rawFragments, std::vector< std::pair< std::pair< unsigned int, unsigned int >, lbne::TpcNanoSlice::Header::nova_timestamp_t > > &DigitsIndexList, lbne::TpcNanoSlice::Header::nova_timestamp_t &firstTimestamp, art::ServiceHandle< lbne::ChannelMapService > const &channelMap, bool useChannelMap, bool debug, raw::Compress_t compression, unsigned int zeroThreshold)
lbne::TpcNanoSlice::Header::nova_timestamp_t Event_timestamp
void readFile(string fileName, string &content)
EventAuxiliary::ExperimentType experimentType() const noexcept
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
RunNumber_t run() const noexcept
SSPReformatterAlgs sspReform
art::EventAuxiliary * pevaux_
double Pt(const int i=0) const
vector< RawDigit > rawDigits_t
LoadedDigits loadedDigits_
virtual float PedMean(raw::ChannelID_t ch) const
Retrieve pedestal information.
void LoadSSPInformation(size_t LoadTree)
void SetPolarization(const TVector3 &p)
int ChansAtEndOfEvent[ArraySize]
int fOpHitADCsOverThreshold
void decode(std::any const &a, Compress_t &result)
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
void SetCSVFileName(std::string fname)
std::vector< std::pair< std::pair< unsigned int, unsigned int >, lbne::TpcNanoSlice::Header::nova_timestamp_t > > DigitsIndexList
art::InputTag PenninputTag_
double Charge(TDC_t tdc) const
Returns the total number of ionization electrons on this channel in the specified TDC...
void makeEventAndPutDigits_(art::EventPrincipal *&outE, art::Timestamp art_timestamp=0)
lbne::TpcNanoSlice::Header::nova_timestamp_t first_timestamp
art::Timestamp make_art_timestamp_from_nova_timestamp(lbne::TpcNanoSlice::Header::nova_timestamp_t this_nova_timestamp)
std::string getenv(std::string const &name)
string MCSimChaninputDataProduct_
double P(const int i=0) const
LoadedWaveforms loadedWaveforms_
std::vector< sim::TrackIDE > TrackIDEs(TDC_t startTDC, TDC_t endTDC) const
Returns energies collected for each track within a time interval.
rawDigits_t bufferedDigits_
double T(const int i=0) const
unsigned __int64 uint64_t
TBranch * SSPinputBranch_
IDNumber_t< Level::SubRun > SubRunNumber_t
lbne::TpcNanoSlice::Header::nova_timestamp_t fLastTimeStamp
double fOpHitADCThreshold
int GivenSubRunNum[ArraySize]
unsigned int fChansPresent
TBranch * EventAuxBranch_
string MCPartinputDataProduct_
art::RunNumber_t inputRunNumber_
double fNovaTicksPerSSPTick
art::InputTag SparseinputTag_
vector< recob::OpHit > OpHits_t
art::InputTag OpHitinputTag_
void SetWeight(double wt)
TBranch * TPCinputBranch_
void SetEndProcess(std::string s)
TBranch * MCSimChaninputBranch_
std::vector< raw::RawDigit > rawDigits_t
art::InputTag MCPartinputTag_
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
string OpHitinputDataProduct_
double fNanoSecondsPerNovaTick
void AddIonizationElectrons(TrackID_t trackID, TDC_t tdc, double numberElectrons, double const *xyz, double energy)
Add ionization electrons and energy to this channel.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
raw::ChannelID_t Channel() const
Returns the readout channel this object describes.
lbne::TpcNanoSlice::Header::nova_timestamp_t this_timestamp
std::map< uint16_t, std::map< size_t, std::pair< float, float > > > AllPedMap
double Vx(const int i=0) const
art::InputTag MCTruthinputTag_
bool readNext(art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
Utility object to perform functions of association.
std::enable_if_t<!detail::range_sets_supported(P::branch_type)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
std::string fPedestalFileSearchPath
double fNovaTicksPerCountTick
int GivenRunNum[ArraySize]
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
bool eventIsFull_(rawDigits_t const &v)
void CheckTimestamps(bool &JumpEvent, size_t &JumpNADC)
bool fUsePedestalFileSearchPath
double Pz(const int i=0) const
object containing MC truth information necessary for making RawDigits and doing back tracking ...
IDNumber_t< Level::Event > EventNumber_t
std::string find_file(std::string const &filename) const
Interface for experiment-specific channel quality info provider.
lbne::TpcNanoSlice::Header::nova_timestamp_t prev_timestamp
LoadedOpHits loadedOpHits_
double Vz(const int i=0) const
bool LoadPTBInformation(size_t LoadTree)
Splitter(fhicl::ParameterSet const &ps, art::ProductRegistryHelper &prh, art::SourceHelper const &sh)
art::RunNumber_t runNumber_
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
std::string const & eventTreeName()
string PenninputDataProduct_
string TPCinputDataProduct_
art::Timestamp inputEventTime_
vector< vector< double > > clear
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
art::RunNumber_t cachedRunNumber_
vector< simb::MCTruth > MCTruth_t
std::map< int, int > fPTBMap
auto const & get(AssnsNode< L, R, D > const &r)
int ChansAtStartOfEvent[ArraySize]
Interface for experiment-specific service for channel quality info.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
std::vector< raw::ExternalTrigger > PennFragmentToExternalTrigger(artdaq::Fragments const &Fragments, std::map< int, int > &channelMap, lbne::PennMicroSlice::Payload_Timestamp *&FirstPTBTimestamp)
void SetRescatter(int code)
TBranch * OpHitinputBranch_
void function(int client, int *resource, int parblock, int *test, int p)
std::vector< RawDigit::ADCvector_t > dbuf_
bool isRealData() const noexcept
bool TicklerTrigger(std::map< int, int > &PrevChanADC, std::vector< short > ADCdigits)
double fWaveformADCThreshold
double fNovaTicksPerTPCTick
double fTimeStampThreshold
std::vector< unsigned int > fWhichTrigger
virtual float PedMeanErr(raw::ChannelID_t ch) const
double Vy(const int i=0) const
Timestamp const & time() const noexcept
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
std::function< rawDigits_t(artdaq::Fragments const &, std::vector< std::pair< std::pair< unsigned int, unsigned int >, lbne::TpcNanoSlice::Header::nova_timestamp_t > > &, lbne::TpcNanoSlice::Header::nova_timestamp_t &, art::ServiceHandle< lbne::ChannelMapService > const &)> fragmentsToDigits_
vector< OpDetWaveform > SSPWaveforms_t
QTextStream & endl(QTextStream &s)
TBranch * PenninputBranch_
void SetDetName(std::string detName)
def load(filename, jpath="depos")
int fWaveformADCsOverThreshold
IDNumber_t< Level::Run > RunNumber_t
unsigned short fTicksAccumulated