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

DT TPG for Phase-2 #30344

Merged
merged 11 commits into from
Jul 2, 2020
44 changes: 44 additions & 0 deletions L1Trigger/DTTriggerPhase2/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<use name="CalibMuon/DTDigiSync"/>
<use name="CondFormats/DTObjects"/>
<use name="CondFormats/DataRecord"/>
<use name="CondFormats/L1TObjects"/>
<use name="DQM/DTMonitorModule"/>
<use name="DataFormats/BeamSpot"/>
<use name="DataFormats/CSCRecHit"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/DTDigi"/>
<use name="DataFormats/DTRecHit"/>
<use name="DataFormats/GeometrySurface"/>
<use name="DataFormats/HLTReco"/>
<use name="DataFormats/L1DTTrackFinder"/>
<use name="DataFormats/L1GlobalTrigger"/>
<use name="DataFormats/L1TMuon"/>
<use name="DataFormats/L1Trigger"/>
<use name="DataFormats/MuonData"/>
<use name="DataFormats/MuonDetId"/>
<use name="DataFormats/MuonReco"/>
<use name="DataFormats/RPCDigi"/>
<use name="DataFormats/RPCRecHit"/>
<use name="DataFormats/Scalers"/>
<use name="DataFormats/TrackReco"/>
<use name="DataFormats/VertexReco"/>
<use name="FWCore/Common"/>
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/Utilities"/>
<use name="Geometry/CommonDetUnit"/>
<use name="Geometry/DTGeometry"/>
<use name="Geometry/RPCGeometry"/>
<use name="Geometry/Records"/>
<use name="L1Trigger/DTSectorCollector"/>
<use name="MagneticField/Engine"/>
<use name="SimDataFormats/DigiSimLinks"/>
<use name="SimDataFormats/PileupSummaryInfo"/>
<use name="TrackingTools/GeomPropagators"/>
<use name="TrackingTools/Records"/>
<use name="TrackingTools/TrajectoryState"/>
<use name="roofitcore"/>
<use name="vdt"/>
<export>
<lib name="1"/>
</export>
20 changes: 20 additions & 0 deletions L1Trigger/DTTriggerPhase2/doc/qualities.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Just to keep track of the fast evolving quality definition
#########################################################
DT quality code
---------------
1, 2: 3-hit in a single SL
3, 4: 4-hit in a single SL (3 means that there are other TP in this SL, 4 that it is the only one)
5: 3-hit in a single SL + 1 or 2 hits in the other SL
6: 3-hit in both SL
7: 4-hit in a single SL + 1 or 2 hits in the other SL
8: 4-hit in a SL + 3-hit in the other SL
9: 4-hit in both SL

RPC Flag (tells how RPC was used) #FIXME being implemented, not everything available yet
---------------------------------
0: segment that could not be matched to any RPC cluster (or 'useRPC' option is set to false)
1: RPC used to overwrite TP timing info (both t0 and BX)
2: RPC only segment
3: RPC single hit not associated to any DT segment
4: RPC used to confirm the presence of the TP, but not used to recompute any of its quantities
5: RPC single hit associated with a DT segment (only kept if 'storeAllRPCHits' is set to True, which not the default)
62 changes: 62 additions & 0 deletions L1Trigger/DTTriggerPhase2/interface/CandidateGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef L1Trigger_DTTriggerPhase2_CandidateGroup_h
#define L1Trigger_DTTriggerPhase2_CandidateGroup_h

#include <tuple>
#include <vector>
#include <bitset>
#include <iostream>
#include <complex>

#include "L1Trigger/DTTriggerPhase2/interface/DTprimitive.h"
#include "L1Trigger/DTTriggerPhase2/interface/DTPattern.h"

namespace dtbayesam {

typedef std::bitset<8> qualitybits;

class CandidateGroup {
public:
//Constructors and destructors
CandidateGroup();
CandidateGroup(DTPattern* p);
~CandidateGroup();

//Hit operation procedures
void addHit(DTPrimitive dthit, int lay, bool isGood);
void removeHit(DTPrimitive dthit);

//Get Methods
int candId() const { return candId_; };
int nhits() const { return nhits_; };
int nisGood() const { return nisGood_; };
int nLayerhits() const { return nLayerhits_; };
int nLayerUp() const { return nLayerUp_; };
int nLayerDown() const { return nLayerDown_; };
DTPrimitivePtrs candHits() const { return candHits_; };
qualitybits quality() const { return quality_; };
const DTPattern* pattern() const { return pattern_; };

//Set Methods
void setCandId(int cId) { candId_ = cId; };

//Pattern rankers
bool operator>(const CandidateGroup& cOther) const;
bool operator==(const CandidateGroup& cOther) const;

private:
DTPrimitivePtrs candHits_;
qualitybits quality_;
int nhits_;
int nLayerhits_;
int nLayerUp_;
int nLayerDown_;
int nisGood_;
DTPattern* pattern_;
int candId_;
};

typedef std::shared_ptr<CandidateGroup> CandidateGroupPtr;
typedef std::vector<CandidateGroupPtr> CandidateGroupPtrs;
}; // namespace dtbayesam

#endif
63 changes: 63 additions & 0 deletions L1Trigger/DTTriggerPhase2/interface/DTPattern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef L1Trigger_DTTriggerPhase2_DTPattern_h
#define L1Trigger_DTTriggerPhase2_DTPattern_h

#include <tuple>
#include <vector>
#include <iostream>

// Typedef for refHits organized as [SL, Cell, Laterality]. Using integers is an
// overkill for something that only needs 3, 7 and 2 bits.
typedef std::tuple<int, int, int> RefDTPatternHit;
// Another overkill typing for the pattern identifier
// [SLUp, SLDown, ChambedUp-ChamberDown], only need 3, 3 and 5 bits
typedef std::tuple<int, int, int> DTPatternIdentifier;

class DTPattern {
// A pattern is a seed plus a set of hits. Translational simmetry is used to
// translate it across all posible recoHits in the lower (upper layer) and
// check for pattern hit matches of recohits.
public:
//Constructors and destructors
DTPattern();
DTPattern(RefDTPatternHit seedUp, RefDTPatternHit seedDown);
DTPattern(int SL1, int SL2, int diff);
virtual ~DTPattern();

//Adding hits to the pattern
void addHit(RefDTPatternHit hit);
// Given the up and down seeding hits check if a given hit is in the pattern.
// Returns -1 for left laterality, +1 for right laterality, 0 if undecided
// and -999 if not in the pattern
int latHitIn(int slId, int chId, int allowedVariance) const;

// When comparing with a given set of hits we need to set up at least one of
// those two to compute the translation
void setHitUp(int chIdUp) { recoseedUp_ = chIdUp; }
void setHitDown(int chIdDown) { recoseedDown_ = chIdDown; }

//Get methods
DTPatternIdentifier id() const { return id_; }
int sl1() const { return std::get<0>(id_); }
int sl2() const { return std::get<1>(id_); }
int diff() const { return std::get<2>(id_); }
const std::vector<RefDTPatternHit> &genHits() const { return genHits_; }

//Printing
friend std::ostream &operator<<(std::ostream &out, DTPattern &p);

private:
//Generated seeds
RefDTPatternHit seedUp_;
RefDTPatternHit seedDown_;
// Generated hits
std::vector<RefDTPatternHit> genHits_;
// Pattern is classified in terms of SL + chamber differences to profit from
// translational invariance
DTPatternIdentifier id_;
//Generated seeds + hits translated to a given seed pair
int recoseedUp_;
int recoseedDown_;
bool debug_ = false;
};

#endif
57 changes: 57 additions & 0 deletions L1Trigger/DTTriggerPhase2/interface/DTprimitive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef L1Trigger_DTTriggerPhase2_DTprimitive_h
#define L1Trigger_DTTriggerPhase2_DTprimitive_h

#include "L1Trigger/DTTriggerPhase2/interface/constants.h"
#include <ostream>
#include <memory>
#include <vector>

class DTPrimitive {
public:
DTPrimitive();
DTPrimitive(std::shared_ptr<DTPrimitive>& ptr);
DTPrimitive(DTPrimitive* ptr);
virtual ~DTPrimitive();

bool isValidTime();
float wireHorizPos();

void setTimeCorrection(int time) { timeCorrection_ = time; };
void setTDCTimeStamp(int tstamp) { tdcTimeStamp_ = tstamp; };
void setOrbit(int orb) { orbit_ = orb; }
void setPayload(double hitTag, int idx) { this->payLoad_[idx] = hitTag; };
void setChannelId(int channel) { channelId_ = channel; };
void setLayerId(int layer) { layerId_ = layer; };
void setCameraId(int camera) { cameraId_ = camera; };
void setSuperLayerId(int lay) { superLayerId_ = lay; };
void setLaterality(cmsdt::LATERAL_CASES lat) { laterality_ = lat; };

const int timeCorrection() const { return timeCorrection_; };
const int tdcTimeStamp() const { return tdcTimeStamp_; };
const int orbit() const { return orbit_; };
const int tdcTimeStampNoOffset() const { return tdcTimeStamp_ - timeCorrection_; };
const double payLoad(int idx) const { return payLoad_[idx]; };
const int channelId() const { return channelId_; };
const int layerId() const { return layerId_; };
const int cameraId() const { return cameraId_; };
const int superLayerId() const { return superLayerId_; };
const cmsdt::LATERAL_CASES laterality() const { return laterality_; };

private:
int cameraId_; // Chamber ID
int superLayerId_; // SL ID
int layerId_; // Layer ID
int channelId_; // Wire number
cmsdt::LATERAL_CASES laterality_; // LEFT, RIGHT, NONE

int timeCorrection_;
int tdcTimeStamp_;
int orbit_;
double payLoad_[cmsdt::PAYLOAD_ENTRIES];
};

typedef std::vector<DTPrimitive> DTPrimitives;
typedef std::shared_ptr<DTPrimitive> DTPrimitivePtr;
typedef std::vector<DTPrimitivePtr> DTPrimitivePtrs;

#endif
106 changes: 106 additions & 0 deletions L1Trigger/DTTriggerPhase2/interface/HoughGrouping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#ifndef L1Trigger_DTTriggerPhase2_HoughGrouping_h
#define L1Trigger_DTTriggerPhase2_HoughGrouping_h

// System / std headers
#include <memory>
#include <cstdlib>
#include <stdexcept>
#include <iostream>
#include <vector>

// Other headers
#include "L1Trigger/DTTriggerPhase2/interface/MuonPath.h"
#include "L1Trigger/DTTriggerPhase2/interface/DTprimitive.h"
#include "L1Trigger/DTTriggerPhase2/interface/MotherGrouping.h"

// ===============================================================================
// Class declarations
// ===============================================================================
struct ProtoCand {
unsigned short int nLayersWithHits_; // 0: # of layers with hits.
std::vector<bool> isThereHitInLayer_; // 1: # of hits of high quality (the expected line crosses the cell).
std::vector<bool>
isThereNeighBourHitInLayer_; // 2: # of hits of low quality (the expected line is in a neighbouring cell).
unsigned short int nHitsDiff_; // 3: absolute diff. between the number of hits in SL1 and SL3.
std::vector<double> xDistToPattern_; // 4: absolute distance to all hits of the segment.
DTPrimitives dtHits_; // 5: DTPrimitive of the candidate.
};

typedef std::pair<double, double> PointInPlane;
typedef std::vector<PointInPlane> PointsInPlane;
typedef std::tuple<double, double, unsigned short int> PointTuple;
typedef std::vector<PointTuple> PointTuples;
typedef std::map<unsigned short int, double> PointMap;

class HoughGrouping : public MotherGrouping {
public:
// Constructors and destructor
HoughGrouping(const edm::ParameterSet& pset, edm::ConsumesCollector& iC);
~HoughGrouping() override;

// Main methods
void initialise(const edm::EventSetup& iEventSetup) override;
void run(edm::Event& iEvent,
const edm::EventSetup& iEventSetup,
const DTDigiCollection& digis,
MuonPathPtrs& outMpath) override;
void finish() override;

// Other public methods
// Public attributes

private:
// Private methods
void resetAttributes();
void resetPosElementsOfLinespace();

void obtainGeometricalBorders(const DTLayer* lay);

void doHoughTransform();

PointsInPlane getMaximaVector();
PointsInPlane findTheMaxima(PointTuples& inputvec);

PointInPlane getTwoDelta(const PointTuple& pair1, const PointTuple& pair2);
PointInPlane getAveragePoint(const PointTuples& inputvec,
unsigned short int firstindex,
const std::vector<unsigned short int>& indexlist);
PointInPlane transformPair(const PointInPlane& inputpair);

ProtoCand associateHits(const DTChamber* thechamb, double m, double n);

void orderAndFilter(std::vector<ProtoCand>& invector, MuonPathPtrs& outMuonPath);

void setDifferenceBetweenSL(ProtoCand& tupl);
bool areThereEnoughHits(const ProtoCand& tupl);

// Private attributes
bool debug_, allowUncorrelatedPatterns_;
unsigned short int minNLayerHits_, minSingleSLHitsMax_, minSingleSLHitsMin_, minUncorrelatedHits_, upperNumber_,
lowerNumber_;
double angletan_, anglebinwidth_, posbinwidth_, maxdeltaAngDeg_, maxdeltaPos_, maxDistanceToWire_;

DTGeometry const* dtGeo_;
edm::ESGetToken<DTGeometry, MuonGeometryRecord> dtGeomH;
DTChamberId TheChambId;

double maxrads_, minangle_, oneanglebin_;
double xlowlim_, xhighlim_, zlowlim_, zhighlim_;
double maxdeltaAng_;

unsigned short int anglebins_, halfanglebins_, spacebins_;
unsigned short int idigi_, nhits_;
unsigned short int thestation_, thesector_;
short int thewheel_;

std::vector<std::vector<unsigned short int>> linespace_;

PointMap anglemap_;
PointMap posmap_;
std::map<unsigned short int, DTPrimitive> digimap_[8];

PointsInPlane maxima_;
PointsInPlane hitvec_;
};

#endif
Loading