CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/src/TEcnaRead.cc

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