Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-05 05:16:34

0001 // -*- C++ -*-
0002 //
0003 // Package:    EcalCorrelatedNoiseAnalysisModules
0004 // Class:      EcnaAnalyzer
0005 // // class EcnaAnalyzer
0006 // EcnaAnalyzer.cc
0007 // CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/src/EcnaAnalyzer.cc
0008 
0009 // Description: <one line class summary>
0010 
0011 // Implementation:
0012 //     <Notes on implementation>
0013 
0014 //
0015 // Original Author:  Bernard Fabbro
0016 //         Created:  Fri Jun  2 10:27:01 CEST 2006
0017 // $Id: EcnaAnalyzer.cc,v 1.4 2013/04/05 20:17:20 wmtan Exp $
0018 //
0019 //          Update: 21/07/2011
0020 
0021 // CMSSW include files
0022 
0023 //#include <signal.h>
0024 
0025 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/interface/EcnaAnalyzer.h"
0026 #include "FWCore/Utilities/interface/Exception.h"
0027 
0028 //--------------------------------------
0029 //  EcnaAnalyzer.cc
0030 //  Class creation: 02 June 2006
0031 //  Documentation: see EcnaAnalyzer.h
0032 //--------------------------------------
0033 //
0034 // constants, enums and typedefs
0035 //
0036 
0037 //
0038 // static data member definitions
0039 //
0040 
0041 //
0042 // Constructor and destructor
0043 //
0044 EcnaAnalyzer::EcnaAnalyzer(const edm::ParameterSet &pSet)
0045     : verbosity_(pSet.getUntrackedParameter("verbosity", 1U)),
0046       nChannels_(0),
0047       iEvent_(0),
0048       fBuildEventDistribBad(nullptr),
0049       fBuildEventDistribGood(nullptr),
0050       fSMFromFedTcc(nullptr),
0051       fESFromFedTcc(nullptr),
0052       fDeeFromFedTcc(nullptr),
0053       fFedStatusOrder(nullptr),
0054       fDeeNumberString(nullptr),
0055       fStexDigiOK(nullptr),
0056       fStexNbOfTreatedEvents(nullptr),
0057       fStexStatus(nullptr),
0058       fFedStatus(nullptr),
0059       fFedDigiOK(nullptr),
0060       fFedNbOfTreatedEvents(nullptr),
0061       fNbOfTreatedFedsInDee(nullptr),
0062       fNbOfTreatedFedsInStex(nullptr),
0063       fTimeFirst(nullptr),
0064       fTimeLast(nullptr),
0065       fDateFirst(nullptr),
0066       fDateLast(nullptr),
0067       fMemoDateFirstEvent(nullptr),
0068       fMyCnaEBSM(nullptr),
0069       fMyCnaEEDee(nullptr),
0070       fMyEBNumbering(nullptr),
0071       fMyEBEcal(nullptr),
0072       fMyEENumbering(nullptr),
0073       fMyEEEcal(nullptr),
0074       fRunTypeCounter(nullptr),
0075       fMgpaGainCounter(nullptr),
0076       fFedIdCounter(nullptr),
0077       fCounterQuad(nullptr) {
0078   // now do what ever initialization is needed
0079 
0080   fMyEcnaEBObjectManager = new TEcnaObject();
0081   fMyEcnaEEObjectManager = new TEcnaObject();
0082 
0083   std::unique_ptr<TEcnaParPaths> myPathEB = std::make_unique<TEcnaParPaths>(fMyEcnaEBObjectManager);
0084   std::unique_ptr<TEcnaParPaths> myPathEE = std::make_unique<TEcnaParPaths>(fMyEcnaEEObjectManager);
0085 
0086   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-constructor> Check path for resultsq Root files.";
0087 
0088   if (myPathEB->GetPathForResultsRootFiles() == kFALSE) {
0089     edm::LogError("ecnaAnal") << "*EcnaAnalyzer-constructor> *** ERROR *** Path for result files not found.";
0090     throw cms::Exception("Calibration") << "*EcnaAnalyzer-constructor> *** ERROR *** Path for result files not found.";
0091   } else {
0092     edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-constructor> Path for result files found = "
0093                                  << myPathEB->ResultsRootFilePath();
0094   }
0095 
0096   if (myPathEE->GetPathForResultsRootFiles() == kFALSE) {
0097     edm::LogError("ecnaAnal") << "*EcnaAnalyzer-constructor> *** ERROR *** Path for result files not found.";
0098     throw cms::Exception("Calibration") << "*EcnaAnalyzer-constructor> *** ERROR *** Path for result files not found.";
0099   } else {
0100     edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-constructor> Path for result files found = "
0101                                  << myPathEE->ResultsRootFilePath();
0102   }
0103 
0104   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-constructor> Parameter initialization.";
0105 
0106   fgMaxCar = (Int_t)512;
0107   fTTBELL = '\007';
0108   fOutcomeError = kFALSE;
0109 
0110   fMyEBEcal = new TEcnaParEcal(fMyEcnaEBObjectManager, "EB");
0111   fMyEBNumbering = new TEcnaNumbering(fMyEcnaEBObjectManager, "EB");
0112 
0113   fMyEEEcal = new TEcnaParEcal(fMyEcnaEEObjectManager, "EE");
0114   fMyEENumbering = new TEcnaNumbering(fMyEcnaEEObjectManager, "EE");
0115 
0116   //==========================================================================================
0117   //.................................. Get parameter values from python file
0118   eventHeaderProducer_ = pSet.getParameter<std::string>("eventHeaderProducer");
0119   digiProducer_ = pSet.getParameter<std::string>("digiProducer");
0120 
0121   eventHeaderCollection_ = pSet.getParameter<std::string>("eventHeaderCollection");
0122   eventHeaderToken_ = consumes<EcalRawDataCollection>(edm::InputTag(digiProducer_, eventHeaderCollection_));
0123 
0124   EBdigiCollection_ = pSet.getParameter<std::string>("EBdigiCollection");
0125   EEdigiCollection_ = pSet.getParameter<std::string>("EEdigiCollection");
0126   EBdigiToken_ = consumes<EBDigiCollection>(edm::InputTag(digiProducer_, EBdigiCollection_));
0127   EEdigiToken_ = consumes<EEDigiCollection>(edm::InputTag(digiProducer_, EEdigiCollection_));
0128 
0129   sAnalysisName_ = pSet.getParameter<std::string>("sAnalysisName");
0130   sNbOfSamples_ = pSet.getParameter<std::string>("sNbOfSamples");
0131   sFirstReqEvent_ = pSet.getParameter<std::string>("sFirstReqEvent");
0132   sLastReqEvent_ = pSet.getParameter<std::string>("sLastReqEvent");
0133   sReqNbOfEvts_ = pSet.getParameter<std::string>("sReqNbOfEvts");
0134   sStexName_ = pSet.getParameter<std::string>("sStexName");
0135   sStexNumber_ = pSet.getParameter<std::string>("sStexNumber");
0136 
0137   fAnalysisName = sAnalysisName_.Data();
0138   fNbOfSamples = atoi(sNbOfSamples_.Data());
0139   fFirstReqEvent = atoi(sFirstReqEvent_.Data());
0140   fLastReqEvent = atoi(sLastReqEvent_.Data());
0141   fReqNbOfEvts = atoi(sReqNbOfEvts_.Data());
0142   fStexName = sStexName_.Data();
0143   fStexNumber = atoi(sStexNumber_.Data());
0144 
0145   //------------------------------- ERRORS in requested evts numbers
0146   if (fFirstReqEvent < 1) {
0147     fOutcomeError = AnalysisOutcome("ERR_FNEG");
0148   }
0149 
0150   if ((fLastReqEvent >= fFirstReqEvent) && (fReqNbOfEvts > fLastReqEvent - fFirstReqEvent + 1)) {
0151     fOutcomeError = AnalysisOutcome("ERR_LREQ");
0152   }
0153 
0154   if (fOutcomeError == kTRUE)
0155     return;
0156   //===========================================================================================
0157 
0158   fMaxRunTypeCounter = 26;
0159   fRunTypeCounter = new Int_t[fMaxRunTypeCounter];
0160   for (Int_t i = 0; i < fMaxRunTypeCounter; i++) {
0161     fRunTypeCounter[i] = 0;
0162   }
0163 
0164   fMaxMgpaGainCounter = 4;  // Because chozen gain = 0,1,2,3
0165   fMgpaGainCounter = new Int_t[fMaxMgpaGainCounter];
0166   for (Int_t i = 0; i < fMaxMgpaGainCounter; i++) {
0167     fMgpaGainCounter[i] = 0;
0168   }
0169 
0170   fMaxFedIdCounter = 54;
0171   fFedIdCounter = new Int_t[fMaxFedIdCounter];
0172   for (Int_t i = 0; i < fMaxFedIdCounter; i++) {
0173     fFedIdCounter[i] = 0;
0174   }
0175 
0176   fEvtNumber = 0;
0177   fEvtNumberMemo = -1;
0178   fRecNumber = 0;
0179 
0180   fDeeDS5Memo1 = 0;
0181   fDeeDS5Memo2 = 0;
0182 
0183   fCurrentEventNumber = 0;
0184   fNbOfSelectedEvents = 0;
0185 
0186   fMemoCutOK = 0;
0187   fTreatedFedOrder = 0;
0188   fNbOfTreatedStexs = 0;
0189 
0190   //-------------- Fed
0191   if (fStexName == "SM") {
0192     fMaxFedUnitCounter = fMyEBEcal->MaxSMInEB();
0193   }  // EB: FED Unit = SM
0194   if (fStexName == "Dee") {
0195     fMaxFedUnitCounter = fMyEEEcal->MaxDSInEE();
0196   }  // EE: FED Unit = Data Sector
0197 
0198   fFedDigiOK = new Int_t[fMaxFedUnitCounter];
0199   for (Int_t i = 0; i < fMaxFedUnitCounter; i++) {
0200     fFedDigiOK[i] = 0;
0201   }
0202 
0203   fFedNbOfTreatedEvents = new Int_t[fMaxFedUnitCounter];
0204   for (Int_t i = 0; i < fMaxFedUnitCounter; i++) {
0205     fFedNbOfTreatedEvents[i] = 0;
0206   }
0207 
0208   fFedStatus = new Int_t[fMaxFedUnitCounter];
0209   for (Int_t i = 0; i < fMaxFedUnitCounter; i++) {
0210     fFedStatus[i] = 0;
0211   }
0212 
0213   fFedStatusOrder = new Int_t[fMaxFedUnitCounter];
0214   for (Int_t i = 0; i < fMaxFedUnitCounter; i++) {
0215     fFedStatusOrder[i] = 0;
0216   }
0217 
0218   fDeeNumberString = new TString[fMaxFedUnitCounter];
0219   for (Int_t i = 0; i < fMaxFedUnitCounter; i++) {
0220     fDeeNumberString[i] = "SM";
0221   }
0222 
0223   if (fStexName == "Dee") {
0224     fDeeNumberString[0] = "Sector1 Dee4";
0225     fDeeNumberString[1] = "Sector2 Dee4";
0226     fDeeNumberString[2] = "Sector3 Dee4";
0227     fDeeNumberString[3] = "Sector4 Dee4";
0228     fDeeNumberString[4] = "Sector5 Dee4-Dee3";
0229     fDeeNumberString[5] = "Sector6 Dee3";
0230     fDeeNumberString[6] = "Sector7 Dee3";
0231     fDeeNumberString[7] = "Sector8 Dee3";
0232     fDeeNumberString[8] = "Sector9 Dee3";
0233     fDeeNumberString[9] = "Sector1 Dee1";
0234     fDeeNumberString[10] = "Sector2 Dee1";
0235     fDeeNumberString[11] = "Sector3 Dee1";
0236     fDeeNumberString[12] = "Sector4 Dee1";
0237     fDeeNumberString[13] = "Sector5 Dee1-Dee2";
0238     fDeeNumberString[14] = "Sector6 Dee2";
0239     fDeeNumberString[15] = "Sector7 Dee2";
0240     fDeeNumberString[16] = "Sector8 Dee2";
0241     fDeeNumberString[17] = "Sector9 Dee2";
0242   }
0243   //............................... arrays fSMFromFedDcc and fESFromFedTcc
0244   //
0245   //  FED-TCC:   1   2   3   4   5   6   7   8   9
0246   //      Dee:   3   3   3   4   4   4   4  4-3  3
0247   //       DS:   7   8   9   1   2   3   4   5   6
0248   //       ES:   7   8   9   1   2   3   4   5   6  (ES = DS)
0249   //
0250   //  FED-TCC:  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25
0251   //  26  27
0252   //       SM:  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34
0253   //       35  36 SM:  -1  -2  -3  -4  -5  -6  -7  -8  -9 -10 -11 -12 -13 -14
0254   //       -15 -16 -17 -18
0255   //
0256   //  FED-TCC:  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43
0257   //  44  45
0258   //       SM:   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16
0259   //       17  18
0260   //
0261   //  FED-TCC:  46  47  48  49  50  51  52  53  54
0262   //      Dee:   2   2   2   1   1   1   1  1-2  2
0263   //       DS:   7   8   9   1   2   3   4   5   6
0264   //       ES:  16  17  18  10  11  12  13  14  15  (ES = DS + 9)
0265 
0266   Int_t MaxSMAndDS = fMyEBEcal->MaxSMInEB() + fMyEEEcal->MaxDSInEE();
0267 
0268   fSMFromFedTcc = new Int_t[MaxSMAndDS];
0269   fESFromFedTcc = new Int_t[MaxSMAndDS];
0270   for (Int_t nFedTcc = 1; nFedTcc <= MaxSMAndDS; nFedTcc++) {
0271     fESFromFedTcc[nFedTcc - 1] = -1;
0272   }
0273 
0274   for (Int_t nFedTcc = 1; nFedTcc <= 3; nFedTcc++) {
0275     fESFromFedTcc[nFedTcc - 1] = nFedTcc + 6;
0276   }  // Dee3, ES 7,8,9
0277   for (Int_t nFedTcc = 4; nFedTcc <= 9; nFedTcc++) {
0278     fESFromFedTcc[nFedTcc - 1] = nFedTcc - 3;
0279   }  // Dee4, ES 1,2,3,4,5; Dee3, DS 5,6
0280 
0281   for (Int_t nFedTcc = 10; nFedTcc <= 27; nFedTcc++) {
0282     fSMFromFedTcc[nFedTcc - 1] = nFedTcc + 9;
0283   }  // EB-  SM 19 to 36
0284   for (Int_t nFedTcc = 28; nFedTcc <= 45; nFedTcc++) {
0285     fSMFromFedTcc[nFedTcc - 1] = nFedTcc - 27;
0286   }  // EB+  SM  1 to 18
0287 
0288   for (Int_t nFedTcc = 46; nFedTcc <= 48; nFedTcc++) {
0289     fESFromFedTcc[nFedTcc - 1] = nFedTcc - 30;
0290   }  // Dee2, ES 16,17,18
0291   for (Int_t nFedTcc = 49; nFedTcc <= 54; nFedTcc++) {
0292     fESFromFedTcc[nFedTcc - 1] = nFedTcc - 39;
0293   }  // Dee1, ES 10,11,12,13,14; Dee2, ES 14,15
0294 
0295   //............................... Nb of treated events for "AdcPeg12" and
0296   //"AdcSPeg12" analysis
0297   //-------------- Stex
0298   if (fStexName == "SM") {
0299     fMaxTreatedStexCounter = fMyEBEcal->MaxSMInEB();
0300   }  // EB: Stex = SM
0301   if (fStexName == "Dee") {
0302     fMaxTreatedStexCounter = fMyEEEcal->MaxDeeInEE();
0303   }  // EE: Stex = Dee
0304 
0305   fStexNbOfTreatedEvents = new Int_t[fMaxTreatedStexCounter];
0306   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0307     fStexNbOfTreatedEvents[i] = 0;
0308   }
0309 
0310   fTimeFirst = new time_t[fMaxTreatedStexCounter];
0311   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0312     fTimeFirst[i] = 0;
0313   }
0314   fTimeLast = new time_t[fMaxTreatedStexCounter];
0315   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0316     fTimeLast[i] = 0;
0317   }
0318 
0319   fMemoDateFirstEvent = new Int_t[fMaxTreatedStexCounter];
0320   ;
0321   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0322     fMemoDateFirstEvent[i] = 0;
0323   }
0324 
0325   Int_t MaxCar = fgMaxCar;
0326   fDateFirst = new TString[fMaxTreatedStexCounter];
0327   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0328     fDateFirst[i].Resize(MaxCar);
0329     fDateFirst[i] = "*1st event date not found*";
0330   }
0331 
0332   MaxCar = fgMaxCar;
0333   fDateLast = new TString[fMaxTreatedStexCounter];
0334   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0335     fDateLast[i].Resize(MaxCar);
0336     fDateLast[i] = "*last event date not found*";
0337   }
0338 
0339   fStexStatus = new Int_t[fMaxTreatedStexCounter];
0340   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0341     fStexStatus[i] = 0;
0342   }
0343 
0344   fStexDigiOK = new Int_t[fMaxTreatedStexCounter];
0345   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0346     fStexDigiOK[i] = 0;
0347   }
0348 
0349   fNbOfTreatedFedsInDee = new Int_t[fMaxTreatedStexCounter];
0350   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0351     fNbOfTreatedFedsInDee[i] = 0;
0352   }
0353 
0354   fNbOfTreatedFedsInStex = new Int_t[fMaxTreatedStexCounter];
0355   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0356     fNbOfTreatedFedsInStex[i] = 0;
0357   }
0358 
0359   //.......................... counters of events for GetSampleAdcValues
0360   fBuildEventDistribBad = new Int_t[fMaxTreatedStexCounter];
0361   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0362     fBuildEventDistribBad[i] = 0;
0363   }
0364 
0365   fBuildEventDistribGood = new Int_t[fMaxTreatedStexCounter];
0366   for (Int_t i = 0; i < fMaxTreatedStexCounter; i++) {
0367     fBuildEventDistribGood[i] = 0;
0368   }
0369 
0370   //----------------------------------- Analysis name codes
0371   //------------------------------------------
0372   //
0373   //                  AnalysisName  RunType         Gain    DBLS (Dynamic
0374   //                  BaseLine Substraction)
0375   //
0376   //                  AdcAny        any run type       0    no
0377   //
0378   //                  AdcPed1       fPEDESTAL_STD      3    No
0379   //                  AdcPed6       fPEDESTAL_STD      2    No
0380   //                  AdcPed12      fPEDESTAL_STD      1    No
0381   //
0382   //                  AdcPeg12      fPEDESTAL_GAP      1    No
0383   //
0384   //                  AdcLaser      fLASER_STD         0    No
0385   //                  AdcPes12      fPEDSIM            0    No
0386   //
0387   //                  AdcPhys       fPHYSICS_GLOBAL    0    No
0388   //
0389   //
0390   //                  AdcSPed1      fPEDESTAL_STD      3    Yes
0391   //                  AdcSPed6      fPEDESTAL_STD      2    Yes
0392   //                  AdcSPed12     fPEDESTAL_STD      1    Yes
0393   //
0394   //                  AdcSPeg12     fPEDESTAL_GAP      1    Yes
0395   //
0396   //                  AdcSLaser     fLASER_STD         0    Yes
0397   //                  AdcSPes12     fPEDSIM            0    Yes
0398   //
0399   //--------------------------------------------------------------------------------------------------
0400 
0401   //................ Run type list
0402 
0403   fLASER_STD = 4;
0404   fPEDESTAL_STD = 9;
0405   fPHYSICS_GLOBAL = 13;
0406   fPEDESTAL_GAP = 18;
0407   fPEDSIM = 24;
0408 
0409   fANY_RUN = 25;
0410 
0411   //................ Chozen run type from analysis name
0412   fChozenRunTypeNumber = fANY_RUN;  // default
0413   if (fAnalysisName == "AdcAny") {
0414     fChozenRunTypeNumber = fANY_RUN;
0415   }
0416   if (fAnalysisName == "AdcPed1" || fAnalysisName == "AdcPed6" || fAnalysisName == "AdcPed12" ||
0417       fAnalysisName == "AdcSPed1" || fAnalysisName == "AdcSPed6" || fAnalysisName == "AdcSPed12") {
0418     fChozenRunTypeNumber = fPEDESTAL_STD;
0419   }
0420   if (fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12") {
0421     fChozenRunTypeNumber = fPEDESTAL_GAP;
0422   }
0423   if (fAnalysisName == "AdcLaser" || fAnalysisName == "AdcSLaser") {
0424     fChozenRunTypeNumber = fLASER_STD;
0425   }
0426   if (fAnalysisName == "AdcPhys") {
0427     fChozenRunTypeNumber = fPHYSICS_GLOBAL;
0428   }
0429   if (fAnalysisName == "AdcPes12 " || fAnalysisName == "AdcSPes12 ") {
0430     fChozenRunTypeNumber = fPEDSIM;
0431   }
0432 
0433   //................ Gains from analysis name
0434   fChozenGainNumber = 0;  // default => event always accepted if fChozenGainNumber = 0 ( see
0435                           // USER's Analysis cut in ::analyze(...) )
0436   if (fAnalysisName == "AdcAny") {
0437     fChozenGainNumber = 0;
0438   }
0439   if (fAnalysisName == "AdcPed1" || fAnalysisName == "AdcSPed1") {
0440     fChozenGainNumber = 3;
0441   }
0442   if (fAnalysisName == "AdcPed6" || fAnalysisName == "AdcSPed6") {
0443     fChozenGainNumber = 2;
0444   }
0445   if (fAnalysisName == "AdcPed12" || fAnalysisName == "AdcSPed12") {
0446     fChozenGainNumber = 1;
0447   }
0448   if (fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12") {
0449     fChozenGainNumber = 0;
0450   }
0451   if (fAnalysisName == "AdcLaser" || fAnalysisName == "AdcSLaser") {
0452     fChozenGainNumber = 0;
0453   }
0454   if (fAnalysisName == "AdcPes12 " || fAnalysisName == "AdcSPes12 ") {
0455     fChozenGainNumber = 0;
0456   }
0457   if (fAnalysisName == "AdcPhys") {
0458     fChozenGainNumber = 0;
0459   }
0460 
0461   //............... Flag for Dynamic BaseLine Substraction from analysis name
0462   fDynBaseLineSub = "no";  // default
0463   if (fAnalysisName == "AdcAny" || fAnalysisName == "AdcPed1" || fAnalysisName == "AdcPed6" ||
0464       fAnalysisName == "AdcPed12" || fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcLaser" ||
0465       fAnalysisName == "AdcPhys" || fAnalysisName == "AdcPes12 ") {
0466     fDynBaseLineSub = "no";
0467   }
0468   if (fAnalysisName == "AdcSPed1" || fAnalysisName == "AdcSPed6" || fAnalysisName == "AdcSPed12" ||
0469       fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcSLaser" || fAnalysisName == "AdcSPes12 ") {
0470     fDynBaseLineSub = "yes";
0471   }
0472 
0473   //....................... Index range for ECNA init and for loop on
0474   // GetSampleAdcValues calls
0475   if (fStexNumber == 0) {
0476     if (fStexName == "SM") {
0477       fSMIndexBegin = 0;
0478       fSMIndexStop = fMyEBEcal->MaxSMInEB();
0479       fStexIndexBegin = fSMIndexBegin;
0480       fStexIndexStop = fSMIndexStop;
0481       fDeeIndexBegin = 0;
0482       fDeeIndexStop = 0;
0483     }
0484     if (fStexName == "Dee") {
0485       fSMIndexBegin = 0;
0486       fSMIndexStop = 0;
0487       fDeeIndexBegin = 0;
0488       fDeeIndexStop = fMyEEEcal->MaxDeeInEE();
0489       fStexIndexBegin = fDeeIndexBegin;
0490       fStexIndexStop = fDeeIndexStop;
0491     }
0492   } else {
0493     if (fStexName == "SM") {
0494       fSMIndexBegin = fStexNumber - 1;
0495       fSMIndexStop = fStexNumber;
0496       fStexIndexBegin = fSMIndexBegin;
0497       fStexIndexStop = fSMIndexStop;
0498       fDeeIndexBegin = 0;
0499       fDeeIndexStop = 0;
0500     }
0501     if (fStexName == "Dee") {
0502       fSMIndexBegin = 0;
0503       fSMIndexStop = 0;
0504       fDeeIndexBegin = fStexNumber - 1;
0505       fDeeIndexStop = fStexNumber;
0506       fStexIndexBegin = fDeeIndexBegin;
0507       fStexIndexStop = fDeeIndexStop;
0508     }
0509   }
0510 
0511   //......... DATA DEPENDENT PARAMETERS
0512   fRunNumber = 0;
0513 
0514   fMyCnaEBSM = nullptr;
0515   fMyCnaEEDee = nullptr;
0516 
0517   fRunTypeNumber = -1;
0518   fMgpaGainNumber = -1;
0519 
0520   fFedId = -1;
0521   fFedTcc = -1;
0522 
0523   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fAnalysisName        = " << fAnalysisName;
0524   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fNbOfSamples         = " << fNbOfSamples;
0525   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fFirstReqEvent       = " << fFirstReqEvent;
0526   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fLastReqEvent        = " << fLastReqEvent;
0527   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fReqNbOfEvts         = " << fReqNbOfEvts;
0528   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fStexName            = " << fStexName;
0529   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fStexNumber          = " << fStexNumber;
0530   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fChozenRunTypeNumber = "
0531                                << fChozenRunTypeNumber;
0532   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fChozenGainNumber    = "
0533                                << fChozenGainNumber << std::endl;
0534 
0535   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer::EcnaAnalyzer-constructor> Init done. ";
0536 }
0537 // end of constructor
0538 
0539 EcnaAnalyzer::~EcnaAnalyzer() {
0540   // do anything here that needs to be done at destruction time
0541   // (e.g. close files, deallocate resources etc.)
0542 
0543   //..................................... format numerical values
0544   edm::LogVerbatim("ecnaAnal") << "EcnaAnalyzer::~EcnaAnalyzer()> destructor is going to be executed." << std::endl;
0545 
0546   delete fMyEcnaEBObjectManager;
0547   delete fMyEcnaEEObjectManager;
0548 
0549   if (fOutcomeError == kTRUE)
0550     return;
0551 
0552   //-------------------------------------------------------------------------------
0553 
0554   //....................................................... EB (SM)
0555   if (fMyCnaEBSM == nullptr && fStexName == "SM") {
0556     edm::LogVerbatim("ecnaAnal") << "\n!EcnaAnalyzer-destructor> **** ERROR **** fMyCnaEBSM = " << fMyCnaEBSM
0557                                  << ". !===> ECNA HAS NOT BEEN INITIALIZED."
0558                                  << "\n  Last event run type = " << runtype(fRunTypeNumber)
0559                                  << ", fRunTypeNumber = " << fRunTypeNumber
0560                                  << ", last event Mgpa gain = " << gainvalue(fMgpaGainNumber)
0561                                  << ", fMgpaGainNumber = " << fMgpaGainNumber
0562                                  << ", last event fFedId(+601) = " << fFedId + 601 << std::endl;
0563   } else {
0564     for (Int_t iSM = fSMIndexBegin; iSM < fSMIndexStop; iSM++) {
0565       if (fMyCnaEBSM[iSM] != nullptr) {
0566         //........................................ register dates 1 and 2
0567         fMyCnaEBSM[iSM]->StartStopDate(fDateFirst[iSM], fDateLast[iSM]);
0568         fMyCnaEBSM[iSM]->StartStopTime(fTimeFirst[iSM], fTimeLast[iSM]);
0569 
0570         //........................................ Init .root file
0571         fMyCnaEBSM[iSM]->GetReadyToCompute();
0572         fMyCnaEBSM[iSM]->SampleValues();
0573 
0574         //........................................ write the sample values in
0575         //.root file
0576         if (fMyCnaEBSM[iSM]->WriteRootFile() == kFALSE) {
0577           edm::LogVerbatim("ecnaAnal") << "!EcnaAnalyzer-destructor> PROBLEM with write ROOT file for SM" << iSM + 1
0578                                        << fTTBELL;
0579         }
0580       } else {
0581         edm::LogVerbatim("ecnaAnal")
0582             << "*EcnaAnalyzer-destructor> Calculations and writing on file already done for SM " << iSM + 1;
0583       }
0584     }
0585     delete fMyCnaEBSM;
0586   }
0587   //....................................................... EE (Dee)
0588 
0589   if (fMyCnaEEDee == nullptr && fStexName == "Dee") {
0590     edm::LogVerbatim("ecnaAnal") << "\n!EcnaAnalyzer-destructor> **** ERROR **** fMyCnaEEDee = " << fMyCnaEEDee
0591                                  << ". !===> ECNA HAS NOT BEEN INITIALIZED."
0592                                  << "\n  Last event run type = " << runtype(fRunTypeNumber)
0593                                  << ", fRunTypeNumber = " << fRunTypeNumber
0594                                  << ", last event Mgpa gain = " << gainvalue(fMgpaGainNumber)
0595                                  << ", fMgpaGainNumber = " << fMgpaGainNumber
0596                                  << ", last event fFedId(+601) = " << fFedId + 601 << std::endl;
0597   } else {
0598     for (Int_t iDee = fDeeIndexBegin; iDee < fDeeIndexStop; iDee++) {
0599       if (fMyCnaEEDee[iDee] != nullptr) {
0600         //........................................ register dates 1 and 2
0601         fMyCnaEEDee[iDee]->StartStopDate(fDateFirst[iDee], fDateLast[iDee]);
0602         fMyCnaEEDee[iDee]->StartStopTime(fTimeFirst[iDee], fTimeLast[iDee]);
0603 
0604         //........................................ Init .root file
0605         fMyCnaEEDee[iDee]->GetReadyToCompute();
0606         fMyCnaEEDee[iDee]->SampleValues();
0607 
0608         //........................................ write the sample values in
0609         //.root file
0610         if (fMyCnaEEDee[iDee]->WriteRootFile() == kFALSE) {
0611           edm::LogVerbatim("ecnaAnal") << "!EcnaAnalyzer-destructor> PROBLEM with write ROOT file for Dee" << iDee + 1
0612                                        << " " << fTTBELL;
0613         }
0614       } else {
0615         edm::LogVerbatim("ecnaAnal")
0616             << "*EcnaAnalyzer-destructor> Calculations and writing on file already done for Dee " << iDee + 1;
0617       }
0618     }
0619     delete fMyCnaEEDee;
0620   }
0621   edm::LogVerbatim("ecnaAnal") << std::endl;
0622 
0623   //-----------------------------------------------------------------------------------
0624 
0625   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-destructor> Status of events returned by GetSampleAdcValues(): ";
0626 
0627   for (Int_t i0Stex = fStexIndexBegin; i0Stex < fStexIndexStop; i0Stex++) {
0628     edm::LogVerbatim("ecnaAnal") << fStexName << i0Stex + 1 << "> Status OK: " << fBuildEventDistribGood[i0Stex]
0629                                  << " / ERROR(S): " << fBuildEventDistribBad[i0Stex];
0630     if (fBuildEventDistribBad[i0Stex] > 0) {
0631       edm::LogVerbatim("ecnaAnal") << " <=== SHOULD BE EQUAL TO ZERO ! " << fTTBELL;
0632     }
0633     edm::LogVerbatim("ecnaAnal") << std::endl;
0634   }
0635 
0636   edm::LogVerbatim("ecnaAnal") << "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ";
0637 
0638   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-destructor> Run types seen in event headers before selection:";
0639 
0640   for (Int_t i = 0; i < fMaxRunTypeCounter; i++) {
0641     edm::LogVerbatim("ecnaAnal") << " => " << std::setw(10) << fRunTypeCounter[i] << " event header(s) with run type "
0642                                  << runtype(i);
0643   }
0644 
0645   edm::LogVerbatim("ecnaAnal") << "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ";
0646 
0647   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-destructor> Mgpa gains seen in event headers before selection:";
0648 
0649   for (Int_t i = 0; i < fMaxMgpaGainCounter; i++) {
0650     edm::LogVerbatim("ecnaAnal") << " => " << std::setw(10) << fMgpaGainCounter[i] << " event header(s) with gain "
0651                                  << gainvalue(i);
0652   }
0653 
0654   edm::LogVerbatim("ecnaAnal") << "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ";
0655 
0656   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-destructor> Numbers of selected events for each FED:";
0657 
0658   for (Int_t i = 0; i < fMaxFedIdCounter; i++) {
0659     edm::LogVerbatim("ecnaAnal") << " => FedId " << i + 601 << ": " << std::setw(10) << fFedIdCounter[i] << " events";
0660   }
0661 
0662   edm::LogVerbatim("ecnaAnal") << "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ";
0663 
0664   if (fStexNumber > 0) {
0665     edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-destructor> fDateFirst = " << fDateFirst[fStexNumber - 1]
0666                                  << "\n                          fDateLast  = " << fDateLast[fStexNumber - 1]
0667                                  << std::endl;
0668   }
0669 
0670   edm::LogVerbatim("ecnaAnal") << "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ";
0671 
0672   Int_t n0 = 0;
0673   CheckMsg(n0);
0674 
0675   delete fBuildEventDistribBad;
0676   delete fBuildEventDistribGood;
0677   delete fSMFromFedTcc;
0678   delete fESFromFedTcc;
0679   delete fDeeFromFedTcc;
0680   delete fFedStatusOrder;
0681   delete fDeeNumberString;
0682 
0683   delete fStexDigiOK;
0684   delete fStexNbOfTreatedEvents;
0685   delete fStexStatus;
0686   delete fFedStatus;
0687   delete fFedDigiOK;
0688   delete fFedNbOfTreatedEvents;
0689   delete fNbOfTreatedFedsInDee;
0690   delete fNbOfTreatedFedsInStex;
0691 
0692   delete fTimeFirst;
0693   delete fTimeLast;
0694   delete fDateFirst;
0695   delete fDateLast;
0696   delete fMemoDateFirstEvent;
0697 
0698   delete fMyEBNumbering;
0699   delete fMyEENumbering;
0700 
0701   delete fMyEBEcal;
0702   delete fMyEEEcal;
0703 
0704   delete fRunTypeCounter;
0705   delete fMgpaGainCounter;
0706   delete fFedIdCounter;
0707   delete fCounterQuad;
0708 
0709   edm::LogVerbatim("ecnaAnal") << "*EcnaAnalyzer-destructor> End of execution.";
0710 }
0711 // end of destructor
0712 
0713 //
0714 // member functions
0715 //
0716 
0717 // ------------ method called to produce the data  ------------
0718 void EcnaAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0719   //..................................... format numerical values
0720   std::cout << std::setiosflags(std::ios::showpoint | std::ios::uppercase);
0721   std::cout << std::setprecision(3) << std::setw(6);
0722   std::cout.setf(std::ios::dec, std::ios::basefield);
0723   std::cout.setf(std::ios::fixed, std::ios::floatfield);
0724   std::cout.setf(std::ios::left, std::ios::adjustfield);
0725   std::cout.setf(std::ios::right, std::ios::adjustfield);
0726 
0727   fRecNumber++;
0728 
0729   Int_t iFreq = (fLastReqEvent - fFirstReqEvent + 1) / 5;
0730   if (iFreq <= 0) {
0731     iFreq = 10000;
0732   }
0733 
0734   Int_t MaxSMAndDS = fMyEBEcal->MaxSMInEB() + fMyEEEcal->MaxDSInEE();
0735 
0736   //********************************************* EVENT TREATMENT
0737   //********************************
0738   const edm::Handle<EcalRawDataCollection> &pEventHeader = iEvent.getHandle(eventHeaderToken_);
0739   const EcalRawDataCollection *myEventHeader = nullptr;
0740   if (pEventHeader.isValid()) {
0741     myEventHeader = pEventHeader.product();
0742   } else {
0743     edm::LogError("ecnaAnal") << "Error! can't get the product " << eventHeaderCollection_.c_str();
0744   }
0745   //........... Decode myEventHeader infos
0746   for (EcalRawDataCollection::const_iterator headerItr = myEventHeader->begin(); headerItr != myEventHeader->end();
0747        ++headerItr) {
0748     //===> fRunNumber, fRunTypeNumber, fMgpaGainNumber, fFedId, fEvtNumber
0749     //     will be used in AnalysisOutcome(...) below
0750     fRunNumber = (Int_t)headerItr->getRunNumber();
0751     if (fRunNumber <= 0) {
0752       fRunNumber = (Int_t)iEvent.id().run();
0753     }
0754     fRunTypeNumber = (Int_t)headerItr->getRunType();
0755     fMgpaGainNumber = (Int_t)headerItr->getMgpaGain();
0756     fFedId = (Int_t)headerItr->fedId() - 601;  // 1st Fed = 601, FedId = Fed number - 1
0757     fEvtNumber = (Int_t)headerItr->getLV1();
0758     if (fEvtNumber <= 0) {
0759       fEvtNumber = (Int_t)iEvent.id().event();
0760     }
0761 
0762     if (fEvtNumber != fEvtNumberMemo) {
0763       fEvtNumberMemo = fEvtNumber;
0764 
0765       //============================================
0766       //  cmsRun INTERRUPTION if analysis complete
0767       //  or if fCurrentEventNumber >= LastReqEvent
0768       //============================================
0769       if (AnalysisOutcome("EVT") == kTRUE) {
0770         return;
0771       }
0772 
0773       // no interruption => event has to be analyzed
0774 
0775       fCurrentEventNumber++;
0776 
0777       if (fRecNumber == 1 || fRecNumber == 50 || fRecNumber == 100 || fRecNumber == 500 || fRecNumber == 1000 ||
0778           fRecNumber % iFreq == 0) {
0779         Int_t n1 = 1;
0780         CheckMsg(n1);
0781       }
0782 
0783       if (fCurrentEventNumber < fFirstReqEvent)
0784         return;  // skip events before fFirstReqEvent
0785     }
0786 
0787     //.................. Increment Run type and MgpaGain counters
0788     if (fRunTypeNumber >= 0 && fRunTypeNumber < fMaxRunTypeCounter) {
0789       fRunTypeCounter[fRunTypeNumber]++;
0790     }
0791     if (fMgpaGainNumber >= 0 && fMgpaGainNumber < fMaxMgpaGainCounter) {
0792       fMgpaGainCounter[fMgpaGainNumber]++;
0793     }
0794 
0795     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User's analysis cut
0796     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0797 
0798     if (!(fRunNumber > 0 && (fRunTypeNumber == fChozenRunTypeNumber || fChozenRunTypeNumber == fANY_RUN) &&
0799           (fMgpaGainNumber == fChozenGainNumber || fChozenGainNumber == 0)))
0800       return;
0801 
0802     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0803 
0804     if (fMemoCutOK == 0) {
0805       fMemoCutOK = 1;
0806     }
0807 
0808     //---- Accelerating selection with "FED-TCC" number [ from
0809     // headerItr->getDccInTCCCommand() ]
0810     //     Arrays fSMFromFedTcc[] and fESFromFedTcc[] are initialised in Init()
0811 
0812     if (fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcPhys" ||
0813         fAnalysisName == "AdcAny") {
0814       fFedTcc = (Int_t)headerItr->getDccInTCCCommand();
0815 
0816       if (fFedTcc >= 1 && fFedTcc <= MaxSMAndDS) {
0817         if (fStexName == "SM") {
0818           if (fFedTcc < 10 || fFedTcc > 45)
0819             return;
0820 
0821           if (fSMFromFedTcc[fFedTcc - 1] >= 1 && fSMFromFedTcc[fFedTcc - 1] <= fMyEBEcal->MaxSMInEB() &&
0822               fStexNbOfTreatedEvents[fSMFromFedTcc[fFedTcc - 1] - 1] >= fReqNbOfEvts)
0823             return;
0824         }
0825 
0826         if (fStexName == "Dee") {
0827           if (fFedTcc >= 10 && fFedTcc <= 45)
0828             return;
0829 
0830           if (fESFromFedTcc[fFedTcc - 1] >= 1 && fESFromFedTcc[fFedTcc - 1] <= fMyEEEcal->MaxDSInEE() &&
0831               fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1] >= fReqNbOfEvts)
0832             return;
0833         }
0834       }  // end of if( fFedTcc >= 1 && fFedTcc <= MaxSMAndDS )
0835     }    // end of if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12"
0836     // ...)
0837 
0838     //.................. Increment FedId counters
0839     if (fFedId >= 0 && fFedId < fMaxFedIdCounter) {
0840       fFedIdCounter[fFedId]++;
0841     }
0842 
0843   }  // end of for(EcalRawDataCollection::const_iterator
0844   // headerItr=myEventHeader->begin(); headerItr !=
0845   // myEventHeader->end();++headerItr)
0846 
0847   if (fMemoCutOK == 0)
0848     return;  // return if no event passed the user's analysis cut
0849 
0850   //========================== SELECTED EVENTS ================================
0851   fNbOfSelectedEvents++;
0852   if (fNbOfSelectedEvents == 1) {
0853     Int_t n2 = 2;
0854     CheckMsg(n2);
0855   }
0856 
0857   //============================ Ecna init for the pointers array
0858   //=================================
0859   //.................................................................. EB (SM)
0860   if (fMyCnaEBSM == nullptr && fStexName == "SM") {
0861     fMyCnaEBSM = new TEcnaRun *[fMyEBEcal->MaxSMInEB()];
0862     for (Int_t i0SM = 0; i0SM < fMyEBEcal->MaxSMInEB(); i0SM++) {
0863       fMyCnaEBSM[i0SM] = nullptr;
0864     }
0865   }
0866   //.................................................................. EE (Dee)
0867   if (fMyCnaEEDee == nullptr && fStexName == "Dee") {
0868     fMyCnaEEDee = new TEcnaRun *[fMyEEEcal->MaxDeeInEE()];
0869     for (Int_t iDee = 0; iDee < fMyEEEcal->MaxDeeInEE(); iDee++) {
0870       fMyCnaEEDee[iDee] = nullptr;
0871     }
0872   }
0873 
0874   //============================ EVENT TREATMENT ==============================
0875   Int_t MaxNbOfStex = 0;
0876   if (fStexName == "SM") {
0877     MaxNbOfStex = fMyEBEcal->MaxSMInEB();
0878   }
0879   if (fStexName == "Dee") {
0880     MaxNbOfStex = fMyEEEcal->MaxDeeInEE();
0881   }
0882 
0883   if ((fStexNumber > 0 && fNbOfTreatedStexs == 0) || (fStexNumber == 0 && fNbOfTreatedStexs < MaxNbOfStex)) {
0884     //================================================================= Record
0885     // type EB (SM)
0886     if (fStexName == "SM" && fSMIndexBegin < fSMIndexStop) {
0887       //......................................... Get digisEB
0888       const edm::Handle<EBDigiCollection> &pdigisEB = iEvent.getHandle(EBdigiToken_);
0889       const EBDigiCollection *digisEB = nullptr;
0890       if (pdigisEB.isValid()) {
0891         digisEB = pdigisEB.product();
0892       } else {
0893         edm::LogError("ecnaAnal") << "Error! can't get the product " << EBdigiCollection_.c_str();
0894       }
0895 
0896       // Initialize vectors if not already done
0897       if (int(digisEB->size()) > nChannels_) {
0898         nChannels_ = digisEB->size();
0899       }
0900 
0901       // Int_t print_count = 0;
0902       if (Int_t(digisEB->end() - digisEB->begin()) >= 0 &&
0903           Int_t(digisEB->end() - digisEB->begin()) <= Int_t(digisEB->size())) {
0904         //..........................................EB
0905         //===============================================================================
0906         //
0907         //                    Loop over Ecal barrel digisEB (Xtals)
0908         //
0909         //===============================================================================
0910 
0911         for (EBDigiCollection::const_iterator digiItr = digisEB->begin(); digiItr != digisEB->end(); ++digiItr) {
0912           EBDetId id_crystal(digiItr->id());
0913           // Int_t HashedIndex = id_crystal.hashedIndex();
0914 
0915           Int_t i0SM = id_crystal.ism() - 1;  //   <============== GET the SM number - 1 here
0916 
0917           if (i0SM >= 0 && i0SM < fMaxTreatedStexCounter) {
0918             if (fMyCnaEBSM[i0SM] == nullptr && fStexStatus[i0SM] != 2) {
0919               //=============================== Init Ecna EB
0920               //===============================
0921               fMyCnaEBSM[i0SM] = new TEcnaRun(fMyEcnaEBObjectManager, "EB", fNbOfSamples);
0922               fMyCnaEBSM[i0SM]->GetReadyToReadData(
0923                   fAnalysisName, fRunNumber, fFirstReqEvent, fLastReqEvent, fReqNbOfEvts, i0SM + 1, fRunTypeNumber);
0924 
0925               edm::LogVerbatim("ecnaAnal")
0926                   << "*EcnaAnalyzer::analyze(...)> ********* INIT ECNA EB ********* "
0927                   << "\n                                   fAnalysisName = " << fAnalysisName
0928                   << "\n                                      fRunNumber = " << fRunNumber
0929                   << "\n                                  fFirstReqEvent = " << fFirstReqEvent
0930                   << "\n                                   fLastReqEvent = " << fLastReqEvent
0931                   << "\n                                    fReqNbOfEvts = " << fReqNbOfEvts
0932                   << "\n                                              SM = " << i0SM + 1
0933                   << "\n                                        run type = " << runtype(fRunTypeNumber);
0934               //============================================================================
0935             }
0936 
0937             if (fStexStatus[i0SM] < 2)  // nothing to do if status=2 reached
0938             {
0939               fStexDigiOK[i0SM]++;
0940               if (fStexDigiOK[i0SM] == 1) {
0941                 fStexNbOfTreatedEvents[i0SM]++;
0942               }
0943 
0944               if (fStexNbOfTreatedEvents[i0SM] >= 1 && fStexNbOfTreatedEvents[i0SM] <= fReqNbOfEvts) {
0945                 //......................................... date of first event
0946                 //(in real time)
0947                 edm::Timestamp Time = iEvent.time();
0948                 edm::TimeValue_t t_current_ev_time = (cond::Time_t)Time.value();
0949                 time_t i_current_ev_time = (time_t)(t_current_ev_time >> 32);
0950                 const time_t *p_current_ev_time = &i_current_ev_time;
0951                 char *astime = ctime(p_current_ev_time);
0952 
0953                 if (fStexDigiOK[i0SM] == 1 && fStexNbOfTreatedEvents[i0SM] == 1 &&
0954                     (fStexNumber == 0 || i0SM + 1 == fStexNumber)) {
0955                   fTimeFirst[i0SM] = i_current_ev_time;
0956                   fDateFirst[i0SM] = astime;
0957                   fTimeLast[i0SM] = i_current_ev_time;
0958                   fDateLast[i0SM] = astime;
0959                   edm::LogVerbatim("ecnaAnal") << "*----> beginning of analysis for " << fStexName << i0SM + 1
0960                                                << ". First analyzed event date : " << astime;
0961                 }
0962 
0963                 if (i_current_ev_time < fTimeFirst[i0SM]) {
0964                   fTimeFirst[i0SM] = i_current_ev_time;
0965                   fDateFirst[i0SM] = astime;
0966                 }
0967                 if (i_current_ev_time > fTimeLast[i0SM]) {
0968                   fTimeLast[i0SM] = i_current_ev_time;
0969                   fDateLast[i0SM] = astime;
0970                 }
0971 
0972                 //=============================================> CUT on i0SM
0973                 // value
0974                 if ((fStexNumber > 0 && i0SM == fStexNumber - 1) || (fStexNumber == 0)) {
0975                   Int_t iEta = id_crystal.ietaSM();  // ietaSM() : range = [1,85]
0976                   Int_t iPhi = id_crystal.iphiSM();  // iphiSM() : range = [1,20]
0977 
0978                   Int_t n1SMCrys = (iEta - 1) * (fMyEBEcal->MaxTowPhiInSM() * fMyEBEcal->MaxCrysPhiInTow()) +
0979                                    iPhi;                                               // range = [1,1700]
0980                   Int_t n1SMTow = fMyEBNumbering->Get1SMTowFrom1SMCrys(n1SMCrys);      // range = [1,68]
0981                   Int_t i0TowEcha = fMyEBNumbering->Get0TowEchaFrom1SMCrys(n1SMCrys);  // range = [0,24]
0982 
0983                   Int_t NbOfSamplesFromDigis = digiItr->size();
0984 
0985                   EBDataFrame df(*digiItr);
0986 
0987                   if (NbOfSamplesFromDigis > 0 && NbOfSamplesFromDigis <= fMyEBEcal->MaxSampADC()) {
0988                     Double_t adcDBLS = (Double_t)0;
0989                     // Three 1st samples mean value for Dynamic Base Line
0990                     // Substraction (DBLS)
0991                     if (fDynBaseLineSub == "yes") {
0992                       for (Int_t i0Sample = 0; i0Sample < 3; i0Sample++) {
0993                         adcDBLS += (Double_t)(df.sample(i0Sample).adc());
0994                       }
0995                       adcDBLS /= (Double_t)3;
0996                     }
0997                     // Loop over the samples
0998                     for (Int_t i0Sample = 0; i0Sample < fNbOfSamples; i0Sample++) {
0999                       Double_t adc = (Double_t)(df.sample(i0Sample).adc()) - adcDBLS;
1000                       //................................................. Calls
1001                       // to GetSampleAdcValues
1002                       if (fMyCnaEBSM[i0SM]->GetSampleAdcValues(
1003                               fStexNbOfTreatedEvents[i0SM], n1SMTow, i0TowEcha, i0Sample, adc) == kTRUE) {
1004                         fBuildEventDistribGood[i0SM]++;
1005                       } else {
1006                         fBuildEventDistribBad[i0SM]++;
1007                       }
1008                     }
1009                   } else {
1010                     edm::LogVerbatim("ecnaAnal")
1011                         << "EcnaAnalyzer::analyze(...)> NbOfSamplesFromDigis out of bounds = " << NbOfSamplesFromDigis;
1012                   }
1013                 }  // end of if( (fStexNumber > 0 && i0SM == fStexNumber-1) ||
1014                    // (fStexNumber == 0) )
1015               }    // end of if( fStexNbOfTreatedEvents[i0SM] >= 1 &&
1016                    // fStexNbOfTreatedEvents[i0SM] <= fReqNbOfEvts )
1017             }      // end of if( fStexStatus[i0SM] < 2 )
1018           }        // end of if( i0SM >= 0 && i0SM<fMaxTreatedStexCounter  )
1019         }          // end of for (EBDigiCollection::const_iterator digiItr =
1020                    // digisEB->begin();
1021                    //             digiItr != digisEB->end(); ++digiItr)
1022 
1023         for (Int_t i0SM = 0; i0SM < fMaxTreatedStexCounter; i0SM++) {
1024           fStexDigiOK[i0SM] = 0;  // reset fStexDigiOK[i0SM] after loop on digis
1025         }
1026 
1027       }  // end of if( Int_t(digisEB->end()-digisEB->begin()) >= 0 &&
1028          // Int_t(digisEB->end()-digisEB->begin()) <=  Int_t(digisEB->size()) )
1029     }    // end of if( fStexName == "SM" && fSMIndexBegin < fSMIndexStop )
1030 
1031     //=============================================================== Record
1032     // type EE (Dee)
1033     if (fStexName == "Dee" && fDeeIndexBegin < fDeeIndexStop) {
1034       //......................................... Get digisEE
1035       const edm::Handle<EEDigiCollection> &pdigisEE = iEvent.getHandle(EEdigiToken_);
1036       const EEDigiCollection *digisEE = nullptr;
1037       if (pdigisEE.isValid()) {
1038         digisEE = pdigisEE.product();
1039       } else {
1040         edm::LogError("ecnaAnal") << "Error! can't get the product " << EEdigiCollection_.c_str();
1041       }
1042 
1043       // Initialize vectors if not already done
1044       if (int(digisEE->size()) > nChannels_) {
1045         nChannels_ = digisEE->size();
1046       }
1047 
1048       // Int_t print_count = 0;
1049       if (Int_t(digisEE->end() - digisEE->begin()) >= 0 &&
1050           Int_t(digisEE->end() - digisEE->begin()) <= Int_t(digisEE->size())) {
1051         //======================================================================================
1052         //
1053         //                           Loop over Ecal endcap digisEE (Xtals)
1054         //
1055         //======================================================================================
1056 
1057         for (EEDigiCollection::const_iterator digiItr = digisEE->begin(); digiItr != digisEE->end(); ++digiItr) {
1058           EEDetId id_crystal(digiItr->id());
1059 
1060           Int_t iX_data = id_crystal.ix();        // iX_data : range = [1,100]
1061           Int_t iY_data = id_crystal.iy();        // iY_data : range = [1,100]
1062           Int_t i_quad = id_crystal.iquadrant();  // iquadrant() : range = [1,4]
1063           Int_t i_sgnZ = id_crystal.zside();      //     zside() : values = -1,+1
1064 
1065           Int_t iX = iX_data;
1066           Int_t iY = iY_data;  // iY : range = [1,100]
1067 
1068           //.......... See
1069           // CMSSW/DataFormats/EcalDetId/src/EEDetId.cc::ixQuadrantOne()  [ in
1070           // which ix() = iX_data ]
1071           if (i_quad == 1 || i_quad == 4) {
1072             iX = iX_data - 50;
1073           }  // iX_data : range = [51,100], iX : range = [1,50]
1074           if (i_quad == 3 || i_quad == 2) {
1075             iX = 51 - iX_data;
1076           }  // iX_data : range = [50,1],   iX : range = [1,50]
1077 
1078           Int_t n1DeeCrys =
1079               (iX - 1) * (fMyEEEcal->MaxSCIYInDee() * fMyEEEcal->MaxCrysIYInSC()) + iY;  // n1DeeCrys: range = [1,5000]
1080 
1081           Int_t n1DeeNumber = 0;
1082           if (i_quad == 1 && i_sgnZ == 1) {
1083             n1DeeNumber = 2;
1084           }
1085           if (i_quad == 1 && i_sgnZ == -1) {
1086             n1DeeNumber = 3;
1087           }
1088           if (i_quad == 2 && i_sgnZ == 1) {
1089             n1DeeNumber = 1;
1090           }
1091           if (i_quad == 2 && i_sgnZ == -1) {
1092             n1DeeNumber = 4;
1093           }
1094           if (i_quad == 3 && i_sgnZ == 1) {
1095             n1DeeNumber = 1;
1096           }
1097           if (i_quad == 3 && i_sgnZ == -1) {
1098             n1DeeNumber = 4;
1099           }
1100           if (i_quad == 4 && i_sgnZ == 1) {
1101             n1DeeNumber = 2;
1102           }
1103           if (i_quad == 4 && i_sgnZ == -1) {
1104             n1DeeNumber = 3;
1105           }
1106 
1107           Int_t i0Dee = n1DeeNumber - 1;  //   <============== GET the Dee number - 1 here
1108 
1109           if (i0Dee >= 0 && i0Dee < fMaxTreatedStexCounter) {
1110             if (fMyCnaEEDee[i0Dee] == nullptr && fStexStatus[i0Dee] != 2) {
1111               //=============================== Init Ecna EE
1112               //===============================
1113               fMyCnaEEDee[i0Dee] = new TEcnaRun(fMyEcnaEEObjectManager, "EE", fNbOfSamples);
1114               fMyCnaEEDee[i0Dee]->GetReadyToReadData(
1115                   fAnalysisName, fRunNumber, fFirstReqEvent, fLastReqEvent, fReqNbOfEvts, i0Dee + 1, fRunTypeNumber);
1116 
1117               edm::LogVerbatim("ecnaAnal")
1118                   << "*EcnaAnalyzer::analyze(...)> ********* INIT ECNA EE ********* "
1119                   << "\n                                   fAnalysisName = " << fAnalysisName
1120                   << "\n                                      fRunNumber = " << fRunNumber
1121                   << "\n                                  fFirstReqEvent = " << fFirstReqEvent
1122                   << "\n                                   fLastReqEvent = " << fLastReqEvent
1123                   << "\n                                    fReqNbOfEvts = " << fReqNbOfEvts
1124                   << "\n                                             Dee = " << i0Dee + 1
1125                   << "\n                                        run type = " << runtype(fRunTypeNumber);
1126               //============================================================================
1127             }
1128 
1129             if (fStexStatus[i0Dee] < 2)  // nothing to do if status=2 reached
1130             {
1131               Bool_t cOKForTreatment = kFALSE;
1132 
1133               if (fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcPhys" ||
1134                   fAnalysisName == "AdcAny") {
1135                 if (fFedTcc >= 1 && fFedTcc <= MaxSMAndDS) {
1136                   fFedDigiOK[fESFromFedTcc[fFedTcc - 1] - 1]++;
1137 
1138                   if (!(fESFromFedTcc[fFedTcc - 1] == 5 || fESFromFedTcc[fFedTcc - 1] == 14)) {
1139                     if (fFedDigiOK[fESFromFedTcc[fFedTcc - 1] - 1] == 1) {
1140                       fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1]++;
1141                     }
1142                     if (fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1] >= 1 &&
1143                         fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1] <= fReqNbOfEvts) {
1144                       fStexNbOfTreatedEvents[i0Dee] = fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1];
1145                       cOKForTreatment = kTRUE;
1146                     }
1147                   }
1148                   if (fESFromFedTcc[fFedTcc - 1] == 5 || fESFromFedTcc[fFedTcc - 1] == 14) {
1149                     if (fFedDigiOK[fESFromFedTcc[fFedTcc - 1] - 1] == 1) {
1150                       fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1]++;
1151                       fDeeDS5Memo1 = n1DeeNumber;
1152                       fStexNbOfTreatedEvents[i0Dee] = fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1];
1153                     } else {
1154                       if (fDeeDS5Memo2 == 0) {
1155                         if (n1DeeNumber != fDeeDS5Memo1) {
1156                           // change of Dee in Data sector 5
1157                           fDeeDS5Memo2 = n1DeeNumber;
1158                           fStexNbOfTreatedEvents[i0Dee] = fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1];
1159                         }
1160                       }
1161                     }
1162                     if (fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1] >= 1 &&
1163                         fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc - 1] - 1] <= fReqNbOfEvts) {
1164                       cOKForTreatment = kTRUE;
1165                     }
1166                   }
1167                 }  // end of if( fFedTcc >= 1 && fFedTcc <= MaxSMAndDS )
1168               }    // end of if( fAnalysisName == "AdcPeg12"  || fAnalysisName ==
1169                    // "AdcSPeg12" .... )
1170               else {
1171                 fStexDigiOK[i0Dee]++;
1172                 if (fStexDigiOK[i0Dee] == 1) {
1173                   fStexNbOfTreatedEvents[i0Dee]++;
1174                 }
1175                 if (fStexNbOfTreatedEvents[i0Dee] >= 1 && fStexNbOfTreatedEvents[i0Dee] <= fReqNbOfEvts) {
1176                   cOKForTreatment = kTRUE;
1177                 }
1178               }
1179 
1180               if (cOKForTreatment == kTRUE) {
1181                 //......................................... date of first event
1182                 //(in real time)
1183                 edm::Timestamp Time = iEvent.time();
1184                 edm::TimeValue_t t_current_ev_time = (cond::Time_t)Time.value();
1185                 time_t i_current_ev_time = (time_t)(t_current_ev_time >> 32);
1186                 const time_t *p_current_ev_time = &i_current_ev_time;
1187                 char *astime = ctime(p_current_ev_time);
1188 
1189                 if ((!(fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcPhys" ||
1190                        fAnalysisName == "AdcAny") &&
1191                      fStexDigiOK[i0Dee] == 1 && fStexNbOfTreatedEvents[i0Dee] == 1) ||
1192                     ((fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcPhys" ||
1193                       fAnalysisName == "AdcAny") &&
1194                      fFedDigiOK[fESFromFedTcc[fFedTcc - 1] - 1] == 1 && fStexNbOfTreatedEvents[i0Dee] == 1 &&
1195                      fMemoDateFirstEvent[i0Dee] == 0)) {
1196                   fTimeFirst[i0Dee] = i_current_ev_time;
1197                   fDateFirst[i0Dee] = astime;
1198                   fTimeLast[i0Dee] = i_current_ev_time;
1199                   fDateLast[i0Dee] = astime;
1200                   edm::LogVerbatim("ecnaAnal")
1201                       << "----- beginning of analysis for " << fStexName << i0Dee + 1 << "-------"
1202                       << "\n First event date  = " << astime << "\n Nb of selected evts = " << fNbOfSelectedEvents
1203                       << "\n---------------------------------------------------------------";
1204                   fMemoDateFirstEvent[i0Dee]++;
1205                 }
1206 
1207                 if (i_current_ev_time < fTimeFirst[i0Dee]) {
1208                   fTimeFirst[i0Dee] = i_current_ev_time;
1209                   fDateFirst[i0Dee] = astime;
1210                 }
1211                 if (i_current_ev_time > fTimeLast[i0Dee]) {
1212                   fTimeLast[i0Dee] = i_current_ev_time;
1213                   fDateLast[i0Dee] = astime;
1214                 }
1215 
1216                 //=============================================> cut on i0Dee
1217                 // value
1218                 if ((fStexNumber > 0 && i0Dee == fStexNumber - 1) || (fStexNumber == 0)) {
1219                   TString sDir = fMyEENumbering->GetDeeDirViewedFromIP(n1DeeNumber);
1220                   Int_t n1DeeSCEcna = fMyEENumbering->Get1DeeSCEcnaFrom1DeeCrys(n1DeeCrys, sDir);
1221                   Int_t i0SCEcha = fMyEENumbering->Get1SCEchaFrom1DeeCrys(n1DeeCrys, sDir) - 1;
1222 
1223                   Int_t NbOfSamplesFromDigis = digiItr->size();
1224 
1225                   EEDataFrame df(*digiItr);
1226 
1227                   if (NbOfSamplesFromDigis > 0 && NbOfSamplesFromDigis <= fMyEEEcal->MaxSampADC()) {
1228                     Double_t adcDBLS = (Double_t)0;
1229                     // Three 1st samples mean value for Dynamic Base Line
1230                     // Substraction (DBLS)
1231                     if (fDynBaseLineSub == "yes") {
1232                       for (Int_t i0Sample = 0; i0Sample < 3; i0Sample++) {
1233                         adcDBLS += (Double_t)(df.sample(i0Sample).adc());
1234                       }
1235                       adcDBLS /= (Double_t)3;
1236                     }
1237                     // Loop over the samples
1238                     for (Int_t i0Sample = 0; i0Sample < fNbOfSamples; i0Sample++) {
1239                       Double_t adc = (Double_t)(df.sample(i0Sample).adc()) - adcDBLS;
1240                       //................................................. Calls
1241                       // to GetSampleAdcValues
1242                       if (fMyCnaEEDee[i0Dee]->GetSampleAdcValues(
1243                               fStexNbOfTreatedEvents[i0Dee], n1DeeSCEcna, i0SCEcha, i0Sample, adc) == kTRUE) {
1244                         fBuildEventDistribGood[i0Dee]++;
1245                       } else {
1246                         fBuildEventDistribBad[i0Dee]++;
1247                       }
1248                     }
1249                   } else {
1250                     edm::LogVerbatim("ecnaAnal")
1251                         << "EcnaAnalyzer::analyze(...)> NbOfSamplesFromDigis out of bounds = " << NbOfSamplesFromDigis;
1252                   }
1253                 }  // end of if( (fStexNumber > 0 && i0Dee == fStexNumber-1) ||
1254                    // (fStexNumber == 0) )
1255               }    // end of if( fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1]
1256                    // >= 1 &&
1257               // fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] <=
1258               // fReqNbOfEvts )
1259             }  // end of if( fStexStatus[i0Dee] < 2 )
1260           }    // end of if( i0Dee >= 0 && i0Dee<fMaxTreatedStexCounter )
1261         }      // end of for (EBDigiCollection::const_iterator digiItr =
1262                // digisEB->begin();
1263                //             digiItr != digisEB->end(); ++digiItr)
1264 
1265         // reset fStexDigiOK[i0Dee] or fFedDigiOK[i0Dee] to zero after loop on
1266         // digis
1267         if (fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcPhys" ||
1268             fAnalysisName == "AdcAny") {
1269           for (Int_t i0FedES = 0; i0FedES < fMaxFedUnitCounter; i0FedES++) {
1270             fFedDigiOK[i0FedES] = 0;
1271           }
1272 
1273           // reset fDeeDS5Memo1 and fDeeDS5Memo2 (for Data sector 5 versus Dee
1274           // number  management)
1275           fDeeDS5Memo1 = 0;
1276           fDeeDS5Memo2 = 0;
1277         } else {
1278           for (Int_t i0Dee = 0; i0Dee < fMaxTreatedStexCounter; i0Dee++) {
1279             fStexDigiOK[i0Dee] = 0;
1280           }
1281         }
1282 
1283       }  // end of if( Int_t(digisEB->end()-digisEB->begin()) >= 0 &&
1284          // Int_t(digisEB->end()-digisEB->begin()) <=  Int_t(digisEB->size()) )
1285 
1286     }  // end of if( fStexName == "Dee" && fDeeIndexBegin < fDeeIndexStop )
1287   }    // end of if( (fStexNumber > 0 && fNbOfTreatedStexs == 0) || (fStexNumber ==
1288   // 0 && fNbOfTreatedStexs < MaxNbOfStex) )
1289 
1290   //=============================================================================================
1291   //
1292   //                    Number of treated events. Setting Stex and Fed status.
1293   //
1294   //=============================================================================================
1295 
1296   // (take into account the "Accelerating selection with FED number" section -
1297   // see above -)
1298   if (fStexName == "SM" || (fStexName == "Dee" &&
1299                             !(fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" ||
1300                               fAnalysisName == "AdcPhys" || fAnalysisName == "AdcAny")))  // one FED = one SM = one Stex
1301   {
1302     for (Int_t i0Stex = fStexIndexBegin; i0Stex < fStexIndexStop; i0Stex++) {
1303       if (fStexStatus[i0Stex] != 2)  // do not change fStexStatus[i0Stex] if already set to 2
1304                                      // even if fStexNbOfTreatedEvents[i0Stex] == fReqNbOfEvts
1305       {
1306         if (fStexNbOfTreatedEvents[i0Stex] == fReqNbOfEvts) {
1307           fStexStatus[i0Stex] = 1;
1308         }
1309         if (fStexNbOfTreatedEvents[i0Stex] > fReqNbOfEvts) {
1310           fStexStatus[i0Stex] = 2;
1311         }
1312       }
1313     }
1314   }
1315 
1316   // one FED = one Data Sector (DS or ES)
1317   if (fStexName == "Dee" && (fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" ||
1318                              fAnalysisName == "AdcPhys" || fAnalysisName == "AdcAny")) {
1319     for (Int_t i0FedES = 0; i0FedES < fMaxFedUnitCounter; i0FedES++) {
1320       if (fFedStatus[i0FedES] != 2)  // do not change fFedStatus[i0FedES] if already set to 2
1321                                      // even if fFedNbOfTreatedEvents[i0FedES] == fReqNbOfEvts
1322       {
1323         if (fFedNbOfTreatedEvents[i0FedES] == fReqNbOfEvts) {
1324           fFedStatus[i0FedES] = 1;
1325           fTreatedFedOrder++;
1326           fFedStatusOrder[i0FedES] = fTreatedFedOrder;
1327         }
1328         if (fFedNbOfTreatedEvents[i0FedES] > fReqNbOfEvts) {
1329           fFedStatus[i0FedES] = 2;
1330         }
1331       }
1332     }
1333 
1334     Int_t j0Fed = 4;
1335     //..................................................... Dee 4 (DS 1,2,3,4 ;
1336     // ES 1,2,3,4)
1337     for (Int_t i0FedES = 0; i0FedES <= 3; i0FedES++) {
1338       if (fFedStatus[i0FedES] == 1) {
1339         fNbOfTreatedFedsInDee[3]++;
1340         fFedStatus[i0FedES] = 2;
1341       }
1342     }
1343 
1344     //..................................................... Dee 3, Dee 4 (DS 5 ;
1345     // ES 5)
1346     j0Fed = 4;
1347     if (fFedStatus[j0Fed] == 1) {
1348       fNbOfTreatedFedsInDee[3]++;
1349       fNbOfTreatedFedsInDee[2]++;
1350       fFedStatus[j0Fed] = 2;
1351     }
1352 
1353     //.................................................... Dee 3 (DS 6,7,8,9 ;
1354     // ES 6,7,8,9)
1355     for (Int_t i0FedES = 5; i0FedES <= 8; i0FedES++) {
1356       if (fFedStatus[i0FedES] == 1) {
1357         fNbOfTreatedFedsInDee[2]++;
1358         fFedStatus[i0FedES] = 2;
1359       }
1360     }
1361 
1362     //..................................................... Dee 1 (DS 1,2,3,4 ;
1363     // ES 10,11,12,13)
1364     for (Int_t i0FedES = 9; i0FedES <= 12; i0FedES++) {
1365       if (fFedStatus[i0FedES] == 1) {
1366         fNbOfTreatedFedsInDee[0]++;
1367         fFedStatus[i0FedES] = 2;
1368       }
1369     }
1370 
1371     //..................................................... Dee 1, Dee 2 (DS 5 ;
1372     // ES 5)
1373     j0Fed = 13;
1374     if (fFedStatus[j0Fed] == 1) {
1375       fNbOfTreatedFedsInDee[0]++;
1376       fNbOfTreatedFedsInDee[1]++;
1377       fFedStatus[j0Fed] = 2;
1378     }
1379 
1380     //..................................................... Dee 2 (DS 6,7,8,9 ;
1381     // ES 15,16,17,18)
1382     for (Int_t i0FedES = 14; i0FedES <= 17; i0FedES++) {
1383       if (fFedStatus[i0FedES] == 1) {
1384         fNbOfTreatedFedsInDee[1]++;
1385         fFedStatus[i0FedES] = 2;
1386       }
1387     }
1388 
1389     //-----------------------------------------------------
1390     for (Int_t i0Dee = 0; i0Dee < 4; i0Dee++) {
1391       if (fNbOfTreatedFedsInStex[i0Dee] >= 0 && fNbOfTreatedFedsInStex[i0Dee] < 5) {
1392         fNbOfTreatedFedsInStex[i0Dee] = fNbOfTreatedFedsInDee[i0Dee];
1393       }
1394       if (fNbOfTreatedFedsInDee[i0Dee] == 5) {
1395         fStexStatus[i0Dee] = 1;
1396         fNbOfTreatedFedsInDee[i0Dee] = 0;
1397       }
1398     }
1399 
1400   }  // end of if( fStexName == "Dee" &&
1401   // ( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" ... ) )
1402 
1403   //----------------------------------------------------------------------------------------------
1404   for (Int_t i0Stex = fStexIndexBegin; i0Stex < fStexIndexStop; i0Stex++) {
1405     if (fStexStatus[i0Stex] == 1) {
1406       fNbOfTreatedStexs++;  // increase nb of treated Stex's only if
1407                             // fStexStatus[i0Stex] == 1
1408       //....................................................... date of last
1409       // event edm::Timestamp Time = iEvent.time(); edm::TimeValue_t
1410       // t_current_ev_time = (cond::Time_t)Time.value(); time_t
1411       // i_current_ev_time = (time_t)(t_current_ev_time>>32); const time_t*
1412       // p_current_ev_time = &i_current_ev_time; char*          astime =
1413       // ctime(p_current_ev_time); fTimeLast[i0Stex] = i_current_ev_time;
1414       // fDateLast[i0Stex] = astime;
1415 
1416       // if( i_current_ev_time > fTimeLast[i0Stex] )
1417       // {fTimeLast[i0Stex] = i_current_ev_time; fDateLast[i0Stex] = astime;}
1418 
1419       edm::LogVerbatim("ecnaAnal") << "---------- End of analysis for " << fStexName << i0Stex + 1 << " -----------";
1420       Int_t n3 = 3;
1421       CheckMsg(n3, i0Stex);
1422       edm::LogVerbatim("ecnaAnal") << " Number of selected events = " << fNbOfSelectedEvents;
1423       edm::LogVerbatim("ecnaAnal") << std::endl
1424                                    << fNbOfTreatedStexs << " " << fStexName << "'s with " << fReqNbOfEvts
1425                                    << " events analyzed."
1426                                    << "\n---------------------------------------------------------";
1427 
1428       //================================= WRITE RESULTS FILE
1429       if (fStexName == "SM") {
1430         if (fMyCnaEBSM[i0Stex] != nullptr) {
1431           //........................................ register dates 1 and 2
1432           fMyCnaEBSM[i0Stex]->StartStopDate(fDateFirst[i0Stex], fDateLast[i0Stex]);
1433           fMyCnaEBSM[i0Stex]->StartStopTime(fTimeFirst[i0Stex], fTimeLast[i0Stex]);
1434 
1435           //........................................ Init .root file
1436           fMyCnaEBSM[i0Stex]->GetReadyToCompute();
1437           fMyCnaEBSM[i0Stex]->SampleValues();
1438 
1439           //........................................ write the sample values in
1440           //.root file
1441           if (fMyCnaEBSM[i0Stex]->WriteRootFile() == kFALSE) {
1442             edm::LogVerbatim("ecnaAnal") << "!EcnaAnalyzer::analyze> PROBLEM with write ROOT file for SM" << i0Stex + 1
1443                                          << fTTBELL;
1444           }
1445         }
1446         // set pointer to zero in order to avoid recalculation and rewriting at
1447         // the destructor level
1448         delete fMyCnaEBSM[i0Stex];
1449         fMyCnaEBSM[i0Stex] = nullptr;
1450         edm::LogVerbatim("ecnaAnal") << "!EcnaAnalyzer::analyze> Set memory free: delete done for SM " << i0Stex + 1;
1451       }
1452 
1453       if (fStexName == "Dee") {
1454         if (fMyCnaEEDee[i0Stex] != nullptr) {
1455           //........................................ register dates 1 and 2
1456           fMyCnaEEDee[i0Stex]->StartStopDate(fDateFirst[i0Stex], fDateLast[i0Stex]);
1457           fMyCnaEEDee[i0Stex]->StartStopTime(fTimeFirst[i0Stex], fTimeLast[i0Stex]);
1458 
1459           //........................................ Init .root file
1460           fMyCnaEEDee[i0Stex]->GetReadyToCompute();
1461           fMyCnaEEDee[i0Stex]->SampleValues();
1462 
1463           //........................................ write the sample values in
1464           //.root file
1465           if (fMyCnaEEDee[i0Stex]->WriteRootFile() == kFALSE) {
1466             edm::LogVerbatim("ecnaAnal") << "!EcnaAnalyzer::analyze> PROBLEM with write ROOT file for Dee" << i0Stex + 1
1467                                          << " " << fTTBELL;
1468           }
1469         }
1470         // set pointer to zero in order to avoid recalculation and rewriting at
1471         // the destructor level
1472         delete fMyCnaEEDee[i0Stex];
1473         fMyCnaEEDee[i0Stex] = nullptr;
1474         edm::LogVerbatim("ecnaAnal") << "!EcnaAnalyzer::analyze> Set memory free: delete done for Dee " << i0Stex + 1;
1475       }
1476 
1477       fStexStatus[i0Stex] = 2;  // set fStexStatus[i0Stex] to 2 definitively
1478       edm::LogVerbatim("ecnaAnal") << "*---------------------------------------------------------------------------- ";
1479 
1480     }  // end of if( fStexStatus[i0Stex] == 1 )
1481   }    // end of for(Int_t i0Stex=fStexIndexBegin; i0Stex<fStexIndexStop; i0Stex++)
1482 }
1483 // end of EcnaAnalyzer::analyse(...)
1484 
1485 Bool_t EcnaAnalyzer::AnalysisOutcome(const TString &s_opt) {
1486   //---- STOP if end of analysis
1487 
1488   Bool_t result = kFALSE;
1489 
1490   if (s_opt == "EVT") {
1491     Int_t MaxNbOfStex = 0;
1492     if (fStexName == "SM") {
1493       MaxNbOfStex = fMyEBEcal->MaxSMInEB();
1494     }
1495     if (fStexName == "Dee") {
1496       MaxNbOfStex = fMyEEEcal->MaxDeeInEE();
1497     }
1498 
1499     if (((fStexNumber > 0 && fNbOfTreatedStexs == 1) || (fStexNumber == 0 && fNbOfTreatedStexs == MaxNbOfStex)) &&
1500         ((fLastReqEvent < fFirstReqEvent) ||
1501          (fLastReqEvent >= fFirstReqEvent && fCurrentEventNumber <= fLastReqEvent))) {
1502       edm::LogVerbatim("ecnaAnal")
1503           << "\n**************************** ANALYSIS REPORT > OK **************************************"
1504           << "\n*EcnaAnalyzer::AnalysisOutcome(...)> The maximum requested number of events and the maximum"
1505           << "\n                                     number of treated " << fStexName << "'s have been reached."
1506           << "\n                                     Analysis successfully ended from EcnaAnalyzer "
1507           << "\n                                     Number of selected events   = " << fNbOfSelectedEvents
1508           << "\n                                     Last requested event number = " << fLastReqEvent
1509           << "\n                                     Current event number        = " << fCurrentEventNumber;
1510 
1511       Int_t n0 = 0;
1512       CheckMsg(n0);
1513 
1514       edm::LogVerbatim("ecnaAnal")
1515           << "****************************************************************************************\n";
1516 
1517       result = kTRUE;
1518       return result;
1519     }
1520 
1521     if (fLastReqEvent >= fFirstReqEvent && fCurrentEventNumber > fLastReqEvent &&
1522         !((fStexNumber > 0 && fNbOfTreatedStexs == 1) || (fStexNumber == 0 && fNbOfTreatedStexs == MaxNbOfStex))) {
1523       edm::LogVerbatim("ecnaAnal") << "\n**************************** ANALYSIS REPORT >>> *** "
1524                                       "WARNING *** WARNING *** WARNING ***"
1525                                    << "\n*EcnaAnalyzer::AnalysisOutcome(...)> Last event reached "
1526                                       "before completion of analysis."
1527                                    << "\n                                     Analysis ended from EcnaAnalyzer "
1528                                    << "\n                                     Number of selected events   = "
1529                                    << fNbOfSelectedEvents
1530                                    << "\n                                     Last requested event number = "
1531                                    << fLastReqEvent
1532                                    << "\n                                     Current event number        = "
1533                                    << fCurrentEventNumber;
1534 
1535       Int_t n0 = 0;
1536       CheckMsg(n0);
1537 
1538       edm::LogVerbatim("ecnaAnal")
1539           << "****************************************************************************************" << std::endl;
1540 
1541       result = kTRUE;
1542       return result;
1543     }
1544   } else {
1545     if (s_opt == "ERR_FNEG") {
1546       edm::LogVerbatim("ecnaAnal")
1547           << "\n**************************** ANALYSIS REPORT >>> **** ERROR **** ERROR **** ERROR ******"
1548           << "\n*EcnaAnalyzer::AnalysisOutcome(...)> First event number = " << fFirstReqEvent
1549           << ". Should be strictly potitive."
1550           << "\n                             Analysis ended from EcnaAnalyzer ";
1551 
1552       edm::LogVerbatim("ecnaAnal")
1553           << "****************************************************************************************" << std::endl;
1554 
1555       result = kTRUE;
1556       return result;
1557     }
1558     if (s_opt == "ERR_LREQ") {
1559       edm::LogVerbatim("ecnaAnal")
1560           << "\n**************************** ANALYSIS REPORT >>> **** ERROR **** ERROR **** ERROR ******"
1561           << "\n*EcnaAnalyzer::analyze(...)> Requested number of events = " << fReqNbOfEvts << "."
1562           << "\n                             Too large compared to the event range: " << fFirstReqEvent << " - "
1563           << fLastReqEvent << "\n                             Analysis ended from EcnaAnalyzer ";
1564 
1565       edm::LogVerbatim("ecnaAnal")
1566           << "****************************************************************************************" << std::endl;
1567 
1568       result = kTRUE;
1569       return result;
1570     }
1571   }
1572   return result;
1573 }  // end of EcnaAnalyzer::AnalysisOutcome(const Int_t& n_option)
1574 
1575 void EcnaAnalyzer::CheckMsg(const Int_t &MsgNum) {
1576   Int_t nm1 = -1;
1577   CheckMsg(MsgNum, nm1);
1578 }
1579 
1580 void EcnaAnalyzer::CheckMsg(const Int_t &MsgNum, const Int_t &i0Stex) {
1581   //------ Cross-check messages
1582 
1583   if (MsgNum == 1) {
1584     edm::LogVerbatim("ecnaAnal") << "---------------- CROSS-CHECK A ------------------ "
1585                                  << "\n**************** CURRENT EVENT ****************** ";
1586   }
1587   if (MsgNum == 2) {
1588     edm::LogVerbatim("ecnaAnal") << "---------------- CROSS-CHECK B ------------------ "
1589                                  << "\n**** FIRST EVENT PASSING USER'S ANALYSIS CUT **** ";
1590   }
1591   if (MsgNum == 3) {
1592     edm::LogVerbatim("ecnaAnal") << "---------------- CROSS-CHECK C ------------------ "
1593                                  << "\n*** CURRENT VALUES BEFORE RESULT FILE WRITING *** ";
1594   }
1595   if (MsgNum == 3 || MsgNum == 4) {
1596     edm::LogVerbatim("ecnaAnal") << "          fRecNumber = " << fRecNumber
1597                                  << "\n          fEvtNumber = " << fEvtNumber;
1598   }
1599 
1600   edm::LogVerbatim("ecnaAnal") << " fCurrentEventNumber = " << fCurrentEventNumber
1601                                << "\n fNbOfSelectedEvents = " << fNbOfSelectedEvents
1602                                << "\n          fRunNumber = " << fRunNumber
1603                                << "\n     Chozen run type = " << runtype(fChozenRunTypeNumber)
1604                                << "\n            Run type = " << runtype(fRunTypeNumber)
1605                                << "\n             fFedTcc = " << fFedTcc << "\n        fFedId(+601) = " << fFedId + 601
1606                                << "\n           fStexName = " << fStexName
1607                                << "\n         Chozen gain = " << gainvalue(fChozenGainNumber)
1608                                << "\n           Mgpa Gain = " << gainvalue(fMgpaGainNumber) << std::endl;
1609 
1610   if (fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcPhys" ||
1611       fAnalysisName == "AdcAny") {
1612     if (fStexName == "SM") {
1613       for (Int_t j0Stex = fStexIndexBegin; j0Stex < fStexIndexStop; j0Stex++) {
1614         Int_t nStexNbOfTreatedEvents = fStexNbOfTreatedEvents[j0Stex];
1615         if (fStexStatus[j0Stex] == 1) {
1616           nStexNbOfTreatedEvents = fStexNbOfTreatedEvents[j0Stex];
1617         }
1618         if (fStexStatus[j0Stex] == 2) {
1619           nStexNbOfTreatedEvents = fStexNbOfTreatedEvents[j0Stex];
1620         }
1621 
1622         edm::LogVerbatim("ecnaAnal") << fStexName << std::setw(3) << j0Stex + 1 << ": " << std::setw(5)
1623                                      << nStexNbOfTreatedEvents << " events. " << fStexName
1624                                      << " status: " << fStexStatus[j0Stex];
1625         if (j0Stex == i0Stex) {
1626           edm::LogVerbatim("ecnaAnal") << " (going to write file for this " << fStexName << ").";
1627         }
1628       }
1629     }
1630 
1631     if (fStexName == "Dee") {
1632       for (Int_t i0FedES = 0; i0FedES < fMaxFedUnitCounter; i0FedES++) {
1633         Int_t nFedNbOfTreatedEvents = fFedNbOfTreatedEvents[i0FedES];
1634         if (fFedStatus[i0FedES] == 1) {
1635           nFedNbOfTreatedEvents = fFedNbOfTreatedEvents[i0FedES];
1636         }
1637         if (fFedStatus[i0FedES] == 2) {
1638           nFedNbOfTreatedEvents = fFedNbOfTreatedEvents[i0FedES];
1639         }
1640 
1641         edm::LogVerbatim("ecnaAnal") << "Fed (ES) " << std::setw(3) << i0FedES + 1 << ": " << std::setw(5)
1642                                      << nFedNbOfTreatedEvents << " events."
1643                                      << " Fed status: " << fFedStatus[i0FedES] << ", order: " << std::setw(3)
1644                                      << fFedStatusOrder[i0FedES] << " (" << fDeeNumberString[i0FedES] << ")";
1645       }
1646 
1647       for (Int_t j0Stex = fStexIndexBegin; j0Stex < fStexIndexStop; j0Stex++) {
1648         edm::LogVerbatim("ecnaAnal") << fStexName << std::setw(3) << j0Stex + 1 << ": " << std::setw(5)
1649                                      << fNbOfTreatedFedsInStex[j0Stex] << " analyzed Fed(s). " << fStexName
1650                                      << " status: " << fStexStatus[j0Stex];
1651         if (j0Stex == i0Stex) {
1652           edm::LogVerbatim("ecnaAnal") << " (going to write file for this " << fStexName << ").";
1653         }
1654       }
1655     }
1656 
1657     edm::LogVerbatim("ecnaAnal") << "Number of " << fStexName << "'s with " << fReqNbOfEvts
1658                                  << " events analyzed: " << fNbOfTreatedStexs;
1659   }
1660 
1661   if (MsgNum == 1 || MsgNum == 2) {
1662     edm::LogVerbatim("ecnaAnal") << "*---------------------------------------------------------------------------- ";
1663   }
1664   if (MsgNum == 3) {
1665     edm::LogVerbatim("ecnaAnal") << "*............................................................................ ";
1666   }
1667 
1668 }  // end of EcnaAnalyzer::CheckMsg(const Int_t& MsgNum, const Int_t& i0Stex)
1669 
1670 TString EcnaAnalyzer::runtype(const Int_t &numtype) {
1671   TString cType = "?";
1672 
1673   if (numtype == 0) {
1674     cType = "COSMICS";
1675   }
1676   if (numtype == 1) {
1677     cType = "BEAMH4";
1678   }
1679   if (numtype == 2) {
1680     cType = "BEAMH2";
1681   }
1682   if (numtype == 3) {
1683     cType = "MTCC";
1684   }
1685   if (numtype == 4) {
1686     cType = "LASER_STD";
1687   }
1688   if (numtype == 5) {
1689     cType = "LASER_POWER_SCAN";
1690   }
1691   if (numtype == 6) {
1692     cType = "LASER_DELAY_SCAN";
1693   }
1694   if (numtype == 7) {
1695     cType = "TESTPULSE_SCAN_MEM";
1696   }
1697   if (numtype == 8) {
1698     cType = "TESTPULSE_MGPA";
1699   }
1700   if (numtype == 9) {
1701     cType = "PEDESTAL_STD";
1702   }
1703   if (numtype == 10) {
1704     cType = "PEDESTAL_OFFSET_SCAN";
1705   }
1706   if (numtype == 11) {
1707     cType = "PEDESTAL_25NS_SCAN";
1708   }
1709   if (numtype == 12) {
1710     cType = "LED_STD";
1711   }
1712 
1713   if (numtype == 13) {
1714     cType = "PHYSICS_GLOBAL";
1715   }
1716   if (numtype == 14) {
1717     cType = "COSMICS_GLOBAL";
1718   }
1719   if (numtype == 15) {
1720     cType = "HALO_GLOBAL";
1721   }
1722 
1723   if (numtype == 16) {
1724     cType = "LASER_GAP";
1725   }
1726   if (numtype == 17) {
1727     cType = "TESTPULSE_GAP";
1728   }
1729   if (numtype == 18) {
1730     cType = "PEDESTAL_GAP";
1731   }
1732   if (numtype == 19) {
1733     cType = "LED_GAP";
1734   }
1735 
1736   if (numtype == 20) {
1737     cType = "PHYSICS_LOCAL";
1738   }
1739   if (numtype == 21) {
1740     cType = "COSMICS_LOCAL";
1741   }
1742   if (numtype == 22) {
1743     cType = "HALO_LOCAL";
1744   }
1745   if (numtype == 23) {
1746     cType = "CALIB_LOCAL";
1747   }
1748 
1749   //.......................................... non-CMS types
1750   if (numtype == 24) {
1751     cType = "PEDSIM";
1752   }  // SIMULATION
1753   if (numtype == 25) {
1754     cType = "ANY_RUN";
1755   }  // ANY RUN (ALL TYPES ACCEPTED)
1756 
1757   return cType;
1758 }
1759 
1760 Int_t EcnaAnalyzer::gainvalue(const Int_t &numgain) {
1761   Int_t value = 0;
1762 
1763   if (numgain == 1) {
1764     value = 12;
1765   }
1766   if (numgain == 2) {
1767     value = 6;
1768   }
1769   if (numgain == 3) {
1770     value = 1;
1771   }
1772 
1773   return value;
1774 }