Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-24 01:27:51

0001 /******************************************
0002  *
0003  * This is a part of CTPPSDQM software.
0004  * Authors:
0005  *   F.Ferro INFN Genova
0006  *   Vladimir Popov (vladimir.popov@cern.ch)
0007  *
0008  *******************************************/
0009 
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "FWCore/Common/interface/TriggerNames.h"
0016 
0017 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0018 #include "DQMServices/Core/interface/DQMStore.h"
0019 
0020 #include "DataFormats/Common/interface/DetSetVector.h"
0021 
0022 #include "CondFormats/PPSObjects/interface/CTPPSPixelIndices.h"
0023 #include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
0024 #include "DataFormats/CTPPSDigi/interface/CTPPSPixelDigi.h"
0025 #include "DataFormats/CTPPSDigi/interface/CTPPSPixelDataError.h"
0026 #include "DataFormats/CTPPSReco/interface/CTPPSPixelCluster.h"
0027 #include "DataFormats/CTPPSReco/interface/CTPPSPixelLocalTrack.h"
0028 #include "DataFormats/Common/interface/TriggerResults.h"
0029 
0030 #include "CondFormats/DataRecord/interface/CTPPSPixelDAQMappingRcd.h"
0031 #include "CondFormats/PPSObjects/interface/CTPPSPixelDAQMapping.h"
0032 
0033 #include <string>
0034 
0035 //-----------------------------------------------------------------------------
0036 
0037 class CTPPSPixelDQMSource : public DQMEDAnalyzer {
0038 public:
0039   CTPPSPixelDQMSource(const edm::ParameterSet &ps);
0040   ~CTPPSPixelDQMSource() override;
0041 
0042 protected:
0043   void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override;
0044   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0045   void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override;
0046 
0047 private:
0048   unsigned int verbosity;
0049   long int nEvents = 0;
0050   edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelDigi>> tokenDigi;
0051   edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelDataError>> tokenError;
0052   edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelCluster>> tokenCluster;
0053   edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelLocalTrack>> tokenTrack;
0054   edm::EDGetTokenT<edm::TriggerResults> tokenTrigResults;
0055   edm::ESGetToken<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd> tokenPixelDAQMapping;
0056   std::string randomHLTPath;
0057   std::string mappingLabel;
0058 
0059   static constexpr int NArms = 2;
0060   static constexpr int NStationMAX = 3;  // in an arm
0061   static constexpr int NRPotsMAX = 6;    // per station
0062   static constexpr int NplaneMAX = 6;    // per RPot
0063   static constexpr int NROCsMAX = 6;     // per plane
0064   static constexpr int RPn_first = 3, RPn_last = 4;
0065   static constexpr int ADCMax = 256;
0066   static constexpr int StationIDMAX = 4;  // possible range of ID
0067   static constexpr int RPotsIDMAX = 8;    // possible range of ID
0068   static constexpr int NLocalTracksMAX = 10;
0069   static constexpr int hitMultMAX = 50;   // tuned
0070   static constexpr int ClusMultMAX = 10;  // tuned
0071   static constexpr int ClusterSizeMax = 9;
0072   static constexpr int errCodeSize = 15;
0073   static constexpr int minFedNumber = 1462;
0074   static constexpr int numberOfFeds = 2;
0075   static constexpr float x0Minimum = -5.;
0076   static constexpr float y0Minimum = -10.;
0077   static constexpr float x0Maximum = 25.;
0078   static constexpr float y0Maximum = 22.;
0079   static constexpr float xBins_per_mm = 3;  // number of x bins per mm
0080   static constexpr float yBins_per_mm = 3;  // number of y bins per mm
0081 
0082   CTPPSPixelIndices thePixIndices;
0083 
0084   int TrackFitDimension = 4;
0085 
0086   static constexpr int NRPotBinsInStation = RPn_last - RPn_first;
0087   static constexpr int NPlaneBins = NplaneMAX * NRPotBinsInStation;
0088 
0089   MonitorElement *hBX, *hBXshort, *h2AllPlanesActive, *hpixLTrack;
0090   MonitorElement *hpRPactive;
0091 
0092   MonitorElement *h2HitsMultipl[NArms][NStationMAX];
0093   MonitorElement *h2CluSize[NArms][NStationMAX];
0094 
0095   static constexpr int RPotsTotalNumber = NArms * NStationMAX * NRPotsMAX;
0096 
0097   int RPindexValid[RPotsTotalNumber];
0098   MonitorElement *h2trackXY0[RPotsTotalNumber];
0099   MonitorElement *h2ErrorCodeRP[RPotsTotalNumber];
0100   MonitorElement *h2ErrorCodeFED[2];
0101   MonitorElement *h2TBMMessageFED[2];
0102   MonitorElement *h2TBMTypeFED[2];
0103   MonitorElement *h2ErrorCodeUnidDet;
0104   MonitorElement *h2TBMMessageUnidDet;
0105   MonitorElement *h2TBMTypeUnidDet;
0106 
0107   MonitorElement *h2FullType;
0108   MonitorElement *h2TBMMessageRP[RPotsTotalNumber];
0109   MonitorElement *h2TBMTypeRP[RPotsTotalNumber];
0110 
0111   MonitorElement *htrackMult[RPotsTotalNumber];
0112   MonitorElement *htrackHits[RPotsTotalNumber];
0113   MonitorElement *hRPotActivPlanes[RPotsTotalNumber];
0114   MonitorElement *hRPotActivBX[RPotsTotalNumber];
0115   MonitorElement *hRPotActivBXroc[RPotsTotalNumber];
0116   MonitorElement *hRPotActivBXroc_3[RPotsTotalNumber];
0117   MonitorElement *hRPotActivBXroc_2[RPotsTotalNumber];
0118   MonitorElement *h2HitsMultROC[RPotsTotalNumber];
0119   MonitorElement *hp2HitsMultROC_LS[RPotsTotalNumber];
0120   MonitorElement *hHitsMult[RPotsTotalNumber][NplaneMAX];
0121   MonitorElement *h2xyHits[RPotsTotalNumber][NplaneMAX];
0122   MonitorElement *hp2xyADC[RPotsTotalNumber][NplaneMAX];
0123   MonitorElement *h2Efficiency[RPotsTotalNumber][NplaneMAX];
0124   MonitorElement *h2xyROCHits[RPotsTotalNumber * NplaneMAX][NROCsMAX];
0125   MonitorElement *hROCadc[RPotsTotalNumber * NplaneMAX][NROCsMAX];
0126   MonitorElement *hRPotActivBXall[RPotsTotalNumber];
0127   MonitorElement *h2HitsVsBXRandoms[RPotsTotalNumber];
0128   int HitsMultROC[RPotsTotalNumber * NplaneMAX][NROCsMAX];
0129   int HitsMultPlane[RPotsTotalNumber][NplaneMAX];
0130 
0131   //--------------------------------------------------------
0132   static constexpr int LINK_bits = 6;
0133   static constexpr int ROC_bits = 5;
0134   static constexpr int DCOL_bits = 5;
0135   static constexpr int PXID_bits = 8;
0136   static constexpr int ADC_bits = 8;
0137   static constexpr int DataBit_bits = 1;
0138 
0139   static constexpr int ADC_shift = 0;
0140   static constexpr int PXID_shift = ADC_shift + ADC_bits;
0141   static constexpr int DCOL_shift = PXID_shift + PXID_bits;
0142   static constexpr int ROC_shift = DCOL_shift + DCOL_bits;
0143   static constexpr int LINK_shift = ROC_shift + ROC_bits;
0144   static constexpr int DB0_shift = 0;
0145   static constexpr int DB1_shift = DB0_shift + DataBit_bits;
0146   static constexpr int DB2_shift = DB1_shift + DataBit_bits;
0147   static constexpr int DB3_shift = DB2_shift + DataBit_bits;
0148   static constexpr int DB4_shift = DB3_shift + DataBit_bits;
0149   static constexpr int DB5_shift = DB4_shift + DataBit_bits;
0150   static constexpr int DB6_shift = DB5_shift + DataBit_bits;
0151   static constexpr int DB7_shift = DB6_shift + DataBit_bits;
0152 
0153   static constexpr uint32_t LINK_mask = ~(~uint32_t(0) << LINK_bits);
0154   static constexpr uint32_t ROC_mask = ~(~uint32_t(0) << ROC_bits);
0155   static constexpr uint32_t DCOL_mask = ~(~uint32_t(0) << DCOL_bits);
0156   static constexpr uint32_t PXID_mask = ~(~uint32_t(0) << PXID_bits);
0157   static constexpr uint32_t ADC_mask = ~(~uint32_t(0) << ADC_bits);
0158   static constexpr uint32_t DataBit_mask = ~(~uint32_t(0) << DataBit_bits);
0159   // Flags for disabling set of plots
0160   bool offlinePlots = true;
0161   bool onlinePlots = true;
0162 
0163   // Flags for disabling plots of a plane
0164   bool isPlanePlotsTurnedOff[NArms][NStationMAX][NRPotsMAX][NplaneMAX] = {};
0165 
0166   unsigned int rpStatusWord = 0x8008;      // 220_fr_hr(stn2rp3)+ 210_fr_hr
0167   int RPstatus[StationIDMAX][RPotsIDMAX];  // symmetric in both arms
0168   int StationStatus[StationIDMAX];         // symmetric in both arms
0169   const int IndexNotValid = 0;
0170 
0171   int getRPindex(int arm, int station, int rp) {
0172     if (arm < 0 || station < 0 || rp < 0)
0173       return (IndexNotValid);
0174     if (arm > 1 || station >= NStationMAX || rp >= NRPotsMAX)
0175       return (IndexNotValid);
0176     int rc = (arm * NStationMAX + station) * NRPotsMAX + rp;
0177     return (rc);
0178   }
0179 
0180   int getPlaneIndex(int arm, int station, int rp, int plane) {
0181     if (plane < 0 || plane >= NplaneMAX)
0182       return (IndexNotValid);
0183     int rc = getRPindex(arm, station, rp);
0184     if (rc == IndexNotValid)
0185       return (IndexNotValid);
0186     return (rc * NplaneMAX + plane);
0187   }
0188 
0189   int getRPInStationBin(int rp) { return (rp - RPn_first + 1); }
0190 
0191   static constexpr int NRPglobalBins = 4;  // 2 arms w. 2 stations w. 1 RP
0192 
0193   int getRPglobalBin(int arm, int stn) {
0194     static constexpr int stationBinOrder[NStationMAX] = {0, 4, 1};
0195     return (arm * 2 + stationBinOrder[stn] + 1);
0196   }
0197 
0198   int prIndex(int rp, int plane)  // plane index in station
0199 
0200   {
0201     return ((rp - RPn_first) * NplaneMAX + plane);
0202   }
0203   int getDet(int id) { return (id >> DetId::kDetOffset) & 0xF; }
0204   int getPixPlane(int id) { return ((id >> 16) & 0x7); }
0205   //  int getSubdet(int id) { return ((id>>kSubdetOffset)&0x7); }
0206 
0207   float x0_MIN, x0_MAX, y0_MIN, y0_MAX;
0208 };
0209 
0210 //----------------------------------------------------------------------------------
0211 
0212 using namespace std;
0213 using namespace edm;
0214 
0215 //-------------------------------------------------------------------------------
0216 
0217 CTPPSPixelDQMSource::CTPPSPixelDQMSource(const edm::ParameterSet &ps)
0218     : verbosity(ps.getUntrackedParameter<unsigned int>("verbosity", 0)),
0219       randomHLTPath(ps.getUntrackedParameter<std::string>("randomHLTPath", "")),
0220       rpStatusWord(ps.getUntrackedParameter<unsigned int>("RPStatusWord", 0x8008)) {
0221   tokenDigi = consumes<DetSetVector<CTPPSPixelDigi>>(ps.getUntrackedParameter<edm::InputTag>("tagRPixDigi"));
0222   tokenError = consumes<DetSetVector<CTPPSPixelDataError>>(ps.getUntrackedParameter<edm::InputTag>("tagRPixError"));
0223   tokenCluster = consumes<DetSetVector<CTPPSPixelCluster>>(ps.getUntrackedParameter<edm::InputTag>("tagRPixCluster"));
0224   tokenTrack = consumes<DetSetVector<CTPPSPixelLocalTrack>>(ps.getUntrackedParameter<edm::InputTag>("tagRPixLTrack"));
0225   tokenTrigResults = consumes<edm::TriggerResults>(ps.getUntrackedParameter<edm::InputTag>("tagTrigResults"));
0226   tokenPixelDAQMapping = esConsumes<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd>();
0227   mappingLabel = ps.getUntrackedParameter<std::string>("mappingLabel");
0228   offlinePlots = ps.getUntrackedParameter<bool>("offlinePlots", true);
0229   onlinePlots = ps.getUntrackedParameter<bool>("onlinePlots", true);
0230 
0231   vector<string> disabledPlanePlotsVec =
0232       ps.getUntrackedParameter<vector<string>>("turnOffPlanePlots", vector<string>());
0233   // Parse the strings in disabledPlanePlotsVec and set the flags in
0234   // isPlanePlotsTurnedOff
0235   for (auto s : disabledPlanePlotsVec) {
0236     // Check that the format is <arm>_<station>_<RP>_<Plane>
0237     if (count(s.begin(), s.end(), '_') != 3)
0238       throw cms::Exception("RPixPlaneCombinatoryTracking") << "Invalid string in turnOffPlanePlots: " << s;
0239     else {
0240       vector<string> armStationRpPlane;
0241       size_t pos = 0;
0242       while ((pos = s.find('_')) != string::npos) {
0243         armStationRpPlane.push_back(s.substr(0, pos));
0244         s.erase(0, pos + 1);
0245       }
0246       armStationRpPlane.push_back(s);
0247 
0248       int arm = stoi(armStationRpPlane.at(0));
0249       int station = stoi(armStationRpPlane.at(1));
0250       int rp = stoi(armStationRpPlane.at(2));
0251       int plane = stoi(armStationRpPlane.at(3));
0252 
0253       if (arm < NArms && station < NStationMAX && rp < NRPotsMAX && plane < NplaneMAX) {
0254         if (verbosity)
0255           LogPrint("CTPPSPixelDQMSource")
0256               << "Shutting off plots for: Arm " << arm << " Station " << station << " Rp " << rp << " Plane " << plane;
0257         isPlanePlotsTurnedOff[arm][station][rp][plane] = true;
0258       } else {
0259         throw cms::Exception("RPixPlaneCombinatoryTracking") << "Invalid string in turnOffPlanePlots: " << s;
0260       }
0261     }
0262   }
0263 }
0264 
0265 //----------------------------------------------------------------------------------
0266 
0267 CTPPSPixelDQMSource::~CTPPSPixelDQMSource() {}
0268 
0269 //--------------------------------------------------------------------------
0270 
0271 void CTPPSPixelDQMSource::dqmBeginRun(edm::Run const &run, edm::EventSetup const &) {
0272   if (verbosity)
0273     LogPrint("CTPPSPixelDQMSource") << "RPstatusWord= " << rpStatusWord;
0274   nEvents = 0;
0275 
0276   CTPPSPixelLocalTrack thePixelLocalTrack;
0277   TrackFitDimension = thePixelLocalTrack.dimension;
0278 
0279   for (int stn = 0; stn < StationIDMAX; stn++) {
0280     StationStatus[stn] = 0;
0281     for (int rp = 0; rp < RPotsIDMAX; rp++)
0282       RPstatus[stn][rp] = 0;
0283   }
0284 
0285   unsigned int rpSts = rpStatusWord << 1;
0286   for (int stn = 0; stn < NStationMAX; stn++) {
0287     int stns = 0;
0288     for (int rp = 0; rp < NRPotsMAX; rp++) {
0289       rpSts = (rpSts >> 1);
0290       RPstatus[stn][rp] = rpSts & 1;
0291       if (RPstatus[stn][rp] > 0)
0292         stns = 1;
0293     }
0294     StationStatus[stn] = stns;
0295   }
0296 
0297   for (int ind = 0; ind < 2 * 3 * NRPotsMAX; ind++)
0298     RPindexValid[ind] = 0;
0299 
0300   x0_MIN = y0_MIN = 1.0e06;
0301   x0_MAX = y0_MAX = -1.0e06;
0302 }
0303 
0304 //-------------------------------------------------------------------------------------
0305 
0306 void CTPPSPixelDQMSource::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) {
0307   ibooker.cd();
0308   ibooker.setCurrentFolder("CTPPS/TrackingPixel");
0309   char s[50];
0310   string armTitleShort, stnTitleShort;
0311 
0312   TAxis *yah1st = nullptr;
0313   TAxis *xaRPact = nullptr;
0314   TAxis *xah1trk = nullptr;
0315   if (onlinePlots) {
0316     hBX = ibooker.book1D("events per BX", "ctpps_pixel;Event.BX", 4002, -1.5, 4000. + 0.5);
0317     hBXshort = ibooker.book1D("events per BX(short)", "ctpps_pixel;Event.BX", 102, -1.5, 100. + 0.5);
0318 
0319     string str1st = "Pixel planes activity";
0320     h2AllPlanesActive = ibooker.book2DD(
0321         str1st, str1st + "(digi task);Plane #", NplaneMAX, 0, NplaneMAX, NRPglobalBins, 0.5, NRPglobalBins + 0.5);
0322     TH2D *h1st = h2AllPlanesActive->getTH2D();
0323     h1st->SetOption("colz");
0324     yah1st = h1st->GetYaxis();
0325 
0326     string str2 = "Pixel RP active";
0327     hpRPactive = ibooker.bookProfile(
0328         str2, str2 + " per event(digi task)", NRPglobalBins, 0.5, NRPglobalBins + 0.5, -0.1, 1.1, "");
0329     xaRPact = hpRPactive->getTProfile()->GetXaxis();
0330     hpRPactive->getTProfile()->SetOption("hist");
0331     hpRPactive->getTProfile()->SetMinimum(0.);
0332     hpRPactive->getTProfile()->SetMaximum(1.1);
0333 
0334     str2 = "Pixel Local Tracks";
0335     hpixLTrack = ibooker.bookProfile(
0336         str2, str2 + " per event", NRPglobalBins, 0.5, NRPglobalBins + 0.5, -0.1, NLocalTracksMAX, "");
0337 
0338     xah1trk = hpixLTrack->getTProfile()->GetXaxis();
0339     hpixLTrack->getTProfile()->GetYaxis()->SetTitle("average number of tracks per event");
0340     hpixLTrack->getTProfile()->SetOption("hist");
0341   }
0342   const float minErrCode = 25.;
0343   const string errCode[errCodeSize] = {
0344       "Masked channel                     ",  // error 25
0345       "Gap word",                             // error 26
0346       "Dummy word",                           // error 27
0347       "FIFO nearly full",                     // error 28
0348       "Channel Timeout",                      // error 29
0349       "TBM Trailer",                          // error 30
0350       "Event number mismatch",                // error 31
0351       "Invalid/no FED header",                // error 32
0352       "Invalid/no FED trailer",               // error 33
0353       "Size mismatch",                        // error 34
0354       "Conversion: inv. channel",             // error 35
0355       "Conversion: inv. ROC number",          // error 36
0356       "Conversion: inv. pixel address",       // error 37
0357       "-",
0358       "CRC"  //error 39
0359   };
0360 
0361   const string tbmMessage[8] = {"Stack full ",
0362                                 "Pre-cal issued ",
0363                                 "Clear trigger counter",
0364                                 "Synch trigger",
0365                                 "Synch trigger error",
0366                                 "Reset ROC",
0367                                 "Reset TBM",
0368                                 "No token pass"};
0369 
0370   const string tbmType[5] = {
0371       "All bits 0", "bit 8 : Overflow", "bit 9 : PKAM", "bit 10 : Auto Reset", "bit 11 : Number of ROC Error"};
0372 
0373   h2ErrorCodeUnidDet = ibooker.book2D("Errors in Unidentified Det",
0374                                       "Errors in Unidentified Det;;fed",
0375                                       errCodeSize,
0376                                       minErrCode - 0.5,
0377                                       minErrCode + float(errCodeSize) - 0.5,
0378                                       2,
0379                                       1461.5,
0380                                       1463.5);
0381   for (unsigned int iBin = 1; iBin <= errCodeSize; iBin++)
0382     h2ErrorCodeUnidDet->setBinLabel(iBin, errCode[iBin - 1]);
0383   h2ErrorCodeUnidDet->setBinLabel(1, "1462", 2);
0384   h2ErrorCodeUnidDet->setBinLabel(2, "1463", 2);
0385   h2ErrorCodeUnidDet->getTH2F()->SetOption("colz");
0386   h2TBMMessageUnidDet =
0387       ibooker.book2D("TBM Message Unid Det", "TBM Message Unid Det;;fed", 8, -0.5, 7.5, 2, 1461.5, 1463.5);
0388   for (unsigned int iBin = 1; iBin <= 8; iBin++)
0389     h2TBMMessageUnidDet->setBinLabel(iBin, tbmMessage[iBin - 1]);
0390   h2TBMMessageUnidDet->getTH2F()->SetOption("colz");
0391 
0392   h2TBMTypeUnidDet =
0393       ibooker.book2D("TBM Type in Unid Det", "TBM Type in Unid Det;;fed", 5, -0.5, 4.5, 2, 1461.5, 1463.5);
0394   for (unsigned int iBin = 1; iBin <= 5; iBin++)
0395     h2TBMTypeUnidDet->setBinLabel(iBin, tbmType[iBin - 1]);
0396   h2TBMTypeUnidDet->getTH2F()->SetOption("colz");
0397 
0398   h2FullType = ibooker.book2D("Full FIFO", "Full FIFO;;fed", 7, 0.5, 7.5, 2, 1461.5, 1463.5);
0399   h2FullType->setBinLabel(1, "1462", 2);
0400   h2FullType->setBinLabel(2, "1463", 2);
0401   h2FullType->getTH2F()->SetOption("colz");
0402 
0403   for (int iFed = 0; iFed < numberOfFeds; iFed++) {
0404     int fedId = minFedNumber + iFed;
0405     auto s_fed = std::to_string(fedId);
0406 
0407     h2ErrorCodeFED[iFed] = ibooker.book2D("Errors in FED" + s_fed,
0408                                           "Errors in FED" + s_fed + ";;channel",
0409                                           errCodeSize,
0410                                           minErrCode - 0.5,
0411                                           minErrCode + float(errCodeSize) - 0.5,
0412                                           37,
0413                                           -0.5,
0414                                           36.5);
0415     for (unsigned int iBin = 1; iBin <= errCodeSize; iBin++)
0416       h2ErrorCodeFED[iFed]->setBinLabel(iBin, errCode[iBin - 1]);
0417     h2ErrorCodeFED[iFed]->getTH2F()->SetOption("colz");
0418 
0419     h2TBMMessageFED[iFed] = ibooker.book2D(
0420         "TBM Message in FED" + s_fed, "TBM Message in FED" + s_fed + ";;channel", 8, -0.5, 7.5, 37, -0.5, 36.5);
0421     for (unsigned int iBin = 1; iBin <= 8; iBin++)
0422       h2TBMMessageFED[iFed]->setBinLabel(iBin, tbmMessage[iBin - 1]);
0423     h2TBMMessageFED[iFed]->getTH2F()->SetOption("colz");
0424 
0425     h2TBMTypeFED[iFed] = ibooker.book2D(
0426         "TBM Type in FED" + s_fed, "TBM Type in FED" + s_fed + ";;channel", 5, -0.5, 4.5, 37, -0.5, 36.5);
0427     for (unsigned int iBin = 1; iBin <= 5; iBin++)
0428       h2TBMTypeFED[iFed]->setBinLabel(iBin, tbmType[iBin - 1]);
0429     h2TBMTypeFED[iFed]->getTH2F()->SetOption("colz");
0430   }
0431 
0432   for (int arm = 0; arm < 2; arm++) {
0433     CTPPSDetId ID(CTPPSDetId::sdTrackingPixel, arm, 0);
0434     string sd, armTitle;
0435     ID.armName(sd, CTPPSDetId::nPath);
0436     ID.armName(armTitle, CTPPSDetId::nFull);
0437     ID.armName(armTitleShort, CTPPSDetId::nShort);
0438 
0439     ibooker.setCurrentFolder(sd);
0440 
0441     for (int stn = 0; stn < NStationMAX; stn++) {
0442       if (StationStatus[stn] == 0)
0443         continue;
0444       ID.setStation(stn);
0445       string stnd, stnTitle;
0446 
0447       CTPPSDetId(ID.stationId()).stationName(stnd, CTPPSDetId::nPath);
0448       CTPPSDetId(ID.stationId()).stationName(stnTitle, CTPPSDetId::nFull);
0449       CTPPSDetId(ID.stationId()).stationName(stnTitleShort, CTPPSDetId::nShort);
0450 
0451       ibooker.setCurrentFolder(stnd);
0452       //--------- RPots ---
0453       int pixBinW = 4;
0454       for (int rp = RPn_first; rp < RPn_last; rp++) {  // only installed pixel pots
0455         ID.setRP(rp);
0456         string rpd, rpTitle;
0457         CTPPSDetId(ID.rpId()).rpName(rpTitle, CTPPSDetId::nShort);
0458         string rpBinName = armTitleShort + "_" + stnTitleShort + "_" + rpTitle;
0459         if (onlinePlots) {
0460           yah1st->SetBinLabel(getRPglobalBin(arm, stn), rpBinName.c_str());
0461           xah1trk->SetBinLabel(getRPglobalBin(arm, stn), rpBinName.c_str());
0462           xaRPact->SetBinLabel(getRPglobalBin(arm, stn), rpBinName.c_str());
0463         }
0464         if (RPstatus[stn][rp] == 0)
0465           continue;
0466         int indexP = getRPindex(arm, stn, rp);
0467         RPindexValid[indexP] = 1;
0468 
0469         CTPPSDetId(ID.rpId()).rpName(rpTitle, CTPPSDetId::nFull);
0470         CTPPSDetId(ID.rpId()).rpName(rpd, CTPPSDetId::nPath);
0471 
0472         ibooker.setCurrentFolder(rpd);
0473 
0474         string st = "track intercept point";
0475         string st2 = ": " + stnTitle;
0476         h2trackXY0[indexP] = ibooker.book2D(st,
0477                                             st + st2 + ";x0;y0",
0478                                             int(x0Maximum - x0Minimum) * xBins_per_mm,
0479                                             x0Minimum,
0480                                             x0Maximum,
0481                                             int(y0Maximum - y0Minimum) * yBins_per_mm,
0482                                             y0Minimum,
0483                                             y0Maximum);
0484         h2trackXY0[indexP]->getTH2F()->SetOption("colz");
0485         st = "Error Code";
0486         h2ErrorCodeRP[indexP] = ibooker.book2D(st,
0487                                                st + st2 + ";;plane",
0488                                                errCodeSize,
0489                                                minErrCode - 0.5,
0490                                                minErrCode + float(errCodeSize) - 0.5,
0491                                                6,
0492                                                -0.5,
0493                                                5.5);
0494         for (unsigned int iBin = 1; iBin <= errCodeSize; iBin++)
0495           h2ErrorCodeRP[indexP]->setBinLabel(iBin, errCode[iBin - 1]);
0496         h2ErrorCodeRP[indexP]->getTH2F()->SetOption("colz");
0497 
0498         h2TBMMessageRP[indexP] = ibooker.book2D("TBM Message", "TBM Message;;plane", 8, -0.5, 7.5, 6, -0.5, 5.5);
0499         for (unsigned int iBin = 1; iBin <= 8; iBin++)
0500           h2TBMMessageRP[indexP]->setBinLabel(iBin, tbmMessage[iBin - 1]);
0501         h2TBMMessageRP[indexP]->getTH2F()->SetOption("colz");
0502 
0503         h2TBMTypeRP[indexP] = ibooker.book2D("TBM Type", "TBM Type;;plane", 5, -0.5, 4.5, 6, -0.5, 5.5);
0504         for (unsigned int iBin = 1; iBin <= 5; iBin++)
0505           h2TBMTypeRP[indexP]->setBinLabel(iBin, tbmType[iBin - 1]);
0506         h2TBMTypeRP[indexP]->getTH2F()->SetOption("colz");
0507 
0508         st = "number of tracks per event";
0509         htrackMult[indexP] = ibooker.bookProfile(st,
0510                                                  rpTitle + ";number of tracks",
0511                                                  NLocalTracksMAX + 1,
0512                                                  -0.5,
0513                                                  NLocalTracksMAX + 0.5,
0514                                                  -0.5,
0515                                                  NLocalTracksMAX + 0.5,
0516                                                  "");
0517         htrackMult[indexP]->getTProfile()->SetOption("hist");
0518 
0519         hRPotActivPlanes[indexP] = ibooker.bookProfile("number of fired planes per event",
0520                                                        rpTitle + ";nPlanes;Probability",
0521                                                        NplaneMAX + 1,
0522                                                        -0.5,
0523                                                        NplaneMAX + 0.5,
0524                                                        -0.5,
0525                                                        NplaneMAX + 0.5,
0526                                                        "");
0527         hRPotActivPlanes[indexP]->getTProfile()->SetOption("hist");
0528 
0529         hp2HitsMultROC_LS[indexP] = ibooker.bookProfile2D("ROCs hits multiplicity per event vs LS",
0530                                                           rpTitle + ";LumiSection;Plane#___ROC#",
0531                                                           1000,
0532                                                           0.,
0533                                                           1000.,
0534                                                           NplaneMAX * NROCsMAX,
0535                                                           0.,
0536                                                           double(NplaneMAX * NROCsMAX),
0537                                                           0.,
0538                                                           rpixValues::ROCSizeInX * rpixValues::ROCSizeInY,
0539                                                           "");
0540         hp2HitsMultROC_LS[indexP]->getTProfile2D()->SetOption("colz");
0541         hp2HitsMultROC_LS[indexP]->getTProfile2D()->SetMinimum(1.0e-10);
0542         hp2HitsMultROC_LS[indexP]->getTProfile2D()->SetCanExtend(TProfile2D::kXaxis);
0543         TAxis *yahp2 = hp2HitsMultROC_LS[indexP]->getTProfile2D()->GetYaxis();
0544         for (int p = 0; p < NplaneMAX; p++) {
0545           sprintf(s, "plane%d_0", p);
0546           yahp2->SetBinLabel(p * NplaneMAX + 1, s);
0547           for (int r = 1; r < NROCsMAX; r++) {
0548             sprintf(s, "   %d_%d", p, r);
0549             yahp2->SetBinLabel(p * NplaneMAX + r + 1, s);
0550           }
0551         }
0552 
0553         // Hits per plane per bx
0554         h2HitsVsBXRandoms[indexP] = ibooker.book2D(
0555             "Hits per plane per BX - random triggers", rpTitle + ";Event.BX;Plane", 4002, -1.5, 4000. + 0.5, 6, 0, 6);
0556 
0557         if (onlinePlots) {
0558           string st3 = ";PlaneIndex(=pixelPot*PlaneMAX + plane)";
0559 
0560           st = "hit multiplicity in planes";
0561           h2HitsMultipl[arm][stn] = ibooker.book2DD(
0562               st, st + st2 + st3 + ";multiplicity", NPlaneBins, 0, NPlaneBins, hitMultMAX, 0, hitMultMAX);
0563           h2HitsMultipl[arm][stn]->getTH2D()->SetOption("colz");
0564 
0565           st = "cluster size in planes";
0566           h2CluSize[arm][stn] = ibooker.book2D(st,
0567                                                st + st2 + st3 + ";Cluster size",
0568                                                NPlaneBins,
0569                                                0,
0570                                                NPlaneBins,
0571                                                ClusterSizeMax + 1,
0572                                                0,
0573                                                ClusterSizeMax + 1);
0574           h2CluSize[arm][stn]->getTH2F()->SetOption("colz");
0575 
0576           st = "number of hits per track";
0577           htrackHits[indexP] = ibooker.bookProfile(st, rpTitle + ";number of hits", 5, 1.5, 6.5, -0.1, 1.1, "");
0578           htrackHits[indexP]->getTProfile()->SetOption("hist");
0579 
0580           h2HitsMultROC[indexP] = ibooker.bookProfile2D("ROCs hits multiplicity per event",
0581                                                         rpTitle + ";plane # ;ROC #",
0582                                                         NplaneMAX,
0583                                                         -0.5,
0584                                                         NplaneMAX - 0.5,
0585                                                         NROCsMAX,
0586                                                         -0.5,
0587                                                         NROCsMAX - 0.5,
0588                                                         0.,
0589                                                         rpixValues::ROCSizeInX * rpixValues::ROCSizeInY,
0590                                                         "");
0591           h2HitsMultROC[indexP]->getTProfile2D()->SetOption("colztext");
0592           h2HitsMultROC[indexP]->getTProfile2D()->SetMinimum(1.e-10);
0593 
0594           ibooker.setCurrentFolder(rpd + "/latency");
0595           hRPotActivBX[indexP] =
0596               ibooker.book1D("5 fired planes per BX", rpTitle + ";Event.BX", 4002, -1.5, 4000. + 0.5);
0597 
0598           hRPotActivBXroc[indexP] =
0599               ibooker.book1D("4 fired ROCs per BX", rpTitle + ";Event.BX", 4002, -1.5, 4000. + 0.5);
0600           hRPotActivBXroc_3[indexP] =
0601               ibooker.book1D("3 fired ROCs per BX", rpTitle + ";Event.BX", 4002, -1.5, 4000. + 0.5);
0602           hRPotActivBXroc_2[indexP] =
0603               ibooker.book1D("2 fired ROCs per BX", rpTitle + ";Event.BX", 4002, -1.5, 4000. + 0.5);
0604 
0605           hRPotActivBXall[indexP] = ibooker.book1D("hits per BX", rpTitle + ";Event.BX", 4002, -1.5, 4000. + 0.5);
0606         }
0607         int nbins = rpixValues::defaultDetSizeInX / pixBinW;
0608 
0609         for (int p = 0; p < NplaneMAX; p++) {
0610           if (isPlanePlotsTurnedOff[arm][stn][rp][p])
0611             continue;
0612           sprintf(s, "plane_%d", p);
0613           string pd = rpd + "/" + string(s);
0614           ibooker.setCurrentFolder(pd);
0615           string st1 = ": " + rpTitle + "_" + string(s);
0616 
0617           st = "adc average value";
0618           hp2xyADC[indexP][p] = ibooker.bookProfile2D(st,
0619                                                       st1 + ";pix col;pix row",
0620                                                       nbins,
0621                                                       0,
0622                                                       rpixValues::defaultDetSizeInX,
0623                                                       nbins,
0624                                                       0,
0625                                                       rpixValues::defaultDetSizeInX,
0626                                                       0.,
0627                                                       512.,
0628                                                       "");
0629           hp2xyADC[indexP][p]->getTProfile2D()->SetOption("colz");
0630 
0631           if (onlinePlots) {
0632             st = "hits position";
0633             h2xyHits[indexP][p] = ibooker.book2DD(st,
0634                                                   st1 + ";pix col;pix row",
0635                                                   rpixValues::defaultDetSizeInX,
0636                                                   0,
0637                                                   rpixValues::defaultDetSizeInX,
0638                                                   rpixValues::defaultDetSizeInX,
0639                                                   0,
0640                                                   rpixValues::defaultDetSizeInX);
0641             h2xyHits[indexP][p]->getTH2D()->SetOption("colz");
0642 
0643             st = "hits multiplicity";
0644             hHitsMult[indexP][p] =
0645                 ibooker.book1DD(st, st1 + ";number of hits;N / 1 hit", hitMultMAX + 1, -0.5, hitMultMAX + 0.5);
0646           }
0647 
0648           if (offlinePlots) {
0649             st = "plane efficiency";
0650             h2Efficiency[indexP][p] = ibooker.bookProfile2D(st,
0651                                                             st1 + ";x0;y0",
0652                                                             int(x0Maximum - x0Minimum) * xBins_per_mm,
0653                                                             x0Minimum,
0654                                                             x0Maximum,
0655                                                             int(y0Maximum - y0Minimum) * yBins_per_mm,
0656                                                             y0Minimum,
0657                                                             y0Maximum,
0658                                                             0,
0659                                                             1,
0660                                                             "");
0661             h2Efficiency[indexP][p]->getTProfile2D()->SetOption("colz");
0662           }
0663         }  // end of for(int p=0; p<NplaneMAX;..
0664 
0665       }  // end for(int rp=0; rp<NRPotsMAX;...
0666     }  // end of for(int stn=0; stn<
0667   }  // end of for(int arm=0; arm<2;...
0668 
0669   return;
0670 }
0671 
0672 //-------------------------------------------------------------------------------
0673 
0674 void CTPPSPixelDQMSource::analyze(edm::Event const &event, edm::EventSetup const &eventSetup) {
0675   ++nEvents;
0676   int lumiId = event.getLuminosityBlock().id().luminosityBlock();
0677   if (lumiId < 0)
0678     lumiId = 0;
0679 
0680   int RPactivity[RPotsTotalNumber], RPdigiSize[RPotsTotalNumber];
0681   int pixRPTracks[RPotsTotalNumber];
0682 
0683   for (int rp = 0; rp < RPotsTotalNumber; rp++) {
0684     RPactivity[rp] = RPdigiSize[rp] = pixRPTracks[rp] = 0;
0685   }
0686 
0687   for (int ind = 0; ind < RPotsTotalNumber; ind++) {
0688     for (int p = 0; p < NplaneMAX; p++) {
0689       HitsMultPlane[ind][p] = 0;
0690     }
0691   }
0692   for (int ind = 0; ind < RPotsTotalNumber * NplaneMAX; ind++) {
0693     for (int roc = 0; roc < NROCsMAX; roc++) {
0694       HitsMultROC[ind][roc] = 0;
0695     }
0696   }
0697   Handle<DetSetVector<CTPPSPixelDigi>> pixDigi;
0698   event.getByToken(tokenDigi, pixDigi);
0699 
0700   Handle<DetSetVector<CTPPSPixelDataError>> pixError;
0701   event.getByToken(tokenError, pixError);
0702 
0703   Handle<DetSetVector<CTPPSPixelCluster>> pixClus;
0704   event.getByToken(tokenCluster, pixClus);
0705 
0706   Handle<DetSetVector<CTPPSPixelLocalTrack>> pixTrack;
0707   event.getByToken(tokenTrack, pixTrack);
0708 
0709   Handle<edm::TriggerResults> hltResults;
0710   event.getByToken(tokenTrigResults, hltResults);
0711 
0712   const CTPPSPixelDAQMapping *mapping = &eventSetup.getData(tokenPixelDAQMapping);
0713 
0714   if (onlinePlots) {
0715     hBX->Fill(event.bunchCrossing());
0716     hBXshort->Fill(event.bunchCrossing());
0717   }
0718 
0719   if (pixTrack.isValid()) {
0720     for (const auto &ds_tr : *pixTrack) {
0721       int idet = getDet(ds_tr.id);
0722       if (idet != DetId::VeryForward) {
0723         if (verbosity > 1)
0724           LogPrint("CTPPSPixelDQMSource") << "not CTPPS: ds_tr.id" << ds_tr.id;
0725         continue;
0726       }
0727       CTPPSDetId theId(ds_tr.id);
0728       int arm = theId.arm() & 0x1;
0729       int station = theId.station() & 0x3;
0730       int rpot = theId.rp() & 0x7;
0731       int rpInd = getRPindex(arm, station, rpot);
0732 
0733       for (DetSet<CTPPSPixelLocalTrack>::const_iterator dit = ds_tr.begin(); dit != ds_tr.end(); ++dit) {
0734         ++pixRPTracks[rpInd];
0735         int nh_tr = (dit->ndf() + TrackFitDimension) / 2;
0736         if (onlinePlots) {
0737           for (int i = 0; i <= NplaneMAX; i++) {
0738             if (i == nh_tr)
0739               htrackHits[rpInd]->Fill(nh_tr, 1.);
0740             else
0741               htrackHits[rpInd]->Fill(i, 0.);
0742           }
0743         }
0744         float x0 = dit->x0();
0745         float y0 = dit->y0();
0746         h2trackXY0[rpInd]->Fill(x0, y0);
0747 
0748         if (x0_MAX < x0)
0749           x0_MAX = x0;
0750         if (y0_MAX < y0)
0751           y0_MAX = y0;
0752         if (x0_MIN > x0)
0753           x0_MIN = x0;
0754         if (y0_MIN > y0)
0755           y0_MIN = y0;
0756 
0757         if (offlinePlots) {
0758           edm::DetSetVector<CTPPSPixelFittedRecHit> fittedHits = dit->hits();
0759 
0760           std::map<int, int> numberOfPointPerPlaneEff;
0761           for (const auto &ds_frh : fittedHits) {
0762             int plane = getPixPlane(ds_frh.id);
0763             for (DetSet<CTPPSPixelFittedRecHit>::const_iterator frh_it = ds_frh.begin(); frh_it != ds_frh.end();
0764                  ++frh_it) {  // there should always be only one hit in each
0765                               // vector
0766               if (frh_it != ds_frh.begin())
0767                 if (verbosity > 1)
0768                   LogPrint("CTPPSPixelDQMSource") << "More than one FittedRecHit found in plane " << plane;
0769               if (frh_it->isRealHit())
0770                 for (int p = 0; p < NplaneMAX; p++) {
0771                   if (p != plane)
0772                     numberOfPointPerPlaneEff[p]++;
0773                 }
0774             }
0775           }
0776 
0777           if (verbosity > 1)
0778             for (auto planeAndHitsOnOthers : numberOfPointPerPlaneEff) {
0779               LogPrint("CTPPSPixelDQMSource")
0780                   << "For plane " << planeAndHitsOnOthers.first << ", " << planeAndHitsOnOthers.second
0781                   << " hits on other planes were found" << endl;
0782             }
0783 
0784           for (const auto &ds_frh : fittedHits) {
0785             int plane = getPixPlane(ds_frh.id);
0786             if (isPlanePlotsTurnedOff[arm][station][rpot][plane])
0787               continue;
0788             for (DetSet<CTPPSPixelFittedRecHit>::const_iterator frh_it = ds_frh.begin(); frh_it != ds_frh.end();
0789                  ++frh_it) {
0790               float frhX0 = frh_it->globalCoordinates().x() + frh_it->xResidual();
0791               float frhY0 = frh_it->globalCoordinates().y() + frh_it->yResidual();
0792               if (numberOfPointPerPlaneEff[plane] >= 3) {
0793                 if (frh_it->isRealHit())
0794                   h2Efficiency[rpInd][plane]->Fill(frhX0, frhY0, 1);
0795                 else
0796                   h2Efficiency[rpInd][plane]->Fill(frhX0, frhY0, 0);
0797               }
0798             }
0799           }
0800         }
0801       }
0802     }
0803   }  // end  if(pixTrack.isValid())
0804 
0805   bool valid = false;
0806   valid |= pixDigi.isValid();
0807   //  valid |= Clus.isValid();
0808 
0809   if (!valid && verbosity)
0810     LogPrint("CTPPSPixelDQMSource") << "No valid data in Event " << nEvents;
0811 
0812   if (pixDigi.isValid()) {
0813     for (const auto &ds_digi : *pixDigi) {
0814       int idet = getDet(ds_digi.id);
0815       if (idet != DetId::VeryForward) {
0816         if (verbosity > 1)
0817           LogPrint("CTPPSPixelDQMSource") << "not CTPPS: ds_digi.id" << ds_digi.id;
0818         continue;
0819       }
0820       //   int subdet = getSubdet(ds_digi.id);
0821 
0822       int plane = getPixPlane(ds_digi.id);
0823 
0824       CTPPSDetId theId(ds_digi.id);
0825       int arm = theId.arm() & 0x1;
0826       int station = theId.station() & 0x3;
0827       int rpot = theId.rp() & 0x7;
0828       int rpInd = getRPindex(arm, station, rpot);
0829       RPactivity[rpInd] = 1;
0830       ++RPdigiSize[rpInd];
0831 
0832       if (StationStatus[station] && RPstatus[station][rpot]) {
0833         if (onlinePlots) {
0834           h2HitsMultipl[arm][station]->Fill(prIndex(rpot, plane), ds_digi.data.size());
0835           h2AllPlanesActive->Fill(plane, getRPglobalBin(arm, station));
0836         }
0837         int index = getRPindex(arm, station, rpot);
0838         HitsMultPlane[index][plane] += ds_digi.data.size();
0839         if (RPindexValid[index]) {
0840           int nh = ds_digi.data.size();
0841           if (nh > hitMultMAX)
0842             nh = hitMultMAX;
0843           if (!isPlanePlotsTurnedOff[arm][station][rpot][plane])
0844             if (onlinePlots)
0845               hHitsMult[index][plane]->Fill(nh);
0846         }
0847         int rocHistIndex = getPlaneIndex(arm, station, rpot, plane);
0848 
0849         for (DetSet<CTPPSPixelDigi>::const_iterator dit = ds_digi.begin(); dit != ds_digi.end(); ++dit) {
0850           int row = dit->row();
0851           int col = dit->column();
0852           int adc = dit->adc();
0853 
0854           if (RPindexValid[index]) {
0855             if (!isPlanePlotsTurnedOff[arm][station][rpot][plane]) {
0856               if (onlinePlots)
0857                 h2xyHits[index][plane]->Fill(col, row);
0858               hp2xyADC[index][plane]->Fill(col, row, adc);
0859             }
0860             int colROC, rowROC;
0861             int trocId;
0862             if (!thePixIndices.transformToROC(col, row, trocId, colROC, rowROC)) {
0863               if (trocId >= 0 && trocId < NROCsMAX) {
0864                 ++HitsMultROC[rocHistIndex][trocId];
0865               }
0866             }
0867           }  // end if(RPindexValid[index]) {
0868         }
0869       }  // end  if(StationStatus[station]) {
0870     }  // end for(const auto &ds_digi : *pixDigi)
0871   }  // if(pixDigi.isValid()) {
0872 
0873   if (pixError.isValid()) {
0874     std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo> rocMapping = mapping->ROCMapping;
0875     for (const auto &ds_error : *pixError) {
0876       int idet = getDet(ds_error.id);
0877       if (idet != DetId::VeryForward) {
0878         if (idet == 15) {  //dummy det id: store in a plot with fed info
0879 
0880           for (DetSet<CTPPSPixelDataError>::const_iterator dit = ds_error.begin(); dit != ds_error.end(); ++dit) {
0881             // recover fed channel number
0882             int chanNmbr = -1;
0883             if (dit->errorType() == 32 || dit->errorType() == 33 || dit->errorType() == 34) {
0884               long long errorWord = dit->errorWord64();  // for 64-bit error words
0885               chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0886             } else {
0887               uint32_t errorWord = dit->errorWord32();
0888               chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0889             }
0890 
0891             // recover detector Id from chanNmbr and fedId
0892             CTPPSPixelFramePosition fPos(dit->fedId(), 0, chanNmbr, 0);  // frame position for ROC 0
0893             std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>::const_iterator mit;
0894             int index = -1;
0895             int plane = -1;
0896             bool goodRecovery = false;
0897             mit = rocMapping.find(fPos);
0898             if (mit != rocMapping.end()) {
0899               CTPPSPixelROCInfo rocInfo = (*mit).second;
0900               CTPPSPixelDetId recoveredDetId(rocInfo.iD);
0901               plane = recoveredDetId.plane();
0902               index = getRPindex(recoveredDetId.arm(), recoveredDetId.station(), recoveredDetId.rp());
0903               if (RPindexValid[index] && !isPlanePlotsTurnedOff[recoveredDetId.arm()][recoveredDetId.station()]
0904                                                                [recoveredDetId.rp()][recoveredDetId.plane()])
0905                 goodRecovery = true;
0906             }  // if (mit != rocMapping.end())
0907 
0908             if (goodRecovery) {
0909               h2ErrorCodeRP[index]->Fill(dit->errorType(), plane);
0910             } else {
0911               h2ErrorCodeUnidDet->Fill(dit->errorType(), dit->fedId());
0912             }
0913 
0914             bool fillFED = false;
0915             int iFed = dit->fedId() - minFedNumber;
0916             if (iFed >= 0 && iFed < numberOfFeds)
0917               fillFED = true;
0918 
0919             if (dit->errorType() == 28) {  //error 28 = FIFO nearly full: identify FIFO and fill histogram
0920               int fullType = -1;
0921               uint32_t errorWord = dit->errorWord32();
0922               int NFa = (errorWord >> DB0_shift) & DataBit_mask;
0923               int NFb = (errorWord >> DB1_shift) & DataBit_mask;
0924               int NFc = (errorWord >> DB2_shift) & DataBit_mask;
0925               int NFd = (errorWord >> DB3_shift) & DataBit_mask;
0926               int NFe = (errorWord >> DB4_shift) & DataBit_mask;
0927               int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
0928               int L1A = (errorWord >> DB7_shift) & DataBit_mask;
0929               if (NFa == 1) {
0930                 fullType = 1;
0931                 h2FullType->Fill((int)fullType, dit->fedId());
0932               }
0933               if (NFb == 1) {
0934                 fullType = 2;
0935                 h2FullType->Fill((int)fullType, dit->fedId());
0936               }
0937               if (NFc == 1) {
0938                 fullType = 3;
0939                 h2FullType->Fill((int)fullType, dit->fedId());
0940               }
0941               if (NFd == 1) {
0942                 fullType = 4;
0943                 h2FullType->Fill((int)fullType, dit->fedId());
0944               }
0945               if (NFe == 1) {
0946                 fullType = 5;
0947                 h2FullType->Fill((int)fullType, dit->fedId());
0948               }
0949               if (NF2 == 1) {
0950                 fullType = 6;
0951                 h2FullType->Fill((int)fullType, dit->fedId());
0952               }
0953               if (L1A == 1) {
0954                 fullType = 7;
0955                 h2FullType->Fill((int)fullType, dit->fedId());
0956               }
0957             }
0958             if (dit->errorType() == 30) {  //error 30 = TBM error trailer
0959               uint32_t errorWord = dit->errorWord32();
0960               int t0 = (errorWord >> DB0_shift) & DataBit_mask;
0961               int t1 = (errorWord >> DB1_shift) & DataBit_mask;
0962               int t2 = (errorWord >> DB2_shift) & DataBit_mask;
0963               int t3 = (errorWord >> DB3_shift) & DataBit_mask;
0964               int t4 = (errorWord >> DB4_shift) & DataBit_mask;
0965               int t5 = (errorWord >> DB5_shift) & DataBit_mask;
0966               int t6 = (errorWord >> DB6_shift) & DataBit_mask;
0967               int t7 = (errorWord >> DB7_shift) & DataBit_mask;
0968               if (t0 == 1) {
0969                 if (goodRecovery) {
0970                   h2TBMMessageRP[index]->Fill(0, plane);
0971                 } else {
0972                   h2TBMMessageUnidDet->Fill(0, dit->fedId());
0973                 }
0974                 if (fillFED)
0975                   h2TBMMessageFED[iFed]->Fill(0, chanNmbr);
0976               }
0977               if (t1 == 1) {
0978                 if (goodRecovery) {
0979                   h2TBMMessageRP[index]->Fill(1, plane);
0980                 } else {
0981                   h2TBMMessageUnidDet->Fill(1, dit->fedId());
0982                 }
0983                 if (fillFED)
0984                   h2TBMMessageFED[iFed]->Fill(1, chanNmbr);
0985               }
0986               if (t2 == 1) {
0987                 if (goodRecovery) {
0988                   h2TBMMessageRP[index]->Fill(2, plane);
0989                 } else {
0990                   h2TBMMessageUnidDet->Fill(2, dit->fedId());
0991                 }
0992                 if (fillFED)
0993                   h2TBMMessageFED[iFed]->Fill(2, chanNmbr);
0994               }
0995               if (t3 == 1) {
0996                 if (goodRecovery) {
0997                   h2TBMMessageRP[index]->Fill(3, plane);
0998                 } else {
0999                   h2TBMMessageUnidDet->Fill(3, dit->fedId());
1000                 }
1001                 if (fillFED)
1002                   h2TBMMessageFED[iFed]->Fill(3, chanNmbr);
1003               }
1004               if (t4 == 1) {
1005                 if (goodRecovery) {
1006                   h2TBMMessageRP[index]->Fill(4, plane);
1007                 } else {
1008                   h2TBMMessageUnidDet->Fill(4, dit->fedId());
1009                 }
1010                 if (fillFED)
1011                   h2TBMMessageFED[iFed]->Fill(4, chanNmbr);
1012               }
1013               if (t5 == 1) {
1014                 if (goodRecovery) {
1015                   h2TBMMessageRP[index]->Fill(5, plane);
1016                 } else {
1017                   h2TBMMessageUnidDet->Fill(5, dit->fedId());
1018                 }
1019                 if (fillFED)
1020                   h2TBMMessageFED[iFed]->Fill(5, chanNmbr);
1021               }
1022               if (t6 == 1) {
1023                 if (goodRecovery) {
1024                   h2TBMMessageRP[index]->Fill(6, plane);
1025                 } else {
1026                   h2TBMMessageUnidDet->Fill(6, dit->fedId());
1027                 }
1028                 if (fillFED)
1029                   h2TBMMessageFED[iFed]->Fill(6, chanNmbr);
1030               }
1031               if (t7 == 1) {
1032                 if (goodRecovery) {
1033                   h2TBMMessageRP[index]->Fill(7, plane);
1034                 } else {
1035                   h2TBMMessageUnidDet->Fill(7, dit->fedId());
1036                 }
1037                 if (fillFED)
1038                   h2TBMMessageFED[iFed]->Fill(7, chanNmbr);
1039               }
1040               int stateMach_bits = 4;
1041               int stateMach_shift = 8;
1042               uint32_t stateMach_mask = ~(~uint32_t(0) << stateMach_bits);
1043               uint32_t stateMach = (errorWord >> stateMach_shift) & stateMach_mask;
1044               if (stateMach == 0) {
1045                 if (goodRecovery) {
1046                   h2TBMTypeRP[index]->Fill(0, plane);
1047                 } else {
1048                   h2TBMTypeUnidDet->Fill(0, dit->fedId());
1049                 }
1050                 if (fillFED)
1051                   h2TBMTypeFED[iFed]->Fill(0, chanNmbr);
1052               } else {
1053                 if (((stateMach >> DB0_shift) & DataBit_mask) == 1) {
1054                   if (goodRecovery) {
1055                     h2TBMTypeRP[index]->Fill(1, plane);
1056                   } else {
1057                     h2TBMTypeUnidDet->Fill(1, dit->fedId());
1058                   }
1059                   if (fillFED)
1060                     h2TBMTypeFED[iFed]->Fill(1, chanNmbr);
1061                 }
1062                 if (((stateMach >> DB1_shift) & DataBit_mask) == 1) {
1063                   if (goodRecovery) {
1064                     h2TBMTypeRP[index]->Fill(2, plane);
1065                   } else {
1066                     h2TBMTypeUnidDet->Fill(2, dit->fedId());
1067                   }
1068                   if (fillFED)
1069                     h2TBMTypeFED[iFed]->Fill(2, chanNmbr);
1070                 }
1071                 if (((stateMach >> DB2_shift) & DataBit_mask) == 1) {
1072                   if (goodRecovery) {
1073                     h2TBMTypeRP[index]->Fill(3, plane);
1074                   } else {
1075                     h2TBMTypeUnidDet->Fill(3, dit->fedId());
1076                   }
1077                   if (fillFED)
1078                     h2TBMTypeFED[iFed]->Fill(3, chanNmbr);
1079                 }
1080                 if (((stateMach >> DB3_shift) & DataBit_mask) == 1) {
1081                   if (goodRecovery) {
1082                     h2TBMTypeRP[index]->Fill(4, plane);
1083                   } else {
1084                     h2TBMTypeUnidDet->Fill(4, dit->fedId());
1085                   }
1086                   if (fillFED)
1087                     h2TBMTypeFED[iFed]->Fill(4, chanNmbr);
1088                 }
1089               }
1090             }
1091             if (fillFED)
1092               h2ErrorCodeFED[iFed]->Fill(dit->errorType(), chanNmbr);
1093           }
1094           continue;
1095         }  // if idet == 15
1096         if (verbosity > 1)
1097           LogPrint("CTPPSPixelDQMSource") << "not CTPPS: ds_error.id" << ds_error.id;
1098         continue;
1099       }  // end of dummy detId block
1100 
1101       int plane = getPixPlane(ds_error.id);
1102       CTPPSDetId theId(ds_error.id);
1103       int arm = theId.arm() & 0x1;
1104       int station = theId.station() & 0x3;
1105       int rpot = theId.rp() & 0x7;
1106       int rpInd = getRPindex(arm, station, rpot);
1107       RPactivity[rpInd] = 1;
1108       CTPPSPixelDetId IDD(ds_error.id);
1109 
1110       if (StationStatus[station] && RPstatus[station][rpot]) {
1111         int index = getRPindex(arm, station, rpot);
1112         for (DetSet<CTPPSPixelDataError>::const_iterator dit = ds_error.begin(); dit != ds_error.end(); ++dit) {
1113           if (RPindexValid[index]) {
1114             if (!isPlanePlotsTurnedOff[arm][station][rpot][plane]) {
1115               h2ErrorCodeRP[index]->Fill(dit->errorType(), plane);
1116               // recover fed channel number
1117               int chanNmbr = -1;
1118               if (dit->errorType() == 32 || dit->errorType() == 33 || dit->errorType() == 34) {
1119                 long long errorWord = dit->errorWord64();  // for 64-bit error words
1120                 chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
1121               } else {
1122                 uint32_t errorWord = dit->errorWord32();
1123                 chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
1124               }
1125               bool fillFED = false;
1126               int iFed = dit->fedId() - minFedNumber;
1127               if (iFed >= 0 && iFed < numberOfFeds)
1128                 fillFED = true;
1129               if (dit->errorType() == 28) {  //error 28 = FIFO nearly full: identify FIFO and fill histogram
1130                 int fullType = -1;
1131                 uint32_t errorWord = dit->errorWord32();
1132                 int NFa = (errorWord >> DB0_shift) & DataBit_mask;
1133                 int NFb = (errorWord >> DB1_shift) & DataBit_mask;
1134                 int NFc = (errorWord >> DB2_shift) & DataBit_mask;
1135                 int NFd = (errorWord >> DB3_shift) & DataBit_mask;
1136                 int NFe = (errorWord >> DB4_shift) & DataBit_mask;
1137                 int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
1138                 int L1A = (errorWord >> DB7_shift) & DataBit_mask;
1139                 if (NFa == 1) {
1140                   fullType = 1;
1141                   h2FullType->Fill((int)fullType, dit->fedId());
1142                 }
1143                 if (NFb == 1) {
1144                   fullType = 2;
1145                   h2FullType->Fill((int)fullType, dit->fedId());
1146                 }
1147                 if (NFc == 1) {
1148                   fullType = 3;
1149                   h2FullType->Fill((int)fullType, dit->fedId());
1150                 }
1151                 if (NFd == 1) {
1152                   fullType = 4;
1153                   h2FullType->Fill((int)fullType, dit->fedId());
1154                 }
1155                 if (NFe == 1) {
1156                   fullType = 5;
1157                   h2FullType->Fill((int)fullType, dit->fedId());
1158                 }
1159                 if (NF2 == 1) {
1160                   fullType = 6;
1161                   h2FullType->Fill((int)fullType, dit->fedId());
1162                 }
1163                 if (L1A == 1) {
1164                   fullType = 7;
1165                   h2FullType->Fill((int)fullType, dit->fedId());
1166                 }
1167               }
1168 
1169               if (dit->errorType() == 30) {  //error 30 = TBM error trailer
1170                 uint32_t errorWord = dit->errorWord32();
1171                 int t0 = (errorWord >> DB0_shift) & DataBit_mask;
1172                 int t1 = (errorWord >> DB1_shift) & DataBit_mask;
1173                 int t2 = (errorWord >> DB2_shift) & DataBit_mask;
1174                 int t3 = (errorWord >> DB3_shift) & DataBit_mask;
1175                 int t4 = (errorWord >> DB4_shift) & DataBit_mask;
1176                 int t5 = (errorWord >> DB5_shift) & DataBit_mask;
1177                 int t6 = (errorWord >> DB6_shift) & DataBit_mask;
1178                 int t7 = (errorWord >> DB7_shift) & DataBit_mask;
1179                 if (t0 == 1) {
1180                   h2TBMMessageRP[index]->Fill(0, plane);
1181                   if (fillFED)
1182                     h2TBMMessageFED[iFed]->Fill(0, chanNmbr);
1183                 }
1184                 if (t1 == 1) {
1185                   h2TBMMessageRP[index]->Fill(1, plane);
1186                   if (fillFED)
1187                     h2TBMMessageFED[iFed]->Fill(1, chanNmbr);
1188                 }
1189                 if (t2 == 1) {
1190                   h2TBMMessageRP[index]->Fill(2, plane);
1191                   if (fillFED)
1192                     h2TBMMessageFED[iFed]->Fill(2, chanNmbr);
1193                 }
1194                 if (t3 == 1) {
1195                   h2TBMMessageRP[index]->Fill(3, plane);
1196                   if (fillFED)
1197                     h2TBMMessageFED[iFed]->Fill(3, chanNmbr);
1198                 }
1199                 if (t4 == 1) {
1200                   h2TBMMessageRP[index]->Fill(4, plane);
1201                   if (fillFED)
1202                     h2TBMMessageFED[iFed]->Fill(4, chanNmbr);
1203                 }
1204                 if (t5 == 1) {
1205                   h2TBMMessageRP[index]->Fill(5, plane);
1206                   if (fillFED)
1207                     h2TBMMessageFED[iFed]->Fill(5, chanNmbr);
1208                 }
1209                 if (t6 == 1) {
1210                   h2TBMMessageRP[index]->Fill(6, plane);
1211                   if (fillFED)
1212                     h2TBMMessageFED[iFed]->Fill(6, chanNmbr);
1213                 }
1214                 if (t7 == 1) {
1215                   h2TBMMessageRP[index]->Fill(7, plane);
1216                   if (fillFED)
1217                     h2TBMMessageFED[iFed]->Fill(7, chanNmbr);
1218                 }
1219                 int stateMach_bits = 4;
1220                 int stateMach_shift = 8;
1221                 uint32_t stateMach_mask = ~(~uint32_t(0) << stateMach_bits);
1222                 uint32_t stateMach = (errorWord >> stateMach_shift) & stateMach_mask;
1223                 if (stateMach == 0) {
1224                   h2TBMTypeRP[index]->Fill(0, plane);
1225                   if (fillFED)
1226                     h2TBMTypeFED[iFed]->Fill(0, chanNmbr);
1227                 } else {
1228                   if (((stateMach >> DB0_shift) & DataBit_mask) == 1) {
1229                     h2TBMTypeRP[index]->Fill(1, plane);
1230                     if (fillFED)
1231                       h2TBMTypeFED[iFed]->Fill(1, chanNmbr);
1232                   }
1233                   if (((stateMach >> DB1_shift) & DataBit_mask) == 1) {
1234                     h2TBMTypeRP[index]->Fill(2, plane);
1235                     if (fillFED)
1236                       h2TBMTypeFED[iFed]->Fill(2, chanNmbr);
1237                   }
1238                   if (((stateMach >> DB2_shift) & DataBit_mask) == 1) {
1239                     h2TBMTypeRP[index]->Fill(3, plane);
1240                     if (fillFED)
1241                       h2TBMTypeFED[iFed]->Fill(3, chanNmbr);
1242                   }
1243                   if (((stateMach >> DB3_shift) & DataBit_mask) == 1) {
1244                     h2TBMTypeRP[index]->Fill(4, plane);
1245                     if (fillFED)
1246                       h2TBMTypeFED[iFed]->Fill(4, chanNmbr);
1247                   }
1248                 }
1249               }
1250               if (fillFED)
1251                 h2ErrorCodeFED[iFed]->Fill(dit->errorType(), chanNmbr);
1252             }
1253           }  // end if(RPindexValid[index]) {
1254         }
1255       }  // end  if(StationStatus[station]) {
1256     }  // end for(const auto &ds_error : *pixDigi)
1257   }  // if(pixError.isValid())
1258 
1259   if (pixClus.isValid() && onlinePlots)
1260     for (const auto &ds : *pixClus) {
1261       int idet = getDet(ds.id);
1262       if (idet != DetId::VeryForward && verbosity > 1) {
1263         LogPrint("CTPPSPixelDQMSource") << "not CTPPS: cluster.id" << ds.id;
1264         continue;
1265       }
1266 
1267       CTPPSDetId theId(ds.id);
1268       int plane = getPixPlane(ds.id);
1269       int arm = theId.arm() & 0x1;
1270       int station = theId.station() & 0x3;
1271       int rpot = theId.rp() & 0x7;
1272 
1273       if ((StationStatus[station] == 0) || (RPstatus[station][rpot] == 0))
1274         continue;
1275 
1276       for (const auto &p : ds) {
1277         int clusize = p.size();
1278 
1279         if (clusize > ClusterSizeMax)
1280           clusize = ClusterSizeMax;
1281 
1282         h2CluSize[arm][station]->Fill(prIndex(rpot, plane), clusize);
1283       }
1284     }  // end if(pixClus.isValid()) for(const auto &ds : *pixClus)
1285 
1286   bool allRPactivity = false;
1287   for (int rp = 0; rp < RPotsTotalNumber; rp++)
1288     if (RPactivity[rp] > 0)
1289       allRPactivity = true;
1290   for (int arm = 0; arm < 2; arm++) {
1291     for (int stn = 0; stn < NStationMAX; stn++) {
1292       for (int rp = 0; rp < NRPotsMAX; rp++) {
1293         int index = getRPindex(arm, stn, rp);
1294         if (RPindexValid[index] == 0)
1295           continue;
1296 
1297         if (onlinePlots)
1298           hpRPactive->Fill(getRPglobalBin(arm, stn), RPactivity[index]);
1299         //        if(RPactivity[index]==0) continue;
1300         if (!allRPactivity)
1301           continue;
1302         if (onlinePlots)
1303           hpixLTrack->Fill(getRPglobalBin(arm, stn), pixRPTracks[index]);
1304         int ntr = pixRPTracks[index];
1305         if (ntr > NLocalTracksMAX)
1306           ntr = NLocalTracksMAX;
1307         for (int i = 0; i <= NLocalTracksMAX; i++) {
1308           if (i == ntr)
1309             htrackMult[index]->Fill(ntr, 1.);
1310           else
1311             htrackMult[index]->Fill(i, 0.);
1312         }
1313 
1314         int np = 0;
1315         for (int p = 0; p < NplaneMAX; p++)
1316           if (HitsMultPlane[index][p] > 0)
1317             np++;
1318         for (int p = 0; p <= NplaneMAX; p++) {
1319           if (p == np)
1320             hRPotActivPlanes[index]->Fill(p, 1.);
1321           else
1322             hRPotActivPlanes[index]->Fill(p, 0.);
1323         }
1324         if (onlinePlots) {
1325           if (np >= 5)
1326             hRPotActivBX[index]->Fill(event.bunchCrossing());
1327           hRPotActivBXall[index]->Fill(event.bunchCrossing(), float(RPdigiSize[index]));
1328         }
1329 
1330         // Select only events from the desired random trigger and fill the histogram
1331         const edm::TriggerNames &trigNames = event.triggerNames(*hltResults);
1332         for (int p = 0; p < NplaneMAX; p++) {
1333           for (unsigned int i = 0; i < trigNames.size(); i++) {
1334             const std::string &triggerName = trigNames.triggerName(i);
1335             if ((hltResults->accept(i) > 0) && (triggerName == randomHLTPath))
1336               h2HitsVsBXRandoms[index]->Fill(event.bunchCrossing(), p, HitsMultPlane[index][p]);
1337           }
1338         }
1339 
1340         int planesFiredAtROC[NROCsMAX];  // how many planes registered hits on ROC r
1341         for (int r = 0; r < NROCsMAX; r++)
1342           planesFiredAtROC[r] = 0;
1343         for (int p = 0; p < NplaneMAX; p++) {
1344           int indp = getPlaneIndex(arm, stn, rp, p);
1345           for (int r = 0; r < NROCsMAX; r++)
1346             if (HitsMultROC[indp][r] > 0)
1347               ++planesFiredAtROC[r];
1348           for (int r = 0; r < NROCsMAX; r++) {
1349             if (onlinePlots)
1350               h2HitsMultROC[index]->Fill(p, r, HitsMultROC[indp][r]);
1351             hp2HitsMultROC_LS[index]->Fill(lumiId, p * NROCsMAX + r, HitsMultROC[indp][r]);
1352           }
1353         }
1354         int max = 0;
1355         for (int r = 0; r < NROCsMAX; r++)
1356           if (max < planesFiredAtROC[r])
1357             max = planesFiredAtROC[r];
1358         if (max >= 4 && onlinePlots)  // fill only if there are at least 4 aligned ROCs firing
1359           hRPotActivBXroc[index]->Fill(event.bunchCrossing());
1360         if (max >= 3 && onlinePlots)  // fill only if there are at least 3 aligned ROCs firing
1361           hRPotActivBXroc_3[index]->Fill(event.bunchCrossing());
1362         if (max >= 2 && onlinePlots)  // fill only if there are at least 2 aligned ROCs firing
1363           hRPotActivBXroc_2[index]->Fill(event.bunchCrossing());
1364       }  // end for(int rp=0; rp<NRPotsMAX; rp++) {
1365     }
1366   }  // end for(int arm=0; arm<2; arm++) {
1367 
1368   if ((nEvents % 100))
1369     return;
1370   if (verbosity)
1371     LogPrint("CTPPSPixelDQMSource") << "analyze event " << nEvents;
1372 }
1373 
1374 //---------------------------------------------------------------------------
1375 DEFINE_FWK_MODULE(CTPPSPixelDQMSource);