CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RechitClusterProducer.cc
Go to the documentation of this file.
1 #include <map>
2 #include <memory>
3 #include <string>
4 #include <utility>
5 #include <vector>
38 #include "fastjet/ClusterSequence.hh"
39 #include "fastjet/JetDefinition.hh"
40 #include "fastjet/PseudoJet.hh"
41 
42 typedef std::vector<reco::MuonRecHitCluster> RecHitClusterCollection;
43 
44 template <typename Trait>
46  typedef typename Trait::RecHitRef RechitRef;
47  typedef typename Trait::RecHitRefVector RecHitRefVector;
48 
49 public:
51  ~RechitClusterProducerT() override = default;
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55 private:
56  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
59  typedef std::vector<reco::MuonRecHitCluster> RecHitClusterCollection;
60 
61  const double rParam_; // distance paramter
62  const int nRechitMin_; // min number of rechits
63  const int nStationThres_; // min number of rechits to count towards nStation
64 };
65 
66 template <typename Trait>
68  : geometryToken_(esConsumes<typename Trait::GeometryType, MuonGeometryRecord>()),
69  inputToken_(consumes<typename Trait::InputType>(iConfig.getParameter<edm::InputTag>("recHitLabel"))),
70  rParam_(iConfig.getParameter<double>("rParam")),
71  nRechitMin_(iConfig.getParameter<int>("nRechitMin")),
72  nStationThres_(iConfig.getParameter<int>("nStationThres")) {
73  produces<RecHitClusterCollection>();
74 }
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called to produce the data ------------
81 template <typename Trait>
83  auto const& geo = iSetup.getData(geometryToken_);
84  auto const& rechits = ev.get(inputToken_);
85 
86  std::vector<fastjet::PseudoJet> fjInput;
88 
89  fastjet::JetDefinition jet_def(fastjet::cambridge_algorithm, rParam_);
90 
91  Trait recHitTrait;
92 
93  int recIt = 0;
94  for (auto const& rechit : rechits) {
95  LocalPoint recHitLocalPosition = rechit.localPosition();
96  auto detid = recHitTrait.detid(rechit);
97  auto thischamber = geo.chamber(detid);
98  if (thischamber) {
99  GlobalPoint globalPosition = thischamber->toGlobal(recHitLocalPosition);
100  float x = globalPosition.x();
101  float y = globalPosition.y();
102  float z = globalPosition.z();
103  RechitRef ref = RechitRef(&rechits, recIt);
104  inputs.push_back(ref);
105  fjInput.push_back(fastjet::PseudoJet(x, y, z, globalPosition.mag()));
106  fjInput.back().set_user_index(recIt);
107  }
108  recIt++;
109  }
110  fastjet::ClusterSequence clus_seq(fjInput, jet_def);
111 
112  //keep all the clusters
113  double ptmin = 0.0;
114  std::vector<fastjet::PseudoJet> fjJets = clus_seq.inclusive_jets(ptmin);
115 
116  auto clusters = std::make_unique<RecHitClusterCollection>();
117  for (auto const& fjJet : fjJets) {
118  // skip if the cluster has too few rechits
119  if (int(fjJet.constituents().size()) < nRechitMin_)
120  continue;
121  // get the constituents from fastjet
123  for (auto const& constituent : fjJet.constituents()) {
124  auto index = constituent.user_index();
125  if (index >= 0 && static_cast<unsigned int>(index) < inputs.size()) {
126  rechits.push_back(inputs[index]);
127  }
128  }
129 
130  //Derive cluster properties
131  int nStation = 0;
132  int totStation = 0;
133  float avgStation = 0.0;
134  std::map<int, int> station_count_map;
135  for (auto const& rechit : rechits) {
136  station_count_map[recHitTrait.station(*rechit)]++;
137  }
138  //station statistics
139  std::map<int, int>::iterator it;
140  for (auto const& [station, count] : station_count_map) {
141  if (count >= nStationThres_) {
142  nStation++;
143  avgStation += station * count;
144  totStation += count;
145  }
146  }
147  if (totStation != 0) {
148  avgStation = avgStation / totStation;
149  }
150  float invN = 1.f / rechits.size();
151  // cluster position is the average position of the constituent rechits
152  float jetX = fjJet.px() * invN;
153  float jetY = fjJet.py() * invN;
154  float jetZ = fjJet.pz() * invN;
155 
157  std::sqrt(jetX * jetX + jetY * jetY), etaFromXYZ(jetX, jetY, jetZ), std::atan2(jetY, jetX));
158  Trait::emplace_back(clusters.get(), position, nStation, avgStation, rechits);
159  }
160  ev.put(std::move(clusters));
161 }
162 
163 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
164 template <typename Trait>
167  desc.add<int>("nRechitMin", 50);
168  desc.add<double>("rParam", 0.4);
169  desc.add<int>("nStationThres", 10);
170  desc.add<edm::InputTag>("recHitLabel", edm::InputTag(Trait::recHitLabel()));
171  descriptions.add(Trait::producerName(), desc);
172 }
178  static std::string recHitLabel() { return "dt1DRecHits"; }
179  static std::string producerName() { return "dtRechitClusterProducer"; }
180 
181  static int station(const DTRecHit1DPair& dtRechit) { return detid(dtRechit).station(); }
182  static DTChamberId detid(const DTRecHit1DPair& dtRechit) {
183  DetId geoid = dtRechit.geographicalId();
184  DTChamberId dtdetid = DTChamberId(geoid);
185  return dtdetid;
186  }
189  int nStation,
190  float avgStation,
191  RecHitRefVector const& rechits) {
192  // compute nMB1, nMB2
193  int nMB1 = 0;
194  int nMB2 = 0;
195  for (auto const& rechit : rechits) {
196  DetId geoid = rechit->geographicalId();
197  DTChamberId dtdetid = DTChamberId(geoid);
198  if (dtdetid.station() == 1)
199  nMB1++;
200  if (dtdetid.station() == 2)
201  nMB2++;
202  }
203  //set time, timespread, nME11,nME12 to 0
204  reco::MuonRecHitCluster cls(position, rechits.size(), nStation, avgStation, 0.0, 0.0, 0, 0, 0, 0, nMB1, nMB2);
205  clusters->emplace_back(cls);
206  }
207 };
208 
214  static std::string recHitLabel() { return "csc2DRecHits"; }
215  static std::string producerName() { return "cscRechitClusterProducer"; }
216 
217  static int station(const CSCRecHit2D& cscRechit) { return CSCDetId::station(detid(cscRechit)); }
218  static CSCDetId detid(const CSCRecHit2D& cscRechit) { return cscRechit.cscDetId(); }
221  int nStation,
222  float avgStation,
223  RecHitRefVector const& rechits) {
224  int nME11 = 0;
225  int nME12 = 0;
226  int nME41 = 0;
227  int nME42 = 0;
228  float timeSpread = 0.0;
229  float time = 0.0;
230  float time_strip = 0.0; // for timeSpread calculation
231  for (auto const& rechit : rechits) {
232  CSCDetId cscdetid = rechit->cscDetId();
233  int stationRing = (CSCDetId::station(cscdetid) * 10 + CSCDetId::ring(cscdetid));
234  if (CSCDetId::ring(cscdetid) == 4)
235  stationRing = (CSCDetId::station(cscdetid) * 10 + 1); // ME1/a has ring==4
236  if (stationRing == 11)
237  nME11++;
238  if (stationRing == 12)
239  nME12++;
240  if (stationRing == 41)
241  nME41++;
242  if (stationRing == 42)
243  nME42++;
244  time += (rechit->tpeak() + rechit->wireTime());
245  time_strip += rechit->tpeak();
246  }
247  float invN = 1.f / rechits.size();
248  time = (time / 2.f) * invN;
249  time_strip = time_strip * invN;
250 
251  //derive cluster statistics
252  for (auto& rechit : rechits) {
253  timeSpread += (rechit->tpeak() - time_strip) * (rechit->tpeak() - time_strip);
254  }
255  timeSpread = std::sqrt(timeSpread * invN);
256 
257  //set nMB1,nMB2 to 0
259  position, rechits.size(), nStation, avgStation, time, timeSpread, nME11, nME12, nME41, nME42, 0, 0);
260  clusters->emplace_back(cls);
261  }
262 };
263 
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::ESGetToken< typename Trait::GeometryType, MuonGeometryRecord > geometryToken_
InputType
Definition: InputType.h:5
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< reco::MuonRecHitCluster > RecHitClusterCollection
CSCDetId cscDetId() const
Definition: CSCRecHit2D.h:58
edm::RangeMap< DTLayerId, edm::OwnVector< DTRecHit1DPair > > DTRecHitCollection
JetDefinition jet_def
edm::RangeMap< CSCDetId, edm::OwnVector< CSCRecHit2D > > CSCRecHit2DCollection
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static std::string producerName()
static DTChamberId detid(const DTRecHit1DPair &dtRechit)
T y() const
Definition: PV3DBase.h:60
static int station(const CSCRecHit2D &cscRechit)
static CSCDetId detid(const CSCRecHit2D &cscRechit)
float float float z
ROOT::Math::DisplacementVector3D< ROOT::Math::CylindricalEta3D< float > > RhoEtaPhiVectorF
spatial vector with cylindrical internal representation using pseudorapidity
Definition: Vector3D.h:18
static void emplace_back(RecHitClusterCollection *clusters, math::RhoEtaPhiVectorF const &position, int nStation, float avgStation, RecHitRefVector const &rechits)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
T mag() const
Definition: PV3DBase.h:64
virtual DetId geographicalId() const
Return the detId of the Det (a DTLayer).
static std::string producerName()
T sqrt(T t)
Definition: SSEVec.h:19
RechitClusterProducerT(const edm::ParameterSet &)
T z() const
Definition: PV3DBase.h:61
def move
Definition: eostools.py:511
~RechitClusterProducerT() override=default
static std::string recHitLabel()
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
std::vector< reco::MuonRecHitCluster > RecHitClusterCollection
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Trait::RecHitRefVector RecHitRefVector
int ring() const
Definition: CSCDetId.h:68
Definition: DetId.h:17
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double ptmin
Definition: HydjetWrapper.h:84
static int position[264][3]
Definition: ReadPGInfo.cc:289
edm::EDGetTokenT< typename Trait::InputType > inputToken_
float x
int station() const
Definition: CSCDetId.h:79
int station() const
Return the station number.
Definition: DTChamberId.h:42
T x() const
Definition: PV3DBase.h:59
static void emplace_back(RecHitClusterCollection *clusters, math::RhoEtaPhiVectorF const &position, int nStation, float avgStation, RecHitRefVector const &rechits)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static int station(const DTRecHit1DPair &dtRechit)
static std::string recHitLabel()