CMS 3D CMS Logo

TCnaRunEB.cc

Go to the documentation of this file.
00001 //----------Author's Names: B.Fabbro, FX Gentit DSM/DAPNIA/SPP CEA-Saclay
00002 //---------Copyright: Those valid for CEA sofware
00003 //----------Modified: 08/06/2007
00004 // ROOT include files
00005 
00006 // user's include files
00007 
00008 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEBParameters.h"
00009 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEBNumbering.h"
00010 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TCnaParameters.h"
00011 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TCnaRunEB.h"
00012 #include <math.h>
00013 
00014 R__EXTERN TCnaRootFile *gCnaRootFile;
00015 
00016 ClassImp(TCnaRunEB)
00017 //___________________________________________________________________________
00018 //
00019 // TCnaRunEB + instructions for use of the CNA (Correlated Noise Analysis)
00020 //             in the framework of CMSSW.
00021 //
00022 //==============> INTRODUCTION
00023 //
00024 //    The present documentation contains:
00025 //
00026 //    [1] a brief description of the CNA package and instructions for use
00027 //        this package in the framework of the CMS Software
00028 //
00029 //    [2] the documentation for the class TCnaRunEB
00030 //
00031 //
00032 //==[1]=====================================================================================
00033 //
00034 //
00035 //         DOCUMENTATION FOR THE INTERFACE: CNA package / CMSSW / SCRAM
00036 //
00037 //
00038 //==========================================================================================
00039 //
00040 //  The CNA software consists in 2 packages named: EcalCorrelatedNoiseAnalysisModules and
00041 //  EcalCorrelatedNoiseAnalysisAlgos.
00042 //
00043 //  The directory tree is the following:
00044 //
00045 //      <local path>/CMSSW_a_b_c/src/----CalibCalorimetry/---EcalCorrelatedNoiseAnalysisModules/BuildFile
00046 //                              |   |                    |                                     |---interface/
00047 //                              |   |                    |                                     |---src/
00048 //                                  |                    |                                     |---data/
00049 //                                  |                    |
00050 //                                  |                    |---EcalCorrelatedNoiseAnalysisAlgos/BuildFile
00051 //                                  |                    |                                   |---interface/
00052 //                                  |                    |                                   |---src/
00053 //                                  |                    |                                   |---test/
00054 //                                  |                    |
00055 //                                  |                    |
00056 //                                  |                    \--- <other packages of CalibCalorimetry> 
00057 //                                  |
00058 //                                  \----<other subsystems...>
00059 //
00060 //
00061 //    The package EcalCorrelatedNoiseAnalysisModules contains one analyzer
00062 //    (EcalCorrelatedNoisePedestalRunAnalyzer). The user has to edit
00063 //    this analyzer. A detailed description is given here after in the class TCnaRunEB
00064 //    documentation. An analyzer skeleton can be obtained by means of the
00065 //    SkeletonCodeGenerator "mkedanlzr" (see the CMSSW Framework/Edm web page).
00066 //
00067 //    The package EcalCorrelatedNoiseAnalysisAlgos contains the basic classes of the CNA 
00068 //    (in src and interface) and two executables (in directory test):
00069 //
00070 //    1) EcalCorrelatedNoiseExample:  a simple example using the class TCnaViewEB
00071 //
00072 //    2) InteractiveCNAForEcalBarrel: a GUI dialog box with buttons, menus...
00073 //       This program uses the classes TCnaDialogEB and  TCnaViewEB.
00074 //       See the documentation of these classes for more details.
00075 //
00076 // 
00077 //==[2]======================================================================================
00078 //
00079 //
00080 //                         DOCUMENTATION FOR THE CLASS TCnaRunEB
00081 //
00082 //
00083 //===========================================================================================
00084 //TCnaRunEB.
00085 //
00086 //
00087 //
00088 //================> Brief and general description
00089 //                  -----------------------------
00090 //
00091 //   This class allows the user to calculate expectation values, variances,
00092 //   covariances, correlations and other quantities of interest for correlated
00093 //   noise studies on the CMS/ECAL BARREL (EB).
00094 //
00095 //   Three main operations are performed by the class TCnaRunEB. Each of them is
00096 //   associated with a specific method of the analyzer EcalCorrelatedNoisePedestalRunAnalyzer:
00097 //
00098 //    (1) Initialization and calls to "preparation methods" of the CNA.
00099 //        This task is done in the constructor of the analyzer:
00100 //        EcalCorrelatedNoiseAnalysisModules::EcalCorrelatedNoisePedestalRunAnalyzer
00101 //                                                          (const edm::ParameterSet& pSet)
00102 //
00103 //    (2) Building of the event distributions (distributions of the ADC
00104 //        values for each sample, each channel, etc...)
00105 //        This task is done in the method "analyze" of the analyzer:
00106 //        EcalCorrelatedNoisePedestalRunAnalyzer::analyze
00107 //                                     (const edm::Event& iEvent, const edm::EventSetup& iSetup)
00108 //
00109 //    (3) Calculation of the different quantities (correlations, covariances, etc...)
00110 //        from the distributions obtained in (2) and writing of these quantities
00111 //        in results ROOT files and also in ASCII files.
00112 //        This task is done in the destructor of the analyzer:
00113 //        EcalCorrelatedNoisePedestalRunAnalyzer::~EcalCorrelatedNoisePedestalRunAnalyzer()
00114 //   
00115 //
00116 //========> Use of the class TCnaRunEB by the analyzer EcalCorrelatedNoisePedestalRunAnalyzer
00117 //          ---------------------------------------------------------------------------------
00118 //
00119 //     In the following, the parts of the code concerning TCnaRunEB
00120 //     are emphasized by special comments with strings: "###############"
00121 //
00122 //     +-----------------------------------------------------------------+
00123 //     |                                                                 |
00124 //     |  (0) The class EcalCorrelatedNoisePedestalRunAnalyzer.          |
00125 //     |      Example of EcalCorrelatedNoisePedestalRunAnalyzer.h file:  |
00126 //     |                                                                 |
00127 //     +-----------------------------------------------------------------+
00128 //
00129 //     #ifndef CNASUB_RUNEVT_H
00130 //     #define CNASUB_RUNEVT_H
00131 //     
00132 //     // -*- C++ -*-
00133 //     //
00134 //     // Package:    EcalCorrelatedNoisePedestalRunAnalyzer
00135 //     // Class:      EcalCorrelatedNoisePedestalRunAnalyzer
00136 //     // 
00137 //     /**\class EcalCorrelatedNoisePedestalRunAnalyzer
00138 //               EcalCorrelatedNoisePedestalRunAnalyzer.cc
00139 //               CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/src/EcalCorrelatedNoisePedestalRunAnalyzer.cc
00140 //     
00141 //      Description: <one line class summary>
00142 //     
00143 //      Implementation:
00144 //          <Notes on implementation>
00145 //     */
00146 //     //
00147 //     // Original Author:  Bernard Fabbro
00148 //     //         Created:  Fri Jun  2 10:27:01 CEST 2006
00149 //     // $Id: TCnaRunEB.cc,v 1.3 2007/12/31 09:19:05 elmer Exp $
00150 //     //
00151 //     //
00152 //     
00153 //     // system include files
00154 //     #include <memory>
00155 //     #include <iostream>
00156 //     #include <fstream>
00157 //     #include <iomanip>
00158 //     #include <string>
00159 //     #include <vector>
00160 //     #include <time.h>
00161 //     #include "Riostream.h"
00162 //     
00163 //     // ROOT include files
00164 //     #include "TObject.h"
00165 //     #include "TSystem.h"
00166 //     #include "TString.h"
00167 //     #include "TVectorD.h"
00168 //     
00169 //     // user include files
00170 //     //################ include of TCnaRunEB.h #################
00171 //     #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TCnaRunEB.h"
00172 //     
00173 //     //
00174 //     // class declaration
00175 //     //
00176 //     
00177 //     class EcalCorrelatedNoisePedestalRunAnalyzer: public edm::EDAnalyzer {
00178 //     
00179 //      public:
00180 //      
00181 //       enum { kChannels = 1700, kGains = 3, kFirstGainId = 1 };
00182 //
00183 //       // CONSTRUCTOR             
00184 //       explicit EcalCorrelatedNoisePedestalRunAnalyzer(const edm::ParameterSet&);
00185 // 
00186 //       // DESTRUCTOR       
00187 //       ~EcalCorrelatedNoisePedestalRunAnalyzer();  
00188 //       
00189 //       // "analyze" METHOD   
00190 //       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00191 //    
00192 //     
00193 //      private:
00194 //       // ----------member data ---------------------------
00195 //       unsigned int verbosity_;
00196 //       Int_t    nChannels_;
00197 //       Int_t    iEvent_;
00198 //     
00199 //       Int_t    fEvtNumber;
00200 //     
00201 //       //############### DECLARATION of the TCnaRunEB OBJECT: fMyCnaRun #################
00202 //       TCnaRunEB*       fMyCnaRun; 
00203 //
00204 //       TEBNumbering* fMyCnaNumbering; // another object used to recover some quantities
00205 //                                      // related to the channel numbers, crystal numbers, etc...
00206 //     };
00207 //     
00208 //     #endif
00209 //     
00210 //
00211 //     +----------------------------------------------------------------------------+
00212 //     |                                                                            |
00213 //     |  (1) EXAMPLE OF CONSTRUCTOR                                                |
00214 //     |      EcalCorrelatedNoisePedestalRunAnalyzer::                              |
00215 //     |      EcalCorrelatedNoisePedestalRunAnalyzer(const edm::ParameterSet& pSet) |
00216 //     |                                                                            |
00217 //     +----------------------------------------------------------------------------+
00218 //
00219 //     // -*- C++ -*-
00220 //     //
00221 //     // Package:    EcalCorrelatedNoiseAnalysisModules
00222 //     // Class:      EcalCorrelatedNoisePedestalRunAnalyzer
00223 //     // 
00224 //     /**\class EcalCorrelatedNoisePedestalRunAnalyzer
00225 //               EcalCorrelatedNoisePedestalRunAnalyzer.cc
00226 //               CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/src/EcalCorrelatedNoisePedestalRunAnalyzer.cc
00227 //     
00228 //      Description: <one line class summary>
00229 //     
00230 //     Implementation:
00231 //         <Notes on implementation>
00232 //     */
00233 //
00234 //     // Original Author:  Bernard Fabbro
00235 //     //         Created:  Fri Jun  2 10:27:01 CEST 2006
00236 //     // $Id: TCnaRunEB.cc,v 1.3 2007/12/31 09:19:05 elmer Exp $
00237 //     //
00238 //     //          Update:  02/10/2006  
00239 //     
00240 //     // CMSSW include files
00241 //     
00242 //     #include "Riostream.h"
00243 //     
00244 //     #include "FWCore/Framework/interface/EDAnalyzer.h"
00245 //     #include "FWCore/Framework/interface/Event.h"
00246 //     #include "FWCore/Framework/interface/Handle.h"
00247 //     
00248 //     #include "FWCore/Framework/interface/Frameworkfwd.h"
00249 //     #include "FWCore/ParameterSet/interface/ParameterSet.h"
00250 //     
00251 //     #include "DataFormats/EcalDigi/interface/EBDataFrame.h"
00252 //     #include "DataFormats/EcalDigi/interface/EcalMGPASample.h"
00253 //     #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00254 //     
00255 //     #include "DataFormats/Common/interface/EventID.h"
00256 //     
00257 //     //################## include of EcalCorrelatedNoisePedestalRunAnalyzer.h ##############
00258 //     #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/interface/EcalCorrelatedNoisePedestalRunAnalyzer.h"
00259 //     
00260 //     // constants, enums and typedefs
00261 //
00262 //     // static data member definitions
00263 //
00264 //     //
00265 //     // constructors
00266 //     //
00267 //
00268 //     EcalCorrelatedNoisePedestalRunAnalyzer::EcalCorrelatedNoisePedestalRunAnalyzer(const edm::ParameterSet& pSet) : 
00269 //       verbosity_(pSet.getUntrackedParameter("verbosity", 1U)),
00270 //       nChannels_(0), iEvent_(0)
00271 //     {
00272 //       //now do what ever initialization is needed
00273 //     
00274 //       using namespace edm;       
00275 //
00276 //       fEvtNumber=0;
00277 //     
00278 //     //#################################################################################
00279 //     //
00280 //     //                          INIT OF the C.N.A.
00281 //     //
00282 //     // First of all, you have to declare fMyCnaRun as an object of the class TCnaRunEB.
00283 //     // This declaration is done by calling the constructor without argument:
00284 //     //#################################################################################
00285 //
00286 //       fMyCnaRun = new TCnaRunEB();
00287 //       fMyCnaRun->PrintComments();  // => optional
00288 //     
00289 //     //##########################################################################
00290 //     // Hence, you have to call the preparation method: "GetReadyToReadData"
00291 //     // This methods needs some arguments.
00292 //     //##########################################################################
00293 //
00294 //       TString AnalysisName    = "cosmics"
00295 //       Int_t   RunNumber       = 22770;
00296 //       Int_t   FirstTakenEvt   = 300;   
00297 //       Int_t   NbOfTakenEvents = 150; // 150 = nb of events in one burst (1 burst = 1 gain)    
00298 //       Int_t   SuperModule     = 22;
00299 //       Int_t   Nentries        = 3*NbOfTakenEvents;       //  3 bursts of 150 events   
00300 //
00301 //
00302 //       MyCnaRun->GetReadyToReadData(AnalysisName,   RunNumber,
00303 //                                    FirstTakenEvt,  NbOfTakenEvents,
00304 //                                    SuperModule,    Nentries);
00305 //
00306 //  * Remark:
00307 //
00308 //       The argument Nentries is used to check that Nentries-FirstTakenEvt is positive.
00309 //       You can call the method without this argument (then default value = 9999999 is used):
00310 //
00311 //       MyCnaRun->GetReadyToReadData(AnalysisName,   RunNumber,
00312 //                                    FirstTakenEvt,  NbOfTakenEvents,
00313 //                                    SuperModule);
00314 //    
00315 //  ! IMPORTANT REMARK ====> In pedestal runs, the number of taken events must not be larger
00316 //                           than the number of events by burst (NBURST = 150).
00317 //                            > 1rst burst: gain  1, event   0 to 149 (       0 to   NBURST-1)
00318 //                            > 2nd  burst: gain  6, event 150 to 299 (  NBURST to 2*NBURST-1)
00319 //                            > 3rd  burst: gain 12. event 300 to 449 (2*NBURST to 3*NBURST-1)
00320 //                           There is a change of gain every NBURST events during a pedestal run.
00321 //                           Therefore, if the calculations are done on more than NBURST events, you
00322 //                           will find very strong correlations because of an artificial effect due
00323 //                           to of the change of gain.
00324 //        
00325 //       fMyCnaNumbering = new TEBNumbering();    // just to recover tower number in SM
00326 //                                                   and channel number in tower in the
00327 //                                                   method "analyze"
00328 //     }
00329 //
00330 //     +-------------------------------------------------------------------------------+
00331 //     |                                                                               |
00332 //     |  (2) EXAMPLE OF METHOD "analyze"                                              |
00333 //     |      EcalCorrelatedNoisePedestalRunAnalyzer::                                 |
00334 //     |              analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) |
00335 //     |                                                                               |
00336 //     +-------------------------------------------------------------------------------+
00337 //
00338 //     void EcalCorrelatedNoisePedestalRunAnalyzer::
00339 //                                analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00340 //     {
00341 //        using namespace std;
00342 //        using namespace edm;
00343 //     
00344 //        edm::Handle<EBDigiCollection> digis;
00345 //        iEvent.getByLabel("ecalEBunpacker", digis);
00346 //     
00347 //       // Initialize vectors if not already done
00348 //       if ( int(digis->size()) > nChannels_ )
00349 //         {
00350 //           nChannels_ = digis->size();
00351 //         }
00352 //       
00353 //       if( fEvtNumber >= fMyCnaRun->GetFirstTakenEvent() )
00354 //         { 
00355 //           Int_t TakenEventNumber = fEvtNumber - fMyCnaRun->GetFirstTakenEvent();
00356 //           
00357 //           if( Int_t(digis->end()-digis->begin()) >= 0 ||
00358 //               Int_t(digis->end()-digis->begin()) <  Int_t(digis->size()) )
00359 //             {
00360 //             // Loop over Ecal barrel digis
00361 //             for (EBDigiCollection::const_iterator digiItr = digis->begin(); 
00362 //                 digiItr != digis->end(); ++digiItr) 
00363 //                  {
00364 //                    Int_t iChannel = Int_t(digiItr - digis->begin());     
00365 //                    Int_t iSMCrys  = iChannel + 1;
00366 //                    Int_t smTower  = fMyCnaNumbering->GetSMTowFromSMCrys(iSMCrys);
00367 //                    Int_t iTowEcha = fMyCnaNumbering->GetTowEchaFromSMCrys(iSMCrys);
00368 //                    
00369 //                    Int_t nSample = digiItr->size();
00370 //
00371 //                    // Loop over the samples
00372 //                    for (Int_t iSample = 0; iSample < nSample; ++iSample)
00373 //                      {
00374 //                        Double_t adc = Double_t((*digiItr).sample(iSample).adc());
00375 //
00376 //                        //####################################################
00377 //                        //
00378 //                        //    CALL TO THE METHOD "BuildEventDistributions"
00379 //                        //
00380 //                        //####################################################
00381 //
00382 //                        fMyCnaRun->BuildEventDistributions
00383 //                                     (TakenEventNumber,SMTower,iTowEcha,iSample,adc);
00384 //                    }
00385 //                }
00386 //             }      
00387 //         }
00388 //           
00389 //       fEvtNumber++;
00390 //       iEvent_++;
00391 //     }
00392 //
00393 //     +---------------------------------------------------------+
00394 //     |                                                         |
00395 //     |  (3) EXAMPLE OF DESTRUCTOR                              |
00396 //     |      EcalCorrelatedNoisePedestalRunAnalyzer::           |
00397 //     |            ~EcalCorrelatedNoisePedestalRunAnalyzer()    |
00398 //     |                                                         |
00399 //     +---------------------------------------------------------+
00400 //
00401 //     EcalCorrelatedNoisePedestalRunAnalyzer::~EcalCorrelatedNoisePedestalRunAnalyzer()
00402 //     {
00403 //        // do anything here that needs to be done at destruction time
00404 //        // (e.g. close files, deallocate resources etc.)
00405 // 
00406 //     //##########> CALL TO THE METHOD: GetReadyToCompute() (MANDATORY)   
00407 //       fMyCnaRun->GetReadyToCompute();
00408 //     
00409 //     //##########> CALLS TO METHODS WHICH COMPUTES THE QUANTITIES. EXAMPLES:
00410 //       fMyCnaRun->ComputeExpectationValuesOfSamples();
00411 //       fMyCnaRun->ComputeVariancesOfSamples();
00412 //       fMyCnaRun->ComputeCorrelationsBetweenSamples();
00413 //     
00414 //       fMyCnaRun->ComputeExpectationValuesOfExpectationValuesOfSamples();
00415 //       fMyCnaRun->ComputeExpectationValuesOfSigmasOfSamples();
00416 //       fMyCnaRun->ComputeExpectationValuesOfCorrelationsBetweenSamples();
00417 // 
00418 //     // etc...  
00419 //
00420 //     //##########> CALLS TO THE METHODS FOR WRITING THE RESULTS IN THE ROOT FILE:    
00421 //
00422 //       fMyCnaRun->GetPathForResultsRootFiles();
00423 //     
00424 //       if(fMyCnaRun->WriteRootFile() == kTRUE )
00425 //        {
00426 //           cout << "*EcalCorrelatedNoisePedestalRunAnalyzer> Write ROOT file OK" << endl;
00427 //         }
00428 //       else 
00429 //         {
00430 //           cout << "!EcalCorrelatedNoisePedestalRunAnalyzer> PROBLEM with write ROOT file." << endl;
00431 //         }
00432 //     
00433 //       delete fMyCnaRun;
00434 //       delete fMyCnaNumbering;
00435 //     }
00436 //
00437 //
00438 //
00439 //================> More detailled description of the class TCnaRunEB
00440 //                  -----------------------------------------------
00441 //
00442 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
00443 //
00444 //                     Declaration and Print Methods
00445 //
00446 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
00447 //
00448 //     Just after the declaration with the constructor without arguments,
00449 //     you can set a "Print Flag" by means of the following "Print Methods":
00450 //
00451 //     TCnaRunEB* MyCnaRun = new TCnaRunEB(); // declaration of the object MyCnaRun
00452 //
00453 //    // Print Methods: 
00454 //
00455 //    MyCnaRun->PrintNoComment();  // Set flag to forbid printing of all the comments
00456 //                                 // except ERRORS.
00457 //
00458 //    MyCnaRun->PrintWarnings();   // (DEFAULT)
00459 //                                 // Set flag to authorize printing of some warnings.
00460 //                                 // WARNING/INFO: information on something unusual
00461 //                                 // in the data is pointed out.
00462 //                                 // WARNING/CORRECTION: something wrong (but not too serious)
00463 //                                 // in the value of some argument is pointed out and
00464 //                                 // automatically modified to a correct value.
00465 //
00466 //   MyCnaRun->PrintComments();    // Set flag to authorize printing of infos
00467 //                                 // and some comments concerning initialisations
00468 //
00469 //   MyCnaRun->PrintAllComments(); // Set flag to authorize printing of all the comments
00470 //
00471 //
00472 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
00473 //
00474 //           Method GetReadyToReadData(...) and associated methods
00475 //
00476 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
00477 //
00478 //      MyCnaRun->GetReadyToReadData(AnalysisName,      RunNumber,
00479 //                    FirstTakenEvt, NbOfTakenEvents,   SuperModule,   Nentries);
00480 //
00481 //
00482 //   Explanations for the arguments (all of them are input arguments):
00483 //
00484 //      TString  AnalysisName: code for the analysis. This code is
00485 //                             necessary to distinguish between different
00486 //                             analyses on the same events of a same run.
00487 //                             
00488 //                             The string ana_name is automatically
00489 //                             included in the name of the results files
00490 //                             (see below: ROOT and ASCII results files paragraph)
00491 //
00492 //      Int_t     RunNumber:        run number
00493 //
00494 //      Int_t     FirstTakenEvent:  first taken event
00495 //      Int_t     NbOfTakenEvents:  number of taken events
00496 //      Int_t     SuperModule:      super-module number
00497 //      
00498 //        The different quantities (correlations, etc...) will be calculated
00499 //        from the event numbered: FirstTakenEvent
00500 //        to the event numbered:   FirstTakenEvent + NbOfTakenEvents - 1.
00501 //
00502 //      Int_t    Nentries:     number of entries of the run
00503 //
00504 //==============> Method to set the start and stop times of the analysis (optional)
00505 //
00506 //  A method can be used to set the fStartDate and fStopDate attributes
00507 //  of the class TCnaHeaderEB from start and stop time given by the user provided
00508 //  these values have been recovered from the event reading:
00509 //
00510 //      void  MyCnaRun->StartStopDate(TString StartDate, TString StopDate);
00511 // 
00512 //     // TString StartDate, StopDate:  start and stop time of the run
00513 //     //                               in "date" format. Example: 
00514 //     //                               Wed Oct  8 04:14:23 2003
00515 //
00516 //     If the method is not called, the values of the attributes
00517 //     fStartDate and fStopDate are set to: "no info" at the level of
00518 //     the Init() method of the class TCnaHeaderEB.
00519 //     The values of StartDate and StopDate are writen in the header of
00520 //     the .root result file.
00521 //
00522 //
00523 //  Another similar method exists, with time_t type arguments:
00524 //
00525 //     void  MyCnaRun->StartStopTime(time_t  StartTime, time_t  StopTime);
00526 //
00527 //
00528 //
00529 //==============> CALCULATION METHODS
00530 //
00531 //    The "calculation methods" are methods which compute the different
00532 //    quantities of interest. 
00533 //
00534 //    List of the calculation methods (still in evolution):
00535 //          
00536 //  void  ComputeExpectationValuesOfSamples(); // expectation values of the samples
00537 //                                             // for all the channels
00538 //
00539 //  void  ComputeVariancesOfSamples();         // variances of the samples
00540 //                                             // for all the channels
00541 //
00542 //  void  MakeHistosOfSampleDistributions();   // Making of the histos of the ADC distributions
00543 //                                             // for all the samples and all the channels
00544 //
00545 //  void  MakeHistosOfSamplesAsFunctionOfEvent(); // Histogram making of the sample ADC value as a function
00546 //                                                // of the event for all the pairs (channel,sample)
00547 //
00548 //  void  ComputeCovariancesBetweenSamples();                  // Cov(s,s) for all the channels 
00549 //  void  ComputeCorrelationsBetweenSamples();                 // Cor(s,s) for all the channels
00550 //
00551 //  void  ComputeCovariancesBetweenChannelsMeanOverSamples();  // Cov(c,c) for all the samples
00552 //  void  ComputeCorrelationsBetweenChannelsMeanOverSamples(); // Cor(c,c) for all the samples 
00553 //
00554 //  void  ComputeCovariancesBetweenTowersMeanOverSamplesAndChannels();
00555 //        // Calculation of the cov(channel,channel) averaged over the samples and
00556 //        // calculation of the mean of these cov(channel,channel) for all the towers
00557 //
00558 //  void  ComputeCorrelationsBetweenTowersMeanOverSamplesAndChannels();
00559 //        // Calculation of the cor(channel,channel) averaged over the samples and
00560 //        // calculation of the mean of these cor(channel,channel) for all the towers
00561 //
00562 //  void  ComputeExpectationValuesOfExpectationValuesOfSamples(); 
00563 //        // Calc. of the exp.val. of the exp.val. of the samples for all the channels
00564 //  void  ComputeExpectationValuesOfSigmasOfSamples(); 
00565 //        // Calc. of the exp.val. of the sigmas of the samples for all the channels
00566 //  void  ComputeExpectationValuesOfCorrelationsBetweenSamples(); 
00567 //        // Calc. of the exp.val. of the (sample,sample) correlations for all the channels
00568 //
00569 //  void  ComputeSigmasOfExpectationValuesOfSamples();
00570 //        // Calc. of the sigmas of the exp.val. of the samples for all the channels
00571 //  void  ComputeSigmasOfSigmasOfSamples();
00572 //        // Calc. of the sigmas of the of the sigmas of the samples for all the channels
00573 //  void  ComputeSigmasOfCorrelationsBetweenSamples();
00574 //        // Calc. of the sigmas of the (sample,sample) correlations for all the channels
00575 //
00576 //==============> RESULTS FILES
00577 //
00578 //  The calculation methods above provide results which can be used directly
00579 //  in the user's code. However, these results can also be written in results
00580 //  files by appropriate methods. In TCnaRunEB, there are such methods which
00581 //  write the results according to two options:
00582 //
00583 //   (a) writting in a ROOT file
00584 //   (b) writting in ASCII files
00585 //
00586 //  The names of the results files are automaticaly generated by the methods.
00587 //
00588 //  In the following, we describe:
00589 //
00590 //     (a1) The method which gets the path for the results ROOT file
00591 //          from a "cna-configuration" file
00592 //     (a2) The codification for the name of the ROOT file
00593 //     (a3) The method which writes the results in the ROOT file
00594 //
00595 //     (b1) The method which gets the path for the results ASCII files
00596 //          from a "cna-configuration" file
00597 //     (b2) The codification for the names of the ASCII files
00598 //     (b3) The methods which writes the results in the ASCII files
00599 //
00600 //    ++++++++++++++++  (a) WRITING IN THE ROOT FILE  ++++++++++++++++++++
00601 //
00602 // (a1)-----------> Method to get the path for the results ROOT file
00603 //
00604 //      void  MyCnaRun->GetPathForResultsRootFiles(pathname);
00605 //            TString pathname = name of a "cna-configuration" file located
00606 //            in the user's HOME directory and containing one line which
00607 //            specifies the path where must be writen the .root result files.
00608 //            (no slash at the end of the string)
00609 //    
00610 //   DEFAULT: 
00611 //            void MyCnaRun->GetPathForResultsRootFiles();
00612 //            If there is no argument, the "cna-configuration" file must be named
00613 //            "cna_results_root.cfg" and must be located in the user's HOME
00614 //            directory
00615 //
00616 //
00617 // (a2)-----------> Codification for the name of the ROOT file:
00618 //
00619 //  The name of the ROOT file is the following:
00620 //
00621 //       aaa_rrr_fff_ttt_SMsss.root
00622 //
00623 //  with:
00624 //       aaa = Analysis name
00625 //       rrr = Run number
00626 //       fff = First event number
00627 //       ttt = Number of taken events
00628 //       sss = Super-module number
00629 //
00630 //  This name is automatically generated from the values of the arguments
00631 //  of the method "GetReadyToReadData".
00632 //
00633 // (a3)-----------> Method which writes the result in the ROOT file:
00634 //
00635 //       Bool_t  MyCnaRun->WriteRootFile();
00636 //
00637 //
00638 //    ++++++++++++++++  (b) WRITING IN THE ASCII FILES  ++++++++++++++++++++
00639 //
00640 // (b1)-----------> Method to set the path for the results ASCII files
00641 //
00642 //      void  MyCnaRun->GetPathForResultsAsciiFiles(pathname);
00643 //
00644 //            TString pathname = name of a "cna-config" file located
00645 //            in the user's HOME directory and containing one line which
00646 //            specifies the path where must be writen the .ascii result files.
00647 //            (no slash at the end of the string)
00648 //    
00649 //   DEFAULT: 
00650 //            void  MyCnaRun->GetPathForResultsAsciiFiles();
00651 //            If there is no argument, the "cna-config" file must be named
00652 //            "cna_results_ascii.cfg" and must be located in the user's HOME
00653 //            directory
00654 //
00655 //
00656 // (b2)-----------> Codification for the names of the ASCII files (examples):
00657 //
00658 //       aaa_rrr_ev_fff_ttt_SMsss.ascii
00659 //       aaa_rrr_cor_ss_cCCC_fff_ttt_SMsss.ascii
00660 //       aaa_rrr_cov_cc_sSSS_fff_ttt_SMsss.ascii
00661 //       etc...  
00662 //
00663 //  with:
00664 //       aaa = Analysis name
00665 //       rrr = Run number
00666 //       fff = First event number
00667 //       ttt = Number of taken (required) events
00668 //       SSS = Sample number
00669 //       CCC = Electronic Channel number in SM
00670 //       sss = Super-module number
00671 //
00672 //  Examples:
00673 //       cut1_2208_ev_0_500_SM10.ascii  :
00674 //        ASCII file containing the expectation values (code "ev")
00675 //        for the analysis "cut1", run 2208, first event: 0,
00676 //        500 events from the event 0 (=> last evt = 499) and super-module 10
00677 //
00678 //       cut2_33559_cor_ss_c1264_2000_1500_SM10.ascii  :
00679 //        ASCII file containing the correlations between samples ("cor_ss")
00680 //        for the channel 1264 ("c1264"), analysis "cut2", run 33559,
00681 //        first event: 2000, 1500 events from the event 2000
00682 //        (=> last evt = 3499) and super-module 10 
00683 //
00684 //       std_10_cov_cc_s0_0_2000_SM8.ascii  :
00685 //        ASCII file containing the covariances between channels ("cov_cc")
00686 //        for the sample 0 ("s0"), analysis "std", run 10,
00687 //        first event: 0, 2000 events from the event 0
00688 //        (=> last evt = 1999) and super-module 8
00689 //
00690 //
00691 // (b3)-----------> Methods which write the ASCII files:
00692 //
00693 //  The methods which write the ASCII files are the following:
00694 //
00695 //      void  WriteAsciiExpectationValuesOfSamples();    
00696 //      void  WriteAsciiVariancesOfSamples();
00697 //      void  WriteAsciiCovariancesBetweenChannelsMeanOverSamples();
00698 //      void  WriteAsciiCovariancesBetweenSamples(n_channel);
00699 //      void  WriteAsciiCorrelationsBetweenChannelsMeanOverSamples();
00700 //      void  WriteAsciiCorrelationsBetweenSamples(n_channel);
00701 //
00702 //  Each of these methods corresponds to a "calculation method" presented
00703 //  above. The calculation method must be called before the writing method.
00704 //
00705 //-------------------------------------------------------------------------
00706 //
00707 //        For more details on other classes of the CNA package:
00708 //
00709 //                 https://www.cern.ch/cms-fabbro/cna
00710 //
00711 //-------------------------------------------------------------------------
00712 //
00713 
00714 //------------------------------ TCnaRunEB.cxx -----------------------------
00715 //  
00716 //   Creation (first version): 03 Dec 2002
00717 //
00718 //   For questions or comments, please send e-mail to Bernard Fabbro:
00719 //             
00720 //   fabbro@hep.saclay.cea.fr 
00721 //
00722 //------------------------------------------------------------------------
00723 
00724 TCnaRunEB::TCnaRunEB()
00725 {
00726 //Constructor without argument: call to Init()
00727   Init();
00728 }
00729 
00730 void TCnaRunEB::Init()
00731 {
00732 //Initialisation
00733 
00734   fCnew       = 0;
00735   fCdelete    = 0;
00736   fCnaCommand = 0;
00737   fCnaError   = 0;
00738 
00739   fTTBELL = '\007';   //   "BIP!"
00740 
00741   //........................... TString file names init
00742   fgMaxCar  = (Int_t)512;
00743 
00744   Int_t MaxCar = fgMaxCar;
00745   fRootFileName.Resize(MaxCar);
00746   fRootFileName      = "?";
00747 
00748   MaxCar = fgMaxCar;
00749   fRootFileNameShort.Resize(MaxCar);
00750   fRootFileNameShort = "?";
00751 
00752   MaxCar = fgMaxCar;
00753   fAsciiFileName.Resize(MaxCar);
00754   fAsciiFileName      = "?";
00755 
00756   MaxCar = fgMaxCar;
00757   fAsciiFileNameShort.Resize(MaxCar);
00758   fAsciiFileNameShort = "?";
00759 
00760   fDim_name = fgMaxCar;
00761 
00762   //................................................... Code Print
00763 
00764   TCnaParameters* MyParameters = new TCnaParameters();      fCnew++;
00765 
00766   fCodePrintNoComment   = MyParameters->GetCodePrint("NoComment");
00767   fCodePrintWarnings    = MyParameters->GetCodePrint("Warnings ");      // => default value
00768   fCodePrintComments    = MyParameters->GetCodePrint("Comments");
00769   fCodePrintAllComments = MyParameters->GetCodePrint("AllComments");
00770 
00771   delete MyParameters;                                      fCdelete++;
00772 
00773   fMiscDiag = 0;
00774 
00775   //................ MiscDiag counters .................
00776   fMaxMsgIndexForMiscDiag = (Int_t)10;
00777   fNbOfMiscDiagCounters   = (Int_t)50;
00778 
00779   fMiscDiag   = new Int_t[fNbOfMiscDiagCounters];       fCnew++;
00780   for (Int_t iz=0; iz<fNbOfMiscDiagCounters; iz++){fMiscDiag[iz] = (Int_t)0;}
00781 
00782   //............................. init pointers
00783 
00784   fT3d_distribs  = 0;
00785   fT3d2_distribs = 0;
00786   fT3d1_distribs = 0;
00787 
00788   fVal_data  = 0;
00789   fVal_dat2  = 0;
00790 
00791   fT2d_EvtNbInLoop = 0;
00792   fT1d_EvtNbInLoop = 0;
00793 
00794   fT1d_SMtowFromIndex = 0;
00795 
00796   fT2d_LastEvtNumber = 0;
00797   fT1d_LastEvtNumber = 0; 
00798 
00799   fT2d_ev        = 0;
00800   fT1d_ev        = 0;
00801   fT2d_var       = 0;
00802   fT1d_var       = 0;
00803 
00804   fT3d_his_s     = 0;
00805   fT2d_his_s     = 0;
00806   fT1d_his_s     = 0;
00807 
00808   fT2d_xmin      = 0;
00809   fT1d_xmin      = 0;
00810 
00811   fT2d_xmax      = 0;
00812   fT1d_xmax      = 0;
00813 
00814   fT3d_cov_ss    = 0;
00815   fT3d2_cov_ss   = 0;
00816   fT3d1_cov_ss   = 0;
00817 
00818   fT3d_cor_ss    = 0;
00819   fT3d2_cor_ss   = 0;
00820   fT3d1_cor_ss   = 0;
00821 
00822   fT3d_cov_cc    = 0;
00823   fT3d2_cov_cc   = 0;
00824   fT3d1_cov_cc   = 0;
00825 
00826   fT3d_cor_cc    = 0;
00827   fT3d2_cor_cc   = 0;
00828   fT3d1_cor_cc   = 0;
00829 
00830   fT2d_cov_cc_mos  = 0;
00831   fT2d1_cov_cc_mos = 0;
00832 
00833   fT2d_cor_cc_mos  = 0;
00834   fT2d1_cor_cc_mos = 0;
00835 
00836   fT2d_cov_moscc_mot  = 0;
00837   fT2d1_cov_moscc_mot = 0;
00838 
00839   fT2d_cor_moscc_mot  = 0;
00840   fT2d1_cor_moscc_mot = 0;
00841 
00842   fT1d_ev_ev     = 0;
00843   fT1d_ev_sig    = 0;
00844   fT1d_ev_cor_ss = 0;
00845 
00846   fT1d_sig_ev     = 0;
00847   fT1d_sig_sig    = 0;
00848   fT1d_sig_cor_ss = 0;
00849 
00850   fT2d_sv_correc_covss_s  = 0;
00851   fT2d1_sv_correc_covss_s = 0;
00852 
00853   fT3d_cov_correc_covss_s  = 0;
00854   fT3d2_cov_correc_covss_s = 0;
00855   fT3d1_cov_correc_covss_s = 0;
00856 
00857   fT3d_cor_correc_covss_s  = 0;
00858   fT3d2_cor_correc_covss_s = 0;
00859   fT3d1_cor_correc_covss_s = 0;
00860 
00861   fT2dCrysNumbersTable = 0;
00862   fT1dCrysNumbersTable = 0;
00863 
00864   fjustap_2d_ev  = 0;
00865   fjustap_1d_ev  = 0;
00866 
00867   fjustap_2d_var = 0;
00868   fjustap_1d_var = 0;
00869 
00870   fjustap_2d_cc  = 0;
00871   fjustap_1d_cc  = 0;
00872 
00873   fjustap_2d_ss  = 0;
00874   fjustap_1d_ss  = 0;
00875 
00876   //............................... codes (all the values must be different)
00877 
00878   fCodeHeaderAscii     =  0;
00879   fCodeRoot            =  1; 
00880   fCodeCorresp         =  2; 
00881 
00882   fCodeSampTime        =  3;
00883 
00884   fCodeEv              =  4;  
00885   fCodeVar             =  5;  
00886   fCodeEvts            =  6;
00887 
00888   fCodeCovCss          =  7;
00889   fCodeCorCss          =  8;
00890   fCodeCovScc          =  9;
00891   fCodeCorScc          = 10;
00892   fCodeCovSccMos       = 11;
00893   fCodeCorSccMos       = 12;
00894 
00895   fCodeCovMosccMot     = 13;
00896   fCodeCorMosccMot     = 14;
00897 
00898   fCodeEvCorCss        = 15; 
00899   fCodeSigCorCss       = 16; 
00900   
00901   fCodeSvCorrecCovCss  = 17;
00902   fCodeCovCorrecCovCss = 18;
00903   fCodeCorCorrecCovCss = 19;
00904 
00905   //.............................................................................. codes (end)
00906 
00907   //................................ tags
00908   fTagTowerNumbers    = 0;
00909   fTagLastEvtNumber   = 0;
00910   fTagEvtNbInLoop     = 0;
00911 
00912   fTagSampTime        = 0;
00913 
00914   fTagEv              = 0;
00915   fTagVar             = 0;
00916   fTagEvts            = 0;
00917 
00918   fTagCovCss          = 0;
00919   fTagCorCss          = 0;
00920 
00921   fTagCovScc          = 0;
00922   fTagCorScc          = 0;
00923   fTagCovSccMos       = 0;
00924   fTagCorSccMos       = 0;
00925 
00926   fTagCovMosccMot     = 0;
00927   fTagCorMosccMot     = 0;
00928 
00929   fTagEvEv            = 0;
00930   fTagEvSig           = 0;
00931   fTagEvCorCss        = 0;
00932 
00933   fTagSigEv           = 0;
00934   fTagSigSig          = 0;
00935   fTagSigCorCss       = 0;
00936 
00937   fTagSvCorrecCovCss  = 0;
00938   fTagCovCorrecCovCss = 0;
00939   fTagCorCorrecCovCss = 0;
00940 
00941   //.............................................. Miscellaneous
00942   
00943   fFlagPrint = fCodePrintWarnings;
00944 
00945   fFileHeader = new TCnaHeaderEB();    fCnew++;
00946   
00947   fOpenRootFile  = kFALSE;
00948   
00949   fReadyToReadData = 0;
00950 
00951   fSectChanSizeX = 0;
00952   fSectChanSizeY = 0;
00953   fSectSampSizeX = 0;
00954   fSectSampSizeY = 0;
00955 
00956   fUserSamp   = 0;
00957   fUserSMEcha = 0;
00958 
00959   fSpecialSMTowerNotIndexed = -1;
00960 
00961   fTowerIndexBuilt = 0;
00962 
00963 }
00964 // end of Init()
00965 //=========================================== private copy ==========
00966 
00967 void  TCnaRunEB::fCopy(const TCnaRunEB& rund)
00968 {
00969 //Private copy
00970 
00971 #define NOCO
00972 #ifndef NOCO
00973   fFileHeader   = rund.fFileHeader;
00974   fOpenRootFile = rund.fOpenRootFile;
00975 
00976   fUserSamp     = rund.fUserSamp;
00977   fUserSMEcha     = rund.fUserSMEcha;
00978 
00979   fSectChanSizeX = rund.fSectChanSizeX;
00980   fSectChanSizeY = rund.fSectChanSizeY;
00981   fSectSampSizeX = rund.fSectSampSizeX;
00982   fSectSampSizeY = rund.fSectSampSizeY;
00983 
00984   fT1d_SMtowFromIndex = rund.fT1d_SMtowFromIndex;
00985 
00986   fT2d_EvtNbInLoop = rund.fT2d_EvtNbInLoop;
00987   fT1d_EvtNbInLoop = rund.fT1d_EvtNbInLoop;
00988 
00989   fT3d_distribs  = rund.fT3d_distribs;
00990   fT3d2_distribs = rund.fT3d2_distribs;
00991   fT3d1_distribs = rund.fT3d1_distribs;
00992 
00993   fVal_data     = rund.fVal_data;   
00994   fVal_dat2     = rund.fVal_dat2;
00995 
00996   fT2d_LastEvtNumber = rund.fT2d_LastEvtNumber;
00997   fT1d_LastEvtNumber = rund.fT1d_LastEvtNumber;
00998 
00999   fT2d_ev      = rund.fT2d_ev;
01000   fT1d_ev      = rund.fT1d_ev;
01001 
01002   fT2d_var     = rund.fT2d_var;
01003   fT1d_var     = rund.fT1d_var;
01004 
01005   fT3d_his_s   = rund.fT3d_his_s;
01006   fT2d_his_s   = rund.fT2d_his_s;
01007   fT1d_his_s   = rund.fT1d_his_s;
01008 
01009   fT2d_xmin    = rund.fT2d_xmin;
01010   fT1d_xmin    = rund.fT1d_xmin;
01011   fT2d_xmax    = rund.fT2d_xmax; 
01012   fT1d_xmax    = rund.fT1d_xmax;   
01013 
01014   fT3d_cov_ss  = rund.fT3d_cov_ss;
01015   fT3d2_cov_ss = rund.fT3d2_cov_ss;
01016   fT3d1_cov_ss = rund.fT3d1_cov_ss;
01017 
01018   fT3d_cor_ss  = rund.fT3d_cor_ss;
01019   fT3d2_cor_ss = rund.fT3d2_cor_ss;
01020   fT3d1_cor_ss = rund.fT3d1_cor_ss;
01021 
01022   fT3d_cov_cc  = rund.fT3d_cov_cc;
01023   fT3d2_cov_cc = rund.fT3d2_cov_cc;
01024   fT3d1_cov_cc = rund.fT3d1_cov_cc;
01025 
01026   fT3d_cor_cc  = rund.fT3d_cor_cc;
01027   fT3d2_cor_cc = rund.fT3d2_cor_cc;
01028   fT3d1_cor_cc = rund.fT3d1_cor_cc;
01029 
01030   fT2d_cov_cc_mos  = rund.fT2d_cov_cc_mos;
01031   fT2d1_cov_cc_mos = rund.fT2d1_cov_cc_mos;
01032 
01033   fT2d_cor_cc_mos  = rund.fT2d_cor_cc_mos;
01034   fT2d1_cor_cc_mos = rund.fT2d1_cor_cc_mos;
01035 
01036   fT2d_cov_moscc_mot  = rund.fT2d_cov_moscc_mot;
01037   fT2d1_cov_moscc_mot = rund.fT2d1_cov_moscc_mot;
01038 
01039   fT2d_cor_moscc_mot  = rund.fT2d_cor_moscc_mot;
01040   fT2d1_cor_moscc_mot = rund.fT2d1_cor_moscc_mot;
01041 
01042   fT1d_ev_ev     = rund.fT1d_ev_ev;
01043   fT1d_ev_sig    = rund.fT1d_ev_sig;
01044   fT1d_ev_cor_ss = rund.fT1d_ev_cor_ss;
01045 
01046   fT1d_sig_ev     = rund.fT1d_sig_ev;
01047   fT1d_sig_sig    = rund.fT1d_sig_sig;
01048   fT1d_sig_cor_ss = rund.fT1d_sig_cor_ss;
01049 
01050   fT2d_sv_correc_covss_s = rund.fT2d_sv_correc_covss_s;
01051   fT2d1_sv_correc_covss_s = rund.fT2d1_sv_correc_covss_s;
01052 
01053   fT3d_cov_correc_covss_s  = rund.fT3d_cov_correc_covss_s;
01054   fT3d2_cov_correc_covss_s = rund.fT3d2_cov_correc_covss_s;
01055   fT3d1_cov_correc_covss_s = rund.fT3d1_cov_correc_covss_s;
01056 
01057   fT3d_cor_correc_covss_s  = rund.fT3d_cor_correc_covss_s;
01058   fT3d2_cor_correc_covss_s = rund.fT3d2_cor_correc_covss_s;
01059   fT3d1_cor_correc_covss_s = rund.fT3d1_cor_correc_covss_s;
01060 
01061   fT2dCrysNumbersTable  = rund.fT2dCrysNumbersTable;
01062   fT1dCrysNumbersTable  = rund.fT1dCrysNumbersTable;
01063 
01064   fjustap_2d_ev  = rund.fjustap_2d_ev;
01065   fjustap_1d_ev  = rund.fjustap_1d_ev;
01066 
01067   fjustap_2d_var = rund.fjustap_2d_var;
01068   fjustap_1d_var = rund.fjustap_1d_var;
01069 
01070   fjustap_2d_cc  = rund.fjustap_2d_cc;
01071   fjustap_1d_cc  = rund.fjustap_1d_cc;
01072 
01073   fjustap_2d_ss  = rund.fjustap_2d_ss;
01074   fjustap_1d_ss  = rund.fjustap_1d_ss;
01075 
01076   //........................................ Codes   
01077   fCodeHeaderAscii     = rund.fCodeHeaderAscii;
01078   fCodeRoot            = rund.fCodeRoot;
01079   fCodeSampTime        = rund.fCodeSampTime;  
01080   fCodeEv              = rund.fCodeEv;  
01081   fCodeVar             = rund.fCodeVar;  
01082   fCodeEvts            = rund.fCodeEvts;
01083   fCodeCovCss          = rund.fCodeCovCss;
01084   fCodeCorCss          = rund.fCodeCorCss;
01085   fCodeCovScc          = rund.fCodeCovScc;
01086   fCodeCorScc          = rund.fCodeCorScc;
01087   fCodeCovSccMos       = rund.fCodeCovSccMos;
01088   fCodeCorSccMos       = rund.fCodeCorSccMos;
01089   fCodeCovMosccMot     = rund.fCodeCovMosccMot;
01090   fCodeCorMosccMot     = rund.fCodeCorMosccMot;
01091   fCodeEvCorCss        = rund.fCodeEvCorCss;
01092   fCodeSigCorCss       = rund.fCodeSigCorCss;
01093   fCodeSvCorrecCovCss  = rund.fCodeSvCorrecCovCss;
01094   fCodeCovCorrecCovCss = rund.fCodeCovCorrecCovCss;
01095   fCodeCorCorrecCovCss = rund.fCodeCorCorrecCovCss;
01096   fCodePrintComments    = rund.fCodePrintComments;
01097   fCodePrintWarnings    = rund.fCodePrintWarnings;
01098   fCodePrintAllComments = rund.fCodePrintAllComments;
01099   fCodePrintNoComment   = rund.fCodePrintNoComment;
01100 
01101   //.................................................. Tags
01102   fTagTowerNumbers  = rund.fTagTowerNumbers;
01103   fTagLastEvtNumber = rund.fTagLastEvtNumber;
01104   fTagEvtNbInLoop   = rund.fTagEvtNbInLoop;
01105   fTagEv            = rund.fTagEv;
01106   fTagVar           = rund.fTagVar;
01107   fTagEvts          = rund.fTagEvts;
01108   fTagCovCss        = rund.fTagCovCss;
01109   fTagCorCss        = rund.fTagCorCss;
01110   fTagCovScc        = rund.fTagCovScc;
01111   fTagCorScc        = rund.fTagCorScc;
01112   fTagCovSccMos     = rund.fTagCovSccMos;
01113   fTagCorSccMos     = rund.fTagCorSccMos;
01114   fTagCovMosccMot   = rund.fTagCovMosccMot;
01115   fTagCorMosccMot   = rund.fTagCorMosccMot;
01116   fTagEvEv          = rund.fTagEvEv;
01117   fTagEvSig         = rund.fTagEvSig;
01118   fTagEvCorCss      = rund.fTagEvCorCss;
01119   fTagSigEv         = rund.fTagSigEv;
01120   fTagSigSig        = rund.fTagSigSig;
01121   fTagSigCorCss     = rund.fTagSigCorCss;
01122   fTagSvCorrecCovCss  = rund.fTagSvCorrecCovCss;
01123   fTagCovCorrecCovCss = rund.fTagCovCorrecCovCss;
01124   fTagCorCorrecCovCss = rund.fTagCorCorrecCovCss;
01125   fFlagPrint          = rund.fFlagPrint;
01126 
01127   fRootFileName         = rund.fRootFileName;
01128   fRootFileNameShort    = rund.fRootFileNameShort;
01129   fAsciiFileName        = rund.fAsciiFileName;
01130   fAsciiFileNameShort   = rund.fAsciiFileNameShort;
01131 
01132   fDim_name             = rund.fDim_name;
01133 
01134   fCfgResultsRootFilePath  = rund.fCfgResultsRootFilePath;
01135   fCfgResultsAsciiFilePath = rund.fCfgResultsAsciiFilePath;
01136 
01137   fFileForResultsRootFilePath  = rund.fFileForResultsRootFilePath; 
01138   fFileForResultsAsciiFilePath = rund.fFileForResultsAsciiFilePath; 
01139 
01140   fCnew    = rund.fCnew;
01141   fCdelete = rund.fCdelete;
01142 #endif // NOCO
01143 }
01144 //  end of private copy
01145 
01146 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01147 //
01148 //                    copy constructor
01149 //
01150 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01151 
01152 TCnaRunEB::TCnaRunEB(const TCnaRunEB& dcop)
01153 {
01154   cout << "*TCnaRunEB::TCnaRunEB(const TCnaRunEB& dcop)> "
01155        << " It is time to write a copy constructor" << endl
01156        << " type an integer value and then RETURN to continue"
01157        << endl;
01158   
01159   { Int_t cintoto;  cin >> cintoto; }
01160   
01161 }
01162 
01163 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01164 //
01165 //                    overloading of the operator=
01166 //
01167 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01168 
01169 TCnaRunEB& TCnaRunEB::operator=(const TCnaRunEB& dcop)
01170 {
01171 //Overloading of the operator=
01172 
01173   fCopy(dcop);
01174   return *this;
01175 }
01176 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01177 //
01178 //                            destructor
01179 //
01180 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01181 
01182 TCnaRunEB::~TCnaRunEB()
01183 {
01184   //Destructor
01185   
01186   if(fFlagPrint == fCodePrintAllComments || fFlagPrint == fCodePrintComments ||
01187      fFlagPrint == fCodePrintWarnings )
01188     {
01189       cout << "*TCnaRunEB::~TCnaRunEB()> Entering destructor." << endl;
01190     }
01191 
01192   if(fFlagPrint == fCodePrintAllComments)
01193     {
01194       Int_t misc_czero = 0;
01195       for(Int_t i = 0; i < fNbOfMiscDiagCounters; i++)
01196         {
01197           if( fMiscDiag[i] != 0 )
01198             {
01199               cout << "                          fMiscDiag Counter "
01200                    << setw(3) << i << " = " << setw(9) << fMiscDiag[i]
01201                    << " (INFO: alloc on non zero freed zone) " << endl;
01202             }
01203           else
01204             {
01205               misc_czero++;
01206             }
01207         }
01208       cout << "                          Nb of fMiscDiag counters at zero: "
01209            << misc_czero << " (total nb of counters: "
01210            << fNbOfMiscDiagCounters << ")" << endl;
01211     }
01212 
01213   if (fMiscDiag                != 0){delete [] fMiscDiag;                 fCdelete++;}
01214   
01215   if (fFileHeader              != 0){delete fFileHeader;                  fCdelete++;}
01216   
01217   if (fT1d_SMtowFromIndex      != 0){delete [] fT1d_SMtowFromIndex;       fCdelete++;}
01218   
01219   if (fVal_data                != 0){delete [] fVal_data;                 fCdelete++;}
01220   if (fVal_dat2                != 0){delete [] fVal_dat2;                 fCdelete++;}
01221 
01222   if (fT2d_LastEvtNumber       != 0){delete [] fT2d_LastEvtNumber;        fCdelete++;}
01223   if (fT1d_LastEvtNumber       != 0){delete [] fT1d_LastEvtNumber;        fCdelete++;}
01224 
01225   if (fT2d_EvtNbInLoop         != 0){delete [] fT2d_EvtNbInLoop;          fCdelete++;}
01226   if (fT1d_EvtNbInLoop         != 0){delete [] fT1d_EvtNbInLoop;          fCdelete++;}
01227 
01228   if (fT3d_distribs            != 0){delete [] fT3d_distribs;             fCdelete++;}
01229   if (fT3d2_distribs           != 0){delete [] fT3d2_distribs;            fCdelete++;}
01230   if (fT3d1_distribs           != 0){delete [] fT3d1_distribs;            fCdelete++;}
01231 
01232   if (fT2d_ev                  != 0){delete [] fT2d_ev;                   fCdelete++;}
01233   if (fT1d_ev                  != 0){delete [] fT1d_ev;                   fCdelete++;}
01234 
01235   if (fT2d_var                 != 0){delete [] fT2d_var;                  fCdelete++;}
01236   if (fT1d_var                 != 0){delete [] fT1d_var;                  fCdelete++;}
01237 
01238   if (fT3d_his_s               != 0){delete [] fT3d_his_s;                fCdelete++;}
01239   if (fT2d_his_s               != 0){delete [] fT2d_his_s;                fCdelete++;}
01240   if (fT1d_his_s               != 0){delete [] fT1d_his_s;                fCdelete++;}
01241 
01242   if (fT2d_xmin                != 0){delete [] fT2d_xmin;                 fCdelete++;}
01243   if (fT1d_xmin                != 0){delete [] fT1d_xmin;                 fCdelete++;}
01244   if (fT2d_xmax                != 0){delete [] fT2d_xmax;                 fCdelete++;}
01245   if (fT1d_xmax                != 0){delete [] fT1d_xmax;                 fCdelete++;}
01246 
01247   if (fT3d_cov_ss              != 0){delete [] fT3d_cov_ss;               fCdelete++;}
01248   if (fT3d2_cov_ss             != 0){delete [] fT3d2_cov_ss;              fCdelete++;}
01249   if (fT3d1_cov_ss             != 0){delete [] fT3d1_cov_ss;              fCdelete++;}
01250 
01251   if (fT3d_cor_ss              != 0){delete [] fT3d_cor_ss;               fCdelete++;}
01252   if (fT3d2_cor_ss             != 0){delete [] fT3d2_cor_ss;              fCdelete++;}
01253   if (fT3d1_cor_ss             != 0){delete [] fT3d1_cor_ss;              fCdelete++;}
01254 
01255   if (fT3d_cov_cc              != 0){delete [] fT3d_cov_cc;               fCdelete++;}
01256   if (fT3d2_cov_cc             != 0){delete [] fT3d2_cov_cc;              fCdelete++;}
01257   if (fT3d1_cov_cc             != 0){delete [] fT3d1_cov_cc;              fCdelete++;}
01258 
01259   if (fT3d_cor_cc              != 0){delete [] fT3d_cor_cc;               fCdelete++;}
01260   if (fT3d2_cor_cc             != 0){delete [] fT3d2_cor_cc;              fCdelete++;}
01261   if (fT3d1_cor_cc             != 0){delete [] fT3d1_cor_cc;              fCdelete++;}
01262 
01263   if (fT2d_cov_cc_mos          != 0){delete [] fT2d_cov_cc_mos;           fCdelete++;}
01264   if (fT2d1_cov_cc_mos         != 0){delete [] fT2d1_cov_cc_mos;          fCdelete++;}
01265 
01266   if (fT2d_cor_cc_mos          != 0){delete [] fT2d_cor_cc_mos;           fCdelete++;}
01267   if (fT2d1_cor_cc_mos         != 0){delete [] fT2d1_cor_cc_mos;          fCdelete++;}
01268 
01269   if (fT2d_cov_moscc_mot       != 0){delete [] fT2d_cov_moscc_mot;        fCdelete++;}
01270   if (fT2d1_cov_moscc_mot      != 0){delete [] fT2d1_cov_moscc_mot ;      fCdelete++;}
01271 
01272   if (fT2d_cor_moscc_mot       != 0){delete [] fT2d_cor_moscc_mot ;       fCdelete++;}
01273   if (fT2d1_cor_moscc_mot      != 0){delete [] fT2d1_cor_moscc_mot;       fCdelete++;}
01274 
01275   if (fT1d_ev_ev               != 0){delete [] fT1d_ev_ev;                fCdelete++;}
01276   if (fT1d_ev_sig              != 0){delete [] fT1d_ev_sig;               fCdelete++;}
01277   if (fT1d_ev_cor_ss           != 0){delete [] fT1d_ev_cor_ss;            fCdelete++;}
01278 
01279   if (fT1d_sig_ev              != 0){delete [] fT1d_sig_ev;               fCdelete++;}
01280   if (fT1d_sig_sig             != 0){delete [] fT1d_sig_sig;              fCdelete++;}
01281   if (fT1d_sig_cor_ss          != 0){delete [] fT1d_sig_cor_ss;           fCdelete++;}
01282 
01283   if (fT2d_sv_correc_covss_s   != 0){delete [] fT2d_sv_correc_covss_s;    fCdelete++;}
01284   if (fT2d1_sv_correc_covss_s  != 0){delete [] fT2d1_sv_correc_covss_s;   fCdelete++;}
01285 
01286   if (fT3d_cov_correc_covss_s  != 0){delete [] fT3d_cov_correc_covss_s;   fCdelete++;}
01287   if (fT3d2_cov_correc_covss_s != 0){delete [] fT3d2_cov_correc_covss_s;  fCdelete++;}
01288   if (fT3d1_cov_correc_covss_s != 0){delete [] fT3d1_cov_correc_covss_s;  fCdelete++;}
01289 
01290   if (fT3d_cor_correc_covss_s  != 0){delete [] fT3d_cor_correc_covss_s;   fCdelete++;}
01291   if (fT3d2_cor_correc_covss_s != 0){delete [] fT3d2_cor_correc_covss_s;  fCdelete++;}
01292   if (fT3d1_cor_correc_covss_s != 0){delete [] fT3d1_cor_correc_covss_s;  fCdelete++;} 
01293 
01294   if (fT2dCrysNumbersTable     != 0){delete [] fT2dCrysNumbersTable;      fCdelete++;}
01295   if (fT1dCrysNumbersTable     != 0){delete [] fT1dCrysNumbersTable;      fCdelete++;}
01296 
01297   if (fjustap_2d_ev            != 0){delete [] fjustap_2d_ev;             fCdelete++;}
01298   if (fjustap_1d_ev            != 0){delete [] fjustap_1d_ev;             fCdelete++;}
01299   if (fjustap_2d_var           != 0){delete [] fjustap_2d_var;            fCdelete++;}
01300   if (fjustap_1d_var           != 0){delete [] fjustap_1d_var;            fCdelete++;}
01301   if (fjustap_2d_cc            != 0){delete [] fjustap_2d_cc;             fCdelete++;}
01302   if (fjustap_1d_cc            != 0){delete [] fjustap_1d_cc;             fCdelete++;}
01303   if (fjustap_2d_ss            != 0){delete [] fjustap_2d_ss;             fCdelete++;}
01304   if (fjustap_1d_ss            != 0){delete [] fjustap_1d_ss;             fCdelete++;}
01305 
01306   if (fTagTowerNumbers         != 0){delete [] fTagTowerNumbers;          fCdelete++;}
01307   if (fTagLastEvtNumber        != 0){delete [] fTagLastEvtNumber;         fCdelete++;}
01308   if (fTagEvtNbInLoop          != 0){delete [] fTagEvtNbInLoop;           fCdelete++;}
01309   if (fTagSampTime             != 0){delete [] fTagSampTime;              fCdelete++;}
01310   if (fTagEv                   != 0){delete [] fTagEv;                    fCdelete++;}
01311   if (fTagVar                  != 0){delete [] fTagVar;                   fCdelete++;}
01312   if (fTagEvts                 != 0){delete [] fTagEvts;                  fCdelete++;}
01313 
01314   if (fTagCovCss               != 0){delete [] fTagCovCss;                fCdelete++;}
01315   if (fTagCorCss               != 0){delete [] fTagCorCss;                fCdelete++;}
01316 
01317   if (fTagCovScc               != 0){delete [] fTagCovScc;                fCdelete++;}
01318   if (fTagCorScc               != 0){delete [] fTagCorScc;                fCdelete++;}
01319   if (fTagCovSccMos            != 0){delete [] fTagCovSccMos;             fCdelete++;}
01320   if (fTagCorSccMos            != 0){delete [] fTagCorSccMos;             fCdelete++;}
01321 
01322   if (fTagCovMosccMot          != 0){delete [] fTagCovMosccMot;           fCdelete++;}
01323   if (fTagCorMosccMot          != 0){delete [] fTagCorMosccMot;           fCdelete++;}
01324 
01325   if (fTagEvEv                 != 0){delete [] fTagEvEv;                  fCdelete++;}
01326   if (fTagEvSig                != 0){delete [] fTagEvSig;                 fCdelete++;}
01327   if (fTagEvCorCss             != 0){delete [] fTagEvCorCss;              fCdelete++;}
01328 
01329   if (fTagSigEv                != 0){delete [] fTagSigEv;                 fCdelete++;}
01330   if (fTagSigSig               != 0){delete [] fTagSigSig;                fCdelete++;}
01331   if (fTagSigCorCss            != 0){delete [] fTagSigCorCss;             fCdelete++;}
01332 
01333   if (fTagSvCorrecCovCss       != 0){delete [] fTagSvCorrecCovCss;        fCdelete++;}
01334   if (fTagCovCorrecCovCss      != 0){delete [] fTagCovCorrecCovCss;       fCdelete++;}
01335   if (fTagCorCorrecCovCss      != 0){delete [] fTagCorCorrecCovCss;       fCdelete++;}
01336 
01337   if ( fCnew != fCdelete )
01338     {
01339       cout << "!TCnaRunEB::~TCnaRunEB()> WRONG MANAGEMENT OF MEMORY ALLOCATIONS: fCnew = "
01340            << fCnew << ", fCdelete = " << fCdelete << fTTBELL << endl;
01341     }
01342   else
01343     {
01344       // cout << "*TCnaRunEB::~TCnaRunEB()> Management of memory allocations: OK. fCnew = "
01345       //   << fCnew << ", fCdelete = " << fCdelete << endl;
01346     }
01347   
01348   if(fFlagPrint == fCodePrintComments || fFlagPrint == fCodePrintWarnings )
01349     {
01350       cout << "*TCnaRunEB::~TCnaRunEB()> Exiting destructor." << endl;
01351     }
01352   if(fFlagPrint == fCodePrintAllComments)
01353     {
01354       cout << "*TCnaRunEB::~TCnaRunEB()> Exiting destructor (this = " << this << ")." << endl
01355            << "~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#"
01356            << endl;
01357     }
01358 }
01359 
01360 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01361 //
01362 //                             M  E  T  H  O  D  S
01363 //
01364 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01365 
01366 //============================================================================
01367 //
01368 //                           GetReadyToReadData(...)
01369 //                  
01370 //============================================================================
01371 
01372 void TCnaRunEB::GetReadyToReadData(TString typ_ana,      const Int_t& run_number,
01373                                  Int_t&  nfirst,             Int_t& nevents,
01374                                  const Int_t&  super_module)
01375 {
01376 //Preparation of the data reading. Set part of the header. No Nentries as argument.
01377 //Use default value = 999999 and call method with all the arguments (see below)
01378 
01379   Int_t nentries = 999999999;
01380 
01381   GetReadyToReadData(typ_ana, run_number, nfirst, nevents, super_module, nentries);
01382 
01383 }
01384 //--------------------------------------------------------------------------------
01385 
01386 void TCnaRunEB::GetReadyToReadData( TString typ_ana,      const Int_t& run_number,
01387                                   Int_t&  nfirst,             Int_t& nevents,
01388                             const Int_t&  super_module, const Int_t& nentries)
01389 {
01390 //Preparation of the data reading. Set part of the header
01391 
01392   //************** CHECK OF ARGUMENTS: nfirst_arg and nevents_arg
01393 
01394   if ( nfirst < nentries )
01395     {
01396       //--------------------- test of positivity of nfirst_arg
01397       if (nfirst < 0 )
01398         {
01399           if (fFlagPrint != fCodePrintNoComment){
01400             cout << "!TCnaRunEB::GetReadyToReadData(...) > WARNING/CORRECTION:" << endl
01401                  << "! The fisrt taken event number is negative ( = " << nfirst << "). Forced to zero."
01402                  << fTTBELL << endl;}
01403           nfirst = 0;
01404         }
01405 
01406       //-------- test of compatibility between the last taken event number
01407       //         and the number of entries
01408 
01409       Int_t   last_taken_event = nfirst + nevents - 1;
01410       Int_t   nevents_anc      = nevents;    
01411 
01412       if( last_taken_event > (nentries - 1) )
01413         {
01414           nevents = nentries - nfirst -1;
01415           if (fFlagPrint != fCodePrintNoComment){
01416             cout << endl << "!TCnaRunEB::GetReadyToReadData(...)> WARNING/CORRECTION:" << endl
01417                  << "! The number of events (nevents = " << nevents_anc << ") is too large." << endl
01418                  << "! Number of last event = nfirst + nevents - 1 = " << nfirst << " + " << nevents_anc
01419                  << " - 1 = " << last_taken_event << " > number of entries - 1 = " << nentries-1 << ". "
01420                  << endl << "! Number of events forced to the value: nb of events ="
01421                  << " nb of entries - first event number - 1 = "
01422                  << nevents << "." << endl
01423                  << "! WARNING ===> THIS MODIFICATION WILL BE TRANSFERED TO THE RESULT FILE NAME"
01424                  << " (ROOT and ASCII FILES)."
01425                  << fTTBELL << endl << endl;}
01426         }
01427       
01428       //-----------------------------------------------------------------------------
01429  
01430       Text_t *h_name  = "CnaHeader";   //==> voir cette question avec FXG
01431       Text_t *h_title = "CnaHeader";   //==> voir cette question avec FXG
01432 
01433       TEBParameters* MyEcal = new TEBParameters();  fCnew++;
01434       Int_t n_tow  = MyEcal->fMaxTowInSM;
01435       Int_t n_crys = MyEcal->fMaxCrysInTow;
01436       Int_t n_samp = MyEcal->fMaxSampADC; 
01437       delete MyEcal;                                  fCdelete++;
01438 
01439       if ( n_tow > 0  &&  n_crys > 0  &&  n_samp> 0 ) 
01440         {
01441           fFileHeader = new TCnaHeaderEB(h_name,       h_title ,
01442                                          typ_ana,      run_number,  nfirst,    nevents,
01443                                          super_module, nentries);
01444           
01445           // After this call to TCnaHeaderEB, we have:
01446           //     fFileHeader->fTypAna        = typ_ana
01447           //     fFileHeader->fRunNumber     = run_number
01448           //     fFileHeader->fFirstEvt      = nfirst
01449           //     fFileHeader->fNbOfTakenEvts = nevents
01450           //     fFileHeader->fSuperModule   = super_module
01451           //     fFileHeader->fNentries      = nentries
01452           
01453           // fFileHeader->Print();
01454 
01455           // {Int_t cintoto; cout << "taper 0 pour continuer" << endl; cin >> cintoto;}
01456           
01457           //  fFileHeader->SetName("CnaHeader");              *======> voir FXG
01458           //  fFileHeader->SetTitle("CnaHeader");
01459           
01460           //......................................... allocation tags + init of them
01461           
01462           fTagTowerNumbers    = new Int_t[1]; fCnew++; fTagTowerNumbers[0]    = (Int_t)0;
01463           fTagLastEvtNumber   = new Int_t[1]; fCnew++; fTagLastEvtNumber[0]   = (Int_t)0;
01464           fTagEvtNbInLoop     = new Int_t[1]; fCnew++; fTagEvtNbInLoop[0]     = (Int_t)0;
01465 
01466           fTagSampTime        = new Int_t[fFileHeader->fMaxCrysInSM]; fCnew++;
01467           for (Int_t iz=0; iz<fFileHeader->fMaxCrysInSM; iz++){fTagSampTime[iz] = (Int_t)0;}
01468 
01469           fTagEv              = new Int_t[1]; fCnew++; fTagEv[0]              = (Int_t)0;
01470           fTagVar             = new Int_t[1]; fCnew++; fTagVar[0]             = (Int_t)0;
01471  
01472           fTagEvts            = new Int_t[fFileHeader->fMaxCrysInSM]; fCnew++;
01473           for (Int_t iz=0; iz<fFileHeader->fMaxCrysInSM; iz++){fTagEvts[iz]   = (Int_t)0;}
01474 
01475           fTagCovCss          = new Int_t[fFileHeader->fMaxCrysInSM]; fCnew++;
01476           for (Int_t iz=0; iz<fFileHeader->fMaxCrysInSM; iz++){fTagCovCss[iz] = (Int_t)0;}
01477 
01478           fTagCorCss          = new Int_t[fFileHeader->fMaxCrysInSM]; fCnew++;
01479           for (Int_t iz=0; iz<fFileHeader->fMaxCrysInSM; iz++){fTagCorCss[iz] = (Int_t)0;}
01480 
01481           fTagCovScc          = new Int_t[fFileHeader->fMaxSampADC];  fCnew++;
01482           for (Int_t iz=0; iz<fFileHeader->fMaxSampADC; iz++){fTagCovScc[iz]  = (Int_t)0;}
01483 
01484           fTagCorScc          = new Int_t[fFileHeader->fMaxSampADC];  fCnew++; 
01485           for (Int_t iz=0; iz<fFileHeader->fMaxSampADC; iz++){fTagCorScc[iz]  = (Int_t)0;}
01486 
01487           fTagCovSccMos       = new Int_t[1]; fCnew++;     fTagCovSccMos[0]    = (Int_t)0;
01488           fTagCorSccMos       = new Int_t[1]; fCnew++;     fTagCorSccMos[0]    = (Int_t)0;
01489           fTagCovMosccMot     = new Int_t[1]; fCnew++;     fTagCovMosccMot[0]  = (Int_t)0;
01490           fTagCorMosccMot     = new Int_t[1]; fCnew++;     fTagCorMosccMot[0]  = (Int_t)0;
01491 
01492           fTagEvEv            = new Int_t[1]; fCnew++;     fTagEvEv[0]         = (Int_t)0;
01493           fTagEvSig           = new Int_t[1]; fCnew++;     fTagEvSig[0]        = (Int_t)0;
01494           fTagEvCorCss        = new Int_t[1]; fCnew++;     fTagEvCorCss[0]     = (Int_t)0; 
01495 
01496           fTagSigEv           = new Int_t[1]; fCnew++;     fTagSigEv[0]        = (Int_t)0; 
01497           fTagSigSig          = new Int_t[1]; fCnew++;     fTagSigSig[0]       = (Int_t)0; 
01498           fTagSigCorCss       = new Int_t[1]; fCnew++;     fTagSigCorCss[0]    = (Int_t)0; 
01499 
01500           fTagSvCorrecCovCss  = new Int_t[1]; fCnew++;     fTagSvCorrecCovCss[0]        = (Int_t)0; 
01501 
01502           fTagCovCorrecCovCss = new Int_t[fFileHeader->fMaxCrysInSM]; fCnew++;
01503            for (Int_t iz=0; iz<fFileHeader->fMaxCrysInSM; iz++){fTagCovCorrecCovCss[iz] = (Int_t)0;}
01504 
01505           fTagCorCorrecCovCss = new Int_t[fFileHeader->fMaxCrysInSM]; fCnew++;
01506            for (Int_t iz=0; iz<fFileHeader->fMaxCrysInSM; iz++){fTagCorCorrecCovCss[iz] = (Int_t)0;}
01507 
01508           //====================================================================================
01509           //
01510           //   allocation for fT1d_SMtowFromIndex[] and init to fSpecialSMTowerNotIndexed
01511           //
01512           //====================================================================================
01513 
01514           if(fT1d_SMtowFromIndex == 0)
01515             {
01516               fT1d_SMtowFromIndex = new Int_t[fFileHeader->fMaxTowInSM];          fCnew++;
01517             }
01518           for ( Int_t i_tow = 0; i_tow < fFileHeader->fMaxTowInSM; i_tow++ )
01519             {
01520               fT1d_SMtowFromIndex[i_tow] = fSpecialSMTowerNotIndexed;
01521             }
01522           
01523           //------------------------------------------------------------------
01524           
01525           //====================================================================================
01526           //
01527           //   allocation of the 3D array fT3d_distribs[channel][sample][events] (ADC values)
01528           //
01529           //   This array is filled in the BuildEventDistributions(...) method
01530           //
01531           //====================================================================================
01532           
01533           if(fT3d_distribs == 0)
01534             {
01535               //............ Allocation for the 3d array 
01536               fT3d_distribs   =
01537                 new Double_t**[fFileHeader->fMaxCrysInSM];                         fCnew++;  
01538               fT3d2_distribs  =
01539                 new  Double_t*[fFileHeader->fMaxCrysInSM*
01540                                fFileHeader->fMaxSampADC];                          fCnew++;  
01541               fT3d1_distribs  =
01542                 new   Double_t[fFileHeader->fMaxCrysInSM*
01543                                fFileHeader->fMaxSampADC*
01544                                fFileHeader->fNbOfTakenEvts];                       fCnew++;
01545               
01546               for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++){
01547                 fT3d_distribs[i_SMEcha] = &fT3d2_distribs[0] + i_SMEcha*fFileHeader->fMaxSampADC;
01548                 for(Int_t j_samp = 0 ; j_samp < fFileHeader->fMaxSampADC ; j_samp++){
01549                   fT3d2_distribs[fFileHeader->fMaxSampADC*i_SMEcha + j_samp] = &fT3d1_distribs[0]+
01550                     fFileHeader->fNbOfTakenEvts*(fFileHeader->fMaxSampADC*i_SMEcha+j_samp);}}
01551             }
01552           
01553           //................................. Init to zero
01554           for (Int_t iza=0; iza<fFileHeader->fMaxCrysInSM; iza++)
01555             {
01556               for (Int_t izb=0; izb<fFileHeader->fMaxSampADC; izb++)
01557                 {
01558                   for (Int_t izc=0; izc<fFileHeader->fNbOfTakenEvts; izc++)
01559                     {
01560                       if( fT3d_distribs[iza][izb][izc] != (Double_t)0 )
01561                         {
01562                           fMiscDiag[0]++;
01563                           fT3d_distribs[iza][izb][izc] = (Double_t)0;
01564                         }
01565                     }
01566                 }
01567             }     
01568           
01569           //====================================================================================
01570           //
01571           //   allocation of the 2D array fT2d_LastEvtNumber[channel][sample] (Max nb of evts)
01572           //
01573           //====================================================================================
01574           
01575           if (fT2d_LastEvtNumber == 0)
01576             {
01577               fT2d_LastEvtNumber  = new Int_t*[fFileHeader->fMaxCrysInSM];           fCnew++;
01578               fT1d_LastEvtNumber  = new  Int_t[fFileHeader->fMaxCrysInSM*
01579                                                fFileHeader->fMaxSampADC];            fCnew++;
01580               
01581               for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
01582                 {
01583                   fT2d_LastEvtNumber[i_SMEcha] =
01584                     &fT1d_LastEvtNumber[0] + i_SMEcha*fFileHeader->fMaxSampADC;
01585                 }
01586               
01587               //................ Init the array to -1
01588               for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
01589                 {
01590                   for(Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC ; i_samp++)
01591                     {
01592                       fT2d_LastEvtNumber[i_SMEcha][i_samp] = -1;
01593                     }
01594                 }
01595             }
01596           else
01597             {
01598               cerr << "!TCnaRunEB::GetReadyToReadData(...)> *** ERROR *** No allocation for fT2d_LastEvtNumber!"
01599                    << " Pointer already not NULL " << fTTBELL << endl;
01600               {Int_t cintoto; cout << "Enter: 0 and RETURN to continue or: CTRL C to exit"
01601                                    << endl; cin >> cintoto;}
01602             }
01603           
01604           //========================================================================================
01605           //
01606           //   allocation of the 2D array fT2d_EvtNbInLoop[tower][cna evt number] (evt nb in loop)
01607           //
01608           //========================================================================================
01609           
01610           if (fT2d_EvtNbInLoop == 0)
01611             {
01612               fT2d_EvtNbInLoop  = new Int_t*[fFileHeader->fMaxTowInSM];          fCnew++;
01613               fT1d_EvtNbInLoop  = new  Int_t[fFileHeader->fMaxTowInSM*
01614                                              fFileHeader->fNbOfTakenEvts];       fCnew++;
01615               
01616               for(Int_t i_tow = 0 ; i_tow < fFileHeader->fMaxTowInSM ; i_tow++)
01617                 {
01618                   fT2d_EvtNbInLoop[i_tow] =
01619                     &fT1d_EvtNbInLoop[0] + i_tow*fFileHeader->fNbOfTakenEvts;
01620                 }
01621               
01622               //................ init the array to -1
01623               for(Int_t i_tow = 0 ; i_tow < fFileHeader->fMaxTowInSM ; i_tow++)
01624                 {
01625                   for(Int_t i_cna_evt = 0 ; i_cna_evt < fFileHeader->fNbOfTakenEvts ; i_cna_evt++)
01626                     {
01627                       fT2d_EvtNbInLoop[i_tow][i_cna_evt] = -1;
01628                     }
01629                 }             
01630             }
01631           else
01632             {
01633               cerr << "!TCnaRunEB::GetReadyToReadData(...)> *** ERROR *** No allocation for fT2d_EvtNbInLoop!"
01634                    << " Pointer already not NULL " << fTTBELL << endl;
01635               {Int_t cintoto; cout << "Enter: 0 and RETURN to continue or: CTRL C to exit"
01636                                    << endl; cin >> cintoto;}
01637             }
01638         }
01639       else
01640         {
01641           cerr << endl
01642                << "!TCnaRunEB::GetReadyToReadData(...)> "
01643                << " *** ERROR *** " << endl
01644                << " --------------------------------------------------"
01645                << endl
01646                << " NULL or NEGATIVE values for arguments" << endl
01647                << " with expected positive values:"        << endl
01648                << " Number of towers in SuperModule = " << fFileHeader->fMaxTowInSM  << endl
01649                << " Number of crystals in tower     = " << fFileHeader->fMaxCrysInTow << endl
01650                << " Number of samples by channel    = " << fFileHeader->fMaxSampADC << endl
01651                << endl
01652                << endl
01653                << " hence, no memory allocation for array member has been performed." << endl;
01654           
01655           cout << "Enter: 0 and RETURN to continue or: CTRL C to exit";
01656           Int_t toto;
01657           cin >> toto;
01658         }
01659 
01660       
01661       //    CI-DESSOUS: REPRENDRE LES VALEURS NUMERIQUES  A PARTIR DE TEBParameters
01662 
01663       //#####################################################################################
01664       //
01665       //..................... (for ASCII files writing methods only) ..............
01666       //
01667       //                DEFINITION OF THE SECTOR SIZES
01668       //       FOR THE CORRELATION AND COVARIANCE MATRICES DISPLAY
01669       //
01670       //            MUST BE A DIVISOR OF THE TOTAL NUMBER.
01671       //            ======================================
01672       //
01673       //     Examples:
01674       //      
01675       //      (1)       25 channels => size = 25 or 5 (divisors of 25)
01676       //
01677       //                25 => matrix = 1 x 1 sector  of size (25 x 25)
01678       //                             = (1 x 1) x (25 x 25) = 1 x 625 = 625 
01679       //                 5 => matrix = 5 x 5 sectors of size (5 x 5)
01680       //                             = (5 x 5) x ( 5 x  5) = 25 x 25 = 625 
01681       //
01682       //      (2)       10 samples  => size = 10, 5 or 2 (divisors of 10)
01683       //
01684       //                10 => matrix = 1 X 1 sectors of size (10 x 10) 
01685       //                             = (1 x 1) x (10 x 10) =  1 x 100 = 100
01686       //                 5 => matrix = 2 x 2 sectors of size (5 x 5) 
01687       //                             = (2 x 2) x ( 5 x  5) =  4 x  25 = 100
01688       //                 2 => matrix = 5 x 5 sectors of size (2 x 2) 
01689       //                             = (5 x 5) x ( 2 x  2) = 25 x  4  = 100
01690       //
01691       //........................................................................
01692       fSectChanSizeX = 5;      // => 25 crystals by tower
01693       fSectChanSizeY = 5;
01694       fSectSampSizeX = 10;      // test beam Nov 2004 => 10 samples
01695       fSectSampSizeY = 10;
01696       
01697       //........................................................................
01698       //
01699       //                DEFINITION OF THE NUMBER OF VALUES BY LINE
01700       //                for the Expectation Values, Variances and.
01701       //                Event distributions by (channel,sample)
01702       //
01703       //               MUST BE A DIVISOR OF THE TOTAL NUMBER.
01704       //               ======================================
01705       //
01706       //     Examples: 
01707       //                1) For expectation values and variances:
01708       //
01709       //                25 channels => size = 5
01710       //                => sample sector = 5 lines of 5 values
01711       //                                 = 5 x 5 = 25 values 
01712       //
01713       //                10 samples  => size = 10
01714       //                => channel sector = 1 lines of 10 values
01715       //                                  = 1 x 10 = 10 values
01716       //
01717       //                2) For event distributions:
01718       //
01719       //                100 bins  => size = 10
01720       //                => sample sector = 10 lines of 10 values
01721       //                                 = 10 x 10 = 100 values
01722       //
01723       //........................................................................
01724       fNbChanByLine = 5;   // => 25 crystals by tower
01725       fNbSampByLine = 10;  // => 10 samples     
01726       
01727       //.............. (for ASCII files writing methods - END - ) ..................
01728     }
01729   else
01730     {
01731       cout << "!TCnaRunEB::GetReadyToReadData(...) *** ERROR ***> "
01732            << " The first taken event number is greater than the number of entries - 1."
01733            << fTTBELL << endl;
01734     }
01735   
01736   if(fFlagPrint == fCodePrintAllComments || fFlagPrint == fCodePrintComments ){
01737     cout << endl;
01738     cout << "*TCnaRunEB::GetReadyToReadData(...)>" << endl
01739          << "          The method has been called with the following argument values:"  << endl
01740          << "          Analysis name          = "
01741          << fFileHeader->fTypAna << endl
01742          << "          Run number             = "
01743          << fFileHeader->fRunNumber << endl
01744          << "          Number of entries      = "
01745          << fFileHeader->fNentries << endl
01746          << "          First taken event      = "
01747          << fFileHeader->fFirstEvt << endl
01748          << "          Number of taken events = "
01749          << fFileHeader->fNbOfTakenEvts << endl
01750          << "          SuperModule number     = "
01751          << fFileHeader->fSuperModule << endl
01752          << "          Number of towers in SM = "
01753          << fFileHeader->fMaxTowInSM   << endl
01754          << "          Number of crystals in tower  = "
01755          << fFileHeader->fMaxCrysInTow  << endl
01756          << "          Number of samples by channel = "
01757          << fFileHeader->fMaxSampADC  << endl
01758          << endl;}
01759 
01760   fReadyToReadData = 1;                        // set flag
01761 
01762   if(fFlagPrint == fCodePrintAllComments){
01763     cout << "*TCnaRunEB::GetReadyToReadData(...)> Leaving the method"
01764          << endl; }
01765 } // end of GetReadyToReadData
01766 
01767 //====================================================================================================
01768 //
01769 //                  Building of the arrays for CNA
01770 //    (tower number <-> tower index correspondance, ADC sample values)
01771 //
01772 //        THIS METHOD IS CALLED INSIDE THE LOOPS OVER:
01773 //          ( EVENTS (TOWERS (CRYSTAL IN TOWER (SAMPLES)))) 
01774 //
01775 //  Arguments: ievent   = event number.                Range = [ 0, fFileHeader->fNbOfTakenEvts - 1 ]
01776 //             SMtower  = tower number in SuperModule. Range = [ 1, fFileHeader->fMaxTowInSM ]
01777 //             TowEcha  = channel number in tower.     Range = [ 0, fFileHeader->fMaxCrysInTow - 1 ]     
01778 //             sample   = ADC sample number.           Range = [ 0, fFileHeader->fMaxSampADC - 1 ]
01779 //             adcvalue = ADC sample value.
01780 //
01781 //====================================================================================================
01782 Bool_t TCnaRunEB::BuildEventDistributions(const Int_t&    ievent,   const Int_t& SMtower,
01783                                         const Int_t&    TowEcha,  const Int_t& sample,
01784                                         const Double_t& adcvalue)
01785 {
01786   //Building of the arrays fT1d_SMtowFromIndex[] and fT3d_distribs[][][]
01787   
01788   Bool_t ret_code = kFALSE;
01789   Int_t  i_SMtow  = SMtower-1;  // INDEX FOR SMTower = Number_of_the_tower_in_SM - 1
01790   Int_t  i_trouve = 0;
01791 
01792   if(fReadyToReadData == 1)  
01793     {
01794       if( SMtower>= 1 && SMtower <= fFileHeader->fMaxTowInSM )
01795         {      
01796           if( TowEcha >= 0 && TowEcha < fFileHeader->fMaxCrysInTow )
01797             {
01798               if( sample >= 0 && sample < fFileHeader->fMaxSampADC )
01799                 {
01800                   //..... Put the SMtower number in 1D array fT1d_SMtowFromIndex[] = tower index + 1
01801                   if(fT1d_SMtowFromIndex != 0)       // table fT1d_SMtowFromIndex[index] already allocated
01802                     {
01803                       ret_code = kTRUE;
01804 
01805                       // SMtower already indexed
01806                       if( SMtower == fT1d_SMtowFromIndex[i_SMtow] )
01807                         {
01808                           i_trouve = 1;
01809                         }
01810                   
01811                       // SMtower index not found: new SMtower
01812                       if (i_trouve != 1 )
01813                         {
01814                           if ( fT1d_SMtowFromIndex[i_SMtow] == fSpecialSMTowerNotIndexed )
01815                             {
01816                               fT1d_SMtowFromIndex[i_SMtow] = SMtower;
01817                               fFileHeader->fTowerNumbersCalc = 1;
01818                               fTagTowerNumbers[0] = 1;
01819                               fTowerIndexBuilt++;                      //  number of found towers
01820                           
01821                               if(fFlagPrint == fCodePrintAllComments || fFlagPrint == fCodePrintComments){
01822                                 cout << "*TCnaRunEB::BuildEventDistributions(...)> event " << ievent
01823                                      << " : first event for tower " << fT1d_SMtowFromIndex[i_SMtow]
01824                                      << " (" << fTowerIndexBuilt << " towers found)" << endl;}
01825                               ret_code = kTRUE;
01826                             }
01827                           else
01828                             {
01829                               cout << "!TCnaRunEB::BuildEventDistributions(...)> *** ERROR ***> IMPOSSIBILITY. " 
01830                                    << " SMtower= " << SMtower << ", fT1d_SMtowFromIndex[" << i_SMtow << "] = "
01831                                    << fT1d_SMtowFromIndex[i_SMtow]
01832                                    << ", fTowerIndexBuilt = " << fTowerIndexBuilt
01833                                    << fTTBELL << endl;
01834                               ret_code = kFALSE;
01835                             }
01836                         }
01837                     }
01838                   else
01839                     {
01840                       cout << "!TCnaRunEB, BuildEventDistributions *** ERROR ***> "
01841                            << " fT1d_SMtowFromIndex = " << fT1d_SMtowFromIndex
01842                            << " fT1d_SMtowFromIndex[] ALLOCATION NOT DONE" << fTTBELL << endl;
01843                       ret_code = kFALSE;
01844                     }
01845                 }
01846               else
01847                 {
01848                   cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> "
01849                        << " sample number = " << sample << ". OUT OF BOUNDS"
01850                        << " (max = " << fFileHeader->fMaxSampADC << ")"
01851                        << fTTBELL << endl;
01852                   ret_code = kFALSE;
01853                 }
01854             }
01855           else
01856             {
01857               cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> "
01858                    << " TowEcha number = " << TowEcha << ". OUT OF BOUNDS"
01859                    << " (max = " << fFileHeader->fMaxCrysInTow << ")"
01860                    << fTTBELL << endl;
01861               ret_code = kFALSE;
01862             }
01863         }
01864       else
01865         {
01866           cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> "
01867                << " SMtower number = " << SMtower << ". OUT OF BOUNDS"
01868                << " (max = " << fFileHeader->fMaxTowInSM << ")"
01869                << fTTBELL << endl;
01870           ret_code = kFALSE;
01871         }
01872 
01873       //........ Filling of the 2D array of the event numbers in the data reading loop and 
01874       //         filling of the 3D array of the ADC sample values
01875 
01876       if( ret_code == kTRUE )
01877         {
01878           //............ 1) Conversion (tower,TowEcha) -> SMEcha
01879           Int_t SMEcha = i_SMtow*fFileHeader->fMaxCrysInTow + TowEcha;
01880           
01881           if( SMEcha >= 0 && SMEcha < fFileHeader->fMaxCrysInSM )
01882             {
01883               //............ 2) Increase of the nb of evts for (SMEcha,sample)
01884               (fT2d_LastEvtNumber[SMEcha][sample])++;     // value after first incrementation = 0
01885               fTagLastEvtNumber[0] = 1;
01886               fFileHeader->fLastEvtNumberCalc = 1;
01887               //if(fBuildEvtDistrib == 0){fBuildEvtDistrib = 1;} // set flag of building
01888               
01889               //............ 3) Filling of the array fT2d_EvtNbInLoop[tower][cna event number]
01890               Int_t k_event = fT2d_LastEvtNumber[SMEcha][sample];
01891 
01892               if ( k_event >= 0 && k_event < fFileHeader->fNbOfTakenEvts )
01893                 { 
01894                   fT2d_EvtNbInLoop[i_SMtow][k_event] = ievent;
01895                 }
01896               else
01897                 {
01898                   cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> "
01899                        << " last event number = " << k_event << ". OUT OF BOUNDS"
01900                        << " (range = [0," << fFileHeader->fNbOfTakenEvts-1
01901                        << "]). Channel# = " << SMEcha << ", sample = " << sample
01902                        << fTTBELL << endl;
01903                   ret_code = kFALSE;
01904                 }
01905               fTagEvtNbInLoop[0] = 1;
01906               fFileHeader->fEvtNbInLoopCalc = 1;
01907               
01908               //............ 4) Filling of the 3D array of the ADC values
01909               if ( ievent >= 0 && ievent < fFileHeader->fNbOfTakenEvts )
01910                 {  
01911                   fT3d_distribs[SMEcha][sample][ievent] = adcvalue;
01912                 }
01913               else
01914                 {
01915                   cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> "
01916                        << " event number = " << ievent << ". OUT OF BOUNDS"
01917                        << " (max = " << fFileHeader->fNbOfTakenEvts << ")"
01918                        << fTTBELL << endl;
01919                   ret_code = kFALSE;
01920                 }
01921             }
01922           else
01923             {
01924               cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> "
01925                    << " CHANNEL NUMBER OUT OF BOUNDS" << endl
01926                    << " SMEcha number = " << SMEcha
01927                    << " , SMtower = " << SMtower
01928                    << " , TowEcha = " << TowEcha
01929                    << " , fFileHeader->fMaxCrysInSM = " << fFileHeader->fMaxCrysInSM 
01930                    << fTTBELL << endl; 
01931               ret_code = kFALSE;
01932               // {Int_t cintoto; cout << "TAPER 0 POUR CONTINUER" << endl; cin >> cintoto;}
01933             }
01934         }
01935       else
01936         {
01937           cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> ret_code = kFALSE "
01938                << fTTBELL << endl;
01939         }
01940     }
01941   else
01942     {
01943       cout << "!TCnaRunEB::BuildEventDistributions(...) *** ERROR ***> GetReadyToReadData(...) not called."
01944            << fTTBELL << endl;
01945       ret_code = kFALSE;
01946     }
01947 
01948   if (ret_code == kFALSE)
01949     {
01950       cout << "*> ievent: " << ievent
01951            << ", SMtower: " << SMtower
01952            << ", TowEcha: " << TowEcha
01953            << ", sample: "  << sample
01954            << ", adcvalue: " << adcvalue << endl;
01955     } 
01956 
01957   return ret_code;
01958 }
01959 //###################################################################################################
01960 //
01961 // THE FOLLOWING METHODS ARE CALLED AFTER THE LOOPS OVER EVENTS, TOWERS, CRYSTALS AND SAMPLES
01962 //
01963 //###################################################################################################
01964 
01965 //=========================================================================
01966 //
01967 //                         GetReadyToCompute()
01968 //          Building of the TDistrib objects for CNA calculations
01969 //
01970 //=========================================================================
01971 void TCnaRunEB::GetReadyToCompute()
01972 {
01973 //Building of the TDistrib objects for CNA calculations
01974 
01975   //----------------------------------------------------------------------
01976   //
01977   //       recuperation des valeurs et mise dans les objets
01978   //       "distributions d'evenements"  ( classe TDistrib )
01979   //
01980   //  fT3d_distribs[SMEcha][sample][event] -> fVal_Data[SMEcha][sample]
01981   //
01982   //----------------------------------------------------------------------  
01983 
01984 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
01985    if(fFlagPrint == fCodePrintAllComments)
01986     { 
01987       cout << endl << "%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%"
01988            << endl << "*TCnaRunEB::GetReadyToCompute()> (this = " << this << ") " << endl;
01989     }
01990 #define TOBJ
01991 #ifndef TOBJ 
01992 
01993   //......... Essai utilisation TClonesArray --> NE MARCHE PAS ENCORE:
01994   //
01995   //TCnaRunEB.cxx: In method `void TCnaRunEB::GetReadyToCompute ()':
01996   //<internal>:1333: too many arguments to function `void *operator new 
01997   //(unsigned int)'
01998   //TCnaRunEB.cxx:1333: at this point in file
01999   // 1333 = ancien numero de la ligne ou il y a : new(fVal_dat2[i_new]) etc...
02000 
02001   Int_t maxichan = fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC;
02002   TObjArray fVal_dat2(maxichan);
02003   
02004   for (Int_t i_chan = 0 ; i_chan < fFileHeader->fMaxCrysInSM ; i_chan++)
02005     { 
02006       for (Int_t n_sampl = 0 ; n_sampl < fFileHeader->fMaxSampADC ; n_sampl++)
02007         {       
02008           Int_t i_new = (fFileHeader->fMaxSampADC)*i_chan + n_sampl;
02009           fVal_dat2[i_new] = new
02010             TDistrib(fFileHeader->fNbOfTakenEvts, fT3d2_distribs[i_new]);  fCnew++;
02011         }
02012     }
02013 
02014 #endif // TOBJ
02015 
02016 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
02017 
02018   //-------------------- declaration des objets fVal_data[][]
02019    
02020   //....................................................................
02021   //
02022   //    TDistrib = "distribution d'evenements" = objet comprenant:
02023   //
02024   //    (1) un nombre d'evenements (Int_t nmax) 
02025   //    (2) un tableau de valeurs de dimension le nombre
02026   //        d'evenements ( Double_t valeurs[nmax] ).
02027   //
02028   //    Il y a une distribution d'evenements par echantillon et par voie.
02029   //    On a donc un tableau 2d fVal_data[][] de distributions qu'on va
02030   //    initialiser ci-dessous a partir du tableau 3d
02031   //    fT3d_distribs[][][].
02032   //
02033   //    PS: on est oblige de passer par un objet temporaire (pdata_temp)
02034   //        pour pouvoir appeler le constructeur avec arguments et faire
02035   //        ensuite fVal_data[i_SMEcha][n_sampl] = pdata_temp;
02036   //        (utilisation de la surcharge de l'operateur=
02037   //         de la classe TDistrib)
02038   //......................................................................
02039   
02040   if(fFlagPrint == fCodePrintAllComments || fFlagPrint == fCodePrintComments ){
02041     cout << "*TCnaRunEB::GetReadyToCompute()> Starting TDistrib object allocations"
02042          << endl;}
02043   
02044   // !!!!! ALLOC DYNAMIQUE D'UN TABLEAU 2D d'objets de classe "TDistrib"
02045   //  alloc dynamique de fVal_data** ou fVal_data[d1][d2]
02046   //  sous forme de tableau 1D de valeurs fVal_dat2[d1xd2]
02047   //  et de tableau d'adresses 1D fVal_data[d1]  
02048   
02049   fVal_data = new TDistrib*[fFileHeader->fMaxCrysInSM];                          fCnew++; 
02050   fVal_dat2 = new  TDistrib[fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC]; fCnew++;
02051   
02052   // calcul des pointeurs du tableau 1D fVal_data[d1]    ( GetReadyToCompute() )
02053   
02054   for( Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++ )
02055     {
02056       fVal_data[i_SMEcha] = &fVal_dat2[0] + i_SMEcha*fFileHeader->fMaxSampADC;
02057     }
02058   
02059   // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      ( GetReadyToCompute() )
02060   
02061   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02062     { 
02063       for (Int_t n_sampl = 0 ; n_sampl < fFileHeader->fMaxSampADC ; n_sampl++)
02064         {       
02065           //.............. standard C++
02066           //      TDistrib  pdata_temp( fFileHeader->fNbOfTakenEvts,
02067           //            *((fT3d_distribs)+
02068           //              (fFileHeader->fMaxSampADC)*i_SMEcha +n_sampl) ); 
02069           
02070           //................  CINT-ROOT
02071 
02072           TDistrib*     pdata_temp =
02073             new TDistrib( fFileHeader->fNbOfTakenEvts,
02074                           fT3d2_distribs[(fFileHeader->fMaxSampADC)*i_SMEcha
02075                                          + n_sampl] );                           fCnew++;
02076           
02077           // Utilisation de la surcharge de l'operateur= de la classe TDistrib
02078           // fVal_data[i_SMEcha][n_sampl] = pdata_temp;  // standard C++
02079           
02080           fVal_data[i_SMEcha][n_sampl] = pdata_temp[0];  // CINT-ROOT
02081           delete pdata_temp;                fCdelete++;  // CINT-ROOT
02082         }
02083     }
02084 
02085   if(fFlagPrint == fCodePrintAllComments || fFlagPrint == fCodePrintComments ){
02086     cout << "*TCnaRunEB::GetReadyToCompute()> TDistrib object allocations done."
02087          << endl;}
02088 
02089 #define RESZ
02090 #ifndef RESZ
02091   //------------- Resize of the TDistrib fVal_data to the effective max nb of evts    ( GetReadyToCompute() )
02092   //
02093   //   Finally, no resize since it masks cases with wrong numbers of events
02094   //
02095   Int_t  nb_of_resize = 0;
02096   Bool_t ok_resize    = kFALSE;
02097 
02098   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02099     { 
02100       for (Int_t n_sampl = 0 ; n_sampl < fFileHeader->fMaxSampADC ; n_sampl++)
02101         {
02102           ok_resize = kFALSE;
02103           Int_t  nb_evts   = fT2d_LastEvtNumber[i_SMEcha][n_sampl]+1;
02104           ok_resize = fVal_data[i_SMEcha][n_sampl].Resize(nb_evts);
02105           if ( ok_resize == kTRUE ) {nb_of_resize++;}
02106         }
02107     }
02108 
02109   if (nb_of_resize != 0)
02110     {
02111       cout << "!TCnaRunEB::GetReadyToCompute()> " 
02112            << "INFO/warning =!=!=!=!=!=> a resize of TDistrib distribution has been done in "
02113            << nb_of_resize << " cases " << endl
02114            << "                               (could be due to incorrect numbers of events in data)"
02115            << fTTBELL << endl;
02116     }
02117   else
02118     {
02119       if(fFlagPrint == fCodePrintAllComments){
02120         cout << "!TCnaRunEB::GetReadyToCompute()> " 
02121              << "INFO =+=+=+=+=+=> TDistrib distributions: no resize has been done." << endl;}
02122     }
02123 
02124   //-----------------------------------------------------------------------------------------------
02125 #endif // RESZ
02126 
02127   // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
02128 }  
02129 //  end of GetReadyToCompute()
02130 
02131 //=========================================================================
02132 //
02133 //     Set start time, stop time, StartDate, StopDate
02134 //
02135 //=========================================================================
02136 void TCnaRunEB::StartStopTime(time_t t_startime, time_t t_stoptime)
02137 {
02138 // Put the start an stop time (if they exist) in class attributes.
02139 
02140   fFileHeader->fStartTime = t_startime;
02141   fFileHeader->fStopTime  = t_stoptime;
02142 }
02143 
02144 void TCnaRunEB::StartStopDate(TString c_startdate, TString c_stopdate)
02145 {
02146 // Put the start an stop date (if they exist) in class attributes.
02147 
02148   fFileHeader->fStartDate = c_startdate;
02149   fFileHeader->fStopDate  = c_stopdate;
02150 }
02151 
02152 //=========================================================================
02153 //
02154 //               C A L C U L A T I O N    M E T H O D S
02155 //
02156 //     fTag... => Calculation done. OK for writing on result file
02157 //     ...Calc => Incrementation for result file size. 
02158 //
02159 //=========================================================================
02160 //-------------------------------------------------------------------
02161 //
02162 //             Making of the histograms of the sample value
02163 //             as a funtion of the event number
02164 //             for all the pairs (SMEcha, samples)
02165 //
02166 //-------------------------------------------------------------------
02167 void TCnaRunEB::MakeHistosOfSamplesAsFunctionOfEvent()
02168 {
02169 //Making of the histograms of the sample value as a funtion of the event number
02170 //for all the pairs (SMEcha, samples)
02171 
02172   if(fFlagPrint == fCodePrintAllComments){
02173     cout << "*TCnaRunEB::MakeHistosOfSamplesAsFunctionOfEvent()>"
02174          << " Making of the histograms of the sample value as a funtion of"
02175          << " the event number for all the pairs (SMEcha, samples)" << endl;}
02176 
02177   // In fact, the histo is already in fT3d_distribs[][][fFileHeader->fNbOfTakenEvts]
02178   // this method sets only the "Tag" and increment the "Calc" (and must be kept for that)
02179 
02180   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02181     {
02182       fTagSampTime[i_SMEcha] = 1;        fFileHeader->fSampTimeCalc++;
02183     }
02184 }
02185 
02186 //----------------------------------------------------------------
02187 //
02188 //     Calculation of the expectation values of the samples
02189 //                 for all the SMEchas
02190 //
02191 //----------------------------------------------------------------
02192 
02193 void TCnaRunEB::ComputeExpectationValuesOfSamples()
02194 {
02195 //Calculation of the expectation values of the samples for all the SMEchas
02196 
02197   if(fFlagPrint == fCodePrintAllComments){
02198     cout << "*TCnaRunEB::ComputeExpectationValuesOfSamples()>"
02199          << " Calculation of the expectation values of the samples"
02200          << " for all the SMEchas" << endl;}
02201 
02202   //................... Allocation ev + init to zero
02203   if ( fT2d_ev == 0 ){
02204     Int_t n_samp = fFileHeader->fMaxSampADC;
02205     Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02206     fT2d_ev = new Double_t*[n_SMEcha];             fCnew++;  
02207     fT1d_ev = new  Double_t[n_SMEcha*n_samp];      fCnew++;   
02208     for(Int_t i = 0 ; i < n_SMEcha ; i++){
02209       fT2d_ev[i] = &fT1d_ev[0] + i*n_samp;}
02210   }
02211   
02212   for(Int_t i_SMEcha=0; i_SMEcha<fFileHeader->fMaxCrysInSM; i_SMEcha++)
02213     {
02214       for(Int_t i_samp=0; i_samp<fFileHeader->fMaxSampADC; i_samp++)
02215         {
02216           if( fT2d_ev[i_SMEcha][i_samp] != (Double_t)0 )
02217             {fMiscDiag[1]++; fT2d_ev[i_SMEcha][i_samp] = (Double_t)0;}
02218         } 
02219     }
02220   
02221   //................... Calculation
02222   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02223     {
02224       for (Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC ; i_samp++)
02225         {         
02226           fT2d_ev[i_SMEcha][i_samp] = 
02227             ((fVal_data)[i_SMEcha][i_samp]).ExpectationValue();
02228         }
02229     }
02230   fTagEv[0] = 1;        fFileHeader->fEvCalc++;
02231 }
02232 
02233 //--------------------------------------------------------
02234 //
02235 //      Calculation of the variances of the samples
02236 //                 for all the SMEchas
02237 //
02238 //--------------------------------------------------------
02239   
02240 void TCnaRunEB::ComputeVariancesOfSamples() 
02241 {
02242 //Calculation of the variances of the samples for all the SMEchas
02243   
02244   if(fFlagPrint == fCodePrintAllComments){
02245     cout << "*TCnaRunEB::ComputeVariancesOfSamples()>"
02246          << " Calculation of the variances of the samples"
02247          << " for all the SMEchas" << endl;}
02248   
02249   //................... Allocation var + init to zero
02250   if( fT2d_var == 0){
02251     Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02252     Int_t n_samp = fFileHeader->fMaxSampADC;
02253     fT2d_var = new Double_t*[n_SMEcha];                fCnew++;        
02254     fT1d_var = new  Double_t[n_SMEcha*n_samp];         fCnew++;  
02255     for(Int_t i_SMEcha = 0 ; i_SMEcha < n_SMEcha ; i_SMEcha++){
02256       fT2d_var[i_SMEcha] = &fT1d_var[0] + i_SMEcha*n_samp;}
02257   }
02258   
02259   for(Int_t i_SMEcha=0; i_SMEcha<fFileHeader->fMaxCrysInSM; i_SMEcha++)
02260     {
02261       for(Int_t i_samp=0; i_samp<fFileHeader->fMaxSampADC; i_samp++)
02262         {
02263           if( fT2d_var[i_SMEcha][i_samp] != (Double_t)0 )
02264             {fMiscDiag[2]++; fT2d_var[i_SMEcha][i_samp] = (Double_t)0;}
02265         } 
02266     }
02267   
02268   //................... Calculation
02269   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02270     {
02271       for (Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC ; i_samp++)
02272         {
02273           fT2d_var[i_SMEcha][i_samp] = 
02274             fVal_data[i_SMEcha][i_samp].VarianceValue();
02275         }
02276     }
02277   fTagVar[0] = 1;        fFileHeader->fVarCalc++;
02278 }
02279 
02280 //-------------------------------------------------------------------
02281 //
02282 //             Making of the histograms of the ADC distributions
02283 //             for all the pairs (SMEcha, samples)
02284 //
02285 //-------------------------------------------------------------------
02286 
02287 void TCnaRunEB::MakeHistosOfSampleDistributions()
02288 {
02289 //Histograms of the ADC distributions for all the pairs (SMEcha,sample)
02290 
02291   if(fFlagPrint == fCodePrintAllComments){
02292     cout << "*TCnaRunEB::MakeHistosOfSampleDistributions()>"
02293          << " Histograms of ADC distributions for all the pairs (SMEcha,sample)"
02294          << endl;}
02295 
02296   //................... Allocation his_s + init to zero
02297 
02298   if (fT3d_his_s == 0 )
02299     {
02300       //............ Allocation fT3d_his_s 
02301       fT3d_his_s = new Double_t**[fFileHeader->fMaxCrysInSM];                          fCnew++;   
02302       fT2d_his_s = new  Double_t*[fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC]; fCnew++;   
02303       fT1d_his_s = new   Double_t[fFileHeader->fMaxCrysInSM*
02304                                   fFileHeader->fMaxSampADC*
02305                                   fFileHeader->fNbBinsADC];                            fCnew++;
02306 
02307       for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++){
02308           fT3d_his_s[i_SMEcha] = &fT2d_his_s[0] + i_SMEcha*fFileHeader->fMaxSampADC;
02309           for(Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++){
02310             fT2d_his_s[i_SMEcha*fFileHeader->fMaxSampADC + i_samp] = &fT1d_his_s[0]
02311               + (i_SMEcha*fFileHeader->fMaxSampADC + i_samp)*fFileHeader->fNbBinsADC;}}
02312     }
02313 
02314   for(Int_t i_SMEcha=0; i_SMEcha<fFileHeader->fMaxCrysInSM; i_SMEcha++)
02315     {
02316       for(Int_t i_samp=0; i_samp<fFileHeader->fMaxSampADC; i_samp++)
02317         {
02318           for(Int_t i_bin=0; i_bin<fFileHeader->fNbBinsADC; i_bin++)
02319             {
02320               if( fT3d_his_s[i_SMEcha][i_samp][i_bin] != (Double_t)0 )
02321                 {fMiscDiag[3]++; fT3d_his_s[i_SMEcha][i_samp][i_bin] = (Double_t)0;}
02322             }
02323         } 
02324     }
02325   
02326   //.................................. Allocations xmin, xmax + init to zero
02327   if( fT1d_xmin == 0 )
02328     {
02329       fT2d_xmin = new Double_t*[fFileHeader->fMaxCrysInSM];                           fCnew++;
02330       fT1d_xmin = new  Double_t[fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC];  fCnew++;
02331       for (Int_t i1 = 0; i1 < fFileHeader->fMaxCrysInSM; i1++){
02332         fT2d_xmin[i1] = &fT1d_xmin[0] + i1*fFileHeader->fMaxSampADC;}
02333     }
02334   
02335   if( fT1d_xmax == 0 )
02336     {
02337       fT2d_xmax = new Double_t*[fFileHeader->fMaxCrysInSM];                           fCnew++;
02338       fT1d_xmax = new  Double_t[fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC];  fCnew++;
02339       for (Int_t i1 = 0; i1 < fFileHeader->fMaxCrysInSM; i1++){
02340         fT2d_xmax[i1] = &fT1d_xmax[0] + i1*fFileHeader->fMaxSampADC;}
02341     } 
02342   
02343   for(Int_t i_SMEcha=0; i_SMEcha<fFileHeader->fMaxCrysInSM; i_SMEcha++)
02344     {
02345       for(Int_t i_samp=0; i_samp<fFileHeader->fMaxSampADC; i_samp++)
02346         {
02347           if( fT2d_xmin[i_SMEcha][i_samp] != (Double_t)0 )
02348             {fMiscDiag[4]++; fT2d_xmin[i_SMEcha][i_samp] = (Double_t)0;}
02349  
02350           if( fT2d_xmax[i_SMEcha][i_samp] != (Double_t)0 )
02351             {fMiscDiag[5]++; fT2d_xmax[i_SMEcha][i_samp] = (Double_t)0;}  
02352         } 
02353     }
02354   
02355   Double_t xmin = 0;
02356   Double_t xmax = 0;
02357 
02358   //............. alloc dynamique de s_histo + init to zero
02359   Double_t*  s_histo = new Double_t[fFileHeader->fNbBinsADC];  fCnew++;  
02360   for(Int_t i_bin=0; i_bin<fFileHeader->fNbBinsADC; i_bin++)
02361     {
02362       if( s_histo[i_bin] != (Double_t)0 ){fMiscDiag[6]++; s_histo[i_bin] = (Double_t)0;}
02363     }
02364 
02365   Int_t total_underflow = 0;
02366   Int_t total_overflow  = 0;
02367 
02368   Int_t nb_null_sample_chan = 0;
02369   Int_t nb_null_sample_all  = 0;
02370 
02371   TEBNumbering* MyNumbering = new TEBNumbering();            fCnew++;
02372 
02373   for (Int_t SMEcha = 0; SMEcha < fFileHeader->fMaxCrysInSM; SMEcha++)
02374     {
02375       Int_t n_underflow = 0;
02376       Int_t n_overflow  = 0;
02377       Int_t nb_null_sample_cases = 0;
02378       
02379       for (Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC; i_samp++)
02380         {
02381           Int_t range_null = 0;
02382           ((fVal_data)[SMEcha][i_samp]).
02383             HistoDistrib(fFileHeader->fNbBinsADC, xmin, xmax,
02384                          &s_histo[0], range_null, n_underflow, n_overflow);
02385 
02386           if ( n_underflow !=0 ){total_underflow++;}
02387           if ( n_overflow  !=0 ){total_overflow++;}
02388  
02389           if (range_null != 0 )
02390             {
02391               nb_null_sample_cases++;
02392               nb_null_sample_all++;
02393             }
02394 
02395           fT2d_xmin[SMEcha][i_samp]= xmin;
02396           fT2d_xmax[SMEcha][i_samp]= xmax;
02397           
02398           for ( Int_t i_bin = 0 ; i_bin < fFileHeader->fNbBinsADC ; i_bin++)
02399             {
02400               fT3d_his_s[SMEcha][i_samp][i_bin] = s_histo[i_bin];
02401             }
02402         } // end of loop on samples
02403       
02404       if ( nb_null_sample_cases != 0 )
02405         {
02406           nb_null_sample_chan++;
02407           if(fFlagPrint == fCodePrintAllComments)
02408             {
02409               Int_t SMTow   = MyNumbering->GetSMTowFromSMEcha(SMEcha);
02410               Int_t TowEcha = MyNumbering->GetTowEchaFromSMEcha(SMEcha);
02411 
02412               cerr << "!TCnaRunEB::MakeHistosOfSampleDistributions()> WARNING/INFO:"
02413                    << " possibility of empty histo in " << nb_null_sample_cases << " case(s)"
02414                    << " for SMEcha " << SMEcha << " (tower: " << SMTow
02415                    << ", TowEcha: " << TowEcha << ")"
02416                    << fTTBELL << endl;
02417             }
02418         } 
02419       fTagEvts[SMEcha] = 1;     fFileHeader->fEvtsCalc++;
02420     } // end of loop on SMEchas
02421   
02422   if ( nb_null_sample_all != 0 )
02423     {    
02424       if(fFlagPrint != fCodePrintNoComment)
02425         {
02426           cerr << "!TCnaRunEB::MakeHistosOfSampleDistributions()> WARNING/INFO:"
02427                << " possibility of empty histo in " << nb_null_sample_all << " case(s)"
02428                << " concerning " << nb_null_sample_chan << " SMEcha(s)" << fTTBELL << endl;
02429         } 
02430     }
02431 
02432   if (total_underflow != 0)
02433     {
02434       if(fFlagPrint != fCodePrintNoComment)
02435         {
02436           cerr << "!TCnaRunEB::MakeHistosOfSampleDistributions()> WARNING/INFO: "
02437                << total_underflow << " underflow(s) have been detected"
02438                << fTTBELL << endl;
02439         }
02440     }
02441 
02442   if (total_overflow != 0)
02443     {
02444       if(fFlagPrint != fCodePrintNoComment)
02445         {
02446           cerr << "!TCnaRunEB::MakeHistosOfSampleDistributions()> WARNING/INFO: "
02447                << total_overflow << " overflow(s) have been detected"
02448                << fTTBELL << endl;
02449         }
02450     }
02451 
02452   delete [] s_histo;        fCdelete++;
02453   delete MyNumbering;       fCdelete++;      
02454 }
02455 
02456 //-----------------------------------------------------------
02457 //
02458 //      Calculation of the covariances between samples
02459 //      for all the SMEchas
02460 //
02461 //-----------------------------------------------------------
02462 void TCnaRunEB::ComputeCovariancesBetweenSamples()
02463 {
02464   //Calculation of the covariances between samples for all the SMEchas
02465   
02466   if(fFlagPrint == fCodePrintAllComments){
02467     cout << "*TCnaRunEB::ComputeCovariancesBetweenSamples()>"
02468          << " Calculation of the covariances between samples"
02469          << " for all the SMEchas" << endl;}
02470   
02471   //................... Allocations cov_ss
02472   if( fT3d_cov_ss == 0 ){
02473     const Int_t n_samp = fFileHeader->fMaxSampADC;
02474     const Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02475     fT3d_cov_ss  = new Double_t**[n_SMEcha];                fCnew++;  
02476     fT3d2_cov_ss = new  Double_t*[n_SMEcha*n_samp];         fCnew++;  
02477     fT3d1_cov_ss = new   Double_t[n_SMEcha*n_samp*n_samp];  fCnew++;  
02478     for(Int_t i = 0 ; i < n_SMEcha ; i++){
02479       fT3d_cov_ss[i] = &fT3d2_cov_ss[0] + i*n_samp;
02480       for(Int_t j = 0 ; j < n_samp ; j++){
02481         fT3d2_cov_ss[n_samp*i+j] = &fT3d1_cov_ss[0]+n_samp*(n_samp*i+j);}}
02482   }
02483   
02484   //.................. Calculation (= init)
02485   //.................. computation of half of the matrix, diagonal included)
02486   for (Int_t j_SMEcha = 0 ; j_SMEcha < fFileHeader->fMaxCrysInSM ; j_SMEcha++)
02487     {
02488       for (Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC ; i_samp++)
02489         {
02490           for (Int_t j_samp = 0 ; j_samp <= i_samp; j_samp++)
02491             {
02492               fT3d_cov_ss[j_SMEcha][i_samp][j_samp] =
02493                 (fVal_data[j_SMEcha][i_samp]).Covariance(fVal_data[j_SMEcha][j_samp]);
02494               fT3d_cov_ss[j_SMEcha][j_samp][i_samp] = fT3d_cov_ss[j_SMEcha][i_samp][j_samp];
02495             }
02496         }
02497       fTagCovCss[j_SMEcha] = 1;     fFileHeader->fCovCssCalc++;
02498     }
02499 }
02500 
02501 //-----------------------------------------------------------
02502 //
02503 //      Calculation of the correlations between samples
02504 //      for all the SMEchas
02505 //
02506 //-----------------------------------------------------------
02507 
02508 void TCnaRunEB::ComputeCorrelationsBetweenSamples()
02509 {
02510 //Calculation of the correlations between samples for all the SMEchas
02511 
02512   //... preliminary calculation of the covariances if not done yet.
02513   //    Test only the first tag since the cov are computed globaly
02514   //    but set all the tags to 0 because we want not to write
02515   //    the covariances in the result ROOT file    
02516   if ( fTagCovCss[0] != 1 ){ComputeCovariancesBetweenSamples();
02517   for (Int_t j_SMEcha = 0 ; j_SMEcha < fFileHeader->fMaxCrysInSM ; j_SMEcha++)
02518     {fTagCovCss[j_SMEcha] = 0;}}
02519   
02520   if(fFlagPrint == fCodePrintAllComments){
02521     cout << "*TCnaRunEB::ComputeCorrelationsBetweenSamples()>"
02522          << " Calculation of the correlations between samples"
02523          << " for all the SMEchas" << endl;}
02524 
02525   //................... Allocations cor_ss
02526   if( fT3d_cor_ss == 0){
02527     const Int_t n_samp = fFileHeader->fMaxSampADC;
02528     const Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02529     fT3d_cor_ss  = new Double_t**[n_SMEcha];                fCnew++;  
02530     fT3d2_cor_ss = new  Double_t*[n_SMEcha*n_samp];         fCnew++;  
02531     fT3d1_cor_ss = new   Double_t[n_SMEcha*n_samp*n_samp];  fCnew++;  
02532     for(Int_t i = 0 ; i < n_SMEcha ; i++){
02533       fT3d_cor_ss[i] = &fT3d2_cor_ss[0] + i*n_samp;
02534       for(Int_t j = 0 ; j < n_samp ; j++){
02535         fT3d2_cor_ss[n_samp*i+j] = &fT3d1_cor_ss[0]+n_samp*(n_samp*i+j);}}
02536   }
02537   
02538   //..................... calculation of the correlations (=init)
02539   //......................computation of half of the matrix, diagonal included (verif = 1)
02540     
02541  for (Int_t j_SMEcha = 0 ; j_SMEcha < fFileHeader->fMaxCrysInSM ; j_SMEcha++)
02542    {
02543      for (Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC ; i_samp++)
02544        {
02545          for (Int_t j_samp = 0 ; j_samp <= i_samp ; j_samp++)
02546            {
02547              if((fT3d_cov_ss)[j_SMEcha][i_samp][i_samp] > 0
02548                 && (fT3d_cov_ss)[j_SMEcha][j_samp][j_samp] > 0 )
02549                {
02550                  fT3d_cor_ss[j_SMEcha][i_samp][j_samp] =
02551                    fT3d_cov_ss[j_SMEcha][i_samp][j_samp]/
02552                    (fVal_data[j_SMEcha][i_samp].StandardDeviation("corss1") *
02553                     fVal_data[j_SMEcha][j_samp].StandardDeviation("corss2"));
02554                }
02555              else
02556                {
02557                  (fT3d_cor_ss)[j_SMEcha][i_samp][j_samp] = (Double_t)0; // prevoir compteur + fTTBELL
02558                }
02559              fT3d_cor_ss[j_SMEcha][j_samp][i_samp] = fT3d_cor_ss[j_SMEcha][i_samp][j_samp];
02560            }
02561        }
02562      fTagCorCss[j_SMEcha] = 1;          fFileHeader->fCorCssCalc++;
02563    }
02564 }
02565 
02566 //------------------------------------------------------------------
02567 //
02568 //      Calculation of the covariances between SMEchas
02569 //      for all the samples
02570 //
02571 //------------------------------------------------------------------
02572 
02573 void TCnaRunEB::ComputeCovariancesBetweenChannels()
02574 {
02575 //Calculation of the covariances between SMEchas for all the samples
02576 
02577   if(fFlagPrint == fCodePrintAllComments){
02578     cout << "*TCnaRunEB::ComputeCovariancesBetweenChannels()>"
02579          << " Calculation of the covariances between SMEchas"
02580          << " for each sample." << endl;}
02581 
02582   //................... Allocations cov_cc
02583   if( fT3d_cov_cc == 0 ){
02584     const Int_t n_samp = fFileHeader->fMaxSampADC;
02585     const Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02586     fT3d_cov_cc  = new Double_t**[n_samp];                   fCnew++;  
02587     fT3d2_cov_cc = new  Double_t*[n_samp*n_SMEcha];          fCnew++;  
02588     fT3d1_cov_cc = new   Double_t[n_samp*n_SMEcha*n_SMEcha]; fCnew++;  
02589     for(Int_t i = 0 ; i < n_samp ; i++){
02590       fT3d_cov_cc[i] = &fT3d2_cov_cc[0] + i*n_SMEcha;
02591       for(Int_t j = 0 ; j < n_SMEcha ; j++){
02592         fT3d2_cov_cc[n_SMEcha*i+j] = &fT3d1_cov_cc[0]+n_SMEcha*(n_SMEcha*i+j);}}
02593   }
02594 
02595   //........ Calculation for each sample (=init)
02596   //...........................computation of half of the matrix, diagonal included
02597 
02598   for (Int_t k_samp = 0 ; k_samp < fFileHeader->fMaxSampADC ; k_samp++)
02599     {
02600       for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02601         {
02602           for (Int_t j_SMEcha = 0 ; j_SMEcha <= i_SMEcha ; j_SMEcha++)
02603             {
02604               fT3d_cov_cc[k_samp][i_SMEcha][j_SMEcha]
02605                 = (fVal_data[i_SMEcha][k_samp]).Covariance(fVal_data[j_SMEcha][k_samp]);
02606               fT3d_cov_cc[k_samp][j_SMEcha][i_SMEcha] = fT3d_cov_cc[k_samp][i_SMEcha][j_SMEcha];              
02607             }
02608         }
02609       fTagCovScc[k_samp] = 1;              fFileHeader->fCovSccCalc++;
02610     }
02611 }
02612 
02613 //------------------------------------------------------------------
02614 //
02615 //      Calculation of the covariances between SMEchas
02616 //      for all the samples, averaged over the samples
02617 //
02618 //------------------------------------------------------------------
02619 
02620 void TCnaRunEB::ComputeCovariancesBetweenChannelsMeanOverSamples()
02621 {
02622 //Calculation of the covariances between SMEchas for all the samples
02623 //and averaged over the samples
02624 
02625   //... preliminary calculation of the covariances if not done yet.
02626   //    Test only the first tag since the cov are computed globaly
02627   //    but set all the tags to 0 because we want not to write
02628   //    the covariances in the result ROOT file    
02629   if ( fTagCovScc[0] != 1 ){ComputeCovariancesBetweenChannels();
02630   for (Int_t k_samp = 0 ; k_samp < fFileHeader->fMaxSampADC ; k_samp++)
02631     {fTagCovScc[k_samp] = 0;}}
02632   
02633   if(fFlagPrint == fCodePrintAllComments){
02634     cout << "*TCnaRunEB::ComputeCovariancesBetweenChannelsMeanOverSamples()>"
02635          << " Calculation of the covariances between SMEchas,"
02636          << " Calculation of the average over the samples." << endl;}
02637 
02638   //.................. Mean over the samples
02639   //................. allocation cov_cc_mos + init to zero (mandatory)
02640   if( fT2d_cov_cc_mos == 0 ){
02641     const Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02642     fT2d_cov_cc_mos   = new Double_t*[n_SMEcha];                   fCnew++;
02643     fT2d1_cov_cc_mos  = new  Double_t[n_SMEcha*n_SMEcha];          fCnew++;
02644     for(Int_t i_SMEcha = 0 ; i_SMEcha < n_SMEcha ; i_SMEcha++){
02645         fT2d_cov_cc_mos[i_SMEcha] = &fT2d1_cov_cc_mos[0] + i_SMEcha*n_SMEcha;} 
02646   }
02647 
02648   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02649     {
02650       for (Int_t j_SMEcha = 0 ; j_SMEcha < fFileHeader->fMaxCrysInSM ; j_SMEcha++)
02651         {
02652           if( fT2d_cov_cc_mos[i_SMEcha][j_SMEcha] != (Double_t)0 )
02653             {fMiscDiag[7]++; fT2d_cov_cc_mos[i_SMEcha][j_SMEcha] = (Double_t)0;}
02654         }
02655     }
02656   
02657   //................. Calculation of the mean over the samples  
02658   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02659     {
02660       for (Int_t j_SMEcha = 0 ; j_SMEcha < fFileHeader->fMaxCrysInSM ; j_SMEcha++)
02661         {
02662           for (Int_t k_samp = 0 ; k_samp < fFileHeader->fMaxSampADC ; k_samp++)
02663             {
02664               fT2d_cov_cc_mos[i_SMEcha][j_SMEcha] =
02665                 fT2d_cov_cc_mos[i_SMEcha][j_SMEcha] + fT3d_cov_cc[k_samp][i_SMEcha][j_SMEcha];
02666             }
02667           fT2d_cov_cc_mos[i_SMEcha][j_SMEcha] =
02668             fT2d_cov_cc_mos[i_SMEcha][j_SMEcha]/(Double_t)(fFileHeader->fMaxSampADC);
02669         } 
02670     }
02671   fTagCovSccMos[0] = 1;    fFileHeader->fCovSccMosCalc++;
02672 }
02673 
02674 //----------------------------------------------------------------------
02675 //
02676 //      Calculation of the correlations between SMEchas
02677 //      for all the samples
02678 //
02679 //----------------------------------------------------------------------
02680 void TCnaRunEB::ComputeCorrelationsBetweenChannels()
02681 {
02682 //Calculation of the correlations between SMEchas for all the samples
02683   
02684   //... preliminary calculation of the covariances if not done yet.
02685   //    Test only the first tag since the cov are computed globaly
02686   //    but set all the tags to 0 because we want not to write
02687   //    the covariances in the result ROOT file  
02688   if ( fTagCovScc[0] != 1 ){ComputeCovariancesBetweenChannels();
02689   for (Int_t k_samp = 0 ; k_samp < fFileHeader->fMaxSampADC ; k_samp++)
02690     {fTagCovScc[k_samp] = 0;}}
02691   
02692   //............ calculation of the correlations from the covariances
02693   
02694   if(fFlagPrint == fCodePrintAllComments){
02695     cout << "*TCnaRunEB::ComputeCorrelationsBetweenChannels()>"
02696          << " Calculation of the correlations between SMEchas"
02697          << " for all the samples." << endl;}
02698  
02699   //................... Allocations cor_cc
02700   if ( fT3d_cor_cc == 0 ){ 
02701     const Int_t n_samp = fFileHeader->fMaxSampADC;
02702     const Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02703     fT3d_cor_cc  = new Double_t**[n_samp];                    fCnew++;  
02704     fT3d2_cor_cc = new  Double_t*[n_samp*n_SMEcha];           fCnew++;  
02705     fT3d1_cor_cc = new   Double_t[n_samp*n_SMEcha*n_SMEcha];  fCnew++;  
02706     for(Int_t i = 0 ; i < n_samp ; i++){
02707       fT3d_cor_cc[i] = &fT3d2_cor_cc[0] + i*n_SMEcha;
02708       for(Int_t j = 0 ; j < n_SMEcha ; j++){
02709         fT3d2_cor_cc[n_SMEcha*i+j] = &fT3d1_cor_cc[0]+n_SMEcha*(n_SMEcha*i+j);}}
02710   }
02711   
02712   //........................... Calculation (=init)
02713   //........................... computation of half of the matrix, diagonal included (verif=1)
02714   for (Int_t n_samp = 0 ; n_samp < fFileHeader->fMaxSampADC ; n_samp++)
02715     {
02716       for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02717         {
02718           for (Int_t j_SMEcha = 0 ; j_SMEcha <= i_SMEcha ; j_SMEcha++)
02719             {
02720               if(  fT3d_cov_cc[n_samp][i_SMEcha][i_SMEcha] > 0
02721                    && fT3d_cov_cc[n_samp][j_SMEcha][j_SMEcha] > 0 )
02722                 {
02723                   fT3d_cor_cc[n_samp][i_SMEcha][j_SMEcha] =
02724                     fT3d_cov_cc[n_samp][i_SMEcha][j_SMEcha]/
02725                     (  (Double_t)sqrt(fT3d_cov_cc[n_samp][i_SMEcha][i_SMEcha]) *
02726                        (Double_t)sqrt(fT3d_cov_cc[n_samp][j_SMEcha][j_SMEcha])  );
02727                 }
02728               else
02729                 {
02730                   fT3d_cor_cc[n_samp][i_SMEcha][j_SMEcha] = (Double_t)0.;
02731                 }
02732 
02733               fT3d_cor_cc[n_samp][j_SMEcha][i_SMEcha] = fT3d_cor_cc[n_samp][i_SMEcha][j_SMEcha];
02734             }
02735         }
02736       fTagCorScc[n_samp] = 1;    fFileHeader->fCorSccCalc++;
02737     }
02738 }
02739 
02740 //----------------------------------------------------------------------
02741 //
02742 //      Calculation of the correlations between SMEchas
02743 //      for all the samples, averaged over the samples
02744 //
02745 //----------------------------------------------------------------------
02746 void TCnaRunEB::ComputeCorrelationsBetweenChannelsMeanOverSamples()
02747 {
02748 //Calculation of the correlations between SMEchas for all the samples
02749 // averaged over the samples
02750 
02751   //... preliminary calculation of the covariances if not done yet.
02752   //    Test only the first tag since the cov are computed globaly
02753   //    but set all the tags to 0 because we want not to write
02754   //    the covariances in the result ROOT file  
02755   if ( fTagCorScc[0] != 1 ){ComputeCorrelationsBetweenChannels();
02756   for (Int_t k_samp = 0 ; k_samp < fFileHeader->fMaxSampADC ; k_samp++)
02757     {fTagCorScc[k_samp] = 0;}}
02758 
02759   //.................. Mean over the samples  
02760   if(fFlagPrint == fCodePrintAllComments){
02761     cout << "*TCnaRunEB::ComputeCorrelationsBetweenChannelsMeanOverSamples()>"
02762          << " Calculation of the correlations between SMEchas"
02763          << " Calculation of the average over the samples." << endl;}
02764 
02765   //................. allocation cor_cc_mos + init to zero (mandatory)
02766   if( fT2d_cor_cc_mos == 0 ){
02767     const Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
02768     fT2d_cor_cc_mos   = new Double_t*[n_SMEcha];                   fCnew++;  
02769     fT2d1_cor_cc_mos  = new  Double_t[n_SMEcha*n_SMEcha];          fCnew++;  
02770     for(Int_t i_SMEcha = 0 ; i_SMEcha < n_SMEcha ; i_SMEcha++){
02771         fT2d_cor_cc_mos[i_SMEcha] = &fT2d1_cor_cc_mos[0] + i_SMEcha*n_SMEcha;} 
02772   }
02773 
02774   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02775     {
02776       for (Int_t j_SMEcha = 0 ; j_SMEcha < fFileHeader->fMaxCrysInSM ; j_SMEcha++)
02777         {
02778           if( fT2d_cor_cc_mos[i_SMEcha][j_SMEcha] != (Double_t)0 )
02779             {fMiscDiag[8]++; fT2d_cor_cc_mos[i_SMEcha][j_SMEcha] = (Double_t)0;}
02780         }
02781     }
02782   
02783   //................. Calculation of the mean over the samples
02784   
02785   for (Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
02786     {
02787       for (Int_t j_SMEcha = 0 ; j_SMEcha < fFileHeader->fMaxCrysInSM ; j_SMEcha++)
02788         {
02789           for (Int_t k_samp = 0 ; k_samp < fFileHeader->fMaxSampADC ; k_samp++)
02790             {
02791               fT2d_cor_cc_mos[i_SMEcha][j_SMEcha] += fT3d_cor_cc[k_samp][i_SMEcha][j_SMEcha];
02792             }
02793           fT2d_cor_cc_mos[i_SMEcha][j_SMEcha] =
02794             fT2d_cor_cc_mos[i_SMEcha][j_SMEcha]/(Double_t)(fFileHeader->fMaxSampADC);
02795         } 
02796     }
02797   fTagCorSccMos[0] = 1;    fFileHeader->fCorSccMosCalc++;
02798 }
02799 
02800 //-----------------------------------------------------------------------------
02801 //      Calculation of the covariances between SMEchas
02802 //      for all the samples, averaged over the samples
02803 //      and calculation of the mean of these covariances
02804 //      (relevant ones) for all the towers
02805 //-----------------------------------------------------------------------------
02806 
02807 void  TCnaRunEB::ComputeCovariancesBetweenTowersMeanOverSamplesAndChannels()
02808 {
02809 //Calculation of the covariances between SMEchas
02810 //for all the samples, averaged over the samples and
02811 //calculation of the mean of these covariances for all the towers
02812 
02813 
02814   //... preliminary calculation of the covariances averaged over samples (cov_moscc_mot) if not done yet
02815   //    Only one tag (dim=1) to set to 0 (no write in the result ROOT file)
02816   if(fTagCovSccMos[0] != 1){ComputeCovariancesBetweenChannelsMeanOverSamples(); fTagCovSccMos[0]=0;}
02817 
02818   //..... mean of the cov_moscc_mot for each pair (tower_X,tower_Y)
02819   if(fFlagPrint == fCodePrintAllComments){
02820     cout << "*TCnaRunEB::ComputeCovariancesBetweenTowersMeanOverSamplesAndChannels()>"
02821          << " Calculation of the averaged covariances between towers,"
02822          << " (average over the samples and over the channels)." << endl;}
02823 
02824   //................. allocation cov_moscc_mot + init to zero (mandatory)
02825   if( fT2d_cov_moscc_mot == 0 ){
02826     const Int_t n_tow = fFileHeader->fMaxTowInSM;
02827     fT2d_cov_moscc_mot  = new Double_t*[n_tow];                 fCnew++;
02828     fT2d1_cov_moscc_mot = new  Double_t[n_tow*n_tow];           fCnew++;  
02829     for(Int_t i_tow = 0 ; i_tow < n_tow ; i_tow++){
02830         fT2d_cov_moscc_mot[i_tow] = &fT2d1_cov_moscc_mot[0] + i_tow*n_tow;} 
02831   }
02832   
02833   for(Int_t i_tow=0; i_tow<fFileHeader->fMaxTowInSM; i_tow++)
02834     {
02835       for(Int_t j_tow=0; j_tow<fFileHeader->fMaxTowInSM; j_tow++)
02836         {
02837           if( fT2d_cov_moscc_mot[i_tow][j_tow] != (Double_t)0 )
02838             {fMiscDiag[9]++; fT2d_cov_moscc_mot[i_tow][j_tow] = (Double_t)0;}
02839         }
02840     }
02841   
02842   //..... Calculation of the mean of the averaged cov(c,c) over samples for each pair (tower_X,tower_Y)    
02843   for(Int_t i_tow=0; i_tow<fFileHeader->fMaxTowInSM; i_tow++)
02844     {
02845       for(Int_t j_tow=0; j_tow<fFileHeader->fMaxTowInSM; j_tow++)
02846         {
02847           for(Int_t i_crys=0; i_crys<fFileHeader->fMaxCrysInTow; i_crys++)
02848             {
02849               Int_t i_SMEcha = i_tow*fFileHeader->fMaxCrysInTow + i_crys;
02850               for(Int_t j_crys=0; j_crys<fFileHeader->fMaxCrysInTow; j_crys++)
02851                 {
02852                   Int_t j_SMEcha = j_tow*fFileHeader->fMaxCrysInTow + j_crys;
02853                   fT2d_cov_moscc_mot[i_tow][j_tow] += fT2d_cov_cc_mos[i_SMEcha][j_SMEcha];
02854                 }
02855             }
02856           fT2d_cov_moscc_mot[i_tow][j_tow] = fT2d_cov_moscc_mot[i_tow][j_tow]
02857             /((Double_t)(fFileHeader->fMaxCrysInTow*fFileHeader->fMaxCrysInTow));
02858         }
02859     }
02860   fTagCovMosccMot[0] = 1;                   fFileHeader->fCovMosccMotCalc++;
02861 }
02862 
02863 //-----------------------------------------------------------------------------
02864 //
02865 //      Calculation of the correlations between SMEchas
02866 //      for all the samples, averaged over the samples
02867 //      and calculation of the mean of these correlations
02868 //      (relevant ones) for all the towers
02869 //-----------------------------------------------------------------------------
02870 
02871 void  TCnaRunEB::ComputeCorrelationsBetweenTowersMeanOverSamplesAndChannels()
02872 {
02873 //Calculation of the correlations between SMEchas
02874 //for all the samples, averaged over the samples and
02875 //calculation of the mean of these correlations for all the towers
02876 
02877   //... preliminary calculation of the correlations averaged over samples (cor_moscc_mot) if not done yet
02878   //    Only one tag (dim=1) to set to 0 (no write in the result ROOT file)
02879 
02880   if(fTagCorSccMos[0] != 1){ComputeCorrelationsBetweenChannelsMeanOverSamples(); fTagCorSccMos[0]= 0;}
02881 
02882   if(fFlagPrint == fCodePrintAllComments){
02883     cout << "*TCnaRunEB::ComputeCorrelationsBetweenTowersMeanOverSamplesAndChannels()>"
02884          << " Calculation of the averaged correlations between towers,"
02885          << " (average over the samples and over the channels)." << endl;}
02886 
02887   //................. allocation cor_moscc_mot + init to zero (mandatory)
02888   if( fT2d_cor_moscc_mot == 0 ){
02889     const Int_t n_tow = fFileHeader->fMaxTowInSM;
02890     fT2d_cor_moscc_mot  = new Double_t*[n_tow];                 fCnew++;
02891     fT2d1_cor_moscc_mot = new  Double_t[n_tow*n_tow];           fCnew++;  
02892     for(Int_t i_tow = 0 ; i_tow < n_tow ; i_tow++){
02893       fT2d_cor_moscc_mot[i_tow] = &fT2d1_cor_moscc_mot[0] + i_tow*n_tow;}
02894   }
02895   
02896   for(Int_t i_tow=0; i_tow<fFileHeader->fMaxTowInSM; i_tow++)
02897     {
02898       for(Int_t j_tow=0; j_tow<fFileHeader->fMaxTowInSM; j_tow++)
02899         {
02900           if( fT2d_cor_moscc_mot[i_tow][j_tow] != (Double_t)0 )
02901             {fMiscDiag[10]++; fT2d_cor_moscc_mot[i_tow][j_tow] = (Double_t)0;}
02902         }
02903     }
02904   
02905   //..... Calculation of the mean of the averaged over samples cor(c,c) for each pair (tower_X,tower_Y)
02906   
02907   for(Int_t i_tow=0; i_tow<fFileHeader->fMaxTowInSM; i_tow++)
02908     {
02909       for(Int_t j_tow=0; j_tow<fFileHeader->fMaxTowInSM; j_tow++)
02910         {
02911           //..... Calculation of the average values over the channels for the current (i_tow, j_tow)
02912           for(Int_t i_crys=0; i_crys<fFileHeader->fMaxCrysInTow; i_crys++)
02913             {
02914               Int_t i_SMEcha = i_tow*fFileHeader->fMaxCrysInTow + i_crys;
02915               for(Int_t j_crys=0; j_crys<fFileHeader->fMaxCrysInTow; j_crys++)
02916                 {
02917                   Int_t j_SMEcha = j_tow*fFileHeader->fMaxCrysInTow + j_crys; 
02918                   fT2d_cor_moscc_mot[i_tow][j_tow] += fT2d_cor_cc_mos[i_SMEcha][j_SMEcha];
02919                 }
02920             }
02921 
02922           fT2d_cor_moscc_mot[i_tow][j_tow] = fT2d_cor_moscc_mot[i_tow][j_tow]
02923             /((Double_t)(fFileHeader->fMaxCrysInTow*fFileHeader->fMaxCrysInTow));
02924         }
02925     }
02926   fTagCorMosccMot[0] = 1;    fFileHeader->fCorMosccMotCalc++;
02927 }
02928 
02929 //-------------------------------------------------------------------------
02930 //
02931 //      Calculation of the expectation values of the expectation values
02932 //      of the samples for all the SMEchas
02933 //
02934 //-------------------------------------------------------------------------
02935 void  TCnaRunEB::ComputeExpectationValuesOfExpectationValuesOfSamples()
02936 {
02937 //Calculation of the expectation values of the expectation values
02938 // of the samples for all the SMEchas 
02939 
02940   //... preliminary calculation of the expectation values if not done yet
02941   if ( fTagEv[0] != 1 ){ComputeExpectationValuesOfSamples(); fTagEv[0]=0; }
02942 
02943   //................... Allocation ev_ev + init to zero (mandatory)
02944   if( fT1d_ev_ev == 0 ){
02945     fT1d_ev_ev = new Double_t[fFileHeader->fMaxCrysInSM];                   fCnew++;
02946   }
02947    for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
02948      {
02949        if( fT1d_ev_ev[i_SMEcha] != (Double_t)0 )
02950          {fMiscDiag[11]++; fT1d_ev_ev[i_SMEcha] = (Double_t)0;}
02951      }
02952 
02953   //................... Allocations ch_ev, amplit
02954     TVectorD ch_ev(fFileHeader->fMaxSampADC);
02955     TDistrib* amplit   = new TDistrib(fFileHeader->fMaxSampADC, ch_ev);     fCnew++;  
02956   
02957   if(fFlagPrint == fCodePrintAllComments){
02958     cout << "*TCnaRunEB::ComputeExpectationValuesOfExpectationValuesOfSamples()>" << endl
02959          << "          Calculation of the expectation values of the"
02960          << " expectation values of the samples for all the SMEchas" << endl;}
02961 
02962   //..................... Calculation
02963   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
02964     {     
02965       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
02966         {
02967           ch_ev(i_samp) = fT2d_ev[i_SMEcha][i_samp];
02968         }
02969 
02970       Bool_t ok_refill = amplit->Refill(fFileHeader->fMaxSampADC, ch_ev);
02971       if(ok_refill == kTRUE){fT1d_ev_ev[i_SMEcha] = amplit->ExpectationValue();}
02972     }
02973   delete amplit;                        fCdelete++;
02974   fTagEvEv[0] = 1;                      fFileHeader->fEvEvCalc++;
02975 }
02976 
02977 //-------------------------------------------------------------------------
02978 //
02979 //      Calculation of the expectation values of the sigmas
02980 //      of the samples for all the SMEchas
02981 //
02982 //-------------------------------------------------------------------------
02983 void  TCnaRunEB::ComputeExpectationValuesOfSigmasOfSamples()
02984 {
02985 //Calculation of the expectation values of the sigmas
02986 // of the samples for all the SMEchas 
02987 
02988   //... preliminary calculation of the variances if not done yet
02989   if ( fTagVar[0] != 1 ){ComputeVariancesOfSamples(); fTagVar[0]=0; }
02990  
02991   //................... Allocation ev_sig + init to zero (mandatory)
02992   if( fT1d_ev_sig == 0 ){
02993     fT1d_ev_sig = new Double_t[fFileHeader->fMaxCrysInSM];              fCnew++;  
02994   }
02995    for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
02996      {
02997        if( fT1d_ev_sig[i_SMEcha] != (Double_t)0 )
02998          {fMiscDiag[12]++; fT1d_ev_sig[i_SMEcha] = (Double_t)0;}
02999      }
03000 
03001   //................... Allocations ch_sig, amplit
03002   TVectorD  ch_sig(fFileHeader->fMaxSampADC);  
03003   TDistrib* amplit   = new TDistrib(fFileHeader->fMaxSampADC, ch_sig);  fCnew++; 
03004  
03005   if(fFlagPrint == fCodePrintAllComments){
03006     cout << "*TCnaRunEB::ComputeExpectationValuesOfSigmasOfSamples()>" << endl
03007          << "          Calculation of the expectation values of the"
03008          << " sigmas of the samples for all the SMEchas" << endl;}
03009 
03010   //..................... Calculation
03011   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03012     {     
03013       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
03014         {
03015           if (ch_sig(i_samp) >= (Double_t)0.)
03016             {
03017               ch_sig(i_samp) = (Double_t)sqrt(fT2d_var[i_SMEcha][i_samp]);
03018             }
03019           else
03020             {
03021               ch_sig(i_samp) = (Double_t)(-1.);
03022               cout << "!TCnaRunEB::ComputeExpectationValuesOfSigmasOfSamples() *** ERROR ***> " << endl
03023                    << "          Negative variance! Sigma forced to -1" << fTTBELL << endl;
03024             }
03025         }
03026 
03027       Bool_t ok_refill = amplit->Refill(fFileHeader->fMaxSampADC, ch_sig);
03028       if(ok_refill == kTRUE){fT1d_ev_sig[i_SMEcha] = amplit->ExpectationValue();}
03029     }
03030   delete amplit;                         fCdelete++;
03031   fTagEvSig[0] = 1;                      fFileHeader->fEvSigCalc++;
03032 }
03033 
03034 //-------------------------------------------------------------------------
03035 //
03036 //      Calculation of the expectation values of the (sample,sample)
03037 //      correlations for all the SMEchas
03038 //
03039 //-------------------------------------------------------------------------
03040 void  TCnaRunEB::ComputeExpectationValuesOfCorrelationsBetweenSamples()
03041 {
03042   //Calculation of the expectation values of the (sample,sample) correlations for all the SMEchas 
03043   
03044   //... preliminary calculation of the correlationss if not done yet
03045   //    (test only the first element since the cor are computed globaly)
03046   if ( fTagCorCss[0] != 1 ){ComputeCorrelationsBetweenSamples(); fTagCorCss[0]=0;}
03047 
03048   //................... Allocations ev_cor_ss + init to zero (mandatory)
03049   if( fT1d_ev_cor_ss == 0 ){
03050     Int_t n_SMEcha =  fFileHeader->fMaxCrysInSM;
03051     fT1d_ev_cor_ss = new Double_t[n_SMEcha];               fCnew++;  
03052   }
03053   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03054     {
03055       if( fT1d_ev_cor_ss[i_SMEcha] != (Double_t)0 )
03056         {fMiscDiag[13]++; fT1d_ev_cor_ss[i_SMEcha] = (Double_t)0;}
03057     }
03058   
03059   //.......... 1D array half_cor_ss[N(N-1)/2] to put the N (sample,sample) correlations
03060   //           (half of them minus the diagonal) 
03061   Int_t ndim = (Int_t)(fFileHeader->fMaxSampADC*(fFileHeader->fMaxSampADC - 1)/2);
03062 
03063   TVectorD  half_cor_ss(ndim);
03064 
03065   TDistrib* amplit = new TDistrib(ndim, half_cor_ss);      fCnew++;
03066   
03067   if(fFlagPrint == fCodePrintAllComments){
03068     cout << "*TCnaRunEB::ComputeExpectationValuesOfCorrelationsBetweenSamples()>" << endl
03069          << "          Calculation of the expectation values of the"
03070          << " (sample,sample) correlations for all the SMEchas" << endl;}
03071 
03072   //..................... Calculation
03073   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03074     {     
03075       Int_t i_count = 0;
03076       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
03077         {
03078           for (Int_t j_samp = 0; j_samp < i_samp; j_samp++)
03079             {
03080               half_cor_ss(i_count) = fT3d_cor_ss[i_SMEcha][i_samp][j_samp];
03081               i_count++;
03082             }
03083         }
03084       
03085       Bool_t ok_refill = amplit->Refill(ndim, half_cor_ss);
03086       if(ok_refill == kTRUE){fT1d_ev_cor_ss[i_SMEcha] = amplit->ExpectationValue();}
03087     }
03088   delete amplit;                    fCdelete++;
03089   fTagEvCorCss[0] = 1;              fFileHeader->fEvCorCssCalc++;
03090 }
03091 
03092 //-------------------------------------------------------------------------
03093 //
03094 //      Calculation of the sigmas of the expectation values
03095 //      of the samples for all the SMEchas
03096 //
03097 //-------------------------------------------------------------------------
03098 void  TCnaRunEB::ComputeSigmasOfExpectationValuesOfSamples()
03099 {
03100 //Calculation of the sigmas of the expectation values
03101 // of the samples for all the SMEchas 
03102   
03103   //... preliminary calculation of the expectation values if not done yet
03104   if ( fTagEv[0] != 1 ){ComputeExpectationValuesOfSamples(); fTagEv[0]=0; }
03105 
03106   //................... Allocation sig_ev + init to zero (mandatory)
03107   if( fT1d_sig_ev == 0 ){
03108     fT1d_sig_ev = new Double_t[fFileHeader->fMaxCrysInSM];               fCnew++;  
03109   }
03110 
03111   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03112     {
03113       if( fT1d_sig_ev[i_SMEcha] != (Double_t)0 )
03114         {fMiscDiag[14]++; fT1d_sig_ev[i_SMEcha] = (Double_t)0;}
03115     }
03116   
03117   //................... Allocations ch_ev, amplit
03118   TVectorD  ch_ev(fFileHeader->fMaxSampADC); 
03119   TDistrib* amplit   = new TDistrib(fFileHeader->fMaxSampADC, ch_ev);    fCnew++;
03120   
03121   if(fFlagPrint == fCodePrintAllComments){
03122     cout << "*TCnaRunEB::ComputeSigmasOfExpectationValuesOfSamples()>" << endl
03123          << "          Calculation of the sigmas of the"
03124          << " expectation values of the samples for all the SMEchas" << endl;}
03125 
03126   //..................... Calculation
03127   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03128     {     
03129       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
03130         {
03131           ch_ev(i_samp) = fT2d_ev[i_SMEcha][i_samp];
03132         }
03133 
03134       Bool_t ok_refill = amplit->Refill(fFileHeader->fMaxSampADC, ch_ev);
03135       if(ok_refill == kTRUE){fT1d_sig_ev[i_SMEcha] = amplit->StandardDeviation();}
03136     }
03137   delete amplit;                        fCdelete++;
03138   fTagSigEv[0] = 1;                     fFileHeader->fSigEvCalc++;
03139 }
03140 
03141 //-------------------------------------------------------------------------
03142 //
03143 //      Calculation of the sigmas of the sigmas
03144 //      of the samples for all the SMEchas
03145 //
03146 //-------------------------------------------------------------------------
03147 void  TCnaRunEB::ComputeSigmasOfSigmasOfSamples()
03148 {
03149 //Calculation of the sigmas of the sigmas
03150 // of the samples for all the SMEchas 
03151 
03152   //... preliminary calculation of the variances if not done yet
03153   if ( fTagVar[0] != 1 ){ComputeVariancesOfSamples(); fTagVar[0]=0; }
03154 
03155   //................... Allocation sig_sig + init to zero (mandatory)
03156   if( fT1d_sig_sig == 0 ){
03157     fT1d_sig_sig = new Double_t[fFileHeader->fMaxCrysInSM];                fCnew++;
03158   } 
03159   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03160     {
03161       if( fT1d_sig_sig[i_SMEcha] != (Double_t)0 )
03162         {fMiscDiag[15]++; fT1d_sig_sig[i_SMEcha] = (Double_t)0;}
03163     }
03164   
03165   //................... Allocations ch_sig, amplit
03166   TVectorD  ch_sig(fFileHeader->fMaxSampADC);
03167   TDistrib* amplit = new TDistrib(fFileHeader->fMaxSampADC, ch_sig);       fCnew++;
03168   
03169   if(fFlagPrint == fCodePrintAllComments){
03170     cout << "*TCnaRunEB::ComputeSigmasOfSigmasOfSamples()>" << endl
03171          << "          Calculation of the sigmas of the"
03172          << " sigmas of the samples for all the SMEchas" << endl;}
03173 
03174   //..................... Calculation
03175   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03176     {     
03177       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
03178         {
03179           if (ch_sig(i_samp) >= (Double_t)0.)
03180             {
03181               ch_sig(i_samp) = (Double_t)sqrt(fT2d_var[i_SMEcha][i_samp]);
03182             }
03183           else
03184             {
03185               ch_sig(i_samp) = (Double_t)(-1.);
03186               cout << "!TCnaRunEB::ComputeSigmasOfSigmasOfSamples() *** ERROR ***> " << endl
03187                    << "          Negative variance! Sigma forced to -1" << fTTBELL << endl;
03188             }
03189         }
03190 
03191       Bool_t ok_refill = amplit->Refill(fFileHeader->fMaxSampADC, ch_sig);
03192       if(ok_refill == kTRUE){fT1d_sig_sig[i_SMEcha] = amplit->StandardDeviation();}
03193     }
03194   delete amplit;                         fCdelete++;
03195   fTagSigSig[0] = 1;                     fFileHeader->fSigSigCalc++;
03196 }
03197 
03198 //-------------------------------------------------------------------------
03199 //
03200 //      Calculation of the sigmas of the (sample,sample) correlations
03201 //      for all the SMEchas
03202 //
03203 //--------------------------------------------------------------------------
03204 void  TCnaRunEB::ComputeSigmasOfCorrelationsBetweenSamples()
03205 {
03206   //Calculation of the sigmas of the (sample,sample) correlations for all the SMEchas
03207  
03208   //... preliminary calculation of the correlationss if not done yet
03209   //    (test only the first element since the cor are computed globaly)
03210   if ( fTagCorCss[0] != 1 ){ComputeCorrelationsBetweenSamples(); fTagCorCss[0]=0;}
03211 
03212   //................... Allocations sig_cor_ss + init to zero
03213   if( fT1d_sig_cor_ss == 0 ){
03214     Int_t n_SMEcha =  fFileHeader->fMaxCrysInSM;
03215     fT1d_sig_cor_ss = new Double_t[n_SMEcha];                fCnew++;  
03216   }
03217   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03218     {
03219       if( fT1d_sig_cor_ss[i_SMEcha] != (Double_t)0 )
03220         {fMiscDiag[16]++; fT1d_sig_cor_ss[i_SMEcha] = (Double_t)0;}
03221     }
03222 
03223   if(fFlagPrint == fCodePrintAllComments){
03224     cout << "*TCnaRunEB::ComputeSigmasOfCorrelationsBetweenSamples()>" << endl
03225          << "          Calculation of the sigmas of the (sample,sample)"
03226          << " correlations for all the cna_SMEchas" << endl;}
03227 
03228   //.......... 1D array half_cor_ss[N(N-1)/2] to put the N (sample,sample) correlations
03229   //           (half of them minus the diagonal)
03230   Int_t ndim = (Int_t)(fFileHeader->fMaxSampADC*(fFileHeader->fMaxSampADC - 1)/2);
03231   //Int_t ndim = (int)(fFileHeader->fMaxSampADC*(fFileHeader->fMaxSampADC - 1.)/2.);
03232 
03233   TVectorD  half_cor_ss(ndim);
03234 
03235   TDistrib* amplit      = new TDistrib(ndim, half_cor_ss);   fCnew++;
03236 
03237   //.................. Calculation
03238   for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03239     {     
03240       Int_t i_count = 0;
03241       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
03242         {
03243           for (Int_t j_samp = 0; j_samp < i_samp; j_samp++)
03244             {
03245               half_cor_ss(i_count) = fT3d_cor_ss[i_SMEcha][i_samp][j_samp];
03246               i_count++;
03247             }
03248         }
03249 
03250       Bool_t ok_refill = amplit->Refill(ndim, half_cor_ss);
03251       if(ok_refill == kTRUE){fT1d_sig_cor_ss[i_SMEcha] = amplit->StandardDeviation("SigmaCorss");}
03252     }
03253   delete amplit;                     fCdelete++;
03254   fTagSigCorCss[0] = 1;              fFileHeader->fSigCorCssCalc++;
03255 }
03256 
03257 //##################################### CORRECTION METHODS ##############################
03258 //---------------------------------------------------------------------------------
03259 //
03260 //     Calculation of the correction coefficients to sample values
03261 //     for all the SMEchas from the (sample,sample) covariances
03262 //
03263 //--------------------------------------------------------------------------------
03264 void  TCnaRunEB::ComputeCorrectionsToSamplesFromCovss(const Int_t& nb_first_samples)
03265 {
03266 // Calulation of the corrections coefficients to the sample values
03267 // for all the SMEchas from cov(s,s)
03268   
03269   //................... Allocations correction samples/covss + init to zero (mandatory)
03270   if( fT2d_sv_correc_covss_s == 0 ){
03271     Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
03272     Int_t n_samp = fFileHeader->fMaxSampADC;
03273     fT2d_sv_correc_covss_s = new Double_t*[n_SMEcha];                 fCnew++;
03274     fT2d1_sv_correc_covss_s = new  Double_t[n_SMEcha*n_samp];         fCnew++;  
03275     for(Int_t i = 0 ; i < n_SMEcha ; i++){
03276       fT2d_sv_correc_covss_s[i] = &fT2d1_sv_correc_covss_s[0] + i*n_samp;}
03277   }
03278 
03279   for(Int_t i_SMEcha = 0; i_SMEcha <fFileHeader->fMaxCrysInSM; i_SMEcha++)
03280     {  
03281       for(Int_t i_samp = 0; i_samp <fFileHeader->fMaxSampADC; i_samp++)
03282         {
03283           if( fT2d_sv_correc_covss_s[i_SMEcha][i_samp] != (Double_t)0 )
03284             {fMiscDiag[17]++; fT2d_sv_correc_covss_s[i_SMEcha][i_samp] = (Double_t)0;}
03285         }
03286     }
03287   
03288   if(fFlagPrint == fCodePrintAllComments){
03289     cout << "*TCnaRunEB::ComputeCorrectionsToSamplesFromCovss()>" << endl
03290          << "          Calculation of the correction coefficients to sample values"
03291          << " for all the SMEchas from the (sample,sample) covariances" << endl;}
03292 
03293   //.. preliminary calculation of the covariances if not done yet
03294   if ( fTagCovCss[0] != 1 ) { ComputeCovariancesBetweenSamples(); }
03295   
03296   //................. Calculation
03297   //----------------- Loop on the SMEchas 
03298   for(Int_t i_SMEcha = 0; i_SMEcha <fFileHeader->fMaxCrysInSM; i_SMEcha++)
03299     {
03300       // to be done...     
03301     }
03302 
03303   fTagSvCorrecCovCss[0] = 1;            fFileHeader->fSvCorrecCovCssCalc++;
03304 }
03305 
03306 
03307 //-------------------------------------------------------------------------
03308 //
03309 //          Calculation of the corrections factors
03310 //  to the (sample,sample) covariances for all the SMEchas  (OLD? CHECK)
03311 //
03312 //-------------------------------------------------------------------------
03313 void  TCnaRunEB::ComputeCorrectionFactorsToCovss()
03314 {
03315 //Calculation of the corrections factors
03316 //to the (sample,sample) covariances for all the SMEchas
03317   
03318   //................... Allocations correction covariances/covss + init to zero
03319   if (fT3d_cov_correc_covss_s == 0 ){
03320     Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
03321     Int_t n_samp = fFileHeader->fMaxSampADC;
03322     fT3d_cov_correc_covss_s  = new Double_t**[n_SMEcha];               fCnew++;
03323     fT3d2_cov_correc_covss_s = new  Double_t*[n_SMEcha*n_samp];        fCnew++;
03324     fT3d1_cov_correc_covss_s = new   Double_t[n_SMEcha*n_samp*n_samp]; fCnew++;
03325     for(Int_t i = 0 ; i < n_SMEcha ; i++){
03326       fT3d_cov_correc_covss_s[i] = &fT3d2_cov_correc_covss_s[0] + i*n_samp;
03327       for(Int_t j = 0 ; j < n_samp ; j++){
03328         fT3d2_cov_correc_covss_s[n_samp*i+j] =
03329           &fT3d1_cov_correc_covss_s[0]+n_samp*(n_samp*i+j);}}
03330   }
03331   
03332   for(Int_t i_SMEcha = 0; i_SMEcha <fFileHeader->fMaxCrysInSM; i_SMEcha++)
03333     {  
03334       for(Int_t i_samp = 0; i_samp <fFileHeader->fMaxSampADC; i_samp++)
03335         {
03336           for(Int_t j_samp = 0; j_samp <fFileHeader->fMaxSampADC; j_samp++)
03337             {
03338               if( fT3d_cov_correc_covss_s[i_SMEcha][i_samp][j_samp] != (Double_t)0 )
03339                 {fMiscDiag[18]++; fT3d_cov_correc_covss_s[i_SMEcha][i_samp][j_samp] = (Double_t)0;}
03340             }
03341         }
03342     }
03343   
03344   //.. preliminary calculation of the covariances if not done yet
03345   //    (test only the first elt since the cov ara computed globaly) 
03346   
03347   if ( fTagCovCss[0] != 1 ) { ComputeCovariancesBetweenSamples(); }
03348  
03349   if(fFlagPrint == fCodePrintAllComments){
03350     cout << "*TCnaRunEB::ComputeCorrectionFactorsToCovss>" << endl
03351          << "          Calculation of the correction factors to the"
03352          << " (sample,sample) covariances for all the SMEchas" << endl;}
03353 
03354  
03355   //.. Calculation of the sum (on mp_samp) of the covariances
03356   //   (sample m_samp , sample mp_samp) as a function of m_samp
03357   //   (array sum_cov[mp_samp])
03358 
03359   //........ ALLOCATION + init to zero (mandatory)
03360   Double_t** sum_cov   = new Double_t*[fFileHeader->fMaxCrysInSM];                         fCnew++;
03361   Double_t*  sum_cov12 = new Double_t[fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC];  fCnew++;
03362   
03363   for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
03364     {sum_cov[i_SMEcha] = &sum_cov12[0] + i_SMEcha*fFileHeader->fMaxSampADC;}
03365   
03366   for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
03367     {
03368       for(Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxCrysInSM ; i_samp++)
03369         {
03370           if( sum_cov[i_SMEcha][i_samp] != (Double_t)0 )
03371             {fMiscDiag[19]++; sum_cov[i_SMEcha][i_samp] = (Double_t)0;}
03372         }
03373     }
03374   
03375   //........ CALCULATION
03376   for (Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03377     {
03378       // to be done...
03379     }
03380 
03381   //..... Calculation of the Double_t sum (on m_samp and mp_samp)
03382   //      of the covariances (sample m_samp , sample mp_samp)
03383   //      (number sum_sum_cov)
03384 
03385   //........ ALLOCATION + init to zerop (mandatory)
03386   Double_t*  sum_sum_cov = new Double_t[fFileHeader->fMaxCrysInSM];     fCnew++;
03387   for (Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03388     {sum_sum_cov[i_SMEcha] = (Double_t)0;}
03389 
03390   //........ CALCULATION
03391   for (Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03392     {     
03393       for (Int_t m_samp = 0; m_samp < fFileHeader->fMaxSampADC; m_samp++)
03394         {     
03395           sum_sum_cov[i_SMEcha] = sum_sum_cov[i_SMEcha] + sum_cov[i_SMEcha][m_samp];
03396         }
03397     }
03398   
03399   //... Calculation of the correction factors to the covariances (f_{jj'})
03400   //      f_{jj'} = 1 - c_{jj'}  
03401 
03402   //........ ALLOCATION + init to zero (mandatory)
03403   Double_t*** sum_cov_num1   = new Double_t**[fFileHeader->fMaxCrysInSM];                          fCnew++;
03404   Double_t**  sum_cov_num12  = new  Double_t*[fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC]; fCnew++;
03405   Double_t*   sum_cov_num123 =
03406     new   Double_t[fFileHeader->fMaxCrysInSM*fFileHeader->fMaxSampADC*fFileHeader->fMaxSampADC];   fCnew++;
03407 
03408   for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
03409     {
03410       sum_cov_num1[i_SMEcha] = &sum_cov_num12[0] + i_SMEcha*fFileHeader->fMaxSampADC;
03411       for (Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC; i_samp++)
03412         {
03413           sum_cov_num12[i_SMEcha*fFileHeader->fMaxSampADC + i_samp] =
03414             &sum_cov_num123[0] + (i_SMEcha*fFileHeader->fMaxSampADC + i_samp)*fFileHeader->fMaxSampADC;
03415         }
03416     }
03417 
03418   for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
03419     {
03420       for(Int_t i_samp = 0 ; i_samp < fFileHeader->fMaxSampADC ; i_samp++)
03421         {
03422           for(Int_t j_samp = 0 ; j_samp < fFileHeader->fMaxSampADC ; j_samp++)
03423             {
03424               if( sum_cov_num1[i_SMEcha][i_samp][j_samp] != (Double_t)0 )
03425                 {fMiscDiag[20]++; sum_cov_num1[i_SMEcha][i_samp][j_samp] = (Double_t)0;}
03426             }
03427         }
03428     }
03429   
03430   //........ CALCULATION
03431   for(Int_t i_SMEcha = 0 ; i_SMEcha < fFileHeader->fMaxCrysInSM ; i_SMEcha++)
03432     {
03433       // to be done...
03434       fTagCovCorrecCovCss[i_SMEcha] = 1;           fFileHeader->fCovCorrecCovCssCalc++;
03435     }
03436 
03437   delete [] sum_cov;                                fCdelete++;
03438   delete [] sum_cov12;                              fCdelete++;
03439   delete [] sum_sum_cov;                            fCdelete++;
03440   delete [] sum_cov_num1;                           fCdelete++;
03441   delete [] sum_cov_num12;                          fCdelete++;
03442   delete [] sum_cov_num123;                         fCdelete++;
03443 }
03444 //-----------------------------------------------------------------------------
03445 //
03446 //             Calculation of the corrections factors
03447 //     to the (sample,sample) correlations for all the SMEchas (OLD? CHECK)
03448 //
03449 //-----------------------------------------------------------------------------
03450 void  TCnaRunEB::ComputeCorrectionFactorsToCorss()
03451 {
03452 // Calculation of the corrections factors to the (sample,sample)
03453 // correlations for all the SMEchas
03454   
03455   //................... Allocations correction correlations/covss + init to zero (mandatory)
03456   if( fT3d_cor_correc_covss_s == 0 ){
03457     Int_t n_SMEcha = fFileHeader->fMaxCrysInSM;
03458     Int_t n_samp = fFileHeader->fMaxSampADC;
03459     fT3d_cor_correc_covss_s  = new Double_t**[n_SMEcha];               fCnew++;
03460     fT3d2_cor_correc_covss_s = new  Double_t*[n_SMEcha*n_samp];        fCnew++;
03461     fT3d1_cor_correc_covss_s = new   Double_t[n_SMEcha*n_samp*n_samp]; fCnew++;
03462     for(Int_t i = 0 ; i < n_SMEcha ; i++){
03463       fT3d_cor_correc_covss_s[i] = &fT3d2_cor_correc_covss_s[0] + i*n_samp;
03464       for(Int_t j = 0 ; j < n_samp ; j++){
03465         fT3d2_cor_correc_covss_s[n_samp*i+j] =
03466           &fT3d1_cor_correc_covss_s[0]+n_samp*(n_samp*i+j);}}   
03467   }
03468  
03469   for(Int_t i_SMEcha = 0; i_SMEcha <fFileHeader->fMaxCrysInSM; i_SMEcha++)
03470     {  
03471       for(Int_t i_samp = 0; i_samp <fFileHeader->fMaxSampADC; i_samp++)
03472         {
03473           for(Int_t j_samp = 0; j_samp <fFileHeader->fMaxSampADC; j_samp++)
03474             {
03475               if( fT3d_cor_correc_covss_s[i_SMEcha][i_samp][j_samp] != (Double_t)0 )
03476                 {fMiscDiag[21]++; fT3d_cor_correc_covss_s[i_SMEcha][i_samp][j_samp] = (Double_t)0;}
03477             }
03478         }
03479     }
03480  
03481   //.. preliminary calculation of the covariances if not done yet
03482   //    (test only the first elt since the cov ara computed globaly)
03483   
03484   if ( fTagCovCss[0] != 1 ) { ComputeCovariancesBetweenSamples(); }
03485    
03486   //.. Calculation of the correction factor to the covariances (f_{jj'})
03487   //   if not done yet
03488   
03489   if ( fTagCovCorrecCovCss[0] != 1 ) ComputeCorrectionFactorsToCovss();
03490 
03491   if(fFlagPrint == fCodePrintAllComments){
03492     cout << "*TCnaRunEB::ComputeCorrectionFactorsToCorss>" << endl
03493          << "          Calculation of the correction factors to the"
03494          << " (sample,sample) correlations for all the SMEchas" << endl;}
03495 
03496   //...... Calculation of the correction factor to the correlations (g_{jj'})
03497   //       g_{jj'} = f_{jj'}/ ( sqrt(f_{jj} sqrt(f_{j'j'}) )
03498 
03499   for ( Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
03500     {
03501       // to be done...
03502       fTagCorCorrecCovCss[i_SMEcha] = 1;         fFileHeader->fCorCorrecCovCssCalc++;
03503     }
03504 }
03505 //########################## (END OF CORRECTION METHODS) ####################################
03506 
03507 //=========================================================================
03508 //
03509 //                  W R I T I N G     M E T H O D S
03510 //
03511 //=========================================================================
03512 
03513 //=======================================================================
03514 //
03515 //        M E T H O D S    T O    G E T    T H E   P A T H S
03516 //
03517 //        O F    T H E    R E S U L T S    F I L E S
03518 //
03519 //=======================================================================
03520 void TCnaRunEB::GetPathForResultsRootFiles()
03521 {
03522   GetPathForResultsRootFiles("");
03523 }
03524 
03525 void TCnaRunEB::GetPathForResultsRootFiles(const TString argFileName)
03526 {
03527   // Init fCfgResultsRootFilePath and get it from the file named argFileName
03528   // argFileName = complete name of the file (/afs/cern.ch/...)
03529   // if string is empty, file name = "cna_results_root.cfg" and file located in $HOME user's directory (default)
03530 
03531   Int_t MaxCar = fgMaxCar;
03532   fCfgResultsRootFilePath.Resize(MaxCar);
03533   fCfgResultsRootFilePath            = "?";
03534 
03535   //..... put the name of the ascii file (containing the paths for CNA treatements)
03536   //      in the string cFileNameForCnaPaths and in class attribute fFileForResultsRootFilePath
03537 
03538   if ( argFileName == "" )
03539     {
03540       string cFileNameForCnaPaths = "cna_results_root.cfg";     // config file name
03541       TString s_file_name = cFileNameForCnaPaths.c_str();
03542       Text_t *t_file_name = (Text_t *)s_file_name.Data();
03543       
03544       TString s_path_name = gSystem->Getenv("HOME");       // get user's home directory path
03545       
03546       fFileForResultsRootFilePath = s_path_name;
03547       fFileForResultsRootFilePath.Append('/');
03548       fFileForResultsRootFilePath.Append(t_file_name);
03549     }
03550   else
03551     {
03552       fFileForResultsRootFilePath = argFileName.Data();
03553     }
03554 
03555   //........ Reading of the paths in the file named fFileForResultsRootFilePath.Data()
03556   //
03557 
03558   fFcin_rr.open(fFileForResultsRootFilePath.Data());
03559   if(fFcin_rr.fail() == kFALSE)
03560     {
03561       fFcin_rr.clear();
03562       string xResultsFileP;
03563       fFcin_rr >> xResultsFileP;
03564       fCfgResultsRootFilePath = xResultsFileP.c_str();
03565 
03566       fCnaCommand++;
03567       cout << "   *CNA [" << fCnaCommand << "]> Automatic registration of cna paths -> " << endl
03568            << "    Results .root files: " << fCfgResultsRootFilePath.Data() << endl;
03569       fFcin_rr.close();
03570 
03571       //.............. Making of the results .root file name (TCnaRunEB specific)
03572       fMakeResultsFileName(fCodeRoot);
03573     }
03574   else
03575     {
03576       fFcin_rr.clear();
03577       fCnaError++;
03578       cout << fTTBELL << endl
03579            << " ***************************************************************************** " << endl;
03580       cout << "   !CNA(TCnaRunEB) (" << fCnaError << ") *** ERROR *** " << endl << endl
03581            << "    "
03582            << fFileForResultsRootFilePath.Data() << ": file not found. " << endl
03583            << "    "
03584            << endl << endl
03585            << "    "
03586            << " The file " << fFileForResultsRootFilePath.Data()
03587            << " is a configuration file for the CNA and"
03588            << " must contain one line with the following syntax:" << endl << endl
03589            << "    "
03590            << "   path of the results .root files ($HOME/etc...) " << endl
03591            << "    "
03592            << "          (without slash at the end of line)" << endl
03593            << endl << endl
03594            << "    "
03595            << " EXAMPLE:" << endl << endl
03596            << "    "
03597            << "  $HOME/scratch0/cna/results_root_files" << endl << endl
03598            << " ***************************************************************************** "
03599            << fTTBELL << endl;
03600 
03601       fFcin_rr.close();
03602     }
03603 }
03604 
03605 //================================================================================================
03606 
03607 void TCnaRunEB::GetPathForResultsAsciiFiles()
03608 {
03609   GetPathForResultsAsciiFiles("");
03610 }
03611 
03612 void TCnaRunEB::GetPathForResultsAsciiFiles(const TString argFileName)
03613 {
03614   // Init fCfgResultsAsciiFilePath and get it from the file named argFileName
03615   // argFileName = complete name of the file (/afs/cern.ch/...)
03616   // if string is empty, file name = "cna_results_ascii.cfg"
03617   // and file located in $HOME user's directory (default)
03618 
03619   Int_t MaxCar = fgMaxCar;
03620   fCfgResultsAsciiFilePath.Resize(MaxCar);
03621   fCfgResultsAsciiFilePath = "?";
03622 
03623   //..... put the name of the ascii file (containing the paths for CNA treatements)
03624   //      in the string cFileNameForCnaPaths and in class attribute fFileForResultsAsciiFilePath
03625 
03626   if ( argFileName == "" )
03627     {
03628       string cFileNameForCnaPaths = "cna_results_ascii.cfg";     // config file name
03629       TString s_file_name = cFileNameForCnaPaths.c_str();
03630       Text_t *t_file_name = (Text_t *)s_file_name.Data();
03631       
03632       TString s_path_name = gSystem->Getenv("HOME");       // get user's home directory path
03633       
03634       fFileForResultsAsciiFilePath = s_path_name;
03635       fFileForResultsAsciiFilePath.Append('/');
03636       fFileForResultsAsciiFilePath.Append(t_file_name);
03637     }
03638   else
03639     {
03640       fFileForResultsAsciiFilePath = argFileName.Data();
03641     }
03642 
03643   //........ Reading of the paths in the file named fFileForResultsAsciiFilePath.Data()
03644   //
03645 
03646   fFcin_ra.open(fFileForResultsAsciiFilePath.Data());
03647   if(fFcin_ra.fail() == kFALSE)
03648     {
03649       fFcin_ra.clear();
03650       string xResultsFileP;
03651       fFcin_ra >> xResultsFileP;
03652       fCfgResultsAsciiFilePath = xResultsFileP.c_str();
03653 
03654       fCnaCommand++;
03655       cout << "   *CNA [" << fCnaCommand << "]> Automatic registration of cna paths -> " << endl
03656            << "    Results .ascii files: " << fCfgResultsAsciiFilePath.Data() << endl;
03657       fFcin_ra.close();
03658       
03659       //.........................Making of the results .ascii file name (TCnaRunEB specific)
03660       fMakeResultsFileName(fCodeHeaderAscii);
03661     }
03662   else
03663     {
03664       fFcin_ra.clear();
03665       fCnaError++;
03666       cout << fTTBELL << endl
03667            << " ***************************************************************************** " << endl;
03668       cout << "   !CNA(TCnaRunEB) (" << fCnaError << ") *** ERROR *** " << endl << endl
03669            << "    "
03670            << fFileForResultsAsciiFilePath.Data() << ": file not found. " << endl
03671            << "    "
03672            << endl << endl
03673            << "    "
03674            << " The file " << fFileForResultsAsciiFilePath.Data()
03675            << " is a configuration file for the CNA and"
03676            << " must contain one line with the following syntax:" << endl << endl
03677            << "    "
03678            << "   path of the results .ascii files ($HOME/etc...) " << endl
03679            << "    "
03680            << "          (without slash at the end of line)" << endl
03681            << endl << endl
03682            << "    "
03683            << " EXAMPLE:" << endl << endl
03684            << "    "
03685            << "  $HOME/scratch0/cna/results_ascii_files" << endl << endl
03686            << " ***************************************************************************** "
03687            << fTTBELL << endl;
03688 
03689       fFcin_ra.close();
03690     }
03691 }
03692 
03693 //=========================================================================
03694 //
03695 //         W R I T I N G   M E T H O D S :    R O O T    F I L E S
03696 //
03697 //=========================================================================
03698 //-------------------------------------------------------------
03699 //
03700 //                      OpenRootFile
03701 //
03702 //-------------------------------------------------------------
03703 Bool_t TCnaRunEB::OpenRootFile(Text_t *name, TString status) {
03704 //Open the Root file
03705 
03706   TString s_path;
03707   s_path = fCfgResultsRootFilePath;
03708   s_path.Append('/');
03709   s_path.Append(name);
03710   
03711   gCnaRootFile   = new TCnaRootFile(s_path.Data(), status);     fCnew++;
03712 
03713   Bool_t ok_open = kFALSE;
03714 
03715   if ( gCnaRootFile->fRootFileStatus == "RECREATE" )
03716     {
03717       ok_open = gCnaRootFile->OpenW();
03718     }
03719   if ( gCnaRootFile->fRootFileStatus == "READ"     )
03720     {
03721       ok_open = gCnaRootFile->OpenR();
03722     }
03723 
03724   if (!ok_open) // unable to open file
03725     {
03726       cout << "TCnaRunEB::OpenRootFile> Cannot open file " << s_path.Data() << endl;
03727 
03728     }
03729   else
03730     {
03731       if(fFlagPrint == fCodePrintAllComments){
03732         cout << "*TCnaRunEB::OpenRootFile> Open ROOT file OK for file " << s_path.Data() << endl;}
03733       
03734       fOpenRootFile  = kTRUE;
03735     }
03736   
03737   return ok_open;
03738 }
03739 
03740 //-------------------------------------------------------------
03741 //
03742 //                      CloseRootFile
03743 //
03744 //-------------------------------------------------------------
03745 Bool_t TCnaRunEB::CloseRootFile(Text_t *name) {
03746 //Close the Root file
03747  
03748   Bool_t ok_close = kFALSE;
03749 
03750   if (fOpenRootFile == kTRUE ) 
03751     {
03752       gCnaRootFile->CloseFile();
03753 
03754       if(fFlagPrint == fCodePrintAllComments){
03755         cout << "*TCnaRunEB::CloseRootFile> Close ROOT file OK " << endl;}
03756 
03757       delete gCnaRootFile;                                     fCdelete++;
03758       fOpenRootFile = kFALSE;
03759       ok_close      = kTRUE;
03760     }
03761   else
03762     {
03763       cout << "*TCnaRunEB::CloseRootFile(...)> no close since no file is open"
03764            << fTTBELL << endl;
03765     }
03766 
03767   return ok_close;
03768 }
03769 //-------------------------------------------------------------
03770 //
03771 //            WriteRootFile without arguments.
03772 //            Call WriteRootFile WITH argument (file name)
03773 //            after an automatic generation of the file name.
03774 //
03775 //            Codification for the file name:
03776 //
03777 //                  AAA_RRR_FFF_LLL_SSS.root
03778 //
03779 //            AAA: Analysis name
03780 //            RRR: Run number
03781 //            FFF: First analysed event number
03782 //            LLL: Last  analysed event number
03783 //            SSS: SuperModule number
03784 //
03785 //-------------------------------------------------------------
03786 Bool_t TCnaRunEB::WriteRootFile() {
03787 //Write the Root file. File name automatically generated in fMakeResultsFileName.
03788 
03789   Bool_t ok_write = kFALSE;
03790   fMakeResultsFileName(fCodeRoot);  // set fRootFileName, fRootFileNameShort,
03791                                     // fAsciiFileName, fAsciiFileNameShort,
03792                                     // fResultsFileName and fResultsFileNameShort
03793 
03794   Text_t *s_name = (Text_t *)fRootFileNameShort.Data();
03795 
03796   if(fFlagPrint != fCodePrintNoComment){
03797     cout << "*TCnaRunEB::WriteRootFile()> Results are going to be written in the ROOT file: " << endl
03798          << "                           " <<  fRootFileName.Data() << endl;}
03799 
03800   ok_write = WriteRootFile(s_name);
03801   
03802   return ok_write;
03803 }
03804 //-------------------------------------------------------------
03805 //
03806 //               WriteRootFile with argument
03807 //
03808 //-------------------------------------------------------------
03809 Bool_t TCnaRunEB::WriteRootFile(Text_t *name) {
03810 //Write the Root file
03811 
03812   Text_t *file_name = name;
03813 
03814   Bool_t ok_open  = kFALSE;
03815   Bool_t ok_write = kFALSE;
03816 
03817   if ( fOpenRootFile )
03818     {
03819       cout << "!TCnaRunEB::WriteRootFile(...) *** ERROR ***> Writing on file already open."
03820            << fTTBELL << endl;
03821     }
03822   else
03823     {
03824       //..... List of the different element types and associated parameters as ordered in the ROOT file
03825       //
03826       //   Nb of   Type of element          Type      Type                                      Size    Comment
03827       // elements                           Number    Name
03828       //
03829       //        1  fMatHis(1,tower)         ( 0)  cTypTowerNumbers        1*(   1,  68) =         68
03830 
03831       //        1  fMatHis(1,SMEcha)        (16)  cTypEvEv                1*(   1,1700) =      1 700
03832       //        1  fMatHis(1,SMEcha)        (17)  cTypEvSig               1*(   1,1700) =      1 700
03833       //        1  fMatHis(1,SMEcha)        (10)  cTypEvCorCss            1*(   1,1700) =      1 700
03834 
03835       //        1  fMatHis(1,SMEcha)        (18)  cTypSigEv               1*(   1,1700) =      1 700
03836       //        1  fMatHis(1,SMEcha)        (19)  cTypSigSig              1*(   1,1700) =      1 700
03837       //        1  fMatHis(1,SMEcha)        (11)  cTypSigCorCss           1*(   1,1700) =      1 700
03838 
03839       //        1  fMatMat(tower,tower)     (23)  cTypCovMosccMot         1*(  68,  68) =      4 624
03840       //        1  fMatMat(tower,tower)     (24)  cTypCorMosccMot         1*(  68,  68) =      4 624
03841 
03842       //        1  fMatHis(SMEcha, sample)  (15)  cTypLastEvtNumber       1*(1700,  10) =     17 000
03843       //        1  fMatHis(SMEcha, sample)  ( 1)  cTypEv                  1*(1700,  10) =     17 000
03844       //        1  fMatHis(SMEcha, sample)  ( 2)  cTypVar                 1*(1700,  10) =     17 000
03845 
03846       //        1  fMatHis(SMEcha, sample)  (12)  cTypSvCorrecCovCss      1*(1700,  10) =     17 000
03847 
03848       //   SMEcha  fMatMat(sample, sample)  ( 8)  cTypCovCss           1700*(  10,  10) =    170 000
03849       //   SMEcha  fMatMat(sample, sample   ( 9)  cTypCorCss           1700*(  10,  10) =    170 000
03850 
03851       //   SMEcha  fMatHis(sample, bin_adc) ( 3)  cTypEvts,            1700*(  10, 100) =  1 700 000
03852       //        1  fMatHis(SMEcha, sample)  ( 4)  cTypEvtsXmin            1*(1700,  10) =     17 000
03853       //        1  fMatHis(SMEcha, sample   ( 5)  cTypEvtsXmax            1*(1700,  10) =     17 000
03854 
03855       //   SMEcha  fMatHis(sample, bin_evt) (20)  cTypSampTime,        1700*(  10, 150) =  2 550 000
03856 
03857       //        1  fMatMat(SMEcha, SMEcha)  (21)  cTypCovSccMos           1*(1700,1700) =  2 890 000
03858       //        1  fMatMat(SMEcha, SMEcha)  (22)  cTypCorSccMos           1*(1700,1700) =  2 890 000
03859 
03860       //   SMEcha  fMatMat(sample, sample)  (13)  cTypCovCorrecCovCss  1700*(  10,  10) =    170 000
03861       //   SMEcha  fMatMat(sample, sample)  (14)  cTypCorCorrecCovCss  1700*(  10,  10) =    170 000
03862 
03863       //......................................................................................................
03864 
03865       ok_open = OpenRootFile(file_name, "RECREATE");
03866 
03867       TString typ_name = "?";
03868       Int_t v_nb_times = 0;
03869       Int_t v_dim_one  = 0;
03870       Int_t v_dim_two  = 0;
03871       Int_t v_size     = 0;
03872       Int_t v_tot      = 0;
03873       Int_t v_tot_writ = 0;
03874 
03875       //-------------------------- Tower numbers 
03876       //       1   fMatHis(1,tower)           ( 0)  cTypTowerNumbers        1*(   1,  68) =         68
03877 
03878       Int_t MaxCar = fgMaxCar;
03879       typ_name.Resize(MaxCar);
03880       typ_name   = "TowerNumbers";
03881       v_nb_times = fFileHeader->fTowerNumbersCalc;
03882       v_dim_one  = 1;
03883       v_dim_two  = fFileHeader->fMaxTowInSM;
03884       v_size     = v_nb_times*v_dim_one*v_dim_two;
03885       v_tot     += v_size;
03886 
03887       if(fFlagPrint != fCodePrintNoComment){
03888       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03889            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03890            << setw(9) << v_size;}
03891 
03892       for (Int_t i = 0; i < v_nb_times; i++)
03893         {
03894           if ( fTagTowerNumbers[0] == 1 )
03895             {
03896               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypTowerNumbers;
03897               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03898               gCnaRootFile->fCnaIndivResult->
03899                 SetSizeHis(1,fFileHeader->fMaxTowInSM);
03900               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03901               TRootTowerNumbers();
03902               gCnaRootFile->fCnaResultsTree->Fill();
03903               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03904             }
03905         }
03906       cout << endl;
03907 
03908       //-------------------------- Expectation values of the expectation values the samples
03909       //       1   fMatHis(1,SMEcha)         (16)  cTypEvEv                1*(   1,1700) =      1 700
03910 
03911       MaxCar = fgMaxCar;
03912       typ_name.Resize(MaxCar);
03913       typ_name   = "EvEv";
03914       v_nb_times = fFileHeader->fEvEvCalc;
03915       v_dim_one  = 1;
03916       v_dim_two  = fFileHeader->fMaxCrysInSM;
03917       v_size     = v_nb_times*v_dim_one*v_dim_two;
03918       v_tot     += v_size;
03919 
03920       if(fFlagPrint != fCodePrintNoComment){
03921       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03922            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03923            << setw(9) << v_size;}
03924 
03925       for (Int_t i = 0; i < v_nb_times; i++)
03926         {
03927           if ( fTagEvEv[0] == 1 )
03928             {
03929               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypEvEv;
03930               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03931               gCnaRootFile->fCnaIndivResult->
03932                 SetSizeHis(1,fFileHeader->fMaxCrysInSM);
03933               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03934               TRootEvEv();
03935               gCnaRootFile->fCnaResultsTree->Fill();
03936               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03937             }
03938         }
03939       cout << endl;
03940                   
03941       //-------------------------- Expectation values of the sigmas the samples
03942       //       1   fMatHis(1,SMEcha)         (17)  cTypEvSig               1*(   1,1700) =      1 700
03943 
03944       MaxCar = fgMaxCar;
03945       typ_name.Resize(MaxCar);
03946       typ_name   = "EvSig";
03947       v_nb_times = fFileHeader->fEvSigCalc;
03948       v_dim_one  = 1;
03949       v_dim_two  = fFileHeader->fMaxCrysInSM;
03950       v_size     = v_nb_times*v_dim_one*v_dim_two;
03951       v_tot     += v_size;
03952 
03953       if(fFlagPrint != fCodePrintNoComment){
03954       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03955            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03956            << setw(9) << v_size;}
03957 
03958       for (Int_t i = 0; i < v_nb_times; i++)
03959         {
03960           if ( fTagEvSig[0] == 1 )
03961             {
03962               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypEvSig;
03963               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03964               gCnaRootFile->fCnaIndivResult->
03965                 SetSizeHis(1,fFileHeader->fMaxCrysInSM);
03966               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
03967               TRootEvSig();
03968               gCnaRootFile->fCnaResultsTree->Fill();
03969               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
03970             }
03971         } 
03972       cout << endl;
03973                                      
03974       //-------------------------- Expectation values of the correlations between the samples
03975       //       1   fMatHis(1,SMEcha)         (10)  cTypEvCorCss            1*(   1,1700) =      1 700
03976 
03977       MaxCar = fgMaxCar;
03978       typ_name.Resize(MaxCar);
03979       typ_name   = "EvCorCss";
03980       v_nb_times = fFileHeader->fEvCorCssCalc;
03981       v_dim_one  = 1;
03982       v_dim_two  = fFileHeader->fMaxCrysInSM;
03983       v_size     = v_nb_times*v_dim_one*v_dim_two;
03984       v_tot     += v_size;
03985 
03986       if(fFlagPrint != fCodePrintNoComment){
03987       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
03988            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
03989            << setw(9) << v_size;}
03990 
03991       for (Int_t i = 0; i < v_nb_times; i++)
03992         {
03993           if ( fTagEvCorCss[0] == 1 )
03994             {
03995               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypEvCorCss;
03996               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
03997               gCnaRootFile->fCnaIndivResult->
03998                 SetSizeHis(1,fFileHeader->fMaxCrysInSM);
03999               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04000               TRootEvCorCss();
04001               gCnaRootFile->fCnaResultsTree->Fill();
04002               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04003             }
04004         } 
04005       cout << endl;
04006       
04007       //-------------------------- Sigmas of the expectation values of the samples  
04008       //       1   fMatHis(1,SMEcha)         (18)  cTypSigEv               1*(   1,1700) =      1 700
04009 
04010       MaxCar = fgMaxCar;
04011       typ_name.Resize(MaxCar);
04012       typ_name   = "SigEv";
04013       v_nb_times = fFileHeader->fSigEvCalc;
04014       v_dim_one  = 1;
04015       v_dim_two  = fFileHeader->fMaxCrysInSM;
04016       v_size     = v_nb_times*v_dim_one*v_dim_two;
04017       v_tot     += v_size;
04018 
04019       if(fFlagPrint != fCodePrintNoComment){
04020       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04021            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04022            << setw(9) << v_size;}
04023 
04024       for (Int_t i = 0; i < v_nb_times; i++)
04025         {
04026           if ( fTagSigEv[0] == 1 )
04027             {
04028               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSigEv;
04029               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04030               gCnaRootFile->fCnaIndivResult->
04031                 SetSizeHis(1,fFileHeader->fMaxCrysInSM);
04032               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04033               TRootSigEv();
04034               gCnaRootFile->fCnaResultsTree->Fill();
04035               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04036             }
04037         } 
04038       cout << endl;
04039       
04040       //-------------------------- Sigmas of the sigmas of the samples  
04041       //       1   fMatHis(1,SMEcha)         (19)  cTypSigSig              1*(   1,1700) =      1 700
04042 
04043       MaxCar = fgMaxCar;
04044       typ_name.Resize(MaxCar);
04045       typ_name   = "SigSig";
04046       v_nb_times = fFileHeader->fSigSigCalc;
04047       v_dim_one  = 1;
04048       v_dim_two  = fFileHeader->fMaxCrysInSM;
04049       v_size     = v_nb_times*v_dim_one*v_dim_two;
04050       v_tot     += v_size;
04051 
04052       if(fFlagPrint != fCodePrintNoComment){
04053       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04054            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04055            << setw(9) << v_size;}
04056  
04057       for (Int_t i = 0; i < v_nb_times; i++)
04058         {
04059           if ( fTagSigSig[0] == 1 )
04060             {
04061               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSigSig;
04062               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04063               gCnaRootFile->fCnaIndivResult->
04064                 SetSizeHis(1,fFileHeader->fMaxCrysInSM);
04065               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04066               TRootSigSig();
04067               gCnaRootFile->fCnaResultsTree->Fill();
04068               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04069             }
04070         }
04071       cout << endl; 
04072                     
04073       //-------------------------- Sigmas of the correlations between the samples  
04074       //       1   fMatHis(1,SMEcha)         (11)  cTypSigCorCss           1*(   1,1700) =      1 700
04075 
04076       MaxCar = fgMaxCar;
04077       typ_name.Resize(MaxCar);
04078       typ_name   = "SigCorCss";
04079       v_nb_times = fFileHeader->fSigCorCssCalc;
04080       v_dim_one  = 1;
04081       v_dim_two  = fFileHeader->fMaxCrysInSM;
04082       v_size     = v_nb_times*v_dim_one*v_dim_two;
04083       v_tot     += v_size;
04084 
04085       if(fFlagPrint != fCodePrintNoComment){
04086       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04087            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04088            << setw(9) << v_size;}
04089    
04090       for (Int_t i = 0; i < v_nb_times; i++)
04091         {
04092           if ( fTagSigCorCss[0] == 1 )
04093             {
04094               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSigCorCss;
04095               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04096               gCnaRootFile->fCnaIndivResult->
04097                 SetSizeHis(1,fFileHeader->fMaxCrysInSM);
04098               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04099               TRootSigCorCss();
04100               gCnaRootFile->fCnaResultsTree->Fill();
04101               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04102             }
04103         } 
04104       cout << endl;
04105             
04106       //----- Mean Covariances between SMEchas (averaged over samples) for all (tower_X,tower_Y)
04107       //       1   fMatMat(tower,tower)       (23)  cTypCovMosccMot         1*(  68,  68) =      4 624
04108 
04109       MaxCar = fgMaxCar;
04110       typ_name.Resize(MaxCar);
04111       typ_name   = "CovMosccMot";
04112       v_nb_times = fFileHeader->fCovMosccMotCalc;
04113       v_dim_one  = fFileHeader->fMaxTowInSM;
04114       v_dim_two  = fFileHeader->fMaxTowInSM;
04115       v_size     = v_nb_times*v_dim_one*v_dim_two;
04116       v_tot     += v_size;
04117  
04118       if(fFlagPrint != fCodePrintNoComment){
04119       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04120            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04121            << setw(9) << v_size;}
04122 
04123       for (Int_t i = 0; i < v_nb_times; i++)
04124         {
04125           if ( fTagCovMosccMot[0] == 1 )
04126             {
04127               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCovMosccMot;
04128               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04129               gCnaRootFile->fCnaIndivResult->
04130                 SetSizeMat(fFileHeader->fMaxTowInSM,fFileHeader->fMaxTowInSM);
04131               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04132               TRootCovMosccMot();
04133               gCnaRootFile->fCnaResultsTree->Fill();
04134               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04135             }
04136         } 
04137       cout << endl;
04138             
04139       //----- Mean Correlations between SMEchas (averaged over samples) for all (tower_X,tower_Y)
04140       //       1   fMatMat(tower,tower)       (24)  cTypCorMosccMot         1*(  68,  68) =      4 624
04141 
04142       MaxCar = fgMaxCar;
04143       typ_name.Resize(MaxCar);
04144       typ_name   = "CorMosccMot";
04145       v_nb_times = fFileHeader->fCorMosccMotCalc;
04146       v_dim_one  = fFileHeader->fMaxTowInSM;
04147       v_dim_two  = fFileHeader->fMaxTowInSM;
04148       v_size     = v_nb_times*v_dim_one*v_dim_two;
04149       v_tot     += v_size;
04150  
04151       if(fFlagPrint != fCodePrintNoComment){
04152       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04153            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04154            << setw(9) << v_size;}
04155 
04156       for (Int_t i = 0; i < v_nb_times; i++)
04157         {
04158           if ( fTagCorMosccMot[0] == 1 )
04159             {
04160               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCorMosccMot;
04161               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04162               gCnaRootFile->fCnaIndivResult->
04163                 SetSizeMat(fFileHeader->fMaxTowInSM,fFileHeader->fMaxTowInSM);
04164               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04165               TRootCorMosccMot();
04166               gCnaRootFile->fCnaResultsTree->Fill();
04167               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04168             }
04169         } 
04170       cout << endl;
04171       
04172       //-------------------------- Numbers of found events (LastEvtNumber)
04173       //       1   fMatHis(SMEcha, sample)   (15)  cTypLastEvtNumber       1*(1700,  10) =     17 000
04174 
04175       MaxCar = fgMaxCar;
04176       typ_name.Resize(MaxCar);
04177       typ_name   = "LastEvtNumber";
04178       v_nb_times = fFileHeader->fLastEvtNumberCalc;
04179       v_dim_one  = fFileHeader->fMaxCrysInSM;
04180       v_dim_two  = fFileHeader->fMaxSampADC;
04181       v_size     = v_nb_times*v_dim_one*v_dim_two;
04182       v_tot     += v_size;
04183  
04184       if(fFlagPrint != fCodePrintNoComment){
04185       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04186            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04187            << setw(9) << v_size;}
04188 
04189       for (Int_t i = 0; i < v_nb_times; i++)
04190         {
04191           if ( fTagLastEvtNumber[0] == 1 )
04192             {
04193               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypLastEvtNumber;
04194               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04195               gCnaRootFile->fCnaIndivResult->
04196                 SetSizeHis(fFileHeader->fMaxCrysInSM,fFileHeader->fMaxSampADC);
04197               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04198               TRootLastEvtNumber();
04199               gCnaRootFile->fCnaResultsTree->Fill();
04200               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04201             }
04202         }
04203       cout << endl;
04204                   
04205       //-------------------------- Expectation values of the samples
04206       //       1   fMatHis(SMEcha, sample)   ( 1)  cTypEv                  1*(1700,  10) =     17 000
04207 
04208       MaxCar = fgMaxCar;
04209       typ_name.Resize(MaxCar);
04210       typ_name   = "Ev";
04211       v_nb_times = fFileHeader->fEvCalc;
04212       v_dim_one  = fFileHeader->fMaxCrysInSM;
04213       v_dim_two  = fFileHeader->fMaxSampADC;
04214       v_size     = v_nb_times*v_dim_one*v_dim_two;
04215       v_tot     += v_size;
04216  
04217       if(fFlagPrint != fCodePrintNoComment){
04218       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04219            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04220            << setw(9) << v_size;}
04221 
04222       for (Int_t i = 0; i < v_nb_times; i++)
04223         {
04224           if ( fTagEv[0] == 1 )
04225             {
04226               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypEv;
04227               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04228               gCnaRootFile->fCnaIndivResult->
04229                 SetSizeHis(fFileHeader->fMaxCrysInSM,fFileHeader->fMaxSampADC);
04230               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04231               TRootEv();
04232               gCnaRootFile->fCnaResultsTree->Fill();
04233               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04234             }
04235         }
04236       cout << endl;
04237       
04238       //-------------------------- Variances of the samples     
04239       //       1   fMatHis(SMEcha, sample)   ( 2)  cTypVar                 1*(1700,  10) =     17 000
04240 
04241       MaxCar = fgMaxCar;
04242       typ_name.Resize(MaxCar);
04243       typ_name   = "Var";
04244       v_nb_times = fFileHeader->fVarCalc;
04245       v_dim_one  = fFileHeader->fMaxCrysInSM;
04246       v_dim_two  = fFileHeader->fMaxSampADC;
04247       v_size     = v_nb_times*v_dim_one*v_dim_two;
04248       v_tot     += v_size;
04249  
04250       if(fFlagPrint != fCodePrintNoComment){
04251       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04252            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04253            << setw(9) << v_size;}
04254 
04255       for (Int_t i = 0; i < v_nb_times; i++)
04256         {
04257           if ( fTagVar[0] == 1 )
04258             {
04259               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypVar;
04260               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04261               gCnaRootFile->fCnaIndivResult->
04262                 SetSizeHis(fFileHeader->fMaxCrysInSM,fFileHeader->fMaxSampADC);
04263               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04264               TRootVar();
04265               gCnaRootFile->fCnaResultsTree->Fill();
04266               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04267             }
04268         }
04269       cout << endl;
04270 
04271       //-------------------------- Corrections to the sample values from cov(s,s)
04272       //       1   fMatHis(SMEcha, sample)   (12)  cTypSvCorrecCovCss      1*(1700,  10) =     17 000
04273 
04274       MaxCar = fgMaxCar;
04275       typ_name.Resize(MaxCar);
04276       typ_name   = "SvCorrecCovCss";
04277       v_nb_times = fFileHeader->fSvCorrecCovCssCalc;
04278       v_dim_one  = fFileHeader->fMaxCrysInSM;
04279       v_dim_two  = fFileHeader->fMaxSampADC;
04280       v_size     = v_nb_times*v_dim_one*v_dim_two;
04281       v_tot     += v_size;
04282  
04283       if(fFlagPrint != fCodePrintNoComment){
04284       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04285            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04286            << setw(9) << v_size;}
04287 
04288       for (Int_t i = 0; i < v_nb_times; i++)
04289         {
04290           if ( fTagSvCorrecCovCss[0] == 1 )
04291             {
04292               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSvCorrecCovCss;
04293               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04294               gCnaRootFile->fCnaIndivResult->
04295                 SetSizeHis(fFileHeader->fMaxCrysInSM,fFileHeader->fMaxSampADC);
04296               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04297               TRootSvCorrecCovCss();
04298               gCnaRootFile->fCnaResultsTree->Fill();
04299               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04300             }
04301         } 
04302       cout << endl;
04303       
04304       //-------------------------- Covariances between samples
04305 
04306       // SMEcha   fMatMat(sample,  sample)   ( 8)  cTypCovCss           1700*(  10,  10) =    170 000
04307 
04308       MaxCar = fgMaxCar;
04309       typ_name.Resize(MaxCar);
04310       typ_name   = "CovCss";
04311       v_nb_times = fFileHeader->fCovCssCalc;
04312       v_dim_one  = fFileHeader->fMaxSampADC;
04313       v_dim_two  = fFileHeader->fMaxSampADC;
04314       v_size     = v_nb_times*v_dim_one*v_dim_two;
04315       v_tot     += v_size;
04316  
04317       if(fFlagPrint != fCodePrintNoComment){
04318       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04319            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04320            << setw(9) << v_size;}
04321 
04322       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04323         {
04324           if ( fTagCovCss[i_SMEcha] == 1 )
04325             {
04326               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCovCss;
04327               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04328               gCnaRootFile->fCnaIndivResult->
04329                 SetSizeMat(fFileHeader->fMaxSampADC,fFileHeader->fMaxSampADC);
04330               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04331               TRootCovCss(i_SMEcha);
04332               gCnaRootFile->fCnaResultsTree->Fill();
04333               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04334             }
04335         }
04336       cout << endl;
04337       
04338       //-------------------------- Correlations between samples   
04339       // SMEcha   fMatMat(sample,  sample)   ( 9)  cTypCorCss           1700*(  10,  10) =    170 000
04340 
04341       MaxCar = fgMaxCar;
04342       typ_name.Resize(MaxCar);
04343       typ_name   = "CorCss";
04344       v_nb_times = fFileHeader->fCorCssCalc;
04345       v_dim_one  = fFileHeader->fMaxSampADC;
04346       v_dim_two  = fFileHeader->fMaxSampADC;
04347       v_size     = v_nb_times*v_dim_one*v_dim_two;
04348       v_tot     += v_size;
04349 
04350       if(fFlagPrint != fCodePrintNoComment){
04351       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04352            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04353            << setw(9) << v_size;}
04354  
04355       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04356         {
04357           if ( fTagCorCss[i_SMEcha] == 1 )
04358             {
04359               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCorCss;
04360               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04361               gCnaRootFile->fCnaIndivResult->
04362                 SetSizeMat(fFileHeader->fMaxSampADC,fFileHeader->fMaxSampADC);
04363               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04364               TRootCorCss(i_SMEcha);
04365               gCnaRootFile->fCnaResultsTree->Fill();
04366               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04367             }     
04368         }
04369       cout << endl;
04370 
04371       //-------------------------- Event distributions
04372       // SMEcha   fMatHis(sample,  bins)     ( 3)  cTypEvts,            1700*(  10, 100) =  1 700 000
04373 
04374       MaxCar = fgMaxCar;
04375       typ_name.Resize(MaxCar);
04376       typ_name   = "Evts";
04377       v_nb_times = fFileHeader->fEvtsCalc;
04378       v_dim_one  = fFileHeader->fMaxSampADC;
04379       v_dim_two  = fFileHeader->fNbBinsADC;
04380       v_size     = v_nb_times*v_dim_one*v_dim_two;
04381       v_tot     += v_size;
04382 
04383       if(fFlagPrint != fCodePrintNoComment){
04384       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04385            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04386            << setw(9) << v_size;}
04387 
04388       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04389         {
04390           if ( fTagEvts[i_SMEcha] == 1 )
04391             {
04392               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypEvts;
04393               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04394               gCnaRootFile->fCnaIndivResult->
04395                 SetSizeHis(fFileHeader->fMaxSampADC,fFileHeader->fNbBinsADC);
04396               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04397               TRootEvts(i_SMEcha);
04398               gCnaRootFile->fCnaResultsTree->Fill(); 
04399               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04400             }
04401         }
04402       cout << endl;
04403 
04404       //-------------------------- Event distributions Xmin
04405       //       1   fMatHis(cna_SMEcha, sample)   ( 4)  cTypEvtsXmin            1*(1700,  10) =     17 000
04406 
04407       MaxCar = fgMaxCar;
04408       typ_name.Resize(MaxCar);
04409       typ_name   = "EvtsXmin";
04410       v_nb_times = fFileHeader->fEvtsCalc;
04411       v_dim_one  = 1;
04412       v_dim_two  = fFileHeader->fMaxSampADC;
04413       v_size     = v_nb_times*v_dim_one*v_dim_two;
04414       v_tot     += v_size;
04415  
04416       if(fFlagPrint != fCodePrintNoComment){
04417       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04418            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04419            << setw(9) << v_size;}
04420       
04421       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04422         {
04423           if ( fTagEvts[i_SMEcha] == 1 )
04424             {
04425               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypEvtsXmin;
04426               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04427               gCnaRootFile->fCnaIndivResult->
04428                 SetSizeHis(1,fFileHeader->fMaxSampADC);
04429               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04430               TRootEvtsXmin(i_SMEcha);
04431               gCnaRootFile->fCnaResultsTree->Fill();
04432               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04433             }
04434         }
04435       cout << endl;
04436       
04437       //-------------------------- Event distributions Xmax
04438       //       1   fMatHis(SMEcha, sample)   ( 5)  cTypEvtsXmax            1*(1700,  10) =     17 000
04439 
04440       MaxCar = fgMaxCar;      
04441       typ_name.Resize(MaxCar);
04442       typ_name   = "EvtsXmax";
04443       v_nb_times = fFileHeader->fEvtsCalc;
04444       v_dim_one  = 1;
04445       v_dim_two  = fFileHeader->fMaxSampADC;
04446       v_size     = v_nb_times*v_dim_one*v_dim_two;
04447       v_tot     += v_size;
04448  
04449       if(fFlagPrint != fCodePrintNoComment){
04450       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04451            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04452            << setw(9) << v_size;}
04453       
04454       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04455         {
04456           if ( fTagEvts[i_SMEcha] == 1 )
04457             {
04458               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypEvtsXmax;
04459               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04460               gCnaRootFile->fCnaIndivResult->
04461                 SetSizeHis(1,fFileHeader->fMaxSampADC);
04462               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04463               TRootEvtsXmax(i_SMEcha);
04464               gCnaRootFile->fCnaResultsTree->Fill();
04465               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04466             }
04467         }
04468       cout << endl;
04469 
04470       //-------------------------- Samples as a function of event
04471       // SMEcha   fMatHis(sample,  bins)     (20)  cTypSampTime,        1700*(  10, 200) =  3 400 000
04472 
04473       MaxCar = fgMaxCar;
04474       typ_name.Resize(MaxCar);
04475       typ_name   = "SampTime";
04476       v_nb_times = fFileHeader->fSampTimeCalc;
04477       v_dim_one  = fFileHeader->fMaxSampADC;
04478       v_dim_two  = fFileHeader->fNbOfTakenEvts;
04479       v_size     = v_nb_times*v_dim_one*v_dim_two;
04480       v_tot     += v_size;
04481  
04482       if(fFlagPrint != fCodePrintNoComment){
04483       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04484            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04485            << setw(9) << v_size;}
04486 
04487       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04488         {
04489           if ( fTagSampTime[i_SMEcha] == 1 )
04490             {
04491               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypSampTime;
04492               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04493               gCnaRootFile->fCnaIndivResult->
04494                 SetSizeHis(fFileHeader->fMaxSampADC,fFileHeader->fNbOfTakenEvts);
04495               gCnaRootFile->fCnaIndivResult->fMatMat.ReSet(1,1);
04496               TRootSampTime(i_SMEcha);
04497               gCnaRootFile->fCnaResultsTree->Fill();
04498               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04499             }
04500         }
04501       cout << endl;
04502 
04503       //-------------------------- Covariances between SMEchas (Mean Over Samples)
04504       //  sample   fMatMat(SMEcha, SMEcha)  (21)  cTypCovSccMos           1*(1700,1700) =  2 890 000
04505 
04506       MaxCar = fgMaxCar;
04507       typ_name.Resize(MaxCar);
04508       typ_name   = "CovSccMos";
04509       v_nb_times = fFileHeader->fCovSccMosCalc;
04510       v_dim_one  = fFileHeader->fMaxCrysInSM;
04511       v_dim_two  = fFileHeader->fMaxCrysInSM;
04512       v_size     = v_nb_times*v_dim_one*v_dim_two;
04513       v_tot     += v_size;
04514  
04515       if(fFlagPrint != fCodePrintNoComment){
04516       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04517            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04518            << setw(9) << v_size;}
04519 
04520       for (Int_t i = 0; i < v_nb_times; i++)
04521         {
04522           if ( fTagCovSccMos[0] == 1 )
04523             {
04524               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCovSccMos;
04525               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04526               gCnaRootFile->fCnaIndivResult->
04527                 SetSizeMat(fFileHeader->fMaxCrysInSM,fFileHeader->fMaxCrysInSM);
04528               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04529               TRootCovSccMos();
04530               gCnaRootFile->fCnaResultsTree->Fill();
04531               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04532             }
04533         } 
04534       cout << endl;
04535       
04536       //-------------------------- Correlations between SMEchas (Mean Over Samples)
04537       //  sample   fMatMat(SMEcha, SMEcha)  (22)  cTypCorSccMos           1*(1700,1700) =  2 890 000
04538 
04539       MaxCar = fgMaxCar;
04540       typ_name.Resize(MaxCar);
04541       typ_name   = "CorSccMos";
04542       v_nb_times = fFileHeader->fCorSccMosCalc;
04543       v_dim_one  = fFileHeader->fMaxCrysInSM;
04544       v_dim_two  = fFileHeader->fMaxCrysInSM;
04545       v_size     = v_nb_times*v_dim_one*v_dim_two;
04546       v_tot     += v_size;
04547 
04548       if(fFlagPrint != fCodePrintNoComment){
04549       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04550            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04551            << setw(9) << v_size;}
04552 
04553       for (Int_t i = 0; i < v_nb_times; i++)
04554         {
04555           if ( fTagCorSccMos[0] == 1 )
04556             {
04557               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCorSccMos;
04558               gCnaRootFile->fCnaIndivResult->fIthElement     = i;
04559               gCnaRootFile->fCnaIndivResult->
04560                 SetSizeMat(fFileHeader->fMaxCrysInSM,fFileHeader->fMaxCrysInSM);
04561               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04562               TRootCorSccMos();
04563               gCnaRootFile->fCnaResultsTree->Fill();
04564               if( i == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04565             }
04566         }
04567       cout << endl;
04568 
04569       //-------------------------- Correction factors to the covariances from cov(s,s)
04570       // SMEcha   fMatMat(sample,  sample)   (13)  cTypCovCorrecCovCss  1700*(  10,  10) =    170 000
04571 
04572       MaxCar = fgMaxCar;
04573       typ_name.Resize(MaxCar);
04574       typ_name   = "CovCorrecCovCss";
04575       v_nb_times = fFileHeader->fCovCorrecCovCssCalc;
04576       v_dim_one  = fFileHeader->fMaxSampADC;
04577       v_dim_two  = fFileHeader->fMaxSampADC;
04578       v_size     = v_nb_times*v_dim_one*v_dim_two;
04579       v_tot     += v_size;
04580  
04581       if(fFlagPrint != fCodePrintNoComment){
04582       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04583            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04584            << setw(9) << v_size;}
04585 
04586       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04587         {
04588           if ( fTagCovCorrecCovCss[i_SMEcha] == 1 )
04589             {
04590               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCovCorrecCovCss;
04591               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04592               gCnaRootFile->fCnaIndivResult->
04593                 SetSizeMat(fFileHeader->fMaxSampADC,fFileHeader->fMaxSampADC);
04594               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04595               TRootCovCorrecCovCss(i_SMEcha);
04596               gCnaRootFile->fCnaResultsTree->Fill();
04597               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04598             }
04599         } 
04600       cout << endl;
04601       
04602       //-------------------------- Correction factors to the correlations from cov(s,s)
04603       // SMEcha   fMatMat(sample,  sample)   (14)  cTypCorCorrecCovCss  1700*(  10,  10) =    170 000
04604 
04605       MaxCar = fgMaxCar;
04606       typ_name.Resize(MaxCar);
04607       typ_name   = "CorCorrecCovCss";
04608       v_nb_times = fFileHeader->fCorCorrecCovCssCalc;
04609       v_dim_one  = fFileHeader->fMaxSampADC;
04610       v_dim_two  = fFileHeader->fMaxSampADC;
04611       v_size     = v_nb_times*v_dim_one*v_dim_two;
04612       v_tot     += v_size;
04613  
04614       if(fFlagPrint != fCodePrintNoComment){
04615       cout << "*TCnaRunEB::WriteRootFile()> " << setw(18) << typ_name << ": " << setw(4) << v_nb_times
04616            << " * ("  << setw(4) << v_dim_one << ","  << setw(4) << v_dim_two  << ") = "
04617            << setw(9) << v_size;}
04618 
04619       for (Int_t i_SMEcha = 0; i_SMEcha < v_nb_times; i_SMEcha++)
04620         {
04621           if ( fTagCorCorrecCovCss[i_SMEcha] == 1 )
04622             {
04623               gCnaRootFile->fCnaIndivResult->fTypOfCnaResult = cTypCorCorrecCovCss;
04624               gCnaRootFile->fCnaIndivResult->fIthElement     = i_SMEcha;
04625               gCnaRootFile->fCnaIndivResult->
04626                 SetSizeMat(fFileHeader->fMaxSampADC,fFileHeader->fMaxSampADC);
04627               gCnaRootFile->fCnaIndivResult->fMatHis.ReSet(1,1);
04628               TRootCorCorrecCovCss(i_SMEcha);
04629               gCnaRootFile->fCnaResultsTree->Fill();
04630               if( i_SMEcha == 0 ){cout << " => WRITTEN ON FILE "; v_tot_writ += v_size;}
04631             }
04632         }
04633       cout << endl;
04634 
04635       //---------------------------------------------- WRITING 
04636       //...................................... file 
04637       gCnaRootFile->fRootFile->Write();
04638       //...................................... header
04639       fFileHeader->Write();
04640 
04641       //...................................... status message
04642       if(fFlagPrint != fCodePrintNoComment){
04643         cout << "*TCnaRunEB::WriteRootFile()> " << setw(20) << "TOTAL: "
04644              << setw(21) << "CALCULATED = " << setw(9) <<  v_tot
04645              << " => WRITTEN ON FILE = "    << setw(9) << v_tot_writ << endl;}
04646 
04647       if(fFlagPrint != fCodePrintNoComment){
04648         cout << "*TCnaRunEB::WriteRootFile()> Write OK in file " << file_name << " in directory:" << endl
04649              << "                           " << fCfgResultsRootFilePath
04650              << endl;}
04651 
04652       ok_write = kTRUE;
04653 
04654       //...................................... close
04655       CloseRootFile(file_name);
04656     }
04657   return ok_write;
04658 }
04659 
04660 //======================== "PREPA FILL" METHODS ===========================
04661 
04662 //-------------------------------------------------------------------------
04663 //
04664 //  Prepa Fill Tower numbers as a function of the tower index 
04665 //                       (for writing in the ROOT file)
04666 //
04667 //-------------------------------------------------------------------------
04668 void TCnaRunEB::TRootTowerNumbers()
04669 {
04670   if (fTagTowerNumbers[0] == 1 )
04671     {
04672       for (Int_t j_tow = 0; j_tow < fFileHeader->fMaxTowInSM; j_tow++)
04673         {
04674           gCnaRootFile->fCnaIndivResult->fMatHis(0, j_tow) =
04675             fT1d_SMtowFromIndex[j_tow];
04676         }
04677     }
04678 }
04679 
04680 //-------------------------------------------------------------------------
04681 //
04682 //  Prepa Fill last evt numbers for all the (SMEcha,sample)
04683 //                       (for writing in the ROOT file)
04684 //
04685 //-------------------------------------------------------------------------
04686 void TCnaRunEB::TRootLastEvtNumber()
04687 {
04688   if (fTagLastEvtNumber[0] == 1 )
04689     {
04690       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
04691         {
04692           for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04693             {
04694               gCnaRootFile->fCnaIndivResult->fMatHis( j_SMEcha, i_samp) =
04695                 fT2d_LastEvtNumber[j_SMEcha][i_samp] + 1;
04696             }
04697         }
04698     }
04699 }
04700 
04701 //-------------------------------------------------------------------------
04702 //
04703 //  Prepa Fill histogram of samples as a function of event
04704 //                       (for writing in the ROOT file)
04705 //
04706 //-------------------------------------------------------------------------
04707 void TCnaRunEB::TRootSampTime(const Int_t& user_SMEcha)
04708 {
04709   if (fTagSampTime[user_SMEcha] == 1 )
04710     {
04711       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04712         {
04713           //...................... all the bins set to zero
04714           for (Int_t j_bin = 0; j_bin < fFileHeader->fNbOfTakenEvts; j_bin++)
04715             {
04716               gCnaRootFile->fCnaIndivResult->fMatHis(i_samp, j_bin) = (Double_t)0.;
04717             }
04718           //...................... fill the non-zero bins 
04719           for (Int_t j_bin = 0; j_bin < fFileHeader->fNbOfTakenEvts; j_bin++)
04720             {
04721               gCnaRootFile->fCnaIndivResult->fMatHis(i_samp, j_bin) =
04722                 fT3d_distribs[user_SMEcha][i_samp][j_bin];  
04723             }
04724         }
04725     }
04726 }
04727 
04728 //-------------------------------------------------------------------------
04729 //
04730 //  Prepa Fill expectation values of the samples for all the SMEchas
04731 //                       (for writing in the ROOT file)
04732 //
04733 //-------------------------------------------------------------------------
04734 void TCnaRunEB::TRootEv()
04735 {
04736   if (fTagEv[0] == 1 )
04737     {
04738       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
04739         {
04740           for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04741             {
04742               gCnaRootFile->fCnaIndivResult->fMatHis( j_SMEcha, i_samp) =
04743                 fT2d_ev[j_SMEcha][i_samp];
04744             }
04745         }
04746     }
04747 }
04748 
04749 //-------------------------------------------------------------------------
04750 //
04751 //  Prepa Fill variances of the samples for all the SMEchas
04752 //                       (for writing in the ROOT file)
04753 //
04754 //-------------------------------------------------------------------------
04755 void TCnaRunEB::TRootVar()
04756 {
04757   if (fTagVar[0] == 1 )
04758     {
04759       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
04760         {
04761           for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04762             {
04763               gCnaRootFile->fCnaIndivResult->fMatHis( j_SMEcha, i_samp) =
04764                 fT2d_var[j_SMEcha][i_samp];
04765             }
04766         }
04767     }
04768 }
04769 
04770 //-------------------------------------------------------------------------
04771 //
04772 //  Prepa Fill mean covariances between SMEchas, mean over samples
04773 //  for all (tower_X, tower_Y)
04774 //                           (for writing in ROOT file)
04775 //
04776 //-------------------------------------------------------------------------
04777 void TCnaRunEB::TRootCovMosccMot()
04778 {
04779   if (fTagCovMosccMot[0] == 1 )
04780     {
04781       for (Int_t i_tow = 0; i_tow < fFileHeader->fMaxTowInSM; i_tow++)
04782         {
04783           for (Int_t j_tow = 0; j_tow < fFileHeader->fMaxTowInSM; j_tow++)
04784             {
04785               gCnaRootFile->fCnaIndivResult->fMatMat(i_tow, j_tow) =
04786                 fT2d_cov_moscc_mot[i_tow][j_tow];
04787             }
04788         }
04789     }
04790 }
04791 
04792 //-------------------------------------------------------------------------
04793 //
04794 //  Prepa Fill mean correlations between SMEchas, mean over samples
04795 //  for all (tower_X, tower_Y)
04796 //                           (for writing in ROOT file)
04797 //
04798 //-------------------------------------------------------------------------
04799 void TCnaRunEB::TRootCorMosccMot()
04800 {
04801   if (fTagCorMosccMot[0] == 1 )
04802     {
04803       for (Int_t i_tow = 0; i_tow < fFileHeader->fMaxTowInSM; i_tow++)
04804         {
04805           for (Int_t j_tow = 0; j_tow < fFileHeader->fMaxTowInSM; j_tow++)
04806             {
04807               gCnaRootFile->fCnaIndivResult->fMatMat(i_tow, j_tow) =
04808                 fT2d_cor_moscc_mot[i_tow][j_tow];
04809             }
04810         }
04811     }
04812 }
04813 
04814 //-------------------------------------------------------------------------
04815 //
04816 //  Prepa Fill ADC distributions of the samples for all the SMEchas
04817 //                       (for writing in the ROOT file)
04818 //
04819 //-------------------------------------------------------------------------
04820 void TCnaRunEB::TRootEvts(const Int_t& user_SMEcha)
04821 {
04822   if (fTagEvts[user_SMEcha] == 1 )
04823     {
04824       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04825         {
04826           for (Int_t j_bin = 0; j_bin < fFileHeader->fNbBinsADC; j_bin++)
04827             {
04828               gCnaRootFile->fCnaIndivResult->fMatHis(i_samp, j_bin) =
04829                 fT3d_his_s[user_SMEcha][i_samp][j_bin];
04830             }
04831         }
04832     }
04833 }
04834 
04835 //-------------------------------------------------------------------------
04836 //
04837 //  Prepa Fill ADC distributions xmin of the samples for all the SMEchas
04838 //                       (for writing in the ROOT file)
04839 //
04840 //-------------------------------------------------------------------------
04841 void TCnaRunEB::TRootEvtsXmin(const Int_t& user_SMEcha)
04842 {
04843   if (fTagEvts[user_SMEcha] == 1 )
04844     {
04845       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04846         {
04847           gCnaRootFile->fCnaIndivResult->fMatHis(0, i_samp) =
04848             fT2d_xmin[user_SMEcha][i_samp];  
04849         }
04850     }
04851 }
04852 
04853 //-------------------------------------------------------------------------
04854 //
04855 //  Prepa Fill ADC distributions xmax of the samples for all the SMEchas
04856 //                       (for writing in the ROOT file)
04857 //
04858 //-------------------------------------------------------------------------
04859 void TCnaRunEB::TRootEvtsXmax(const Int_t& user_SMEcha)
04860 {
04861   if (fTagEvts[user_SMEcha] == 1 )
04862     {
04863       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04864         {
04865           gCnaRootFile->fCnaIndivResult->fMatHis(0, i_samp) =
04866             fT2d_xmax[user_SMEcha][i_samp];  
04867         }
04868     }
04869 }
04870 
04871 //-------------------------------------------------------------------------
04872 //
04873 //  Prepa Fill covariances between SMEchas, mean over samples
04874 //                           (for writing in ROOT file)
04875 //
04876 //-------------------------------------------------------------------------
04877 void TCnaRunEB::TRootCovSccMos()
04878 {
04879   if (fTagCovSccMos[0] == 1 )
04880     {
04881       for (Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
04882         {
04883           for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
04884             {
04885               gCnaRootFile->fCnaIndivResult->fMatMat(i_SMEcha, j_SMEcha) =
04886                 fT2d_cov_cc_mos[i_SMEcha][j_SMEcha];
04887             }
04888         }
04889     }
04890 }
04891 
04892 //-------------------------------------------------------------------------
04893 //
04894 //  Prepa Fill correlations between SMEchas, mean over samples
04895 //                         (for writing in ROOT file)
04896 //
04897 //-------------------------------------------------------------------------
04898 void TCnaRunEB::TRootCorSccMos()
04899 {
04900   if (fTagCorSccMos[0] == 1 )
04901     {
04902       for (Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
04903         {
04904           for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
04905             {
04906               gCnaRootFile->fCnaIndivResult->fMatMat(i_SMEcha, j_SMEcha) =
04907                 fT2d_cor_cc_mos[i_SMEcha][j_SMEcha];
04908             }
04909         }
04910     }
04911 }
04912 
04913 //-------------------------------------------------------------------------
04914 //
04915 //  Prepa Fill covariances between samples for a given SMEcha
04916 //                      (for writing in ROOT file)
04917 //
04918 //-------------------------------------------------------------------------
04919 void TCnaRunEB::TRootCovCss(const Int_t& user_SMEcha)
04920 {
04921    if (fTagCovCss[user_SMEcha] == 1 )
04922      {
04923        for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04924          {
04925            for (Int_t j_samp = 0; j_samp < fFileHeader->fMaxSampADC; j_samp++)
04926              {
04927                gCnaRootFile->fCnaIndivResult->fMatMat(i_samp, j_samp) =
04928                  fT3d_cov_ss[user_SMEcha][i_samp][j_samp];
04929              }
04930          }
04931      }
04932 }
04933 
04934 //-------------------------------------------------------------------------
04935 //
04936 //  Prepa Fill correlations between samples for a given SMEcha
04937 //                        (for writing in ROOT file)
04938 //
04939 //-------------------------------------------------------------------------
04940 void TCnaRunEB::TRootCorCss(const Int_t& user_SMEcha)
04941 {
04942    if (fTagCorCss[user_SMEcha] == 1 )
04943      {
04944        for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
04945          {
04946            for (Int_t j_samp = 0; j_samp < fFileHeader->fMaxSampADC; j_samp++)
04947              {
04948                gCnaRootFile->fCnaIndivResult->fMatMat(i_samp, j_samp) =
04949                  fT3d_cor_ss[user_SMEcha][i_samp][j_samp];
04950              }
04951          }
04952      }
04953 }
04954 
04955 //-------------------------------------------------------------------------
04956 //
04957 //  Prepa Fill expectation values of the expectation values of the samples
04958 //  for all the SMEchas
04959 //                        (for writing in ROOT file)
04960 //
04961 //-------------------------------------------------------------------------
04962 void TCnaRunEB::TRootEvEv()
04963 {
04964   if (fTagEvEv[0] == 1 )
04965     {
04966       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
04967         {
04968           gCnaRootFile->fCnaIndivResult->fMatHis(0, j_SMEcha) =
04969             fT1d_ev_ev[j_SMEcha];
04970         }      
04971     }
04972 }
04973 //-------------------------------------------------------------------------
04974 //
04975 //  Prepa Fill expectation values of the sigmas of the samples
04976 //  for all the SMEchas
04977 //                        (for writing in ROOT file)
04978 //
04979 //-------------------------------------------------------------------------
04980 void TCnaRunEB::TRootEvSig()
04981 {
04982   if (fTagEvSig[0] == 1 )
04983     {
04984       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
04985         {
04986           gCnaRootFile->fCnaIndivResult->fMatHis(0, j_SMEcha) =
04987             fT1d_ev_sig[j_SMEcha];
04988         }      
04989     }
04990 }
04991 
04992 //-------------------------------------------------------------------------
04993 //
04994 //  Prepa Fill expectation values of the (sample,sample) correlations
04995 //  for all the SMEchas
04996 //                        (for writing in ROOT file)
04997 //
04998 //-------------------------------------------------------------------------
04999 void TCnaRunEB::TRootEvCorCss()
05000 {
05001   if (fTagEvCorCss[0] == 1 )
05002     {
05003       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
05004         {
05005           gCnaRootFile->fCnaIndivResult->fMatHis(0, j_SMEcha) =
05006             fT1d_ev_cor_ss[j_SMEcha];
05007         }      
05008     }
05009 }
05010 
05011 //-------------------------------------------------------------------------
05012 //
05013 //  Prepa Fill sigmas of the expectation values of the samples
05014 //  for all the SMEchas
05015 //                        (for writing in ROOT file)
05016 //
05017 //-------------------------------------------------------------------------
05018 void TCnaRunEB::TRootSigEv()
05019 {
05020   if (fTagSigEv[0] == 1 )
05021     {
05022       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
05023         {
05024           gCnaRootFile->fCnaIndivResult->fMatHis(0, j_SMEcha) =
05025             fT1d_sig_ev[j_SMEcha];
05026         }      
05027     }
05028 }
05029 
05030 //-------------------------------------------------------------------------
05031 //
05032 //  Prepa Fill sigmas of the expectation values of the sigmas
05033 //  for all the SMEchas
05034 //                        (for writing in ROOT file)
05035 //
05036 //-------------------------------------------------------------------------
05037 void TCnaRunEB::TRootSigSig()
05038 {
05039   if (fTagSigSig[0] == 1 )
05040     {
05041       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
05042         {
05043           gCnaRootFile->fCnaIndivResult->fMatHis(0, j_SMEcha) =
05044             fT1d_sig_sig[j_SMEcha];
05045         }      
05046     }
05047 }
05048 
05049 //-------------------------------------------------------------------------
05050 //
05051 //  Prepa Fill sigmas of the (sample,sample) correlations
05052 //  for all the SMEchas
05053 //                        (for writing in ROOT file)
05054 //
05055 //-------------------------------------------------------------------------
05056 void TCnaRunEB::TRootSigCorCss()
05057 {
05058   if (fTagSigCorCss[0] == 1 )
05059     {
05060       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
05061         {
05062           gCnaRootFile->fCnaIndivResult->fMatHis(0, j_SMEcha) =
05063             fT1d_sig_cor_ss[j_SMEcha];
05064         }      
05065     }
05066 }
05067 
05068 //-------------------------------------------------------------------------
05069 //
05070 //  Prepa Fill sample values correction coefficients
05071 //  for all the SMEchas
05072 //                        (for writing in ROOT file)
05073 //
05074 //-------------------------------------------------------------------------
05075 void TCnaRunEB::TRootSvCorrecCovCss()
05076 {
05077   if (fTagSvCorrecCovCss[0] == 1 )
05078     {
05079       for (Int_t j_SMEcha = 0; j_SMEcha < fFileHeader->fMaxCrysInSM; j_SMEcha++)
05080         {
05081           for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
05082             {
05083               gCnaRootFile->fCnaIndivResult->fMatHis(j_SMEcha, i_samp) =
05084                 fT2d_sv_correc_covss_s[j_SMEcha][i_samp];
05085             }
05086         }
05087     }
05088 }
05089 
05090 //-------------------------------------------------------------------------
05091 //
05092 //  Prepa Fill 
05093 //  
05094 //                        (for writing in ROOT file)
05095 //
05096 //-------------------------------------------------------------------------
05097 void TCnaRunEB::TRootCovCorrecCovCss(const Int_t& user_SMEcha)
05098 {
05099   if (fTagCovCorrecCovCss[0] == 1 )   // test 1st elt only since global calc
05100     {
05101       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
05102         {
05103           for (Int_t j_samp = 0; j_samp < fFileHeader->fMaxSampADC; j_samp++)
05104             {
05105               gCnaRootFile->fCnaIndivResult->fMatMat(i_samp, j_samp) =
05106                 fT3d_cov_correc_covss_s[user_SMEcha][i_samp][j_samp];
05107             }
05108         }
05109     }
05110 }
05111 
05112 //-------------------------------------------------------------------------
05113 //
05114 //  Prepa Fill 
05115 //  
05116 //                        (for writing in ROOT file)
05117 //
05118 //-------------------------------------------------------------------------
05119 void TCnaRunEB::TRootCorCorrecCovCss(const Int_t& user_SMEcha)
05120 {
05121   if (fTagCorCorrecCovCss[0] == 1 )   // test 1st elt only since global calc
05122     {
05123       for (Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
05124         {
05125           for (Int_t j_samp = 0; j_samp < fFileHeader->fMaxSampADC; j_samp++)
05126             {
05127               gCnaRootFile->fCnaIndivResult->fMatMat(i_samp, j_samp) =
05128                 fT3d_cor_correc_covss_s[user_SMEcha][i_samp][j_samp];
05129             }
05130         }
05131     }
05132 }
05133 
05134 //=========================================================================
05135 //
05136 //    W R I T I N G   M E T H O D S :    A S C I I    F I L E S   
05137 //
05138 //=========================================================================
05139 
05140 //------------------------------------------------------------
05141 //
05142 //      Writing of the expectation values in an ASCII file
05143 //
05144 //------------------------------------------------------------
05145 
05146 void TCnaRunEB::WriteAsciiExpectationValuesOfSamples()
05147 {
05148 //Writing of the expectation values in an ASCII file
05149 
05150   if ( fTagEv[0] == 1)
05151     {
05152       Int_t i_code = fCodeEv;
05153       fMakeResultsFileName(i_code);
05154       fAsciiFileWriteHeader(i_code);
05155       
05156       Int_t i_lic1 = fNbChanByLine; 
05157       Int_t i_lic2 = fNbSampByLine;
05158 
05159       fT1dWriteAscii(i_code, i_lic1, i_lic2);
05160     }
05161   else
05162     {
05163       cout << "!TCnaRunEB::WriteAsciiExpectationValuesOfSamples()> "
05164            << " Quantities not calculated. No reason to write an ASCII file."
05165            << fTTBELL << endl;
05166     }
05167 }
05168 
05169 //-------------------------------------------------------
05170 //
05171 //      Writing of the variances in an ASCII file
05172 //
05173 //-------------------------------------------------------
05174 
05175 void TCnaRunEB::WriteAsciiVariancesOfSamples()
05176 {
05177 //Writing of the variances in an ASCII file
05178 
05179   if ( fTagVar[0] == 1)
05180     { 
05181       Int_t i_code = fCodeVar;  // code for variance   
05182       fMakeResultsFileName(i_code);
05183       fAsciiFileWriteHeader(i_code);
05184       
05185       Int_t i_lic1 = fNbChanByLine;
05186       Int_t i_lic2 = fNbSampByLine;
05187       
05188       fT1dWriteAscii(i_code, i_lic1, i_lic2);
05189     }
05190   else
05191     {
05192       cout << "!TCnaRunEB::WriteAsciiVariancesOfSamples()> "
05193            << " Quantities not calculated. No reason to write an ASCII file."
05194            << fTTBELL << endl;
05195     }
05196 }
05197 
05198 //--------------------------------------------------------------------------------
05199 //
05200 //      Writing of the covariances between samples
05201 //      for a given SMEcha in an ASCII file
05202 //
05203 //--------------------------------------------------------------------------------
05204 void   TCnaRunEB::WriteAsciiCovariancesBetweenSamples(const Int_t& user_SMEcha)
05205 {
05206 //Writing of the covariances between samples for a given SMEcha in an ASCII file
05207 
05208   if (fTagCovCss[user_SMEcha] != 1 ) {ComputeCovariancesBetweenSamples();}
05209   fUserSMEcha = user_SMEcha;
05210   Int_t i_code = fCodeCovCss;  // code for covariances between samples
05211   fMakeResultsFileName(i_code);  
05212   fAsciiFileWriteHeader(i_code);
05213 
05214   Int_t i_pasx = fSectSampSizeX;
05215   Int_t i_pasy = fSectSampSizeY;
05216 
05217   fT2dWriteAscii(i_code, i_pasx, i_pasy);
05218 }
05219 
05220 //---------------------------------------------------------------------------------
05221 //
05222 //   Writing of the correlations between samples
05223 //   for a given SMEcha in an ASCII file
05224 //
05225 //---------------------------------------------------------------------------------
05226 void      TCnaRunEB::WriteAsciiCorrelationsBetweenSamples(const Int_t& user_SMEcha)
05227 {
05228 //Writing of the correlations between samples for a given SMEcha in an ASCII file
05229 
05230   if (fTagCorCss[user_SMEcha] != 1 ) {ComputeCorrelationsBetweenSamples();}
05231 
05232   fUserSMEcha = user_SMEcha;
05233   Int_t i_code = fCodeCorCss; // code for correlations between samples
05234   fMakeResultsFileName(i_code); 
05235   fAsciiFileWriteHeader(i_code);
05236 
05237   Int_t i_pasx = fSectSampSizeX;
05238   Int_t i_pasy = fSectSampSizeY;
05239  
05240   fT2dWriteAscii(i_code, i_pasx, i_pasy);
05241 }
05242 
05243 //---------------------------------------------------------------------------
05244 //
05245 //   Writing of the expectation values of the correlations between samples
05246 //   for all the SMEchas in an ASCII file
05247 //
05248 //---------------------------------------------------------------------------
05249 
05250 void     TCnaRunEB::WriteAsciiExpectationValuesOfCorrelationsBetweenSamples()
05251 {
05252 //Write the expectation values of the correlations between samples for all the SMEchas in an ASCII file
05253 
05254   if ( fTagEvCorCss[0] == 1)
05255     {
05256       Int_t i_code = fCodeEvCorCss;  // code for expectation values of ss correlations   
05257       fMakeResultsFileName(i_code);
05258       fAsciiFileWriteHeader(i_code);
05259       
05260       Int_t i_lic1 = fNbChanByLine;
05261       Int_t i_lic2 = 0;
05262       
05263       fT1dWriteAscii(i_code, i_lic1, i_lic2);
05264     }
05265   else
05266     {
05267       cout << "!TCnaRunEB::WriteAsciiExpectationValuesOfCorrelationsBetweenSamples()> "
05268            << " Quantities not calculated. No reason to write an ASCII file."
05269            << fTTBELL << endl;
05270     }
05271 }
05272 //---------------------------------------------------------------------
05273 //
05274 //   Writing of the sigmas of the correlations between samples
05275 //   for all the SMEchas in an ASCII file
05276 //
05277 //---------------------------------------------------------------------
05278 
05279 void     TCnaRunEB::WriteAsciiSigmasOfCorrelationsBetweenSamples()
05280 {
05281 //Writing of the amplitudes of the correlations between samples for all the SMEchas in an ASCII file
05282 
05283   if ( fTagSigCorCss[0] == 1)
05284     {
05285       Int_t i_code = fCodeSigCorCss;  // code for amplitudes   
05286       fMakeResultsFileName(i_code);
05287       fAsciiFileWriteHeader(i_code);
05288       
05289       Int_t i_lic1 = fNbChanByLine;
05290       Int_t i_lic2 = 0;
05291       
05292       fT1dWriteAscii(i_code, i_lic1, i_lic2);
05293     }
05294   else
05295     {
05296       cout << "!TCnaRunEB::WriteAsciiSigmasOfCorrelationsBetweenSamples()> "
05297            << " Quantities not calculated. No reason to write an ASCII file."
05298            << fTTBELL << endl;
05299     }
05300 }
05301 
05302 //------------------------------------------------------------
05303 //
05304 //      Writing of the sample value correction coefficients
05305 //      in an ASCII file
05306 //
05307 //------------------------------------------------------------
05308 
05309 void  TCnaRunEB::WriteAsciiSvCorrecCovCss()
05310 {
05311 //Writing of the sample value correction coefficients in an ASCII file
05312 
05313   if ( fTagSvCorrecCovCss[0] == 1)
05314     {
05315       Int_t i_code = fCodeSvCorrecCovCss;
05316       fMakeResultsFileName(i_code);
05317       fAsciiFileWriteHeader(i_code);
05318       
05319       Int_t i_lic1 = fNbChanByLine;    
05320       Int_t i_lic2 = fNbSampByLine;
05321       
05322       fT1dWriteAscii(i_code, i_lic1, i_lic2);
05323     }
05324   else
05325     {
05326       cout << "!TCnaRunEB::WriteAsciiSvCorrecCovCss()> "
05327            << " Quantities not calculated. No reason to write an ASCII file."
05328            << fTTBELL << endl;
05329     }
05330 }
05331 
05332 //------------------------------------------------------------
05333 //
05334 //      Writing of the  correction factors to the
05335 //      (sample,sample) covariances in an ASCII file
05336 //
05337 //------------------------------------------------------------
05338 
05339 void  TCnaRunEB::WriteAsciiCovCorrecCovCss(const Int_t& user_SMEcha)
05340 {
05341 //Writing of the correction factors to the (sample,sample) covariances in ASCII file
05342 
05343   if ( fTagCovCorrecCovCss[0] == 1)
05344     {
05345       Int_t i_code = fCodeCovCorrecCovCss; // code for correction factors to ss covariances
05346       fUserSMEcha = user_SMEcha;
05347       fMakeResultsFileName(i_code); 
05348       fAsciiFileWriteHeader(i_code);
05349       
05350       Int_t i_pasx = fSectSampSizeX;
05351       Int_t i_pasy = fSectSampSizeY;
05352       
05353       fT2dWriteAscii(i_code, i_pasx, i_pasy);
05354     }
05355   else
05356     {
05357       cout << "!TCnaRunEB::WriteAsciiCovCorrecCovCss()> "
05358            << " Quantities not calculated. No reason to write an ASCII file."
05359            << fTTBELL << endl;
05360     }
05361 }
05362 
05363 //------------------------------------------------------------
05364 //
05365 //      Writing of the  correction factors to the
05366 //      (sample,sample) correlations in an ASCII file
05367 //
05368 //------------------------------------------------------------
05369 
05370 void  TCnaRunEB::WriteAsciiCorCorrecCovCss(const Int_t& user_SMEcha)
05371 {
05372 //Writing of the correction factors to the (sample,sample) correlations in ASCII file
05373 
05374   if ( fTagCorCorrecCovCss[0] == 1)
05375     {
05376       Int_t i_code = fCodeCorCorrecCovCss; // code for correction factors to ss correlations
05377       fUserSMEcha = user_SMEcha;
05378       fMakeResultsFileName(i_code);
05379       fAsciiFileWriteHeader(i_code);
05380       
05381       Int_t i_pasx = fSectSampSizeX;
05382       Int_t i_pasy = fSectSampSizeY;
05383       
05384       fT2dWriteAscii(i_code, i_pasx, i_pasy);
05385     }
05386   else
05387     {
05388       cout << "!TCnaRunEB::WriteAsciiCorCorrecCovCss()> "
05389            << " Quantities not calculated. No reason to write an ASCII file."
05390            << fTTBELL << endl;
05391     }
05392 }
05393 
05394 //------------------------------------------------------------
05395 //
05396 //             WriteAsciiCnaChannelTable()   
05397 //
05398 //------------------------------------------------------------
05399 void  TCnaRunEB::WriteAsciiCnaChannelTable()
05400 {
05401 //Write the correspondance table: CNA-channel <-> (SMTow,TowEcha), SMcrystal
05402 
05403   TEBNumbering* MyNumbering = new TEBNumbering();           fCnew++;
05404   // BuildCrysTable() is called in the method Init() which is called by the constructor
05405 
05406   if(fFlagPrint != fCodePrintNoComment){
05407     cout << "*TCnaRunEB::WriteAsciiCnaChannelTable()> The correspondance table is made."
05408          << " Number of CNA-channels = " << fFileHeader->fMaxCrysInSM << endl;}
05409 
05410   Int_t i_code = fCodeCorresp; // code for cna correspondance table
05411   fMakeResultsFileName(i_code);
05412   fAsciiFileWriteHeader(i_code);
05413 
05414   for (Int_t i_SMEcha=0; i_SMEcha<fFileHeader->fMaxCrysInSM; i_SMEcha++)
05415     {
05416       Int_t sm_tower = MyNumbering->GetSMTowFromSMEcha(i_SMEcha);
05417       Int_t TowEcha  = MyNumbering->GetTowEchaFromSMEcha(i_SMEcha);
05418       if ( TowEcha == 0 )
05419         { fFcout_f << endl;
05420           fFcout_f << "  CNA     tower#   channel#   crystal#    Number of events"  << endl;
05421           fFcout_f << "channel    in SM   in tower     in SM     found  (required)" << endl << endl;      
05422         }
05423       Int_t SMcrys      = MyNumbering->GetSMCrysFromSMTowAndTowEcha(sm_tower, TowEcha);
05424       Int_t sample_z    = 0;
05425       Int_t nb_of_evts  = PickupNumberOfEvents(i_SMEcha, sample_z);
05426       fFcout_f  << setw(7)  << i_SMEcha
05427                 << setw(9)  << sm_tower
05428                 << setw(11) << TowEcha
05429                 << setw(10) << SMcrys
05430                 << setw(10) << nb_of_evts 
05431                 << setw(4) << "(" << setw(6) << fFileHeader->fNbOfTakenEvts << ")" << endl;
05432     }
05433   fFcout_f.close();
05434 
05435   if(fFlagPrint != fCodePrintNoComment){
05436     cout << "*TCnaRunEB::WriteAsciiCnaChannelTable()> The CNA correspondance table "
05437          << "has been written in file: " << fAsciiFileName << endl;}
05438 
05439   delete MyNumbering;                       fCdelete++;
05440 }
05441 
05442 //=========================================================================
05443 //
05444 //         METHODS TO SET FLAGD TO PRINT (OR NOT) COMMENTS (DEBUG)
05445 //
05446 //=========================================================================
05447 
05448 void  TCnaRunEB::PrintComments()
05449 {
05450 // Set flags to authorize printing of some comments concerning initialisations (default)
05451 
05452   fFlagPrint = fCodePrintComments;
05453   cout << "*TCnaRunEB::PrintComments()> Warnings and some comments on init will be printed" << endl;
05454 }
05455 
05456 void  TCnaRunEB::PrintWarnings()
05457 {
05458 // Set flags to authorize printing of warnings
05459 
05460   fFlagPrint = fCodePrintWarnings;
05461   cout << "*TCnaRunEB::PrintWarnings()> Warnings will be printed" << endl;
05462 }
05463 
05464 void  TCnaRunEB::PrintAllComments()
05465 {
05466 // Set flags to authorize printing of the comments of all the methods
05467 
05468   fFlagPrint = fCodePrintAllComments;
05469   cout << "*TCnaRunEB::PrintAllComments()> All the comments will be printed" << endl;
05470 }
05471 
05472 void  TCnaRunEB::PrintNoComment()
05473 {
05474 // Set flags to forbid the printing of all the comments
05475 
05476   fFlagPrint = fCodePrintNoComment;
05477 }
05478 
05479 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05480 //
05481 //                 +--------------------------------------+
05482 //                 |    P R I V A T E     M E T H O D S   |
05483 //                 +--------------------------------------+
05484 //
05485 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05486 
05487 
05488 //=========================================================================
05489 //
05490 //                 Results Filename Making  (private)
05491 //
05492 //=========================================================================
05493 
05494 void  TCnaRunEB::fMakeResultsFileName(const Int_t&  i_code)
05495 {
05496 //Results filename making  (private)
05497   
05498   //----------------------------------------------------------------------
05499   //
05500   //     making of the name of the results file.
05501   //
05502   //     Put the names in the following class attributes:
05503   //
05504   //     fRootFileName,  fRootFileNameShort,
05505   //     fAsciiFileName, fAsciiFileNameShort
05506   //
05507   //     (Short means: without the directory path)
05508   //
05509   //     set indications (run number, type of quantity, ...)
05510   //     and add the extension ".ascii" or ".root"
05511   //     
05512   //     ROOT:  only one ROOT file:  i_code = fCodeRoot.
05513   //                                          All the types of quantities
05514   //
05515   //     ASCII: several ASCII files: i_code = code for one type of quantity
05516   //            each i_code which is not equal to fCodeRoot is also implicitly
05517   //            a code "fCodeAscii" (this last attribute is not in the class)
05518   //     
05519   //----------------------------------------------------------------------
05520   
05521   char* f_in       = new char[fDim_name];                 fCnew++;
05522   char* f_in_short = new char[fDim_name];                 fCnew++;
05523   
05524   //  switch (i_code){  
05525   
05526   //===================================  R O O T  =====================================
05527   if (i_code == fCodeRoot)
05528     {
05529       if(fCfgResultsRootFilePath == "?")
05530         {
05531           cout << "#TCnaRunEB::fMakeResultsFileName>  * * * W A R N I N G * * * " << endl << endl
05532                << "    Path for results .root file not defined. Default option will be used here:" << endl
05533                << "    your results files will be writen in your HOME directory." << endl << endl
05534                << "    In order to write the results file in the file FILE_NAME," << endl
05535                << "    you have to call the method GetPathForResultsRootFiles(TString FILE_NAME)" << endl 
05536                << "    where FILE_NAME is the complete name (/afs/etc...) of a configuration file" << endl 
05537                << "    which must have only one line containing the path of the .root result files." << endl
05538                << "    If the TString FILE_NAME is empty, the configuration file must be " << endl
05539                << "    in your HOME directory and must be called: cna_results_root.cfg" << endl
05540                << endl;
05541 
05542           TString home_path = gSystem->Getenv("HOME");
05543           fCfgResultsRootFilePath = home_path;      
05544         }
05545 
05546       if(fCfgResultsRootFilePath.BeginsWith("$HOME"))
05547         {
05548           fCfgResultsRootFilePath.Remove(0,5);
05549           Text_t *t_file_nohome = (Text_t *)fCfgResultsRootFilePath.Data(); //  /scratch0/cna/...
05550           
05551           TString home_path = gSystem->Getenv("HOME");
05552           fCfgResultsRootFilePath = home_path;             //  /afs/cern.ch/u/USER
05553           fCfgResultsRootFilePath.Append(t_file_nohome);   //  /afs/cern.ch/u/USER/scratch0/cna/...
05554         }
05555 
05556       sprintf(f_in, "%s/%s_%d_%d_%d_SM%d",
05557               fCfgResultsRootFilePath.Data(), fFileHeader->fTypAna.Data(),  fFileHeader->fRunNumber,
05558               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05559       sprintf(f_in_short, "%s_%d_%d_%d_SM%d",
05560               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05561               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05562     }
05563 
05564   //===================================  A S C I I  ===================================  
05565 
05566   if (i_code == fCodeHeaderAscii)
05567     {
05568       if(fCfgResultsAsciiFilePath == "?")
05569         {
05570           cout << "#TCnaRunEB::fMakeResultsFileName>  * * * W A R N I N G * * * " << endl << endl
05571                << "    Path for results .ascii file not defined. Default option will be used here:" << endl
05572                << "    your results files will be writen in your HOME directory." << endl << endl
05573                << "    In order to write the results file in the file FILE_NAME," << endl
05574                << "    you have to call the method GetPathForResultsAsciiFiles(TString FILE_NAME)" << endl 
05575                << "    where FILE_NAME is the complete name (/afs/etc...) of a configuration file" << endl 
05576                << "    which must have only one line containing the path of the .ascii result files." << endl
05577                << "    If the TString FILE_NAME is empty, the configuration file must be " << endl
05578                << "    in your HOME directory and must be called: cna_results_ascii.cfg" << endl
05579                << endl;
05580 
05581           TString home_path = gSystem->Getenv("HOME");
05582           fCfgResultsAsciiFilePath = home_path;  
05583         } 
05584       
05585       if(fCfgResultsAsciiFilePath.BeginsWith("$HOME"))
05586         {
05587           fCfgResultsAsciiFilePath.Remove(0,5);
05588           Text_t *t_file_nohome = (Text_t *)fCfgResultsAsciiFilePath.Data(); //  /scratch0/cna/...
05589           
05590           TString home_path = gSystem->Getenv("HOME");
05591           fCfgResultsAsciiFilePath = home_path;             //  /afs/cern.ch/u/USER
05592           fCfgResultsAsciiFilePath.Append(t_file_nohome);   //  /afs/cern.ch/u/USER/scratch0/cna/...
05593         }
05594      
05595       sprintf(f_in, "%s/%s_%d_header_%d_%d_SM%d",
05596               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05597               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05598       sprintf(f_in_short, "%s_%d_header_%d_%d_SM%d",
05599               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05600               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05601     }
05602 
05603   //------------------------------------------------------------------------------------------------------
05604   if (i_code == fCodeCorresp)
05605     {
05606       sprintf(f_in, "%s/%s_%d_%d_%d_SM%d_cna",
05607               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05608               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05609       sprintf(f_in_short, "%s_%d_%d_%d_SM%d_cna",
05610               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05611               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05612     }
05613 
05614   if (i_code == fCodeEv)
05615     {
05616       sprintf(f_in, "%s/%s_%d_ev_%d_%d_SM%d",
05617               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05618               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05619       sprintf(f_in_short, "%s_%d_ev_%d_%d_SM%d",
05620               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05621               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05622     }
05623   
05624   if (i_code == fCodeVar)
05625     {
05626       sprintf(f_in, "%s/%s_%d_var_%d_%d_SM%d",
05627               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05628               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05629       sprintf(f_in_short, "%s_%d_var_%d_%d_SM%d",
05630               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05631               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05632     }
05633   
05634   if( i_code == fCodeEvts)
05635     {
05636       sprintf(f_in, "%s/%s_%d_evts_s_c%d_%d_%d_SM%d",
05637               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber, fUserSMEcha,
05638               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05639       sprintf(f_in_short, "%s_%d_evts_s_c%d_%d_%d_SM%d",
05640               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber, fUserSMEcha,
05641               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05642     }
05643   
05644   if(  i_code == fCodeCovSccMos)
05645     {
05646       sprintf(f_in, "%s/%s_%d_cov_cc_mos_%d_%d_SM%d",
05647               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05648               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05649       sprintf(f_in_short, "%s_%d_cov_cc_mos_%d_%d_SM%d",
05650               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05651               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05652     }
05653   
05654   if ( i_code == fCodeCorSccMos)
05655     {
05656       sprintf(f_in, "%s/%s_%d_cor_cc_mos_%d_%d_SM%d",
05657               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05658               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05659       sprintf(f_in_short, "%s_%d_cor_cc_mos_%d_%d_SM%d",
05660               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05661               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05662     }
05663   
05664   if (i_code ==  fCodeCovCss)
05665     {
05666       sprintf(f_in, "%s/%s_%d_cov_ss_c%d_%d_%d_SM%d",
05667               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber, fUserSMEcha,
05668               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05669       sprintf(f_in_short, "%s_%d_cov_ss_c%d_%d_%d_SM%d",
05670               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber, fUserSMEcha,
05671               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05672     }
05673   
05674   if (i_code == fCodeCorCss)
05675     {
05676       sprintf(f_in, "%s/%s_%d_cor_ss_c%d_%d_%d_SM%d",
05677               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05678               fUserSMEcha, fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05679       sprintf(f_in_short, "%s_%d_cor_ss_c%d_%d_%d_SM%d",
05680               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05681               fUserSMEcha, fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05682     }
05683   
05684   if (i_code == fCodeEvCorCss)
05685     {
05686       sprintf(f_in, "%s/%s_%d_ev_cor_ss_%d_%d_SM%d",
05687               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05688               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05689       sprintf(f_in_short, "%s_%d_ev_cor_ss_%d_%d_SM%d",
05690               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05691               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05692     }
05693   
05694   if (i_code == fCodeSigCorCss)
05695     {
05696       sprintf(f_in, "%s/%s_%d_sig_cor_ss_%d_%d_SM%d",
05697               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05698               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05699       sprintf(f_in_short, "%s_%d_sig_cor_ss_%d_%d_SM%d",
05700               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05701               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05702     }
05703 
05704   if (i_code == fCodeSvCorrecCovCss)
05705     {
05706       sprintf(f_in, "%s/%s_%d_sv_correc_covss_%d_%d_SM%d",
05707               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05708               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05709       sprintf(f_in_short, "%s_%d_sv_correc_covss_%d_%d_SM%d",
05710               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05711               fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05712     }
05713   
05714   if (i_code == fCodeCovCorrecCovCss)
05715     {
05716       sprintf(f_in, "%s/%s_%d_cov_correc_covss_c%d_%d_%d_SM%d",
05717               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05718               fUserSMEcha, fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05719       sprintf(f_in_short, "%s_%d_cov_correc_covss_c%d_%d_%d_SM%d",
05720               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05721               fUserSMEcha, fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05722     }
05723 
05724   if (i_code == fCodeCorCorrecCovCss)
05725     {
05726       sprintf(f_in, "%s/%s_%d_cor_correc_covss_c%d_%d_%d_SM%d",
05727               fCfgResultsAsciiFilePath.Data(), fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05728               fUserSMEcha, fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05729       sprintf(f_in_short, "%s_%d_cor_correc_covss_c%d_%d_%d_SM%d",
05730               fFileHeader->fTypAna.Data(), fFileHeader->fRunNumber,
05731               fUserSMEcha, fFileHeader->fFirstEvt, fFileHeader->fNbOfTakenEvts, fFileHeader->fSuperModule);
05732     } 
05733 
05734   // default:
05735   //    cout << "*TCnaRunEB::fMakeResultsFileName(const Int_t&  i_code)> "
05736   //     << "wrong header code , i_code = " << i_code << endl; 
05737   //  }
05738 
05739   //======================================= f_name
05740   
05741   char* f_name = new char[fDim_name];                   fCnew++;
05742   
05743   for (Int_t i = 0 ; i < fDim_name ; i++)
05744     {
05745       f_name[i] = '\0';
05746     }
05747   
05748   Int_t ii = 0;
05749   for (Int_t i = 0 ; i < fDim_name ; i++)
05750     {
05751       if ( f_in[i] != '\0' ){f_name[i] = f_in[i]; ii++;}
05752       else {break;}  // va directement a f_name[ii] = '.';
05753     }
05754  
05755   if ( ii+5 < fDim_name )
05756     {
05757       //.......... writing of the file extension (.root or .ascii)
05758       
05759       //------------------------------------------- extension .ascii
05760       if ( i_code != fCodeRoot  || i_code == fCodeCorresp )
05761         {
05762           f_name[ii] = '.';   f_name[ii+1] = 'a';
05763           f_name[ii+2] = 's'; f_name[ii+3] = 'c';
05764           f_name[ii+4] = 'i'; f_name[ii+5] = 'i';
05765           
05766           fAsciiFileName = f_name;
05767         }
05768       //------------------------------------------- extension .root
05769       if ( i_code == fCodeRoot )
05770         {
05771           f_name[ii] = '.';   f_name[ii+1] = 'r';
05772           f_name[ii+2] = 'o'; f_name[ii+3] = 'o';  f_name[ii+4] = 't';
05773           
05774           fRootFileName = f_name;
05775         }
05776     }
05777   else
05778     {
05779       cout << "*TCnaRunEB::fMakeResultsFileName(...)> Name too long (for f_name)."
05780            << " No room enough for the extension. (ii = " << ii << ")"
05781            << fTTBELL << endl; 
05782     }
05783 
05784 
05785   //====================================== f_name_short
05786   
05787   char* f_name_short = new char[fDim_name];          fCnew++;
05788 
05789   for (Int_t i = 0 ; i < fDim_name ; i++)
05790     {
05791       f_name_short[i] = '\0';
05792     }
05793   
05794   ii = 0;
05795   for (Int_t i = 0 ; i < fDim_name ; i++)
05796     {
05797       if ( f_in_short[i] != '\0' ){f_name_short[i] = f_in_short[i]; ii++;}
05798       else {break;}  // va directement a f_name_short[ii] = '.';
05799     }
05800  
05801   if ( ii+5 < fDim_name )
05802     {
05803       //.......... writing of the file extension (.root or .ascii)
05804       
05805       //-------------------------------------------extension .ascii
05806       if ( i_code != fCodeRoot || i_code == fCodeCorresp )
05807         {
05808           f_name_short[ii] = '.';   f_name_short[ii+1] = 'a';
05809           f_name_short[ii+2] = 's'; f_name_short[ii+3] = 'c';
05810           f_name_short[ii+4] = 'i'; f_name_short[ii+5] = 'i';
05811           
05812           fAsciiFileNameShort = f_name_short;
05813         }
05814       
05815       //-------------------------------------------- extension .root
05816       if ( i_code == fCodeRoot )
05817         {
05818           f_name_short[ii] = '.';   f_name_short[ii+1] = 'r';
05819           f_name_short[ii+2] = 'o'; f_name_short[ii+3] = 'o';  f_name_short[ii+4] = 't';
05820           
05821           fRootFileNameShort = f_name_short;
05822         }
05823     }
05824   else
05825     {
05826       cout << "*TCnaRunEB::fMakeResultsFileName(...)> Name too long (for f_name_short)."
05827            << " No room enough for the extension. (ii = " << ii << ")"
05828            << fTTBELL  << endl; 
05829     }
05830 
05831     delete [] f_name;                                        fCdelete++;
05832     delete [] f_name_short;                                  fCdelete++;
05833 
05834     delete [] f_in;                                          fCdelete++;
05835     delete [] f_in_short;                                    fCdelete++;
05836 }
05837 
05838 //==========================================================================================
05839 //
05840 //
05841 //
05842 //==========================================================================================
05843 void TCnaRunEB::fAsciiFileWriteHeader(const Int_t&  i_code)
05844 {
05845 //Ascii results file header writing  (private). Called by the WriteAscii...() methods
05846   
05847   //-----------------------------------------------
05848   //
05849   //     opening of the ASCII results file
05850   //     and writing of its header
05851   //
05852   //-----------------------------------------------
05853   
05854   fFcout_f.open(fAsciiFileName);
05855   
05856   fFcout_f << "*** File: " << fAsciiFileName
05857            << " *** " << endl << endl;
05858   fFcout_f << "*Analysis name            : " << fFileHeader->fTypAna        << endl; 
05859   fFcout_f << "*Run number               : " << fFileHeader->fRunNumber     << endl;
05860   fFcout_f << "*First taken event        : " << fFileHeader->fFirstEvt      << endl;
05861   fFcout_f << "*Number of taken events   : " << fFileHeader->fNbOfTakenEvts << endl;
05862   fFcout_f << "*Super-module number      : " << fFileHeader->fSuperModule   << endl;
05863   fFcout_f << "*Time first taken event   : " << fFileHeader->fStartTime     << endl;
05864   fFcout_f << "*Time last  taken event   : " << fFileHeader->fStopTime      << endl;
05865   fFcout_f << "*Date first taken event   : " << fFileHeader->fStartDate     << endl;
05866   fFcout_f << "*Date last  taken event   : " << fFileHeader->fStopDate      << endl;
05867   fFcout_f << "*Number of entries        : " << fFileHeader->fNentries      << endl;
05868   fFcout_f << "*Max nb of towers in SM   : " << fFileHeader->fMaxTowInSM    << endl;
05869   fFcout_f << "*Max nb of Xtals in tower : " << fFileHeader->fMaxCrysInTow  << endl;
05870   fFcout_f << "*Max nb of samples ADC    : " << fFileHeader->fMaxSampADC    << endl;
05871   fFcout_f << endl; 
05872 
05873   //========================================================================= 
05874   //   closing of the results file if i_code = fCodeHeaderAscii only.
05875   //   closing is done in the fT1dWriteAscii() and fT2dWriteAscii() methods
05876   //   except for i_code = fCodeHeaderAscii
05877   //=========================================================================
05878   if(i_code == fCodeHeaderAscii) fFcout_f.close();
05879 }
05880 
05881 //===========================================================================
05882 //
05883 //         fT1dWriteAscii: writing of  a 2d array as a 1d array of 1d arrays
05884 //
05885 //                              (private)
05886 //
05887 //===========================================================================
05888 
05889 void  TCnaRunEB::fT1dWriteAscii(const Int_t&  i_code,
05890                               const Int_t&  i_lic1, const Int_t&  i_lic2 )
05891 {
05892   //Writing of the values of a 2d array as a 1d array of 1d arrays (private)
05893   
05894   //----------------------------------------------------------------
05895   //
05896   //     The 2D Array TAB[d1][d2] is writen like this:
05897   //
05898   //     TAB[0][j]  ; j=1,d2 by lines of i_lic1 values
05899   //     TAB[1][j]  ; j=1,d2 by lines of i_lic1 values
05900   //     TAB[2][j]  ; j=1,d2 by lines of i_lic1 values  
05901   // 
05902   //      etc... ,      hence (if i_lic2 > 0 ):
05903   //     
05904   //     TAB[i][0]  ; i=1,d1 by lines of i_lic2 values
05905   //     TAB[i][1]  ; i=1,d1 by lines of i_lic2 values
05906   //     TAB[i][2]  ; i=1,d1 by lines of i_lic2 values  
05907   //
05908   //----------------------------------------------------------------
05909 
05910   fFcout_f << setiosflags(ios::showpoint | ios::uppercase);
05911   fFcout_f << setprecision(3) << setw(6);
05912   fFcout_f.setf(ios::dec, ios::basefield);
05913   fFcout_f.setf(ios::fixed, ios::floatfield);
05914   fFcout_f.setf(ios::left, ios::adjustfield);
05915   fFcout_f.setf(ios::right, ios::adjustfield);
05916   
05917   cout << setiosflags(ios::showpoint | ios::uppercase);
05918   cout << setprecision(3) << setw(6);
05919   cout.setf(ios::dec, ios::basefield);
05920   cout.setf(ios::fixed, ios::floatfield);
05921   cout.setf(ios::left, ios::adjustfield);
05922   cout.setf(ios::right, ios::adjustfield);
05923   
05924   Int_t limit   = 0;
05925   Int_t nb_elts = 0;
05926   Int_t i_lico  = 0;
05927   
05928   TString g_nam0 = "?";
05929   TString g_nam1 = "?";
05930   TString g_nam2 = "?";
05931   TString g_nam3 = "?";
05932   TString g_nam4 = "?";
05933   
05934   Int_t nb_pass = 2;
05935 
05936   //------------------------------------------------------------------------
05937   //  Reservation dynamique de 2 arrays Double_t** (pour ev et var) de
05938   //  dimensions les multiples de 5 juste au-dessus des dimensions de
05939   //  l'array 2D a ecrire (array de dimensions
05940   // (fFileHeader->fMaxSampADC,fFileHeader->fMaxCrysInSM))
05941   //------------------------------------------------------------------------
05942   //.... Determination des tailles multiples de fNbChanByLine ou fNbSampByLine
05943 
05944   Int_t justap_samp = 0;
05945   if ( fFileHeader->fMaxSampADC%fNbSampByLine == 0 ){
05946       justap_samp = fFileHeader->fMaxSampADC;}
05947   else{
05948       justap_samp = ((fFileHeader->fMaxSampADC/fNbSampByLine)+1)*fNbSampByLine;}
05949 
05950   Int_t justap_chan = 0;  
05951   if ( fFileHeader->fMaxCrysInSM%fNbChanByLine == 0 ){
05952       justap_chan = fFileHeader->fMaxCrysInSM;}
05953   else{
05954       justap_chan = ((fFileHeader->fMaxCrysInSM/fNbChanByLine)+1)*fNbChanByLine;}
05955   
05956   //................................. allocation fjustap_2d_ev
05957   if ( i_code == fCodeEv )
05958     {
05959       if( fjustap_2d_ev == 0 )
05960         {
05961           //................... Allocation
05962           fjustap_2d_ev = new Double_t*[justap_chan];              fCnew++;  
05963           fjustap_1d_ev = new  Double_t[justap_chan*justap_samp];  fCnew++;  
05964           for(Int_t i = 0 ; i < justap_chan ; i++){
05965             fjustap_2d_ev[i] = &fjustap_1d_ev[0] + i*justap_samp;}
05966         }
05967       //...................... Transfert des valeurs dans fjustap_2d_ev (=init)
05968       for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
05969         { 
05970           for(Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
05971             { 
05972               fjustap_2d_ev[i_SMEcha][i_samp]  = fT2d_ev[i_SMEcha][i_samp];
05973             }
05974         }      
05975       //............................... mise a zero du reste de l'array (=init)
05976       for(Int_t i_SMEcha = fFileHeader->fMaxCrysInSM; i_SMEcha < justap_chan; i_SMEcha++)
05977         {
05978           for(Int_t i_samp = fFileHeader->fMaxSampADC; i_samp < justap_samp; i_samp++)
05979             {
05980               fjustap_2d_ev[i_SMEcha][i_samp] = (Double_t)0;
05981             }
05982         }      
05983     }
05984 
05985   //...... Allocation fjustap_2d_var (meme tableau pour corrections samples => a clarifier)
05986 
05987   if ( i_code == fCodeVar || i_code == fCodeSvCorrecCovCss )
05988     {
05989       if(fjustap_2d_var == 0)
05990         {
05991           //................... Allocation
05992           fjustap_2d_var = new Double_t*[justap_chan];             fCnew++;  
05993           fjustap_1d_var = new  Double_t[justap_chan*justap_samp]; fCnew++;  
05994           for(Int_t i = 0 ; i < justap_chan ; i++){
05995             fjustap_2d_var[i] = &fjustap_1d_var[0] + i*justap_samp;}
05996         }
05997       //...................... Transfert des valeurs dans les fjustap_2d_var (=init)
05998       for(Int_t i_SMEcha = 0; i_SMEcha < fFileHeader->fMaxCrysInSM; i_SMEcha++)
05999         { 
06000           for(Int_t i_samp = 0; i_samp < fFileHeader->fMaxSampADC; i_samp++)
06001             {
06002               if (i_code == fCodeVar){
06003                 fjustap_2d_var[i_SMEcha][i_samp] = fT2d_var[i_SMEcha][i_samp];}
06004               if (i_code == fCodeSvCorrecCovCss){
06005                 fjustap_2d_var[i_SMEcha][i_samp] =
06006                   fT2d_sv_correc_covss_s[i_SMEcha][i_samp];}
06007             }
06008         }
06009       //............................... mise a zero du reste de l'array (=init)
06010       for(Int_t i_SMEcha = fFileHeader->fMaxCrysInSM; i_SMEcha < justap_chan; i_SMEcha++)
06011         {
06012           for(Int_t i_samp = fFileHeader->fMaxSampADC; i_samp < justap_samp; i_samp++)
06013             {
06014               fjustap_2d_var[i_SMEcha][i_samp] = (Double_t)0;
06015             }
06016         }
06017     }
06018 
06019   //------------------------------------------------------------------------
06020 
06021  //................ Ecriture de la taille des lignes
06022   if( i_code == fCodeEv || i_code == fCodeVar || i_code == fCodeSvCorrecCovCss )
06023     {
06024       fFcout_f << "*TCnaRunEB> sample sectors, nb of channels by line = "
06025                << fNbChanByLine <<endl;
06026       fFcout_f << "*TCnaRunEB> channel sectors, nb of samples by line = "
06027                << fNbSampByLine <<endl;
06028     }
06029   if( i_code == fCodeEvCorCss || i_code == fCodeSigCorCss)
06030     {
06031       fFcout_f << "*TCnaRunEB> sample sectors, nb of channels by line = "
06032                << fNbChanByLine <<endl;
06033     }
06034 
06035   fFcout_f << endl;
06036   //.......................................................................
06037 
06038   if ( i_code == fCodeEvts || i_code == fCodeEvCorCss 
06039        || i_code == fCodeSigCorCss ) {nb_pass = 1;}
06040   
06041   for(Int_t i_pass = 0 ; i_pass < nb_pass ; i_pass++)
06042     {
06043       if(i_pass == 0)
06044         {
06045           i_lico  = i_lic1;
06046           limit   = justap_samp;
06047           
06048           if( i_code == fCodeEv  ||
06049               i_code == fCodeVar ||
06050               i_code == fCodeSvCorrecCovCss )
06051             {
06052               limit   = justap_samp;
06053               nb_elts = justap_chan;
06054               g_nam1  = "sample";
06055               g_nam2  = "channel";
06056             }
06057           if(i_code == fCodeEvCorCss || i_code == fCodeSigCorCss )
06058             {
06059               limit   = 1;
06060               nb_elts = justap_chan;
06061               g_nam1  = "channel";
06062             }
06063           if ( i_code == fCodeEvts )
06064             {
06065               limit   = fFileHeader->fMaxSampADC;
06066               nb_elts = fFileHeader->fNbBinsADC;
06067               g_nam0  = "channel";
06068               g_nam1  = "sample";
06069               g_nam2  = "bins";
06070               g_nam3  = "xmin=";
06071               g_nam4  = "xmax=";
06072             }
06073         }
06074       
06075       if(i_pass == 1)
06076         {
06077           i_lico  = i_lic2;
06078           limit   = justap_chan;
06079           nb_elts = justap_samp;
06080           g_nam1  = "channel";
06081           g_nam2  = "sample";
06082         }
06083       
06084       if(i_lico > nb_elts){i_lico = nb_elts;}
06085       
06086       for (Int_t i_dim = 0 ; i_dim < limit ; i_dim++)
06087         {
06088           //  switch (i_code){
06089 
06090           if ( i_code ==  fCodeEv)
06091             {
06092               fFcout_f << "*TCnaRunEB> expectation values, ";
06093             }
06094           
06095           if ( i_code ==  fCodeVar)
06096             {
06097               fFcout_f << "*TCnaRunEB> variances, ";
06098             }
06099           
06100           if ( i_code ==  fCodeSvCorrecCovCss)
06101             {
06102               fFcout_f
06103                 << "*TCnaRunEB> Sample value correction coefficients, ";
06104             }
06105 
06106           if ( i_code ==  fCodeEvCorCss)
06107             {
06108               fFcout_f
06109                 << "*TCnaRunEB> expectation values of the"
06110                 << " (sample,sample) correlations, ";
06111             }
06112                   
06113           if ( i_code ==  fCodeSigCorCss)
06114             {
06115               fFcout_f << "*TCnaRunEB> sigmas of the"
06116                        << " (sample,sample) correlations, ";
06117             }
06118          
06119           if ( i_code ==  fCodeEvts)
06120             {
06121               fFcout_f << "*TCnaRunEB> numbers of events, ";
06122             }
06123           
06124             //default:
06125             // cout << "*TCnaRunEB::fT1dWriteAscii(const Int_t& i_code)> "
06126             //   << "wrong code , i_code = " << i_code << endl; 
06127             // }
06128           
06129           if(i_code == fCodeEvts)
06130             {
06131               fFcout_f << g_nam0 << " "
06132                                << fUserSMEcha << ", "
06133                                << g_nam1 << " " 
06134                                << i_dim  << ", "
06135                                << g_nam2 << " 0 to 99";
06136             }
06137           if(i_code == fCodeEv  ||
06138              i_code == fCodeVar ||
06139              i_code == fCodeSvCorrecCovCss)
06140             {
06141               fFcout_f << g_nam1 << " " << i_dim << ", " << g_nam2
06142                                << " 0 to " << nb_elts - 1;
06143             }
06144           if ( i_code == fCodeEvCorCss || i_code == fCodeSigCorCss)
06145             {
06146               fFcout_f << g_nam1 << " 0 to " << nb_elts - 1;
06147             }
06148           if(i_code == fCodeEvts)
06149             {
06150               fFcout_f << ", " << g_nam3 << " "
06151                                << (fT1d_xmin)[i_dim]
06152                                << " , " << g_nam4 << " "
06153                                << (fT1d_xmax)[i_dim];
06154             }
06155           
06156           fFcout_f << " :" << endl;
06157           
06158           Int_t k_lec = 1;  // indice pour gestion saut de ligne
06159           
06160           for (Int_t i_elt = 0 ; i_elt < nb_elts ; i_elt++)
06161             {
06162               fFcout_f.width(8);
06163               
06164               //  switch (i_code){
06165               
06166               if ( i_code ==  fCodeEv)
06167                 {
06168                   switch (i_pass){
06169                   case 0:
06170                     fFcout_f << (fjustap_2d_ev)[i_elt][i_dim];
06171                     break;
06172                   case 1:
06173                     fFcout_f << (fjustap_2d_ev)[i_dim][i_elt];
06174                     break;
06175                   }
06176                 }
06177               
06178               if ( i_code ==   fCodeVar || i_code == fCodeSvCorrecCovCss)
06179                 {
06180                   switch (i_pass){
06181                   case 0:
06182                     fFcout_f << fjustap_2d_var[i_elt][i_dim];
06183                     break;
06184                   case 1:
06185                     fFcout_f << fjustap_2d_var[i_dim][i_elt];
06186                     break;
06187                   }
06188                 }  
06189               
06190               if ( i_code ==  fCodeEvCorCss)
06191                 {
06192                   fFcout_f << fT1d_ev_cor_ss[i_elt];
06193                 }  
06194                       
06195               if ( i_code ==  fCodeSigCorCss)
06196                 {
06197                   fFcout_f << fT1d_sig_cor_ss[i_elt];
06198                 }  
06199               
06200               if ( i_code ==  fCodeEvts)
06201                 {
06202                   fFcout_f << fT2d_his_s[i_dim][i_elt];
06203                 }  
06204                       
06205               //  default:
06206               //  cout << "*TCnaRunEB::fT1dWriteAscii(const Int_t& i_code)> "
06207               //     << "wrong code , i_code = " << i_code << endl; 
06208               //  }
06209               
06210               fFcout_f << "  "; 
06211               
06212               if ( k_lec >= i_lico )
06213                 { 
06214                   fFcout_f << endl;       
06215                   k_lec = 1;
06216                 }
06217               else
06218                 { 
06219                   k_lec++;
06220                 }             
06221             }
06222         }
06223     }
06224   fFcout_f << endl;
06225 
06226   //................ closing of the results file      
06227   fFcout_f.close();
06228 
06229   if(fFlagPrint == fCodePrintAllComments){
06230     cout << "*TCnaRunEB> The results have been writen in the ASCII file: "
06231          << fAsciiFileName << endl;}
06232 } 
06233 
06234 //----------------------------------------------------------------------
06235 //
06236 //            fT2dWriteAscii: Array 2D of (n_sctx , n_scty) sectors
06237 //                          of size: i_pasx_arg * i_pasy_arg 
06238 //
06239 //                       (private)
06240 //
06241 //----------------------------------------------------------------------
06242 
06243 void  TCnaRunEB::fT2dWriteAscii(const Int_t&  i_code,
06244                               const Int_t&  i_pasx_arg,
06245                               const Int_t&  i_pasy_arg)
06246 {
06247 //Writing of a matrix by sectors (private)
06248 
06249   Int_t i_pasx = i_pasx_arg;           // taille secteur en x
06250   Int_t i_pasy = i_pasy_arg;           // taille secteur en y
06251   
06252   //------------ formatage des nombres en faisant appel a la classe ios
06253   
06254   fFcout_f << setiosflags(ios::showpoint | ios::uppercase);
06255   fFcout_f.setf(ios::dec, ios::basefield);
06256   fFcout_f.setf(ios::fixed, ios::floatfield);
06257   fFcout_f.setf(ios::left, ios::adjustfield);
06258   fFcout_f.setf(ios::right, ios::adjustfield);
06259   fFcout_f << setprecision(3) << setw(6);
06260   
06261   cout << setiosflags(ios::showpoint | ios::uppercase);
06262   cout.setf(ios::dec, ios::basefield);
06263   cout.setf(ios::fixed, ios::floatfield);
06264   cout.setf(ios::left, ios::adjustfield);
06265   cout.setf(ios::right, ios::adjustfield);
06266   cout << setprecision(3) << setw(6);  
06267 
06268   //--------------------- fin du formatage standard C++ -------------------
06269 
06270   //-----------------------------------------------------------------------
06271   //  Reservation dynamique d'un array Double_t** de dimensions
06272   //  les multiples de 5 juste au-dessus des dimensions de l'array 2D
06273   //  a ecrire ( array de dimensions
06274   //  (fFileHeader->fMaxSampADC,fFileHeader->fMaxSampADC)
06275   //  (fFileHeader->fMaxCrysInSM,fFileHeader->fMaxCrysInSM) )
06276   //-----------------------------------------------------------------------
06277   // Determination des tailles multiples de fSectChanSizeX ou fSectSampSizeX
06278 
06279   //*************** channels (NON UTILISE APPARAMENT. A REVOIR )******
06280   Int_t justap_chan = 0;
06281 
06282   if ( fFileHeader->fMaxCrysInSM%fSectChanSizeX == 0 ){
06283       justap_chan = fFileHeader->fMaxCrysInSM;}
06284   else{
06285       justap_chan=((fFileHeader->fMaxCrysInSM/fSectChanSizeX)+1)*fSectChanSizeX;}
06286 
06287   //....................... Allocation fjustap_2d_cc
06288 
06289   if ( i_code == fCodeCovScc || i_code == fCodeCorScc||
06290        i_code == fCodeCovSccMos || i_code == fCodeCorSccMos ){
06291     if(fjustap_2d_cc == 0)
06292       {
06293         //................... Allocation
06294         fjustap_2d_cc = new Double_t*[justap_chan];              fCnew++;  
06295         fjustap_1d_cc = new  Double_t[justap_chan*justap_chan];  fCnew++;  
06296         for(Int_t i = 0 ; i < justap_chan ; i++){
06297           fjustap_2d_cc[i] = &fjustap_1d_cc[0] + i*justap_chan;}
06298       }
06299   
06300     //............................... Transfert des valeurs dans fjustap_2d_cc  (=init)
06301     for(Int_t i = 0; i < fFileHeader->fMaxCrysInSM; i++){
06302       for(Int_t j = 0; j < fFileHeader->fMaxCrysInSM; j++){
06303         if ( i_code == fCodeCovScc ){
06304           fjustap_2d_cc[i][j] = fT3d_cov_cc[fUserSamp][i][j];}
06305         if ( i_code == fCodeCorScc ){
06306           fjustap_2d_cc[i][j] = fT3d_cor_cc[fUserSamp][i][j];}
06307         if ( i_code == fCodeCovSccMos ){
06308           fjustap_2d_cc[i][j] = fT2d_cov_cc_mos[i][j];}
06309         if ( i_code == fCodeCorSccMos ){
06310           fjustap_2d_cc[i][j] = fT2d_cor_cc_mos[i][j];}
06311       }
06312     }
06313     
06314     //.......................... mise a zero du reste de la matrice (=init)
06315     for(Int_t i = fFileHeader->fMaxCrysInSM; i < justap_chan; i++){
06316       for(Int_t j = fFileHeader->fMaxCrysInSM; j < justap_chan; j++){
06317         fjustap_2d_cc[i][j] = (Double_t)0.;}}
06318   }
06319 
06320   //************************************ Samples ***************************
06321   Int_t justap_samp = 0;
06322   
06323   if ( fFileHeader->fMaxSampADC%fSectSampSizeX == 0 ){
06324     justap_samp = fFileHeader->fMaxSampADC;}
06325   else{
06326     justap_samp=((fFileHeader->fMaxSampADC/fSectSampSizeX)+1)*fSectSampSizeX;}
06327 
06328   //....................... allocation fjustap_2d_ss
06329 
06330   if (i_code == fCodeCovCss          || i_code == fCodeCorCss ||
06331       i_code == fCodeCovCorrecCovCss || i_code == fCodeCorCorrecCovCss){
06332     if(fjustap_2d_ss == 0)
06333       {
06334         //................... Allocation
06335         fjustap_2d_ss = new Double_t*[justap_samp];              fCnew++;  
06336         fjustap_1d_ss = new  Double_t[justap_samp*justap_samp];  fCnew++;  
06337         for(Int_t i = 0 ; i < justap_samp ; i++){
06338           fjustap_2d_ss[i] = &fjustap_1d_ss[0] + i*justap_samp;}
06339       }
06340   //.............................. Transfert des valeurs dans fjustap_2d_ss (=init)
06341   for(Int_t i = 0; i < fFileHeader->fMaxSampADC; i++){
06342     for(Int_t j = 0; j < fFileHeader->fMaxSampADC; j++){
06343       if( i_code == fCodeCovCss ){
06344         fjustap_2d_ss[i][j] = fT3d_cov_ss[fUserSMEcha][i][j];}
06345       if( i_code == fCodeCorCss ){
06346         fjustap_2d_ss[i][j] = fT3d_cor_ss[fUserSMEcha][i][j];}
06347       if( i_code == fCodeCovCorrecCovCss ){
06348         fjustap_2d_ss[i][j] = fT3d_cov_correc_covss_s[fUserSMEcha][i][j];}
06349       if( i_code == fCodeCorCorrecCovCss ){
06350         fjustap_2d_ss[i][j] = fT3d_cor_correc_covss_s[fUserSMEcha][i][j];}
06351     }
06352   }
06353   //.......................... mise a zero du reste de la matrice (=init)
06354   for(Int_t i = fFileHeader->fMaxSampADC; i < justap_samp; i++){
06355     for(Int_t j = fFileHeader->fMaxSampADC; j < justap_samp; j++){
06356       fjustap_2d_ss[i][j] = (Double_t)0.;}}
06357   }
06358  
06359   //-------------------------------------------------------------------
06360 
06361   TEBNumbering* MyNumbering = new TEBNumbering();    fCnew++;
06362 
06363   //..................... impressions + initialisations selon i_code
06364   
06365   Int_t isx_max = 0;    
06366   Int_t isy_max = 0;
06367   
06368   if(i_code == fCodeCovScc)
06369     {
06370       fFcout_f << "*TCnaRunEB> Covariance matrix between SMEchas "
06371                << "for sample number " << fUserSamp;
06372       //    isx_max = fFileHeader->fMaxCrysInSM;
06373       //    isy_max = fFileHeader->fMaxCrysInSM;
06374       isx_max = justap_chan;
06375       isy_max = justap_chan;
06376     }
06377   if(i_code == fCodeCorScc)
06378     {
06379       fFcout_f << "*TCnaRunEB> Correlation matrix between SMEchas "
06380                << "for sample number " << fUserSamp;
06381       //     isx_max = fFileHeader->fMaxCrysInSM;
06382       //     isy_max = fFileHeader->fMaxCrysInSM;
06383       isx_max = justap_chan;
06384       isy_max = justap_chan;
06385     }
06386   
06387   if(i_code == fCodeCovSccMos)
06388     {
06389       fFcout_f << "*TCnaRunEB> Covariance matrix between SMEchas "
06390                << "averaged on the samples ";
06391       //    isx_max = fFileHeader->fMaxCrysInSM;
06392       //    isy_max = fFileHeader->fMaxCrysInSM;
06393       isx_max = justap_chan;
06394       isy_max = justap_chan;
06395     }
06396   if(i_code == fCodeCorSccMos)
06397     {
06398       fFcout_f << "*TCnaRunEB> Correlation matrix between SMEchas "
06399                << "averaged on the samples ";
06400       //     isx_max = fFileHeader->fMaxCrysInSM;
06401       //     isy_max = fFileHeader->fMaxCrysInSM;
06402       isx_max = justap_chan;
06403       isy_max = justap_chan;
06404     }
06405 
06406   if(i_code == fCodeCovCss)
06407     {
06408       fFcout_f << "*TCnaRunEB> Covariance matrix between samples "
06409                << "for SMEcha number " << fUserSMEcha
06410                << " (SMTow " << MyNumbering->GetSMTowFromSMEcha(fUserSMEcha)
06411                << " , TowEcha " << MyNumbering->GetTowEchaFromSMEcha(fUserSMEcha) << ")";
06412       //    isx_max = fFileHeader->fMaxSampADC;
06413       //    isy_max = fFileHeader->fMaxSampADC;
06414       isx_max = justap_samp;
06415       isy_max = justap_samp;
06416     }
06417   if(i_code == fCodeCorCss)
06418     { 
06419       fFcout_f << "*TCnaRunEB> Correlation matrix between samples "
06420                << "for SMEcha number " << fUserSMEcha
06421                << " (SMTow " << MyNumbering->GetSMTowFromSMEcha(fUserSMEcha) 
06422                << " , TowEcha " << MyNumbering->GetTowEchaFromSMEcha(fUserSMEcha) << ")";
06423       //      isx_max = fFileHeader->fMaxSampADC;
06424       //      isy_max = fFileHeader->fMaxSampADC;
06425       isx_max = justap_samp;
06426       isy_max = justap_samp;
06427     }
06428  
06429   if(i_code == fCodeCovCorrecCovCss)
06430     { 
06431       fFcout_f << "*TCnaRunEB> Correction factors to the covariances "
06432                << "between samples for SMEcha number " << fUserSMEcha
06433                << " (SMTow " << MyNumbering->GetSMTowFromSMEcha(fUserSMEcha)
06434                << " , TowEcha " << MyNumbering->GetTowEchaFromSMEcha(fUserSMEcha) << ")";
06435       //      isx_max = fFileHeader->fMaxSampADC;
06436       //      isy_max = fFileHeader->fMaxSampADC;
06437       isx_max = justap_samp;
06438       isy_max = justap_samp;
06439     }
06440   
06441   if(i_code == fCodeCorCorrecCovCss)
06442     { 
06443       fFcout_f << "*TCnaRunEB> Correction factors to the correlations "
06444                << "between samples for SMEcha number " << fUserSMEcha
06445                << " (SMTow " << MyNumbering->GetSMTowFromSMEcha(fUserSMEcha)
06446                << " , TowEcha " << MyNumbering->GetTowEchaFromSMEcha(fUserSMEcha) << ")";
06447       //      isx_max = fFileHeader->fMaxSampADC;
06448       //      isy_max = fFileHeader->fMaxSampADC;
06449       isx_max = justap_samp;
06450       isy_max = justap_samp;
06451     }
06452  
06453   fFcout_f << endl;
06454 
06455   //............... Calcul des nombres de secteurs selon x
06456   //                i_pasx  = taille secteur en x 
06457   //                isx_max = taille de la matrice en x
06458   //                n_sctx  = nombre de secteurs en x
06459   //
06460   if(i_pasx > isx_max){i_pasx = isx_max;}  
06461   Int_t n_sctx;
06462   Int_t max_verix; 
06463   n_sctx = isx_max/i_pasx;
06464   max_verix = n_sctx*i_pasx; 
06465   if(max_verix < isx_max){ n_sctx++;}
06466 
06467   //............... Calcul des nombres de secteurs selon y
06468   //                i_pasy  = taille secteur en y
06469   //                isy_max = taille de la matrice en y
06470   //                n_scty  = nombre de secteurs en x
06471   //
06472   if(i_pasy > isy_max){i_pasy = isy_max;} 
06473   Int_t n_scty;
06474   Int_t max_veriy; 
06475   n_scty = isy_max/i_pasy;
06476   max_veriy = n_scty*i_pasy; 
06477   if(max_veriy < isy_max){ n_scty++;}
06478 
06479 
06480   //................ Ecriture de la taille et du nombre des secteurs
06481   if( i_code == fCodeCovCss || i_code == fCodeCorCss ||
06482       i_code == fCodeCovCorrecCovCss ||  i_code == fCodeCorCorrecCovCss)
06483     {
06484       fFcout_f << "*TCnaRunEB> sector size = " << fSectSampSizeX 
06485                << " , number of sectors = " << n_sctx << " x " << n_scty
06486                <<endl;
06487     }
06488  if( i_code == fCodeCovScc     || i_code == fCodeCorScc ||
06489      i_code == fCodeCovSccMos  || i_code == fCodeCorSccMos )
06490     {
06491       fFcout_f << "*TCnaRunEB> sector size = " << fSectChanSizeX 
06492                << " , number of sectors = " << n_sctx << " x " << n_scty
06493                << endl;
06494     }
06495   fFcout_f << endl;
06496 
06497   //............... impression matrice par secteurs i_pas x i_pas  
06498   //........................... boucles pour display des secteurs 
06499   Int_t   ix_inf = -i_pasx;
06500   
06501   for(Int_t nsx = 0 ; nsx < n_sctx ; nsx++)
06502     { 
06503       //......................... calcul limites secteur
06504       ix_inf = ix_inf + i_pasx;
06505       Int_t   ix_sup = ix_inf + i_pasx; 
06506       
06507       Int_t   iy_inf = -i_pasy;
06508       
06509       for(Int_t nsy = 0 ; nsy < n_scty ; nsy++)
06510         {       
06511           iy_inf = iy_inf + i_pasy;          
06512           Int_t   iy_sup = iy_inf + i_pasy;
06513           
06514           //......................... display du secteur (nsx,nsy)
06515           
06516           if(i_code == fCodeCovScc || i_code == fCodeCovCss ||
06517              i_code == fCodeCovCorrecCovCss || i_code == fCodeCorCorrecCovCss )
06518             {fFcout_f << "        ";}
06519           if(i_code == fCodeCorScc || i_code == fCodeCorCss)
06520             {fFcout_f << "      ";}
06521           
06522           for (Int_t iy_c = iy_inf ; iy_c < iy_sup ; iy_c++)
06523             {
06524               if(i_code == fCodeCovScc || i_code == fCodeCovSccMos || i_code == fCodeCovCss ||
06525                  i_code == fCodeCovCorrecCovCss ||
06526                  i_code == fCodeCorCorrecCovCss)
06527                 {fFcout_f.width(8);}
06528               if(i_code == fCodeCorScc || i_code == fCodeCorSccMos || i_code == fCodeCorCss)
06529                 {fFcout_f.width(6);}
06530               fFcout_f << iy_c << "  ";
06531             }     
06532           fFcout_f << endl << endl;
06533           
06534           for (Int_t ix_c = ix_inf ; ix_c < ix_sup ; ix_c++)
06535             { 
06536               if(i_code == fCodeCovScc|| i_code == fCodeCovSccMos || i_code == fCodeCovCss ||
06537                  i_code == fCodeCovCorrecCovCss ||
06538                  i_code == fCodeCorCorrecCovCss)
06539                 {fFcout_f.width(8);}
06540               if(i_code == fCodeCorScc || i_code == fCodeCorSccMos || i_code == fCodeCorCss)
06541                 {fFcout_f.width(6);}
06542               fFcout_f << ix_c << "   ";
06543               
06544               for (Int_t iy_c = iy_inf ; iy_c < iy_sup ; iy_c++)
06545                 {
06546                   if(i_code == fCodeCovScc          ||
06547                      i_code == fCodeCovSccMos       ||
06548                      i_code == fCodeCovCss          ||
06549                      i_code == fCodeCovCorrecCovCss || 
06550                      i_code == fCodeCorCorrecCovCss ){
06551                     fFcout_f.width(8);}
06552 
06553                   if(i_code == fCodeCorScc || i_code == fCodeCorSccMos ||  i_code == fCodeCorCss){
06554                     fFcout_f.width(6);}
06555                   
06556                   if( i_code == fCodeCovScc ||  i_code == fCodeCovSccMos || i_code == fCodeCorScc){
06557                     fFcout_f << fjustap_2d_cc[ix_c][iy_c] << "  ";}
06558                   
06559                   if ( i_code == fCodeCovCss          ||
06560                        i_code == fCodeCorCss          ||
06561                        i_code == fCodeCovCorrecCovCss ||
06562                        i_code == fCodeCorCorrecCovCss )
06563                     {
06564                       fFcout_f << fjustap_2d_ss[ix_c][iy_c] << "  ";
06565                     }
06566                 }
06567               fFcout_f << endl;
06568             }
06569           fFcout_f << endl;
06570         }
06571     }
06572 
06573   //........... closing of the results file
06574   
06575   fFcout_f.close();
06576   
06577   if(fFlagPrint == fCodePrintAllComments){
06578     cout << "*TCnaRunEB> The results have been writen in the ASCII file: "
06579          << fAsciiFileName << endl;}
06580 
06581   delete MyNumbering;                      fCdelete++;
06582 }
06583 
06584 //-------------------------------------------------------------------------
06585 //
06586 //    Get methods for different run or file parameters
06587 //
06588 //    W A R N I N G :  some of these methods are called by external code
06589 //
06590 //                D O N ' T    S U P P R E S S !
06591 //
06592 //
06593 //     TString  fFileHeader->fTypAna        = typ_ana
06594 //     Int_t    fFileHeader->fRunNumber     = run_number
06595 //     Int_t    fFileHeader->fFirstEvt      = nfirst
06596 //     Int_t    fFileHeader->fNbOfTakenEvts = nevents
06597 //     Int_t    fFileHeader->fSuperModule   = super_module
06598 //     Int_t    fFileHeader->fNentries      = nentries
06599 //
06600 //-------------------------------------------------------------------------
06601 TString TCnaRunEB::GetRootFileNameShort()  {return fRootFileNameShort;}
06602 
06603 TString TCnaRunEB::GetAnalysisName()       {return fFileHeader->fTypAna;}
06604 Int_t   TCnaRunEB::GetRunNumber()          {return fFileHeader->fRunNumber;}
06605 Int_t   TCnaRunEB::GetFirstTakenEvent()    {return fFileHeader->fFirstEvt;}
06606 Int_t   TCnaRunEB::GetNumberOfTakenEvents(){return fFileHeader->fNbOfTakenEvts;}
06607 Int_t   TCnaRunEB::GetSMNumber()           {return fFileHeader->fSuperModule;}
06608 Int_t   TCnaRunEB::GetNentries()           {return fFileHeader->fNentries;}
06609 
06610 //------------------------------------------------------------------------
06611 Int_t  TCnaRunEB::PickupNumberOfEvents(const Int_t& SMEcha,
06612                                      const Int_t& sample)
06613 {
06614   Int_t nb_of_evts = -1;
06615 
06616   if( SMEcha >= 0 && SMEcha < fFileHeader->fMaxCrysInSM )
06617     {
06618       if( sample >= 0 && sample < fFileHeader->fMaxSampADC )
06619         { 
06620           nb_of_evts = fT2d_LastEvtNumber[SMEcha][sample] + 1;
06621         }
06622       else
06623         {
06624           cout << "!TCnaRunEB::PickupNumberOfEvents()> sample = "
06625            << sample << "OUT OF BOUNDS" << fTTBELL << endl;
06626         }
06627     }
06628   else
06629     {
06630       cout << "!TCnaRunEB::PickupNumberOfEvents()> SMEcha = "
06631            << SMEcha << "OUT OF BOUNDS" << fTTBELL << endl;
06632     }
06633 
06634   return nb_of_evts;
06635 }
06636 
06637 //=========================== E N D ======================================

Generated on Tue Jun 9 17:25:17 2009 for CMSSW by  doxygen 1.5.4