CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/src/TEcnaWrite.cc

Go to the documentation of this file.
00001 //----------Author's Name: B.Fabbro DSM/IRFU/SPP CEA-Saclay
00002 //----------Copyright: Those valid for CEA sofware
00003 //----------Modified: 30/06/2011
00004 
00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaWrite.h"
00006 
00007 //--------------------------------------
00008 //  TEcnaWrite.cc
00009 //  Class creation: 19 May 2005
00010 //  Documentation: see TEcnaWrite.h
00011 //--------------------------------------
00012 
00013 ClassImp(TEcnaWrite)
00014 //______________________________________________________________________________
00015 //
00016 
00017   TEcnaWrite::~TEcnaWrite()
00018 {
00019   //destructor
00020   
00021   //if (fEcal          != 0){delete fEcal;          fCdelete++;}
00022   //if (fEcalNumbering != 0){delete fEcalNumbering; fCdelete++;}
00023   //if (fCnaParPaths   != 0){delete fCnaParPaths;   fCdelete++;}
00024   //if (fCnaParCout    != 0){delete fCnaParCout;    fCdelete++;}
00025   
00026   // cout << "[Info Management] CLASS: TEcnaWrite.         DESTROY OBJECT: this = " << this << endl;
00027 }
00028 
00029 //===================================================================
00030 //
00031 //                   Constructors
00032 //
00033 //===================================================================
00034 TEcnaWrite::TEcnaWrite()
00035 {
00036 
00037  // cout << "[Info Management] CLASS: TEcnaWrite.         CREATE OBJECT: this = " << this << endl;
00038 
00039   Init();
00040 }
00041 
00042 TEcnaWrite::TEcnaWrite(TEcnaObject* pObjectManager, const TString SubDet)
00043 {
00044  // cout << "[Info Management] CLASS: TEcnaWrite.         CREATE OBJECT: this = " << this << endl;
00045 
00046   Init();
00047   Long_t i_this = (Long_t)this;
00048   pObjectManager->RegisterPointer("TEcnaWrite", i_this);
00049 
00050   //............................ fCnaParCout
00051   fCnaParCout = 0;
00052   Long_t iCnaParCout = pObjectManager->GetPointerValue("TEcnaParCout");
00053   if( iCnaParCout == 0 )
00054     {fCnaParCout = new TEcnaParCout(pObjectManager); /*fCnew++*/}
00055   else
00056     {fCnaParCout = (TEcnaParCout*)iCnaParCout;}
00057 
00058   //............................ fCnaParPaths
00059   fCnaParPaths = 0;
00060   Long_t iCnaParPaths = pObjectManager->GetPointerValue("TEcnaParPaths");
00061   if( iCnaParPaths == 0 )
00062     {fCnaParPaths = new TEcnaParPaths(pObjectManager); /*fCnew++*/}
00063   else
00064     {fCnaParPaths = (TEcnaParPaths*)iCnaParPaths;}
00065 
00066   //fCfgResultsRootFilePath    = fCnaParPaths->ResultsRootFilePath();
00067   //fCfgHistoryRunListFilePath = fCnaParPaths->HistoryRunListFilePath();
00068 
00069   fCnaParPaths->GetPathForResultsRootFiles();
00070   fCnaParPaths->GetPathForResultsAsciiFiles();
00071 
00072   //............................ fEcal  => should be changed in fParEcal
00073   fEcal = 0;
00074   Long_t iParEcal = pObjectManager->GetPointerValue("TEcnaParEcal");
00075   if( iParEcal == 0 )
00076     {fEcal = new TEcnaParEcal(pObjectManager, SubDet.Data()); /*fCnew++*/}
00077   else
00078     {fEcal = (TEcnaParEcal*)iParEcal;}
00079 
00080   //............................ fEcalNumbering
00081   fEcalNumbering = 0;
00082   Long_t iEcalNumbering = pObjectManager->GetPointerValue("TEcnaNumbering");
00083   if( iEcalNumbering == 0 )
00084     {fEcalNumbering = new TEcnaNumbering(pObjectManager, SubDet.Data()); /*fCnew++*/}
00085   else
00086     {fEcalNumbering = (TEcnaNumbering*)iEcalNumbering;}
00087 
00088   SetEcalSubDetector(SubDet.Data());
00089 }
00090 
00091 TEcnaWrite::TEcnaWrite(const TString SubDet,
00092                        const TEcnaParPaths*  pCnaParPaths, 
00093                        const TEcnaParCout*   pCnaParCout,
00094                        const TEcnaParEcal*   pEcal,
00095                        const TEcnaNumbering* pEcalNumbering)
00096 {
00097 
00098  // cout << "[Info Management] CLASS: TEcnaWrite.         CREATE OBJECT: this = " << this << endl;
00099 
00100   Init();
00101 
00102   //----------------------------- Object management
00103   fCnaParPaths = 0;
00104   if( pCnaParPaths == 0 )
00105     {fCnaParPaths = new TEcnaParPaths();  /*fCnew++*/ ;}
00106   else
00107     {fCnaParPaths = (TEcnaParPaths*)pCnaParPaths;}
00108 
00109   //................. Get paths from ECNA directory
00110   fCnaParPaths->GetPathForResultsRootFiles();
00111   fCnaParPaths->GetPathForResultsAsciiFiles();
00112 
00113   fCnaParCout  = 0;
00114   if( pCnaParCout == 0 )
00115     {fCnaParCout  = new TEcnaParCout();   /*fCnew++*/;}
00116   else
00117     {fCnaParCout = (TEcnaParCout*)pCnaParCout;}
00118 
00119   fEcal = 0;
00120   if( pEcal == 0 )
00121     {fEcal = new TEcnaParEcal(SubDet.Data());  /*fCnew++*/;}
00122   else
00123     {fEcal = (TEcnaParEcal*)pEcal;}
00124 
00125   fEcalNumbering = 0;
00126   if( pEcalNumbering == 0 )
00127     {fEcalNumbering = new TEcnaNumbering(SubDet.Data(), fEcal);  /*fCnew++*/;}
00128   else
00129     {fEcalNumbering = (TEcnaNumbering*)pEcalNumbering;}
00130 
00131   SetEcalSubDetector(SubDet.Data(), fEcal, fEcalNumbering);
00132 }
00133 
00134 void  TEcnaWrite::Init()
00135 {
00136   //----------------------------- Parameters values
00137   fTTBELL = '\007';
00138 
00139   fgMaxCar = (Int_t)512;              // max number of characters in TStrings
00140   fCodeHeaderAscii =  0;
00141   fCodeRoot        =  1;
00142 
00143   //------------------------------------------- Codes
00144   //................. presently used codes
00145   fCodeNbOfEvts    = 101;
00146   fCodePed         = 102;
00147   fCodeTno         = 103;
00148   fCodeLfn         = 104;
00149   fCodeHfn         = 105;
00150   fCodeMeanCorss   = 106;
00151   fCodeSigCorss    = 107;
00152 
00153   fCodeCovCss      = 201;
00154   fCodeCorCss      = 202;
00155 
00156   //................. not yet used codes 
00157   //fCodeAdcEvt      =  3;
00158   //fCodeMSp         =  4;  
00159   //fCodeSSp         =  5;
00160 
00161   //fCodeAvPed       = 17;
00162   //fCodeAvTno       =  6;
00163   //fCodeAvMeanCorss = 18;
00164   //fCodeAvSigCorss  = 19;
00165 
00166   //fCodeLfCov       = 11;
00167   //fCodeLfCor       = 12;
00168   //fCodeHfCov       =  9;
00169   //fCodeHfCor       = 10;
00170 
00171   //fCodeLFccMoStins = 13;
00172   //fCodeHFccMoStins = 14;
00173   
00174   //----------------------------------------
00175 
00176   fUserSamp     = 0;
00177   fStexStinUser = 0;
00178   fStinEchaUser = 0;
00179 
00180   fjustap_2d_ev  = 0;
00181   fjustap_1d_ev  = 0;
00182 
00183   fjustap_2d_var = 0;
00184   fjustap_1d_var = 0;
00185 
00186   fjustap_2d_cc  = 0;
00187   fjustap_1d_cc  = 0;
00188 
00189   fjustap_2d_ss  = 0;
00190   fjustap_1d_ss  = 0;
00191 
00192   fCodePrintAllComments = fCnaParCout->GetCodePrint("AllComments");
00193 
00194 }
00195 // end of Init()
00196 
00197 //===================================================================
00198 //
00199 //                   Methods
00200 //
00201 //===================================================================
00202 
00203 void TEcnaWrite::SetEcalSubDetector(const TString SubDet)
00204 {
00205  // Set Subdetector (EB or EE)
00206 
00207   Int_t MaxCar = fgMaxCar;
00208   fFlagSubDet.Resize(MaxCar);
00209   fFlagSubDet = fEcal->GetEcalSubDetector();
00210 
00211   //........................................................................
00212   //
00213   //             (for ASCII files writing methods only) ...
00214   //
00215   //                DEFINITION OF THE SECTOR SIZES
00216   //       FOR THE CORRELATION AND COVARIANCE MATRICES DISPLAY
00217   //
00218   //            MUST BE A DIVISOR OF THE TOTAL NUMBER.
00219   //            ======================================
00220   //
00221   //     Examples:
00222   //      
00223   //      (1)    25 channels => size = 25 or 5 (divisors of 25)
00224   //
00225   //             25 => matrix = 1 x 1 sector  of size (25 x 25)
00226   //                          = (1 x 1) x (25 x 25) = 1 x 625 = 625 
00227   //              5 => matrix = 5 x 5 sectors of size (5 x 5)
00228   //                          = (5 x 5) x ( 5 x  5) = 25 x 25 = 625 
00229   //
00230   //      (2)    10 samples  => size = 10, 5 or 2 (divisors of 10)
00231   //
00232   //             10 => matrix = 1 X 1 sectors of size (10 x 10) 
00233   //                          = (1 x 1) x (10 x 10) =  1 x 100 = 100
00234   //              5 => matrix = 2 x 2 sectors of size (5 x 5) 
00235   //                          = (2 x 2) x ( 5 x  5) =  4 x  25 = 100
00236   //              2 => matrix = 5 x 5 sectors of size (2 x 2) 
00237   //                          = (5 x 5) x ( 2 x  2) = 25 x  4  = 100
00238   //
00239   //........................................................................
00240   fSectChanSizeX = fEcal->MaxCrysHocoInStin();
00241   fSectChanSizeY = fEcal->MaxCrysVecoInStin();
00242   fSectSampSizeX = fEcal->MaxSampADC(); 
00243   fSectSampSizeY = fEcal->MaxSampADC();
00244 
00245   //........................................................................
00246   //
00247   //                DEFINITION OF THE NUMBER OF VALUES BY LINE
00248   //                for the Expectation Values, Variances and.
00249   //                Event distributions by (channel,sample)
00250   //
00251   //               MUST BE A DIVISOR OF THE TOTAL NUMBER.
00252   //               ======================================
00253   //
00254   //     Examples: 
00255   //                1) For expectation values and variances:
00256   //
00257   //                25 channels => size = 5
00258   //                => sample sector = 5 lines of 5 values
00259   //                                 = 5 x 5 = 25 values 
00260   //
00261   //                10 samples  => size = 10
00262   //                => channel sector = 1 lines of 10 values
00263   //                                  = 1 x 10 = 10 values
00264   //
00265   //                2) For event distributions:
00266   //
00267   //                100 bins  => size = 10
00268   //                => sample sector = 10 lines of 10 values
00269   //                                 = 10 x 10 = 100 values
00270   //
00271   //........................................................................
00272   fNbChanByLine = fEcal->MaxCrysHocoInStin();
00273   fNbSampByLine = fEcal->MaxSampADC();  
00274 }//---------- (end of SetEcalSubDetector) ------------------
00275 
00276 
00277 void TEcnaWrite::SetEcalSubDetector(const TString SubDet,
00278                                    const TEcnaParEcal* pEcal,
00279                                    const TEcnaNumbering*  pEcalNumbering)
00280 {
00281  // Set Subdetector (EB or EE)
00282 
00283 
00284   fEcal = 0;
00285   if( pEcal == 0 )
00286     {fEcal = new TEcnaParEcal(SubDet.Data());  fCnew++;}
00287   else
00288     {fEcal = (TEcnaParEcal*)pEcal;}
00289 
00290   Int_t MaxCar = fgMaxCar;
00291   fFlagSubDet.Resize(MaxCar);
00292   fFlagSubDet = fEcal->GetEcalSubDetector();
00293 
00294   fEcalNumbering = 0;
00295   if( pEcalNumbering == 0 )
00296     {fEcalNumbering = new TEcnaNumbering(SubDet.Data(), fEcal);  fCnew++;}
00297   else
00298     {fEcalNumbering = (TEcnaNumbering*)pEcalNumbering;}
00299 
00300   //........................................................................
00301   //
00302   //             (for ASCII files writing methods only) ...
00303   //
00304   //                DEFINITION OF THE SECTOR SIZES
00305   //       FOR THE CORRELATION AND COVARIANCE MATRICES DISPLAY
00306   //
00307   //            MUST BE A DIVISOR OF THE TOTAL NUMBER.
00308   //            ======================================
00309   //
00310   //     Examples:
00311   //      
00312   //      (1)    25 channels => size = 25 or 5 (divisors of 25)
00313   //
00314   //             25 => matrix = 1 x 1 sector  of size (25 x 25)
00315   //                          = (1 x 1) x (25 x 25) = 1 x 625 = 625 
00316   //              5 => matrix = 5 x 5 sectors of size (5 x 5)
00317   //                          = (5 x 5) x ( 5 x  5) = 25 x 25 = 625 
00318   //
00319   //      (2)    10 samples  => size = 10, 5 or 2 (divisors of 10)
00320   //
00321   //             10 => matrix = 1 X 1 sectors of size (10 x 10) 
00322   //                          = (1 x 1) x (10 x 10) =  1 x 100 = 100
00323   //              5 => matrix = 2 x 2 sectors of size (5 x 5) 
00324   //                          = (2 x 2) x ( 5 x  5) =  4 x  25 = 100
00325   //              2 => matrix = 5 x 5 sectors of size (2 x 2) 
00326   //                          = (5 x 5) x ( 2 x  2) = 25 x  4  = 100
00327   //
00328   //........................................................................
00329   fSectChanSizeX = fEcal->MaxCrysHocoInStin();
00330   fSectChanSizeY = fEcal->MaxCrysVecoInStin();
00331   fSectSampSizeX = fEcal->MaxSampADC(); 
00332   fSectSampSizeY = fEcal->MaxSampADC();
00333 
00334   //........................................................................
00335   //
00336   //                DEFINITION OF THE NUMBER OF VALUES BY LINE
00337   //                for the Expectation Values, Variances and.
00338   //                Event distributions by (channel,sample)
00339   //
00340   //               MUST BE A DIVISOR OF THE TOTAL NUMBER.
00341   //               ======================================
00342   //
00343   //     Examples: 
00344   //                1) For expectation values and variances:
00345   //
00346   //                25 channels => size = 5
00347   //                => sample sector = 5 lines of 5 values
00348   //                                 = 5 x 5 = 25 values 
00349   //
00350   //                10 samples  => size = 10
00351   //                => channel sector = 1 lines of 10 values
00352   //                                  = 1 x 10 = 10 values
00353   //
00354   //                2) For event distributions:
00355   //
00356   //                100 bins  => size = 10
00357   //                => sample sector = 10 lines of 10 values
00358   //                                 = 10 x 10 = 100 values
00359   //
00360   //........................................................................
00361   fNbChanByLine = fEcal->MaxCrysHocoInStin();
00362   fNbSampByLine = fEcal->MaxSampADC();  
00363 }//---------- (end of SetEcalSubDetector) ------------------
00364 
00365 
00366 //-------------------------------------------------------------------------
00367 //
00368 //    Get methods for different run or file parameters
00369 //
00370 //    W A R N I N G :  some of these methods are called by external code
00371 //
00372 //                D O N ' T    S U P P R E S S !
00373 //
00374 //
00375 //     TString  fRootFileNameShort
00376 //     TString  fAnaType       = typ_ana
00377 //     Int_t    fRunNumber     = run_number
00378 //     Int_t    fFirstReqEvtNumber = nfirst
00379 //     Int_t    fReqNbOfEvts = nevents
00380 //     Int_t    fStexNumber    = super_module
00381 //
00382 //-------------------------------------------------------------------------
00383 TString TEcnaWrite::GetAsciiFileName()    {return fAsciiFileName;}
00384 TString TEcnaWrite::GetRootFileName()     {return fRootFileName;}
00385 TString TEcnaWrite::GetRootFileNameShort(){return fRootFileNameShort;}
00386 TString TEcnaWrite::GetAnalysisName()     {return fAnaType;}
00387 Int_t   TEcnaWrite::GetNbOfSamples()      {return fNbOfSamples;}
00388 Int_t   TEcnaWrite::GetRunNumber()        {return fRunNumber;}
00389 Int_t   TEcnaWrite::GetFirstReqEvtNumber(){return fFirstReqEvtNumber;}
00390 Int_t   TEcnaWrite::GetReqNbOfEvts()      {return fReqNbOfEvts;}
00391 Int_t   TEcnaWrite::GetStexNumber()       {return fStexNumber;}
00392 
00393 //---------------------------------------------------------------------------------------------------
00394 //
00395 //  NumberOfEventsAnalysis(...) : Analyses the number of events found in data
00396 //                                channel by channel OR sample by sample
00397 //                                an output ERROR message is delivered if differences are detected
00398 //
00399 //            channel by channel: called by TEcnaRead object (3 arguments)
00400 //            sample  by sample : called by TEcnaRun  object (4 arguments)
00401 //
00402 //    This method must be a TEcnaWrite method since it can be called by objects
00403 //    of class TEcnaRead OR TEcnaRun
00404 //
00405 //---------------------------------------------------------------------------------------------------
00406 //.............................................................................................
00407 Int_t TEcnaWrite::NumberOfEventsAnalysis(Int_t*       ArrayNbOfEvts, const Int_t& MaxArray,
00408                                          const Int_t& NbOfReqEvts,   const Int_t& StexNumber)
00409 {
00410   //  CHECK THE NUMBER OF FOUND EVENTS, return rNumberOfEvents (NumberOfEvents())
00411   //  (number used to compute the average values over the events)
00412   //
00413   //  1D array: called by TEcnaRead object
00414 
00415   Int_t rNumberOfEvents = 0;
00416   Int_t PresentNumber   = 0;
00417   Int_t EmptyChannel    = 0;
00418   Int_t DifferentMinusValue = 0;
00419   Int_t DifferentPlusValue  = 0;
00420 
00421   //........................................................ i_SSoSE = StexStin or StinEcha
00422   for(Int_t i_SSoSE=0; i_SSoSE<MaxArray; i_SSoSE++)
00423     {
00424       Int_t NbOfEvts = ArrayNbOfEvts[i_SSoSE];
00425 
00426       if( NbOfEvts > 0 )
00427         {
00428           if( PresentNumber == 0 )   // first channel
00429             {
00430               PresentNumber = NbOfEvts;
00431             }
00432           else                      // current channel
00433             {
00434               if( NbOfEvts > PresentNumber )   // warning
00435                 { 
00436                   PresentNumber = NbOfEvts;
00437                   DifferentPlusValue++;
00438                 }
00439               if( NbOfEvts < PresentNumber )   // warning
00440                 {
00441                   DifferentMinusValue++;
00442                 }
00443             }
00444         }
00445       else
00446         {
00447           EmptyChannel++;
00448         }
00449     }
00450 
00451   rNumberOfEvents = PresentNumber;
00452 
00453   if( EmptyChannel > 0 )
00454     {
00455       if( MaxArray == fEcal->MaxCrysInSM() )  // (EB)
00456         {
00457           cout << "!TEcnaWrite::NumberOfEventsAnalysis()> *** WARNING *** "
00458                << EmptyChannel << " empty channels detected in SM " << StexNumber
00459                << " (EB " << fEcalNumbering->PlusMinusSMNumber(StexNumber) << ")" << endl;
00460         }
00461       if( MaxArray == fEcal->MaxCrysEcnaInDee() )  // (EE)
00462         {
00463           EmptyChannel -= fEcal->EmptyChannelsInDeeMatrixIncompleteSCIncluded();
00464           if( EmptyChannel > 0 )
00465             {
00466               cout << "!TEcnaWrite::NumberOfEventsAnalysis()> *** WARNING *** "
00467                    << EmptyChannel << " empty channels detected in Dee " << StexNumber << endl;
00468             }
00469         }
00470     }
00471 
00472   if( DifferentMinusValue > 0 || DifferentPlusValue > 0 )
00473     {
00474       cout << "!TEcnaWrite::NumberOfEventsAnalysis()> " << endl;
00475 
00476       if( MaxArray == fEcal->MaxCrysInSM() )  // (EB)
00477         {
00478           cout << "************** W A R N I N G  :  NUMBER OF EVENTS NOT CONSTANT FOR SM " << StexNumber
00479                << " (EB " << fEcalNumbering->PlusMinusSMNumber(StexNumber) << ")  *********************";
00480         }
00481 
00482       if( MaxArray == fEcal->MaxCrysEcnaInDee() )  // (EE)
00483         {
00484           cout << "****************** W A R N I N G  :  NUMBER OF EVENTS NOT CONSTANT FOR Dee " << StexNumber
00485                << " **************************";
00486         }
00487 
00488       cout << endl
00489            << "  Result ROOT file: " << fRootFileName << endl
00490            << "  The number of events is not the same for all the non-empty channels." << endl     
00491            << "  The maximum number (" << rNumberOfEvents << ") is considered as the number of events for calculations "
00492            << endl      
00493            << "  of pedestals, noises and correlations." << endl
00494            << "  Number of channels with 0 < nb of evts < " << rNumberOfEvents << " : " << DifferentMinusValue
00495            << endl
00496         // << "  Number of channels with nb of evts > " << rNumberOfEvents << " = " << DifferentPlusValue  << endl
00497            << "  Number of empty channels : " << EmptyChannel << endl
00498            << "  Some values of pedestals, noises and correlations may be wrong for channels" << endl
00499            << "  with number of events different from " << rNumberOfEvents << "." << endl
00500            << "  Please, check the histogram 'Numbers of events'." << endl
00501            << "*******************************************************************************************************"
00502            << endl;
00503     }
00504   else
00505     {
00506       if(fFlagPrint == fCodePrintAllComments)
00507         {
00508           if( rNumberOfEvents < NbOfReqEvts )
00509             {
00510               cout << "*TEcnaWrite::NumberOfEventsAnalysis()> *** INFO *** Number of events found in data = "
00511                    << rNumberOfEvents << ": less than number of requested events ( = " << NbOfReqEvts << ")" << endl;
00512             }
00513         }
00514     }
00515   return rNumberOfEvents;  
00516 }
00517 
00518 //.............................................................................................
00519 Int_t TEcnaWrite::NumberOfEventsAnalysis(Int_t**      T2d_NbOfEvts,   const Int_t& MaxCrysEcnaInStex,
00520                                          const Int_t& MaxNbOfSamples, const Int_t& NbOfReqEvts)
00521 {
00522   //  CHECK OF THE NUMBER OF FOUND EVENTS, return rNumberOfEvents (NumberOfEvents())
00523   //       (number used to compute the average values over the events)
00524   //
00525   //  2D array: called by TEcnaRun object
00526 
00527   Int_t rNumberOfEvents = 0;
00528   Int_t PresentNumber   = 0;
00529   Int_t DifferentMinusValue  = 0;
00530   Int_t DifferentPlusValue  = 0;
00531 
00532   for(Int_t i0StexEcha = 0 ; i0StexEcha < MaxCrysEcnaInStex ; i0StexEcha++)
00533     {
00534       for(Int_t i_samp = 0 ; i_samp < MaxNbOfSamples ; i_samp++)
00535         {
00536           Int_t NbOfEvts = T2d_NbOfEvts[i0StexEcha][i_samp];
00537 
00538           if( NbOfEvts > 0 )
00539             {
00540               if( PresentNumber == 0 )
00541                 {
00542                   PresentNumber = NbOfEvts;
00543                 }
00544               else
00545                 {
00546                   if( NbOfEvts > PresentNumber )
00547                     { 
00548                       PresentNumber = NbOfEvts;
00549                       DifferentPlusValue++;
00550                     }
00551                   if( NbOfEvts < PresentNumber )
00552                     {
00553                       DifferentMinusValue++;
00554                     }
00555                 }
00556             }
00557         }
00558     }
00559   //.............................................................  (NumberOfEvents())
00560   rNumberOfEvents = PresentNumber;
00561 
00562   if( DifferentMinusValue > 0 || DifferentPlusValue > 0 )
00563     {
00564       cout << "!TEcnaWrite::NumberOfEventsAnalysis()> " << endl
00565            << "****************** W A R N I N G  :  NUMBER OF EVENTS NOT CONSTANT !  *********************************"
00566            << endl
00567            << "  Result ROOT file: " << fRootFileName << endl
00568            << "  The number of events is not the same for all the non-empty channels" << endl      
00569            << "  The maximum number (" << rNumberOfEvents << ") is considered as the number of events " << endl 
00570            << "  for calculations of pedestals, noises and correlations." << endl
00571            << "  Number of channels with 0 < nb of evts < " << rNumberOfEvents << " : " << DifferentMinusValue << endl
00572         // << "  Number of channels with nb of evts > " << rNumberOfEvents << " : " << DifferentPlusValue  << endl
00573         // << "  Number of empty channels : " << EmptyChannel << endl
00574            << "  Some values of pedestals, noises and correlations may be wrong for channels" << endl
00575            << "  with number of events different from " << rNumberOfEvents << "." << endl
00576            << "  Please, check the histogram 'Numbers of events'." << endl
00577            << "*******************************************************************************************************"
00578            << endl;
00579     }
00580   else
00581     {
00582       if(fFlagPrint == fCodePrintAllComments)
00583         {
00584           if( rNumberOfEvents < NbOfReqEvts )
00585             {
00586               cout << "*TEcnaWrite::NumberOfEventsAnalysis()> *** INFO *** Number of events found in data = "
00587                    << rNumberOfEvents << ": less than number of requested events ( = " << NbOfReqEvts << ")" << endl;
00588             }
00589         }
00590     }
00591   return rNumberOfEvents;  
00592   
00593 }//----- ( end of NumberOfEvents(...) ) ----------------
00594 
00595 void TEcnaWrite::RegisterFileParameters(const TString ArgAnaType,
00596                                         const Int_t&  ArgNbOfSamples,       const Int_t& ArgRunNumber,
00597                                         const Int_t&  ArgFirstReqEvtNumber, const Int_t& ArgLastReqEvtNumber,
00598                                         const Int_t&  ArgReqNbOfEvts,       const Int_t& ArgStexNumber)
00599 {
00600   fAnaType           = ArgAnaType;
00601   fNbOfSamples       = ArgNbOfSamples;
00602   fRunNumber         = ArgRunNumber;
00603   fFirstReqEvtNumber = ArgFirstReqEvtNumber;
00604   fLastReqEvtNumber  = ArgLastReqEvtNumber;
00605   fReqNbOfEvts       = ArgReqNbOfEvts;
00606   fStexNumber        = ArgStexNumber;
00607 }
00608 
00609 void TEcnaWrite::RegisterFileParameters(const TString ArgAnaType, 
00610                                         const Int_t&  ArgNbOfSamples,       const Int_t&  ArgRunNumber,
00611                                         const Int_t&  ArgFirstReqEvtNumber, const Int_t&  ArgLastReqEvtNumber,
00612                                         const Int_t&  ArgReqNbOfEvts,       const Int_t&  ArgStexNumber,
00613                                         const TString ArgStartDate,         const TString ArgStopDate,
00614                                         const time_t  ArgStartTime,         const time_t  ArgStopTime)
00615 {
00616   fAnaType           = ArgAnaType;
00617   fNbOfSamples       = ArgNbOfSamples;
00618   fRunNumber         = ArgRunNumber;
00619   fFirstReqEvtNumber = ArgFirstReqEvtNumber;
00620   fLastReqEvtNumber  = ArgLastReqEvtNumber;
00621   fReqNbOfEvts       = ArgReqNbOfEvts;
00622   fStexNumber        = ArgStexNumber;
00623   fStartDate         = ArgStartDate;
00624 
00625   fStopDate          = ArgStopDate;
00626   fStartTime         = ArgStartTime;
00627   fStopTime          = ArgStopTime;
00628 }
00629 //=======================================================================
00630 //
00631 //                      FILE NAMES MANAGEMENT
00632 //
00633 //=======================================================================
00634 //==============================================================================
00635 //
00636 //                     Results Filename Making  (private)
00637 //
00638 //==============================================================================
00639 void TEcnaWrite::fMakeResultsFileName(){fMakeResultsFileName(fCodeRoot);}
00640 void TEcnaWrite::fMakeResultsFileName(const Int_t&  i_code)
00641 {
00642 //Results filename making  (private)
00643   
00644   //----------------------------------------------------------------------
00645   //
00646   //     Making of the name of the result file from the parameters set
00647   //     by call to RegisterFileParameters(...)
00648   //
00649   //     Put the names in the following class attributes:
00650   //
00651   //     fRootFileName,  fRootFileNameShort,
00652   //     fAsciiFileName, fAsciiFileNameShort
00653   //
00654   //     (Short means: without the directory path)
00655   //
00656   //     set indications (run number, type of quantity, ...)
00657   //     and add the extension ".ascii" or ".root"
00658   //     
00659   //     ROOT:  only one ROOT file:  i_code = fCodeRoot.
00660   //                                          All the types of quantities
00661   //
00662   //     ASCII: several ASCII files: i_code = code for one type of quantity
00663   //            each i_code which is not equal to fCodeRoot is also implicitly
00664   //            a code "fCodeAscii" (this last attribute is not in the class)
00665   //     
00666   //----------------------------------------------------------------------
00667 
00668   char* f_in       = new char[fgMaxCar];                 fCnew++;
00669   char* f_in_short = new char[fgMaxCar];                 fCnew++;
00670 
00671   Int_t MaxCar = fgMaxCar;
00672   fStexName.Resize(MaxCar); 
00673   fStexName  = "SM or Dee?";
00674 
00675   MaxCar = fgMaxCar;
00676   fStinName.Resize(MaxCar); 
00677   fStinName  = "tower or SC?";
00678 
00679   if( fFlagSubDet == "EB" ){fStexName = "SM";  fStinName = "tower";}
00680   if( fFlagSubDet == "EE" ){fStexName = "Dee"; fStinName = "SC";}
00681 
00682   //  switch (i_code){  
00683 
00684   //===================================  R O O T  =========================  (fMakeResultsFileName)
00685   TString sPointInterrog = "?";
00686   TString sDollarHome    = "$HOME";
00687 
00688   if (i_code == fCodeRoot)
00689     {
00690       if( fCnaParPaths->ResultsRootFilePath().Data() == sPointInterrog.Data() )
00691         {
00692           cout << "!TEcnaWrite::fMakeResultsFileName>  * * * W A R N I N G * * * " << endl << endl
00693                << "    Path for results .root file not defined. Default option will be used here:" << endl
00694                << "    your results files will be written in your HOME directory." << endl << endl
00695                << "    In order to write the .root results file in a specific directory," << endl
00696                << "    you have to create a file named path_results_root in a subdirectory named ECNA" << endl
00697                << "    previously created in your home directory." << endl 
00698                << "    This file must have only one line containing the path of the directory" << endl 
00699                << "    where must be the .root result files." << endl
00700                << endl;
00701 
00702           TString home_path = gSystem->Getenv("HOME");
00703           fCnaParPaths->SetResultsRootFilePath(home_path.Data());  
00704         }
00705 
00706       if( fCnaParPaths->BeginningOfResultsRootFilePath().Data() == sDollarHome.Data() )
00707         {
00708           fCnaParPaths->TruncateResultsRootFilePath(0,5);
00709           const Text_t *t_file_nohome = (const Text_t *)fCnaParPaths->ResultsRootFilePath().Data(); //  /scratch0/cna/...
00710           
00711           TString home_path = gSystem->Getenv("HOME");
00712           fCnaParPaths->SetResultsRootFilePath(home_path.Data());   //  /afs/cern.ch/u/USER
00713           fCnaParPaths->AppendResultsRootFilePath(t_file_nohome);   //  /afs/cern.ch/u/USER/scratch0/cna/...
00714         }
00715 
00716       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d",
00717               fCnaParPaths->ResultsRootFilePath().Data(), fAnaType.Data(), fNbOfSamples,
00718               fRunNumber, fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00719       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d",
00720               fAnaType.Data(), fNbOfSamples,
00721               fRunNumber, fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00722     }
00723 
00724   //===================================  A S C I I  ====================  (fMakeResultsFileName)
00725   //fCnaParPaths->GetPathForResultsAsciiFiles();
00726   if (i_code != fCodeRoot)
00727     {
00728       if (i_code == fCodeHeaderAscii)
00729         {
00730           if( fCnaParPaths->ResultsAsciiFilePath().Data() == sPointInterrog.Data() )
00731             {
00732               cout << "!TEcnaWrite::fMakeResultsFileName>  * * * W A R N I N G * * * " << endl << endl
00733                    << "    Path for results .ascii file not defined. Default option will be used here:" << endl
00734                    << "    your results files will be written in your HOME directory." << endl << endl
00735                    << "    In order to write the .ascii results file in a specific directory," << endl
00736                    << "    you have to create a file named path_results_ascii in a subdirectory named ECNA" << endl
00737                    << "    previously created in your home directory." << endl 
00738                    << "    This file must have only one line containing the path of the directory" << endl 
00739                    << "    where must be the .ascii result files." << endl
00740                    << endl;
00741               
00742               TString home_path = gSystem->Getenv("HOME");
00743               fCnaParPaths->SetResultsAsciiFilePath(home_path.Data());  
00744             } 
00745           
00746           if( fCnaParPaths->BeginningOfResultsAsciiFilePath().Data() == sDollarHome.Data() )
00747             {
00748               fCnaParPaths->TruncateResultsAsciiFilePath(0,5);
00749               const Text_t *t_file_nohome = (const Text_t *)fCnaParPaths->ResultsAsciiFilePath().Data(); // /scratch0/cna/...
00750               
00751               TString home_path = gSystem->Getenv("HOME");
00752               fCnaParPaths->SetResultsAsciiFilePath(home_path.Data());   //  /afs/cern.ch/u/USER
00753               fCnaParPaths->AppendResultsAsciiFilePath(t_file_nohome);   //  /afs/cern.ch/u/USER/scratch0/cna/...
00754             }
00755         }
00756 
00757       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_header",
00758               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00759               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00760       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_header",
00761               fAnaType.Data(), fNbOfSamples, fRunNumber,
00762               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00763     }
00764 
00765   //--------------------------------------------------------------  (fMakeResultsFileName)
00766   if (i_code == fCodeNbOfEvts)
00767     {
00768       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_NbOfEvents",
00769               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00770               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00771       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_NbOfEvents",
00772               fAnaType.Data(), fNbOfSamples, fRunNumber,
00773               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00774     }
00775 
00776   if (i_code == fCodePed)
00777     {
00778       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_Pedestals",
00779               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00780               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00781       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_Pedestals",
00782               fAnaType.Data(), fNbOfSamples, fRunNumber,
00783               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00784     } 
00785 
00786   if (i_code == fCodeTno)
00787     {
00788       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_TotalNoise",
00789               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00790               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00791       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_TotalNoise",
00792               fAnaType.Data(), fNbOfSamples, fRunNumber,
00793               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00794     } 
00795 
00796   if (i_code == fCodeLfn)
00797     {
00798       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_LFNoise",
00799               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00800               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00801       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_LFNoise",
00802               fAnaType.Data(), fNbOfSamples, fRunNumber,
00803               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00804     } 
00805 
00806   if (i_code == fCodeHfn)
00807     {
00808       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_HFNoise",
00809               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00810               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00811       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_HFNoise",
00812               fAnaType.Data(), fNbOfSamples, fRunNumber,
00813               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00814     }
00815 
00816   if (i_code == fCodeMeanCorss)
00817     {
00818       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_MeanCorss",
00819               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00820               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00821       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_MeanCorss",
00822               fAnaType.Data(), fNbOfSamples, fRunNumber,
00823               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00824     }
00825 
00826   if (i_code == fCodeSigCorss)
00827     {
00828       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_SigmaCorss",
00829               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00830               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00831       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_SigmaCorss",
00832               fAnaType.Data(), fNbOfSamples, fRunNumber,
00833               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00834     } 
00835 
00836   if (i_code ==  fCodeCovCss)
00837     {
00838       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_Covss_%s%d_Channel_%d",
00839               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00840               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber,
00841               fStinName.Data(), fStexStinUser, fStinEchaUser);
00842       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_Covss_%s%d_Channel_%d",
00843               fAnaType.Data(), fNbOfSamples, fRunNumber,
00844               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber,
00845               fStinName.Data(), fStexStinUser, fStinEchaUser);
00846     }
00847   
00848   if (i_code == fCodeCorCss)
00849     {
00850       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_Corss_%s%d_Channel_%d",
00851               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00852               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber,
00853               fStinName.Data(), fStexStinUser, fStinEchaUser);
00854       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_Corss_%s%d_Channel_%d",
00855               fAnaType.Data(), fNbOfSamples, fRunNumber,
00856               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber,
00857               fStinName.Data(), fStexStinUser, fStinEchaUser);
00858     }
00859 
00860   //------- (not used yet)
00861 #define OCOD
00862 #ifndef OCOD
00863   if (i_code == fCodeMSp)
00864     {
00865       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_SampleMeans",
00866               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00867               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00868       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_SampleMeans",
00869               fAnaType.Data(), fNbOfSamples, fRunNumber,
00870               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00871     }
00872   
00873   if (i_code == fCodeSSp)
00874     {
00875       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_SampleSigmas",
00876               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00877               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00878       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_SampleSigmas",
00879               fAnaType.Data(), fNbOfSamples, fRunNumber,
00880               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00881     }
00882   
00883   if( i_code == fCodeAvTno)
00884     {
00885       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_AverageTotalNoise_c%d",
00886               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00887               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber, fStinEchaUser);
00888       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_AverageTotalNoise_c%d",
00889               fAnaType.Data(), fNbOfSamples, fRunNumber,
00890               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber, fStinEchaUser);
00891     }
00892   
00893   if(  i_code == fCodeLfCov)
00894     {
00895       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_LF_cov",
00896               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00897               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00898       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_LF_cov",
00899               fAnaType.Data(), fNbOfSamples, fRunNumber,
00900               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00901     }
00902   
00903   if ( i_code == fCodeLfCor)
00904     {
00905       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_LF_cor",
00906               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00907               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00908       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_LF_cor",
00909               fAnaType.Data(), fNbOfSamples, fRunNumber,
00910               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00911     }
00912   
00913   if (i_code == fCodeAvPed)
00914     {
00915       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_AveragePedestals",
00916               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00917               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00918       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_AveragePedestals",
00919               fAnaType.Data(), fNbOfSamples, fRunNumber,
00920               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber);
00921     }
00922   
00923   if (i_code == fCodeAvMeanCorss)
00924     {
00925       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_AverageMeanCorss%d",
00926               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00927               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber, fStinEchaUser);
00928       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_AverageMeanCorss%d",
00929               fAnaType.Data(), fNbOfSamples, fRunNumber,
00930               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber, fStinEchaUser);
00931     }
00932 
00933   if (i_code == fCodeAvSigCorss)
00934     {
00935       sprintf(f_in, "%s/%s_S1_%d_R%d_%d_%d_%d_%s%d_AverageSigmaCorss%d",
00936               fCnaParPaths->ResultsAsciiFilePath().Data(), fAnaType.Data(), fNbOfSamples, fRunNumber,
00937               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber, fStinEchaUser);
00938       sprintf(f_in_short, "%s_S1_%d_R%d_%d_%d_%d_%s%d_AverageSigmaCorss%d",
00939               fAnaType.Data(), fNbOfSamples, fRunNumber,
00940               fFirstReqEvtNumber, fLastReqEvtNumber, fReqNbOfEvts, fStexName.Data(), fStexNumber, fStinEchaUser);
00941     } 
00942 #endif // OCOD
00943 
00944   //----------------------------------------------------------- (fMakeResultsFileName)
00945 
00946   // default:
00947   //    cout << "*TEcnaWrite::fMakeResultsFileName(const Int_t&  i_code)> "
00948   //     << "wrong header code , i_code = " << i_code << endl; 
00949   //  }
00950 
00951   //======================================= f_name
00952   
00953   char* f_name = new char[fgMaxCar];                   fCnew++;
00954   
00955   for (Int_t i = 0 ; i < fgMaxCar ; i++){f_name[i] = '\0';}
00956   
00957   Int_t ii = 0;
00958   for (Int_t i = 0 ; i < fgMaxCar ; i++)
00959     {
00960       if ( f_in[i] != '\0' ){f_name[i] = f_in[i]; ii++;}
00961       else {break;}  // va directement a if ( ii+5 < fgMaxCar ) puis... f_name[ii] = '.';
00962     }
00963  
00964   if ( ii+5 < fgMaxCar )
00965     {
00966       //.......... writing of the file extension (.root or .ascii)  (fMakeResultsFileName)
00967       
00968       //------------------------------------------- extension .ascii
00969       if ( i_code != fCodeRoot  || i_code == fCodeNbOfEvts )
00970         {
00971           f_name[ii] = '.';   f_name[ii+1] = 'a';
00972           f_name[ii+2] = 's'; f_name[ii+3] = 'c';
00973           f_name[ii+4] = 'i'; f_name[ii+5] = 'i';
00974           
00975           fAsciiFileName = f_name;
00976         }
00977       //------------------------------------------- extension .root
00978       if ( i_code == fCodeRoot )
00979         {
00980           f_name[ii] = '.';   f_name[ii+1] = 'r';
00981           f_name[ii+2] = 'o'; f_name[ii+3] = 'o';  f_name[ii+4] = 't';
00982           
00983           fRootFileName = f_name;
00984         }
00985     }
00986   else
00987     {
00988       cout << "*TEcnaWrite::fMakeResultsFileName(...)> Name too long (for f_name)."
00989            << " No room enough for the extension. (ii = " << ii << ")"
00990            << fTTBELL << endl; 
00991     }
00992 
00993 
00994   //====================================== f_name_short  (fMakeResultsFileName)
00995   
00996   char* f_name_short = new char[fgMaxCar];          fCnew++;
00997 
00998   for (Int_t i = 0 ; i < fgMaxCar ; i++){f_name_short[i] = '\0';}
00999   
01000   ii = 0;
01001   for (Int_t i = 0 ; i < fgMaxCar ; i++)
01002     {
01003       if ( f_in_short[i] != '\0' ){f_name_short[i] = f_in_short[i]; ii++;}
01004       else {break;}  // va directement a f_name_short[ii] = '.';
01005     }
01006  
01007   if ( ii+5 < fgMaxCar )
01008     {
01009       //.......... writing of the file extension (.root or .ascii)
01010       
01011       //-------------------------------------------extension .ascii
01012       if ( i_code != fCodeRoot || i_code == fCodeNbOfEvts )
01013         {
01014           f_name_short[ii] = '.';   f_name_short[ii+1] = 'a';
01015           f_name_short[ii+2] = 's'; f_name_short[ii+3] = 'c';
01016           f_name_short[ii+4] = 'i'; f_name_short[ii+5] = 'i';
01017           
01018           fAsciiFileNameShort = f_name_short;
01019         }
01020       
01021       //-------------------------------------------- extension .root
01022       if ( i_code == fCodeRoot )
01023         {
01024           f_name_short[ii] = '.';   f_name_short[ii+1] = 'r';
01025           f_name_short[ii+2] = 'o'; f_name_short[ii+3] = 'o';  f_name_short[ii+4] = 't';
01026           
01027           fRootFileNameShort = f_name_short;
01028         }
01029     }
01030   else
01031     {
01032       cout << "*TEcnaWrite::fMakeResultsFileName(...)> Name too long (for f_name_short)."
01033            << " No room enough for the extension. (ii = " << ii << ")"
01034            << fTTBELL  << endl; 
01035     }
01036     delete [] f_name;        f_name       = 0;         fCdelete++;
01037     delete [] f_name_short;  f_name_short = 0;         fCdelete++;
01038 
01039     delete [] f_in;          f_in       = 0;           fCdelete++;
01040     delete [] f_in_short;    f_in_short = 0;           fCdelete++;
01041 
01042 }  // end of fMakeResultsFileName
01043 
01044 //==========================================================================================
01045 //
01046 //
01047 //
01048 //==========================================================================================
01049 
01050 void TEcnaWrite::fAsciiFileWriteHeader(const Int_t&  i_code)
01051 {
01052 //Ascii results file header writing  (private). Called by the WriteAscii...() methods
01053   
01054   //-----------------------------------------------
01055   //
01056   //     opening of the ASCII results file
01057   //     and writing of its header
01058   //
01059   //-----------------------------------------------
01060 
01061   if(fAsciiFileName.BeginsWith("$HOME"))
01062     {
01063       fAsciiFileName.Remove(0,5);
01064       TString EndOfAsciiFileName = fAsciiFileName;
01065       const Text_t *t_file_nohome = (const Text_t *)EndOfAsciiFileName.Data(); //  const Text_t* -> EndOfAsciiFileName
01066       // ( /scratch0/cna/... )
01067       TString home_path = gSystem->Getenv("HOME");
01068       fAsciiFileName = home_path;             // fAsciiFileName = absolute HOME path ( /afs/cern.ch/u/USER )
01069       fAsciiFileName.Append(t_file_nohome);   // Append  (const Text_t* -> EndOfAsciiFileName) to fAsciiFileName
01070       // ( /afs/cern.ch/u/USER/scratch0/cna/... )
01071     }
01072 
01073   fFcout_f.open(fAsciiFileName.Data());
01074 
01075   fFcout_f << "*** File: " << fAsciiFileName
01076            << " *** " << endl << endl;
01077   fFcout_f << "*Analysis name                : " << fAnaType       << endl;
01078   fFcout_f << "*First-Last samples           : 1 - " << fNbOfSamples   << endl; 
01079   fFcout_f << "*Run number                   : " << fRunNumber     << endl;
01080   fFcout_f << "*First requested event number : " << fFirstReqEvtNumber << endl;
01081   fFcout_f << "*Last  requested event number : " << fLastReqEvtNumber << endl;
01082   fFcout_f << "*Requested number of events   : " << fReqNbOfEvts << endl;
01083   if( fFlagSubDet == "EB" )
01084     {fFcout_f << "*SuperModule number           : " << fStexNumber   << endl;}
01085   if( fFlagSubDet == "EE" )
01086     {fFcout_f << "*Dee number                   : " << fStexNumber   << endl;}
01087   fFcout_f << "*Date first requested event   : " << fStartDate;
01088   fFcout_f << "*Date last requested event    : " << fStopDate      << endl;
01089   fFcout_f << endl;
01090 
01091   //========================================================================= 
01092   //   closing of the results file if i_code = fCodeHeaderAscii only.
01093   //   closing is done in the fT1dWriteAscii() and fT2dWriteAscii() methods
01094   //   except for i_code = fCodeHeaderAscii
01095   //=========================================================================
01096   if(i_code == fCodeHeaderAscii){fFcout_f.close();}
01097 }
01098 
01099 //=========================================================================
01100 //
01101 //         W R I T I N G   M E T H O D S :    R O O T    F I L E S
01102 //
01103 //    The root files are written by TEcnaRun since the arrays are computed
01104 //    by this class (arrays fT2d_..., fT1d_..) and are private attributes.
01105 //    No writing method in ROOT file here.
01106 //    Just the making of the file name
01107 //
01108 //=========================================================================
01109 
01110 //=========================================================================
01111 //
01112 //    W R I T I N G   M E T H O D S :    A S C I I    F I L E S   
01113 //
01114 //    Ascii file are treated on the same footing as plots in the
01115 //    TEcnaHistos methods.
01116 //    The arrays are TVectorD or TMatrixD and are arguments of the
01117 //    writting methods (WriteAsciiHisto, fT2dWriteAscii)
01118 //
01119 //=========================================================================
01120 //
01121 //  In the following, we describe:
01122 //  
01123 //     (1) The method which gets the path for the results ASCII files
01124 //         from a "cna-configuration" file
01125 //     (2) The codification for the names of the ASCII files
01126 //     (3) The methods which writes the results in the ASCII files
01127 //
01128 //
01129 //
01130 // (1)-----------> Method to set the path for the results ASCII files
01131 //
01132 //      void  MyCnaRun->GetPathForResultsAsciiFiles(pathname);
01133 //
01134 //            TString pathname = name of a "cna-config" file located
01135 //            in the user's HOME directory and containing one line which
01136 //            specifies the path where must be written the .ascii result files.
01137 //            (no slash at the end of the string)
01138 //    
01139 //   DEFAULT: 
01140 //            void  MyCnaRun->GetPathForResultsAsciiFiles();
01141 //            If there is no argument, the "cna-config" file must be named
01142 //            "path_results_ascii.ecna" and must be located in the user's HOME
01143 //            directory
01144 //
01145 //
01146 // (2)-----------> Codification for the names of the ASCII files (examples):
01147 //
01148 //       aaa_nnnS_Rrrr_fff_ttt_SMnnn_pedestals.ascii   OR  aaa_nnnS_Rrrr_fff_ttt_Deennn_pedestals.ascii
01149 //       aaa_nnnS_Rrrr_fff_ttt_SMnnn_HF_noise.ascii    OR  aaa_nnnS_Rrrr_fff_ttt_Deennn_HF_noise.ascii 
01150 //       aaa_nnnS_Rrrr_fff_ttt_SMnnn_corss_cCCC.ascii  OR  aaa_nnnS_Rrrr_fff_ttt_Deennn_corss_cCCC.ascii 
01151 //       etc...  
01152 //
01153 //  with:
01154 //       aaa = Analysis name
01155 //       rrr = Run number
01156 //       fff = First requested event number
01157 //       ttt = Number of requested events
01158 //       CCC = Electronic Channel number in Stex
01159 //       nnn = SM number or Dee number
01160 //
01161 //  Examples:
01162 //       StdPed12_10S_R66689_1_50_SM1_pedestals.ascii
01163 //       StdPed6_10S_R66689_1_50_Dee3_cor_ss_c2234.ascii
01164 //
01165 //
01166 // (3)-----------> Methods which write the ASCII files:
01167 //
01168 //  The methods which write the ASCII files are the following:
01169 //
01170 //      void  WriteAsciiCovariancesBetweenSamples(Channel, MatrixSize, TMatrixD matrix);
01171 //      void  WriteAsciiCorrelationsBetweenSamples(Channel, MatrixSize, TMatrixD matrix);
01172 //      void  fT2dWriteAscii(code, px, py, MatrixSize, TMatrixD matrix) [private]
01173 //      void  WriteAsciiHisto(CodeHisto, HistoSize, TVectorD histo)
01174 //
01175 //  Each of these methods corresponds to a "calculation method" of TEcnaRun.
01176 //  The calculation method of TEcnaRun must have been been called before
01177 //  using the writing method of TEcnaWrite.
01178 //==========================================================================================
01179 
01180 //-------------------------------------------------------------------------------------------
01181 //
01182 //          WriteAsciiHisto()
01183 //
01184 //          Stex = SM or Dee , Stin = Tower or SC
01185 //
01186 //-------------------------------------------------------------------------------------------
01187 void TEcnaWrite::WriteAsciiHisto(const TString HistoCode, const Int_t& HisSize, 
01188                                 const TVectorD& read_histo)
01189 {
01190 //Write histo with correspondance CNA-channel <-> xtal number in SM or Dee
01191 
01192   // BuildCrysTable() is called in the method Init() which is called by the constructor
01193 
01194   Int_t i_code = fCodeNbOfEvts;
01195 
01196   //--------------------------------------------------------------------------------
01197   if( HistoCode == "D_NOE_ChNb" ){i_code = fCodeNbOfEvts;}
01198   if( HistoCode == "D_Ped_ChNb" ){i_code = fCodePed;}
01199   if( HistoCode == "D_TNo_ChNb" ){i_code = fCodeTno;}
01200   if( HistoCode == "D_LFN_ChNb" ){i_code = fCodeLfn;}
01201   if( HistoCode == "D_HFN_ChNb" ){i_code = fCodeHfn;}
01202   if( HistoCode == "D_MCs_ChNb" ){i_code = fCodeMeanCorss;}
01203   if( HistoCode == "D_SCs_ChNb" ){i_code = fCodeSigCorss;}
01204 
01205   fMakeResultsFileName(i_code);    // => Making of the results .ascii file name
01206   fAsciiFileWriteHeader(i_code);   // => Open of the file associated with stream fFcout_f
01207 
01208   //..................................... format numerical values
01209   fFcout_f << setiosflags(ios::showpoint | ios::uppercase);
01210   fFcout_f << setprecision(3) << setw(6);
01211   fFcout_f.setf(ios::dec, ios::basefield);
01212   fFcout_f.setf(ios::fixed, ios::floatfield);
01213   fFcout_f.setf(ios::left, ios::adjustfield);
01214   fFcout_f.setf(ios::right, ios::adjustfield);
01215   
01216   cout << setiosflags(ios::showpoint | ios::uppercase);
01217   cout << setprecision(3) << setw(6);
01218   cout.setf(ios::dec, ios::basefield);
01219   cout.setf(ios::fixed, ios::floatfield);
01220   cout.setf(ios::left, ios::adjustfield);
01221   cout.setf(ios::right, ios::adjustfield);
01222 
01223   //........................................................ WriteAsciiHisto
01224   TString aStexName;
01225   Int_t MaxCar = fgMaxCar;
01226   aStexName.Resize(MaxCar); 
01227   aStexName  = "SM or Dee?";
01228   
01229   TString aStinName;     
01230   MaxCar = fgMaxCar;
01231   aStinName.Resize(MaxCar); 
01232   aStinName  = "Tower or SC?";
01233   
01234   TString aHoco;
01235   MaxCar = fgMaxCar;
01236   aHoco.Resize(MaxCar); 
01237   aHoco  = "Eta or IX?";
01238   
01239   TString aVeco;
01240   MaxCar = fgMaxCar;
01241   aVeco.Resize(MaxCar); 
01242   aVeco  = "Phi or IY?";
01243   
01244   TString aSpecifa;     
01245   MaxCar = fgMaxCar;
01246   aSpecifa.Resize(MaxCar); 
01247   aSpecifa  = " ";
01248   
01249   TString aSpecifc;     
01250   MaxCar = fgMaxCar;
01251   aSpecifc.Resize(MaxCar); 
01252   aSpecifc  = " ";
01253 
01254   TString aSpecifd;     
01255   MaxCar = fgMaxCar;
01256   aSpecifd.Resize(MaxCar); 
01257   aSpecifd  = " ";
01258 
01259   TString aSpecife;     
01260   MaxCar = fgMaxCar;
01261   aSpecife.Resize(MaxCar); 
01262   aSpecife  = " ";
01263     
01264   TString aSpecif1;     
01265   MaxCar = fgMaxCar;
01266   aSpecif1.Resize(MaxCar); 
01267   aSpecif1  = " ";
01268   
01269   TString aSpecif2;
01270   MaxCar = fgMaxCar;
01271   aSpecif2.Resize(MaxCar); 
01272   aSpecif2  = " ";
01273   
01274   if( fFlagSubDet == "EB" )
01275     {
01276       aStexName = "SM   "     ; aStinName = "tower"     ; aSpecifa = " channel# ";
01277       aHoco     = "   Eta    "; aVeco     = "   Phi    "; aSpecifc = " channel# ";
01278       aSpecifd  = " crystal# "; aSpecife  = "SM    ";
01279     }
01280   if( fFlagSubDet == "EE" )
01281     {
01282       aStexName = "Dee  "     ; aStinName = " SC  "     ; aSpecifa = "  Sector# ";
01283       aHoco     = "   IX     "; aVeco     = "   IY     "; aSpecifc = " crystal# ";
01284       aSpecifd  = "   SC #   "; aSpecife  = "Sector";
01285     }
01286   
01287   //.............................................................. WriteAsciiHisto
01288   for (Int_t i0StexEcha=0; i0StexEcha<HisSize; i0StexEcha++)
01289     {
01290       Int_t n1StexStin   = 0;
01291       Int_t StexStinEcna = 0;
01292       Int_t i0StinEcha   = 0;
01293       Int_t n1StinEcha   = 0;
01294       Int_t n1StexCrys   = 0;
01295       Int_t n1DataSector = 0;
01296       Int_t n1SCinDS     = 0;
01297 
01298       if( fFlagSubDet == "EB")
01299         {
01300           n1StexStin   = fEcalNumbering->Get1SMTowFrom0SMEcha(i0StexEcha);
01301           StexStinEcna = n1StexStin;
01302           i0StinEcha   = fEcalNumbering->Get0TowEchaFrom0SMEcha(i0StexEcha);
01303           n1StexCrys   = fEcalNumbering->Get1SMCrysFrom1SMTowAnd0TowEcha(n1StexStin, i0StinEcha);
01304         }
01305       if( fFlagSubDet == "EE")
01306         {
01307           StexStinEcna = fEcalNumbering->Get1DeeSCEcnaFrom0DeeEcha(i0StexEcha);
01308           n1DataSector = fEcalNumbering->GetDSFrom1DeeSCEcna(fStexNumber, StexStinEcna);
01309           n1SCinDS     = fEcalNumbering->GetDSSCFrom1DeeSCEcna(fStexNumber, StexStinEcna);
01310           n1StexStin   = fEcalNumbering->GetDeeSCConsFrom1DeeSCEcna(fStexNumber, StexStinEcna);
01311           n1StinEcha   = fEcalNumbering->Get1SCEchaFrom0DeeEcha(i0StexEcha);
01312         }
01313       
01314       if( n1StexStin > 0 )
01315         {
01316           if( (fFlagSubDet == "EB" && i0StinEcha == 0) || (fFlagSubDet == "EE" && n1StinEcha == 1) )
01317             {
01318               if( HistoCode == "D_NOE_ChNb" ){aSpecif1 = "Number of"; aSpecif2 = "     events (requested)";}
01319               if( HistoCode == "D_Ped_ChNb" ){aSpecif1 = "Pedestals"; aSpecif2 = "             ";}
01320               if( HistoCode == "D_TNo_ChNb" ){aSpecif1 = "   Total "; aSpecif2 = "   noise     ";}
01321               if( HistoCode == "D_MCs_ChNb" ){aSpecif1 = "    Mean "; aSpecif2 = "   cor(s,s)  ";}
01322               if( HistoCode == "D_LFN_ChNb" ){aSpecif1 = "   Low Fq"; aSpecif2 = "   noise     ";}
01323               if( HistoCode == "D_HFN_ChNb" ){aSpecif1 = "  High Fq"; aSpecif2 = "   noise     ";}
01324               if( HistoCode == "D_SCs_ChNb" ){aSpecif1 = " Sigma of"; aSpecif2 = "   cor(s,s)  ";}
01325               
01326               fFcout_f << endl;
01327           
01328               fFcout_f << aSpecifa.Data()
01329                        << "  " << aStinName.Data() << "#   "
01330                        << aSpecifc.Data()
01331                        << aSpecifd.Data()
01332                        << aHoco.Data()
01333                        << aVeco.Data()
01334                        << aSpecif1.Data() << endl;
01335           
01336               fFcout_f << "  in " << aStexName.Data()
01337                        << "  in " << aStexName.Data()
01338                        << "  in " << aStinName.Data()
01339                        << "  in " << aSpecife.Data()
01340                        << "  in " << aStexName.Data()
01341                        << "  in " << aStexName.Data()
01342                        << aSpecif2.Data()  << endl << endl;
01343             }
01344  
01345           Double_t value = read_histo(i0StexEcha);
01346 
01347           if( fFlagSubDet == "EB" )
01348             {
01349               fFcout_f  << setw(7)  << i0StexEcha
01350                         << setw(8)  << n1StexStin
01351                         << setw(11) << i0StinEcha   // (Electronic channel number in tower)
01352                         << setw(10) << n1StexCrys
01353                         << setw(10) << (Int_t)fEcalNumbering->GetEta(fStexNumber, StexStinEcna, i0StinEcha)
01354                         << setw(10) << (Int_t)fEcalNumbering->GetPhiInSM(fStexNumber, StexStinEcna, i0StinEcha);
01355             }
01356           if( fFlagSubDet == "EE" )
01357             {
01358               Int_t n1StinEcha_m = n1StinEcha-1;
01359               fFcout_f  << setw(7)  << n1DataSector
01360                         << setw(8)  << n1StexStin
01361                         << setw(11) << n1StinEcha   // (Xtal number for construction in SC)
01362                         << setw(10) << n1SCinDS
01363                         << setw(10) << fEcalNumbering->GetIXCrysInDee(fStexNumber, StexStinEcna, n1StinEcha_m)
01364                         << setw(10) << fEcalNumbering->GetJYCrysInDee(fStexNumber, StexStinEcna, n1StinEcha_m);
01365             }
01366 
01367           if( HistoCode == "D_NOE_ChNb")
01368             {
01369               Int_t ivalue = (Int_t)value;
01370               fFcout_f  << setw(13) << ivalue;
01371               fFcout_f  << setw(4) << "(" << setw(6) << fReqNbOfEvts << ")";
01372             }
01373           else
01374             {
01375               fFcout_f  << setw(13) << value;
01376             }
01377 
01378           fFcout_f  << endl;
01379         }
01380     } // end of loop:  for (Int_t i0StexEcha=0; i0StexEcha<HisSize; i0StexEcha++)
01381 
01382   fFcout_f.close();
01383   
01384   // if(fFlagPrint != fCodePrintNoComment)
01385   // {
01386       cout << "*TEcnaWrite::WriteAsciiHisto(...)> INFO: "
01387            << "histo has been written in file: " << endl
01388            << "            " << fAsciiFileName.Data() << endl;
01389       // }
01390 } // end of TEcnaWrite::WriteAsciiHisto
01391 
01392 //================================================================================
01393 //
01394 //        W R I T I N G  O F  T H E   C O V   A N D   C O R  M A T R I C E S 
01395 //
01396 //================================================================================
01397 
01398 //--------------------------------------------------------------------------------
01399 //
01400 //      Writing of the covariances between samples
01401 //      for a given StexEcha in an ASCII file
01402 //
01403 //--------------------------------------------------------------------------------
01404 void TEcnaWrite::WriteAsciiCovariancesBetweenSamples(const Int_t& user_StexStin,
01405                                                     const Int_t& user_StinEcha,
01406                                                     const Int_t& MatSize,
01407                                                     const TMatrixD& read_matrix)
01408 {
01409 //Writing of the covariances between samples for a given StexEcha in an ASCII file
01410 
01411   if( fFlagSubDet == "EB" ){fStexStinUser = user_StexStin;}
01412   if( fFlagSubDet == "EE" ){fStexStinUser =
01413                               fEcalNumbering->GetDeeSCConsFrom1DeeSCEcna(fStexNumber, user_StexStin);}
01414 
01415   if( fFlagSubDet == "EB" ){fStinEchaUser = user_StinEcha;}
01416   if( fFlagSubDet == "EE" ){fStinEchaUser = user_StinEcha+1;}
01417 
01418   Int_t i_code = fCodeCovCss;  // code for covariances between samples
01419   fMakeResultsFileName(i_code);  
01420   fAsciiFileWriteHeader(i_code);
01421 
01422   Int_t i_pasx = fSectSampSizeX;
01423   Int_t i_pasy = fSectSampSizeY;
01424 
01425   fT2dWriteAscii(i_code, i_pasx, i_pasy, MatSize, read_matrix);
01426 }
01427 
01428 //---------------------------------------------------------------------------------
01429 //
01430 //   Writing of the correlations between samples
01431 //   for a given StexEcha in an ASCII file
01432 //
01433 //---------------------------------------------------------------------------------
01434 void TEcnaWrite::WriteAsciiCorrelationsBetweenSamples(const Int_t& user_StexStin,
01435                                                      const Int_t& user_StinEcha,
01436                                                      const Int_t& MatSize,
01437                                                      const TMatrixD& read_matrix)
01438 {
01439 //Writing of the correlations between samples for a given StexEcha in an ASCII file
01440 
01441 
01442   if( fFlagSubDet == "EB" ){fStexStinUser = user_StexStin;}
01443   if( fFlagSubDet == "EE" ){fStexStinUser =
01444                               fEcalNumbering->GetDeeSCConsFrom1DeeSCEcna(fStexNumber, user_StexStin);}
01445 
01446   if( fFlagSubDet == "EB" ){fStinEchaUser = user_StinEcha;}
01447   if( fFlagSubDet == "EE" ){fStinEchaUser = user_StinEcha+1;}
01448 
01449   Int_t i_code = fCodeCorCss; // code for correlations between samples
01450   fMakeResultsFileName(i_code); 
01451   fAsciiFileWriteHeader(i_code);
01452 
01453   Int_t i_pasx = fSectSampSizeX;
01454   Int_t i_pasy = fSectSampSizeY;
01455 
01456   fT2dWriteAscii(i_code, i_pasx, i_pasy, MatSize, read_matrix);
01457 }
01458 
01459 //----------------------------------------------------------------------
01460 //
01461 //            fT2dWriteAscii: Array 2D of (n_sctx , n_scty) sectors
01462 //                            of size: i_pasx_arg * i_pasy_arg 
01463 //
01464 //                       (private)
01465 //
01466 //----------------------------------------------------------------------
01467 
01468 void  TEcnaWrite::fT2dWriteAscii(const Int_t&    i_code,
01469                                 const Int_t&    i_pasx_arg,
01470                                 const Int_t&    i_pasy_arg,
01471                                 const Int_t&    MatSize,
01472                                 const TMatrixD& read_matrix)
01473 {
01474 //Writing of a matrix by sectors (private)
01475 
01476   Int_t i_pasx = i_pasx_arg;           // taille secteur en x
01477   Int_t i_pasy = i_pasy_arg;           // taille secteur en y
01478   
01479   //------------ formatage des nombres en faisant appel a la classe ios
01480   
01481   fFcout_f << setiosflags(ios::showpoint | ios::uppercase);
01482   fFcout_f.setf(ios::dec, ios::basefield);
01483   fFcout_f.setf(ios::fixed, ios::floatfield);
01484   fFcout_f.setf(ios::left, ios::adjustfield);
01485   fFcout_f.setf(ios::right, ios::adjustfield);
01486   fFcout_f << setprecision(3) << setw(6);
01487   
01488   cout << setiosflags(ios::showpoint | ios::uppercase);
01489   cout.setf(ios::dec, ios::basefield);
01490   cout.setf(ios::fixed, ios::floatfield);
01491   cout.setf(ios::left, ios::adjustfield);
01492   cout.setf(ios::right, ios::adjustfield);
01493   cout << setprecision(3) << setw(6);  
01494 
01495   //--------------------- fin du formatage standard C++ -------------------
01496 
01497   //-----------------------------------------------------------------------
01498   //  Reservation dynamique d'un array Double_t** de dimensions
01499   //  les multiples de 5 juste au-dessus des dimensions de l'array 2D
01500   //  a ecrire ( array de dimensions
01501   //  (fEcal->MaxSampADC(),fEcal->MaxSampADC())
01502   //  (fEcal->MaxCrysEcnaInStex(),fEcal->MaxCrysEcnaInStex()) )
01503   //-----------------------------------------------------------------------
01504   // Determination des tailles multiples de fSectChanSizeX ou fSectSampSizeX
01505 
01506 #define NOUC
01507 #ifndef NOUC
01508 
01509   //*************** channels *************
01510   Int_t justap_chan = 0;
01511   
01512   if( fEcal->MaxCrysEcnaInStex()%fSectChanSizeX == 0 )
01513     {justap_chan = fEcal->MaxCrysEcnaInStex();}
01514   else
01515     {justap_chan=((fEcal->MaxCrysEcnaInStex()/fSectChanSizeX)+1)*fSectChanSizeX;}
01516   
01517   //....................... Allocation fjustap_2d_cc
01518 
01519   if ( i_code == fCodeHfCov || i_code == fCodeHfCor||
01520        i_code == fCodeLfCov || i_code == fCodeLfCor ){
01521     if(fjustap_2d_cc == 0)
01522       {
01523         //................... Allocation
01524         fjustap_2d_cc = new Double_t*[justap_chan];              fCnew++;  
01525         fjustap_1d_cc = new  Double_t[justap_chan*justap_chan];  fCnew++;  
01526         for(Int_t i = 0 ; i < justap_chan ; i++){
01527           fjustap_2d_cc[i] = &fjustap_1d_cc[0] + i*justap_chan;}
01528       }
01529 
01530      //............................... Transfert des valeurs dans fjustap_2d_cc  (=init)
01531     for(Int_t i = 0; i < fEcal->MaxCrysEcnaInStex(); i++){
01532       for(Int_t j = 0; j < fEcal->MaxCrysEcnaInStex(); j++){
01533         if ( i_code == fCodeHfCov ){
01534           fjustap_2d_cc[i][j] = read_matrix(i,j);}
01535         if ( i_code == fCodeHfCor ){
01536           fjustap_2d_cc[i][j] = read_matrix(i,j);}
01537         if ( i_code == fCodeLfCov ){
01538           fjustap_2d_cc[i][j] = read_matrix(i,j);}
01539         if ( i_code == fCodeLfCor ){
01540           fjustap_2d_cc[i][j] = read_matrix(i,j);}
01541       }
01542     }
01543 
01544     //.......................... mise a zero du reste de la matrice (=init)
01545     for(Int_t i = fEcal->MaxCrysEcnaInStex(); i < justap_chan; i++){
01546       for(Int_t j = fEcal->MaxCrysEcnaInStex(); j < justap_chan; j++){
01547         fjustap_2d_cc[i][j] = (Double_t)0.;}}
01548   }
01549 
01550 #endif //NOUC
01551 
01552   //************************************ Samples ***************************
01553   Int_t justap_samp = 0;
01554   
01555   if ( fEcal->MaxSampADC()%fSectSampSizeX == 0 ){
01556     justap_samp = fEcal->MaxSampADC();}
01557   else{
01558     justap_samp=((fEcal->MaxSampADC()/fSectSampSizeX)+1)*fSectSampSizeX;}
01559 
01560   //....................... allocation fjustap_2d_ss
01561 
01562   if (i_code == fCodeCovCss      || i_code == fCodeCorCss ||
01563       i_code == fCodeAvMeanCorss || i_code == fCodeAvSigCorss){
01564     if(fjustap_2d_ss == 0)
01565       {
01566         //................... Allocation
01567         fjustap_2d_ss = new Double_t*[justap_samp];              fCnew++;  
01568         fjustap_1d_ss = new  Double_t[justap_samp*justap_samp];  fCnew++;  
01569         for(Int_t i = 0 ; i < justap_samp ; i++){
01570           fjustap_2d_ss[i] = &fjustap_1d_ss[0] + i*justap_samp;}
01571       }
01572 
01573   //.............................. Transfert des valeurs dans fjustap_2d_ss (=init)
01574   for(Int_t i = 0; i < fEcal->MaxSampADC(); i++){
01575     for(Int_t j = 0; j < fEcal->MaxSampADC(); j++){
01576       if( i_code == fCodeCovCss ){
01577         fjustap_2d_ss[i][j] = read_matrix(i,j);}
01578       if( i_code == fCodeCorCss ){
01579         fjustap_2d_ss[i][j] = read_matrix(i,j);}
01580       if( i_code == fCodeAvMeanCorss ){
01581         fjustap_2d_ss[i][j] = read_matrix(i,j);}
01582       if( i_code == fCodeAvSigCorss ){
01583         fjustap_2d_ss[i][j] = read_matrix(i,j);}
01584     }
01585   }
01586 
01587   //.......................... mise a zero du reste de la matrice (=init)
01588   for(Int_t i = fEcal->MaxSampADC(); i < justap_samp; i++){
01589     for(Int_t j = fEcal->MaxSampADC(); j < justap_samp; j++){
01590       fjustap_2d_ss[i][j] = (Double_t)0.;}}
01591   }
01592 
01593   //..................... impressions + initialisations selon i_code
01594   
01595   Int_t isx_max = 0;    
01596   Int_t isy_max = 0;
01597 
01598 #define COCC
01599 #ifndef COCC
01600   if(i_code == fCodeHfCov)
01601     {
01602       fFcout_f << "Covariance matrix between channels "
01603                << "for sample number " << fUserSamp;
01604       isx_max = justap_chan;
01605       isy_max = justap_chan;
01606     }
01607   if(i_code == fCodeHfCor)
01608     {
01609       fFcout_f << "*Correlation matrix between channels "
01610                << "for sample number " << fUserSamp;
01611       isx_max = justap_chan;
01612       isy_max = justap_chan;
01613     }
01614   
01615   if(i_code == fCodeLfCov)
01616     {
01617       fFcout_f << "Covariance matrix between channels "
01618                << "averaged on the samples ";
01619       isx_max = justap_chan;
01620       isy_max = justap_chan;
01621     }
01622   if(i_code == fCodeLfCor)
01623     {
01624       fFcout_f << "Correlation matrix between channels "
01625                << "averaged on the samples ";
01626       isx_max = justap_chan;
01627       isy_max = justap_chan;
01628     }
01629 #endif // COCC
01630 
01631   Int_t n1StexStin = 0; 
01632   Int_t i0StinEcha = 0;
01633   Int_t n1StinEcha = 0;
01634   
01635   if( fFlagSubDet == "EB")
01636     {
01637       n1StexStin = fStexStinUser;
01638       i0StinEcha = fEcalNumbering->Get0TowEchaFrom0SMEcha(fStinEchaUser);
01639     }
01640   if( fFlagSubDet == "EE")
01641     {
01642       n1StexStin = fStexStinUser;
01643       Int_t fStinEchaUser_m = fStinEchaUser-1;
01644       n1StinEcha = fEcalNumbering->Get1SCEchaFrom0DeeEcha(fStinEchaUser_m);
01645       
01646       TString sDeeDir = fEcalNumbering->GetDeeDirViewedFromIP(fStexNumber);
01647     }
01648   
01649   if(i_code == fCodeCovCss)
01650     {
01651       if( fFlagSubDet == "EB")
01652         {
01653           fFcout_f << "Covariance matrix between samples "
01654                    << "for channel number " << fStinEchaUser
01655                    << " (" << fStinName << ": " << n1StexStin
01656                    << " , channel in " << fStinName << ": " << i0StinEcha << ")";
01657         }
01658       if( fFlagSubDet == "EE")
01659         {
01660           fFcout_f << "Covariance matrix between samples "
01661                    << "for channel number " << fStinEchaUser
01662                    << " (" << fStinName << ": " << n1StexStin
01663                    << " , channel in " << fStinName << ": " << n1StinEcha << ")";
01664         }
01665       isx_max = justap_samp;
01666       isy_max = justap_samp;
01667     }
01668   if(i_code == fCodeCorCss)
01669     {
01670       if( fFlagSubDet == "EB")
01671         {
01672           fFcout_f << "Correlation matrix between samples "
01673                    << "for channel number " << fStinEchaUser
01674                    << " (" << fStinName << ": " << n1StexStin
01675                    << " , channel in " << fStinName << ": " << i0StinEcha << ")"; 
01676         }
01677       if( fFlagSubDet == "EE")
01678         {
01679           fFcout_f << "Correlation matrix between samples "
01680                    << "for channel number " << fStinEchaUser
01681                    << " (" << fStinName << ": " << n1StexStin
01682                    << " , channel in " << fStinName << ": " << n1StinEcha << ")"; 
01683         }
01684       isx_max = justap_samp;
01685       isy_max = justap_samp;
01686     }
01687  
01688   if(i_code == fCodeAvMeanCorss)
01689     {
01690       if( fFlagSubDet == "EB")
01691         {
01692           fFcout_f << "Correction factors to the covariances "
01693                    << "between samples for channel number " << fStinEchaUser
01694                    << " (" << fStinName << ": " << n1StexStin
01695                    << " , channel in " << fStinName << ": " << i0StinEcha << ")";
01696         }
01697       if( fFlagSubDet == "EE")
01698         {
01699           fFcout_f << "Correction factors to the covariances "
01700                    << "between samples for channel number " << fStinEchaUser
01701                    << " (" << fStinName << ": " << n1StexStin
01702                    << " , channel in " << fStinName << ": " << n1StinEcha << ")";
01703         }
01704       isx_max = justap_samp;
01705       isy_max = justap_samp;
01706     }
01707   
01708   if(i_code == fCodeAvSigCorss)
01709     {
01710       if( fFlagSubDet == "EB")
01711         {
01712           fFcout_f << "Correction factors to the correlations "
01713                    << "between samples for channel number " << fStinEchaUser
01714                    << " ( " << fStinName << ": " << n1StexStin
01715                    << " , channel in " << fStinName << ": " << i0StinEcha << ")";
01716         }
01717       if( fFlagSubDet == "EE")
01718         {
01719           fFcout_f << "Correction factors to the correlations "
01720                    << "between samples for channel number " << fStinEchaUser
01721                    << " ( " << fStinName << ": " << n1StexStin
01722                    << " , channel in " << fStinName << ": " << n1StinEcha << ")";
01723         }
01724       isx_max = justap_samp;
01725       isy_max = justap_samp;
01726     }
01727   
01728   fFcout_f << endl;
01729 
01730   //............... Calcul des nombres de secteurs selon x
01731   //                i_pasx  = taille secteur en x 
01732   //                isx_max = taille de la matrice en x
01733   //                n_sctx  = nombre de secteurs en x
01734   //
01735   if(i_pasx > isx_max){i_pasx = isx_max;}  
01736   Int_t n_sctx;
01737   Int_t max_verix; 
01738   n_sctx = isx_max/i_pasx;
01739   max_verix = n_sctx*i_pasx; 
01740   if(max_verix < isx_max){ n_sctx++;}
01741 
01742   //............... Calcul des nombres de secteurs selon y
01743   //                i_pasy  = taille secteur en y
01744   //                isy_max = taille de la matrice en y
01745   //                n_scty  = nombre de secteurs en x
01746   //
01747   if(i_pasy > isy_max){i_pasy = isy_max;} 
01748   Int_t n_scty;
01749   Int_t max_veriy; 
01750   n_scty = isy_max/i_pasy;
01751   max_veriy = n_scty*i_pasy; 
01752   if(max_veriy < isy_max){ n_scty++;}
01753 
01754 #define NBSC
01755 #ifndef NBSC
01756   //................ Ecriture de la taille et du nombre des secteurs
01757   if( i_code == fCodeCovCss      || i_code == fCodeCorCss ||
01758       i_code == fCodeAvMeanCorss || i_code == fCodeAvSigCorss)
01759     {
01760       fFcout_f << "sector size = " << fSectSampSizeX 
01761                << " , number of sectors = " << n_sctx << " x " << n_scty
01762                <<endl;
01763     }
01764  if( i_code == fCodeHfCov || i_code == fCodeHfCor ||
01765      i_code == fCodeLfCov || i_code == fCodeLfCor )
01766     {
01767       fFcout_f << "sector size = " << fSectChanSizeX 
01768                << " , number of sectors = " << n_sctx << " x " << n_scty
01769                << endl;
01770     }
01771 #endif // NBSC
01772 
01773   fFcout_f << endl;
01774 
01775   //............... impression matrice par secteurs i_pas x i_pas  
01776   //........................... boucles pour display des secteurs 
01777   Int_t   ix_inf = -i_pasx;
01778   
01779   for(Int_t nsx = 0 ; nsx < n_sctx ; nsx++)
01780     { 
01781       //......................... calcul limites secteur
01782       ix_inf = ix_inf + i_pasx;
01783       Int_t   ix_sup = ix_inf + i_pasx; 
01784       
01785       Int_t   iy_inf = -i_pasy;
01786       
01787       for(Int_t nsy = 0 ; nsy < n_scty ; nsy++)
01788         {       
01789           iy_inf = iy_inf + i_pasy;          
01790           Int_t   iy_sup = iy_inf + i_pasy;
01791           
01792           //......................... display du secteur (nsx,nsy)
01793           
01794           if(i_code == fCodeHfCov || i_code == fCodeCovCss ||
01795              i_code == fCodeAvMeanCorss || i_code == fCodeAvSigCorss )
01796             {fFcout_f << "        ";}
01797           if(i_code == fCodeHfCor || i_code == fCodeCorCss)
01798             {fFcout_f << "      ";}
01799           
01800           for (Int_t iy_c = iy_inf ; iy_c < iy_sup ; iy_c++)
01801             {
01802               if(i_code == fCodeHfCov || i_code == fCodeLfCov || i_code == fCodeCovCss ||
01803                  i_code == fCodeAvMeanCorss ||
01804                  i_code == fCodeAvSigCorss)
01805                 {fFcout_f.width(8);}
01806               if(i_code == fCodeHfCor || i_code == fCodeLfCor || i_code == fCodeCorCss)
01807                 {fFcout_f.width(6);}
01808               fFcout_f << iy_c << "  ";
01809             }     
01810           fFcout_f << endl << endl;
01811           
01812           for (Int_t ix_c = ix_inf ; ix_c < ix_sup ; ix_c++)
01813             { 
01814               if(i_code == fCodeHfCov|| i_code == fCodeLfCov || i_code == fCodeCovCss ||
01815                  i_code == fCodeAvMeanCorss ||
01816                  i_code == fCodeAvSigCorss)
01817                 {fFcout_f.width(8);}
01818               if(i_code == fCodeHfCor || i_code == fCodeLfCor || i_code == fCodeCorCss)
01819                 {fFcout_f.width(6);}
01820               fFcout_f << ix_c << "   ";
01821               
01822               for (Int_t iy_c = iy_inf ; iy_c < iy_sup ; iy_c++)
01823                 {
01824                   if(i_code == fCodeHfCov  ||
01825                      i_code == fCodeLfCov  ||
01826                      i_code == fCodeCovCss ||
01827                      i_code == fCodeAvMeanCorss || 
01828                      i_code == fCodeAvSigCorss ){
01829                     fFcout_f.width(8);}
01830 
01831                   if(i_code == fCodeHfCor || i_code == fCodeLfCor ||  i_code == fCodeCorCss){
01832                     fFcout_f.width(6);}
01833                   
01834                   if( i_code == fCodeHfCov ||  i_code == fCodeLfCov || i_code == fCodeHfCor){
01835                     fFcout_f << fjustap_2d_cc[ix_c][iy_c] << "  ";}
01836                   
01837                   if ( i_code == fCodeCovCss ||
01838                        i_code == fCodeCorCss ||
01839                        i_code == fCodeAvMeanCorss ||
01840                        i_code == fCodeAvSigCorss )
01841                     {
01842                       fFcout_f << fjustap_2d_ss[ix_c][iy_c] << "  ";
01843                     }
01844                 }
01845               fFcout_f << endl;
01846             }
01847           fFcout_f << endl;
01848         }
01849     }
01850 
01851   //........... closing of the results file
01852   
01853   fFcout_f.close();
01854   
01855   if(fFlagPrint != fCodePrintNoComment)
01856     {
01857       cout << "*TEcnaWrite::fT2dWriteAscii(....)> INFO: "
01858            << "matrix has been written in file: " << endl
01859            << "            " << fAsciiFileName.Data() << endl;
01860     }
01861   
01862 }// end of TEcnaWrite::fT2dWriteAscii
01863 
01864 
01865 //=========================================================================
01866 //
01867 //   ci-dessous: ===> methodes a implementer plus tard?
01868 //
01869 //=========================================================================
01870 #define WASC
01871 #ifndef WASC
01872 //------------------------------------------------------------
01873 //
01874 //      Writing of the expectation values in an ASCII file
01875 //
01876 //------------------------------------------------------------
01877 
01878 void TEcnaWrite::WriteAsciiSampleMeans()
01879 {
01880 //Writing of the expectation values in an ASCII file
01881   
01882   Int_t i_code = fCodeMSp;
01883   fMakeResultsFileName(i_code);
01884   fAsciiFileWriteHeader(i_code);
01885   
01886   Int_t i_lic1 = fNbChanByLine; 
01887   Int_t i_lic2 = fNbSampByLine;
01888   
01889   fT1dWriteAscii(i_code, i_lic1, i_lic2);
01890 }
01891 
01892 //-------------------------------------------------------
01893 //
01894 //      Writing of the sigmas in an ASCII file
01895 //
01896 //-------------------------------------------------------
01897 
01898 void TEcnaWrite::WriteAsciiSampleSigmas()
01899 {
01900 //Writing of the variances in an ASCII file
01901   
01902   Int_t i_code = fCodeVar;  // code for variance   
01903   fMakeResultsFileName(i_code);
01904   fAsciiFileWriteHeader(i_code);
01905   
01906   Int_t i_lic1 = fNbChanByLine;
01907   Int_t i_lic2 = fNbSampByLine;
01908   
01909   fT1dWriteAscii(i_code, i_lic1, i_lic2);
01910 }
01911 #endif // WASC