CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/src/EcnaAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EcalCorrelatedNoiseAnalysisModules
00004 // Class:      EcnaAnalyzer
00005 // // class EcnaAnalyzer
00006 // EcnaAnalyzer.cc
00007 // CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/src/EcnaAnalyzer.cc
00008 
00009 // Description: <one line class summary>
00010 
00011 // Implementation:
00012 //     <Notes on implementation>
00013 
00014 //
00015 // Original Author:  Bernard Fabbro
00016 //         Created:  Fri Jun  2 10:27:01 CEST 2006
00017 // $Id: EcnaAnalyzer.cc,v 1.3 2011/10/13 09:02:06 eulisse Exp $
00018 //
00019 //          Update: 02/03/2011  
00020 
00021 // CMSSW include files
00022 
00023 //#include <signal.h>
00024 
00025 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/interface/EcnaAnalyzer.h"
00026 //#include <DataFormats/Provenance/interface/Timestamp.h>
00027 
00028 //--------------------------------------
00029 //  EcnaAnalyzer.cc
00030 //  Class creation: 02 June 2006
00031 //  Documentation: see EcnaAnalyzer.h
00032 //--------------------------------------
00033 //
00034 // constants, enums and typedefs
00035 //
00036 
00037 //
00038 // static data member definitions
00039 //
00040 
00041 //
00042 // constructors and destructor
00043 //
00044 EcnaAnalyzer::EcnaAnalyzer(const edm::ParameterSet& pSet) : 
00045   verbosity_(pSet.getUntrackedParameter("verbosity", 1U)),
00046   nChannels_(0), iEvent_(0)
00047 {
00048   //now do what ever initialization is needed
00049 
00050   using namespace edm;
00051   using namespace std;
00052 
00053   fMyEcnaEBObjectManager = new TEcnaObject();
00054   fMyEcnaEEObjectManager = new TEcnaObject();
00055 
00056   TEcnaParPaths* myPathEB = new TEcnaParPaths(fMyEcnaEBObjectManager);
00057   TEcnaParPaths* myPathEE = new TEcnaParPaths(fMyEcnaEEObjectManager);
00058 
00059   std::cout << "*EcnaAnalyzer-constructor> Check path for resultsq Root files." << endl;
00060 
00061   if( myPathEB->GetPathForResultsRootFiles() == kFALSE )
00062     {
00063       std::cout << "*EcnaAnalyzer-constructor> *** ERROR *** Path for result files not found." << endl;
00064       kill(getpid(),SIGUSR2);
00065     }
00066   else
00067     {
00068       std::cout << "*EcnaAnalyzer-constructor> Path for result files found = " << myPathEB->ResultsRootFilePath() << endl;
00069     }
00070 
00071   if( myPathEE->GetPathForResultsRootFiles() == kFALSE )
00072     {
00073       std::cout << "*EcnaAnalyzer-constructor> *** ERROR *** Path for result files not found." << endl;
00074       kill(getpid(),SIGUSR2);
00075     }
00076   else
00077     {
00078       std::cout << "*EcnaAnalyzer-constructor> Path for result files found = " << myPathEE->ResultsRootFilePath() << endl;
00079     }
00080 
00081 
00082   std::cout << "*EcnaAnalyzer-constructor> Parameter initialization." << endl;
00083 
00084   fgMaxCar = (Int_t)512;
00085   fTTBELL = '\007';
00086   fOutcomeError = kFALSE;
00087 
00088   fMyEBEcal      = new TEcnaParEcal(fMyEcnaEBObjectManager, "EB");
00089   fMyEBNumbering = new TEcnaNumbering(fMyEcnaEBObjectManager, "EB");
00090 
00091   fMyEEEcal      = new TEcnaParEcal(fMyEcnaEEObjectManager, "EE");
00092   fMyEENumbering = new TEcnaNumbering(fMyEcnaEEObjectManager, "EE");
00093 
00094   //========================================================================================== 
00095   //.................................. Get parameter values from python file
00096   eventHeaderProducer_   = pSet.getParameter<std::string>("eventHeaderProducer");
00097   digiProducer_          = pSet.getParameter<std::string>("digiProducer");
00098 
00099   eventHeaderCollection_ = pSet.getParameter<std::string>("eventHeaderCollection");
00100   EBdigiCollection_      = pSet.getParameter<std::string>("EBdigiCollection");
00101   EEdigiCollection_      = pSet.getParameter<std::string>("EEdigiCollection");
00102 
00103   sAnalysisName_  = pSet.getParameter<std::string>("sAnalysisName");
00104   sNbOfSamples_   = pSet.getParameter<std::string>("sNbOfSamples");
00105   sFirstReqEvent_ = pSet.getParameter<std::string>("sFirstReqEvent");
00106   sLastReqEvent_  = pSet.getParameter<std::string>("sLastReqEvent");
00107   sReqNbOfEvts_   = pSet.getParameter<std::string>("sReqNbOfEvts");
00108   sStexName_      = pSet.getParameter<std::string>("sStexName");
00109   sStexNumber_    = pSet.getParameter<std::string>("sStexNumber");
00110 
00111   fAnalysisName  = sAnalysisName_.Data();
00112   fNbOfSamples   = atoi(sNbOfSamples_.Data());
00113   fFirstReqEvent = atoi(sFirstReqEvent_.Data());
00114   fLastReqEvent  = atoi(sLastReqEvent_.Data());
00115   fReqNbOfEvts   = atoi(sReqNbOfEvts_.Data());
00116   fStexName      = sStexName_.Data();
00117   fStexNumber    = atoi(sStexNumber_.Data());
00118 
00119   //------------------------------- ERRORS in requested evts numbers
00120   if( fFirstReqEvent < 1 )
00121     {fOutcomeError = AnalysisOutcome("ERR_FNEG");}
00122 
00123   if( (fLastReqEvent >= fFirstReqEvent) && (fReqNbOfEvts > fLastReqEvent - fFirstReqEvent + 1 ) )
00124     {fOutcomeError = AnalysisOutcome("ERR_LREQ");}
00125 
00126   if( fOutcomeError == kTRUE )return;
00127   //===========================================================================================
00128 
00129   fRunTypeCounter = 0;
00130   fMaxRunTypeCounter = 25;
00131   fRunTypeCounter = new Int_t[fMaxRunTypeCounter];
00132   for(Int_t i=0; i<fMaxRunTypeCounter; i++){fRunTypeCounter[i] = 0;}
00133 
00134   fMgpaGainCounter = 0;
00135   fMaxMgpaGainCounter = 4;  // Because chozen gain = 0,1,2,3
00136   fMgpaGainCounter = new Int_t[fMaxMgpaGainCounter];
00137   for(Int_t i=0; i<fMaxMgpaGainCounter; i++){fMgpaGainCounter[i] = 0;}
00138 
00139   fFedIdCounter = 0;
00140   fMaxFedIdCounter = 54;
00141   fFedIdCounter = new Int_t[fMaxFedIdCounter];
00142   for(Int_t i=0; i<fMaxFedIdCounter; i++){fFedIdCounter[i] = 0;}
00143 
00144   fEvtNumber = 0;
00145   fEvtNumberMemo = -1;
00146   fRecNumber = 0;
00147 
00148   fDeeDS5Memo1 = 0;
00149   fDeeDS5Memo2 = 0;
00150 
00151   fCurrentEventNumber = 0;
00152   fNbOfSelectedEvents = 0;
00153 
00154   fMemoCutOK = 0;
00155   fTreatedFedOrder = 0;
00156   fNbOfTreatedStexs = 0;
00157 
00158   //-------------- Fed
00159   if( fStexName == "SM"  ){fMaxFedUnitCounter = fMyEBEcal->MaxSMInEB();}  // EB: FED Unit = SM
00160   if( fStexName == "Dee" ){fMaxFedUnitCounter = fMyEEEcal->MaxDSInEE();}  // EE: FED Unit = Data Sector
00161 
00162   fFedDigiOK = new Int_t[fMaxFedUnitCounter];
00163   for(Int_t i=0; i<fMaxFedUnitCounter; i++){fFedDigiOK[i] = 0;}
00164 
00165   fFedNbOfTreatedEvents = new Int_t[fMaxFedUnitCounter];
00166   for(Int_t i=0; i<fMaxFedUnitCounter; i++){fFedNbOfTreatedEvents[i] = 0;}
00167 
00168   fFedStatus = new Int_t[fMaxFedUnitCounter];
00169   for(Int_t i=0; i<fMaxFedUnitCounter; i++){fFedStatus[i] = 0;}
00170 
00171   fFedStatusOrder = new Int_t[fMaxFedUnitCounter];
00172   for(Int_t i=0; i<fMaxFedUnitCounter; i++){fFedStatusOrder[i] = 0;}
00173 
00174   fDeeNumberString = new TString[fMaxFedUnitCounter];
00175   for(Int_t i=0; i<fMaxFedUnitCounter; i++){fDeeNumberString[i] = "SM";}
00176 
00177   if( fStexName == "Dee" )
00178     { 
00179       fDeeNumberString[ 0] = "Sector1 Dee4";
00180       fDeeNumberString[ 1] = "Sector2 Dee4";
00181       fDeeNumberString[ 2] = "Sector3 Dee4";
00182       fDeeNumberString[ 3] = "Sector4 Dee4";
00183       fDeeNumberString[ 4] = "Sector5 Dee4-Dee3";
00184       fDeeNumberString[ 5] = "Sector6 Dee3";
00185       fDeeNumberString[ 6] = "Sector7 Dee3";
00186       fDeeNumberString[ 7] = "Sector8 Dee3";
00187       fDeeNumberString[ 8] = "Sector9 Dee3";
00188       fDeeNumberString[ 9] = "Sector1 Dee1";
00189       fDeeNumberString[10] = "Sector2 Dee1";
00190       fDeeNumberString[11] = "Sector3 Dee1";
00191       fDeeNumberString[12] = "Sector4 Dee1";
00192       fDeeNumberString[13] = "Sector5 Dee1-Dee2";
00193       fDeeNumberString[14] = "Sector6 Dee2";
00194       fDeeNumberString[15] = "Sector7 Dee2";
00195       fDeeNumberString[16] = "Sector8 Dee2";
00196       fDeeNumberString[17] = "Sector9 Dee2";
00197     }
00198   //............................... arrays fSMFromFedDcc and fESFromFedTcc
00199   //
00200   //  FED-TCC:   1   2   3   4   5   6   7   8   9
00201   //      Dee:   3   3   3   4   4   4   4  4-3  3
00202   //       DS:   7   8   9   1   2   3   4   5   6
00203   //       ES:   7   8   9   1   2   3   4   5   6  (ES = DS)
00204   //
00205   //  FED-TCC:  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27
00206   //       SM:  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
00207   //       SM:  -1  -2  -3  -4  -5  -6  -7  -8  -9 -10 -11 -12 -13 -14 -15 -16 -17 -18
00208   //
00209   //  FED-TCC:  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45
00210   //       SM:   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
00211   //
00212   //  FED-TCC:  46  47  48  49  50  51  52  53  54
00213   //      Dee:   2   2   2   1   1   1   1  1-2  2
00214   //       DS:   7   8   9   1   2   3   4   5   6
00215   //       ES:  16  17  18  10  11  12  13  14  15  (ES = DS + 9)
00216   
00217   Int_t MaxSMAndDS = fMyEBEcal->MaxSMInEB()+fMyEEEcal->MaxDSInEE();
00218 
00219   fSMFromFedTcc = new Int_t[MaxSMAndDS];
00220   fESFromFedTcc = new Int_t[MaxSMAndDS];
00221   for(Int_t nFedTcc= 1; nFedTcc<=MaxSMAndDS; nFedTcc++){fESFromFedTcc[nFedTcc-1] = -1;}
00222 
00223   for(Int_t nFedTcc= 1;nFedTcc<= 3;nFedTcc++){fESFromFedTcc[nFedTcc-1]=nFedTcc+ 6;} // Dee3, ES 7,8,9
00224   for(Int_t nFedTcc= 4;nFedTcc<= 9;nFedTcc++){fESFromFedTcc[nFedTcc-1]=nFedTcc- 3;} // Dee4, ES 1,2,3,4,5; Dee3, DS 5,6
00225 
00226   for(Int_t nFedTcc=10;nFedTcc<=27;nFedTcc++){fSMFromFedTcc[nFedTcc-1]=nFedTcc+ 9;} // EB-  SM 19 to 36
00227   for(Int_t nFedTcc=28;nFedTcc<=45;nFedTcc++){fSMFromFedTcc[nFedTcc-1]=nFedTcc-27;} // EB+  SM  1 to 18
00228 
00229   for(Int_t nFedTcc=46;nFedTcc<=48;nFedTcc++){fESFromFedTcc[nFedTcc-1]=nFedTcc-30;} // Dee2, ES 16,17,18
00230   for(Int_t nFedTcc=49;nFedTcc<=54;nFedTcc++){fESFromFedTcc[nFedTcc-1]=nFedTcc-39;} // Dee1, ES 10,11,12,13,14; Dee2, ES 14,15
00231 
00232   //............................... Nb of treated events for "AdcPeg12" and "AdcSPeg12" analysis
00233   //-------------- Stex
00234   if( fStexName == "SM"  ){fMaxTreatedStexCounter = fMyEBEcal->MaxSMInEB();}  // EB: Stex = SM
00235   if( fStexName == "Dee" ){fMaxTreatedStexCounter = fMyEEEcal->MaxDeeInEE();} // EE: Stex = Dee
00236 
00237   fStexNbOfTreatedEvents = new Int_t[fMaxTreatedStexCounter];
00238   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fStexNbOfTreatedEvents[i] = 0;}
00239 
00240   fTimeFirst = new time_t[fMaxTreatedStexCounter];
00241   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fTimeFirst[i] = 0;}
00242   fTimeLast = new time_t[fMaxTreatedStexCounter];
00243   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fTimeLast[i] = 0;}
00244 
00245   fMemoDateFirstEvent = new Int_t[fMaxTreatedStexCounter];;
00246   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fMemoDateFirstEvent[i] = 0;}
00247 
00248   Int_t MaxCar = fgMaxCar; 
00249   fDateFirst = new TString[fMaxTreatedStexCounter];
00250   for(Int_t i=0; i<fMaxTreatedStexCounter; i++)
00251     {
00252       fDateFirst[i].Resize(MaxCar);
00253       fDateFirst[i] = "*1st event date not found*";
00254     }
00255 
00256   MaxCar = fgMaxCar; 
00257   fDateLast = new TString[fMaxTreatedStexCounter];
00258   for(Int_t i=0; i<fMaxTreatedStexCounter; i++)
00259     {
00260       fDateLast[i].Resize(MaxCar);
00261       fDateLast[i] = "*last event date not found*";
00262     }
00263 
00264   fStexStatus = new Int_t[fMaxTreatedStexCounter];
00265   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fStexStatus[i] = 0;}
00266 
00267   fStexDigiOK = new Int_t[fMaxTreatedStexCounter];
00268   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fStexDigiOK[i] = 0;}
00269 
00270   fNbOfTreatedFedsInDee = new Int_t[fMaxTreatedStexCounter];
00271   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fNbOfTreatedFedsInDee[i] = 0;}
00272 
00273   fNbOfTreatedFedsInStex = new Int_t[fMaxTreatedStexCounter];
00274   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fNbOfTreatedFedsInStex[i] = 0;}
00275 
00276 
00277   //.......................... counters of events for GetSampleAdcValues
00278   fBuildEventDistribBad = 0;
00279   fBuildEventDistribBad = new Int_t[fMaxTreatedStexCounter];
00280   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fBuildEventDistribBad[i] = 0;}
00281 
00282   fBuildEventDistribGood = 0;
00283   fBuildEventDistribGood = new Int_t[fMaxTreatedStexCounter];
00284   for(Int_t i=0; i<fMaxTreatedStexCounter; i++){fBuildEventDistribGood[i] = 0;}
00285 
00286   //----------------------------------- Analysis name codes ------------------------------------------
00287   //   
00288   //                  AnalysisName  RunType         Gain    DBLS (Dynamic BaseLine Substraction)
00289   //
00290   //                  AdcPed1       fPEDESTAL_STD      3    No
00291   //                  AdcPed6       fPEDESTAL_STD      2    No
00292   //                  AdcPed12      fPEDESTAL_STD      1    No
00293   //
00294   //                  AdcPeg12      fPEDESTAL_GAP      1    No
00295   //
00296   //                  AdcLaser      fLASER_STD         0    No
00297   //                  AdcPes12      fPEDSIM            0    No
00298   //
00299   //
00300   //                  AdcSPed1      fPEDESTAL_STD      3    Yes
00301   //                  AdcSPed6      fPEDESTAL_STD      2    Yes
00302   //                  AdcSPed12     fPEDESTAL_STD      1    Yes
00303   //
00304   //                  AdcSPeg12     fPEDESTAL_GAP      1    Yes
00305   //
00306   //                  AdcSLaser     fLASER_STD         0    Yes
00307   //                  AdcSPes12     fPEDSIM            0    Yes
00308   //
00309   //--------------------------------------------------------------------------------------------------
00310 
00311   //................ Run type list
00312   fLASER_STD    =  4;
00313   fPEDESTAL_STD =  9;
00314   fPEDESTAL_GAP = 18;
00315   fPEDSIM       = 24;
00316  
00317   //................ Chozen run type from analysis name
00318   fChozenRunTypeNumber = fPEDESTAL_STD;   // default
00319   if( fAnalysisName == "AdcPed1"  || fAnalysisName == "AdcPed6"  || fAnalysisName == "AdcPed12" ||
00320       fAnalysisName == "AdcSPed1" || fAnalysisName == "AdcSPed6" || fAnalysisName == "AdcSPed12" )
00321     {fChozenRunTypeNumber = fPEDESTAL_STD;}
00322   if( fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" )
00323     {fChozenRunTypeNumber = fPEDESTAL_GAP;}
00324   if( fAnalysisName == "AdcLaser"  || fAnalysisName == "AdcSLaser"  ){fChozenRunTypeNumber = fLASER_STD;}
00325   if( fAnalysisName == "AdcPes12 " || fAnalysisName == "AdcSPes12 " ){fChozenRunTypeNumber = fPEDSIM;}
00326 
00327   //................ Gains from analysis name
00328   fChozenGainNumber = 0;   // default => event always accepted if fChozenGainNumber = 0 ( see USER's Analysis cut in ::analyze(...) )
00329   if( fAnalysisName == "AdcPed1"   || fAnalysisName == "AdcSPed1"  ){fChozenGainNumber = 3;}
00330   if( fAnalysisName == "AdcPed6"   || fAnalysisName == "AdcSPed6"  ){fChozenGainNumber = 2;}
00331   if( fAnalysisName == "AdcPed12"  || fAnalysisName == "AdcSPed12" ){fChozenGainNumber = 1;}
00332   if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" ){fChozenGainNumber = 0;}
00333   if( fAnalysisName == "AdcLaser"  || fAnalysisName == "AdcSLaser" ){fChozenGainNumber = 0;}
00334   if( fAnalysisName == "AdcPes12 " || fAnalysisName == "AdcSPes12 "){fChozenGainNumber = 0;}
00335 
00336   //............... Flag for Dynamic BaseLine Substraction from analysis name
00337   fDynBaseLineSub = "no";   // default
00338   if( fAnalysisName == "AdcPed1"   || fAnalysisName == "AdcPed6"  || fAnalysisName == "AdcPed12" ||
00339       fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcLaser" || fAnalysisName == "AdcPes12 " )
00340     {fDynBaseLineSub = "no";}
00341   if( fAnalysisName == "AdcSPed1"  || fAnalysisName == "AdcSPed6"  || fAnalysisName == "AdcSPed12" ||
00342       fAnalysisName == "AdcSPeg12" || fAnalysisName == "AdcSLaser" || fAnalysisName == "AdcSPes12 " )
00343     {fDynBaseLineSub = "yes";}
00344 
00345   //....................... Index range for ECNA init and for loop on GetSampleAdcValues calls
00346   if( fStexNumber == 0 )
00347     {
00348       if( fStexName == "SM"  )
00349         {
00350           fSMIndexBegin   = 0;             fSMIndexStop   = fMyEBEcal->MaxSMInEB();
00351           fStexIndexBegin = fSMIndexBegin; fStexIndexStop = fSMIndexStop;
00352           fDeeIndexBegin  = 0;             fDeeIndexStop  = 0;
00353         }
00354       if( fStexName == "Dee"  )
00355         {
00356           fSMIndexBegin   = 0;              fSMIndexStop   = 0;
00357           fDeeIndexBegin  = 0;              fDeeIndexStop  = fMyEEEcal->MaxDeeInEE();
00358           fStexIndexBegin = fDeeIndexBegin; fStexIndexStop = fDeeIndexStop;
00359         }
00360     }
00361   else
00362     {
00363       if( fStexName == "SM"  )
00364         {
00365           fSMIndexBegin   = fStexNumber-1; fSMIndexStop   = fStexNumber;
00366           fStexIndexBegin = fSMIndexBegin; fStexIndexStop = fSMIndexStop;
00367           fDeeIndexBegin  = 0;             fDeeIndexStop  = 0;
00368         }
00369       if( fStexName == "Dee" )
00370         {
00371           fSMIndexBegin   = 0;              fSMIndexStop   = 0;
00372           fDeeIndexBegin  = fStexNumber-1;  fDeeIndexStop  = fStexNumber;
00373           fStexIndexBegin = fDeeIndexBegin; fStexIndexStop = fDeeIndexStop;
00374         }
00375     }
00376 
00377   //......... DATA DEPENDENT PARAMETERS
00378   fRunNumber  = 0;
00379 
00380   fMyCnaEBSM  = 0;
00381   fMyCnaEEDee = 0;
00382 
00383   fRunTypeNumber  = -1;
00384   fMgpaGainNumber = -1;
00385 
00386   fFedId  = -1;
00387   fFedTcc = -1;
00388 
00389   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fAnalysisName        = " << fAnalysisName << endl;
00390   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fNbOfSamples         = " << fNbOfSamples << endl;
00391   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fFirstReqEvent       = " << fFirstReqEvent << endl;
00392   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fLastReqEvent        = " << fLastReqEvent << endl;
00393   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fReqNbOfEvts         = " << fReqNbOfEvts << endl;
00394   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fStexName            = " << fStexName << endl;
00395   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fStexNumber          = " << fStexNumber << endl;
00396   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fChozenRunTypeNumber = " << fChozenRunTypeNumber << endl;
00397   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> fChozenGainNumber    = " << fChozenGainNumber  << endl << endl;
00398 
00399   std::cout << "*EcnaAnalyzer::EcnaAnalyzer-constructor> Init done. " << endl;
00400 }
00401 // end of constructor
00402 
00403 EcnaAnalyzer::~EcnaAnalyzer()
00404 {
00405   // do anything here that needs to be done at destruction time
00406   // (e.g. close files, deallocate resources etc.)
00407 
00408   using namespace std;
00409   //..................................... format numerical values
00410   cout << setiosflags(ios::showpoint | ios::uppercase);
00411   cout << setprecision(3) << setw(6);
00412   cout.setf(ios::dec, ios::basefield);
00413   cout.setf(ios::fixed, ios::floatfield);
00414   cout.setf(ios::left, ios::adjustfield);
00415   cout.setf(ios::right, ios::adjustfield);
00416 
00417   std::cout << "EcnaAnalyzer::~EcnaAnalyzer()> destructor is going to be executed." << endl;
00418 
00419   if( fOutcomeError == kTRUE )return;
00420 
00421   //-------------------------------------------------------------------------------
00422 
00423   //....................................................... EB (SM)
00424   if( fMyCnaEBSM == 0 && fStexName == "SM" )
00425     {
00426       std::cout << endl << "!EcnaAnalyzer-destructor> **** ERROR **** fMyCnaEBSM = " << fMyCnaEBSM
00427                 << ". !===> ECNA HAS NOT BEEN INITIALIZED. Last event run type = " << runtype(fRunTypeNumber)
00428                 << ", last event fFedId(+601) = " << fFedId+601 << endl 
00429                 << ", last event Mgpa gain = " << gainvalue(fMgpaGainNumber) << endl << endl;
00430     }
00431   else
00432     {
00433       for(Int_t iSM = fSMIndexBegin; iSM < fSMIndexStop; iSM++)
00434         {
00435           if( fMyCnaEBSM[iSM] != 0 )
00436             {
00437               //........................................ register dates 1 and 2
00438               fMyCnaEBSM[iSM]->StartStopDate(fDateFirst[iSM], fDateLast[iSM]);
00439               fMyCnaEBSM[iSM]->StartStopTime(fTimeFirst[iSM], fTimeLast[iSM]);
00440               
00441               //........................................ Init .root file
00442               fMyCnaEBSM[iSM]->GetReadyToCompute();
00443               fMyCnaEBSM[iSM]->SampleValues();
00444               
00445               //........................................ write the sample values in .root file
00446               if( fMyCnaEBSM[iSM]->WriteRootFile() == kFALSE )
00447                 {
00448                   std::cout << "!EcnaAnalyzer-destructor> PROBLEM with write ROOT file for SM" << iSM+1
00449                             << fTTBELL << endl;
00450                 }
00451             }
00452           else
00453             {
00454               std::cout << "*EcnaAnalyzer-destructor> Calculations and writing on file already done for SM "
00455                         << iSM+1 << endl;
00456             }
00457         }
00458       delete fMyCnaEBSM;
00459     }
00460   //....................................................... EE (Dee)
00461 
00462   if( fMyCnaEEDee == 0 && fStexName == "Dee" )
00463     {
00464       std::cout << endl << "!EcnaAnalyzer-destructor> **** ERROR **** fMyCnaEEDee = " << fMyCnaEEDee
00465                 << ". !===> ECNA HAS NOT BEEN INITIALIZED. Last event run type = " << runtype(fRunTypeNumber)
00466                 << ", last event fFedId(+601) = " << fFedId+601 << endl 
00467                 << ", last event Mgpa gain = " << gainvalue(fMgpaGainNumber) << endl << endl;
00468     }
00469   else
00470     {
00471       for(Int_t iDee = fDeeIndexBegin; iDee < fDeeIndexStop; iDee++)
00472         {
00473           if( fMyCnaEEDee[iDee] != 0 )
00474             {
00475               //........................................ register dates 1 and 2
00476               fMyCnaEEDee[iDee]->StartStopDate(fDateFirst[iDee], fDateLast[iDee]);
00477               fMyCnaEEDee[iDee]->StartStopTime(fTimeFirst[iDee], fTimeLast[iDee]);
00478               
00479               //........................................ Init .root file
00480               fMyCnaEEDee[iDee]->GetReadyToCompute();
00481               fMyCnaEEDee[iDee]->SampleValues();
00482               
00483               //........................................ write the sample values in .root file
00484               if(fMyCnaEEDee[iDee]->WriteRootFile() == kFALSE )
00485                 {
00486                   std::cout << "!EcnaAnalyzer-destructor> PROBLEM with write ROOT file for Dee" << iDee+1
00487                             << fTTBELL << endl;
00488                 }
00489             }
00490           else
00491             {
00492               std::cout << "*EcnaAnalyzer-destructor> Calculations and writing on file already done for Dee "
00493                         << iDee+1 << endl;
00494             }
00495         }
00496       delete fMyCnaEEDee;
00497     }
00498   std::cout <<endl;
00499 
00500   //-----------------------------------------------------------------------------------
00501 
00502   std::cout << "*EcnaAnalyzer-destructor> Status of events returned by GetSampleAdcValues(): "
00503             << endl;
00504 
00505   for(Int_t i0Stex=fStexIndexBegin; i0Stex<fStexIndexStop; i0Stex++ )
00506     {
00507       std::cout << fStexName << i0Stex+1 << "> Status OK: " << fBuildEventDistribGood[i0Stex]
00508                 << " / ERROR(S): " << fBuildEventDistribBad[i0Stex];
00509       if( fBuildEventDistribBad[i0Stex] > 0 )
00510         {std::cout << " <=== SHOULD BE EQUAL TO ZERO ! " << fTTBELL;}
00511       std::cout << endl;
00512     }
00513 
00514   std::cout << endl<< "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " <<  endl;
00515   
00516   std::cout << "*EcnaAnalyzer-destructor> Run types seen in event headers before selection:" << endl;
00517 
00518   for(Int_t i=0; i<fMaxRunTypeCounter; i++)
00519     {
00520       std::cout << " => " << setw(10) << fRunTypeCounter[i]
00521                 << " event header(s) with run type " << runtype(i) << endl; 
00522     }
00523 
00524   std::cout << endl<< "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " <<  endl;
00525 
00526   std::cout << "*EcnaAnalyzer-destructor> Mgpa gains seen in event headers before selection:" << endl;
00527 
00528   for(Int_t i=0; i<fMaxMgpaGainCounter; i++)
00529     {
00530       std::cout << " => " << setw(10) << fMgpaGainCounter[i]
00531                 << " event header(s) with gain " << gainvalue(i) << endl; 
00532     }
00533 
00534   std::cout << endl<< "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " <<  endl;
00535 
00536   std::cout << "*EcnaAnalyzer-destructor> Numbers of selected events for each FED:" << endl;
00537 
00538   for(Int_t i=0; i<fMaxFedIdCounter; i++)
00539     {
00540           std::cout << " => FedId " << i+601 << ": "
00541                     << setw(10) << fFedIdCounter[i] << " events" << endl;
00542     }
00543 
00544   std::cout << endl<< "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " <<  endl;
00545 
00546   if( fStexNumber == 0 )
00547     {
00548       // std::cout << "*EcnaAnalyzer-destructor> fDateFirst = " << fDateFirst[0] << endl
00549       //           << "                          fDateLast  = " << fDateLast[fMaxTreatedStexCounter-1] << endl << endl;
00550     }
00551   if( fStexNumber > 0 )
00552     {
00553       std::cout << "*EcnaAnalyzer-destructor> fDateFirst = " << fDateFirst[fStexNumber-1] << endl
00554                 << "                          fDateLast  = " << fDateLast[fStexNumber-1] << endl << endl;
00555     }
00556 
00557   std::cout << endl<< "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " <<  endl;
00558 
00559   Int_t n0 =0; CheckMsg(n0);
00560 
00561   delete fMyEBNumbering;
00562   delete fMyEENumbering;
00563 
00564   delete fMyEBEcal;
00565   delete fMyEEEcal;
00566 
00567   std::cout << "*EcnaAnalyzer-destructor> End of execution." << endl;
00568 }
00569 // end of destructor
00570 
00571 
00572 //
00573 // member functions
00574 //
00575 
00576 // ------------ method called to produce the data  ------------
00577 void EcnaAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00578 {
00579   using namespace std;
00580   //..................................... format numerical values
00581   cout << setiosflags(ios::showpoint | ios::uppercase);
00582   cout << setprecision(3) << setw(6);
00583   cout.setf(ios::dec, ios::basefield);
00584   cout.setf(ios::fixed, ios::floatfield);
00585   cout.setf(ios::left, ios::adjustfield);
00586   cout.setf(ios::right, ios::adjustfield);
00587 
00588   using namespace edm;
00589 
00590   fRecNumber++; 
00591 
00592   Int_t iFreq = (fLastReqEvent - fFirstReqEvent + 1)/5;
00593   if( iFreq <= 0 ){iFreq = 10000;}
00594 
00595   Int_t MaxSMAndDS = fMyEBEcal->MaxSMInEB()+fMyEEEcal->MaxDSInEE();
00596 
00597   //********************************************* EVENT TREATMENT ********************************
00598   Handle<EcalRawDataCollection> pEventHeader;
00599   const EcalRawDataCollection* myEventHeader = 0;
00600   try{
00601     iEvent.getByLabel(eventHeaderProducer_, eventHeaderCollection_, pEventHeader);
00602     myEventHeader = pEventHeader.product();
00603   }catch (std::exception& ex ){
00604     std::cerr << "Error! can't get the product " << eventHeaderCollection_.c_str() << std::endl;
00605   }
00606   //........... Decode myEventHeader infos
00607   for(EcalRawDataCollection::const_iterator headerItr=myEventHeader->begin();
00608       headerItr != myEventHeader->end();++headerItr)
00609     {
00610       //===> fRunNumber, fRunTypeNumber, fMgpaGainNumber, fFedId, fEvtNumber
00611       //     will be used in AnalysisOutcome(...) below
00612       fRunNumber = (Int_t)headerItr->getRunNumber();
00613       if( fRunNumber <= 0 ){fRunNumber = (Int_t)iEvent.id().run();}
00614       fRunTypeNumber  = (Int_t)headerItr->getRunType();
00615       fMgpaGainNumber = (Int_t)headerItr->getMgpaGain();
00616       fFedId = (Int_t)headerItr->fedId() - 601;   // 1st Fed = 601, FedId = Fed number - 1 
00617       fEvtNumber = (Int_t)headerItr->getLV1(); 
00618       if( fEvtNumber <= 0 ){fEvtNumber = (Int_t)iEvent.id().event();}
00619 
00620       if( fEvtNumber != fEvtNumberMemo )
00621         {
00622           fEvtNumberMemo = fEvtNumber;
00623 
00624           //============================================
00625           //  cmsRun INTERRUPTION if analysis complete
00626           //  or if fCurrentEventNumber >= LastReqEvent
00627           //============================================
00628           if( AnalysisOutcome("EVT") == kTRUE ){return;}
00629 
00630           // no interruption => event has to be analyzed
00631 
00632           fCurrentEventNumber++;
00633 
00634           if( fRecNumber ==   1 || fRecNumber ==   50 || fRecNumber == 100 ||
00635               fRecNumber == 500 || fRecNumber == 1000 || fRecNumber%iFreq == 0 ){Int_t n1 =1; CheckMsg(n1);}
00636   
00637           if( fCurrentEventNumber < fFirstReqEvent )return; // skip events before fFirstReqEvent
00638         }
00639 
00640       //.................. Increment Run type and MgpaGain counters
00641       if( fRunTypeNumber  >= 0 && fRunTypeNumber  < fMaxRunTypeCounter  ){fRunTypeCounter[fRunTypeNumber]++;}
00642       if( fMgpaGainNumber >= 0 && fMgpaGainNumber < fMaxMgpaGainCounter ){fMgpaGainCounter[fMgpaGainNumber]++;}
00643 
00644       //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User's analysis cut %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00645       
00646       if( !(
00647             fRunNumber > 0 &&
00648             fRunTypeNumber == fChozenRunTypeNumber &&
00649             ( fMgpaGainNumber == fChozenGainNumber || fChozenGainNumber == 0 )
00650             )
00651           ) return;
00652       
00653       //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00654 
00655       if( fMemoCutOK == 0 ){fMemoCutOK = 1;}
00656 
00657       //---- Accelerating selection with "FED-TCC" number [ from headerItr->getDccInTCCCommand() ]
00658       //     Arrays fSMFromFedTcc[] and fESFromFedTcc[] are initialised in Init()
00659 
00660       if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" )
00661         {
00662           fFedTcc = (Int_t)headerItr->getDccInTCCCommand();
00663 
00664           if( fFedTcc >= 1 && fFedTcc <= MaxSMAndDS )
00665             {
00666               if( fStexName == "SM" )
00667                 {
00668                   if( fFedTcc < 10 || fFedTcc > 45 )return;
00669                   
00670                   if( fSMFromFedTcc[fFedTcc-1] >= 1 && fSMFromFedTcc[fFedTcc-1] <= fMyEBEcal->MaxSMInEB() &&
00671                       fStexNbOfTreatedEvents[fSMFromFedTcc[fFedTcc-1]-1] >= fReqNbOfEvts )return;
00672                 }
00673               
00674               if( fStexName == "Dee" )
00675                 {
00676                   if( fFedTcc >= 10 && fFedTcc <= 45 )return;
00677                   
00678                   if( fESFromFedTcc[fFedTcc-1] >= 1 && fESFromFedTcc[fFedTcc-1] <= fMyEEEcal->MaxDSInEE() &&
00679                       fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] >= fReqNbOfEvts )return;
00680                 }
00681             } // end of if( fFedTcc >= 1 && fFedTcc <= MaxSMAndDS )
00682         } // end of if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" )
00683       
00684       //.................. Increment FedId counters     
00685       if( fFedId >= 0 && fFedId < fMaxFedIdCounter ){fFedIdCounter[fFedId]++;}
00686       
00687     } // end of for(EcalRawDataCollection::const_iterator headerItr=myEventHeader->begin();
00688       // headerItr != myEventHeader->end();++headerItr)
00689   
00690   if( fMemoCutOK == 0 )return;   // return if no event passed the user's analysis cut
00691 
00692   //========================== SELECTED EVENTS ================================
00693   fNbOfSelectedEvents++;
00694   if( fNbOfSelectedEvents == 1 ){Int_t n2 = 2; CheckMsg(n2);}
00695 
00696   //============================ Ecna init for the pointers array =================================
00697   //.................................................................. EB (SM)
00698   if( fMyCnaEBSM == 0 && fStexName == "SM" )
00699     {
00700       fMyCnaEBSM = new TEcnaRun*[fMyEBEcal->MaxSMInEB()];
00701       for(Int_t i0SM = 0; i0SM < fMyEBEcal->MaxSMInEB(); i0SM++)
00702         {fMyCnaEBSM[i0SM] = 0;}
00703     }
00704   //.................................................................. EE (Dee)
00705   if( fMyCnaEEDee == 0 && fStexName == "Dee" )
00706     {
00707       fMyCnaEEDee = new TEcnaRun*[fMyEEEcal->MaxDeeInEE()];
00708       for(Int_t iDee = 0; iDee < fMyEEEcal->MaxDeeInEE(); iDee++)
00709         {fMyCnaEEDee[iDee] = 0;}
00710     }
00711   
00712   //============================ EVENT TREATMENT ==============================
00713   Int_t MaxNbOfStex = 0;
00714   if( fStexName == "SM"  ){MaxNbOfStex = fMyEBEcal->MaxSMInEB();}
00715   if( fStexName == "Dee" ){MaxNbOfStex = fMyEEEcal->MaxDeeInEE();}
00716 
00717   if( (fStexNumber > 0 && fNbOfTreatedStexs == 0) || (fStexNumber == 0 && fNbOfTreatedStexs < MaxNbOfStex) )
00718     {
00719       //================================================================= Record type EB (SM)
00720       if( fStexName == "SM" && fSMIndexBegin < fSMIndexStop )
00721         {
00722           //......................................... Get digisEB
00723           Handle<EBDigiCollection> pdigisEB;
00724           const EBDigiCollection* digisEB = 0;
00725           try{
00726             iEvent.getByLabel(digiProducer_, EBdigiCollection_, pdigisEB); 
00727             digisEB = pdigisEB.product();
00728           }catch (std::exception& ex ){
00729             std::cerr << "Error! can't get the product " << EBdigiCollection_.c_str() << std::endl;
00730           }
00731           
00732           // Initialize vectors if not already done
00733           if ( int(digisEB->size()) > nChannels_ ){nChannels_ = digisEB->size();}
00734           
00735           //Int_t print_count = 0;
00736           if( Int_t(digisEB->end()-digisEB->begin()) >= 0 &&
00737               Int_t(digisEB->end()-digisEB->begin()) <=  Int_t(digisEB->size()) )
00738             {
00739               //..........................................EB
00740               //===============================================================================
00741               //
00742               //                    Loop over Ecal barrel digisEB (Xtals)
00743               //
00744               //===============================================================================
00745 
00746               for(EBDigiCollection::const_iterator digiItr = digisEB->begin(); digiItr != digisEB->end(); ++digiItr)
00747                 {
00748                   EBDetId id_crystal(digiItr->id());
00749                   // Int_t HashedIndex = id_crystal.hashedIndex();
00750                   
00751                   Int_t i0SM = id_crystal.ism() - 1;    //   <============== GET the SM number - 1 here
00752                   
00753                   if( i0SM >= 0 && i0SM<fMaxTreatedStexCounter )
00754                     {
00755                       if( fMyCnaEBSM[i0SM] == 0 && fStexStatus[i0SM] != 2 )
00756                         {
00757                           //=============================== Init Ecna EB ===============================
00758                           fMyCnaEBSM[i0SM] = new TEcnaRun(fMyEcnaEBObjectManager, "EB", fNbOfSamples);
00759                           fMyCnaEBSM[i0SM]->GetReadyToReadData(fAnalysisName,  fRunNumber,
00760                                                                fFirstReqEvent, fLastReqEvent, fReqNbOfEvts,
00761                                                                i0SM+1,         fRunTypeNumber);
00762                       
00763                           std::cout << "*EcnaAnalyzer::analyze(...)> ********* INIT ECNA EB ********* " << endl
00764                                     << "                                   fAnalysisName = " << fAnalysisName << endl
00765                                     << "                                      fRunNumber = " << fRunNumber << endl
00766                                     << "                                  fFirstReqEvent = " << fFirstReqEvent << endl
00767                                     << "                                   fLastReqEvent = " << fLastReqEvent << endl
00768                                     << "                                    fReqNbOfEvts = " << fReqNbOfEvts << endl
00769                                     << "                                              SM = " << i0SM+1 << endl
00770                                     << "                                        run type = " << runtype(fRunTypeNumber)
00771                                     << endl;
00772                           //============================================================================
00773                         }
00774                       
00775                       if( fStexStatus[i0SM] < 2 )  // nothing to do if status=2 reached
00776                         {
00777                           fStexDigiOK[i0SM]++;
00778                           if( fStexDigiOK[i0SM] == 1 ){fStexNbOfTreatedEvents[i0SM]++;}
00779                           
00780                           if( fStexNbOfTreatedEvents[i0SM] >= 1 && fStexNbOfTreatedEvents[i0SM] <= fReqNbOfEvts )
00781                             {
00782                               //......................................... date of first event (in real time)
00783                               edm::Timestamp Time = iEvent.time();
00784                               edm::TimeValue_t t_current_ev_time = (cond::Time_t)Time.value();
00785                               time_t         i_current_ev_time = (time_t)(t_current_ev_time>>32);
00786                               const time_t*  p_current_ev_time = &i_current_ev_time;
00787                               char*          astime            = ctime(p_current_ev_time);
00788 
00789                               if( fStexDigiOK[i0SM] == 1 && fStexNbOfTreatedEvents[i0SM] == 1 &&
00790                                   ( fStexNumber == 0 || i0SM+1 == fStexNumber )
00791                                   )
00792                                 {
00793                                   fTimeFirst[i0SM] = i_current_ev_time;
00794                                   fDateFirst[i0SM] = astime;
00795                                   fTimeLast[i0SM]  = i_current_ev_time;
00796                                   fDateLast[i0SM]  = astime;
00797                                   std::cout << "*----> beginning of analysis for " << fStexName << i0SM+1
00798                                             << ". First analyzed event date : " << astime << endl;
00799                                   //      << " t_current_ev_time = " << t_current_ev_time  << endl
00800                                   //      << " i_current_ev_time = " << i_current_ev_time  << endl
00801                                   //      << " p_current_ev_time = " << p_current_ev_time  << endl
00802                                 }
00803 
00804                               if( i_current_ev_time < fTimeFirst[i0SM] )
00805                                 { fTimeFirst[i0SM] = i_current_ev_time; fDateFirst[i0SM] = astime;}
00806                               if( i_current_ev_time > fTimeLast[i0SM] )
00807                                 { fTimeLast[i0SM] = i_current_ev_time; fDateLast[i0SM] = astime;}
00808                               
00809                               //=============================================> CUT on i0SM value
00810                               if( (fStexNumber > 0 && i0SM == fStexNumber-1) || (fStexNumber == 0) )
00811                                 { 
00812                                   Int_t iEta = id_crystal.ietaSM(); // ietaSM() : range = [1,85]
00813                                   Int_t iPhi = id_crystal.iphiSM(); // iphiSM() : range = [1,20]
00814                                   
00815                                   Int_t n1SMCrys  =
00816                                     (iEta-1)*(fMyEBEcal->MaxTowPhiInSM()*fMyEBEcal->MaxCrysPhiInTow())+iPhi; // range = [1,1700]
00817                                   Int_t n1SMTow   = fMyEBNumbering->Get1SMTowFrom1SMCrys(n1SMCrys);          // range = [1,68]
00818                                   Int_t i0TowEcha = fMyEBNumbering->Get0TowEchaFrom1SMCrys(n1SMCrys);        // range = [0,24]
00819                                   
00820                                   Int_t NbOfSamplesFromDigis = digiItr->size();
00821                                   
00822                                   EBDataFrame df( *digiItr );
00823                                   
00824                                   if( NbOfSamplesFromDigis > 0 && NbOfSamplesFromDigis <= fMyEBEcal->MaxSampADC() )
00825                                     {
00826                                       Double_t adcDBLS = (Double_t)0;
00827                                       // Three 1st samples mean value for Dynamic Base Line Substraction (DBLS)
00828                                       if( fDynBaseLineSub == "yes" )
00829                                         {
00830                                           for (Int_t i0Sample=0; i0Sample<3; i0Sample++)  
00831                                             {adcDBLS += (Double_t)(df.sample(i0Sample).adc());}
00832                                           adcDBLS /= (Double_t)3;
00833                                         }
00834                                       // Loop over the samples
00835                                       for (Int_t i0Sample=0; i0Sample<fNbOfSamples; i0Sample++)  
00836                                         {
00837                                           Double_t adc = (Double_t)(df.sample(i0Sample).adc()) - adcDBLS;
00838                                           //................................................. Calls to GetSampleAdcValues
00839                                           if( fMyCnaEBSM[i0SM]->GetSampleAdcValues
00840                                               (fStexNbOfTreatedEvents[i0SM],n1SMTow,i0TowEcha,i0Sample,adc) == kTRUE )
00841                                             {
00842                                               fBuildEventDistribGood[i0SM]++;
00843                                             }
00844                                           else
00845                                             {
00846                                               fBuildEventDistribBad[i0SM]++;
00847                                             }
00848                                         }
00849                                     }
00850                                   else
00851                                     {
00852                                       std::cout << "EcnaAnalyzer::analyze(...)> NbOfSamplesFromDigis out of bounds = "
00853                                                 << NbOfSamplesFromDigis << endl;
00854                                     }
00855                                 } // end of if( (fStexNumber > 0 && i0SM == fStexNumber-1) || (fStexNumber == 0) )
00856                             } // end of if( fStexNbOfTreatedEvents[i0SM] >= 1 && fStexNbOfTreatedEvents[i0SM] <= fReqNbOfEvts )
00857                         } // end of if( fStexStatus[i0SM] < 2 )
00858                     } // end of if( i0SM >= 0 && i0SM<fMaxTreatedStexCounter  )   
00859                 } // end of for (EBDigiCollection::const_iterator digiItr = digisEB->begin();
00860                   //             digiItr != digisEB->end(); ++digiItr)
00861               
00862               for(Int_t i0SM=0; i0SM<fMaxTreatedStexCounter; i0SM++)
00863                 {
00864                   fStexDigiOK[i0SM] = 0;  // reset fStexDigiOK[i0SM] after loop on digis
00865                 }
00866               
00867             } // end of if( Int_t(digisEB->end()-digisEB->begin()) >= 0 &&
00868               // Int_t(digisEB->end()-digisEB->begin()) <=  Int_t(digisEB->size()) )
00869         } // end of if( fStexName == "SM" && fSMIndexBegin < fSMIndexStop )
00870       
00871       //=============================================================== Record type EE (Dee)
00872       if( fStexName == "Dee" && fDeeIndexBegin < fDeeIndexStop )
00873         {
00874           //......................................... Get digisEE
00875           Handle<EEDigiCollection> pdigisEE;
00876           const EEDigiCollection* digisEE = 0;
00877           try{
00878             iEvent.getByLabel(digiProducer_, EEdigiCollection_, pdigisEE); 
00879             digisEE = pdigisEE.product();
00880           }catch (std::exception& ex ){
00881             std::cerr << "Error! can't get the product " << EEdigiCollection_.c_str() << std::endl;
00882           }
00883       
00884           // Initialize vectors if not already done
00885           if( int(digisEE->size()) > nChannels_ ){nChannels_ = digisEE->size();}
00886       
00887           //Int_t print_count = 0;
00888           if( Int_t(digisEE->end()-digisEE->begin()) >= 0 &&
00889               Int_t(digisEE->end()-digisEE->begin()) <= Int_t(digisEE->size()) )
00890             {
00891               //======================================================================================
00892               //
00893               //                           Loop over Ecal endcap digisEE (Xtals)
00894               //
00895               //======================================================================================
00896 
00897               for (EEDigiCollection::const_iterator digiItr = digisEE->begin(); digiItr != digisEE->end(); ++digiItr) 
00898                 {         
00899                   EEDetId id_crystal(digiItr->id());
00900 
00901                   Int_t iX_data = id_crystal.ix();        // iX_data : range = [1,100]
00902                   Int_t iY_data = id_crystal.iy();        // iY_data : range = [1,100] 
00903                   Int_t i_quad  = id_crystal.iquadrant(); // iquadrant() : range = [1,4]
00904                   Int_t i_sgnZ  = id_crystal.zside();     //     zside() : values = -1,+1    
00905                     
00906                   Int_t iX = iX_data;
00907                   Int_t iY = iY_data; // iY : range = [1,100]
00908 
00909                   //.......... See CMSSW/DataFormats/EcalDetId/src/EEDetId.cc::ixQuadrantOne()  [ in which ix() = iX_data ]
00910                   if( i_quad == 1 || i_quad == 4 ){iX = iX_data - 50;} // iX_data : range = [51,100], iX : range = [1,50]
00911                   if( i_quad == 3 || i_quad == 2 ){iX = 51 - iX_data;} // iX_data : range = [50,1],   iX : range = [1,50]
00912                                     
00913                   Int_t n1DeeCrys =
00914                     (iX-1)*(fMyEEEcal->MaxSCIYInDee()*fMyEEEcal->MaxCrysIYInSC()) + iY; // n1DeeCrys: range = [1,5000]
00915 
00916                   Int_t n1DeeNumber = 0;
00917                   if( i_quad == 1 && i_sgnZ ==  1 ){n1DeeNumber = 2;}
00918                   if( i_quad == 1 && i_sgnZ == -1 ){n1DeeNumber = 3;}
00919                   if( i_quad == 2 && i_sgnZ ==  1 ){n1DeeNumber = 1;}
00920                   if( i_quad == 2 && i_sgnZ == -1 ){n1DeeNumber = 4;}
00921                   if( i_quad == 3 && i_sgnZ ==  1 ){n1DeeNumber = 1;}
00922                   if( i_quad == 3 && i_sgnZ == -1 ){n1DeeNumber = 4;}
00923                   if( i_quad == 4 && i_sgnZ ==  1 ){n1DeeNumber = 2;}
00924                   if( i_quad == 4 && i_sgnZ == -1 ){n1DeeNumber = 3;}
00925 
00926                   Int_t i0Dee = n1DeeNumber-1;   //   <============== GET the Dee number - 1 here
00927 
00928                   if( i0Dee >= 0 && i0Dee<fMaxTreatedStexCounter )
00929                     {
00930                       if( fMyCnaEEDee[i0Dee] == 0  && fStexStatus[i0Dee] != 2 )
00931                         {
00932                           //=============================== Init Ecna EE ===============================
00933                           fMyCnaEEDee[i0Dee] = new TEcnaRun(fMyEcnaEEObjectManager, "EE", fNbOfSamples);
00934                           fMyCnaEEDee[i0Dee]->GetReadyToReadData(fAnalysisName,  fRunNumber,
00935                                                                  fFirstReqEvent, fLastReqEvent, fReqNbOfEvts,
00936                                                                  i0Dee+1,         fRunTypeNumber);
00937                           
00938                           std::cout << "*EcnaAnalyzer::analyze(...)> ********* INIT ECNA EE ********* " << endl
00939                                     << "                                   fAnalysisName = " << fAnalysisName << endl
00940                                     << "                                      fRunNumber = " << fRunNumber << endl
00941                                     << "                                  fFirstReqEvent = " << fFirstReqEvent << endl
00942                                     << "                                   fLastReqEvent = " << fLastReqEvent << endl
00943                                     << "                                    fReqNbOfEvts = " << fReqNbOfEvts << endl
00944                                     << "                                             Dee = " << i0Dee+1 << endl
00945                                     << "                                        run type = " << runtype(fRunTypeNumber)
00946                                     << endl;
00947                           //============================================================================
00948                         }
00949 
00950                       if( fStexStatus[i0Dee] < 2 ) // nothing to do if status=2 reached
00951                         {
00952                           Bool_t cOKForTreatment = kFALSE;
00953 
00954                           if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" )
00955                             {
00956                               if( fFedTcc >= 1 && fFedTcc <= MaxSMAndDS )
00957                                 {
00958                                   fFedDigiOK[fESFromFedTcc[fFedTcc-1]-1]++;
00959 
00960                                   if( !(fESFromFedTcc[fFedTcc-1] == 5 || fESFromFedTcc[fFedTcc-1] == 14) )
00961                                     {  
00962                                       if( fFedDigiOK[fESFromFedTcc[fFedTcc-1]-1] == 1 )
00963                                         {
00964                                           fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1]++;
00965                                         }
00966                                       if( fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] >= 1 &&
00967                                           fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] <= fReqNbOfEvts )
00968                                         {
00969                                           fStexNbOfTreatedEvents[i0Dee] = fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1];
00970                                           cOKForTreatment = kTRUE;
00971                                         }
00972                                     }
00973                                   if( fESFromFedTcc[fFedTcc-1] == 5 || fESFromFedTcc[fFedTcc-1] == 14 )
00974                                     {
00975                                       if( fFedDigiOK[fESFromFedTcc[fFedTcc-1]-1] == 1 )
00976                                         {
00977                                           fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1]++;
00978                                           fDeeDS5Memo1 = n1DeeNumber;
00979                                           fStexNbOfTreatedEvents[i0Dee] = fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1];
00980                                         }
00981                                       else
00982                                         {
00983                                           if( fDeeDS5Memo2 == 0 )
00984                                             {
00985                                               if( n1DeeNumber != fDeeDS5Memo1 )
00986                                                 {
00987                                                   // change of Dee in Data sector 5
00988                                                   fDeeDS5Memo2 = n1DeeNumber;
00989                                                   fStexNbOfTreatedEvents[i0Dee] =
00990                                                     fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1];
00991                                                 }
00992                                             }
00993                                         }
00994                                       if( fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] >= 1 &&
00995                                           fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] <= fReqNbOfEvts )
00996                                         {
00997                                           cOKForTreatment = kTRUE;
00998                                         }
00999                                     }
01000                                 } // end of if( fFedTcc >= 1 && fFedTcc <= MaxSMAndDS )
01001                             } // end of if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" )
01002                           else
01003                             {
01004                               fStexDigiOK[i0Dee]++;
01005                               if( fStexDigiOK[i0Dee] == 1 ){fStexNbOfTreatedEvents[i0Dee]++;}
01006                               if( fStexNbOfTreatedEvents[i0Dee] >= 1 &&
01007                                   fStexNbOfTreatedEvents[i0Dee] <= fReqNbOfEvts )
01008                                 {cOKForTreatment = kTRUE;}
01009                             }
01010 
01011                           if( cOKForTreatment== kTRUE )
01012                             {
01013                               //......................................... date of first event (in real time)
01014                               edm::Timestamp Time = iEvent.time();
01015                               edm::TimeValue_t t_current_ev_time = (cond::Time_t)Time.value();
01016                               time_t         i_current_ev_time = (time_t)(t_current_ev_time>>32);
01017                               const time_t*  p_current_ev_time = &i_current_ev_time;
01018                               char*          astime            = ctime(p_current_ev_time);
01019 
01020                               if( ( !(fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12") &&
01021                                     fStexDigiOK[i0Dee] == 1 &&
01022                                     fStexNbOfTreatedEvents[i0Dee] == 1 ) ||
01023                                   (  (fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12") && 
01024                                      fFedDigiOK[fESFromFedTcc[fFedTcc-1]-1] == 1 &&
01025                                      fStexNbOfTreatedEvents[i0Dee] == 1 &&
01026                                      fMemoDateFirstEvent[i0Dee] == 0 ) )
01027                                 {
01028                                   fTimeFirst[i0Dee] = i_current_ev_time;
01029                                   fDateFirst[i0Dee] = astime;
01030                                   fTimeLast[i0Dee]  = i_current_ev_time;
01031                                   fDateLast[i0Dee]  = astime;
01032                                   std::cout << "----- beginning of analysis for " << fStexName << i0Dee+1 << "-------"  << endl
01033                                     //<< " t_current_ev_time = " << t_current_ev_time  << endl
01034                                     //<< " i_current_ev_time = " << i_current_ev_time  << endl
01035                                     //<< " p_current_ev_time = " << p_current_ev_time  << endl
01036                                             << " First event date  = " << astime << endl
01037                                             << " Nb of selected evts = " << fNbOfSelectedEvents << endl
01038                                             << "---------------------------------------------------------------"  << endl;
01039                                   fMemoDateFirstEvent[i0Dee]++;
01040                                 }
01041 
01042                               if( i_current_ev_time < fTimeFirst[i0Dee] )
01043                                 { fTimeFirst[i0Dee] = i_current_ev_time; fDateFirst[i0Dee] = astime;}
01044                               if( i_current_ev_time > fTimeLast[i0Dee] )
01045                                 { fTimeLast[i0Dee] = i_current_ev_time; fDateLast[i0Dee] = astime;}
01046                               
01047                               //=============================================> cut on i0Dee value
01048                               if( (fStexNumber > 0 && i0Dee == fStexNumber-1) || (fStexNumber == 0) )
01049                                 {
01050                                   TString sDir = fMyEENumbering->GetDeeDirViewedFromIP(n1DeeNumber);
01051                                   Int_t n1DeeSCEcna = fMyEENumbering->Get1DeeSCEcnaFrom1DeeCrys(n1DeeCrys, sDir);
01052                                   Int_t i0SCEcha = fMyEENumbering->Get1SCEchaFrom1DeeCrys(n1DeeCrys, sDir) - 1;
01053                               
01054                                   Int_t NbOfSamplesFromDigis = digiItr->size();
01055                               
01056                                   EEDataFrame df( *digiItr );
01057                               
01058                                   if( NbOfSamplesFromDigis > 0 && NbOfSamplesFromDigis <= fMyEEEcal->MaxSampADC() )
01059                                     {
01060                                       Double_t adcDBLS = (Double_t)0;
01061                                       // Three 1st samples mean value for Dynamic Base Line Substraction (DBLS)
01062                                       if( fDynBaseLineSub == "yes" )
01063                                         {
01064                                           for (Int_t i0Sample=0; i0Sample<3; i0Sample++)  
01065                                             {adcDBLS += (Double_t)(df.sample(i0Sample).adc());}
01066                                           adcDBLS /= (Double_t)3;
01067                                         }
01068                                       // Loop over the samples
01069                                       for (Int_t i0Sample = 0; i0Sample < fNbOfSamples; i0Sample++)  
01070                                         {
01071                                           Double_t adc = (Double_t)(df.sample(i0Sample).adc()) - adcDBLS;
01072                                           //................................................. Calls to GetSampleAdcValues
01073                                           if( fMyCnaEEDee[i0Dee]->GetSampleAdcValues
01074                                               (fStexNbOfTreatedEvents[i0Dee],n1DeeSCEcna,i0SCEcha,i0Sample,adc) == kTRUE )
01075                                             {
01076                                               fBuildEventDistribGood[i0Dee]++;
01077                                             }
01078                                           else
01079                                             {
01080                                               fBuildEventDistribBad[i0Dee]++;
01081                                             }
01082                                         }
01083                                     }
01084                                   else
01085                                     {
01086                                       std::cout << "EcnaAnalyzer::analyze(...)> NbOfSamplesFromDigis out of bounds = "
01087                                                 << NbOfSamplesFromDigis << endl;
01088                                     }
01089                                 } // end of if( (fStexNumber > 0 && i0Dee == fStexNumber-1) || (fStexNumber == 0) )
01090                             } // end of if( fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] >= 1 &&
01091                           // fFedNbOfTreatedEvents[fESFromFedTcc[fFedTcc-1]-1] <= fReqNbOfEvts )
01092                         } // end of if( fStexStatus[i0Dee] < 2 )
01093                     } // end of if( i0Dee >= 0 && i0Dee<fMaxTreatedStexCounter )
01094                 } // end of for (EBDigiCollection::const_iterator digiItr = digisEB->begin();
01095                   //             digiItr != digisEB->end(); ++digiItr)
01096 
01097               // reset fStexDigiOK[i0Dee] or fFedDigiOK[i0Dee] to zero after loop on digis
01098               if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" )
01099                 {
01100                   for(Int_t i0FedES=0; i0FedES<fMaxFedUnitCounter; i0FedES++)
01101                     {fFedDigiOK[i0FedES] = 0;}
01102                   
01103                   // reset fDeeDS5Memo1 and fDeeDS5Memo2 (for Data sector 5 versus Dee number  management)
01104                   fDeeDS5Memo1 = 0;
01105                   fDeeDS5Memo2 = 0;
01106                 }
01107               else
01108                 {
01109                   for(Int_t i0Dee=0; i0Dee<fMaxTreatedStexCounter; i0Dee++)
01110                     {fStexDigiOK[i0Dee] = 0;}
01111                 }
01112               
01113             } // end of if( Int_t(digisEB->end()-digisEB->begin()) >= 0 &&
01114               // Int_t(digisEB->end()-digisEB->begin()) <=  Int_t(digisEB->size()) )
01115 
01116         } // end of if( fStexName == "Dee" && fDeeIndexBegin < fDeeIndexStop )
01117     }  // end of if( (fStexNumber > 0 && fNbOfTreatedStexs == 0) || (fStexNumber == 0 && fNbOfTreatedStexs < MaxNbOfStex) )
01118 
01119   //=============================================================================================
01120   //
01121   //                    Number of treated events. Setting Stex and Fed status.
01122   //
01123   //=============================================================================================
01124 
01125   // (take into account the "Accelerating selection with FED number" section - see above -)
01126   if( fStexName == "SM" ||
01127       ( fStexName == "Dee" && !( fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" ) )
01128       )  // one FED = one SM = one Stex
01129     {
01130       for(Int_t i0Stex=fStexIndexBegin; i0Stex<fStexIndexStop; i0Stex++)
01131         {
01132           if( fStexStatus[i0Stex] != 2 )  // do not change fStexStatus[i0Stex] if already set to 2
01133             // even if fStexNbOfTreatedEvents[i0Stex] == fReqNbOfEvts 
01134             {
01135               if( fStexNbOfTreatedEvents[i0Stex] == fReqNbOfEvts ){fStexStatus[i0Stex] = 1;}
01136               if( fStexNbOfTreatedEvents[i0Stex] >  fReqNbOfEvts ){fStexStatus[i0Stex] = 2;}
01137             }
01138         }
01139     }
01140 
01141   // one FED = one Data Sector (DS or ES)
01142   if( fStexName == "Dee" &&
01143       ( fAnalysisName == "AdcPeg12" || fAnalysisName == "AdcSPeg12" ) )
01144     {
01145       for(Int_t i0FedES=0; i0FedES<fMaxFedUnitCounter; i0FedES++)
01146         {
01147           if( fFedStatus[i0FedES] != 2 )  // do not change fFedStatus[i0FedES] if already set to 2
01148             // even if fFedNbOfTreatedEvents[i0FedES] == fReqNbOfEvts 
01149             {
01150               if( fFedNbOfTreatedEvents[i0FedES] == fReqNbOfEvts )
01151                 {
01152                   fFedStatus[i0FedES] = 1;
01153                   fTreatedFedOrder++; fFedStatusOrder[i0FedES] = fTreatedFedOrder;
01154                 }
01155               if( fFedNbOfTreatedEvents[i0FedES] > fReqNbOfEvts ){fFedStatus[i0FedES] = 2;}
01156             }
01157         }
01158     
01159       Int_t j0Fed = 4;
01160       //..................................................... Dee 4 (DS 1,2,3,4 ; ES 1,2,3,4)
01161       for( Int_t i0FedES= 0; i0FedES<= 3; i0FedES++ )
01162         {if( fFedStatus[i0FedES] == 1 ){fNbOfTreatedFedsInDee[3]++; fFedStatus[i0FedES] = 2;}}
01163     
01164       //..................................................... Dee 3, Dee 4 (DS 5 ; ES 5)
01165       j0Fed = 4;
01166       if( fFedStatus[j0Fed] == 1 )
01167         {fNbOfTreatedFedsInDee[3]++; fNbOfTreatedFedsInDee[2]++; fFedStatus[j0Fed] = 2;}
01168     
01169        //.................................................... Dee 3 (DS 6,7,8,9 ; ES 6,7,8,9)
01170       for( Int_t i0FedES= 5; i0FedES<= 8; i0FedES++ )
01171         {if( fFedStatus[i0FedES] == 1 ){fNbOfTreatedFedsInDee[2]++; fFedStatus[i0FedES] = 2;}}
01172     
01173       //..................................................... Dee 1 (DS 1,2,3,4 ; ES 10,11,12,13)
01174       for( Int_t i0FedES= 9; i0FedES<=12; i0FedES++ )
01175         {if( fFedStatus[i0FedES] == 1 ){fNbOfTreatedFedsInDee[0]++; fFedStatus[i0FedES] = 2;}}
01176     
01177       //..................................................... Dee 1, Dee 2 (DS 5 ; ES 5)
01178       j0Fed = 13;
01179       if( fFedStatus[j0Fed] == 1 )
01180         {fNbOfTreatedFedsInDee[0]++; fNbOfTreatedFedsInDee[1]++; fFedStatus[j0Fed] = 2;}
01181     
01182       //..................................................... Dee 2 (DS 6,7,8,9 ; ES 15,16,17,18)
01183       for( Int_t i0FedES=14; i0FedES<=17; i0FedES++ )
01184         {if( fFedStatus[i0FedES] == 1 ){fNbOfTreatedFedsInDee[1]++; fFedStatus[i0FedES] = 2;}}
01185     
01186       //-----------------------------------------------------
01187       for( Int_t i0Dee=0; i0Dee<4; i0Dee++ )
01188         {
01189           if( fNbOfTreatedFedsInStex[i0Dee] >= 0 && fNbOfTreatedFedsInStex[i0Dee] < 5 )
01190             {fNbOfTreatedFedsInStex[i0Dee] = fNbOfTreatedFedsInDee[i0Dee];}
01191           if( fNbOfTreatedFedsInDee[i0Dee] == 5 )
01192             {fStexStatus[i0Dee] = 1; fNbOfTreatedFedsInDee[i0Dee] = 0;}
01193         }
01194     
01195     } // end of if( fStexName == "Dee" &&
01196       // ( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" ) )
01197 
01198   //----------------------------------------------------------------------------------------------
01199   for(Int_t i0Stex=fStexIndexBegin; i0Stex<fStexIndexStop; i0Stex++)
01200     {
01201       if( fStexStatus[i0Stex] == 1 )
01202         {
01203           fNbOfTreatedStexs++; // increase nb of treated Stex's only if fStexStatus[i0Stex] == 1
01204           //....................................................... date of last event
01205           //edm::Timestamp Time = iEvent.time();
01206           //edm::TimeValue_t t_current_ev_time = (cond::Time_t)Time.value();
01207           //time_t         i_current_ev_time = (time_t)(t_current_ev_time>>32);
01208           //const time_t*  p_current_ev_time = &i_current_ev_time;
01209           //char*          astime            = ctime(p_current_ev_time);
01210           //fTimeLast[i0Stex] = i_current_ev_time;
01211           //fDateLast[i0Stex] = astime;
01212 
01213           //if( i_current_ev_time > fTimeLast[i0Stex] )
01214           // {fTimeLast[i0Stex] = i_current_ev_time; fDateLast[i0Stex] = astime;}
01215           
01216           std::cout << "---------- End of analysis for " << fStexName << i0Stex+1 << " -----------" << endl;
01217           Int_t n3 = 3; CheckMsg(n3, i0Stex);
01218           // std::cout     << " t_current_ev_time = " << t_current_ev_time  << endl
01219           //<< " i_current_ev_time = " << i_current_ev_time  << endl
01220           //<< " p_current_ev_time = " << p_current_ev_time  << endl
01221           // std::cout      << " Last analyzed event date  = " << astime << endl;
01222           std::cout         << " Number of selected events = " << fNbOfSelectedEvents << endl;
01223           std::cout << endl << fNbOfTreatedStexs << " " << fStexName
01224                     << "'s with " << fReqNbOfEvts << " events analyzed." << endl
01225                     << "---------------------------------------------------------"  << endl;
01226           
01227           //================================= WRITE RESULTS FILE
01228           if( fStexName == "SM" )
01229             {
01230               if( fMyCnaEBSM[i0Stex] != 0 )
01231                 {
01232                   //........................................ register dates 1 and 2
01233                   fMyCnaEBSM[i0Stex]->StartStopDate(fDateFirst[i0Stex], fDateLast[i0Stex]);
01234                   fMyCnaEBSM[i0Stex]->StartStopTime(fTimeFirst[i0Stex], fTimeLast[i0Stex]);
01235                   
01236                   //........................................ Init .root file
01237                   fMyCnaEBSM[i0Stex]->GetReadyToCompute();
01238                   fMyCnaEBSM[i0Stex]->SampleValues();
01239                   
01240                   //........................................ write the sample values in .root file
01241                   if( fMyCnaEBSM[i0Stex]->WriteRootFile() == kFALSE )
01242                     {
01243                       std::cout << "!EcnaAnalyzer::analyze> PROBLEM with write ROOT file for SM" << i0Stex+1
01244                                 << fTTBELL << endl;
01245                     }
01246                 }
01247               // set pointer to zero in order to avoid recalculation and rewriting at the destructor level
01248               delete fMyCnaEBSM[i0Stex];  fMyCnaEBSM[i0Stex] = 0;
01249               std::cout << "!EcnaAnalyzer::analyze> Set memory free: delete done for SM " << i0Stex+1 << endl;
01250             }
01251 
01252           if( fStexName == "Dee" )
01253             {
01254               if( fMyCnaEEDee[i0Stex] != 0 )
01255                 {
01256                   //........................................ register dates 1 and 2
01257                   fMyCnaEEDee[i0Stex]->StartStopDate(fDateFirst[i0Stex], fDateLast[i0Stex]);
01258                   fMyCnaEEDee[i0Stex]->StartStopTime(fTimeFirst[i0Stex], fTimeLast[i0Stex]);
01259                   
01260                   //........................................ Init .root file
01261                   fMyCnaEEDee[i0Stex]->GetReadyToCompute();
01262                   fMyCnaEEDee[i0Stex]->SampleValues();
01263 
01264                   //........................................ write the sample values in .root file
01265                   if(fMyCnaEEDee[i0Stex]->WriteRootFile() == kFALSE )
01266                     {
01267                       std::cout << "!EcnaAnalyzer::analyze> PROBLEM with write ROOT file for Dee" << i0Stex+1
01268                                 << fTTBELL << endl;
01269                     }
01270                 }
01271               // set pointer to zero in order to avoid recalculation and rewriting at the destructor level
01272               delete fMyCnaEEDee[i0Stex]; fMyCnaEEDee[i0Stex] = 0;
01273               std::cout << "!EcnaAnalyzer::analyze> Set memory free: delete done for Dee " << i0Stex+1 << endl;
01274             }
01275 
01276           fStexStatus[i0Stex] = 2;        // set fStexStatus[i0Stex] to 2 definitively
01277           std::cout << "*---------------------------------------------------------------------------- " << endl;
01278 
01279         } // end of if( fStexStatus[i0Stex] == 1 )
01280     } // end of for(Int_t i0Stex=fStexIndexBegin; i0Stex<fStexIndexStop; i0Stex++)
01281 }
01282 // end of EcnaAnalyzer::analyse(...)
01283 
01284 Bool_t EcnaAnalyzer::AnalysisOutcome(const TString s_opt)
01285 {
01286   //---- STOP if end of analysis
01287 
01288   Bool_t result = kFALSE;
01289 
01290   if( s_opt == "EVT" )
01291     {
01292       Int_t MaxNbOfStex = 0;
01293       if( fStexName == "SM"  ){MaxNbOfStex = fMyEBEcal->MaxSMInEB();}
01294       if( fStexName == "Dee" ){MaxNbOfStex = fMyEEEcal->MaxDeeInEE();}
01295 
01296       if( ( (fStexNumber > 0 && fNbOfTreatedStexs == 1) ||
01297             (fStexNumber == 0 && fNbOfTreatedStexs == MaxNbOfStex) ) &&
01298           ( (fLastReqEvent < fFirstReqEvent) ||
01299             (fLastReqEvent >= fFirstReqEvent && fCurrentEventNumber <= fLastReqEvent) )
01300           )
01301         {
01302           std::cout << endl
01303                     << "**************************** ANALYSIS REPORT > OK **************************************" << endl
01304                     << "*EcnaAnalyzer::AnalysisOutcome(...)> The maximum requested number of events and the maximum" << endl
01305                     << "                                     number of treated " << fStexName
01306                     << "'s have been reached." << endl
01307                     << "                                     Analysis successfully ended from EcnaAnalyzer " << endl
01308                     << "                                     by SIGNAL: kill(getpid(),SIGUSR2)." << endl
01309                     << "                                     Number of selected events   = " << fNbOfSelectedEvents << endl
01310                     << "                                     Last requested event number = " << fLastReqEvent << endl
01311                     << "                                     Current event number        = " << fCurrentEventNumber << endl;
01312 
01313           Int_t n0 = 0; CheckMsg(n0);
01314 
01315           std::cout << "****************************************************************************************" << endl
01316                     << endl;
01317 
01318           result = kTRUE;
01319           kill(getpid(),SIGUSR2);
01320         }
01321 
01322       if( fLastReqEvent >= fFirstReqEvent && fCurrentEventNumber > fLastReqEvent &&
01323           ! ( (fStexNumber > 0 && fNbOfTreatedStexs == 1) ||
01324               (fStexNumber == 0 && fNbOfTreatedStexs == MaxNbOfStex) ) )
01325         {
01326           std::cout << endl
01327                     << "**************************** ANALYSIS REPORT >>> *** WARNING *** WARNING *** WARNING ***" << endl
01328                     << "*EcnaAnalyzer::AnalysisOutcome(...)> Last event reached before completion of analysis." << endl
01329                     << "                                     Analysis ended from EcnaAnalyzer " << endl
01330                     << "                                     by SIGNAL: kill(getpid(),SIGUSR2)." << endl
01331                     << "                                     Number of selected events   = " << fNbOfSelectedEvents << endl
01332                     << "                                     Last requested event number = " << fLastReqEvent << endl
01333                     << "                                     Current event number        = " << fCurrentEventNumber << endl;
01334 
01335           Int_t n0 = 0; CheckMsg(n0);
01336 
01337           std::cout << "****************************************************************************************" << endl
01338                     << endl;
01339       
01340           result = kTRUE;
01341           kill(getpid(),SIGUSR2);
01342         }
01343     }
01344   else
01345     {
01346       if( s_opt == "ERR_FNEG" )
01347         {
01348           std::cout << endl
01349                     << "**************************** ANALYSIS REPORT >>> **** ERROR **** ERROR **** ERROR ******" << endl
01350                     << "*EcnaAnalyzer::AnalysisOutcome(...)> First event number = " << fFirstReqEvent
01351                     << ". Should be strictly potitive." << endl
01352                     << "                             Analysis ended from EcnaAnalyzer " << endl
01353                     << "                             by SIGNAL: kill(getpid(),SIGUSR2)." << endl;
01354 
01355           std::cout << "****************************************************************************************" << endl
01356                     << endl;
01357 
01358           result = kTRUE;
01359           kill(getpid(),SIGUSR2);
01360         }
01361       if( s_opt == "ERR_LREQ" )
01362         {
01363           std::cout << endl
01364                     << "**************************** ANALYSIS REPORT >>> **** ERROR **** ERROR **** ERROR ******" << endl
01365                     << "*EcnaAnalyzer::analyze(...)> Requested number of events = " << fReqNbOfEvts << "." << endl
01366                     << "                             Too large compared to the event range: "
01367                     << fFirstReqEvent << " - " << fLastReqEvent << endl
01368                     << "                             Analysis ended from EcnaAnalyzer " << endl
01369                     << "                             by SIGNAL: kill(getpid(),SIGUSR2)." << endl;
01370 
01371           std::cout << "****************************************************************************************" << endl
01372                     << endl;
01373 
01374           result = kTRUE;
01375           kill(getpid(),SIGUSR2);
01376         }
01377     }
01378   return result;
01379 } // end of EcnaAnalyzer::AnalysisOutcome(const Int_t& n_option)
01380 
01381 void EcnaAnalyzer::CheckMsg(const Int_t& MsgNum)
01382 {Int_t nm1 = -1; CheckMsg(MsgNum, nm1);}
01383 
01384 void EcnaAnalyzer::CheckMsg(const Int_t& MsgNum, const Int_t& i0Stex)
01385 {
01386   //------ Cross-check messages
01387 
01388   if( MsgNum == 1 )
01389     {std::cout << "---------------- CROSS-CHECK A ------------------ " << endl
01390                << "**************** CURRENT EVENT ****************** " << endl;}
01391   if( MsgNum == 2 )
01392     {std::cout << "---------------- CROSS-CHECK B ------------------ " << endl
01393                << "**** FIRST EVENT PASSING USER'S ANALYSIS CUT **** " << endl;}
01394   if( MsgNum == 3 )
01395     {std::cout << "---------------- CROSS-CHECK C ------------------ " << endl
01396                << "*** CURRENT VALUES BEFORE RESULT FILE WRITING *** " << endl;}
01397   if( MsgNum == 3 || MsgNum == 4 )
01398     {std::cout << "          fRecNumber = " << fRecNumber << endl
01399                << "          fEvtNumber = " << fEvtNumber << endl;}
01400   
01401   std::cout << " fCurrentEventNumber = " << fCurrentEventNumber << endl
01402             << " fNbOfSelectedEvents = " << fNbOfSelectedEvents << endl
01403             << "          fRunNumber = " << fRunNumber << endl
01404             << "     Chozen run type = " << runtype(fChozenRunTypeNumber) << endl
01405             << "            Run type = " << runtype(fRunTypeNumber) << endl
01406             << "             fFedTcc = " << fFedTcc << endl
01407             << "        fFedId(+601) = " << fFedId+601 << endl
01408             << "           fStexName = " << fStexName << endl
01409             << "         Chozen gain = " << gainvalue(fChozenGainNumber) << endl 
01410             << "           Mgpa Gain = " << gainvalue(fMgpaGainNumber) << endl << endl;
01411           
01412   if( fAnalysisName == "AdcPeg12"  || fAnalysisName == "AdcSPeg12" )
01413     {
01414       if( fStexName == "SM" )
01415         {
01416           for(Int_t j0Stex=fStexIndexBegin; j0Stex<fStexIndexStop; j0Stex++)
01417             {
01418               Int_t nStexNbOfTreatedEvents = fStexNbOfTreatedEvents[j0Stex];
01419               if( fStexStatus[j0Stex] == 1 ){nStexNbOfTreatedEvents = fStexNbOfTreatedEvents[j0Stex];}
01420               if( fStexStatus[j0Stex] == 2 ){nStexNbOfTreatedEvents = fStexNbOfTreatedEvents[j0Stex];}
01421               
01422               std::cout << fStexName << setw(3) << j0Stex+1 << ": "
01423                         << setw(5) << nStexNbOfTreatedEvents << " events. "
01424                         << fStexName << " status: " << fStexStatus[j0Stex];
01425               if( j0Stex == i0Stex ){std::cout << " (going to write file for this " << fStexName << ").";}
01426               std::cout << endl; 
01427             }
01428         }
01429 
01430       if( fStexName == "Dee" )
01431         {
01432           for(Int_t i0FedES=0; i0FedES<fMaxFedUnitCounter; i0FedES++)
01433             {
01434               Int_t nFedNbOfTreatedEvents = fFedNbOfTreatedEvents[i0FedES];
01435               if( fFedStatus[i0FedES] == 1 ){nFedNbOfTreatedEvents = fFedNbOfTreatedEvents[i0FedES];}
01436               if( fFedStatus[i0FedES] == 2 ){nFedNbOfTreatedEvents = fFedNbOfTreatedEvents[i0FedES];}
01437               
01438               std::cout << "Fed (ES) " << setw(3) << i0FedES+1 << ": "
01439                         << setw(5) << nFedNbOfTreatedEvents << " events."
01440                         << " Fed status: " << fFedStatus[i0FedES]
01441                         << ", order: " << setw(3) << fFedStatusOrder[i0FedES]
01442                         << " (" << fDeeNumberString[i0FedES] << ")" << endl;
01443             }
01444           
01445           for(Int_t j0Stex=fStexIndexBegin; j0Stex<fStexIndexStop; j0Stex++)
01446             {
01447               std::cout << fStexName << setw(3) << j0Stex+1 << ": "
01448                         << setw(5) << fNbOfTreatedFedsInStex[j0Stex] << " analyzed Fed(s). "
01449                         << fStexName << " status: " << fStexStatus[j0Stex];
01450               if( j0Stex == i0Stex ){std::cout << " (going to write file for this " << fStexName << ").";}
01451               std::cout << endl; 
01452             }
01453         }
01454 
01455       std::cout << "Number of " << fStexName << "'s with "
01456                 << fReqNbOfEvts << " events analyzed: " << fNbOfTreatedStexs << endl;
01457     }
01458   
01459   if( MsgNum == 1 || MsgNum == 2 )
01460     {std::cout << "*---------------------------------------------------------------------------- " << endl;}
01461   if( MsgNum == 3 )
01462     {std::cout << "*............................................................................ " << endl;}
01463 
01464 } // end of EcnaAnalyzer::CheckMsg(const Int_t& MsgNum, const Int_t& i0Stex)
01465 
01466 TString EcnaAnalyzer::runtype(const Int_t& numtype)
01467 {
01468   TString cType = "?";
01469 
01470   if( numtype ==  0 ){cType = "COSMICS";}
01471   if( numtype ==  1 ){cType = "BEAMH4";}
01472   if( numtype ==  2 ){cType = "BEAMH2";}
01473   if( numtype ==  3 ){cType = "MTCC";}
01474   if( numtype ==  4 ){cType = "LASER_STD";}
01475   if( numtype ==  5 ){cType = "LASER_POWER_SCAN";}
01476   if( numtype ==  6 ){cType = "LASER_DELAY_SCAN";}
01477   if( numtype ==  7 ){cType = "TESTPULSE_SCAN_MEM";}
01478   if( numtype ==  8 ){cType = "TESTPULSE_MGPA";}
01479   if( numtype ==  9 ){cType = "PEDESTAL_STD";}
01480   if( numtype == 10 ){cType = "PEDESTAL_OFFSET_SCAN";}
01481   if( numtype == 11 ){cType = "PEDESTAL_25NS_SCAN";}
01482   if( numtype == 12 ){cType = "LED_STD";}
01483 
01484   if( numtype == 13 ){cType = "PHYSICS_GLOBAL";}
01485   if( numtype == 14 ){cType = "COSMICS_GLOBAL";}
01486   if( numtype == 15 ){cType = "HALO_GLOBAL";}
01487 
01488   if( numtype == 16 ){cType = "LASER_GAP";}
01489   if( numtype == 17 ){cType = "TESTPULSE_GAP";}
01490   if( numtype == 18 ){cType = "PEDESTAL_GAP";}
01491   if( numtype == 19 ){cType = "LED_GAP";}
01492 
01493   if( numtype == 20 ){cType = "PHYSICS_LOCAL";}
01494   if( numtype == 21 ){cType = "COSMICS_LOCAL";}
01495   if( numtype == 22 ){cType = "HALO_LOCAL";}
01496   if( numtype == 23 ){cType = "CALIB_LOCAL";}
01497 
01498   if( numtype == 24 ){cType = "PEDSIM";}
01499 
01500   return cType;
01501 }
01502 
01503 Int_t EcnaAnalyzer::gainvalue(const Int_t& numgain)
01504 {
01505   Int_t value = 0;
01506 
01507   if( numgain == 1 ){value = 12;}
01508   if( numgain == 2 ){value =  6;}
01509   if( numgain == 3 ){value =  1;}
01510 
01511   return value;
01512 }
01513 
01514