HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HGCalTBRawToDigi.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include "HGCal/RawToDigi/plugins/HGCalTBRawToDigi.h"
3 #include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
4 using namespace std;
5 
6 unsigned int gray_to_binary (unsigned int gray);
7 int counter=0;
8 HGCalTBRawToDigi::HGCalTBRawToDigi(edm::ParameterSet const& conf):
9  dataTag_(conf.getParameter<edm::InputTag>("InputLabel")),
10  fedId_(conf.getUntrackedParameter<int>("fedId")),
11  mapfile_(conf.getUntrackedParameter<std::string>("electronicsMap"))
12 {
13  produces<SKIROC2DigiCollection>();
14  consumes<FEDRawDataCollection>(dataTag_);
15 }
16 
18 {
19  ///\todo this should be done by an ESProducer
20  HGCalCondObjectTextIO io(0); // don't need a numbering scheme for this
21 
22  edm::FileInPath fip(mapfile_);
23  if (!io.load(fip.fullPath(), essource_.emap_)) {
24  throw cms::Exception("Unable to load electronics map");
25  }
26 }
27 
28 void HGCalTBRawToDigi::produce(edm::Event& e, const edm::EventSetup& c)
29 {
30  // Step A: Get Inputs
31  edm::Handle<FEDRawDataCollection> rawraw;
32  e.getByLabel(dataTag_, rawraw);
33 
34  std::auto_ptr<SKIROC2DigiCollection> digis(0);
35  //
36  const FEDRawData& fed = rawraw->FEDData(fedId_);
37  if (fed.size() != 0) { /// \todo Exception if 0????
38  int ski_up = 2;
39  int ski_down = 1;
40  // we can figure out the number of samples from the size of the raw data
41  int nsamples = fed.size() / (sizeof(uint16_t) * SKIROC::NCHANNELS * 2); // 2 is for ADC and TDC
42  digis = std::auto_ptr<SKIROC2DigiCollection>(new SKIROC2DigiCollection(nsamples));
43  const uint16_t* pdata = (const uint16_t*)(fed.data());
44 
45  // we start from the back...
46  int ptr = fed.size() / sizeof(uint16_t) - 1;
47 /*
48  printf("Starting on SKIROC %x\n", pdata[ptr]);
49  ptr--; // now we are pointing at a relatively-useless header word
50  ptr--; // now we are pointing at the first TDC word
51 */
52  counter++;
53  if(counter > 150){
54  ski_up = 4;
55  ski_down = 3;
56  }
57 
58  if(counter > 150*2 ){
59  ski_up = 6;
60  ski_down = 5;
61  }
62  if(counter > 150*3){
63  ski_up = 8;
64  ski_down = 7;
65  }
66  if(counter > 150*4){
67  ski_up = 10;
68  ski_down = 9;
69  }
70  if(counter > 150*5){
71  ski_up = 12;
72  ski_down = 11;
73  }
74  if(counter > 150*6){
75  ski_up = 14;
76  ski_down = 13;
77  }
78  if(counter > 150*7){
79  ski_up = 16;
80  ski_down = 15;
81  }
82  if(counter > 150*8 ){
83  ski_up = 18;
84  ski_down = 17;
85  }
86  if(counter > 150*9){
87  ski_up = 20;
88  ski_down = 19;
89  }
90  if(counter > 150*10){
91  ski_up = 22;
92  ski_down = 21;
93  }
94  if(counter > 150*11 ){
95  ski_up = 24;
96  ski_down = 23;
97  }
98  if(counter > 150*12){
99  ski_up = 26;
100  ski_down = 25;
101  }
102  if(counter > 150*13){
103  ski_up = 28;
104  ski_down = 27;
105  }
106  if(counter > 150*14){
107  ski_up = 30;
108  ski_down = 29;
109  }
110  if(counter > 150*15){
111  ski_up = 32;
112  ski_down = 31;
113  }
114 
115  if(counter == 150*MAXLAYERS) counter = 0;
116 // for (int ski = 2; ski >= 1; ski--) {
117  for (int ichan = 0; ichan < SKIROC::NCHANNELS; ichan++) {
118  for (int ski = ski_down; ski <= ski_up; ski++) {
119  HGCalTBElectronicsId eid(ski, ichan);
120  if (!essource_.emap_.existsEId(eid.rawId())) {
121 // std::cout << "We do not have a mapping for " << eid;
122  } else {
123  HGCalTBDetId did = essource_.emap_.eid2detId(eid);
124  digis->addDataFrame(did);
125  if(ski <=32){
126  int ptradc1 = ptr - ichan*2 - (ski - ski_down);
127  int ptradc2 = ptr - ichan*2 - (ski - ski_down) - 128;
128  digis->backDataFrame().setSample(0, gray_to_binary(pdata[ptradc1] & 0xFFF),gray_to_binary( pdata[ptradc2] & 0xFFF),0);
129 // cout<<endl<<dec<<"SKI= "<<ski<<" chan= "<<ichan<<" "<<ptradc1<<" "<<ptradc2<<" "<<" High= "<<hex<<(pdata[ptradc1])<<dec<<" "<<gray_to_binary(pdata[ptradc1] & 0xFFF)<<" Low= "<<hex<<( pdata[ptradc2] & 0xFFF)<<" "<<dec<<gray_to_binary( pdata[ptradc2] & 0xFFF)<<endl;
130  }
131 
132 /*
133  else{
134  int ptradc1 = ptr - ichan*2 + (ski_up - ski) ;
135  int ptradc2 = ptr - ichan*2 + (ski_up - ski) - 128;
136 // cout<<endl<<dec<<" Layer= "<<did.layer()<<" SKI= "<<eid.iskiroc()<<" chan= "<<ichan<<" "<<ptradc1<<" "<<ptradc2<<" "<<" High= "<<hex<<(pdata[ptradc1])<<dec<<" "<<gray_to_binary(pdata[ptradc1] & 0xFFF)<<" Low= "<<hex<<( pdata[ptradc2] & 0xFFF)<<" "<<dec<<gray_to_binary( pdata[ptradc2] & 0xFFF)<<endl;
137  digis->backDataFrame().setSample(0, gray_to_binary(pdata[ptradc1] & 0xFFF),gray_to_binary( pdata[ptradc2] & 0xFFF),0);
138 
139  }
140 */
141 
142  }
143  }//loop over skirocs
144  }
145 // }
146 
147  }// fed size > 0
148 
149  // put it into the event
150  e.put(digis);
151 }
152 
153 unsigned int gray_to_binary (unsigned int gray){
154 
155  unsigned int result = gray & (1 << 11);
156  result |= (gray ^ (result >> 1)) & (1 << 10);
157  result |= (gray ^ (result >> 1)) & (1 << 9);
158  result |= (gray ^ (result >> 1)) & (1 << 8);
159  result |= (gray ^ (result >> 1)) & (1 << 7);
160  result |= (gray ^ (result >> 1)) & (1 << 6);
161  result |= (gray ^ (result >> 1)) & (1 << 5);
162  result |= (gray ^ (result >> 1)) & (1 << 4);
163  result |= (gray ^ (result >> 1)) & (1 << 3);
164  result |= (gray ^ (result >> 1)) & (1 << 2);
165  result |= (gray ^ (result >> 1)) & (1 << 1);
166  result |= (gray ^ (result >> 1)) & (1 << 0);
167  return result;
168 }
169 
170 
171 #include "FWCore/PluginManager/interface/ModuleDef.h"
172 #include "FWCore/Framework/interface/MakerMacros.h"
173 
175 
DEFINE_FWK_MODULE(Pedestals)
virtual void produce(edm::Event &e, const edm::EventSetup &c)
bool load(const std::string &filename, HGCalCondObjectContainer< float > &)
load conditions from file
#define MAXLAYERS
unsigned int gray_to_binary(unsigned int gray)
uint32_t rawId() const
int counter
HGCalTBRawToDigi(const edm::ParameterSet &ps)
virtual void beginJob()
HGCalDataFrameContainer< SKIROC2DataFrame > SKIROC2DigiCollection