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

Revisit usage of HitPattern in DataFormats/Scouting #37149

Merged
merged 6 commits into from Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion DataFormats/Scouting/BuildFile.xml
@@ -1,4 +1,3 @@
<use name="DataFormats/TrackReco"/>
<use name="DataFormats/Common"/>
<export>
<lib name="1"/>
Expand Down
18 changes: 18 additions & 0 deletions DataFormats/Scouting/interface/Run3ScoutingHitPatternPOD.h
@@ -0,0 +1,18 @@
#ifndef DataFormats_Scouting_Run3ScoutingHitPatternPOD_h
#define DataFormats_Scouting_Run3ScoutingHitPatternPOD_h

#include <vector>
#include <cstdint>

struct Run3ScoutingHitPatternPOD {
uint8_t hitCount;
uint8_t beginTrackHits;
uint8_t endTrackHits;
uint8_t beginInner;
uint8_t endInner;
uint8_t beginOuter;
uint8_t endOuter;
std::vector<uint16_t> hitPattern;
};

#endif
18 changes: 9 additions & 9 deletions DataFormats/Scouting/interface/Run3ScoutingMuon.h
@@ -1,8 +1,8 @@
#ifndef DataFormats_Run3ScoutingMuon_h
#define DataFormats_Run3ScoutingMuon_h
#ifndef DataFormats_Scouting_Run3ScoutingMuon_h
#define DataFormats_Scouting_Run3ScoutingMuon_h

#include <vector>
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/Scouting/interface/Run3ScoutingHitPatternPOD.h"

// Class for holding muon information, for use in data scouting
// IMPORTANT: the content of this class should be changed only in backwards compatible ways!
Expand Down Expand Up @@ -63,8 +63,8 @@ class Run3ScoutingMuon {
float trk_vx,
float trk_vy,
float trk_vz,
reco::HitPattern trk_hitPattern,
std::vector<int> vtxIndx)
std::vector<int> vtxIndx,
Run3ScoutingHitPatternPOD trk_hitPattern)
: pt_(pt),
eta_(eta),
phi_(phi),
Expand Down Expand Up @@ -119,8 +119,8 @@ class Run3ScoutingMuon {
trk_vx_(trk_vx),
trk_vy_(trk_vy),
trk_vz_(trk_vz),
trk_hitPattern_(trk_hitPattern),
vtxIndx_(std::move(vtxIndx)) {}
vtxIndx_(std::move(vtxIndx)),
trk_hitPattern_(trk_hitPattern) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the std::vector member this would avoid one copy of it with std::move

Suggested change
trk_hitPattern_(trk_hitPattern) {}
trk_hitPattern_(std::move(trk_hitPattern)) {}

(sorry for noticing only now, I'm fine with a follow-up PR for that given the time pressure)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update this PR right away, if it works too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qliphy @perrotta Do you have preferences (or shall we wait for ORP)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let have this PR merged now.
Please @mmasciov prepare a follow-up one-line PR with the proposed fix as soon as you can (even right after this one is merged on top of the master HEAD).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@perrotta, @makortel: done in PR #37176

//default constructor
Run3ScoutingMuon()
: pt_(0),
Expand Down Expand Up @@ -237,8 +237,8 @@ class Run3ScoutingMuon {
float trk_vx() const { return trk_vx_; }
float trk_vy() const { return trk_vy_; }
float trk_vz() const { return trk_vz_; }
reco::HitPattern const& trk_hitPattern() const { return trk_hitPattern_; }
std::vector<int> const& vtxIndx() const { return vtxIndx_; }
Run3ScoutingHitPatternPOD const& trk_hitPattern() const { return trk_hitPattern_; }

private:
float pt_;
Expand Down Expand Up @@ -295,8 +295,8 @@ class Run3ScoutingMuon {
float trk_vx_;
float trk_vy_;
float trk_vz_;
reco::HitPattern trk_hitPattern_;
std::vector<int> vtxIndx_;
Run3ScoutingHitPatternPOD trk_hitPattern_;
};

typedef std::vector<Run3ScoutingMuon> Run3ScoutingMuonCollection;
Expand Down
1 change: 1 addition & 0 deletions DataFormats/Scouting/src/classes.h
Expand Up @@ -7,6 +7,7 @@
#include "DataFormats/Scouting/interface/ScoutingMuon.h"
#include "DataFormats/Scouting/interface/ScoutingPhoton.h"
#include "DataFormats/Scouting/interface/Run3ScoutingCaloJet.h"
#include "DataFormats/Scouting/interface/Run3ScoutingHitPatternPOD.h"
#include "DataFormats/Scouting/interface/Run3ScoutingPFJet.h"
#include "DataFormats/Scouting/interface/Run3ScoutingParticle.h"
#include "DataFormats/Scouting/interface/Run3ScoutingTrack.h"
Expand Down
6 changes: 5 additions & 1 deletion DataFormats/Scouting/src/classes_def.xml
Expand Up @@ -44,8 +44,9 @@
<version ClassVersion="3" checksum="1086011373"/>
<version ClassVersion="4" checksum="1250202632"/>
</class>
<class name="Run3ScoutingMuon" ClassVersion="3">
<class name="Run3ScoutingMuon" ClassVersion="4">
<version ClassVersion="3" checksum="3882497397"/>
<version ClassVersion="4" checksum="4206297195"/>
</class>
<class name="Run3ScoutingPhoton" ClassVersion="4">
<version ClassVersion="3" checksum="1683146807"/>
Expand All @@ -54,6 +55,9 @@
<class name="Run3ScoutingTrack" ClassVersion="3">
<version ClassVersion="3" checksum="3352318277"/>
</class>
<class name="Run3ScoutingHitPatternPOD" ClassVersion="3">
<version ClassVersion="3" checksum="1448115564"/>
</class>
<class name="std::vector<ScoutingCaloJet>"/>
<class name="std::vector<ScoutingPFJet>"/>
<class name="std::vector<ScoutingParticle>"/>
Expand Down
1 change: 1 addition & 0 deletions DataFormats/TrackReco/BuildFile.xml
Expand Up @@ -6,6 +6,7 @@
<use name="DataFormats/GeometryVector"/>
<use name="DataFormats/Math"/>
<use name="DataFormats/MuonDetId"/>
<use name="DataFormats/Scouting"/>
<use name="DataFormats/SiPixelCluster"/>
<use name="DataFormats/SiPixelDetId"/>
<use name="DataFormats/SiStripCluster"/>
Expand Down
6 changes: 6 additions & 0 deletions DataFormats/TrackReco/interface/HitPattern.h
Expand Up @@ -124,6 +124,7 @@
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
#include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
#include "DataFormats/ForwardDetId/interface/MTDDetId.h"
#include "DataFormats/Scouting/interface/Run3ScoutingHitPatternPOD.h"
mmasciov marked this conversation as resolved.
Show resolved Hide resolved
#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
#include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
#include "FWCore/Utilities/interface/Likely.h"
Expand Down Expand Up @@ -229,6 +230,8 @@ namespace reco {

HitPattern(const HitPattern &other);

HitPattern(const Run3ScoutingHitPatternPOD &other);

HitPattern &operator=(const HitPattern &other);

template <typename I>
Expand Down Expand Up @@ -424,6 +427,9 @@ namespace reco {
int numberOfDTStationsWithRZView() const;
int numberOfDTStationsWithBothViews() const;

// fill Run3ScoutingHitPatternPOD struct
Run3ScoutingHitPatternPOD run3ScoutingHitPatternPOD() const;

//only used by ROOT IO rule to read v12 HitPatterns
static bool fillNewHitPatternWithOldHitPattern_v12(const uint16_t oldHitPattern[],
uint8_t hitCount,
Expand Down
26 changes: 26 additions & 0 deletions DataFormats/TrackReco/src/HitPattern.cc
Expand Up @@ -32,6 +32,19 @@ HitPattern::HitPattern(const HitPattern& other)
memcpy(this->hitPattern, other.hitPattern, sizeof(uint16_t) * HitPattern::ARRAY_LENGTH);
}

HitPattern::HitPattern(const Run3ScoutingHitPatternPOD& other)
: hitCount(other.hitCount),
beginTrackHits(other.beginTrackHits),
endTrackHits(other.endTrackHits),
beginInner(other.beginInner),
endInner(other.endInner),
beginOuter(other.beginOuter),
endOuter(other.endOuter) {
const unsigned short max_vector_length =
(other.hitPattern.size() > HitPattern::ARRAY_LENGTH) ? HitPattern::ARRAY_LENGTH : other.hitPattern.size();
std::copy(other.hitPattern.begin(), other.hitPattern.begin() + max_vector_length, this->hitPattern);
}

HitPattern::~HitPattern() { ; }

HitPattern& HitPattern::operator=(const HitPattern& other) {
Expand Down Expand Up @@ -1013,3 +1026,16 @@ bool HitPattern::insertExpectedOuterHit(const uint16_t pattern) {

return true;
}

Run3ScoutingHitPatternPOD HitPattern::run3ScoutingHitPatternPOD() const {
Run3ScoutingHitPatternPOD result{
.hitCount = hitCount,
.beginTrackHits = beginTrackHits,
.endTrackHits = endTrackHits,
.beginInner = beginInner,
.endInner = endInner,
.beginOuter = beginOuter,
.endOuter = endOuter,
.hitPattern = std::vector<uint16_t>(hitPattern, hitPattern + HitPattern::ARRAY_LENGTH)};
return result;
}
4 changes: 2 additions & 2 deletions HLTrigger/Muon/plugins/HLTScoutingMuonProducer.cc
Expand Up @@ -284,8 +284,8 @@ void HLTScoutingMuonProducer::produce(edm::StreamID sid, edm::Event& iEvent, edm
track->vx(),
track->vy(),
track->vz(),
track->hitPattern(),
vtxInd);
vtxInd,
track->hitPattern().run3ScoutingHitPatternPOD());
vtxInd.clear();
}

Expand Down
1 change: 1 addition & 0 deletions HLTrigger/Muon/plugins/HLTScoutingMuonProducer.h
Expand Up @@ -39,6 +39,7 @@ Description: Producer for Run3ScoutingMuon
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"

#include "DataFormats/Scouting/interface/Run3ScoutingHitPatternPOD.h"
#include "DataFormats/Scouting/interface/Run3ScoutingMuon.h"
#include "DataFormats/Scouting/interface/Run3ScoutingVertex.h"

Expand Down