Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option in CSC DigiToRaw to pack strip digis by CFEB in each chamber. #34783

Merged
merged 11 commits into from Aug 25, 2021
6 changes: 6 additions & 0 deletions DataFormats/MuonDetId/interface/CSCDetId.h
Expand Up @@ -249,6 +249,12 @@ class CSCDetId : public DetId {
static std::string chamberName(int endcap, int station, int ring, int chamber);
static std::string chamberName(int iChamberType);
std::string chamberName() const;
/**
* Returns the layer name in the format
* ME$sign$station/$ring/$chamber/$layer. Example: ME+1/1/9/1
*/
static std::string layerName(int endcap, int station, int ring, int chamber, int layer);
std::string layerName() const;

private:
/**
Expand Down
8 changes: 8 additions & 0 deletions DataFormats/MuonDetId/src/CSCDetId.cc
Expand Up @@ -76,6 +76,12 @@ std::string CSCDetId::chamberName(int endcap, int station, int ring, int chamber
return "ME" + eSign + std::to_string(station) + "/" + std::to_string(ring) + "/" + std::to_string(chamber);
}

std::string CSCDetId::layerName(int endcap, int station, int ring, int chamber, int layer) {
const std::string eSign = endcap == 1 ? "+" : "-";
return "ME" + eSign + std::to_string(station) + "/" + std::to_string(ring) + "/" + std::to_string(chamber) + "/" +
std::to_string(layer);
}

std::string CSCDetId::chamberName(int chamberType) {
// ME1a, ME1b, ME12, ME13, ME21, ME22, ME31, ME32, ME41, ME42
const unsigned stations[10] = {1, 1, 1, 1, 2, 2, 3, 3, 4, 4};
Expand All @@ -85,6 +91,8 @@ std::string CSCDetId::chamberName(int chamberType) {

std::string CSCDetId::chamberName() const { return chamberName(endcap(), station(), ring(), chamber()); }

std::string CSCDetId::layerName() const { return layerName(endcap(), station(), ring(), chamber(), layer()); }

std::ostream& operator<<(std::ostream& os, const CSCDetId& id) {
// Note that there is no endl to end the output

Expand Down
1 change: 1 addition & 0 deletions EventFilter/CSCRawToDigi/interface/CSCDigiToRaw.h
Expand Up @@ -81,6 +81,7 @@ class CSCDigiToRaw {
uint16_t formatVersion_;
bool packEverything_;
bool usePreTriggers_;
bool packByCFEB_;
};

#endif
58 changes: 58 additions & 0 deletions EventFilter/CSCRawToDigi/interface/CSCDigiToRawAccept.h
@@ -0,0 +1,58 @@
#ifndef EventFilter_CSCRawToDigi_CSCDigiToRawAccept_h
#define EventFilter_CSCRawToDigi_CSCDigiToRawAccept_h

/** \class CSCDigiToRawAccept
*
* Static class with conditions to accept CSC digis in the Digi-to-Raw step
*
* \author Sven Dildick - Rice
*/

#include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
#include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
#include "DataFormats/CSCDigi/interface/CSCCLCTPreTriggerCollection.h"
#include "DataFormats/CSCDigi/interface/CSCCLCTPreTriggerDigiCollection.h"

namespace CSCDigiToRawAccept {

// takes layer ID, converts to chamber ID, switching ME1A to ME11
CSCDetId chamberID(const CSCDetId& cscDetId);

/* Was there a trigger primitive in the BX range between bxMin and bxMax?
The nominalBX argument is 3 for ALCTs and 7 for CLCTs. This is subtracted
from the object BX before we check if it is in the BX range.

Triggers in ME1/1 should always be assigned with ring number equal to 1.
Distinguishing CLCTs in ME1/a and ME1/b is done with the CLCT half-strip,
or CLCT CFEB.
*/
template <typename LCTCollection>
bool accept(const CSCDetId& cscId, const LCTCollection& lcts, int bxMin, int bxMax, int nominalBX) {
if (bxMin == -999)
return true;
CSCDetId chamberId = chamberID(cscId);
typename LCTCollection::Range lctRange = lcts.get(chamberId);
bool result = false;
for (typename LCTCollection::const_iterator lctItr = lctRange.first; lctItr != lctRange.second; ++lctItr) {
int bx = lctItr->getBX() - nominalBX;
if (bx >= bxMin && bx <= bxMax) {
result = true;
break;
}
}
return result;
}

// older implementation for CLCT pretrigger objects that only have BX information
bool accept(const CSCDetId& cscId, const CSCCLCTPreTriggerCollection& lcts, int bxMin, int bxMax, int nominalBX);

// newer implementation for CLCT pretrigger objects that have BX and CFEB information
bool accept(const CSCDetId& cscId,
const CSCCLCTPreTriggerDigiCollection& lcts,
int bxMin,
int bxMax,
int nominalBX,
std::vector<bool>& preTriggerInCFEB);
}; // namespace CSCDigiToRawAccept

#endif
1 change: 1 addition & 0 deletions EventFilter/CSCRawToDigi/plugins/CSCDigiToRawModule.cc
Expand Up @@ -105,6 +105,7 @@ void CSCDigiToRawModule::fillDescriptions(edm::ConfigurationDescriptions& descri
desc.add<bool>("usePreTriggers", true)->setComment("Set to false if CSCCLCTPreTrigger digis are not available");
desc.add<bool>("packEverything", false)
->setComment("Set to true to disable trigger-related constraints on readout data");
desc.add<bool>("packByCFEB", false)->setComment("Pack strip digis using CFEB info");
desc.add<bool>("useGEMs", false)->setComment("Pack GEM trigger data");
desc.add<bool>("useCSCShowers", false)->setComment("Pack CSC shower trigger data");

Expand Down
127 changes: 29 additions & 98 deletions EventFilter/CSCRawToDigi/src/CSCDigiToRaw.cc
Expand Up @@ -7,6 +7,7 @@
#include "DataFormats/MuonDetId/interface/CSCDetId.h"
#include "DataFormats/CSCDigi/interface/CSCConstants.h"
#include "EventFilter/CSCRawToDigi/interface/CSCDigiToRaw.h"
#include "EventFilter/CSCRawToDigi/interface/CSCDigiToRawAccept.h"
#include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
Expand All @@ -25,87 +26,6 @@
using namespace edm;
using namespace std;

namespace cscd2r {
/// takes layer ID, converts to chamber ID, switching ME1A to ME11
CSCDetId chamberID(const CSCDetId& cscDetId) {
CSCDetId chamberId = cscDetId.chamberId();
if (chamberId.ring() == 4) {
chamberId = CSCDetId(chamberId.endcap(), chamberId.station(), 1, chamberId.chamber(), 0);
}
return chamberId;
}

template <typename LCTCollection>
bool accept(
const CSCDetId& cscId, const LCTCollection& lcts, int bxMin, int bxMax, int nominalBX, bool me1abCheck = false) {
if (bxMin == -999)
return true;
CSCDetId chamberId = chamberID(cscId);
typename LCTCollection::Range lctRange = lcts.get(chamberId);
bool result = false;
for (typename LCTCollection::const_iterator lctItr = lctRange.first; lctItr != lctRange.second; ++lctItr) {
int bx = lctItr->getBX() - nominalBX;
if (bx >= bxMin && bx <= bxMax) {
result = true;
break;
}
}

bool me1 = cscId.station() == 1 && cscId.ring() == 1;
//this is another "creative" recovery of smart ME1A-ME1B TMB logic cases:
//wire selective readout requires at least one (A)LCT in the full chamber
if (me1 && result == false && me1abCheck) {
CSCDetId me1aId = CSCDetId(chamberId.endcap(), chamberId.station(), 4, chamberId.chamber(), 0);
lctRange = lcts.get(me1aId);
for (typename LCTCollection::const_iterator lctItr = lctRange.first; lctItr != lctRange.second; ++lctItr) {
int bx = lctItr->getBX() - nominalBX;
if (bx >= bxMin && bx <= bxMax) {
result = true;
break;
}
}
}

return result;
}

// need to specialize for pretriggers, since they don't have a getBX()
template <>
bool accept(const CSCDetId& cscId,
const CSCCLCTPreTriggerCollection& lcts,
int bxMin,
int bxMax,
int nominalBX,
bool me1abCheck) {
if (bxMin == -999)
return true;
CSCDetId chamberId = chamberID(cscId);
CSCCLCTPreTriggerCollection::Range lctRange = lcts.get(chamberId);
bool result = false;
for (CSCCLCTPreTriggerCollection::const_iterator lctItr = lctRange.first; lctItr != lctRange.second; ++lctItr) {
int bx = *lctItr - nominalBX;
if (bx >= bxMin && bx <= bxMax) {
result = true;
break;
}
}
bool me1a = cscId.station() == 1 && cscId.ring() == 4;
if (me1a && result == false && me1abCheck) {
//check pretriggers in me1a as well; relevant for TMB emulator writing to separate detIds
lctRange = lcts.get(cscId);
for (CSCCLCTPreTriggerCollection::const_iterator lctItr = lctRange.first; lctItr != lctRange.second; ++lctItr) {
int bx = *lctItr - nominalBX;
if (bx >= bxMin && bx <= bxMax) {
result = true;
break;
}
}
}
return result;
}

} // namespace cscd2r

CSCDigiToRaw::CSCDigiToRaw(const edm::ParameterSet& pset)
: alctWindowMin_(pset.getParameter<int>("alctWindowMin")),
alctWindowMax_(pset.getParameter<int>("alctWindowMax")),
Expand All @@ -118,10 +38,11 @@ CSCDigiToRaw::CSCDigiToRaw(const edm::ParameterSet& pset)
// don't check for consistency with trig primitives
// overrides usePreTriggers
packEverything_(pset.getParameter<bool>("packEverything")),
usePreTriggers_(pset.getParameter<bool>("usePreTriggers")) {}
usePreTriggers_(pset.getParameter<bool>("usePreTriggers")),
packByCFEB_(pset.getParameter<bool>("packByCFEB")) {}

CSCEventData& CSCDigiToRaw::findEventData(const CSCDetId& cscDetId, FindEventDataInfo& info) const {
CSCDetId chamberId = cscd2r::chamberID(cscDetId);
CSCDetId chamberId = CSCDigiToRawAccept::chamberID(cscDetId);
// find the entry into the map
map<CSCDetId, CSCEventData>::iterator chamberMapItr = info.theChamberDataMap.find(chamberId);
if (chamberMapItr == info.theChamberDataMap.end()) {
Expand Down Expand Up @@ -156,16 +77,19 @@ void CSCDigiToRaw::add(const CSCStripDigiCollection& stripDigis,
CSCDetId cscDetId = (*j).first;
// only digitize if there are pre-triggers

bool me1abCheck = fedInfo.formatVersion_ == 2013;
// determine where the pretriggers are
std::vector<bool> preTriggerInCFEB;
preTriggerInCFEB.resize(CSCConstants::MAX_CFEBS_RUN2);

// pretrigger flag must be set and the pretrigger collection must be nonzero!
const bool usePreTriggers = usePreTriggers_ and preTriggers != nullptr;
if (!usePreTriggers || packEverything_ ||
(usePreTriggers && cscd2r::accept(cscDetId,
*preTriggerDigis,
preTriggerWindowMin_,
preTriggerWindowMax_,
CSCConstants::CLCT_CENTRAL_BX,
me1abCheck))) {
(usePreTriggers && CSCDigiToRawAccept::accept(cscDetId,
*preTriggerDigis,
preTriggerWindowMin_,
preTriggerWindowMax_,
CSCConstants::CLCT_CENTRAL_BX,
preTriggerInCFEB))) {
bool me1a = (cscDetId.station() == 1) && (cscDetId.ring() == 4);
bool zplus = (cscDetId.endcap() == 1);
bool me1b = (cscDetId.station() == 1) && (cscDetId.ring() == 1);
Expand All @@ -177,6 +101,17 @@ void CSCDigiToRaw::add(const CSCStripDigiCollection& stripDigis,
for (; digiItr != last; ++digiItr) {
CSCStripDigi digi = *digiItr;
int strip = digi.getStrip();
int cfeb = digi.getCFEB();
// CSC strip digis in ME1/a have CFEB number 0, 1, or 2
// But a pretrigger in ME1/a has CFEB number 4, 5, or 6 (+4)
if (me1a)
cfeb += CSCConstants::NUM_CFEBS_ME1B;

// At this point, if we are packing by CFEBs and there is no
// pretrigger in this CFEB, ignore this strip digi
if (packByCFEB_ and not preTriggerInCFEB[cfeb])
continue;

// From LS1 on ME1a strips are unganged
if (fedInfo.formatVersion_ == 2013) {
if (me1a && zplus) {
Expand Down Expand Up @@ -215,10 +150,8 @@ void CSCDigiToRaw::add(const CSCWireDigiCollection& wireDigis,
add(alctDigis, fedInfo);
for (CSCWireDigiCollection::DigiRangeIterator j = wireDigis.begin(); j != wireDigis.end(); ++j) {
CSCDetId cscDetId = (*j).first;
bool me1abCheck = fedInfo.formatVersion_ == 2013;
if (packEverything_ ||
cscd2r::accept(
cscDetId, alctDigis, alctWindowMin_, alctWindowMax_, CSCConstants::ALCT_CENTRAL_BX, me1abCheck)) {
if (packEverything_ || CSCDigiToRawAccept::accept(
cscDetId, alctDigis, alctWindowMin_, alctWindowMax_, CSCConstants::ALCT_CENTRAL_BX)) {
CSCEventData& cscData = findEventData(cscDetId, fedInfo);
std::vector<CSCWireDigi>::const_iterator digiItr = (*j).second.first;
std::vector<CSCWireDigi>::const_iterator last = (*j).second.second;
Expand All @@ -236,10 +169,8 @@ void CSCDigiToRaw::add(const CSCComparatorDigiCollection& comparatorDigis,
for (auto const& j : comparatorDigis) {
CSCDetId cscDetId = j.first;
CSCEventData& cscData = findEventData(cscDetId, fedInfo);
bool me1abCheck = fedInfo.formatVersion_ == 2013;
if (packEverything_ ||
cscd2r::accept(
cscDetId, clctDigis, clctWindowMin_, clctWindowMax_, CSCConstants::CLCT_CENTRAL_BX, me1abCheck)) {
if (packEverything_ || CSCDigiToRawAccept::accept(
cscDetId, clctDigis, clctWindowMin_, clctWindowMax_, CSCConstants::CLCT_CENTRAL_BX)) {
bool me1a = (cscDetId.station() == 1) && (cscDetId.ring() == 4);

/*
Expand Down
52 changes: 52 additions & 0 deletions EventFilter/CSCRawToDigi/src/CSCDigiToRawAccept.cc
@@ -0,0 +1,52 @@
#include "DataFormats/CSCDigi/interface/CSCConstants.h"
#include "EventFilter/CSCRawToDigi/interface/CSCDigiToRawAccept.h"

CSCDetId CSCDigiToRawAccept::chamberID(const CSCDetId& cscDetId) {
CSCDetId chamberId = cscDetId.chamberId();
if (chamberId.ring() == 4) {
chamberId = CSCDetId(chamberId.endcap(), chamberId.station(), 1, chamberId.chamber(), 0);
}
return chamberId;
}

// older function for pretriggers BX objects
bool CSCDigiToRawAccept::accept(
const CSCDetId& cscId, const CSCCLCTPreTriggerCollection& lcts, int bxMin, int bxMax, int nominalBX) {
if (bxMin == -999)
return true;
CSCDetId chamberId = chamberID(cscId);
CSCCLCTPreTriggerCollection::Range lctRange = lcts.get(chamberId);
bool result = false;
for (CSCCLCTPreTriggerCollection::const_iterator lctItr = lctRange.first; lctItr != lctRange.second; ++lctItr) {
int bx = *lctItr - nominalBX;
if (bx >= bxMin && bx <= bxMax) {
result = true;
break;
}
}
return result;
}

bool CSCDigiToRawAccept::accept(const CSCDetId& cscId,
const CSCCLCTPreTriggerDigiCollection& lcts,
int bxMin,
int bxMax,
int nominalBX,
std::vector<bool>& preTriggerInCFEB) {
if (bxMin == -999)
return true;

bool atLeastOnePreTrigger = false;

CSCDetId chamberId = chamberID(cscId);
CSCCLCTPreTriggerDigiCollection::Range lctRange = lcts.get(chamberId);
for (CSCCLCTPreTriggerDigiCollection::const_iterator lctItr = lctRange.first; lctItr != lctRange.second; ++lctItr) {
int bx = lctItr->getBX() - nominalBX;
if (bx >= bxMin && bx <= bxMax) {
atLeastOnePreTrigger = true;
// save the location of all pretriggers
preTriggerInCFEB[lctItr->getCFEB()] = true;
}
}
return atLeastOnePreTrigger;
}
6 changes: 6 additions & 0 deletions EventFilter/CSCRawToDigi/test/BuildFile.xml
@@ -1,3 +1,9 @@
<bin file="cscRawToDigiTest.cpp">
<use name="EventFilter/CSCRawToDigi"/>
</bin>
<library file="CSCPackerUnpackerUnitTest.cc" name="CSCRawToDigiTest">
<use name="EventFilter/CSCRawToDigi"/>
<use name="FWCore/Framework"/>
<use name="DataFormats/CSCDigi"/>
<flags EDM_PLUGIN="1"/>
</library>