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