CMS 3D CMS Logo

L1TMicroGMTInputProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TMicroGMTInputProducer
4 // Class: L1TMicroGMTInputProducer
5 //
13 //
14 // Original Author: Joschka Philip Lingemann,40 3-B01,+41227671598,
15 // Created: Thu Oct 3 10:12:30 CEST 2013
16 // $Id$
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <fstream>
24 
25 // user include files
28 
31 
35 
40 
41 #include <iostream>
42 //
43 // class declaration
44 //
45 using namespace l1t;
46 
48  public:
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54  private:
55  virtual void beginJob() override ;
56  virtual void produce(edm::Event&, const edm::EventSetup&) override ;
57  virtual void endJob() override ;
58 
59  virtual void beginRun(const edm::Run&, edm::EventSetup const&) override ;
60  virtual void endRun(const edm::Run&, edm::EventSetup const&) override ;
61  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
62  virtual void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
63 
64  void openFile();
65  void skipHeader();
66  int convertToInt(std::string &bitstr) const;
67  static bool cmpProc(const RegionalMuonCand&, const RegionalMuonCand&);
68 
69  // ----------member data ---------------------------
71  std::ifstream m_filestream;
72  bool m_endOfBx;
75  int m_currEvt;
76 };
77 
78 //
79 // constants, enums and typedefs
80 //
81 
82 
83 //
84 // static data member definitions
85 //
86 
87 //
88 // constructors and destructor
89 //
91  m_endOfBx(false), m_currType(0), m_currEvt(0)
92 {
93  //register your products
94  produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
95  produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
96  produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
97  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
98 
99  //now do what ever other initialization is needed
100  m_fname = iConfig.getParameter<std::string> ("inputFileName");
101 
102  openFile();
103  skipHeader();
104 }
105 
106 
108 {
109  // do anything here that needs to be done at desctruction time
110  // (e.g. close files, deallocate resources etc.)
111  m_filestream.close();
112 }
113 
114 
115 //
116 // member functions
117 //
118 bool
120 {
121  return mu1.processor() < mu2.processor();
122 }
123 
124 void
126 {
127  if (!m_filestream.is_open()) {
128  m_filestream.open(m_fname.c_str());
129  if (!m_filestream.good()) {
130  cms::Exception("FileOpenError") << "Failed to open input file";
131  }
132  }
133 }
134 
135 void
137 {
138  while (m_filestream.peek() == '#') {
140  getline(m_filestream, tmp);
141  }
142 }
143 
144 int
146 {
147  int num = 0;
148  for (size_t cntr = 0; cntr < bitstr.size(); ++cntr) {
149  char c = bitstr[cntr];
150  num = (num << 1) | // Shift the current set of bits to the left one bit
151  (c - '0'); // Add in the current bit via a bitwise-or
152  }
153  return num;
154 }
155 
156 
157 
158 // ------------ method called to produce the data ------------
159 void
161 {
162  using namespace edm;
163 
164  std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons (new RegionalMuonCandBxCollection());
165  std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons (new RegionalMuonCandBxCollection());
166  std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons (new RegionalMuonCandBxCollection());
167  std::unique_ptr<MuonCaloSumBxCollection> towerSums (new MuonCaloSumBxCollection());
168 
170  MuonCaloSum tSum;
171  m_endOfBx = false;
172  int caloCounter = 0;
173  std::vector<int> bar{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
174  std::vector<int> ovl_neg{0, 0, 0, 0, 0, 0};
175  std::vector<int> ovl_pos{0, 0, 0, 0, 0, 0};
176  std::vector<int> fwd_neg{0, 0, 0, 0, 0, 0};
177  std::vector<int> fwd_pos{0, 0, 0, 0, 0, 0};
178  while(!m_endOfBx && !m_filestream.eof()) {
179  std::string lineID;
180  m_filestream >> lineID;
181  std::string restOfLine;
182 
183 
184  if (lineID == "BAR" || lineID == "OVL-" || lineID == "FWD-" || lineID == "OVL+" || lineID == "FWD+") {
185  int tmp;
186  m_filestream >> tmp; // cable no
187  // if (lineID == "BAR") tmp += 12;
188  // if (lineID == "OVL-") tmp = (tmp-6)+24;
189  // if (lineID == "OVL+") tmp = tmp + 6;
190  // if (lineID == "FWD-") tmp = (tmp-6)+30;
191 
192  // mu.setLink(tmp);
193  m_filestream >> tmp;
194  mu.setHwPt(tmp);
195 
196  m_filestream >> tmp;
197 
198  int globalPhi = int(tmp*0.560856864654333f); // correction from txt file producer!
199  int globalWedgePhi = (globalPhi+24)%576; // this sets CMS phi = 0 to -15 deg
200  int globalSectorPhi = (globalPhi-24); // this sets CMS phi = 0 to +15 deg
201  if (globalSectorPhi < 0) {
202  globalSectorPhi += 576;
203  }
204 
205 
206  // int globalMuonPhi = int(tmp*0.560856864654333f); // make sure scale is correct
207  bool skip = false;
208  if (lineID == "BAR") {
209  int processor = globalWedgePhi / 48 + 1;
210  int localPhi = globalWedgePhi%48;
211  mu.setTFIdentifiers(processor, tftype::bmtf);
212  mu.setHwPhi(localPhi);
213  bar[processor-1]++;
214  if (bar[processor-1] > 3) skip = true;
215  }
216  if (lineID == "OVL-") {
217  int processor = globalSectorPhi / 96 + 1;
218  int localPhi = globalSectorPhi%96;
219  mu.setTFIdentifiers(processor, tftype::omtf_neg);
220  mu.setHwPhi(localPhi);
221  ovl_neg[processor-1]++;
222  if (ovl_neg[processor-1] > 3) skip = true;
223  }
224  if (lineID == "OVL+") {
225  int processor = globalSectorPhi / 96 + 1;
226  int localPhi = globalSectorPhi%96;
227  mu.setTFIdentifiers(processor, tftype::omtf_pos);
228  mu.setHwPhi(localPhi);
229  ovl_pos[processor-1]++;
230  if (ovl_pos[processor-1] > 3) skip = true;
231  }
232  if (lineID == "FWD-") {
233  int processor = globalSectorPhi / 96 + 1;
234  int localPhi = globalSectorPhi%96;
235  mu.setTFIdentifiers(processor, tftype::emtf_neg);
236  mu.setHwPhi(localPhi);
237  fwd_neg[processor-1]++;
238  if (fwd_neg[processor-1] > 3) skip = true;
239  }
240  if (lineID == "FWD+") {
241  int processor = globalSectorPhi / 96 + 1;
242  int localPhi = globalSectorPhi%96;
243  mu.setTFIdentifiers(processor, tftype::emtf_pos);
244  mu.setHwPhi(localPhi);
245  fwd_pos[processor-1]++;
246  if (fwd_pos[processor-1] > 3) skip = true;
247  }
248 
249  m_filestream >> tmp;
250  tmp = int(tmp*0.9090909090f);
251  mu.setHwEta(tmp);
252 
253 
254 
255  m_filestream >> tmp;
256  mu.setHwSign(tmp);
257 
258  m_filestream >> tmp;
259  mu.setHwSignValid(tmp);
260 
261  m_filestream >> tmp;
262  mu.setHwQual(tmp);
263 
264  if (lineID == "BAR") m_currType = 0;
265  if (lineID == "OVL-") m_currType = 1;
266  if (lineID == "OVL+") m_currType = 2;
267  if (lineID == "FWD-") m_currType = 3;
268  if (lineID == "FWD+") m_currType = 4;
269 
270  if (m_currType == 0 && !skip) barrelMuons->push_back(0, mu);
271  if ((m_currType == 1 || m_currType == 2) && !skip) overlapMuons->push_back(0, mu);
272  if ((m_currType == 3 || m_currType == 4) && !skip) endcapMuons->push_back(0, mu);
273  }
274 
275  if (lineID == "EVT" && m_currEvt != 0) {
276  m_endOfBx = true;
277  } else if (lineID == "EVT") {
278  m_currEvt++;
279  }
280 
281  if (lineID == "CALO") {
282  for (int i = 0; i < 28; ++i) {
283  int ieta = i; //caloCounter%28;
284  int iphi = caloCounter;
285  int et;
286 
287  m_filestream >> et;
288  tSum.setEtBits(et);
289  tSum.setEtaBits(ieta);
290  tSum.setPhiBits(iphi);
291  tSum.setIndex(caloCounter*28+i);
292  towerSums->push_back(0, tSum);
293  }
294  caloCounter++;
295  }
296  getline(m_filestream, restOfLine);
297  //std::cout << restOfLine;
298  }
299 
300 
301  // std::sort(barrelMuons->begin(0), barrelMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
302  // std::sort(overlapMuons->begin(0), overlapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
303  // std::sort(endcapMuons->begin(0), endcapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
304 
305  iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
306  iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
307  iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
308  iEvent.put(std::move(towerSums), "TriggerTowerSums");
309  m_currEvt++;
310 
311 }
312 
313 // ------------ method called once each job just before starting event loop ------------
314 void
316 {
317 }
318 
319 // ------------ method called once each job just after ending the event loop ------------
320 void
322 }
323 
324 // ------------ method called when starting to processes a run ------------
325 void
327 {
328 }
329 
330 // ------------ method called when ending the processing of a run ------------
331 void
333 {
334 }
335 
336 // ------------ method called when starting to processes a luminosity block ------------
337 void
339 {
340 }
341 
342 // ------------ method called when ending the processing of a luminosity block ------------
343 void
345 {
346 }
347 
348 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
349 void
351  //The following says we do not know what parameters are allowed so do no validation
352  // Please change this to state exactly what you do use, even if it is no parameters
354  desc.setUnknown();
355  descriptions.addDefault(desc);
356 }
357 
358 //define this as a plug-in
T getParameter(std::string const &) const
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
virtual void produce(edm::Event &, const edm::EventSetup &) override
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
void setEtaBits(int bits)
Definition: MuonCaloSum.h:19
BXVector< RegionalMuonCand > RegionalMuonCandBxCollection
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
BXVector< MuonCaloSum > MuonCaloSumBxCollection
Definition: MuonCaloSumFwd.h:7
delete x;
Definition: CaloConfig.h:22
void setIndex(int idx)
Definition: MuonCaloSum.h:20
virtual void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
void beginJob()
Definition: Breakpoints.cc:15
L1TMicroGMTInputProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
virtual void endRun(const edm::Run &, edm::EventSetup const &) override
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
virtual void endJob() override
double f[11][100]
const int mu
Definition: Constants.h:22
static bool cmpProc(const RegionalMuonCand &, const RegionalMuonCand &)
virtual void beginJob() override
void setPhiBits(int bits)
Definition: MuonCaloSum.h:18
void setHwQual(int bits)
Set compressed quality code as transmitted by hardware (4 bits)
void setEtBits(int bits)
Definition: MuonCaloSum.h:17
void setHwPt(int bits)
Set compressed pT as transmitted by hardware LSB = 0.5 (9 bits)
void setHwEta(int bits)
Set compressed eta as transmitted by hardware LSB = 0.010875 (9 bits)
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF) ...
int convertToInt(std::string &bitstr) const
virtual void beginRun(const edm::Run &, edm::EventSetup const &) override
et
define resolution functions of each parameter
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
void setHwSignValid(int bits)
Set whether charge measurement is valid (0 for high pT muons)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42
void setHwSign(int bits)
Set charge sign bit (charge = (-1)^(sign))