CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1MuGMTHWFileReader.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // \class L1MuGMTHWFileReader
4 //
5 // Description: Puts the GMT input information from
6 // a GMT ascii HW testfile into the Event
7 //
8 //
9 //
10 // Author :
11 // Tobias Noebauer HEPHY Vienna
12 // Ivan Mikulec HEPHY Vienna
13 //
14 //--------------------------------------------------
15 
16 //-----------------------
17 // This Class's Header --
18 //-----------------------
20 
21 //---------------
22 // C++ Headers --
23 //---------------
24 #include <stdexcept>
25 
26 //-------------------------------
27 // Collaborating Class Headers --
28 //-------------------------------
31 
33 
34 //----------------
35 // Constructors --
36 //----------------
38  : ProducerSourceFromFiles(ps, desc, true) {
39  produces<std::vector<L1MuRegionalCand> >("DT");
40  produces<std::vector<L1MuRegionalCand> >("CSC");
41  produces<std::vector<L1MuRegionalCand> >("RPCb");
42  produces<std::vector<L1MuRegionalCand> >("RPCf");
43 
44  produces<L1CaloRegionCollection>();
45 
46  if (fileNames(0).empty()) {
47  throw std::runtime_error("L1MuGMTHWFileReader: no input file");
48  }
49  edm::LogInfo("GMT_HWFileReader_info") << "opening file " << fileNames(0)[0];
50  m_in.open((fileNames(0)[0].substr(fileNames(0)[0].find(':') + 1)).c_str());
51  if (!m_in) {
52  throw std::runtime_error("L1MuGMTHWFileReader: file " + fileNames(0)[0] + " could not be openned");
53  }
54 }
55 
56 //--------------
57 // Destructor --
58 //--------------
60 
61 //--------------
62 // Operations --
63 //--------------
65  edm::TimeValue_t& time,
67  readNextEvent();
69  return false;
70  id = edm::EventID(m_evt.getRunNumber(), id.luminosityBlock(), m_evt.getEventNumber());
71 
72  edm::LogInfo("GMT_HWFileReader_info") << "run: " << m_evt.getRunNumber() << " evt: " << m_evt.getEventNumber();
73  return true;
74 }
75 
77  L1MuRegionalCand empty_mu;
78 
79  std::unique_ptr<std::vector<L1MuRegionalCand> > DTCands(new std::vector<L1MuRegionalCand>);
80  for (unsigned i = 0; i < 4; i++) {
81  const L1MuRegionalCand* mu = m_evt.getInputMuon("IND", i);
82  if (!mu)
83  mu = &empty_mu;
84  DTCands->push_back(*mu);
85  }
86  e.put(std::move(DTCands), "DT");
87 
88  std::unique_ptr<std::vector<L1MuRegionalCand> > CSCCands(new std::vector<L1MuRegionalCand>);
89  for (unsigned i = 0; i < 4; i++) {
90  const L1MuRegionalCand* mu = m_evt.getInputMuon("INC", i);
91  if (!mu)
92  mu = &empty_mu;
93  CSCCands->push_back(*mu);
94  }
95  e.put(std::move(CSCCands), "CSC");
96 
97  std::unique_ptr<std::vector<L1MuRegionalCand> > RPCbCands(new std::vector<L1MuRegionalCand>);
98  for (unsigned i = 0; i < 4; i++) {
99  const L1MuRegionalCand* mu = m_evt.getInputMuon("INB", i);
100  if (!mu)
101  mu = &empty_mu;
102  RPCbCands->push_back(*mu);
103  }
104  e.put(std::move(RPCbCands), "RPCb");
105 
106  std::unique_ptr<std::vector<L1MuRegionalCand> > RPCfCands(new std::vector<L1MuRegionalCand>);
107  for (unsigned i = 0; i < 4; i++) {
108  const L1MuRegionalCand* mu = m_evt.getInputMuon("INF", i);
109  if (!mu)
110  mu = &empty_mu;
111  RPCfCands->push_back(*mu);
112  }
113  e.put(std::move(RPCfCands), "RPCf");
114 
115  std::unique_ptr<L1CaloRegionCollection> rctRegions(new L1CaloRegionCollection);
116  for (int ieta = 4; ieta < 18; ieta++) {
117  for (int iphi = 0; iphi < 18; iphi++) {
118  rctRegions->push_back(
119  L1CaloRegion(0, false, true, m_evt.getMipBit(ieta - 4, iphi), m_evt.getIsoBit(ieta - 4, iphi), ieta, iphi));
120  }
121  }
122 
123  e.put(std::move(rctRegions));
124 }
125 
127  m_evt.reset();
128 
129  std::string line_id;
130  do {
131  int bx = 0;
132 
133  m_in >> line_id;
134  if (line_id == "--")
135  continue;
136 
137  if (line_id == "RUN") {
138  unsigned long runnr;
139  m_in >> runnr;
140  m_evt.setRunNumber(runnr);
141  }
142 
143  if (line_id == "EVT") {
144  unsigned long evtnr;
145  m_in >> evtnr;
146  m_evt.setEventNumber(evtnr);
147  }
148 
149  if (line_id == "DT" || line_id == "CSC" || line_id == "BRPC" || line_id == "FRPC") {
150  // decode input muon
151 
152  unsigned inpmu = 0;
153  unsigned val;
154  m_in >> val;
155  inpmu |= (val & 0x01) << 24; // valid charge
156  m_in >> val;
157  inpmu |= (val & 0x01) << 23; // charge
158  m_in >> val;
159  inpmu |= (val & 0x01) << 22; // halo / fine
160  m_in >> val;
161  inpmu |= (val & 0x3f) << 16; // eta
162  m_in >> val;
163  inpmu |= (val & 0x07) << 13; // quality
164  m_in >> val;
165  inpmu |= (val & 0x1f) << 8; // pt
166  m_in >> val;
167  inpmu |= (val & 0xff); // phi
168 
169  std::string chipid("IN");
170  chipid += line_id[0];
171 
172  int type = 0;
173  if (line_id == "DT")
174  type = 0;
175  if (line_id == "CSC")
176  type = 2;
177  if (line_id == "BRPC")
178  type = 1;
179  if (line_id == "FRPC")
180  type = 3;
181 
182  L1MuRegionalCand cand(inpmu);
183  cand.setType(type);
184  cand.setBx(bx);
185  m_evt.addInputMuon(chipid, cand);
186  }
187 
188  if (line_id == "MIP") {
189  int nPairs;
190  m_in >> nPairs;
191  for (int i = 0; i < nPairs; i++) {
192  unsigned eta;
193  unsigned phi;
194  m_in >> eta;
195  m_in >> phi;
196  if (phi >= 9)
197  phi -= 9;
198  else
199  phi += 9;
200  m_evt.setMipBit(eta, phi, true);
201  }
202  }
203 
204  if (line_id == "NQ") {
205  int nPairs;
206  m_in >> nPairs;
207  for (int i = 0; i < nPairs; i++) {
208  unsigned eta;
209  unsigned phi;
210  m_in >> eta;
211  m_in >> phi;
212  if (phi >= 9)
213  phi -= 9;
214  else
215  phi += 9;
216  m_evt.setIsoBit(eta, phi, false);
217  }
218  }
219 
220  //read the rest of the line
221  const int sz = 4000;
222  char buf[sz];
223  m_in.getline(buf, sz);
224 
225  } while (line_id != "NQ" && !m_in.eof());
226 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
L1MuGMTHWFileReader(edm::ParameterSet const &, edm::InputSourceDescription const &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
constexpr int nPairs
void setRunNumber(unsigned long runnr)
unsigned long getRunNumber() const
get the Run number
void setBx(int bx)
Set Bunch Crossing.
unsigned long getEventNumber() const
get the Event number
L1MuGMTInputEvent m_evt
def move
Definition: eostools.py:511
void setType(unsigned type)
Set Type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC.
const int mu
Definition: Constants.h:22
unsigned long long TimeValue_t
Definition: Timestamp.h:28
void addInputMuon(std::string chipid, const L1MuRegionalCand &inMu)
void setIsoBit(unsigned etaIndex, unsigned phiIndex, bool val)
Log< level::Info, false > LogInfo
const L1MuRegionalCand * getInputMuon(std::string chipid, unsigned index) const
const bool & getMipBit(unsigned etaIndex, unsigned phiIndex)
const bool & getIsoBit(unsigned etaIndex, unsigned phiIndex)
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:21
std::vector< L1CaloRegion > L1CaloRegionCollection
bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &eType) override
void produce(edm::Event &) override
void setEventNumber(unsigned long eventnr)
void setMipBit(unsigned etaIndex, unsigned phiIndex, bool val)
std::vector< std::string > fileNames(unsigned iCatalog) const
Definition: FromFiles.h:22