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"))},
30  maskSource_(MaskSource::EventSetup),
31  deadSource_(MaskSource::EventSetup) {
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")) {
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  }
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
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 }
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:59
GEMDeadStripsRcd
Definition: GEMDeadStripsRcd.h:6
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
MessageLogger.h
GEMRecHit.h
GEMRecHitProducer::deadSource_
enum GEMRecHitProducer::MaskSource deadSource_
GEMMaskedStripsRcd
Definition: GEMMaskedStripsRcd.h:6
GEMMaskedStrips::MaskItem
Definition: GEMMaskedStrips.h:10
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
GEMEtaPartition
Definition: GEMEtaPartition.h:12
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:128
GEMRecHitAlgoFactory.h
edm::Handle< GEMDigiCollection >
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
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
GEMDeadStripsRcd.h
edm::ESHandle
Definition: DTSurvey.h:22
GEMMaskedStripsRcd.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
GEMRecHitProducer::gemGeom_
edm::ESHandle< GEMGeometry > gemGeom_
Definition: GEMRecHitProducer.h:54
EtaPartitionMask
std::bitset< maskSIZE > EtaPartitionMask
Definition: GEMEtaPartitionMask.h:8
GEMMaskedStrips::MaskItem::strip
int strip
Definition: GEMMaskedStrips.h:12
GEMDetId
Definition: GEMDetId.h:17
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:50
edm::EventSetup
Definition: EventSetup.h:57
GEMRecHitProducer::theGEMMaskedStripsObj
std::unique_ptr< GEMMaskedStrips > theGEMMaskedStripsObj
Definition: GEMRecHitProducer.h:47
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:57
VtxSmearedBeamProfile_cfi.File
File
Definition: VtxSmearedBeamProfile_cfi.py:30
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:246
GEMRecHitProducer::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: GEMRecHitProducer.cc:85
GEMRecHitProducer::theGEMDigiToken
edm::EDGetTokenT< GEMDigiCollection > theGEMDigiToken
Definition: GEMRecHitProducer.h:41
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
MuonGeometryRecord.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
GEMDeadStrips::DeadItem::rawId
int rawId
Definition: GEMDeadStrips.h:11
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
GEMRecHitProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: GEMRecHitProducer.cc:73
edm::InputTag
Definition: InputTag.h:15
GEMRecHitProducer::GEMRecHitProducer
GEMRecHitProducer(const edm::ParameterSet &config)
Constructor.
Definition: GEMRecHitProducer.cc:25
GEMDeadStrips::DeadItem::strip
int strip
Definition: GEMDeadStrips.h:12
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
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:44