CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESRawDataTask.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
9 
12 
19 
25 
27 
28 using namespace cms;
29 using namespace edm;
30 using namespace std;
31 
33 
34  init_ = false;
35 
36  dqmStore_ = Service<DQMStore>().operator->();
37 
38  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
39  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
40  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
41 
42  FEDRawDataCollection_ = ps.getParameter<InputTag>("FEDRawDataCollection");
43  dccCollections_ = ps.getParameter<InputTag>("ESDCCCollections");
44 
45 }
46 
48 }
49 
51 
52  ievt_ = 0;
53 
54  if ( dqmStore_ ) {
55  dqmStore_->setCurrentFolder(prefixME_ + "/ESRawDataTask");
56  dqmStore_->rmdir(prefixME_ + "/ESRawDataTask");
57  }
58 
59 }
60 
61 void ESRawDataTask::beginRun(const Run& r, const EventSetup& c) {
62 
63  if ( ! mergeRuns_ ) this->reset();
64 
65 }
66 
67 void ESRawDataTask::endRun(const Run& r, const EventSetup& c) {
68 
69 }
70 
72 
73 }
74 
76 
77  init_ = true;
78 
79  char histo[200];
80 
81  if (dqmStore_) {
82  dqmStore_->setCurrentFolder(prefixME_ + "/ESRawDataTask");
83 
84  //sprintf(histo, "ES run number errors");
85  //meRunNumberErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
86  //meRunNumberErrors_->setAxisTitle("ES FED", 1);
87  //meRunNumberErrors_->setAxisTitle("Num of Events", 2);
88 
89  sprintf(histo, "ES L1A DCC errors");
90  meL1ADCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
91  meL1ADCCErrors_->setAxisTitle("ES FED", 1);
92  meL1ADCCErrors_->setAxisTitle("Num of Events", 2);
93 
94  sprintf(histo, "ES BX DCC errors");
95  meBXDCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
96  meBXDCCErrors_->setAxisTitle("ES FED", 1);
97  meBXDCCErrors_->setAxisTitle("Num of Events", 2);
98 
99  sprintf(histo, "ES Orbit Number DCC errors");
100  meOrbitNumberDCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
101  meOrbitNumberDCCErrors_->setAxisTitle("ES FED", 1);
102  meOrbitNumberDCCErrors_->setAxisTitle("Num of Events", 2);
103 
104  sprintf(histo, "Difference between ES and GT L1A");
105  meL1ADiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
106  meL1ADiff_->setAxisTitle("ES - GT L1A", 1);
107  meL1ADiff_->setAxisTitle("Num of Events", 2);
108 
109  sprintf(histo, "Difference between ES and GT BX");
110  meBXDiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
111  meBXDiff_->setAxisTitle("ES - GT BX", 1);
112  meBXDiff_->setAxisTitle("Num of Events", 2);
113 
114  sprintf(histo, "Difference between ES and GT Orbit Number");
115  meOrbitNumberDiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
116  meOrbitNumberDiff_->setAxisTitle("ES - GT orbit number", 1);
117  meOrbitNumberDiff_->setAxisTitle("Num of Events", 2);
118  }
119 
120 }
121 
123 
124  if ( ! init_ ) return;
125 
126  if ( dqmStore_ ) {
127  //if ( meRunNumberErrors_ ) dqmStore_->removeElement( meRunNumberErrors_->getName() );
128  //meRunNumberErrors_ = 0;
129 
130  if ( meL1ADCCErrors_ ) dqmStore_->removeElement( meL1ADCCErrors_->getName() );
131  meL1ADCCErrors_ = 0;
132 
133  if ( meBXDCCErrors_ ) dqmStore_->removeElement( meBXDCCErrors_->getName() );
134  meBXDCCErrors_ = 0;
135 
136  if ( meOrbitNumberDCCErrors_ ) dqmStore_->removeElement( meOrbitNumberDCCErrors_->getName() );
137  meOrbitNumberDCCErrors_ = 0;
138 
139  if ( meL1ADiff_ ) dqmStore_->removeElement( meL1ADiff_->getName() );
140  meL1ADiff_ = 0;
141 
142  if ( meBXDiff_ ) dqmStore_->removeElement( meBXDiff_->getName() );
143  meBXDiff_ = 0;
144 
145  if ( meOrbitNumberDiff_ ) dqmStore_->removeElement( meOrbitNumberDiff_->getName() );
146  meOrbitNumberDiff_ = 0;
147  }
148 
149  init_ = false;
150 
151 }
152 
154 
155  LogInfo("ESRawDataTask") << "analyzed " << ievt_ << " events";
156 
157  if ( enableCleanup_ ) this->cleanup();
158 
159 }
160 
161 void ESRawDataTask::analyze(const Event& e, const EventSetup& c){
162 
163  if ( ! init_ ) this->setup();
164 
165  ievt_++;
166  runNum_ = e.id().run();
167 
168  int gt_L1A = 0, gt_OrbitNumber = 0, gt_BX = 0;
169  int esDCC_L1A_MostFreqCounts = 0;
170  int esDCC_BX_MostFreqCounts = 0;
171  int esDCC_OrbitNumber_MostFreqCounts = 0;
172 
174  Handle<FEDRawDataCollection> allFedRawData;
175 
176  int gtFedDataSize = 0;
177 
178  if ( e.getByLabel(FEDRawDataCollection_, allFedRawData) ) {
179 
180  // GT FED data
181  const FEDRawData& gtFedData = allFedRawData->FEDData(812);
182 
183  gtFedDataSize = gtFedData.size()/sizeof(uint64_t);
184 
185  if ( gtFedDataSize > 0 ) {
186 
187  FEDHeader header(gtFedData.data());
188 
189  gt_L1A = header.lvl1ID();
190  gt_OrbitNumber = e.orbitNumber();
191  gt_BX = e.bunchCrossing();
192  } else {
193 
194  map<int, int> esDCC_L1A_FreqMap;
195  map<int, int> esDCC_BX_FreqMap;
196  map<int, int> esDCC_OrbitNumber_FreqMap;
197 
198  if ( e.getByLabel(dccCollections_, dccs) ) {
199  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
200  ESDCCHeaderBlock esdcc = (*dccItr);
201 
202  esDCC_L1A_FreqMap[esdcc.getLV1()]++;
203  esDCC_BX_FreqMap[esdcc.getBX()]++;
204  esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
205 
206  if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
207  esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
208  gt_L1A = esdcc.getLV1();
209  }
210 
211  if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
212  esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
213  gt_BX = esdcc.getBX();
214  }
215 
216  if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
217  esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
218  gt_OrbitNumber = esdcc.getOrbitNumber();
219  }
220 
221  }
222  } else {
223  LogWarning("ESRawDataTask") << dccCollections_ << " not available";
224  }
225 
226  }
227  } else {
228  LogWarning("ESRawDataTask") << FEDRawDataCollection_ << " not available";
229  }
230 
231  // DCC
232  vector<int> fiberStatus;
233  if ( e.getByLabel(dccCollections_, dccs) ) {
234 
235  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
236  ESDCCHeaderBlock dcc = (*dccItr);
237 
238  //if (dcc.getRunNumber() != runNum_) {
239  //meRunNumberErrors_->Fill(dcc.fedId());
240  //cout<<"Run # err : "<<dcc.getRunNumber()<<" "<<runNum_<<endl;
241  //}
242 
243  if (dcc.getLV1() != gt_L1A) {
244  meL1ADCCErrors_->Fill(dcc.fedId());
245  //cout<<"L1A err : "<<dcc.getLV1()<<" "<<gt_L1A<<endl;
246  Float_t l1a_diff = dcc.getLV1() - gt_L1A;
247  if (l1a_diff > 100) l1a_diff = 100;
248  else if (l1a_diff < -100) l1a_diff = -100;
249  meL1ADiff_->Fill(l1a_diff);
250  }
251 
252  if (dcc.getBX() != gt_BX) {
253  meBXDCCErrors_->Fill(dcc.fedId());
254  //cout<<"BX err : "<<dcc.getBX()<<" "<<gt_BX<<endl;
255  Float_t bx_diff = dcc.getBX() - gt_BX;
256  if (bx_diff > 100) bx_diff = 100;
257  else if (bx_diff < -100) bx_diff = -100;
258  meBXDiff_->Fill(bx_diff);
259  }
260  if (dcc.getOrbitNumber() != gt_OrbitNumber) {
261  meOrbitNumberDCCErrors_->Fill(dcc.fedId());
262  //cout<<"Orbit err : "<<dcc.getOrbitNumber()<<" "<<gt_OrbitNumber<<endl;
263  Float_t orbitnumber_diff = dcc.getOrbitNumber() - gt_OrbitNumber;
264  if (orbitnumber_diff > 100) orbitnumber_diff = 100;
265  else if (orbitnumber_diff < -100) orbitnumber_diff = -100;
266  meOrbitNumberDiff_->Fill(orbitnumber_diff);
267  }
268  }
269  }
270 
271 }
272 
RunNumber_t run() const
Definition: EventID.h:42
virtual ~ESRawDataTask()
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int getLV1() const
void cleanup(void)
Cleanup.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< T >::const_iterator const_iterator
static void cleanup(const Factory::MakerMap::value_type &v)
Definition: Factory.cc:12
int bunchCrossing() const
Definition: EventBase.h:62
tuple histo
Definition: trackerHits.py:12
void setup(void)
Setup.
void beginJob(void)
BeginJob.
ESRawDataTask(const edm::ParameterSet &ps)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
int getBX() const
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
int getOrbitNumber() const
int orbitNumber() const
Definition: EventBase.h:63
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
void endJob(void)
EndJob.
unsigned long long uint64_t
Definition: Time.h:15
edm::EventID id() const
Definition: EventBase.h:56
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
const int fedId() const
int lvl1ID()
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:22
void reset(void)
Reset.
void reset(double vett[256])
Definition: TPedValues.cc:11
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:32