CMS 3D CMS Logo

RPCRecHitProducer.cc
Go to the documentation of this file.
1 
6 #include "RPCRecHitProducer.h"
7 
11 
12 #include "RPCRecHitAlgoFactory.h"
14 
16 
17 #include <string>
18 #include <fstream>
19 
20 using namespace edm;
21 using namespace std;
22 
24  : theRPCDigiLabel(consumes<RPCDigiCollection>(config.getParameter<InputTag>("rpcDigiLabel"))),
25  theRPCGeomToken(esConsumes()),
26  // Get the concrete reconstruction algo from the factory
27  theAlgo{RPCRecHitAlgoFactory::get()->create(config.getParameter<string>("recAlgo"),
28  config.getParameter<ParameterSet>("recAlgoConfig"))},
29  maskSource_(MaskSource::EventSetup),
30  deadSource_(MaskSource::EventSetup) {
31  // Set verbose output
32  produces<RPCRecHitCollection>();
33 
34  // Get masked- and dead-strip information
35  theRPCMaskedStripsObj = std::make_unique<RPCMaskedStrips>();
36  theRPCDeadStripsObj = std::make_unique<RPCDeadStrips>();
37 
38  const string maskSource = config.getParameter<std::string>("maskSource");
39  if (maskSource == "File") {
40  maskSource_ = MaskSource::File;
41  edm::FileInPath fp = config.getParameter<edm::FileInPath>("maskvecfile");
42  std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
43  if (!inputFile) {
44  std::cerr << "Masked Strips File cannot not be opened" << std::endl;
45  exit(1);
46  }
47  while (inputFile.good()) {
49  inputFile >> Item.rawId >> Item.strip;
50  if (inputFile.good())
51  MaskVec.push_back(Item);
52  }
53  inputFile.close();
54  } else {
55  theReadoutMaskedStripsToken = esConsumes();
56  }
57 
58  const string deadSource = config.getParameter<std::string>("deadSource");
59  if (deadSource == "File") {
60  deadSource_ = MaskSource::File;
61  edm::FileInPath fp = config.getParameter<edm::FileInPath>("deadvecfile");
62  std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
63  if (!inputFile) {
64  std::cerr << "Dead Strips File cannot not be opened" << std::endl;
65  exit(1);
66  }
67  while (inputFile.good()) {
69  inputFile >> Item.rawId >> Item.strip;
70  if (inputFile.good())
71  DeadVec.push_back(Item);
72  }
73  inputFile.close();
74  } else {
75  theReadoutDeadStripsToken = esConsumes();
76  }
77 }
78 
80  // Getting the masked-strip information
82  theRPCMaskedStripsObj->MaskVec = setup.getData(theReadoutMaskedStripsToken).MaskVec;
83  } else if (maskSource_ == MaskSource::File) {
84  std::vector<RPCMaskedStrips::MaskItem>::iterator posVec;
85  for (posVec = MaskVec.begin(); posVec != MaskVec.end(); ++posVec) {
87  Item.rawId = (*posVec).rawId;
88  Item.strip = (*posVec).strip;
89  theRPCMaskedStripsObj->MaskVec.push_back(Item);
90  }
91  }
92 
93  // Getting the dead-strip information
95  theRPCDeadStripsObj->DeadVec = setup.getData(theReadoutDeadStripsToken).DeadVec;
96  } else if (deadSource_ == MaskSource::File) {
97  std::vector<RPCDeadStrips::DeadItem>::iterator posVec;
98  for (posVec = DeadVec.begin(); posVec != DeadVec.end(); ++posVec) {
100  Item.rawId = (*posVec).rawId;
101  Item.strip = (*posVec).strip;
102  theRPCDeadStripsObj->DeadVec.push_back(Item);
103  }
104  }
105 }
106 
108  // Get the RPC Geometry
109  auto const& rpcGeom = setup.getData(theRPCGeomToken);
110 
111  // Get the digis from the event
113  event.getByToken(theRPCDigiLabel, digis);
114 
115  // Pass the EventSetup to the algo
116  theAlgo->setES(setup);
117 
118  // Create the pointer to the collection which will store the rechits
119  auto recHitCollection = std::make_unique<RPCRecHitCollection>();
120 
121  // Iterate through all digi collections ordered by LayerId
122 
123  for (auto rpcdgIt = digis->begin(); rpcdgIt != digis->end(); ++rpcdgIt) {
124  // The layerId
125  const RPCDetId& rpcId = (*rpcdgIt).first;
126 
127  // Get the GeomDet from the setup
128  const RPCRoll* roll = rpcGeom.roll(rpcId);
129  if (roll == nullptr) {
130  edm::LogError("BadDigiInput") << "Failed to find RPCRoll for ID " << rpcId;
131  continue;
132  }
133 
134  // Get the iterators over the digis associated with this LayerId
135  const RPCDigiCollection::Range& range = (*rpcdgIt).second;
136 
137  // Getting the roll mask, that includes dead strips, for the given RPCDet
138  RollMask mask;
139  const int rawId = rpcId.rawId();
140  for (const auto& tomask : theRPCMaskedStripsObj->MaskVec) {
141  if (tomask.rawId == rawId) {
142  const int bit = tomask.strip;
143  mask.set(bit - 1);
144  }
145  }
146 
147  for (const auto& tomask : theRPCDeadStripsObj->DeadVec) {
148  if (tomask.rawId == rawId) {
149  const int bit = tomask.strip;
150  mask.set(bit - 1);
151  }
152  }
153 
154  // Call the reconstruction algorithm
155  OwnVector<RPCRecHit> recHits = theAlgo->reconstruct(*roll, rpcId, range, mask);
156 
157  if (!recHits.empty()) //FIXME: is it really needed?
158  recHitCollection->put(rpcId, recHits.begin(), recHits.end());
159  }
160 
161  event.put(std::move(recHitCollection));
162 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< RPCGeometry, MuonGeometryRecord > theRPCGeomToken
edm::ESGetToken< RPCDeadStrips, RPCDeadStripsRcd > theReadoutDeadStripsToken
std::unique_ptr< RPCRecHitBaseAlgo > theAlgo
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: config.py:1
Log< level::Error, false > LogError
enum RPCRecHitProducer::MaskSource deadSource_
void produce(edm::Event &event, const edm::EventSetup &setup) override
The method which produces the rechits.
const edm::EDGetTokenT< RPCDigiCollection > theRPCDigiLabel
std::bitset< maskSIZE > RollMask
Definition: RPCRollMask.h:7
std::unique_ptr< RPCMaskedStrips > theRPCMaskedStripsObj
std::vector< RPCDeadStrips::DeadItem > DeadVec
RPCRecHitProducer(const edm::ParameterSet &config)
Constructor.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::ESGetToken< RPCMaskedStrips, RPCMaskedStripsRcd > theReadoutMaskedStripsToken
std::pair< const_iterator, const_iterator > Range
std::vector< DeadRegion > DeadVec
Definition: Hit.h:280
enum RPCRecHitProducer::MaskSource maskSource_
HLT enums.
std::vector< RPCMaskedStrips::MaskItem > MaskVec
#define get
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< RPCDeadStrips > theRPCDeadStripsObj
Definition: event.py:1
Definition: Run.h:45
def exit(msg="")