CMS 3D CMS Logo

GEMRecHitProducer.cc
Go to the documentation of this file.
1 
6 
10 
13 
15 
16 #include <string>
17 #include <fstream>
18 
19 using namespace edm;
20 using namespace std;
21 
23  : theGEMDigiToken(consumes<GEMDigiCollection>(config.getParameter<InputTag>("gemDigiLabel"))),
24  // Get the concrete reconstruction algo from the factory
25  theAlgo{GEMRecHitAlgoFactory::get()->create(config.getParameter<string>("recAlgo"),
26  config.getParameter<ParameterSet>("recAlgoConfig"))},
27  maskSource_(MaskSource::EventSetup),
28  deadSource_(MaskSource::EventSetup),
29  gemGeomToken_(esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>()) {
30  produces<GEMRecHitCollection>();
31 
32  // Turns off GE2/1 demonstrator reconstruction in Run3
33  ge21Off_ = config.getParameter<bool>("ge21Off");
34  // Get masked- and dead-strip information from file
35  applyMasking_ = config.getParameter<bool>("applyMasking");
36  if (applyMasking_) {
37  if (config.existsAs<edm::FileInPath>("maskFile")) {
38  maskSource_ = MaskSource::File;
39  std::ifstream inputFile(config.getParameter<edm::FileInPath>("maskFile").fullPath());
40  if (!inputFile) {
41  throw cms::Exception("GEMRecHitProducer") << "Masked Strips File cannot not be opened";
42  }
43  theGEMMaskedStripsObj = std::make_unique<GEMMaskedStrips>();
44  while (inputFile.good()) {
46  inputFile >> Item.rawId >> Item.strip;
47  if (inputFile.good())
48  theGEMMaskedStripsObj->fillMaskVec(Item);
49  }
50  inputFile.close();
51  }
52 
53  if (config.existsAs<edm::FileInPath>("deadFile")) {
54  deadSource_ = MaskSource::File;
55  std::ifstream inputFile(config.getParameter<edm::FileInPath>("deadFile").fullPath());
56  if (!inputFile) {
57  throw cms::Exception("GEMRecHitProducer") << "Dead Strips File cannot not be opened";
58  }
59  theGEMDeadStripsObj = std::make_unique<GEMDeadStrips>();
60  while (inputFile.good()) {
62  inputFile >> Item.rawId >> Item.strip;
63  if (inputFile.good())
64  theGEMDeadStripsObj->fillDeadVec(Item);
65  }
66  inputFile.close();
67  }
68  if (maskSource_ == MaskSource::EventSetup) {
69  maskedStripsToken_ = esConsumes<GEMMaskedStrips, GEMMaskedStripsRcd, edm::Transition::BeginRun>();
70  }
71  if (deadSource_ == MaskSource::EventSetup) {
72  deadStripsToken_ = esConsumes<GEMDeadStrips, GEMDeadStripsRcd, edm::Transition::BeginRun>();
73  }
74  }
75 }
76 
78 
81  edm::ParameterSetDescription recAlgoConfigDesc;
82  desc.add<edm::ParameterSetDescription>("recAlgoConfig", recAlgoConfigDesc);
83  desc.add<std::string>("recAlgo", "GEMRecHitStandardAlgo");
84  desc.add<edm::InputTag>("gemDigiLabel", edm::InputTag("muonGEMDigis"));
85  desc.add<bool>("applyMasking", false);
86  desc.add<bool>("ge21Off", false);
87  desc.addOptional<edm::FileInPath>("maskFile");
88  desc.addOptional<edm::FileInPath>("deadFile");
89  descriptions.add("gemRecHitsDef", desc);
90 }
91 
93  // Get the GEM Geometry
94  gemGeom_ = setup.getHandle(gemGeomToken_);
95 
96  if (applyMasking_) {
97  // Getting the masked-strip information
99  edm::ESHandle<GEMMaskedStrips> readoutMaskedStrips = setup.getHandle(maskedStripsToken_);
100  theGEMMaskedStripsObj = std::make_unique<GEMMaskedStrips>(*readoutMaskedStrips.product());
101  }
102  // Getting the dead-strip information
104  edm::ESHandle<GEMDeadStrips> readoutDeadStrips = setup.getHandle(deadStripsToken_);
105  theGEMDeadStripsObj = std::make_unique<GEMDeadStrips>(*readoutDeadStrips.product());
106  }
107 
108  for (auto gems : gemGeom_->etaPartitions()) {
109  // Getting the EtaPartitionMask mask, that includes dead strips, for the given GEMDet
110  GEMDetId gemId = gems->id();
111  if (ge21Off_ && gemId.station() == 2) {
112  continue;
113  }
115  const int rawId = gemId.rawId();
116  for (const auto& tomask : theGEMMaskedStripsObj->getMaskVec()) {
117  if (tomask.rawId == rawId) {
118  const int bit = tomask.strip;
119  mask.set(bit);
120  }
121  }
122  for (const auto& tomask : theGEMDeadStripsObj->getDeadVec()) {
123  if (tomask.rawId == rawId) {
124  const int bit = tomask.strip;
125  mask.set(bit);
126  }
127  }
128  // add to masking map if masking present in etaPartition
129  if (mask.any()) {
130  gemMask_.emplace(gemId, mask);
131  }
132  }
133  }
134 }
135 
137  // Get the digis from the event
139  event.getByToken(theGEMDigiToken, digis);
140 
141  // Pass the EventSetup to the algo
142  theAlgo->setES(setup);
143 
144  // Create the pointer to the collection which will store the rechits
145  auto recHitCollection = std::make_unique<GEMRecHitCollection>();
146 
147  // Iterate through all digi collections ordered by LayerId
148  for (auto gemdgIt = digis->begin(); gemdgIt != digis->end(); ++gemdgIt) {
149  // The layerId
150  const GEMDetId& gemId = (*gemdgIt).first;
151  if (ge21Off_ && gemId.station() == 2) {
152  continue;
153  }
154 
155  // Get the GeomDet from the setup
156  const GEMEtaPartition* roll = gemGeom_->etaPartition(gemId);
157  if (roll == nullptr) {
158  edm::LogError("BadDigiInput") << "Failed to find GEMEtaPartition for ID " << gemId;
159  continue;
160  }
161 
162  // Get the iterators over the digis associated with this LayerId
163  const GEMDigiCollection::Range& range = (*gemdgIt).second;
164 
165  // get mask from map
167  if (applyMasking_) {
168  auto gemmaskIt = gemMask_.find(gemId);
169  if (gemmaskIt != gemMask_.end())
170  mask = gemmaskIt->second;
171  }
172 
173  // Call the reconstruction algorithm
174  OwnVector<GEMRecHit> recHits = theAlgo->reconstruct(*roll, gemId, range, mask);
175 
176  if (!recHits.empty()) //FIXME: is it really needed?
177  recHitCollection->put(gemId, recHits.begin(), recHits.end());
178  }
179 
180  event.put(std::move(recHitCollection));
181 }
constexpr int station() const
Definition: GEMDetId.h:179
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:77
void produce(edm::Event &event, const edm::EventSetup &setup) override
The method which produces the rechits.
edm::ESGetToken< GEMMaskedStrips, GEMMaskedStripsRcd > maskedStripsToken_
GEMRecHitProducer(const edm::ParameterSet &config)
Constructor.
std::string fullPath() const
Definition: FileInPath.cc:161
enum GEMRecHitProducer::MaskSource deadSource_
Definition: config.py:1
Log< level::Error, false > LogError
constexpr uint32_t mask
Definition: gpuClustering.h:24
T const * product() const
Definition: ESHandle.h:86
edm::ESGetToken< GEMDeadStrips, GEMDeadStripsRcd > deadStripsToken_
edm::ESHandle< GEMGeometry > gemGeom_
std::unique_ptr< GEMDeadStrips > theGEMDeadStripsObj
std::bitset< maskSIZE > EtaPartitionMask
std::map< GEMDetId, EtaPartitionMask > gemMask_
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > gemGeomToken_
std::unique_ptr< GEMMaskedStrips > theGEMMaskedStripsObj
~GEMRecHitProducer() override
Destructor.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::pair< const_iterator, const_iterator > Range
void add(std::string const &label, ParameterSetDescription const &psetDescription)
enum GEMRecHitProducer::MaskSource maskSource_
HLT enums.
std::unique_ptr< GEMRecHitBaseAlgo > theAlgo
#define get
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45
edm::EDGetTokenT< GEMDigiCollection > theGEMDigiToken
void beginRun(const edm::Run &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM eta partitions.
Definition: GEMGeometry.cc:40