CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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   if(fReadyToReadRootFile == 1)
00929     {
00930       //------------ Call to ReadRootFileHeader
00931       Int_t iprint = 0;
00932       if( ReadRootFileHeader(iprint) == kTRUE )   //    (1) = print, (0) = no print
00933         {
00934           //........................................ allocation tags      
00935           if( fTagStinNumbers == 0 ){fTagStinNumbers = new Int_t[1]; Anew("fTagStinNumbers");}
00936 
00937           //...................... allocation for fT1d_StexStinFromIndex[]
00938           if(fT1d_StexStinFromIndex == 0)
00939             {fT1d_StexStinFromIndex = new Int_t[fEcal->MaxStinEcnaInStex()]; Anew("fT1d_StexStinFromIndex");}
00940           
00941           //.. recover of the Stin numbers from the ROOT file (= init fT1d_StexStinFromIndex+init TagStin)
00942           TVectorD vec(fEcal->MaxStinEcnaInStex());
00943           for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
00944           vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
00945           
00946           for (Int_t i = 0; i < fEcal->MaxStinEcnaInStex(); i++ ){
00947             fT1d_StexStinFromIndex[i] = (Int_t)vec(i);}
00948 
00949           fTagStinNumbers[0] = 1;                fFileHeader->fStinNumbersCalc++;
00950           
00951           fLookAtRootFile = 1;           // set flag
00952           return kTRUE;
00953         }
00954       else
00955         {
00956           cout << "!TEcnaRead::LookAtRootFile()> *** ERROR ***>"
00957                << " ROOT file not found " << fTTBELL << endl;
00958           return kFALSE; 
00959         }
00960     }
00961   else
00962     {
00963       cout << "!TEcnaRead::LookAtRootFile()> *** ERROR ***>"
00964            << " FileParameters not called " << fTTBELL << endl;
00965       return kFALSE;      
00966     }
00967   return kFALSE;
00968 } //----------------- end of LookAtRootFile()
00969 //-------------------------------------------------------------------------
00970 //
00971 //                     DataExist()
00972 //
00973 //     DON'T SUPPRESS: CALLED BY ANOTHER CLASSES
00974 //
00975 //-------------------------------------------------------------------------
00976 Bool_t TEcnaRead::DataExist()
00977 {
00978   // return kTRUE if the data are present in the ROOT file, kFALSE if not.
00979   // fDataExist is set in the read methods
00980 
00981   return fDataExist;
00982 }
00983 //-------------------------------------------------------------------------
00984 //
00985 //                     ReadRootFileHeader
00986 //
00987 //-------------------------------------------------------------------------
00988 Bool_t TEcnaRead::ReadRootFileHeader(const Int_t& i_print)
00989 {
00990 //Read the header of the Root file => test the file existence
00991 
00992   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
00993   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
00994 
00995   if( i_print == 1 ){cout << "*TEcnaRead::ReadRootFileHeader> file_name = "
00996                          << fCnaWrite->fRootFileNameShort.Data() << endl;}
00997 
00998   Bool_t ok_open = kFALSE;
00999  
01000   TString FileNameLong = fCnaWrite->GetRootFileName(); 
01001   Bool_t allowed_to_read = kFALSE;
01002 
01003   //  if( fOpenRootFile )
01004   //    {
01005   //      cout << "!TEcnaRead::ReadRootFileHeader(...)*** ERROR ***> "
01006   //       << "Reading header on file already open." << endl;
01007   //    }
01008 
01009   if( FileNameLong == fCurrentlyOpenFileName )
01010     {
01011       allowed_to_read = kTRUE;
01012     }
01013   else
01014     {
01015       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01016       ok_open = OpenRootFile(file_name, "READ");
01017       if(ok_open)
01018         {
01019           allowed_to_read = kTRUE;
01020         }
01021       else
01022         {
01023           cout << "!TEcnaRead::ReadRootFileHeader(...) *** ERROR ***> Open .root file failed for file: "
01024                << file_name << fTTBELL << endl;
01025           allowed_to_read = kFALSE;
01026         }
01027     }
01028 
01029   if( allowed_to_read == kTRUE )
01030     {
01031       TEcnaHeader *headerFile;
01032       headerFile =(TEcnaHeader*)gCnaRootFile->fRootFile->Get("CnaHeader");
01033 
01034       //..... get the attributes which are not already set by the call to TEcnaHeader
01035       //      in FileParameters(...) and are only available in the ROOT file
01036 
01037       fFileHeader->fStartTime = headerFile->fStartTime;
01038       fFileHeader->fStopTime  = headerFile->fStopTime;
01039       fFileHeader->fStartDate = headerFile->fStartDate;
01040       fFileHeader->fStopDate  = headerFile->fStopDate;
01041 
01042       fFileHeader->fRunType   = headerFile->fRunType;
01043 
01044       //....... Les f..Calc dans le header: pour acces direct a la taille des differentes data du fichier
01045       fFileHeader->fStinNumbersCalc = headerFile->fStinNumbersCalc;
01046       fFileHeader->fAdcEvtCalc      = headerFile->fAdcEvtCalc;
01047       fFileHeader->fMSpCalc         = headerFile->fMSpCalc;
01048       fFileHeader->fSSpCalc         = headerFile->fSSpCalc;
01049       fFileHeader->fAvTnoCalc       = headerFile->fAvTnoCalc;
01050       fFileHeader->fAvLfnCalc       = headerFile->fAvLfnCalc;
01051       fFileHeader->fAvHfnCalc       = headerFile->fAvHfnCalc;
01052 
01053       fFileHeader->fCovCssCalc      = headerFile->fCovCssCalc;
01054       fFileHeader->fCorCssCalc      = headerFile->fCorCssCalc;
01055       fFileHeader->fHfCovCalc       = headerFile->fHfCovCalc;
01056       fFileHeader->fHfCorCalc       = headerFile->fHfCorCalc;
01057       fFileHeader->fLfCovCalc       = headerFile->fLfCovCalc;
01058       fFileHeader->fLfCorCalc       = headerFile->fLfCorCalc;
01059       fFileHeader->fLFccMoStinsCalc = headerFile->fLFccMoStinsCalc;
01060       fFileHeader->fHFccMoStinsCalc = headerFile->fHFccMoStinsCalc;
01061       fFileHeader->fMeanCorssCalc   = headerFile->fMeanCorssCalc;
01062       fFileHeader->fSigCorssCalc    = headerFile->fSigCorssCalc;
01063 
01064       fFileHeader->fAvPedCalc       = headerFile->fAvPedCalc;
01065       fFileHeader->fAvMeanCorssCalc = headerFile->fAvMeanCorssCalc;
01066       fFileHeader->fAvSigCorssCalc  = headerFile->fAvSigCorssCalc;
01067           
01068       if(i_print == 1){fFileHeader->Print();}
01069 
01070       CloseRootFile(file_name);
01071       return kTRUE;
01072     }
01073   return kFALSE;
01074 }
01075 //-------------------------------------------------------------------------
01076 void  TEcnaRead::TestArrayDimH1(const TString CallingMethod, const TString MaxName,
01077                                 const Int_t& MaxValue, const Int_t& VecDim)
01078 {
01079 // array dim test
01080 
01081   if( MaxValue != VecDim)
01082     {
01083       cout << "!TEcnaRead::TestArrayDimH1(...)> No matching for array dimension: CallingMethod: " << CallingMethod.Data()
01084            << ", MaxName: " << MaxName.Data()
01085            << ", Maxvalue = " << MaxValue
01086            << ", VecDim = " << VecDim << fTTBELL << endl;
01087     }
01088 #define NOPM
01089 #ifndef NOPM
01090   else
01091     {
01092       cout << "!TEcnaRead::TestArrayDimH1(...)> matching array dimension: OK. CallingMethod: " << CallingMethod.Data()
01093            << ", MaxName: " << MaxName.Data()
01094            << ", Maxvalue = " << MaxValue
01095            << ", VecDim = " << VecDim << endl;
01096     }
01097 #endif // NOPM
01098 }
01099 //-------------------------------------------------------------------------
01100 void  TEcnaRead::TestArrayDimH2(const TString CallingMethod, const TString MaxName,
01101                                 const Int_t& MaxValue, const Int_t& MatDim)
01102 {
01103 // array dim test
01104 
01105   if( MaxValue != MatDim)
01106     {
01107       cout << "!TEcnaRead::TestArrayDimH2(...)> No matching for array dimension: CallingMethod: " << CallingMethod.Data()
01108            << ", MaxName: " << MaxName.Data()
01109            << ", Maxvalue = " << MaxValue
01110            << ", MatDim = " << MatDim << fTTBELL << endl;
01111     }
01112 #define NOPN
01113 #ifndef NOPN
01114   else
01115     {
01116       cout << "!TEcnaRead::TestArrayDimH2(...)> matching array dimension: OK. CallingMethod: " << CallingMethod.Data()
01117            << ", MaxName: " << MaxName.Data()
01118            << ", Maxvalue = " << MaxValue
01119            << ", MatDim = " << MatDim << endl;
01120     }
01121 #endif // NOPN
01122 }
01123 
01124 //-------------------------------------------------------------------------
01125 //
01126 //                     ReadStinNumbers(...)
01127 //
01128 //-------------------------------------------------------------------------
01129 TVectorD TEcnaRead::ReadStinNumbers(const Int_t& VecDim)
01130 {
01131 //Get the Stin numbers and put them in a TVectorD
01132 //Read the ROOT file at first call and load in a TVectorD attribute
01133 //Get directly the TVectorD attribute at other times
01134 //
01135 // Possible values for VecDim:
01136 //          (1) VecDim = fEcal->MaxStinEcnaInStex()
01137 
01138   TVectorD vec(VecDim);
01139 
01140   TestArrayDimH1("ReadStinNumbers", "fEcal->MaxStinEcnaInStex()", fEcal->MaxStinEcnaInStex(), VecDim);
01141 
01142   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01143 
01144   if (fMemoStinNumbers == 0)
01145     {
01146       CnaResultTyp typ = cTypNumbers;
01147       const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01148       const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01149 
01150       //.............. reading of the ROOT file data type TResultTyp = cTypStinsNumbers
01151       //               to get the conversion: Stin index -> Stin number (n1StexStin)
01152 
01153       Bool_t ok_open = kFALSE;
01154       Bool_t ok_read = kFALSE;
01155 
01156       TString FileNameLong = fCnaWrite->GetRootFileName();
01157       Bool_t allowed_to_read = kFALSE;
01158 
01159 //      if ( fOpenRootFile )
01160 //      {
01161 //        cout << "!TEcnaRead::ReadStinNumbers(...) *** ERROR ***> Reading on file already open."
01162 //             << fTTBELL << endl;
01163 //      }
01164 
01165       if( FileNameLong == fCurrentlyOpenFileName )
01166         {
01167           allowed_to_read = kTRUE;
01168         }
01169       else
01170         {
01171           if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01172           ok_open = OpenRootFile(file_name, "READ");
01173           
01174           if(ok_open)
01175             {
01176               allowed_to_read = kTRUE;
01177             }
01178           else
01179             {
01180               cout << "!TEcnaRead::ReadStinNumbers(...) *** ERROR ***> Open .root file failed for file: "
01181                    << file_name << fTTBELL << endl;
01182               allowed_to_read = kFALSE;
01183               ok_read = kFALSE;
01184             }
01185         }
01186 
01187       if( allowed_to_read == kTRUE )
01188         {
01189           Int_t i_zero = 0;
01190           ok_read = gCnaRootFile->ReadElement(typ, i_zero);
01191           
01192           if( ok_read == kTRUE )
01193             {
01194               fDataExist = kTRUE;
01195               //......... Get the Stin numbers and put them in TVectorD vec()
01196               for ( Int_t i_Stin = 0; i_Stin < VecDim; i_Stin++)
01197                 {
01198                   vec(i_Stin) = gCnaRootFile->fCnaIndivResult->fMatHis(0,i_Stin);
01199                   fT1d_StexStinFromIndex[i_Stin] = (Int_t)vec(i_Stin);
01200                 }
01201               fMemoStinNumbers++;
01202             }
01203           else
01204             {
01205               fDataExist = kFALSE;
01206               cout << "!TEcnaRead::ReadStinNumbers(...) *** ERROR ***> "
01207                    << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01208                    << "                                                -> quantity: <"
01209                    << GetTypeOfQuantity(typ) << "> not available in file."
01210                    << fTTBELL << endl;
01211             }
01212           CloseRootFile(file_name);
01213         }
01214       
01215       if( ok_read == kTRUE )
01216         {
01217           //........................... Print the Stin numbers 
01218           if(fFlagPrint == fCodePrintAllComments)
01219             {
01220               for(Int_t i=0; i < VecDim; i++)
01221                 {
01222                   cout << "*TEcnaRead::ReadStinNumbers(...)> StinNumber[" << i << "] = "
01223                        << vec[i] << endl;
01224                 }
01225             }
01226         }
01227     }
01228   else
01229     {
01230       fDataExist = kTRUE;
01231       for ( Int_t i_Stin = 0; i_Stin < VecDim; i_Stin++)
01232         {vec(i_Stin) = fT1d_StexStinFromIndex[i_Stin];}
01233     }
01234   return vec;
01235 } // ----------------- ( end of ReadStinNumbers(...) ) -----------------
01236 
01237 //============================================================================
01238 //
01239 //                       1 D   H I S T O S   (TECHNICAL METHODS)
01240 //
01241 //============================================================================
01242 
01243 //--------------------------------------------------------------------------------------
01244 //
01245 //                 ReadSampleAdcValues(i0StexEcha,sample,fFileHeader->fReqNbOfEvts)  
01246 //
01247 //--------------------------------------------------------------------------------------
01248 TVectorD TEcnaRead::ReadSampleAdcValues(const Int_t& n1StexStin, const Int_t& i0StinEcha,
01249                                         const Int_t& sample,     const Int_t& VecDim)
01250 {
01251 //Read the sample ADC values for each event for a given i0StexEcha and a given sample
01252 //in the results ROOT file and return it in a TVectorD(requested nb of events)
01253 //
01254 //Possible values for VecDim: (1) VecDim = fFileHeader->fReqNbOfEvts
01255 
01256   TestArrayDimH1("ReadSampleAdcValues", "fFileHeader->fReqNbOfEvts", fFileHeader->fReqNbOfEvts, VecDim);
01257 
01258   Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
01259 
01260   TVectorD vec(VecDim);
01261   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01262 
01263   CnaResultTyp typ = cTypAdcEvt;   //  sample as a function of time type
01264 
01265   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01266   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01267 
01268   Bool_t ok_open = kFALSE;
01269   Bool_t ok_read = kFALSE;
01270 
01271   TString FileNameLong = fCnaWrite->GetRootFileName();
01272   Bool_t allowed_to_read = kFALSE;
01273   
01274   //  if ( fOpenRootFile )
01275   //   {
01276   //     cout << "!TEcnaRead::ReadSampleAdcValues(...) *** ERROR ***> "
01277   //       << "Reading on file already open." << fTTBELL << endl;
01278   //   }
01279   
01280   if( FileNameLong == fCurrentlyOpenFileName )
01281     {
01282       allowed_to_read = kTRUE;
01283     }
01284   else
01285     {
01286       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01287       ok_open = OpenRootFile(file_name, "READ");
01288 
01289       if(ok_open)
01290         {
01291           allowed_to_read = kTRUE;
01292         }
01293       else
01294         {
01295           cout << "!TEcnaRead::ReadSampleAdcValues(...) *** ERROR ***> Open .root file failed for file: "
01296                << file_name << fTTBELL << endl;
01297           allowed_to_read = kFALSE;
01298           ok_read = kFALSE;
01299         }
01300     }
01301   
01302   if( allowed_to_read == kTRUE )
01303     {
01304       ok_read = gCnaRootFile->ReadElement(typ, i0StexEcha);
01305       
01306       if ( ok_read == kTRUE )
01307         {
01308           fDataExist = kTRUE;
01309           for ( Int_t i_bin=0; i_bin<VecDim; i_bin++)
01310             {
01311               vec(i_bin) = gCnaRootFile->fCnaIndivResult->fMatHis(sample, i_bin);
01312             }   
01313         }
01314       else
01315         {
01316           fDataExist = kFALSE;
01317           cout << "!TEcnaRead::ReadSampleAdcValues(...) *** ERROR ***> "
01318                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01319                << "                                                 -> quantity: <"
01320                << GetTypeOfQuantity(typ) << "> not available in file."
01321                << fTTBELL << endl;
01322         }
01323       CloseRootFile(file_name);
01324     }
01325   return vec;
01326 }
01327 //--- (end of ReadSampleAdcValues) ----------
01328 
01329 
01330 //-------------------------------------------------------------------------
01331 //
01332 //                  ReadSampleMeans  
01333 //
01334 //-------------------------------------------------------------------------
01335 TVectorD TEcnaRead::ReadSampleMeans(const Int_t & n1StexStin, const Int_t & i0StinEcha,
01336                                     const Int_t & VecDim)
01337 {
01338 //Read the expectation values of the samples
01339 //for a given Stin and a given channel
01340 //in the ROOT file and return them in a TVectorD
01341 //
01342 //Possible values for VecDim : (1) VecDim = fFileHeader->fNbOfSamples
01343 
01344   TestArrayDimH1("ReadSampleMeans", "fFileHeader->fNbOfSamples", fFileHeader->fNbOfSamples, VecDim);
01345 
01346   Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
01347   
01348   TVectorD vec(VecDim);
01349   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01350 
01351   CnaResultTyp typ = cTypMSp;
01352 
01353   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01354   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01355 
01356   Bool_t ok_open = kFALSE;
01357   Bool_t ok_read = kFALSE;
01358 
01359   TString FileNameLong = fCnaWrite->GetRootFileName();
01360   Bool_t allowed_to_read = kFALSE;
01361     
01362   // if ( fOpenRootFile )
01363   //  {
01364   //    cout << "!TEcnaRead::ReadSampleMeans(...) *** ERROR ***> "
01365   //       << " Reading on file already open." << fTTBELL << endl;
01366   //  }
01367 
01368   if( FileNameLong == fCurrentlyOpenFileName )
01369     {
01370       allowed_to_read = kTRUE;
01371     }
01372   else
01373     {
01374       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01375       ok_open = OpenRootFile(file_name, "READ");
01376       if(ok_open)
01377         {
01378           allowed_to_read = kTRUE;
01379         }
01380       else
01381         {
01382           cout << "!TEcnaRead::ReadSampleMeans(...) *** ERROR ***> Open .root file failed for file: "
01383                << file_name << fTTBELL << endl;
01384           allowed_to_read = kFALSE;
01385           ok_read = kFALSE;
01386         }
01387     }
01388   
01389   if( allowed_to_read == kTRUE )
01390     {
01391       Int_t i_zero = 0;
01392       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
01393       
01394       if ( ok_read == kTRUE )
01395         {
01396           fDataExist = kTRUE;
01397           for ( Int_t i_samp = 0; i_samp < VecDim; i_samp++)
01398             {
01399               vec(i_samp) = gCnaRootFile->fCnaIndivResult->fMatHis(i0StexEcha, i_samp);
01400             }   
01401         }
01402       else
01403         {
01404           fDataExist = kFALSE;
01405           cout << "!TEcnaRead::ReadSampleMeans(...) *** ERROR ***> "
01406                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01407                << "                                                quantity: <"
01408                << GetTypeOfQuantity(typ) << "> not available in file."
01409                << fTTBELL << endl;
01410         }
01411       CloseRootFile(file_name);
01412     }
01413   return vec;
01414 }
01415 //------------------------------------------------------------------------------------------------
01416 TVectorD TEcnaRead::ReadSampleMeans(const Int_t & n1StexStin, const Int_t & VecDim)
01417 {
01418 //Read the expectation values of the samples
01419 //for all the channel of a given Stin 
01420 //in the ROOT file and return them in a TVectorD
01421 //
01422 //Possible values for VecDim : (1) VecDim = fFileHeader->fNbOfSamples*fEcal->MaxCrysInStin()
01423 
01424   TestArrayDimH1("ReadSampleMeans", "fFileHeader->fNbOfSamples*fEcal->MaxCrysInStin()",
01425                  fFileHeader->fNbOfSamples*fEcal->MaxCrysInStin() , VecDim);
01426   
01427   TVectorD vec(VecDim);
01428   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01429 
01430   CnaResultTyp typ = cTypMSp;
01431 
01432   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01433   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01434 
01435   Bool_t ok_open = kFALSE;
01436   Bool_t ok_read = kFALSE;
01437 
01438   TString FileNameLong = fCnaWrite->GetRootFileName();
01439   Bool_t allowed_to_read = kFALSE;
01440       
01441   //if ( fOpenRootFile )
01442   //  {
01443   //    cout << "!TEcnaRead::ReadSampleMeans(...) *** ERROR ***> "
01444   //       << " Reading on file already open." << fTTBELL << endl;
01445   //  }
01446 
01447   if( FileNameLong == fCurrentlyOpenFileName )
01448     {
01449       allowed_to_read = kTRUE;
01450     } 
01451   else
01452     {
01453       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01454       ok_open = OpenRootFile(file_name, "READ");
01455 
01456       if(ok_open)
01457         {
01458           allowed_to_read = kTRUE;
01459         }
01460       else
01461         {
01462           cout << "!TEcnaRead::ReadSampleMeans(...) *** ERROR ***> Open .root file failed for file: "
01463                << file_name << fTTBELL << endl;
01464           allowed_to_read = kFALSE;
01465           ok_read = kFALSE;
01466         }
01467     }
01468   
01469   if( allowed_to_read == kTRUE )
01470     {
01471       Int_t i_zero = 0;
01472       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
01473       
01474       if ( ok_read == kTRUE )
01475         {
01476           fDataExist = kTRUE;
01477 
01478           for( Int_t i0StinEcha=0; i0StinEcha<fEcal->MaxCrysInStin(); i0StinEcha++ )
01479             {
01480               Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
01481               for ( Int_t i_samp=0; i_samp<fFileHeader->fNbOfSamples; i_samp++ )
01482                 {
01483                   vec(i0StinEcha*fFileHeader->fNbOfSamples+i_samp) =
01484                     gCnaRootFile->fCnaIndivResult->fMatHis(i0StexEcha, i_samp);
01485                 }
01486             }   
01487         }
01488       else
01489         {
01490           fDataExist = kFALSE;
01491           cout << "!TEcnaRead::ReadSampleMeans(...) *** ERROR ***> "
01492                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01493                << "                                                -> quantity: <"
01494                << GetTypeOfQuantity(typ) << "> not available in file."
01495                << fTTBELL << endl;
01496         }
01497       CloseRootFile(file_name);
01498     }
01499   return vec;
01500 }
01501 
01502 //-------------------------------------------------------------------------
01503 //
01504 //                  ReadSampleSigmas  
01505 //                   
01506 //-------------------------------------------------------------------------
01507 TVectorD TEcnaRead::ReadSampleSigmas(const Int_t & n1StexStin, const Int_t & i0StinEcha,
01508                                      const Int_t & VecDim)
01509 {
01510 //Read the expectation values of the samples
01511 //for a given Stin and a given channel
01512 //in the ROOT file and return them in a TVectorD
01513 //
01514 //Possible values for VecDim : (1) VecDim = fFileHeader->fNbOfSamples
01515 
01516   TestArrayDimH1("ReadSampleSigmas", "fFileHeader->fNbOfSamples", fFileHeader->fNbOfSamples, VecDim);
01517 
01518   Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
01519   
01520   TVectorD vec(VecDim);
01521   vec.Zero();
01522 
01523   CnaResultTyp typ = cTypSSp;
01524 
01525   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01526   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01527 
01528   TString FileNameLong = fCnaWrite->GetRootFileName();
01529      
01530   //if ( fOpenRootFile )
01531   //  {
01532   //    cout << "!TEcnaRead::ReadSampleSigmas(...) *** ERROR ***> "
01533   //       << "Reading on file already open." << fTTBELL << endl;
01534   //  }
01535 
01536   if (FileNameLong != fCurrentlyOpenFileName)
01537     {
01538       if( fCurrentlyOpenFileName != fFlagNoFileOpen )
01539         CloseRootFile(current_file_name);
01540 
01541       if(!(OpenRootFile(file_name, "READ")))
01542         {
01543           cout << "!TEcnaRead::ReadSampleSigmas(...) *** ERROR ***> Open .root file failed for file: "
01544                << file_name << fTTBELL << endl;
01545           return vec;
01546         }
01547     }
01548   
01549   Int_t i_zero = 0;
01550   
01551   if ( gCnaRootFile->ReadElement(typ, i_zero) )
01552     {
01553       fDataExist = kTRUE;
01554       for ( Int_t i_samp = 0; i_samp < VecDim; i_samp++)
01555         {
01556           vec(i_samp) = gCnaRootFile->fCnaIndivResult->fMatHis(i0StexEcha,i_samp);
01557         }   
01558     }
01559   else
01560     {
01561       fDataExist = kFALSE;
01562       cout << "!TEcnaRead::ReadSampleSigmas(...) *** ERROR ***> "
01563            << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01564            << "                                                 -> quantity: <"
01565            << GetTypeOfQuantity(typ) << "> not available in file."
01566            << fTTBELL << endl;
01567     }
01568   CloseRootFile(file_name);
01569   return vec;
01570 }
01571 //------------------------------------------------------------------------------------------------
01572 TVectorD TEcnaRead::ReadSampleSigmas(const Int_t & n1StexStin, const Int_t & VecDim)
01573 {
01574 //Read the expectation values of the samples
01575 //for all the channel of a given Stin
01576 //in the ROOT file and return them in a TVectorD
01577 //
01578 //Possible values for VecDim : (1) VecDim = fFileHeader->fNbOfSamples*fEcal->MaxCrysInStin()
01579 
01580   TestArrayDimH1("ReadSampleSigmas", "fFileHeader->fNbOfSamples*fEcal->MaxCrysInStin()", 
01581                  fFileHeader->fNbOfSamples*fEcal->MaxCrysInStin(), VecDim);
01582   
01583   TVectorD vec(VecDim); for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01584 
01585   CnaResultTyp typ = cTypSSp;
01586 
01587   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01588   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01589 
01590   Bool_t ok_open = kFALSE;
01591   Bool_t ok_read = kFALSE;
01592 
01593   TString FileNameLong = fCnaWrite->GetRootFileName();
01594   Bool_t allowed_to_read = kFALSE;
01595        
01596   //if ( fOpenRootFile )
01597   //  {
01598   //    cout << "!TEcnaRead::ReadSampleSigmas(...) *** ERROR ***> "
01599   //       << "Reading on file already open." << fTTBELL << endl;
01600   // }
01601 
01602   if( FileNameLong == fCurrentlyOpenFileName )
01603     {
01604       allowed_to_read = kTRUE;
01605     }
01606   else
01607     {
01608       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01609       ok_open = OpenRootFile(file_name, "READ");
01610 
01611       if(ok_open)
01612         {
01613           allowed_to_read = kTRUE;
01614         }
01615       else
01616         {
01617           cout << "!TEcnaRead::ReadSampleSigmas(...) *** ERROR ***> Open .root file failed for file: "
01618                << file_name << fTTBELL << endl;
01619           allowed_to_read = kFALSE;
01620           ok_read = kFALSE;
01621         }
01622     }
01623   
01624   if( allowed_to_read == kTRUE )
01625     {
01626       Int_t i_zero = 0;
01627       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
01628       
01629       if ( ok_read == kTRUE )
01630         {
01631           fDataExist = kTRUE;
01632 
01633           for( Int_t i0StinEcha=0; i0StinEcha<fEcal->MaxCrysInStin(); i0StinEcha++ )
01634             {
01635               Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
01636               for ( Int_t i_samp = 0; i_samp < fFileHeader->fNbOfSamples; i_samp++)
01637                 {
01638                   vec(i0StinEcha*fFileHeader->fNbOfSamples+i_samp) =
01639                     gCnaRootFile->fCnaIndivResult->fMatHis(i0StexEcha,i_samp);
01640                 }
01641             }   
01642         }
01643       else
01644         {
01645           fDataExist = kFALSE;
01646           cout << "!TEcnaRead::ReadSampleSigmas(...) *** ERROR ***> "
01647                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01648                << "                                                 -> quantity: <"
01649                << GetTypeOfQuantity(typ) << "> not available in file."
01650                << fTTBELL << endl;
01651         }
01652       CloseRootFile(file_name);
01653     }
01654   return vec;
01655 }
01656 
01657 //-----------------------------------------------------------------------------
01658 //
01659 //                  ReadNumberOfEvents(...)
01660 //
01661 //-----------------------------------------------------------------------------
01662 TVectorD TEcnaRead::ReadNumberOfEvents(const Int_t& VecDim)
01663 {
01664 //Read the numbers of found events in the data
01665 //for the crystals and for the samples for all the Stin's in the Stex
01666 //in the ROOT file, compute the average on the samples
01667 //and return them in a TVectorD(MaxCrysEcnaInStex)
01668 //
01669 //Possible values for VecDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
01670 
01671   TestArrayDimH1("ReadNumberOfEvents", "fEcal->MaxCrysEcnaInStex()", fEcal->MaxCrysEcnaInStex(), VecDim);
01672 
01673   TVectorD vec(VecDim);
01674   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01675 
01676   TMatrixD mat(fEcal->MaxCrysInStin(), fFileHeader->fNbOfSamples);
01677 
01678   for(Int_t iStexStin=0; iStexStin<fEcal->MaxStinEcnaInStex(); iStexStin++)
01679     {
01680       //............. set mat(,) to zero before reading it
01681       for(Int_t i=0; i<fEcal->MaxCrysInStin(); i++)
01682         {for(Int_t j=0; j<fFileHeader->fNbOfSamples; j++){mat(i,j)=(Double_t)0.;}}
01683       //............. read mat(,)
01684       Int_t n1StexStin = iStexStin+1;
01685       mat = ReadNumberOfEventsForSamples(n1StexStin, fEcal->MaxCrysInStin(), fFileHeader->fNbOfSamples);
01686 
01687       for(Int_t i0StinEcha=0; i0StinEcha<fEcal->MaxCrysInStin(); i0StinEcha++)
01688         {
01689           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
01690           vec(i0StexEcha) = 0; 
01691           //.... average value over the samples
01692           for(Int_t i_samp=0; i_samp<fFileHeader->fNbOfSamples; i_samp++)
01693             {vec(i0StexEcha) += mat(i0StinEcha, i_samp);}
01694           vec(i0StexEcha) = vec(i0StexEcha)/fFileHeader->fNbOfSamples;
01695         } 
01696     }
01697   return vec;
01698 }
01699 
01700 //-----------------------------------------------------------------------------
01701 //
01702 //                  ReadNumberOfEventsForSamples 
01703 //
01704 //-----------------------------------------------------------------------------
01705 TMatrixD TEcnaRead::ReadNumberOfEventsForSamples(const Int_t& n1StexStin,
01706                                                  const Int_t& MatDimX, const Int_t& MatDimY)
01707 {
01708 //Read the numbers of found events in the data
01709 //for the crystals and for the samples, for a given Stin in the Stex
01710 //in the ROOT file and return them in a TMatrixD(MaxCrysInStin,NbOfSamples)
01711 //
01712 //Possible values for MatDimX and MatDimY:
01713 //  (1) MatDimX = fEcal->MaxCrysInStin(), MatDimY = fFileHeader->fNbOfSamples
01714 
01715 
01716 
01717   TMatrixD mat(MatDimX, MatDimY);
01718   for(Int_t i=0; i-MatDimX<0; i++)
01719     {for(Int_t j=0; j-MatDimY<0; j++){mat(i,j)=(Double_t)0.;}}
01720 
01721   Int_t Stin_index = GetStinIndex(n1StexStin);
01722   if( Stin_index >= 0 )
01723     {
01724       if(fLookAtRootFile == 1)
01725         {
01726           CnaResultTyp typ = cTypNbOfEvts;
01727           const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01728           const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01729           
01730           Bool_t ok_open = kFALSE;
01731           Bool_t ok_read = kFALSE;
01732           
01733           TString FileNameLong = fCnaWrite->GetRootFileName();
01734           Bool_t allowed_to_read = kFALSE;
01735           
01736           //      if ( fOpenRootFile )
01737           //        {
01738           //          cout << "!TEcnaRead::ReadNumberOfEventsForSamples(...) *** ERROR ***> "
01739           //               << " Reading on file already open." << fTTBELL << endl;
01740           //        }
01741 
01742           if( FileNameLong == fCurrentlyOpenFileName  )
01743             {
01744               allowed_to_read = kTRUE;
01745             }
01746           else
01747             {
01748               if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01749               ok_open = OpenRootFile(file_name, "READ");  // set fOpenRootFile to kTRUE
01750               if(ok_open)
01751                 {
01752                   allowed_to_read = kTRUE;
01753                 }
01754               else
01755                 {
01756                   cout << "!TEcnaRead::ReadNumberOfEventsForSamples(...) *** ERROR ***> Open .root file failed for file: "
01757                        << file_name << fTTBELL << endl;
01758                   allowed_to_read = kFALSE;
01759                   ok_read = kFALSE;
01760                 }
01761             }
01762           
01763           if( allowed_to_read == kTRUE )
01764             {
01765               Int_t i_zero = 0;
01766               ok_read = gCnaRootFile->ReadElement(typ, i_zero);
01767               
01768               if ( ok_read == kTRUE )
01769                 {
01770                   fDataExist = kTRUE;
01771                   for (Int_t i_crys=0; i_crys-MatDimX<0; i_crys++)
01772                     {                 
01773                       Int_t j_cna_chan = Stin_index*MatDimX + i_crys;
01774                       for ( Int_t i_samp=0; i_samp-MatDimY<0; i_samp++)
01775                         {
01776                           mat(i_crys, i_samp) = gCnaRootFile->fCnaIndivResult->fMatHis(j_cna_chan, i_samp);
01777                         }
01778                     }
01779                 }
01780               else
01781                 {
01782                   fDataExist = kFALSE;
01783                   cout << "!TEcnaRead::ReadNumberOfEventsForSamples(...) *** ERROR ***> "
01784                        << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01785                        << "                                                                 -> quantity: <"
01786                        << GetTypeOfQuantity(typ) << "> not available in file."
01787                        << fTTBELL << endl;
01788                 }
01789             }
01790           CloseRootFile(file_name);
01791         }  // end of if (fLookAtRootFile == 1)
01792       else
01793         {
01794           cout << "!TEcnaRead::ReadNumberOfEventsForSamples(...) *** ERROR ***> "
01795                << "It is not possible to access the number of found events: the ROOT file has not been read."
01796                << fTTBELL << endl;
01797         }
01798     }  // end of if (Stin_index >= 0)
01799   return mat;
01800 }// ----------------- end of ReadNumberOfEventsForSamples(...)
01801 
01802 //-------------------------------------------------------------------------
01803 //
01804 //        ReadPedestals(...)      
01805 //
01806 //-------------------------------------------------------------------------
01807 TVectorD TEcnaRead::ReadPedestals(const Int_t& VecDim)
01808 {
01809 //Read the expectation values of the expectation values of the samples
01810 //for all the channels of a given Stin
01811 //in the ROOT file and return them in a TVectorD
01812 //
01813 //Possible values for VecDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
01814 
01815   TestArrayDimH1("ReadPedestals", "fEcal->MaxCrysEcnaInStex()", fEcal->MaxCrysEcnaInStex(), VecDim);
01816 
01817   TVectorD vec(VecDim);
01818   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01819 
01820   CnaResultTyp typ = cTypPed;    // pedestals type
01821   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01822   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01823 
01824   Bool_t ok_open = kFALSE;
01825   Bool_t ok_read = kFALSE;
01826   
01827   TString FileNameLong = fCnaWrite->GetRootFileName();
01828   Bool_t allowed_to_read = kFALSE;
01829   
01830 //    if ( fOpenRootFile )
01831 //    {
01832 //      cout << "!TEcnaRead::ReadPedestals(...) *** ERROR ***> "
01833 //         << "Reading on file already open." << fTTBELL << endl;
01834 //    }
01835 
01836   if( FileNameLong == fCurrentlyOpenFileName )
01837     {
01838       allowed_to_read = kTRUE;
01839     }
01840   else
01841     {
01842       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01843       ok_open = OpenRootFile(file_name, "READ");
01844       if(ok_open)
01845         {
01846           allowed_to_read = kTRUE;
01847         }
01848       else
01849         {
01850           cout << "!TEcnaRead::ReadPedestals(...) *** ERROR ***> Open .root file failed for file: "
01851                << file_name << fTTBELL << endl;
01852           allowed_to_read = kFALSE;
01853           ok_read = kFALSE;
01854         }
01855     }
01856 
01857   if( allowed_to_read == kTRUE )
01858     {
01859       Int_t i_zero = 0;
01860       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
01861       
01862       if ( ok_read == kTRUE )
01863         {
01864           fDataExist = kTRUE;
01865           for ( Int_t i_StexCrys = 0; i_StexCrys < VecDim; i_StexCrys++)
01866             {
01867               vec(i_StexCrys) = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero, i_StexCrys);
01868             }   
01869         }
01870       else
01871         {
01872           fDataExist = kFALSE;
01873           cout << "!TEcnaRead::ReadPedestals(...) *** ERROR ***> "
01874                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01875                << "                                              -> quantity: <"
01876                << GetTypeOfQuantity(typ) << "> not available in file."
01877                << fTTBELL << endl;
01878         }
01879       CloseRootFile(file_name);
01880     }
01881   return vec;
01882 }
01883 
01884 //-------------------------------------------------------------------------
01885 //
01886 //              ReadTotalNoise(...)      
01887 //
01888 //-------------------------------------------------------------------------
01889 TVectorD TEcnaRead::ReadTotalNoise(const Int_t& VecDim)
01890 {
01891 //Read the expectation values of the sigmas of the samples
01892 //for all the channels of a given Stin
01893 //in the ROOT file and return them in a TVectorD
01894 //
01895 //Possible values for VecDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
01896 
01897   TestArrayDimH1("ReadTotalNoise", "fEcal->MaxCrysEcnaInStex()", fEcal->MaxCrysEcnaInStex(), VecDim);
01898 
01899   TVectorD vec(VecDim); for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01900   CnaResultTyp typ = cTypTno;   // Total noise type
01901   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01902   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01903 
01904   Bool_t ok_open = kFALSE;
01905   Bool_t ok_read = kFALSE;
01906 
01907   TString FileNameLong = fCnaWrite->GetRootFileName();
01908   Bool_t allowed_to_read = kFALSE;
01909   
01910   //  if ( fOpenRootFile )
01911   //  {
01912   //    cout << "!TEcnaRead::ReadTotalNoise(...) *** ERROR ***> "
01913   //       << "Reading on file already open." << fTTBELL << endl;
01914   //  }
01915 
01916   if( FileNameLong == fCurrentlyOpenFileName )
01917     {
01918       allowed_to_read = kTRUE;
01919     }
01920   else
01921     {
01922       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
01923       ok_open = OpenRootFile(file_name, "READ");
01924       if(ok_open)
01925         {
01926           allowed_to_read = kTRUE;
01927         }
01928       else
01929         {
01930           cout << "!TEcnaRead::ReadTotalNoise(...) *** ERROR ***> Open .root file failed for file: "
01931                << file_name << fTTBELL << endl;
01932           allowed_to_read = kFALSE;
01933           ok_read = kFALSE;
01934         }
01935     }
01936 
01937   if( allowed_to_read == kTRUE )
01938     {
01939       Int_t i_zero = 0;
01940       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
01941       
01942       if ( ok_read == kTRUE )
01943         {
01944           fDataExist = kTRUE;
01945           for ( Int_t i_StexCrys = 0; i_StexCrys < VecDim; i_StexCrys++)
01946             {
01947               vec(i_StexCrys)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero,i_StexCrys);
01948             }   
01949         }
01950       else
01951         {
01952           fDataExist = kFALSE;
01953           cout << "!TEcnaRead::ReadTotalNoise(...) *** ERROR ***> "
01954                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
01955                << "                                               -> quantity: <"
01956                << GetTypeOfQuantity(typ) << "> not available in file."
01957                << fTTBELL << endl;
01958         }
01959       CloseRootFile(file_name);
01960     }
01961   return vec;
01962 }
01963 //-------------------------------------------------------------------------
01964 //
01965 //          ReadMeanCorrelationsBetweenSamples(...)      
01966 //
01967 //-------------------------------------------------------------------------
01968 TVectorD TEcnaRead::ReadMeanCorrelationsBetweenSamples(const Int_t& VecDim)
01969 {
01970 //Read the Expectation values of the (sample,sample) correlations
01971 //for all the channels of a given Stin
01972 //in the ROOT file and return them in a TVectorD
01973 //
01974 //Possible values for VecDim: (1) VecDim = fEcal->MaxCrysEcnaInStex()
01975 
01976   TestArrayDimH1("ReadMeanCorrelationsBetweenSamples", "fEcal->MaxCrysEcnaInStex()",
01977                  fEcal->MaxCrysEcnaInStex(), VecDim);
01978 
01979   TVectorD vec(VecDim); for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
01980   CnaResultTyp typ = cTypMeanCorss;     // mean corss type
01981   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
01982   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
01983 
01984   Bool_t ok_open = kFALSE;
01985   Bool_t ok_read = kFALSE;
01986 
01987   TString FileNameLong = fCnaWrite->GetRootFileName();
01988   Bool_t allowed_to_read = kFALSE;
01989    
01990   //if ( fOpenRootFile )
01991   //  {
01992   //    cout << "!TEcnaRead::ReadMeanCorrelationsBetweenSamples(...) *** ERROR ***> "
01993   //       << "Reading on file already open." << fTTBELL << endl;
01994   //  }
01995 
01996   if( FileNameLong == fCurrentlyOpenFileName )
01997     {
01998       allowed_to_read = kTRUE;
01999     }
02000   else
02001     {
02002       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02003       ok_open = OpenRootFile(file_name, "READ");
02004       if(ok_open)
02005         {
02006           allowed_to_read = kTRUE;
02007         }
02008       else
02009         {
02010           cout << "!TEcnaRead::ReadMeanCorrelationsBetweenSamples(...) *** ERROR ***> Open .root file failed for file: "
02011                << file_name << fTTBELL << endl;
02012           allowed_to_read = kFALSE;
02013           ok_read = kFALSE;
02014         }
02015     }
02016 
02017   if( allowed_to_read == kTRUE )
02018     {
02019       Int_t i_zero = 0;
02020       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02021       
02022       if ( ok_read == kTRUE )
02023         {
02024           fDataExist = kTRUE;
02025           for ( Int_t i_StexCrys = 0; i_StexCrys < VecDim; i_StexCrys++)
02026             {
02027               vec(i_StexCrys)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero,i_StexCrys);
02028             }   
02029         }
02030       else
02031         {
02032           fDataExist = kFALSE;
02033           cout << "!TEcnaRead::ReadMeanCorrelationsBetweenSamples(...) *** ERROR ***> "
02034                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02035                << "                                                                   ->  quantity: <"
02036                << GetTypeOfQuantity(typ) << "> not available in file."
02037                << fTTBELL << endl;
02038         }
02039       CloseRootFile(file_name);
02040     }
02041   return vec;
02042 }
02043 
02044 //-------------------------------------------------------------------------
02045 //
02046 //              ReadLowFrequencyNoise(...)      
02047 //
02048 //-------------------------------------------------------------------------
02049 TVectorD TEcnaRead::ReadLowFrequencyNoise(const Int_t& VecDim)
02050 {
02051 //Read the sigmas of the expectation values of the samples
02052 //for all the channels of a given Stin
02053 //in the ROOT file and return them in a TVectorD
02054 //
02055 //Possible values for VecDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
02056 
02057   TestArrayDimH1("ReadLowFrequencyNoise", "fEcal->MaxCrysEcnaInStex()", fEcal->MaxCrysEcnaInStex(), VecDim);
02058 
02059   TVectorD vec(VecDim); for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02060   CnaResultTyp typ = cTypLfn;        // low frequency noise type
02061   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02062   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02063 
02064   Bool_t ok_open = kFALSE;
02065   Bool_t ok_read = kFALSE;
02066 
02067   TString FileNameLong = fCnaWrite->GetRootFileName();
02068   Bool_t allowed_to_read = kFALSE;
02069     
02070 //  if ( fOpenRootFile )
02071 //    {
02072 //      cout << "!TEcnaRead::ReadLowFrequencyNoise(...) *** ERROR ***> "
02073 //         << "Reading on file already open." << fTTBELL << endl;
02074 //    }
02075 
02076   if( FileNameLong == fCurrentlyOpenFileName )
02077     {
02078       allowed_to_read = kTRUE;
02079     }
02080   else
02081     {
02082       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02083       ok_open = OpenRootFile(file_name, "READ");
02084 
02085       if(ok_open)
02086         {
02087           allowed_to_read = kTRUE;
02088         }
02089       else
02090         {
02091           cout << "!TEcnaRead::ReadLowFrequencyNoise(...) *** ERROR ***> Open .root file failed for file: "
02092                << file_name << fTTBELL << endl;
02093           allowed_to_read = kFALSE;
02094           ok_read = kFALSE;
02095         }
02096     }
02097 
02098   if( allowed_to_read == kTRUE )
02099     {
02100       Int_t i_zero = 0;
02101       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02102       
02103       if ( ok_read == kTRUE )
02104         {
02105           fDataExist = kTRUE;
02106           for ( Int_t i_StexCrys = 0; i_StexCrys < VecDim; i_StexCrys++)
02107             {
02108               vec(i_StexCrys)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero,i_StexCrys);
02109             }   
02110         }
02111       else
02112         {
02113           fDataExist = kFALSE;
02114           cout << "!TEcnaRead::ReadLowFrequencyNoise(...) *** ERROR ***> "
02115                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02116                << "                                                      -> quantity: <"
02117                << GetTypeOfQuantity(typ) << "> not available in file."
02118                << fTTBELL << endl;
02119         }
02120       CloseRootFile(file_name);
02121     }
02122   return vec;
02123 }
02124 
02125 //-------------------------------------------------------------------------
02126 //
02127 //              ReadHighFrequencyNoise(...)      
02128 //
02129 //-------------------------------------------------------------------------
02130 TVectorD TEcnaRead::ReadHighFrequencyNoise(const Int_t& VecDim)
02131 {
02132 //Read the sigmas of the sigmas of the samples
02133 //for all the channels of a given Stin
02134 //in the ROOT file and return them in a TVectorD
02135 //
02136 //Possible values for VecDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
02137 
02138   TestArrayDimH1("ReadHighFrequencyNoise", "fEcal->MaxCrysEcnaInStex()", fEcal->MaxCrysEcnaInStex(), VecDim);
02139   
02140   TVectorD vec(VecDim); for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02141   CnaResultTyp typ = cTypHfn;        // high frequency noise type
02142   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02143   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02144 
02145   Bool_t ok_open = kFALSE;
02146   Bool_t ok_read = kFALSE;
02147   
02148   TString FileNameLong = fCnaWrite->GetRootFileName();
02149   Bool_t allowed_to_read = kFALSE;
02150 
02151 //  if ( fOpenRootFile )
02152 //    {
02153 //      cout << "!TEcnaRead::ReadHighFrequencyNoise(...) *** ERROR ***> "
02154 //         << "Reading on file already open." << fTTBELL << endl;
02155 //    }
02156 
02157   if( FileNameLong == fCurrentlyOpenFileName )
02158     {
02159       allowed_to_read = kTRUE;
02160     }
02161   else
02162     {
02163       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02164       ok_open = OpenRootFile(file_name, "READ");
02165 
02166       if(ok_open)
02167         {
02168           allowed_to_read = kTRUE;
02169         }
02170       else
02171         {
02172           cout << "!TEcnaRead::ReadHighFrequencyNoise(...) *** ERROR ***> Open .root file failed for file: "
02173                << file_name << fTTBELL << endl;
02174           allowed_to_read = kFALSE;
02175           ok_read = kFALSE;
02176         }
02177     }
02178 
02179   if( allowed_to_read == kTRUE )
02180     {
02181       Int_t i_zero = 0;
02182       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02183       
02184       if ( ok_read == kTRUE )
02185         {
02186           fDataExist = kTRUE;
02187           for ( Int_t i_StexCrys = 0; i_StexCrys < VecDim; i_StexCrys++)
02188             {
02189               vec(i_StexCrys)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero,i_StexCrys);
02190             }   
02191         }
02192       else
02193         {
02194           fDataExist = kFALSE;
02195           cout << "!TEcnaRead::ReadHighFrequencyNoise(...) *** ERROR ***> "
02196                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02197                << "                                                       -> quantity: <"
02198                << GetTypeOfQuantity(typ) << "> not available in file."
02199                << fTTBELL << endl;
02200         }
02201       CloseRootFile(file_name);
02202     }
02203   return vec;
02204 }
02205 
02206 //-------------------------------------------------------------------------
02207 //
02208 //              ReadSigmaOfCorrelationsBetweenSamples(...)       
02209 //
02210 //-------------------------------------------------------------------------
02211 TVectorD TEcnaRead::ReadSigmaOfCorrelationsBetweenSamples(const Int_t& VecDim)
02212 {
02213 //Read the Expectation values of the (sample,sample) correlations
02214 //for all the channels of a given Stin
02215 //in the ROOT file and return them in a TVectorD
02216 //
02217 //Possible values for VecDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
02218 
02219   TestArrayDimH1("ReadSigmaOfCorrelationsBetweenSamples", "fEcal->MaxCrysEcnaInStex()",
02220                  fEcal->MaxCrysEcnaInStex(), VecDim);
02221 
02222   TVectorD vec(VecDim); for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02223   CnaResultTyp typ = cTypSigCorss;  // sigma of corss type
02224   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02225   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02226 
02227   Bool_t ok_open = kFALSE;
02228   Bool_t ok_read = kFALSE;
02229   
02230   TString FileNameLong = fCnaWrite->GetRootFileName();
02231   Bool_t allowed_to_read = kFALSE;
02232   
02233 //  if ( fOpenRootFile )
02234 //    {
02235 //      cout << "!TEcnaRead::ReadSigmaOfCorrelationsBetweenSamples(...) *** ERROR ***> "
02236 //         << "Reading on file already open." << fTTBELL << endl;
02237 //    }
02238 
02239   if( FileNameLong == fCurrentlyOpenFileName )
02240     {
02241       allowed_to_read = kTRUE;
02242     }
02243   else
02244     {
02245       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02246       ok_open = OpenRootFile(file_name, "READ");
02247 
02248       if(ok_open)
02249         {
02250           allowed_to_read = kTRUE;
02251         }
02252       else
02253         {
02254           cout << "!TEcnaRead::ReadSigmaOfCorrelationsBetweenSamples(...) *** ERROR ***> Open .root file failed for file: "
02255                << file_name << fTTBELL << endl;
02256           allowed_to_read = kFALSE;
02257           ok_read = kFALSE;
02258         }
02259     }
02260 
02261   if( allowed_to_read == kTRUE )
02262     {
02263       Int_t i_zero = 0;
02264       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02265       
02266       if ( ok_read == kTRUE )
02267         {
02268           fDataExist = kTRUE;
02269           for ( Int_t i_StexCrys = 0; i_StexCrys < VecDim; i_StexCrys++)
02270             {
02271               vec(i_StexCrys)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero,i_StexCrys);
02272             }   
02273         }
02274       else
02275         {
02276           fDataExist = kFALSE;
02277           cout << "!TEcnaRead::ReadSigmaOfCorrelationsBetweenSamples(...) *** ERROR ***> "
02278                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02279                << "                                                                      -> quantity: <"
02280                << GetTypeOfQuantity(typ) << "> not available in file."
02281                << fTTBELL << endl;
02282         }
02283       CloseRootFile(file_name);
02284     }
02285   return vec;
02286 }
02287 //==================================================================================================
02288 //-----------------------------------------------------------------------------
02289 //
02290 //                  ReadAverageNumberOfEvents(...)
02291 //
02292 //       NB: read "direct" numbers of evts and compute the average HERE
02293 //           (different from ReadAveragePedestals, Noises, etc...)
02294 //
02295 //-----------------------------------------------------------------------------
02296 TVectorD TEcnaRead::ReadAverageNumberOfEvents(const Int_t& VecDim)
02297 {
02298 //Read the numbers of found events in the data
02299 //for the crystals and for the samples for all the Stin's in the Stex
02300 //in the ROOT file, compute the average on the samples and on the crystals
02301 //and return them in a TVectorD(MaxStinEcnaInStex)
02302 //
02303 //Possible values for VecDim: (1) VecDim = fEcal->MaxStinEcnaInStex()
02304 
02305   TestArrayDimH1("ReadAverageNumberOfEvents", "fEcal->MaxStinEcnaInStex()", fEcal->MaxStinEcnaInStex(), VecDim);
02306 
02307   TVectorD vecAverage(VecDim);
02308   for(Int_t i=0; i<VecDim; i++){vecAverage(i)=(Double_t)0.;}
02309 
02310   TVectorD vecMean(fEcal->MaxCrysEcnaInStex());
02311   for(Int_t i=0; i<fEcal->MaxCrysEcnaInStex(); i++){vecMean(i)=(Double_t)0.;}
02312 
02313   vecMean = ReadNumberOfEvents(fEcal->MaxCrysEcnaInStex());
02314 
02315   for(Int_t i0StexStin=0; i0StexStin<VecDim; i0StexStin++)
02316     {
02317       vecAverage(i0StexStin) = 0;
02318       //.... average value over the crystals
02319       for(Int_t i0StinEcha=0; i0StinEcha<fEcal->MaxCrysInStin(); i0StinEcha++)
02320         {
02321           Int_t n1StexStin = i0StexStin+1;
02322           Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
02323           
02324           if( fStexName == "SM" )
02325             {vecAverage(i0StexStin) += vecMean(i0StexEcha);}
02326 
02327           if( fStexName == "Dee" )
02328             {
02329               //--------- EE --> Special translation for mixed SCEcna (29 and 32)
02330               //                 Xtal 11 of SCEcna 29 -> Xtal 11 of SCEcna 10
02331               //                 Xtal 11 of SCEcna 32 -> Xtal 11 of SCEcna 11
02332               Int_t n1StinEcha = i0StinEcha+1;
02333               if( n1StexStin == 10 && n1StinEcha == 11 )
02334                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(29, i0StinEcha);}
02335               if( n1StexStin == 11 && n1StinEcha == 11 )
02336                 {i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(32, i0StinEcha);}
02337               if( !( (n1StexStin == 29 || n1StexStin == 32) && n1StinEcha == 11 )  )
02338                 {vecAverage(i0StexStin) += vecMean(i0StexEcha);}
02339             }
02340         }
02341 
02342       Double_t xdivis = (Double_t)0.;
02343       if( fStexName == "SM"  )
02344         {xdivis = (Double_t)fEcal->MaxCrysInStin();}
02345       if( fStexName == "Dee" )
02346         {
02347           Int_t n1StexStin = i0StexStin+1;
02348           xdivis = (Double_t)fEcalNumbering->MaxCrysInStinEcna(fFileHeader->fStex, n1StexStin, "TEcnaRead");
02349         }
02350 
02351       vecAverage(i0StexStin) = vecAverage(i0StexStin)/xdivis;   
02352     }
02353   return vecAverage;
02354 }
02355 
02356 //-------------------------------------------------------------------------
02357 //
02358 //        ReadAveragePedestals(...)      
02359 //
02360 //-------------------------------------------------------------------------
02361 TVectorD TEcnaRead::ReadAveragePedestals(const Int_t& VecDim)
02362 {
02363 //Read the expectation values of the Pedestals
02364 //for all the Stins of a given Stex
02365 //in the ROOT file and return them in a TVectorD
02366 //
02367 //Possible values for VecDim: (1) VecDim = fEcal->MaxStinEcnaInStex()
02368 
02369   TestArrayDimH1("ReadAveragePedestals", "fEcal->MaxStinEcnaInStex()", fEcal->MaxStinEcnaInStex(), VecDim);
02370 
02371   TVectorD vec(VecDim);
02372   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02373 
02374   CnaResultTyp typ = cTypAvPed;    // averaged pedestals type
02375   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02376   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02377 
02378   Bool_t ok_open = kFALSE;
02379   Bool_t ok_read = kFALSE;
02380 
02381   TString FileNameLong = fCnaWrite->GetRootFileName();
02382   Bool_t allowed_to_read = kFALSE;
02383   
02384 //  if ( fOpenRootFile )
02385 //    {
02386 //      cout << "!TEcnaRead::ReadAveragePedestals(...) *** ERROR ***> "
02387 //         << "Reading on file already open." << fTTBELL << endl;
02388 //    }
02389 
02390   if( FileNameLong == fCurrentlyOpenFileName )
02391     {
02392       allowed_to_read = kTRUE;
02393     }
02394   else
02395     {
02396       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02397       ok_open = OpenRootFile(file_name, "READ");
02398 
02399       if(ok_open)
02400         {
02401           allowed_to_read = kTRUE;
02402         }
02403       else
02404         {
02405           cout << "!TEcnaRead::ReadAveragePedestals(...) *** ERROR ***> Open .root file failed for file: "
02406                << file_name << fTTBELL << endl;
02407           allowed_to_read = kFALSE;
02408           ok_read = kFALSE;
02409         }
02410     }
02411 
02412   if( allowed_to_read == kTRUE )
02413     {
02414       Int_t i_zero = 0;
02415       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02416       
02417       if ( ok_read == kTRUE )
02418         {
02419           fDataExist = kTRUE;
02420           for(Int_t i0StexStin=0; i0StexStin<VecDim; i0StexStin++)
02421             {
02422               vec(i0StexStin) = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero, i0StexStin);
02423             }   
02424         }
02425       else
02426         {
02427           fDataExist = kFALSE;
02428           cout << "!TEcnaRead::ReadAveragePedestals(...) *** ERROR ***> "
02429                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02430                << "                                                     -> quantity: <"
02431                << GetTypeOfQuantity(typ) << "> not available in file."
02432                << fTTBELL << endl;
02433         }
02434       CloseRootFile(file_name);
02435     }
02436   return vec;
02437 } // end of ReadAveragePedestals
02438 
02439 //-------------------------------------------------------------------------
02440 //
02441 //        ReadAverageTotalNoise(...)      
02442 //
02443 //-------------------------------------------------------------------------
02444 TVectorD TEcnaRead::ReadAverageTotalNoise(const Int_t& VecDim)
02445 {
02446 //Read the expectation values of the Total Noise
02447 //for all the Stins of a given Stex
02448 //in the ROOT file and return them in a TVectorD
02449 //
02450 //Possible values for VecDim: (1) VecDim = fEcal->MaxStinEcnaInStex()
02451 
02452   TestArrayDimH1("ReadAverageTotalNoise", "fEcal->MaxStinEcnaInStex()", fEcal->MaxStinEcnaInStex(), VecDim);
02453 
02454   TVectorD vec(VecDim);
02455   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02456 
02457   CnaResultTyp typ = cTypAvTno;    // averaged Total Noise type
02458   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02459   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02460 
02461   Bool_t ok_open = kFALSE;
02462   Bool_t ok_read = kFALSE;
02463   
02464   TString FileNameLong = fCnaWrite->GetRootFileName();
02465   Bool_t allowed_to_read = kFALSE;
02466   
02467 //  if ( fOpenRootFile )
02468 //    {
02469 //      cout << "!TEcnaRead::ReadAverageTotalNoise(...) *** ERROR ***> "
02470 //         << "Reading on file already open." << fTTBELL << endl;
02471 //    }
02472 
02473   if( FileNameLong == fCurrentlyOpenFileName )
02474     {
02475       allowed_to_read = kTRUE;
02476     }
02477   else
02478     {
02479       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02480       ok_open = OpenRootFile(file_name, "READ");
02481 
02482       if(ok_open)
02483         {
02484           allowed_to_read = kTRUE;
02485         }
02486       else
02487         {
02488           cout << "!TEcnaRead::ReadAverageTotalNoise(...) *** ERROR ***> Open .root file failed for file: "
02489                << file_name << fTTBELL << endl;
02490           allowed_to_read = kFALSE;
02491           ok_read = kFALSE;
02492         }
02493     }
02494 
02495   if( allowed_to_read == kTRUE )
02496     {
02497       Int_t i_zero = 0;
02498       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02499       
02500       if ( ok_read == kTRUE )
02501         {
02502           fDataExist = kTRUE;
02503           for ( Int_t i0StexStin = 0; i0StexStin < VecDim; i0StexStin++)
02504             {
02505               vec(i0StexStin)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero, i0StexStin);
02506             }   
02507         }
02508       else
02509         {
02510           fDataExist = kFALSE;
02511           cout << "!TEcnaRead::ReadAverageTotalNoise(...) *** ERROR ***> "
02512                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02513                << "                                                      -> quantity: <"
02514                << GetTypeOfQuantity(typ) << "> not available in file."
02515                << fTTBELL << endl;
02516         }
02517       CloseRootFile(file_name);
02518     }
02519   return vec;
02520 }
02521 
02522 //-------------------------------------------------------------------------
02523 //
02524 //        ReadAverageLowFrequencyNoise(...)      
02525 //
02526 //-------------------------------------------------------------------------
02527 TVectorD TEcnaRead::ReadAverageLowFrequencyNoise(const Int_t& VecDim)
02528 {
02529 //Read the expectation values of the Pedestals
02530 //for all the Stins of a given Stex
02531 //in the ROOT file and return them in a TVectorD
02532 //
02533 //Possible values for VecDim: (1) VecDim = fEcal->MaxStinEcnaInStex()
02534 
02535   TestArrayDimH1("ReadAverageLowFrequencyNoise", "fEcal->MaxStinEcnaInStex()", fEcal->MaxStinEcnaInStex(), VecDim);
02536 
02537   TVectorD vec(VecDim);
02538   for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02539 
02540   CnaResultTyp typ = cTypAvLfn;    // averaged Low FrequencyNoise type
02541   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02542   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02543 
02544   Bool_t ok_open = kFALSE;
02545   Bool_t ok_read = kFALSE;
02546   
02547   TString FileNameLong = fCnaWrite->GetRootFileName();
02548   Bool_t allowed_to_read = kFALSE;
02549 
02550 //  if ( fOpenRootFile )
02551 //    {
02552 //      cout << "!TEcnaRead::ReadAverageLowFrequencyNoise(...) *** ERROR ***> "
02553 //         << "Reading on file already open." << fTTBELL << endl;
02554 //    }
02555 
02556   if( FileNameLong == fCurrentlyOpenFileName )
02557     {
02558       allowed_to_read = kTRUE;
02559     }
02560   else
02561     {
02562       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02563       ok_open = OpenRootFile(file_name, "READ");
02564 
02565       if(ok_open)
02566         {
02567           allowed_to_read = kTRUE;
02568         }
02569       else
02570         {
02571           cout << "!TEcnaRead::ReadAverageLowFrequencyNoise(...) *** ERROR ***> Open .root file failed for file: "
02572                << file_name << fTTBELL << endl;
02573           allowed_to_read = kFALSE;
02574           ok_read = kFALSE;
02575         }
02576     }
02577 
02578   if( allowed_to_read == kTRUE )
02579     {
02580       Int_t i_zero = 0;
02581       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02582       
02583       if ( ok_read == kTRUE )
02584         {
02585           fDataExist = kTRUE;
02586           for ( Int_t i0StexStin = 0; i0StexStin < VecDim; i0StexStin++)
02587             {
02588               vec(i0StexStin)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero, i0StexStin);
02589             }   
02590         }
02591       else
02592         {
02593           fDataExist = kFALSE;
02594           cout << "!TEcnaRead::ReadAverageLowFrequencyNoise(...) *** ERROR ***> "
02595                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02596                << "                                                             -> quantity: <"
02597                << GetTypeOfQuantity(typ) << "> not available in file."
02598                << fTTBELL << endl;
02599         }
02600       CloseRootFile(file_name);
02601     }
02602   return vec;
02603 } // end of ReadAverageLowFrequencyNoise
02604 
02605 //-------------------------------------------------------------------------
02606 //
02607 //        ReadAverageHighFrequencyNoise(...)      
02608 //
02609 //-------------------------------------------------------------------------
02610 TVectorD TEcnaRead::ReadAverageHighFrequencyNoise(const Int_t& VecDim)
02611 {
02612 //Read the expectation values of the Pedestals
02613 //for all the Stins of a given Stex
02614 //in the ROOT file and return them in a TVectorD
02615 //
02616 //Possible values for VecDim: (1) VecDim = fEcal->MaxStinEcnaInStex()
02617 
02618   TestArrayDimH1("ReadAverageHighFrequencyNoise", "fEcal->MaxStinEcnaInStex()", fEcal->MaxStinEcnaInStex(), VecDim);
02619 
02620   TVectorD vec(VecDim);
02621  for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02622 
02623   CnaResultTyp typ = cTypAvHfn;    // averaged High FrequencyNoise type
02624   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02625   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02626 
02627   Bool_t ok_open = kFALSE;
02628   Bool_t ok_read = kFALSE;
02629   
02630   TString FileNameLong = fCnaWrite->GetRootFileName();
02631   Bool_t allowed_to_read = kFALSE;
02632   
02633 //  if ( fOpenRootFile )
02634 //    {
02635 //      cout << "!TEcnaRead::ReadAverageHighFrequencyNoise(...) *** ERROR ***> "
02636 //         << "Reading on file already open." << fTTBELL << endl;
02637 //    }
02638 
02639   if( FileNameLong == fCurrentlyOpenFileName )
02640     {
02641       allowed_to_read = kTRUE;
02642     }
02643   else
02644     {
02645       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02646       ok_open = OpenRootFile(file_name, "READ");
02647 
02648       if(ok_open)
02649         {
02650           allowed_to_read = kTRUE;
02651         }
02652       else
02653         {
02654           cout << "!TEcnaRead::ReadAverageHighFrequencyNoise(...) *** ERROR ***> Open .root file failed for file: "
02655                << file_name << fTTBELL << endl;
02656           allowed_to_read = kFALSE;
02657           ok_read = kFALSE;
02658         }
02659     }
02660 
02661   if( allowed_to_read == kTRUE )
02662     {
02663       Int_t i_zero = 0;
02664       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02665       
02666       if ( ok_read == kTRUE )
02667         {
02668           fDataExist = kTRUE;
02669           for ( Int_t i0StexStin = 0; i0StexStin < VecDim; i0StexStin++)
02670             {
02671               vec(i0StexStin)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero, i0StexStin);
02672             }   
02673         }
02674       else
02675         {
02676           fDataExist = kFALSE;
02677           cout << "!TEcnaRead::ReadAverageHighFrequencyNoise(...) *** ERROR ***> "
02678                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02679                << "                                                              -> quantity: <"
02680                << GetTypeOfQuantity(typ) << "> not available in file."
02681                << fTTBELL << endl;
02682         }
02683       CloseRootFile(file_name);
02684     }
02685   return vec;
02686 } // end of ReadAverageHighFrequencyNoise
02687 
02688 //-------------------------------------------------------------------------
02689 //
02690 //        ReadAverageMeanCorrelationsBetweenSamples(...)      
02691 //
02692 //-------------------------------------------------------------------------
02693 TVectorD TEcnaRead::ReadAverageMeanCorrelationsBetweenSamples(const Int_t& VecDim)
02694 {
02695 //Read the expectation values of the Pedestals
02696 //for all the Stins of a given Stex
02697 //in the ROOT file and return them in a TVectorD
02698 //
02699 //Possible values for VecDim: (1) VecDim = fEcal->MaxStinEcnaInStex()
02700 
02701   TestArrayDimH1("ReadAverageMeanCorrelationsBetweenSamples", "fEcal->MaxStinEcnaInStex()",
02702                  fEcal->MaxStinEcnaInStex(), VecDim);
02703 
02704   TVectorD vec(VecDim);
02705  for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02706 
02707   CnaResultTyp typ = cTypAvMeanCorss;    // averaged MeanCorrelationsBetweenSamples type
02708   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02709   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02710 
02711   Bool_t ok_open = kFALSE;
02712   Bool_t ok_read = kFALSE;
02713 
02714   TString FileNameLong = fCnaWrite->GetRootFileName();
02715   Bool_t allowed_to_read = kFALSE;
02716     
02717 //  if ( fOpenRootFile )
02718 //    {
02719 //      cout << "!TEcnaRead::ReadAverageMeanCorrelationsBetweenSamples(...) *** ERROR ***> "
02720 //         << "Reading on file already open." << fTTBELL << endl;
02721 //    }
02722 
02723   if( FileNameLong == fCurrentlyOpenFileName )
02724     {
02725       allowed_to_read = kTRUE;
02726     }
02727   else
02728     {
02729       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02730       ok_open = OpenRootFile(file_name, "READ");
02731 
02732       if(ok_open)
02733         {
02734           allowed_to_read = kTRUE;
02735         }
02736       else
02737         {
02738           cout << "!TEcnaRead::ReadAverageMeanCorrelationsBetweenSamples(...) *** ERROR ***> Open .root file failed for file: "
02739                << file_name << fTTBELL << endl;
02740           allowed_to_read = kFALSE;
02741           ok_read = kFALSE;
02742         }
02743     }
02744 
02745   if( allowed_to_read == kTRUE )
02746     {
02747       Int_t i_zero = 0;
02748       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02749       
02750       if ( ok_read == kTRUE )
02751         {
02752           fDataExist = kTRUE;
02753           for ( Int_t i0StexStin = 0; i0StexStin < VecDim; i0StexStin++)
02754             {
02755               vec(i0StexStin)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero, i0StexStin);
02756             }   
02757         }
02758       else
02759         {
02760           fDataExist = kFALSE;
02761           cout << "!TEcnaRead::ReadAverageMeanCorrelationsBetweenSamples(...) *** ERROR ***> "
02762                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02763                << "                                                                          -> quantity: <"
02764                << GetTypeOfQuantity(typ) << "> not available in file."
02765                << fTTBELL << endl;
02766         }
02767       CloseRootFile(file_name);
02768     }
02769   return vec;
02770 } // end of ReadAverageMeanCorrelationsBetweenSamples
02771 
02772 //-------------------------------------------------------------------------
02773 //
02774 //        ReadAverageSigmaOfCorrelationsBetweenSamples(...)      
02775 //
02776 //-------------------------------------------------------------------------
02777 TVectorD TEcnaRead::ReadAverageSigmaOfCorrelationsBetweenSamples(const Int_t& VecDim)
02778 {
02779 //Read the expectation values of the Pedestals
02780 //for all the Stins of a given Stex
02781 //in the ROOT file and return them in a TVectorD
02782 //
02783 //Possible values for VecDim: (1) VecDim = fEcal->MaxStinEcnaInStex()
02784 
02785   TestArrayDimH1("ReadAverageSigmaOfCorrelationsBetweenSamples", "fEcal->MaxStinEcnaInStex()",
02786                  fEcal->MaxStinEcnaInStex(), VecDim);
02787 
02788   TVectorD vec(VecDim);
02789  for(Int_t i=0; i<VecDim; i++){vec(i)=(Double_t)0.;}
02790 
02791   CnaResultTyp typ = cTypAvSigCorss;    // averaged SigmaOfCorrelationsBetweenSamples type
02792   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02793   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02794 
02795   Bool_t ok_open = kFALSE;
02796   Bool_t ok_read = kFALSE;
02797 
02798   TString FileNameLong = fCnaWrite->GetRootFileName();
02799   Bool_t allowed_to_read = kFALSE;
02800       
02801 //  if ( fOpenRootFile )
02802 //    {
02803 //      cout << "!TEcnaRead::ReadAverageSigmaOfCorrelationsBetweenSamples(...) *** ERROR ***> "
02804 //         << "Reading on file already open." << fTTBELL << endl;
02805 //    }
02806 
02807   if( FileNameLong == fCurrentlyOpenFileName )
02808     {
02809       allowed_to_read = kTRUE;
02810     }
02811   else
02812     {
02813       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02814       ok_open = OpenRootFile(file_name, "READ");
02815 
02816       if(ok_open)
02817         {
02818           allowed_to_read = kTRUE;
02819         }
02820       else
02821         {
02822           cout << "!TEcnaRead::ReadAverageSigmaOfCorrelationsBetweenSamples(...) *** ERROR ***> Open .root file failed for file: "
02823                << file_name << fTTBELL << endl;
02824           allowed_to_read = kFALSE;
02825           ok_read = kFALSE;
02826         }
02827     }
02828 
02829   if( allowed_to_read == kTRUE )
02830     {
02831       Int_t i_zero = 0;
02832       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
02833       
02834       if ( ok_read == kTRUE )
02835         {
02836           fDataExist = kTRUE;
02837           for ( Int_t i0StexStin = 0; i0StexStin < VecDim; i0StexStin++)
02838             {
02839               vec(i0StexStin)  = gCnaRootFile->fCnaIndivResult->fMatHis(i_zero, i0StexStin);
02840             }   
02841         }
02842       else
02843         {
02844           fDataExist = kFALSE;
02845           cout << "!TEcnaRead::ReadAverageSigmaOfCorrelationsBetweenSamples(...) *** ERROR ***> "
02846                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02847                << "                                                                             -> quantity: <"
02848                << GetTypeOfQuantity(typ) << "> not available in file."
02849                << fTTBELL << endl;
02850         }
02851       CloseRootFile(file_name);
02852     }
02853   return vec;
02854 } // end of ReadAverageSigmaOfCorrelationsBetweenSamples
02855 
02856 
02857 //============================================================================
02858 //
02859 //                       2 D   H I S T O S   (TECHNICAL METHODS)
02860 //
02861 //============================================================================
02862 //-------------------------------------------------------------------------
02863 //
02864 //  ReadCovariancesBetweenSamples(n1StexStin,StinEcha,fFileHeader->fNbOfSamples)
02865 //
02866 //-------------------------------------------------------------------------
02867 TMatrixD TEcnaRead::ReadCovariancesBetweenSamples(const Int_t & n1StexStin, const Int_t & i0StinEcha,
02868                                                   const Int_t& MatDim)
02869 {
02870 //Read the (sample,sample) covariances for a given channel
02871 //in ROOT file and return them in a TMatrixD
02872 //
02873 //Possible values for MatDim: (1) MatDim = fFileHeader->fNbOfSamples
02874 
02875   TestArrayDimH2("ReadCovariancesBetweenSamples", "fFileHeader->fNbOfSamples", fFileHeader->fNbOfSamples, MatDim);
02876 
02877   Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
02878 
02879   TMatrixD mat(MatDim, MatDim);
02880   for(Int_t i=0; i-MatDim<0; i++)
02881     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
02882   
02883   CnaResultTyp typ = cTypCovCss;
02884 
02885   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02886   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02887 
02888   Bool_t ok_open = kFALSE;
02889   Bool_t ok_read = kFALSE;
02890   
02891   TString FileNameLong = fCnaWrite->GetRootFileName();
02892   Bool_t allowed_to_read = kFALSE;
02893       
02894 //  if ( fOpenRootFile )
02895 //    {
02896 //      cout << "!TEcnaRead::ReadCovariancesBetweenSamples(...) *** ERROR ***> "
02897 //         << "Reading on file already open." << fTTBELL << endl;
02898 //    }
02899 
02900   if( FileNameLong == fCurrentlyOpenFileName )
02901     {
02902       allowed_to_read = kTRUE;
02903     }
02904   else
02905     {
02906       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02907       ok_open = OpenRootFile(file_name, "READ");
02908 
02909       if(ok_open)
02910         {
02911           allowed_to_read = kTRUE;
02912         }
02913       else
02914         {
02915           cout << "!TEcnaRead::ReadCovariancesBetweenSamples(...) *** ERROR ***> Open .root file failed for file: "
02916                << file_name << fTTBELL << endl;
02917           allowed_to_read = kFALSE;
02918           ok_read = kFALSE;
02919         }
02920     }
02921 
02922   if( allowed_to_read == kTRUE )
02923     {
02924       ok_read = gCnaRootFile->ReadElement(typ, i0StexEcha);
02925       
02926       if ( ok_read == kTRUE )
02927         {
02928           fDataExist = kTRUE;
02929           for( Int_t i_samp = 0; i_samp - MatDim < 0; i_samp++ )
02930             {
02931               for ( Int_t j_samp = 0; j_samp - MatDim < 0; j_samp++)
02932                 {
02933                  mat(i_samp, j_samp) = gCnaRootFile->fCnaIndivResult->fMatMat(i_samp,j_samp);
02934                 }
02935             }
02936         }
02937       else
02938         {
02939           fDataExist = kFALSE;
02940           cout << "!TEcnaRead::ReadCovariancesBetweenSamples() *** ERROR ***> "
02941                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
02942                << "                                                           -> quantity: <"
02943                << GetTypeOfQuantity(typ) << "> not available in file."
02944                << fTTBELL << endl;
02945         }
02946       CloseRootFile(file_name);
02947     }
02948   return mat;
02949 }
02950 
02951 //-------------------------------------------------------------------------
02952 //
02953 //  ReadCorrelationsBetweenSamples(n1StexStin,StinEcha,fFileHeader->fNbOfSamples)
02954 //
02955 //-------------------------------------------------------------------------
02956 TMatrixD TEcnaRead::ReadCorrelationsBetweenSamples(const Int_t & n1StexStin, const Int_t & i0StinEcha,
02957                                                    const Int_t& MatDim)
02958 {
02959 //Read the (sample,sample) correlations for a given channel
02960 //in ROOT file and return them in a TMatrixD
02961 //
02962 //Possible values for MatDim: (1) MatDim = fFileHeader->fNbOfSamples
02963 
02964   TestArrayDimH2("ReadCorrelationsBetweenSamples", "fFileHeader->fNbOfSamples", fFileHeader->fNbOfSamples, MatDim);
02965 
02966   Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
02967   TMatrixD mat(MatDim, MatDim);
02968   for(Int_t i=0; i- MatDim <0; i++)
02969     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
02970 
02971   CnaResultTyp typ = cTypCorCss;
02972   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
02973   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
02974 
02975   Bool_t ok_open = kFALSE;
02976   Bool_t ok_read = kFALSE;
02977     
02978   TString FileNameLong = fCnaWrite->GetRootFileName();
02979   Bool_t allowed_to_read = kFALSE;
02980       
02981 //  if ( fOpenRootFile )
02982 //    {
02983 //      cout << "!TEcnaRead::ReadCorrelationsBetweenSamples(...) *** ERROR ***> "
02984 //         << "Reading on file already open." << fTTBELL << endl;
02985 //    }
02986 
02987   if( FileNameLong == fCurrentlyOpenFileName )
02988     {
02989       allowed_to_read = kTRUE;
02990     }
02991   else
02992     {
02993       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
02994       ok_open = OpenRootFile(file_name, "READ");
02995 
02996       if(ok_open)
02997         {
02998           allowed_to_read = kTRUE;
02999         }
03000       else
03001         {
03002           cout << "!TEcnaRead::ReadCorrelationsBetweenSamples(...) *** ERROR ***> Open .root file failed for file: "
03003                << file_name << fTTBELL << endl;
03004           allowed_to_read = kFALSE;
03005           ok_read = kFALSE;
03006         }
03007     }
03008 
03009   if( allowed_to_read == kTRUE )
03010     {
03011       ok_read = gCnaRootFile->ReadElement(typ, i0StexEcha);
03012       
03013       if ( ok_read == kTRUE )
03014         {
03015           fDataExist = kTRUE;
03016           for ( Int_t i_samp = 0; i_samp - MatDim < 0; i_samp++){
03017             for ( Int_t j_samp = 0; j_samp - MatDim < 0; j_samp++){
03018               mat(i_samp, j_samp) = gCnaRootFile->fCnaIndivResult->fMatMat(i_samp,j_samp);}}
03019         }
03020       else
03021         {
03022           fDataExist = kFALSE;
03023           cout << "!TEcnaRead::ReadCorrelationsBetweenSamples() *** ERROR ***> "
03024                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03025                << "                                                            -> quantity: <"
03026                << GetTypeOfQuantity(typ) << "> not available in file."
03027                << fTTBELL << endl;
03028         }
03029       CloseRootFile(file_name);
03030     }
03031   return mat;
03032 }
03033 //-------------------------------------------------------------------------
03034 //
03035 //  ReadRelevantCorrelationsBetweenSamples(n1StexStin,i0StinEcha)
03036 //                 (NOT USED)
03037 //-------------------------------------------------------------------------
03038 TVectorD TEcnaRead::ReadRelevantCorrelationsBetweenSamples(const Int_t & n1StexStin, const Int_t & i0StinEcha,
03039                                                            const Int_t & InPutMatDim )
03040 {
03041 //Read the (sample,sample) correlations for a given channel
03042 //in ROOT file and return the relevant correlations in a TVectorD
03043 //
03044 //Possible values for InPutMatDim: (1) InPutMatDim = fFileHeader->fNbOfSamples
03045 //
03046 //  *===>  OutPut TVectorD dimension value = InPutMatDim*(InPutMatDim-1)/2
03047 
03048   TestArrayDimH2("ReadRelevantCorrelationsBetweenSamples", "fFileHeader->fNbOfSamples",
03049                  fFileHeader->fNbOfSamples, InPutMatDim);
03050 
03051   Int_t i0StexEcha = fEcalNumbering->Get0StexEchaFrom1StexStinAnd0StinEcha(n1StexStin, i0StinEcha);
03052   Int_t nb_of_relevant = InPutMatDim*(InPutMatDim-1)/2;
03053   TVectorD vec_rel(nb_of_relevant); for(Int_t i=0; i<nb_of_relevant; i++){vec_rel(i)=(Double_t)0.;}
03054   CnaResultTyp typ = cTypCorCss;
03055   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03056   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03057 
03058   Bool_t ok_open = kFALSE;
03059   Bool_t ok_read = kFALSE;
03060     
03061   TString FileNameLong = fCnaWrite->GetRootFileName();
03062   Bool_t allowed_to_read = kFALSE;
03063 
03064 //  if ( fOpenRootFile )
03065 //    {
03066 //      cout << "!TEcnaRead::ReadRelevantCorrelationsBetweenSamples(...) *** ERROR ***> "
03067 //         << "Reading on file already open." << fTTBELL << endl;
03068 //    }
03069 
03070   if( FileNameLong == fCurrentlyOpenFileName )
03071     {
03072       allowed_to_read = kTRUE;
03073     }
03074   else
03075     {
03076       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03077       ok_open = OpenRootFile(file_name, "READ");
03078 
03079       if(ok_open)
03080         {
03081           allowed_to_read = kTRUE;
03082         }
03083       else
03084         {
03085           cout << "!TEcnaRead::ReadRelevantCorrelationsBetweenSamples(...) *** ERROR ***> Open .root file failed for file: "
03086                << file_name << fTTBELL << endl;
03087           allowed_to_read = kFALSE;
03088           ok_read = kFALSE;
03089         }
03090     }
03091 
03092   if( allowed_to_read == kTRUE )
03093     {
03094       ok_read = gCnaRootFile->ReadElement(typ, i0StexEcha);
03095       
03096       if ( ok_read == kTRUE )
03097         {
03098           fDataExist = kTRUE;
03099           Int_t k_cor = 0;
03100           for ( Int_t i_samp = 0; i_samp < InPutMatDim; i_samp++){
03101             for ( Int_t j_samp = 0; j_samp < i_samp; j_samp++){
03102               vec_rel(k_cor) = gCnaRootFile->fCnaIndivResult->fMatMat(i_samp,j_samp);
03103               k_cor++;}}
03104         }
03105       else
03106         {
03107           fDataExist = kFALSE;
03108           cout << "!TEcnaRead::ReadRelevantCorrelationsBetweenSamples() *** ERROR ***> "
03109                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03110                << "                                                                    -> quantity: <"
03111                << GetTypeOfQuantity(typ) << "> not available in file."
03112                << fTTBELL << endl;
03113         }
03114       CloseRootFile(file_name);
03115     }
03116   return vec_rel;
03117 }
03118 //----- end of (ReadRelevantCorrelationsBetweenSamples ) -------
03119 
03120 //-----------------------------------------------------------------------------------------
03121 //
03122 //        ReadLowFrequencyCovariancesBetweenChannels(Stin_a, Stin_b)
03123 //
03124 //-----------------------------------------------------------------------------------------
03125 TMatrixD TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels(const Int_t& n1StexStin_a,
03126                                                                const Int_t& n1StexStin_b,
03127                                                                const Int_t& MatDim)
03128 {
03129 //Read the Low Frequency cov(i0StinEcha of Stin_a, i0StinEcha of Stin b)
03130 //in ROOT file and return them in a TMatrixD
03131 //
03132 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysInStin()
03133 
03134   TestArrayDimH2("ReadLowFrequencyCovariancesBetweenChannels", "fEcal->MaxCrysInStin()",
03135                  fEcal->MaxCrysInStin(), MatDim);
03136 
03137   Int_t   index_Stin_a = GetStinIndex(n1StexStin_a);
03138   Int_t   index_Stin_b = GetStinIndex(n1StexStin_b);
03139 
03140   TMatrixD mat(MatDim, MatDim);
03141   for(Int_t i=0; i-MatDim<0; i++)
03142     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03143   
03144   CnaResultTyp typ = cTypLfCov;
03145 
03146   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03147   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03148 
03149   Bool_t ok_open = kFALSE;
03150   Bool_t ok_read = kFALSE;
03151     
03152   TString FileNameLong = fCnaWrite->GetRootFileName();
03153   Bool_t allowed_to_read = kFALSE;
03154   
03155 //  if ( fOpenRootFile )
03156 //    {
03157 //      cout << "!TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels(...) *** ERROR ***>"
03158 //         << " Reading on file already open." << fTTBELL << endl;
03159 //    }
03160 
03161   if( FileNameLong == fCurrentlyOpenFileName )
03162     {
03163       allowed_to_read = kTRUE;
03164     }
03165   else
03166     {
03167       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03168       ok_open = OpenRootFile(file_name, "READ");
03169 
03170       if(ok_open)
03171         {
03172           allowed_to_read = kTRUE;
03173         }
03174       else
03175         {
03176           cout << "!TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03177                << file_name << fTTBELL << endl;
03178           allowed_to_read = kFALSE;
03179           ok_read = kFALSE;
03180         }
03181     }
03182 
03183   if( allowed_to_read == kTRUE )
03184     {
03185       Int_t i_zero = 0;
03186       ok_read = gCnaRootFile->ReadElement(typ,i_zero);
03187       
03188       if ( ok_read == kTRUE )
03189         {
03190           fDataExist = kTRUE;
03191           for ( Int_t i_crys = 0; i_crys - MatDim < 0; i_crys++)
03192             {
03193               Int_t i_cna_chan = index_Stin_a*MatDim + i_crys;
03194               for ( Int_t j_crys = 0; j_crys - MatDim<0; j_crys++)
03195                 {
03196                   Int_t j_cna_chan = index_Stin_b*MatDim + j_crys;
03197                   mat(i_crys, j_crys) = gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03198                 }
03199             }
03200         }
03201       else
03202         {
03203           fDataExist = kFALSE;
03204           cout << "!TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels(...) *** ERROR ***> "
03205                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03206                << "                                                                           -> quantity: <"
03207                << GetTypeOfQuantity(typ) << "> not available in file."
03208                << fTTBELL << endl;
03209         }
03210       CloseRootFile(file_name);
03211     }
03212   return mat;
03213 }
03214 //----- end of ( ReadLowFrequencyCovariancesBetweenChannels(...) ) -------
03215 
03216 //-------------------------------------------------------------------------------------------
03217 //
03218 //         ReadLowFrequencyCorrelationsBetweenChannels(Stin_a, Stin_b)
03219 //
03220 //-------------------------------------------------------------------------------------------
03221 TMatrixD TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels(const Int_t & n1StexStin_a,
03222                                                                 const Int_t & n1StexStin_b,
03223                                                                 const Int_t& MatDim)
03224 {
03225 //Read the Low Frequency cor(i0StinEcha of Stin_a, i0StinEcha of Stin b)
03226 //in ROOT file and return them in a TMatrixD
03227 //
03228 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysInStin()
03229 
03230   TestArrayDimH2("ReadLowFrequencyCorrelationsBetweenChannels", "fEcal->MaxCrysInStin()", fEcal->MaxCrysInStin(), MatDim);
03231 
03232   Int_t   index_Stin_a = GetStinIndex(n1StexStin_a);
03233   Int_t   index_Stin_b = GetStinIndex(n1StexStin_b);
03234 
03235   TMatrixD mat(MatDim, MatDim);
03236   for(Int_t i=0; i-MatDim<0; i++)
03237     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03238   
03239   CnaResultTyp typ = cTypLfCor;
03240 
03241   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03242   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03243 
03244   Bool_t ok_open = kFALSE;
03245   Bool_t ok_read = kFALSE;
03246     
03247   TString FileNameLong = fCnaWrite->GetRootFileName();
03248   Bool_t allowed_to_read = kFALSE;
03249   
03250 //  if ( fOpenRootFile )
03251 //    {
03252 //      cout << "!TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels(...) *** ERROR ***>"
03253 //         << " Reading on file already open." << fTTBELL << endl;
03254 //    }
03255 
03256   if( FileNameLong == fCurrentlyOpenFileName )
03257     {
03258       allowed_to_read = kTRUE;
03259     }
03260   else
03261     {
03262       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03263       ok_open = OpenRootFile(file_name, "READ");
03264 
03265       if(ok_open)
03266         {
03267           allowed_to_read = kTRUE;
03268         }
03269       else
03270         {
03271           cout << "!TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03272                << file_name << fTTBELL << endl;
03273           allowed_to_read = kFALSE;
03274           ok_read = kFALSE;
03275         }
03276     }
03277 
03278   if( allowed_to_read == kTRUE )
03279     {
03280       Int_t i_zero = 0;
03281 
03282       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
03283       
03284       if ( ok_read == kTRUE )
03285         {
03286           fDataExist = kTRUE;
03287           for ( Int_t i_crys = 0; i_crys - MatDim<0; i_crys++)
03288             {
03289               Int_t i_cna_chan = index_Stin_a*MatDim + i_crys;
03290               for ( Int_t j_crys = 0; j_crys - MatDim<0; j_crys++)
03291                 {
03292                   Int_t j_cna_chan = index_Stin_b*MatDim + j_crys;
03293                   mat(i_crys, j_crys) = gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03294                 }
03295             }
03296         }
03297       else
03298         {
03299           fDataExist = kFALSE;
03300           cout << "!TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels(...) *** ERROR ***> "
03301                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03302                << "                                                                            -> quantity: <"
03303                << GetTypeOfQuantity(typ) << "> not available in file."
03304                << fTTBELL << endl;
03305         }
03306       CloseRootFile(file_name);
03307     }
03308   return mat;
03309 }
03310 //----- end of ( ReadLowFrequencyCorrelationsBetweenChannels(...) ) -------
03311 
03312 //-----------------------------------------------------------------------------------------
03313 //
03314 //        ReadHighFrequencyCovariancesBetweenChannels(Stin_a, Stin_b)
03315 //
03316 //-----------------------------------------------------------------------------------------
03317 TMatrixD TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels(const Int_t & n1StexStin_a,
03318                                                                 const Int_t & n1StexStin_b,
03319                                                                 const Int_t& MatDim)
03320 {
03321 //Read the High Frequency cov(i0StinEcha of Stin_a, i0StinEcha of Stin b)
03322 //in ROOT file and return them in a TMatrixD
03323 //
03324 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysInStin()
03325 
03326   TestArrayDimH2("ReadHighFrequencyCovariancesBetweenChannels", "fEcal->MaxCrysInStin()",
03327                  fEcal->MaxCrysInStin(), MatDim);
03328 
03329   Int_t   index_Stin_a = GetStinIndex(n1StexStin_a);
03330   Int_t   index_Stin_b = GetStinIndex(n1StexStin_b);
03331 
03332   TMatrixD mat(MatDim, MatDim);
03333   for(Int_t i=0; i-MatDim<0; i++)
03334     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03335   
03336   CnaResultTyp typ = cTypHfCov;
03337 
03338   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03339   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03340 
03341   Bool_t ok_open = kFALSE;
03342   Bool_t ok_read = kFALSE;
03343     
03344   TString FileNameLong = fCnaWrite->GetRootFileName();
03345   Bool_t allowed_to_read = kFALSE;
03346   
03347 //  if ( fOpenRootFile )
03348 //    {
03349 //      cout << "!TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels(...) *** ERROR ***>"
03350 //         << " Reading on file already open." << fTTBELL << endl;
03351 //    }
03352 
03353   if( FileNameLong == fCurrentlyOpenFileName )
03354     {
03355       allowed_to_read = kTRUE;
03356     }
03357   else
03358     {
03359       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03360       ok_open = OpenRootFile(file_name, "READ");
03361 
03362       if(ok_open)
03363         {
03364           allowed_to_read = kTRUE;
03365         }
03366       else
03367         {
03368           cout << "!TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03369                << file_name << fTTBELL << endl;
03370           allowed_to_read = kFALSE;
03371           ok_read = kFALSE;
03372         }
03373     }
03374 
03375   if( allowed_to_read == kTRUE )
03376     {
03377       Int_t i_zero = 0;
03378       ok_read = gCnaRootFile->ReadElement(typ,i_zero);
03379       
03380       if ( ok_read == kTRUE )
03381         {
03382           fDataExist = kTRUE;
03383           for ( Int_t i_crys = 0; i_crys - MatDim<0; i_crys++)
03384             {
03385               Int_t i_cna_chan = index_Stin_a*MatDim + i_crys;
03386               for ( Int_t j_crys = 0; j_crys - MatDim<0; j_crys++)
03387                 {
03388                   Int_t j_cna_chan = index_Stin_b*MatDim + j_crys;
03389                   mat(i_crys, j_crys) = gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03390                 }
03391             }
03392         }
03393       else
03394         {
03395           fDataExist = kFALSE;
03396           cout << "!TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels(...) *** ERROR ***> "
03397                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03398                << "                                                                            -> quantity: <"
03399                << GetTypeOfQuantity(typ) << "> not available in file."
03400                << fTTBELL << endl;
03401         }
03402       CloseRootFile(file_name);
03403     }
03404   return mat;
03405 }
03406 //----- end of ( ReadHighFrequencyCovariancesBetweenChannels(...) ) -------
03407 
03408 //-------------------------------------------------------------------------------------------
03409 //
03410 //         ReadHighFrequencyCorrelationsBetweenChannels(Stin_a, Stin_b)
03411 //
03412 //-------------------------------------------------------------------------------------------
03413 TMatrixD TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels(const Int_t & n1StexStin_a,
03414                                                                  const Int_t & n1StexStin_b,
03415                                                                  const Int_t& MatDim)
03416 {
03417 //Read the High Frequency Cor(i0StinEcha of Stin_a, i0StinEcha of Stin b)
03418 //in ROOT file and return them in a TMatrixD
03419 //
03420 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysInStin()
03421 
03422   TestArrayDimH2("ReadHighFrequencyCorrelationsBetweenChannels", "fEcal->MaxCrysInStin()",
03423                  fEcal->MaxCrysInStin(), MatDim);
03424 
03425   Int_t   index_Stin_a = GetStinIndex(n1StexStin_a);
03426   Int_t   index_Stin_b = GetStinIndex(n1StexStin_b);
03427 
03428   TMatrixD mat(MatDim, MatDim);
03429   for(Int_t i=0; i-MatDim<0; i++)
03430     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03431   
03432   CnaResultTyp typ = cTypHfCor;
03433 
03434   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03435   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03436 
03437   Bool_t ok_open = kFALSE;
03438   Bool_t ok_read = kFALSE;
03439     
03440   TString FileNameLong = fCnaWrite->GetRootFileName();
03441   Bool_t allowed_to_read = kFALSE;
03442     
03443 //  if ( fOpenRootFile )
03444 //    {
03445 //      cout << "!TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels(...) *** ERROR ***>"
03446 //         << " Reading on file already open." << fTTBELL << endl;
03447 //    }
03448 
03449   if( FileNameLong == fCurrentlyOpenFileName )
03450     {
03451       allowed_to_read = kTRUE;
03452     }
03453   else
03454     {
03455       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03456       ok_open = OpenRootFile(file_name, "READ");
03457 
03458       if(ok_open)
03459         {
03460           allowed_to_read = kTRUE;
03461         }
03462       else
03463         {
03464           cout << "!TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03465                << file_name << fTTBELL << endl;
03466           allowed_to_read = kFALSE;
03467           ok_read = kFALSE;
03468         }
03469     }
03470 
03471   if( allowed_to_read == kTRUE )
03472     {
03473       Int_t i_zero = 0;
03474 
03475       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
03476       
03477       if ( ok_read == kTRUE )
03478         {
03479           fDataExist = kTRUE;
03480           for ( Int_t i_crys = 0; i_crys - MatDim<0; i_crys++)
03481             {
03482               Int_t i_cna_chan = index_Stin_a*MatDim + i_crys;
03483               for ( Int_t j_crys = 0; j_crys - MatDim<0; j_crys++)
03484                 {
03485                   Int_t j_cna_chan = index_Stin_b*MatDim + j_crys;
03486                   mat(i_crys, j_crys) = gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03487                 }
03488             }
03489         }
03490       else
03491         {
03492           fDataExist = kFALSE;
03493           cout << "!TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels(...) *** ERROR ***> "
03494                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03495                << "                                                                             -> quantity: <"
03496                << GetTypeOfQuantity(typ) << "> not available in file."
03497                << fTTBELL << endl;
03498         }
03499       CloseRootFile(file_name);
03500     }
03501   return mat;
03502 }
03503 //----- end of ( ReadHighFrequencyCorrelationsBetweenChannels(...) ) -------
03504 
03505 //-------------------------------------------------------------------------
03506 //
03507 //         ReadLowFrequencyCovariancesBetweenChannels(...)
03508 //                  (NOT USED)
03509 //-------------------------------------------------------------------------
03510 TMatrixD TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels(const Int_t& MatDim)
03511 {
03512 //Read all the Low Frequency covariances
03513 //in ROOT file and return them in a TMatrixD
03514 //
03515 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
03516 
03517   TestArrayDimH2("ReadLowFrequencyCovariancesBetweenChannels", "fEcal->MaxCrysEcnaInStex()",
03518                  fEcal->MaxCrysEcnaInStex(), MatDim);
03519 
03520   //=====> WARNING: BIG MATRIX (1700x1700)
03521   TMatrixD mat(MatDim, MatDim);
03522   for(Int_t i=0; i-MatDim<0; i++){for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03523 
03524   TVectorD vec(fEcal->MaxStinEcnaInStex());
03525   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
03526   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
03527   
03528   CnaResultTyp typ = cTypLfCov;
03529 
03530   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03531   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03532 
03533   Bool_t ok_open = kFALSE;
03534   Bool_t ok_read = kFALSE;
03535     
03536   TString FileNameLong = fCnaWrite->GetRootFileName();
03537   Bool_t allowed_to_read = kFALSE;
03538   
03539 //  if ( fOpenRootFile )
03540 //    {
03541 //      cout << "!TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels() *** ERROR ***>"
03542 //         << " Reading on file already open." << fTTBELL << endl;
03543 //    }
03544 
03545   if( FileNameLong == fCurrentlyOpenFileName )
03546     {
03547       allowed_to_read = kTRUE;
03548     }
03549   else
03550     {
03551       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03552       ok_open = OpenRootFile(file_name, "READ");
03553 
03554       if(ok_open)
03555         {
03556           allowed_to_read = kTRUE;
03557         }
03558       else
03559         {
03560           cout << "!TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03561                << file_name << fTTBELL << endl;
03562           allowed_to_read = kFALSE;
03563           ok_read = kFALSE;
03564         }
03565     }
03566 
03567   if( allowed_to_read == kTRUE )
03568     {
03569       Int_t i_zero = 0;
03570       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
03571       
03572       if ( ok_read == kTRUE )
03573         {
03574           fDataExist = kTRUE;
03575           for (Int_t index_Stin_a = 0; index_Stin_a < fEcal->MaxStinEcnaInStex(); index_Stin_a++)
03576             {
03577               if ( vec(index_Stin_a) > 0 && vec(index_Stin_a) <= fEcal->MaxStinEcnaInStex())
03578                 {
03579                   for (Int_t index_Stin_b = 0; index_Stin_b < fEcal->MaxStinEcnaInStex(); index_Stin_b++)
03580                     {
03581                       if ( vec(index_Stin_b) > 0 && vec(index_Stin_b) <= fEcal->MaxStinEcnaInStex())
03582                         {
03583                           for ( Int_t i_crys = 0; i_crys < fEcal->MaxCrysInStin(); i_crys++)
03584                             {
03585                               Int_t i_cna_chan = index_Stin_a*fEcal->MaxCrysInStin() + i_crys;
03586                               Int_t i_chan_sm = (Int_t)(vec(index_Stin_a)-1)*fEcal->MaxCrysInStin() +i_crys;
03587                               for ( Int_t j_crys = 0; j_crys < fEcal->MaxCrysInStin(); j_crys++)
03588                                 {
03589                                   Int_t j_cna_chan = index_Stin_b*fEcal->MaxCrysInStin() + j_crys;
03590                                   Int_t j_chan_sm = (Int_t)(vec(index_Stin_b)-1)*fEcal->MaxCrysInStin() +j_crys;
03591                                   mat(i_chan_sm, j_chan_sm) =
03592                                     gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03593                                 }
03594                             }
03595                         }
03596                     }
03597                 }
03598             }
03599         }
03600       else
03601         {
03602           fDataExist = kFALSE;
03603           cout << "!TEcnaRead::ReadLowFrequencyCovariancesBetweenChannels() *** ERROR ***> "
03604                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03605                << "                                                                        -> quantity: <"
03606                << GetTypeOfQuantity(typ) << "> not available in file."
03607                << fTTBELL << endl;
03608         }
03609       CloseRootFile(file_name);
03610     }
03611   return mat;
03612 }
03613 //----- end of ( ReadLowFrequencyCovariancesBetweenChannels(...) ) -------
03614 
03615 //-------------------------------------------------------------------------
03616 //
03617 //         ReadLowFrequencyCorrelationsBetweenChannels(...)
03618 //
03619 //-------------------------------------------------------------------------
03620 TMatrixD TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels(const Int_t& MatDim)
03621 {
03622 //Read all the Low Frequency correlations
03623 //in ROOT file and return them in a TMatrixD
03624 //
03625 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
03626 
03627   TestArrayDimH2("ReadLowFrequencyCorrelationsBetweenChannels", "fEcal->MaxCrysEcnaInStex()",
03628                  fEcal->MaxCrysEcnaInStex(), MatDim);
03629 
03630   //=====> WARNING: BIG MATRIX (1700x1700)
03631   TMatrixD mat(MatDim, MatDim);
03632   for(Int_t i=0; i-MatDim<0; i++){for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03633 
03634   TVectorD vec(fEcal->MaxStinEcnaInStex());
03635   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
03636   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
03637   
03638   CnaResultTyp typ = cTypLfCor;
03639 
03640   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03641   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03642 
03643   Bool_t ok_open = kFALSE;
03644   Bool_t ok_read = kFALSE;
03645     
03646   TString FileNameLong = fCnaWrite->GetRootFileName();
03647   Bool_t allowed_to_read = kFALSE;
03648     
03649 //  if ( fOpenRootFile )
03650 //    {
03651 //      cout << "!TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels() *** ERROR ***>"
03652 //         << " Reading on file already open." << fTTBELL << endl;
03653 //    }
03654 
03655   if( FileNameLong == fCurrentlyOpenFileName )
03656     {
03657       allowed_to_read = kTRUE;
03658     }
03659   else
03660     {
03661       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03662       ok_open = OpenRootFile(file_name, "READ");
03663 
03664       if(ok_open)
03665         {
03666           allowed_to_read = kTRUE;
03667         }
03668       else
03669         {
03670           cout << "!TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03671                << file_name << fTTBELL << endl;
03672           allowed_to_read = kFALSE;
03673           ok_read = kFALSE;
03674         }
03675     }
03676 
03677   if( allowed_to_read == kTRUE )
03678     {
03679       Int_t i_zero = 0;
03680       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
03681       
03682       if ( ok_read == kTRUE )
03683         {
03684           fDataExist = kTRUE;
03685           for (Int_t index_Stin_a = 0; index_Stin_a < fEcal->MaxStinEcnaInStex(); index_Stin_a++)
03686             {
03687               if ( vec(index_Stin_a) > 0 && vec(index_Stin_a) <= fEcal->MaxStinEcnaInStex())
03688                 {
03689                   for (Int_t index_Stin_b = 0; index_Stin_b < fEcal->MaxStinEcnaInStex(); index_Stin_b++)
03690                     {
03691                       if ( vec(index_Stin_b) > 0 && vec(index_Stin_b) <= fEcal->MaxStinEcnaInStex())
03692                         {
03693                           for ( Int_t i_crys = 0; i_crys < fEcal->MaxCrysInStin(); i_crys++)
03694                             {
03695                               Int_t i_cna_chan = index_Stin_a*fEcal->MaxCrysInStin() + i_crys;
03696                               Int_t i_chan_sm = (Int_t)(vec(index_Stin_a)-1)*fEcal->MaxCrysInStin() + i_crys;
03697                               for ( Int_t j_crys = 0; j_crys < fEcal->MaxCrysInStin(); j_crys++)
03698                                 {
03699                                   Int_t j_cna_chan = index_Stin_b*fEcal->MaxCrysInStin() + j_crys;
03700                                   Int_t j_chan_sm = (Int_t)(vec(index_Stin_b)-1)*fEcal->MaxCrysInStin() + j_crys;
03701                                   mat(i_chan_sm, j_chan_sm) =
03702                                     gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03703                                 }
03704                             }
03705                         }
03706                     }
03707                 }
03708             }
03709         }
03710       else
03711         {
03712           fDataExist = kFALSE;
03713           cout << "!TEcnaRead::ReadLowFrequencyCorrelationsBetweenChannels() *** ERROR ***> "
03714                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03715                << "                                                                         ->  quantity: <"
03716                << GetTypeOfQuantity(typ) << "> not available in file."
03717                << fTTBELL << endl;
03718         }
03719       CloseRootFile(file_name);
03720     }
03721   return mat;
03722 }
03723 //----- end of (ReadLowFrequencyCorrelationsBetweenChannels(...) ) -------
03724 
03725 //-------------------------------------------------------------------------
03726 //
03727 //         ReadHighFrequencyCovariancesBetweenChannels(...)
03728 //                  (NOT USED)
03729 //-------------------------------------------------------------------------
03730 TMatrixD TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels(const Int_t& MatDim)
03731 {
03732 //Read all the High Frequency covariances
03733 //in ROOT file and return them in a TMatrixD
03734 //
03735 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
03736 
03737   TestArrayDimH2("ReadHighFrequencyCovariancesBetweenChannels", "fEcal->MaxCrysEcnaInStex()",
03738                  fEcal->MaxCrysEcnaInStex(), MatDim);
03739 
03740   //=====> WARNING: BIG MATRIX (1700x1700)
03741   TMatrixD mat(MatDim, MatDim);
03742   for(Int_t i=0; i-MatDim<0; i++){for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03743 
03744   TVectorD vec(fEcal->MaxStinEcnaInStex());
03745   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
03746   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
03747   
03748   CnaResultTyp typ = cTypHfCov;
03749 
03750   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03751   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03752 
03753   Bool_t ok_open = kFALSE;
03754   Bool_t ok_read = kFALSE;
03755     
03756   TString FileNameLong = fCnaWrite->GetRootFileName();
03757   Bool_t allowed_to_read = kFALSE;
03758 
03759 //  if ( fOpenRootFile )
03760 //    {
03761 //      cout << "!TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels() *** ERROR ***>"
03762 //         << " Reading on file already open." << fTTBELL << endl;
03763 //    }
03764 
03765   if( FileNameLong == fCurrentlyOpenFileName )
03766     {
03767       allowed_to_read = kTRUE;
03768     }
03769   else
03770     {
03771       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03772       ok_open = OpenRootFile(file_name, "READ");
03773 
03774       if(ok_open)
03775         {
03776           allowed_to_read = kTRUE;
03777         }
03778       else
03779         {
03780           cout << "!TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03781                << file_name << fTTBELL << endl;
03782           allowed_to_read = kFALSE;
03783           ok_read = kFALSE;
03784         }
03785     }
03786 
03787   if( allowed_to_read == kTRUE )
03788     {
03789       Int_t i_zero = 0;
03790       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
03791       
03792       if ( ok_read == kTRUE )
03793         {
03794           fDataExist = kTRUE;
03795           for (Int_t index_Stin_a = 0; index_Stin_a < fEcal->MaxStinEcnaInStex(); index_Stin_a++)
03796             {
03797               if ( vec(index_Stin_a) > 0 && vec(index_Stin_a) <= fEcal->MaxStinEcnaInStex())
03798                 {
03799                   for (Int_t index_Stin_b = 0; index_Stin_b < fEcal->MaxStinEcnaInStex(); index_Stin_b++)
03800                     {
03801                       if ( vec(index_Stin_b) > 0 && vec(index_Stin_b) <= fEcal->MaxStinEcnaInStex())
03802                         {
03803                           for ( Int_t i_crys = 0; i_crys < fEcal->MaxCrysInStin(); i_crys++)
03804                             {
03805                               Int_t i_cna_chan = index_Stin_a*fEcal->MaxCrysInStin() + i_crys;
03806                               Int_t i_chan_sm = (Int_t)(vec(index_Stin_a)-1)*fEcal->MaxCrysInStin() +i_crys;
03807                               for ( Int_t j_crys = 0; j_crys < fEcal->MaxCrysInStin(); j_crys++)
03808                                 {
03809                                   Int_t j_cna_chan = index_Stin_b*fEcal->MaxCrysInStin() + j_crys;
03810                                   Int_t j_chan_sm = (Int_t)(vec(index_Stin_b)-1)*fEcal->MaxCrysInStin() +j_crys;
03811                                   mat(i_chan_sm, j_chan_sm) =
03812                                     gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03813                                 }
03814                             }
03815                         }
03816                     }
03817                 }
03818             }
03819         }
03820       else
03821         {
03822           fDataExist = kFALSE;
03823           cout << "!TEcnaRead::ReadHighFrequencyCovariancesBetweenChannels() *** ERROR ***> "
03824                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03825                << "                                                                         -> quantity: <"
03826                << GetTypeOfQuantity(typ) << "> not available in file."
03827                << fTTBELL << endl;
03828         }
03829       CloseRootFile(file_name);
03830     }
03831   return mat;
03832 }
03833 //----- end of ( ReadHighFrequencyCovariancesBetweenChannels(...) ) -------
03834 
03835 //-------------------------------------------------------------------------
03836 //
03837 //         ReadHighFrequencyCorrelationsBetweenChannels(...)
03838 //
03839 //-------------------------------------------------------------------------
03840 TMatrixD TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels(const Int_t& MatDim)
03841 {
03842 //Read all the High Frequency correlations
03843 //in ROOT file and return them in a TMatrixD
03844 //
03845 //Possible values for MatDim: (1) MatDim = fEcal->MaxCrysEcnaInStex()
03846 
03847   TestArrayDimH2("ReadHighFrequencyCorrelationsBetweenChannels", "fEcal->MaxCrysEcnaInStex()",
03848                  fEcal->MaxCrysEcnaInStex(), MatDim);
03849 
03850   //=====> WARNING: BIG MATRIX (1700x1700)
03851   TMatrixD mat(MatDim, MatDim);
03852   for(Int_t i=0; i-MatDim<0; i++){for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03853 
03854   TVectorD vec(fEcal->MaxStinEcnaInStex());
03855   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
03856   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
03857   
03858   CnaResultTyp typ = cTypHfCor;
03859 
03860   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03861   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03862 
03863   Bool_t ok_open = kFALSE;
03864   Bool_t ok_read = kFALSE;
03865     
03866   TString FileNameLong = fCnaWrite->GetRootFileName();
03867   Bool_t allowed_to_read = kFALSE;
03868   
03869 //  if ( fOpenRootFile )
03870 //    {
03871 //      cout << "!TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels() *** ERROR ***>"
03872 //         << " Reading on file already open." << fTTBELL << endl;
03873 //    }
03874 
03875   if( FileNameLong == fCurrentlyOpenFileName )
03876     {
03877       allowed_to_read = kTRUE;
03878     }
03879   else
03880     {
03881       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03882       ok_open = OpenRootFile(file_name, "READ");
03883 
03884       if(ok_open)
03885         {
03886           allowed_to_read = kTRUE;
03887         }
03888       else
03889         {
03890           cout << "!TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels(...) *** ERROR ***> Open .root file failed for file: "
03891                << file_name << fTTBELL << endl;
03892           allowed_to_read = kFALSE;
03893           ok_read = kFALSE;
03894         }
03895     }
03896 
03897   if( allowed_to_read == kTRUE )
03898     {
03899       Int_t i_zero = 0;
03900       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
03901       
03902       if ( ok_read == kTRUE )
03903         {
03904           fDataExist = kTRUE;
03905           for (Int_t index_Stin_a = 0; index_Stin_a < fEcal->MaxStinEcnaInStex(); index_Stin_a++)
03906             {
03907               if ( vec(index_Stin_a) > 0 && vec(index_Stin_a) <= fEcal->MaxStinEcnaInStex())
03908                 {
03909                   for (Int_t index_Stin_b = 0; index_Stin_b < fEcal->MaxStinEcnaInStex(); index_Stin_b++)
03910                     {
03911                       if ( vec(index_Stin_b) > 0 && vec(index_Stin_b) <= fEcal->MaxStinEcnaInStex())
03912                         {
03913                           for ( Int_t i_crys = 0; i_crys < fEcal->MaxCrysInStin(); i_crys++)
03914                             {
03915                               Int_t i_cna_chan = index_Stin_a*fEcal->MaxCrysInStin() + i_crys;
03916                               Int_t i_chan_sm = (Int_t)(vec(index_Stin_a)-1)*fEcal->MaxCrysInStin() + i_crys;
03917                               for ( Int_t j_crys = 0; j_crys < fEcal->MaxCrysInStin(); j_crys++)
03918                                 {
03919                                   Int_t j_cna_chan = index_Stin_b*fEcal->MaxCrysInStin() + j_crys;
03920                                   Int_t j_chan_sm = (Int_t)(vec(index_Stin_b)-1)*fEcal->MaxCrysInStin() + j_crys;
03921                                   mat(i_chan_sm, j_chan_sm) =
03922                                     gCnaRootFile->fCnaIndivResult->fMatMat(i_cna_chan,j_cna_chan);
03923                                 }
03924                             }
03925                         }
03926                     }
03927                 }
03928             }
03929         }
03930       else
03931         {
03932           fDataExist = kFALSE;
03933           cout << "!TEcnaRead::ReadHighFrequencyCorrelationsBetweenChannels() *** ERROR ***> "
03934                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
03935                << "                                                                          -> quantity: <"
03936                << GetTypeOfQuantity(typ) << "> not available in file."
03937                << fTTBELL << endl;
03938         }
03939       CloseRootFile(file_name);
03940     }
03941   return mat;
03942 }
03943 //-------------- ( end of ReadHighFrequencyCorrelationsBetweenChannels(...) ) ---------
03944 
03945 
03946 //-------------------------------------------------------------------------
03947 //
03948 //         ReadLowFrequencyMeanCorrelationsBetweenStins(...)
03949 //
03950 //-------------------------------------------------------------------------
03951 TMatrixD TEcnaRead::ReadLowFrequencyMeanCorrelationsBetweenStins(const Int_t& MatDim)
03952 {
03953 //Read all the Low Frequency Mean Correlations Between Stins the for all (Stin_X, Stin_Y)
03954 //in ROOT file and return them in a TMatrixD
03955 //
03956 //Possible values for MatDim: (1) MatDim = fEcal->MaxStinEcnaInStex()
03957 
03958   TestArrayDimH2("ReadLowFrequencyMeanCorrelationsBetweenStins", "fEcal->MaxStinEcnaInStex()",
03959                  fEcal->MaxStinEcnaInStex(), MatDim);
03960 
03961   TMatrixD mat(MatDim, MatDim);
03962   for(Int_t i=0; i-MatDim<0; i++)
03963     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
03964 
03965   TVectorD vec(fEcal->MaxStinEcnaInStex());
03966   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
03967   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
03968 
03969   CnaResultTyp typ = cTypLFccMoStins;
03970 
03971   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
03972   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
03973 
03974   Bool_t ok_open = kFALSE;
03975   Bool_t ok_read = kFALSE;
03976     
03977   TString FileNameLong = fCnaWrite->GetRootFileName();
03978   Bool_t allowed_to_read = kFALSE;
03979     
03980 //  if ( fOpenRootFile )
03981 //    {
03982 //      cout << "!TEcnaRead::ReadLowFrequencyMeanCorrelationsBetweenStins() *** ERROR ***>"
03983 //         << " Reading on file already open." << fTTBELL << endl;
03984 //    }
03985 
03986   if( FileNameLong == fCurrentlyOpenFileName )
03987     {
03988       allowed_to_read = kTRUE;
03989     }
03990   else
03991     {
03992       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
03993       ok_open = OpenRootFile(file_name, "READ");
03994 
03995       if(ok_open)
03996         {
03997           allowed_to_read = kTRUE;
03998         }
03999       else
04000         {
04001           cout << "!TEcnaRead::ReadLowFrequencyMeanCorrelationsBetweenStins(...) *** ERROR ***> Open .root file failed for file: "
04002                << file_name << fTTBELL << endl;
04003           allowed_to_read = kFALSE;
04004           ok_read = kFALSE;
04005         }
04006     }
04007 
04008   if( allowed_to_read == kTRUE )
04009     {
04010       Int_t i_zero = 0;
04011       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
04012       
04013       if( ok_read == kTRUE )
04014         {
04015           fDataExist = kTRUE;
04016           for(Int_t index_Stin_a = 0; index_Stin_a - MatDim < 0; index_Stin_a++)
04017             {
04018               for(Int_t index_Stin_b = 0; index_Stin_b - MatDim < 0; index_Stin_b++)   
04019                 {
04020                   if( vec(index_Stin_a) > 0 && vec(index_Stin_a) <= MatDim)
04021                     {
04022                       if( vec(index_Stin_b) > 0 && vec(index_Stin_b) <= MatDim)
04023                         {
04024                           Int_t vec_ia_m = (Int_t)vec(index_Stin_a)-1;
04025                           Int_t vec_ib_m = (Int_t)vec(index_Stin_b)-1;
04026                           mat((Int_t)vec_ia_m, vec_ib_m) =
04027                             gCnaRootFile->fCnaIndivResult->fMatMat(index_Stin_a,index_Stin_b);
04028                         }
04029                     }
04030                 }
04031             }
04032         } 
04033       else
04034         {
04035           fDataExist = kFALSE;
04036           cout << "!TEcnaRead::ReadLowFrequencyMeanCorrelationsBetweenStins() *** ERROR ***> "
04037                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
04038                << "                                                                          -> quantity: <"
04039                << GetTypeOfQuantity(typ) << "> not available in file."
04040                << fTTBELL << endl;
04041         }
04042       CloseRootFile(file_name);
04043     }
04044   return mat;
04045 }
04046 //-------- ( end of ReadLowFrequencyMeanCorrelationsBetweenStins) --------
04047 
04048 //-------------------------------------------------------------------------
04049 //
04050 //         ReadHighFrequencyMeanCorrelationsBetweenStins(...)
04051 //
04052 //-------------------------------------------------------------------------
04053 TMatrixD TEcnaRead::ReadHighFrequencyMeanCorrelationsBetweenStins(const Int_t& MatDim)
04054 {
04055 //Read all the High Frequency Mean Correlations Between Stins the for all (Stin_X, Stin_Y)
04056 //in ROOT file and return them in a TMatrixD
04057 //
04058 //Possible values for MatDim: (1) MatDim = fEcal->MaxStinEcnaInStex()
04059 
04060   TestArrayDimH2("ReadHighFrequencyMeanCorrelationsBetweenStins", "fEcal->MaxStinEcnaInStex()",
04061                  fEcal->MaxStinEcnaInStex(), MatDim);
04062 
04063   TMatrixD mat(MatDim, MatDim);
04064   for(Int_t i=0; i-MatDim<0; i++)
04065     {for(Int_t j=0; j-MatDim<0; j++){mat(i,j)=(Double_t)0.;}}
04066 
04067   TVectorD vec(fEcal->MaxStinEcnaInStex());
04068   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
04069   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
04070 
04071   CnaResultTyp typ = cTypHFccMoStins;
04072 
04073   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
04074   const Text_t *current_file_name = (const Text_t *)fCurrentlyOpenFileName.Data();
04075 
04076   Bool_t ok_open = kFALSE;
04077   Bool_t ok_read = kFALSE;
04078     
04079   TString FileNameLong = fCnaWrite->GetRootFileName();
04080   Bool_t allowed_to_read = kFALSE;
04081   
04082 //  if ( fOpenRootFile )
04083 //    {
04084 //      cout << "!TEcnaRead::ReadHighFrequencyMeanCorrelationsBetweenStins() *** ERROR ***>"
04085 //         << " Reading on file already open." << fTTBELL << endl;
04086 //    }
04087 
04088   if( FileNameLong == fCurrentlyOpenFileName )
04089     {
04090       allowed_to_read = kTRUE;
04091     }
04092   else
04093     {
04094       if( fCurrentlyOpenFileName != fFlagNoFileOpen ){CloseRootFile(current_file_name);}
04095       ok_open = OpenRootFile(file_name, "READ");
04096 
04097       if(ok_open)
04098         {
04099           allowed_to_read = kTRUE;
04100         }
04101       else
04102         {
04103           cout << "!TEcnaRead::ReadHighFrequencyMeanCorrelationsBetweenStins(...) *** ERROR ***> Open .root file failed for file: "
04104                << file_name << fTTBELL << endl;
04105           allowed_to_read = kFALSE;
04106           ok_read = kFALSE;
04107         }
04108     }
04109 
04110   if( allowed_to_read == kTRUE )
04111     {
04112       Int_t i_zero = 0;
04113       ok_read = gCnaRootFile->ReadElement(typ, i_zero);
04114       
04115       if( ok_read == kTRUE )
04116         {
04117           fDataExist = kTRUE;
04118           for(Int_t index_Stin_a = 0; index_Stin_a - MatDim<0; index_Stin_a++)
04119             {
04120               for(Int_t index_Stin_b = 0; index_Stin_b - MatDim<0; index_Stin_b++)   
04121                 {
04122                   if( vec(index_Stin_a) > 0 && vec(index_Stin_a) <= MatDim)
04123                     {
04124                       if( vec(index_Stin_b) > 0 && vec(index_Stin_b) <= MatDim)
04125                         {
04126                           Int_t vec_ia_m = (Int_t)vec(index_Stin_a)-1;
04127                           Int_t vec_ib_m = (Int_t)vec(index_Stin_b)-1;
04128                           mat((Int_t)vec_ia_m, (Int_t)vec_ib_m) =
04129                             gCnaRootFile->fCnaIndivResult->fMatMat(index_Stin_a,index_Stin_b);
04130                         }
04131                     }
04132                 }
04133             }
04134         } 
04135       else
04136         {
04137           fDataExist = kFALSE;
04138           cout << "!TEcnaRead::ReadHighFrequencyMeanCorrelationsBetweenStins() *** ERROR ***> "
04139                << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
04140                << "                                                                           -> quantity: <"
04141                << GetTypeOfQuantity(typ) << "> not available in file."
04142                << fTTBELL << endl;
04143         }
04144       CloseRootFile(file_name);
04145     }
04146   return mat;
04147 }
04148 //-------- ( end of ReadHighFrequencyMeanCorrelationsBetweenStins) --------
04149 
04150 //=============================================================================
04151 //
04152 //             M I S C E L L A N E O U S     R E A D      M E T H O D S
04153 //
04154 //=============================================================================
04155 
04156 //--------------------------------------------------------------------------------------
04157 //
04158 //       ReadSampleAdcValuesSameFile(fEcal->MaxCrysEcnaInStex(),
04159 //                                   fFileHeader->fNbOfSamples, fFileHeader->fReqNbOfEvts)  
04160 //
04161 //--------------------------------------------------------------------------------------
04162 Double_t*** TEcnaRead::ReadSampleAdcValuesSameFile(const Int_t& DimX, const Int_t& DimY, const Int_t& DimZ)
04163 {
04164 
04165 //Possible values for DimX, DimY, DimZ : (1) DimX = fEcal->MaxCrysEcnaInStex()
04166 //                                           DimY = fFileHeader->fNbOfSamples
04167 //                                           DimZ = fFileHeader->fReqNbOfEvts
04168 
04169   if(fT3d_AdcValues == 0)
04170     {
04171       //............ Allocation for the 3d array 
04172       fT3d_AdcValues   = new Double_t**[DimX];                         fCnew++;  
04173       fT3d2_AdcValues  = new  Double_t*[DimX*DimY];                    fCnew++;  
04174       fT3d1_AdcValues  = new   Double_t[DimX*DimY*DimZ];               fCnew++;
04175       
04176       for(Int_t i0StexEcha = 0 ; i0StexEcha < DimX ; i0StexEcha++){
04177         fT3d_AdcValues[i0StexEcha] = &fT3d2_AdcValues[0] + i0StexEcha*DimY;
04178         for(Int_t j_samp = 0 ; j_samp < DimY ; j_samp++){
04179           fT3d2_AdcValues[DimY*i0StexEcha + j_samp] = &fT3d1_AdcValues[0]+
04180             DimZ*(DimY*i0StexEcha+j_samp);}}
04181     }
04182   
04183   //................................. Init to zero                 (ReadSampleAdcValuesSameFile)
04184   for (Int_t iza=0; iza<DimX; iza++)
04185     {
04186       for (Int_t izb=0; izb<DimY; izb++)
04187         {
04188           for (Int_t izc=0; izc<DimZ; izc++)
04189             {
04190               if( fT3d_AdcValues[iza][izb][izc] != (Double_t)0 )
04191                 {
04192                   fT3d_AdcValues[iza][izb][izc] = (Double_t)0;
04193                 }
04194             }
04195         }
04196     }     
04197   
04198   //-------------------------------------------------------------------------- (ReadSampleAdcValuesSameFile)
04199   CnaResultTyp typ = cTypAdcEvt;   //  sample as a function of time type
04200 
04201   const Text_t *file_name = (const Text_t *)fCnaWrite->fRootFileNameShort.Data();
04202 
04203   Bool_t ok_open = kFALSE;
04204   Bool_t ok_read = kFALSE;
04205 
04206   Int_t  i_entry      = 0;  
04207   Int_t  i_entry_fail = 0;  
04208 
04209   ok_open = OpenRootFile(file_name, "READ");
04210   
04211   if( ok_open == kTRUE )
04212     {
04213       for(Int_t i0StexEcha=0; i0StexEcha<DimX; i0StexEcha++)
04214         {
04215           if( i0StexEcha == 0 )
04216             {
04217               i_entry = gCnaRootFile->ReadElementNextEntryNumber(typ, i0StexEcha);
04218               if( i_entry >= 0 ){ok_read = kTRUE;}
04219             }
04220           if( i_entry >= 0 )                                                //  (ReadSampleAdcValuesSameFile)
04221             {
04222               if( i0StexEcha > 0 ){ok_read = gCnaRootFile->ReadElement(i_entry); i_entry++;}
04223               
04224               if ( ok_read == kTRUE )
04225                 {
04226                   fDataExist = kTRUE;     
04227                   for(Int_t sample=0; sample<DimY; sample++)
04228                     {
04229                       for ( Int_t i_bin=0; i_bin<DimZ; i_bin++)
04230                         {
04231                           fT3d_AdcValues[i0StexEcha][sample][i_bin]
04232                             = gCnaRootFile->fCnaIndivResult->fMatHis(sample, i_bin);
04233                         }  
04234                     }
04235                 } 
04236               else                                                        //  (ReadSampleAdcValuesSameFile)
04237                 {
04238                   fDataExist = kFALSE;
04239                   cout << "!TEcnaRead::ReadSampleAdcValuesSameFile(...) *** ERROR ***> "
04240                        << fCnaWrite->fRootFileNameShort.Data() << ": .root file failed" << endl
04241                        << "                                                         -> quantity: <"
04242                        << GetTypeOfQuantity(typ) << "> not available in file."
04243                        << fTTBELL << endl;
04244                 }
04245             }
04246           else
04247             {
04248               i_entry_fail++;
04249             }
04250         }
04251       CloseRootFile(file_name);
04252     }
04253   else
04254     {
04255       cout  << "*TEcnaRead::ReadSampleAdcValuesSameFile(...)> *ERROR* =====> "
04256             << " ROOT file not found" << fTTBELL << endl;
04257     }
04258 
04259   if(i_entry_fail > 0 )
04260     {
04261       cout  << "*TEcnaRead::ReadSampleAdcValuesSameFile(...)> *ERROR* =====> "
04262             << " Entry reading failure(s). i_entry_fail = "
04263             << i_entry_fail << fTTBELL << endl;
04264     }
04265   return fT3d_AdcValues;
04266 }
04267 //--- (end of ReadSampleAdcValuesSameFile) ----------
04268 
04269 
04270 //=========================================================================
04271 //
04272 //          M I S C E L L A N E O U S    G E T    M E T H O D S   
04273 //
04274 //=========================================================================
04275 Int_t TEcnaRead::GetNumberOfEvents(const Int_t& xFapNbOfReqEvts, const Int_t& xStexNumber)
04276 {
04277   //...... Calculate the number of found events  (file existence already tested in calling method)
04278   Int_t xFapNbOfEvts = 0; 
04279 
04280   TVectorD NOFE_histp(fEcal->MaxCrysEcnaInStex());
04281   for(Int_t i=0; i<fEcal->MaxCrysEcnaInStex(); i++){NOFE_histp(i)=(Double_t)0.;}
04282   NOFE_histp = ReadNumberOfEvents(fEcal->MaxCrysEcnaInStex());
04283 
04284   //... Call to fCnaWrite->NumberOfEventsAnalysis(...) 1rst argument must be Int_t, not TVectorD,
04285   //    duplicate NOFE_histp to NOFE_int to obtain fFapNbOfEvts from fCnaWrite->NumberOfEventsAnalysis(...)
04286   Int_t* NOFE_int = new Int_t[fEcal->MaxCrysEcnaInStex()];   fCnew++;
04287   for(Int_t i=0; i<fEcal->MaxCrysEcnaInStex(); i++){NOFE_int[i]=(Int_t)NOFE_histp(i);}
04288 
04289   xFapNbOfEvts =
04290     fCnaWrite->NumberOfEventsAnalysis(NOFE_int, fEcal->MaxCrysEcnaInStex(), xFapNbOfReqEvts, xStexNumber);
04291 
04292   delete [] NOFE_int; NOFE_int = 0;                          fCdelete++;
04293 
04294   return xFapNbOfEvts;
04295 }
04296 
04297 //-------------------------------------------------------------------------
04298 //
04299 //    Get the name of the quantity from its "CnaResultTyp" type
04300 //
04301 //-------------------------------------------------------------------------
04302 TString TEcnaRead::GetTypeOfQuantity(const CnaResultTyp arg_typ)
04303 {
04304   TString quantity_name = "?";
04305 
04306   if( arg_typ == cTypNumbers)
04307     {
04308       if( fFlagSubDet == "EB" ){quantity_name = "SM numbers";}
04309       if( fFlagSubDet == "EE" ){quantity_name = "Dee numbers";}
04310     }
04311   if( arg_typ == cTypMSp    ){quantity_name = "Mean samples";}
04312   if( arg_typ == cTypSSp    ){quantity_name = "Sigma of samples";}
04313 
04314   if( arg_typ == cTypNbOfEvts ){quantity_name = "Number of events";}
04315   if( arg_typ == cTypPed      ){quantity_name = "Pedestals";}
04316   if( arg_typ == cTypTno      ){quantity_name = "Total noise";}
04317   if( arg_typ == cTypLfn      ){quantity_name = "LF noise";}
04318   if( arg_typ == cTypHfn      ){quantity_name = "HF noise";}
04319   if( arg_typ == cTypMeanCorss){quantity_name = "Mean cor(s,s')";}
04320   if( arg_typ == cTypSigCorss ){quantity_name = "Sigma of cor(s,s')";}
04321 
04322   if( arg_typ == cTypAvPed      ){quantity_name = "Average pedestals";}
04323   if( arg_typ == cTypAvTno      ){quantity_name = "Average total noise";}
04324   if( arg_typ == cTypAvLfn      ){quantity_name = "Average LF noise";}
04325   if( arg_typ == cTypAvHfn      ){quantity_name = "Average HF noise";}
04326   if( arg_typ == cTypAvMeanCorss){quantity_name = "Average mean cor(s,s')";}
04327   if( arg_typ == cTypAvSigCorss ){quantity_name = "Average sigma of cor(s,s')";}
04328 
04329   if( arg_typ == cTypAdcEvt ){quantity_name = "Sample ADC a.f.o event number";}
04330 
04331   if( arg_typ == cTypCovCss ){quantity_name = "Cov(s,s')";}
04332   if( arg_typ == cTypCorCss ){quantity_name = "Cor(s,s')";}
04333   if( arg_typ == cTypLfCov  ){quantity_name = "LF Cov(c,c')";}
04334   if( arg_typ == cTypLfCor  ){quantity_name = "LF Cor(c,c')";}
04335   if( arg_typ == cTypHfCov  ){quantity_name = "HF Cov(c,c')";}
04336   if( arg_typ == cTypHfCor  ){quantity_name = "HF Cor(c,c')";}
04337 
04338   if( fFlagSubDet == "EB" )
04339     {
04340       if( arg_typ == cTypLFccMoStins){quantity_name = "Mean LF |Cor(c,c')| in (tow,tow')";}
04341       if( arg_typ == cTypHFccMoStins){quantity_name = "Mean HF |Cor(c,c')| in (tow,tow')";}
04342     }
04343   if( fFlagSubDet == "EE" )
04344     {
04345       if( arg_typ == cTypLFccMoStins){quantity_name = "Mean LF |Cor(c,c')| in (SC,SC')";}
04346       if( arg_typ == cTypHFccMoStins){quantity_name = "Mean HF |Cor(c,c')| in (SC,SC')";}
04347     }
04348   return quantity_name;
04349 }
04350 
04351 //-------------------------------------------------------------------------
04352 //
04353 //    Get the ROOT file name (long and short)
04354 //
04355 //-------------------------------------------------------------------------
04356 TString TEcnaRead::GetRootFileName(){return fCnaWrite->GetRootFileName();}
04357 TString TEcnaRead::GetRootFileNameShort(){return fCnaWrite->GetRootFileNameShort();}
04358 //-------------------------------------------------------------------------
04359 //
04360 //                     GetStexStinFromIndex
04361 //
04362 //  *==> DON'T SUPPRESS: this method is called by TEcnaRun and TEcnaHistos
04363 //
04364 //-------------------------------------------------------------------------
04365 Int_t TEcnaRead::GetStexStinFromIndex(const Int_t& i0StexStinEcna)
04366 {
04367 // Get the Stin number in Stex from the Stin index
04368 
04369   Int_t number = -1;
04370   TVectorD vec(fEcal->MaxStinEcnaInStex());
04371   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
04372   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
04373   number = (Int_t)vec(i0StexStinEcna);
04374   return number;
04375 }
04376 
04377 //------------------------------------------------------------------------
04378 
04379 Int_t  TEcnaRead::GetNumberOfBinsSampleAsFunctionOfTime(){return GetReqNbOfEvts();}
04380 //-------------------------------------------------------------------------
04381 //
04382 //                     GetStinIndex(n1StexStin)
04383 //
04384 //-------------------------------------------------------------------------
04385 Int_t  TEcnaRead::GetStinIndex(const Int_t & n1StexStin)
04386 {
04387 //Get the index of the Stin from its number in Stex
04388 
04389   if(fFlagPrint == fCodePrintAllComments){
04390     cout << "*TEcnaRead::GetStinIndex(...)> fEcal->MaxStinEcnaInStex() = "
04391          << fEcal->MaxStinEcnaInStex() << endl
04392          << "                              n1StexStin = " << n1StexStin
04393          << endl << endl;}
04394 
04395   Int_t Stin_index = n1StexStin-1;    // suppose les 68 tours 
04396 
04397 #define NOGT
04398 #ifndef NOGT
04399   Int_t Stin_index = -1;
04400   TVectorD vec(fEcal->MaxStinEcnaInStex());
04401   for(Int_t i=0; i<fEcal->MaxStinEcnaInStex(); i++){vec(i)=(Double_t)0.;}
04402   vec = ReadStinNumbers(fEcal->MaxStinEcnaInStex());
04403 
04404   //........................... Get the Stin index
04405 
04406   for(Int_t i=0; i < fEcal->MaxStinEcnaInStex(); i++)
04407     {
04408       if(fFlagPrint == fCodePrintAllComments){
04409         cout << "*TEcnaRead::GetStinIndex(...)> StinNumber[" << i << "] = "
04410              << vec[i] << endl;}
04411       if ( vec[i] == n1StexStin ){Stin_index = i;}
04412     }
04413 
04414   if(fFlagPrint == fCodePrintAllComments){
04415     cout << "~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-" << endl;
04416     cout << "*TEcnaRead::GetStinIndex> Stin number: " << n1StexStin  << endl
04417          << "                          Stin index : " << Stin_index << endl;
04418     cout << "~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-" << endl;}
04419 
04420   if ( Stin_index < 0 )
04421     {
04422       if(fFlagPrint == fCodePrintAllComments){
04423         cout << "!TEcnaRead::GetStinIndex *** WARNING ***> n1StexStin" << n1StexStin << " : "
04424              << "index Stin not found"
04425              << fTTBELL << endl;}
04426     }
04427 #endif // NOGT
04428 
04429   return Stin_index;
04430 }
04431 
04432 //=========================================================================
04433 //
04434 //         METHODS TO SET FLAGS TO PRINT (OR NOT) COMMENTS (DEBUG)
04435 //
04436 //=========================================================================
04437 
04438 void  TEcnaRead::PrintComments()
04439 {
04440 // Set flags to authorize printing of some comments concerning initialisations (default)
04441 
04442   fFlagPrint = fCodePrintComments;
04443   cout << "*TEcnaRead::PrintComments()> Warnings and some comments on init will be printed" << endl;
04444 }
04445 
04446 void  TEcnaRead::PrintWarnings()
04447 {
04448 // Set flags to authorize printing of warnings
04449 
04450   fFlagPrint = fCodePrintWarnings;
04451   cout << "*TEcnaRead::PrintWarnings()> Warnings will be printed" << endl;
04452 }
04453 
04454 void  TEcnaRead::PrintAllComments()
04455 {
04456 // Set flags to authorize printing of the comments of all the methods
04457 
04458   fFlagPrint = fCodePrintAllComments;
04459   cout << "*TEcnaRead::PrintAllComments()> All the comments will be printed" << endl;
04460 }
04461 
04462 void  TEcnaRead::PrintNoComment()
04463 {
04464 // Set flags to forbid the printing of all the comments
04465 
04466   fFlagPrint = fCodePrintNoComment;
04467 }