CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/src/TEcnaRun.cc

Go to the documentation of this file.
00001 //----------Author's Names: B.Fabbro, FX Gentit DSM/IRFU/SPP CEA-Saclay
00002 //----------Copyright: Those valid for CEA sofware
00003 //----------Modified: 24/03/2011
00004 
00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaRun.h"
00006 
00007 //--------------------------------------
00008 //  TEcnaRun.cc
00009 //  Class creation: 03 Dec 2002
00010 //  Documentation: see TEcnaRun.h
00011 //--------------------------------------
00012 
00013 R__EXTERN TEcnaRootFile *gCnaRootFile;
00014 
00015 ClassImp(TEcnaRun)
00016 //___________________________________________________________________________
00017 //
00018 
00019 TEcnaRun::TEcnaRun()
00020 {
00021 //Constructor without argument: nothing special done
00022 
00023  // cout << "[Info Management] CLASS: TEcnaRun.           CREATE OBJECT: this = " << this << endl;
00024 }
00025 
00026 TEcnaRun::TEcnaRun(TEcnaObject* pObjectManager, const TString SubDet)
00027 {
00028 //Constructor with argument: call to Init() and declare fEcal according to SubDet value ("EB" or "EE")
00029 
00030  // cout << "[Info Management] CLASS: TEcnaRun.           CREATE OBJECT: this = " << this << endl;
00031 
00032   Init();
00033   fObjectManager = (TEcnaObject*)pObjectManager;
00034   Long_t i_this = (Long_t)this;
00035   pObjectManager->RegisterPointer("TEcnaRun", i_this);
00036 
00037   //............................ fCnaParCout
00038   fCnaParCout = 0;
00039   Int_t iCnaParCout = pObjectManager->GetPointerValue("TEcnaParCout");
00040   if( iCnaParCout == 0 )
00041     {fCnaParCout = new TEcnaParCout(pObjectManager); /*fCnew++*/}
00042   else
00043     {fCnaParCout = (TEcnaParCout*)iCnaParCout;}
00044 
00045   //............................ fCnaParPaths
00046   fCnaParPaths = 0;
00047   Int_t iCnaParPaths = pObjectManager->GetPointerValue("TEcnaParPaths");
00048   if( iCnaParPaths == 0 )
00049     {fCnaParPaths = new TEcnaParPaths(pObjectManager); /*fCnew++*/}
00050   else
00051     {fCnaParPaths = (TEcnaParPaths*)iCnaParPaths;}
00052 
00053   //fCfgResultsRootFilePath    = fCnaParPaths->ResultsRootFilePath();
00054   //fCfgHistoryRunListFilePath = fCnaParPaths->HistoryRunListFilePath();
00055 
00056   //ffFileHeader = 0;
00057   //fconst Text_t *h_name  = "CnaHeader";   //==> voir cette question avec FXG
00058   //fconst Text_t *h_title = "CnaHeader";   //==> voir cette question avec FXG
00059   //ffFileHeader = new TEcnaHeader(h_name, h_title);     //fCnew++;
00060 
00061   //............................ fFileHeader
00062   const Text_t *h_name  = "CnaHeader";  //==> voir cette question avec FXG
00063   const Text_t *h_title = "CnaHeader";  //==> voir cette question avec FXG
00064 
00065   fFileHeader = 0;
00066   //Int_t iFileHeader = pObjectManager->GetPointerValue("TEcnaHeader");
00067   Int_t iFileHeader = 0;  // one TEcnaHeader object for each file since they can be open simultaneously 
00068   if( iFileHeader == 0 )
00069     {fFileHeader = new TEcnaHeader(pObjectManager, h_name, h_title); /*fCnew++*/}
00070   else
00071     {fFileHeader = (TEcnaHeader*)iFileHeader;}
00072 
00073   SetEcalSubDetector(SubDet.Data());
00074   fNbSampForFic = fEcal->MaxSampADC(); // DEFAULT Number of samples for ROOT file
00075 }
00076 
00077 TEcnaRun::TEcnaRun(TEcnaObject* pObjectManager, const TString SubDet, const Int_t& NbOfSamples)
00078 {
00079   //fCnaParPaths = 0; fCnaParPaths = new TEcnaParPaths();  //fCnew++;
00080   //fCnaParCout = 0;  fCnaParCout  = new TEcnaParCout();   //fCnew++;
00081 
00082   Init();
00083   fObjectManager = (TEcnaObject*)pObjectManager;
00084   Long_t i_this = (Long_t)this;
00085   pObjectManager->RegisterPointer("TEcnaRun", i_this);
00086 
00087   //............................ fCnaParCout
00088   fCnaParCout = 0;
00089   Int_t iCnaParCout = pObjectManager->GetPointerValue("TEcnaParCout");
00090   if( iCnaParCout == 0 )
00091     {fCnaParCout = new TEcnaParCout(pObjectManager); /*fCnew++*/}
00092   else
00093     {fCnaParCout = (TEcnaParCout*)iCnaParCout;}
00094 
00095   //............................ fCnaParPaths
00096   fCnaParPaths = 0;
00097   Int_t iCnaParPaths = pObjectManager->GetPointerValue("TEcnaParPaths");
00098   if( iCnaParPaths == 0 )
00099     {fCnaParPaths = new TEcnaParPaths(pObjectManager); /*fCnew++*/}
00100   else
00101     {fCnaParPaths = (TEcnaParPaths*)iCnaParPaths;}
00102 
00103   //fCfgResultsRootFilePath    = fCnaParPaths->ResultsRootFilePath();
00104   //fCfgHistoryRunListFilePath = fCnaParPaths->HistoryRunListFilePath();
00105 
00106   //............................ fFileHeader
00107   const Text_t *h_name  = "CnaHeader";  //==> voir cette question avec FXG
00108   const Text_t *h_title = "CnaHeader";  //==> voir cette question avec FXG
00109 
00110   fFileHeader = 0;
00111   //Int_t iFileHeader = pObjectManager->GetPointerValue("TEcnaHeader");
00112   Int_t iFileHeader = 0;  // one TEcnaHeader object for each file since they can be open simultaneously 
00113   if( iFileHeader == 0 )
00114     {fFileHeader = new TEcnaHeader(pObjectManager, h_name, h_title); /*fCnew++*/}
00115   else
00116     {fFileHeader = (TEcnaHeader*)iFileHeader;}
00117 
00118   SetEcalSubDetector(SubDet.Data());
00119   if( NbOfSamples>0 && NbOfSamples<=fEcal->MaxSampADC() )
00120     {
00121       fNbSampForFic = NbOfSamples;
00122     }
00123   else
00124     {
00125       cout << "TEcnaRun/CONSTRUCTOR> Number of required samples = " << NbOfSamples
00126            << ": OUT OF RANGE. Set to the default value (= " << fEcal->MaxSampADC() << ")."
00127            << fTTBELL << endl;
00128       fNbSampForFic = fEcal->MaxSampADC(); // DEFAULT Number of samples for file reading
00129     }
00130 }
00131 
00132 //.... return true or false according to the existence of the path. The path itself is in an attribute of fCnaParPaths.
00133 Bool_t TEcnaRun::GetPathForResults(){return fCnaParPaths->GetPathForResultsRootFiles();}
00134 
00135 void TEcnaRun::Init()
00136 {
00137 //Initialisation
00138 
00139   fCnew       = 0;
00140   fCdelete    = 0;
00141   fCnaCommand = 0;
00142   fCnaError   = 0;
00143 
00144   fTTBELL = '\007';
00145 
00146   //........................... TString file names init
00147   fgMaxCar  = (Int_t)512;
00148 
00149   //................ MiscDiag counters .................
00150   fMaxMsgIndexForMiscDiag = (Int_t)10;
00151   fNbOfMiscDiagCounters   = (Int_t)50;
00152   fMiscDiag = 0;
00153 
00154   fNumberOfEvents = 0;
00155   //............................. init pointers  ( Init() )
00156   fT3d_AdcValues  = 0;
00157   fT3d2_AdcValues = 0;
00158   fT3d1_AdcValues = 0;
00159 
00160   fT1d_StexStinFromIndex = 0;
00161 
00162   fT2d_NbOfEvts = 0;
00163   fT1d_NbOfEvts = 0; 
00164 
00165   fT2d_ev        = 0;
00166   fT1d_ev        = 0;
00167   fT2d_sig       = 0;
00168   fT1d_sig       = 0;
00169 
00170   fT3d_cov_ss    = 0;
00171   fT3d2_cov_ss   = 0;
00172   fT3d1_cov_ss   = 0;
00173 
00174   fT3d_cor_ss    = 0;
00175   fT3d2_cor_ss   = 0;
00176   fT3d1_cor_ss   = 0;
00177 
00178   fT2d_lf_cov  = 0;
00179   fT2d1_lf_cov = 0;
00180 
00181   fT2d_lf_cor  = 0;
00182   fT2d1_lf_cor = 0;
00183 
00184   fT2d_hf_cov  = 0;
00185   fT2d1_hf_cov = 0;
00186 
00187   fT2d_hf_cor  = 0;
00188   fT2d1_hf_cor = 0;
00189 
00190   fT2d_lfcc_mostins  = 0;
00191   fT2d1_lfcc_mostins = 0;
00192 
00193   fT2d_hfcc_mostins  = 0;
00194   fT2d1_hfcc_mostins = 0;
00195 
00196   fT1d_ev_ev            = 0;
00197   fT1d_evsamp_of_sigevt = 0;
00198   fT1d_ev_cor_ss        = 0;
00199   fT1d_av_mped          = 0;
00200   fT1d_av_totn          = 0;
00201   fT1d_av_lofn          = 0;
00202   fT1d_av_hifn          = 0;
00203   fT1d_av_ev_corss      = 0;
00204   fT1d_av_sig_corss     = 0;
00205 
00206   fT1d_sigevt_of_evsamp = 0;
00207   fT1d_evevt_of_sigsamp = 0;
00208   fT1d_sig_cor_ss       = 0;
00209 
00210   fT2dCrysNumbersTable = 0;
00211   fT1dCrysNumbersTable = 0;
00212 
00213   //................................ tags   ( Init() )
00214   fTagStinNumbers = 0;
00215 
00216   fTagNbOfEvts = 0;
00217 
00218   fTagAdcEvt = 0;
00219 
00220   fTagMSp    = 0;
00221   fTagSSp    = 0;
00222 
00223   fTagCovCss = 0;
00224   fTagCorCss = 0;
00225 
00226   fTagHfCov  = 0;
00227   fTagHfCor  = 0;
00228   fTagLfCov  = 0;
00229   fTagLfCor  = 0;
00230 
00231   fTagLFccMoStins = 0;
00232   fTagHFccMoStins = 0;
00233 
00234   fTagPed = 0;
00235   fTagTno = 0;
00236   fTagMeanCorss = 0;
00237 
00238   fTagLfn = 0;
00239   fTagHfn = 0;
00240   fTagSigCorss = 0;
00241 
00242   fTagAvPed = 0;
00243   fTagAvTno = 0;
00244   fTagAvLfn = 0;
00245   fTagAvHfn = 0;
00246 
00247   fTagAvMeanCorss = 0;
00248   fTagAvSigCorss  = 0;
00249 
00250   //................................................... Code Print  ( Init() )
00251   fCodePrintNoComment   = fCnaParCout->GetCodePrint("NoComment");
00252   fCodePrintWarnings    = fCnaParCout->GetCodePrint("Warnings ");      // => default value
00253   fCodePrintComments    = fCnaParCout->GetCodePrint("Comments");
00254   fCodePrintAllComments = fCnaParCout->GetCodePrint("AllComments");
00255 
00256   fFlagPrint = fCodePrintWarnings;
00257 
00258   //...................................................
00259   gCnaRootFile = 0;
00260   fOpenRootFile = kFALSE;
00261   fReadyToReadData = 0;
00262 
00263   //.............................................. Miscellaneous
00264   fSpecialStexStinNotIndexed = -1;
00265 
00266   fStinIndexBuilt     = 0;
00267   fBuildEvtNotSkipped = 0;
00268 
00269   fMemoReadNumberOfEventsforSamples = 0;
00270 
00271 }// end of Init()
00272 
00273 //========================================================================
00274 void  TEcnaRun::SetEcalSubDetector(const TString SubDet)
00275 {
00276  // Set Subdetector (EB or EE)
00277 
00278   Int_t MaxCar = fgMaxCar;
00279   fFlagSubDet.Resize(MaxCar);
00280   fFlagSubDet = SubDet.Data();
00281 
00282   fEcal          = 0; fEcal          = new TEcnaParEcal(fFlagSubDet.Data());           //fCnew++;
00283   fEcalNumbering = 0; fEcalNumbering = new TEcnaNumbering(fFlagSubDet.Data(), fEcal);  //fCnew++;
00284   fCnaWrite      = 0;
00285   fCnaWrite =
00286     new TEcnaWrite(fFlagSubDet.Data(), fCnaParPaths, fCnaParCout, fEcal, fEcalNumbering); //fCnew++;
00287 
00288   if( fFlagSubDet == "EB" ){fStexName = "SM "; fStinName = "tower";}
00289   if( fFlagSubDet == "EE" ){fStexName = "Dee"; fStinName = " SC  ";}
00290 }
00291 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00292 //
00293 //                    copy constructor
00294 //
00295 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00296 
00297 TEcnaRun::TEcnaRun(const TEcnaRun& dcop)
00298 {
00299   cout << "*TEcnaRun::TEcnaRun(const TEcnaRun& dcop)> "
00300        << " Now is the time to write a copy constructor" 
00301        << endl;
00302   
00303   //{ Int_t cintoto;  cin >> cintoto; }
00304   
00305 }
00306 
00307 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00308 //
00309 //                    overloading of the operator=
00310 //
00311 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00312 
00313 //TEcnaRun& TEcnaRun::operator=(const TEcnaRun& dcop)
00314 //{
00315 //Overloading of the operator=
00316 //
00317 //  fCopy(dcop);
00318 //  return *this;
00319 //}
00320 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00321 //
00322 //                            destructor
00323 //
00324 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00325 
00326 TEcnaRun::~TEcnaRun()
00327 {
00328   //Destructor
00329   
00330   if(fFlagPrint == fCodePrintAllComments)
00331     {
00332       cout << "*TEcnaRun::~TEcnaRun()> Entering destructor." << endl;
00333     }
00334 
00335   if(fFlagPrint != fCodePrintNoComment || fFlagPrint == fCodePrintWarnings )
00336     {
00337       if( fBuildEvtNotSkipped > 0 )
00338         {
00339           cout << "************************************************************************************* "
00340                << endl;
00341           cout << "*TEcnaRun::~TEcnaRun()> Nb of calls to GetSampleAdcValues by cmsRun: "
00342                << fBuildEvtNotSkipped << endl;
00343           cout << "************************************************************************************* "
00344                << endl;
00345         }
00346     }
00347 
00348   if(fFlagPrint == fCodePrintAllComments)
00349     {
00350       Int_t misc_czero = 0;
00351       for(Int_t i = 0; i < fNbOfMiscDiagCounters; i++)
00352         {
00353           if( fMiscDiag[i] != 0 )
00354             {
00355               cout << "                          fMiscDiag Counter "
00356                    << setw(3) << i << " = " << setw(9) << fMiscDiag[i]
00357                    << " (INFO: alloc on non zero freed zone) " << endl;
00358             }
00359           else
00360             {
00361               misc_czero++;
00362             }
00363         }
00364       cout << "                          Nb of fMiscDiag counters at zero: "
00365            << misc_czero << " (total nb of counters: "
00366            << fNbOfMiscDiagCounters << ")" << endl;
00367     }
00368   
00369   if (fMiscDiag                != 0){delete [] fMiscDiag;                 fCdelete++;}
00370   
00371   //if (fFileHeader              != 0){delete fFileHeader;                  fCdelete++;}
00372   //if (fEcal                    != 0){delete fEcal;                        fCdelete++;}
00373   //if (fEcalNumbering           != 0){delete fEcalNumbering;               fCdelete++;}
00374   //if (fCnaParCout              != 0){delete fCnaParCout;                  fCdelete++;}
00375   //if (fCnaParPaths             != 0){delete fCnaParPaths;                 fCdelete++;}
00376   //if (fCnaWrite                != 0){delete fCnaWrite;                    fCdelete++;}
00377   
00378   if (fT1d_StexStinFromIndex   != 0){delete [] fT1d_StexStinFromIndex;    fCdelete++;}
00379 
00380   if (fT2d_NbOfEvts        != 0){delete [] fT2d_NbOfEvts;         fCdelete++;}
00381   if (fT1d_NbOfEvts        != 0){delete [] fT1d_NbOfEvts;         fCdelete++;}
00382 
00383   if (fT3d_AdcValues        != 0){delete [] fT3d_AdcValues;         fCdelete++;}
00384   if (fT3d2_AdcValues       != 0){delete [] fT3d2_AdcValues;        fCdelete++;}
00385   if (fT3d1_AdcValues       != 0){delete [] fT3d1_AdcValues;        fCdelete++;}
00386 
00387   if (fT2d_ev              != 0){delete [] fT2d_ev;               fCdelete++;}
00388   if (fT1d_ev              != 0){delete [] fT1d_ev;               fCdelete++;}
00389 
00390   if (fT2d_sig             != 0){delete [] fT2d_sig;              fCdelete++;}
00391   if (fT1d_sig             != 0){delete [] fT1d_sig;              fCdelete++;}
00392 
00393   if (fT3d_cov_ss          != 0){delete [] fT3d_cov_ss;           fCdelete++;}
00394   if (fT3d2_cov_ss         != 0){delete [] fT3d2_cov_ss;          fCdelete++;}
00395   if (fT3d1_cov_ss         != 0){delete [] fT3d1_cov_ss;          fCdelete++;}
00396 
00397   if (fT3d_cor_ss          != 0){delete [] fT3d_cor_ss;           fCdelete++;}
00398   if (fT3d2_cor_ss         != 0){delete [] fT3d2_cor_ss;          fCdelete++;}
00399   if (fT3d1_cor_ss         != 0){delete [] fT3d1_cor_ss;          fCdelete++;}
00400 
00401   if (fT2d_lf_cov          != 0){delete [] fT2d_lf_cov;           fCdelete++;}
00402   if (fT2d1_lf_cov         != 0){delete [] fT2d1_lf_cov;          fCdelete++;}
00403 
00404   if (fT2d_lf_cor          != 0){delete [] fT2d_lf_cor;           fCdelete++;}
00405   if (fT2d1_lf_cor         != 0){delete [] fT2d1_lf_cor;          fCdelete++;}
00406 
00407   if (fT2d_hf_cov          != 0){delete [] fT2d_hf_cov;           fCdelete++;}
00408   if (fT2d1_hf_cov         != 0){delete [] fT2d1_hf_cov;          fCdelete++;}
00409 
00410   if (fT2d_hf_cor          != 0){delete [] fT2d_hf_cor;           fCdelete++;}
00411   if (fT2d1_hf_cor         != 0){delete [] fT2d1_hf_cor;          fCdelete++;}
00412 
00413   if (fT2d_lfcc_mostins    != 0){delete [] fT2d_lfcc_mostins;     fCdelete++;}
00414   if (fT2d1_lfcc_mostins   != 0){delete [] fT2d1_lfcc_mostins ;   fCdelete++;}
00415 
00416   if (fT2d_hfcc_mostins    != 0){delete [] fT2d_hfcc_mostins ;    fCdelete++;}
00417   if (fT2d1_hfcc_mostins   != 0){delete [] fT2d1_hfcc_mostins;    fCdelete++;}
00418 
00419   if (fT1d_ev_ev             != 0){delete [] fT1d_ev_ev;              fCdelete++;}
00420   if (fT1d_evsamp_of_sigevt  != 0){delete [] fT1d_evsamp_of_sigevt;   fCdelete++;}
00421   if (fT1d_ev_cor_ss         != 0){delete [] fT1d_ev_cor_ss;          fCdelete++;}
00422   if (fT1d_av_mped           != 0){delete [] fT1d_av_mped;            fCdelete++;}
00423   if (fT1d_av_totn           != 0){delete [] fT1d_av_totn;            fCdelete++;}
00424   if (fT1d_av_lofn           != 0){delete [] fT1d_av_lofn;            fCdelete++;}
00425   if (fT1d_av_hifn           != 0){delete [] fT1d_av_hifn;            fCdelete++;}
00426   if (fT1d_av_ev_corss       != 0){delete [] fT1d_av_ev_corss;        fCdelete++;}
00427   if (fT1d_av_sig_corss      != 0){delete [] fT1d_av_sig_corss;       fCdelete++;}
00428 
00429   if (fT1d_sigevt_of_evsamp    != 0){delete [] fT1d_sigevt_of_evsamp;     fCdelete++;}
00430   if (fT1d_evevt_of_sigsamp    != 0){delete [] fT1d_evevt_of_sigsamp;     fCdelete++;}
00431   if (fT1d_sig_cor_ss          != 0){delete [] fT1d_sig_cor_ss;           fCdelete++;}
00432 
00433   if (fT2dCrysNumbersTable     != 0){delete [] fT2dCrysNumbersTable;      fCdelete++;}
00434   if (fT1dCrysNumbersTable     != 0){delete [] fT1dCrysNumbersTable;      fCdelete++;}
00435 
00436   if (fTagStinNumbers          != 0){delete [] fTagStinNumbers;           fCdelete++;}
00437   if (fTagNbOfEvts             != 0){delete [] fTagNbOfEvts;              fCdelete++;}
00438   if (fTagAdcEvt               != 0){delete [] fTagAdcEvt;                fCdelete++;}
00439   if (fTagMSp                  != 0){delete [] fTagMSp;                   fCdelete++;}
00440   if (fTagSSp                  != 0){delete [] fTagSSp;                   fCdelete++;}
00441 
00442   if (fTagCovCss               != 0){delete [] fTagCovCss;                fCdelete++;}
00443   if (fTagCorCss               != 0){delete [] fTagCorCss;                fCdelete++;}
00444 
00445   if (fTagHfCov                != 0){delete [] fTagHfCov;                 fCdelete++;}
00446   if (fTagHfCor                != 0){delete [] fTagHfCor;                 fCdelete++;}
00447   if (fTagLfCov                != 0){delete [] fTagLfCov;                 fCdelete++;}
00448   if (fTagLfCor                != 0){delete [] fTagLfCor;                 fCdelete++;}
00449 
00450   if (fTagLFccMoStins          != 0){delete [] fTagLFccMoStins;           fCdelete++;}
00451   if (fTagHFccMoStins          != 0){delete [] fTagHFccMoStins;           fCdelete++;}
00452 
00453   if (fTagPed                 != 0){delete [] fTagPed;                  fCdelete++;}
00454   if (fTagTno                 != 0){delete [] fTagTno;                  fCdelete++;}
00455   if (fTagMeanCorss           != 0){delete [] fTagMeanCorss;            fCdelete++;}
00456 
00457   if (fTagLfn                != 0){delete [] fTagLfn;                 fCdelete++;}
00458   if (fTagHfn                != 0){delete [] fTagHfn;                 fCdelete++;}
00459   if (fTagSigCorss           != 0){delete [] fTagSigCorss;            fCdelete++;}
00460 
00461   if (fTagAvPed          != 0){delete [] fTagAvPed;           fCdelete++;}
00462   if (fTagAvTno          != 0){delete [] fTagAvTno;           fCdelete++;}
00463   if (fTagAvLfn          != 0){delete [] fTagAvLfn;           fCdelete++;}
00464   if (fTagAvHfn          != 0){delete [] fTagAvHfn;           fCdelete++;}
00465   if (fTagAvMeanCorss    != 0){delete [] fTagAvMeanCorss;     fCdelete++;}
00466   if (fTagAvSigCorss     != 0){delete [] fTagAvSigCorss;      fCdelete++;}
00467 
00468   if ( fCnew != fCdelete )
00469     {
00470       cout << "!TEcnaRun::~TEcnaRun()> WRONG MANAGEMENT OF MEMORY ALLOCATIONS: fCnew = "
00471            << fCnew << ", fCdelete = " << fCdelete << fTTBELL << endl;
00472     }
00473   else
00474     {
00475       // cout << "*TEcnaRun::~TEcnaRun()> Management of memory allocations: OK. fCnew = "
00476       //   << fCnew << ", fCdelete = " << fCdelete << endl;
00477     }
00478 
00479   if(fFlagPrint == fCodePrintAllComments)
00480     {
00481       cout << "*TEcnaRun::~TEcnaRun()> Exiting destructor (this = " << this << ")." << endl
00482            << "~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#"
00483            << endl;
00484     }
00485 
00486  // cout << "[Info Management] CLASS: TEcnaRun.           DESTROY OBJECT: this = " << this << endl;
00487 }
00488 
00489 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00490 //
00491 //                             M  E  T  H  O  D  S
00492 //
00493 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00494 
00495 //============================================================================
00496 //
00497 //                           GetReadyToReadData(...)
00498 //                  
00499 //  Preparation of the result file name + tags allocations
00500 //  + ADC event distribution array allocation + nb of events array allocation
00501 //
00502 //============================================================================
00503 
00504 void TEcnaRun::GetReadyToReadData(TString     typ_ana, const Int_t& run_number,
00505                                  const Int_t& nfirst,  const Int_t& nlast, const Int_t& nbevts,
00506                                  const Int_t& Stex)
00507 {
00508 //Preparation of the data reading. Set part of the header. No RunType as argument.
00509 //Use default value = 99999999 and call method with all the arguments (see below)
00510 
00511   Int_t RunType = 99999999;
00512   GetReadyToReadData(typ_ana, run_number, nfirst, nlast, nbevts, Stex, RunType);
00513 }
00514 //--------------------------------------------------------------------------------
00515 void TEcnaRun::GetReadyToReadData( TString       typ_ana, const Int_t& run_number,
00516                                    const Int_t&  nfirst,  const Int_t& nlast, const Int_t& nbevts,
00517                                    const Int_t&  Stex,    const Int_t& run_type)
00518 {
00519 //Preparation of the data reading. Set part of the header
00520 //
00521 //   [nfirst, nlast] = [1,50] (50 events) or [151,300] (150 events) or etc...
00522 
00523   Int_t nrangeevts = nlast - nfirst + 1;  // number of events in range
00524 
00525   if( nrangeevts < nbevts )
00526     {
00527       if( nlast >= nfirst )
00528         {
00529           cout << "*TEcnaRun::GetReadyToReadData(...)> --- WARNING ---> number of events = " << nbevts
00530                << ", out of range (range = " << nfirst << "," << nlast << ")" << endl
00531                << "                                    The number of found events will be less " << endl
00532                << "                                    than the number of requested events." << endl;
00533         }
00534       if( nlast < nfirst )
00535         {
00536           cout << "*TEcnaRun::GetReadyToReadData(...)> --- INFO ---> last requested event number = " << nlast
00537                << ", less than first requested event number (= " << nfirst << ")" << endl
00538                << "                                    File will be read until EOF if the number of found events" << endl
00539                << "                                    remains less than the number of requested events." << endl;
00540         }
00541 
00542     }
00543   
00544   Int_t ifirst  = nfirst - 1;
00545 
00546   //............. allocation for counters
00547   fMiscDiag = new Int_t[fNbOfMiscDiagCounters];       fCnew++;
00548   for (Int_t iz=0; iz<fNbOfMiscDiagCounters; iz++){fMiscDiag[iz] = (Int_t)0;}
00549 
00550   //************** CHECK OF ARGUMENTS: nfirst_arg and nbevts_arg
00551   Int_t nentries = 99999999;   // => to be reintroduced as argument (like run_type) (?)
00552   if ( nfirst <= nentries )
00553     {
00554       //--------------------- test positivity of nfirst_arg        (GetReadyToReadData)
00555       if ( nfirst > 0 )
00556         {
00557           //-------- test compatibility between the last requested event number
00558           //         and the number of entries
00559           if( nlast <= nentries )
00560             { 
00561               const Text_t *h_name  = "CnaHeader";   //==> voir cette question avec FXG
00562               const Text_t *h_title = "CnaHeader";   //==> voir cette question avec FXG
00563               //fFileHeader->HeaderParameters(h_name,     h_title ,
00564               //                              typ_ana,    fNbSampForFic,
00565               //                              run_number, nfirst,  nlast,  nbevts,
00566               //                              Stex,       nentries);                 fCnew++;
00567 
00568               if ( fEcal->MaxStinEcnaInStex() > 0  &&  fEcal->MaxCrysInStin() > 0  &&  fNbSampForFic > 0 ) 
00569                 {
00570                   if( fFileHeader == 0 ){fFileHeader = new TEcnaHeader(fObjectManager, h_name, h_title);} // fCnew++;
00571 
00572                   fFileHeader->HeaderParameters(typ_ana,    fNbSampForFic,
00573                                                 run_number, nfirst, nlast, nbevts,
00574                                                 Stex,       run_type);
00575 
00576                   // After this call to TEcnaHeader, we have:               (GetReadyToReadData)
00577                   //     fFileHeader->fTypAna            = typ_ana
00578                   //     fFileHeader->fNbOfSamples       = fNbSampForFic
00579                   //     fFileHeader->fRunNumber         = run_number
00580                   //     fFileHeader->fFirstReqEvtNumber = nfirst
00581                   //     fFileHeader->fLastReqEvtNumber  = nlast
00582                   //     fFileHeader->fReqNbOfEvts       = nbevts
00583                   //     fFileHeader->fStex              = Stex number
00584                   //     fFileHeader->fRunType           = run_type
00585                   
00586                   // fFileHeader->Print();
00587                   
00588                   // {Int_t cintoto; cout << "taper 0 pour continuer" << endl; cin >> cintoto;}
00589                   
00590                   //  fFileHeader->SetName("CnaHeader");              *======> voir FXG
00591                   //  fFileHeader->SetTitle("CnaHeader");
00592                   
00593                   //......................................... allocation tags + init of them (GetReadyToReadData)
00594                   
00595                   fTagStinNumbers = new Int_t[1]; fCnew++; fTagStinNumbers[0] = (Int_t)0;
00596                   fTagNbOfEvts    = new Int_t[1]; fCnew++; fTagNbOfEvts[0]    = (Int_t)0;
00597                   
00598                   fTagAdcEvt      = new Int_t[fEcal->MaxCrysEcnaInStex()]; fCnew++;
00599                   for (Int_t iz=0; iz<fEcal->MaxCrysEcnaInStex(); iz++){fTagAdcEvt[iz] = (Int_t)0;}
00600                   
00601                   fTagMSp         = new Int_t[1]; fCnew++; fTagMSp[0] = (Int_t)0;
00602                   fTagSSp         = new Int_t[1]; fCnew++; fTagSSp[0] = (Int_t)0;
00603                   
00604                   fTagCovCss      = new Int_t[fEcal->MaxCrysEcnaInStex()]; fCnew++;
00605                   for (Int_t iz=0; iz<fEcal->MaxCrysEcnaInStex(); iz++){fTagCovCss[iz] = (Int_t)0;}
00606                   
00607                   fTagCorCss      = new Int_t[fEcal->MaxCrysEcnaInStex()]; fCnew++;
00608                   for (Int_t iz=0; iz<fEcal->MaxCrysEcnaInStex(); iz++){fTagCorCss[iz] = (Int_t)0;}
00609                   
00610                   fTagLfCov       = new Int_t[1]; fCnew++; fTagLfCov[0] = (Int_t)0;
00611                   fTagLfCor       = new Int_t[1]; fCnew++; fTagLfCor[0] = (Int_t)0;
00612                   
00613                   fTagHfCov       = new Int_t[1]; fCnew++; fTagHfCov[0] = (Int_t)0;
00614                   fTagHfCor       = new Int_t[1]; fCnew++; fTagHfCor[0] = (Int_t)0;
00615                   
00616                   fTagLFccMoStins = new Int_t[1]; fCnew++; fTagLFccMoStins[0] = (Int_t)0;
00617                   fTagHFccMoStins = new Int_t[1]; fCnew++; fTagHFccMoStins[0] = (Int_t)0;
00618                   
00619                   fTagPed         = new Int_t[1]; fCnew++; fTagPed[0]         = (Int_t)0;
00620                   fTagTno         = new Int_t[1]; fCnew++; fTagTno[0]         = (Int_t)0;
00621                   fTagMeanCorss   = new Int_t[1]; fCnew++; fTagMeanCorss[0]   = (Int_t)0; 
00622                   
00623                   fTagLfn         = new Int_t[1]; fCnew++; fTagLfn[0]         = (Int_t)0; 
00624                   fTagHfn         = new Int_t[1]; fCnew++; fTagHfn[0]         = (Int_t)0; 
00625                   fTagSigCorss    = new Int_t[1]; fCnew++; fTagSigCorss[0]    = (Int_t)0; 
00626                   
00627                   fTagAvPed       = new Int_t[1]; fCnew++; fTagAvPed[0]       = (Int_t)0; 
00628                   fTagAvTno       = new Int_t[1]; fCnew++; fTagAvTno[0]       = (Int_t)0; 
00629                   fTagAvLfn       = new Int_t[1]; fCnew++; fTagAvLfn[0]       = (Int_t)0; 
00630                   fTagAvHfn       = new Int_t[1]; fCnew++; fTagAvHfn[0]       = (Int_t)0; 
00631                   fTagAvMeanCorss = new Int_t[1]; fCnew++; fTagAvMeanCorss[0] = (Int_t)0; 
00632                   fTagAvSigCorss  = new Int_t[1]; fCnew++; fTagAvSigCorss[0]  = (Int_t)0; 
00633                   
00634                   //====================================================================================
00635                   //
00636                   //   allocation for fT1d_StexStinFromIndex[] and init to fSpecialStexStinNotIndexed
00637                   //
00638                   //====================================================================================
00639                   
00640                   if(fT1d_StexStinFromIndex == 0)
00641                     {
00642                       fT1d_StexStinFromIndex = new Int_t[fEcal->MaxStinEcnaInStex()];          fCnew++;
00643                     }
00644                   for ( Int_t i0_Stin = 0; i0_Stin < fEcal->MaxStinEcnaInStex(); i0_Stin++ )
00645                     {
00646                       fT1d_StexStinFromIndex[i0_Stin] = fSpecialStexStinNotIndexed;
00647                     }
00648                   
00649                   //-------------------------------------------------------------  (GetReadyToReadData)
00650           
00651                   //====================================================================================
00652                   //
00653                   //   allocation of the 3D array fT3d_AdcValues[channel][sample][events] (ADC values)
00654                   //
00655                   //   This array is filled in the GetSampleAdcValues(...) method
00656                   //
00657                   //====================================================================================
00658                   
00659                   if(fT3d_AdcValues == 0)
00660                     {
00661                       //............ Allocation for the 3d array 
00662                       cout << "*TEcnaRun::GetReadyToReadData(...)> Allocation of 3D array for ADC distributions."
00663                            << " Nb of requested evts = " << fFileHeader->fReqNbOfEvts << endl
00664                            << "                                    This number must not be too large"
00665                            << " (no failure after this message means alloc OK)." << endl;
00666 
00667                       fT3d_AdcValues = new Double_t**[fEcal->MaxCrysEcnaInStex()];        fCnew++;  
00668 
00669                       fT3d2_AdcValues  =
00670                         new  Double_t*[fEcal->MaxCrysEcnaInStex()*
00671                                        fNbSampForFic];                          fCnew++;  
00672 
00673                       fT3d1_AdcValues  =
00674                         new   Double_t[fEcal->MaxCrysEcnaInStex()*
00675                                        fNbSampForFic*
00676                                        fFileHeader->fReqNbOfEvts];                       fCnew++;
00677 
00678                       for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++){
00679                         fT3d_AdcValues[i0StexEcha] = &fT3d2_AdcValues[0] + i0StexEcha*fNbSampForFic;
00680                         for(Int_t j0Sample=0; j0Sample<fNbSampForFic; j0Sample++){
00681                           fT3d2_AdcValues[fNbSampForFic*i0StexEcha + j0Sample] = &fT3d1_AdcValues[0]+
00682                             fFileHeader->fReqNbOfEvts*(fNbSampForFic*i0StexEcha+j0Sample);}}
00683                     }
00684                   //................................. Init to zero
00685                   for (Int_t iza=0; iza<fEcal->MaxCrysEcnaInStex(); iza++)
00686                     {
00687                       for (Int_t izb=0; izb<fNbSampForFic; izb++)
00688                         {
00689                           for (Int_t izc=0; izc<fFileHeader->fReqNbOfEvts; izc++)
00690                             {
00691                               if( fT3d_AdcValues[iza][izb][izc] != (Double_t)0 )
00692                                 {
00693                                   fMiscDiag[0]++;
00694                                   fT3d_AdcValues[iza][izb][izc] = (Double_t)0;
00695                                 }
00696                             }
00697                         }
00698                     }
00699 
00700                   //--------------------------------------------------------- (GetReadyToReadData)        
00701                   //====================================================================================
00702                   //
00703                   //   allocation of the 2D array fT2d_NbOfEvts[channel][sample] (Max nb of evts)
00704                   //
00705                   //====================================================================================
00706                   
00707                   if (fT2d_NbOfEvts == 0)
00708                     {
00709                       fT2d_NbOfEvts  = new Int_t*[fEcal->MaxCrysEcnaInStex()];           fCnew++;
00710                       fT1d_NbOfEvts  = new  Int_t[fEcal->MaxCrysEcnaInStex()*
00711                                                       fNbSampForFic];            fCnew++;
00712                       
00713                       for(Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
00714                         {
00715                           fT2d_NbOfEvts[i0StexEcha] =
00716                             &fT1d_NbOfEvts[0] + i0StexEcha*fNbSampForFic;
00717                         }
00718                       
00719                       //................ Init the array to 0
00720                       for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
00721                         {
00722                           for(Int_t i0Sample=0; i0Sample<fNbSampForFic; i0Sample++)
00723                             {
00724                               fT2d_NbOfEvts[i0StexEcha][i0Sample] = 0;
00725                             }
00726                         }
00727                     }
00728                   else
00729                     {
00730                       cerr << "!TEcnaRun::GetReadyToReadData(...)> *** ERROR *** No allocation for fT2d_NbOfEvts!"
00731                            << " Pointer already not NULL " << fTTBELL << endl;
00732                       // {Int_t cintoto; cout << "Enter: 0 and RETURN to continue or: CTRL C to exit"
00733                       //                   << endl; cin >> cintoto;}
00734                     }
00735                 }
00736               else
00737                 {
00738                   cerr << endl
00739                        << "!TEcnaRun::GetReadyToReadData(...)> "
00740                        << " *** ERROR *** " << endl
00741                        << " --------------------------------------------------"
00742                        << endl
00743                        << " NULL or NEGATIVE values for arguments" << endl
00744                        << " with expected positive values:"        << endl
00745                        << " Number of Stins in Stex = " << fEcal->MaxStinEcnaInStex()  << endl
00746                        << " Number of crystals in Stin     = " << fEcal->MaxCrysInStin() << endl
00747                        << " Number of samples by channel    = " << fNbSampForFic << endl
00748                        << endl
00749                        << endl
00750                        << " hence, no memory allocation for array member has been performed." << endl;
00751                   
00752                   cout << "Enter: 0 and RETURN to continue or: CTRL C to exit";
00753                   Int_t toto;
00754                   cin >> toto;
00755                 }
00756               //----------------------------------------------------------- (GetReadyToReadData)
00757               if(fFlagPrint == fCodePrintAllComments ){
00758                 cout << endl;
00759                 cout << "*TEcnaRun::GetReadyToReadData(...)>" << endl
00760                      << "          The method has been called with the following argument values:"  << endl
00761                      << "          Analysis name                = "
00762                      << fFileHeader->fTypAna << endl
00763                      << "          Run number                   = "
00764                      << fFileHeader->fRunNumber << endl
00765                      << "          Run type                     = "
00766                      << fFileHeader->fRunType << endl
00767                      << "          First requested event number = "
00768                      << fFileHeader->fFirstReqEvtNumber << endl
00769                      << "          Last requested event number  = "
00770                      << fFileHeader->fLastReqEvtNumber << endl
00771                      << "          " << fStexName.Data() << " number                  = "
00772                      << fFileHeader->fStex << endl
00773                      << "          Number of " << fStinName.Data()
00774                      << " in " << fStexName.Data() << "       = "
00775                      << fEcal->MaxStinEcnaInStex()  << endl
00776                      << "          Number of crystals in " << fStinName.Data() << "  = "
00777                      << fEcal->MaxCrysInStin()  << endl
00778                      << "          Number of samples by channel = "
00779                      << fNbSampForFic  << endl
00780                      << endl;}
00781               
00782               fReadyToReadData = 1;                        // set flag
00783             }
00784           else
00785             {
00786               if (fFlagPrint != fCodePrintNoComment){
00787                 cout << "!TEcnaRun::GetReadyToReadData(...) > WARNING/CORRECTION:" << endl
00788                      << "! The fisrt requested event number is not positive (nfirst = " << nfirst << ") "
00789                      << fTTBELL << endl;}
00790               ifirst = 0;
00791             }
00792         }
00793       else
00794         {
00795           if (fFlagPrint != fCodePrintNoComment){
00796             cout << endl << "!TEcnaRun::GetReadyToReadData(...)> WARNING/CORRECTION:" << endl
00797                  << "! The number of requested events (nbevts = " << nbevts << ") is too large." << endl
00798                  << "! Last event number = " << nlast << " > number of entries = " << nentries << ". "
00799                  << fTTBELL << endl << endl;}
00800         }
00801     }
00802   else
00803     {
00804       cout << "!TEcnaRun::GetReadyToReadData(...) *** ERROR ***> "
00805            << " The first requested event number is greater than the number of entries."
00806            << fTTBELL << endl;
00807     }
00808   if(fFlagPrint == fCodePrintAllComments){
00809     cout << "*TEcnaRun::GetReadyToReadData(...)> Leaving the method. fReadyToReadData = "
00810          << fReadyToReadData << endl; }
00811 
00812 } // end of GetReadyToReadData
00813 
00814 //====================================================================================================
00815 //
00816 //     GetSampleAdcValues: method called by the CMSSW analyzer (cmsRun)
00817 //
00818 //     At each event, put the Sample ADC value in the 3D array: fT3d_AdcValues[i0StexEcha][i0Sample][i0EventIndex]
00819 //
00820 //         |============================================================|
00821 //         |                                                            |
00822 //         | (Stex,Stin) means: (SM,tower) for EB and: (Dee,SC) for EE  |
00823 //         |                                                            |
00824 //         |============================================================|
00825 //
00826 //    (Stin number <-> Stin index correspondance, ADC sample values)
00827 //
00828 //        THIS METHOD IS CALLED INSIDE THE LOOPS OVER:
00829 //          ( EVENTS (tower or SC (CRYSTAL in tower or SC (SAMPLES)))) 
00830 //
00831 //  Arguments: Event    = event number.              Range = [ 1, fFileHeader->fReqNbOfEvts ]
00832 //             n1StexStin = Stin number in Stex.     Range = [ 1, fEcal->MaxStinEcnaInStex() ]
00833 //             i0StinEcha = channel number in Stin.  Range = [ 0, fEcal->MaxCrysInStin() - 1 ]     
00834 //             sample   = ADC sample number.         Range = [ 0, fNbSampForFic - 1 ]
00835 //             adcvalue = ADC sample value.
00836 //
00837 //====================================================================================================
00838 Bool_t TEcnaRun::GetSampleAdcValues(const Int_t&    n1EventNumber, const Int_t& n1StexStin,
00839                                     const Int_t&    i0StinEcha,    const Int_t& i0Sample,
00840                                     const Double_t& adcvalue)
00841 {
00842   //Building of the arrays fT1d_StexStinFromIndex[] and fT3d_AdcValues[][][]
00843   
00844   fBuildEvtNotSkipped++;      // event not skipped by cmsRun
00845 
00846   Bool_t ret_code = kFALSE;
00847 
00848   Int_t i0EventIndex   = n1EventNumber - 1;  // INDEX FOR Event number  
00849   Int_t i0StexStinEcna = n1StexStin - 1;     // INDEX FOR StexStin = Number_of_the_Stin_in_Stex - 1
00850 
00851   Int_t i_trouve = 0;
00852   //.................................................................. (GetSampleAdcValues)
00853   if(fReadyToReadData == 1)  
00854     {
00855       if( n1StexStin>= 1 && n1StexStin <= fEcal->MaxStinEcnaInStex() )
00856         {      
00857           if( i0StinEcha >= 0 && i0StinEcha < fEcal->MaxCrysInStin() )
00858             {
00859               if( i0Sample >= 0 && i0Sample < fEcal->MaxSampADC() )
00860                 {
00861                   //..... Put the StexStin number in 1D array fT1d_StexStinFromIndex[] = Stin index + 1
00862                   if( fT1d_StexStinFromIndex != 0 )  // table fT1d_StexStinFromIndex[index] already allocated
00863                     {
00864                       ret_code = kTRUE;
00865 
00866                       // StexStin already indexed
00867                       if( n1StexStin == fT1d_StexStinFromIndex[i0StexStinEcna] ){i_trouve = 1;}
00868                   
00869                       // StexStin index not found: set index for new StexStin
00870                       if (i_trouve != 1 )
00871                         {
00872                           if( fT1d_StexStinFromIndex[i0StexStinEcna] == fSpecialStexStinNotIndexed )
00873                             {
00874                               fT1d_StexStinFromIndex[i0StexStinEcna] = n1StexStin;
00875                               fFileHeader->fStinNumbersCalc = 1;
00876                               fTagStinNumbers[0] = 1;
00877                               fStinIndexBuilt++;                      //  number of found Stins
00878                               
00879                               if(fFlagPrint == fCodePrintAllComments)
00880                                 {
00881                                   if( fStinIndexBuilt == 1 )
00882                                     {
00883                                       cout << endl << "*TEcnaRun::GetSampleAdcValues(...)> event " << n1EventNumber
00884                                            << " : first event for " << fStexName.Data() << " " << fFileHeader->fStex
00885                                            << "; " << fStinName.Data() << "s : ";
00886                                     }
00887                                   if( fFlagSubDet == "EB" )
00888                                     {cout << fT1d_StexStinFromIndex[i0StexStinEcna] << ", ";}
00889                                   if( fFlagSubDet == "EE" )
00890                                     {cout << fEcalNumbering->
00891                                        GetDeeSCConsFrom1DeeSCEcna(fFileHeader->fStex, fT1d_StexStinFromIndex[i0StexStinEcna])
00892                                           << ", ";}
00893                                 }
00894                               //.................................................... (GetSampleAdcValues)
00895                               if(fFlagPrint == fCodePrintAllComments)
00896                                 {
00897                                   cout << " (" << fStinIndexBuilt << " " << fStinName.Data()
00898                                        << " found), channel " << i0StinEcha << ", i0Sample " << i0Sample << endl;
00899                                 }
00900                               ret_code = kTRUE;
00901                             } // if ( fT1d_StexStinFromIndex[i0StexStinEcna] == fSpecialStexStinNotIndexed )
00902                           else
00903                             {
00904                               cout << "!TEcnaRun::GetSampleAdcValues(...)> *** ERROR ***> NOT ALLOWED if RESULT. " 
00905                                    << " n1StexStin = " << n1StexStin << ", fT1d_StexStinFromIndex["
00906                                    << i0StexStinEcna << "] = "
00907                                    << fT1d_StexStinFromIndex[i0StexStinEcna]
00908                                    << ", fStinIndexBuilt = " << fStinIndexBuilt
00909                                    << fTTBELL << endl;
00910                               ret_code = kFALSE;
00911                             }
00912                         }  //  if (i_trouve != 1 )
00913 
00914                     } //  if( fT1d_StexStinFromIndex != 0 ) 
00915                   else
00916                     {
00917                       cout << "!TEcnaRun, GetSampleAdcValues *** ERROR ***> "
00918                            << " fT1d_StexStinFromIndex = " << fT1d_StexStinFromIndex
00919                            << " fT1d_StexStinFromIndex[] ALLOCATION NOT DONE" << fTTBELL << endl;
00920                       ret_code = kFALSE;
00921                     } //.................................................................. (GetSampleAdcValues)
00922                 } // end of if( i0Sample >= 0 && i0Sample < fNbSampForFic )
00923               else
00924                 {
00925                   //.......Reading data => Message and error only if sample >= fEcal->MaxSampADC()
00926                   //       (not fNbSampForFic, the later is used only for calculations)
00927                   if( i0Sample >= fEcal->MaxSampADC() )
00928                     {
00929                       cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
00930                            << " sample number = " << i0Sample << ". OUT OF BOUNDS"
00931                            << " (max = " << fNbSampForFic << ")"
00932                            << fTTBELL << endl;
00933                       ret_code = kFALSE;
00934                     }
00935                   else
00936                     {
00937                       ret_code = kTRUE;
00938                     }
00939                 }// else of if( i0Sample >= 0 && i0Sample < fNbSampForFic )
00940             } // end of if( i0StinEcha >= 0 && i0StinEcha < fEcal->MaxCrysInStin() )
00941           else
00942             {
00943               cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
00944                    << " channel number in " << fStinName.Data() << " = " << i0StinEcha << ". OUT OF BOUNDS"
00945                    << " (max = " << fEcal->MaxCrysInStin() << ")" 
00946                    << fTTBELL << endl;
00947               ret_code = kFALSE;
00948             } // else of if( i0StinEcha >= 0 && i0StinEcha < fEcal->MaxCrysInStin() )
00949         }
00950       else
00951         {
00952           cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
00953                << fStinName.Data() << " number in " << fStexName.Data() << " = " << n1StexStin << ". OUT OF BOUNDS"
00954                << " (max = " << fEcal->MaxStinEcnaInStex() << ")"
00955                << fTTBELL << endl;
00956           ret_code = kFALSE;
00957         }
00958 
00959       //.................................................................. (GetSampleAdcValues)
00960       //........ Filling of the 2D array of the event numbers in the data reading loop and 
00961       //         filling of the 3D array of the ADC sample values
00962       //
00963       //                           ONLY if ret_code == kTRUE
00964 
00965       if( ret_code == kTRUE )
00966         {
00967           //............ 1) Conversion (Stin,i0StinEcha) -> i0StexEcha  (same numbering for EB and EE)
00968           //==========================================================================================
00969           //   n1StexStin (Tower or SC):      1            2            3
00970           //   iStexStin                      0            1            2 
00971           //
00972           //   i0StinEcha:                 0......24    0......24    0......24
00973           //
00974           //   i0StexEcha         :        0......24   25......49   50......74  grouped by StexStin's
00975           //   i0StexEcha+1 (Xtal):        1......25   26......50   51......75       
00976           //
00977           //==========================================================================================
00978 
00979           Int_t i0StexEcha = i0StexStinEcna*fEcal->MaxCrysInStin() + i0StinEcha;
00980               
00981           //--------------------------------------------------------- (GetSampleAdcValues)
00982           if( i0StexEcha >= 0 && i0StexEcha < fEcal->MaxCrysEcnaInStex() )
00983             {
00984               //............ 2) Increase of the nb of evts for (StexEcha,sample) (events found in the data)
00985               (fT2d_NbOfEvts[i0StexEcha][i0Sample])++;     // value after first incrementation = 1
00986               fTagNbOfEvts[0] = 1;
00987               fFileHeader->fNbOfEvtsCalc = 1;
00988                   
00989               //............ 3) Filling of the 3D array of the ADC values
00990               if ( i0EventIndex >= 0 && i0EventIndex < fFileHeader->fReqNbOfEvts )
00991                 {  
00992                   if( i0Sample >= 0 && i0Sample < fNbSampForFic )
00993                     {
00994                       fT3d_AdcValues[i0StexEcha][i0Sample][i0EventIndex] = adcvalue;
00995                     }
00996                   else
00997                     {
00998                       cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
00999                            << " sample index = " << i0Sample << ". OUT OF BOUNDS"
01000                            << " (max = " << fNbSampForFic << ")"
01001                            << fTTBELL << endl;
01002                     }
01003                 }
01004               else
01005                 {
01006                   cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
01007                        << " event number = " << n1EventNumber << ". OUT OF BOUNDS"
01008                        << " (max = " << fFileHeader->fReqNbOfEvts << ")"
01009                        << fTTBELL << endl;
01010                   ret_code = kFALSE;
01011                 }
01012             }
01013           else
01014             {
01015               cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> "
01016                    << " CHANNEL NUMBER OUT OF BOUNDS" << endl
01017                    << " i0StexEcha number = " << i0StexEcha
01018                    << " , n1StexStin = " << n1StexStin
01019                    << " , i0StinEcha = " << i0StinEcha
01020                    << " , fEcal->MaxCrysEcnaInStex() = " << fEcal->MaxCrysEcnaInStex() 
01021                    << fTTBELL << endl; 
01022               ret_code = kFALSE;
01023               // {Int_t cintoto; cout << "TAPER 0 POUR CONTINUER" << endl; cin >> cintoto;}
01024             }
01025         } // end of if( ret_code == kTRUE )
01026       else
01027         {
01028           cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> ret_code = kFALSE "
01029                << fTTBELL << endl;
01030         }
01031     } // end of if(fReadyToReadData == 1)
01032   else
01033     {
01034       cout << "!TEcnaRun::GetSampleAdcValues(...) *** ERROR ***> GetReadyToReadData(...) not called."
01035            << fTTBELL << endl;
01036       ret_code = kFALSE;
01037     }
01038   //.................................................................. (GetSampleAdcValues)
01039   if (ret_code == kFALSE)
01040     {
01041       cout << "!TEcnaRun::GetSampleAdcValues(...)> *** ERROR ***> ret_code = " << ret_code
01042            << " (FALSE). Event: " << n1EventNumber
01043            << ", " << fStexName.Data() << ": " << fFileHeader->fStex
01044            << ", " << fStinName.Data() << ": " << n1StexStin
01045            << ", channel: " << i0StinEcha
01046            << ", Sample: "   << i0Sample
01047            << ", ADC value: " << adcvalue << endl;
01048     } 
01049   return ret_code;
01050 }
01051 //------------- ( end of GetSampleAdcValues ) -----------------------
01052 //====================================================================================================
01053 //
01054 //  ReadSampleAdcValues: Get the Sample ADC values from file by using TEcnaRead.
01055 //
01056 //====================================================================================================
01057 Bool_t TEcnaRun::ReadSampleAdcValues(){return ReadSampleAdcValues(fEcal->MaxSampADC());}
01058 
01059 Bool_t TEcnaRun::ReadSampleAdcValues(const Int_t& nb_samp_for_calc)
01060 {
01061   // read the Sample ADC values from "ADC" result root files                     (ReadSampleAdcValues)
01062 
01063   // put the number of sample for calculations in attribute fNbSampForCalc
01064   // and call the method without arguments
01065   // We must have: nb_samp_for_calc <= fFileHeader->fNbOfSamples (= nb of samples in ROOT file)
01066 
01067   fNbSampForCalc = nb_samp_for_calc;
01068 
01069 //   TEcnaRead* MyRootFile = new TEcnaRead(fFlagSubDet.Data(), fCnaParPaths, fCnaParCout,
01070 //                                         fFileHeader, fEcalNumbering, fCnaWrite);          //  fCnew++;
01071   
01072   TEcnaRead* MyRootFile = new TEcnaRead(fObjectManager, fFlagSubDet.Data());              //  fCnew++;
01073 
01074   MyRootFile->PrintNoComment();
01075 
01076   MyRootFile->FileParameters(fFileHeader->fTypAna, fFileHeader->fNbOfSamples, fFileHeader->fRunNumber,
01077                              fFileHeader->fFirstReqEvtNumber, fFileHeader->fLastReqEvtNumber,
01078                              fFileHeader->fReqNbOfEvts,       fFileHeader->fStex,
01079                              fCnaParPaths->ResultsRootFilePath().Data());
01080 
01081   Bool_t ok_read = MyRootFile->LookAtRootFile();
01082 
01083   fFileHeader->fStartTime = MyRootFile->GetStartTime();
01084   fFileHeader->fStopTime  = MyRootFile->GetStopTime();
01085   fFileHeader->fStartDate = MyRootFile->GetStartDate();
01086   fFileHeader->fStopDate  = MyRootFile->GetStopDate();
01087   
01088   if ( ok_read == kTRUE )
01089     {
01090       fRootFileName      = MyRootFile->GetRootFileName();
01091       fRootFileNameShort = MyRootFile->GetRootFileNameShort();
01092       cout << "*TEcnaRun::ReadSampleAdcValues> Reading sample ADC values from file: " << endl
01093            << "           " << fRootFileName << endl;
01094       
01095       Int_t i_no_data = 0;
01096 
01097       //.......... Read the StinNumbers in the old file                     (ReadSampleAdcValues)
01098       TVectorD vec(fEcal->MaxStinEcnaInStex());
01099       for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
01100       vec = MyRootFile->ReadStinNumbers(fEcal->MaxStinEcnaInStex());
01101       if( MyRootFile->DataExist() == kTRUE )
01102         {
01103           fTagStinNumbers[0] = 1;
01104           fFileHeader->fStinNumbersCalc = 1;
01105           for(Int_t i0StexStinEcna=0; i0StexStinEcna<fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
01106             {fT1d_StexStinFromIndex[i0StexStinEcna] = (Int_t)vec(i0StexStinEcna);}
01107         }
01108       else
01109         {
01110           i_no_data++;
01111         }
01112       //.......... Read the Numbers of Events in the old file                      (ReadSampleAdcValues)
01113       TMatrixD partial_matrix(fEcal->MaxCrysInStin(), fFileHeader->fNbOfSamples);
01114       for(Int_t i=0; i<fEcal->MaxCrysInStin(); i++)
01115         {for(Int_t j=0; j<fFileHeader->fNbOfSamples; j++){partial_matrix(i,j)=(Double_t)0.;}}
01116 
01117       for(Int_t i0StexStinEcna=0; i0StexStinEcna<fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
01118         {
01119           Int_t n1StexStin = MyRootFile->GetStexStinFromIndex(i0StexStinEcna);
01120           if(n1StexStin != -1)
01121             {
01122               partial_matrix =
01123                 MyRootFile->ReadNumberOfEventsForSamples
01124                 (n1StexStin, fEcal->MaxCrysInStin(), fFileHeader->fNbOfSamples);
01125 
01126               if( MyRootFile->DataExist() == kTRUE )
01127                 {
01128                   fTagNbOfEvts[0] = 1;
01129                   fFileHeader->fNbOfEvtsCalc = 1;
01130                   for(Int_t i0StinCrys=0; i0StinCrys<fEcal->MaxCrysInStin(); i0StinCrys++)
01131                     {
01132                       Int_t i0StexEcha = (n1StexStin-1)*fEcal->MaxCrysInStin() + i0StinCrys;
01133                       for(Int_t i0Sample=0; i0Sample<fFileHeader->fNbOfSamples; i0Sample++)
01134                         {fT2d_NbOfEvts[i0StexEcha][i0Sample] = (Int_t)partial_matrix(i0StinCrys,i0Sample);}
01135                     }
01136                 }
01137               else
01138                 {
01139                   i_no_data++;
01140                 }
01141             }
01142         }
01143 
01144       //.......... Read the Sample ADC values in the old file                     (ReadSampleAdcValues)
01145       Double_t*** fT3d_read_AdcValues =
01146         MyRootFile->ReadSampleAdcValuesSameFile
01147         (fEcal->MaxCrysEcnaInStex(), fFileHeader->fNbOfSamples, fFileHeader->fReqNbOfEvts);
01148       
01149       if( MyRootFile->DataExist() == kTRUE )
01150         {             
01151           for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01152             {
01153               for(Int_t i0Sample=0; i0Sample<fFileHeader->fNbOfSamples;i0Sample++)
01154                 {      
01155                   for(Int_t i_event=0; i_event<fFileHeader->fReqNbOfEvts; i_event++)
01156                     {fT3d_AdcValues[i0StexEcha][i0Sample][i_event] = 
01157                        fT3d_read_AdcValues[i0StexEcha][i0Sample][i_event];}
01158                 }
01159             }
01160         }
01161       else
01162         {
01163           i_no_data++;
01164         }
01165       if( i_no_data != 0 )
01166         {
01167           cout << "!TEcnaRun::ReadSampleAdcValues(...)> *ERROR* =====> "
01168                << " Read failure. i_no_data = " << i_no_data << fTTBELL << endl;  
01169         }
01170     }
01171   else
01172     {
01173       cout << "!TEcnaRun::ReadSampleAdcValues(...)> *ERROR* =====> "
01174            << " ROOT file not found" << fTTBELL << endl;     
01175     }
01176   delete MyRootFile;        //  fCdelete++;
01177   return ok_read;
01178 }
01179 //------------- ( end of ReadSampleAdcValues ) -----------------------
01180 //-------------------------------------------------------------------------
01181 //
01182 //    Get the ROOT file name (long and short)
01183 //
01184 //-------------------------------------------------------------------------
01185 TString TEcnaRun::GetRootFileName(){return fRootFileName;}
01186 TString TEcnaRun::GetRootFileNameShort(){return fRootFileNameShort;}
01187 
01188 //###################################################################################################
01189 //
01190 // THE FOLLOWING METHODS ARE CALLED AFTER THE LOOPS OVER EVENTS, STINS, CRYSTALS AND SAMPLES
01191 //
01192 //###################################################################################################
01193 //=========================================================================
01194 //
01195 //     Set start time, stop time, StartDate, StopDate
01196 //
01197 //=========================================================================
01198 void TEcnaRun::StartStopTime(time_t t_startime, time_t t_stoptime)
01199 {
01200 // Put the start an stop time (if they exist) in fFileHeader class attributes.
01201   
01202   fFileHeader->fStartTime = t_startime;
01203   fFileHeader->fStopTime  = t_stoptime;
01204 }
01205 
01206 void TEcnaRun::StartStopDate(TString c_startdate, TString c_stopdate)
01207 {
01208 // Put the start an stop date (if they exist) in fFileHeader class attributes.
01209 
01210   fFileHeader->fStartDate = c_startdate;
01211   fFileHeader->fStopDate  = c_stopdate;
01212 }
01213 
01214 //=========================================================================
01215 //
01216 //                         GetReadyToCompute()   (technical)
01217 //
01218 //=========================================================================
01219 void TEcnaRun::GetReadyToCompute()
01220 {
01221 //
01222   // MAKE THE RESULTS FILE NAME and
01223   // CHECK OF THE NUMBER OF FOUND EVENTS AND init fNumberOfEvents
01224   // (number used to compute the average values over the events)
01225   // The number of events fNumberOfEvents is extracted from the array fT2d_NbOfEvts[] 
01226   // which has been filled by the GetSampleAdcValues(...) method
01227 
01228   //..................... Making of the Root File name that will be written
01229   fCnaWrite->RegisterFileParameters(fFileHeader->fTypAna.Data(), fFileHeader->fNbOfSamples,
01230                                     fFileHeader->fRunNumber,
01231                                     fFileHeader->fFirstReqEvtNumber, fFileHeader->fLastReqEvtNumber,
01232                                     fFileHeader->fReqNbOfEvts,       fFileHeader->fStex);
01233   
01234   fCnaWrite->fMakeResultsFileName();  // set fRootFileName, fRootFileNameShort
01235 
01236   //..................... Checking numbers of found events channel by channel
01237   if( fT2d_NbOfEvts != 0 )
01238     {
01239       fNumberOfEvents = fCnaWrite->NumberOfEventsAnalysis(fT2d_NbOfEvts, fEcal->MaxCrysEcnaInStex(),
01240                                                           fNbSampForFic, fFileHeader->fReqNbOfEvts);
01241     }
01242   else
01243     {
01244       cout << "*TEcnaRun::GetReadyToCompute()> no data? fT2d_NbOfEvts = " << fT2d_NbOfEvts << endl;
01245     }
01246 }  
01247 //  end of GetReadyToCompute()
01248 
01249 //-------------------------------------------------------------------
01250 //
01251 //                      SampleValues()      (technical)
01252 //
01253 //  Written in .root file corresponding to analysis name
01254 //  beginning with: "Adc" (see EcnaAnalyzer.cc in package "Modules")
01255 //
01256 //-------------------------------------------------------------------
01257 void TEcnaRun::SampleValues()
01258 {
01259 //3D histo of the sample ADC values for all the triples (StexEcha, sample, event)
01260 
01261   // The histo is already in fT3d_AdcValues[][][]
01262   // this method sets the "Tag", increment the "f...Calc" (and must be kept for that)
01263   // f...Calc > 0  => allow writing on file.
01264  
01265   if( fFileHeader->fAdcEvtCalc > 0 ){fFileHeader->fAdcEvtCalc = 0;}
01266   for( Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01267     {fTagAdcEvt[i0StexEcha] = 1;        fFileHeader->fAdcEvtCalc++;}
01268 }
01269 
01270 //=========================================================================
01271 //
01272 //               C A L C U L A T I O N    M E T H O D S
01273 //
01274 //     fTag... = 1 => Calculation done. OK for writing on result file
01275 //     ...Calc++   => Incrementation for result file size. 
01276 //
01277 //=========================================================================
01278 void TEcnaRun::StandardCalculations()
01279 {
01280   SampleMeans();
01281   SampleSigmas();
01282   CorrelationsBetweenSamples();
01283   
01284   Pedestals();                          // => mean over Xtal's
01285   TotalNoise();
01286   LowFrequencyNoise();
01287   HighFrequencyNoise();
01288   MeanCorrelationsBetweenSamples();
01289   SigmaOfCorrelationsBetweenSamples();
01290   
01291   AveragePedestals();                  // Average => mean over Stin's (Tower if EB, SC if EE)
01292   AverageTotalNoise();
01293   AverageLowFrequencyNoise();
01294   AverageHighFrequencyNoise();
01295   AverageMeanCorrelationsBetweenSamples();
01296   AverageSigmaOfCorrelationsBetweenSamples();
01297 }
01298 
01299 void TEcnaRun::Expert1Calculations()
01300 {
01301   // long time, big file
01302 
01303   LowFrequencyCorrelationsBetweenChannels();
01304   HighFrequencyCorrelationsBetweenChannels();
01305 }
01306 
01307 void TEcnaRun::Expert2Calculations()
01308 {
01309   // long time, no big file
01310   // expert 1 is called (if not called before) without writing in file.
01311   // Results are used only in memory to compute expert2 calculations
01312 
01313   LowFrequencyMeanCorrelationsBetweenStins();
01314   HighFrequencyMeanCorrelationsBetweenStins();
01315 }
01316 //====================================================================
01317 //
01318 //       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
01319 // 
01320 //====================================================================
01321 //----------------------------------------------------------------
01322 //  Calculation of the expectation values of the samples
01323 //  for all the StexEchas
01324 //
01325 //  SMean(c,s)  = E_e[A(c,s,e*)]
01326 //  A(c,s,e) : ADC value for channel c, sample s, event e
01327 //  E_e : average over the events
01328 //----------------------------------------------------------------
01329 void TEcnaRun::SampleMeans()
01330 {
01331 // Calculation of the expectation values over events
01332 // for the samples 0 to fNbSampForCalc and for all the StexEchas
01333 
01334   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::SampleMeans() " << endl;}
01335   if(fFlagPrint == fCodePrintAllComments){
01336     cout  << "           Calculation: sample expectation values over the events"
01337           << " for each channel." << endl;}
01338   
01339   //................... Allocation fT2d_ev
01340   if ( fT2d_ev == 0 ){
01341     Int_t n_samp = fNbSampForCalc;
01342     Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
01343     fT2d_ev = new Double_t*[n_StexEcha];             fCnew++;  
01344     fT1d_ev = new  Double_t[n_StexEcha*n_samp];      fCnew++;   
01345     for(Int_t i = 0 ; i < n_StexEcha ; i++){
01346       fT2d_ev[i] = &fT1d_ev[0] + i*n_samp;}
01347   }
01348   //................... init fT2d_ev to zero
01349   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01350     {
01351       for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
01352         {
01353           if( fT2d_ev[i0StexEcha][i0Sample] != (Double_t)0 )
01354             {fMiscDiag[1]++; fT2d_ev[i0StexEcha][i0Sample] = (Double_t)0;}
01355         } 
01356     }
01357   
01358   //................... Calculation
01359   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
01360     {
01361       for (Int_t i0Sample = 0 ; i0Sample < fNbSampForCalc ; i0Sample++)
01362         {
01363           for( Int_t i_event = 0; i_event < fNumberOfEvents; i_event++ )
01364             {
01365               fT2d_ev[i0StexEcha][i0Sample] += fT3d_AdcValues[i0StexEcha][i0Sample][i_event];
01366             }
01367           fT2d_ev[i0StexEcha][i0Sample] /= fNumberOfEvents;
01368         }
01369     }
01370   fTagMSp[0] = 1;        fFileHeader->fMSpCalc++;
01371 }
01372 
01373 //--------------------------------------------------------
01374 //  Calculation of the sigmas of the samples
01375 //  for all the StexEchas
01376 //
01377 //  SSigma(c,s) = sqrt{ Cov_e[A(c,s,e*),A(c,s,e*)] }
01378 //  A(c,s,e) : ADC value for channel c, sample s, event e
01379 //  Cov_e : covariance over the events
01380 //--------------------------------------------------------
01381 void TEcnaRun::SampleSigmas() 
01382 {
01383 //Calculation of the sigmas of the samples for all the StexEchas
01384   
01385   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::SampleSigmas()" << endl;}
01386   if(fFlagPrint == fCodePrintAllComments){
01387     cout << "           Calculation: sample ADC sigmas over the events "
01388          << " for each channel." << endl;}
01389   
01390   //... preliminary calculation of the expectation values if not done yet.
01391   //    The tag is set to 1 after call to the method. It is reset to 0
01392   //    because the expectation values must not be written in the result ROOT file
01393   //    (since the tag was equal to 0)
01394   if(fTagMSp[0] != 1){SampleMeans(); fTagMSp[0] = 0;}
01395 
01396   //................... Allocation fT2d_sig
01397   if( fT2d_sig == 0){
01398     Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
01399     Int_t n_samp = fNbSampForCalc;
01400     fT2d_sig = new Double_t*[n_StexEcha];                fCnew++;        
01401     fT1d_sig = new  Double_t[n_StexEcha*n_samp];         fCnew++;  
01402     for(Int_t i0StexEcha = 0 ; i0StexEcha < n_StexEcha ; i0StexEcha++){
01403       fT2d_sig[i0StexEcha] = &fT1d_sig[0] + i0StexEcha*n_samp;}
01404   }
01405   // ................... init fT2d_sig to zero
01406   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01407     {
01408       for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
01409         {
01410           if( fT2d_sig[i0StexEcha][i0Sample] != (Double_t)0 )
01411             {fMiscDiag[2]++; fT2d_sig[i0StexEcha][i0Sample] = (Double_t)0;}
01412         } 
01413     }
01414   
01415   //................... Calculation
01416   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
01417     {
01418       for (Int_t i0Sample = 0 ; i0Sample < fNbSampForCalc ; i0Sample++)
01419         {
01420           Double_t variance = (Double_t)0.;
01421           for( Int_t i_event = 0; i_event < fNumberOfEvents; i_event++ )
01422             {
01423               Double_t ecart = fT3d_AdcValues[i0StexEcha][i0Sample][i_event] - fT2d_ev[i0StexEcha][i0Sample];
01424               variance += ecart*ecart;
01425             }
01426           variance /= fNumberOfEvents;
01427           fT2d_sig[i0StexEcha][i0Sample] = sqrt(variance);
01428         }
01429     }
01430   fTagSSp[0] = 1;        fFileHeader->fSSpCalc++;
01431 }
01432 
01433 //====================================================================
01434 //
01435 //       C O V A R I A N C E S   &   C O R R E L A T I O N S
01436 //
01437 //                 B E T W E E N   S A M P L E S
01438 //
01439 //====================================================================
01440 //-----------------------------------------------------------
01441 //  Calculation of the covariances between samples
01442 //  for all the StexEchas
01443 //  Cov(c;s,s') = Cov_e[ A(c,s,e*) , A(c,s',e*) ]
01444 //              = E_e[ ( A(c,s,e*) - E_e[A(c,s,e*)] )*
01445 //                     ( A(c,s',e*) - E_e[A(c,s',e*)] ) ]
01446 //  A(c,s,e)    : ADC value for channel c, sample s, event e
01447 //  E_e , Cov_e : average, covariance over the events
01448 //-----------------------------------------------------------
01449 void TEcnaRun::CovariancesBetweenSamples()
01450 {
01451   //Calculation of the covariances between samples for all the StexEchas
01452   
01453   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::CovariancesBetweenSamples()" << endl;}
01454   if(fFlagPrint == fCodePrintAllComments){
01455     cout << "           Calculation: covariances between samples"
01456          << " for each channel." << endl;}
01457   
01458   //................... Allocations cov_ss
01459   if( fT3d_cov_ss == 0 ){
01460     const Int_t n_samp = fNbSampForCalc;
01461     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
01462     fT3d_cov_ss  = new Double_t**[n_StexEcha];                fCnew++;  
01463     fT3d2_cov_ss = new  Double_t*[n_StexEcha*n_samp];         fCnew++;  
01464     fT3d1_cov_ss = new   Double_t[n_StexEcha*n_samp*n_samp];  fCnew++;  
01465     for(Int_t i = 0 ; i < n_StexEcha ; i++){
01466       fT3d_cov_ss[i] = &fT3d2_cov_ss[0] + i*n_samp;
01467       for(Int_t j = 0 ; j < n_samp ; j++){
01468         fT3d2_cov_ss[n_samp*i+j] = &fT3d1_cov_ss[0]+n_samp*(n_samp*i+j);}}
01469   }
01470   
01471   //.................. Calculation (= init)
01472   //.................. computation of half of the matrix, diagonal included)
01473 
01474   //... preliminary calculation of the expectation values if not done yet.
01475   //    The tag is set to 1 after call to the method. It is reset to 0
01476   //    because the expectation values must not be written in the result ROOT file
01477   //    (since the tag was equal to 0)
01478   //    Results in array  fT2d_ev[j0StexEcha][i0Sample]
01479   if(fTagMSp[0] != 1){SampleMeans(); fTagMSp[0] = 0;}
01480 
01481 
01482   for (Int_t j0StexEcha = 0 ; j0StexEcha < fEcal->MaxCrysEcnaInStex() ; j0StexEcha++)
01483     {
01484       for (Int_t i0Sample = 0 ; i0Sample < fNbSampForCalc ; i0Sample++)
01485         {
01486           for (Int_t j0Sample = 0 ; j0Sample <= i0Sample; j0Sample++)
01487             {
01488               fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample] = (Double_t)0;
01489               for( Int_t i_event = 0; i_event < fNumberOfEvents; i_event++ )
01490                 {
01491                   fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample] +=
01492                     (fT3d_AdcValues[j0StexEcha][i0Sample][i_event] - fT2d_ev[j0StexEcha][i0Sample])
01493                     *(fT3d_AdcValues[j0StexEcha][j0Sample][i_event] - fT2d_ev[j0StexEcha][j0Sample]);
01494                 }
01495               fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample] /= (Double_t)fNumberOfEvents;
01496               fT3d_cov_ss[j0StexEcha][j0Sample][i0Sample] = fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample];
01497             }
01498         }
01499       fTagCovCss[j0StexEcha] = 1;     fFileHeader->fCovCssCalc++;
01500     }
01501 }
01502 
01503 //-----------------------------------------------------------
01504 //
01505 //  Calculation of the correlations between samples
01506 //  for all the StexEchas
01507 //  Cor(c;s,s') = Cov(c;s,s')/sqrt{ Cov(c;s,s)*Cov(c;s',s') }
01508 //-----------------------------------------------------------
01509 void TEcnaRun::CorrelationsBetweenSamples()
01510 {
01511 //Calculation of the correlations between samples for all the StexEchas
01512 
01513   //... preliminary calculation of the covariances if not done yet.
01514   //    Test only the first tag since the cov are computed globaly
01515   //    but set all the tags to 0 because we don't want to write
01516   //    the covariances in the result ROOT file    
01517   if ( fTagCovCss[0] != 1 ){CovariancesBetweenSamples();
01518   for (Int_t j0StexEcha = 0 ; j0StexEcha < fEcal->MaxCrysEcnaInStex() ; j0StexEcha++)
01519     {fTagCovCss[j0StexEcha] = 0;}}
01520   
01521   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::CorrelationsBetweenSamples()" << endl;}
01522   if(fFlagPrint == fCodePrintAllComments){
01523     cout << "           Calculation: correlations between samples"
01524          << " for each channel." << endl;}
01525 
01526   //................... Allocations cor_ss
01527   if( fT3d_cor_ss == 0){
01528     const Int_t n_samp = fNbSampForCalc;
01529     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
01530     fT3d_cor_ss  = new Double_t**[n_StexEcha];                fCnew++;  
01531     fT3d2_cor_ss = new  Double_t*[n_StexEcha*n_samp];         fCnew++;  
01532     fT3d1_cor_ss = new   Double_t[n_StexEcha*n_samp*n_samp];  fCnew++;  
01533     for(Int_t i = 0 ; i < n_StexEcha ; i++){
01534       fT3d_cor_ss[i] = &fT3d2_cor_ss[0] + i*n_samp;
01535       for(Int_t j = 0 ; j < n_samp ; j++){
01536         fT3d2_cor_ss[n_samp*i+j] = &fT3d1_cor_ss[0]+n_samp*(n_samp*i+j);}}
01537   }
01538   
01539   //..................... calculation of the correlations (=init)
01540   //......................computation of half of the matrix, diagonal included (verif = 1)
01541     
01542  for (Int_t j0StexEcha = 0 ; j0StexEcha < fEcal->MaxCrysEcnaInStex() ; j0StexEcha++)
01543    {
01544      for (Int_t i0Sample = 0 ; i0Sample < fNbSampForCalc ; i0Sample++)
01545        {
01546          for (Int_t j0Sample = 0 ; j0Sample <= i0Sample ; j0Sample++)
01547            {
01548              if( (fT3d_cov_ss[j0StexEcha][i0Sample][i0Sample] > 0) &&
01549                  (fT3d_cov_ss[j0StexEcha][j0Sample][j0Sample] > 0) )
01550                {
01551                  fT3d_cor_ss[j0StexEcha][i0Sample][j0Sample] = fT3d_cov_ss[j0StexEcha][i0Sample][j0Sample]/
01552                    ( sqrt(fT3d_cov_ss[j0StexEcha][i0Sample][i0Sample])*sqrt(fT3d_cov_ss[j0StexEcha][j0Sample][j0Sample]) );
01553                }
01554              else
01555                {
01556                  (fT3d_cor_ss)[j0StexEcha][i0Sample][j0Sample] = (Double_t)0; // prevoir compteur + fTTBELL
01557                }
01558              fT3d_cor_ss[j0StexEcha][j0Sample][i0Sample] = fT3d_cor_ss[j0StexEcha][i0Sample][j0Sample];
01559            }
01560        }
01561      fTagCorCss[j0StexEcha] = 1;          fFileHeader->fCorCssCalc++;
01562    }
01563 }
01564 
01565 //===========================================================================
01566 //
01567 //     M E A N   P E D E S T A L S ,   T O T A L    N O I S E ,
01568 //     L O W     F R E Q U E N C Y    N O I S E , 
01569 //     H I G H   F R E Q U E N C Y    N O I S E 
01570 //     M E A N   O F  C O R ( S , S ),  S I G M A   O F  C O R ( S , S )
01571 //
01572 //===========================================================================
01573 //-------------------------------------------------------------------------
01574 //
01575 //  Calculation of the Pedestals for each channel in Stex
01576 //  tag: Ped
01577 //  Pedestal(c ) = E_e[ E_s[A(c ,s*,e*)] ]
01578 //  A(c,s,e) : ADC value for channel c, sample s, event e
01579 //  E_e : average over the events
01580 //  E_s : average over the samples
01581 //      
01582 //-------------------------------------------------------------------------
01583 void TEcnaRun::Pedestals()
01584 {
01585 // Calculation, for each channel, of the expectation values
01586 // (over the samples 0 to fNbSampForCalc-1) of the ADC expectation values 
01587 // (over the events)
01588 
01589   //... preliminary calculation of the expectation values if not done yet
01590   if ( fTagMSp[0] != 1 ){SampleMeans(); fTagMSp[0]=0;}
01591 
01592   //................... Allocation ev_ev + init to zero (mandatory)
01593   if( fT1d_ev_ev == 0 ){fT1d_ev_ev = new Double_t[fEcal->MaxCrysEcnaInStex()]; fCnew++;}
01594   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01595     {if( fT1d_ev_ev[i0StexEcha] != (Double_t)0 )
01596       {fMiscDiag[11]++; fT1d_ev_ev[i0StexEcha] = (Double_t)0;}}
01597   
01598   //..................... Calculation
01599   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::Pedestals()" << endl;}
01600   if(fFlagPrint == fCodePrintAllComments){
01601     cout << "           Calculation, for all the channels, of the expectation values (over the samples 1 to "
01602          << fNbSampForCalc << ")" << endl
01603          << "          of the ADC expectation values (over the events)." << endl;}
01604   
01605   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01606     {     
01607       for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++)
01608         {
01609           fT1d_ev_ev[i0StexEcha] += fT2d_ev[i0StexEcha][i0Sample];
01610         }
01611       fT1d_ev_ev[i0StexEcha] /= fNbSampForCalc;
01612     }
01613   fTagPed[0] = 1;                      fFileHeader->fPedCalc++;
01614 }
01615 //------------------------ (end of Pedestals) ----------------------------
01616 
01617 //------------------------------------------------------------------------------
01618 //
01619 //  Calculation of the TN (Total Noise)
01620 //  tag: Tno
01621 //    
01622 //  TotalNoise(c)  = E_s[ sqrt{ E_e[ ( A(c ,s*,e*) - E_e[A(c ,s*,e*)] )^2 ] } ]
01623 //  A(c,s,e) : ADC value for channel c, sample s, event e
01624 //  E_e : average over the events
01625 //  E_s : average over the samples
01626 //
01627 //------------------------------------------------------------------------------
01628 void TEcnaRun::TotalNoise()
01629 {
01630 // Calculation, for each channel, of the expectation values
01631 // (over the samples 0 to fNbSampForCalc-1) of the sigmas 
01632 // (over the events)
01633 
01634   //... preliminary calculation of the sigmas if not done yet
01635   if ( fTagSSp[0] != 1 ){SampleSigmas(); fTagSSp[0]=0;}
01636 
01637   //................... Allocation ev_ev + init to zero (mandatory)
01638   if( fT1d_evsamp_of_sigevt == 0 ){fT1d_evsamp_of_sigevt = new Double_t[fEcal->MaxCrysEcnaInStex()]; fCnew++;}
01639   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01640     {if( fT1d_evsamp_of_sigevt[i0StexEcha] != (Double_t)0 )
01641       {fMiscDiag[12]++; fT1d_evsamp_of_sigevt[i0StexEcha] = (Double_t)0;}}
01642   
01643   //..................... Calculation
01644   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::TotalNoise()" << endl;}
01645   if(fFlagPrint == fCodePrintAllComments){
01646     cout << "           Calculation, for all the channels, of the expectation values (over the samples 1 to "
01647          << fNbSampForCalc << ")" << endl
01648          << "          of the ADC expectation values (over the events)." << endl;}
01649 
01650   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01651     {     
01652       for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++)
01653         {
01654           if( fT2d_sig[i0StexEcha][i0Sample] < 0)
01655             {
01656               cout << "!TEcnaRun::TotalNoise() *** ERROR ***> Negative sigma!"
01657                    << fTTBELL << endl;
01658             }
01659           else
01660             {
01661               fT1d_evsamp_of_sigevt[i0StexEcha] += fT2d_sig[i0StexEcha][i0Sample];
01662             }
01663         }
01664       fT1d_evsamp_of_sigevt[i0StexEcha] /= fNbSampForCalc;
01665     }
01666   fTagTno[0] = 1;                     fFileHeader->fTnoCalc++;
01667 }
01668 //------------------------ (end of TotalNoise) ----------------------------
01669 
01670 //---------------------------------------------------------------------------------
01671 //
01672 //  Calculation of the LFN  (Low Frequency Noise)
01673 //  tag: Lfn
01674 //
01675 //  LowFqNoise(c) = sqrt{ E_e[ ( E_s[A(c ,s*,e*)] - E_e[ E_s[A(c ,s*,e*)] ] )^2 ] }
01676 //  A(c,s,e) : ADC value for channel c, sample s, event e
01677 //  E_e : average over the events
01678 //  E_s : average over the samples
01679 //
01680 //---------------------------------------------------------------------------------
01681 void TEcnaRun::LowFrequencyNoise()
01682 {
01683 // Calculation, for each channel, of the sigma (over the events)
01684 // of the ADC expectation values (over the samples 0 to fNbSampForCalc-1)
01685 
01686   //................... Allocation fT1d_sigevt_of_evsamp + init to zero (mandatory)
01687   if( fT1d_sigevt_of_evsamp == 0 ){
01688     fT1d_sigevt_of_evsamp = new Double_t[fEcal->MaxCrysEcnaInStex()];              fCnew++;  
01689   }
01690   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01691     {
01692       if( fT1d_sigevt_of_evsamp[i0StexEcha] != (Double_t)0 )
01693         {fMiscDiag[13]++; fT1d_sigevt_of_evsamp[i0StexEcha] = (Double_t)0;}
01694     }
01695 
01696   //................... Allocation mean_over_samples
01697   TVectorD  mean_over_samples(fNumberOfEvents);
01698   for(Int_t i=0; i<fNumberOfEvents; i++){mean_over_samples(i)=(Double_t)0.;}
01699 
01700   //..................... Calculation
01701   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::LowFrequencyNoise()" << endl;}
01702   if(fFlagPrint == fCodePrintAllComments){
01703     cout << "           Calculation, for each channel, of the sigma (over the events)" << endl
01704          << "           of the ADC expectation values (over the samples 1 to "
01705          <<  fNbSampForCalc << ")." << endl;}
01706 
01707   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01708     {
01709       // Calculation of the mean over the events of the mean over the samples
01710       Double_t mean_over_events = (Double_t)0;
01711       for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
01712         {
01713           // Calculation, for each event, of the mean over the samples  
01714           mean_over_samples(n_event) = (Double_t)0.;
01715           for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
01716             {
01717               mean_over_samples(n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];
01718             }
01719           mean_over_samples(n_event) /= (Double_t)fNbSampForCalc;
01720 
01721           mean_over_events += mean_over_samples(n_event);
01722         }
01723        mean_over_events /= (Double_t)fNumberOfEvents;
01724        
01725        // Calculation of the sigma over the events of the mean over the samples
01726        Double_t var = (Double_t)0;
01727        for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
01728          {
01729           Double_t ecart =  mean_over_samples(n_event) - mean_over_events;
01730           var += ecart*ecart;
01731          }
01732        var /= (Double_t)fNumberOfEvents;
01733        
01734        fT1d_sigevt_of_evsamp[i0StexEcha] = sqrt(var);
01735     }
01736   fTagLfn[0] = 1;                      fFileHeader->fLfnCalc++;
01737 }
01738 //------------------------ (end of LowFrequencyNoise) ----------------------------
01739 
01740 //---------------------------------------------------------------------------------
01741 //
01742 //  Calculation of the HFN  (High Frequency Noise)
01743 //  tag: Hfn
01744 //
01745 //  HighFqNoise(c) = E_e[ sqrt{ E_s[ (A(c ,s*,e*) - E_s[A(c ,s*,e*)] )^2 ] } ]
01746 //  A(c,s,e) : ADC value for channel c, sample s, event e
01747 //  E_e : average over the events
01748 //  E_s : average over the samples
01749 //
01750 //---------------------------------------------------------------------------------
01751 void TEcnaRun::HighFrequencyNoise()
01752 {
01753 // Calculation, for each channel, of the mean (over the events)
01754 // of the ADC sigmas (over the samples 0 to fNbSampForCalc-1)
01755 
01756   //................... Allocation fT1d_evevt_of_sigsamp + init to zero (mandatory)
01757   if( fT1d_evevt_of_sigsamp == 0 ){
01758     fT1d_evevt_of_sigsamp = new Double_t[fEcal->MaxCrysEcnaInStex()];              fCnew++;  
01759   }
01760   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01761     {
01762       if( fT1d_evevt_of_sigsamp[i0StexEcha] != (Double_t)0 )
01763         {fMiscDiag[14]++; fT1d_evevt_of_sigsamp[i0StexEcha] = (Double_t)0;}
01764     }
01765 
01766   //................... Allocations mean_over_samples, sigma_over_sample
01767   TVectorD  mean_over_samples(fNumberOfEvents);
01768   for(Int_t i=0; i<fNumberOfEvents; i++){mean_over_samples(i)=(Double_t)0.;} 
01769   TVectorD  sigma_over_samples(fNumberOfEvents);
01770   for(Int_t i=0; i<fNumberOfEvents; i++){sigma_over_samples(i)=(Double_t)0.;}
01771 
01772   //..................... Calculation
01773   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::HighFrequencyNoise()" << endl;}
01774   if(fFlagPrint == fCodePrintAllComments){
01775     cout << "           Calculation, for each channel, of the sigma (over the events)" << endl
01776          << "           of the ADC expectation values (over the samples 1 to "
01777          <<  fNbSampForCalc << ")." << endl;}
01778 
01779   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01780     {
01781       //..................... Calculation of the sigma over samples
01782       for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
01783         {
01784           // Calculation, for each event, of the mean over the samples  
01785           mean_over_samples(n_event) = (Double_t)0.;
01786           for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
01787             {mean_over_samples(n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];}
01788           mean_over_samples(n_event) /= (Double_t)fNbSampForCalc;
01789           
01790           // Calculation, for each event, of the sigma over the samples
01791           Double_t var_over_samples =  (Double_t)0;
01792           for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
01793             {Double_t deviation = fT3d_AdcValues[i0StexEcha][i0Sample][n_event] - mean_over_samples(n_event);
01794             var_over_samples += deviation*deviation;}
01795           var_over_samples /= (Double_t)fNbSampForCalc;
01796           
01797           if( var_over_samples < 0)
01798             {cout << "!TEcnaRun::HighFrequencyNoise() *** ERROR ***> Negative variance! " << fTTBELL << endl;}
01799           else
01800             {sigma_over_samples(n_event) = sqrt(var_over_samples);}
01801         }
01802 
01803       //....... Calculation of the mean over the events of the sigma over samples
01804       for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
01805         {fT1d_evevt_of_sigsamp[i0StexEcha] += sigma_over_samples(n_event);}
01806 
01807       fT1d_evevt_of_sigsamp[i0StexEcha] /= (Double_t)fNumberOfEvents;
01808     }
01809   fTagHfn[0] = 1;                      fFileHeader->fHfnCalc++;
01810 }
01811 //------------------------ (end of HighFrequencyNoise) ----------------------------
01812 
01813 //-------------------------------------------------------------------------
01814 //
01815 //  Calculation of the expectation values of (sample,sample)
01816 //  correlations for all the channels (mean cor(s,s))
01817 //  tag: MeanCorss
01818 //
01819 //  MeanCorss(c)   = E_s,s'[ Cor(c;s,s') ]
01820 //  E_s,s': average  over couples of samples (half correlation matrix)
01821 //
01822 //-------------------------------------------------------------------------
01823 void TEcnaRun::MeanCorrelationsBetweenSamples()
01824 {
01825   // Calculation, for all the channels, of the expectation values
01826   // of the correlations between the first fNbSampForCalc samples
01827   
01828   //... preliminary calculation of the correlations if not done yet
01829   //    (test only the first element since the cor are computed globaly)
01830   if ( fTagCorCss[0] != 1 ){CorrelationsBetweenSamples(); fTagCorCss[0]=0;}
01831 
01832   //................... Allocations ev_cor_ss + init to zero (mandatory)
01833   if( fT1d_ev_cor_ss == 0 ){
01834     Int_t n_StexEcha =  fEcal->MaxCrysEcnaInStex();
01835     fT1d_ev_cor_ss = new Double_t[n_StexEcha];               fCnew++;  
01836   }
01837   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01838     {
01839       if( fT1d_ev_cor_ss[i0StexEcha] != (Double_t)0 )
01840         {fMiscDiag[15]++; fT1d_ev_cor_ss[i0StexEcha] = (Double_t)0;}
01841     }
01842   
01843   //.......... 1D array half_cor_ss[N(N-1)/2] to put the N (sample,sample) correlations
01844   //           ( half of (them minus the diagonal) ) 
01845   Int_t ndim = (Int_t)(fNbSampForCalc*(fNbSampForCalc - 1)/2);
01846 
01847   TVectorD  half_cor_ss(ndim); for(Int_t i=0; i<ndim; i++){half_cor_ss(i)=(Double_t)0.;}
01848 
01849   //..................... Calculation
01850   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::MeanCorrelationsBetweenSamples()" << endl;}
01851   if(fFlagPrint == fCodePrintAllComments){
01852     cout << "           Calculation, for all the channels, of the expectation values of the" << endl
01853          << "           correlations between the first " << fNbSampForCalc << " samples." << endl;}
01854 
01855   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01856     {
01857       //..................... half_cor_ss() array filling
01858       Int_t i_count = 0;
01859       for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++)
01860         {
01861           for (Int_t j0Sample = 0; j0Sample < i0Sample; j0Sample++)
01862             {
01863               half_cor_ss(i_count) = fT3d_cor_ss[i0StexEcha][i0Sample][j0Sample];
01864               i_count++;
01865             }
01866         }
01867       //...................... mean cor(s,s') calculation
01868       fT1d_ev_cor_ss[i0StexEcha] = (Double_t)0;
01869       for(Int_t i_rcor = 0; i_rcor < ndim; i_rcor++)
01870         {
01871           fT1d_ev_cor_ss[i0StexEcha] += half_cor_ss(i_rcor);
01872         }
01873       fT1d_ev_cor_ss[i0StexEcha] /= (Double_t)ndim;
01874     }
01875   fTagMeanCorss[0] = 1;               fFileHeader->fMeanCorssCalc++;
01876 }
01877 //--------------- (end of MeanCorrelationsBetweenSamples) -----------
01878 
01879 //-------------------------------------------------------------------------
01880 //
01881 // Calculation of the sigmas of the (sample,sample) correlations
01882 // for all the channels (sigma of cor(s,s))
01883 // tag: SigCorss
01884 //
01885 // SigmaCorss(c)  = E_s,s'[ Cor(c;s,s') - E_s,s'[ Cor(c;s,s') ] ]
01886 // E_s,s': average  over couples of samples (half correlation matrix)
01887 //
01888 //--------------------------------------------------------------------------
01889 void  TEcnaRun::SigmaOfCorrelationsBetweenSamples()
01890 {
01891   //Calculation of the sigmas of the (sample,sample) correlations for all the StexEchas
01892  
01893   //... preliminary calculation of the mean cor(s,s') if not done yet
01894   //    (test only the first element since the cor are computed globaly)
01895   //    Results available in array fT1d_ev_cor_ss[i0StexEcha]
01896   if ( fTagMeanCorss[0] != 1 ){MeanCorrelationsBetweenSamples(); fTagMeanCorss[0]=0;}
01897 
01898   //................... Allocations sig_cor_ss + init to zero
01899   if( fT1d_sig_cor_ss == 0 ){
01900     Int_t n_StexEcha =  fEcal->MaxCrysEcnaInStex();
01901     fT1d_sig_cor_ss = new Double_t[n_StexEcha];                fCnew++;  
01902   }
01903   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01904     {
01905       if( fT1d_sig_cor_ss[i0StexEcha] != (Double_t)0 )
01906         {fMiscDiag[16]++; fT1d_sig_cor_ss[i0StexEcha] = (Double_t)0;}
01907     }
01908 
01909   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::SigmasOfCorrelationsBetweenSamples()" << endl;}
01910   if(fFlagPrint == fCodePrintAllComments){
01911     cout << "           Calculation of the sigmas of the (sample,sample)" << endl
01912          << "           correlations for all the channels." << endl;}
01913 
01914   //.......... 1D array half_cor_ss[N(N-1)/2] to put the N (sample,sample) correlations
01915   //           (half of them minus the diagonal)
01916   Int_t ndim = (Int_t)(fNbSampForCalc*(fNbSampForCalc - 1)/2);
01917 
01918   TVectorD  half_cor_ss(ndim); for(Int_t i=0; i<ndim; i++){half_cor_ss(i)=(Double_t)0.;}
01919 
01920   //.................. Calculation
01921   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
01922     {
01923       //..................... half_cor_ss() array filling
01924       Int_t i_count = 0;
01925       for (Int_t i0Sample = 0; i0Sample < fNbSampForCalc; i0Sample++)
01926         {
01927           for (Int_t j0Sample = 0; j0Sample < i0Sample; j0Sample++)
01928             {
01929               half_cor_ss(i_count) = fT3d_cor_ss[i0StexEcha][i0Sample][j0Sample];
01930               i_count++;
01931             }
01932         }
01933 
01934       //...................... sigma of cor(s,s') calculation
01935       Double_t var = (Double_t)0;
01936       for(Int_t i_rcor = 0; i_rcor < ndim; i_rcor++)
01937         {
01938           Double_t ecart = half_cor_ss(i_rcor) - fT1d_ev_cor_ss[i0StexEcha];
01939           var += ecart*ecart;
01940         }
01941       var /= (Double_t)ndim;
01942       fT1d_sig_cor_ss[i0StexEcha] = sqrt(var);
01943     }
01944   fTagSigCorss[0] = 1;              fFileHeader->fSigCorssCalc++;
01945 }
01946 //--------------- (end of SigmaOfCorrelationsBetweenSamples) -----------
01947 
01948 //-----------------------------------------------------------------------------
01949 //
01950 //  Calculation of the average Pedestals for each Stin in Stex
01951 //  tag: AvPed
01952 //      
01953 //-----------------------------------------------------------------------------
01954 void TEcnaRun::AveragePedestals()
01955 {
01956 // Calculation of the average 
01957 // (over the Stin's 0 to fEcal->MaxStinInStex()) of the Pedestals
01958 
01959   //... preliminary calculation of the Pedestals if not done yet
01960   if ( fTagPed[0] != 1 ){Pedestals(); fTagPed[0]=0;}
01961   //................... Allocation av_mped + init to zero (mandatory)
01962   if( fT1d_av_mped == 0 ){fT1d_av_mped = new Double_t[fEcal->MaxStinEcnaInStex()]; fCnew++;}
01963   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
01964     {if( fT1d_av_mped[i0StexStinEcna] != (Double_t)0 )
01965       {fMiscDiag[41]++; fT1d_av_mped[i0StexStinEcna] = (Double_t)0;}}
01966  
01967   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::AveragePedestals()" << endl;}
01968   if(fFlagPrint == fCodePrintAllComments){
01969     cout << "           Calculation, for all the "
01970          << fStinName.Data() << "s, of the average Pedestals" << endl;}
01971 
01972   //................... Calculation
01973   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
01974     {
01975       Int_t n1StexStinEcna = i0StexStinEcna+1;
01976       fT1d_av_mped[i0StexStinEcna] = (Double_t)0;
01977       for(Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++)
01978         {
01979           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
01980 
01981           if( fStexName == "SM " )
01982             {fT1d_av_mped[i0StexStinEcna] += fT1d_ev_ev[i0StexEcha];}
01983 
01984           if( fStexName == "Dee" )
01985             {
01986               //---------------- Special translation for mixed SCEcna (29 and 32)
01987               //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
01988               //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
01989               Int_t n1StinEcha = i0StinEcha+1;
01990               if( n1StexStinEcna == 10 && n1StinEcha == 11 )
01991                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);}
01992               if( n1StexStinEcna == 11 && n1StinEcha == 11 )
01993                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);}
01994               if( !( (n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11 )  )
01995                 {fT1d_av_mped[i0StexStinEcna] += fT1d_ev_ev[i0StexEcha];}
01996             }
01997         }
01998       Double_t xdivis = (Double_t)0.;
01999       if( fStexName == "SM "  )
02000         {xdivis = (Double_t)fEcal->MaxCrysInStin();}
02001       if( fStexName == "Dee" )
02002         {xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");}
02003       
02004       fT1d_av_mped[i0StexStinEcna] = fT1d_av_mped[i0StexStinEcna]/xdivis;
02005     }
02006   
02007   fTagAvPed[0] = 1;                      fFileHeader->fAvPedCalc++;
02008 }
02009 //-----------------------------------------------------------------------------
02010 //
02011 // Calculation of the average total noise for each Stin in Stex
02012 // tag: AvTno
02013 //      
02014 //-----------------------------------------------------------------------------
02015 void TEcnaRun::AverageTotalNoise()
02016 {
02017 // Calculation of the average 
02018 // (over the Stin's 0 to fEcal->MaxStinInStex()) of the Total Noise
02019   
02020   //... preliminary calculation of the averaged Total Noise if not done yet
02021   if ( fTagTno[0] != 1 ){TotalNoise(); fTagTno[0]=0;}
02022   //................... Allocation av_totn + init to zero (mandatory)
02023   if( fT1d_av_totn == 0 ){fT1d_av_totn = new Double_t[fEcal->MaxStinEcnaInStex()]; fCnew++;}
02024   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02025     {if( fT1d_av_totn[i0StexStinEcna] != (Double_t)0 )
02026       {fMiscDiag[42]++; fT1d_av_totn[i0StexStinEcna] = (Double_t)0;}}
02027 
02028   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::AverageTotalNoise()" << endl;}
02029   if(fFlagPrint == fCodePrintAllComments){
02030     cout << "           Calculation, for all the "
02031          << fStinName.Data() << "s, of the average total Noise" << endl;}
02032 
02033   //................... Calculation
02034   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02035     {
02036       Int_t n1StexStinEcna = i0StexStinEcna+1;
02037       fT1d_av_totn[i0StexStinEcna] = (Double_t)0;
02038       for(Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++)
02039         {
02040           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
02041           
02042           if( fStexName == "SM " )
02043             {fT1d_av_totn[i0StexStinEcna] += fT1d_evsamp_of_sigevt[i0StexEcha];}
02044           
02045           if( fStexName == "Dee" )
02046             {
02047               //---------------- Special translation for mixed SCEcna (29 and 32)
02048               //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
02049               //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
02050               Int_t n1StinEcha = i0StinEcha+1;
02051               if( n1StexStinEcna == 10 && n1StinEcha == 11 )
02052                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);}
02053               if( n1StexStinEcna == 11 && n1StinEcha == 11 )
02054                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);}
02055               if( !( (n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11 )  )
02056                 {fT1d_av_totn[i0StexStinEcna] += fT1d_evsamp_of_sigevt[i0StexEcha];}
02057             }
02058         }
02059       Double_t xdivis = (Double_t)0.;
02060       if( fStexName == "SM "  )
02061         {xdivis = (Double_t)fEcal->MaxCrysInStin();}
02062       if( fStexName == "Dee" )
02063         {xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");}
02064       
02065       fT1d_av_totn[i0StexStinEcna] = fT1d_av_totn[i0StexStinEcna]/xdivis;
02066     }
02067   fTagAvTno[0] = 1;                      fFileHeader->fAvTnoCalc++;
02068 }
02069 //-----------------------------------------------------------------------------
02070 //
02071 // Calculation of the average Low Frequency noise for each Stin in Stex
02072 // tag: AvLfn
02073 //      
02074 //-----------------------------------------------------------------------------
02075 void TEcnaRun::AverageLowFrequencyNoise()
02076 {
02077 // Calculation of the average 
02078 // (over the Stin's 0 to fEcal->MaxStinInStex()) of the Low Frequency Noise
02079   
02080   //... preliminary calculation of the Low Frequency Noise if not done yet
02081   if ( fTagLfn[0] != 1 ){LowFrequencyNoise(); fTagLfn[0]=0;}
02082   //................... Allocation av_lofn + init to zero (mandatory)
02083   if( fT1d_av_lofn == 0 ){fT1d_av_lofn = new Double_t[fEcal->MaxStinEcnaInStex()]; fCnew++;}
02084   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02085     {if( fT1d_av_lofn[i0StexStinEcna] != (Double_t)0 )
02086       {fMiscDiag[43]++; fT1d_av_lofn[i0StexStinEcna] = (Double_t)0;}}
02087 
02088   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::AverageLowFrequencyNoise()" << endl;}
02089   if(fFlagPrint == fCodePrintAllComments){
02090     cout << "           Calculation, for all the "
02091          << fStinName.Data() << "s, of the average Low Frequency Noise" << endl;}
02092 
02093   //................... Calculation
02094   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02095     {
02096       Int_t n1StexStinEcna = i0StexStinEcna+1;
02097       fT1d_av_lofn[i0StexStinEcna] = (Double_t)0;
02098       for(Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++)
02099         {
02100           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
02101 
02102           if( fStexName == "SM " )
02103             {fT1d_av_lofn[i0StexStinEcna] += fT1d_sigevt_of_evsamp[i0StexEcha];}
02104           
02105           if( fStexName == "Dee" )
02106             {
02107               //---------------- Special translation for mixed SCEcna (29 and 32)
02108               //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
02109               //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
02110               Int_t n1StinEcha = i0StinEcha+1;
02111               if( n1StexStinEcna == 10 &&  n1StinEcha == 11 )
02112                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);}
02113               if( n1StexStinEcna == 11 &&  n1StinEcha == 11 )
02114                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);}
02115               if( !( (n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11 )  )
02116                 {fT1d_av_lofn[i0StexStinEcna] += fT1d_sigevt_of_evsamp[i0StexEcha];}
02117             }
02118         }
02119       Double_t xdivis = (Double_t)0.;
02120       if( fStexName == "SM "  )
02121         {xdivis = (Double_t)fEcal->MaxCrysInStin();}
02122       if( fStexName == "Dee" )
02123         {xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");}
02124       
02125       fT1d_av_lofn[i0StexStinEcna] = fT1d_av_lofn[i0StexStinEcna]/xdivis;
02126     }
02127   fTagAvLfn[0] = 1;                      fFileHeader->fAvLfnCalc++; 
02128 }
02129 //-----------------------------------------------------------------------------
02130 //
02131 // Calculation of the average high frequency noise for each Stin in Stex
02132 // tag: AvHfn
02133 //      
02134 //-----------------------------------------------------------------------------
02135 void TEcnaRun::AverageHighFrequencyNoise()
02136 {
02137 // Calculation of the average 
02138 // (over the Stin's 0 to fEcal->MaxStinInStex()) of the High Frequency Noise
02139   
02140   //... preliminary calculation of the High Frequency Noise if not done yet
02141   if ( fTagHfn[0] != 1 ){HighFrequencyNoise(); fTagHfn[0]=0;}
02142   //................... Allocation av_hifn + init to zero (mandatory)
02143   if( fT1d_av_hifn == 0 ){fT1d_av_hifn = new Double_t[fEcal->MaxStinEcnaInStex()]; fCnew++;}
02144   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02145     {if( fT1d_av_hifn[i0StexStinEcna] != (Double_t)0 )
02146       {fMiscDiag[44]++; fT1d_av_hifn[i0StexStinEcna] = (Double_t)0;}}
02147 
02148   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::AverageHighFrequencyNoise()" << endl;}
02149   if(fFlagPrint == fCodePrintAllComments){
02150     cout << "           Calculation, for all the "
02151          << fStinName.Data() << "s, of the average High Frequency Noise" << endl;}
02152 
02153   //................... Calculation
02154   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02155     {   
02156       Int_t n1StexStinEcna = i0StexStinEcna+1;
02157       fT1d_av_hifn[i0StexStinEcna] = (Double_t)0;
02158       for(Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++)
02159         {
02160           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
02161 
02162           if( fStexName == "SM " )
02163             {fT1d_av_hifn[i0StexStinEcna] += fT1d_evevt_of_sigsamp[i0StexEcha];}
02164           
02165           if( fStexName == "Dee" )
02166             {
02167               //---------------- Special translation for mixed SCEcna (29 and 32)
02168               //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
02169               //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
02170               Int_t n1StinEcha = i0StinEcha+1;
02171               if( n1StexStinEcna == 10 &&  n1StinEcha == 11 )
02172                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);}
02173               if( n1StexStinEcna == 11 &&  n1StinEcha == 11 )
02174                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);}
02175               if( !( (n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11 )  )
02176                 {fT1d_av_hifn[i0StexStinEcna] += fT1d_evevt_of_sigsamp[i0StexEcha];}
02177             }
02178         }
02179       Double_t xdivis = (Double_t)0.;
02180       if( fStexName == "SM "  )
02181         {xdivis = (Double_t)fEcal->MaxCrysInStin();}
02182       if( fStexName == "Dee" )
02183         {xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");}
02184 
02185       fT1d_av_hifn[i0StexStinEcna] = fT1d_av_hifn[i0StexStinEcna]/xdivis;
02186     }
02187   fTagAvHfn[0] = 1;                      fFileHeader->fAvHfnCalc++;  
02188 }
02189 //-----------------------------------------------------------------------------
02190 //
02191 // Calculation of the average mean cor(s,s) for each Stin in Stex
02192 // tag: AvMeanCorss
02193 //      
02194 //-----------------------------------------------------------------------------
02195 void TEcnaRun::AverageMeanCorrelationsBetweenSamples()
02196 {
02197 // Calculation of the average 
02198 // (over the Stin's 0 to fEcal->MaxStinInStex()) of the mean cor(s,s)
02199   
02200   //... preliminary calculation of the mean cor(s,s) if not done yet
02201   if ( fTagMeanCorss[0] != 1 ){MeanCorrelationsBetweenSamples(); fTagMeanCorss[0]=0;}
02202   //................... Allocation av_ev_corss + init to zero (mandatory)
02203   if( fT1d_av_ev_corss == 0 ){fT1d_av_ev_corss = new Double_t[fEcal->MaxStinEcnaInStex()]; fCnew++;}
02204   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02205     {if( fT1d_av_ev_corss[i0StexStinEcna] != (Double_t)0 )
02206       {fMiscDiag[45]++; fT1d_av_ev_corss[i0StexStinEcna] = (Double_t)0;}}
02207 
02208   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::AverageMeanCorrelationsBetweenSamples()" << endl;}
02209   if(fFlagPrint == fCodePrintAllComments){
02210     cout << "           Calculation, for all the "
02211          << fStinName.Data() << "s, of the average mean cor(s,s)" << endl;}
02212 
02213   //................... Calculation
02214   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02215     {
02216       Int_t n1StexStinEcna = i0StexStinEcna+1;
02217       fT1d_av_ev_corss[i0StexStinEcna] = (Double_t)0;
02218       for(Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++)
02219         {
02220           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
02221 
02222           if( fStexName == "SM " )
02223             {fT1d_av_ev_corss[i0StexStinEcna] += fT1d_ev_cor_ss[i0StexEcha];}
02224           
02225           if( fStexName == "Dee" )
02226             {
02227               //---------------- Special translation for mixed SCEcna (29 and 32)
02228               //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
02229               //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
02230               Int_t n1StinEcha = i0StinEcha+1;
02231               if( n1StexStinEcna == 10 &&  n1StinEcha == 11 )
02232                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);}
02233               if( n1StexStinEcna == 11 &&  n1StinEcha == 11 )
02234                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);}
02235               if( !( (n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11 )  )
02236                 {fT1d_av_ev_corss[i0StexStinEcna] += fT1d_ev_cor_ss[i0StexEcha];}
02237             }
02238         }
02239       Double_t xdivis = (Double_t)0.;
02240       if( fStexName == "SM "  )
02241         {xdivis = (Double_t)fEcal->MaxCrysInStin();}
02242       if( fStexName == "Dee" )
02243         {xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");}
02244 
02245       fT1d_av_ev_corss[i0StexStinEcna] = fT1d_av_ev_corss[i0StexStinEcna]/xdivis;
02246     }
02247   fTagAvMeanCorss[0] = 1;                      fFileHeader->fAvMeanCorssCalc++;    
02248 }
02249 //-----------------------------------------------------------------------------
02250 //
02251 // Calculation of the average sigma of cor(s,s) for each Stin in Stex
02252 // tag: AvSigCorss
02253 //      
02254 //-----------------------------------------------------------------------------
02255 void TEcnaRun::AverageSigmaOfCorrelationsBetweenSamples()
02256 {
02257 // Calculation of the average 
02258 // (over the Stin's 0 to fEcal->MaxStinInStex()) of the sigma of cor(s,s)
02259   
02260   //... preliminary calculation of the sigma of cor(s,s) if not done yet
02261   if ( fTagSigCorss[0] != 1 ){SigmaOfCorrelationsBetweenSamples(); fTagSigCorss[0]=0;}
02262   //................... Allocation av_sig_corss + init to zero (mandatory)
02263   if( fT1d_av_sig_corss == 0 ){fT1d_av_sig_corss = new Double_t[fEcal->MaxStinEcnaInStex()]; fCnew++;}
02264   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02265     {if( fT1d_av_sig_corss[i0StexStinEcna] != (Double_t)0 )
02266       {fMiscDiag[46]++; fT1d_av_sig_corss[i0StexStinEcna] = (Double_t)0;}}
02267 
02268   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::AverageSigmaOfCorrelationsBetweenSamples()" << endl;}
02269   if(fFlagPrint == fCodePrintAllComments){
02270     cout << "           Calculation, for all the "
02271          << fStinName.Data() << "s, of the average sigma of cor(s,s)" << endl;}
02272 
02273   //................... Calculation
02274   for(Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02275     {
02276       Int_t n1StexStinEcna = i0StexStinEcna+1;
02277       fT1d_av_sig_corss[i0StexStinEcna] = (Double_t)0;
02278       for(Int_t i0StinEcha = 0; i0StinEcha < fEcal->MaxCrysInStin(); i0StinEcha++)
02279         {
02280           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStinEcna, i0StinEcha);
02281 
02282           if( fStexName == "SM " )
02283             {fT1d_av_sig_corss[i0StexStinEcna] += fT1d_sig_cor_ss[i0StexEcha];}
02284           
02285           if( fStexName == "Dee" )
02286             {
02287               //---------------- Special translation for mixed SCEcna (29 and 32)
02288               //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
02289               //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
02290               Int_t n1StinEcha = i0StinEcha+1;
02291               if( n1StexStinEcna == 10 &&  n1StinEcha == 11 )
02292                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);}
02293               if( n1StexStinEcna == 11 &&  n1StinEcha == 11 )
02294                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);}
02295               if( !( (n1StexStinEcna == 29 || n1StexStinEcna == 32) && n1StinEcha == 11 )  )
02296                 {fT1d_av_sig_corss[i0StexStinEcna] += fT1d_sig_cor_ss[i0StexEcha];}
02297             }
02298         }
02299       Double_t xdivis = (Double_t)0.;
02300       if( fStexName == "SM "  )
02301         {xdivis = (Double_t)fEcal->MaxCrysInStin();}
02302       if( fStexName == "Dee" )
02303         {xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStinEcna, "TEcnaRun");}
02304 
02305       fT1d_av_sig_corss[i0StexStinEcna] = fT1d_av_sig_corss[i0StexStinEcna]/xdivis;
02306     }
02307   fTagAvSigCorss[0] = 1;                      fFileHeader->fAvSigCorssCalc++;       
02308 }
02309 
02310 //======================================================================
02311 //
02312 //       C O V A R I A N C E S   &   C O R R E L A T I O N S
02313 //
02314 //                 B E T W E E N   C H A N N E L S
02315 //
02316 //======================================================================
02317 //----------------------------------------------------------------------
02318 //
02319 //  Calculation of the Low Frequency Covariances between channels
02320 //
02321 //  LFCov(Ci,Cj) = Cov_e[ E_s[A(Ci,s*,e*)] , E_s[A(Cj,s*,e*) ]
02322 //
02323 //               = E_e[ ( E_s[A(Ci,s*,e*)] - E_e[ E_s[A(Ci,s*,e*)] ] )*
02324 //                      ( E_s[A(Cj,s*,e*)] - E_e[ E_s[A(Cj,s*,e*)] ] ) ]
02325 //
02326 //   A(Ci,s,e) : ADC value for channel Ci, sample s, event e
02327 //
02328 //   E_e , Cov_e : average, covariance over the events
02329 //   E_s :         average over the samples
02330 //
02331 //   e* : random variable associated to events
02332 //   s* : random variable associated to samples
02333 //
02334 //----------------------------------------------------------------------
02335 void TEcnaRun::LowFrequencyCovariancesBetweenChannels()
02336 {
02337 //Calculation of the Low Frequency Covariances between channels
02338   
02339   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::LowFrequencyCovariancesBetweenChannels()" << endl;}
02340   if(fFlagPrint == fCodePrintAllComments){
02341     cout << "           Calculation of the Low Frequency Covariances between channels" << endl;}
02342 
02343   //................. allocation fT2d_lf_cov + init to zero (mandatory)
02344   if( fT2d_lf_cov == 0 ){
02345     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
02346     fT2d_lf_cov  = new Double_t*[n_StexEcha];                   fCnew++;
02347     fT2d1_lf_cov = new  Double_t[n_StexEcha*n_StexEcha];          fCnew++;
02348     for(Int_t i0StexEcha = 0 ; i0StexEcha < n_StexEcha ; i0StexEcha++){
02349         fT2d_lf_cov[i0StexEcha] = &fT2d1_lf_cov[0] + i0StexEcha*n_StexEcha;}}
02350 
02351   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
02352     {
02353       for (Int_t j0StexEcha = 0 ; j0StexEcha < fEcal->MaxCrysEcnaInStex() ; j0StexEcha++)
02354         {
02355           if( fT2d_lf_cov[i0StexEcha][j0StexEcha] != (Double_t)0 )
02356             {fMiscDiag[21]++; fT2d_lf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;}
02357         }
02358     }
02359   //........................................... Calculation  (LowFrequencyCovariancesBetweenChannels)
02360   //................... Allocation mean_over_samples(i0StexEcha, n_event)
02361   TMatrixD mean_over_samples(fEcal->MaxCrysEcnaInStex(), fNumberOfEvents);
02362   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02363     {for(Int_t n_event=0; n_event<fNumberOfEvents; n_event++)
02364         {mean_over_samples(i0StexEcha, n_event)=(Double_t)0.;}}
02365   //................... Allocation MoeOfMos(i0StexEcha)
02366   TVectorD MoeOfMos(fEcal->MaxCrysEcnaInStex());
02367   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02368     { MoeOfMos(i0StexEcha)=(Double_t)0.;}
02369 
02370   //................... Calculation  
02371   if(fFlagPrint != fCodePrintNoComment){
02372     cout << "          Calculation, for each pair of channels, of the covariance (over the events)" << endl
02373          << "          between the ADC expectation values (over the samples 1 to "
02374          <<  fNbSampForCalc << ")." << endl;}
02375 
02376   cout << " Please, wait (end at i= " << fEcal->MaxCrysEcnaInStex() << "): " << endl;
02377 
02378   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02379     {
02380       MoeOfMos(i0StexEcha) = (Double_t)0;
02381 
02382       if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0)
02383           || ( fFlagSubDet == "EB") )
02384         {
02385           for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
02386             {
02387               // Calculation, for each event, of the mean over the samples  ( = E_s[A(c_i,s*,e_n] )
02388               mean_over_samples(i0StexEcha, n_event) = (Double_t)0.;
02389               for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
02390                 {
02391                   mean_over_samples(i0StexEcha, n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];
02392                 }
02393               mean_over_samples(i0StexEcha, n_event) /= (Double_t)fNbSampForCalc;
02394             }
02395           //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*]] )
02396           for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
02397             {MoeOfMos(i0StexEcha) += mean_over_samples(i0StexEcha, n_event);}
02398           MoeOfMos(i0StexEcha) /= (Double_t)fNumberOfEvents;
02399         }
02400     }
02401 
02402   //... Calculation of half of the matrix, diagonal included        (LowFrequencyCovariancesBetweenChannels)
02403   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02404     {
02405       if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0)
02406           || ( fFlagSubDet == "EB") )
02407         {
02408           for(Int_t j0StexEcha = 0; j0StexEcha <= i0StexEcha; j0StexEcha++)
02409             {
02410               if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0)
02411                   || ( fFlagSubDet == "EB") )
02412                 {
02413                   fT2d_lf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;
02414                   for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
02415                     {
02416                       fT2d_lf_cov[i0StexEcha][j0StexEcha] +=
02417                         ( mean_over_samples(i0StexEcha, n_event) - MoeOfMos(i0StexEcha) )
02418                         *( mean_over_samples(j0StexEcha, n_event) - MoeOfMos(j0StexEcha) );    
02419                     }
02420                   fT2d_lf_cov[i0StexEcha][j0StexEcha] /= (Double_t)fNumberOfEvents;
02421                   
02422                   fT2d_lf_cov[j0StexEcha][i0StexEcha] = fT2d_lf_cov[i0StexEcha][j0StexEcha];
02423                 }
02424             }
02425           if( i0StexEcha%100 == 0 ){cout << i0StexEcha << "[LFN Cov], ";}
02426         }
02427     }
02428   cout << endl;
02429   fTagLfCov[0] = 1;    fFileHeader->fLfCovCalc++;
02430 }
02431 //---------- (end of LowFrequencyCovariancesBetweenChannels ) --------------------
02432 
02433 //------------------------------------------------------------------
02434 //
02435 //  Calculation of the Low Frequency Correlations between channels
02436 //
02437 //  LFCor(Ci,Cj) = LFCov(Ci,Cj)/sqrt(LFCov(Ci,Ci)*LFCov(Cj,Cj))
02438 //
02439 //------------------------------------------------------------------
02440 void TEcnaRun::LowFrequencyCorrelationsBetweenChannels()
02441 {
02442 //Calculation of the Low Frequency Correlations between channels
02443 
02444   //... preliminary calculation of the covariances if not done yet.
02445   if ( fTagLfCov[0] != 1 )
02446     {LowFrequencyCovariancesBetweenChannels(); fTagLfCov[0] = 0;}
02447   
02448   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::LowFrequencyCorrelationsBetweenChannels()" << endl;}
02449   if(fFlagPrint == fCodePrintAllComments){
02450     cout << "          Calculation of the Low Frequency Correlations between channels" << endl
02451          << "          Starting allocation. "
02452          << endl;}
02453 
02454   //................. allocation fT2d_lf_cor + init to zero (mandatory)
02455   if( fT2d_lf_cor == 0 ){
02456     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
02457     fT2d_lf_cor  = new Double_t*[n_StexEcha];                   fCnew++;
02458     fT2d1_lf_cor = new  Double_t[n_StexEcha*n_StexEcha];        fCnew++;
02459     for(Int_t i0StexEcha = 0 ; i0StexEcha < n_StexEcha ; i0StexEcha++){
02460         fT2d_lf_cor[i0StexEcha] = &fT2d1_lf_cor[0] + i0StexEcha*n_StexEcha;} 
02461   }
02462   
02463   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
02464     {
02465       for (Int_t j0StexEcha = 0 ; j0StexEcha < fEcal->MaxCrysEcnaInStex() ; j0StexEcha++)
02466         {
02467           if( fT2d_lf_cor[i0StexEcha][j0StexEcha] != (Double_t)0 )
02468             {fMiscDiag[22]++; fT2d_lf_cor[i0StexEcha][j0StexEcha] = (Double_t)0;}
02469         }
02470     }
02471   
02472   //................. calculation  
02473   //........................... computation of half of the matrix, diagonal included
02474   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
02475     {
02476       if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0)
02477           || ( fFlagSubDet == "EB") )
02478         {
02479           for (Int_t j0StexEcha = 0 ; j0StexEcha <= i0StexEcha ; j0StexEcha++)
02480             {
02481               if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0)
02482                   || ( fFlagSubDet == "EB") )
02483                 {
02484                   if(  fT2d_lf_cov[i0StexEcha][i0StexEcha] > 0
02485                        && fT2d_lf_cov[j0StexEcha][j0StexEcha] > 0 )
02486                     {
02487                       fT2d_lf_cor[i0StexEcha][j0StexEcha] =
02488                         fT2d_lf_cov[i0StexEcha][j0StexEcha]/
02489                         ( (Double_t)sqrt( fT2d_lf_cov[i0StexEcha][i0StexEcha]*
02490                                           fT2d_lf_cov[j0StexEcha][j0StexEcha] ) );
02491                     }
02492                   else
02493                     {
02494                       fT2d_lf_cor[i0StexEcha][j0StexEcha] = (Double_t)0.;
02495                     }
02496                   fT2d_lf_cor[j0StexEcha][i0StexEcha] = fT2d_lf_cor[i0StexEcha][j0StexEcha];
02497                 }
02498             }
02499         }
02500       if( i0StexEcha%100 == 0 ){cout << i0StexEcha << "[LFN Cor], ";}
02501     }
02502   cout << endl;
02503   
02504   fTagLfCor[0] = 1;    fFileHeader->fLfCorCalc++;
02505 }
02506 //--------------- (end of LowFrequencyCorrelationsBetweenChannels) --------------------
02507 
02508 //------------------------------------------------------------------
02509 //
02510 //  Calculation of the High Frequency Covariances between channels
02511 //
02512 //  HFCov(Ci,Cj) = E_e[ Cov_s[ A(Ci,s*,e*) , A(Cj,s*,e*) ] ] 
02513 //
02514 //               = E_e[ E_s[ ( A(Ci,s*,e*) - E_s[A(Ci,s*,e*)] )*
02515 //                           ( A(Cj,s*,e*) - E_s[A(Cj,s*,e*)] ) ] ]
02516 //   
02517 //   A(Ci,s,e) : ADC value for channel Ci, sample s, event e
02518 //
02519 //   E_e         : average over the events
02520 //   E_s , Cov_s : average, covariance over the samples
02521 //
02522 //------------------------------------------------------------------
02523 void TEcnaRun::HighFrequencyCovariancesBetweenChannels()
02524 {
02525 //Calculation of the High Frequency Covariances between channels
02526   
02527   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::HighFrequencyCovariancesBetweenChannels()" << endl;}
02528   if(fFlagPrint == fCodePrintAllComments){
02529     cout << "           Calculation of the High Frequency Covariances between channels" << endl;}
02530 
02531   //................. allocation fT2d_hf_cov + init to zero (mandatory)
02532   if( fT2d_hf_cov == 0 ){
02533     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
02534     fT2d_hf_cov   = new Double_t*[n_StexEcha];                   fCnew++;
02535     fT2d1_hf_cov  = new  Double_t[n_StexEcha*n_StexEcha];        fCnew++;
02536     for(Int_t i0StexEcha = 0 ; i0StexEcha < n_StexEcha ; i0StexEcha++){
02537         fT2d_hf_cov[i0StexEcha] = &fT2d1_hf_cov[0] + i0StexEcha*n_StexEcha;} 
02538   }
02539 
02540   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
02541     {
02542       for (Int_t j0StexEcha = 0 ; j0StexEcha < fEcal->MaxCrysEcnaInStex() ; j0StexEcha++)
02543         {
02544           if( fT2d_hf_cov[i0StexEcha][j0StexEcha] != (Double_t)0 )
02545             {fMiscDiag[23]++; fT2d_hf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;}
02546         }
02547     }
02548 
02549   //................... Allocation mean_over_samples(i0StexEcha, n_event) 
02550   TMatrixD mean_over_samples(fEcal->MaxCrysEcnaInStex(), fNumberOfEvents);
02551   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02552     {for(Int_t n_event=0; n_event<fNumberOfEvents; n_event++)
02553         {mean_over_samples(i0StexEcha, n_event)=(Double_t)0.;}}
02554   //................... Allocation cov_over_samp(i0StexEcha,j0StexEcha)
02555   TMatrixD cov_over_samp(fEcal->MaxCrysEcnaInStex(), fEcal->MaxCrysEcnaInStex());
02556   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02557     {for(Int_t j0StexEcha=0; j0StexEcha<fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
02558         {cov_over_samp(i0StexEcha, j0StexEcha)=(Double_t)0.;}}
02559 
02560   //........................................... Calculation    (HighFrequencyCovariancesBetweenChannels)
02561   if(fFlagPrint != fCodePrintNoComment){
02562     cout << "          Calculation of the mean (over the events)" << endl
02563          << "          of the covariances between the channels (over the samples 1 to "
02564          <<  fNbSampForCalc << ")." << endl;}
02565 
02566   cout << " Please, wait (end at i= " << fEcal->MaxCrysEcnaInStex() << "): " << endl;
02567 
02568   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02569     {
02570       if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0)
02571           || ( fFlagSubDet == "EB") )
02572         {
02573           for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
02574             {
02575               // Calculation, for each event, of the mean over the samples  ( = E_s[A(c_i,s*,e_n] )
02576               mean_over_samples(i0StexEcha, n_event) = (Double_t)0.;
02577               for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
02578                 {mean_over_samples(i0StexEcha, n_event) += fT3d_AdcValues[i0StexEcha][i0Sample][n_event];}
02579               mean_over_samples(i0StexEcha, n_event) /= (Double_t)fNbSampForCalc;
02580             }
02581         }
02582       if( i0StexEcha%100 == 0 ){cout << i0StexEcha << "[HFNa Cov], ";}
02583     }
02584   cout << endl;
02585 
02586   cout << " Please, wait (end at i= " << fEcal->MaxCrysEcnaInStex() << "): " << endl;
02587 
02588   //... Calculation of half of the matrix, diagonal included    (HighFrequencyCovariancesBetweenChannels)
02589   for(Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
02590     {
02591       if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0)
02592           || ( fFlagSubDet == "EB") )
02593         {
02594           for(Int_t j0StexEcha = 0; j0StexEcha <= i0StexEcha; j0StexEcha++)
02595             {
02596               if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0)
02597                   || ( fFlagSubDet == "EB") )
02598                 {
02599                   for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
02600                     {
02601                       // Calculation, for each event, of the covariance over the samples
02602                       cov_over_samp(i0StexEcha,j0StexEcha) = (Double_t)0;
02603                       for(Int_t i0Sample=0; i0Sample<fNbSampForCalc; i0Sample++)
02604                         {
02605                           cov_over_samp(i0StexEcha,j0StexEcha) +=
02606                             ( fT3d_AdcValues[i0StexEcha][i0Sample][n_event] - mean_over_samples(i0StexEcha, n_event) )*
02607                             ( fT3d_AdcValues[j0StexEcha][i0Sample][n_event] - mean_over_samples(j0StexEcha, n_event) );
02608                         }
02609                       cov_over_samp(i0StexEcha,j0StexEcha) /= (Double_t)fNbSampForCalc;
02610 
02611                     }
02612                   //....... Calculation of the mean over the events of Cov_s[A(c_i,s*,e*),A(c_j,s*,e*)]
02613                   //......... Calculation of half of the matrix, diagonal included
02614                   fT2d_hf_cov[i0StexEcha][j0StexEcha] = (Double_t)0;
02615                   for (Int_t n_event = 0; n_event < fNumberOfEvents; n_event++)
02616                     {
02617                       fT2d_hf_cov[i0StexEcha][j0StexEcha] += cov_over_samp(i0StexEcha,j0StexEcha);
02618                     }
02619                     fT2d_hf_cov[i0StexEcha][j0StexEcha] /= (Double_t)fNumberOfEvents;
02620                   
02621                   fT2d_hf_cov[j0StexEcha][i0StexEcha] = fT2d_hf_cov[i0StexEcha][j0StexEcha];
02622                 }
02623             }
02624         }
02625       if( i0StexEcha%100 == 0 ){cout << i0StexEcha << "[HFNb Cov], ";}
02626     }
02627   cout << endl;
02628 
02629   fTagHfCov[0] = 1;    fFileHeader->fHfCovCalc++;
02630 }
02631 //---------- (end of HighFrequencyCovariancesBetweenChannels ) --------------------
02632 
02633 //------------------------------------------------------------------
02634 //
02635 //  Calculation of the High Frequency Correlations between channels
02636 //
02637 //  HFCor(Ci,Cj) = HFCov(Ci,Cj)/sqrt(HFCov(Ci,Ci)*HFCov(Cj,Cj))
02638 //
02639 //------------------------------------------------------------------
02640 void TEcnaRun::HighFrequencyCorrelationsBetweenChannels()
02641 {
02642 //Calculation of the High Frequency Correlations between channels
02643 
02644   //... preliminary calculation of the covariances if not done yet.
02645   if ( fTagHfCov[0] != 1 )
02646     {HighFrequencyCovariancesBetweenChannels(); fTagHfCov[0] = 0;}
02647   
02648   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::HighFrequencyCorrelationsBetweenChannels()" << endl;}
02649   if(fFlagPrint == fCodePrintAllComments){
02650     cout << "           Calculation of the High Frequency Correlations between channels" << endl
02651          << "          Starting allocation. "
02652          << endl;}
02653 
02654   //................. allocation fT2d_hf_cor + init to zero (mandatory)
02655   if( fT2d_hf_cor == 0 ){
02656     const Int_t n_StexEcha = fEcal->MaxCrysEcnaInStex();
02657     fT2d_hf_cor  = new Double_t*[n_StexEcha];                   fCnew++;
02658     fT2d1_hf_cor = new  Double_t[n_StexEcha*n_StexEcha];        fCnew++;
02659     for(Int_t i0StexEcha = 0 ; i0StexEcha < n_StexEcha ; i0StexEcha++){
02660         fT2d_hf_cor[i0StexEcha] = &fT2d1_hf_cor[0] + i0StexEcha*n_StexEcha;} 
02661   }
02662 
02663   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
02664     {
02665       for (Int_t j0StexEcha = 0 ; j0StexEcha < fEcal->MaxCrysEcnaInStex() ; j0StexEcha++)
02666         {
02667           if( fT2d_hf_cor[i0StexEcha][j0StexEcha] != (Double_t)0 )
02668             {fMiscDiag[24]++; fT2d_hf_cor[i0StexEcha][j0StexEcha] = (Double_t)0;}
02669         }
02670     }
02671   
02672   //................. calculation  
02673   //........................... computation of half of the matrix, diagonal included
02674   
02675   for (Int_t i0StexEcha = 0 ; i0StexEcha < fEcal->MaxCrysEcnaInStex() ; i0StexEcha++)
02676     {
02677       if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, i0StexEcha) > 0)
02678           || ( fFlagSubDet == "EB") )
02679         {
02680           for (Int_t j0StexEcha = 0 ; j0StexEcha <= i0StexEcha ; j0StexEcha++)
02681             {
02682               if( (fFlagSubDet == "EE" && fEcalNumbering->StexEchaForCons(fFileHeader->fStex, j0StexEcha) > 0)
02683                   || ( fFlagSubDet == "EB") )
02684                 {
02685                   if(  fT2d_hf_cov[i0StexEcha][i0StexEcha] > 0
02686                        && fT2d_hf_cov[j0StexEcha][j0StexEcha] > 0 )
02687                     {
02688                       fT2d_hf_cor[i0StexEcha][j0StexEcha] =
02689                         fT2d_hf_cov[i0StexEcha][j0StexEcha]/
02690                         (  (Double_t)sqrt(fT2d_hf_cov[i0StexEcha][i0StexEcha]) *
02691                            (Double_t)sqrt(fT2d_hf_cov[j0StexEcha][j0StexEcha])  );
02692                     }
02693                   else
02694                     {
02695                       fT2d_hf_cor[i0StexEcha][j0StexEcha] = (Double_t)0.;
02696                     }
02697                   
02698                   fT2d_hf_cor[j0StexEcha][i0StexEcha] = fT2d_hf_cor[i0StexEcha][j0StexEcha];
02699                 }
02700             }
02701         }
02702       if( i0StexEcha%100 == 0 ){cout << i0StexEcha << "[HFN Cor], ";}
02703     }
02704   cout << endl;  
02705   
02706   fTagHfCor[0] = 1;    fFileHeader->fHfCorCalc++;
02707 }
02708 //------- (end of HighFrequencyCorrelationsBetweenChannels) ----------
02709 
02710 //=================================================================================
02711 //
02712 //          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
02713 //
02714 //       B E T W E E N   T O W E R S  ( E B )  O R   S C s   ( E E )
02715 //
02716 //=================================================================================
02717 //-----------------------------------------------------------------------------
02718 //      Calculation of the mean Low Frequency Correlations
02719 //      between channels for each Stin
02720 //-----------------------------------------------------------------------------
02721 void TEcnaRun::LowFrequencyMeanCorrelationsBetweenTowers()
02722 {LowFrequencyMeanCorrelationsBetweenStins();}
02723 void TEcnaRun::LowFrequencyMeanCorrelationsBetweenSCs()
02724 {LowFrequencyMeanCorrelationsBetweenStins();}
02725 
02726 void TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins()
02727 {
02728 //Calculation of the mean Low Frequency Correlations
02729 //between channels for each Stin
02730 
02731   //... preliminary calculation of the Low Frequency Cor(c,c) if not done yet
02732   //    Only one tag (dim=1) to set to 0 (no write in the result ROOT file)
02733   if(fTagLfCor[0] != 1){LowFrequencyCorrelationsBetweenChannels(); fTagLfCor[0]=0;}
02734 
02735   //..... mean fT2d_lfcc_mostins for each pair (Stin_X,Stin_Y)
02736   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins()" << endl;}
02737   if(fFlagPrint == fCodePrintAllComments){
02738     cout << "           Calculation of the mean, for each "
02739          << fStinName.Data() << ", of the" << endl
02740          << "           Low Frequency Correlations between channels." << endl;}
02741   
02742   //................. allocation fT2d_lfcc_mostins + init to zero (mandatory)
02743   if( fT2d_lfcc_mostins == 0 ){
02744     const Int_t n_Stin = fEcal->MaxStinEcnaInStex();
02745     fT2d_lfcc_mostins  = new Double_t*[n_Stin];                 fCnew++;
02746     fT2d1_lfcc_mostins = new  Double_t[n_Stin*n_Stin];          fCnew++;  
02747     for(Int_t i0StexStinEcna = 0 ; i0StexStinEcna < n_Stin ; i0StexStinEcna++){
02748         fT2d_lfcc_mostins[i0StexStinEcna] = &fT2d1_lfcc_mostins[0] + i0StexStinEcna*n_Stin;} 
02749   }
02750   
02751   for(Int_t i0StexStinEcna=0; i0StexStinEcna<fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02752     {
02753       for(Int_t j0StexStinEcna=0; j0StexStinEcna<fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
02754         {
02755           if( fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] != (Double_t)0 )
02756             {fMiscDiag[31]++; fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;}
02757         }
02758     }
02759 
02760   //..... Calculation of the mean LF Cor(c,c) for each pair (Stin_X,Stin_Y)
02761   //
02762   //           ! => Warning: this matrix is NOT symmetric => take N*N elements
02763   //                Only (Stin,Stin) matrix is symmetric.
02764   //                (StinEcha,StinEcha) matrix inside a (Stin,Stin) element is NOT symmetric
02765   //                (except for the (Stin,Stin) DIAGONAL elements)
02766   //      Then:
02767   //            1D array half_LFccMos[N*N] to put the (channel,channel) correlations
02768 
02769   Int_t ndim = (Int_t)(fEcal->MaxCrysInStin()*fEcal->MaxCrysInStin());
02770 
02771   TVectorD  half_LFccMos(ndim); for(Int_t i=0; i<ndim; i++){half_LFccMos(i)=(Double_t)0.;}
02772 
02773   //..................... Calculation
02774   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins()" << endl;}
02775   if(fFlagPrint == fCodePrintAllComments){
02776     cout << "           Calculation, for each "
02777          << fStinName.Data() << ", of the mean " << endl
02778          << "           Low Frequency cor(c,c)." << endl;}
02779 
02780   for(Int_t i0StexStinEcna=0; i0StexStinEcna<fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02781     {
02782       for(Int_t j0StexStinEcna=0; j0StexStinEcna<fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
02783         {
02784           //................... .Copy the Mean Correlations(c,c') in 1D vector half_LFccMos() 
02785           Int_t i_count = 0;
02786           for(Int_t i0StinCrys=0; i0StinCrys<fEcal->MaxCrysInStin(); i0StinCrys++)
02787             {
02788               Int_t i0StexEcha = i0StexStinEcna*fEcal->MaxCrysInStin() + i0StinCrys;
02789               for(Int_t j0StinCrys=0; j0StinCrys<fEcal->MaxCrysInStin(); j0StinCrys++)
02790                 {
02791                   Int_t j0StexEcha = j0StexStinEcna*fEcal->MaxCrysInStin() + j0StinCrys;
02792                   if(  (i0StexEcha>= 0 && i0StexEcha < fEcal->MaxCrysEcnaInStex()) &&
02793                        (j0StexEcha>= 0 && j0StexEcha < fEcal->MaxCrysEcnaInStex())  )
02794                   {half_LFccMos(i_count) = fT2d_lf_cor[i0StexEcha][j0StexEcha]; i_count++;}
02795                   else
02796                     {cout << "!TEcnaRun::LowFrequencyMeanCorrelationsBetweenStins()> Channel number out of range."
02797                           << "i0StexEcha = " << i0StexEcha <<", j0StexEcha = " << j0StexEcha << fTTBELL << endl; }
02798                 }
02799             }
02800           //...... Calculation of the mean absolute values of the LF mean Correlations(c,c')
02801           fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;
02802           for(Int_t i_rcor = 0; i_rcor < ndim; i_rcor++)
02803             {
02804               fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] += fabs(half_LFccMos(i_rcor));
02805             }
02806           fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna] /= (Double_t)ndim;
02807         }
02808       if( i0StexStinEcna%10 == 0 ){cout << i0StexStinEcna << "[LFN MCtt], ";}
02809     }
02810   cout << endl;
02811 
02812   fTagLFccMoStins[0] = 1;           fFileHeader->fLFccMoStinsCalc++;
02813 } // ------- end of LowFrequencyMeanCorrelationsBetweenStins() -------
02814 
02815 //-----------------------------------------------------------------------------
02816 //      Calculation of the mean High Frequency Correlations
02817 //      between channels for each Stin
02818 //-----------------------------------------------------------------------------
02819 void TEcnaRun::HighFrequencyMeanCorrelationsBetweenTowers()
02820 {HighFrequencyMeanCorrelationsBetweenStins();}
02821 void TEcnaRun::HighFrequencyMeanCorrelationsBetweenSCs()
02822 {HighFrequencyMeanCorrelationsBetweenStins();}
02823 
02824 void TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins()
02825 {
02826 //Calculation of the mean High Frequency Correlations
02827 //between channels for each Stin
02828 
02829   //... preliminary calculation of the High Frequency Cor(c,c) if not done yet
02830   //    Only one tag (dim=1) to set to 0 (no write in the result ROOT file)
02831   if(fTagHfCor[0] != 1){HighFrequencyCorrelationsBetweenChannels();fTagHfCor[0]=0;}
02832 
02833   //..... mean fT2d_hfcc_mostins for each pair (Stin_X,Stin_Y)
02834   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins()" << endl;}
02835   if(fFlagPrint == fCodePrintAllComments){
02836     cout << "           Calculation of the mean, for each "
02837          << fFlagSubDet.Data() << ", of the" << endl
02838          << "           High Frequency Correlations between channels." << endl;}
02839 
02840   //................. allocation fT2d_hfcc_mostins + init to zero (mandatory)
02841   if( fT2d_hfcc_mostins == 0 ){
02842     const Int_t n_Stin = fEcal->MaxStinEcnaInStex();
02843     fT2d_hfcc_mostins  = new Double_t*[n_Stin];                 fCnew++;
02844     fT2d1_hfcc_mostins = new  Double_t[n_Stin*n_Stin];           fCnew++;  
02845     for(Int_t i0StexStinEcna = 0 ; i0StexStinEcna < n_Stin ; i0StexStinEcna++){
02846         fT2d_hfcc_mostins[i0StexStinEcna] = &fT2d1_hfcc_mostins[0] + i0StexStinEcna*n_Stin;} 
02847   }
02848   
02849   for(Int_t i0StexStinEcna=0; i0StexStinEcna<fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02850     {
02851       for(Int_t j0StexStinEcna=0; j0StexStinEcna<fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
02852         {
02853           if( fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] != (Double_t)0 )
02854             {fMiscDiag[32]++; fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;}
02855         }
02856     }
02857 
02858   //..... Calculation of the mean HF Cor(c,c) for each pair (Stin_X,Stin_Y)
02859   //
02860   //           ! => Warning: this matrix is NOT symmetric => take N*N elements
02861   //                Only (Stin,Stin) matrix is symmetric.
02862   //                (StinEcha,StinEcha) matrix inside a (Stin,Stin) element is NOT symmetric
02863   //                (except for the (Stin,Stin) DIAGONAL elements)
02864   //      Then:
02865   //            1D array half_LFccMos[N*N] to put the (channel,channel) correlations
02866 
02867   Int_t ndim = (Int_t)(fEcal->MaxCrysInStin()*fEcal->MaxCrysInStin());
02868 
02869   TVectorD half_HFccMos(ndim); for(Int_t i=0; i<ndim; i++){half_HFccMos(i)=(Double_t)0.;}
02870 
02871   if(fFlagPrint != fCodePrintNoComment){cout << "*TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins()" << endl;}
02872   if(fFlagPrint == fCodePrintAllComments){
02873     cout << "           Calculation, for each "
02874          << fFlagSubDet.Data()  << ", of the mean " << endl
02875          << "           High Frequency cor(c,c)." << endl;}
02876 
02877   //..................... Calculation
02878   for(Int_t i0StexStinEcna=0; i0StexStinEcna<fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
02879     {
02880       for(Int_t j0StexStinEcna=0; j0StexStinEcna<fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
02881         {
02882           //.................... Copy the relevant Mean Correlations(c,c') in 1D vector half_HFccMos()
02883           Int_t i_count = 0;
02884           for(Int_t i0StinCrys=0; i0StinCrys<fEcal->MaxCrysInStin(); i0StinCrys++)
02885             {
02886               Int_t i0StexEcha = i0StexStinEcna*fEcal->MaxCrysInStin() + i0StinCrys;
02887               for(Int_t j0StinCrys=0; j0StinCrys<fEcal->MaxCrysInStin(); j0StinCrys++)
02888                 {
02889                   Int_t j0StexEcha = j0StexStinEcna*fEcal->MaxCrysInStin() + j0StinCrys;
02890                   if(  (i0StexEcha>= 0 && i0StexEcha < fEcal->MaxCrysEcnaInStex()) &&
02891                        (j0StexEcha>= 0 && j0StexEcha < fEcal->MaxCrysEcnaInStex())  )
02892                     {half_HFccMos(i_count) = fT2d_hf_cor[i0StexEcha][j0StexEcha]; i_count++;}
02893                   else
02894                     {cout << "!TEcnaRun::HighFrequencyMeanCorrelationsBetweenStins()> Channel number out of range."
02895                           << "i0StexEcha = " << i0StexEcha <<", j0StexEcha = " << j0StexEcha << fTTBELL << endl; }
02896                 }
02897             }
02898           //..... Calculation of the mean absolute values of the HF mean Correlations(c,c')
02899           fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] = (Double_t)0;
02900           for(Int_t i_rcor = 0; i_rcor < ndim; i_rcor++)
02901             {
02902               fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] += fabs(half_HFccMos(i_rcor));
02903             }
02904           fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna] /= (Double_t)ndim;
02905         }
02906       if( i0StexStinEcna%10 == 0 ){cout << i0StexStinEcna << "[HFN MCtt], ";}
02907     }
02908   cout << endl;
02909 
02910   fTagHFccMoStins[0] = 1;                   fFileHeader->fHFccMoStinsCalc++;
02911 } // ------- end of HighFrequencyMeanCorrelationsBetweenStins() -------
02912 
02913 //=========================================================================
02914 //
02915 //                  W R I T I N G     M E T H O D S
02916 //
02917 //=========================================================================
02918 
02919 //=========================================================================
02920 //
02921 //         W R I T I N G   M E T H O D S :    R O O T    F I L E S
02922 //
02923 //=========================================================================
02924 //-------------------------------------------------------------
02925 //
02926 //                      OpenRootFile
02927 //
02928 //-------------------------------------------------------------
02929 Bool_t TEcnaRun::OpenRootFile(const Text_t *name, TString status) {
02930 //Open the Root file
02931 
02932   Bool_t ok_open = kFALSE;
02933 
02934   TString s_name;
02935   s_name = fCnaParPaths->ResultsRootFilePath();
02936   s_name.Append('/');
02937   s_name.Append(name);
02938   
02939   //gCnaRootFile = new TEcnaRootFile(fObjectManager, s_name.Data(), status);     fCnew++;
02940 
02941       Int_t iCnaRootFile = fObjectManager->GetPointerValue("TEcnaRootFile");
02942       if( iCnaRootFile == 0 )
02943         {
02944           gCnaRootFile = new TEcnaRootFile(fObjectManager, s_name.Data(), status); /* Anew("gCnaRootFile");*/
02945         }
02946       else
02947         {
02948           gCnaRootFile = (TEcnaRootFile*)iCnaRootFile;
02949           gCnaRootFile->ReStart(s_name.Data(), status);
02950         }
02951 
02952   if ( gCnaRootFile->fRootFileStatus == "RECREATE" ){ok_open = gCnaRootFile->OpenW();}
02953   if ( gCnaRootFile->fRootFileStatus == "READ"     ){ok_open = gCnaRootFile->OpenR();}
02954 
02955   if (!ok_open) // unable to open file
02956     {
02957       cout << "TEcnaRun::OpenRootFile> Cannot open file " << s_name.Data() << endl;
02958     }
02959   else
02960     {
02961       if(fFlagPrint == fCodePrintAllComments)
02962         {cout << "*TEcnaRun::OpenRootFile> Open ROOT file OK for file " << s_name.Data() << endl;}  
02963       fOpenRootFile  = kTRUE;
02964     }
02965   return ok_open;
02966 }
02967 //-------------------------------------------------------------
02968 //
02969 //                      CloseRootFile
02970 //
02971 //-------------------------------------------------------------
02972 Bool_t TEcnaRun::CloseRootFile(const Text_t *name) {
02973 //Close the Root file
02974  
02975   TString s_name;
02976   s_name = fCnaParPaths->ResultsRootFilePath();
02977   s_name.Append('/');
02978   s_name.Append(name);
02979 
02980   Bool_t ok_close = kFALSE;
02981 
02982   if (fOpenRootFile == kTRUE ) 
02983     {
02984       gCnaRootFile->CloseFile();
02985 
02986       if(fFlagPrint != fCodePrintAllComments){
02987         cout << "*TEcnaRun::CloseRootFile> ROOT file " << s_name.Data() << " closed." << endl;}
02988 
02989       //     delete gCnaRootFile;     gCnaRootFile = 0;          fCdelete++;
02990 
02991       fOpenRootFile = kFALSE;
02992       ok_close      = kTRUE;
02993     }
02994   else
02995     {
02996       cout << "*TEcnaRun::CloseRootFile(...)> No close since no file is open."
02997            << fTTBELL << endl;
02998     }
02999   return ok_close;
03000 }
03001 //-------------------------------------------------------------
03002 //
03003 //   WriteRootFile without arguments.
03004 //   Call WriteRootFile WITH argument (file name)
03005 //   after an automatic generation of the file name.
03006 //
03007 //   Codification for the file name:
03008 //            see comment at the beginning of this file
03009 //
03010 //-------------------------------------------------------------
03011 
03012 //=================================================================================
03013 //
03014 //         WriteRootFile()   ====>  D O N ' T    S U P P R E S S  ! ! !
03015 //                                  Called by the analyzer in package: "Modules"
03016 //
03017 //=================================================================================
03018 Bool_t TEcnaRun::WriteRootFile(){
03019 //Write the Root file.
03020 //File name automatically generated by fCnaWrite->fMakeResultsFileName()
03021 //previously called in GetReadyToCompute().
03022 
03023   Bool_t ok_write = kFALSE;
03024 
03025   //============================= check number of found events
03026   Int_t nCountEvts = 0;
03027   
03028   for(Int_t i0StexEcha=0; i0StexEcha<fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
03029     {for(Int_t i0Sample=0; i0Sample<fFileHeader->fNbOfSamples; i0Sample++)
03030       {nCountEvts += fT2d_NbOfEvts[i0StexEcha][i0Sample];}}
03031   
03032   if ( nCountEvts <= 0 )
03033     {
03034       //============== no write if no event found
03035       cout << "!TEcnaRun::WriteRootFile()> No event found for file " << fCnaWrite->GetRootFileNameShort().Data()
03036            << ". File will not be written." << endl;
03037       ok_write = kTRUE;
03038     }
03039   else
03040     {    
03041       if(fFlagPrint == fCodePrintAllComments){
03042         cout << "*TEcnaRun::WriteRootFile()> Results are going to be written in the ROOT file: " << endl
03043              << "                           " << fCnaWrite->GetRootFileName().Data() << endl;}
03044 
03045       const Text_t *FileShortName = (const Text_t *)fCnaWrite->GetRootFileNameShort().Data();
03046       ok_write = WriteRootFile(FileShortName, fFileHeader->fNbOfSamples);
03047 
03048       if( ok_write == kTRUE )
03049         {
03050           if(fFlagPrint != fCodePrintNoComment)
03051             {cout << "*TEcnaRun::WriteRootFile()> Writing OK for file " << fCnaWrite->GetRootFileName().Data()
03052                   << endl;}
03053         }
03054       else
03055         {
03056           cout << "!TEcnaRun::WriteRootFile()> Writing FAILLED for file " << fCnaWrite->GetRootFileName().Data()
03057                << fTTBELL << endl;
03058         }
03059     }
03060   return ok_write;
03061 } // end of WriteRootFile()
03062 
03063 //--------------------------------------------------------------------
03064 //
03065 //               WriteNewRootFile with argument
03066 //    Called by TEcnaGui for results file of the Calculations method
03067 //    analysis type and nb of samples changed, other arguments kept
03068 //
03069 //--------------------------------------------------------------------
03070 Bool_t TEcnaRun::WriteNewRootFile(const TString TypAna){
03071 //Write a new Root file. File name automatically generated by fCnaWrite->fMakeResultsFileName()
03072 //called here.
03073 
03074   Bool_t ok_write = kFALSE;
03075 
03076   fCnaWrite->RegisterFileParameters(TypAna.Data(),   fNbSampForCalc, fFileHeader->fRunNumber,
03077                                     fFileHeader->fFirstReqEvtNumber, fFileHeader->fLastReqEvtNumber,
03078                                     fFileHeader->fReqNbOfEvts,       fFileHeader->fStex,
03079                                     fFileHeader->fStartDate, fFileHeader->fStopDate,
03080                                     fFileHeader->fStartTime, fFileHeader->fStopTime);
03081 
03082   fCnaWrite->fMakeResultsFileName();  // set fRootFileName, fRootFileNameShort
03083   fNewRootFileName      = fCnaWrite->GetRootFileName();
03084   fNewRootFileNameShort = fCnaWrite->GetRootFileNameShort();
03085 
03086   const Text_t *FileShortName = (const Text_t *)fNewRootFileNameShort.Data();
03087 
03088   if(fFlagPrint == fCodePrintAllComments){
03089     cout << "*TEcnaRun::WriteNewRootFile()> Results are going to be written in the ROOT file: " << endl
03090          << "                              " << fNewRootFileNameShort.Data() << endl;}
03091 
03092   ok_write = WriteRootFile(FileShortName, fNbSampForCalc);
03093 
03094   return ok_write;
03095 }
03096 
03097 //-------------------------------------------------------------------------
03098 //
03099 //    Get the new ROOT file name (long and short)
03100 //   (called by TEcnaGui in Calculations method)
03101 //
03102 //-------------------------------------------------------------------------
03103 TString TEcnaRun::GetNewRootFileName(){return fNewRootFileName;}
03104 TString TEcnaRun::GetNewRootFileNameShort(){return fNewRootFileNameShort;}
03105 
03106 //--------------------------------------------------------------------
03107 //
03108 //               WriteRootFile with argument
03109 //
03110 //--------------------------------------------------------------------
03111 Bool_t TEcnaRun::WriteRootFile(const Text_t* name, Int_t& argNbSampWrite) 
03112 {
03113 //Write the Root file
03114 
03115   const Text_t* file_name = name;
03116 
03117   Bool_t ok_open  = kFALSE;
03118   Bool_t ok_write = kFALSE;
03119 
03120   if ( fOpenRootFile )
03121     {
03122       cout << "!TEcnaRun::WriteRootFile(...) *** ERROR ***> Writing on file already open."
03123            << fTTBELL << endl;
03124     }
03125   else
03126     {
03127       // List of the different element types and associated parameters as ordered in the ROOT file (smaller -> larger)
03128       //                                                                 ==========
03129       //
03130       //         WARNING  *** HERE SIZES ARE THESE FOR THE BARREL (1700 Xtals) and for 10 samples ***
03131       //
03132       //   Nb of   Type of element            Type      Type                                    Size    Comment
03133       // elements                             Number    Name
03134       //
03135       //        1  fMatHis(1,StexStin)         ( 0)  cTypNumbers             1*(   1,  68) =         68
03136 
03137       //        1  fMatHis(1,StexStin)         (12)  cTypAvPed               1*(   1,  68) =         68
03138       //        1  fMatHis(1,StexStin)         ( 3)  cTypAvTno               1*(   1,  68) =         68
03139       //        1  fMatHis(1,StexStin)         ( 4)  cTypAvLfn               1*(   1,  68) =         68
03140       //        1  fMatHis(1,StexStin)         ( 5)  cTypAvHfn               1*(   1,  68) =         68
03141       //        1  fMatHis(1,StexStin)         (13)  cTypAvMeanCorss         1*(   1,  68) =         68
03142       //        1  fMatHis(1,StexStin)         (14)  cTypAvSigCorss          1*(   1,  68) =         68
03143 
03144       //        1  fMatHis(1,StexEcha)         (16)  cTypPed                 1*(   1,1700) =      1 700
03145       //        1  fMatHis(1,StexEcha)         (17)  cTypTno                 1*(   1,1700) =      1 700
03146       //        1  fMatHis(1,StexEcha)         (10)  cTypMeanCorss           1*(   1,1700) =      1 700
03147       //        1  fMatHis(1,StexEcha)         (18)  cTypLfn                 1*(   1,1700) =      1 700
03148       //        1  fMatHis(1,StexEcha)         (19)  cTypHfn                 1*(   1,1700) =      1 700
03149       //        1  fMatHis(1,StexEcha)         (11)  cTypSigCorss            1*(   1,1700) =      1 700
03150 
03151       //        1  fMatMat(Stin,Stin)          (23)  cTypLFccMoStins         1*(  68,  68) =      4 624
03152       //        1  fMatMat(Stin,Stin)          (24)  cTypHFccMoStins         1*(  68,  68) =      4 624
03153 
03154       //        1  fMatHis(StexEcha, sample)   (15)  cTypNbOfEvts            1*(1700,  10) =     17 000
03155       //        1  fMatHis(StexEcha, sample)   ( 1)  cTypMSp                 1*(1700,  10) =     17 000
03156       //        1  fMatHis(StexEcha, sample)   ( 2)  cTypSSp                 1*(1700,  10) =     17 000
03157  
03158       //   StexEcha  fMatMat(sample, sample)   ( 8)  cTypCovCss           1700*(  10,  10) =    170 000
03159       //   StexEcha  fMatMat(sample, sample    ( 9)  cTypCorCss           1700*(  10,  10) =    170 000
03160 
03161       //   StexEcha  fMatHis(sample, bin_evt)  (20)  cTypAdcEvt,          1700*(  10, 150) =  2 550 000
03162 
03163       //        1  fMatMat(StexEcha, StexEcha) (21)  cTypLfCov               1*(1700,1700) =  2 890 000
03164       //        1  fMatMat(StexEcha, StexEcha) (22)  cTypLfCor               1*(1700,1700) =  2 890 000
03165 
03166       //        1  fMatMat(StexEcha, StexEcha) ( 6)  cTypHfCov               1*(1700,1700) =  2 890 000 // (06/05/08)
03167       //        1  fMatMat(StexEcha, StexEcha) ( 7)  cTypHfCor               1*(1700,1700) =  2 890 000 // (06/05/08)
03168 
03169 
03170       //......................................................................................................
03171 
03172       ok_open = OpenRootFile(file_name, "RECREATE");
03173 
03174       TString typ_name = "?";
03175       Int_t v_nb_times = 0;
03176       Int_t v_dim_one  = 0;
03177       Int_t v_dim_two  = 0;
03178       Int_t v_size     = 0;
03179       Int_t v_tot      = 0;
03180       Int_t v_tot_writ = 0;
03181 
03182       //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03183       //       
03184       //  ===> no general method and no translation to TEcnaWrite
03185       //       because the fT1d.. and fT2d... arrays
03186       //       are attributes of TEcnaRun (calls to the "TRootXXXX" methods)
03187       //
03188       //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03189 
03190       //-------------------------- Stin numbers 
03191       //       1   fMatHis(1,Stin)           ( 0)  cTypNumbers        1*(   1,  68) =         68
03192 
03193       Int_t MaxCar = fgMaxCar;
03194       typ_name.Resize(MaxCar);
03195       typ_name   = "StinNumbers";
03196       v_nb_times = fFileHeader->fStinNumbersCalc;
03197       v_dim_one  = 1;
03198       v_dim_two  = fEcal->MaxStinEcnaInStex();
03199       v_size     = v_nb_times*v_dim_one*v_dim_two;
03200       v_tot     += v_size;
03201 
03202       if(fFlagPrint == fCodePrintAllComments){
03203       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03204            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03205            << setw(9) << v_size;}
03206 
03207       for (Int_t i = 0; i < v_nb_times; i++)
03208         {
03209           if ( fTagStinNumbers[0] == 1 )
03210             {
03211               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypNumbers;
03212               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03213               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03214               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03215               TRootStinNumbers();
03216               gCnaRootFile->fCnaResultsTree->Fill();
03217               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03218             }
03219         }
03220       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03221 
03222       //-------------------------- Average Pedestals (1 value per Stin)
03223       //       1   fMatHis(1, StexStin)   (12)  cTypAvPed      1*(1,  68) =     68
03224 
03225       MaxCar = fgMaxCar;
03226       typ_name.Resize(MaxCar);
03227       typ_name   = "AvPed";
03228       v_nb_times = fFileHeader->fAvPedCalc;
03229       v_dim_one  = 1;
03230       v_dim_two  = fEcal->MaxStinEcnaInStex();
03231       v_size     = v_nb_times*v_dim_one*v_dim_two;
03232       v_tot     += v_size;
03233  
03234       if(fFlagPrint == fCodePrintAllComments){
03235       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03236            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03237            << setw(9) << v_size;}
03238 
03239       for (Int_t i = 0; i < v_nb_times; i++)
03240         {
03241           if ( fTagAvPed[0] == 1 )
03242             {
03243               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvPed;
03244               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03245               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03246               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03247               TRootAvPed();
03248               gCnaRootFile->fCnaResultsTree->Fill();
03249               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03250             }
03251         }
03252       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03253 
03254       //-------------------------- Average Total noise
03255       // StexEcha   fMatHis(1, StexStin)     ( 3)  cTypAvTno      1*(1,  68) =     68
03256 
03257       MaxCar = fgMaxCar;
03258       typ_name.Resize(MaxCar);
03259       typ_name   = "AvTno";
03260       v_nb_times = fFileHeader->fAvTnoCalc;
03261       v_dim_one  = 1;
03262       v_dim_two  = fEcal->MaxStinEcnaInStex();
03263       v_size     = v_nb_times*v_dim_one*v_dim_two;
03264       v_tot     += v_size;
03265 
03266       if(fFlagPrint == fCodePrintAllComments){
03267       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03268            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03269            << setw(9) << v_size;}
03270 
03271       for (Int_t i = 0; i < v_nb_times; i++)
03272         {
03273           if ( fTagAvTno[0] == 1 )
03274             {
03275               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvTno;
03276               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03277               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03278               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03279               TRootAvTno();
03280               gCnaRootFile->fCnaResultsTree->Fill(); 
03281               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03282             }
03283         }
03284       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03285 
03286       //-------------------------- Average Low frequency noise
03287       //       1   fMatHis(1, StexStin)   ( 4)  cTypAvLfn      1*(1,  68) =     68
03288 
03289       MaxCar = fgMaxCar;
03290       typ_name.Resize(MaxCar);
03291       typ_name   = "AvLfn";
03292       v_nb_times = fFileHeader->fAvLfnCalc;
03293       v_dim_one  = 1;
03294       v_dim_two  = fEcal->MaxStinEcnaInStex();
03295       v_size     = v_nb_times*v_dim_one*v_dim_two;
03296       v_tot     += v_size;
03297  
03298       if(fFlagPrint == fCodePrintAllComments){
03299       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03300            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03301            << setw(9) << v_size;}
03302       
03303       for (Int_t i = 0; i < v_nb_times; i++)
03304         {
03305           if ( fTagAvLfn[0] == 1 )
03306             {
03307               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvLfn;
03308               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03309               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03310               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03311               TRootAvLfn();
03312               gCnaRootFile->fCnaResultsTree->Fill();
03313               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03314             }
03315         }
03316       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03317       
03318       //-------------------------- Average High frequency noise
03319       //       1   fMatHis(1, StexStin)   ( 5)  cTypAvHfn      1*(1,  68) =     68
03320 
03321       MaxCar = fgMaxCar;      
03322       typ_name.Resize(MaxCar);
03323       typ_name   = "AvHfn";
03324       v_nb_times = fFileHeader->fAvHfnCalc;
03325       v_dim_one  = 1;
03326       v_dim_two  = fEcal->MaxStinEcnaInStex();
03327       v_size     = v_nb_times*v_dim_one*v_dim_two;
03328       v_tot     += v_size;
03329  
03330       if(fFlagPrint == fCodePrintAllComments){
03331       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03332            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03333            << setw(9) << v_size;}
03334       
03335       for (Int_t i = 0; i < v_nb_times; i++)
03336         {
03337           if ( fTagAvHfn[0] == 1 )
03338             {
03339               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvHfn;
03340               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03341               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03342               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03343               TRootAvHfn();
03344               gCnaRootFile->fCnaResultsTree->Fill();
03345               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03346             }
03347         }
03348       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03349 
03350       //-------------------------- Average mean cor(s,s)
03351       //       1   fMatHis(1, StexStin)   (13)  cTypAvMeanCorss      1*(1,  68) =     68
03352 
03353       MaxCar = fgMaxCar;
03354       typ_name.Resize(MaxCar);
03355       typ_name   = "AvMeanCorss";
03356       v_nb_times = fFileHeader->fAvMeanCorssCalc;
03357       v_dim_one  = 1;
03358       v_dim_two  = fEcal->MaxStinEcnaInStex();
03359       v_size     = v_nb_times*v_dim_one*v_dim_two;
03360       v_tot     += v_size;
03361  
03362       if(fFlagPrint == fCodePrintAllComments){
03363       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03364            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03365            << setw(9) << v_size;}
03366 
03367       for (Int_t i = 0; i < v_nb_times; i++)
03368         {
03369           if ( fTagAvMeanCorss[0] == 1 )
03370             {
03371               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvMeanCorss;
03372               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03373               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03374               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03375               TRootAvEvCorss();
03376               gCnaRootFile->fCnaResultsTree->Fill();
03377               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03378             }
03379         }
03380       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03381       
03382       //--------------------------  Average sigma of cor(s,s)
03383       //       1   fMatHis(1, StexStin)    (14)  cTypAvSigCorss      1*(1,  68) =     68
03384 
03385       MaxCar = fgMaxCar;
03386       typ_name.Resize(MaxCar);
03387       typ_name   = "AvSigCorss";
03388       v_nb_times = fFileHeader->fAvSigCorssCalc;
03389       v_dim_one  = 1;
03390       v_dim_two  = fEcal->MaxStinEcnaInStex();
03391       v_size     = v_nb_times*v_dim_one*v_dim_two;
03392       v_tot     += v_size;
03393  
03394       if(fFlagPrint == fCodePrintAllComments){
03395       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03396            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03397            << setw(9) << v_size;}
03398 
03399       for (Int_t i = 0; i < v_nb_times; i++)
03400         {
03401           if ( fTagAvSigCorss[0] == 1 )
03402             {
03403               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAvSigCorss;
03404               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03405               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03406               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03407               TRootAvSigCorss();
03408               gCnaRootFile->fCnaResultsTree->Fill();
03409               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03410             }
03411         }
03412       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03413 
03414       //-------------------------- Expectation values of the expectation values of the samples (pedestals)
03415       //       1   fMatHis(1,StexEcha)         (16)  cTypPed                1*(   1,1700) =      1 700
03416 
03417       MaxCar = fgMaxCar;
03418       typ_name.Resize(MaxCar);
03419       typ_name   = "Ped";
03420       v_nb_times = fFileHeader->fPedCalc;
03421       v_dim_one  = 1;
03422       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03423       v_size     = v_nb_times*v_dim_one*v_dim_two;
03424       v_tot     += v_size;
03425 
03426       if(fFlagPrint == fCodePrintAllComments){
03427       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03428            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03429            << setw(9) << v_size;}
03430 
03431       for (Int_t i = 0; i < v_nb_times; i++)
03432         {
03433           if ( fTagPed[0] == 1 )
03434             {
03435               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypPed;
03436               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03437               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03438               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03439               TRootPed();
03440               gCnaRootFile->fCnaResultsTree->Fill();
03441               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03442             }
03443         }
03444       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03445                   
03446       //-------------------------- Expectation values of the sigmas the samples
03447       //       1   fMatHis(1,StexEcha)         (17)  cTypTno               1*(   1,1700) =      1 700
03448 
03449       MaxCar = fgMaxCar;
03450       typ_name.Resize(MaxCar);
03451       typ_name   = "Tno";
03452       v_nb_times = fFileHeader->fTnoCalc;
03453       v_dim_one  = 1;
03454       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03455       v_size     = v_nb_times*v_dim_one*v_dim_two;
03456       v_tot     += v_size;
03457 
03458       if(fFlagPrint == fCodePrintAllComments){
03459       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03460            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03461            << setw(9) << v_size;}
03462 
03463       for (Int_t i = 0; i < v_nb_times; i++)
03464         {
03465           if ( fTagTno[0] == 1 )
03466             {
03467               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypTno;
03468               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03469               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03470               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03471               TRootTno();
03472               gCnaRootFile->fCnaResultsTree->Fill();
03473               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03474             }
03475         }
03476       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03477                                      
03478       //-------------------------- Expectation values of the correlations between the samples
03479       //       1   fMatHis(1,StexEcha)         (10)  cTypMeanCorss            1*(   1,1700) =      1 700
03480 
03481       MaxCar = fgMaxCar;
03482       typ_name.Resize(MaxCar);
03483       typ_name   = "MeanCorss";
03484       v_nb_times = fFileHeader->fMeanCorssCalc;
03485       v_dim_one  = 1;
03486       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03487       v_size     = v_nb_times*v_dim_one*v_dim_two;
03488       v_tot     += v_size;
03489 
03490       if(fFlagPrint == fCodePrintAllComments){
03491       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03492            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03493            << setw(9) << v_size;}
03494 
03495       for (Int_t i = 0; i < v_nb_times; i++)
03496         {
03497           if ( fTagMeanCorss[0] == 1 )
03498             {
03499               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypMeanCorss;
03500               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03501               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03502               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03503               TRootMeanCorss();
03504               gCnaRootFile->fCnaResultsTree->Fill();
03505               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03506             }
03507         } 
03508       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03509       
03510       //-------------------------- Sigmas of the expectation values of the samples  
03511       //       1   fMatHis(1,StexEcha)         (18)  cTypLfn               1*(   1,1700) =      1 700
03512 
03513       MaxCar = fgMaxCar;
03514       typ_name.Resize(MaxCar);
03515       typ_name   = "Lfn";
03516       v_nb_times = fFileHeader->fLfnCalc;
03517       v_dim_one  = 1;
03518       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03519       v_size     = v_nb_times*v_dim_one*v_dim_two;
03520       v_tot     += v_size;
03521 
03522       if(fFlagPrint == fCodePrintAllComments){
03523       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03524            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03525            << setw(9) << v_size;}
03526 
03527       for (Int_t i = 0; i < v_nb_times; i++)
03528         {
03529           if ( fTagLfn[0] == 1 )
03530             {
03531               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLfn;
03532               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03533               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03534               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03535               TRootLfn();
03536               gCnaRootFile->fCnaResultsTree->Fill();
03537               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03538             }
03539         } 
03540       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03541       
03542       //-------------------------- Sigmas of the sigmas of the samples  
03543       //       1   fMatHis(1,StexEcha)         (19)  cTypHfn              1*(   1,1700) =      1 700
03544 
03545       MaxCar = fgMaxCar;
03546       typ_name.Resize(MaxCar);
03547       typ_name   = "Hfn";
03548       v_nb_times = fFileHeader->fHfnCalc;
03549       v_dim_one  = 1;
03550       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03551       v_size     = v_nb_times*v_dim_one*v_dim_two;
03552       v_tot     += v_size;
03553 
03554       if(fFlagPrint == fCodePrintAllComments){
03555       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03556            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03557            << setw(9) << v_size;}
03558  
03559       for (Int_t i = 0; i < v_nb_times; i++)
03560         {
03561           if ( fTagHfn[0] == 1 )
03562             {
03563               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHfn;
03564               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03565               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03566               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03567               TRootHfn();
03568               gCnaRootFile->fCnaResultsTree->Fill();
03569               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03570             }
03571         }
03572       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03573                     
03574       //-------------------------- Sigmas of the correlations between the samples  
03575       //       1   fMatHis(1,StexEcha)         (11)  cTypSigCorss           1*(   1,1700) =      1 700
03576 
03577       MaxCar = fgMaxCar;
03578       typ_name.Resize(MaxCar);
03579       typ_name   = "SigCorss";
03580       v_nb_times = fFileHeader->fSigCorssCalc;
03581       v_dim_one  = 1;
03582       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03583       v_size     = v_nb_times*v_dim_one*v_dim_two;
03584       v_tot     += v_size;
03585 
03586       if(fFlagPrint == fCodePrintAllComments){
03587       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03588            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03589            << setw(9) << v_size;}
03590    
03591       for (Int_t i = 0; i < v_nb_times; i++)
03592         {
03593           if ( fTagSigCorss[0] == 1 )
03594             {
03595               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSigCorss;
03596               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03597               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03598               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03599               TRootSigCorss();
03600               gCnaRootFile->fCnaResultsTree->Fill();
03601               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03602             }
03603         }
03604       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03605 
03606       //----- Mean Covariances between StexEchas (averaged over samples) for all (Stin_X,Stin_Y)
03607       //       1   fMatMat(Stin,Stin)       (23)  cTypLFccMoStins         1*(  68,  68) =      4 624
03608 
03609       MaxCar = fgMaxCar;
03610       typ_name.Resize(MaxCar);
03611       typ_name   = "LFccMoStins";
03612       v_nb_times = fFileHeader->fLFccMoStinsCalc;
03613       v_dim_one  = fEcal->MaxStinEcnaInStex();
03614       v_dim_two  = fEcal->MaxStinEcnaInStex();
03615       v_size     = v_nb_times*v_dim_one*v_dim_two;
03616       v_tot     += v_size;
03617  
03618       if(fFlagPrint == fCodePrintAllComments){
03619       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03620            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03621            << setw(9) << v_size;}
03622 
03623       for (Int_t i = 0; i < v_nb_times; i++)
03624         {
03625           if ( fTagLFccMoStins[0] == 1 )
03626             {
03627               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLFccMoStins;
03628               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03629               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03630               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03631               TRootLFccMoStins();
03632               gCnaRootFile->fCnaResultsTree->Fill();
03633               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03634             }
03635         } 
03636       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03637             
03638       //----- Mean Correlations between StexEchas (averaged over samples) for all (Stin_X,Stin_Y)
03639       //       1   fMatMat(Stin,Stin)       (24)  cTypHFccMoStins         1*(  68,  68) =      4 624
03640 
03641       MaxCar = fgMaxCar;
03642       typ_name.Resize(MaxCar);
03643       typ_name   = "HFccMoStins";
03644       v_nb_times = fFileHeader->fHFccMoStinsCalc;
03645       v_dim_one  = fEcal->MaxStinEcnaInStex();
03646       v_dim_two  = fEcal->MaxStinEcnaInStex();
03647       v_size     = v_nb_times*v_dim_one*v_dim_two;
03648       v_tot     += v_size;
03649  
03650       if(fFlagPrint == fCodePrintAllComments){
03651       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03652            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03653            << setw(9) << v_size;}
03654 
03655       for (Int_t i = 0; i < v_nb_times; i++)
03656         {
03657           if ( fTagHFccMoStins[0] == 1 )
03658             {
03659               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHFccMoStins;
03660               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03661               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03662               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03663               TRootHFccMoStins();
03664               gCnaRootFile->fCnaResultsTree->Fill();
03665               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03666             }
03667         }
03668       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03669       
03670       //-------------------------- Numbers of found events (NbOfEvts)
03671       //       1   fMatHis(StexEcha, sample)   (15)  cTypNbOfEvts       1*(1700,  10) =     17 000
03672 
03673       MaxCar = fgMaxCar;
03674       typ_name.Resize(MaxCar);
03675       typ_name   = "NbOfEvts";
03676       v_nb_times = fFileHeader->fNbOfEvtsCalc;
03677       v_dim_one  = fEcal->MaxCrysEcnaInStex();
03678       v_dim_two  = argNbSampWrite;
03679       v_size     = v_nb_times*v_dim_one*v_dim_two;
03680       v_tot     += v_size;
03681  
03682       if(fFlagPrint == fCodePrintAllComments){
03683       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03684            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03685            << setw(9) << v_size;}
03686 
03687       for (Int_t i = 0; i < v_nb_times; i++)
03688         {
03689           if ( fTagNbOfEvts[0] == 1 )
03690             {
03691               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypNbOfEvts;
03692               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03693               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03694               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03695               TRootNbOfEvts(argNbSampWrite);
03696               gCnaRootFile->fCnaResultsTree->Fill();
03697               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03698             }
03699         }
03700       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03701                   
03702       //-------------------------- Expectation values of the samples
03703       //       1   fMatHis(StexEcha, sample)   ( 1)  cTypMSp                  1*(1700,  10) =     17 000
03704 
03705       MaxCar = fgMaxCar;
03706       typ_name.Resize(MaxCar);
03707       typ_name   = "MSp";
03708       v_nb_times = fFileHeader->fMSpCalc;
03709       v_dim_one  = fEcal->MaxCrysEcnaInStex();
03710       v_dim_two  = argNbSampWrite;
03711       v_size     = v_nb_times*v_dim_one*v_dim_two;
03712       v_tot     += v_size;
03713  
03714       if(fFlagPrint == fCodePrintAllComments){
03715       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03716            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03717            << setw(9) << v_size;}
03718 
03719       for (Int_t i = 0; i < v_nb_times; i++)
03720         {
03721           if ( fTagMSp[0] == 1 )
03722             {
03723               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypMSp;
03724               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03725               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03726               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03727               TRootMSp(argNbSampWrite);
03728               gCnaRootFile->fCnaResultsTree->Fill();
03729               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03730             }
03731         }
03732       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03733       
03734       //-------------------------- Sigmas of the samples     
03735       //       1   fMatHis(StexEcha, sample)   ( 2)  cTypSSp                 1*(1700,  10) =     17 000
03736 
03737       MaxCar = fgMaxCar;
03738       typ_name.Resize(MaxCar);
03739       typ_name   = "SSp";
03740       v_nb_times = fFileHeader->fSSpCalc;
03741       v_dim_one  = fEcal->MaxCrysEcnaInStex();
03742       v_dim_two  = argNbSampWrite;
03743       v_size     = v_nb_times*v_dim_one*v_dim_two;
03744       v_tot     += v_size;
03745  
03746       if(fFlagPrint == fCodePrintAllComments){
03747       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03748            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03749            << setw(9) << v_size;}
03750 
03751       for (Int_t i = 0; i < v_nb_times; i++)
03752         {
03753           if ( fTagSSp[0] == 1 )
03754             {
03755               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSSp;
03756               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03757               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03758               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03759               TRootSSp(argNbSampWrite);
03760               gCnaRootFile->fCnaResultsTree->Fill();
03761               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03762             }
03763         }
03764       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03765 
03766       //-------------------------- Covariances between samples
03767 
03768       // StexEcha   fMatMat(sample,  sample)   ( 8)  cTypCovCss           1700*(  10,  10) =    170 000
03769 
03770       MaxCar = fgMaxCar;
03771       typ_name.Resize(MaxCar);
03772       typ_name   = "CovCss";
03773       v_nb_times = fFileHeader->fCovCssCalc;
03774       v_dim_one  = argNbSampWrite;
03775       v_dim_two  = argNbSampWrite;
03776       v_size     = v_nb_times*v_dim_one*v_dim_two;
03777       v_tot     += v_size;
03778  
03779       if(fFlagPrint == fCodePrintAllComments){
03780       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03781            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03782            << setw(9) << v_size;}
03783 
03784       for (Int_t i0StexEcha = 0; i0StexEcha < v_nb_times; i0StexEcha++)
03785         {
03786           if ( fTagCovCss[i0StexEcha] == 1 )
03787             {
03788               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCovCss;
03789               gCnaRootFile->fCnaIndivResult->fIthElement     = i0StexEcha;
03790               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03791               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03792               TRootCovCss(i0StexEcha, argNbSampWrite);
03793               gCnaRootFile->fCnaResultsTree->Fill();
03794               if( i0StexEcha == 0  && fFlagPrint == fCodePrintAllComments)
03795                 {cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03796             }
03797         }
03798       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03799       
03800       //-------------------------- Correlations between samples   
03801       // StexEcha   fMatMat(sample,  sample)   ( 9)  cTypCorCss           1700*(  10,  10) =    170 000
03802 
03803       MaxCar = fgMaxCar;
03804       typ_name.Resize(MaxCar);
03805       typ_name   = "CorCss";
03806       v_nb_times = fFileHeader->fCorCssCalc;
03807       v_dim_one  = argNbSampWrite;
03808       v_dim_two  = argNbSampWrite;
03809       v_size     = v_nb_times*v_dim_one*v_dim_two;
03810       v_tot     += v_size;
03811 
03812       if(fFlagPrint == fCodePrintAllComments){
03813       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03814            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03815            << setw(9) << v_size;}
03816  
03817       for (Int_t i0StexEcha = 0; i0StexEcha < v_nb_times; i0StexEcha++)
03818         {
03819           if ( fTagCorCss[i0StexEcha] == 1 )
03820             {
03821               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCorCss;
03822               gCnaRootFile->fCnaIndivResult->fIthElement     = i0StexEcha;
03823               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03824               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03825               TRootCorCss(i0StexEcha, argNbSampWrite);
03826               gCnaRootFile->fCnaResultsTree->Fill();
03827               if( i0StexEcha == 0  && fFlagPrint == fCodePrintAllComments)
03828                 {cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03829             }     
03830         }
03831       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03832 
03833       //-------------------------- Samples as a function of event = events distributions
03834       // StexEcha   fMatHis(sample,  bins)     (20)  cTypAdcEvt,        1700*(  10, 150) =  2 550 000
03835 
03836       MaxCar = fgMaxCar;
03837       typ_name.Resize(MaxCar);
03838       typ_name   = "AdcEvt";
03839       v_nb_times = fFileHeader->fAdcEvtCalc;
03840       v_dim_one  = argNbSampWrite;
03841       v_dim_two  = fFileHeader->fReqNbOfEvts;
03842       v_size     = v_nb_times*v_dim_one*v_dim_two;
03843       v_tot     += v_size;
03844  
03845       if(fFlagPrint == fCodePrintAllComments){
03846       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03847            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03848            << setw(9) << v_size;}
03849 
03850       for (Int_t i0StexEcha = 0; i0StexEcha < v_nb_times; i0StexEcha++)
03851         {
03852           if ( fTagAdcEvt[i0StexEcha] == 1 )
03853             {
03854               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypAdcEvt;
03855               gCnaRootFile->fCnaIndivResult->fIthElement     = i0StexEcha;
03856               gCnaRootFile->fCnaIndivResult->SetSizeHis(v_dim_one,v_dim_two);
03857               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03858               TRootAdcEvt(i0StexEcha, argNbSampWrite);
03859               gCnaRootFile->fCnaResultsTree->Fill();
03860               if( i0StexEcha == 0  && fFlagPrint == fCodePrintAllComments )
03861                 {cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03862             }
03863         }
03864       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03865 
03866       //-------------------------- Low Frequency Covariances between StexEchas
03867       //  sample   fMatMat(StexEcha, StexEcha)  (21)  cTypLfCov           1*(1700,1700) =  2 890 000
03868 
03869       MaxCar = fgMaxCar;
03870       typ_name.Resize(MaxCar);
03871       typ_name   = "LfCov";
03872       v_nb_times = fFileHeader->fLfCovCalc;
03873       v_dim_one  = fEcal->MaxCrysEcnaInStex();
03874       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03875       v_size     = v_nb_times*v_dim_one*v_dim_two;
03876       v_tot     += v_size;
03877  
03878       if(fFlagPrint == fCodePrintAllComments){
03879       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03880            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03881            << setw(9) << v_size;}
03882 
03883       for (Int_t i = 0; i < v_nb_times; i++)
03884         {      //=================================== Record type EB
03885           if ( fTagLfCov[0] == 1 )
03886             {
03887               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLfCov;
03888               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03889               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03890               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03891               TRootLfCov();
03892               gCnaRootFile->fCnaResultsTree->Fill();
03893               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03894             }
03895         }
03896       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03897       
03898       //-------------------------- Low Frequency Correlations between StexEchas
03899       //  sample   fMatMat(StexEcha, StexEcha)  (22)  cTypLfCor           1*(1700,1700) =  2 890 000
03900 
03901       MaxCar = fgMaxCar;
03902       typ_name.Resize(MaxCar);
03903       typ_name   = "LfCor";
03904       v_nb_times = fFileHeader->fLfCorCalc;
03905       v_dim_one  = fEcal->MaxCrysEcnaInStex();
03906       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03907       v_size     = v_nb_times*v_dim_one*v_dim_two;
03908       v_tot     += v_size;
03909 
03910       if(fFlagPrint == fCodePrintAllComments){
03911       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03912            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03913            << setw(9) << v_size;}
03914 
03915       for (Int_t i = 0; i < v_nb_times; i++)
03916         {
03917           if ( fTagLfCor[0] == 1 )
03918             {
03919               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLfCor;
03920               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03921               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03922               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03923               TRootLfCor();
03924               gCnaRootFile->fCnaResultsTree->Fill();
03925               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03926             }
03927         }
03928       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03929 
03930       //-------------------------- High Frequency Covariances between StexEchas
03931       //  sample   fMatMat(StexEcha, StexEcha)  (6)  cTypHfCov           1*(1700,1700) =  2 890 000
03932 
03933       MaxCar = fgMaxCar;
03934       typ_name.Resize(MaxCar);
03935       typ_name   = "HfCov";
03936       v_nb_times = fFileHeader->fHfCovCalc;
03937       v_dim_one  = fEcal->MaxCrysEcnaInStex();
03938       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03939       v_size     = v_nb_times*v_dim_one*v_dim_two;
03940       v_tot     += v_size;
03941  
03942       if(fFlagPrint == fCodePrintAllComments){
03943       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03944            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03945            << setw(9) << v_size;}
03946 
03947       for (Int_t i = 0; i < v_nb_times; i++)
03948         {
03949           if ( fTagHfCov[0] == 1 )
03950             {
03951               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHfCov;
03952               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03953               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03954               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03955               TRootHfCov();
03956               gCnaRootFile->fCnaResultsTree->Fill();
03957               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03958             }
03959         }
03960       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03961       
03962       //-------------------------- High Frequency Correlations between StexEchas
03963       //  sample   fMatMat(StexEcha, StexEcha)  (7)  cTypHfCor           1*(1700,1700) =  2 890 000
03964 
03965       MaxCar = fgMaxCar;
03966       typ_name.Resize(MaxCar);
03967       typ_name   = "HfCor";
03968       v_nb_times = fFileHeader->fHfCorCalc;
03969       v_dim_one  = fEcal->MaxCrysEcnaInStex();
03970       v_dim_two  = fEcal->MaxCrysEcnaInStex();
03971       v_size     = v_nb_times*v_dim_one*v_dim_two;
03972       v_tot     += v_size;
03973 
03974       if(fFlagPrint == fCodePrintAllComments){
03975       cout << "*TEcnaRun::WriteRootFile(...)> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03976            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03977            << setw(9) << v_size;}
03978 
03979       for (Int_t i = 0; i < v_nb_times; i++)
03980         {
03981           if ( fTagHfCor[0] == 1 )
03982             {
03983               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypHfCor;
03984               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03985               gCnaRootFile->fCnaIndivResult->SetSizeMat(v_dim_one,v_dim_two);
03986               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
03987               TRootHfCor();
03988               gCnaRootFile->fCnaResultsTree->Fill();
03989               if( i == 0 && fFlagPrint == fCodePrintAllComments ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03990             }
03991         }
03992       if(fFlagPrint == fCodePrintAllComments){cout << endl;}
03993 
03994       //---------------------------------------------- WRITING 
03995       //...................................... file 
03996       gCnaRootFile->fRootFile->Write();
03997       //...................................... header
03998       fFileHeader->Write();
03999 
04000       //...................................... status message
04001       if(fFlagPrint == fCodePrintAllComments){
04002         cout << "*TEcnaRun::WriteRootFile(...)> " << setw(20) << "TOTAL: "
04003              << setw(21) << "CALCULATED = " << setw(9) <<  v_tot
04004              << " => WRITTEN ON FILE = "    << setw(9) << v_tot_writ << endl;}
04005 
04006       if(fFlagPrint == fCodePrintAllComments){
04007         cout << "*TEcnaRun::WriteRootFile(...)> Write OK in file " << file_name << " in directory:" << endl
04008              << "                           " << fCnaParPaths->ResultsRootFilePath().Data()
04009              << endl;}
04010 
04011       ok_write = kTRUE;
04012 
04013       //...................................... close
04014       CloseRootFile(file_name);
04015     }
04016   return ok_write;
04017 }  //-------------- End of WriteRootFile(...) -----------------------
04018 
04019 //======================== "PREPA FILL" METHODS ===========================
04020 
04021 //-------------------------------------------------------------------------
04022 //
04023 //  Prepa Fill Stin numbers as a function of the Stin index 
04024 //                       (for writing in the ROOT file)
04025 //
04026 //-------------------------------------------------------------------------
04027 void TEcnaRun::TRootStinNumbers()
04028 {
04029   if (fTagStinNumbers[0] == 1 )
04030     {
04031       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04032         {
04033           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) =
04034             fT1d_StexStinFromIndex[j0StexStinEcna];
04035         }
04036     }
04037 }
04038 
04039 //-------------------------------------------------------------------------
04040 //
04041 //  Prepa Fill last evt numbers for all the (StexEcha,sample)
04042 //                       (for writing in the ROOT file)
04043 //
04044 //-------------------------------------------------------------------------
04045 void TEcnaRun::TRootNbOfEvts(const Int_t& argNbSampWrite)
04046 {
04047   if (fTagNbOfEvts[0] == 1 )
04048     {
04049       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04050         {
04051           for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++)
04052             {
04053               gCnaRootFile->fCnaIndivResult->fMatHis(j0StexEcha, i0Sample) =
04054                 fT2d_NbOfEvts[j0StexEcha][i0Sample];
04055             }
04056         }
04057     }
04058 }
04059 
04060 //-------------------------------------------------------------------------
04061 //
04062 //  Prepa Fill histogram of samples as a function of event
04063 //                       (for writing in the ROOT file)
04064 //
04065 //-------------------------------------------------------------------------
04066 void TEcnaRun::TRootAdcEvt(const Int_t& user_StexEcha, const Int_t& argNbSampWrite)
04067 {
04068   if (fTagAdcEvt[user_StexEcha] == 1 )
04069     {
04070       for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++)
04071         {
04072           //...................... all the bins set to zero
04073           for (Int_t j_bin = 0; j_bin < fFileHeader->fReqNbOfEvts; j_bin++)
04074             {
04075               gCnaRootFile->fCnaIndivResult->fMatHis(i0Sample, j_bin) = (Double_t)0.;
04076             }
04077           //...................... fill the non-zero bins 
04078           for (Int_t j_bin = 0; j_bin < fFileHeader->fReqNbOfEvts; j_bin++)
04079             {
04080               gCnaRootFile->fCnaIndivResult->fMatHis(i0Sample, j_bin) =
04081                 fT3d_AdcValues[user_StexEcha][i0Sample][j_bin]; 
04082             }
04083         }
04084     }
04085 }
04086 
04087 //-------------------------------------------------------------------------
04088 //
04089 //  Prepa Fill expectation values of the samples for all the StexEchas
04090 //                       (for writing in the ROOT file)
04091 //
04092 //-------------------------------------------------------------------------
04093 void TEcnaRun::TRootMSp(const Int_t& argNbSampWrite)
04094 {
04095   if (fTagMSp[0] == 1 )
04096     {
04097       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04098         {
04099           for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++)
04100             {
04101               gCnaRootFile->fCnaIndivResult->fMatHis( j0StexEcha, i0Sample) =
04102                 fT2d_ev[j0StexEcha][i0Sample];
04103             }
04104         }
04105     }
04106 }
04107 
04108 //-------------------------------------------------------------------------
04109 //
04110 //  Prepa Fill sigmas of the samples for all the StexEchas
04111 //                       (for writing in the ROOT file)
04112 //
04113 //-------------------------------------------------------------------------
04114 void TEcnaRun::TRootSSp(const Int_t& argNbSampWrite)
04115 {
04116   if (fTagSSp[0] == 1 )
04117     {
04118       for (Int_t j0StexEcha=0; j0StexEcha<fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04119         {
04120           for (Int_t i0Sample=0; i0Sample<argNbSampWrite; i0Sample++)
04121             {
04122               gCnaRootFile->fCnaIndivResult->fMatHis(j0StexEcha, i0Sample) =
04123                 fT2d_sig[j0StexEcha][i0Sample];
04124             }
04125         }
04126     }
04127 }
04128 
04129 //-------------------------------------------------------------------------
04130 //
04131 //  Prepa Fill mean covariances between StexEchas, mean over samples
04132 //  for all (Stin_X, Stin_Y)
04133 //                           (for writing in ROOT file)
04134 //
04135 //-------------------------------------------------------------------------
04136 void TEcnaRun::TRootLFccMoStins()
04137 {
04138   if (fTagLFccMoStins[0] == 1 )
04139     {
04140       for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
04141         {
04142           for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04143             {
04144               gCnaRootFile->fCnaIndivResult->fMatMat(i0StexStinEcna, j0StexStinEcna) =
04145                 fT2d_lfcc_mostins[i0StexStinEcna][j0StexStinEcna];
04146             }
04147         }
04148     }
04149 }
04150 
04151 //-------------------------------------------------------------------------
04152 //
04153 //  Prepa Fill mean correlations between StexEchas, mean over samples
04154 //  for all (Stin_X, Stin_Y)
04155 //                           (for writing in ROOT file)
04156 //
04157 //-------------------------------------------------------------------------
04158 void TEcnaRun::TRootHFccMoStins()
04159 {
04160   if (fTagHFccMoStins[0] == 1 )
04161     {
04162       for (Int_t i0StexStinEcna = 0; i0StexStinEcna < fEcal->MaxStinEcnaInStex(); i0StexStinEcna++)
04163         {
04164           for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04165             {
04166               gCnaRootFile->fCnaIndivResult->fMatMat(i0StexStinEcna, j0StexStinEcna) =
04167                 fT2d_hfcc_mostins[i0StexStinEcna][j0StexStinEcna];
04168             }
04169         }
04170     }
04171 }
04172 
04173 //-------------------------------------------------------------------------
04174 //
04175 //  Prepa Fill ADC distributions of the samples for all the StexEchas
04176 //                       (for writing in the ROOT file)
04177 //
04178 //-------------------------------------------------------------------------
04179 void TEcnaRun::TRootAvTno()
04180 {
04181   if (fTagAvTno[0] == 1 )
04182     {
04183       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04184         {
04185           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) =
04186             fT1d_av_totn[j0StexStinEcna];
04187         }
04188     }
04189 }
04190 //-------------------------------------------------------------------------
04191 //
04192 //  Prepa Fill ADC distributions xmin of the samples for all the StexEchas
04193 //                       (for writing in the ROOT file)
04194 //
04195 //-------------------------------------------------------------------------
04196 void TEcnaRun::TRootAvLfn()
04197 {
04198   if (fTagAvLfn[0] == 1 )
04199     {
04200       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04201         {
04202           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) =
04203             fT1d_av_lofn[j0StexStinEcna];  
04204         }
04205     }
04206 }
04207 
04208 //-------------------------------------------------------------------------
04209 //
04210 //  Prepa Fill ADC distributions xmax of the samples for all the StexEchas
04211 //                       (for writing in the ROOT file)
04212 //
04213 //-------------------------------------------------------------------------
04214 void TEcnaRun::TRootAvHfn()
04215 {
04216   if (fTagAvHfn[0] == 1 )
04217     {
04218       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04219         {
04220           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) =
04221             fT1d_av_hifn[j0StexStinEcna];  
04222         }
04223     }
04224 }
04225 
04226 //-------------------------------------------------------------------------
04227 //
04228 //  Prepa Fill Low Frequency covariances between StexEchas
04229 //                           (for writing in ROOT file)
04230 //
04231 //-------------------------------------------------------------------------
04232 void TEcnaRun::TRootLfCov()
04233 {
04234   if (fTagLfCov[0] == 1 )
04235     {
04236       for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
04237         {
04238           for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04239             {
04240               gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) =
04241                 fT2d_lf_cov[i0StexEcha][j0StexEcha];
04242             }
04243         }
04244     }
04245 }
04246 
04247 //-------------------------------------------------------------------------
04248 //
04249 //  Prepa Fill Low Frequency correlations between StexEchas
04250 //                         (for writing in ROOT file)
04251 //
04252 //-------------------------------------------------------------------------
04253 void TEcnaRun::TRootLfCor()
04254 {
04255   if (fTagLfCor[0] == 1 )
04256     {
04257       for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
04258         {
04259           for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04260             {
04261               gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) =
04262                 fT2d_lf_cor[i0StexEcha][j0StexEcha];
04263             }
04264         }
04265     }
04266 }
04267 
04268 //-------------------------------------------------------------------------
04269 //
04270 //  Prepa Fill High Frequency covariances between StexEchas
04271 //                           (for writing in ROOT file)
04272 //
04273 //-------------------------------------------------------------------------
04274 void TEcnaRun::TRootHfCov()
04275 {
04276   if (fTagHfCov[0] == 1 )
04277     {
04278       for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
04279         {
04280           for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04281             {
04282               gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) =
04283                 fT2d_hf_cov[i0StexEcha][j0StexEcha];
04284             }
04285         }
04286     }
04287 }
04288 
04289 //-------------------------------------------------------------------------
04290 //
04291 //  Prepa Fill High Frequency correlations between StexEchas
04292 //                         (for writing in ROOT file)
04293 //
04294 //-------------------------------------------------------------------------
04295 void TEcnaRun::TRootHfCor()
04296 {
04297   if (fTagHfCor[0] == 1 )
04298     {
04299       for (Int_t i0StexEcha = 0; i0StexEcha < fEcal->MaxCrysEcnaInStex(); i0StexEcha++)
04300         {
04301           for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04302             {
04303               gCnaRootFile->fCnaIndivResult->fMatMat(i0StexEcha, j0StexEcha) =
04304                 fT2d_hf_cor[i0StexEcha][j0StexEcha];
04305             }
04306         }
04307     }
04308 }
04309 
04310 
04311 //-------------------------------------------------------------------------
04312 //
04313 //  Prepa Fill covariances between samples for a given StexEcha
04314 //                      (for writing in ROOT file)
04315 //
04316 //-------------------------------------------------------------------------
04317 void TEcnaRun::TRootCovCss(const Int_t& user_StexEcha, const Int_t& argNbSampWrite)
04318 {
04319    if (fTagCovCss[user_StexEcha] == 1 )
04320      {
04321        for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++)
04322          {
04323            for (Int_t j0Sample = 0; j0Sample < argNbSampWrite; j0Sample++)
04324              {
04325                gCnaRootFile->fCnaIndivResult->fMatMat(i0Sample, j0Sample) =
04326                  fT3d_cov_ss[user_StexEcha][i0Sample][j0Sample];
04327              }
04328          }
04329      }
04330 }
04331 
04332 //-------------------------------------------------------------------------
04333 //
04334 //  Prepa Fill correlations between samples for a given StexEcha
04335 //                        (for writing in ROOT file)
04336 //
04337 //-------------------------------------------------------------------------
04338 void TEcnaRun::TRootCorCss(const Int_t& user_StexEcha, const Int_t& argNbSampWrite)
04339 {
04340    if (fTagCorCss[user_StexEcha] == 1 )
04341      {
04342        for (Int_t i0Sample = 0; i0Sample < argNbSampWrite; i0Sample++)
04343          {
04344            for (Int_t j0Sample = 0; j0Sample < argNbSampWrite; j0Sample++)
04345              {
04346                gCnaRootFile->fCnaIndivResult->fMatMat(i0Sample, j0Sample) =
04347                  fT3d_cor_ss[user_StexEcha][i0Sample][j0Sample];
04348              }
04349          }
04350      }
04351 }
04352 
04353 //-------------------------------------------------------------------------
04354 //
04355 //  Prepa Fill expectation values of the expectation values of the samples
04356 //  for all the StexEchas
04357 //                        (for writing in ROOT file)
04358 //
04359 //-------------------------------------------------------------------------
04360 void TEcnaRun::TRootPed()
04361 {
04362   if (fTagPed[0] == 1 )
04363     {
04364       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04365         {
04366           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) =
04367             fT1d_ev_ev[j0StexEcha];
04368         }      
04369     }
04370 }
04371 //-------------------------------------------------------------------------
04372 //
04373 //  Prepa Fill expectation values of the sigmas of the samples
04374 //  for all the StexEchas
04375 //                        (for writing in ROOT file)
04376 //
04377 //-------------------------------------------------------------------------
04378 void TEcnaRun::TRootTno()
04379 {
04380   if (fTagTno[0] == 1 )
04381     {
04382       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04383         {
04384           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) =
04385             fT1d_evsamp_of_sigevt[j0StexEcha];
04386         }      
04387     }
04388 }
04389 
04390 //-------------------------------------------------------------------------
04391 //
04392 //  Prepa Fill expectation values of the (sample,sample) correlations
04393 //  for all the StexEchas
04394 //                        (for writing in ROOT file)
04395 //
04396 //-------------------------------------------------------------------------
04397 void TEcnaRun::TRootMeanCorss()
04398 {
04399   if (fTagMeanCorss[0] == 1 )
04400     {
04401       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04402         {
04403           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) =
04404             fT1d_ev_cor_ss[j0StexEcha];
04405         }      
04406     }
04407 }
04408 
04409 //-------------------------------------------------------------------------
04410 //
04411 //  Prepa Fill sigmas of the expectation values of the samples
04412 //  for all the StexEchas
04413 //                        (for writing in ROOT file)
04414 //
04415 //-------------------------------------------------------------------------
04416 void TEcnaRun::TRootLfn()
04417 {
04418   if (fTagLfn[0] == 1 )
04419     {
04420       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04421         {
04422           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) =
04423             fT1d_sigevt_of_evsamp[j0StexEcha];
04424         }      
04425     }
04426 }
04427 
04428 //-------------------------------------------------------------------------
04429 //
04430 //  Prepa Fill sigmas of the expectation values of the sigmas
04431 //  for all the StexEchas
04432 //                        (for writing in ROOT file)
04433 //
04434 //-------------------------------------------------------------------------
04435 void TEcnaRun::TRootHfn()
04436 {
04437   if (fTagHfn[0] == 1 )
04438     {
04439       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04440         {
04441           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) =
04442             fT1d_evevt_of_sigsamp[j0StexEcha];
04443         }      
04444     }
04445 }
04446 
04447 //-------------------------------------------------------------------------
04448 //
04449 //  Prepa Fill sigmas of the (sample,sample) correlations
04450 //  for all the StexEchas
04451 //                        (for writing in ROOT file)
04452 //
04453 //-------------------------------------------------------------------------
04454 void TEcnaRun::TRootSigCorss()
04455 {
04456   if (fTagSigCorss[0] == 1 )
04457     {
04458       for (Int_t j0StexEcha = 0; j0StexEcha < fEcal->MaxCrysEcnaInStex(); j0StexEcha++)
04459         {
04460           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexEcha) =
04461             fT1d_sig_cor_ss[j0StexEcha];
04462         }      
04463     }
04464 }
04465 
04466 //-------------------------------------------------------------------------
04467 //
04468 //  Prepa Fill Average Pedestals
04469 //  for all the StexStins
04470 //                        (for writing in ROOT file)
04471 //
04472 //-------------------------------------------------------------------------
04473 void TEcnaRun::TRootAvPed()
04474 {
04475   if (fTagAvPed[0] == 1 )
04476     {
04477       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04478         {
04479           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) =
04480             fT1d_av_mped[j0StexStinEcna];
04481         }
04482     }
04483 }
04484 
04485 //-------------------------------------------------------------------------
04486 //
04487 //  Prepa Fill 
04488 //  
04489 //                        (for writing in ROOT file)
04490 //
04491 //-------------------------------------------------------------------------
04492 void TEcnaRun::TRootAvEvCorss()
04493 {
04494   if (fTagAvMeanCorss[0] == 1 )   // test 1st elt only since global calc
04495     {
04496       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04497         {
04498           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) =
04499             fT1d_av_ev_corss[j0StexStinEcna];
04500         }
04501     }
04502 }
04503 
04504 //-------------------------------------------------------------------------
04505 //
04506 //  Prepa Fill 
04507 //  
04508 //                        (for writing in ROOT file)
04509 //
04510 //-------------------------------------------------------------------------
04511 void TEcnaRun::TRootAvSigCorss()
04512 {
04513   if (fTagAvSigCorss[0] == 1 )   // test 1st elt only since global calc
04514     {
04515       for (Int_t j0StexStinEcna = 0; j0StexStinEcna < fEcal->MaxStinEcnaInStex(); j0StexStinEcna++)
04516         {
04517           gCnaRootFile->fCnaIndivResult->fMatHis(0, j0StexStinEcna) =
04518             fT1d_av_sig_corss[j0StexStinEcna];
04519         } 
04520     }
04521 }
04522 
04523 //=========================================================================
04524 //
04525 //         METHODS TO SET FLAGS TO PRINT (OR NOT) COMMENTS (DEBUG)
04526 //
04527 //=========================================================================
04528 
04529 void TEcnaRun::PrintComments()
04530 {
04531 // Set flags to authorize printing of some comments concerning initialisations (default)
04532 
04533   fFlagPrint = fCodePrintComments;
04534   cout << "*TEcnaRun::PrintComments()> Warnings and some comments on init will be printed" << endl;
04535 }
04536 
04537 void TEcnaRun::PrintWarnings()
04538 {
04539 // Set flags to authorize printing of warnings
04540 
04541   fFlagPrint = fCodePrintWarnings;
04542   cout << "*TEcnaRun::PrintWarnings()> Warnings will be printed" << endl;
04543 }
04544 
04545 void TEcnaRun::PrintAllComments()
04546 {
04547 // Set flags to authorize printing of the comments of all the methods
04548 
04549   fFlagPrint = fCodePrintAllComments;
04550   cout << "*TEcnaRun::PrintAllComments()> All the comments will be printed" << endl;
04551 }
04552 
04553 void  TEcnaRun::PrintNoComment()
04554 {
04555 // Set flags to forbid the printing of all the comments
04556 
04557   fFlagPrint = fCodePrintNoComment;
04558 }
04559 //=========================== E N D ======================================