CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
38 
39 #include <iostream>
40 //
41 // class declaration
42 //
43 using namespace l1t;
44 
46  public:
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52  private:
53  virtual void beginJob() ;
54  virtual void produce(edm::Event&, const edm::EventSetup&);
55  virtual void endJob() ;
56 
57  virtual void beginRun(edm::Run&, edm::EventSetup const&);
58  virtual void endRun(edm::Run&, edm::EventSetup const&);
59  virtual void beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
60  virtual void endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
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<GMTInputCaloSumBxCollection>("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::auto_ptr<RegionalMuonCandBxCollection> barrelMuons (new RegionalMuonCandBxCollection());
163  std::auto_ptr<RegionalMuonCandBxCollection> overlapMuons (new RegionalMuonCandBxCollection());
164  std::auto_ptr<RegionalMuonCandBxCollection> endcapMuons (new RegionalMuonCandBxCollection());
165  std::auto_ptr<GMTInputCaloSumBxCollection> towerSums (new GMTInputCaloSumBxCollection());
166 
168  GMTInputCaloSum 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(barrelMuons, "BarrelTFMuons");
304  iEvent.put(overlapMuons, "OverlapTFMuons");
305  iEvent.put(endcapMuons, "ForwardTFMuons");
306  iEvent.put(towerSums, "TriggerTowerSums");
307  m_currEvt++;
308 
309 }
310 
311 // ------------ method called once each job just before starting event loop ------------
312 void
314 {
315 }
316 
317 // ------------ method called once each job just after ending the event loop ------------
318 void
320 }
321 
322 // ------------ method called when starting to processes a run ------------
323 void
325 {
326 }
327 
328 // ------------ method called when ending the processing of a run ------------
329 void
331 {
332 }
333 
334 // ------------ method called when starting to processes a luminosity block ------------
335 void
337 {
338 }
339 
340 // ------------ method called when ending the processing of a luminosity block ------------
341 void
343 {
344 }
345 
346 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
347 void
349  //The following says we do not know what parameters are allowed so do no validation
350  // Please change this to state exactly what you do use, even if it is no parameters
352  desc.setUnknown();
353  descriptions.addDefault(desc);
354 }
355 
356 //define this as a plug-in
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
BXVector< RegionalMuonCand > RegionalMuonCandBxCollection
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
virtual void beginRun(edm::Run &, edm::EventSetup const &)
void beginJob()
Definition: Breakpoints.cc:15
L1TMicroGMTInputProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
virtual void produce(edm::Event &, const edm::EventSetup &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
double f[11][100]
const int mu
Definition: Constants.h:22
static bool cmpProc(const RegionalMuonCand &, const RegionalMuonCand &)
BXVector< GMTInputCaloSum > GMTInputCaloSumBxCollection
const int processor() const
Get processor ID on which the candidate was found (1..6 for OMTF/EMTF; 1..12 for BMTF) ...
int convertToInt(std::string &bitstr) const
virtual void endLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
volatile std::atomic< bool > shutdown_flag false
virtual void endRun(edm::Run &, edm::EventSetup const &)
Definition: Run.h:43