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