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  // 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
91  gemGeom_ = setup.getHandle(gemGeomToken_);
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 }
GEMRecHitProducer::MaskSource::EventSetup
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
GEMRecHitProducer::applyMasking_
bool applyMasking_
Definition: GEMRecHitProducer.h:67
MessageLogger.h
GEMRecHit.h
GEMRecHitProducer::deadSource_
enum GEMRecHitProducer::MaskSource deadSource_
GEMMaskedStrips::MaskItem
Definition: GEMMaskedStrips.h:10
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
GEMEtaPartition
Definition: GEMEtaPartition.h:12
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
GEMDeadStrips::DeadItem
Definition: GEMDeadStrips.h:10
GEMRecHitProducer::produce
void produce(edm::Event &event, const edm::EventSetup &setup) override
The method which produces the rechits.
Definition: GEMRecHitProducer.cc:130
GEMRecHitAlgoFactory.h
edm::Handle< GEMDigiCollection >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
config
Definition: config.py:1
edm::FileInPath
Definition: FileInPath.h:64
GEMEtaPartition.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::ESHandle
Definition: DTSurvey.h:22
GEMRecHitProducer::gemGeomToken_
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > gemGeomToken_
Definition: GEMRecHitProducer.h:60
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
edm::ParameterSet
Definition: ParameterSet.h:47
GEMRecHitProducer::gemGeom_
edm::ESHandle< GEMGeometry > gemGeom_
Definition: GEMRecHitProducer.h:58
GEMRecHitProducer::deadStripsToken_
edm::ESGetToken< GEMDeadStrips, GEMDeadStripsRcd > deadStripsToken_
Definition: GEMRecHitProducer.h:62
EtaPartitionMask
std::bitset< maskSIZE > EtaPartitionMask
Definition: GEMEtaPartitionMask.h:8
GEMMaskedStrips::MaskItem::strip
int strip
Definition: GEMMaskedStrips.h:12
GEMDetId
Definition: GEMDetId.h:18
GEMRecHitProducer::maskSource_
enum GEMRecHitProducer::MaskSource maskSource_
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
GEMRecHitCollection.h
GEMRecHitProducer::theGEMDeadStripsObj
std::unique_ptr< GEMDeadStrips > theGEMDeadStripsObj
Definition: GEMRecHitProducer.h:54
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
GEMRecHitProducer::theGEMMaskedStripsObj
std::unique_ptr< GEMMaskedStrips > theGEMMaskedStripsObj
Definition: GEMRecHitProducer.h:51
get
#define get
GEMRecHitProducer::~GEMRecHitProducer
~GEMRecHitProducer() override
Destructor.
alignCSCRings.r
r
Definition: alignCSCRings.py:93
GEMRecHitProducer::gemMask_
std::map< GEMDetId, EtaPartitionMask > gemMask_
Definition: GEMRecHitProducer.h:65
VtxSmearedBeamProfile_cfi.File
File
Definition: VtxSmearedBeamProfile_cfi.py:30
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
GEMDetId.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
GEMDigiCollection
Exception
Definition: hltDiff.cc:245
GEMRecHitProducer::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: GEMRecHitProducer.cc:89
GEMRecHitProducer::theGEMDigiToken
edm::EDGetTokenT< GEMDigiCollection > theGEMDigiToken
Definition: GEMRecHitProducer.h:45
MuonDigiCollection::Range
std::pair< const_iterator, const_iterator > Range
Definition: MuonDigiCollection.h:95
GEMRecHitProducer.h
GEMGeometry::etaPartitions
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM eta partitions.
Definition: GEMGeometry.cc:40
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
GEMRecHitProducer::maskedStripsToken_
edm::ESGetToken< GEMMaskedStrips, GEMMaskedStripsRcd > maskedStripsToken_
Definition: GEMRecHitProducer.h:61
GEMDeadStrips::DeadItem::rawId
int rawId
Definition: GEMDeadStrips.h:11
GEMRecHitProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: GEMRecHitProducer.cc:77
edm::InputTag
Definition: InputTag.h:15
GEMRecHitProducer::GEMRecHitProducer
GEMRecHitProducer(const edm::ParameterSet &config)
Constructor.
Definition: GEMRecHitProducer.cc:22
GEMDeadStrips::DeadItem::strip
int strip
Definition: GEMDeadStrips.h:12
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
edm::OwnVector
Definition: OwnVector.h:24
GEMMaskedStrips::MaskItem::rawId
int rawId
Definition: GEMMaskedStrips.h:11
GEMGeometry::etaPartition
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:77
GEMRecHitProducer::theAlgo
std::unique_ptr< GEMRecHitBaseAlgo > theAlgo
Definition: GEMRecHitProducer.h:48