Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-30 03:01:37

0001 //----------Author's Names: B.Fabbro, FX Gentit DSM/IRFU/SPP CEA-Saclay
0002 //----------Copyright: Those valid for CEA sofware
0003 //----------Modified: 30/01/2014
0004 
0005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaRun.h"
0006 
0007 //--------------------------------------
0008 //  TEcnaRun.cc
0009 //  Class creation: 03 Dec 2002
0010 //  Documentation: see TEcnaRun.h
0011 //--------------------------------------
0012 
0013 R__EXTERN TEcnaRootFile* gCnaRootFile;
0014 
0015 ClassImp(TEcnaRun);
0016 //___________________________________________________________________________
0017 //
0018 
0019 TEcnaRun::TEcnaRun() {
0020   //Constructor without argument: nothing special done
0021 
0022   // std::cout << "[Info Management] CLASS: TEcnaRun.           CREATE OBJECT: this = " << this << std::endl;
0023 }
0024 
0025 TEcnaRun::TEcnaRun(TEcnaObject* pObjectManager, const TString& SubDet) {
0026   //Constructor with argument: call to Init() and declare fEcal according to SubDet value ("EB" or "EE")
0027 
0028   // std::cout << "[Info Management] CLASS: TEcnaRun.           CREATE OBJECT: this = " << this << std::endl;
0029 
0030   Init(pObjectManager);
0031 
0032   //fCfgResultsRootFilePath    = fCnaParPaths->ResultsRootFilePath();
0033   //fCfgHistoryRunListFilePath = fCnaParPaths->HistoryRunListFilePath();
0034 
0035   //ffFileHeader = 0;
0036   //fconst Text_t *h_name  = "CnaHeader";   //==> voir cette question avec FXG
0037   //fconst Text_t *h_title = "CnaHeader";   //==> voir cette question avec FXG
0038   //ffFileHeader = new TEcnaHeader(h_name, h_title);     //fCnew++;
0039 
0040   //............................ fFileHeader
0041   const Text_t* h_name = "CnaHeader";   //==> voir cette question avec FXG
0042   const Text_t* h_title = "CnaHeader";  //==> voir cette question avec FXG
0043 
0044   fFileHeader = nullptr;
0045   //Int_t iFileHeader = pObjectManager->GetPointerValue("TEcnaHeader");
0046   Long_t iFileHeader = 0;  // one TEcnaHeader object for each file since they can be open simultaneously
0047   if (iFileHeader == 0) {
0048     fFileHeader = new TEcnaHeader(pObjectManager, h_name, h_title); /*fCnew++*/
0049   } else {
0050     fFileHeader = (TEcnaHeader*)iFileHeader;
0051   }
0052 
0053   SetEcalSubDetector(SubDet.Data());
0054   fNbSampForFic = fEcal->MaxSampADC();  // DEFAULT Number of samples for ROOT file
0055 }
0056 
0057 TEcnaRun::TEcnaRun(TEcnaObject* pObjectManager, const TString& SubDet, const Int_t& NbOfSamples) {
0058   Init(pObjectManager);
0059 
0060   //fCfgResultsRootFilePath    = fCnaParPaths->ResultsRootFilePath();
0061   //fCfgHistoryRunListFilePath = fCnaParPaths->HistoryRunListFilePath();
0062 
0063   //............................ fFileHeader
0064   const Text_t* h_name = "CnaHeader";   //==> voir cette question avec FXG
0065   const Text_t* h_title = "CnaHeader";  //==> voir cette question avec FXG
0066 
0067   fFileHeader = nullptr;
0068   //Long_t iFileHeader = pObjectManager->GetPointerValue("TEcnaHeader");
0069   Long_t iFileHeader = 0;  // one TEcnaHeader object for each file since they can be open simultaneously
0070   if (iFileHeader == 0) {
0071     fFileHeader = new TEcnaHeader(pObjectManager, h_name, h_title); /*fCnew++*/
0072   } else {
0073     fFileHeader = (TEcnaHeader*)iFileHeader;
0074   }
0075 
0076   SetEcalSubDetector(SubDet.Data());
0077   if (NbOfSamples > 0 && NbOfSamples <= fEcal->MaxSampADC()) {
0078     fNbSampForFic = NbOfSamples;
0079   } else {
0080     std::cout << "TEcnaRun/CONSTRUCTOR> Number of required samples = " << NbOfSamples
0081               << ": OUT OF RANGE. Set to the default value (= " << fEcal->MaxSampADC() << ")." << fTTBELL << std::endl;
0082     fNbSampForFic = fEcal->MaxSampADC();  // DEFAULT Number of samples for file reading
0083   }
0084 }
0085 
0086 //.... return true or false according to the existence of the path. The path itself is in an attribute of fCnaParPaths.
0087 Bool_t TEcnaRun::GetPathForResults() { return fCnaParPaths->GetPathForResultsRootFiles(); }
0088 
0089 void TEcnaRun::Init(TEcnaObject* pObjectManager) {
0090   //Initialisation
0091 
0092   fCnew = 0;
0093   fCdelete = 0;
0094   fCnaCommand = 0;
0095   fCnaError = 0;
0096 
0097   fTTBELL = '\007';
0098 
0099   //........................... TString file names init
0100   fgMaxCar = (Int_t)512;
0101 
0102   //................ MiscDiag counters .................
0103   fMaxMsgIndexForMiscDiag = (Int_t)10;
0104   fNbOfMiscDiagCounters = (Int_t)50;
0105   fMiscDiag = nullptr;
0106 
0107   fNumberOfEvents = 0;
0108   //............................. init pointers  ( Init() )
0109   fT3d_AdcValues = nullptr;
0110   fT3d2_AdcValues = nullptr;
0111   fT3d1_AdcValues = nullptr;
0112 
0113   fT1d_StexStinFromIndex = nullptr;
0114 
0115   fT2d_NbOfEvts = nullptr;
0116   fT1d_NbOfEvts = nullptr;
0117 
0118   fT2d_ev = nullptr;
0119   fT1d_ev = nullptr;
0120   fT2d_sig = nullptr;
0121   fT1d_sig = nullptr;
0122 
0123   fT3d_cov_ss = nullptr;
0124   fT3d2_cov_ss = nullptr;
0125   fT3d1_cov_ss = nullptr;
0126 
0127   fT3d_cor_ss = nullptr;
0128   fT3d2_cor_ss = nullptr;
0129   fT3d1_cor_ss = nullptr;
0130 
0131   fT2d_lf_cov = nullptr;
0132   fT2d1_lf_cov = nullptr;
0133 
0134   fT2d_lf_cor = nullptr;
0135   fT2d1_lf_cor = nullptr;
0136 
0137   fT2d_hf_cov = nullptr;
0138   fT2d1_hf_cov = nullptr;
0139 
0140   fT2d_hf_cor = nullptr;
0141   fT2d1_hf_cor = nullptr;
0142 
0143   fT2d_lfcc_mostins = nullptr;
0144   fT2d1_lfcc_mostins = nullptr;
0145 
0146   fT2d_hfcc_mostins = nullptr;
0147   fT2d1_hfcc_mostins = nullptr;
0148 
0149   fT1d_ev_ev = nullptr;
0150   fT1d_evsamp_of_sigevt = nullptr;
0151   fT1d_ev_cor_ss = nullptr;
0152   fT1d_av_mped = nullptr;
0153   fT1d_av_totn = nullptr;
0154   fT1d_av_lofn = nullptr;
0155   fT1d_av_hifn = nullptr;
0156   fT1d_av_ev_corss = nullptr;
0157   fT1d_av_sig_corss = nullptr;
0158 
0159   fT1d_sigevt_of_evsamp = nullptr;
0160   fT1d_evevt_of_sigsamp = nullptr;
0161   fT1d_sig_cor_ss = nullptr;
0162 
0163   fT2dCrysNumbersTable = nullptr;
0164   fT1dCrysNumbersTable = nullptr;
0165 
0166   //................................ tags   ( Init() )
0167   fTagStinNumbers = nullptr;
0168 
0169   fTagNbOfEvts = nullptr;
0170 
0171   fTagAdcEvt = nullptr;
0172 
0173   fTagMSp = nullptr;
0174   fTagSSp = nullptr;
0175 
0176   fTagCovCss = nullptr;
0177   fTagCorCss = nullptr;
0178 
0179   fTagHfCov = nullptr;
0180   fTagHfCor = nullptr;
0181   fTagLfCov = nullptr;
0182   fTagLfCor = nullptr;
0183 
0184   fTagLFccMoStins = nullptr;
0185   fTagHFccMoStins = nullptr;
0186 
0187   fTagPed = nullptr;
0188   fTagTno = nullptr;
0189   fTagMeanCorss = nullptr;
0190 
0191   fTagLfn = nullptr;
0192   fTagHfn = nullptr;
0193   fTagSigCorss = nullptr;
0194 
0195   fTagAvPed = nullptr;
0196   fTagAvTno = nullptr;
0197   fTagAvLfn = nullptr;
0198   fTagAvHfn = nullptr;
0199 
0200   fTagAvMeanCorss = nullptr;
0201   fTagAvSigCorss = nullptr;
0202 
0203   fObjectManager = (TEcnaObject*)pObjectManager;
0204   pObjectManager->RegisterPointer("TEcnaRun", (Long_t)this);
0205 
0206   //............................ fCnaParCout
0207   Long_t iCnaParCout = pObjectManager->GetPointerValue("TEcnaParCout");
0208   if (iCnaParCout == 0) {
0209     fCnaParCout = new TEcnaParCout(pObjectManager); /*fCnew++*/
0210   } else {
0211     fCnaParCout = (TEcnaParCout*)iCnaParCout;
0212   }
0213 
0214   //............................ fCnaParPaths
0215   Long_t iCnaParPaths = pObjectManager->GetPointerValue("TEcnaParPaths");
0216   if (iCnaParPaths == 0) {
0217     fCnaParPaths = new TEcnaParPaths(pObjectManager); /*fCnew++*/
0218   } else {
0219     fCnaParPaths = (TEcnaParPaths*)iCnaParPaths;
0220   }
0221 
0222   //................................................... Code Print  ( Init() )
0223   fCodePrintNoComment = fCnaParCout->GetCodePrint("NoComment");
0224   fCodePrintWarnings = fCnaParCout->GetCodePrint("Warnings ");  // => default value
0225   fCodePrintComments = fCnaParCout->GetCodePrint("Comments");
0226   fCodePrintAllComments = fCnaParCout->GetCodePrint("AllComments");
0227 
0228   fFlagPrint = fCodePrintWarnings;
0229 
0230   //...................................................
0231   gCnaRootFile = nullptr;
0232   fOpenRootFile = kFALSE;
0233   fReadyToReadData = 0;
0234 
0235   //.............................................. Miscellaneous
0236   fSpecialStexStinNotIndexed = -1;
0237 
0238   fStinIndexBuilt = 0;
0239   fBuildEvtNotSkipped = 0;
0240 
0241   fMemoReadNumberOfEventsforSamples = 0;
0242 
0243 }  // end of Init()
0244 
0245 //========================================================================
0246 void TEcnaRun::SetEcalSubDetector(const TString& SubDet) {
0247   // Set Subdetector (EB or EE)
0248 
0249   Int_t MaxCar = fgMaxCar;
0250   fFlagSubDet.Resize(MaxCar);
0251   fFlagSubDet = SubDet.Data();
0252 
0253   fEcal = nullptr;
0254   fEcal = new TEcnaParEcal(fFlagSubDet.Data());  //fCnew++;
0255   fEcalNumbering = nullptr;
0256   fEcalNumbering = new TEcnaNumbering(fFlagSubDet.Data(), fEcal);  //fCnew++;
0257   fCnaWrite = nullptr;
0258 
0259   fCnaWrite = new TEcnaWrite(fFlagSubDet.Data(), fCnaParPaths, fCnaParCout, fEcal, fEcalNumbering);  //fCnew++;
0260 
0261   if (fFlagSubDet == "EB") {
0262     fStexName = "SM ";
0263     fStinName = "tower";
0264   }
0265   if (fFlagSubDet == "EE") {
0266     fStexName = "Dee";
0267     fStinName = " SC  ";
0268   }
0269 }
0270 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0271 //
0272 //                    copy constructor
0273 //
0274 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0275 
0276 TEcnaRun::TEcnaRun(const TEcnaRun& dcop) : TObject::TObject(dcop) {
0277   std::cout << "*TEcnaRun::TEcnaRun(const TEcnaRun& dcop)> "
0278             << " Now is the time to write a copy constructor" << std::endl;
0279 
0280   //{ Int_t cintoto;  cin >> cintoto; }
0281 }
0282 
0283 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0284 //
0285 //                    overloading of the operator=
0286 //
0287 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0288 
0289 //TEcnaRun& TEcnaRun::operator=(const TEcnaRun& dcop)
0290 //{
0291 //Overloading of the operator=
0292 //
0293 //  fCopy(dcop);
0294 //  return *this;
0295 //}
0296 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0297 //
0298 //                            destructor
0299 //
0300 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0301 
0302 TEcnaRun::~TEcnaRun() {
0303   //Destructor
0304 
0305   if (fFlagPrint == fCodePrintAllComments) {
0306     std::cout << "*TEcnaRun::~TEcnaRun()> Entering destructor." << std::endl;
0307   }
0308 
0309   if (fFlagPrint != fCodePrintNoComment || fFlagPrint == fCodePrintWarnings) {
0310     if (fBuildEvtNotSkipped > 0) {
0311       std::cout << "************************************************************************************* "
0312                 << std::endl;
0313       std::cout << "*TEcnaRun::~TEcnaRun()> Nb of calls to GetSampleAdcValues by cmsRun: " << fBuildEvtNotSkipped
0314                 << std::endl;
0315       std::cout << "************************************************************************************* "
0316                 << std::endl;
0317     }
0318   }
0319 
0320   if (fFlagPrint == fCodePrintAllComments) {
0321     Int_t misc_czero = 0;
0322     for (Int_t i = 0; i < fNbOfMiscDiagCounters; i++) {
0323       if (fMiscDiag[i] != 0) {
0324         std::cout << "                          fMiscDiag Counter " << std::setw(3) << i << " = " << std::setw(9)
0325                   << fMiscDiag[i] << " (INFO: alloc on non zero freed zone) " << std::endl;
0326       } else {
0327         misc_czero++;
0328       }
0329     }
0330     std::cout << "                          Nb of fMiscDiag counters at zero: " << misc_czero
0331               << " (total nb of counters: " << fNbOfMiscDiagCounters << ")" << std::endl;
0332   }
0333 
0334   if (fMiscDiag != nullptr) {
0335     delete[] fMiscDiag;
0336     fCdelete++;
0337   }
0338 
0339   //if (fFileHeader              != 0){delete fFileHeader;                  fCdelete++;}
0340   //if (fEcal                    != 0){delete fEcal;                        fCdelete++;}
0341   //if (fEcalNumbering           != 0){delete fEcalNumbering;               fCdelete++;}
0342   //if (fCnaParCout              != 0){delete fCnaParCout;                  fCdelete++;}
0343   //if (fCnaParPaths             != 0){delete fCnaParPaths;                 fCdelete++;}
0344   //if (fCnaWrite                != 0){delete fCnaWrite;                    fCdelete++;}
0345 
0346   if (fT1d_StexStinFromIndex != nullptr) {
0347     delete[] fT1d_StexStinFromIndex;
0348     fCdelete++;
0349   }
0350 
0351   if (fT2d_NbOfEvts != nullptr) {
0352     delete[] fT2d_NbOfEvts;
0353     fCdelete++;
0354   }
0355   if (fT1d_NbOfEvts != nullptr) {
0356     delete[] fT1d_NbOfEvts;
0357     fCdelete++;
0358   }
0359 
0360   if (fT3d_AdcValues != nullptr) {
0361     delete[] fT3d_AdcValues;
0362     fCdelete++;
0363   }
0364   if (fT3d2_AdcValues != nullptr) {
0365     delete[] fT3d2_AdcValues;
0366     fCdelete++;
0367   }
0368   if (fT3d1_AdcValues != nullptr) {
0369     delete[] fT3d1_AdcValues;
0370     fCdelete++;
0371   }
0372 
0373   if (fT2d_ev != nullptr) {
0374     delete[] fT2d_ev;
0375     fCdelete++;
0376   }
0377   if (fT1d_ev != nullptr) {
0378     delete[] fT1d_ev;
0379     fCdelete++;
0380   }
0381 
0382   if (fT2d_sig != nullptr) {
0383     delete[] fT2d_sig;
0384     fCdelete++;
0385   }
0386   if (fT1d_sig != nullptr) {
0387     delete[] fT1d_sig;
0388     fCdelete++;
0389   }
0390 
0391   if (fT3d_cov_ss != nullptr) {
0392     delete[] fT3d_cov_ss;
0393     fCdelete++;
0394   }
0395   if (fT3d2_cov_ss != nullptr) {
0396     delete[] fT3d2_cov_ss;
0397     fCdelete++;
0398   }
0399   if (fT3d1_cov_ss != nullptr) {
0400     delete[] fT3d1_cov_ss;
0401     fCdelete++;
0402   }
0403 
0404   if (fT3d_cor_ss != nullptr) {
0405     delete[] fT3d_cor_ss;
0406     fCdelete++;
0407   }
0408   if (fT3d2_cor_ss != nullptr) {
0409     delete[] fT3d2_cor_ss;
0410     fCdelete++;
0411   }
0412   if (fT3d1_cor_ss != nullptr) {
0413     delete[] fT3d1_cor_ss;
0414     fCdelete++;
0415   }
0416 
0417   if (fT2d_lf_cov != nullptr) {
0418     delete[] fT2d_lf_cov;
0419     fCdelete++;
0420   }
0421   if (fT2d1_lf_cov != nullptr) {
0422     delete[] fT2d1_lf_cov;
0423     fCdelete++;
0424   }
0425 
0426   if (fT2d_lf_cor != nullptr) {
0427     delete[] fT2d_lf_cor;
0428     fCdelete++;
0429   }
0430   if (fT2d1_lf_cor != nullptr) {
0431     delete[] fT2d1_lf_cor;
0432     fCdelete++;
0433   }
0434 
0435   if (fT2d_hf_cov != nullptr) {
0436     delete[] fT2d_hf_cov;
0437     fCdelete++;
0438   }
0439   if (fT2d1_hf_cov != nullptr) {
0440     delete[] fT2d1_hf_cov;
0441     fCdelete++;
0442   }
0443 
0444   if (fT2d_hf_cor != nullptr) {
0445     delete[] fT2d_hf_cor;
0446     fCdelete++;
0447   }
0448   if (fT2d1_hf_cor != nullptr) {
0449     delete[] fT2d1_hf_cor;
0450     fCdelete++;
0451   }
0452 
0453   if (fT2d_lfcc_mostins != nullptr) {
0454     delete[] fT2d_lfcc_mostins;
0455     fCdelete++;
0456   }
0457   if (fT2d1_lfcc_mostins != nullptr) {
0458     delete[] fT2d1_lfcc_mostins;
0459     fCdelete++;
0460   }
0461 
0462   if (fT2d_hfcc_mostins != nullptr) {
0463     delete[] fT2d_hfcc_mostins;
0464     fCdelete++;
0465   }
0466   if (fT2d1_hfcc_mostins != nullptr) {
0467     delete[] fT2d1_hfcc_mostins;
0468     fCdelete++;
0469   }
0470 
0471   if (fT1d_ev_ev != nullptr) {
0472     delete[] fT1d_ev_ev;
0473     fCdelete++;
0474   }
0475   if (fT1d_evsamp_of_sigevt != nullptr) {
0476     delete[] fT1d_evsamp_of_sigevt;
0477     fCdelete++;
0478   }
0479   if (fT1d_ev_cor_ss != nullptr) {
0480     delete[] fT1d_ev_cor_ss;
0481     fCdelete++;
0482   }
0483   if (fT1d_av_mped != nullptr) {
0484     delete[] fT1d_av_mped;
0485     fCdelete++;
0486   }
0487   if (fT1d_av_totn != nullptr) {
0488     delete[] fT1d_av_totn;
0489     fCdelete++;
0490   }
0491   if (fT1d_av_lofn != nullptr) {
0492     delete[] fT1d_av_lofn;
0493     fCdelete++;
0494   }
0495   if (fT1d_av_hifn != nullptr) {
0496     delete[] fT1d_av_hifn;
0497     fCdelete++;
0498   }
0499   if (fT1d_av_ev_corss != nullptr) {
0500     delete[] fT1d_av_ev_corss;
0501     fCdelete++;
0502   }
0503   if (fT1d_av_sig_corss != nullptr) {
0504     delete[] fT1d_av_sig_corss;
0505     fCdelete++;
0506   }
0507 
0508   if (fT1d_sigevt_of_evsamp != nullptr) {
0509     delete[] fT1d_sigevt_of_evsamp;
0510     fCdelete++;
0511   }
0512   if (fT1d_evevt_of_sigsamp != nullptr) {
0513     delete[] fT1d_evevt_of_sigsamp;
0514     fCdelete++;
0515   }
0516   if (fT1d_sig_cor_ss != nullptr) {
0517     delete[] fT1d_sig_cor_ss;
0518     fCdelete++;
0519   }
0520 
0521   if (fT2dCrysNumbersTable != nullptr) {
0522     delete[] fT2dCrysNumbersTable;
0523     fCdelete++;
0524   }
0525   if (fT1dCrysNumbersTable != nullptr) {
0526     delete[] fT1dCrysNumbersTable;
0527     fCdelete++;
0528   }
0529 
0530   if (fTagStinNumbers != nullptr) {
0531     delete[] fTagStinNumbers;
0532     fCdelete++;
0533   }
0534   if (fTagNbOfEvts != nullptr) {
0535     delete[] fTagNbOfEvts;
0536     fCdelete++;
0537   }
0538   if (fTagAdcEvt != nullptr) {
0539     delete[] fTagAdcEvt;
0540     fCdelete++;
0541   }
0542   if (fTagMSp != nullptr) {
0543     delete[] fTagMSp;
0544     fCdelete++;
0545   }
0546   if (fTagSSp != nullptr) {
0547     delete[] fTagSSp;
0548     fCdelete++;
0549   }
0550 
0551   if (fTagCovCss != nullptr) {
0552     delete[] fTagCovCss;
0553     fCdelete++;
0554   }
0555   if (fTagCorCss != nullptr) {
0556     delete[] fTagCorCss;
0557     fCdelete++;
0558   }
0559 
0560   if (fTagHfCov != nullptr) {
0561     delete[] fTagHfCov;
0562     fCdelete++;
0563   }
0564   if (fTagHfCor != nullptr) {
0565     delete[] fTagHfCor;
0566     fCdelete++;
0567   }
0568   if (fTagLfCov != nullptr) {
0569     delete[] fTagLfCov;
0570     fCdelete++;
0571   }
0572   if (fTagLfCor != nullptr) {
0573     delete[] fTagLfCor;
0574     fCdelete++;
0575   }
0576 
0577   if (fTagLFccMoStins != nullptr) {
0578     delete[] fTagLFccMoStins;
0579     fCdelete++;
0580   }
0581   if (fTagHFccMoStins != nullptr) {
0582     delete[] fTagHFccMoStins;
0583     fCdelete++;
0584   }
0585 
0586   if (fTagPed != nullptr) {
0587     delete[] fTagPed;
0588     fCdelete++;
0589   }
0590   if (fTagTno != nullptr) {
0591     delete[] fTagTno;
0592     fCdelete++;
0593   }
0594   if (fTagMeanCorss != nullptr) {
0595     delete[] fTagMeanCorss;
0596     fCdelete++;
0597   }
0598 
0599   if (fTagLfn != nullptr) {
0600     delete[] fTagLfn;
0601     fCdelete++;
0602   }
0603   if (fTagHfn != nullptr) {
0604     delete[] fTagHfn;
0605     fCdelete++;
0606   }
0607   if (fTagSigCorss != nullptr) {
0608     delete[] fTagSigCorss;
0609     fCdelete++;
0610   }
0611 
0612   if (fTagAvPed != nullptr) {
0613     delete[] fTagAvPed;
0614     fCdelete++;
0615   }
0616   if (fTagAvTno != nullptr) {
0617     delete[] fTagAvTno;
0618     fCdelete++;
0619   }
0620   if (fTagAvLfn != nullptr) {
0621     delete[] fTagAvLfn;
0622     fCdelete++;
0623   }
0624   if (fTagAvHfn != nullptr) {
0625     delete[] fTagAvHfn;
0626     fCdelete++;
0627   }
0628   if (fTagAvMeanCorss != nullptr) {
0629     delete[] fTagAvMeanCorss;
0630     fCdelete++;
0631   }
0632   if (fTagAvSigCorss != nullptr) {
0633     delete[] fTagAvSigCorss;
0634     fCdelete++;
0635   }
0636 
0637   if (fCnew != fCdelete) {
0638     std::cout << "!TEcnaRun::~TEcnaRun()> WRONG MANAGEMENT OF MEMORY ALLOCATIONS: fCnew = " << fCnew
0639               << ", fCdelete = " << fCdelete << fTTBELL << std::endl;
0640   } else {
0641     // std::cout << "*TEcnaRun::~TEcnaRun()> Management of memory allocations: OK. fCnew = "
0642     //   << fCnew << ", fCdelete = " << fCdelete << std::endl;
0643   }
0644 
0645   if (fFlagPrint == fCodePrintAllComments) {
0646     std::cout << "*TEcnaRun::~TEcnaRun()> Exiting destructor (this = " << this << ")." << std::endl
0647               << "~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#"
0648               << std::endl;
0649   }
0650 
0651   // std::cout << "[Info Management] CLASS: TEcnaRun.           DESTROY OBJECT: this = " << this << std::endl;
0652 }
0653 
0654 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0655 //
0656 //                             M  E  T  H  O  D  S
0657 //
0658 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0659 
0660 //============================================================================
0661 //
0662 //                           GetReadyToReadData(...)
0663 //
0664 //  Preparation of the result file name + tags allocations
0665 //  + ADC event distribution array allocation + nb of events array allocation
0666 //
0667 //============================================================================
0668 
0669 void TEcnaRun::GetReadyToReadData(const TString& typ_ana,
0670                                   const Int_t& run_number,
0671                                   const Int_t& nfirst,
0672                                   const Int_t& nlast,
0673                                   const Int_t& nbevts,
0674                                   const Int_t& Stex) {
0675   //Preparation of the data reading. Set part of the header. No RunType as argument.
0676   //Use default value = 99999999 and call method with all the arguments (see below)
0677 
0678   Int_t RunType = 99999999;
0679   GetReadyToReadData(typ_ana, run_number, nfirst, nlast, nbevts, Stex, RunType);
0680 }
0681 //--------------------------------------------------------------------------------
0682 void TEcnaRun::GetReadyToReadData(const TString& typ_ana,
0683                                   const Int_t& run_number,
0684                                   const Int_t& nfirst,
0685                                   const Int_t& nlast,
0686                                   const Int_t& nbevts,
0687                                   const Int_t& Stex,
0688                                   const Int_t& run_type) {
0689   //Preparation of the data reading. Set part of the header
0690   //
0691   //   [nfirst, nlast] = [1,50] (50 events) or [151,300] (150 events) or etc...
0692 
0693   Int_t nrangeevts = nlast - nfirst + 1;  // number of events in range
0694 
0695   if (nrangeevts < nbevts) {
0696     if (nlast >= nfirst) {
0697       std::cout << "*TEcnaRun::GetReadyToReadData(...)> --- WARNING ---> number of events = " << nbevts
0698                 << ", out of range (range = " << nfirst << "," << nlast << ")" << std::endl
0699                 << "                                    The number of found events will be less " << std::endl
0700                 << "                                    than the number of requested events." << std::endl;
0701     }
0702     if (nlast < nfirst) {
0703       std::cout << "*TEcnaRun::GetReadyToReadData(...)> --- INFO ---> last requested event number = " << nlast
0704                 << ", less than first requested event number (= " << nfirst << ")" << std::endl
0705                 << "                                    File will be read until EOF if the number of found events"
0706                 << std::endl
0707                 << "                                    remains less than the number of requested events." << std::endl;
0708     }
0709   }
0710 
0711   //............. allocation for counters
0712   fMiscDiag = new Int_t[fNbOfMiscDiagCounters];
0713   fCnew++;
0714   for (Int_t iz = 0; iz < fNbOfMiscDiagCounters; iz++) {
0715     fMiscDiag[iz] = (Int_t)0;
0716   }
0717 
0718   //************** CHECK OF ARGUMENTS: nfirst_arg and nbevts_arg
0719   Int_t nentries = 99999999;  // => to be reintroduced as argument (like run_type) (?)
0720   if (nfirst <= nentries) {
0721     //--------------------- test positivity of nfirst_arg        (GetReadyToReadData)
0722     if (nfirst > 0) {
0723       //-------- test compatibility between the last requested event number
0724       //         and the number of entries
0725       if (nlast <= nentries) {
0726         const Text_t* h_name = "CnaHeader";   //==> voir cette question avec FXG
0727         const Text_t* h_title = "CnaHeader";  //==> voir cette question avec FXG
0728         //fFileHeader->HeaderParameters(h_name,     h_title ,
0729         //                    typ_ana,    fNbSampForFic,
0730         //                run_number, nfirst,  nlast,  nbevts,
0731         //                Stex,       nentries);                 fCnew++;
0732 
0733         if (fEcal->MaxStinEcnaInStex() > 0 && fEcal->MaxCrysInStin() > 0 && fNbSampForFic > 0) {
0734           if (fFileHeader == nullptr) {
0735             fFileHeader = new TEcnaHeader(fObjectManager, h_name, h_title);
0736           }  // fCnew++;
0737 
0738           fFileHeader->HeaderParameters(typ_ana, fNbSampForFic, run_number, nfirst, nlast, nbevts, Stex, run_type);
0739 
0740           // After this call to TEcnaHeader, we have:               (GetReadyToReadData)
0741           //     fFileHeader->fTypAna            = typ_ana
0742           //     fFileHeader->fNbOfSamples       = fNbSampForFic
0743           //     fFileHeader->fRunNumber         = run_number
0744           //     fFileHeader->fFirstReqEvtNumber = nfirst
0745           //     fFileHeader->fLastReqEvtNumber  = nlast
0746           //     fFileHeader->fReqNbOfEvts       = nbevts
0747           //     fFileHeader->fStex              = Stex number
0748           //     fFileHeader->fRunType           = run_type
0749 
0750           // fFileHeader->Print();
0751 
0752           // {Int_t cintoto; std::cout << "taper 0 pour continuer" << std::endl; cin >> cintoto;}
0753 
0754           //  fFileHeader->SetName("CnaHeader");              *======> voir FXG
0755           //  fFileHeader->SetTitle("CnaHeader");
0756 
0757           //......................................... allocation tags + init of them (GetReadyToReadData)
0758 
0759           fTagStinNumbers = new Int_t[1];
0760           fCnew++;
0761           fTagStinNumbers[0] = (Int_t)0;
0762           fTagNbOfEvts = new Int_t[1];
0763           fCnew++;
0764           fTagNbOfEvts[0] = (Int_t)0;
0765 
0766           fTagAdcEvt = new Int_t[fEcal->MaxCrysEcnaInStex()];
0767           fCnew++;
0768           for (Int_t iz = 0; iz < fEcal->MaxCrysEcnaInStex(); iz++) {
0769             fTagAdcEvt[iz] = (Int_t)0;
0770           }
0771 
0772           fTagMSp = new Int_t[1];
0773           fCnew++;
0774           fTagMSp[0] = (Int_t)0;
0775           fTagSSp = new Int_t[1];
0776           fCnew++;
0777           fTagSSp[0] = (Int_t)0;
0778 
0779           fTagCovCss = new Int_t[fEcal->MaxCrysEcnaInStex()];
0780           fCnew++;
0781           for (Int_t iz = 0; iz < fEcal->MaxCrysEcnaInStex(); iz++) {
0782             fTagCovCss[iz] = (Int_t)0;
0783           }
0784 
0785           fTagCorCss = new Int_t[fEcal->MaxCrysEcnaInStex()];
0786           fCnew++;
0787           for (Int_t iz = 0; iz < fEcal->MaxCrysEcnaInStex(); iz++) {
0788             fTagCorCss[iz] = (Int_t)0;
0789           }
0790 
0791           fTagLfCov = new Int_t[1];
0792           fCnew++;
0793           fTagLfCov[0] = (Int_t)0;
0794           fTagLfCor = new Int_t[1];
0795           fCnew++;
0796           fTagLfCor[0] = (Int_t)0;
0797 
0798           fTagHfCov = new Int_t[1];
0799           fCnew++;
0800           fTagHfCov[0] = (Int_t)0;
0801           fTagHfCor = new Int_t[1];
0802           fCnew++;
0803           fTagHfCor[0] = (Int_t)0;
0804 
0805           fTagLFccMoStins = new Int_t[1];
0806           fCnew++;
0807           fTagLFccMoStins[0] = (Int_t)0;
0808           fTagHFccMoStins = new Int_t[1];
0809           fCnew++;
0810           fTagHFccMoStins[0] = (Int_t)0;
0811 
0812           fTagPed = new Int_t[1];
0813           fCnew++;
0814           fTagPed[0] = (Int_t)0;
0815           fTagTno = new Int_t[1];
0816           fCnew++;
0817           fTagTno[0] = (Int_t)0;
0818           fTagMeanCorss = new Int_t[1];
0819           fCnew++;
0820           fTagMeanCorss[0] = (Int_t)0;
0821 
0822           fTagLfn = new Int_t[1];
0823           fCnew++;
0824           fTagLfn[0] = (Int_t)0;
0825           fTagHfn = new Int_t[1];
0826           fCnew++;
0827           fTagHfn[0] = (Int_t)0;
0828           fTagSigCorss = new Int_t[1];
0829           fCnew++;
0830           fTagSigCorss[0] = (Int_t)0;
0831 
0832           fTagAvPed = new Int_t[1];
0833           fCnew++;
0834           fTagAvPed[0] = (Int_t)0;
0835           fTagAvTno = new Int_t[1];
0836           fCnew++;
0837           fTagAvTno[0] = (Int_t)0;
0838           fTagAvLfn = new Int_t[1];
0839           fCnew++;
0840           fTagAvLfn[0] = (Int_t)0;
0841           fTagAvHfn = new Int_t[1];
0842           fCnew++;
0843           fTagAvHfn[0] = (Int_t)0;
0844           fTagAvMeanCorss = new Int_t[1];
0845           fCnew++;
0846           fTagAvMeanCorss[0] = (Int_t)0;
0847           fTagAvSigCorss = new Int_t[1];
0848           fCnew++;
0849           fTagAvSigCorss[0] = (Int_t)0;
0850 
0851           //====================================================================================
0852           //
0853           //   allocation for fT1d_StexStinFromIndex[] and init to fSpecialStexStinNotIndexed
0854           //
0855           //====================================================================================
0856 
0857           if (fT1d_StexStinFromIndex == nullptr) {
0858             fT1d_StexStinFromIndex = new Int_t[fEcal->MaxStinEcnaInStex()];
0859             fCnew++;
0860           }
0861           for (Int_t i0_Stin = 0; i0_Stin < fEcal->MaxStinEcnaInStex(); i0_Stin++) {
0862             fT1d_StexStinFromIndex[i0_Stin] = fSpecialStexStinNotIndexed;
0863           }
0864 
0865           //-------------------------------------------------------------  (GetReadyToReadData)
0866 
0867           //====================================================================================
0868           //
0869           //   allocation of the 3D array fT3d_AdcValues[channel][sample][events] (ADC values)
0870           //
0871           //   This array is filled in the GetSampleAdcValues(...) method
0872           //
0873           //====================================================================================
0874 
0875           if (fT3d_AdcValues == nullptr) {
0876             //............ Allocation for the 3d array
0877             std::cout << "*TEcnaRun::GetReadyToReadData(...)> Allocation of 3D array for ADC distributions."
0878                       << " Nb of requested evts = " << fFileHeader->fReqNbOfEvts << std::endl
0879                       << "                                    This number must not be too large"
0880                       << " (no failure after this message means alloc OK)." << std::endl;
0881 
0882             fT3d_AdcValues = new Double_t**[fEcal->MaxCrysEcnaInStex()];
0883             fCnew++;
0884 
0885             fT3d2_AdcValues = new Double_t*[fEcal->MaxCrysEcnaInStex() * fNbSampForFic];
0886             fCnew++;
0887 
0888             fT3d1_AdcValues = new Double_t[fEcal->MaxCrysEcnaInStex() * fNbSampForFic * fFileHeader->fReqNbOfEvts];
0889             fCnew++;
0890 
0891             for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
0892               fT3d_AdcValues[i0StexEcha] = &fT3d2_AdcValues[0] + i0StexEcha * fNbSampForFic;
0893               for (Int_t j0Sample = 0; j0Sample < fNbSampForFic; j0Sample++) {
0894                 fT3d2_AdcValues[fNbSampForFic * i0StexEcha + j0Sample] =
0895                     &fT3d1_AdcValues[0] + fFileHeader->fReqNbOfEvts * (fNbSampForFic * i0StexEcha + j0Sample);
0896               }
0897             }
0898           }
0899           //................................. Init to zero
0900           for (Int_t iza = 0; iza < fEcal->MaxCrysEcnaInStex(); iza++) {
0901             for (Int_t izb = 0; izb < fNbSampForFic; izb++) {
0902               for (Int_t izc = 0; izc < fFileHeader->fReqNbOfEvts; izc++) {
0903                 if (fT3d_AdcValues[iza][izb][izc] != (Double_t)0) {
0904                   fMiscDiag[0]++;
0905                   fT3d_AdcValues[iza][izb][izc] = (Double_t)0;
0906                 }
0907               }
0908             }
0909           }
0910 
0911           //--------------------------------------------------------- (GetReadyToReadData)
0912           //====================================================================================
0913           //
0914           //   allocation of the 2D array fT2d_NbOfEvts[channel][sample] (Max nb of evts)
0915           //
0916           //====================================================================================
0917 
0918           if (fT2d_NbOfEvts == nullptr) {
0919             fT2d_NbOfEvts = new Int_t*[fEcal->MaxCrysEcnaInStex()];
0920             fCnew++;
0921             fT1d_NbOfEvts = new Int_t[fEcal->MaxCrysEcnaInStex() * fNbSampForFic];
0922             fCnew++;
0923 
0924             for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
0925               fT2d_NbOfEvts[i0StexEcha] = &fT1d_NbOfEvts[0] + i0StexEcha * fNbSampForFic;
0926             }
0927 
0928             //................ Init the array to 0
0929             for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
0930               for (Int_t i0Sample = 0; i0Sample < fNbSampForFic; i0Sample++) {
0931                 fT2d_NbOfEvts[i0StexEcha][i0Sample] = 0;
0932               }
0933             }
0934           } else {
0935             std::cerr << "!TEcnaRun::GetReadyToReadData(...)> *** ERROR *** No allocation for fT2d_NbOfEvts!"
0936                       << " Pointer already not NULL " << fTTBELL << std::endl;
0937             // {Int_t cintoto; std::cout << "Enter: 0 and RETURN to continue or: CTRL C to exit"
0938             //         << std::endl; std::cin >> cintoto;}
0939           }
0940         } else {
0941           std::cerr << std::endl
0942                     << "!TEcnaRun::GetReadyToReadData(...)> "
0943                     << " *** ERROR *** " << std::endl
0944                     << " --------------------------------------------------" << std::endl
0945                     << " NULL or NEGATIVE values for arguments" << std::endl
0946                     << " with expected positive values:" << std::endl
0947                     << " Number of Stins in Stex = " << fEcal->MaxStinEcnaInStex() << std::endl
0948                     << " Number of crystals in Stin     = " << fEcal->MaxCrysInStin() << std::endl
0949                     << " Number of samples by channel    = " << fNbSampForFic << std::endl
0950                     << std::endl
0951                     << std::endl
0952                     << " hence, no memory allocation for array member has been performed." << std::endl;
0953 
0954           std::cout << "Enter: 0 and RETURN to continue or: CTRL C to exit";
0955           Int_t toto;
0956           std::cin >> toto;
0957         }
0958         //----------------------------------------------------------- (GetReadyToReadData)
0959         if (fFlagPrint == fCodePrintAllComments) {
0960           std::cout << std::endl;
0961           std::cout << "*TEcnaRun::GetReadyToReadData(...)>" << std::endl
0962                     << "          The method has been called with the following argument values:" << std::endl
0963                     << "          Analysis name                = " << fFileHeader->fTypAna << std::endl
0964                     << "          Run number                   = " << fFileHeader->fRunNumber << std::endl
0965                     << "          Run type                     = " << fFileHeader->fRunType << std::endl
0966                     << "          First requested event number = " << fFileHeader->fFirstReqEvtNumber << std::endl
0967                     << "          Last requested event number  = " << fFileHeader->fLastReqEvtNumber << std::endl
0968                     << "          " << fStexName.Data() << " number                  = " << fFileHeader->fStex
0969                     << std::endl
0970                     << "          Number of " << fStinName.Data() << " in " << fStexName.Data() << "       = "
0971                     << fEcal->MaxStinEcnaInStex() << std::endl
0972                     << "          Number of crystals in " << fStinName.Data() << "  = " << fEcal->MaxCrysInStin()
0973                     << std::endl
0974                     << "          Number of samples by channel = " << fNbSampForFic << std::endl
0975                     << std::endl;
0976         }
0977 
0978         fReadyToReadData = 1;  // set flag
0979       } else {
0980         if (fFlagPrint != fCodePrintNoComment) {
0981           std::cout << "!TEcnaRun::GetReadyToReadData(...) > WARNING/CORRECTION:" << std::endl
0982                     << "! The fisrt requested event number is not positive (nfirst = " << nfirst << ") " << fTTBELL
0983                     << std::endl;
0984         }
0985       }
0986     } else {
0987       if (fFlagPrint != fCodePrintNoComment) {
0988         std::cout << std::endl
0989                   << "!TEcnaRun::GetReadyToReadData(...)> WARNING/CORRECTION:" << std::endl
0990                   << "! The number of requested events (nbevts = " << nbevts << ") is too large." << std::endl
0991                   << "! Last event number = " << nlast << " > number of entries = " << nentries << ". " << fTTBELL
0992                   << std::endl
0993                   << std::endl;
0994       }
0995     }
0996   } else {
0997     std::cout << "!TEcnaRun::GetReadyToReadData(...) *** ERROR ***> "
0998               << " The first requested event number is greater than the number of entries." << fTTBELL << std::endl;
0999   }
1000   if (fFlagPrint == fCodePrintAllComments) {
1001     std::cout << "*TEcnaRun::GetReadyToReadData(...)> Leaving the method. fReadyToReadData = " << fReadyToReadData
1002               << std::endl;
1003   }
1004 
1005 }  // end of GetReadyToReadData
1006 
1007 //====================================================================================================
1008 //
1009 //     GetSampleAdcValues: method called by the CMSSW analyzer (cmsRun)
1010 //
1011 //     At each event, put the Sample ADC value in the 3D array: fT3d_AdcValues[i0StexEcha][i0Sample][i0EventIndex]
1012 //
1013 //         |============================================================|
1014 //         |                                                            |
1015 //         | (Stex,Stin) means: (SM,tower) for EB and: (Dee,SC) for EE  |
1016 //         |                                                            |
1017 //         |============================================================|
1018 //
1019 //    (Stin number <-> Stin index correspondance, ADC sample values)
1020 //
1021 //        THIS METHOD IS CALLED INSIDE THE LOOPS OVER:
1022 //          ( EVENTS (tower or SC (CRYSTAL in tower or SC (SAMPLES))))
1023 //
1024 //  Arguments: Event    = event number.              Range = [ 1, fFileHeader->fReqNbOfEvts ]
1025 //             n1StexStin = Stin number in Stex.     Range = [ 1, fEcal->MaxStinEcnaInStex() ]
1026 //             i0StinEcha = channel number in Stin.  Range = [ 0, fEcal->MaxCrysInStin() - 1 ]
1027 //             sample   = ADC sample number.         Range = [ 0, fNbSampForFic - 1 ]
1028 //             adcvalue = ADC sample value.
1029 //
1030 //====================================================================================================
1031 Bool_t TEcnaRun::GetSampleAdcValues(const Int_t& n1EventNumber,
1032                                     const Int_t& n1StexStin,
1033                                     const Int_t& i0StinEcha,
1034                                     const Int_t& i0Sample,
1035                                     const Double_t& adcvalue) {
1036   //Building of the arrays fT1d_StexStinFromIndex[] and fT3d_AdcValues[][][]
1037 
1038   fBuildEvtNotSkipped++;  // event not skipped by cmsRun
1039 
1040   Bool_t ret_code = kFALSE;
1041 
1042   Int_t i0EventIndex = n1EventNumber - 1;  // INDEX FOR Event number
1043   Int_t i0StexStinEcna = n1StexStin - 1;   // INDEX FOR StexStin = Number_of_the_Stin_in_Stex - 1
1044 
1045   Int_t i_trouve = 0;
1046   //.................................................................. (GetSampleAdcValues)
1047   if (fReadyToReadData == 1) {
1048     if (n1StexStin >= 1 && n1StexStin <= fEcal->MaxStinEcnaInStex()) {
1049       if (i0StinEcha >= 0 && i0StinEcha < fEcal->MaxCrysInStin()) {
1050         if (i0Sample >= 0 && i0Sample < fEcal->MaxSampADC()) {
1051           //..... Put the StexStin number in 1D array fT1d_StexStinFromIndex[] = Stin index + 1
1052           if (fT1d_StexStinFromIndex != nullptr)  // table fT1d_StexStinFromIndex[index] already allocated
1053           {
1054             ret_code = kTRUE;
1055 
1056             // StexStin already indexed
1057             if (n1StexStin == fT1d_StexStinFromIndex[i0StexStinEcna]) {
1058               i_trouve = 1;
1059             }
1060 
1061             // StexStin index not found: set index for new StexStin
1062             if (i_trouve != 1) {
1063               if (fT1d_StexStinFromIndex[i0StexStinEcna] == fSpecialStexStinNotIndexed) {
1064                 fT1d_StexStinFromIndex[i0StexStinEcna] = n1StexStin;
1065                 fFileHeader->fStinNumbersCalc = 1;
1066                 fTagStinNumbers[0] = 1;
1067                 fStinIndexBuilt++;  //  number of found Stins
1068 
1069                 if (fFlagPrint == fCodePrintAllComments) {
1070                   if (fStinIndexBuilt == 1) {
1071                     std::cout << std::endl
1072                               << "*TEcnaRun::GetSampleAdcValues(...)> event " << n1EventNumber << " : first event for "
1073                               << fStexName.Data() << " " << fFileHeader->fStex << "; " << fStinName.Data() << "s : ";
1074                   }
1075                   if (fFlagSubDet == "EB") {
1076                     std::cout << fT1d_StexStinFromIndex[i0StexStinEcna] << ", ";
1077                   }
1078                   if (fFlagSubDet == "EE") {
1079                     std::cout << fEcalNumbering->GetDeeSCConsFrom1DeeSCEcna(fFileHeader->fStex,
1080                                                                             fT1d_StexStinFromIndex[i0StexStinEcna])
1081                               << ", ";
1082                   }
1083                 }
1084                 //.................................................... (GetSampleAdcValues)
1085                 if (fFlagPrint == fCodePrintAllComments) {
1086                   std::cout << " (" << fStinIndexBuilt << " " << fStinName.Data() << " found), channel " << i0StinEcha
1087                             << ", i0Sample " << i0Sample << std::endl;
1088                 }
1089                 ret_code = kTRUE;
1090               }  // if ( fT1d_StexStinFromIndex[i0StexStinEcna] == fSpecialStexStinNotIndexed )
1091               else {
1092                 std::cout << "!TEcnaRun::GetSampleAdcValues(...)> *** ERROR ***> NOT ALLOWED if RESULT. "
1093                           << " n1StexStin = " << n1StexStin << ", fT1d_StexStinFromIndex[" << i0StexStinEcna
1094                           << "] = " << fT1d_StexStinFromIndex[i0StexStinEcna]
1095                           << ", fStinIndexBuilt = " << fStinIndexBuilt << fTTBELL << std::endl;
1096                 ret_code = kFALSE;
1097               }
1098             }  //  if (i_trouve != 1 )
1099 
1100           }  //  if( fT1d_StexStinFromIndex != 0 )
1101           else {
1102             std::cout << "!TEcnaRun, GetSampleAdcValues *** ERROR ***> "
1103                       << " fT1d_StexStinFromIndex = " << fT1d_StexStinFromIndex
1104                       << " fT1d_StexStinFromIndex[] ALLOCATION NOT DONE" << fTTBELL << std::endl;
1105             ret_code = kFALSE;
1106           }  //.................................................................. (GetSampleAdcValues)
1107         }    // end of if( i0Sample >= 0 && i0Sample < fNbSampForFic )
1108         else {
1109           //.......Reading data => Message and error only if sample >= fEcal->MaxSampADC()
1110           //       (not fNbSampForFic, the later is used only for calculations)
1111           if (i0Sample >= fEcal->MaxSampADC()) {
1112             std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
1113                       << " sample number = " << i0Sample << ". OUT OF BOUNDS"
1114                       << " (max = " << fNbSampForFic << ")" << fTTBELL << std::endl;
1115             ret_code = kFALSE;
1116           } else {
1117             ret_code = kTRUE;
1118           }
1119         }  // else of if( i0Sample >= 0 && i0Sample < fNbSampForFic )
1120       }    // end of if( i0StinEcha >= 0 && i0StinEcha < fEcal->MaxCrysInStin() )
1121       else {
1122         std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
1123                   << " channel number in " << fStinName.Data() << " = " << i0StinEcha << ". OUT OF BOUNDS"
1124                   << " (max = " << fEcal->MaxCrysInStin() << ")" << fTTBELL << std::endl;
1125         ret_code = kFALSE;
1126       }  // else of if( i0StinEcha >= 0 && i0StinEcha < fEcal->MaxCrysInStin() )
1127     } else {
1128       std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> " << fStinName.Data() << " number in "
1129                 << fStexName.Data() << " = " << n1StexStin << ". OUT OF BOUNDS"
1130                 << " (max = " << fEcal->MaxStinEcnaInStex() << ")" << fTTBELL << std::endl;
1131       ret_code = kFALSE;
1132     }
1133 
1134     //.................................................................. (GetSampleAdcValues)
1135     //........ Filling of the 2D array of the event numbers in the data reading loop and
1136     //         filling of the 3D array of the ADC sample values
1137     //
1138     //                           ONLY if ret_code == kTRUE
1139 
1140     if (ret_code == kTRUE) {
1141       //............ 1) Conversion (Stin,i0StinEcha) -> i0StexEcha  (same numbering for EB and EE)
1142       //==========================================================================================
1143       //   n1StexStin (Tower or SC):      1            2            3
1144       //   iStexStin                      0            1            2
1145       //
1146       //   i0StinEcha:                 0......24    0......24    0......24
1147       //
1148       //   i0StexEcha         :        0......24   25......49   50......74  grouped by StexStin's
1149       //   i0StexEcha+1 (Xtal):        1......25   26......50   51......75
1150       //
1151       //==========================================================================================
1152 
1153       Int_t i0StexEcha = i0StexStinEcna * fEcal->MaxCrysInStin() + i0StinEcha;
1154 
1155       //--------------------------------------------------------- (GetSampleAdcValues)
1156       if (i0StexEcha >= 0 && i0StexEcha < fEcal->MaxCrysEcnaInStex()) {
1157         //............ 2) Increase of the nb of evts for (StexEcha,sample) (events found in the data)
1158         (fT2d_NbOfEvts[i0StexEcha][i0Sample])++;  // value after first incrementation = 1
1159         fTagNbOfEvts[0] = 1;
1160         fFileHeader->fNbOfEvtsCalc = 1;
1161 
1162         //............ 3) Filling of the 3D array of the ADC values
1163         if (i0EventIndex >= 0 && i0EventIndex < fFileHeader->fReqNbOfEvts) {
1164           if (i0Sample >= 0 && i0Sample < fNbSampForFic) {
1165             fT3d_AdcValues[i0StexEcha][i0Sample][i0EventIndex] = adcvalue;
1166           } else {
1167             std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
1168                       << " sample index = " << i0Sample << ". OUT OF BOUNDS"
1169                       << " (max = " << fNbSampForFic << ")" << fTTBELL << std::endl;
1170           }
1171         } else {
1172           std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
1173                     << " event number = " << n1EventNumber << ". OUT OF BOUNDS"
1174                     << " (max = " << fFileHeader->fReqNbOfEvts << ")" << fTTBELL << std::endl;
1175           ret_code = kFALSE;
1176         }
1177       } else {
1178         std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
1179                   << " CHANNEL NUMBER OUT OF BOUNDS" << std::endl
1180                   << " i0StexEcha number = " << i0StexEcha << " , n1StexStin = " << n1StexStin
1181                   << " , i0StinEcha = " << i0StinEcha
1182                   << " , fEcal->MaxCrysEcnaInStex() = " << fEcal->MaxCrysEcnaInStex() << fTTBELL << std::endl;
1183         ret_code = kFALSE;
1184         // {Int_t cintoto; std::cout << "TAPER 0 POUR CONTINUER" << std::endl; cin >> cintoto;}
1185       }
1186     }  // end of if( ret_code == kTRUE )
1187     else {
1188       std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> ret_code = kFALSE " << fTTBELL << std::endl;
1189     }
1190   }  // end of if(fReadyToReadData == 1)
1191   else {
1192     std::cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> GetReadyToReadData(...) not called." << fTTBELL
1193               << std::endl;
1194     ret_code = kFALSE;
1195   }
1196   //.................................................................. (GetSampleAdcValues)
1197   if (ret_code == kFALSE) {
1198     std::cout << "!TEcnaRun::GetSampleAdcValues(...)> *** ERROR ***> ret_code = " << ret_code
1199               << " (FALSE). Event: " << n1EventNumber << ", " << fStexName.Data() << ": " << fFileHeader->fStex << ", "
1200               << fStinName.Data() << ": " << n1StexStin << ", channel: " << i0StinEcha << ", Sample: " << i0Sample
1201               << ", ADC value: " << adcvalue << std::endl;
1202   }
1203   return ret_code;
1204 }
1205 //------------- ( end of GetSampleAdcValues ) -----------------------
1206 //====================================================================================================
1207 //
1208 //  ReadSampleAdcValues: Get the Sample ADC values from file by using TEcnaRead.
1209 //
1210 //====================================================================================================
1211 Bool_t TEcnaRun::ReadSampleAdcValues() { return ReadSampleAdcValues(fEcal->MaxSampADC()); }
1212 
1213 Bool_t TEcnaRun::ReadSampleAdcValues(const Int_t& nb_samp_for_calc) {
1214   // read the Sample ADC values from "ADC" result root files                     (ReadSampleAdcValues)
1215 
1216   // put the number of sample for calculations in attribute fNbSampForCalc
1217   // and call the method without arguments
1218   // We must have: nb_samp_for_calc <= fFileHeader->fNbOfSamples (= nb of samples in ROOT file)
1219 
1220   fNbSampForCalc = nb_samp_for_calc;
1221 
1222   //   TEcnaRead* MyRootFile = new TEcnaRead(fFlagSubDet.Data(), fCnaParPaths, fCnaParCout,
1223   //                       fFileHeader, fEcalNumbering, fCnaWrite);          //  fCnew++;
1224 
1225   TEcnaRead* MyRootFile = new TEcnaRead(fObjectManager, fFlagSubDet.Data());  //  fCnew++;
1226 
1227   MyRootFile->PrintNoComment();
1228 
1229   MyRootFile->FileParameters(fFileHeader->fTypAna,
1230                              fFileHeader->fNbOfSamples,
1231                              fFileHeader->fRunNumber,
1232                              fFileHeader->fFirstReqEvtNumber,
1233                              fFileHeader->fLastReqEvtNumber,
1234                              fFileHeader->fReqNbOfEvts,
1235                              fFileHeader->fStex,
1236                              fCnaParPaths->ResultsRootFilePath().Data());
1237 
1238   Bool_t ok_read = MyRootFile->LookAtRootFile();
1239 
1240   fFileHeader->fStartTime = MyRootFile->GetStartTime();
1241   fFileHeader->fStopTime = MyRootFile->GetStopTime();
1242   fFileHeader->fStartDate = MyRootFile->GetStartDate();
1243   fFileHeader->fStopDate = MyRootFile->GetStopDate();
1244 
1245   if (ok_read == kTRUE) {
1246     fRootFileName = MyRootFile->GetRootFileName();
1247     fRootFileNameShort = MyRootFile->GetRootFileNameShort();
1248     std::cout << "*TEcnaRun::ReadSampleAdcValues> Reading sample ADC values from file: " << std::endl
1249               << "           " << fRootFileName << std::endl;
1250 
1251     size_t i_no_data = 0;
1252 
1253     //.......... Read the StinNumbers in the old file                     (ReadSampleAdcValues)
1254     TVectorD vec(fEcal->MaxStinEcnaInStex());
1255     for (Int_t i = 0; i < fEcal->MaxStinEcnaInStex(); i++) {
1256       vec(i) = (Double_t)0.;
1257     }
1258     vec = MyRootFile->ReadStinNumbers(fEcal->MaxStinEcnaInStex());
1259     if (MyRootFile->DataExist() == kTRUE) {
1260       fTagStinNumbers[0] = 1;
1261       fFileHeader->fStinNumbersCalc = 1;
1262       for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
1263         fT1d_StexStinFromIndex[i0StexStinEcna] = (Int_t)vec(i0StexStinEcna);
1264       }
1265     } else {
1266       i_no_data++;
1267     }
1268     //.......... Read the Numbers of Events in the old file                      (ReadSampleAdcValues)
1269     TMatrixD partial_matrix(fEcal->MaxCrysInStin(), fFileHeader->fNbOfSamples);
1270     for (Int_t i = 0; i < fEcal->MaxCrysInStin(); i++) {
1271       for (Int_t j = 0; j < fFileHeader->fNbOfSamples; j++) {
1272         partial_matrix(i, j) = (Double_t)0.;
1273       }
1274     }
1275 
1276     for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
1277       Int_t n1StexStin = MyRootFile->GetStexStinFromIndex(i0StexStinEcna);
1278       if (n1StexStin != -1) {
1279         partial_matrix =
1280             MyRootFile->ReadNumberOfEventsForSamples(n1StexStin, fEcal->MaxCrysInStin(), fFileHeader->fNbOfSamples);
1281 
1282         if (MyRootFile->DataExist() == kTRUE) {
1283           fTagNbOfEvts[0] = 1;
1284           fFileHeader->fNbOfEvtsCalc = 1;
1285           for (Int_t i0StinCrys = 0; i0StinCrys < fEcal->MaxCrysInStin(); i0StinCrys++) {
1286             Int_t i0StexEcha = (n1StexStin - 1) * fEcal->MaxCrysInStin() + i0StinCrys;
1287             for (Int_t i0Sample = 0; i0Sample < fFileHeader->fNbOfSamples; i0Sample++) {
1288               fT2d_NbOfEvts[i0StexEcha][i0Sample] = (Int_t)partial_matrix(i0StinCrys, i0Sample);
1289             }
1290           }
1291         } else {
1292           i_no_data++;
1293         }
1294       }
1295     }
1296 
1297     //.......... Read the Sample ADC values in the old file                     (ReadSampleAdcValues)
1298     Double_t*** fT3d_read_AdcValues = MyRootFile->ReadSampleAdcValuesSameFile(
1299         fEcal->MaxCrysEcnaInStex(), fFileHeader->fNbOfSamples, fFileHeader->fReqNbOfEvts);
1300 
1301     if (MyRootFile->DataExist() == kTRUE) {
1302       for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1303         for (Int_t i0Sample = 0; i0Sample < fFileHeader->fNbOfSamples; i0Sample++) {
1304           for (Int_t i_event = 0; i_event < fFileHeader->fReqNbOfEvts; i_event++) {
1305             fT3d_AdcValues[i0StexEcha][i0Sample][i_event] = fT3d_read_AdcValues[i0StexEcha][i0Sample][i_event];
1306           }
1307         }
1308       }
1309     } else {
1310       i_no_data++;
1311     }
1312     if (i_no_data) {
1313       std::cout << "!TEcnaRun::ReadSampleAdcValues(...)> *ERROR* =====> "
1314                 << " Read failure. i_no_data = " << i_no_data << fTTBELL << std::endl;
1315     }
1316   } else {
1317     std::cout << "!TEcnaRun::ReadSampleAdcValues(...)> *ERROR* =====> "
1318               << " ROOT file not found" << fTTBELL << std::endl;
1319   }
1320   delete MyRootFile;  //  fCdelete++;
1321   return ok_read;
1322 }
1323 //------------- ( end of ReadSampleAdcValues ) -----------------------
1324 //-------------------------------------------------------------------------
1325 //
1326 //    Get the ROOT file name (long and short)
1327 //
1328 //-------------------------------------------------------------------------
1329 TString TEcnaRun::GetRootFileName() { return fRootFileName; }
1330 TString TEcnaRun::GetRootFileNameShort() { return fRootFileNameShort; }
1331 
1332 //###################################################################################################
1333 //
1334 // THE FOLLOWING METHODS ARE CALLED AFTER THE LOOPS OVER EVENTS, STINS, CRYSTALS AND SAMPLES
1335 //
1336 //###################################################################################################
1337 //=========================================================================
1338 //
1339 //     Set start time, stop time, StartDate, StopDate
1340 //
1341 //=========================================================================
1342 void TEcnaRun::StartStopTime(time_t t_startime, time_t t_stoptime) {
1343   // Put the start an stop time (if they exist) in fFileHeader class attributes.
1344 
1345   fFileHeader->fStartTime = t_startime;
1346   fFileHeader->fStopTime = t_stoptime;
1347 }
1348 
1349 void TEcnaRun::StartStopDate(const TString& c_startdate, const TString& c_stopdate) {
1350   // Put the start an stop date (if they exist) in fFileHeader class attributes.
1351 
1352   fFileHeader->fStartDate = c_startdate;
1353   fFileHeader->fStopDate = c_stopdate;
1354 }
1355 
1356 //=========================================================================
1357 //
1358 //                         GetReadyToCompute()   (technical)
1359 //
1360 //=========================================================================
1361 void TEcnaRun::GetReadyToCompute() {
1362   //
1363   // MAKE THE RESULTS FILE NAME and
1364   // CHECK OF THE NUMBER OF FOUND EVENTS AND init fNumberOfEvents
1365   // (number used to compute the average values over the events)
1366   // The number of events fNumberOfEvents is extracted from the array fT2d_NbOfEvts[]
1367   // which has been filled by the GetSampleAdcValues(...) method
1368 
1369   //..................... Making of the Root File name that will be written
1370   fCnaWrite->RegisterFileParameters(fFileHeader->fTypAna.Data(),
1371                                     fFileHeader->fNbOfSamples,
1372                                     fFileHeader->fRunNumber,
1373                                     fFileHeader->fFirstReqEvtNumber,
1374                                     fFileHeader->fLastReqEvtNumber,
1375                                     fFileHeader->fReqNbOfEvts,
1376                                     fFileHeader->fStex);
1377 
1378   fCnaWrite->fMakeResultsFileName();  // set fRootFileName, fRootFileNameShort
1379 
1380   //..................... Checking numbers of found events channel by channel
1381   if (fT2d_NbOfEvts != nullptr) {
1382     fNumberOfEvents = fCnaWrite->NumberOfEventsAnalysis(
1383         fT2d_NbOfEvts, fEcal->MaxCrysEcnaInStex(), fNbSampForFic, fFileHeader->fReqNbOfEvts);
1384   } else {
1385     std::cout << "*TEcnaRun::GetReadyToCompute()> no data? fT2d_NbOfEvts = " << fT2d_NbOfEvts << std::endl;
1386   }
1387 }
1388 //  end of GetReadyToCompute()
1389 
1390 //-------------------------------------------------------------------
1391 //
1392 //                      SampleValues()      (technical)
1393 //
1394 //  Written in .root file corresponding to analysis name
1395 //  beginning with: "Adc" (see EcnaAnalyzer.cc in package "Modules")
1396 //
1397 //-------------------------------------------------------------------
1398 void TEcnaRun::SampleValues() {
1399   //3D histo of the sample ADC values for all the triples (StexEcha, sample, event)
1400 
1401   // The histo is already in fT3d_AdcValues[][][]
1402   // this method sets the "Tag", increment the "f...Calc" (and must be kept for that)
1403   // f...Calc > 0  => allow writing on file.
1404 
1405   if (fFileHeader->fAdcEvtCalc > 0) {
1406     fFileHeader->fAdcEvtCalc = 0;
1407   }
1408   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1409     fTagAdcEvt[i0StexEcha] = 1;
1410     fFileHeader->fAdcEvtCalc++;
1411   }
1412 }
1413 
1414 //=========================================================================
1415 //
1416 //               C A L C U L A T I O N    M E T H O D S
1417 //
1418 //     fTag... = 1 => Calculation done. OK for writing on result file
1419 //     ...Calc++   => Incrementation for result file size.
1420 //
1421 //=========================================================================
1422 void TEcnaRun::StandardCalculations() {
1423   SampleMeans();
1424   SampleSigmas();
1425   CorrelationsBetweenSamples();
1426 
1427   Pedestals();  // => mean over Xtal's
1428   TotalNoise();
1429   LowFrequencyNoise();
1430   HighFrequencyNoise();
1431   MeanCorrelationsBetweenSamples();
1432   SigmaOfCorrelationsBetweenSamples();
1433 
1434   AveragePedestals();  // Average => mean over Stin's (Tower if EB, SC if EE)
1435   AverageTotalNoise();
1436   AverageLowFrequencyNoise();
1437   AverageHighFrequencyNoise();
1438   AverageMeanCorrelationsBetweenSamples();
1439   AverageSigmaOfCorrelationsBetweenSamples();
1440 }
1441 
1442 void TEcnaRun::Expert1Calculations() {
1443   // long time, big file
1444 
1445   LowFrequencyCorrelationsBetweenChannels();
1446   HighFrequencyCorrelationsBetweenChannels();
1447 }
1448 
1449 void TEcnaRun::Expert2Calculations() {
1450   // long time, no big file
1451   // expert 1 is called (if not called before) without writing in file.
1452   // Results are used only in memory to compute expert2 calculations
1453 
1454   LowFrequencyMeanCorrelationsBetweenStins();
1455   HighFrequencyMeanCorrelationsBetweenStins();
1456 }
1457 //====================================================================
1458 //
1459 //       E X P E C T A T I O N   V A L U E S  ,  V A R I A N C E S
1460 //
1461 //====================================================================
1462 //----------------------------------------------------------------
1463 //  Calculation of the expectation values of the samples
1464 //  for all the StexEchas
1465 //
1466 //  SMean(c,s)  = E_e[A(c,s,e*)]
1467 //  A(c,s,e) : ADC value for channel c, sample s, event e
1468 //  E_e : average over the events
1469 //----------------------------------------------------------------
1470 void TEcnaRun::SampleMeans() {
1471   // Calculation of the expectation values over events
1472   // for the samples 0 to fNbSampForCalc and for all the StexEchas
1473 
1474   if (fFlagPrint != fCodePrintNoComment) {
1475     std::cout << "*TEcnaRun::SampleMeans() " << std::endl;
1476   }
1477   if (fFlagPrint == fCodePrintAllComments) {
1478     std::cout << "           Calculation: sample expectation values over the events"
1479               << " for each channel." << std::endl;
1480   }
1481 
1482   //................... Allocation fT2d_ev
1483   if (fT2d_ev == nullptr) {
1484     Int_t n_samp = fNbSampForCalc;
1485     Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
1486     fT2d_ev = new Double_t*[n_StexEcha];
1487     fCnew++;
1488     fT1d_ev = new Double_t[n_StexEcha * n_samp];
1489     fCnew++;
1490     for (Int_t i = 0; i < n_StexEcha; i++) {
1491       fT2d_ev[i] = &fT1d_ev[0] + i * n_samp;
1492     }
1493   }
1494   //................... init fT2d_ev to zero
1495   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1496     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1497       if (fT2d_ev[i0StexEcha][i0Sample] != (Double_t)0) {
1498         fMiscDiag[1]++;
1499         fT2d_ev[i0StexEcha][i0Sample] = (Double_t)0;
1500       }
1501     }
1502   }
1503 
1504   //................... Calculation
1505   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1506     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1507       for (Int_t i_event = 0; i_event < fNumberOfEvents; i_event++) {
1508         fT2d_ev[i0StexEcha][i0Sample] += fT3d_AdcValues[i0StexEcha][i0Sample][i_event];
1509       }
1510       fT2d_ev[i0StexEcha][i0Sample] /= fNumberOfEvents;
1511     }
1512   }
1513   fTagMSp[0] = 1;
1514   fFileHeader->fMSpCalc++;
1515 }
1516 
1517 //--------------------------------------------------------
1518 //  Calculation of the sigmas of the samples
1519 //  for all the StexEchas
1520 //
1521 //  SSigma(c,s) = sqrt{ Cov_e[A(c,s,e*),A(c,s,e*)] }
1522 //  A(c,s,e) : ADC value for channel c, sample s, event e
1523 //  Cov_e : covariance over the events
1524 //--------------------------------------------------------
1525 void TEcnaRun::SampleSigmas() {
1526   //Calculation of the sigmas of the samples for all the StexEchas
1527 
1528   if (fFlagPrint != fCodePrintNoComment) {
1529     std::cout << "*TEcnaRun::SampleSigmas()" << std::endl;
1530   }
1531   if (fFlagPrint == fCodePrintAllComments) {
1532     std::cout << "           Calculation: sample ADC sigmas over the events "
1533               << " for each channel." << std::endl;
1534   }
1535 
1536   //... preliminary calculation of the expectation values if not done yet.
1537   //    The tag is set to 1 after call to the method. It is reset to 0
1538   //    because the expectation values must not be written in the result ROOT file
1539   //    (since the tag was equal to 0)
1540   if (fTagMSp[0] != 1) {
1541     SampleMeans();
1542     fTagMSp[0] = 0;
1543   }
1544 
1545   //................... Allocation fT2d_sig
1546   if (fT2d_sig == nullptr) {
1547     Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
1548     Int_t n_samp = fNbSampForCalc;
1549     fT2d_sig = new Double_t*[n_StexEcha];
1550     fCnew++;
1551     fT1d_sig = new Double_t[n_StexEcha * n_samp];
1552     fCnew++;
1553     for (Int_t i0StexEcha = 0; i0StexEcha < n_StexEcha; i0StexEcha++) {
1554       fT2d_sig[i0StexEcha] = &fT1d_sig[0] + i0StexEcha * n_samp;
1555     }
1556   }
1557   // ................... init fT2d_sig to zero
1558   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1559     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1560       if (fT2d_sig[i0StexEcha][i0Sample] != (Double_t)0) {
1561         fMiscDiag[2]++;
1562         fT2d_sig[i0StexEcha][i0Sample] = (Double_t)0;
1563       }
1564     }
1565   }
1566 
1567   //................... Calculation
1568   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1569     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1570       Double_t variance = (Double_t)0.;
1571       for (Int_t i_event = 0; i_event < fNumberOfEvents; i_event++) {
1572         Double_t ecart = fT3d_AdcValues[i0StexEcha][i0Sample][i_event] - fT2d_ev[i0StexEcha][i0Sample];
1573         variance += ecart * ecart;
1574       }
1575       variance /= fNumberOfEvents;
1576       fT2d_sig[i0StexEcha][i0Sample] = sqrt(variance);
1577     }
1578   }
1579   fTagSSp[0] = 1;
1580   fFileHeader->fSSpCalc++;
1581 }
1582 
1583 //====================================================================
1584 //
1585 //       C O V A R I A N C E S   &   C O R R E L A T I O N S
1586 //
1587 //                 B E T W E E N   S A M P L E S
1588 //
1589 //====================================================================
1590 //-----------------------------------------------------------
1591 //  Calculation of the covariances between samples
1592 //  for all the StexEchas
1593 //  Cov(c;s,s') = Cov_e[ A(c,s,e*) , A(c,s',e*) ]
1594 //              = E_e[ ( A(c,s,e*) - E_e[A(c,s,e*)] )*
1595 //                     ( A(c,s',e*) - E_e[A(c,s',e*)] ) ]
1596 //  A(c,s,e)    : ADC value for channel c, sample s, event e
1597 //  E_e , Cov_e : average, covariance over the events
1598 //-----------------------------------------------------------
1599 void TEcnaRun::CovariancesBetweenSamples() {
1600   //Calculation of the covariances between samples for all the StexEchas
1601 
1602   if (fFlagPrint != fCodePrintNoComment) {
1603     std::cout << "*TEcnaRun::CovariancesBetweenSamples()" << std::endl;
1604   }
1605   if (fFlagPrint == fCodePrintAllComments) {
1606     std::cout << "           Calculation: covariances between samples"
1607               << " for each channel." << std::endl;
1608   }
1609 
1610   //................... Allocations cov_ss
1611   if (fT3d_cov_ss == nullptr) {
1612     const Int_t n_samp = fNbSampForCalc;
1613     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
1614     fT3d_cov_ss = new Double_t**[n_StexEcha];
1615     fCnew++;
1616     fT3d2_cov_ss = new Double_t*[n_StexEcha * n_samp];
1617     fCnew++;
1618     fT3d1_cov_ss = new Double_t[n_StexEcha * n_samp * n_samp];
1619     fCnew++;
1620     for (Int_t i = 0; i < n_StexEcha; i++) {
1621       fT3d_cov_ss[i] = &fT3d2_cov_ss[0] + i * n_samp;
1622       for (Int_t j = 0; j < n_samp; j++) {
1623         fT3d2_cov_ss[n_samp * i + j] = &fT3d1_cov_ss[0] + n_samp * (n_samp * i + j);
1624       }
1625     }
1626   }
1627 
1628   //.................. Calculation (= init)
1629   //.................. computation of half of the matrix, diagonal included)
1630 
1631   //... preliminary calculation of the expectation values if not done yet.
1632   //    The tag is set to 1 after call to the method. It is reset to 0
1633   //    because the expectation values must not be written in the result ROOT file
1634   //    (since the tag was equal to 0)
1635   //    Results in array  fT2d_ev[j0StexEcha][i0Sample]
1636   if (fTagMSp[0] != 1) {
1637     SampleMeans();
1638     fTagMSp[0] = 0;
1639   }
1640 
1641   for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
1642     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1643       for (Int_t j0Sample = 0; j0Sample <= i0Sample; j0Sample++) {
1644         fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample] = (Double_t)0;
1645         for (Int_t i_event = 0; i_event < fNumberOfEvents; i_event++) {
1646           fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample] +=
1647               (fT3d_AdcValues[j0StexEcha][i0Sample][i_event] - fT2d_ev[j0StexEcha][i0Sample]) *
1648               (fT3d_AdcValues[j0StexEcha][j0Sample][i_event] - fT2d_ev[j0StexEcha][j0Sample]);
1649         }
1650         fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample] /= (Double_t)fNumberOfEvents;
1651         fT3d_cov_ss[j0StexEcha][j0Sample][i0Sample] = fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample];
1652       }
1653     }
1654     fTagCovCss[j0StexEcha] = 1;
1655     fFileHeader->fCovCssCalc++;
1656   }
1657 }
1658 
1659 //-----------------------------------------------------------
1660 //
1661 //  Calculation of the correlations between samples
1662 //  for all the StexEchas
1663 //  Cor(c;s,s') = Cov(c;s,s')/sqrt{ Cov(c;s,s)*Cov(c;s',s') }
1664 //-----------------------------------------------------------
1665 void TEcnaRun::CorrelationsBetweenSamples() {
1666   //Calculation of the correlations between samples for all the StexEchas
1667 
1668   //... preliminary calculation of the covariances if not done yet.
1669   //    Test only the first tag since the cov are computed globaly
1670   //    but set all the tags to 0 because we don't want to write
1671   //    the covariances in the result ROOT file
1672   if (fTagCovCss[0] != 1) {
1673     CovariancesBetweenSamples();
1674     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
1675       fTagCovCss[j0StexEcha] = 0;
1676     }
1677   }
1678 
1679   if (fFlagPrint != fCodePrintNoComment) {
1680     std::cout << "*TEcnaRun::CorrelationsBetweenSamples()" << std::endl;
1681   }
1682   if (fFlagPrint == fCodePrintAllComments) {
1683     std::cout << "           Calculation: correlations between samples"
1684               << " for each channel." << std::endl;
1685   }
1686 
1687   //................... Allocations cor_ss
1688   if (fT3d_cor_ss == nullptr) {
1689     const Int_t n_samp = fNbSampForCalc;
1690     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
1691     fT3d_cor_ss = new Double_t**[n_StexEcha];
1692     fCnew++;
1693     fT3d2_cor_ss = new Double_t*[n_StexEcha * n_samp];
1694     fCnew++;
1695     fT3d1_cor_ss = new Double_t[n_StexEcha * n_samp * n_samp];
1696     fCnew++;
1697     for (Int_t i = 0; i < n_StexEcha; i++) {
1698       fT3d_cor_ss[i] = &fT3d2_cor_ss[0] + i * n_samp;
1699       for (Int_t j = 0; j < n_samp; j++) {
1700         fT3d2_cor_ss[n_samp * i + j] = &fT3d1_cor_ss[0] + n_samp * (n_samp * i + j);
1701       }
1702     }
1703   }
1704 
1705   //..................... calculation of the correlations (=init)
1706   //......................computation of half of the matrix, diagonal included (verif = 1)
1707 
1708   for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
1709     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1710       for (Int_t j0Sample = 0; j0Sample <= i0Sample; j0Sample++) {
1711         if ((fT3d_cov_ss[j0StexEcha][i0Sample][i0Sample] > 0) && (fT3d_cov_ss[j0StexEcha][j0Sample][j0Sample] > 0)) {
1712           fT3d_cor_ss[j0StexEcha][i0Sample][j0Sample] =
1713               fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample] /
1714               (sqrt(fT3d_cov_ss[j0StexEcha][i0Sample][i0Sample]) * sqrt(fT3d_cov_ss[j0StexEcha][j0Sample][j0Sample]));
1715         } else {
1716           (fT3d_cor_ss)[j0StexEcha][i0Sample][j0Sample] = (Double_t)0;  // prevoir compteur + fTTBELL
1717         }
1718         fT3d_cor_ss[j0StexEcha][j0Sample][i0Sample] = fT3d_cor_ss[j0StexEcha][i0Sample][j0Sample];
1719       }
1720     }
1721     fTagCorCss[j0StexEcha] = 1;
1722     fFileHeader->fCorCssCalc++;
1723   }
1724 }
1725 
1726 //===========================================================================
1727 //
1728 //     M E A N   P E D E S T A L S ,   T O T A L    N O I S E ,
1729 //     L O W     F R E Q U E N C Y    N O I S E ,
1730 //     H I G H   F R E Q U E N C Y    N O I S E
1731 //     M E A N   O F  C O R ( S , S ),  S I G M A   O F  C O R ( S , S )
1732 //
1733 //===========================================================================
1734 //-------------------------------------------------------------------------
1735 //
1736 //  Calculation of the Pedestals for each channel in Stex
1737 //  tag: Ped
1738 //  Pedestal(c ) = E_e[ E_s[A(c ,s*,e*)] ]
1739 //  A(c,s,e) : ADC value for channel c, sample s, event e
1740 //  E_e : average over the events
1741 //  E_s : average over the samples
1742 //
1743 //-------------------------------------------------------------------------
1744 void TEcnaRun::Pedestals() {
1745   // Calculation, for each channel, of the expectation values
1746   // (over the samples 0 to fNbSampForCalc-1) of the ADC expectation values
1747   // (over the events)
1748 
1749   //... preliminary calculation of the expectation values if not done yet
1750   if (fTagMSp[0] != 1) {
1751     SampleMeans();
1752     fTagMSp[0] = 0;
1753   }
1754 
1755   //................... Allocation ev_ev + init to zero (mandatory)
1756   if (fT1d_ev_ev == nullptr) {
1757     fT1d_ev_ev = new Double_t[fEcal->MaxCrysEcnaInStex()];
1758     fCnew++;
1759   }
1760   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1761     if (fT1d_ev_ev[i0StexEcha] != (Double_t)0) {
1762       fMiscDiag[11]++;
1763       fT1d_ev_ev[i0StexEcha] = (Double_t)0;
1764     }
1765   }
1766 
1767   //..................... Calculation
1768   if (fFlagPrint != fCodePrintNoComment) {
1769     std::cout << "*TEcnaRun::Pedestals()" << std::endl;
1770   }
1771   if (fFlagPrint == fCodePrintAllComments) {
1772     std::cout << "           Calculation, for all the channels, of the expectation values (over the samples 1 to "
1773               << fNbSampForCalc << ")" << std::endl
1774               << "          of the ADC expectation values (over the events)." << std::endl;
1775   }
1776 
1777   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1778     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1779       fT1d_ev_ev[i0StexEcha] += fT2d_ev[i0StexEcha][i0Sample];
1780     }
1781     fT1d_ev_ev[i0StexEcha] /= fNbSampForCalc;
1782   }
1783   fTagPed[0] = 1;
1784   fFileHeader->fPedCalc++;
1785 }
1786 //------------------------ (end of Pedestals) ----------------------------
1787 
1788 //------------------------------------------------------------------------------
1789 //
1790 //  Calculation of the TN (Total Noise)
1791 //  tag: Tno
1792 //
1793 //  TotalNoise(c)  = E_s[ sqrt{ E_e[ ( A(c ,s*,e*) - E_e[A(c ,s*,e*)] )^2 ] } ]
1794 //  A(c,s,e) : ADC value for channel c, sample s, event e
1795 //  E_e : average over the events
1796 //  E_s : average over the samples
1797 //
1798 //------------------------------------------------------------------------------
1799 void TEcnaRun::TotalNoise() {
1800   // Calculation, for each channel, of the expectation values
1801   // (over the samples 0 to fNbSampForCalc-1) of the sigmas
1802   // (over the events)
1803 
1804   //... preliminary calculation of the sigmas if not done yet
1805   if (fTagSSp[0] != 1) {
1806     SampleSigmas();
1807     fTagSSp[0] = 0;
1808   }
1809 
1810   //................... Allocation ev_ev + init to zero (mandatory)
1811   if (fT1d_evsamp_of_sigevt == nullptr) {
1812     fT1d_evsamp_of_sigevt = new Double_t[fEcal->MaxCrysEcnaInStex()];
1813     fCnew++;
1814   }
1815   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1816     if (fT1d_evsamp_of_sigevt[i0StexEcha] != (Double_t)0) {
1817       fMiscDiag[12]++;
1818       fT1d_evsamp_of_sigevt[i0StexEcha] = (Double_t)0;
1819     }
1820   }
1821 
1822   //..................... Calculation
1823   if (fFlagPrint != fCodePrintNoComment) {
1824     std::cout << "*TEcnaRun::TotalNoise()" << std::endl;
1825   }
1826   if (fFlagPrint == fCodePrintAllComments) {
1827     std::cout << "           Calculation, for all the channels, of the expectation values (over the samples 1 to "
1828               << fNbSampForCalc << ")" << std::endl
1829               << "          of the ADC expectation values (over the events)." << std::endl;
1830   }
1831 
1832   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1833     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1834       if (fT2d_sig[i0StexEcha][i0Sample] < 0) {
1835         std::cout << "!TEcnaRun::TotalNoise() *** ERROR ***> Negative sigma!" << fTTBELL << std::endl;
1836       } else {
1837         fT1d_evsamp_of_sigevt[i0StexEcha] += fT2d_sig[i0StexEcha][i0Sample];
1838       }
1839     }
1840     fT1d_evsamp_of_sigevt[i0StexEcha] /= fNbSampForCalc;
1841   }
1842   fTagTno[0] = 1;
1843   fFileHeader->fTnoCalc++;
1844 }
1845 //------------------------ (end of TotalNoise) ----------------------------
1846 
1847 //---------------------------------------------------------------------------------
1848 //
1849 //  Calculation of the LFN  (Low Frequency Noise)
1850 //  tag: Lfn
1851 //
1852 //  LowFqNoise(c) = sqrt{ E_e[ ( E_s[A(c ,s*,e*)] - E_e[ E_s[A(c ,s*,e*)] ] )^2 ] }
1853 //  A(c,s,e) : ADC value for channel c, sample s, event e
1854 //  E_e : average over the events
1855 //  E_s : average over the samples
1856 //
1857 //---------------------------------------------------------------------------------
1858 void TEcnaRun::LowFrequencyNoise() {
1859   // Calculation, for each channel, of the sigma (over the events)
1860   // of the ADC expectation values (over the samples 0 to fNbSampForCalc-1)
1861 
1862   //................... Allocation fT1d_sigevt_of_evsamp + init to zero (mandatory)
1863   if (fT1d_sigevt_of_evsamp == nullptr) {
1864     fT1d_sigevt_of_evsamp = new Double_t[fEcal->MaxCrysEcnaInStex()];
1865     fCnew++;
1866   }
1867   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1868     if (fT1d_sigevt_of_evsamp[i0StexEcha] != (Double_t)0) {
1869       fMiscDiag[13]++;
1870       fT1d_sigevt_of_evsamp[i0StexEcha] = (Double_t)0;
1871     }
1872   }
1873 
1874   //................... Allocation mean_over_samples
1875   TVectorD mean_over_samples(fNumberOfEvents);
1876   for (Int_t i = 0; i < fNumberOfEvents; i++) {
1877     mean_over_samples(i) = (Double_t)0.;
1878   }
1879 
1880   //..................... Calculation
1881   if (fFlagPrint != fCodePrintNoComment) {
1882     std::cout << "*TEcnaRun::LowFrequencyNoise()" << std::endl;
1883   }
1884   if (fFlagPrint == fCodePrintAllComments) {
1885     std::cout << "           Calculation, for each channel, of the sigma (over the events)" << std::endl
1886               << "           of the ADC expectation values (over the samples 1 to " << fNbSampForCalc << ")."
1887               << std::endl;
1888   }
1889 
1890   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1891     // Calculation of the mean over the events of the mean over the samples
1892     Double_t mean_over_events = (Double_t)0;
1893     for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
1894       // Calculation, for each event, of the mean over the samples
1895       mean_over_samples(n_event) = (Double_t)0.;
1896       for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1897         mean_over_samples(n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];
1898       }
1899       mean_over_samples(n_event) /= (Double_t)fNbSampForCalc;
1900 
1901       mean_over_events += mean_over_samples(n_event);
1902     }
1903     mean_over_events /= (Double_t)fNumberOfEvents;
1904 
1905     // Calculation of the sigma over the events of the mean over the samples
1906     Double_t var = (Double_t)0;
1907     for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
1908       Double_t ecart = mean_over_samples(n_event) - mean_over_events;
1909       var += ecart * ecart;
1910     }
1911     var /= (Double_t)fNumberOfEvents;
1912 
1913     fT1d_sigevt_of_evsamp[i0StexEcha] = sqrt(var);
1914   }
1915   fTagLfn[0] = 1;
1916   fFileHeader->fLfnCalc++;
1917 }
1918 //------------------------ (end of LowFrequencyNoise) ----------------------------
1919 
1920 //---------------------------------------------------------------------------------
1921 //
1922 //  Calculation of the HFN  (High Frequency Noise)
1923 //  tag: Hfn
1924 //
1925 //  HighFqNoise(c) = E_e[ sqrt{ E_s[ (A(c ,s*,e*) - E_s[A(c ,s*,e*)] )^2 ] } ]
1926 //  A(c,s,e) : ADC value for channel c, sample s, event e
1927 //  E_e : average over the events
1928 //  E_s : average over the samples
1929 //
1930 //---------------------------------------------------------------------------------
1931 void TEcnaRun::HighFrequencyNoise() {
1932   // Calculation, for each channel, of the mean (over the events)
1933   // of the ADC sigmas (over the samples 0 to fNbSampForCalc-1)
1934 
1935   //................... Allocation fT1d_evevt_of_sigsamp + init to zero (mandatory)
1936   if (fT1d_evevt_of_sigsamp == nullptr) {
1937     fT1d_evevt_of_sigsamp = new Double_t[fEcal->MaxCrysEcnaInStex()];
1938     fCnew++;
1939   }
1940   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1941     if (fT1d_evevt_of_sigsamp[i0StexEcha] != (Double_t)0) {
1942       fMiscDiag[14]++;
1943       fT1d_evevt_of_sigsamp[i0StexEcha] = (Double_t)0;
1944     }
1945   }
1946 
1947   //................... Allocations mean_over_samples, sigma_over_sample
1948   TVectorD mean_over_samples(fNumberOfEvents);
1949   for (Int_t i = 0; i < fNumberOfEvents; i++) {
1950     mean_over_samples(i) = (Double_t)0.;
1951   }
1952   TVectorD sigma_over_samples(fNumberOfEvents);
1953   for (Int_t i = 0; i < fNumberOfEvents; i++) {
1954     sigma_over_samples(i) = (Double_t)0.;
1955   }
1956 
1957   //..................... Calculation
1958   if (fFlagPrint != fCodePrintNoComment) {
1959     std::cout << "*TEcnaRun::HighFrequencyNoise()" << std::endl;
1960   }
1961   if (fFlagPrint == fCodePrintAllComments) {
1962     std::cout << "           Calculation, for each channel, of the sigma (over the events)" << std::endl
1963               << "           of the ADC expectation values (over the samples 1 to " << fNbSampForCalc << ")."
1964               << std::endl;
1965   }
1966 
1967   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
1968     //..................... Calculation of the sigma over samples
1969     for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
1970       // Calculation, for each event, of the mean over the samples
1971       mean_over_samples(n_event) = (Double_t)0.;
1972       for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1973         mean_over_samples(n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];
1974       }
1975       mean_over_samples(n_event) /= (Double_t)fNbSampForCalc;
1976 
1977       // Calculation, for each event, of the sigma over the samples
1978       Double_t var_over_samples = (Double_t)0;
1979       for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
1980         Double_t deviation = fT3d_AdcValues[i0StexEcha][i0Sample][n_event] - mean_over_samples(n_event);
1981         var_over_samples += deviation * deviation;
1982       }
1983       var_over_samples /= (Double_t)fNbSampForCalc;
1984 
1985       if (var_over_samples < 0) {
1986         std::cout << "!TEcnaRun::HighFrequencyNoise() *** ERROR ***> Negative variance! " << fTTBELL << std::endl;
1987       } else {
1988         sigma_over_samples(n_event) = sqrt(var_over_samples);
1989       }
1990     }
1991 
1992     //....... Calculation of the mean over the events of the sigma over samples
1993     for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
1994       fT1d_evevt_of_sigsamp[i0StexEcha] += sigma_over_samples(n_event);
1995     }
1996 
1997     fT1d_evevt_of_sigsamp[i0StexEcha] /= (Double_t)fNumberOfEvents;
1998   }
1999   fTagHfn[0] = 1;
2000   fFileHeader->fHfnCalc++;
2001 }
2002 //------------------------ (end of HighFrequencyNoise) ----------------------------
2003 
2004 //-------------------------------------------------------------------------
2005 //
2006 //  Calculation of the expectation values of (sample,sample)
2007 //  correlations for all the channels (mean cor(s,s))
2008 //  tag: MeanCorss
2009 //
2010 //  MeanCorss(c)   = E_s,s'[ Cor(c;s,s') ]
2011 //  E_s,s': average  over couples of samples (half correlation matrix)
2012 //
2013 //-------------------------------------------------------------------------
2014 void TEcnaRun::MeanCorrelationsBetweenSamples() {
2015   // Calculation, for all the channels, of the expectation values
2016   // of the correlations between the first fNbSampForCalc samples
2017 
2018   //... preliminary calculation of the correlations if not done yet
2019   //    (test only the first element since the cor are computed globaly)
2020   if (fTagCorCss[0] != 1) {
2021     CorrelationsBetweenSamples();
2022     fTagCorCss[0] = 0;
2023   }
2024 
2025   //................... Allocations ev_cor_ss + init to zero (mandatory)
2026   if (fT1d_ev_cor_ss == nullptr) {
2027     Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
2028     fT1d_ev_cor_ss = new Double_t[n_StexEcha];
2029     fCnew++;
2030   }
2031   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2032     if (fT1d_ev_cor_ss[i0StexEcha] != (Double_t)0) {
2033       fMiscDiag[15]++;
2034       fT1d_ev_cor_ss[i0StexEcha] = (Double_t)0;
2035     }
2036   }
2037 
2038   //.......... 1D array half_cor_ss[N(N-1)/2] to put the N (sample,sample) correlations
2039   //           ( half of (them minus the diagonal) )
2040   Int_t ndim = (Int_t)(fNbSampForCalc * (fNbSampForCalc - 1) / 2);
2041 
2042   TVectorD half_cor_ss(ndim);
2043   for (Int_t i = 0; i < ndim; i++) {
2044     half_cor_ss(i) = (Double_t)0.;
2045   }
2046 
2047   //..................... Calculation
2048   if (fFlagPrint != fCodePrintNoComment) {
2049     std::cout << "*TEcnaRun::MeanCorrelationsBetweenSamples()" << std::endl;
2050   }
2051   if (fFlagPrint == fCodePrintAllComments) {
2052     std::cout << "           Calculation, for all the channels, of the expectation values of the" << std::endl
2053               << "           correlations between the first " << fNbSampForCalc << " samples." << std::endl;
2054   }
2055 
2056   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2057     //..................... half_cor_ss() array filling
2058     Int_t i_count = 0;
2059     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
2060       for (Int_t j0Sample = 0; j0Sample < i0Sample; j0Sample++) {
2061         half_cor_ss(i_count) = fT3d_cor_ss[i0StexEcha][i0Sample][j0Sample];
2062         i_count++;
2063       }
2064     }
2065     //...................... mean cor(s,s') calculation
2066     fT1d_ev_cor_ss[i0StexEcha] = (Double_t)0;
2067     for (Int_t i_rcor = 0; i_rcor < ndim; i_rcor++) {
2068       fT1d_ev_cor_ss[i0StexEcha] += half_cor_ss(i_rcor);
2069     }
2070     fT1d_ev_cor_ss[i0StexEcha] /= (Double_t)ndim;
2071   }
2072   fTagMeanCorss[0] = 1;
2073   fFileHeader->fMeanCorssCalc++;
2074 }
2075 //--------------- (end of MeanCorrelationsBetweenSamples) -----------
2076 
2077 //-------------------------------------------------------------------------
2078 //
2079 // Calculation of the sigmas of the (sample,sample) correlations
2080 // for all the channels (sigma of cor(s,s))
2081 // tag: SigCorss
2082 //
2083 // SigmaCorss(c)  = E_s,s'[ Cor(c;s,s') - E_s,s'[ Cor(c;s,s') ] ]
2084 // E_s,s': average  over couples of samples (half correlation matrix)
2085 //
2086 //--------------------------------------------------------------------------
2087 void TEcnaRun::SigmaOfCorrelationsBetweenSamples() {
2088   //Calculation of the sigmas of the (sample,sample) correlations for all the StexEchas
2089 
2090   //... preliminary calculation of the mean cor(s,s') if not done yet
2091   //    (test only the first element since the cor are computed globaly)
2092   //    Results available in array fT1d_ev_cor_ss[i0StexEcha]
2093   if (fTagMeanCorss[0] != 1) {
2094     MeanCorrelationsBetweenSamples();
2095     fTagMeanCorss[0] = 0;
2096   }
2097 
2098   //................... Allocations sig_cor_ss + init to zero
2099   if (fT1d_sig_cor_ss == nullptr) {
2100     Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
2101     fT1d_sig_cor_ss = new Double_t[n_StexEcha];
2102     fCnew++;
2103   }
2104   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2105     if (fT1d_sig_cor_ss[i0StexEcha] != (Double_t)0) {
2106       fMiscDiag[16]++;
2107       fT1d_sig_cor_ss[i0StexEcha] = (Double_t)0;
2108     }
2109   }
2110 
2111   if (fFlagPrint != fCodePrintNoComment) {
2112     std::cout << "*TEcnaRun::SigmasOfCorrelationsBetweenSamples()" << std::endl;
2113   }
2114   if (fFlagPrint == fCodePrintAllComments) {
2115     std::cout << "           Calculation of the sigmas of the (sample,sample)" << std::endl
2116               << "           correlations for all the channels." << std::endl;
2117   }
2118 
2119   //.......... 1D array half_cor_ss[N(N-1)/2] to put the N (sample,sample) correlations
2120   //           (half of them minus the diagonal)
2121   Int_t ndim = (Int_t)(fNbSampForCalc * (fNbSampForCalc - 1) / 2);
2122 
2123   TVectorD half_cor_ss(ndim);
2124   for (Int_t i = 0; i < ndim; i++) {
2125     half_cor_ss(i) = (Double_t)0.;
2126   }
2127 
2128   //.................. Calculation
2129   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2130     //..................... half_cor_ss() array filling
2131     Int_t i_count = 0;
2132     for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
2133       for (Int_t j0Sample = 0; j0Sample < i0Sample; j0Sample++) {
2134         half_cor_ss(i_count) = fT3d_cor_ss[i0StexEcha][i0Sample][j0Sample];
2135         i_count++;
2136       }
2137     }
2138 
2139     //...................... sigma of cor(s,s') calculation
2140     Double_t var = (Double_t)0;
2141     for (Int_t i_rcor = 0; i_rcor < ndim; i_rcor++) {
2142       Double_t ecart = half_cor_ss(i_rcor) - fT1d_ev_cor_ss[i0StexEcha];
2143       var += ecart * ecart;
2144     }
2145     var /= (Double_t)ndim;
2146     fT1d_sig_cor_ss[i0StexEcha] = sqrt(var);
2147   }
2148   fTagSigCorss[0] = 1;
2149   fFileHeader->fSigCorssCalc++;
2150 }
2151 //--------------- (end of SigmaOfCorrelationsBetweenSamples) -----------
2152 
2153 //-----------------------------------------------------------------------------
2154 //
2155 //  Calculation of the average Pedestals for each Stin in Stex
2156 //  tag: AvPed
2157 //
2158 //-----------------------------------------------------------------------------
2159 void TEcnaRun::AveragePedestals() {
2160   // Calculation of the average
2161   // (over the Stin's 0 to fEcal->MaxStinInStex()) of the Pedestals
2162 
2163   //... preliminary calculation of the Pedestals if not done yet
2164   if (fTagPed[0] != 1) {
2165     Pedestals();
2166     fTagPed[0] = 0;
2167   }
2168   //................... Allocation av_mped + init to zero (mandatory)
2169   if (fT1d_av_mped == nullptr) {
2170     fT1d_av_mped = new Double_t[fEcal->MaxStinEcnaInStex()];
2171     fCnew++;
2172   }
2173   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2174     if (fT1d_av_mped[i0StexStinEcna] != (Double_t)0) {
2175       fMiscDiag[41]++;
2176       fT1d_av_mped[i0StexStinEcna] = (Double_t)0;
2177     }
2178   }
2179 
2180   if (fFlagPrint != fCodePrintNoComment) {
2181     std::cout << "*TEcnaRun::AveragePedestals()" << std::endl;
2182   }
2183   if (fFlagPrint == fCodePrintAllComments) {
2184     std::cout << "           Calculation, for all the " << fStinName.Data() << "s, of the average Pedestals"
2185               << std::endl;
2186   }
2187 
2188   //................... Calculation
2189   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2190     Int_t n1StexStinEcna = i0StexStinEcna + 1;
2191     fT1d_av_mped[i0StexStinEcna] = (Double_t)0;
2192     for (Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++) {
2193       Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
2194 
2195       if (fStexName == "SM ") {
2196         fT1d_av_mped[i0StexStinEcna] += fT1d_ev_ev[i0StexEcha];
2197       }
2198 
2199       if (fStexName == "Dee") {
2200         //---------------- Special translation for mixed SCEcna (29 and 32)
2201         //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
2202         //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
2203         Int_t n1StinEcha = i0StinEcha + 1;
2204         if (n1StexStinEcna == 10 && n1StinEcha == 11) {
2205           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);
2206         }
2207         if (n1StexStinEcna == 11 && n1StinEcha == 11) {
2208           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);
2209         }
2210         if (!((n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11)) {
2211           fT1d_av_mped[i0StexStinEcna] += fT1d_ev_ev[i0StexEcha];
2212         }
2213       }
2214     }
2215     Double_t xdivis = (Double_t)0.;
2216     if (fStexName == "SM ") {
2217       xdivis = (Double_t)fEcal->MaxCrysInStin();
2218     }
2219     if (fStexName == "Dee") {
2220       xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");
2221     }
2222 
2223     fT1d_av_mped[i0StexStinEcna] = fT1d_av_mped[i0StexStinEcna] / xdivis;
2224   }
2225 
2226   fTagAvPed[0] = 1;
2227   fFileHeader->fAvPedCalc++;
2228 }
2229 //-----------------------------------------------------------------------------
2230 //
2231 // Calculation of the average total noise for each Stin in Stex
2232 // tag: AvTno
2233 //
2234 //-----------------------------------------------------------------------------
2235 void TEcnaRun::AverageTotalNoise() {
2236   // Calculation of the average
2237   // (over the Stin's 0 to fEcal->MaxStinInStex()) of the Total Noise
2238 
2239   //... preliminary calculation of the averaged Total Noise if not done yet
2240   if (fTagTno[0] != 1) {
2241     TotalNoise();
2242     fTagTno[0] = 0;
2243   }
2244   //................... Allocation av_totn + init to zero (mandatory)
2245   if (fT1d_av_totn == nullptr) {
2246     fT1d_av_totn = new Double_t[fEcal->MaxStinEcnaInStex()];
2247     fCnew++;
2248   }
2249   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2250     if (fT1d_av_totn[i0StexStinEcna] != (Double_t)0) {
2251       fMiscDiag[42]++;
2252       fT1d_av_totn[i0StexStinEcna] = (Double_t)0;
2253     }
2254   }
2255 
2256   if (fFlagPrint != fCodePrintNoComment) {
2257     std::cout << "*TEcnaRun::AverageTotalNoise()" << std::endl;
2258   }
2259   if (fFlagPrint == fCodePrintAllComments) {
2260     std::cout << "           Calculation, for all the " << fStinName.Data() << "s, of the average total Noise"
2261               << std::endl;
2262   }
2263 
2264   //................... Calculation
2265   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2266     Int_t n1StexStinEcna = i0StexStinEcna + 1;
2267     fT1d_av_totn[i0StexStinEcna] = (Double_t)0;
2268     for (Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++) {
2269       Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
2270 
2271       if (fStexName == "SM ") {
2272         fT1d_av_totn[i0StexStinEcna] += fT1d_evsamp_of_sigevt[i0StexEcha];
2273       }
2274 
2275       if (fStexName == "Dee") {
2276         //---------------- Special translation for mixed SCEcna (29 and 32)
2277         //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
2278         //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
2279         Int_t n1StinEcha = i0StinEcha + 1;
2280         if (n1StexStinEcna == 10 && n1StinEcha == 11) {
2281           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);
2282         }
2283         if (n1StexStinEcna == 11 && n1StinEcha == 11) {
2284           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);
2285         }
2286         if (!((n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11)) {
2287           fT1d_av_totn[i0StexStinEcna] += fT1d_evsamp_of_sigevt[i0StexEcha];
2288         }
2289       }
2290     }
2291     Double_t xdivis = (Double_t)0.;
2292     if (fStexName == "SM ") {
2293       xdivis = (Double_t)fEcal->MaxCrysInStin();
2294     }
2295     if (fStexName == "Dee") {
2296       xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");
2297     }
2298 
2299     fT1d_av_totn[i0StexStinEcna] = fT1d_av_totn[i0StexStinEcna] / xdivis;
2300   }
2301   fTagAvTno[0] = 1;
2302   fFileHeader->fAvTnoCalc++;
2303 }
2304 //-----------------------------------------------------------------------------
2305 //
2306 // Calculation of the average Low Frequency noise for each Stin in Stex
2307 // tag: AvLfn
2308 //
2309 //-----------------------------------------------------------------------------
2310 void TEcnaRun::AverageLowFrequencyNoise() {
2311   // Calculation of the average
2312   // (over the Stin's 0 to fEcal->MaxStinInStex()) of the Low Frequency Noise
2313 
2314   //... preliminary calculation of the Low Frequency Noise if not done yet
2315   if (fTagLfn[0] != 1) {
2316     LowFrequencyNoise();
2317     fTagLfn[0] = 0;
2318   }
2319   //................... Allocation av_lofn + init to zero (mandatory)
2320   if (fT1d_av_lofn == nullptr) {
2321     fT1d_av_lofn = new Double_t[fEcal->MaxStinEcnaInStex()];
2322     fCnew++;
2323   }
2324   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2325     if (fT1d_av_lofn[i0StexStinEcna] != (Double_t)0) {
2326       fMiscDiag[43]++;
2327       fT1d_av_lofn[i0StexStinEcna] = (Double_t)0;
2328     }
2329   }
2330 
2331   if (fFlagPrint != fCodePrintNoComment) {
2332     std::cout << "*TEcnaRun::AverageLowFrequencyNoise()" << std::endl;
2333   }
2334   if (fFlagPrint == fCodePrintAllComments) {
2335     std::cout << "           Calculation, for all the " << fStinName.Data() << "s, of the average Low Frequency Noise"
2336               << std::endl;
2337   }
2338 
2339   //................... Calculation
2340   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2341     Int_t n1StexStinEcna = i0StexStinEcna + 1;
2342     fT1d_av_lofn[i0StexStinEcna] = (Double_t)0;
2343     for (Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++) {
2344       Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
2345 
2346       if (fStexName == "SM ") {
2347         fT1d_av_lofn[i0StexStinEcna] += fT1d_sigevt_of_evsamp[i0StexEcha];
2348       }
2349 
2350       if (fStexName == "Dee") {
2351         //---------------- Special translation for mixed SCEcna (29 and 32)
2352         //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
2353         //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
2354         Int_t n1StinEcha = i0StinEcha + 1;
2355         if (n1StexStinEcna == 10 && n1StinEcha == 11) {
2356           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);
2357         }
2358         if (n1StexStinEcna == 11 && n1StinEcha == 11) {
2359           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);
2360         }
2361         if (!((n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11)) {
2362           fT1d_av_lofn[i0StexStinEcna] += fT1d_sigevt_of_evsamp[i0StexEcha];
2363         }
2364       }
2365     }
2366     Double_t xdivis = (Double_t)0.;
2367     if (fStexName == "SM ") {
2368       xdivis = (Double_t)fEcal->MaxCrysInStin();
2369     }
2370     if (fStexName == "Dee") {
2371       xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");
2372     }
2373 
2374     fT1d_av_lofn[i0StexStinEcna] = fT1d_av_lofn[i0StexStinEcna] / xdivis;
2375   }
2376   fTagAvLfn[0] = 1;
2377   fFileHeader->fAvLfnCalc++;
2378 }
2379 //-----------------------------------------------------------------------------
2380 //
2381 // Calculation of the average high frequency noise for each Stin in Stex
2382 // tag: AvHfn
2383 //
2384 //-----------------------------------------------------------------------------
2385 void TEcnaRun::AverageHighFrequencyNoise() {
2386   // Calculation of the average
2387   // (over the Stin's 0 to fEcal->MaxStinInStex()) of the High Frequency Noise
2388 
2389   //... preliminary calculation of the High Frequency Noise if not done yet
2390   if (fTagHfn[0] != 1) {
2391     HighFrequencyNoise();
2392     fTagHfn[0] = 0;
2393   }
2394   //................... Allocation av_hifn + init to zero (mandatory)
2395   if (fT1d_av_hifn == nullptr) {
2396     fT1d_av_hifn = new Double_t[fEcal->MaxStinEcnaInStex()];
2397     fCnew++;
2398   }
2399   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2400     if (fT1d_av_hifn[i0StexStinEcna] != (Double_t)0) {
2401       fMiscDiag[44]++;
2402       fT1d_av_hifn[i0StexStinEcna] = (Double_t)0;
2403     }
2404   }
2405 
2406   if (fFlagPrint != fCodePrintNoComment) {
2407     std::cout << "*TEcnaRun::AverageHighFrequencyNoise()" << std::endl;
2408   }
2409   if (fFlagPrint == fCodePrintAllComments) {
2410     std::cout << "           Calculation, for all the " << fStinName.Data() << "s, of the average High Frequency Noise"
2411               << std::endl;
2412   }
2413 
2414   //................... Calculation
2415   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2416     Int_t n1StexStinEcna = i0StexStinEcna + 1;
2417     fT1d_av_hifn[i0StexStinEcna] = (Double_t)0;
2418     for (Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++) {
2419       Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
2420 
2421       if (fStexName == "SM ") {
2422         fT1d_av_hifn[i0StexStinEcna] += fT1d_evevt_of_sigsamp[i0StexEcha];
2423       }
2424 
2425       if (fStexName == "Dee") {
2426         //---------------- Special translation for mixed SCEcna (29 and 32)
2427         //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
2428         //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
2429         Int_t n1StinEcha = i0StinEcha + 1;
2430         if (n1StexStinEcna == 10 && n1StinEcha == 11) {
2431           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);
2432         }
2433         if (n1StexStinEcna == 11 && n1StinEcha == 11) {
2434           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);
2435         }
2436         if (!((n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11)) {
2437           fT1d_av_hifn[i0StexStinEcna] += fT1d_evevt_of_sigsamp[i0StexEcha];
2438         }
2439       }
2440     }
2441     Double_t xdivis = (Double_t)0.;
2442     if (fStexName == "SM ") {
2443       xdivis = (Double_t)fEcal->MaxCrysInStin();
2444     }
2445     if (fStexName == "Dee") {
2446       xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");
2447     }
2448 
2449     fT1d_av_hifn[i0StexStinEcna] = fT1d_av_hifn[i0StexStinEcna] / xdivis;
2450   }
2451   fTagAvHfn[0] = 1;
2452   fFileHeader->fAvHfnCalc++;
2453 }
2454 //-----------------------------------------------------------------------------
2455 //
2456 // Calculation of the average mean cor(s,s) for each Stin in Stex
2457 // tag: AvMeanCorss
2458 //
2459 //-----------------------------------------------------------------------------
2460 void TEcnaRun::AverageMeanCorrelationsBetweenSamples() {
2461   // Calculation of the average
2462   // (over the Stin's 0 to fEcal->MaxStinInStex()) of the mean cor(s,s)
2463 
2464   //... preliminary calculation of the mean cor(s,s) if not done yet
2465   if (fTagMeanCorss[0] != 1) {
2466     MeanCorrelationsBetweenSamples();
2467     fTagMeanCorss[0] = 0;
2468   }
2469   //................... Allocation av_ev_corss + init to zero (mandatory)
2470   if (fT1d_av_ev_corss == nullptr) {
2471     fT1d_av_ev_corss = new Double_t[fEcal->MaxStinEcnaInStex()];
2472     fCnew++;
2473   }
2474   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2475     if (fT1d_av_ev_corss[i0StexStinEcna] != (Double_t)0) {
2476       fMiscDiag[45]++;
2477       fT1d_av_ev_corss[i0StexStinEcna] = (Double_t)0;
2478     }
2479   }
2480 
2481   if (fFlagPrint != fCodePrintNoComment) {
2482     std::cout << "*TEcnaRun::AverageMeanCorrelationsBetweenSamples()" << std::endl;
2483   }
2484   if (fFlagPrint == fCodePrintAllComments) {
2485     std::cout << "           Calculation, for all the " << fStinName.Data() << "s, of the average mean cor(s,s)"
2486               << std::endl;
2487   }
2488 
2489   //................... Calculation
2490   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2491     Int_t n1StexStinEcna = i0StexStinEcna + 1;
2492     fT1d_av_ev_corss[i0StexStinEcna] = (Double_t)0;
2493     for (Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++) {
2494       Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
2495 
2496       if (fStexName == "SM ") {
2497         fT1d_av_ev_corss[i0StexStinEcna] += fT1d_ev_cor_ss[i0StexEcha];
2498       }
2499 
2500       if (fStexName == "Dee") {
2501         //---------------- Special translation for mixed SCEcna (29 and 32)
2502         //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
2503         //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
2504         Int_t n1StinEcha = i0StinEcha + 1;
2505         if (n1StexStinEcna == 10 && n1StinEcha == 11) {
2506           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);
2507         }
2508         if (n1StexStinEcna == 11 && n1StinEcha == 11) {
2509           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);
2510         }
2511         if (!((n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11)) {
2512           fT1d_av_ev_corss[i0StexStinEcna] += fT1d_ev_cor_ss[i0StexEcha];
2513         }
2514       }
2515     }
2516     Double_t xdivis = (Double_t)0.;
2517     if (fStexName == "SM ") {
2518       xdivis = (Double_t)fEcal->MaxCrysInStin();
2519     }
2520     if (fStexName == "Dee") {
2521       xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");
2522     }
2523 
2524     fT1d_av_ev_corss[i0StexStinEcna] = fT1d_av_ev_corss[i0StexStinEcna] / xdivis;
2525   }
2526   fTagAvMeanCorss[0] = 1;
2527   fFileHeader->fAvMeanCorssCalc++;
2528 }
2529 //-----------------------------------------------------------------------------
2530 //
2531 // Calculation of the average sigma of cor(s,s) for each Stin in Stex
2532 // tag: AvSigCorss
2533 //
2534 //-----------------------------------------------------------------------------
2535 void TEcnaRun::AverageSigmaOfCorrelationsBetweenSamples() {
2536   // Calculation of the average
2537   // (over the Stin's 0 to fEcal->MaxStinInStex()) of the sigma of cor(s,s)
2538 
2539   //... preliminary calculation of the sigma of cor(s,s) if not done yet
2540   if (fTagSigCorss[0] != 1) {
2541     SigmaOfCorrelationsBetweenSamples();
2542     fTagSigCorss[0] = 0;
2543   }
2544   //................... Allocation av_sig_corss + init to zero (mandatory)
2545   if (fT1d_av_sig_corss == nullptr) {
2546     fT1d_av_sig_corss = new Double_t[fEcal->MaxStinEcnaInStex()];
2547     fCnew++;
2548   }
2549   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2550     if (fT1d_av_sig_corss[i0StexStinEcna] != (Double_t)0) {
2551       fMiscDiag[46]++;
2552       fT1d_av_sig_corss[i0StexStinEcna] = (Double_t)0;
2553     }
2554   }
2555 
2556   if (fFlagPrint != fCodePrintNoComment) {
2557     std::cout << "*TEcnaRun::AverageSigmaOfCorrelationsBetweenSamples()" << std::endl;
2558   }
2559   if (fFlagPrint == fCodePrintAllComments) {
2560     std::cout << "           Calculation, for all the " << fStinName.Data() << "s, of the average sigma of cor(s,s)"
2561               << std::endl;
2562   }
2563 
2564   //................... Calculation
2565   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
2566     Int_t n1StexStinEcna = i0StexStinEcna + 1;
2567     fT1d_av_sig_corss[i0StexStinEcna] = (Double_t)0;
2568     for (Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++) {
2569       Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
2570 
2571       if (fStexName == "SM ") {
2572         fT1d_av_sig_corss[i0StexStinEcna] += fT1d_sig_cor_ss[i0StexEcha];
2573       }
2574 
2575       if (fStexName == "Dee") {
2576         //---------------- Special translation for mixed SCEcna (29 and 32)
2577         //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
2578         //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
2579         Int_t n1StinEcha = i0StinEcha + 1;
2580         if (n1StexStinEcna == 10 && n1StinEcha == 11) {
2581           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);
2582         }
2583         if (n1StexStinEcna == 11 && n1StinEcha == 11) {
2584           i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);
2585         }
2586         if (!((n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11)) {
2587           fT1d_av_sig_corss[i0StexStinEcna] += fT1d_sig_cor_ss[i0StexEcha];
2588         }
2589       }
2590     }
2591     Double_t xdivis = (Double_t)0.;
2592     if (fStexName == "SM ") {
2593       xdivis = (Double_t)fEcal->MaxCrysInStin();
2594     }
2595     if (fStexName == "Dee") {
2596       xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");
2597     }
2598 
2599     fT1d_av_sig_corss[i0StexStinEcna] = fT1d_av_sig_corss[i0StexStinEcna] / xdivis;
2600   }
2601   fTagAvSigCorss[0] = 1;
2602   fFileHeader->fAvSigCorssCalc++;
2603 }
2604 
2605 //======================================================================
2606 //
2607 //       C O V A R I A N C E S   &   C O R R E L A T I O N S
2608 //
2609 //                 B E T W E E N   C H A N N E L S
2610 //
2611 //======================================================================
2612 //----------------------------------------------------------------------
2613 //
2614 //  Calculation of the Low Frequency Covariances between channels
2615 //
2616 //  LFCov(Ci,Cj) = Cov_e[ E_s[A(Ci,s*,e*)] , E_s[A(Cj,s*,e*) ]
2617 //
2618 //               = E_e[ ( E_s[A(Ci,s*,e*)] - E_e[ E_s[A(Ci,s*,e*)] ] )*
2619 //                      ( E_s[A(Cj,s*,e*)] - E_e[ E_s[A(Cj,s*,e*)] ] ) ]
2620 //
2621 //   A(Ci,s,e) : ADC value for channel Ci, sample s, event e
2622 //
2623 //   E_e , Cov_e : average, covariance over the events
2624 //   E_s :         average over the samples
2625 //
2626 //   e* : random variable associated to events
2627 //   s* : random variable associated to samples
2628 //
2629 //----------------------------------------------------------------------
2630 void TEcnaRun::LowFrequencyCovariancesBetweenChannels() {
2631   //Calculation of the Low Frequency Covariances between channels
2632 
2633   if (fFlagPrint != fCodePrintNoComment) {
2634     std::cout << "*TEcnaRun::LowFrequencyCovariancesBetweenChannels()" << std::endl;
2635   }
2636   if (fFlagPrint == fCodePrintAllComments) {
2637     std::cout << "           Calculation of the Low Frequency Covariances between channels" << std::endl;
2638   }
2639 
2640   //................. allocation fT2d_lf_cov + init to zero (mandatory)
2641   if (fT2d_lf_cov == nullptr) {
2642     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
2643     fT2d_lf_cov = new Double_t*[n_StexEcha];
2644     fCnew++;
2645     fT2d1_lf_cov = new Double_t[n_StexEcha * n_StexEcha];
2646     fCnew++;
2647     for (Int_t i0StexEcha = 0; i0StexEcha < n_StexEcha; i0StexEcha++) {
2648       fT2d_lf_cov[i0StexEcha] = &fT2d1_lf_cov[0] + i0StexEcha * n_StexEcha;
2649     }
2650   }
2651 
2652   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2653     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
2654       if (fT2d_lf_cov[i0StexEcha][j0StexEcha] != (Double_t)0) {
2655         fMiscDiag[21]++;
2656         fT2d_lf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;
2657       }
2658     }
2659   }
2660   //........................................... Calculation  (LowFrequencyCovariancesBetweenChannels)
2661   //................... Allocation mean_over_samples(i0StexEcha, n_event)
2662   TMatrixD mean_over_samples(fEcal->MaxCrysEcnaInStex(), fNumberOfEvents);
2663   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2664     for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2665       mean_over_samples(i0StexEcha, n_event) = (Double_t)0.;
2666     }
2667   }
2668   //................... Allocation MoeOfMos(i0StexEcha)
2669   TVectorD MoeOfMos(fEcal->MaxCrysEcnaInStex());
2670   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2671     MoeOfMos(i0StexEcha) = (Double_t)0.;
2672   }
2673 
2674   //................... Calculation
2675   if (fFlagPrint != fCodePrintNoComment) {
2676     std::cout << "          Calculation, for each pair of channels, of the covariance (over the events)" << std::endl
2677               << "          between the ADC expectation values (over the samples 1 to " << fNbSampForCalc << ")."
2678               << std::endl;
2679   }
2680 
2681   std::cout << " Please, wait (end at i= " << fEcal->MaxCrysEcnaInStex() << "): " << std::endl;
2682 
2683   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2684     MoeOfMos(i0StexEcha) = (Double_t)0;
2685 
2686     if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0) ||
2687         (fFlagSubDet == "EB")) {
2688       for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2689         // Calculation, for each event, of the mean over the samples  ( = E_s[A(c_i,s*,e_n] )
2690         mean_over_samples(i0StexEcha, n_event) = (Double_t)0.;
2691         for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
2692           mean_over_samples(i0StexEcha, n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];
2693         }
2694         mean_over_samples(i0StexEcha, n_event) /= (Double_t)fNbSampForCalc;
2695       }
2696       //Calculation of the mean over the events of E_s[A(c_i,s*,e_n] ( = E_e[E_s[A(c_i,s*,e*]] )
2697       for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2698         MoeOfMos(i0StexEcha) += mean_over_samples(i0StexEcha, n_event);
2699       }
2700       MoeOfMos(i0StexEcha) /= (Double_t)fNumberOfEvents;
2701     }
2702   }
2703 
2704   //... Calculation of half of the matrix, diagonal included        (LowFrequencyCovariancesBetweenChannels)
2705   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2706     if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0) ||
2707         (fFlagSubDet == "EB")) {
2708       for (Int_t j0StexEcha = 0; j0StexEcha <= i0StexEcha; j0StexEcha++) {
2709         if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0) ||
2710             (fFlagSubDet == "EB")) {
2711           fT2d_lf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;
2712           for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2713             fT2d_lf_cov[i0StexEcha][j0StexEcha] += (mean_over_samples(i0StexEcha, n_event) - MoeOfMos(i0StexEcha)) *
2714                                                    (mean_over_samples(j0StexEcha, n_event) - MoeOfMos(j0StexEcha));
2715           }
2716           fT2d_lf_cov[i0StexEcha][j0StexEcha] /= (Double_t)fNumberOfEvents;
2717 
2718           fT2d_lf_cov[j0StexEcha][i0StexEcha] = fT2d_lf_cov[i0StexEcha][j0StexEcha];
2719         }
2720       }
2721       if (i0StexEcha % 100 == 0) {
2722         std::cout << i0StexEcha << "[LFN Cov], ";
2723       }
2724     }
2725   }
2726   std::cout << std::endl;
2727   fTagLfCov[0] = 1;
2728   fFileHeader->fLfCovCalc++;
2729 }
2730 //---------- (end of LowFrequencyCovariancesBetweenChannels ) --------------------
2731 
2732 //------------------------------------------------------------------
2733 //
2734 //  Calculation of the Low Frequency Correlations between channels
2735 //
2736 //  LFCor(Ci,Cj) = LFCov(Ci,Cj)/sqrt(LFCov(Ci,Ci)*LFCov(Cj,Cj))
2737 //
2738 //------------------------------------------------------------------
2739 void TEcnaRun::LowFrequencyCorrelationsBetweenChannels() {
2740   //Calculation of the Low Frequency Correlations between channels
2741 
2742   //... preliminary calculation of the covariances if not done yet.
2743   if (fTagLfCov[0] != 1) {
2744     LowFrequencyCovariancesBetweenChannels();
2745     fTagLfCov[0] = 0;
2746   }
2747 
2748   if (fFlagPrint != fCodePrintNoComment) {
2749     std::cout << "*TEcnaRun::LowFrequencyCorrelationsBetweenChannels()" << std::endl;
2750   }
2751   if (fFlagPrint == fCodePrintAllComments) {
2752     std::cout << "          Calculation of the Low Frequency Correlations between channels" << std::endl
2753               << "          Starting allocation. " << std::endl;
2754   }
2755 
2756   //................. allocation fT2d_lf_cor + init to zero (mandatory)
2757   if (fT2d_lf_cor == nullptr) {
2758     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
2759     fT2d_lf_cor = new Double_t*[n_StexEcha];
2760     fCnew++;
2761     fT2d1_lf_cor = new Double_t[n_StexEcha * n_StexEcha];
2762     fCnew++;
2763     for (Int_t i0StexEcha = 0; i0StexEcha < n_StexEcha; i0StexEcha++) {
2764       fT2d_lf_cor[i0StexEcha] = &fT2d1_lf_cor[0] + i0StexEcha * n_StexEcha;
2765     }
2766   }
2767 
2768   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2769     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
2770       if (fT2d_lf_cor[i0StexEcha][j0StexEcha] != (Double_t)0) {
2771         fMiscDiag[22]++;
2772         fT2d_lf_cor[i0StexEcha][j0StexEcha] = (Double_t)0;
2773       }
2774     }
2775   }
2776 
2777   //................. calculation
2778   //........................... computation of half of the matrix, diagonal included
2779   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2780     if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0) ||
2781         (fFlagSubDet == "EB")) {
2782       for (Int_t j0StexEcha = 0; j0StexEcha <= i0StexEcha; j0StexEcha++) {
2783         if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0) ||
2784             (fFlagSubDet == "EB")) {
2785           if (fT2d_lf_cov[i0StexEcha][i0StexEcha] > 0 && fT2d_lf_cov[j0StexEcha][j0StexEcha] > 0) {
2786             fT2d_lf_cor[i0StexEcha][j0StexEcha] =
2787                 fT2d_lf_cov[i0StexEcha][j0StexEcha] /
2788                 ((Double_t)sqrt(fT2d_lf_cov[i0StexEcha][i0StexEcha] * fT2d_lf_cov[j0StexEcha][j0StexEcha]));
2789           } else {
2790             fT2d_lf_cor[i0StexEcha][j0StexEcha] = (Double_t)0.;
2791           }
2792           fT2d_lf_cor[j0StexEcha][i0StexEcha] = fT2d_lf_cor[i0StexEcha][j0StexEcha];
2793         }
2794       }
2795     }
2796     if (i0StexEcha % 100 == 0) {
2797       std::cout << i0StexEcha << "[LFN Cor], ";
2798     }
2799   }
2800   std::cout << std::endl;
2801 
2802   fTagLfCor[0] = 1;
2803   fFileHeader->fLfCorCalc++;
2804 }
2805 //--------------- (end of LowFrequencyCorrelationsBetweenChannels) --------------------
2806 
2807 //------------------------------------------------------------------
2808 //
2809 //  Calculation of the High Frequency Covariances between channels
2810 //
2811 //  HFCov(Ci,Cj) = E_e[ Cov_s[ A(Ci,s*,e*) , A(Cj,s*,e*) ] ]
2812 //
2813 //               = E_e[ E_s[ ( A(Ci,s*,e*) - E_s[A(Ci,s*,e*)] )*
2814 //                           ( A(Cj,s*,e*) - E_s[A(Cj,s*,e*)] ) ] ]
2815 //
2816 //   A(Ci,s,e) : ADC value for channel Ci, sample s, event e
2817 //
2818 //   E_e         : average over the events
2819 //   E_s , Cov_s : average, covariance over the samples
2820 //
2821 //------------------------------------------------------------------
2822 void TEcnaRun::HighFrequencyCovariancesBetweenChannels() {
2823   //Calculation of the High Frequency Covariances between channels
2824 
2825   if (fFlagPrint != fCodePrintNoComment) {
2826     std::cout << "*TEcnaRun::HighFrequencyCovariancesBetweenChannels()" << std::endl;
2827   }
2828   if (fFlagPrint == fCodePrintAllComments) {
2829     std::cout << "           Calculation of the High Frequency Covariances between channels" << std::endl;
2830   }
2831 
2832   //................. allocation fT2d_hf_cov + init to zero (mandatory)
2833   if (fT2d_hf_cov == nullptr) {
2834     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
2835     fT2d_hf_cov = new Double_t*[n_StexEcha];
2836     fCnew++;
2837     fT2d1_hf_cov = new Double_t[n_StexEcha * n_StexEcha];
2838     fCnew++;
2839     for (Int_t i0StexEcha = 0; i0StexEcha < n_StexEcha; i0StexEcha++) {
2840       fT2d_hf_cov[i0StexEcha] = &fT2d1_hf_cov[0] + i0StexEcha * n_StexEcha;
2841     }
2842   }
2843 
2844   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2845     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
2846       if (fT2d_hf_cov[i0StexEcha][j0StexEcha] != (Double_t)0) {
2847         fMiscDiag[23]++;
2848         fT2d_hf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;
2849       }
2850     }
2851   }
2852 
2853   //................... Allocation mean_over_samples(i0StexEcha, n_event)
2854   TMatrixD mean_over_samples(fEcal->MaxCrysEcnaInStex(), fNumberOfEvents);
2855   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2856     for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2857       mean_over_samples(i0StexEcha, n_event) = (Double_t)0.;
2858     }
2859   }
2860   //................... Allocation cov_over_samp(i0StexEcha,j0StexEcha)
2861   TMatrixD cov_over_samp(fEcal->MaxCrysEcnaInStex(), fEcal->MaxCrysEcnaInStex());
2862   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2863     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
2864       cov_over_samp(i0StexEcha, j0StexEcha) = (Double_t)0.;
2865     }
2866   }
2867 
2868   //........................................... Calculation    (HighFrequencyCovariancesBetweenChannels)
2869   if (fFlagPrint != fCodePrintNoComment) {
2870     std::cout << "          Calculation of the mean (over the events)" << std::endl
2871               << "          of the covariances between the channels (over the samples 1 to " << fNbSampForCalc << ")."
2872               << std::endl;
2873   }
2874 
2875   std::cout << " Please, wait (end at i= " << fEcal->MaxCrysEcnaInStex() << "): " << std::endl;
2876 
2877   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2878     if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0) ||
2879         (fFlagSubDet == "EB")) {
2880       for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2881         // Calculation, for each event, of the mean over the samples  ( = E_s[A(c_i,s*,e_n] )
2882         mean_over_samples(i0StexEcha, n_event) = (Double_t)0.;
2883         for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
2884           mean_over_samples(i0StexEcha, n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];
2885         }
2886         mean_over_samples(i0StexEcha, n_event) /= (Double_t)fNbSampForCalc;
2887       }
2888     }
2889     if (i0StexEcha % 100 == 0) {
2890       std::cout << i0StexEcha << "[HFNa Cov], ";
2891     }
2892   }
2893   std::cout << std::endl;
2894 
2895   std::cout << " Please, wait (end at i= " << fEcal->MaxCrysEcnaInStex() << "): " << std::endl;
2896 
2897   //... Calculation of half of the matrix, diagonal included    (HighFrequencyCovariancesBetweenChannels)
2898   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2899     if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0) ||
2900         (fFlagSubDet == "EB")) {
2901       for (Int_t j0StexEcha = 0; j0StexEcha <= i0StexEcha; j0StexEcha++) {
2902         if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0) ||
2903             (fFlagSubDet == "EB")) {
2904           for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2905             // Calculation, for each event, of the covariance over the samples
2906             cov_over_samp(i0StexEcha, j0StexEcha) = (Double_t)0;
2907             for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++) {
2908               cov_over_samp(i0StexEcha, j0StexEcha) +=
2909                   (fT3d_AdcValues[i0StexEcha][i0Sample][n_event] - mean_over_samples(i0StexEcha, n_event)) *
2910                   (fT3d_AdcValues[j0StexEcha][i0Sample][n_event] - mean_over_samples(j0StexEcha, n_event));
2911             }
2912             cov_over_samp(i0StexEcha, j0StexEcha) /= (Double_t)fNbSampForCalc;
2913           }
2914           //....... Calculation of the mean over the events of Cov_s[A(c_i,s*,e*),A(c_j,s*,e*)]
2915           //......... Calculation of half of the matrix, diagonal included
2916           fT2d_hf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;
2917           for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++) {
2918             fT2d_hf_cov[i0StexEcha][j0StexEcha] += cov_over_samp(i0StexEcha, j0StexEcha);
2919           }
2920           fT2d_hf_cov[i0StexEcha][j0StexEcha] /= (Double_t)fNumberOfEvents;
2921 
2922           fT2d_hf_cov[j0StexEcha][i0StexEcha] = fT2d_hf_cov[i0StexEcha][j0StexEcha];
2923         }
2924       }
2925     }
2926     if (i0StexEcha % 100 == 0) {
2927       std::cout << i0StexEcha << "[HFNb Cov], ";
2928     }
2929   }
2930   std::cout << std::endl;
2931 
2932   fTagHfCov[0] = 1;
2933   fFileHeader->fHfCovCalc++;
2934 }
2935 //---------- (end of HighFrequencyCovariancesBetweenChannels ) --------------------
2936 
2937 //------------------------------------------------------------------
2938 //
2939 //  Calculation of the High Frequency Correlations between channels
2940 //
2941 //  HFCor(Ci,Cj) = HFCov(Ci,Cj)/sqrt(HFCov(Ci,Ci)*HFCov(Cj,Cj))
2942 //
2943 //------------------------------------------------------------------
2944 void TEcnaRun::HighFrequencyCorrelationsBetweenChannels() {
2945   //Calculation of the High Frequency Correlations between channels
2946 
2947   //... preliminary calculation of the covariances if not done yet.
2948   if (fTagHfCov[0] != 1) {
2949     HighFrequencyCovariancesBetweenChannels();
2950     fTagHfCov[0] = 0;
2951   }
2952 
2953   if (fFlagPrint != fCodePrintNoComment) {
2954     std::cout << "*TEcnaRun::HighFrequencyCorrelationsBetweenChannels()" << std::endl;
2955   }
2956   if (fFlagPrint == fCodePrintAllComments) {
2957     std::cout << "           Calculation of the High Frequency Correlations between channels" << std::endl
2958               << "          Starting allocation. " << std::endl;
2959   }
2960 
2961   //................. allocation fT2d_hf_cor + init to zero (mandatory)
2962   if (fT2d_hf_cor == nullptr) {
2963     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
2964     fT2d_hf_cor = new Double_t*[n_StexEcha];
2965     fCnew++;
2966     fT2d1_hf_cor = new Double_t[n_StexEcha * n_StexEcha];
2967     fCnew++;
2968     for (Int_t i0StexEcha = 0; i0StexEcha < n_StexEcha; i0StexEcha++) {
2969       fT2d_hf_cor[i0StexEcha] = &fT2d1_hf_cor[0] + i0StexEcha * n_StexEcha;
2970     }
2971   }
2972 
2973   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2974     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
2975       if (fT2d_hf_cor[i0StexEcha][j0StexEcha] != (Double_t)0) {
2976         fMiscDiag[24]++;
2977         fT2d_hf_cor[i0StexEcha][j0StexEcha] = (Double_t)0;
2978       }
2979     }
2980   }
2981 
2982   //................. calculation
2983   //........................... computation of half of the matrix, diagonal included
2984 
2985   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
2986     if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0) ||
2987         (fFlagSubDet == "EB")) {
2988       for (Int_t j0StexEcha = 0; j0StexEcha <= i0StexEcha; j0StexEcha++) {
2989         if ((fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0) ||
2990             (fFlagSubDet == "EB")) {
2991           if (fT2d_hf_cov[i0StexEcha][i0StexEcha] > 0 && fT2d_hf_cov[j0StexEcha][j0StexEcha] > 0) {
2992             fT2d_hf_cor[i0StexEcha][j0StexEcha] =
2993                 fT2d_hf_cov[i0StexEcha][j0StexEcha] / ((Double_t)sqrt(fT2d_hf_cov[i0StexEcha][i0StexEcha]) *
2994                                                        (Double_t)sqrt(fT2d_hf_cov[j0StexEcha][j0StexEcha]));
2995           } else {
2996             fT2d_hf_cor[i0StexEcha][j0StexEcha] = (Double_t)0.;
2997           }
2998 
2999           fT2d_hf_cor[j0StexEcha][i0StexEcha] = fT2d_hf_cor[i0StexEcha][j0StexEcha];
3000         }
3001       }
3002     }
3003     if (i0StexEcha % 100 == 0) {
3004       std::cout << i0StexEcha << "[HFN Cor], ";
3005     }
3006   }
3007   std::cout << std::endl;
3008 
3009   fTagHfCor[0] = 1;
3010   fFileHeader->fHfCorCalc++;
3011 }
3012 //------- (end of HighFrequencyCorrelationsBetweenChannels) ----------
3013 
3014 //=================================================================================
3015 //
3016 //          L O W  &  H I G H    F R E Q U E N C Y    C O R R E L A T I O N S
3017 //
3018 //       B E T W E E N   T O W E R S  ( E B )  O R   S C s   ( E E )
3019 //
3020 //=================================================================================
3021 //-----------------------------------------------------------------------------
3022 //      Calculation of the mean Low Frequency Correlations
3023 //      between channels for each Stin
3024 //-----------------------------------------------------------------------------
3025 void TEcnaRun::LowFrequencyMeanCorrelationsBetweenTowers() { LowFrequencyMeanCorrelationsBetweenStins(); }
3026 void TEcnaRun::LowFrequencyMeanCorrelationsBetweenSCs() { LowFrequencyMeanCorrelationsBetweenStins(); }
3027 
3028 void TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins() {
3029   //Calculation of the mean Low Frequency Correlations
3030   //between channels for each Stin
3031 
3032   //... preliminary calculation of the Low Frequency Cor(c,c) if not done yet
3033   //    Only one tag (dim=1) to set to 0 (no write in the result ROOT file)
3034   if (fTagLfCor[0] != 1) {
3035     LowFrequencyCorrelationsBetweenChannels();
3036     fTagLfCor[0] = 0;
3037   }
3038 
3039   //..... mean fT2d_lfcc_mostins for each pair (Stin_X,Stin_Y)
3040   if (fFlagPrint != fCodePrintNoComment) {
3041     std::cout << "*TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins()" << std::endl;
3042   }
3043   if (fFlagPrint == fCodePrintAllComments) {
3044     std::cout << "           Calculation of the mean, for each " << fStinName.Data() << ", of the" << std::endl
3045               << "           Low Frequency Correlations between channels." << std::endl;
3046   }
3047 
3048   //................. allocation fT2d_lfcc_mostins + init to zero (mandatory)
3049   if (fT2d_lfcc_mostins == nullptr) {
3050     const Int_t n_Stin = fEcal->MaxStinEcnaInStex();
3051     fT2d_lfcc_mostins = new Double_t*[n_Stin];
3052     fCnew++;
3053     fT2d1_lfcc_mostins = new Double_t[n_Stin * n_Stin];
3054     fCnew++;
3055     for (Int_t i0StexStinEcna = 0; i0StexStinEcna < n_Stin; i0StexStinEcna++) {
3056       fT2d_lfcc_mostins[i0StexStinEcna] = &fT2d1_lfcc_mostins[0] + i0StexStinEcna * n_Stin;
3057     }
3058   }
3059 
3060   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
3061     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
3062       if (fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] != (Double_t)0) {
3063         fMiscDiag[31]++;
3064         fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;
3065       }
3066     }
3067   }
3068 
3069   //..... Calculation of the mean LF Cor(c,c) for each pair (Stin_X,Stin_Y)
3070   //
3071   //           ! => Warning: this matrix is NOT symmetric => take N*N elements
3072   //                Only (Stin,Stin) matrix is symmetric.
3073   //                (StinEcha,StinEcha) matrix inside a (Stin,Stin) element is NOT symmetric
3074   //                (except for the (Stin,Stin) DIAGONAL elements)
3075   //      Then:
3076   //            1D array half_LFccMos[N*N] to put the (channel,channel) correlations
3077 
3078   Int_t ndim = (Int_t)(fEcal->MaxCrysInStin() * fEcal->MaxCrysInStin());
3079 
3080   TVectorD half_LFccMos(ndim);
3081   for (Int_t i = 0; i < ndim; i++) {
3082     half_LFccMos(i) = (Double_t)0.;
3083   }
3084 
3085   //..................... Calculation
3086   if (fFlagPrint != fCodePrintNoComment) {
3087     std::cout << "*TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins()" << std::endl;
3088   }
3089   if (fFlagPrint == fCodePrintAllComments) {
3090     std::cout << "           Calculation, for each " << fStinName.Data() << ", of the mean " << std::endl
3091               << "           Low Frequency cor(c,c)." << std::endl;
3092   }
3093 
3094   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
3095     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
3096       //................... .Copy the Mean Correlations(c,c') in 1D vector half_LFccMos()
3097       Int_t i_count = 0;
3098       for (Int_t i0StinCrys = 0; i0StinCrys < fEcal->MaxCrysInStin(); i0StinCrys++) {
3099         Int_t i0StexEcha = i0StexStinEcna * fEcal->MaxCrysInStin() + i0StinCrys;
3100         for (Int_t j0StinCrys = 0; j0StinCrys < fEcal->MaxCrysInStin(); j0StinCrys++) {
3101           Int_t j0StexEcha = j0StexStinEcna * fEcal->MaxCrysInStin() + j0StinCrys;
3102           if ((i0StexEcha >= 0 && i0StexEcha < fEcal->MaxCrysEcnaInStex()) &&
3103               (j0StexEcha >= 0 && j0StexEcha < fEcal->MaxCrysEcnaInStex())) {
3104             half_LFccMos(i_count) = fT2d_lf_cor[i0StexEcha][j0StexEcha];
3105             i_count++;
3106           } else {
3107             std::cout << "!TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins()> Channel number out of range."
3108                       << "i0StexEcha = " << i0StexEcha << ", j0StexEcha = " << j0StexEcha << fTTBELL << std::endl;
3109           }
3110         }
3111       }
3112       //...... Calculation of the mean absolute values of the LF mean Correlations(c,c')
3113       fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;
3114       for (Int_t i_rcor = 0; i_rcor < ndim; i_rcor++) {
3115         fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] += fabs(half_LFccMos(i_rcor));
3116       }
3117       fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] /= (Double_t)ndim;
3118     }
3119     if (i0StexStinEcna % 10 == 0) {
3120       std::cout << i0StexStinEcna << "[LFN MCtt], ";
3121     }
3122   }
3123   std::cout << std::endl;
3124 
3125   fTagLFccMoStins[0] = 1;
3126   fFileHeader->fLFccMoStinsCalc++;
3127 }  // ------- end of LowFrequencyMeanCorrelationsBetweenStins() -------
3128 
3129 //-----------------------------------------------------------------------------
3130 //      Calculation of the mean High Frequency Correlations
3131 //      between channels for each Stin
3132 //-----------------------------------------------------------------------------
3133 void TEcnaRun::HighFrequencyMeanCorrelationsBetweenTowers() { HighFrequencyMeanCorrelationsBetweenStins(); }
3134 void TEcnaRun::HighFrequencyMeanCorrelationsBetweenSCs() { HighFrequencyMeanCorrelationsBetweenStins(); }
3135 
3136 void TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins() {
3137   //Calculation of the mean High Frequency Correlations
3138   //between channels for each Stin
3139 
3140   //... preliminary calculation of the High Frequency Cor(c,c) if not done yet
3141   //    Only one tag (dim=1) to set to 0 (no write in the result ROOT file)
3142   if (fTagHfCor[0] != 1) {
3143     HighFrequencyCorrelationsBetweenChannels();
3144     fTagHfCor[0] = 0;
3145   }
3146 
3147   //..... mean fT2d_hfcc_mostins for each pair (Stin_X,Stin_Y)
3148   if (fFlagPrint != fCodePrintNoComment) {
3149     std::cout << "*TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins()" << std::endl;
3150   }
3151   if (fFlagPrint == fCodePrintAllComments) {
3152     std::cout << "           Calculation of the mean, for each " << fFlagSubDet.Data() << ", of the" << std::endl
3153               << "           High Frequency Correlations between channels." << std::endl;
3154   }
3155 
3156   //................. allocation fT2d_hfcc_mostins + init to zero (mandatory)
3157   if (fT2d_hfcc_mostins == nullptr) {
3158     const Int_t n_Stin = fEcal->MaxStinEcnaInStex();
3159     fT2d_hfcc_mostins = new Double_t*[n_Stin];
3160     fCnew++;
3161     fT2d1_hfcc_mostins = new Double_t[n_Stin * n_Stin];
3162     fCnew++;
3163     for (Int_t i0StexStinEcna = 0; i0StexStinEcna < n_Stin; i0StexStinEcna++) {
3164       fT2d_hfcc_mostins[i0StexStinEcna] = &fT2d1_hfcc_mostins[0] + i0StexStinEcna * n_Stin;
3165     }
3166   }
3167 
3168   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
3169     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
3170       if (fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] != (Double_t)0) {
3171         fMiscDiag[32]++;
3172         fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;
3173       }
3174     }
3175   }
3176 
3177   //..... Calculation of the mean HF Cor(c,c) for each pair (Stin_X,Stin_Y)
3178   //
3179   //           ! => Warning: this matrix is NOT symmetric => take N*N elements
3180   //                Only (Stin,Stin) matrix is symmetric.
3181   //                (StinEcha,StinEcha) matrix inside a (Stin,Stin) element is NOT symmetric
3182   //                (except for the (Stin,Stin) DIAGONAL elements)
3183   //      Then:
3184   //            1D array half_LFccMos[N*N] to put the (channel,channel) correlations
3185 
3186   Int_t ndim = (Int_t)(fEcal->MaxCrysInStin() * fEcal->MaxCrysInStin());
3187 
3188   TVectorD half_HFccMos(ndim);
3189   for (Int_t i = 0; i < ndim; i++) {
3190     half_HFccMos(i) = (Double_t)0.;
3191   }
3192 
3193   if (fFlagPrint != fCodePrintNoComment) {
3194     std::cout << "*TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins()" << std::endl;
3195   }
3196   if (fFlagPrint == fCodePrintAllComments) {
3197     std::cout << "           Calculation, for each " << fFlagSubDet.Data() << ", of the mean " << std::endl
3198               << "           High Frequency cor(c,c)." << std::endl;
3199   }
3200 
3201   //..................... Calculation
3202   for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
3203     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
3204       //.................... Copy the relevant Mean Correlations(c,c') in 1D vector half_HFccMos()
3205       Int_t i_count = 0;
3206       for (Int_t i0StinCrys = 0; i0StinCrys < fEcal->MaxCrysInStin(); i0StinCrys++) {
3207         Int_t i0StexEcha = i0StexStinEcna * fEcal->MaxCrysInStin() + i0StinCrys;
3208         for (Int_t j0StinCrys = 0; j0StinCrys < fEcal->MaxCrysInStin(); j0StinCrys++) {
3209           Int_t j0StexEcha = j0StexStinEcna * fEcal->MaxCrysInStin() + j0StinCrys;
3210           if ((i0StexEcha >= 0 && i0StexEcha < fEcal->MaxCrysEcnaInStex()) &&
3211               (j0StexEcha >= 0 && j0StexEcha < fEcal->MaxCrysEcnaInStex())) {
3212             half_HFccMos(i_count) = fT2d_hf_cor[i0StexEcha][j0StexEcha];
3213             i_count++;
3214           } else {
3215             std::cout << "!TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins()> Channel number out of range."
3216                       << "i0StexEcha = " << i0StexEcha << ", j0StexEcha = " << j0StexEcha << fTTBELL << std::endl;
3217           }
3218         }
3219       }
3220       //..... Calculation of the mean absolute values of the HF mean Correlations(c,c')
3221       fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;
3222       for (Int_t i_rcor = 0; i_rcor < ndim; i_rcor++) {
3223         fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] += fabs(half_HFccMos(i_rcor));
3224       }
3225       fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] /= (Double_t)ndim;
3226     }
3227     if (i0StexStinEcna % 10 == 0) {
3228       std::cout << i0StexStinEcna << "[HFN MCtt], ";
3229     }
3230   }
3231   std::cout << std::endl;
3232 
3233   fTagHFccMoStins[0] = 1;
3234   fFileHeader->fHFccMoStinsCalc++;
3235 }  // ------- end of HighFrequencyMeanCorrelationsBetweenStins() -------
3236 
3237 //=========================================================================
3238 //
3239 //                  W R I T I N G     M E T H O D S
3240 //
3241 //=========================================================================
3242 
3243 //=========================================================================
3244 //
3245 //         W R I T I N G   M E T H O D S :    R O O T    F I L E S
3246 //
3247 //=========================================================================
3248 //-------------------------------------------------------------
3249 //
3250 //                      OpenRootFile
3251 //
3252 //-------------------------------------------------------------
3253 Bool_t TEcnaRun::OpenRootFile(const Text_t* name, const TString& status) {
3254   //Open the Root file
3255 
3256   Bool_t ok_open = kFALSE;
3257 
3258   TString s_name;
3259   s_name = fCnaParPaths->ResultsRootFilePath();
3260   s_name.Append('/');
3261   s_name.Append(name);
3262 
3263   //gCnaRootFile = new TEcnaRootFile(fObjectManager, s_name.Data(), status);     fCnew++;
3264 
3265   Long_t iCnaRootFile = fObjectManager->GetPointerValue("TEcnaRootFile");
3266   if (iCnaRootFile == 0) {
3267     gCnaRootFile = new TEcnaRootFile(fObjectManager, s_name.Data(), status); /* Anew("gCnaRootFile");*/
3268   } else {
3269     gCnaRootFile = (TEcnaRootFile*)iCnaRootFile;
3270     gCnaRootFile->ReStart(s_name.Data(), status);
3271   }
3272 
3273   if (gCnaRootFile->fRootFileStatus == "RECREATE") {
3274     ok_open = gCnaRootFile->OpenW();
3275   }
3276   if (gCnaRootFile->fRootFileStatus == "READ") {
3277     ok_open = gCnaRootFile->OpenR();
3278   }
3279 
3280   if (!ok_open)  // unable to open file
3281   {
3282     std::cout << "TEcnaRun::OpenRootFile> Cannot open file " << s_name.Data() << std::endl;
3283   } else {
3284     if (fFlagPrint == fCodePrintAllComments) {
3285       std::cout << "*TEcnaRun::OpenRootFile> Open ROOT file OK for file " << s_name.Data() << std::endl;
3286     }
3287     fOpenRootFile = kTRUE;
3288   }
3289   return ok_open;
3290 }
3291 //-------------------------------------------------------------
3292 //
3293 //                      CloseRootFile
3294 //
3295 //-------------------------------------------------------------
3296 Bool_t TEcnaRun::CloseRootFile(const Text_t* name) {
3297   //Close the Root file
3298 
3299   TString s_name;
3300   s_name = fCnaParPaths->ResultsRootFilePath();
3301   s_name.Append('/');
3302   s_name.Append(name);
3303 
3304   Bool_t ok_close = kFALSE;
3305 
3306   if (fOpenRootFile == kTRUE) {
3307     gCnaRootFile->CloseFile();
3308 
3309     if (fFlagPrint != fCodePrintAllComments) {
3310       std::cout << "*TEcnaRun::CloseRootFile> ROOT file " << s_name.Data() << " closed." << std::endl;
3311     }
3312 
3313     //     delete gCnaRootFile;     gCnaRootFile = 0;          fCdelete++;
3314 
3315     fOpenRootFile = kFALSE;
3316     ok_close = kTRUE;
3317   } else {
3318     std::cout << "*TEcnaRun::CloseRootFile(...)> No close since no file is open." << fTTBELL << std::endl;
3319   }
3320   return ok_close;
3321 }
3322 //-------------------------------------------------------------
3323 //
3324 //   WriteRootFile without arguments.
3325 //   Call WriteRootFile WITH argument (file name)
3326 //   after an automatic generation of the file name.
3327 //
3328 //   Codification for the file name:
3329 //            see comment at the beginning of this file
3330 //
3331 //-------------------------------------------------------------
3332 
3333 //=================================================================================
3334 //
3335 //         WriteRootFile()   ====>  D O N ' T    S U P P R E S S  ! ! !
3336 //                                  Called by the analyzer in package: "Modules"
3337 //
3338 //=================================================================================
3339 Bool_t TEcnaRun::WriteRootFile() {
3340   //Write the Root file.
3341   //File name automatically generated by fCnaWrite->fMakeResultsFileName()
3342   //previously called in GetReadyToCompute().
3343 
3344   Bool_t ok_write = kFALSE;
3345 
3346   //============================= check number of found events
3347   Int_t nCountEvts = 0;
3348 
3349   for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
3350     for (Int_t i0Sample = 0; i0Sample < fFileHeader->fNbOfSamples; i0Sample++) {
3351       nCountEvts += fT2d_NbOfEvts[i0StexEcha][i0Sample];
3352     }
3353   }
3354 
3355   if (nCountEvts <= 0) {
3356     //============== no write if no event found
3357     std::cout << "!TEcnaRun::WriteRootFile()> No event found for file " << fCnaWrite->GetRootFileNameShort().Data()
3358               << ". File will not be written." << std::endl;
3359     ok_write = kTRUE;
3360   } else {
3361     if (fFlagPrint == fCodePrintAllComments) {
3362       std::cout << "*TEcnaRun::WriteRootFile()> Results are going to be written in the ROOT file: " << std::endl
3363                 << "                           " << fCnaWrite->GetRootFileName().Data() << std::endl;
3364     }
3365 
3366     const Text_t* FileShortName = (const Text_t*)fCnaWrite->GetRootFileNameShort().Data();
3367     ok_write = WriteRootFile(FileShortName, fFileHeader->fNbOfSamples);
3368 
3369     if (ok_write == kTRUE) {
3370       if (fFlagPrint != fCodePrintNoComment) {
3371         std::cout << "*TEcnaRun::WriteRootFile()> Writing OK for file " << fCnaWrite->GetRootFileName().Data()
3372                   << std::endl;
3373       }
3374     } else {
3375       std::cout << "!TEcnaRun::WriteRootFile()> Writing FAILLED for file " << fCnaWrite->GetRootFileName().Data()
3376                 << fTTBELL << std::endl;
3377     }
3378   }
3379   return ok_write;
3380 }  // end of WriteRootFile()
3381 
3382 //--------------------------------------------------------------------
3383 //
3384 //               WriteNewRootFile with argument
3385 //    Called by TEcnaGui for results file of the Calculations method
3386 //    analysis type and nb of samples changed, other arguments kept
3387 //
3388 //--------------------------------------------------------------------
3389 Bool_t TEcnaRun::WriteNewRootFile(const TString& TypAna) {
3390   //Write a new Root file. File name automatically generated by fCnaWrite->fMakeResultsFileName()
3391   //called here.
3392 
3393   Bool_t ok_write = kFALSE;
3394 
3395   fCnaWrite->RegisterFileParameters(TypAna.Data(),
3396                                     fNbSampForCalc,
3397                                     fFileHeader->fRunNumber,
3398                                     fFileHeader->fFirstReqEvtNumber,
3399                                     fFileHeader->fLastReqEvtNumber,
3400                                     fFileHeader->fReqNbOfEvts,
3401                                     fFileHeader->fStex,
3402                                     fFileHeader->fStartDate,
3403                                     fFileHeader->fStopDate,
3404                                     fFileHeader->fStartTime,
3405                                     fFileHeader->fStopTime);
3406 
3407   fCnaWrite->fMakeResultsFileName();  // set fRootFileName, fRootFileNameShort
3408   fNewRootFileName = fCnaWrite->GetRootFileName();
3409   fNewRootFileNameShort = fCnaWrite->GetRootFileNameShort();
3410 
3411   const Text_t* FileShortName = (const Text_t*)fNewRootFileNameShort.Data();
3412 
3413   if (fFlagPrint == fCodePrintAllComments) {
3414     std::cout << "*TEcnaRun::WriteNewRootFile()> Results are going to be written in the ROOT file: " << std::endl
3415               << "                              " << fNewRootFileNameShort.Data() << std::endl;
3416   }
3417 
3418   ok_write = WriteRootFile(FileShortName, fNbSampForCalc);
3419 
3420   return ok_write;
3421 }
3422 
3423 //-------------------------------------------------------------------------
3424 //
3425 //    Get the new ROOT file name (long and short)
3426 //   (called by TEcnaGui in Calculations method)
3427 //
3428 //-------------------------------------------------------------------------
3429 TString TEcnaRun::GetNewRootFileName() { return fNewRootFileName; }
3430 TString TEcnaRun::GetNewRootFileNameShort() { return fNewRootFileNameShort; }
3431 
3432 //--------------------------------------------------------------------
3433 //
3434 //               WriteRootFile with argument
3435 //
3436 //--------------------------------------------------------------------
3437 Bool_t TEcnaRun::WriteRootFile(const Text_t* name, Int_t& argNbSampWrite) {
3438   //Write the Root file
3439 
3440   const Text_t* file_name = name;
3441 
3442   Bool_t ok_write = kFALSE;
3443 
3444   if (fOpenRootFile) {
3445     std::cout << "!TEcnaRun::WriteRootFile(...) *** ERROR ***> Writing on file already open." << fTTBELL << std::endl;
3446   } else {
3447     // List of the different element types and associated parameters as ordered in the ROOT file (smaller -> larger)
3448     //                                                                 ==========
3449     //
3450     //         WARNING  *** HERE SIZES ARE THESE FOR THE BARREL (1700 Xtals) and for 10 samples ***
3451     //
3452     //   Nb of   Type of element            Type      Type                                    Size    Comment
3453     // elements                             Number    Name
3454     //
3455     //        1  fMatHis(1,StexStin)         ( 0)  cTypNumbers             1*(   1,  68) =         68
3456 
3457     //        1  fMatHis(1,StexStin)         (12)  cTypAvPed               1*(   1,  68) =         68
3458     //        1  fMatHis(1,StexStin)         ( 3)  cTypAvTno               1*(   1,  68) =         68
3459     //        1  fMatHis(1,StexStin)         ( 4)  cTypAvLfn               1*(   1,  68) =         68
3460     //        1  fMatHis(1,StexStin)         ( 5)  cTypAvHfn               1*(   1,  68) =         68
3461     //        1  fMatHis(1,StexStin)         (13)  cTypAvMeanCorss         1*(   1,  68) =         68
3462     //        1  fMatHis(1,StexStin)         (14)  cTypAvSigCorss          1*(   1,  68) =         68
3463 
3464     //        1  fMatHis(1,StexEcha)         (16)  cTypPed                 1*(   1,1700) =      1 700
3465     //        1  fMatHis(1,StexEcha)         (17)  cTypTno                 1*(   1,1700) =      1 700
3466     //        1  fMatHis(1,StexEcha)         (10)  cTypMeanCorss           1*(   1,1700) =      1 700
3467     //        1  fMatHis(1,StexEcha)         (18)  cTypLfn                 1*(   1,1700) =      1 700
3468     //        1  fMatHis(1,StexEcha)         (19)  cTypHfn                 1*(   1,1700) =      1 700
3469     //        1  fMatHis(1,StexEcha)         (11)  cTypSigCorss            1*(   1,1700) =      1 700
3470 
3471     //        1  fMatMat(Stin,Stin)          (23)  cTypLFccMoStins         1*(  68,  68) =      4 624
3472     //        1  fMatMat(Stin,Stin)          (24)  cTypHFccMoStins         1*(  68,  68) =      4 624
3473 
3474     //        1  fMatHis(StexEcha, sample)   (15)  cTypNbOfEvts            1*(1700,  10) =     17 000
3475     //        1  fMatHis(StexEcha, sample)   ( 1)  cTypMSp                 1*(1700,  10) =     17 000
3476     //        1  fMatHis(StexEcha, sample)   ( 2)  cTypSSp                 1*(1700,  10) =     17 000
3477 
3478     //   StexEcha  fMatMat(sample, sample)   ( 8)  cTypCovCss           1700*(  10,  10) =    170 000
3479     //   StexEcha  fMatMat(sample, sample    ( 9)  cTypCorCss           1700*(  10,  10) =    170 000
3480 
3481     //   StexEcha  fMatHis(sample, bin_evt)  (20)  cTypAdcEvt,          1700*(  10, 150) =  2 550 000
3482 
3483     //        1  fMatMat(StexEcha, StexEcha) (21)  cTypLfCov               1*(1700,1700) =  2 890 000
3484     //        1  fMatMat(StexEcha, StexEcha) (22)  cTypLfCor               1*(1700,1700) =  2 890 000
3485 
3486     //        1  fMatMat(StexEcha, StexEcha) ( 6)  cTypHfCov               1*(1700,1700) =  2 890 000 // (06/05/08)
3487     //        1  fMatMat(StexEcha, StexEcha) ( 7)  cTypHfCor               1*(1700,1700) =  2 890 000 // (06/05/08)
3488 
3489     //......................................................................................................
3490 
3491     OpenRootFile(file_name, "RECREATE");
3492 
3493     TString typ_name = "?";
3494     Int_t v_nb_times = 0;
3495     Int_t v_dim_one = 0;
3496     Int_t v_dim_two = 0;
3497     Int_t v_size = 0;
3498     Int_t v_tot = 0;
3499     Int_t v_tot_writ = 0;
3500 
3501     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3502     //
3503     //  ===> no general method and no translation to TEcnaWrite
3504     //       because the fT1d.. and fT2d... arrays
3505     //       are attributes of TEcnaRun (calls to the "TRootXXXX" methods)
3506     //
3507     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3508 
3509     //-------------------------- Stin numbers
3510     //       1   fMatHis(1,Stin)           ( 0)  cTypNumbers        1*(   1,  68) =         68
3511 
3512     Int_t MaxCar = fgMaxCar;
3513     typ_name.Resize(MaxCar);
3514     typ_name = "StinNumbers";
3515     v_nb_times = fFileHeader->fStinNumbersCalc;
3516     v_dim_one = 1;
3517     v_dim_two = fEcal->MaxStinEcnaInStex();
3518     v_size = v_nb_times * v_dim_one * v_dim_two;
3519     v_tot += v_size;
3520 
3521     if (fFlagPrint == fCodePrintAllComments) {
3522       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3523                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3524                 << v_size;
3525     }
3526 
3527     for (Int_t i = 0; i < v_nb_times; i++) {
3528       if (fTagStinNumbers[0] == 1) {
3529         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypNumbers;
3530         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3531         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3532         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3533         TRootStinNumbers();
3534         gCnaRootFile->fCnaResultsTree->Fill();
3535         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3536           std::cout << " => WRITTEN ON FILE ";
3537           v_tot_writ += v_size;
3538         }
3539       }
3540     }
3541     if (fFlagPrint == fCodePrintAllComments) {
3542       std::cout << std::endl;
3543     }
3544 
3545     //-------------------------- Average Pedestals (1 value per Stin)
3546     //       1   fMatHis(1, StexStin)   (12)  cTypAvPed      1*(1,  68) =     68
3547 
3548     MaxCar = fgMaxCar;
3549     typ_name.Resize(MaxCar);
3550     typ_name = "AvPed";
3551     v_nb_times = fFileHeader->fAvPedCalc;
3552     v_dim_one = 1;
3553     v_dim_two = fEcal->MaxStinEcnaInStex();
3554     v_size = v_nb_times * v_dim_one * v_dim_two;
3555     v_tot += v_size;
3556 
3557     if (fFlagPrint == fCodePrintAllComments) {
3558       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3559                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3560                 << v_size;
3561     }
3562 
3563     for (Int_t i = 0; i < v_nb_times; i++) {
3564       if (fTagAvPed[0] == 1) {
3565         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvPed;
3566         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3567         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3568         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3569         TRootAvPed();
3570         gCnaRootFile->fCnaResultsTree->Fill();
3571         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3572           std::cout << " => WRITTEN ON FILE ";
3573           v_tot_writ += v_size;
3574         }
3575       }
3576     }
3577     if (fFlagPrint == fCodePrintAllComments) {
3578       std::cout << std::endl;
3579     }
3580 
3581     //-------------------------- Average Total noise
3582     // StexEcha   fMatHis(1, StexStin)     ( 3)  cTypAvTno      1*(1,  68) =     68
3583 
3584     MaxCar = fgMaxCar;
3585     typ_name.Resize(MaxCar);
3586     typ_name = "AvTno";
3587     v_nb_times = fFileHeader->fAvTnoCalc;
3588     v_dim_one = 1;
3589     v_dim_two = fEcal->MaxStinEcnaInStex();
3590     v_size = v_nb_times * v_dim_one * v_dim_two;
3591     v_tot += v_size;
3592 
3593     if (fFlagPrint == fCodePrintAllComments) {
3594       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3595                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3596                 << v_size;
3597     }
3598 
3599     for (Int_t i = 0; i < v_nb_times; i++) {
3600       if (fTagAvTno[0] == 1) {
3601         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvTno;
3602         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3603         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3604         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3605         TRootAvTno();
3606         gCnaRootFile->fCnaResultsTree->Fill();
3607         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3608           std::cout << " => WRITTEN ON FILE ";
3609           v_tot_writ += v_size;
3610         }
3611       }
3612     }
3613     if (fFlagPrint == fCodePrintAllComments) {
3614       std::cout << std::endl;
3615     }
3616 
3617     //-------------------------- Average Low frequency noise
3618     //       1   fMatHis(1, StexStin)   ( 4)  cTypAvLfn      1*(1,  68) =     68
3619 
3620     MaxCar = fgMaxCar;
3621     typ_name.Resize(MaxCar);
3622     typ_name = "AvLfn";
3623     v_nb_times = fFileHeader->fAvLfnCalc;
3624     v_dim_one = 1;
3625     v_dim_two = fEcal->MaxStinEcnaInStex();
3626     v_size = v_nb_times * v_dim_one * v_dim_two;
3627     v_tot += v_size;
3628 
3629     if (fFlagPrint == fCodePrintAllComments) {
3630       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3631                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3632                 << v_size;
3633     }
3634 
3635     for (Int_t i = 0; i < v_nb_times; i++) {
3636       if (fTagAvLfn[0] == 1) {
3637         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvLfn;
3638         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3639         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3640         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3641         TRootAvLfn();
3642         gCnaRootFile->fCnaResultsTree->Fill();
3643         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3644           std::cout << " => WRITTEN ON FILE ";
3645           v_tot_writ += v_size;
3646         }
3647       }
3648     }
3649     if (fFlagPrint == fCodePrintAllComments) {
3650       std::cout << std::endl;
3651     }
3652 
3653     //-------------------------- Average High frequency noise
3654     //       1   fMatHis(1, StexStin)   ( 5)  cTypAvHfn      1*(1,  68) =     68
3655 
3656     MaxCar = fgMaxCar;
3657     typ_name.Resize(MaxCar);
3658     typ_name = "AvHfn";
3659     v_nb_times = fFileHeader->fAvHfnCalc;
3660     v_dim_one = 1;
3661     v_dim_two = fEcal->MaxStinEcnaInStex();
3662     v_size = v_nb_times * v_dim_one * v_dim_two;
3663     v_tot += v_size;
3664 
3665     if (fFlagPrint == fCodePrintAllComments) {
3666       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3667                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3668                 << v_size;
3669     }
3670 
3671     for (Int_t i = 0; i < v_nb_times; i++) {
3672       if (fTagAvHfn[0] == 1) {
3673         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvHfn;
3674         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3675         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3676         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3677         TRootAvHfn();
3678         gCnaRootFile->fCnaResultsTree->Fill();
3679         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3680           std::cout << " => WRITTEN ON FILE ";
3681           v_tot_writ += v_size;
3682         }
3683       }
3684     }
3685     if (fFlagPrint == fCodePrintAllComments) {
3686       std::cout << std::endl;
3687     }
3688 
3689     //-------------------------- Average mean cor(s,s)
3690     //       1   fMatHis(1, StexStin)   (13)  cTypAvMeanCorss      1*(1,  68) =     68
3691 
3692     MaxCar = fgMaxCar;
3693     typ_name.Resize(MaxCar);
3694     typ_name = "AvMeanCorss";
3695     v_nb_times = fFileHeader->fAvMeanCorssCalc;
3696     v_dim_one = 1;
3697     v_dim_two = fEcal->MaxStinEcnaInStex();
3698     v_size = v_nb_times * v_dim_one * v_dim_two;
3699     v_tot += v_size;
3700 
3701     if (fFlagPrint == fCodePrintAllComments) {
3702       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3703                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3704                 << v_size;
3705     }
3706 
3707     for (Int_t i = 0; i < v_nb_times; i++) {
3708       if (fTagAvMeanCorss[0] == 1) {
3709         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvMeanCorss;
3710         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3711         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3712         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3713         TRootAvEvCorss();
3714         gCnaRootFile->fCnaResultsTree->Fill();
3715         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3716           std::cout << " => WRITTEN ON FILE ";
3717           v_tot_writ += v_size;
3718         }
3719       }
3720     }
3721     if (fFlagPrint == fCodePrintAllComments) {
3722       std::cout << std::endl;
3723     }
3724 
3725     //--------------------------  Average sigma of cor(s,s)
3726     //       1   fMatHis(1, StexStin)    (14)  cTypAvSigCorss      1*(1,  68) =     68
3727 
3728     MaxCar = fgMaxCar;
3729     typ_name.Resize(MaxCar);
3730     typ_name = "AvSigCorss";
3731     v_nb_times = fFileHeader->fAvSigCorssCalc;
3732     v_dim_one = 1;
3733     v_dim_two = fEcal->MaxStinEcnaInStex();
3734     v_size = v_nb_times * v_dim_one * v_dim_two;
3735     v_tot += v_size;
3736 
3737     if (fFlagPrint == fCodePrintAllComments) {
3738       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3739                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3740                 << v_size;
3741     }
3742 
3743     for (Int_t i = 0; i < v_nb_times; i++) {
3744       if (fTagAvSigCorss[0] == 1) {
3745         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvSigCorss;
3746         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3747         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3748         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3749         TRootAvSigCorss();
3750         gCnaRootFile->fCnaResultsTree->Fill();
3751         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3752           std::cout << " => WRITTEN ON FILE ";
3753           v_tot_writ += v_size;
3754         }
3755       }
3756     }
3757     if (fFlagPrint == fCodePrintAllComments) {
3758       std::cout << std::endl;
3759     }
3760 
3761     //-------------------------- Expectation values of the expectation values of the samples (pedestals)
3762     //       1   fMatHis(1,StexEcha)         (16)  cTypPed                1*(   1,1700) =      1 700
3763 
3764     MaxCar = fgMaxCar;
3765     typ_name.Resize(MaxCar);
3766     typ_name = "Ped";
3767     v_nb_times = fFileHeader->fPedCalc;
3768     v_dim_one = 1;
3769     v_dim_two = fEcal->MaxCrysEcnaInStex();
3770     v_size = v_nb_times * v_dim_one * v_dim_two;
3771     v_tot += v_size;
3772 
3773     if (fFlagPrint == fCodePrintAllComments) {
3774       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3775                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3776                 << v_size;
3777     }
3778 
3779     for (Int_t i = 0; i < v_nb_times; i++) {
3780       if (fTagPed[0] == 1) {
3781         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypPed;
3782         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3783         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3784         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3785         TRootPed();
3786         gCnaRootFile->fCnaResultsTree->Fill();
3787         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3788           std::cout << " => WRITTEN ON FILE ";
3789           v_tot_writ += v_size;
3790         }
3791       }
3792     }
3793     if (fFlagPrint == fCodePrintAllComments) {
3794       std::cout << std::endl;
3795     }
3796 
3797     //-------------------------- Expectation values of the sigmas the samples
3798     //       1   fMatHis(1,StexEcha)         (17)  cTypTno               1*(   1,1700) =      1 700
3799 
3800     MaxCar = fgMaxCar;
3801     typ_name.Resize(MaxCar);
3802     typ_name = "Tno";
3803     v_nb_times = fFileHeader->fTnoCalc;
3804     v_dim_one = 1;
3805     v_dim_two = fEcal->MaxCrysEcnaInStex();
3806     v_size = v_nb_times * v_dim_one * v_dim_two;
3807     v_tot += v_size;
3808 
3809     if (fFlagPrint == fCodePrintAllComments) {
3810       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3811                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3812                 << v_size;
3813     }
3814 
3815     for (Int_t i = 0; i < v_nb_times; i++) {
3816       if (fTagTno[0] == 1) {
3817         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypTno;
3818         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3819         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3820         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3821         TRootTno();
3822         gCnaRootFile->fCnaResultsTree->Fill();
3823         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3824           std::cout << " => WRITTEN ON FILE ";
3825           v_tot_writ += v_size;
3826         }
3827       }
3828     }
3829     if (fFlagPrint == fCodePrintAllComments) {
3830       std::cout << std::endl;
3831     }
3832 
3833     //-------------------------- Expectation values of the correlations between the samples
3834     //       1   fMatHis(1,StexEcha)         (10)  cTypMeanCorss            1*(   1,1700) =      1 700
3835 
3836     MaxCar = fgMaxCar;
3837     typ_name.Resize(MaxCar);
3838     typ_name = "MeanCorss";
3839     v_nb_times = fFileHeader->fMeanCorssCalc;
3840     v_dim_one = 1;
3841     v_dim_two = fEcal->MaxCrysEcnaInStex();
3842     v_size = v_nb_times * v_dim_one * v_dim_two;
3843     v_tot += v_size;
3844 
3845     if (fFlagPrint == fCodePrintAllComments) {
3846       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3847                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3848                 << v_size;
3849     }
3850 
3851     for (Int_t i = 0; i < v_nb_times; i++) {
3852       if (fTagMeanCorss[0] == 1) {
3853         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypMeanCorss;
3854         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3855         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3856         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3857         TRootMeanCorss();
3858         gCnaRootFile->fCnaResultsTree->Fill();
3859         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3860           std::cout << " => WRITTEN ON FILE ";
3861           v_tot_writ += v_size;
3862         }
3863       }
3864     }
3865     if (fFlagPrint == fCodePrintAllComments) {
3866       std::cout << std::endl;
3867     }
3868 
3869     //-------------------------- Sigmas of the expectation values of the samples
3870     //       1   fMatHis(1,StexEcha)         (18)  cTypLfn               1*(   1,1700) =      1 700
3871 
3872     MaxCar = fgMaxCar;
3873     typ_name.Resize(MaxCar);
3874     typ_name = "Lfn";
3875     v_nb_times = fFileHeader->fLfnCalc;
3876     v_dim_one = 1;
3877     v_dim_two = fEcal->MaxCrysEcnaInStex();
3878     v_size = v_nb_times * v_dim_one * v_dim_two;
3879     v_tot += v_size;
3880 
3881     if (fFlagPrint == fCodePrintAllComments) {
3882       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3883                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3884                 << v_size;
3885     }
3886 
3887     for (Int_t i = 0; i < v_nb_times; i++) {
3888       if (fTagLfn[0] == 1) {
3889         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLfn;
3890         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3891         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3892         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3893         TRootLfn();
3894         gCnaRootFile->fCnaResultsTree->Fill();
3895         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3896           std::cout << " => WRITTEN ON FILE ";
3897           v_tot_writ += v_size;
3898         }
3899       }
3900     }
3901     if (fFlagPrint == fCodePrintAllComments) {
3902       std::cout << std::endl;
3903     }
3904 
3905     //-------------------------- Sigmas of the sigmas of the samples
3906     //       1   fMatHis(1,StexEcha)         (19)  cTypHfn              1*(   1,1700) =      1 700
3907 
3908     MaxCar = fgMaxCar;
3909     typ_name.Resize(MaxCar);
3910     typ_name = "Hfn";
3911     v_nb_times = fFileHeader->fHfnCalc;
3912     v_dim_one = 1;
3913     v_dim_two = fEcal->MaxCrysEcnaInStex();
3914     v_size = v_nb_times * v_dim_one * v_dim_two;
3915     v_tot += v_size;
3916 
3917     if (fFlagPrint == fCodePrintAllComments) {
3918       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3919                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3920                 << v_size;
3921     }
3922 
3923     for (Int_t i = 0; i < v_nb_times; i++) {
3924       if (fTagHfn[0] == 1) {
3925         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHfn;
3926         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3927         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3928         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3929         TRootHfn();
3930         gCnaRootFile->fCnaResultsTree->Fill();
3931         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3932           std::cout << " => WRITTEN ON FILE ";
3933           v_tot_writ += v_size;
3934         }
3935       }
3936     }
3937     if (fFlagPrint == fCodePrintAllComments) {
3938       std::cout << std::endl;
3939     }
3940 
3941     //-------------------------- Sigmas of the correlations between the samples
3942     //       1   fMatHis(1,StexEcha)         (11)  cTypSigCorss           1*(   1,1700) =      1 700
3943 
3944     MaxCar = fgMaxCar;
3945     typ_name.Resize(MaxCar);
3946     typ_name = "SigCorss";
3947     v_nb_times = fFileHeader->fSigCorssCalc;
3948     v_dim_one = 1;
3949     v_dim_two = fEcal->MaxCrysEcnaInStex();
3950     v_size = v_nb_times * v_dim_one * v_dim_two;
3951     v_tot += v_size;
3952 
3953     if (fFlagPrint == fCodePrintAllComments) {
3954       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3955                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3956                 << v_size;
3957     }
3958 
3959     for (Int_t i = 0; i < v_nb_times; i++) {
3960       if (fTagSigCorss[0] == 1) {
3961         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSigCorss;
3962         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3963         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
3964         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
3965         TRootSigCorss();
3966         gCnaRootFile->fCnaResultsTree->Fill();
3967         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
3968           std::cout << " => WRITTEN ON FILE ";
3969           v_tot_writ += v_size;
3970         }
3971       }
3972     }
3973     if (fFlagPrint == fCodePrintAllComments) {
3974       std::cout << std::endl;
3975     }
3976 
3977     //----- Mean Covariances between StexEchas (averaged over samples) for all (Stin_X,Stin_Y)
3978     //       1   fMatMat(Stin,Stin)       (23)  cTypLFccMoStins         1*(  68,  68) =      4 624
3979 
3980     MaxCar = fgMaxCar;
3981     typ_name.Resize(MaxCar);
3982     typ_name = "LFccMoStins";
3983     v_nb_times = fFileHeader->fLFccMoStinsCalc;
3984     v_dim_one = fEcal->MaxStinEcnaInStex();
3985     v_dim_two = fEcal->MaxStinEcnaInStex();
3986     v_size = v_nb_times * v_dim_one * v_dim_two;
3987     v_tot += v_size;
3988 
3989     if (fFlagPrint == fCodePrintAllComments) {
3990       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
3991                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
3992                 << v_size;
3993     }
3994 
3995     for (Int_t i = 0; i < v_nb_times; i++) {
3996       if (fTagLFccMoStins[0] == 1) {
3997         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLFccMoStins;
3998         gCnaRootFile->fCnaIndivResult->fIthElement = i;
3999         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4000         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4001         TRootLFccMoStins();
4002         gCnaRootFile->fCnaResultsTree->Fill();
4003         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4004           std::cout << " => WRITTEN ON FILE ";
4005           v_tot_writ += v_size;
4006         }
4007       }
4008     }
4009     if (fFlagPrint == fCodePrintAllComments) {
4010       std::cout << std::endl;
4011     }
4012 
4013     //----- Mean Correlations between StexEchas (averaged over samples) for all (Stin_X,Stin_Y)
4014     //       1   fMatMat(Stin,Stin)       (24)  cTypHFccMoStins         1*(  68,  68) =      4 624
4015 
4016     MaxCar = fgMaxCar;
4017     typ_name.Resize(MaxCar);
4018     typ_name = "HFccMoStins";
4019     v_nb_times = fFileHeader->fHFccMoStinsCalc;
4020     v_dim_one = fEcal->MaxStinEcnaInStex();
4021     v_dim_two = fEcal->MaxStinEcnaInStex();
4022     v_size = v_nb_times * v_dim_one * v_dim_two;
4023     v_tot += v_size;
4024 
4025     if (fFlagPrint == fCodePrintAllComments) {
4026       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4027                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4028                 << v_size;
4029     }
4030 
4031     for (Int_t i = 0; i < v_nb_times; i++) {
4032       if (fTagHFccMoStins[0] == 1) {
4033         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHFccMoStins;
4034         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4035         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4036         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4037         TRootHFccMoStins();
4038         gCnaRootFile->fCnaResultsTree->Fill();
4039         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4040           std::cout << " => WRITTEN ON FILE ";
4041           v_tot_writ += v_size;
4042         }
4043       }
4044     }
4045     if (fFlagPrint == fCodePrintAllComments) {
4046       std::cout << std::endl;
4047     }
4048 
4049     //-------------------------- Numbers of found events (NbOfEvts)
4050     //       1   fMatHis(StexEcha, sample)   (15)  cTypNbOfEvts       1*(1700,  10) =     17 000
4051 
4052     MaxCar = fgMaxCar;
4053     typ_name.Resize(MaxCar);
4054     typ_name = "NbOfEvts";
4055     v_nb_times = fFileHeader->fNbOfEvtsCalc;
4056     v_dim_one = fEcal->MaxCrysEcnaInStex();
4057     v_dim_two = argNbSampWrite;
4058     v_size = v_nb_times * v_dim_one * v_dim_two;
4059     v_tot += v_size;
4060 
4061     if (fFlagPrint == fCodePrintAllComments) {
4062       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4063                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4064                 << v_size;
4065     }
4066 
4067     for (Int_t i = 0; i < v_nb_times; i++) {
4068       if (fTagNbOfEvts[0] == 1) {
4069         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypNbOfEvts;
4070         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4071         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
4072         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
4073         TRootNbOfEvts(argNbSampWrite);
4074         gCnaRootFile->fCnaResultsTree->Fill();
4075         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4076           std::cout << " => WRITTEN ON FILE ";
4077           v_tot_writ += v_size;
4078         }
4079       }
4080     }
4081     if (fFlagPrint == fCodePrintAllComments) {
4082       std::cout << std::endl;
4083     }
4084 
4085     //-------------------------- Expectation values of the samples
4086     //       1   fMatHis(StexEcha, sample)   ( 1)  cTypMSp                  1*(1700,  10) =     17 000
4087 
4088     MaxCar = fgMaxCar;
4089     typ_name.Resize(MaxCar);
4090     typ_name = "MSp";
4091     v_nb_times = fFileHeader->fMSpCalc;
4092     v_dim_one = fEcal->MaxCrysEcnaInStex();
4093     v_dim_two = argNbSampWrite;
4094     v_size = v_nb_times * v_dim_one * v_dim_two;
4095     v_tot += v_size;
4096 
4097     if (fFlagPrint == fCodePrintAllComments) {
4098       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4099                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4100                 << v_size;
4101     }
4102 
4103     for (Int_t i = 0; i < v_nb_times; i++) {
4104       if (fTagMSp[0] == 1) {
4105         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypMSp;
4106         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4107         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
4108         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
4109         TRootMSp(argNbSampWrite);
4110         gCnaRootFile->fCnaResultsTree->Fill();
4111         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4112           std::cout << " => WRITTEN ON FILE ";
4113           v_tot_writ += v_size;
4114         }
4115       }
4116     }
4117     if (fFlagPrint == fCodePrintAllComments) {
4118       std::cout << std::endl;
4119     }
4120 
4121     //-------------------------- Sigmas of the samples
4122     //       1   fMatHis(StexEcha, sample)   ( 2)  cTypSSp                 1*(1700,  10) =     17 000
4123 
4124     MaxCar = fgMaxCar;
4125     typ_name.Resize(MaxCar);
4126     typ_name = "SSp";
4127     v_nb_times = fFileHeader->fSSpCalc;
4128     v_dim_one = fEcal->MaxCrysEcnaInStex();
4129     v_dim_two = argNbSampWrite;
4130     v_size = v_nb_times * v_dim_one * v_dim_two;
4131     v_tot += v_size;
4132 
4133     if (fFlagPrint == fCodePrintAllComments) {
4134       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4135                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4136                 << v_size;
4137     }
4138 
4139     for (Int_t i = 0; i < v_nb_times; i++) {
4140       if (fTagSSp[0] == 1) {
4141         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSSp;
4142         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4143         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
4144         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
4145         TRootSSp(argNbSampWrite);
4146         gCnaRootFile->fCnaResultsTree->Fill();
4147         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4148           std::cout << " => WRITTEN ON FILE ";
4149           v_tot_writ += v_size;
4150         }
4151       }
4152     }
4153     if (fFlagPrint == fCodePrintAllComments) {
4154       std::cout << std::endl;
4155     }
4156 
4157     //-------------------------- Covariances between samples
4158 
4159     // StexEcha   fMatMat(sample,  sample)   ( 8)  cTypCovCss           1700*(  10,  10) =    170 000
4160 
4161     MaxCar = fgMaxCar;
4162     typ_name.Resize(MaxCar);
4163     typ_name = "CovCss";
4164     v_nb_times = fFileHeader->fCovCssCalc;
4165     v_dim_one = argNbSampWrite;
4166     v_dim_two = argNbSampWrite;
4167     v_size = v_nb_times * v_dim_one * v_dim_two;
4168     v_tot += v_size;
4169 
4170     if (fFlagPrint == fCodePrintAllComments) {
4171       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4172                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4173                 << v_size;
4174     }
4175 
4176     for (Int_t i0StexEcha = 0; i0StexEcha < v_nb_times; i0StexEcha++) {
4177       if (fTagCovCss[i0StexEcha] == 1) {
4178         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCovCss;
4179         gCnaRootFile->fCnaIndivResult->fIthElement = i0StexEcha;
4180         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4181         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4182         TRootCovCss(i0StexEcha, argNbSampWrite);
4183         gCnaRootFile->fCnaResultsTree->Fill();
4184         if (i0StexEcha == 0 && fFlagPrint == fCodePrintAllComments) {
4185           std::cout << " => WRITTEN ON FILE ";
4186           v_tot_writ += v_size;
4187         }
4188       }
4189     }
4190     if (fFlagPrint == fCodePrintAllComments) {
4191       std::cout << std::endl;
4192     }
4193 
4194     //-------------------------- Correlations between samples
4195     // StexEcha   fMatMat(sample,  sample)   ( 9)  cTypCorCss           1700*(  10,  10) =    170 000
4196 
4197     MaxCar = fgMaxCar;
4198     typ_name.Resize(MaxCar);
4199     typ_name = "CorCss";
4200     v_nb_times = fFileHeader->fCorCssCalc;
4201     v_dim_one = argNbSampWrite;
4202     v_dim_two = argNbSampWrite;
4203     v_size = v_nb_times * v_dim_one * v_dim_two;
4204     v_tot += v_size;
4205 
4206     if (fFlagPrint == fCodePrintAllComments) {
4207       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4208                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4209                 << v_size;
4210     }
4211 
4212     for (Int_t i0StexEcha = 0; i0StexEcha < v_nb_times; i0StexEcha++) {
4213       if (fTagCorCss[i0StexEcha] == 1) {
4214         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCorCss;
4215         gCnaRootFile->fCnaIndivResult->fIthElement = i0StexEcha;
4216         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4217         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4218         TRootCorCss(i0StexEcha, argNbSampWrite);
4219         gCnaRootFile->fCnaResultsTree->Fill();
4220         if (i0StexEcha == 0 && fFlagPrint == fCodePrintAllComments) {
4221           std::cout << " => WRITTEN ON FILE ";
4222           v_tot_writ += v_size;
4223         }
4224       }
4225     }
4226     if (fFlagPrint == fCodePrintAllComments) {
4227       std::cout << std::endl;
4228     }
4229 
4230     //-------------------------- Samples as a function of event = events distributions
4231     // StexEcha   fMatHis(sample,  bins)     (20)  cTypAdcEvt,        1700*(  10, 150) =  2 550 000
4232 
4233     MaxCar = fgMaxCar;
4234     typ_name.Resize(MaxCar);
4235     typ_name = "AdcEvt";
4236     v_nb_times = fFileHeader->fAdcEvtCalc;
4237     v_dim_one = argNbSampWrite;
4238     v_dim_two = fFileHeader->fReqNbOfEvts;
4239     v_size = v_nb_times * v_dim_one * v_dim_two;
4240     v_tot += v_size;
4241 
4242     if (fFlagPrint == fCodePrintAllComments) {
4243       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4244                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4245                 << v_size;
4246     }
4247 
4248     for (Int_t i0StexEcha = 0; i0StexEcha < v_nb_times; i0StexEcha++) {
4249       if (fTagAdcEvt[i0StexEcha] == 1) {
4250         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAdcEvt;
4251         gCnaRootFile->fCnaIndivResult->fIthElement = i0StexEcha;
4252         gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one, v_dim_two);
4253         gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1, 1);
4254         TRootAdcEvt(i0StexEcha, argNbSampWrite);
4255         gCnaRootFile->fCnaResultsTree->Fill();
4256         if (i0StexEcha == 0 && fFlagPrint == fCodePrintAllComments) {
4257           std::cout << " => WRITTEN ON FILE ";
4258           v_tot_writ += v_size;
4259         }
4260       }
4261     }
4262     if (fFlagPrint == fCodePrintAllComments) {
4263       std::cout << std::endl;
4264     }
4265 
4266     //-------------------------- Low Frequency Covariances between StexEchas
4267     //  sample   fMatMat(StexEcha, StexEcha)  (21)  cTypLfCov           1*(1700,1700) =  2 890 000
4268 
4269     MaxCar = fgMaxCar;
4270     typ_name.Resize(MaxCar);
4271     typ_name = "LfCov";
4272     v_nb_times = fFileHeader->fLfCovCalc;
4273     v_dim_one = fEcal->MaxCrysEcnaInStex();
4274     v_dim_two = fEcal->MaxCrysEcnaInStex();
4275     v_size = v_nb_times * v_dim_one * v_dim_two;
4276     v_tot += v_size;
4277 
4278     if (fFlagPrint == fCodePrintAllComments) {
4279       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4280                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4281                 << v_size;
4282     }
4283 
4284     for (Int_t i = 0; i < v_nb_times; i++) {  //=================================== Record type EB
4285       if (fTagLfCov[0] == 1) {
4286         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLfCov;
4287         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4288         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4289         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4290         TRootLfCov();
4291         gCnaRootFile->fCnaResultsTree->Fill();
4292         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4293           std::cout << " => WRITTEN ON FILE ";
4294           v_tot_writ += v_size;
4295         }
4296       }
4297     }
4298     if (fFlagPrint == fCodePrintAllComments) {
4299       std::cout << std::endl;
4300     }
4301 
4302     //-------------------------- Low Frequency Correlations between StexEchas
4303     //  sample   fMatMat(StexEcha, StexEcha)  (22)  cTypLfCor           1*(1700,1700) =  2 890 000
4304 
4305     MaxCar = fgMaxCar;
4306     typ_name.Resize(MaxCar);
4307     typ_name = "LfCor";
4308     v_nb_times = fFileHeader->fLfCorCalc;
4309     v_dim_one = fEcal->MaxCrysEcnaInStex();
4310     v_dim_two = fEcal->MaxCrysEcnaInStex();
4311     v_size = v_nb_times * v_dim_one * v_dim_two;
4312     v_tot += v_size;
4313 
4314     if (fFlagPrint == fCodePrintAllComments) {
4315       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4316                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4317                 << v_size;
4318     }
4319 
4320     for (Int_t i = 0; i < v_nb_times; i++) {
4321       if (fTagLfCor[0] == 1) {
4322         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLfCor;
4323         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4324         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4325         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4326         TRootLfCor();
4327         gCnaRootFile->fCnaResultsTree->Fill();
4328         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4329           std::cout << " => WRITTEN ON FILE ";
4330           v_tot_writ += v_size;
4331         }
4332       }
4333     }
4334     if (fFlagPrint == fCodePrintAllComments) {
4335       std::cout << std::endl;
4336     }
4337 
4338     //-------------------------- High Frequency Covariances between StexEchas
4339     //  sample   fMatMat(StexEcha, StexEcha)  (6)  cTypHfCov           1*(1700,1700) =  2 890 000
4340 
4341     MaxCar = fgMaxCar;
4342     typ_name.Resize(MaxCar);
4343     typ_name = "HfCov";
4344     v_nb_times = fFileHeader->fHfCovCalc;
4345     v_dim_one = fEcal->MaxCrysEcnaInStex();
4346     v_dim_two = fEcal->MaxCrysEcnaInStex();
4347     v_size = v_nb_times * v_dim_one * v_dim_two;
4348     v_tot += v_size;
4349 
4350     if (fFlagPrint == fCodePrintAllComments) {
4351       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4352                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4353                 << v_size;
4354     }
4355 
4356     for (Int_t i = 0; i < v_nb_times; i++) {
4357       if (fTagHfCov[0] == 1) {
4358         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHfCov;
4359         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4360         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4361         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4362         TRootHfCov();
4363         gCnaRootFile->fCnaResultsTree->Fill();
4364         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4365           std::cout << " => WRITTEN ON FILE ";
4366           v_tot_writ += v_size;
4367         }
4368       }
4369     }
4370     if (fFlagPrint == fCodePrintAllComments) {
4371       std::cout << std::endl;
4372     }
4373 
4374     //-------------------------- High Frequency Correlations between StexEchas
4375     //  sample   fMatMat(StexEcha, StexEcha)  (7)  cTypHfCor           1*(1700,1700) =  2 890 000
4376 
4377     MaxCar = fgMaxCar;
4378     typ_name.Resize(MaxCar);
4379     typ_name = "HfCor";
4380     v_nb_times = fFileHeader->fHfCorCalc;
4381     v_dim_one = fEcal->MaxCrysEcnaInStex();
4382     v_dim_two = fEcal->MaxCrysEcnaInStex();
4383     v_size = v_nb_times * v_dim_one * v_dim_two;
4384     v_tot += v_size;
4385 
4386     if (fFlagPrint == fCodePrintAllComments) {
4387       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(18) << typ_name << ": " << std::setw(4) << v_nb_times
4388                 << " * (" << std::setw(4) << v_dim_one << "," << std::setw(4) << v_dim_two << ") = " << std::setw(9)
4389                 << v_size;
4390     }
4391 
4392     for (Int_t i = 0; i < v_nb_times; i++) {
4393       if (fTagHfCor[0] == 1) {
4394         gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHfCor;
4395         gCnaRootFile->fCnaIndivResult->fIthElement = i;
4396         gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one, v_dim_two);
4397         gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1, 1);
4398         TRootHfCor();
4399         gCnaRootFile->fCnaResultsTree->Fill();
4400         if (i == 0 && fFlagPrint == fCodePrintAllComments) {
4401           std::cout << " => WRITTEN ON FILE ";
4402           v_tot_writ += v_size;
4403         }
4404       }
4405     }
4406     if (fFlagPrint == fCodePrintAllComments) {
4407       std::cout << std::endl;
4408     }
4409 
4410     //---------------------------------------------- WRITING
4411     //...................................... file
4412     gCnaRootFile->fRootFile->Write();
4413     //...................................... header
4414     fFileHeader->Write();
4415 
4416     //...................................... status message
4417     if (fFlagPrint == fCodePrintAllComments) {
4418       std::cout << "*TEcnaRun::WriteRootFile(...)> " << std::setw(20) << "TOTAL: " << std::setw(21)
4419                 << "CALCULATED = " << std::setw(9) << v_tot << " => WRITTEN ON FILE = " << std::setw(9) << v_tot_writ
4420                 << std::endl;
4421     }
4422 
4423     if (fFlagPrint == fCodePrintAllComments) {
4424       std::cout << "*TEcnaRun::WriteRootFile(...)> Write OK in file " << file_name << " in directory:" << std::endl
4425                 << "                           " << fCnaParPaths->ResultsRootFilePath().Data() << std::endl;
4426     }
4427 
4428     ok_write = kTRUE;
4429 
4430     //...................................... close
4431     CloseRootFile(file_name);
4432   }
4433   return ok_write;
4434 }  //-------------- End of WriteRootFile(...) -----------------------
4435 
4436 //======================== "PREPA FILL" METHODS ===========================
4437 
4438 //-------------------------------------------------------------------------
4439 //
4440 //  Prepa Fill Stin numbers as a function of the Stin index
4441 //                       (for writing in the ROOT file)
4442 //
4443 //-------------------------------------------------------------------------
4444 void TEcnaRun::TRootStinNumbers() {
4445   if (fTagStinNumbers[0] == 1) {
4446     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4447       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) = fT1d_StexStinFromIndex[j0StexStinEcna];
4448     }
4449   }
4450 }
4451 
4452 //-------------------------------------------------------------------------
4453 //
4454 //  Prepa Fill last evt numbers for all the (StexEcha,sample)
4455 //                       (for writing in the ROOT file)
4456 //
4457 //-------------------------------------------------------------------------
4458 void TEcnaRun::TRootNbOfEvts(const Int_t& argNbSampWrite) {
4459   if (fTagNbOfEvts[0] == 1) {
4460     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4461       for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++) {
4462         gCnaRootFile->fCnaIndivResult->fMatHis(j0StexEcha, i0Sample) = fT2d_NbOfEvts[j0StexEcha][i0Sample];
4463       }
4464     }
4465   }
4466 }
4467 
4468 //-------------------------------------------------------------------------
4469 //
4470 //  Prepa Fill histogram of samples as a function of event
4471 //                       (for writing in the ROOT file)
4472 //
4473 //-------------------------------------------------------------------------
4474 void TEcnaRun::TRootAdcEvt(const Int_t& user_StexEcha, const Int_t& argNbSampWrite) {
4475   if (fTagAdcEvt[user_StexEcha] == 1) {
4476     for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++) {
4477       //...................... all the bins set to zero
4478       for (Int_t j_bin = 0; j_bin < fFileHeader->fReqNbOfEvts; j_bin++) {
4479         gCnaRootFile->fCnaIndivResult->fMatHis(i0Sample, j_bin) = (Double_t)0.;
4480       }
4481       //...................... fill the non-zero bins
4482       for (Int_t j_bin = 0; j_bin < fFileHeader->fReqNbOfEvts; j_bin++) {
4483         gCnaRootFile->fCnaIndivResult->fMatHis(i0Sample, j_bin) = fT3d_AdcValues[user_StexEcha][i0Sample][j_bin];
4484       }
4485     }
4486   }
4487 }
4488 
4489 //-------------------------------------------------------------------------
4490 //
4491 //  Prepa Fill expectation values of the samples for all the StexEchas
4492 //                       (for writing in the ROOT file)
4493 //
4494 //-------------------------------------------------------------------------
4495 void TEcnaRun::TRootMSp(const Int_t& argNbSampWrite) {
4496   if (fTagMSp[0] == 1) {
4497     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4498       for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++) {
4499         gCnaRootFile->fCnaIndivResult->fMatHis(j0StexEcha, i0Sample) = fT2d_ev[j0StexEcha][i0Sample];
4500       }
4501     }
4502   }
4503 }
4504 
4505 //-------------------------------------------------------------------------
4506 //
4507 //  Prepa Fill sigmas of the samples for all the StexEchas
4508 //                       (for writing in the ROOT file)
4509 //
4510 //-------------------------------------------------------------------------
4511 void TEcnaRun::TRootSSp(const Int_t& argNbSampWrite) {
4512   if (fTagSSp[0] == 1) {
4513     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4514       for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++) {
4515         gCnaRootFile->fCnaIndivResult->fMatHis(j0StexEcha, i0Sample) = fT2d_sig[j0StexEcha][i0Sample];
4516       }
4517     }
4518   }
4519 }
4520 
4521 //-------------------------------------------------------------------------
4522 //
4523 //  Prepa Fill mean covariances between StexEchas, mean over samples
4524 //  for all (Stin_X, Stin_Y)
4525 //                           (for writing in ROOT file)
4526 //
4527 //-------------------------------------------------------------------------
4528 void TEcnaRun::TRootLFccMoStins() {
4529   if (fTagLFccMoStins[0] == 1) {
4530     for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
4531       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4532         gCnaRootFile->fCnaIndivResult->fMatMat(i0StexStinEcna, j0StexStinEcna) =
4533             fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna];
4534       }
4535     }
4536   }
4537 }
4538 
4539 //-------------------------------------------------------------------------
4540 //
4541 //  Prepa Fill mean correlations between StexEchas, mean over samples
4542 //  for all (Stin_X, Stin_Y)
4543 //                           (for writing in ROOT file)
4544 //
4545 //-------------------------------------------------------------------------
4546 void TEcnaRun::TRootHFccMoStins() {
4547   if (fTagHFccMoStins[0] == 1) {
4548     for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++) {
4549       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4550         gCnaRootFile->fCnaIndivResult->fMatMat(i0StexStinEcna, j0StexStinEcna) =
4551             fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna];
4552       }
4553     }
4554   }
4555 }
4556 
4557 //-------------------------------------------------------------------------
4558 //
4559 //  Prepa Fill ADC distributions of the samples for all the StexEchas
4560 //                       (for writing in the ROOT file)
4561 //
4562 //-------------------------------------------------------------------------
4563 void TEcnaRun::TRootAvTno() {
4564   if (fTagAvTno[0] == 1) {
4565     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4566       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) = fT1d_av_totn[j0StexStinEcna];
4567     }
4568   }
4569 }
4570 //-------------------------------------------------------------------------
4571 //
4572 //  Prepa Fill ADC distributions xmin of the samples for all the StexEchas
4573 //                       (for writing in the ROOT file)
4574 //
4575 //-------------------------------------------------------------------------
4576 void TEcnaRun::TRootAvLfn() {
4577   if (fTagAvLfn[0] == 1) {
4578     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4579       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) = fT1d_av_lofn[j0StexStinEcna];
4580     }
4581   }
4582 }
4583 
4584 //-------------------------------------------------------------------------
4585 //
4586 //  Prepa Fill ADC distributions xmax of the samples for all the StexEchas
4587 //                       (for writing in the ROOT file)
4588 //
4589 //-------------------------------------------------------------------------
4590 void TEcnaRun::TRootAvHfn() {
4591   if (fTagAvHfn[0] == 1) {
4592     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4593       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) = fT1d_av_hifn[j0StexStinEcna];
4594     }
4595   }
4596 }
4597 
4598 //-------------------------------------------------------------------------
4599 //
4600 //  Prepa Fill Low Frequency covariances between StexEchas
4601 //                           (for writing in ROOT file)
4602 //
4603 //-------------------------------------------------------------------------
4604 void TEcnaRun::TRootLfCov() {
4605   if (fTagLfCov[0] == 1) {
4606     for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
4607       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4608         gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) = fT2d_lf_cov[i0StexEcha][j0StexEcha];
4609       }
4610     }
4611   }
4612 }
4613 
4614 //-------------------------------------------------------------------------
4615 //
4616 //  Prepa Fill Low Frequency correlations between StexEchas
4617 //                         (for writing in ROOT file)
4618 //
4619 //-------------------------------------------------------------------------
4620 void TEcnaRun::TRootLfCor() {
4621   if (fTagLfCor[0] == 1) {
4622     for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
4623       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4624         gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) = fT2d_lf_cor[i0StexEcha][j0StexEcha];
4625       }
4626     }
4627   }
4628 }
4629 
4630 //-------------------------------------------------------------------------
4631 //
4632 //  Prepa Fill High Frequency covariances between StexEchas
4633 //                           (for writing in ROOT file)
4634 //
4635 //-------------------------------------------------------------------------
4636 void TEcnaRun::TRootHfCov() {
4637   if (fTagHfCov[0] == 1) {
4638     for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
4639       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4640         gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) = fT2d_hf_cov[i0StexEcha][j0StexEcha];
4641       }
4642     }
4643   }
4644 }
4645 
4646 //-------------------------------------------------------------------------
4647 //
4648 //  Prepa Fill High Frequency correlations between StexEchas
4649 //                         (for writing in ROOT file)
4650 //
4651 //-------------------------------------------------------------------------
4652 void TEcnaRun::TRootHfCor() {
4653   if (fTagHfCor[0] == 1) {
4654     for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++) {
4655       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4656         gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) = fT2d_hf_cor[i0StexEcha][j0StexEcha];
4657       }
4658     }
4659   }
4660 }
4661 
4662 //-------------------------------------------------------------------------
4663 //
4664 //  Prepa Fill covariances between samples for a given StexEcha
4665 //                      (for writing in ROOT file)
4666 //
4667 //-------------------------------------------------------------------------
4668 void TEcnaRun::TRootCovCss(const Int_t& user_StexEcha, const Int_t& argNbSampWrite) {
4669   if (fTagCovCss[user_StexEcha] == 1) {
4670     for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++) {
4671       for (Int_t j0Sample = 0; j0Sample < argNbSampWrite; j0Sample++) {
4672         gCnaRootFile->fCnaIndivResult->fMatMat(i0Sample, j0Sample) = fT3d_cov_ss[user_StexEcha][i0Sample][j0Sample];
4673       }
4674     }
4675   }
4676 }
4677 
4678 //-------------------------------------------------------------------------
4679 //
4680 //  Prepa Fill correlations between samples for a given StexEcha
4681 //                        (for writing in ROOT file)
4682 //
4683 //-------------------------------------------------------------------------
4684 void TEcnaRun::TRootCorCss(const Int_t& user_StexEcha, const Int_t& argNbSampWrite) {
4685   if (fTagCorCss[user_StexEcha] == 1) {
4686     for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++) {
4687       for (Int_t j0Sample = 0; j0Sample < argNbSampWrite; j0Sample++) {
4688         gCnaRootFile->fCnaIndivResult->fMatMat(i0Sample, j0Sample) = fT3d_cor_ss[user_StexEcha][i0Sample][j0Sample];
4689       }
4690     }
4691   }
4692 }
4693 
4694 //-------------------------------------------------------------------------
4695 //
4696 //  Prepa Fill expectation values of the expectation values of the samples
4697 //  for all the StexEchas
4698 //                        (for writing in ROOT file)
4699 //
4700 //-------------------------------------------------------------------------
4701 void TEcnaRun::TRootPed() {
4702   if (fTagPed[0] == 1) {
4703     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4704       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) = fT1d_ev_ev[j0StexEcha];
4705     }
4706   }
4707 }
4708 //-------------------------------------------------------------------------
4709 //
4710 //  Prepa Fill expectation values of the sigmas of the samples
4711 //  for all the StexEchas
4712 //                        (for writing in ROOT file)
4713 //
4714 //-------------------------------------------------------------------------
4715 void TEcnaRun::TRootTno() {
4716   if (fTagTno[0] == 1) {
4717     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4718       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) = fT1d_evsamp_of_sigevt[j0StexEcha];
4719     }
4720   }
4721 }
4722 
4723 //-------------------------------------------------------------------------
4724 //
4725 //  Prepa Fill expectation values of the (sample,sample) correlations
4726 //  for all the StexEchas
4727 //                        (for writing in ROOT file)
4728 //
4729 //-------------------------------------------------------------------------
4730 void TEcnaRun::TRootMeanCorss() {
4731   if (fTagMeanCorss[0] == 1) {
4732     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4733       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) = fT1d_ev_cor_ss[j0StexEcha];
4734     }
4735   }
4736 }
4737 
4738 //-------------------------------------------------------------------------
4739 //
4740 //  Prepa Fill sigmas of the expectation values of the samples
4741 //  for all the StexEchas
4742 //                        (for writing in ROOT file)
4743 //
4744 //-------------------------------------------------------------------------
4745 void TEcnaRun::TRootLfn() {
4746   if (fTagLfn[0] == 1) {
4747     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4748       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) = fT1d_sigevt_of_evsamp[j0StexEcha];
4749     }
4750   }
4751 }
4752 
4753 //-------------------------------------------------------------------------
4754 //
4755 //  Prepa Fill sigmas of the expectation values of the sigmas
4756 //  for all the StexEchas
4757 //                        (for writing in ROOT file)
4758 //
4759 //-------------------------------------------------------------------------
4760 void TEcnaRun::TRootHfn() {
4761   if (fTagHfn[0] == 1) {
4762     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4763       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) = fT1d_evevt_of_sigsamp[j0StexEcha];
4764     }
4765   }
4766 }
4767 
4768 //-------------------------------------------------------------------------
4769 //
4770 //  Prepa Fill sigmas of the (sample,sample) correlations
4771 //  for all the StexEchas
4772 //                        (for writing in ROOT file)
4773 //
4774 //-------------------------------------------------------------------------
4775 void TEcnaRun::TRootSigCorss() {
4776   if (fTagSigCorss[0] == 1) {
4777     for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++) {
4778       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) = fT1d_sig_cor_ss[j0StexEcha];
4779     }
4780   }
4781 }
4782 
4783 //-------------------------------------------------------------------------
4784 //
4785 //  Prepa Fill Average Pedestals
4786 //  for all the StexStins
4787 //                        (for writing in ROOT file)
4788 //
4789 //-------------------------------------------------------------------------
4790 void TEcnaRun::TRootAvPed() {
4791   if (fTagAvPed[0] == 1) {
4792     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4793       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) = fT1d_av_mped[j0StexStinEcna];
4794     }
4795   }
4796 }
4797 
4798 //-------------------------------------------------------------------------
4799 //
4800 //  Prepa Fill
4801 //
4802 //                        (for writing in ROOT file)
4803 //
4804 //-------------------------------------------------------------------------
4805 void TEcnaRun::TRootAvEvCorss() {
4806   if (fTagAvMeanCorss[0] == 1)  // test 1st elt only since global calc
4807   {
4808     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4809       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) = fT1d_av_ev_corss[j0StexStinEcna];
4810     }
4811   }
4812 }
4813 
4814 //-------------------------------------------------------------------------
4815 //
4816 //  Prepa Fill
4817 //
4818 //                        (for writing in ROOT file)
4819 //
4820 //-------------------------------------------------------------------------
4821 void TEcnaRun::TRootAvSigCorss() {
4822   if (fTagAvSigCorss[0] == 1)  // test 1st elt only since global calc
4823   {
4824     for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++) {
4825       gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) = fT1d_av_sig_corss[j0StexStinEcna];
4826     }
4827   }
4828 }
4829 
4830 //=========================================================================
4831 //
4832 //         METHODS TO SET FLAGS TO PRINT (OR NOT) COMMENTS (DEBUG)
4833 //
4834 //=========================================================================
4835 
4836 void TEcnaRun::PrintComments() {
4837   // Set flags to authorize printing of some comments concerning initialisations (default)
4838 
4839   fFlagPrint = fCodePrintComments;
4840   std::cout << "*TEcnaRun::PrintComments()> Warnings and some comments on init will be printed" << std::endl;
4841 }
4842 
4843 void TEcnaRun::PrintWarnings() {
4844   // Set flags to authorize printing of warnings
4845 
4846   fFlagPrint = fCodePrintWarnings;
4847   std::cout << "*TEcnaRun::PrintWarnings()> Warnings will be printed" << std::endl;
4848 }
4849 
4850 void TEcnaRun::PrintAllComments() {
4851   // Set flags to authorize printing of the comments of all the methods
4852 
4853   fFlagPrint = fCodePrintAllComments;
4854   std::cout << "*TEcnaRun::PrintAllComments()> All the comments will be printed" << std::endl;
4855 }
4856 
4857 void TEcnaRun::PrintNoComment() {
4858   // Set flags to forbid the printing of all the comments
4859 
4860   fFlagPrint = fCodePrintNoComment;
4861 }
4862 //=========================== E N D ======================================