CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  // Get masked- and dead-strip information from file
33  applyMasking_ = config.getParameter<bool>("applyMasking");
34  if (applyMasking_) {
35  if (config.existsAs<edm::FileInPath>("maskFile")) {
36  maskSource_ = MaskSource::File;
37  std::ifstream inputFile(config.getParameter<edm::FileInPath>("maskFile").fullPath());
38  if (!inputFile) {
39  throw cms::Exception("GEMRecHitProducer") << "Masked Strips File cannot not be opened";
40  }
41  theGEMMaskedStripsObj = std::make_unique<GEMMaskedStrips>();
42  while (inputFile.good()) {
44  inputFile >> Item.rawId >> Item.strip;
45  if (inputFile.good())
46  theGEMMaskedStripsObj->fillMaskVec(Item);
47  }
48  inputFile.close();
49  }
50 
51  if (config.existsAs<edm::FileInPath>("deadFile")) {
52  deadSource_ = MaskSource::File;
53  std::ifstream inputFile(config.getParameter<edm::FileInPath>("deadFile").fullPath());
54  if (!inputFile) {
55  throw cms::Exception("GEMRecHitProducer") << "Dead Strips File cannot not be opened";
56  }
57  theGEMDeadStripsObj = std::make_unique<GEMDeadStrips>();
58  while (inputFile.good()) {
60  inputFile >> Item.rawId >> Item.strip;
61  if (inputFile.good())
62  theGEMDeadStripsObj->fillDeadVec(Item);
63  }
64  inputFile.close();
65  }
66  if (maskSource_ == MaskSource::EventSetup) {
67  maskedStripsToken_ = esConsumes<GEMMaskedStrips, GEMMaskedStripsRcd, edm::Transition::BeginRun>();
68  }
69  if (deadSource_ == MaskSource::EventSetup) {
70  deadStripsToken_ = esConsumes<GEMDeadStrips, GEMDeadStripsRcd, edm::Transition::BeginRun>();
71  }
72  }
73 }
74 
76 
79  edm::ParameterSetDescription recAlgoConfigDesc;
80  desc.add<edm::ParameterSetDescription>("recAlgoConfig", recAlgoConfigDesc);
81  desc.add<std::string>("recAlgo", "GEMRecHitStandardAlgo");
82  desc.add<edm::InputTag>("gemDigiLabel", edm::InputTag("muonGEMDigis"));
83  desc.add<bool>("applyMasking", false);
84  desc.addOptional<edm::FileInPath>("maskFile");
85  desc.addOptional<edm::FileInPath>("deadFile");
86  descriptions.add("gemRecHitsDef", desc);
87 }
88 
90  // Get the GEM Geometry
92 
93  if (applyMasking_) {
94  // Getting the masked-strip information
96  edm::ESHandle<GEMMaskedStrips> readoutMaskedStrips = setup.getHandle(maskedStripsToken_);
97  theGEMMaskedStripsObj = std::make_unique<GEMMaskedStrips>(*readoutMaskedStrips.product());
98  }
99  // Getting the dead-strip information
101  edm::ESHandle<GEMDeadStrips> readoutDeadStrips = setup.getHandle(deadStripsToken_);
102  theGEMDeadStripsObj = std::make_unique<GEMDeadStrips>(*readoutDeadStrips.product());
103  }
104 
105  for (auto gems : gemGeom_->etaPartitions()) {
106  // Getting the EtaPartitionMask mask, that includes dead strips, for the given GEMDet
107  GEMDetId gemId = gems->id();
108  EtaPartitionMask mask;
109  const int rawId = gemId.rawId();
110  for (const auto& tomask : theGEMMaskedStripsObj->getMaskVec()) {
111  if (tomask.rawId == rawId) {
112  const int bit = tomask.strip;
113  mask.set(bit);
114  }
115  }
116  for (const auto& tomask : theGEMDeadStripsObj->getDeadVec()) {
117  if (tomask.rawId == rawId) {
118  const int bit = tomask.strip;
119  mask.set(bit);
120  }
121  }
122  // add to masking map if masking present in etaPartition
123  if (mask.any()) {
124  gemMask_.emplace(gemId, mask);
125  }
126  }
127  }
128 }
129 
131  // Get the digis from the event
133  event.getByToken(theGEMDigiToken, digis);
134 
135  // Pass the EventSetup to the algo
136  theAlgo->setES(setup);
137 
138  // Create the pointer to the collection which will store the rechits
139  auto recHitCollection = std::make_unique<GEMRecHitCollection>();
140 
141  // Iterate through all digi collections ordered by LayerId
142  for (auto gemdgIt = digis->begin(); gemdgIt != digis->end(); ++gemdgIt) {
143  // The layerId
144  const GEMDetId& gemId = (*gemdgIt).first;
145 
146  // Get the GeomDet from the setup
147  const GEMEtaPartition* roll = gemGeom_->etaPartition(gemId);
148  if (roll == nullptr) {
149  edm::LogError("BadDigiInput") << "Failed to find GEMEtaPartition for ID " << gemId;
150  continue;
151  }
152 
153  // Get the iterators over the digis associated with this LayerId
154  const GEMDigiCollection::Range& range = (*gemdgIt).second;
155 
156  // get mask from map
157  EtaPartitionMask mask;
158  if (applyMasking_) {
159  auto gemmaskIt = gemMask_.find(gemId);
160  if (gemmaskIt != gemMask_.end())
161  mask = gemmaskIt->second;
162  }
163 
164  // Call the reconstruction algorithm
165  OwnVector<GEMRecHit> recHits = theAlgo->reconstruct(*roll, gemId, range, mask);
166 
167  if (!recHits.empty()) //FIXME: is it really needed?
168  recHitCollection->put(gemId, recHits.begin(), recHits.end());
169  }
170 
171  event.put(std::move(recHitCollection));
172 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
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.
enum GEMRecHitProducer::MaskSource deadSource_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Log< level::Error, false > LogError
const uint16_t range(const Frame &aFrame)
iterator begin()
Definition: OwnVector.h:280
edm::ESGetToken< GEMDeadStrips, GEMDeadStripsRcd > deadStripsToken_
bool empty() const
Definition: OwnVector.h:305
def move
Definition: eostools.py:511
edm::ESHandle< GEMGeometry > gemGeom_
std::unique_ptr< GEMDeadStrips > theGEMDeadStripsObj
std::bitset< maskSIZE > EtaPartitionMask
std::map< GEMDetId, EtaPartitionMask > gemMask_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > gemGeomToken_
std::unique_ptr< GEMMaskedStrips > theGEMMaskedStripsObj
~GEMRecHitProducer() override
Destructor.
iterator end()
Definition: OwnVector.h:285
std::pair< const_iterator, const_iterator > Range
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
enum GEMRecHitProducer::MaskSource maskSource_
tuple config
parse the configuration file
std::string fullPath() const
Definition: FileInPath.cc:161
std::unique_ptr< GEMRecHitBaseAlgo > theAlgo
#define get
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
Definition: Run.h:45
edm::EDGetTokenT< GEMDigiCollection > theGEMDigiToken
void beginRun(const edm::Run &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)