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"))},
31 {
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() ) theGEMMaskedStripsObj->fillMaskVec(Item);
48 
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() ) theGEMDeadStripsObj->fillDeadVec(Item);
64  }
65  inputFile.close();
66  }
67  }
68 }
69 
71 
73 {
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 {
87  // Get the GEM Geometry
88  setup.get<MuonGeometryRecord>().get(gemGeom_);
89 
90  if (applyMasking_) {
91  // Getting the masked-strip information
93  edm::ESHandle<GEMMaskedStrips> readoutMaskedStrips;
94  setup.get<GEMMaskedStripsRcd>().get(readoutMaskedStrips);
95  theGEMMaskedStripsObj = std::make_unique<GEMMaskedStrips>(*readoutMaskedStrips.product());
96  }
97  // Getting the dead-strip information
99  edm::ESHandle<GEMDeadStrips> readoutDeadStrips;
100  setup.get<GEMDeadStripsRcd>().get(readoutDeadStrips);
101  theGEMDeadStripsObj = std::make_unique<GEMDeadStrips>(*readoutDeadStrips.product());
102  }
103 
104  for (auto gems: gemGeom_->etaPartitions()) {
105  // Getting the EtaPartitionMask mask, that includes dead strips, for the given GEMDet
106  GEMDetId gemId = gems->id();
108  const int rawId = gemId.rawId();
109  for ( const auto& tomask : theGEMMaskedStripsObj->getMaskVec() ) {
110  if ( tomask.rawId == rawId ) {
111  const int bit = tomask.strip;
112  mask.set(bit-1);
113  }
114  }
115  for ( const auto& tomask : theGEMDeadStripsObj->getDeadVec() ) {
116  if ( tomask.rawId == rawId ) {
117  const int bit = tomask.strip;
118  mask.set(bit-1);
119  }
120  }
121  // add to masking map if masking present in etaPartition
122  if (mask.any()) {
123  gemMask_.emplace(gemId,mask);
124  }
125  }
126  }
127 }
128 
130 {
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
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 }
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:50
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
Definition: config.py:1
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:99
iterator begin()
Definition: OwnVector.h:244
bool empty() const
Definition: OwnVector.h:269
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:63
std::bitset< maskSIZE > EtaPartitionMask
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< GEMMaskedStrips > theGEMMaskedStripsObj
~GEMRecHitProducer() override
Destructor.
iterator end()
Definition: OwnVector.h:249
void add(std::string const &label, ParameterSetDescription const &psetDescription)
enum GEMRecHitProducer::MaskSource maskSource_
HLT enums.
T get() const
Definition: EventSetup.h:71
std::map< GEMDetId, EtaPartitionMask > gemMask_
std::string fullPath() const
Definition: FileInPath.cc:163
std::unique_ptr< GEMRecHitBaseAlgo > theAlgo
std::pair< const_iterator, const_iterator > Range
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
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)