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:
50  ~L1TMicroGMTInputProducer() override;
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54  private:
55  void produce(edm::Event&, const edm::EventSetup&) override ;
56 
57  void beginRun(const edm::Run&, edm::EventSetup const&) override ;
58  void endRun(const edm::Run&, edm::EventSetup const&) override ;
59  void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
60  void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
61 
62  void openFile();
63  void skipHeader();
64  int convertToInt(std::string &bitstr) const;
65  static bool cmpProc(const RegionalMuonCand&, const RegionalMuonCand&);
66 
67  // ----------member data ---------------------------
69  std::ifstream m_filestream;
70  bool m_endOfBx;
73  int m_currEvt;
74 };
75 
76 //
77 // constants, enums and typedefs
78 //
79 
80 
81 //
82 // static data member definitions
83 //
84 
85 //
86 // constructors and destructor
87 //
89  m_endOfBx(false), m_currType(0), m_currEvt(0)
90 {
91  //register your products
92  produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
93  produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
94  produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
95  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
96 
97  //now do what ever other initialization is needed
98  m_fname = iConfig.getParameter<std::string> ("inputFileName");
99 
100  openFile();
101  skipHeader();
102 }
103 
104 
106 {
107  // do anything here that needs to be done at desctruction time
108  // (e.g. close files, deallocate resources etc.)
109  m_filestream.close();
110 }
111 
112 
113 //
114 // member functions
115 //
116 bool
118 {
119  return mu1.processor() < mu2.processor();
120 }
121 
122 void
124 {
125  if (!m_filestream.is_open()) {
126  m_filestream.open(m_fname.c_str());
127  if (!m_filestream.good()) {
128  cms::Exception("FileOpenError") << "Failed to open input file";
129  }
130  }
131 }
132 
133 void
135 {
136  while (m_filestream.peek() == '#') {
138  getline(m_filestream, tmp);
139  }
140 }
141 
142 int
144 {
145  int num = 0;
146  for (size_t cntr = 0; cntr < bitstr.size(); ++cntr) {
147  char c = bitstr[cntr];
148  num = (num << 1) | // Shift the current set of bits to the left one bit
149  (c - '0'); // Add in the current bit via a bitwise-or
150  }
151  return num;
152 }
153 
154 
155 
156 // ------------ method called to produce the data ------------
157 void
159 {
160  using namespace edm;
161 
162  std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons (new RegionalMuonCandBxCollection());
163  std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons (new RegionalMuonCandBxCollection());
164  std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons (new RegionalMuonCandBxCollection());
165  std::unique_ptr<MuonCaloSumBxCollection> towerSums (new MuonCaloSumBxCollection());
166 
168  MuonCaloSum tSum;
169  m_endOfBx = false;
170  int caloCounter = 0;
171  std::vector<int> bar{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
172  std::vector<int> ovl_neg{0, 0, 0, 0, 0, 0};
173  std::vector<int> ovl_pos{0, 0, 0, 0, 0, 0};
174  std::vector<int> fwd_neg{0, 0, 0, 0, 0, 0};
175  std::vector<int> fwd_pos{0, 0, 0, 0, 0, 0};
176  while(!m_endOfBx && !m_filestream.eof()) {
177  std::string lineID;
178  m_filestream >> lineID;
179  std::string restOfLine;
180 
181 
182  if (lineID == "BAR" || lineID == "OVL-" || lineID == "FWD-" || lineID == "OVL+" || lineID == "FWD+") {
183  int tmp;
184  m_filestream >> tmp; // cable no
185  // if (lineID == "BAR") tmp += 12;
186  // if (lineID == "OVL-") tmp = (tmp-6)+24;
187  // if (lineID == "OVL+") tmp = tmp + 6;
188  // if (lineID == "FWD-") tmp = (tmp-6)+30;
189 
190  // mu.setLink(tmp);
191  m_filestream >> tmp;
192  mu.setHwPt(tmp);
193 
194  m_filestream >> tmp;
195 
196  int globalPhi = int(tmp*0.560856864654333f); // correction from txt file producer!
197  int globalWedgePhi = (globalPhi+24)%576; // this sets CMS phi = 0 to -15 deg
198  int globalSectorPhi = (globalPhi-24); // this sets CMS phi = 0 to +15 deg
199  if (globalSectorPhi < 0) {
200  globalSectorPhi += 576;
201  }
202 
203 
204  // int globalMuonPhi = int(tmp*0.560856864654333f); // make sure scale is correct
205  bool skip = false;
206  if (lineID == "BAR") {
207  int processor = globalWedgePhi / 48 + 1;
208  int localPhi = globalWedgePhi%48;
209  mu.setTFIdentifiers(processor, tftype::bmtf);
210  mu.setHwPhi(localPhi);
211  bar[processor-1]++;
212  if (bar[processor-1] > 3) skip = true;
213  }
214  if (lineID == "OVL-") {
215  int processor = globalSectorPhi / 96 + 1;
216  int localPhi = globalSectorPhi%96;
217  mu.setTFIdentifiers(processor, tftype::omtf_neg);
218  mu.setHwPhi(localPhi);
219  ovl_neg[processor-1]++;
220  if (ovl_neg[processor-1] > 3) skip = true;
221  }
222  if (lineID == "OVL+") {
223  int processor = globalSectorPhi / 96 + 1;
224  int localPhi = globalSectorPhi%96;
225  mu.setTFIdentifiers(processor, tftype::omtf_pos);
226  mu.setHwPhi(localPhi);
227  ovl_pos[processor-1]++;
228  if (ovl_pos[processor-1] > 3) skip = true;
229  }
230  if (lineID == "FWD-") {
231  int processor = globalSectorPhi / 96 + 1;
232  int localPhi = globalSectorPhi%96;
233  mu.setTFIdentifiers(processor, tftype::emtf_neg);
234  mu.setHwPhi(localPhi);
235  fwd_neg[processor-1]++;
236  if (fwd_neg[processor-1] > 3) skip = true;
237  }
238  if (lineID == "FWD+") {
239  int processor = globalSectorPhi / 96 + 1;
240  int localPhi = globalSectorPhi%96;
241  mu.setTFIdentifiers(processor, tftype::emtf_pos);
242  mu.setHwPhi(localPhi);
243  fwd_pos[processor-1]++;
244  if (fwd_pos[processor-1] > 3) skip = true;
245  }
246 
247  m_filestream >> tmp;
248  tmp = int(tmp*0.9090909090f);
249  mu.setHwEta(tmp);
250 
251 
252 
253  m_filestream >> tmp;
254  mu.setHwSign(tmp);
255 
256  m_filestream >> tmp;
257  mu.setHwSignValid(tmp);
258 
259  m_filestream >> tmp;
260  mu.setHwQual(tmp);
261 
262  if (lineID == "BAR") m_currType = 0;
263  if (lineID == "OVL-") m_currType = 1;
264  if (lineID == "OVL+") m_currType = 2;
265  if (lineID == "FWD-") m_currType = 3;
266  if (lineID == "FWD+") m_currType = 4;
267 
268  if (m_currType == 0 && !skip) barrelMuons->push_back(0, mu);
269  if ((m_currType == 1 || m_currType == 2) && !skip) overlapMuons->push_back(0, mu);
270  if ((m_currType == 3 || m_currType == 4) && !skip) endcapMuons->push_back(0, mu);
271  }
272 
273  if (lineID == "EVT" && m_currEvt != 0) {
274  m_endOfBx = true;
275  } else if (lineID == "EVT") {
276  m_currEvt++;
277  }
278 
279  if (lineID == "CALO") {
280  for (int i = 0; i < 28; ++i) {
281  int ieta = i; //caloCounter%28;
282  int iphi = caloCounter;
283  int et;
284 
285  m_filestream >> et;
286  tSum.setEtBits(et);
287  tSum.setEtaBits(ieta);
288  tSum.setPhiBits(iphi);
289  tSum.setIndex(caloCounter*28+i);
290  towerSums->push_back(0, tSum);
291  }
292  caloCounter++;
293  }
294  getline(m_filestream, restOfLine);
295  //std::cout << restOfLine;
296  }
297 
298 
299  // std::sort(barrelMuons->begin(0), barrelMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
300  // std::sort(overlapMuons->begin(0), overlapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
301  // std::sort(endcapMuons->begin(0), endcapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
302 
303  iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
304  iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
305  iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
306  iEvent.put(std::move(towerSums), "TriggerTowerSums");
307  m_currEvt++;
308 
309 }
310 
311 // ------------ method called when starting to processes a run ------------
312 void
314 {
315 }
316 
317 // ------------ method called when ending the processing of a run ------------
318 void
320 {
321 }
322 
323 // ------------ method called when starting to processes a luminosity block ------------
324 void
326 {
327 }
328 
329 // ------------ method called when ending the processing of a luminosity block ------------
330 void
332 {
333 }
334 
335 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
336 void
338  //The following says we do not know what parameters are allowed so do no validation
339  // Please change this to state exactly what you do use, even if it is no parameters
341  desc.setUnknown();
342  descriptions.addDefault(desc);
343 }
344 
345 //define this as a plug-in
T getParameter(std::string const &) const
void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
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:125
void setEtaBits(int bits)
Definition: MuonCaloSum.h:19
BXVector< RegionalMuonCand > RegionalMuonCandBxCollection
BXVector< MuonCaloSum > MuonCaloSumBxCollection
Definition: MuonCaloSumFwd.h:7
delete x;
Definition: CaloConfig.h:22
void setIndex(int idx)
Definition: MuonCaloSum.h:20
void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
L1TMicroGMTInputProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
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.
double f[11][100]
const int mu
Definition: Constants.h:22
static bool cmpProc(const RegionalMuonCand &, const RegionalMuonCand &)
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) ...
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int convertToInt(std::string &bitstr) const
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:511
Definition: Run.h:45
void setHwSign(int bits)
Set charge sign bit (charge = (-1)^(sign))