CMS 3D CMS Logo

GEMRecHitProducer.cc
Go to the documentation of this file.
1 
6 
11 
14 
18 
19 #include <string>
20 #include <fstream>
21 
22 using namespace edm;
23 using namespace std;
24 
26  : theGEMDigiToken(consumes<GEMDigiCollection>(config.getParameter<InputTag>("gemDigiLabel"))),
27  // Get the concrete reconstruction algo from the factory
28  theAlgo{GEMRecHitAlgoFactory::get()->create(config.getParameter<string>("recAlgo"),
29  config.getParameter<ParameterSet>("recAlgoConfig"))},
32  produces<GEMRecHitCollection>();
33 
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")) {
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")) {
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  }
69 }
70 
72 
75  edm::ParameterSetDescription recAlgoConfigDesc;
76  desc.add<edm::ParameterSetDescription>("recAlgoConfig", recAlgoConfigDesc);
77  desc.add<std::string>("recAlgo", "GEMRecHitStandardAlgo");
78  desc.add<edm::InputTag>("gemDigiLabel", edm::InputTag("muonGEMDigis"));
79  desc.add<bool>("applyMasking", false);
80  desc.addOptional<edm::FileInPath>("maskFile");
81  desc.addOptional<edm::FileInPath>("deadFile");
82  descriptions.add("gemRecHitsDef", desc);
83 }
84 
86  // Get the GEM Geometry
87  setup.get<MuonGeometryRecord>().get(gemGeom_);
88 
89  if (applyMasking_) {
90  // Getting the masked-strip information
92  edm::ESHandle<GEMMaskedStrips> readoutMaskedStrips;
93  setup.get<GEMMaskedStripsRcd>().get(readoutMaskedStrips);
94  theGEMMaskedStripsObj = std::make_unique<GEMMaskedStrips>(*readoutMaskedStrips.product());
95  }
96  // Getting the dead-strip information
98  edm::ESHandle<GEMDeadStrips> readoutDeadStrips;
99  setup.get<GEMDeadStripsRcd>().get(readoutDeadStrips);
100  theGEMDeadStripsObj = std::make_unique<GEMDeadStrips>(*readoutDeadStrips.product());
101  }
102 
103  for (auto gems : gemGeom_->etaPartitions()) {
104  // Getting the EtaPartitionMask mask, that includes dead strips, for the given GEMDet
105  GEMDetId gemId = gems->id();
106  EtaPartitionMask mask;
107  const int rawId = gemId.rawId();
108  for (const auto& tomask : theGEMMaskedStripsObj->getMaskVec()) {
109  if (tomask.rawId == rawId) {
110  const int bit = tomask.strip;
111  mask.set(bit);
112  }
113  }
114  for (const auto& tomask : theGEMDeadStripsObj->getDeadVec()) {
115  if (tomask.rawId == rawId) {
116  const int bit = tomask.strip;
117  mask.set(bit);
118  }
119  }
120  // add to masking map if masking present in etaPartition
121  if (mask.any()) {
122  gemMask_.emplace(gemId, mask);
123  }
124  }
125  }
126 }
127 
129  // Get the digis from the event
131  event.getByToken(theGEMDigiToken, digis);
132 
133  // Pass the EventSetup to the algo
134  theAlgo->setES(setup);
135 
136  // Create the pointer to the collection which will store the rechits
137  auto recHitCollection = std::make_unique<GEMRecHitCollection>();
138 
139  // Iterate through all digi collections ordered by LayerId
140  for (auto gemdgIt = digis->begin(); gemdgIt != digis->end(); ++gemdgIt) {
141  // The layerId
142  const GEMDetId& gemId = (*gemdgIt).first;
143 
144  // Get the GeomDet from the setup
145  const GEMEtaPartition* roll = gemGeom_->etaPartition(gemId);
146  if (roll == nullptr) {
147  edm::LogError("BadDigiInput") << "Failed to find GEMEtaPartition for ID " << gemId;
148  continue;
149  }
150 
151  // Get the iterators over the digis associated with this LayerId
152  const GEMDigiCollection::Range& range = (*gemdgIt).second;
153 
154  // get mask from map
155  EtaPartitionMask mask;
156  if (applyMasking_) {
157  auto gemmaskIt = gemMask_.find(gemId);
158  if (gemmaskIt != gemMask_.end())
159  mask = gemmaskIt->second;
160  }
161 
162  // Call the reconstruction algorithm
163  OwnVector<GEMRecHit> recHits = theAlgo->reconstruct(*roll, gemId, range, mask);
164 
165  if (!recHits.empty()) //FIXME: is it really needed?
166  recHitCollection->put(gemId, recHits.begin(), recHits.end());
167  }
168 
169  event.put(std::move(recHitCollection));
170 }
T getParameter(std::string const &) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
void produce(edm::Event &event, const edm::EventSetup &setup) override
The method which produces the rechits.
GEMRecHitProducer(const edm::ParameterSet &config)
Constructor.
enum GEMRecHitProducer::MaskSource deadSource_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Definition: config.py:1
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:77
iterator begin()
Definition: OwnVector.h:280
bool empty() const
Definition: OwnVector.h:305
edm::ESHandle< GEMGeometry > gemGeom_
std::unique_ptr< GEMDeadStrips > theGEMDeadStripsObj
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM eta partitions.
Definition: GEMGeometry.cc:40
std::bitset< maskSIZE > EtaPartitionMask
std::map< GEMDetId, EtaPartitionMask > gemMask_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< GEMMaskedStrips > theGEMMaskedStripsObj
~GEMRecHitProducer() override
Destructor.
iterator end()
Definition: OwnVector.h:285
std::pair< const_iterator, const_iterator > Range
void add(std::string const &label, ParameterSetDescription const &psetDescription)
enum GEMRecHitProducer::MaskSource maskSource_
HLT enums.
T get() const
Definition: EventSetup.h:73
std::string fullPath() const
Definition: FileInPath.cc:163
std::unique_ptr< GEMRecHitBaseAlgo > theAlgo
T const * product() const
Definition: ESHandle.h:86
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)