CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuGMTHWFileReader.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // \class L1MuGMTHWFileReader
4 //
5 // Description: Puts the GMT input information from
6 // a GMT ascii HW testfile into the Event
7 //
8 //
9 // $Date: 2012/11/19 21:03:41 $
10 // $Revision: 1.5 $
11 //
12 // Author :
13 // Tobias Noebauer HEPHY Vienna
14 // Ivan Mikulec HEPHY Vienna
15 //
16 //--------------------------------------------------
17 
18 //-----------------------
19 // This Class's Header --
20 //-----------------------
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 #include <stdexcept>
27 
28 //-------------------------------
29 // Collaborating Class Headers --
30 //-------------------------------
33 
35 
36 //----------------
37 // Constructors --
38 //----------------
40  edm::InputSourceDescription const& desc) :
41  ProducerSourceFromFiles(ps, desc, true) {
42 
43  produces<std::vector<L1MuRegionalCand> >("DT");
44  produces<std::vector<L1MuRegionalCand> >("CSC");
45  produces<std::vector<L1MuRegionalCand> >("RPCb");
46  produces<std::vector<L1MuRegionalCand> >("RPCf");
47 
48  produces<L1CaloRegionCollection>();
49 
50  if(!fileNames().size()) {
51  throw std::runtime_error("L1MuGMTHWFileReader: no input file");
52  }
53  edm::LogInfo("GMT_HWFileReader_info") << "opening file " << fileNames()[0];
54  m_in.open((fileNames()[0].substr(fileNames()[0].find(":")+1)).c_str());
55  if(!m_in) {
56  throw std::runtime_error("L1MuGMTHWFileReader: file " + fileNames()[0]
57  + " could not be openned");
58  }
59 
60 }
61 
62 //--------------
63 // Destructor --
64 //--------------
66  m_in.close();
67 }
68 
69 //--------------
70 // Operations --
71 //--------------
73  readNextEvent();
74  if(!m_evt.getRunNumber() && !m_evt.getEventNumber()) return false;
75  id = edm::EventID(m_evt.getRunNumber(), id.luminosityBlock(), m_evt.getEventNumber());
76 
77  edm::LogInfo("GMT_HWFileReader_info") << "run: " << m_evt.getRunNumber() <<
78  " evt: " << m_evt.getEventNumber();
79  return true;
80 }
81 
83  L1MuRegionalCand empty_mu;
84 
85 
86  std::auto_ptr<std::vector<L1MuRegionalCand> > DTCands(new std::vector<L1MuRegionalCand>);
87  for (unsigned i = 0; i < 4; i++) {
88  const L1MuRegionalCand *mu = m_evt.getInputMuon("IND", i);
89  if (!mu) mu = &empty_mu;
90  DTCands->push_back(*mu);
91  }
92  e.put(DTCands,"DT");
93 
94  std::auto_ptr<std::vector<L1MuRegionalCand> > CSCCands(new std::vector<L1MuRegionalCand>);
95  for (unsigned i = 0; i < 4; i++) {
96  const L1MuRegionalCand *mu = m_evt.getInputMuon("INC", i);
97  if (!mu) mu = &empty_mu;
98  CSCCands->push_back(*mu);
99  }
100  e.put(CSCCands,"CSC");
101 
102  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCbCands(new std::vector<L1MuRegionalCand>);
103  for (unsigned i = 0; i < 4; i++) {
104  const L1MuRegionalCand *mu = m_evt.getInputMuon("INB", i);
105  if (!mu) mu = &empty_mu;
106  RPCbCands->push_back(*mu);
107  }
108  e.put(RPCbCands,"RPCb");
109 
110  std::auto_ptr<std::vector<L1MuRegionalCand> > RPCfCands(new std::vector<L1MuRegionalCand>);
111  for (unsigned i = 0; i < 4; i++) {
112  const L1MuRegionalCand *mu = m_evt.getInputMuon("INF", i);
113  if (!mu) mu = &empty_mu;
114  RPCfCands->push_back(*mu);
115  }
116  e.put(RPCfCands,"RPCf");
117 
118  std::auto_ptr<L1CaloRegionCollection> rctRegions (new L1CaloRegionCollection);
119  for(int ieta = 4; ieta < 18; ieta++) {
120  for(int iphi = 0; iphi < 18; iphi++) {
121  rctRegions->push_back(L1CaloRegion(0,false,true,m_evt.getMipBit(ieta-4,iphi),m_evt.getIsoBit(ieta-4,iphi),ieta,iphi));
122  }
123  }
124 
125  e.put(rctRegions);
126 }
127 
129  m_evt.reset();
130 
131  std::string line_id;
132  do {
133  int bx = 0;
134 
135  m_in >> line_id;
136  if (line_id == "--") continue;
137 
138  if (line_id == "RUN") {
139  unsigned long runnr;
140  m_in >> runnr;
141  m_evt.setRunNumber(runnr);
142  }
143 
144  if (line_id == "EVT") {
145  unsigned long evtnr;
146  m_in >> evtnr;
147  m_evt.setEventNumber(evtnr);
148  }
149 
150 
151  if (line_id == "DT" || line_id == "CSC" || line_id == "BRPC" || line_id == "FRPC")
152  {
153 
154  // decode input muon
155 
156  unsigned inpmu = 0;
157  unsigned val;
158  m_in >> val; inpmu |= (val & 0x01) << 24; // valid charge
159  m_in >> val; inpmu |= (val & 0x01) << 23; // charge
160  m_in >> val; inpmu |= (val & 0x01) << 22; // halo / fine
161  m_in >> val; inpmu |= (val & 0x3f) << 16; // eta
162  m_in >> val; inpmu |= (val & 0x07) << 13; // quality
163  m_in >> val; inpmu |= (val & 0x1f) << 8; // pt
164  m_in >> val; inpmu |= (val & 0xff) ; // phi
165 
166  std::string chipid("IN");
167  chipid += line_id[0];
168 
169  int type=0;
170  if (line_id == "DT") type = 0;
171  if (line_id == "CSC") type = 2;
172  if (line_id == "BRPC") type = 1;
173  if (line_id == "FRPC") type = 3;
174 
175 
176  L1MuRegionalCand cand(inpmu);
177  cand.setType(type);
178  cand.setBx(bx);
179  m_evt.addInputMuon(chipid, cand);
180  }
181 
182  if (line_id == "MIP") {
183  int nPairs;
184  m_in >> nPairs;
185  for (int i=0; i<nPairs; i++) {
186  unsigned eta;
187  unsigned phi;
188  m_in >> eta;
189  m_in >> phi;
190  if (phi >= 9) phi-=9;
191  else phi+=9;
192  m_evt.setMipBit(eta, phi, true);
193  }
194  }
195 
196  if (line_id == "NQ") {
197  int nPairs;
198  m_in >> nPairs;
199  for (int i=0; i<nPairs; i++) {
200  unsigned eta;
201  unsigned phi;
202  m_in >> eta;
203  m_in >> phi;
204  if (phi >= 9) phi-=9;
205  else phi+=9;
206  m_evt.setIsoBit(eta, phi, false);
207  }
208  }
209 
210  //read the rest of the line
211  const int sz=4000; char buf[sz];
212  m_in.getline(buf, sz);
213 
214  } while (line_id != "NQ" && !m_in.eof());
215 
216 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
L1MuGMTHWFileReader(edm::ParameterSet const &, edm::InputSourceDescription const &)
T eta() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void setRunNumber(unsigned long runnr)
unsigned long getRunNumber() const
get the Run number
std::vector< std::string > const & fileNames() const
Definition: FromFiles.h:22
void setBx(int bx)
Set Bunch Crossing.
unsigned long getEventNumber() const
get the Event number
virtual bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time)
L1MuGMTInputEvent m_evt
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
virtual void produce(edm::Event &)
void setType(unsigned type)
Set Type: 0 DT, 1 bRPC, 2 CSC, 3 fRPC.
const int mu
Definition: Constants.h:23
unsigned long long TimeValue_t
Definition: Timestamp.h:27
void addInputMuon(std::string chipid, const L1MuRegionalCand &inMu)
void setIsoBit(unsigned etaIndex, unsigned phiIndex, bool val)
const L1MuRegionalCand * getInputMuon(std::string chipid, unsigned index) const
const bool & getMipBit(unsigned etaIndex, unsigned phiIndex)
const bool & getIsoBit(unsigned etaIndex, unsigned phiIndex)
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:22
std::vector< L1CaloRegion > L1CaloRegionCollection
void setEventNumber(unsigned long eventnr)
void setMipBit(unsigned etaIndex, unsigned phiIndex, bool val)
Definition: DDAxes.h:10