CMS 3D CMS Logo

RPCRecHitProducer.cc
Go to the documentation of this file.
1 
6 #include "RPCRecHitProducer.h"
7 
9 
15 
18 
22 
23 #include <string>
24 #include <fstream>
25 
26 using namespace edm;
27 using namespace std;
28 
30  theRPCDigiLabel(consumes<RPCDigiCollection>(config.getParameter<InputTag>("rpcDigiLabel"))),
31  // Get the concrete reconstruction algo from the factory
32  theAlgo{RPCRecHitAlgoFactory::get()->create(config.getParameter<string>("recAlgo"),
33  config.getParameter<ParameterSet>("recAlgoConfig"))},
35 {
36  // Set verbose output
37  produces<RPCRecHitCollection>();
38 
39  // Get masked- and dead-strip information
40  theRPCMaskedStripsObj = std::make_unique<RPCMaskedStrips>();
41  theRPCDeadStripsObj = std::make_unique<RPCDeadStrips>();
42 
43  const string maskSource = config.getParameter<std::string>("maskSource");
44  if (maskSource == "File") {
46  edm::FileInPath fp = config.getParameter<edm::FileInPath>("maskvecfile");
47  std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
48  if ( !inputFile ) {
49  std::cerr << "Masked Strips File cannot not be opened" << std::endl;
50  exit(1);
51  }
52  while ( inputFile.good() ) {
54  inputFile >> Item.rawId >> Item.strip;
55  if ( inputFile.good() ) MaskVec.push_back(Item);
56  }
57  inputFile.close();
58  }
59 
60  const string deadSource = config.getParameter<std::string>("deadSource");
61  if (deadSource == "File") {
63  edm::FileInPath fp = config.getParameter<edm::FileInPath>("deadvecfile");
64  std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
65  if ( !inputFile ) {
66  std::cerr << "Dead Strips File cannot not be opened" << std::endl;
67  exit(1);
68  }
69  while ( inputFile.good() ) {
71  inputFile >> Item.rawId >> Item.strip;
72  if ( inputFile.good() ) DeadVec.push_back(Item);
73  }
74  inputFile.close();
75  }
76 }
77 
78 
80  // Getting the masked-strip information
82  edm::ESHandle<RPCMaskedStrips> readoutMaskedStrips;
83  setup.get<RPCMaskedStripsRcd>().get(readoutMaskedStrips);
84  const RPCMaskedStrips* tmp_obj = readoutMaskedStrips.product();
85  theRPCMaskedStripsObj->MaskVec = tmp_obj->MaskVec;
86  delete tmp_obj;
87  }
88  else if ( maskSource_ == MaskSource::File ) {
89  std::vector<RPCMaskedStrips::MaskItem>::iterator posVec;
90  for ( posVec = MaskVec.begin(); posVec != MaskVec.end(); ++posVec ) {
92  Item.rawId = (*posVec).rawId;
93  Item.strip = (*posVec).strip;
94  theRPCMaskedStripsObj->MaskVec.push_back(Item);
95  }
96  }
97 
98  // Getting the dead-strip information
100  edm::ESHandle<RPCDeadStrips> readoutDeadStrips;
101  setup.get<RPCDeadStripsRcd>().get(readoutDeadStrips);
102  const RPCDeadStrips* tmp_obj = readoutDeadStrips.product();
103  theRPCDeadStripsObj->DeadVec = tmp_obj->DeadVec;
104  delete tmp_obj;
105  }
106  else if ( deadSource_ == MaskSource::File ) {
107  std::vector<RPCDeadStrips::DeadItem>::iterator posVec;
108  for ( posVec = DeadVec.begin(); posVec != DeadVec.end(); ++posVec ) {
110  Item.rawId = (*posVec).rawId;
111  Item.strip = (*posVec).strip;
112  theRPCDeadStripsObj->DeadVec.push_back(Item);
113  }
114  }
115 
116 }
117 
119  // Get the RPC Geometry
120  ESHandle<RPCGeometry> rpcGeom;
121  setup.get<MuonGeometryRecord>().get(rpcGeom);
122 
123  // Get the digis from the event
125  event.getByToken(theRPCDigiLabel,digis);
126 
127  // Pass the EventSetup to the algo
128  theAlgo->setES(setup);
129 
130  // Create the pointer to the collection which will store the rechits
131  auto recHitCollection = std::make_unique<RPCRecHitCollection>();
132 
133  // Iterate through all digi collections ordered by LayerId
134 
135  for ( auto rpcdgIt = digis->begin(); rpcdgIt != digis->end(); ++rpcdgIt ) {
136  // The layerId
137  const RPCDetId& rpcId = (*rpcdgIt).first;
138 
139  // Get the GeomDet from the setup
140  const RPCRoll* roll = rpcGeom->roll(rpcId);
141  if (roll == nullptr){
142  edm::LogError("BadDigiInput")<<"Failed to find RPCRoll for ID "<<rpcId;
143  continue;
144  }
145 
146  // Get the iterators over the digis associated with this LayerId
147  const RPCDigiCollection::Range& range = (*rpcdgIt).second;
148 
149  // Getting the roll mask, that includes dead strips, for the given RPCDet
150  RollMask mask;
151  const int rawId = rpcId.rawId();
152  for ( const auto& tomask : theRPCMaskedStripsObj->MaskVec ) {
153  if ( tomask.rawId == rawId ) {
154  const int bit = tomask.strip;
155  mask.set(bit-1);
156  }
157  }
158 
159  for ( const auto& tomask : theRPCDeadStripsObj->DeadVec ) {
160  if ( tomask.rawId == rawId ) {
161  const int bit = tomask.strip;
162  mask.set(bit-1);
163  }
164  }
165 
166  // Call the reconstruction algorithm
167  OwnVector<RPCRecHit> recHits = theAlgo->reconstruct(*roll, rpcId, range, mask);
168 
169  if(!recHits.empty()) //FIXME: is it really needed?
170  recHitCollection->put(rpcId, recHits.begin(), recHits.end());
171  }
172 
173  event.put(std::move(recHitCollection));
174 
175 }
176 
T getParameter(std::string const &) const
std::vector< MaskItem > MaskVec
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::unique_ptr< RPCRecHitBaseAlgo > theAlgo
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: config.py:1
iterator begin()
Definition: OwnVector.h:244
enum RPCRecHitProducer::MaskSource deadSource_
void produce(edm::Event &event, const edm::EventSetup &setup) override
The method which produces the rechits.
bool empty() const
Definition: OwnVector.h:269
const edm::EDGetTokenT< RPCDigiCollection > theRPCDigiLabel
std::bitset< maskSIZE > RollMask
Definition: RPCRollMask.h:7
std::unique_ptr< RPCMaskedStrips > theRPCMaskedStripsObj
iterator end()
Definition: OwnVector.h:249
std::vector< RPCDeadStrips::DeadItem > DeadVec
RPCRecHitProducer(const edm::ParameterSet &config)
Constructor.
enum RPCRecHitProducer::MaskSource maskSource_
HLT enums.
T get() const
Definition: EventSetup.h:71
std::vector< DeadItem > DeadVec
Definition: RPCDeadStrips.h:28
std::string fullPath() const
Definition: FileInPath.cc:163
std::vector< RPCMaskedStrips::MaskItem > MaskVec
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
std::unique_ptr< RPCDeadStrips > theRPCDeadStripsObj
const RPCRoll * roll(RPCDetId id) const
Return a roll given its id.
Definition: RPCGeometry.cc:75
Definition: event.py:1
Definition: Run.h:45