Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-13 23:20:40

0001 /** \class SiPixelRawDumper_H
0002  *  Plug-in module that dump raw data file 
0003  *  for pixel subdetector
0004  *  Added class to interpret the data d.k. 30/10/08
0005  *  Add histograms. Add pix 0 detection.
0006  * Works with v7x, comment out the digis access.
0007  */
0008 
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 #include "DataFormats/Common/interface/Handle.h"
0014 
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0017 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0018 
0019 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0020 
0021 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h"
0022 
0023 // For L1  NOT IN RAW
0024 //#include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
0025 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
0026 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
0027 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0028 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
0029 
0030 // For luminisoty NOT IN RAW
0031 //#include "FWCore/Framework/interface/LuminosityBlock.h"
0032 //#include "DataFormats/Luminosity/interface/LumiSummary.h"
0033 //#include "DataFormats/Common/interface/ConditionsInEdm.h"
0034 
0035 // To use root histos
0036 #include "FWCore/ServiceRegistry/interface/Service.h"
0037 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0038 
0039 // For ROOT
0040 #include <TROOT.h>
0041 //#include <TChain.h>
0042 #include <TFile.h>
0043 #include <TF1.h>
0044 #include <TH2F.h>
0045 #include <TH1D.h>
0046 #include <TProfile.h>
0047 #include <TProfile2D.h>
0048 
0049 #include <iostream>
0050 #include <fstream>
0051 
0052 using namespace std;
0053 
0054 // #define L1  // L1 information not in RAW
0055 //#define OUTFILE
0056 
0057 namespace {
0058   bool printErrors = true;
0059   bool printData = false;
0060   bool printHeaders = false;
0061   const bool CHECK_PIXELS = true;
0062   const bool PRINT_BASELINE = false;
0063   // to store the previous pixel
0064   int fed0 = -1, chan0 = -1, roc0 = -1, dcol0 = -1, pix0 = -1, count0 = -1;
0065   int countDecodeErrors1 = 0, countDecodeErrors2 = 0;
0066 }  // namespace
0067 
0068 // Include the helper decoding class
0069 /////////////////////////////////////////////////////////////////////////////
0070 class MyDecode {
0071 public:
0072   MyDecode() {}
0073   ~MyDecode() {}
0074   static int error(int error, int &fedChannel, int fed, int &stat1, int &stat2, bool print = false);
0075   static int data(int error, int &fedChannel, int fed, int &stat1, int &stat2, bool print = false);
0076   static int header(unsigned long long word64, int fed, bool print, unsigned int &bx);
0077   static int trailer(unsigned long long word64, int fed, bool print);
0078   static int convertToCol(int dcol, int pix);
0079   static int convertToRow(int pix);
0080   static int checkLayerLink(int fed, int chan);
0081 
0082 private:
0083 };
0084 /////////////////////////////////////////////////////////////////////////////
0085 //Returns 1,2,3 for layer 1,2,3 full modules, 11,12,13 for 1/2 modules
0086 // 0 for fpix
0087 // needs fedid 0-31, and channel 1-36.
0088 int MyDecode::checkLayerLink(int fed, int chan) {
0089   int layer = 0;
0090   if (fed < 0 || fed > 31)
0091     return layer;  // return 0 for invalid of fpix
0092 
0093   if (chan > 24) {  // layer 3
0094 
0095     if (fed == 0 || fed == 8) {  // Type A
0096 
0097       if (chan == 28 || chan == 34 || chan == 35 || chan == 36)
0098         layer = 13;  // 1/2 module
0099       else
0100         layer = 3;
0101 
0102     } else if (fed == 23 || fed == 31) {  // Type A
0103 
0104       if (chan == 27 || chan == 31 || chan == 32 || chan == 33)
0105         layer = 13;  // 1/2 module
0106       else
0107         layer = 3;
0108 
0109     } else if (fed == 7 || fed == 15 || fed == 16 || fed == 24) {  // Type D
0110 
0111       if (chan == 25 || chan == 26 || chan == 29 || chan == 30)
0112         layer = 13;
0113       else
0114         layer = 3;
0115 
0116     } else {
0117       layer = 3;
0118     }
0119 
0120     return layer;  // layer 3
0121 
0122   } else if ((chan >= 13 && chan <= 19) || chan == 24) {
0123     return 2;  //layer 2
0124 
0125   } else {
0126     if (fed == 0 || fed == 8 || fed == 16 || fed == 24) {  // Type A   WRONG AFTER FIBER SWAP
0127 
0128       if (chan == 5 || chan == 6 || chan == 22 || chan == 23)
0129         layer = 12;  // 1/2 module
0130       else if (chan == 4 || chan == 10 || chan == 11 || chan == 12)
0131         layer = 11;  // 1/2 module
0132       else
0133         layer = 1;
0134 
0135     } else if (fed == 7 || fed == 15 || fed == 23 || fed == 31) {  // Type D
0136 
0137       if (chan == 1 || chan == 2 || chan == 20 || chan == 21)
0138         layer = 12;  // 1/2
0139       else if (chan == 3 || chan == 7 || chan == 8 || chan == 9)
0140         layer = 11;  // 1/2
0141       else
0142         layer = 1;
0143 
0144     } else if (fed == 1 || fed == 2 || fed == 3 || fed == 9 || fed == 10 || fed == 11 || fed == 17 || fed == 18 ||
0145                fed == 19 || fed == 25 || fed == 26 || fed == 27) {  // Type B
0146 
0147       if ((chan >= 4 && chan <= 6) || (chan >= 10 && chan <= 12) || (chan >= 22 && chan <= 23))
0148         layer = 2;
0149       else
0150         layer = 1;
0151 
0152     } else if (fed == 4 || fed == 5 || fed == 6 || fed == 12 || fed == 13 || fed == 14 || fed == 20 || fed == 21 ||
0153                fed == 22 || fed == 28 || fed == 29 || fed == 30) {  // Type C
0154 
0155       if ((chan >= 1 && chan <= 3) || (chan >= 7 && chan <= 9) || (chan >= 20 && chan <= 21))
0156         layer = 2;
0157       else
0158         layer = 1;
0159 
0160     } else {
0161       cout << "unknown fed " << fed << endl;
0162     }  // if fed
0163 
0164     return layer;
0165 
0166   }  // if chan
0167 }
0168 
0169 int MyDecode::convertToCol(int dcol, int pix) {
0170   // First find if we are in the first or 2nd col of a dcol.
0171   int colEvenOdd = pix % 2;  // module(2), 0-1st sol, 1-2nd col.
0172   // Transform
0173   return (dcol * 2 + colEvenOdd);  // col address, starts from 0
0174 }
0175 int MyDecode::convertToRow(int pix) {
0176   return abs(int(pix / 2) - 80);  // row addres, starts from 0
0177 }
0178 
0179 int MyDecode::header(unsigned long long word64, int fed, bool print, unsigned int &bx) {
0180   int fed_id = (word64 >> 8) & 0xfff;
0181   int event_id = (word64 >> 32) & 0xffffff;
0182   bx = (word64 >> 20) & 0xfff;
0183   //   if(bx!=101) {
0184   //     cout<<" Header "<<" for FED "
0185   //    <<fed_id<<" event "<<event_id<<" bx "<<bx<<endl;
0186   //     int dummy=0;
0187   //     cout<<" : ";
0188   //     cin>>dummy;
0189   //   }
0190   if (print)
0191     cout << "Header "
0192          << " for FED " << fed_id << " event " << event_id << " bx " << bx << endl;
0193   fed0 = -1;  // reset the previous hit fed id
0194   return event_id;
0195 }
0196 //
0197 int MyDecode::trailer(unsigned long long word64, int fed, bool print) {
0198   int slinkLength = int((word64 >> 32) & 0xffffff);
0199   int crc = int((word64 & 0xffff0000) >> 16);
0200   int tts = int((word64 & 0xf0) >> 4);
0201   int slinkError = int((word64 & 0xf00) >> 8);
0202   if (print)
0203     cout << "Trailer "
0204          << " len " << slinkLength << " tts " << tts << " error " << slinkError << " crc " << hex << crc << dec << endl;
0205   return slinkLength;
0206 }
0207 //
0208 // Decode error FIFO
0209 // Works for both, the error FIFO and the SLink error words. d.k. 25/04/07
0210 int MyDecode::error(int word, int &fedChannel, int fed, int &stat1, int &stat2, bool print) {
0211   int status = -1;
0212   print = print || printErrors;
0213 
0214   const unsigned int errorMask = 0x3e00000;
0215   const unsigned int dummyMask = 0x03600000;
0216   const unsigned int gapMask = 0x03400000;
0217   const unsigned int timeOut = 0x3a00000;
0218   const unsigned int eventNumError = 0x3e00000;
0219   const unsigned int trailError = 0x3c00000;
0220   const unsigned int fifoError = 0x3800000;
0221 
0222   //  const unsigned int  timeOutChannelMask = 0x1f;  // channel mask for timeouts
0223   //const unsigned int  eventNumMask = 0x1fe000; // event number mask
0224   const unsigned int channelMask = 0xfc000000;  // channel num mask
0225   const unsigned int tbmEventMask = 0xff;       // tbm event num mask
0226   const unsigned int overflowMask = 0x100;      // data overflow
0227   const unsigned int tbmStatusMask = 0xff;      //TBM trailer info
0228   const unsigned int BlkNumMask = 0x700;        //pointer to error fifo #
0229   const unsigned int FsmErrMask = 0x600;        //pointer to FSM errors
0230   const unsigned int RocErrMask = 0x800;        //pointer to #Roc errors
0231   const unsigned int ChnFifMask = 0x1f;         //channel mask for fifo error
0232   const unsigned int Fif2NFMask = 0x40;         //mask for fifo2 NF
0233   const unsigned int TrigNFMask = 0x80;         //mask for trigger fifo NF
0234 
0235   const int offsets[8] = {0, 4, 9, 13, 18, 22, 27, 31};
0236   unsigned int channel = 0;
0237 
0238   //cout<<"error word "<<hex<<word<<dec<<endl;
0239 
0240   if ((word & errorMask) == dummyMask) {  // DUMMY WORD
0241     //cout<<" Dummy word";
0242     return 0;
0243 
0244   } else if ((word & errorMask) == gapMask) {  // GAP WORD
0245     //cout<<" Gap word";
0246     return 0;
0247 
0248   } else if ((word & errorMask) == timeOut) {  // TIMEOUT
0249 
0250     unsigned int bit20 = (word & 0x100000) >> 20;  // works only for slink format
0251 
0252     if (bit20 == 0) {  // 2nd word
0253 
0254       unsigned int timeoutCnt = (word & 0x7f800) >> 11;  // only for slink
0255       // unsigned int timeoutCnt = ((word&0xfc000000)>>24) + ((word&0x1800)>>11); // only for fifo
0256       // More than 1 channel within a group can have a timeout error
0257       // More than 1 channel within a group can have a timeout error
0258 
0259       unsigned int index = (word & 0x1F);  // index within a group of 4/5
0260       unsigned int chip = (word & BlkNumMask) >> 8;
0261       int offset = offsets[chip];
0262       if (print)
0263         cout << "Timeout Error- channel: ";
0264       //cout<<"Timeout Error- channel: ";
0265       for (int i = 0; i < 5; i++) {
0266         if ((index & 0x1) != 0) {
0267           channel = offset + i + 1;
0268           if (print)
0269             cout << channel << " ";
0270           //cout<<channel<<" ";
0271         }
0272         index = index >> 1;
0273       }
0274 
0275       if (print)
0276         cout << " TimeoutCount: " << timeoutCnt;
0277       //cout << " TimeoutCount: " << timeoutCnt<<endl;;
0278 
0279       //if(print) cout<<" for Fed "<<fed<<endl;
0280       status = -10;
0281       fedChannel = channel;
0282       //end of timeout  chip and channel decoding
0283 
0284     } else {  // this is the 1st timout word with the baseline correction
0285 
0286       int baselineCorr = 0;
0287       if (word & 0x200) {
0288         baselineCorr = -(((~word) & 0x1ff) + 1);
0289       } else {
0290         baselineCorr = (word & 0x1ff);
0291       }
0292 
0293       if (PRINT_BASELINE && print)
0294         cout << "Timeout BaselineCorr: " << baselineCorr << endl;
0295       //cout<<"Timeout BaselineCorr: "<<baselineCorr<<endl;
0296       status = 0;
0297     }
0298 
0299   } else if ((word & errorMask) == eventNumError) {  // EVENT NUMBER ERROR
0300     channel = (word & channelMask) >> 26;
0301     unsigned int tbm_event = (word & tbmEventMask);
0302 
0303     if (print)
0304       cout << " Event Number Error- channel: " << channel << " tbm event nr. " << tbm_event << " ";
0305     status = -11;
0306     fedChannel = channel;
0307 
0308   } else if (((word & errorMask) == trailError)) {  // TRAILER
0309     channel = (word & channelMask) >> 26;
0310     unsigned int tbm_status = (word & tbmStatusMask);
0311 
0312     if (tbm_status != 0) {
0313       if (print)
0314         cout << " Trailer Error- "
0315              << "channel: " << channel << " TBM status:0x" << hex << tbm_status << dec << " ";  // <<endl;
0316       status = -15;
0317       // implement the resync/reset 17
0318     }
0319 
0320     if (word & RocErrMask) {
0321       if (print)
0322         cout << "Number of Rocs Error- "
0323              << "channel: " << channel << " ";  // <<endl;
0324       status = -12;
0325     }
0326 
0327     if (word & overflowMask) {
0328       if (print)
0329         cout << "Overflow Error- "
0330              << "channel: " << channel << " ";  // <<endl;
0331       status = -14;
0332     }
0333 
0334     if (word & FsmErrMask) {
0335       if (print)
0336         cout << "Finite State Machine Error- "
0337              << "channel: " << channel << " Error status:0x" << hex << ((word & FsmErrMask) >> 9) << dec
0338              << " ";  // <<endl;
0339       status = -13;
0340     }
0341 
0342     fedChannel = channel;
0343 
0344   } else if ((word & errorMask) == fifoError) {  // FIFO
0345     if (print) {
0346       if (word & Fif2NFMask)
0347         cout << "A fifo 2 is Nearly full- ";
0348       if (word & TrigNFMask)
0349         cout << "The trigger fifo is nearly Full - ";
0350       if (word & ChnFifMask)
0351         cout << "fifo-1 is nearly full for channel" << (word & ChnFifMask);
0352       //cout<<endl;
0353       status = -16;
0354     }
0355 
0356   } else {
0357     cout << " Unknown error?"
0358          << " : ";
0359     cout << " for FED " << fed << " Word " << hex << word << dec << endl;
0360   }
0361 
0362   if (print && status < 0)
0363     cout << " FED " << fed << " status " << status << endl;
0364   return status;
0365 }
0366 ///////////////////////////////////////////////////////////////////////////
0367 int MyDecode::data(int word, int &fedChannel, int fed, int &stat1, int &stat2, bool print) {
0368   //const int ROCMAX = 24;
0369   const unsigned int plsmsk = 0xff;    // pulse height
0370   const unsigned int pxlmsk = 0xff00;  // pixel index
0371   const unsigned int dclmsk = 0x1f0000;
0372   const unsigned int rocmsk = 0x3e00000;
0373   const unsigned int chnlmsk = 0xfc000000;
0374   int status = 0;
0375 
0376   int roc = ((word & rocmsk) >> 21);  // rocs start from 1
0377   // Check for embeded special words
0378   if (roc > 0 && roc < 25) {  // valid ROCs go from 1-24
0379     //if(print) cout<<"data "<<hex<<word<<dec;
0380     int channel = ((word & chnlmsk) >> 26);
0381 
0382     if (channel > 0 && channel < 37) {  // valid channels 1-36
0383       //cout<<hex<<word<<dec;
0384       int dcol = (word & dclmsk) >> 16;
0385       int pix = (word & pxlmsk) >> 8;
0386       int adc = (word & plsmsk);
0387       fedChannel = channel;
0388 
0389       int col = convertToCol(dcol, pix);
0390       int row = convertToRow(pix);
0391 
0392       // print the roc number according to the online 0-15 scheme
0393       if (print)
0394         cout << " Fed " << fed << " Channel- " << channel << " ROC- " << (roc - 1) << " DCOL- " << dcol << " Pixel- "
0395              << pix << " (" << col << "," << row << ") ADC- " << adc << endl;
0396       status++;
0397 
0398       if (CHECK_PIXELS) {
0399         // invalid roc number
0400         if ((fed > 31 && roc > 24) || (fed <= 31 && roc > 16)) {  //inv ROC
0401                                                                   //if(printErrors)
0402           cout << " Fed " << fed << " wrong roc number chan/roc/dcol/pix/adc = " << channel << "/" << roc - 1 << "/"
0403                << dcol << "/" << pix << "/" << adc << endl;
0404           status = -4;
0405 
0406         } else if (fed <= 31 && channel <= 24 && roc > 8) {
0407           // Check invalid ROC numbers
0408 
0409           // protect for rerouted signals
0410           if (!((fed == 13 && channel == 17) || (fed == 15 && channel == 5) || (fed == 31 && channel == 10) ||
0411                 (fed == 27 && channel == 15))) {
0412             //if(printErrors)
0413             cout << " Fed " << fed << " wrong roc number, chan/roc/dcol/pix/adc = " << channel << "/" << roc - 1 << "/"
0414                  << dcol << "/" << pix << "/" << adc << endl;
0415             status = -4;
0416           }
0417         }
0418 
0419         // Check pixels
0420         if (pix == 0) {  // PIX=0
0421                          // Detect pixel 0 events
0422           if (printErrors)
0423             cout << " Fed " << fed << " pix=0 chan/roc/dcol/pix/adc = " << channel << "/" << roc - 1 << "/" << dcol
0424                  << "/" << pix << "/" << adc << " (" << col << "," << row << ")" << endl;
0425           count0++;
0426           stat1 = roc - 1;
0427           stat2 = count0;
0428           status = -5;
0429 
0430         } else if (fed == fed0 && channel == chan0 && roc == roc0 && dcol == dcol0 && pix == pix0) {
0431           // detect multiple pixels
0432 
0433           count0++;
0434           if (printErrors)
0435             cout << " Fed "
0436                  << fed
0437                  //cout<<" Fed "<<fed
0438                  << " double pixel  chan/roc/dcol/pix/adc = " << channel << "/" << roc - 1 << "/" << dcol << "/" << pix
0439                  << "/" << adc << " (" << col << "," << row << ") " << count0 << endl;
0440           stat1 = roc - 1;
0441           stat2 = count0;
0442           status = -6;
0443 
0444         } else {  // normal
0445 
0446           count0 = 0;
0447 
0448           fed0 = fed;
0449           chan0 = channel;
0450           roc0 = roc;
0451           dcol0 = dcol;
0452           pix0 = pix;
0453 
0454           // Decode errors
0455           if (pix < 2 || pix > 161) {  // inv PIX
0456             if (printErrors)
0457               cout << " Fed " << fed << " wrong pix number chan/roc/dcol/pix/adc = " << channel << "/" << roc - 1 << "/"
0458                    << dcol << "/" << pix << "/" << adc << " (" << col << "," << row << ")" << endl;
0459             status = -3;
0460           }
0461 
0462           if (dcol < 0 || dcol > 25) {  // inv DCOL
0463             if (printErrors)
0464               cout << " Fed " << fed << " wrong dcol number chan/roc/dcol/pix/adc = " << channel << "/" << roc - 1
0465                    << "/" << dcol << "/" << pix << "/" << adc << " (" << col << "," << row << ")" << endl;
0466             status = -3;
0467           }
0468 
0469         }  // check pixels
0470 
0471         // Summary error count (for testing only)
0472         if (pix < 2 || pix > 161 || dcol < 0 || dcol > 25) {
0473           countDecodeErrors2++;  // count pixels with errors
0474           if (pix < 2 || pix > 161)
0475             countDecodeErrors1++;  // count errors
0476           if (dcol < 0 || dcol > 25)
0477             countDecodeErrors1++;  // count errors
0478           //if(fed==6 && channel==35 ) cout<<" Fed "<<fed<<" wrong dcol number chan/roc/dcol/pix/adc = "<<channel<<"/"
0479           //             <<roc-1<<"/"<<dcol<<"/"<<pix<<"/"<<adc<<" ("<<col<<","<<row<<")"<<endl;
0480         }
0481 
0482       }  // if CHECK_PIXELS
0483 
0484     } else {  // channel
0485 
0486       cout << " Wrong channel " << channel << " : ";
0487       cout << " for FED " << fed << " Word " << hex << word << dec << endl;
0488       return -2;
0489     }
0490 
0491   } else if (roc == 25) {  // ROC?
0492     unsigned int channel = ((word & chnlmsk) >> 26);
0493     cout << "Wrong roc 25 "
0494          << " in fed/chan " << fed << "/" << channel << endl;
0495     status = -4;
0496 
0497   } else {  // error word
0498 
0499     //cout<<"error word "<<hex<<word<<dec;
0500     status = error(word, fedChannel, fed, stat1, stat2, print);
0501   }
0502 
0503   return status;
0504 }
0505 ////////////////////////////////////////////////////////////////////////////
0506 
0507 class SiPixelRawDumper : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0508 public:
0509   /// ctor
0510   explicit SiPixelRawDumper(const edm::ParameterSet &cfg);
0511 
0512   //explicit SiPixelRawDumper( const edm::ParameterSet& cfg) : theConfig(cfg) {
0513   //consumes<FEDRawDataCollection>(theConfig.getUntrackedParameter<std::string>("InputLabel","source"));}
0514 
0515   /// dtor
0516   virtual ~SiPixelRawDumper() = default;
0517 
0518   void beginJob();
0519 
0520   // end of job
0521   void endJob();
0522 
0523   /// get data, convert to digis attach againe to Event
0524   virtual void analyze(const edm::Event &, const edm::EventSetup &);
0525 
0526 private:
0527   edm::ParameterSet theConfig;
0528   edm::EDGetTokenT<FEDRawDataCollection> rawData;
0529 
0530   int printLocal;
0531   double printThreshold;
0532   int countEvents, countAllEvents;
0533   int countTotErrors;
0534   float sumPixels, sumFedSize, sumFedPixels[40];
0535   int fedErrors[40][36];
0536   int fedErrorsENE[40][36];
0537   int fedErrorsTime[40][36];
0538   int fedErrorsOver[40][36];
0539   int decodeErrors[40][36];
0540   int decodeErrors000[40][36];     // pix 0 problem
0541   int decodeErrorsDouble[40][36];  // double pix  problem
0542   int errorType[20];
0543 
0544 #ifdef OUTFILE
0545   ofstream outfile;
0546 #endif
0547 
0548   TH1D *hsize, *hsize0, *hsize1, *hsize2, *hsize3;
0549 #ifdef IND_FEDS
0550   TH1D *hsizeFeds[40];
0551 #endif
0552   TH1D *hpixels, *hpixels0, *hpixels1, *hpixels2, *hpixels3, *hpixels4;
0553   TH1D *htotPixels, *htotPixels0, *htotPixels1;
0554   TH1D *herrors, *htotErrors;
0555   TH1D *herrorType1, *herrorType1Fed, *herrorType1Chan, *herrorType2, *herrorType2Fed, *herrorType2Chan;
0556   TH1D *hcountDouble, *hcount000, *hrocDouble, *hroc000;
0557 
0558   TH2F *hfed2DErrorsType1, *hfed2DErrorsType2;
0559   TH2F *hfed2DErrors1, *hfed2DErrors2, *hfed2DErrors3, *hfed2DErrors4, *hfed2DErrors5, *hfed2DErrors6, *hfed2DErrors7,
0560       *hfed2DErrors8, *hfed2DErrors9, *hfed2DErrors10, *hfed2DErrors11, *hfed2DErrors12, *hfed2DErrors13,
0561       *hfed2DErrors14, *hfed2DErrors15, *hfed2DErrors16;
0562   TH2F *hfed2d, *hsize2d, *hfedErrorType1ls, *hfedErrorType2ls, *hcountDouble2, *hcount0002;
0563   TH2F *hfed2DErrors1ls, *hfed2DErrors2ls, *hfed2DErrors3ls, *hfed2DErrors4ls, *hfed2DErrors5ls, *hfed2DErrors6ls,
0564       *hfed2DErrors7ls, *hfed2DErrors8ls, *hfed2DErrors9ls, *hfed2DErrors10ls, *hfed2DErrors11ls, *hfed2DErrors12ls,
0565       *hfed2DErrors13ls, *hfed2DErrors14ls, *hfed2DErrors15ls, *hfed2DErrors16ls;
0566 
0567   TH1D *hevent, *hlumi, *horbit, *hbx, *hlumi0, *hbx0;
0568   //TH1D *hbx1,*hbx2,*hbx3,*hbx4,*hbx5,*hbx6,*hbx7,*hbx8,*hbx9,*hbx10,*hbx11,*hbx12;
0569   TProfile *htotPixelsls, *hsizels, *herrorType1ls, *herrorType2ls, *havsizels, *htotPixelsbx, *herrorType1bx,
0570       *herrorType2bx, *havsizebx, *hsizep;
0571   TProfile *herror1ls, *herror2ls, *herror3ls, *herror4ls, *herror5ls, *herror6ls, *herror7ls, *herror8ls, *herror9ls,
0572       *herror10ls, *herror11ls, *herror12ls, *herror13ls, *herror14ls, *herror15ls, *herror16ls;
0573   TProfile2D *hfedchannelsize;
0574   TH1D *herrorTimels, *herrorOverls, *herrorTimels1, *herrorOverls1, *herrorTimels2, *herrorOverls2, *herrorTimels3,
0575       *herrorOverls3, *herrorTimels0, *herrorOverls0;
0576   TH1D *hfedchannelsizeb, *hfedchannelsizeb1, *hfedchannelsizeb2, *hfedchannelsizeb3, *hfedchannelsizef;
0577 };
0578 //----------------------------------------------------------------------------------
0579 SiPixelRawDumper::SiPixelRawDumper(const edm::ParameterSet &cfg) : theConfig(cfg) {
0580   string label = theConfig.getUntrackedParameter<std::string>("InputLabel", "source");
0581   // For the ByToken method
0582   rawData = consumes<FEDRawDataCollection>(label);
0583   usesResource(TFileService::kSharedResource);
0584 }
0585 //----------------------------------------------------------------------------------------
0586 void SiPixelRawDumper::endJob() {
0587   string errorName[18] = {" ",
0588                           " ",
0589                           "wrong channel",
0590                           "wrong pix or dcol",
0591                           "wrong roc",
0592                           "pix=0",
0593                           " double-pix",
0594                           " ",
0595                           " ",
0596                           " ",
0597                           "timeout",
0598                           "ENE",
0599                           "NOR",
0600                           "FSM",
0601                           "overflow",
0602                           "trailer",
0603                           "fifo",
0604                           "reset/resync"};
0605 
0606   // 2 - wrong channel
0607   // 3 - wrong pix or dcol
0608   // 4 - wrong roc
0609   // 5 - pix=0
0610   // 6 - double pixel
0611   // 10 - timeout ()
0612   // 11 - ene ()
0613   // 12 - mum pf rocs error ()
0614   // 13 - fsm ()
0615   // 14 - overflow ()
0616   // 15 - trailer ()
0617   // 16 - fifo  (30)
0618   // 17 - reset/resync NOT INCLUDED YET
0619 
0620   if (countEvents > 0) {
0621     sumPixels /= float(countEvents);
0622     sumFedSize /= float(countAllEvents);
0623     for (int i = 0; i < 40; ++i) {
0624       sumFedPixels[i] /= float(countEvents);
0625       hpixels4->Fill(float(i), sumFedPixels[i]);  //pixels only
0626     }
0627   }
0628 
0629   cout << " Total/non-empty events " << countAllEvents << " / " << countEvents << " average number of pixels "
0630        << sumPixels << endl;
0631 
0632   cout << " Average Fed size per event for all events (in 4-words) " << (sumFedSize * 2. / 40.)
0633        << " total for all feds " << (sumFedSize * 2.) << endl;
0634 
0635   cout << " Size for ech FED per event in units of hit pixels:" << endl;
0636 
0637   for (int i = 0; i < 40; ++i)
0638     cout << sumFedPixels[i] << " ";
0639   cout << endl;
0640 
0641   cout << " Total number of errors " << countTotErrors << " print threshold " << int(countEvents * printThreshold)
0642        << " total errors per fed channel" << endl;
0643   cout << " FED errors " << endl << "Fed Channel Tot-Errors ENE-Errors Time-Errors Over-Errors" << endl;
0644 
0645   for (int i = 0; i < 40; ++i) {
0646     for (int j = 0; j < 36; ++j)
0647       if ((fedErrors[i][j]) > int(countEvents * printThreshold) || (fedErrorsENE[i][j] > 0)) {
0648         cout << " " << i << "  -  " << (j + 1) << " -  " << fedErrors[i][j] << " - " << fedErrorsENE[i][j] << " -  "
0649              << fedErrorsTime[i][j] << " - " << fedErrorsOver[i][j] << endl;
0650       }
0651   }
0652   cout << " Decode errors " << endl << "Fed Channel Errors Pix_000 Double_Pix" << endl;
0653   for (int i = 0; i < 40; ++i) {
0654     for (int j = 0; j < 36; ++j) {
0655       int tmp = decodeErrors[i][j] + decodeErrors000[i][j] + decodeErrorsDouble[i][j];
0656       if (tmp > 10)
0657         cout << " " << i << " -  " << (j + 1) << "   -  " << decodeErrors[i][j] << "  -    " << decodeErrors000[i][j]
0658              << "  -   " << decodeErrorsDouble[i][j] << endl;
0659     }
0660   }
0661 
0662   cout << " Total errors for all feds " << endl << " Type Name Num-Of-Errors" << endl;
0663   for (int i = 0; i < 20; ++i) {
0664     if (errorType[i] > 0)
0665       cout << "   " << i << " - " << errorName[i] << " - " << errorType[i] << endl;
0666   }
0667 
0668   cout << " Test decode errors " << countDecodeErrors1 << " " << countDecodeErrors2 << endl;
0669 
0670 #ifdef OUTFILE
0671   outfile.close();
0672 #endif
0673 }
0674 //----------------------------------------------------------------------
0675 void SiPixelRawDumper::beginJob() {
0676   printLocal = theConfig.getUntrackedParameter<int>("Verbosity", 1);
0677   // threshold per event for printing errors
0678   printThreshold = theConfig.getUntrackedParameter<double>("PrintThreshold", 0.001);
0679   cout << " beginjob " << printLocal << " " << printThreshold << endl;
0680 
0681   if (printLocal > 0)
0682     printErrors = true;
0683   else
0684     printErrors = false;
0685   if (printLocal > 1)
0686     printData = true;
0687   else
0688     printData = false;
0689   if (printLocal > 2)
0690     printHeaders = true;
0691   else
0692     printHeaders = false;
0693 
0694   countEvents = 0;
0695   countAllEvents = 0;
0696   countTotErrors = 0;
0697   sumPixels = 0.;
0698   sumFedSize = 0;
0699   for (int i = 0; i < 40; ++i) {
0700     sumFedPixels[i] = 0;
0701     for (int j = 0; j < 36; ++j) {
0702       fedErrors[i][j] = 0;
0703       fedErrorsENE[i][j] = 0;
0704       fedErrorsTime[i][j] = 0;
0705       fedErrorsOver[i][j] = 0;
0706     }
0707     for (int j = 0; j < 36; ++j) {
0708       decodeErrors[i][j] = 0;
0709       decodeErrors000[i][j] = 0;
0710       decodeErrorsDouble[i][j] = 0;
0711     }
0712   }
0713   for (int i = 0; i < 20; ++i)
0714     errorType[i] = 0;
0715 
0716   edm::Service<TFileService> fs;
0717 
0718   //const float pixMax = 5999.5;   // pp value
0719   //const float totMax = 99999.5;  // pp value
0720   //const float maxLink = 200.;    // pp value
0721 
0722   const float pixMax = 19999.5;   // hi value
0723   const float totMax = 399999.5;  // hi value
0724   const float maxLink = 1000.;    // hi value
0725 
0726   hsize = fs->make<TH1D>("hsize", "FED event size in words-4", 6000, -0.5, pixMax);
0727   hsize0 = fs->make<TH1D>("hsize0", "FED event size in words-4", 2000, -0.5, 19999.5);
0728   hsize1 = fs->make<TH1D>("hsize1", "bpix FED event size in words-4", 6000, -0.5, pixMax);
0729   hsize2 = fs->make<TH1D>("hsize2", "fpix FED event size in words-4", 6000, -0.5, pixMax);
0730   hsize3 = fs->make<TH1D>("hsize3", "ave bpix FED event size in words-4", 6000, -0.5, pixMax);
0731 
0732   hpixels = fs->make<TH1D>("hpixels", "pixels per FED", 2000, -0.5, 19999.5);
0733   hpixels0 = fs->make<TH1D>("hpixels0", "pixels per FED", 6000, -0.5, pixMax);
0734   hpixels1 = fs->make<TH1D>("hpixels1", "pixels >0 per FED", 6000, -0.5, pixMax);
0735   hpixels2 = fs->make<TH1D>("hpixels2", "pixels >0 per BPix FED", 6000, -0.5, pixMax);
0736   hpixels3 = fs->make<TH1D>("hpixels3", "pixels >0 per Fpix FED", 6000, -0.5, pixMax);
0737   hpixels4 = fs->make<TH1D>("hpixels4", "pixels per each FED", 40, -0.5, 39.5);
0738 
0739   htotPixels = fs->make<TH1D>("htotPixels", "pixels per event", 10000, -0.5, totMax);
0740   htotPixels0 = fs->make<TH1D>("htotPixels0", "pixels per event, zoom low region", 20000, -0.5, 19999.5);
0741   htotPixels1 = fs->make<TH1D>("htotPixels1", "pixels >0 per event", 10000, -0.5, totMax);
0742 
0743   herrors = fs->make<TH1D>("herrors", "errors per FED", 100, -0.5, 99.5);
0744   htotErrors = fs->make<TH1D>("htotErrors", "errors per event", 1000, -0.5, 999.5);
0745 
0746   herrorType1 = fs->make<TH1D>("herrorType1", "errors 1 per type", 20, -0.5, 19.5);
0747   herrorType1Fed = fs->make<TH1D>("herrorType1Fed", "errors 1 per FED", 40, -0.5, 39.5);
0748   herrorType1Chan = fs->make<TH1D>("herrorType1Chan", "errors 1 per chan", 37, -0.5, 36.5);
0749   herrorType2 = fs->make<TH1D>("herrorType2", "readout errors 2 per type", 20, -0.5, 19.5);
0750   herrorType2Fed = fs->make<TH1D>("herrorType2Fed", "readout errors 2 per FED", 40, -0.5, 39.5);
0751   herrorType2Chan = fs->make<TH1D>("herrorType2Chan", "readout errors 2 per chan", 37, -0.5, 36.5);
0752 
0753   hcountDouble = fs->make<TH1D>("hcountDouble", "count double pixels", 100, -0.5, 99.5);
0754   hcountDouble2 = fs->make<TH2F>("hcountDouble2", "count double pixels", 40, -0.5, 39.5, 10, 0., 10.);
0755   hcount000 = fs->make<TH1D>("hcount000", "count 000 pixels", 100, -0.5, 99.5);
0756   hcount0002 = fs->make<TH2F>("hcount0002", "count 000 pixels", 40, -0.5, 39.5, 10, 0., 10.);
0757   hrocDouble = fs->make<TH1D>("hrocDouble", "double pixels rocs", 25, -0.5, 24.5);
0758   hroc000 = fs->make<TH1D>("hroc000", "000 pixels rocs", 25, -0.5, 24.5);
0759 
0760   hfed2d = fs->make<TH2F>("hfed2d", "errors", 40, -0.5, 39.5, 21, -0.5, 20.5);  // ALL
0761 
0762   hsize2d = fs->make<TH2F>("hsize2d", "size vs fed", 40, -0.5, 39.5, 50, 0, 500);   // ALL
0763   hsizep = fs->make<TProfile>("hsizep", "size vs fed", 40, -0.5, 39.5, 0, 100000);  // ALL
0764   //hsize2dls = fs->make<TH2F>( "hsize2dls", "size vs lumi",100,0,1000, 50,0.,500.); // ALL
0765 
0766 #ifdef IND_FEDS
0767   hsizeFeds[0] = fs->make<TH1D>("hsizeFed0", "FED 0 event size ", 1000, -0.5, pixMax);
0768   hsizeFeds[1] = fs->make<TH1D>("hsizeFed1", "FED 1 event size ", 1000, -0.5, pixMax);
0769   hsizeFeds[2] = fs->make<TH1D>("hsizeFed2", "FED 2 event size ", 1000, -0.5, pixMax);
0770   hsizeFeds[3] = fs->make<TH1D>("hsizeFed3", "FED 3 event size ", 1000, -0.5, pixMax);
0771   hsizeFeds[4] = fs->make<TH1D>("hsizeFed4", "FED 4 event size ", 1000, -0.5, pixMax);
0772   hsizeFeds[5] = fs->make<TH1D>("hsizeFed5", "FED 5 event size ", 1000, -0.5, pixMax);
0773   hsizeFeds[6] = fs->make<TH1D>("hsizeFed6", "FED 6 event size ", 1000, -0.5, pixMax);
0774   hsizeFeds[7] = fs->make<TH1D>("hsizeFed7", "FED 7 event size ", 1000, -0.5, pixMax);
0775   hsizeFeds[8] = fs->make<TH1D>("hsizeFed8", "FED 8 event size ", 1000, -0.5, pixMax);
0776   hsizeFeds[9] = fs->make<TH1D>("hsizeFed9", "FED 9 event size ", 1000, -0.5, pixMax);
0777   hsizeFeds[10] = fs->make<TH1D>("hsizeFed10", "FED 10 event size ", 1000, -0.5, pixMax);
0778   hsizeFeds[11] = fs->make<TH1D>("hsizeFed11", "FED 11 event size ", 1000, -0.5, pixMax);
0779   hsizeFeds[12] = fs->make<TH1D>("hsizeFed12", "FED 12 event size ", 1000, -0.5, pixMax);
0780   hsizeFeds[13] = fs->make<TH1D>("hsizeFed13", "FED 13 event size ", 1000, -0.5, pixMax);
0781   hsizeFeds[14] = fs->make<TH1D>("hsizeFed14", "FED 14 event size ", 1000, -0.5, pixMax);
0782   hsizeFeds[15] = fs->make<TH1D>("hsizeFed15", "FED 15 event size ", 1000, -0.5, pixMax);
0783   hsizeFeds[16] = fs->make<TH1D>("hsizeFed16", "FED 16 event size ", 1000, -0.5, pixMax);
0784   hsizeFeds[17] = fs->make<TH1D>("hsizeFed17", "FED 17 event size ", 1000, -0.5, pixMax);
0785   hsizeFeds[18] = fs->make<TH1D>("hsizeFed18", "FED 18 event size ", 1000, -0.5, pixMax);
0786   hsizeFeds[19] = fs->make<TH1D>("hsizeFed19", "FED 19 event size ", 1000, -0.5, pixMax);
0787   hsizeFeds[20] = fs->make<TH1D>("hsizeFed20", "FED 20 event size ", 1000, -0.5, pixMax);
0788   hsizeFeds[21] = fs->make<TH1D>("hsizeFed21", "FED 21 event size ", 1000, -0.5, pixMax);
0789   hsizeFeds[22] = fs->make<TH1D>("hsizeFed22", "FED 22 event size ", 1000, -0.5, pixMax);
0790   hsizeFeds[23] = fs->make<TH1D>("hsizeFed23", "FED 23 event size ", 1000, -0.5, pixMax);
0791   hsizeFeds[24] = fs->make<TH1D>("hsizeFed24", "FED 24 event size ", 1000, -0.5, pixMax);
0792   hsizeFeds[25] = fs->make<TH1D>("hsizeFed25", "FED 25 event size ", 1000, -0.5, pixMax);
0793   hsizeFeds[26] = fs->make<TH1D>("hsizeFed26", "FED 26 event size ", 1000, -0.5, pixMax);
0794   hsizeFeds[27] = fs->make<TH1D>("hsizeFed27", "FED 27 event size ", 1000, -0.5, pixMax);
0795   hsizeFeds[28] = fs->make<TH1D>("hsizeFed28", "FED 28 event size ", 1000, -0.5, pixMax);
0796   hsizeFeds[29] = fs->make<TH1D>("hsizeFed29", "FED 29 event size ", 1000, -0.5, pixMax);
0797   hsizeFeds[30] = fs->make<TH1D>("hsizeFed30", "FED 30 event size ", 1000, -0.5, pixMax);
0798   hsizeFeds[31] = fs->make<TH1D>("hsizeFed31", "FED 31 event size ", 1000, -0.5, pixMax);
0799   hsizeFeds[32] = fs->make<TH1D>("hsizeFed32", "FED 32 event size ", 1000, -0.5, pixMax);
0800   hsizeFeds[33] = fs->make<TH1D>("hsizeFed33", "FED 33 event size ", 1000, -0.5, pixMax);
0801   hsizeFeds[34] = fs->make<TH1D>("hsizeFed34", "FED 34 event size ", 1000, -0.5, pixMax);
0802   hsizeFeds[35] = fs->make<TH1D>("hsizeFed35", "FED 35 event size ", 1000, -0.5, pixMax);
0803   hsizeFeds[36] = fs->make<TH1D>("hsizeFed36", "FED 36 event size ", 1000, -0.5, pixMax);
0804   hsizeFeds[37] = fs->make<TH1D>("hsizeFed37", "FED 37 event size ", 1000, -0.5, pixMax);
0805   hsizeFeds[38] = fs->make<TH1D>("hsizeFed38", "FED 38 event size ", 1000, -0.5, pixMax);
0806   hsizeFeds[39] = fs->make<TH1D>("hsizeFed39", "FED 39 event size ", 1000, -0.5, pixMax);
0807 #endif
0808 
0809   hevent = fs->make<TH1D>("hevent", "event", 1000, 0, 10000000.);
0810   //horbit = fs->make<TH1D>("horbit","orbit",100, 0,100000000.);
0811   hlumi = fs->make<TH1D>("hlumi", "lumi", 3000, 0, 3000.);
0812   hlumi0 = fs->make<TH1D>("hlumi0", "lumi", 3000, 0, 3000.);
0813 
0814   hbx = fs->make<TH1D>("hbx", "bx", 4000, 0, 4000.);
0815   hbx0 = fs->make<TH1D>("hbx0", "bx", 4000, 0, 4000.);
0816 
0817   //   hbx1    = fs->make<TH1D>("hbx1",   "bx",   4000,0,4000.);
0818   //   hbx2    = fs->make<TH1D>("hbx2",   "bx",   4000,0,4000.);
0819   //   hbx3    = fs->make<TH1D>("hbx3",   "bx",   4000,0,4000.);
0820   //   hbx4    = fs->make<TH1D>("hbx4",   "bx",   4000,0,4000.);
0821   //   hbx5    = fs->make<TH1D>("hbx5",   "bx",   4000,0,4000.);
0822   //   hbx6    = fs->make<TH1D>("hbx6",   "bx",   4000,0,4000.);
0823   //   hbx7    = fs->make<TH1D>("hbx7",   "bx",   4000,0,4000.);
0824   //   hbx8    = fs->make<TH1D>("hbx8",   "bx",   4000,0,4000.);
0825   //   hbx9    = fs->make<TH1D>("hbx9",   "bx",   4000,0,4000.);
0826   //   hbx10    = fs->make<TH1D>("hbx10",   "bx",   4000,0,4000.);
0827   //   hbx11    = fs->make<TH1D>("hbx11",   "bx",   4000,0,4000.);
0828   //   hbx12    = fs->make<TH1D>("hbx12",   "bx",   4000,0,4000.);
0829 
0830   herrorTimels = fs->make<TH1D>("herrorTimels", "timeouts vs ls", 1000, 0, 3000);
0831   herrorOverls = fs->make<TH1D>("herrorOverls", "overflows vs ls", 1000, 0, 3000);
0832   herrorTimels1 = fs->make<TH1D>("herrorTimels1", "timeouts vs ls", 1000, 0, 3000);
0833   herrorOverls1 = fs->make<TH1D>("herrorOverls1", "overflows vs ls", 1000, 0, 3000);
0834   herrorTimels2 = fs->make<TH1D>("herrorTimels2", "timeouts vs ls", 1000, 0, 3000);
0835   herrorOverls2 = fs->make<TH1D>("herrorOverls2", "overflows vs ls", 1000, 0, 3000);
0836   herrorTimels3 = fs->make<TH1D>("herrorTimels3", "timeouts vs ls", 1000, 0, 3000);
0837   herrorOverls3 = fs->make<TH1D>("herrorOverls3", "overflows vs ls", 1000, 0, 3000);
0838   herrorTimels0 = fs->make<TH1D>("herrorTimels0", "timeouts vs ls", 1000, 0, 3000);
0839   herrorOverls0 = fs->make<TH1D>("herrorOverls0", "overflows vs ls", 1000, 0, 3000);
0840 
0841   hfed2DErrorsType1 = fs->make<TH2F>("hfed2DErrorsType1", "errors type 1 per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0842   hfed2DErrorsType2 = fs->make<TH2F>("hfed2DErrorsType2", "errors type 2 per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0843 
0844   hfed2DErrors1 = fs->make<TH2F>("hfed2DErrors1", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0845   //hfed2DErrors2 = fs->make<TH2F>("hfed2DErrors2", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0846   hfed2DErrors3 = fs->make<TH2F>("hfed2DErrors3", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0847   hfed2DErrors4 = fs->make<TH2F>("hfed2DErrors4", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0848   hfed2DErrors5 = fs->make<TH2F>("hfed2DErrors5", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0849   hfed2DErrors6 = fs->make<TH2F>("hfed2DErrors6", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0850   //hfed2DErrors7 = fs->make<TH2F>("hfed2DErrors7", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0851   //hfed2DErrors8 = fs->make<TH2F>("hfed2DErrors8", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0852   //hfed2DErrors9 = fs->make<TH2F>("hfed2DErrors9", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0853   hfed2DErrors10 = fs->make<TH2F>("hfed2DErrors10", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0854   hfed2DErrors11 = fs->make<TH2F>("hfed2DErrors11", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0855   hfed2DErrors12 = fs->make<TH2F>("hfed2DErrors12", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0856   hfed2DErrors13 = fs->make<TH2F>("hfed2DErrors13", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0857   hfed2DErrors14 = fs->make<TH2F>("hfed2DErrors14", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0858   hfed2DErrors15 = fs->make<TH2F>("hfed2DErrors15", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0859   hfed2DErrors16 = fs->make<TH2F>("hfed2DErrors16", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0860 
0861   hfedErrorType1ls = fs->make<TH2F>("hfedErrorType1ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0862   hfedErrorType2ls = fs->make<TH2F>("hfedErrorType2ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0863 
0864   hfed2DErrors1ls = fs->make<TH2F>("hfed2DErrors1ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0865   //hfed2DErrors2ls  = fs->make<TH2F>("hfed2DErrors2ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0866   hfed2DErrors3ls = fs->make<TH2F>("hfed2DErrors3ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0867   hfed2DErrors4ls = fs->make<TH2F>("hfed2DErrors4ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0868   hfed2DErrors5ls = fs->make<TH2F>("hfed2DErrors5ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0869   hfed2DErrors6ls = fs->make<TH2F>("hfed2DErrors6ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0870   //hfed2DErrors7ls  = fs->make<TH2F>("hfed2DErrors7ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0871   //hfed2DErrors8ls  = fs->make<TH2F>("hfed2DErrors8ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0872   //hfed2DErrors9ls  = fs->make<TH2F>("hfed2DErrors9ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0873   hfed2DErrors10ls = fs->make<TH2F>("hfed2DErrors10ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0874   hfed2DErrors11ls = fs->make<TH2F>("hfed2DErrors11ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0875   hfed2DErrors12ls = fs->make<TH2F>("hfed2DErrors12ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0876   hfed2DErrors13ls = fs->make<TH2F>("hfed2DErrors13ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0877   hfed2DErrors14ls = fs->make<TH2F>("hfed2DErrors14ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0878   hfed2DErrors15ls = fs->make<TH2F>("hfed2DErrors15ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0879   hfed2DErrors16ls = fs->make<TH2F>("hfed2DErrors16ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0880 
0881   herrorTimels = fs->make<TH1D>("herrorTimels", "timeouts vs ls", 1000, 0, 3000);
0882   herrorOverls = fs->make<TH1D>("herrorOverls", "overflows vs ls", 1000, 0, 3000);
0883   herrorTimels1 = fs->make<TH1D>("herrorTimels1", "timeouts vs ls", 1000, 0, 3000);
0884   herrorOverls1 = fs->make<TH1D>("herrorOverls1", "overflows vs ls", 1000, 0, 3000);
0885   herrorTimels2 = fs->make<TH1D>("herrorTimels2", "timeouts vs ls", 1000, 0, 3000);
0886   herrorOverls2 = fs->make<TH1D>("herrorOverls2", "overflows vs ls", 1000, 0, 3000);
0887   herrorTimels3 = fs->make<TH1D>("herrorTimels3", "timeouts vs ls", 1000, 0, 3000);
0888   herrorOverls3 = fs->make<TH1D>("herrorOverls3", "overflows vs ls", 1000, 0, 3000);
0889   herrorTimels0 = fs->make<TH1D>("herrorTimels0", "timeouts vs ls", 1000, 0, 3000);
0890   herrorOverls0 = fs->make<TH1D>("herrorOverls0", "overflows vs ls", 1000, 0, 3000);
0891 
0892   hfed2DErrorsType1 = fs->make<TH2F>("hfed2DErrorsType1", "errors type 1 per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0893   hfed2DErrorsType2 = fs->make<TH2F>("hfed2DErrorsType2", "errors type 2 per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0894 
0895   hfed2DErrors1 = fs->make<TH2F>("hfed2DErrors1", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0896   //hfed2DErrors2 = fs->make<TH2F>("hfed2DErrors2", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0897   hfed2DErrors3 = fs->make<TH2F>("hfed2DErrors3", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0898   hfed2DErrors4 = fs->make<TH2F>("hfed2DErrors4", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0899   hfed2DErrors5 = fs->make<TH2F>("hfed2DErrors5", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0900   hfed2DErrors6 = fs->make<TH2F>("hfed2DErrors6", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0901   //hfed2DErrors7 = fs->make<TH2F>("hfed2DErrors7", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0902   //hfed2DErrors8 = fs->make<TH2F>("hfed2DErrors8", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0903   //hfed2DErrors9 = fs->make<TH2F>("hfed2DErrors9", "errors per FED", 40,-0.5,39.5,37, -0.5, 36.5);
0904   hfed2DErrors10 = fs->make<TH2F>("hfed2DErrors10", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0905   hfed2DErrors11 = fs->make<TH2F>("hfed2DErrors11", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0906   hfed2DErrors12 = fs->make<TH2F>("hfed2DErrors12", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0907   hfed2DErrors13 = fs->make<TH2F>("hfed2DErrors13", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0908   hfed2DErrors14 = fs->make<TH2F>("hfed2DErrors14", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0909   hfed2DErrors15 = fs->make<TH2F>("hfed2DErrors15", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0910   hfed2DErrors16 = fs->make<TH2F>("hfed2DErrors16", "errors per FED", 40, -0.5, 39.5, 37, -0.5, 36.5);
0911 
0912   hfedErrorType1ls = fs->make<TH2F>("hfedErrorType1ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0913   hfedErrorType2ls = fs->make<TH2F>("hfedErrorType2ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0914 
0915   hfed2DErrors1ls = fs->make<TH2F>("hfed2DErrors1ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0916   //hfed2DErrors2ls  = fs->make<TH2F>("hfed2DErrors2ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0917   hfed2DErrors3ls = fs->make<TH2F>("hfed2DErrors3ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0918   hfed2DErrors4ls = fs->make<TH2F>("hfed2DErrors4ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0919   hfed2DErrors5ls = fs->make<TH2F>("hfed2DErrors5ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0920   hfed2DErrors6ls = fs->make<TH2F>("hfed2DErrors6ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0921   //hfed2DErrors7ls  = fs->make<TH2F>("hfed2DErrors7ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0922   //hfed2DErrors8ls  = fs->make<TH2F>("hfed2DErrors8ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0923   //hfed2DErrors9ls  = fs->make<TH2F>("hfed2DErrors9ls", "errors vs lumi",300,0,3000, 40,-0.5,39.5); //
0924   hfed2DErrors10ls = fs->make<TH2F>("hfed2DErrors10ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0925   hfed2DErrors11ls = fs->make<TH2F>("hfed2DErrors11ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0926   hfed2DErrors12ls = fs->make<TH2F>("hfed2DErrors12ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0927   hfed2DErrors13ls = fs->make<TH2F>("hfed2DErrors13ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0928   hfed2DErrors14ls = fs->make<TH2F>("hfed2DErrors14ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0929   hfed2DErrors15ls = fs->make<TH2F>("hfed2DErrors15ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0930   hfed2DErrors16ls = fs->make<TH2F>("hfed2DErrors16ls", "errors vs lumi", 300, 0, 3000, 40, -0.5, 39.5);  //
0931 
0932   hsizels = fs->make<TProfile>("hsizels", " bpix fed size vs ls", 300, 0, 3000, 0, 200000.);
0933   htotPixelsls = fs->make<TProfile>("htotPixelsls", " tot pixels vs ls", 300, 0, 3000, 0, 300000.);
0934   havsizels = fs->make<TProfile>("havsizels", "av. bpix fed size vs ls", 300, 0, 3000, 0, 300000.);
0935 
0936   herrorType1ls = fs->make<TProfile>("herrorType1ls", "error type 1 vs ls", 300, 0, 3000, 0, 1000.);
0937   herrorType2ls = fs->make<TProfile>("herrorType2ls", "error type 2 vs ls", 300, 0, 3000, 0, 1000.);
0938 
0939   herror1ls = fs->make<TProfile>("herror1ls", "error 1 vs ls", 300, 0, 3000, 0, 1000.);
0940   //herror2ls = fs->make<TProfile>("herror2ls","error 2 vs ls",300,0,3000,0,1000.);
0941   herror3ls = fs->make<TProfile>("herror3ls", "error 3 vs ls", 300, 0, 3000, 0, 1000.);
0942   herror4ls = fs->make<TProfile>("herror4ls", "error 4 vs ls", 300, 0, 3000, 0, 1000.);
0943   herror5ls = fs->make<TProfile>("herror5ls", "error 5 vs ls", 300, 0, 3000, 0, 1000.);
0944   herror6ls = fs->make<TProfile>("herror6ls", "error 6 vs ls", 300, 0, 3000, 0, 1000.);
0945   //herror7ls = fs->make<TProfile>("herror7ls","error 7 vs ls",300,0,3000,0,1000.);
0946   //herror8ls = fs->make<TProfile>("herror8ls","error 8 vs ls",300,0,3000,0,1000.);
0947   //herror9ls = fs->make<TProfile>("herror9ls","error 9 vs ls",300,0,3000,0,1000.);
0948   herror10ls = fs->make<TProfile>("herror10ls", "error 10 vs ls", 300, 0, 3000, 0, 1000.);
0949   herror11ls = fs->make<TProfile>("herror11ls", "error 11 vs ls", 300, 0, 3000, 0, 1000.);
0950   herror12ls = fs->make<TProfile>("herror12ls", "error 12 vs ls", 300, 0, 3000, 0, 1000.);
0951   herror13ls = fs->make<TProfile>("herror13ls", "error 13 vs ls", 300, 0, 3000, 0, 1000.);
0952   herror14ls = fs->make<TProfile>("herror14ls", "error 14 vs ls", 300, 0, 3000, 0, 1000.);
0953   herror15ls = fs->make<TProfile>("herror15ls", "error 15 vs ls", 300, 0, 3000, 0, 1000.);
0954   herror16ls = fs->make<TProfile>("herror16ls", "error 16 vs ls", 300, 0, 3000, 0, 1000.);
0955 
0956   htotPixelsbx = fs->make<TProfile>("htotPixelsbx", " tot pixels vs bx", 4000, -0.5, 3999.5, 0, 300000.);
0957   havsizebx = fs->make<TProfile>("havsizebx", " ave bpix fed size vs bx", 4000, -0.5, 3999.5, 0, 300000.);
0958   herrorType1bx = fs->make<TProfile>("herrorType1bx", " error type 1 vs bx", 4000, -0.5, 3999.5, 0, 300000.);
0959   herrorType2bx = fs->make<TProfile>("herrorType2bx", " error type 2 vs bx", 4000, -0.5, 3999.5, 0, 300000.);
0960 
0961   //hintgl  = fs->make<TProfile>("hintgl", "inst lumi vs ls ",1000,0.,3000.,0.0,1000.);
0962   //hinstl  = fs->make<TProfile>("hinstl", "intg lumi vs ls ",1000,0.,3000.,0.0,10.);
0963 
0964   hfedchannelsize =
0965       fs->make<TProfile2D>("hfedchannelsize", "pixels per fed/channel", 40, -0.5, 39.5, 37, -0.5, 36.5, 0.0, 10000.);
0966 
0967   hfedchannelsizeb = fs->make<TH1D>("hfedchannelsizeb", "pixels per bpix channel", 200, 0.0, maxLink);
0968   hfedchannelsizeb1 = fs->make<TH1D>("hfedchannelsizeb1", "pixels per bpix1 channel", 200, 0.0, maxLink);
0969   hfedchannelsizeb2 = fs->make<TH1D>("hfedchannelsizeb2", "pixels per bpix2 channel", 200, 0.0, maxLink);
0970   hfedchannelsizeb3 = fs->make<TH1D>("hfedchannelsizeb3", "pixels per bpix3 channel", 200, 0.0, maxLink);
0971   hfedchannelsizef = fs->make<TH1D>("hfedchannelsizef", "pixels per fpix channel", 200, 0.0, maxLink);
0972 
0973 #ifdef OUTFILE
0974   outfile.open("pixfed.csv");
0975   for (int i = 0; i < 40; ++i) {
0976     if (i < 39)
0977       outfile << i << ",";
0978     else
0979       outfile << i << endl;
0980   }
0981 #endif
0982 }
0983 //-----------------------------------------------------------------------
0984 void SiPixelRawDumper::analyze(const edm::Event &ev, const edm::EventSetup &es) {
0985   // Access event information
0986   int run = ev.id().run();
0987   int event = ev.id().event();
0988   int lumiBlock = ev.luminosityBlock();
0989   int bx = ev.bunchCrossing();
0990   //int orbit     = ev.orbitNumber();
0991 
0992   hevent->Fill(float(event));
0993   hlumi0->Fill(float(lumiBlock));
0994   hbx0->Fill(float(bx));
0995   //horbit->Fill(float(orbit));
0996 
0997 #ifdef L1
0998   // Get L1
0999   edm::Handle<L1GlobalTriggerReadoutRecord> L1GTRR;
1000   ev.getByLabel("gtDigis", L1GTRR);
1001 
1002   if (L1GTRR.isValid()) {
1003     bool l1a = L1GTRR->decision();
1004     cout << " L1 status :" << l1a << endl;
1005   } else {
1006     cout << " NO L1 status " << endl;
1007   }  // if l1a
1008 #endif
1009 
1010   // Get lumi info (does not work for raw)
1011   //  edm::LuminosityBlock const& iLumi = ev.getLuminosityBlock();
1012   //   edm::Handle<LumiSummary> lumi;
1013   //   iLumi.getByLabel("lumiProducer", lumi);
1014   //   edm::Handle<edm::ConditionsInLumiBlock> cond;
1015   //   float intlumi = 0, instlumi=0;
1016   //   int beamint1=0, beamint2=0;
1017   //   iLumi.getByLabel("conditionsInEdm", cond);
1018   //   // This will only work when running on RECO until (if) they fix it in the FW
1019   //   // When running on RAW and reconstructing, the LumiSummary will not appear
1020   //   // in the event before reaching endLuminosityBlock(). Therefore, it is not
1021   //   // possible to get this info in the event
1022   //   if (lumi.isValid()) {
1023   //     intlumi =(lumi->intgRecLumi())/1000.; // integrated lumi per LS in -pb
1024   //     instlumi=(lumi->avgInsDelLumi())/1000.; //ave. inst lumi per LS in -pb
1025   //     beamint1=(cond->totalIntensityBeam1)/1000;
1026   //     beamint2=(cond->totalIntensityBeam2)/1000;
1027   //   } else {
1028   //     std::cout << "** ERROR: Event does not get lumi info\n";
1029   //   }
1030   //   cout<<instlumi<<" "<<intlumi<<" "<<lumiBlock<<endl;
1031 
1032   //   hinstl->Fill(float(lumiBlock),float(instlumi));
1033   //   hintgl->Fill(float(lumiBlock),float(intlumi));
1034 
1035   edm::Handle<FEDRawDataCollection> buffers;
1036   //static std::string label = theConfig.getUntrackedParameter<std::string>("InputLabel","source");
1037   //static std::string instance = theConfig.getUntrackedParameter<std::string>("InputInstance","");
1038   //ev.getByLabel( label, instance, buffers);
1039   ev.getByToken(rawData, buffers);  // the new bytoken
1040 
1041   std::pair<int, int> fedIds(FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID);
1042 
1043   //PixelDataFormatter formatter(0);  // only for digis
1044   //bool dummyErrorBool;
1045 
1046   //typedef unsigned int Word32;
1047   //typedef long long Word64;
1048   typedef uint32_t Word32;
1049   typedef uint64_t Word64;
1050   int status = 0;
1051   int countPixels = 0;
1052   int eventId = -1;
1053   int countErrorsPerEvent = 0;
1054   int countErrorsPerEvent1 = 0;
1055   int countErrorsPerEvent2 = 0;
1056   double aveFedSize = 0.;
1057   int stat1 = -1, stat2 = -1;
1058   int fedchannelsize[36];
1059 
1060   int countErrors[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1061 
1062   countAllEvents++;
1063 
1064   if (printHeaders || printLocal > 0)
1065     cout << "Event = " << countEvents << " Event number " << event << " Run " << run << " LS " << lumiBlock << endl;
1066 
1067   // Loop over FEDs
1068   for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
1069     //edm::DetSetVector<PixelDigi> collection;
1070     PixelDataFormatter::Errors errors;
1071 
1072     //get event data for this fed
1073     const FEDRawData &rawData = buffers->FEDData(fedId);
1074 
1075     if (printHeaders)
1076       cout << "Get data For FED = " << fedId << " size in bytes " << rawData.size() << endl;
1077     if (rawData.size() == 0)
1078       continue;  // skip if not data for this fed
1079 
1080     for (int i = 0; i < 36; ++i)
1081       fedchannelsize[i] = 0;
1082 
1083     int nWords = rawData.size() / sizeof(Word64);
1084     //cout<<" size "<<nWords<<endl;
1085 
1086     sumFedSize += float(nWords);
1087     if (fedId < 32)
1088       aveFedSize += double(2. * nWords);
1089 
1090     hsize->Fill(float(2 * nWords));   // fed buffer size in words (32bit)
1091     hsize0->Fill(float(2 * nWords));  // fed buffer size in words (32bit)
1092     if (fedId < 32)
1093       hsize1->Fill(float(2 * nWords));  // bpix fed buffer size in words (32bit)
1094     else
1095       hsize2->Fill(float(2 * nWords));  // fpix fed buffer size in words (32bit)
1096 
1097 #ifdef IND_FEDS
1098     hsizeFeds[fedId]->Fill(float(2 * nWords));  // size, includes errors and dummy words
1099 #endif
1100     hsize2d->Fill(float(fedId), float(2 * nWords));  // 2d
1101     hsizep->Fill(float(fedId), float(2 * nWords));   // profile
1102     if (fedId < 32)
1103       hsizels->Fill(float(lumiBlock), float(2 * nWords));  // bpix versu sls
1104 
1105     // check headers
1106     const Word64 *header = reinterpret_cast<const Word64 *>(rawData.data());
1107     //cout<<hex<<*header<<dec<<endl;
1108 
1109     unsigned int bxid = 0;
1110     eventId = MyDecode::header(*header, fedId, printHeaders, bxid);
1111     //if(fedId = fedIds.first)
1112     if (bx != int(bxid))
1113       cout << " Inconsistent BX: from event " << bx << " from FED " << bxid << endl;
1114 
1115     const Word64 *trailer = reinterpret_cast<const Word64 *>(rawData.data()) + (nWords - 1);
1116     //cout<<hex<<*trailer<<dec<<endl;
1117     status = MyDecode::trailer(*trailer, fedId, printHeaders);
1118 
1119     int countPixelsInFed = 0;
1120     int countErrorsInFed = 0;
1121     int countErrorsInFed1 = 0;
1122     int countErrorsInFed2 = 0;
1123     int fedChannel = 0;
1124     int num = 0;
1125 
1126     // Loop over payload words
1127     for (const Word64 *word = header + 1; word != trailer; word++) {
1128       static const Word64 WORD32_mask = 0xffffffff;
1129 
1130       for (int ipart = 0; ipart < 2; ++ipart) {
1131         Word32 w = 0;
1132         if (ipart == 0) {
1133           w = *word & WORD32_mask;  // 1st word
1134           //w1=w;
1135         } else if (ipart == 1) {
1136           w = *word >> 32 & WORD32_mask;  // 2nd word
1137         }
1138 
1139         num++;
1140         if (printLocal > 3)
1141           cout << " " << num << " " << hex << w << dec << endl;
1142 
1143         status = MyDecode::data(w, fedChannel, fedId, stat1, stat2, printData);
1144         int layer = MyDecode::checkLayerLink(fedId, fedChannel);  // get bpix layer
1145         if (layer > 10)
1146           layer = layer - 10;  // ignore 1/2 modules
1147         if (status > 0) {      // data
1148           countPixels++;
1149           countPixelsInFed++;
1150           fedchannelsize[fedChannel - 1]++;
1151 
1152         } else if (status < 0) {  // error word
1153           countErrorsInFed++;
1154           //if( status == -6 || status == -5)
1155           if (printErrors)
1156             cout << " Bad stats for FED " << fedId << " Event " << eventId << "/" << countAllEvents << " chan "
1157                  << fedChannel << " status " << status << endl;
1158           status = abs(status);
1159           // 2 - wrong channel
1160           // 3 - wrong pix or dcol
1161           // 4 - wrong roc
1162           // 5 - pix=0
1163           // 6 - double pixel
1164           // 10 - timeout ()
1165           // 11 - ene ()
1166           // 12 - mum pf rocs error ()
1167           // 13 - fsm ()
1168           // 14 - overflow ()
1169           // 15 - trailer ()
1170           // 16 - fifo  (30)
1171           // 17 - reset/resync NOT INCLUDED YET
1172 
1173           switch (status) {
1174             case (10): {  // Timeout
1175 
1176               countErrors[10]++;
1177               fedErrorsTime[fedId][(fedChannel - 1)]++;
1178               hfed2DErrors10->Fill(float(fedId), float(fedChannel));
1179               hfed2DErrors10ls->Fill(float(lumiBlock), float(fedId));  //errors
1180 
1181               herrorTimels->Fill(float(lumiBlock));
1182               if (layer == 1)
1183                 herrorTimels1->Fill(float(lumiBlock));
1184               else if (layer == 2)
1185                 herrorTimels2->Fill(float(lumiBlock));
1186               else if (layer == 3)
1187                 herrorTimels3->Fill(float(lumiBlock));
1188               else if (layer == 0)
1189                 herrorTimels0->Fill(float(lumiBlock));
1190 
1191               //hbx1->Fill(float(bx));
1192               break;
1193             }
1194 
1195             case (14): {  // OVER
1196 
1197               countErrors[14]++;
1198               fedErrorsOver[fedId][(fedChannel - 1)]++;
1199               hfed2DErrors14->Fill(float(fedId), float(fedChannel));
1200               hfed2DErrors14ls->Fill(float(lumiBlock), float(fedId));  //errors
1201 
1202               herrorOverls->Fill(float(lumiBlock));
1203               if (layer == 1)
1204                 herrorOverls1->Fill(float(lumiBlock));
1205               else if (layer == 2)
1206                 herrorOverls2->Fill(float(lumiBlock));
1207               else if (layer == 3)
1208                 herrorOverls3->Fill(float(lumiBlock));
1209               else if (layer == 0)
1210                 herrorOverls0->Fill(float(lumiBlock));
1211               //hbx2->Fill(float(bx));
1212               break;
1213             }
1214 
1215             case (11): {  // ENE
1216 
1217               countErrors[11]++;
1218               hfed2DErrors11->Fill(float(fedId), float(fedChannel));
1219               hfed2DErrors11ls->Fill(float(lumiBlock), float(fedId));  //errors
1220               //hbx3->Fill(float(bx));
1221               fedErrorsENE[fedId][(fedChannel - 1)]++;
1222               break;
1223             }
1224 
1225             case (16): {  //FIFO
1226 
1227               countErrors[16]++;
1228               hfed2DErrors16->Fill(float(fedId), float(fedChannel));
1229               hfed2DErrors16ls->Fill(float(lumiBlock), float(fedId));  //errors
1230               break;
1231             }
1232 
1233             case (12): {  // NOR
1234 
1235               countErrors[12]++;
1236               hfed2DErrors12->Fill(float(fedId), float(fedChannel));
1237               hfed2DErrors12ls->Fill(float(lumiBlock), float(fedId));  //errors
1238               //hbx5->Fill(float(bx));
1239               break;
1240             }
1241 
1242             case (15): {  // TBM Trailer
1243 
1244               countErrors[15]++;
1245               hfed2DErrors15->Fill(float(fedId), float(fedChannel));
1246               hfed2DErrors15ls->Fill(float(lumiBlock), float(fedId));  //errors
1247               break;
1248             }
1249 
1250             case (13): {  // FSM
1251 
1252               countErrors[13]++;
1253               hfed2DErrors13->Fill(float(fedId), float(fedChannel));
1254               hfed2DErrors13ls->Fill(float(lumiBlock), float(fedId));  //errors
1255               break;
1256             }
1257 
1258             case (3): {  //  inv. pix-dcol
1259 
1260               countErrors[3]++;
1261               hfed2DErrors3->Fill(float(fedId), float(fedChannel));
1262               hfed2DErrors3ls->Fill(float(lumiBlock), float(fedId));  //errors
1263               //hbx8->Fill(float(bx));
1264               break;
1265             }
1266 
1267             case (4): {  // inv roc
1268               countErrors[4]++;
1269               hfed2DErrors4->Fill(float(fedId), float(fedChannel));
1270               hfed2DErrors4ls->Fill(float(lumiBlock), float(fedId));  //errors
1271               //hbx9->Fill(float(bx));
1272               break;
1273             }
1274 
1275             case (5): {  // pix=0
1276               countErrors[5]++;
1277               hfed2DErrors5->Fill(float(fedId), float(fedChannel));
1278               hfed2DErrors5ls->Fill(float(lumiBlock), float(fedId));  //errors
1279               //hbx10->Fill(float(bx));
1280 
1281               hroc000->Fill(float(stat1));  // count rocs
1282               hcount000->Fill(float(stat2));
1283               hcount0002->Fill(float(fedId), float(stat2));
1284               break;
1285             }
1286 
1287             case (6): {  // double pix
1288 
1289               countErrors[6]++;
1290               hfed2DErrors6->Fill(float(fedId), float(fedChannel));
1291               hfed2DErrors6ls->Fill(float(lumiBlock), float(fedId));  //errors
1292               //hbx12->Fill(float(bx));
1293 
1294               hrocDouble->Fill(float(stat1));  // count rocs
1295               hcountDouble->Fill(float(stat2));
1296               hcountDouble2->Fill(float(fedId), float(stat2));
1297               break;
1298             }
1299 
1300             case (1): {  // unknown
1301               countErrors[1]++;
1302               hfed2DErrors1->Fill(float(fedId), float(fedChannel));
1303               hfed2DErrors1ls->Fill(float(lumiBlock), float(fedId));  //errors
1304               break;
1305             }
1306 
1307           }  // end switch
1308 
1309           if (status < 20)
1310             errorType[status]++;
1311 
1312           //herrorType0->Fill(float(status));
1313           //herrorFed0->Fill(float(fedId));
1314           //herrorChan0->Fill(float(fedChannel));
1315 
1316           hfed2d->Fill(float(fedId), float(status));
1317 
1318           if (status >= 10) {  // hard errors
1319             // Type - 1 Errors
1320 
1321             countErrorsInFed1++;
1322             hfedErrorType1ls->Fill(float(lumiBlock), float(fedId));  // hard errors
1323             hfed2DErrorsType1->Fill(float(fedId), float(fedChannel));
1324 
1325             herrorType1->Fill(float(status));
1326             herrorType1Fed->Fill(float(fedId));
1327             herrorType1Chan->Fill(float(fedChannel));
1328 
1329             fedErrors[fedId][(fedChannel - 1)]++;
1330 
1331           } else if (status > 0) {  // decode errors
1332             // Type 2 errprs
1333 
1334             countErrorsInFed2++;
1335             hfedErrorType2ls->Fill(float(lumiBlock), float(fedId));  // decode errors
1336             hfed2DErrorsType2->Fill(float(fedId), float(fedChannel));
1337 
1338             herrorType2->Fill(float(status));
1339             herrorType2Fed->Fill(float(fedId));
1340             herrorType2Chan->Fill(float(fedChannel));
1341 
1342             if (status == 5)
1343               decodeErrors000[fedId][(fedChannel - 1)]++;
1344             else if (status == 6)
1345               decodeErrorsDouble[fedId][(fedChannel - 1)]++;
1346             else
1347               decodeErrors[fedId][(fedChannel - 1)]++;
1348           }
1349         }
1350       }  // for  1/2 word
1351 
1352     }  // loop over longlong  words
1353 
1354     countTotErrors += countErrorsInFed;
1355     countErrorsPerEvent += countErrorsInFed;
1356     countErrorsPerEvent1 += countErrorsInFed1;
1357     countErrorsPerEvent2 += countErrorsInFed2;
1358 
1359     //convert data to digi (dummy for the moment)
1360     //formatter.interpretRawData( dummyErrorBool, fedId, rawData, collection, errors);
1361     //cout<<dummyErrorBool<<" "<<digis.size()<<" "<<errors.size()<<endl;
1362 
1363     if (countPixelsInFed > 0) {
1364       sumFedPixels[fedId] += countPixelsInFed;
1365     }
1366 
1367     hpixels->Fill(float(countPixelsInFed));
1368     hpixels0->Fill(float(countPixelsInFed));
1369     if (countPixelsInFed > 0)
1370       hpixels1->Fill(float(countPixelsInFed));
1371     if (countPixelsInFed > 0 && fedId < 32)
1372       hpixels2->Fill(float(countPixelsInFed));
1373     if (countPixelsInFed > 0 && fedId >= 32)
1374       hpixels3->Fill(float(countPixelsInFed));
1375     herrors->Fill(float(countErrorsInFed));
1376 
1377     for (int i = 0; i < 36; ++i) {
1378       hfedchannelsize->Fill(float(fedId), float(i + 1), float(fedchannelsize[i]));
1379       if (fedId < 32) {
1380         hfedchannelsizeb->Fill(float(fedchannelsize[i]));
1381         int layer = MyDecode::checkLayerLink(fedId, i);  // get bpix layer
1382         if (layer > 10)
1383           layer = layer - 10;  // ignore 1/2 modules
1384         if (layer == 3)
1385           hfedchannelsizeb3->Fill(float(fedchannelsize[i]));  // layer 3
1386         else if (layer == 2)
1387           hfedchannelsizeb2->Fill(float(fedchannelsize[i]));  // layer 2
1388         else if (layer == 1)
1389           hfedchannelsizeb1->Fill(float(fedchannelsize[i]));  // layer 1
1390         else
1391           cout << " Cannot be " << layer << " " << fedId << " " << i << endl;
1392       } else
1393         hfedchannelsizef->Fill(float(fedchannelsize[i]));  // fpix
1394     }
1395     //    if(fedId == fedIds.first || countPixelsInFed>0 || countErrorsInFed>0 )  {
1396     //       eventId = MyDecode::header(*header, true);
1397     //       if(countPixelsInFed>0 || countErrorsInFed>0 ) cout<<"fed "<<fedId<<" pix "<<countPixelsInFed<<" err "<<countErrorsInFed<<endl;
1398     //       status = MyDecode::trailer(*trailer,true);
1399     //     }
1400 
1401 #ifdef OUTFILE
1402     // print number of bytes per fed, CSV
1403     if (fedId == fedIds.second)
1404       outfile << (nWords * 8) << endl;
1405     else
1406       outfile << (nWords * 8) << ",";
1407 #endif
1408 
1409   }  // loop over feds
1410 
1411   htotPixels->Fill(float(countPixels));
1412   htotPixels0->Fill(float(countPixels));
1413   htotErrors->Fill(float(countErrorsPerEvent));
1414 
1415   htotPixelsls->Fill(float(lumiBlock), float(countPixels));
1416   htotPixelsbx->Fill(float(bx), float(countPixels));
1417 
1418   herrorType1ls->Fill(float(lumiBlock), float(countErrorsPerEvent1));
1419   herrorType2ls->Fill(float(lumiBlock), float(countErrorsPerEvent2));
1420 
1421   herror1ls->Fill(float(lumiBlock), float(countErrors[1]));
1422   herror3ls->Fill(float(lumiBlock), float(countErrors[3]));
1423   herror4ls->Fill(float(lumiBlock), float(countErrors[4]));
1424   herror5ls->Fill(float(lumiBlock), float(countErrors[5]));
1425   herror6ls->Fill(float(lumiBlock), float(countErrors[6]));
1426   herror10ls->Fill(float(lumiBlock), float(countErrors[10]));
1427   herror11ls->Fill(float(lumiBlock), float(countErrors[11]));
1428   herror12ls->Fill(float(lumiBlock), float(countErrors[12]));
1429   herror13ls->Fill(float(lumiBlock), float(countErrors[13]));
1430   herror14ls->Fill(float(lumiBlock), float(countErrors[14]));
1431   herror15ls->Fill(float(lumiBlock), float(countErrors[15]));
1432   herror16ls->Fill(float(lumiBlock), float(countErrors[16]));
1433 
1434   herrorType1bx->Fill(float(bx), float(countErrorsPerEvent1));
1435   herrorType2bx->Fill(float(bx), float(countErrorsPerEvent2));
1436 
1437   aveFedSize /= 32.;
1438   hsize3->Fill(aveFedSize);
1439   //hsize2dls->Fill(float(lumiBlock),aveFedSize);
1440 
1441   havsizels->Fill(float(lumiBlock), aveFedSize);
1442   havsizebx->Fill(float(bx), aveFedSize);
1443 
1444   if (countPixels > 0) {
1445     hlumi->Fill(float(lumiBlock));
1446     hbx->Fill(float(bx));
1447     htotPixels1->Fill(float(countPixels));
1448 
1449     //cout<<"EVENT: "<<countEvents<<" "<<eventId<<" pixels "<<countPixels<<" errors "<<countTotErrors<<endl;
1450     sumPixels += countPixels;
1451     countEvents++;
1452     //int dummy=0;
1453     //cout<<" : ";
1454     //cin>>dummy;
1455   }  // end if
1456 
1457 }  // end analyze
1458 
1459 // 2 - wrong channel
1460 // 4 - wrong roc
1461 // 3 - wrong pix or dcol
1462 // 5 - pix=0
1463 // 6 - double pix
1464 // 10 - timeout ()
1465 // 11 - ene ()
1466 // 12 - mum pf rocs error ()
1467 // 13 - fsm ()
1468 // 14 - overflow ()
1469 // 15 - trailer ()
1470 // 16 - fifo  (30)
1471 // 17 - reset/resync NOT INCLUDED YET
1472 
1473 #include "FWCore/Framework/interface/MakerMacros.h"
1474 DEFINE_FWK_MODULE(SiPixelRawDumper);