test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RctInputTextToDigi.cc
Go to the documentation of this file.
1 #include "RctInputTextToDigi.h"
2 
3 //
4 // constructors and destructor
5 //
6 
8  inputFile_(iConfig.getParameter<edm::FileInPath>("inputFile")),
9  inputStream_(inputFile_.fullPath().c_str()),
10  nEvent_(0),
11  oldVersion_(false),
12  lookupTables_(new L1RCTLookupTables)
13 {
14  //register your products
15  /* Examples
16  produces<ExampleData2>();
17 
18  //if do put with a label
19  produces<ExampleData2>("label");
20  */
21 
22  produces<EcalTrigPrimDigiCollection>();
23  produces<HcalTrigPrimDigiCollection>();
24 
25  //now do what ever other initialization is needed
26 
27  if ((!inputStream_.is_open())||(!inputStream_))
28  {
29  // not good!!
30  std::cerr << "Input file didn't open!!" << std::endl;
31  }
32  //if (inputStream_.eof()) {std::cout << "Real zeroth eof! " << std::endl;}
33 
34 }
35 
36 
38 {
39 
40  // do anything here that needs to be done at desctruction time
41  // (e.g. close files, deallocate resources etc.)
42 
43  inputStream_.close();
44 
45 }
46 
47 
48 //
49 // member functions
50 //
51 
52 // ------------ method called to produce the data ------------
53 void
55 {
56  using namespace edm;
57 
58  //std::cout << std::endl << std::endl << "Event number " << nEvent_ << std::endl;
59 
60  // This next section taken directly from
61  // L1Trigger/RegionalCaloTrigger/plugins/L1RCTProducer.cc rev. 1.6
62  // Refresh configuration information every event
63  // Hopefully doesn't take too much time
64  ESHandle<L1RCTParameters> rctParameters;
65  iSetup.get<L1RCTParametersRcd>().get(rctParameters);
66  const L1RCTParameters* r = rctParameters.product();
68 
69  std::auto_ptr<EcalTrigPrimDigiCollection>
70  ecalTPs(new EcalTrigPrimDigiCollection());
71  std::auto_ptr<HcalTrigPrimDigiCollection>
72  hcalTPs(new HcalTrigPrimDigiCollection());
73  ecalTPs->reserve(56*72);
74  hcalTPs->reserve(56*72+18*8); // includes HF
75  const int nEcalSamples = 1; // we only use 1 sample for each
76  const int nHcalSamples = 1;
77 
78  int fileEventNumber;
79 
80  // check to see if need to skip file header and do so before
81  // looping through entire event
82 
83  std::string junk;
84  //bool old_version = false;
85  if (nEvent_ == 0)
86  {
87  //std::string junk;
88  unsigned short junk_counter = 0;
89  //bool old_version = false;
90  do
91  {
92  if(inputStream_ >> junk) {/*std::cout << "Good: ";*/}
93  //std::cout << "header junk was input: \"" << junk << "\"."
94  // << std::endl;
95  // for oldest version, which is same as newest version
96  // if((junk_counter == 11) && (junk.compare("0-32") == 0))
97  // {
98  // oldVersion_ = true;
99  // }
100  if((junk_counter == 11) && (junk.compare("1-32") == 0))
101  {
102  oldVersion_ = true;
103  }
104  junk_counter++;
105  }
106  while (junk.compare("LUTOut") != 0);
107  std::cout << "Skipped file header" << std::endl;
108  if (oldVersion_) {std::cout << "oldVersion_ TRUE (tower 1-32)" << std::endl;}
109  else {std::cout << "oldVersion_ FALSE (tower 0-31)" << std::endl;}
110  }
111 
112  // can't actually read in phi and eta, file has crate card tower instead
113  // do a while loop for event number instead?? dunno
114  for (int i = 0; i < 72; i++)
115  {
116  // negative eta, iEta -28 to -1
117  for (int j = 0; j < 56; j++)
118  {
119  // calc ieta, iphi coords of tower
120  // ieta -28 to -1 or 1 to 28, iphi 1 to 72
121  // methods in CondFormats/L1TObjects/src/L1RCTParameters.cc
122 
123  unsigned short crate;
124  unsigned short card;
125  unsigned short tower;
126  unsigned eAddr;
127  unsigned hAddr;
128 
129  inputStream_ >> std::hex >> fileEventNumber >> crate >> card
130  >> tower
131  >> eAddr >> hAddr >> junk >> std::dec;
132 
133  if (oldVersion_)
134  {
135  tower = tower - 1;
136  }
137  int encodedEtEcal = (int) (eAddr>>1);
138  bool fineGrainEcal = (bool) (eAddr&1);
139  int encodedEtHcal = (int) (hAddr>>1);
140  bool fineGrainHcal = (bool) (hAddr&1); // mip bit
141 
142  //std::cout << "Eventnumber " << fileEventNumber << "\tCrate "
143  // << crate << "\tCard " << card << "\tTower "
144  // << tower << " \teAddr " << eAddr <<"\thAddr "
145  // << hAddr << "\tjunk " << junk << std::endl;
146 
147  int iEta = lookupTables_->rctParameters()->calcIEta(crate,card,tower);
148  int iPhi = lookupTables_->rctParameters()->calcIPhi(crate,card,tower);
149  // transform rct iphi coords into global coords
150  iPhi = ((72 + 18 - iPhi) % 72);
151  if (iPhi == 0) {iPhi = 72;}
152  unsigned absIeta = abs(iEta);
153  int zSide = (iEta/absIeta);
154 
155  /*std::cout << "iEta " << iEta << "\tabsiEta " << absIeta
156  << "\tiPhi " << iPhi << "\tzSide "
157  << zSide << std::endl;
158  */
159 
160  // args to detid are zside, type of tower, absieta, iphi
161  // absieta and iphi must be between 1 and 127 inclusive
162 
164  ecalDigi(EcalTrigTowerDetId(zSide, EcalTriggerTower, absIeta,
165  iPhi));
166  ecalDigi.setSize(nEcalSamples);
167 
168  // last arg is 3-bit trigger tower flag, which we don't use
169  // we only use 8-bit encoded et and 1-bit fg
170  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(encodedEtEcal,
171  fineGrainEcal, 0));
172  //std::cout << ecalDigi << std::endl;
173  ecalTPs->push_back(ecalDigi);
174 
176  hcalDigi(HcalTrigTowerDetId(iEta, iPhi));
177 
178  hcalDigi.setSize(nHcalSamples);
179 
180  // last two arg's are slb and slb channel, which we don't need
181  hcalDigi.setSample(0, HcalTriggerPrimitiveSample(encodedEtHcal,
182  fineGrainHcal,
183  0, 0));
184  //std::cout << hcalDigi << std::endl;
185  hcalTPs->push_back(hcalDigi);
186  }
187 
188  // also need to push_back HF digis!
189  // file input doesn't include HF, so need empty digis
190  for (int i = 0; i < 18; i++)
191  {
192  for (int j = 0; j < 8; j++)
193  {
194  // HF ieta: +- 29 through 32. HF iphi: 1,5,9,13,etc.
195  int hfIEta = (j%4)+29;
196  if (i < 9)
197  {
198  hfIEta = hfIEta*(-1);
199  }
200  // iphi shift not implemented, but not necessary here --
201  // everything's filled with zeros so it's symmetric anyhow
202  int hfIPhi = (i%9)*8 + (j/4)*4 + 1;
203 
205  hfDigi(HcalTrigTowerDetId(hfIEta, hfIPhi));
206  hfDigi.setSize(1);
207  hfDigi.setSample(0, HcalTriggerPrimitiveSample(0,0,0,0));
208  hcalTPs->push_back(hfDigi);
209  }
210  }
211  }
212  iEvent.put(ecalTPs);
213  iEvent.put(hcalTPs);
214 
215  nEvent_++;
216  //std::cout << "Produce done" << std::endl;
217 }
218 
219 // ------------ method called once each job just before starting event loop ------------
220 void
222 {
223  // open input file to read all events
224  //inputStream_.open(inputFile_.fullPath().c_str());
225  //std::cout << "beginJob entered" << std::endl;
226 }
227 
228 // ------------ method called once each job just after ending the event loop ------------
229 void
231 {
232  // close input file
233  //inputStream_.close();
234 }
235 
236 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
edm::SortedCollection< HcalTriggerPrimitiveDigi > HcalTrigPrimDigiCollection
short calcIEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:230
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
unsigned short calcIPhi(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
RctInputTextToDigi(const edm::ParameterSet &)
edm::SortedCollection< EcalTriggerPrimitiveDigi > EcalTrigPrimDigiCollection
L1RCTLookupTables * lookupTables_
const T & get() const
Definition: EventSetup.h:56
std::ifstream inputStream_
const L1RCTParameters * rctParameters() const
void setRCTParameters(const L1RCTParameters *rctParameters)
tuple cout
Definition: gather_cfg.py:145
volatile std::atomic< bool > shutdown_flag false