00001 #include "DQM/HcalMonitorTasks/interface/HcalEEUSMonitor.h"
00002
00003
00004 #define PI 3.1415926535897932
00005
00006 using namespace std;
00007 using namespace edm;
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 HcalEEUSMonitor::HcalEEUSMonitor()
00020 {
00021 for (int f=0; f<NUMFEDS;f++){
00022 for (int s=0; s<NUMSPIGS; s++) {
00023 consecutiveEETriggers[f][s] = 0;
00024 consecutiveNETriggers[f][s] = 0;
00025 consecutiveTriggers[f][s] = 0;
00026 prevWasEE[f][s] = 0;}}
00027
00028
00029 for (int f=0; f<NUMFEDS; f++) {
00030 for (int s=0; s<NUMSPIGS; s++) {
00031 UScount[f][s] = 0;
00032 }
00033 }
00034
00035
00036
00037 for (int f=0; f<NUMFEDS; f++) {
00038 for (int s=0; s<NUMSPIGS; s++) {
00039 US0EE0count[f][s] = 0;
00040 }
00041 }
00042
00043
00044 for (int f=0; f<NUMFEDS; f++) {
00045 for (int s=0; s<NUMSPIGS; s++) {
00046 US0EE1count[f][s] = 0;
00047 }
00048 }
00049
00050
00051 for (int f=0; f<NUMFEDS; f++) {
00052 for (int s=0; s<NUMSPIGS; s++) {
00053 US1EE0count[f][s] = 0;
00054 }
00055 }
00056
00057
00058 for (int f=0; f<NUMFEDS; f++) {
00059 for (int s=0; s<NUMSPIGS; s++) {
00060 US1EE1count[f][s] = 0;
00061 }
00062 }
00063
00064
00065 }
00066
00067
00068 HcalEEUSMonitor::~HcalEEUSMonitor() {}
00069
00070 void HcalEEUSMonitor::reset() {}
00071
00072 void HcalEEUSMonitor::clearME()
00073 {
00074 if (m_dbe)
00075 {
00076 m_dbe->setCurrentFolder(baseFolder_);
00077 m_dbe->removeContents();
00078 }
00079 meEVT_=0;
00080 }
00081
00082
00083 void HcalEEUSMonitor::setup(const edm::ParameterSet& ps, DQMStore* dbe)
00084 {
00085 HcalBaseMonitor::setup(ps,dbe);
00086
00087 ievt_=0;
00088 baseFolder_ = rootFolder_ + "EEUSMonitor";
00089 if (fVerbosity) cout <<"<HcalEEUSMonitor::setup> Setup in progress"<<endl;
00090
00091
00092 if(fVerbosity) cout << "About to pushback fedUnpackList_" << endl;
00093 firstFED_ = FEDNumbering::getHcalFEDIds().first;
00094 if (fVerbosity>0) cout <<"FIRST FED = "<<firstFED_<<endl;
00095
00096 for (int i=FEDNumbering::getHcalFEDIds().first;
00097 i<=FEDNumbering::getHcalFEDIds().second; ++i)
00098 {
00099 if(fVerbosity) cout << "<HcalEEUSMonitor::setup>:Pushback for fedUnpackList_: " << i <<endl;
00100 fedUnpackList_.push_back(i);
00101 }
00102
00103
00104
00105 if (m_dbe)
00106 {
00107 char* type;
00108 m_dbe->setCurrentFolder(baseFolder_);
00109 type = "EEUSMonitor Event Number";
00110 meEVT_ = m_dbe->bookInt(type);
00111
00112 char label[10];
00113
00114
00115
00116
00117 type = "Fraction Normal Events - US0 EE0";
00118 meNormFractSpigs_US0_EE0_ = m_dbe->book1D(type,type,481,0,481);
00119 for(int f=0; f<NUMFEDS; f++) {
00120 sprintf(label, "FED 7%02d", f);
00121 meNormFractSpigs_US0_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00122 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00123 sprintf(label, "sp%02d", s-1);
00124 meNormFractSpigs_US0_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00125
00126 type = "Fraction Empty Events - US0 EE1";
00127 meEEFractSpigs_US0_EE1_ = m_dbe->book1D(type,type,481,0,481);
00128 for(int f=0; f<NUMFEDS; f++) {
00129 sprintf(label, "FED 7%02d", f);
00130 meEEFractSpigs_US0_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00131 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00132 sprintf(label, "sp%02d", s-1);
00133 meEEFractSpigs_US0_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00134
00135 type = "Fraction UnSuppressed Events - US1 EE0";
00136 meUSFractSpigs_US1_EE0_ = m_dbe->book1D(type,type,481,0,481);
00137 for(int f=0; f<NUMFEDS; f++) {
00138 sprintf(label, "FED 7%02d", f);
00139 meUSFractSpigs_US1_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00140 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00141 sprintf(label, "sp%02d", s-1);
00142 meUSFractSpigs_US1_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00143
00144 type = "Fraction UnSuppressed Events - US1 EE1";
00145 meUSFractSpigs_US1_EE1_ = m_dbe->book1D(type,type,481,0,481);
00146 for(int f=0; f<NUMFEDS; f++) {
00147 sprintf(label, "FED 7%02d", f);
00148 meUSFractSpigs_US1_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00149 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00150 sprintf(label, "sp%02d", s-1);
00151 meUSFractSpigs_US1_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00152
00153
00154
00155 type = "Length of raw data - US0 EE0";
00156 meRawDataLength2_US0_EE0_ = m_dbe->book2D(type,type,481,0,481,600,0,1200);
00157 for(int f=0; f<NUMFEDS; f++) {
00158 sprintf(label, "FED 7%02d", f);
00159 meRawDataLength2_US0_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00160 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00161 sprintf(label, "sp%02d", s-1);
00162 meRawDataLength2_US0_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00163
00164 type = "Length of raw data - US0 EE1";
00165 meRawDataLength2_US0_EE1_ = m_dbe->book2D(type,type,481,0,481,600,0,1200);
00166 for(int f=0; f<NUMFEDS; f++) {
00167 sprintf(label, "FED 7%02d", f);
00168 meRawDataLength2_US0_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00169 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00170 sprintf(label, "sp%02d", s-1);
00171 meRawDataLength2_US0_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00172
00173 type = "Length of raw data - US1 EE0";
00174 meRawDataLength2_US1_EE0_ = m_dbe->book2D(type,type,481,0,481,600,0,1200);
00175 for(int f=0; f<NUMFEDS; f++) {
00176 sprintf(label, "FED 7%02d", f);
00177 meRawDataLength2_US1_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00178 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00179 sprintf(label, "sp%02d", s-1);
00180 meRawDataLength2_US1_EE0_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00181
00182 type = "Length of raw data - US1 EE1";
00183 meRawDataLength2_US1_EE1_ = m_dbe->book2D(type,type,481,0,481,600,0,1200);
00184 for(int f=0; f<NUMFEDS; f++) {
00185 sprintf(label, "FED 7%02d", f);
00186 meRawDataLength2_US1_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00187 for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00188 sprintf(label, "sp%02d", s-1);
00189 meRawDataLength2_US1_EE1_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00190
00191
00192
00193
00194
00195 type="EE Spigot Correlation";
00196 meEECorrel_ = m_dbe->book2D(type, type,
00197 (NUMSPIGS * NUMFEDS), 0, (NUMSPIGS * NUMFEDS),
00198 (NUMSPIGS * NUMFEDS), 0, (NUMSPIGS * NUMFEDS));
00199 type="EE per Spigot";
00200 meEEPerSpigot_ = m_dbe->book1D(type, type,
00201 (NUMSPIGS * NUMFEDS), 0, (NUMSPIGS * NUMFEDS));
00202 type="EE Spigots per Event";
00203 meEEThisEvent_ = m_dbe->book1D(type, type,500,-0.5,499.5);
00204
00205
00206
00207 char title[128];
00208 sprintf(title, "EE Triggers");
00209 meNumberEETriggered_ = m_dbe->book2D(title,title,(NUMSPIGS * NUMFEDS),0,(NUMSPIGS * NUMFEDS),100,-0.5,99.5);
00210 sprintf(title, "NE Triggers");
00211 meNumberNETriggered_ = m_dbe->book2D(title,title,(NUMSPIGS * NUMFEDS),0,(NUMSPIGS * NUMFEDS),100,-0.5,99.5);
00212 sprintf(title, "Triggers");
00213 meNumberTriggered_ = m_dbe->book2D(title,title,(NUMSPIGS * NUMFEDS),0,(NUMSPIGS * NUMFEDS),100,-0.5,99.5);
00214
00215 for (int f=0; f<NUMFEDS;f++){
00216 sprintf(label, "DCC 7%02d", f);
00217 meEECorrel_->setBinLabel(1+(f*NUMSPIGS), label, 1);
00218 meEECorrel_->setBinLabel(1+(f*NUMSPIGS), label, 2);
00219 meEEPerSpigot_->setBinLabel(1+(f*NUMSPIGS), label, 1);
00220 meNumberEETriggered_->setBinLabel(1+(f*NUMSPIGS), label, 1);
00221 meNumberNETriggered_->setBinLabel(1+(f*NUMSPIGS), label, 1);
00222 meNumberTriggered_->setBinLabel(1+(f*NUMSPIGS), label, 1);
00223 for (int s=1; s<NUMSPIGS; s+=2) {
00224 sprintf(label, "Spgt %02d", s-1);
00225 meEECorrel_->setBinLabel((f*NUMSPIGS)+s+1, label, 1);
00226 meEECorrel_->setBinLabel((f*NUMSPIGS)+s+1, label, 2);
00227 meEEPerSpigot_->setBinLabel((f*NUMSPIGS)+s+1, label, 1);
00228 meNumberEETriggered_->setBinLabel((f*NUMSPIGS)+s+1, label, 1);
00229 meNumberNETriggered_->setBinLabel((f*NUMSPIGS)+s+1, label, 1);
00230 meNumberTriggered_->setBinLabel((f*NUMSPIGS)+s+1, label, 1);}}
00231
00232 prevOrN = -1;
00233 }
00234
00235 return;
00236
00237 }
00238
00239
00240 void HcalEEUSMonitor::processEvent( const FEDRawDataCollection& rawraw,
00241 const HcalUnpackerReport& report,
00242 const HcalElectronicsMap& emap
00243 )
00244
00245 {
00246 if (!m_dbe)
00247 {
00248 if (fVerbosity) cout <<"HcalEEUSMonitor::processEvent DQMStore not instantiated!!!"<<endl;
00249 return;
00250 }
00251
00252
00253 ievt_++;
00254 meEVT_->Fill(ievt_);
00255
00256
00257
00258 for (int i=0; i<(NUMSPIGS*NUMFEDS); i++)
00259 EEthisEvent[i]=false;
00260
00261 processEvent_RawData(rawraw, report, emap);
00262 prevOrN=dccOrN;
00263 return;
00264 }
00265
00266
00267 void HcalEEUSMonitor::processEvent_RawData(const FEDRawDataCollection& rawraw,
00268 const HcalUnpackerReport& report,
00269 const HcalElectronicsMap& emap)
00270 {
00271
00272
00273
00274
00275
00276
00277
00278
00279 if(!m_dbe)
00280 {
00281 cout <<"HcalEEUSMonitor::processEvent_RawData: DQMStore not instantiated!!!\n"<<endl;
00282 return;
00283 }
00284 numEEthisEvent = 0;
00285
00286 for (vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++)
00287 {
00288 const FEDRawData& fed = rawraw.FEDData(*i);
00289 if (fed.size()<12) continue;
00290 unpack(fed,emap);
00291 }
00292
00293 prevOrN=dccOrN;
00294 meEEThisEvent_->Fill(numEEthisEvent);
00295 numEEthisEvent = 0;
00296
00297
00298
00299 for (int outer=0; outer<(NUMSPIGS*NUMFEDS); outer++)
00300 if (EEthisEvent[outer])
00301 for (int inner=0; inner<(NUMSPIGS*NUMFEDS); inner++)
00302 if (EEthisEvent[inner])
00303 meEECorrel_->Fill(outer, inner);
00304
00305 return;
00306
00307 }
00308
00309
00310
00311
00312 void HcalEEUSMonitor::unpack(const FEDRawData& raw,
00313 const HcalElectronicsMap& emap)
00314 {
00315
00316
00317
00318
00319
00320
00321 const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
00322 if(!dccHeader) return;
00323
00324
00325 unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
00326 FEDTrailer trailer = FEDTrailer(trailer_ptr);
00327
00328
00329
00330
00331 int dccid = dccHeader->getSourceId();
00332
00333 dccOrN = dccHeader->getOrbitNumber();
00334
00335
00336 uint64_t* lastDataWord = (uint64_t*) ( raw.data()+raw.size()-(2*sizeof(uint64_t)) );
00337 int EvFragLength = ((*lastDataWord>>32)*8);
00338 EvFragLength = raw.size();
00339
00340
00341 unsigned char WholeErrorList=0;
00342 for(int j=0; j<HcalDCCHeader::SPIGOT_COUNT; j++) {
00343 WholeErrorList=dccHeader->getSpigotErrorBits((unsigned int) j);
00344
00345 if ((WholeErrorList>>2)&0x01) EEthisEvent[(NUMSPIGS *max(0,dccid-700))+j] = true;
00346 }
00347
00348
00349
00350
00351 HcalHTRData htr;
00352 for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
00353 if (!dccHeader->getSpigotPresent(spigot)) continue;
00354
00355 bool chsummAOK=true;
00356
00357
00358
00359 WholeErrorList=dccHeader->getLRBErrorBits((unsigned int) spigot);
00360
00361 dccHeader->getSpigotData(spigot,htr, raw.size());
00362 const unsigned short* HTRraw = htr.getRawData();
00363 unsigned short HTRwdcount = HTRraw[htr.getRawLength() - 2];
00364
00365
00366
00367 HTRwdcount=htr.getRawLength();
00368
00369
00370
00371 int NTP = ((htr.getExtHdr6() >> 8) & 0x00FF);
00372 int NDAQ = (HTRraw[htr.getRawLength() - 4] & 0x7FF);
00373
00374 int here=1+(HcalDCCHeader::SPIGOT_COUNT*(dccid-700))+spigot;
00375
00376 if ( ! ((HTRwdcount != 8) ||
00377 (HTRwdcount != 12 + NTP + NDAQ) ||
00378 (HTRwdcount != 20 + NTP + NDAQ) )) {
00379 chsummAOK=false;
00380
00381 continue; }
00382 bool EE = ((dccHeader->getSpigotErrorBits(spigot) >> 2) & 0x01);
00383 if (EE) {
00384 numEEthisEvent++;
00385 meEEPerSpigot_->Fill(here);
00386 if (HTRwdcount != 8) {
00387 chsummAOK=false;
00388
00389 continue;}}
00390 else{
00391 if ((HTRwdcount-NDAQ-NTP) != 20) {
00392 chsummAOK=false;
00393
00394 continue;}}
00395
00396
00397 if(dccOrN==prevOrN){
00398 consecutiveTriggers[dccid-700][spigot]++;
00399 if(prevWasEE[dccid-700][spigot]) {
00400 if (EE) consecutiveEETriggers[dccid-700][spigot]++;
00401 else {
00402 meNumberEETriggered_->Fill(here,consecutiveEETriggers[dccid-700][spigot]);
00403 consecutiveEETriggers[dccid-700][spigot] = 0;
00404 consecutiveNETriggers[dccid-700][spigot]++;}}
00405 else {
00406 if(!EE) consecutiveNETriggers[dccid-700][spigot]++;
00407 else {
00408 meNumberNETriggered_->Fill(here,consecutiveNETriggers[dccid-700][spigot]);
00409 consecutiveNETriggers[dccid-700][spigot] = 0;
00410 consecutiveEETriggers[dccid-700][spigot]++;}}}
00411 else {
00412 if (prevOrN>-1) {
00413 meNumberTriggered_->Fill(here,consecutiveTriggers[dccid-700][spigot]);
00414 meNumberEETriggered_->Fill(here,consecutiveEETriggers[dccid-700][spigot]);
00415 meNumberNETriggered_->Fill(here,consecutiveNETriggers[dccid-700][spigot]);}
00416 consecutiveTriggers[dccid-700][spigot] = 1;
00417 if(EE) {
00418 consecutiveEETriggers[dccid-700][spigot] = 1;
00419 consecutiveNETriggers[dccid-700][spigot] = 0;}
00420 else {
00421 consecutiveEETriggers[dccid-700][spigot] = 0;
00422 consecutiveNETriggers[dccid-700][spigot] = 1;}}
00423
00424
00425
00426 if (EE) prevWasEE[dccid-700][spigot] = 1;
00427 else prevWasEE[dccid-700][spigot] = 0;
00428
00429 if (htr.isHistogramEvent()) continue;
00430
00431 bool htrUnSuppressed=(HTRraw[6]>>15 & 0x0001);
00432
00433 bool htrEmpty=(HTRraw[2] & 0x4);
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 if (htrUnSuppressed==false && htrEmpty==false){
00445 US0EE0count[dccid-700][spigot]++;
00446 meNormFractSpigs_US0_EE0_->setBinContent(here,
00447 ((double)US0EE0count[dccid-700][spigot])/(double)ievt_);
00448 meRawDataLength2_US0_EE0_->Fill(here-1, HTRwdcount);
00449 }
00450
00451 if (htrUnSuppressed==false && htrEmpty==true){
00452 US0EE1count[dccid-700][spigot]++;
00453 meEEFractSpigs_US0_EE1_->setBinContent(here,
00454 ((double)US0EE1count[dccid-700][spigot])/(double)ievt_);
00455 meRawDataLength2_US0_EE1_->Fill(here-1, HTRwdcount);
00456 }
00457
00458 if (htrUnSuppressed==true && htrEmpty==false){
00459 US1EE0count[dccid-700][spigot]++;
00460 meUSFractSpigs_US1_EE0_->setBinContent(here,
00461 ((double)US1EE0count[dccid-700][spigot])/(double)ievt_);
00462 meRawDataLength2_US1_EE0_->Fill(here-1, HTRwdcount);
00463 }
00464
00465 if (htrUnSuppressed==true && htrEmpty==true){
00466 US1EE1count[dccid-700][spigot]++;
00467 meUSFractSpigs_US1_EE1_->setBinContent(here,
00468 ((double)US1EE1count[dccid-700][spigot])/(double)ievt_);
00469 meRawDataLength2_US1_EE1_->Fill(here-1, HTRwdcount);
00470 }
00471
00472
00473
00474 }
00475
00476
00477
00478
00479
00480
00481
00482
00483 if (!dccHeader->thereIsASecondCDFHeaderWord())
00484 {
00485 cout <<"No second CDF header found!"<<endl;
00486 }
00487
00488 return;
00489 }