CMS 3D CMS Logo

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