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
Ecal2004TBTDCRanges_v1_cff.endRun
endRun
Definition: Ecal2004TBTDCRanges_v1_cff.py:4
l1t::bmtf
Definition: RegionalMuonCandFwd.h:8
l1t::emtf_neg
Definition: RegionalMuonCandFwd.h:8
l1t::RegionalMuonCand::processor
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF)
Definition: RegionalMuonCand.h:179
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
L1TMicroGMTInputProducer::cmpProc
static bool cmpProc(const RegionalMuonCand &, const RegionalMuonCand &)
Definition: L1TMicroGMTInputProducer.cc:110
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
l1t::omtf_pos
Definition: RegionalMuonCandFwd.h:8
MuonCaloSumFwd.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
L1TMicroGMTInputProducer::~L1TMicroGMTInputProducer
~L1TMicroGMTInputProducer() override
Definition: L1TMicroGMTInputProducer.cc:101
L1TMicroGMTInputProducer::openFile
void openFile()
Definition: L1TMicroGMTInputProducer.cc:114
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
L1TMicroGMTInputProducer::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
Definition: L1TMicroGMTInputProducer.cc:310
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
l1t::MuonCaloSum::setPhiBits
void setPhiBits(int bits)
Definition: MuonCaloSum.h:16
EDProducer.h
l1t::MuonCaloSum::setEtaBits
void setEtaBits(int bits)
Definition: MuonCaloSum.h:17
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
L1TMicroGMTInputProducer::endRun
void endRun(const edm::Run &, edm::EventSetup const &) override
Definition: L1TMicroGMTInputProducer.cc:304
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
optionsL1T.skip
skip
Definition: optionsL1T.py:30
MakerMacros.h
L1TMicroGMTInputProducer::m_lastMuInBx
bool m_lastMuInBx
Definition: L1TMicroGMTInputProducer.cc:70
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TMicroGMTInputProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TMicroGMTInputProducer.cc:313
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
l1t::MuonCaloSum::setEtBits
void setEtBits(int bits)
Definition: MuonCaloSum.h:15
L1TMicroGMTInputProducer::m_endOfBx
bool m_endOfBx
Definition: L1TMicroGMTInputProducer.cc:69
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
edm::ParameterSet
Definition: ParameterSet.h:47
L1TMicroGMTInputProducer::m_fname
std::string m_fname
Definition: L1TMicroGMTInputProducer.cc:67
Event.h
l1t
delete x;
Definition: CaloConfig.h:22
L1TMicroGMTInputProducer::m_currEvt
int m_currEvt
Definition: L1TMicroGMTInputProducer.cc:72
L1TMicroGMTInputProducer
Definition: L1TMicroGMTInputProducer.cc:46
L1TMicroGMTInputProducer::convertToInt
int convertToInt(std::string &bitstr) const
Definition: L1TMicroGMTInputProducer.cc:130
L1TMicroGMTInputProducer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
Definition: L1TMicroGMTInputProducer.cc:307
createfilelist.int
int
Definition: createfilelist.py:10
L1TMicroGMTInputProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TMicroGMTInputProducer.cc:141
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
l1t::RegionalMuonCandBxCollection
BXVector< RegionalMuonCand > RegionalMuonCandBxCollection
Definition: RegionalMuonCandFwd.h:9
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
edm::EventSetup
Definition: EventSetup.h:58
l1t::MuonCaloSumBxCollection
BXVector< MuonCaloSum > MuonCaloSumBxCollection
Definition: MuonCaloSumFwd.h:7
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
MuonCaloSum.h
l1t::emtf_pos
Definition: RegionalMuonCandFwd.h:8
l1t::MuonCaloSum
Definition: MuonCaloSum.h:7
Frameworkfwd.h
Exception
Definition: hltDiff.cc:245
l1t::MuonCaloSum::setIndex
void setIndex(int idx)
Definition: MuonCaloSum.h:18
L1TMicroGMTInputProducer::m_currType
int m_currType
Definition: L1TMicroGMTInputProducer.cc:71
RegionalMuonCand.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
L1TMicroGMTInputProducer::beginRun
void beginRun(const edm::Run &, edm::EventSetup const &) override
Definition: L1TMicroGMTInputProducer.cc:301
L1TMicroGMTInputProducer::L1TMicroGMTInputProducer
L1TMicroGMTInputProducer(const edm::ParameterSet &)
Definition: L1TMicroGMTInputProducer.cc:86
L1TMicroGMTInputProducer::skipHeader
void skipHeader()
Definition: L1TMicroGMTInputProducer.cc:123
RegionalMuonCandFwd.h
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::Event
Definition: Event.h:73
l1t::omtf_neg
Definition: RegionalMuonCandFwd.h:8
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
L1TMicroGMTInputProducer::m_filestream
std::ifstream m_filestream
Definition: L1TMicroGMTInputProducer.cc:68
l1t::RegionalMuonCand
Definition: RegionalMuonCand.h:8