Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CRVResponse/fcl/prolog_v11.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ BEGIN_PROLOG
//-may be changed for testing purposes,
// if a database table of a random gaussian distribution is used
// (current random table uses a sigma equal to 5% of the nominal photon yied)
photonYieldVariationCutoffLow :-0.2 //the photon yield variation is cut off at 20% below the mean
photonYieldVariationCutoffHigh : 0.2 //the photon yield variation is cut off at 20% above the mean
//note: if measured deviations are used, the cutoffs should be set to the maximum values
digitizationStart : @local::DigitizationStart
digitizationEnd : @local::DigitizationEnd
digitizationStartMargin : 100.0 //ns start recording earlier to account for photon travel times and electronics response times
Expand Down
3 changes: 0 additions & 3 deletions CRVResponse/fcl/prolog_v12.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ BEGIN_PROLOG
//-may be changed for testing purposes,
// if a database table of a random gaussian distribution is used
// (current random table uses a sigma equal to 5% of the nominal photon yied)
photonYieldVariationCutoffLow :-0.2 //the photon yield variation is cut off at 20% below the mean
photonYieldVariationCutoffHigh : 0.2 //the photon yield variation is cut off at 20% above the mean
//note: if measured deviations are used, the cutoffs should be set to the maximum values
digitizationStart : @local::DigitizationStart
digitizationEnd : @local::DigitizationEnd
digitizationStartMargin : 100.0 //ns start recording earlier to account for photon travel times and electronics response times
Expand Down
8 changes: 0 additions & 8 deletions CRVResponse/src/CrvPhotonGenerator_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ namespace mu2e
fhicl::Sequence<double> scintillationYields{ Name("scintillationYields"), Comment("scintillation yields at Crv sectors")};
fhicl::Atom<double> photonYieldScaleFactor{ Name("photonYieldScaleFactor"), Comment("global scale factor for the photon yield")};
fhicl::Atom<double> photonYieldVariationScale{ Name("photonYieldVariationScale"),Comment("scale factor of the photon yield variation")};
fhicl::Atom<double> photonYieldVariationCutoffLow{ Name("photonYieldVariationCutoffLow"),Comment("lower cutoff at photon yield variation")};
fhicl::Atom<double> photonYieldVariationCutoffHigh{ Name("photonYieldVariationCutoffHigh"),Comment("upper cutoff at photon yield variation")};
fhicl::Atom<double> digitizationStart{ Name("digitizationStart"), Comment("start of digitization after DAQ event window start")};
fhicl::Atom<double> digitizationEnd{ Name("digitizationEnd"), Comment("end of digitization after DAQ event window start")};
fhicl::Atom<double> digitizationStartMargin{ Name("digitizationStartMargin"),
Expand Down Expand Up @@ -100,8 +98,6 @@ namespace mu2e
double _photonYieldScaleFactor;
mu2e::ProditionsHandle<mu2e::CRVPhotonYield> _photonYieldVariationVector;
double _photonYieldVariationScale;
double _photonYieldVariationCutoffLow;
double _photonYieldVariationCutoffHigh;

//On-spill
//-Event length: 1695ns (microbunch period)
Expand Down Expand Up @@ -164,8 +160,6 @@ namespace mu2e
_scintillationYields(conf().scintillationYields()),
_photonYieldScaleFactor(conf().photonYieldScaleFactor()),
_photonYieldVariationScale(conf().photonYieldVariationScale()),
_photonYieldVariationCutoffLow(conf().photonYieldVariationCutoffLow()),
_photonYieldVariationCutoffHigh(conf().photonYieldVariationCutoffHigh()),
_digitizationStart(conf().digitizationStart()),
_digitizationEnd(conf().digitizationEnd()),
_digitizationStartMargin(conf().digitizationStartMargin()),
Expand Down Expand Up @@ -347,8 +341,6 @@ namespace mu2e
size_t channel = step.barIndex().asUint()*CRVId::nChanPerBar + SiPM;
float photonYieldDeviation = photonYieldVariationVector.photonYieldDeviation(channel);
photonYieldDeviation *= _photonYieldVariationScale; //scale factor for the variation
if(photonYieldDeviation<_photonYieldVariationCutoffLow) photonYieldDeviation=_photonYieldVariationCutoffLow;
if(photonYieldDeviation>_photonYieldVariationCutoffHigh) photonYieldDeviation=_photonYieldVariationCutoffHigh;
photonYieldDeviation = (photonYieldDeviation+1.0)*_photonYieldScaleFactor; //global photon yield scale factor for e.g. aging
photonMaker->SetPhotonYieldDeviation(photonYieldDeviation,SiPM);
}
Expand Down
6 changes: 2 additions & 4 deletions CRVResponse/src/MakeCrvPhotons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,22 +538,20 @@ double MakeCrvPhotons::GetAverageNumberOfCerenkovPhotons(double beta, double cha
{
if(charge==0) return 0;

bool first=true;
double prevBeta=0;
double prevNumberPhotons=0;
std::map<double,double>::const_iterator i;
for(i=photons.begin(); i!=photons.end(); i++)
{
if(beta<=i->first)
if(beta<=i->first) //first beta in the Cerenkov map is always greater than 0.0 and has number of photons of 0.
{
if(first) return 0; //this shouldn't happen
if(i->first==0) return i->second; //beta=0 in Cerenkov map shouldn't happen. if it did and was the first entry, i->first-prevBeta would result in a division by 0.
double numberPhotons=prevNumberPhotons+(i->second-prevNumberPhotons)/(i->first-prevBeta)*(beta-prevBeta);
numberPhotons*=fabs(charge/eplus);
return numberPhotons;
}
prevBeta=i->first;
prevNumberPhotons=i->second;
first=false;
}
return photons.rbegin()->second*fabs(charge/eplus); //this shouldn't happen
}
Expand Down
23 changes: 23 additions & 0 deletions DAQ/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ cet_build_plugin(CrvDigisFromArtdaqFragments art::module
REG_SOURCE src/CrvDigisFromArtdaqFragments_module.cc
LIBRARIES REG
Offline::DAQ
Offline::CRVConditions
Offline::DataProducts
Offline::ProditionsService
Offline::RecoDataProducts
artdaq-core-mu2e::Data
artdaq-core-mu2e::Overlays
Expand All @@ -207,7 +209,9 @@ cet_build_plugin(CrvDigisFromArtdaqFragmentsFEBII art::module
REG_SOURCE src/CrvDigisFromArtdaqFragmentsFEBII_module.cc
LIBRARIES REG
Offline::DAQ
Offline::CRVConditions
Offline::DataProducts
Offline::ProditionsService
Offline::RecoDataProducts
artdaq-core-mu2e::Data
artdaq-core-mu2e::Data_dict
Expand All @@ -225,6 +229,25 @@ cet_build_plugin(CrvGRdataFromArtdaqFragments art::module
artdaq-core-mu2e::Overlays
)

cet_build_plugin(CrvDigisToFragments art::module
REG_SOURCE src/CrvDigisToFragments_module.cc
LIBRARIES REG
Offline::DAQ
Offline::CRVConditions
Offline::DataProducts
Offline::ProditionsService
Offline::RecoDataProducts
artdaq-core-mu2e::Data
artdaq-core-mu2e::Data_dict
)

cet_build_plugin(CrvDigiCollectionsComparator art::module
REG_SOURCE src/CrvDigiCollectionsComparator_module.cc
LIBRARIES REG
Offline::RecoDataProducts
Offline::DataProducts
)

cet_build_plugin(MSDHitsFromDTCEvents art::module
REG_SOURCE src/MSDHitsFromDTCEvents_module.cc
LIBRARIES REG
Expand Down
210 changes: 210 additions & 0 deletions DAQ/src/CrvDigiCollectionsComparator_module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
// ======================================================================
//
// CrvDigiCollectionsComparator_module: Compare two CrvDigiCollections
//
// ======================================================================

#include "art/Framework/Core/EDAnalyzer.h"
#include "art/Framework/Core/ModuleMacros.h"
#include "art/Framework/Principal/Event.h"
#include "cetlib_except/exception.h"
#include "fhiclcpp/ParameterSet.h"

#include "Offline/RecoDataProducts/inc/CrvDigi.hh"

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

namespace mu2e {

class CrvDigiCollectionsComparator : public art::EDAnalyzer {
public:
struct Config {
fhicl::Atom<art::InputTag> referenceTag{fhicl::Name("referenceTag"),
fhicl::Comment("Reference CrvDigiCollection")};
fhicl::Atom<art::InputTag> candidateTag{fhicl::Name("candidateTag"),
fhicl::Comment("Candidate CrvDigiCollection")};
fhicl::Atom<bool> failOnMismatch{fhicl::Name("failOnMismatch"),
fhicl::Comment("Throw if any mismatch is found"),
false};
fhicl::Atom<int> diagLevel{fhicl::Name("diagLevel"),
fhicl::Comment("Diagnostic verbosity"),
0};
fhicl::Atom<size_t> maxMismatchesToPrint{fhicl::Name("maxMismatchesToPrint"),
fhicl::Comment("Maximum mismatch entries to print"),
10};
fhicl::Atom<size_t> maxWaveformSamplesToPrint{
fhicl::Name("maxWaveformSamplesToPrint"),
fhicl::Comment("Maximum waveform samples to print in mismatch diagnostics"),
64};
};

using Parameters = art::EDAnalyzer::Table<Config>;

explicit CrvDigiCollectionsComparator(Parameters const& config);

void analyze(art::Event const& event) override;
void endJob() override;

private:
struct FlatDigi {
uint32_t scintillatorBarIndex;
uint16_t sipm;
uint16_t startTdc;
std::vector<int16_t> waveform;

bool operator<(FlatDigi const& other) const {
return std::tie(scintillatorBarIndex, sipm, startTdc, waveform) <
std::tie(other.scintillatorBarIndex, other.sipm, other.startTdc, other.waveform);
}

bool operator==(FlatDigi const& other) const {
return scintillatorBarIndex == other.scintillatorBarIndex && sipm == other.sipm && startTdc == other.startTdc &&
waveform == other.waveform;
}
};

static std::vector<FlatDigi> normalize(mu2e::CrvDigiCollection const& digis);
static std::string describe(FlatDigi const& digi, size_t maxWaveformSamplesToPrint);

art::InputTag referenceTag_;
art::InputTag candidateTag_;
bool failOnMismatch_;
int diagLevel_;
size_t maxMismatchesToPrint_;
size_t maxWaveformSamplesToPrint_;

size_t totalEvents_{0};
size_t matchingEvents_{0};
size_t mismatchedEvents_{0};
};

CrvDigiCollectionsComparator::CrvDigiCollectionsComparator(Parameters const& config)
: art::EDAnalyzer{config}
, referenceTag_(config().referenceTag())
, candidateTag_(config().candidateTag())
, failOnMismatch_(config().failOnMismatch())
, diagLevel_(config().diagLevel())
, maxMismatchesToPrint_(config().maxMismatchesToPrint())
, maxWaveformSamplesToPrint_(config().maxWaveformSamplesToPrint()) {}

std::vector<CrvDigiCollectionsComparator::FlatDigi>
CrvDigiCollectionsComparator::normalize(mu2e::CrvDigiCollection const& digis) {
std::vector<FlatDigi> out;
out.reserve(digis.size());
for (auto const& digi : digis) {
if(digi.IsNZS()) continue;
out.push_back(FlatDigi{digi.GetScintillatorBarIndex().asUint(), digi.GetSiPMNumber(), digi.GetStartTDC(), digi.GetADCs()});
}
// Sort so comparison is robust against ordering differences between producers.
std::sort(out.begin(), out.end());
return out;
}

std::string CrvDigiCollectionsComparator::describe(FlatDigi const& digi,
size_t maxWaveformSamplesToPrint) {
std::ostringstream os;
os << "scintillatorBarIndex=" << digi.scintillatorBarIndex << ", sipm=" << digi.sipm << ", startTdc=" << digi.startTdc
<< ", waveformSize=" << digi.waveform.size();
if (!digi.waveform.empty()) {
os << ", waveform={";
size_t const n = digi.waveform.size();
if (n <= maxWaveformSamplesToPrint) {
for (size_t i = 0; i < n; ++i) {
if (i != 0) {
os << ",";
}
os << digi.waveform[i];
}
} else {
size_t const head = maxWaveformSamplesToPrint / 2;
size_t const tail = maxWaveformSamplesToPrint - head;
for (size_t i = 0; i < head; ++i) {
if (i != 0) {
os << ",";
}
os << digi.waveform[i];
}
os << ",...,";
for (size_t i = n - tail; i < n; ++i) {
if (i != n - tail) {
os << ",";
}
os << digi.waveform[i];
}
}
os << "}";
}
return os.str();
}

void CrvDigiCollectionsComparator::analyze(art::Event const& event) {
++totalEvents_;

auto const& referenceHandle = event.getValidHandle<mu2e::CrvDigiCollection>(referenceTag_);
auto const& candidateHandle = event.getValidHandle<mu2e::CrvDigiCollection>(candidateTag_);

auto reference = normalize(*referenceHandle);
auto candidate = normalize(*candidateHandle);

std::vector<std::string> mismatches;
if (reference.size() != candidate.size()) {
std::ostringstream os;
os << "Collection sizes differ: reference=" << reference.size()
<< ", candidate=" << candidate.size();
mismatches.push_back(os.str());
}

size_t compareCount = std::min(reference.size(), candidate.size());
for (size_t i = 0; i < compareCount && mismatches.size() < maxMismatchesToPrint_; ++i) {
if (!(reference[i] == candidate[i])) {
std::ostringstream os;
os << "Digi mismatch at sorted index " << i << "\n"
<< " reference: " << describe(reference[i], maxWaveformSamplesToPrint_) << "\n"
<< " candidate: " << describe(candidate[i], maxWaveformSamplesToPrint_);
mismatches.push_back(os.str());
}
}

if (mismatches.empty()) {
++matchingEvents_;
if (diagLevel_ > 1) {
std::cout << "[CrvDigiCollectionsComparator] Event " << event.id()
<< " collections are equivalent (" << reference.size() << " digis)" << std::endl;
}
return;
}

++mismatchedEvents_;

std::ostringstream summary;
summary << "[CrvDigiCollectionsComparator] Event " << event.id() << " mismatch between "
<< referenceTag_ << " and " << candidateTag_ << "\n";
for (auto const& mismatch : mismatches) {
summary << mismatch << "\n";
}

if (diagLevel_ > 0 || failOnMismatch_) {
// Keep human-readable details even when failOnMismatch is false.
std::cout << summary.str();
}

if (failOnMismatch_) {
throw cet::exception("CRVDIGI_COMPARE") << summary.str();
}
}

void CrvDigiCollectionsComparator::endJob() {
std::cout << "\n ----- [CrvDigiCollectionsComparator] Summary ----- " << std::endl;
std::cout << "Total events: " << totalEvents_ << std::endl;
std::cout << "Matching events: " << matchingEvents_ << std::endl;
std::cout << "Mismatched events: " << mismatchedEvents_ << std::endl;
}

} // namespace mu2e

DEFINE_ART_MODULE(mu2e::CrvDigiCollectionsComparator)
Loading