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