00001 
00002 
00003 #include "TRPCProc.h"
00004 #include "TCBMBeamtimeEvent.h"
00005 #include "Riostream.h"
00006 #include "TGo4UserException.h"
00007 #include "TGo4MbsEvent.h"
00008 #include "roc/Message.h"
00009 #include "roc/Board.h"
00010 
00011 #include "TH1.h"
00012 #include "TH2.h"
00013 #include "TProfile.h"
00014 
00015 #include "TGo4Analysis.h"
00016 
00017 #include <algorithm>
00018 
00019 
00020 TRPCProc::TRPCProc(const char* name) :
00021 TCBMBeamtimeProc(name), 
00022 fRocInputEvent(0), 
00023 fCrateInputEvent(0),
00024 fTriglogInputEvent(0),
00025 fOutputEvent(0), 
00026 fBeamEvent(0),
00027 cleanTree(0)
00028 {
00029    TGo4Log::Info("**** TRPCProc: Create instance %s");
00030    
00031    fRocPar = (TRocParam*) GetParameter("RocPar");
00032    cout << "ROCPAR = " << fRocPar << endl;
00033 
00034    fRpcPar = (TRPCParam*) MakeParameter("RPCPar", "TRPCParam");
00035    cout << "RPCPAR = " << fRpcPar << endl;
00036 
00037    if (fRocPar->numRocs > 0) fNumRocs = (UInt_t) fRocPar->numRocs;
00038 
00039    for( UInt_t uChip = 0; uChip < 2*fRocPar->uNbFeets; uChip++ )
00040       FECHIP.push_back(TRpcRec());
00041    
00042    Int_t iNbBinsRate = 87 ;
00043    Double_t dBinsRates[87+ 1] = {  0.1,        1,                2,                3,            4,          5,        6,         7,         8,         9,
00044                                               10,               20,               30,           40,         50,       60,        70,        80,        90,
00045                                              100,              200,              300,          400,        500,      600,       700,       800,       900,
00046                                             1000,    1500,    2000,    2500,    3000,  3500,  4000, 4500, 5000,     6000,      7000,      8000,      9000,
00047                                            10000,   15000,   20000,   25000,   30000,        40000,      50000,    60000,     70000,     80000,     90000,
00048                                           100000,           200000,           300000,       400000,     500000,   600000,    700000,    800000,    900000,
00049                                          1000000,          2000000,          3000000,      4000000,    5000000,  6000000,   7000000,   8000000,   9000000,
00050                                         10000000,         20000000,         30000000,     40000000,   50000000, 60000000,  70000000,  80000000,  90000000,
00051                                        100000000,        200000000,        300000000,    400000000,  500000000,600000000, 700000000, 800000000, 900000000 };
00052    
00053    
00054    for( UInt_t uChip = 0; uChip < 2*fRocPar->uNbFeets; uChip++ )
00055    {
00056       
00057       
00058       
00059       (FECHIP[uChip].uEpochStart).resize(      fRocPar->uNbBuffers );
00060       (FECHIP[uChip].uCycleStart).resize(      fRocPar->uNbBuffers );
00061       for( UInt_t uBuffer = 0; uBuffer < fRocPar->uNbBuffers; uBuffer ++)
00062       {
00063          (FECHIP[uChip].uEpochStart)[uBuffer]     = 0;
00064          (FECHIP[uChip].uCycleStart)[uBuffer]     = 0;
00065       }
00066 
00067       TString sChipFolder = Form("Feet/Get4/Chip%u/",uChip);
00068       TString sChanFolder[NB_CHAN_GET4];
00069       for(Int_t iChan = 0; iChan < NB_CHAN_GET4; iChan++)
00070          sChanFolder[iChan] = Form("Channel%d/",NB_CHAN_GET4*uChip + iChan);
00071       
00072       
00073       if( 1 == fRpcPar->uHitBuildingEnable )
00074       {
00075          FECHIP[uChip].fGet4MessValidEpochs = MakeTH1( 'I', 
00076             sChipFolder + Form( "MessValidEpochs%d", uChip),
00077             Form( "Messages in Valid epochs (chips %d synched)", uChip ),
00078             501, -0.5, 500.5, "Mess Nb [1]", "Entries [1]" );
00079       }
00080       
00081       
00082       for(Int_t iChan = 0; iChan < NB_CHAN_GET4; iChan++)
00083       {
00084          Int_t iFullChan = NB_CHAN_GET4*uChip + iChan;
00085             
00086          
00087          FECHIP[uChip].dInstantRateOld[iChan]  = new Double_t[ fRpcPar->uNbHitMeanRate ];
00088          for( UInt_t hitIndex = 0; hitIndex<fRpcPar->uNbHitMeanRate; hitIndex++)
00089            FECHIP[uChip].dInstantRateOld[iChan][hitIndex]  = 0.0; 
00090          
00091          
00092          FECHIP[uChip].fGet4FineTimeLE[iChan]       = 0; 
00093          FECHIP[uChip].fGet4FineTimeTE[iChan]       = 0; 
00094          
00095          
00096 
00097 
00098 
00099 
00100 
00101          FECHIP[uChip].fGet4TOT[iChan]              = 0; 
00102 
00103          FECHIP[uChip].fGet4PulseSpacingClose[iChan]= 0; 
00104          FECHIP[uChip].fGet4PulseSpacingMid[iChan]  = 0; 
00105          FECHIP[uChip].fGet4PulseSpacingFar[iChan]  = 0; 
00106          FECHIP[uChip].fGet4InstantRate[iChan]      = 0; 
00107          FECHIP[uChip].fGet4LeSpacingClose[iChan]   = 0; 
00108          FECHIP[uChip].fGet4TeSpacingClose[iChan]   = 0; 
00109         
00110          FECHIP[uChip].fGet4RisEdgesNbEvol[iChan]   = 0; 
00111          FECHIP[uChip].fGet4FalEdgesNbEvol[iChan]   = 0; 
00112          FECHIP[uChip].fGet4HitsNbEvolution[iChan]  = 0; 
00113          
00114          FECHIP[uChip].fNbConsecutiveLE[iChan]      = 0; 
00115          FECHIP[uChip].fNbConsecutiveTE[iChan]      = 0; 
00116          
00117          if( 1 == fRpcPar->uHitBuildingEnable )
00118          {
00119             FECHIP[uChip].fGet4TOT[iChan] = MakeTH1( 'D', 
00120                "Feet/Channels/"+ sChanFolder[iChan] + Form("TimeOverThreshold%d",iFullChan),
00121                Form( "Time over Threshold of Channel %d", iFullChan ),
00122                (Int_t)(fRpcPar->fTotSize*10), 0, fRpcPar->fTotSize - 0.1, "ToT [ns]", "Entries [1]" );
00123 
00124             FECHIP[uChip].fGet4PulseSpacingClose[iChan] = MakeTH1( 'D', 
00125                "Feet/Channels/"+ sChanFolder[iChan] + Form("LeadingEdge/PulseSpacingClose%d", iFullChan),
00126                Form( "Pulse Spacing between Leading Edges of following Pulses Channel %d", iFullChan ), 
00127                1000, 0, 99.9, "Pulse Spacing [ns]", "Entries [1]" );
00128 
00129             FECHIP[uChip].fGet4LeSpacingClose[iChan] = MakeTH1( 'D',
00130                "Feet/Channels/"+ sChanFolder[iChan] + Form("LeadingEdge/LePulseSpacingClose%d", iFullChan),
00131                Form( "Pulse Spacing between following Leading Edges Channel %d", iFullChan ),
00132                1000, 0, 99.9, "Pulse Spacing [ns]", "Entries [1]" );
00133             FECHIP[uChip].fGet4TeSpacingClose[iChan] = MakeTH1( 'D',
00134                "Feet/Channels/"+ sChanFolder[iChan] + Form("TrailingEdge/TePulseSpacingClose%d", iFullChan),
00135                Form( "Pulse Spacing between following Trailing Edges Channel %d", iFullChan ),
00136                1000, 0, 99.9, "Pulse Spacing [ns]", "Entries [1]" );
00137                
00138             if( 1 == fRocPar->uDebugHistoOn )
00139             {
00140                FECHIP[uChip].fGet4PulseSpacingMid[iChan] = MakeTH1( 'D', 
00141                   "Feet/Channels/"+ sChanFolder[iChan] + Form("LeadingEdge/PulseSpacingMid%d", iFullChan),
00142                   Form( "Pulse Spacing between Leading Edges of following Pulses Channel %d",
00143                   iFullChan ), 
00144                   1000, 0, 99.9, "Pulse Spacing [us]", "Entries [1]" );
00145                FECHIP[uChip].fGet4PulseSpacingFar[iChan] = MakeTH1( 'D', 
00146                   "Feet/Channels/"+ sChanFolder[iChan] + Form("LeadingEdge/PulseSpacingFar%d", iFullChan),
00147                   Form( "Pulse Spacing between Leading Edges of following Pulses Channel %d",
00148                   iFullChan ), 
00149                   1000, 0, 99.9, "Pulse Spacing [s]", "Entries [1]" );
00150                
00151                FECHIP[uChip].fGet4FineTimeLE[iChan] = MakeTH1('I', 
00152                   "Feet/Channels/"+ sChanFolder[iChan] + Form("LeadingEdge/FineTimeL%d", iFullChan),
00153                   Form( "Nonlinearity Histogram of Channel %d Leading Edge",iFullChan), 
00154                   NB_BIN_GET4_FTS,-0.5, NB_BIN_GET4_FTS- 0.5, "Bin [1]","Entries [1]" );
00155 
00156                FECHIP[uChip].fGet4FineTimeTE[iChan] = MakeTH1('I', 
00157                   "Feet/Channels/"+ sChanFolder[iChan] + Form("TrailingEdge/FineTimeT%d", iFullChan),
00158                   Form( "Nonlinearity Histogram of Channel %d Trailing Edge",iFullChan), 
00159                   NB_BIN_GET4_FTS,-0.5, NB_BIN_GET4_FTS - 0.5, "Bin [1]","Entries [1]" );
00160 
00161                
00162                
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181                      
00182                FECHIP[uChip].fNbConsecutiveLE[iChan] = MakeTH1( 'I', 
00183                   "Feet/debug/"+ sChanFolder[iChan] + Form("ConsLE%d", iFullChan),
00184                   Form( "Nb of consecutive Leading edges in Valid epochs (chips %d synched)", uChip ),
00185                   15, 0.5, 15.5, "LE Nb [1]", "Entries [1]" );
00186                FECHIP[uChip].fNbConsecutiveTE[iChan] = MakeTH1( 'I', 
00187                   "Feet/debug/"+ sChanFolder[iChan] + Form("ConsTE%d", iFullChan),
00188                   Form( "Nb of consecutive Leading edges in Valid epochs (chips %d synched)", uChip ),
00189                   15, 0.5, 15.5, "TE Nb [1]", "Entries [1]" );
00190                FECHIP[uChip].fTestConsecutiveLE[iChan] = MakeTH2( 'D',
00191                   "Feet/debug/"+ sChanFolder[iChan] + Form("TestConsLE%d", iFullChan),
00192                   Form( "When consecutive Leading edges on chan %d: time distance between 1st one and last trailing edge",
00193                         iFullChan ),
00194                   257, -0.05, 12.85, 15, 0.5, 15.5, "Time difference [ns]", "LE Nb [1]", "Entries [1]" );
00195                FECHIP[uChip].fTestConsecutiveTE[iChan] = MakeTH2( 'D',
00196                   "Feet/debug/"+ sChanFolder[iChan] + Form("TestConsTE%d", iFullChan),
00197                   Form( "When consecutive Trailing edges on chan %d: time distance between 1st one and last leading edge",
00198                         iFullChan ),
00199                   257, -0.05, 12.85, 15, 0.5, 15.5, "Time difference [ns]", "TE Nb [1]", "Entries [1]" );
00200                FECHIP[uChip].fTest2ConsecutiveLE[iChan] = MakeTH2( 'I',
00201                   "Feet/debug/"+ sChanFolder[iChan] + Form("Test2ConsLE%d", iFullChan),
00202                   Form( "When consecutive Leading edges on chan %d: FTS 1st one and last trailing edge",
00203                         iFullChan ),
00204                   128, -0.5, 127.5, 128, -0.05, 127.5, "FTS [bin]", "FTS [bin]", "Entries [1]" );
00205                FECHIP[uChip].fTest2ConsecutiveTE[iChan] = MakeTH2( 'I',
00206                   "Feet/debug/"+ sChanFolder[iChan] + Form("Test2ConsTE%d", iFullChan),
00207                   Form( "When consecutive Trailing edges on chan %d: FTS 1st one and last leading edge",
00208                         iFullChan ),
00209                   128, -0.05, 127.5, 128, -0.05, 127.5, "FTS [bin]", "FTS [bin]", "Entries [1]" );
00210 
00211                FECHIP[uChip].fGet4FineTimeLE_First[iChan] = MakeTH1( 'I',
00212                      "Feet/Channels/"+ sChanFolder[iChan] + Form("LeadingEdge/FineTimeL%d_f", iFullChan),
00213                      Form( "Nonlinearity Histogram of Channel %d Leading Edge first hit in event",iFullChan),
00214                      NB_BIN_GET4_FTS,-0.5, NB_BIN_GET4_FTS- 0.5, "Bin [1]","Entries [1]" );
00215                FECHIP[uChip].fGet4FineTimeTE_First[iChan] = MakeTH1( 'I',
00216                      "Feet/Channels/"+ sChanFolder[iChan] + Form("TrailingEdge/FineTimeT%d_f", iFullChan),
00217                      Form( "Nonlinearity Histogram of Channel %d Trailing Edge first hit in event",iFullChan),
00218                      NB_BIN_GET4_FTS,-0.5, NB_BIN_GET4_FTS - 0.5, "Bin [1]","Entries [1]" );
00219                FECHIP[uChip].fGet4FineTimeLE_Second[iChan] = MakeTH1( 'I',
00220                      "Feet/Channels/"+ sChanFolder[iChan] + Form("LeadingEdge/FineTimeL%d_s", iFullChan),
00221                      Form( "Nonlinearity Histogram of Channel %d Leading Edge second hit in event",iFullChan),
00222                      NB_BIN_GET4_FTS,-0.5, NB_BIN_GET4_FTS- 0.5, "Bin [1]","Entries [1]" );
00223                FECHIP[uChip].fGet4FineTimeTE_Second[iChan] = MakeTH1( 'I',
00224                      "Feet/Channels/"+ sChanFolder[iChan] + Form("TrailingEdge/FineTimeT%d_s", iFullChan),
00225                      Form( "Nonlinearity Histogram of Channel %d Trailing Edge second hit in event",iFullChan),
00226                      NB_BIN_GET4_FTS,-0.5, NB_BIN_GET4_FTS - 0.5, "Bin [1]","Entries [1]" );
00227 
00228                FECHIP[uChip].fGet4RisEdgesNbEvol[iChan] = MakeTH1( 'I', 
00229                   "Feet/debug/"+ sChanFolder[iChan] + Form("RisingNbEvo%d", iFullChan),
00230                   Form( "Nb of rising  edges per s, channel %d ", iFullChan ),
00231                   10000, 0, 10000, "Time [s]", "Edges [1]" );
00232                FECHIP[uChip].fGet4FalEdgesNbEvol[iChan] = MakeTH1( 'I', 
00233                   "Feet/debug/"+ sChanFolder[iChan] + Form("FallingNbEvo%d", iFullChan),
00234                   Form( "Nb of falling edges per s, channel %d ", iFullChan ),
00235                   10000, 0, 10000, "Time [s]", "Edges [1]" );
00236             } 
00237          } 
00238          if( 1 == fRpcPar->uBlockOrderingEnable )
00239          {            
00240             
00241             
00242             FECHIP[uChip].fGet4InstantRate[iChan] =
00243                   (TH2*)GetHistogram("Feet/Channels/"+ sChanFolder[iChan] + Form("/Rate%d",iFullChan));
00244             if (FECHIP[uChip].fGet4InstantRate[iChan] == 0 )
00245             {
00246                FECHIP[uChip].fGet4InstantRate[iChan] = new TH2D( Form("Rate%d",iFullChan),
00247                     Form( "Instantaneous rate on channel %d, averaged over %d hits; Rate [Hz]; Cycle []", iFullChan,
00248                      fRpcPar->uNbHitMeanRate ), iNbBinsRate, &(dBinsRates[0]), 10, 0, 10 );
00249                AddHistogram(FECHIP[uChip].fGet4InstantRate[iChan], "Feet/Channels/"+ sChanFolder[iChan] );
00250             }
00251             
00252             if( 1 == fRocPar->uDebugHistoOn )
00253             {
00254                FECHIP[uChip].fGet4HitsNbEvolution[iChan] = MakeTH1( 'I', 
00255                   "Feet/debug/"+ sChanFolder[iChan] + Form("HitsNbEvo%d", iFullChan),
00256                   Form( "Nb of matched hits per s, channel %d ", iFullChan ),
00257                   10000, 0, 10000, "Time [s]", "Hits [1]" );
00258             } 
00259             
00260             
00261             Int_t iFullChanSec = 0;
00262             for(Int_t iChanSec = iChan + 1; iChanSec < NB_CHAN_GET4; iChanSec++)
00263             {
00264                iFullChanSec = NB_CHAN_GET4*uChip + iChanSec;
00265                
00266                FECHIP[uChip].fVGetTimeCorrelation.push_back(
00267                   MakeTH1( 'D', Form( "Feet/Correlations/Chan%dChan%d/TimeDifference%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00268                            Form( "Time Correlation Between Channel %d and Channel %d", iFullChan,iFullChanSec ), 
00269                            (Int_t)(4*fRpcPar->fCorrelationCheck), -1*fRpcPar->fCorrelationCheck, fRpcPar->fCorrelationCheck ,
00270                            "Time Difference [ns]", "Entries [1]" ) );
00271                if( 1 == fRpcPar->uCorrelationHistoOn )
00272                {               
00273                   FECHIP[uChip].fVGetTotCorrelation.push_back(
00274                      MakeTH2( 'D', Form( "Feet/Correlations/Chan%dChan%d/TotCorr%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00275                            Form( "Tot Correlation Between Channel %d and Channel %d", iFullChan,iFullChanSec ), 
00276                            200, 0, 50, 200, 0, 50,
00277                            "Tot 1 [ns]", "Tot 2 [ns]", "Entries [1]" ) );
00278                   FECHIP[uChip].fVCheckCorrelation.push_back(
00279                      MakeTH1( 'I', Form( "Feet/Correlations/Chan%dChan%d/Check%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00280                            Form( "Nb of 3 chan Correlation when ok between Chan %d & Chan %d?", iFullChan,iFullChanSec ), 
00281                            fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00282                            "Channel []", "Entries [1]" ) );
00283                   FECHIP[uChip].fVCheckCorrelation4.push_back(
00284                      MakeTH2( 'I',  Form( "Feet/Correlations/Chan%dChan%d/Check4ch%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00285                            Form( "Nb of 4 chan Correlation when ok between Chan %d & Chan %d?", iFullChan,iFullChanSec ), 
00286                            fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00287                            fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00288                            "Channel []", "Channel []", "Entries [1]" ) );
00289                } 
00290             } 
00291             
00292             for(Int_t iChipSec = uChip + 1; iChipSec < 2*(Int_t)fRocPar->uNbFeets; iChipSec++)
00293             {
00294                for(Int_t iChanSec = 0; iChanSec < NB_CHAN_GET4; iChanSec++)
00295                {
00296                   iFullChanSec = NB_CHAN_GET4*iChipSec + iChanSec;
00297                   FECHIP[uChip].fVGetTimeCorrelation.push_back(
00298                      MakeTH1( 'D', Form( "Feet/Correlations/Chan%dChan%d/TimeDifference%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00299                               Form( "Time Correlation Between Channel %d and Channel %d", iFullChan,iFullChanSec ), 
00300                               (Int_t)(4*fRpcPar->fCorrelationCheck), -1*fRpcPar->fCorrelationCheck, fRpcPar->fCorrelationCheck ,
00301                               "Time Difference [ns]", "Entries [1]" ) );
00302                   
00303                   if( 1 == fRpcPar->uTotCorrelationHistOn )
00304                   {
00305                      FECHIP[uChip].fVGetTotCorrelation.push_back(
00306                         MakeTH2( 'D', Form( "Feet/Correlations/Chan%dChan%d/TotCorr%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00307                               Form( "Tot Correlation Between Channel %d and Channel %d", iFullChan,iFullChanSec ), 
00308                               200, 0, 50, 200, 0, 50,
00309                               "Tot 1 [ns]", "Tot 2 [ns]", "Entries [1]" ) );
00310                   }
00311                   if( 1 == fRpcPar->uCorrelationHistoOn )
00312                   {               
00313                      FECHIP[uChip].fVCheckCorrelation.push_back(
00314                         MakeTH1( 'I', Form( "Feet/Correlations/Chan%dChan%d/Check%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00315                               Form( "Nb of 3 chan Correlation when ok between Chan %d & Chan %d?", iFullChan,iFullChanSec ), 
00316                               fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00317                               "Channel []", "Entries [1]" ) );
00318                      FECHIP[uChip].fVCheckCorrelation4.push_back(
00319                         MakeTH2( 'I',  Form( "Feet/Correlations/Chan%dChan%d/Check4ch%d%d", iFullChan,iFullChanSec, iFullChan,iFullChanSec ),
00320                               Form( "Nb of 4 chan Correlation when ok between Chan %d & Chan %d?", iFullChan,iFullChanSec ), 
00321                               fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00322                               fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00323                               "Channel []", "Channel []", "Entries [1]" ) );
00324                   } 
00325                } 
00326             }
00327          } 
00328       } 
00329    } 
00330       
00331    
00332    uNbEvents = 0;
00333    
00334    
00335      
00336    v_HitUnpBlock.resize( fRocPar->uNbBuffers );
00337    for( UInt_t uBuffer = 0; uBuffer < fRocPar->uNbBuffers; uBuffer ++)
00338       v_HitUnpBlock[uBuffer].clear();
00339    lastHit.ClearHit();
00340    uBlockIndexLast = 0;
00341    uBlockIndex = 0;
00342    
00343    uEpochLastBlock = 0;
00344    uLastEpochLastBlock = 0;
00345    uLastCycleLastBlock = 0;
00346 
00347    uLastEpochMainClock = 0;
00348    uMainEpochCycle     = 0;
00349    
00350    uEpochBufferStart = 0 ;
00351    uCycleBufferStart = 0 ;
00352    
00353    uCurrentBlockBuffer = 0;
00354       
00355    
00356    fGet4EdgeMessagePerEvent = MakeTH1('I', "Feet/GET4/EdgePerEvt", "Nb of accepted edge message per event",
00357                            2000, -0.5, 2000 -0.5, 
00358                            "Nb accepted edge message [1]","Nb Events [1]");
00359          
00360    if( 1 == fRpcPar->uHitBuildingEnable )
00361    {
00362       fGet4RisEdgesNb = MakeTH1('I', "Feet/Get4EdgesCount/RisingEdgesNb",
00363                                "Number of Rising edges per channel", 
00364                                fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00365                                "Channel [1]", "Entries [1]" );
00366       fGet4FalEdgesNb = MakeTH1('I', "Feet/Get4EdgesCount/FallingEdgesNb",
00367                                "Number of Falling edges per channel", 
00368                                fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00369                                "Channel [1]", "Entries [1]" );
00370       fGet4EdgesDiffEvol= MakeTH2('I', "Feet/Get4EdgesCount/EdgesDiffEvol",
00371                                "diff ( nb falling - nb rising ) for each cycle/channel", 
00372                                500, 0, 500, fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00373                                "Cycle []", "Chan []", "(Falling - Rising[1]" );
00374       fGet4RisEdgesEvol = MakeTH1('I', "Feet/Get4EdgesCount/RisingEdgesEvol",
00375                                "Number of Rising edges per s",
00376                                100000, 0, 100000, "s []", "Edges [1]" );
00377       fGet4FalEdgesEvol = MakeTH1('I', "Feet/Get4EdgesCount/FallingEdgesEvol",
00378                                "Number of Falling edges per s",
00379                                100000, 0, 100000, "s []", "Edges [1]" );
00380       fReconErrLE = MakeTH1( 'I', "Feet/Messages/ReconErrLE",
00381                             "Reconstruction Errors on Leading Edge", 
00382                             fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00383                             "Channel [1]", "Entries [1]" );
00384 
00385       fReconErrTE = MakeTH1( 'I', "Feet/Messages/ReconErrTE",
00386                             "Reconstruction Errors on Trailing Edge", 
00387                             fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00388                             "Channel [1]", "Entries [1]" );
00389 
00390       fReconErrNegToT = MakeTH1( 'I', "Feet/Messages/ReconErrNegToT",
00391                             "Reconstruction Errors with Negative ToT", 
00392                             fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00393                             "Channel [1]", "Entries [1]" );
00394 
00395       fReconErrTimeGate = MakeTH1( 'I', "Feet/Messages/ReconErrTimeGate",
00396                             "Reconstruction Errors with too big ToT", 
00397                             fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00398                             "Channel [1]", "Entries [1]" );
00399    }
00400    if( 1 == fRpcPar->uBlockOrderingEnable )
00401    { 
00402       fBeamProfileHDRPC = MakeTH2('D', "Feet/debug/BeamProfileHD",
00403                                "Attempt to get beam profile for HDRPC, Strip map in option file",
00404                                fRpcPar->iBeamProfileSize, -(fRpcPar->iBeamProfileSize/2.0) -0.5, (fRpcPar->iBeamProfileSize/2.0) -0.5,
00405                                fRpcPar->uNbStrips, -((Double_t)fRpcPar->uNbStrips/2.0), ((Double_t)fRpcPar->uNbStrips/2.0),
00406                                "Left right dt [cm]", "Strip index[cm]" ); 
00407 
00408       
00409       iIsPadChannelX = new Int_t[fRocPar->uNbFeets * 8];
00410       iIsPadChannelY = new Int_t[fRocPar->uNbFeets * 8];
00411       for(UInt_t uTempChan = 0; uTempChan < fRocPar->uNbFeets * 8; uTempChan++)
00412       {
00413          iIsPadChannelX[uTempChan] = -1;
00414          iIsPadChannelY[uTempChan] = -1;
00415       }
00416       for(UInt_t temp_Yindex = 0; temp_Yindex < fRpcPar->uNbPadsY; temp_Yindex++)
00417          for(UInt_t temp_Xindex = 0; temp_Xindex < fRpcPar->uNbPadsX; temp_Xindex++)
00418             if( fRpcPar->uPadsList[temp_Yindex][temp_Xindex] < fRocPar->uNbFeets * 8 )
00419             {
00420                iIsPadChannelX[ fRpcPar->uPadsList[temp_Yindex][temp_Xindex] ] = temp_Xindex;
00421                iIsPadChannelY[ fRpcPar->uPadsList[temp_Yindex][temp_Xindex] ] = temp_Yindex;
00422             }
00423       fBeamProfilePRPC  = MakeTH2('D', "Feet/debug/BeamProfilePrpc",
00424                                "Attempt to get beam profile for PRPC, Pad map in option file",
00425                                fRpcPar->uNbPadsX, -(fRpcPar->uNbPadsX/2.0), (fRpcPar->uNbPadsX/2.0),
00426                                fRpcPar->uNbPadsY, -((Double_t)fRpcPar->uNbPadsY/2.0), ((Double_t)fRpcPar->uNbPadsY/2.0),
00427                                "X [cm]", "Y [cm]" );
00428 
00429       fGet4HitsNb = MakeTH1('I', "Feet/Get4EdgesCount/HitsNb",
00430                                "Number of matched Hits per channel", 
00431                                fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00432                                "Channel [1]", "Entries [1]" );
00433       bHitInThisEvent = new Bool_t[fRocPar->uNbFeets * 8];
00434       for(UInt_t uTempChan = 0; uTempChan < fRocPar->uNbFeets * 8; uTempChan++)
00435          bHitInThisEvent[uTempChan] = kFALSE;
00436       fGet4EventsWithHitsNb = MakeTH1('I', "Feet/Get4EdgesCount/EventsWithHitsNb",
00437                                "Number of events with matched Hits per channel",
00438                                fRocPar->uNbFeets * 8, -0.5, fRocPar->uNbFeets * 8 - 0.5,
00439                                "Channel [1]", "Events [1]" );
00440 
00441       fGet4HitsEvol = MakeTH1('I', "Feet/Get4EdgesCount/HitsEvol",
00442                                "Number of matched Hits per s",
00443                                10000, 0, 10000, "Time [s]", "Hits [1]" );
00444       fMapOrderErrors= MakeTH2( 'I', "Feet/Messages/MapOrderErrors",
00445             "Map of channels in time order errors", 
00446             8*fRocPar->uNbFeets, -0.5, 8*fRocPar->uNbFeets-0.5, 8*fRocPar->uNbFeets, -0.5, 8*fRocPar->uNbFeets-0.5,
00447             "Chan1 []", "Chan2 []" );
00448       fMapOrderErrorsChips= MakeTH2( 'I', "Feet/Messages/MapOrderErrorsChips",
00449             "Map of chips in time order errors", 
00450             2*fRocPar->uNbFeets, -0.5, 2*fRocPar->uNbFeets-0.5, 2*fRocPar->uNbFeets, -0.5, 2*fRocPar->uNbFeets-0.5,
00451             "Chip1 []", "Chip2 []" );
00452                                
00453       if( 1 == fRocPar->uDebugHistoOn )
00454       {                          
00455          fGet4IncompletHitsEvol = MakeTH1('I', "Feet/Get4EdgesCount/IncompHitsEvol",
00456                                     "Number of incomplet Hits per s",
00457                                     10000, 0, 10000, "Time [s]", "Edges [1]" );
00458          fGet4BlocksEvol = MakeTH1('I', "Feet/Get4EdgesCount/BlocksEvol",
00459                                     "Number of blocks analysed per cycle", 
00460                                     500, 0, 500, "Cycle []", "Blocks [1]" );
00461       }
00462    }
00463 
00464 
00465 
00466       
00467    printf("RPC Histograms created \n");
00468    fflush ( stdout);
00469 }
00470 
00471 TRPCProc::~TRPCProc()
00472 {
00473    for( UInt_t uChip = 0; uChip < 2*fRocPar->uNbFeets; uChip++ )
00474           for(Int_t iChan = 0; iChan < NB_CHAN_GET4; iChan++)
00475           {
00476                   delete [] FECHIP[uChip].dInstantRateOld[iChan];
00477                   FECHIP[uChip].dInstantRateOld[iChan] = 0;
00478           }
00479    
00480    delete [] iIsPadChannelX;  iIsPadChannelX = 0;
00481    delete [] iIsPadChannelY;  iIsPadChannelY = 0;
00482 
00483    delete bHitInThisEvent;
00484 
00485    if( 1 == fRpcPar->uCleanOuputEnable || 1 == fRpcPar->uRootDisplay)
00486    {
00487        if( 1 == fRpcPar->uCleanOuputEnable )
00488        {
00489           cout<<oldDir->GetPath()<<endl;
00490           gDirectory->Cd(sOutputFilename);
00491           cout<<gDirectory->GetPath()<<endl;
00492 
00493           cleanTree->SetDirectory(gDirectory);
00494 
00495           fRootOut->Write("");
00496 
00497           fRootOut->Close();
00498 
00499           gDirectory->Cd(oldDir->GetPath());
00500           cout<<gDirectory->GetPath()<<endl;
00501        } 
00502        if( 1 == fRpcPar->uRootDisplay )
00503           TGo4Analysis::Instance()->RemoveTree(cleanTree);
00504 
00505        if( 0 == fRpcPar->uCleanOuputEnable )
00506           delete cleanTree;
00507 
00508        if( 1 == fRpcPar->uAddGet4DataInTree )
00509        {
00510           for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00511           {
00512              (*vuHitNumber)[uChannelTemp]  = 0;
00513              (*vuTime)[uChannelTemp].clear();
00514              (*vuEpochTime)[uChannelTemp].clear();
00515              (*viTot)[uChannelTemp].clear();
00516           }
00517 
00518           delete vuHitNumber;
00519           delete vuTime;
00520           delete vuEpochTime;
00521           delete viTot;
00522        } 
00523 
00524        if( 1 == fRpcPar->uCleanOuputEnable )
00525           delete fRootOut;
00526    }
00527 
00528    
00529    if( fBeamProfileHDRPC->GetEntries() )
00530    {
00531       Double_t offset = 0;
00532       TGo4Log::Info("********************************************************");
00533       for( UInt_t uBin = 0; uBin < fRpcPar->uNbStrips; uBin++)
00534       {
00535          offset = ( (TProfile*)fBeamProfileHDRPC->ProfileX(Form("_pfx%d", uBin), uBin+1, uBin+1) )->GetMean();
00536          TGo4Log::Info("Offset of HD strip %2u is %3.2f cm", uBin, offset);
00537       }
00538       TGo4Log::Info("********************************************************");
00539    }
00540 
00541    cout << "**** TRPCProc: Delete instance " << endl;
00542 }
00543 
00544 
00545 void TRPCProc::InitEvent(TGo4EventElement* outevnt)
00546 {
00547    
00548    
00549    
00550    if(fRocInputEvent==0)
00551    {
00552       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00553       if(btevent)
00554          {
00555             fRocInputEvent=dynamic_cast<TRocEvent*>(btevent->GetSubEvent("ROC"));
00556          }
00557       else
00558          {
00559             fRocInputEvent=dynamic_cast<TRocEvent*>(GetInputEvent());
00560 
00561          }
00562       if(fRocInputEvent==0) {
00563          GO4_STOP_ANALYSIS_MESSAGE("**** TRPCProc: Fatal error: input event is not a TRocEvent!!! STOP GO4");
00564          }
00565    }
00566 
00567    
00568    
00569    
00570    if( kFALSE == fRocPar->noTrigger && ( 1 == fRpcPar->uCleanOuputEnable || 1 == fRpcPar->uRootDisplay) )
00571    {
00572       if(fCrateInputEvent==0)
00573       {
00574          TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00575          if(btevent)
00576          {
00577             fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00578          }
00579          else
00580          {
00581             fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(GetInputEvent());
00582 
00583          }
00584          if(fCrateInputEvent==0) {
00585             GO4_STOP_ANALYSIS_MESSAGE("**** TRPCProc: Fatal error: input event is/has not a TMbsCrateEvent!!! STOP GO4");
00586          }
00587       } 
00588       if( 1 == fRpcPar->uTriglogInputInTree )
00589       {
00590          if(fTriglogInputEvent==0)
00591          {
00592             TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00593             if(btevent)
00594             {
00595                fTriglogInputEvent=dynamic_cast<TTriglogEvent*>(btevent->GetSubEvent("TRIGLOG"));
00596             }
00597             else
00598             {
00599                fTriglogInputEvent=dynamic_cast<TTriglogEvent*>(GetInputEvent());
00600 
00601             }
00602             if(fTriglogInputEvent==0) {
00603                GO4_STOP_ANALYSIS_MESSAGE("**** TRPCProc: Fatal error: input event is/has not a TTriglogEvent!!! STOP GO4");
00604             }
00605          } 
00606       } 
00607    } 
00608 
00609    
00610    
00611    
00612    if(fOutputEvent==0)
00613    {
00614       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00615       if(btevent)
00616       {
00617          fOutputEvent=dynamic_cast<TRPCEvent*>(btevent->GetSubEvent("RPC"));
00618          fBeamEvent=dynamic_cast<TBeamMonitorEvent*>(btevent->GetSubEvent("BEAM"));
00619       }
00620       else
00621       {
00622 
00623             fOutputEvent= dynamic_cast<TRPCEvent*>(outevnt);
00624       }
00625       if(fOutputEvent==0) {
00626       GO4_STOP_ANALYSIS_MESSAGE("**** TRPCProc: Fatal error: output event is not a TRPCEvent!!! STOP GO4");
00627       }
00628 
00629    }
00630 
00631    
00632    if( 1 == fRpcPar->uCleanOuputEnable || 1 == fRpcPar->uRootDisplay)
00633    {
00634       if( 0 == cleanTree)
00635       {
00636          TGo4Log::Info("**** TRPCProc: Create tree ");
00637 
00638          if( 1 == fRpcPar->uCleanOuputEnable )
00639          {
00640             oldDir = gDirectory;
00641 
00642             sOutputFilename = fRpcPar->sOutputFilename;
00643             fRootOut= new TFile(sOutputFilename, "RECREATE", "TTree file from GET4 and CAEN v1290", 9);
00644             sOutputFilename += ":/";
00645             if (fRootOut->IsZombie()) {
00646                cout << "Error opening file for TTree output in TRpcProc" << endl;
00647             }
00648 
00649             gDirectory->Cd(sOutputFilename);
00650          }
00651 
00652          if( 0 == TGo4Analysis::Instance()->GetTree( "CosyRpc" ) )
00653          {
00654             cleanTree = new TTree("CosyRpc", "RPC Caen and Get4");
00655             TGo4Log::Info("RPC Tree created in %s", gDirectory->GetPath());
00656          } 
00657             else
00658             {
00659                cleanTree = TGo4Analysis::Instance()->GetTree( "CosyRpc" );
00660                TGo4Log::Info("RPC Tree recovered from Go4");
00661             } 
00662 
00663          
00664          if( kFALSE == fRocPar->noTrigger )
00665          {
00666             if( -1 != fRpcPar->iPmtTdc && -1 != fRpcPar->iPmtQdc )
00667             {
00668                cleanTree->Branch("PmtTdc_Leading",  (fCrateInputEvent->fMtdc[fRpcPar->iPmtTdc]).lead,
00669                                  Form("PmtTdc_Leading[%u]/I", T1290Data::NumChan )  );
00670                cleanTree->Branch("PmtTdc_Trailing", (fCrateInputEvent->fMtdc[fRpcPar->iPmtTdc]).trail,
00671                                  Form("PmtTdc_Trailing[%u]/I", T1290Data::NumChan ) );
00672                cleanTree->Branch("PmtTdc_Leading_multi",  (fCrateInputEvent->fMtdc[fRpcPar->iPmtTdc]).lead_multi,
00673                                  Form("PmtTdc_Leading_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits )  );
00674                cleanTree->Branch("PmtTdc_Trailing_multi", (fCrateInputEvent->fMtdc[fRpcPar->iPmtTdc]).trail_multi,
00675                                  Form("PmtTdc_Trailing_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits ) );
00676                cleanTree->Branch("PmtQdc", fCrateInputEvent->fData1182[fRpcPar->iPmtQdc], Form("PmtQdc[%u]/s", NUM_1182_CH ) );
00677             } 
00678             if( -1 != fRpcPar->iRpcTdcLeading && -1 != fRpcPar->iRpcTdcTrailing )
00679             {
00680                cleanTree->Branch("CaenRpc_Leading",  (fCrateInputEvent->fMtdc[fRpcPar->iRpcTdcLeading]).lead,
00681                                  Form("CaenRpc_Leading[%u]/I", T1290Data::NumChan )  );
00682                cleanTree->Branch("CaenRpc_Trailing", (fCrateInputEvent->fMtdc[fRpcPar->iRpcTdcTrailing]).trail,
00683                                  Form("CaenRpc_Trailing[%u]/I", T1290Data::NumChan ) );
00684                cleanTree->Branch("CaenRpc_Leading_NbHit", (fCrateInputEvent->fMtdc[fRpcPar->iRpcTdcTrailing]).hit_lead,
00685                                     Form("CaenRpc_Leading_NbHit[%u]/I", T1290Data::NumChan ) );
00686                cleanTree->Branch("CaenRpc_Trailing_NbHit", (fCrateInputEvent->fMtdc[fRpcPar->iRpcTdcTrailing]).hit_trail,
00687                                  Form("CaenRpc_Trailing_NbHit[%u]/I", T1290Data::NumChan ) );
00688                cleanTree->Branch("CaenRpc_Leading_multi",  (fCrateInputEvent->fMtdc[fRpcPar->iRpcTdcLeading]).lead_multi,
00689                                  Form("CaenRpc_Leading_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits )  );
00690                cleanTree->Branch("CaenRpc_Trailing_multi", (fCrateInputEvent->fMtdc[fRpcPar->iRpcTdcTrailing]).trail_multi,
00691                                  Form("CaenRpc_Trailing_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits ) );
00692             } 
00693             if( -1 != fRpcPar->iReferenceTdc && -1 != fRpcPar->iReferenceChannel1 )
00694             {
00695                cleanTree->Branch("CaenRef1_Leading",
00696                                  &((fCrateInputEvent->fMtdc[fRpcPar->iReferenceTdc]).lead[fRpcPar->iReferenceChannel1]),
00697                                  "CaenRef1_Leading/I" );
00698                cleanTree->Branch("CaenRef1_Trailing",
00699                                  &((fCrateInputEvent->fMtdc[fRpcPar->iReferenceTdc]).trail[fRpcPar->iReferenceChannel1]),
00700                                  "CaenRef1_Trailing/I" );
00701             } 
00702             if( -1 != fRpcPar->iReferenceTdc && -1 != fRpcPar->iReferenceChannel2 )
00703             {
00704                cleanTree->Branch("CaenRef2_Leading",
00705                                  &((fCrateInputEvent->fMtdc[fRpcPar->iReferenceTdc]).lead[fRpcPar->iReferenceChannel2]),
00706                                  "CaenRef2_Leading/I" );
00707                cleanTree->Branch("CaenRef2_Trailing",
00708                                  &((fCrateInputEvent->fMtdc[fRpcPar->iReferenceTdc]).trail[fRpcPar->iReferenceChannel2]),
00709                                  "CaenRef2_Trailing/I" );
00710             } 
00711 
00712             if( 1 == fRpcPar->uTriglogInputInTree)
00713             {
00714                cleanTree->Branch("TriglogPattern",  &(fTriglogInputEvent->fVulomTriggerPattern),
00715                                  "TriglogPattern/i"  );
00716                cleanTree->Branch("TriglogScalers1",  (fTriglogInputEvent->fVulomScaler[0]),
00717                                  Form("TriglogScalers1[%u]/i", N_SCALERS_CH )  );
00718                cleanTree->Branch("TriglogScalers2",  (fTriglogInputEvent->fVulomScaler[1]),
00719                                  Form("TriglogScalers2[%u]/i", N_SCALERS_CH )  );
00720                cleanTree->Branch("TriglogScalers3",  (fTriglogInputEvent->fVulomScaler[2]),
00721                                  Form("TriglogScalers3[%u]/i", N_SCALERS_CH )  );
00722             }
00723          } 
00724 
00725          if( 1 == fRpcPar->uAddGet4DataInTree )
00726          {
00727             
00728             vuHitNumber = new std::vector< UInt_t >;
00729             vuHitNumber->resize( fRocPar->uNbFeets*8 );
00730 
00731             vuTime      = new std::vector< std::vector< UInt_t > >;
00732             vuEpochTime = new std::vector< std::vector< UInt_t > >;
00733             viTot       = new std::vector< std::vector<  Int_t > >;
00734 
00735             vuTime->resize(      fRocPar->uNbFeets*8 );
00736             vuEpochTime->resize( fRocPar->uNbFeets*8 );
00737             viTot->resize(       fRocPar->uNbFeets*8 );
00738 
00739             for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00740             {
00741                (*vuHitNumber)[uChannelTemp]  = 0;
00742                (*vuTime)[uChannelTemp].clear();
00743                (*vuEpochTime)[uChannelTemp].clear();
00744                (*viTot)[uChannelTemp].clear();
00745             }
00746 
00747             cleanTree->Bronch( "vuHitNumber",     "std::vector< UInt_t >",   &vuHitNumber );
00748             cleanTree->Bronch( "get4_time",       "std::vector< std::vector< UInt_t > >", &(vuTime) );
00749             cleanTree->Bronch( "get4_epoch_time", "std::vector< std::vector< UInt_t > >", &(vuEpochTime) );
00750             cleanTree->Bronch( "get4_tot",        "std::vector< std::vector<  Int_t > >", &(viTot) );
00751          }
00752 
00753          cleanTree->SetDirectory(gDirectory);
00754 
00755          if( 1 == fRpcPar->uRootDisplay && 0 == TGo4Analysis::Instance()->GetTree( "CosyRpc" ))
00756          {
00757             TGo4Analysis::Instance()->AddTree(cleanTree );
00758             TGo4Log::Info("RPC Tree registered in Go4: %p", TGo4Analysis::Instance()->GetTree( "CosyRpc" ) );
00759          }
00760       } 
00761    } 
00762 }
00763 
00764 
00765 void TRPCProc::FinalizeEvent()
00766 {
00767         if(!fRocInputEvent->IsValid())
00768    {
00769            
00770            if( ( 1 == fRpcPar->uCleanOuputEnable || 1 == fRpcPar->uRootDisplay) )
00771               if( fCrateInputEvent->IsValid() && fTriglogInputEvent->IsValid() )
00772          {
00773             cleanTree->Fill();
00774          }
00775            return; 
00776    }
00777 
00778 
00779   
00780   if( 0 == dynamic_cast<TGo4MbsEvent*>(fRocInputEvent) )
00781       fMbsEventNumber = fRocInputEvent->fMbsEventNumber;
00782   if(uNbEvents == 0)
00783   {
00784     uFirstEventIndex = fMbsEventNumber;
00785     uPrevEventIndex  = fMbsEventNumber;
00786     
00787    for ( UInt_t uChip = 0; uChip < fRocPar->uNbFeets * 2; uChip++ )
00788       FECHIP[uChip].bFirstEpochBlock = kTRUE;
00789   }
00790    else
00791    {
00792       if( 0 < fRocPar->iEventNbGap &&
00793           (Int_t)uPrevEventIndex + fRocPar->iEventNbGap != fMbsEventNumber )
00794          Message(0, "***** TRPCProc Missing event in file: Event %d, Previous event index %d, Current event Index %d, expected %d",
00795                uNbEvents, uPrevEventIndex, GetEventNumber(), (Int_t)uPrevEventIndex + fRocPar->iEventNbGap);
00796       uPrevEventIndex  = fMbsEventNumber;
00797    }
00798 
00799         
00800    Bool_t bTestAllValid = kTRUE;
00801    for(UInt_t uTempChan = 0; uTempChan < fRocPar->uNbFeets * 8; uTempChan++)
00802       bHitInThisEvent[uTempChan] = kFALSE;
00803 
00804         for(Int_t iFeetRoc=0; iFeetRoc < (Int_t)fRocPar->uNbRocsGet4; iFeetRoc ++)
00805         {
00806       
00807       Int_t iFeetRocId= fRocPar->uFeetRocsMapping[iFeetRoc];
00808       TRocData* theRoc=dynamic_cast<TRocData*>(fRocInputEvent->getEventElement(iFeetRocId));
00809       if(theRoc==0) continue;
00810       
00811       if( kFALSE == BuildHits( theRoc ) )
00812       {
00813          bTestAllValid = kFALSE;
00814 
00815          if( (1 == fRpcPar->uCleanOuputEnable || 1 == fRpcPar->uRootDisplay) && 1 == fRpcPar->uAddGet4DataInTree )
00816          {
00817             for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00818             {
00819                (*vuHitNumber)[uChannelTemp]  = 0;
00820                (*vuTime)[uChannelTemp].clear();
00821                (*vuEpochTime)[uChannelTemp].clear();
00822                (*viTot)[uChannelTemp].clear();
00823             } 
00824          } 
00825       } 
00826    } 
00827 
00828    for(UInt_t uTempChan = 0; uTempChan < fRocPar->uNbFeets * 8; uTempChan++)
00829       if( kTRUE == bHitInThisEvent[uTempChan])
00830          fGet4EventsWithHitsNb->Fill(uTempChan);
00831 
00832    uNbEvents++;
00833 
00834    
00835    if( ( 1 == fRpcPar->uCleanOuputEnable || 1 == fRpcPar->uRootDisplay) )
00836    {
00837       cleanTree->Fill();
00838       if( 1 == fRpcPar->uAddGet4DataInTree )
00839       {
00840          for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00841          {
00842             (*vuHitNumber)[uChannelTemp]  = 0;
00843             (*vuTime)[uChannelTemp].clear();
00844             (*vuEpochTime)[uChannelTemp].clear();
00845             (*viTot)[uChannelTemp].clear();
00846          } 
00847       } 
00848    } 
00849 
00850    if( kTRUE == bTestAllValid)
00851       fOutputEvent->SetValid(kTRUE);
00852       else fOutputEvent->SetValid(kFALSE);
00853 }
00854 
00855 
00856 
00857 
00858 
00859 
00860 
00861 
00862 
00863 
00864 Bool_t TRPCProc::BuildHits( TRocData* rocEvent )
00865 {  
00866    UInt_t uFirstActiveChip = fRocPar->uNbFeets*2 + 1;
00867 
00868    if( kTRUE == fRocPar->noTrigger && 0 == (rocEvent->vMessageEventBuffer).size() )
00869       return kFALSE;
00870    else if( 0 == (rocEvent->fExtMessages).size() )
00871       return kFALSE;
00872 
00873    
00874    if( kTRUE == fRocPar->noTrigger )
00875       fGet4EdgeMessagePerEvent->Fill( (rocEvent->vMessageEventBuffer).size() );
00876       else fGet4EdgeMessagePerEvent->Fill( (rocEvent->fExtMessages).size() );
00877    
00878    
00879    
00880    if( 0 == fRpcPar->uHitBuildingEnable )
00881    {
00882       
00883       
00884       
00885       for(UInt_t uChip = 0; uChip < fRocPar->uNbFeets*2; uChip++)
00886          if( 1 == fRocPar->uGet4Active[uChip] )
00887          {
00888             if( uFirstActiveChip > fRocPar->uNbFeets*2)
00889                uFirstActiveChip = uChip;
00890          }
00891       
00892       
00893       if( fRocPar->uNbBuffers - 1  == uCurrentBlockBuffer) 
00894       {
00895          if( kFALSE == TimeOrderBlock( 0 ) )
00896             return kFALSE;
00897       }
00898          else
00899          {
00900             if( kFALSE == TimeOrderBlock( uCurrentBlockBuffer + 1) )
00901                return kFALSE;
00902          }
00903       
00904       
00905       uLastEpochLastBlock = uCurrentEpoch2;
00906       uLastCycleLastBlock = uCurrentCycle2;
00907 
00908       
00909       uCurrentBlockBuffer = (uCurrentBlockBuffer + 1)%fRocPar->uNbBuffers;
00910       
00911       return kTRUE;
00912    }
00913    
00914    roc::Message storedData;
00915    ULong64_t     storedEpoch;
00916    ULong64_t     storedEpochCycle;
00917    ULong64_t     storedLocalEpoch;
00918    ULong64_t     storedLocalEpochCycle;
00919    
00920    
00921    
00922    for(UInt_t uChip = 0; uChip < fRocPar->uNbFeets*2; uChip++)
00923    {
00924       if( 1 == fRocPar->uGet4Active[uChip] && uFirstActiveChip > fRocPar->uNbFeets*2)
00925          uFirstActiveChip = uChip;
00926 
00927       for(UInt_t uChan = 0; uChan < NB_CHAN_GET4; uChan++)
00928       {
00929          (FECHIP[uChip].uNbHitsInEventLE[uChan])         = 0;
00930          (FECHIP[uChip].uNbHitsInEventTE[uChan])         = 0;
00931       }
00932    }
00933 
00934    UInt_t epochLocalTemp = 0;
00935    UInt_t cycleLocalTemp = 0;
00936    UInt_t uPrevEpochTest = 0;
00937    UInt_t uPrevPrevEpochTest = 0;
00938 
00939    
00940    
00941    UInt_t uBufferSize = 0;
00942    if( kTRUE == fRocPar->noTrigger )
00943       uBufferSize =  (rocEvent->vMessageEventBuffer).size();
00944       else  uBufferSize =  (rocEvent->fExtMessages).size();
00945 
00946    for( UInt_t uMessIndex = 0;
00947          uMessIndex <uBufferSize;
00948          uMessIndex++)
00949    {
00950       if( kTRUE == fRocPar->noTrigger )
00951       {
00952          storedData            = ( (rocEvent->vMessageEventBuffer).at(uMessIndex) ).GetRocMessage();
00953          storedEpoch           = ( (rocEvent->vMessageEventBuffer).at(uMessIndex) ).GetRocEpoch();
00954          storedEpochCycle      = ( (rocEvent->vMessageEventBuffer).at(uMessIndex) ).GetRocCycle();
00955          storedLocalEpoch      = ( (rocEvent->vMessageEventBuffer).at(uMessIndex) ).GetLocalEpoch();
00956          storedLocalEpochCycle = ( (rocEvent->vMessageEventBuffer).at(uMessIndex) ).GetLocalCycle();
00957       } 
00958          else
00959          {
00960             storedData            = ( (rocEvent->fExtMessages).at(uMessIndex) ).GetRocMessage();
00961             if( kTRUE == fRocPar->NoGet4Cleaning)
00962             {
00963                storedEpoch           = ( (rocEvent->fExtMessages).at(uMessIndex) ).GetRocEpoch();
00964                storedEpochCycle      = 0;
00965                storedLocalEpoch      = 0;
00966                storedLocalEpochCycle = 0;
00967             }
00968             else
00969             {
00970                storedEpoch           = ( (rocEvent->fExtMessages).at(uMessIndex) ).GetRocEpoch();
00971                storedEpochCycle      = ( (rocEvent->fExtMessages).at(uMessIndex) ).GetRocCycle();
00972                storedLocalEpoch      = ( (rocEvent->fExtMessages).at(uMessIndex) ).GetLocalEpoch();
00973                storedLocalEpochCycle = ( (rocEvent->fExtMessages).at(uMessIndex) ).GetLocalCycle();
00974             }
00975          } 
00976 
00977       UInt_t typStored = storedData.getMessageType();
00978 
00979 
00980 
00981 
00982 
00983 
00984 
00985       if( typStored == roc::MSG_SYNC )
00986       {
00987          
00988 
00989 
00990          continue;
00991       }
00992 
00993       if( kTRUE == fRocPar->noTrigger )
00994       {
00995 
00996 
00997 
00998 
00999 
01000 
01001 
01002 
01003 
01004 
01005 
01006 
01007 
01008          mLastFromBuffer = (rocEvent->vMessageEventBuffer).at(uMessIndex);
01009       }
01010                         
01011       if( 0 == uMessIndex )
01012       {           
01013          if( 1 == fRocPar->uUseLocalEpochs)
01014          {
01015             uEpochBufferStart = storedLocalEpoch;
01016             uCycleBufferStart = storedLocalEpochCycle;
01017          }
01018          else
01019          {
01020             uEpochBufferStart = storedEpoch;
01021             uCycleBufferStart = storedEpochCycle;
01022          }
01023       }
01024 
01025       if( typStored == roc::MSG_SYS )
01026       {
01027          TGet4HitUnpacked hitChipSync;
01028          hitChipSync.ClearHit();
01029          hitChipSync.SetFullChan( fRocPar->uNbFeets*8 );
01030          if( 1 == fRocPar->uUseLocalEpochs)
01031             hitChipSync.SetEpochLeading( storedLocalEpoch, storedLocalEpochCycle );
01032             else hitChipSync.SetEpochLeading( storedEpoch, storedEpochCycle );
01033          hitChipSync.SetTsLeading( (storedData.getField(23,12))<<7 );
01034          v_HitUnpBlock[ uCurrentBlockBuffer ].push_back( hitChipSync );
01035          uPrevPrevEpochTest = uPrevEpochTest;
01036          uPrevEpochTest = storedLocalEpoch;
01037          continue;
01038       }
01039       else if( typStored != roc::MSG_GET4 )
01040       {
01041          if( kTRUE == fRocPar->noTrigger )
01042             Message(3, "Error 2: this message is not a GET4 data: chip %2u type %2u, start ep. %7d cy. %7d Mess %5u/%5u local ep. %7d  %7d %7d",
01043                         uFirstActiveChip, typStored, epochLocalTemp, cycleLocalTemp, uMessIndex,
01044                         (rocEvent->vMessageEventBuffer).size() - 1,
01045                         storedLocalEpoch, uPrevEpochTest, uPrevPrevEpochTest);
01046             else Message(3, "Error 2: this message is not a GET4 data: chip %2u type %2u, start ep. %7d cy. %7d Mess %5u/%5u local ep. %7d  %7d %7d",
01047                            uFirstActiveChip, typStored, epochLocalTemp, cycleLocalTemp, uMessIndex,
01048                            (rocEvent->fExtMessages).size() - 1,
01049                            storedLocalEpoch, uPrevEpochTest, uPrevPrevEpochTest);
01050          storedData.printData(roc::msg_print_Hex, storedLocalEpoch);
01051       }
01052       uPrevPrevEpochTest = uPrevEpochTest;
01053       uPrevEpochTest = storedLocalEpoch;
01054       
01055       
01056       UInt_t uChipStored    = storedData.getGet4Number();
01057       
01058 
01059 
01060 
01061 
01062       
01063       UInt_t uChannelStored = storedData.getGet4ChNum();
01064       
01065       UInt_t uFullChannelStored = uChipStored * 4 + storedData.getGet4ChNum();
01066       
01067       
01068       if ( uFullChannelStored >= 0 && uFullChannelStored < fRocPar->uNbFeets * 8 )
01069       {
01070          
01071          
01072          UInt_t uEdge     = storedData.getGet4Edge();
01073 
01074          
01075          if ( uEdge == 0 )
01076          {            
01077             fGet4RisEdgesNb->Fill( uFullChannelStored );
01078             if( kFALSE == fRocPar->noTrigger && 0 != (FECHIP[uChipStored].mLastLeading[uChannelStored]).GetFullTime() )
01079             {
01080                if( 1 == fRocPar->uUseLocalEpochs )
01081                   FECHIP[uChipStored].fGet4LeSpacingClose[uChannelStored]->Fill(
01082                         FECHIP[uChipStored].mLastLeading[uChannelStored].LocalSpacing(
01083                         ( (rocEvent->fExtMessages).at(uMessIndex) ) ) ); 
01084                   else FECHIP[uChipStored].fGet4LeSpacingClose[uChannelStored]->Fill(
01085                         FECHIP[uChipStored].mLastLeading[uChannelStored].RocSpacing(
01086                         ( (rocEvent->fExtMessages).at(uMessIndex) ) ) ); 
01087             } 
01088             if( 1 == fRocPar->uUseLocalEpochs)
01089             {
01090                fGet4EdgesDiffEvol->Fill( storedLocalEpochCycle, uFullChannelStored, -1);
01091             }
01092                else
01093                { 
01094                   fGet4EdgesDiffEvol->Fill( storedEpochCycle, uFullChannelStored, -1);
01095                }
01096 
01097             if( kFALSE == fRocPar->noTrigger )
01098                fGet4RisEdgesEvol->Fill( ((rocEvent->fExtMessages).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01099                else fGet4RisEdgesEvol->Fill(
01100                      ((rocEvent->vMessageEventBuffer).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01101             if( (FECHIP[uChipStored].u_nbConsLE[uChannelStored]) &&  kFALSE == fRocPar->noTrigger )
01102             {
01103                if( 1 == fRocPar->uUseLocalEpochs)
01104                   (FECHIP[uChipStored].fTestConsecutiveLE[uChannelStored])->Fill(
01105                         FECHIP[uChipStored].mLastTrailing[uChannelStored].LocalSpacing(
01106                               FECHIP[uChipStored].mLastLeading[uChannelStored] ),
01107                               FECHIP[uChipStored].u_nbConsLE[uChannelStored]);
01108                   else (FECHIP[uChipStored].fTestConsecutiveLE[uChannelStored])->Fill(
01109                            FECHIP[uChipStored].mLastTrailing[uChannelStored].RocSpacing(
01110                                  FECHIP[uChipStored].mLastLeading[uChannelStored] ),
01111                                  FECHIP[uChipStored].u_nbConsLE[uChannelStored]);
01112                (FECHIP[uChipStored].fTest2ConsecutiveLE[uChannelStored])->Fill(
01113                      (FECHIP[uChipStored].mLastLeading[uChannelStored]).GetRocMessage().getGet4Ts() % NB_BIN_GET4_FTS,
01114                      (FECHIP[uChipStored].mLastTrailing[uChannelStored]).GetRocMessage().getGet4Ts() % NB_BIN_GET4_FTS );
01115             } 
01116             (FECHIP[uChipStored].u_nbConsLE[uChannelStored])++;
01117             if( kFALSE == fRocPar->noTrigger )
01118                (FECHIP[uChipStored].mLastLeading[uChannelStored]) = (rocEvent->fExtMessages).at(uMessIndex);
01119             if( 1 == fRocPar->uDebugHistoOn )
01120             {
01121                (FECHIP[uChipStored].fGet4FineTimeLE)[uChannelStored]->Fill( storedData.getGet4Ts() % NB_BIN_GET4_FTS);
01122                if( 0 == (FECHIP[uChipStored].uNbHitsInEventLE[uChannelStored]) )
01123                   (FECHIP[uChipStored].fGet4FineTimeLE_First[uChannelStored])->Fill( storedData.getGet4Ts() % NB_BIN_GET4_FTS);
01124                else if( 1 == (FECHIP[uChipStored].uNbHitsInEventLE[uChannelStored]) )
01125                   (FECHIP[uChipStored].fGet4FineTimeLE_Second[uChannelStored])->Fill( storedData.getGet4Ts() % NB_BIN_GET4_FTS);
01126                (FECHIP[uChipStored].uNbHitsInEventLE[uChannelStored]) ++;
01127 
01128                if( kFALSE == fRocPar->noTrigger )
01129                   (FECHIP[uChipStored].fGet4RisEdgesNbEvol[uChannelStored])->Fill(
01130                                        ((rocEvent->fExtMessages).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01131                   else (FECHIP[uChipStored].fGet4RisEdgesNbEvol[uChannelStored])->Fill(
01132                      ((rocEvent->vMessageEventBuffer).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01133                if( (FECHIP[uChipStored].u_nbConsTE[uChannelStored]) )
01134                {
01135                   (FECHIP[uChipStored].fNbConsecutiveTE[uChannelStored])->Fill((FECHIP[uChipStored].u_nbConsTE[uChannelStored]));
01136                }
01137             } 
01138             if( (FECHIP[uChipStored].u_nbConsTE[uChannelStored]) )
01139                (FECHIP[uChipStored].u_nbConsTE[uChannelStored]) = 0;
01140          } 
01141          else
01142          {            
01143             fGet4FalEdgesNb->Fill( uFullChannelStored );
01144             if( kFALSE == fRocPar->noTrigger && 0 != (FECHIP[uChipStored].mLastTrailing[uChannelStored]).GetFullTime() )
01145             {
01146                if( 1 == fRocPar->uUseLocalEpochs )
01147                   FECHIP[uChipStored].fGet4TeSpacingClose[uChannelStored]->Fill(
01148                         FECHIP[uChipStored].mLastTrailing[uChannelStored].LocalSpacing(
01149                         ( (rocEvent->fExtMessages).at(uMessIndex) ) ) ); 
01150                   else FECHIP[uChipStored].fGet4TeSpacingClose[uChannelStored]->Fill(
01151                         FECHIP[uChipStored].mLastTrailing[uChannelStored].RocSpacing(
01152                         ( (rocEvent->fExtMessages).at(uMessIndex) ) ) ); 
01153             } 
01154             if( 1 == fRocPar->uUseLocalEpochs)
01155             {
01156                fGet4EdgesDiffEvol->Fill( storedLocalEpochCycle, uFullChannelStored, 1);
01157             }
01158                else
01159                { 
01160                   fGet4EdgesDiffEvol->Fill( storedEpochCycle, uFullChannelStored, 1);
01161                }
01162             if( kFALSE == fRocPar->noTrigger )
01163                fGet4FalEdgesEvol->Fill( ((rocEvent->fExtMessages).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01164                else fGet4FalEdgesEvol->Fill(
01165                      ((rocEvent->vMessageEventBuffer).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01166             if( (FECHIP[uChipStored].u_nbConsTE[uChannelStored]) &&  kFALSE == fRocPar->noTrigger )
01167             {
01168                if( 1 == fRocPar->uUseLocalEpochs)
01169                   (FECHIP[uChipStored].fTestConsecutiveTE[uChannelStored])->Fill(
01170                         FECHIP[uChipStored].mLastLeading[uChannelStored].LocalSpacing(
01171                               FECHIP[uChipStored].mLastTrailing[uChannelStored] ),
01172                               FECHIP[uChipStored].u_nbConsTE[uChannelStored] );
01173                   else (FECHIP[uChipStored].fTestConsecutiveTE[uChannelStored])->Fill(
01174                            FECHIP[uChipStored].mLastLeading[uChannelStored].RocSpacing(
01175                                  FECHIP[uChipStored].mLastTrailing[uChannelStored] ),
01176                                  FECHIP[uChipStored].u_nbConsTE[uChannelStored]);
01177                (FECHIP[uChipStored].fTest2ConsecutiveTE[uChannelStored])->Fill(
01178                      (FECHIP[uChipStored].mLastTrailing[uChannelStored]).GetRocMessage().getGet4Ts() % NB_BIN_GET4_FTS,
01179                      (FECHIP[uChipStored].mLastLeading[uChannelStored]).GetRocMessage().getGet4Ts() % NB_BIN_GET4_FTS );
01180             }
01181             (FECHIP[uChipStored].u_nbConsTE[uChannelStored])++;
01182             if( kFALSE == fRocPar->noTrigger )
01183                (FECHIP[uChipStored].mLastTrailing[uChannelStored]) = (rocEvent->fExtMessages).at(uMessIndex);
01184             if( 1 == fRocPar->uDebugHistoOn )
01185             {
01186                (FECHIP[uChipStored].fGet4FineTimeTE[uChannelStored])->Fill( storedData.getGet4Ts() % NB_BIN_GET4_FTS);
01187                if( 0 == (FECHIP[uChipStored].uNbHitsInEventTE[uChannelStored]) )
01188                   (FECHIP[uChipStored].fGet4FineTimeTE_First[uChannelStored])->Fill( storedData.getGet4Ts() % NB_BIN_GET4_FTS);
01189                else if( 1 == (FECHIP[uChipStored].uNbHitsInEventTE[uChannelStored]) )
01190                   (FECHIP[uChipStored].fGet4FineTimeTE_Second[uChannelStored])->Fill( storedData.getGet4Ts() % NB_BIN_GET4_FTS);
01191                (FECHIP[uChipStored].uNbHitsInEventTE[uChannelStored]) ++;
01192 
01193                if( kFALSE == fRocPar->noTrigger )
01194                   (FECHIP[uChipStored].fGet4FalEdgesNbEvol[uChannelStored])->Fill(
01195                         ((rocEvent->fExtMessages).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01196                   else
01197                      (FECHIP[uChipStored].fGet4FalEdgesNbEvol[uChannelStored])->Fill(
01198                            ((rocEvent->vMessageEventBuffer).at(uMessIndex)).GetFullTime() / (ULong64_t)1000000000 );
01199 
01200                if( (FECHIP[uChipStored].u_nbConsLE[uChannelStored]) )
01201                {
01202                (FECHIP[uChipStored].fNbConsecutiveLE[uChannelStored])->Fill((FECHIP[uChipStored].u_nbConsLE[uChannelStored]));
01203                }
01204             } 
01205             if( (FECHIP[uChipStored].u_nbConsLE[uChannelStored]) )
01206                (FECHIP[uChipStored].u_nbConsLE[uChannelStored]) = 0;
01207          }
01208          
01209          try
01210          {
01211          
01212          
01213          
01214          
01215             if( 1 == fRocPar->uUseLocalEpochs)
01216                (FECHIP[uChipStored].hitCurrent[uChannelStored]).SetMessage( storedData,
01217                                              storedLocalEpoch, storedLocalEpochCycle );
01218                else (FECHIP[uChipStored].hitCurrent[uChannelStored]).SetMessage( storedData,
01219                                              storedEpoch, storedEpochCycle );
01220             
01221             
01222             
01223             if ( (FECHIP[uChipStored].hitCurrent[uChannelStored]).Complete() )
01224             {
01225                
01226                
01227                (FECHIP[uChipStored].fGet4TOT[uChannelStored])->Fill(
01228                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTOT() );
01229                
01230                
01231                
01232                
01233                if ( (FECHIP[uChipStored].hitLatest[uChannelStored]).Complete() )
01234                {
01235                  (FECHIP[uChipStored].fGet4PulseSpacingClose[uChannelStored])->Fill( (-1)*
01236                     (FECHIP[uChipStored].hitCurrent[uChannelStored]).Spacing(FECHIP[uChipStored].hitLatest[uChannelStored]));
01237                  if( 1 == fRocPar->uDebugHistoOn )
01238                  { 
01239                     (FECHIP[uChipStored].fGet4PulseSpacingMid[uChannelStored])->Fill( (-0.001)*
01240                      (FECHIP[uChipStored].hitCurrent[uChannelStored]).Spacing(FECHIP[uChipStored].hitLatest[uChannelStored]));
01241                     (FECHIP[uChipStored].fGet4PulseSpacingFar[uChannelStored])->Fill( (-0.000000001)*
01242                      (FECHIP[uChipStored].hitCurrent[uChannelStored]).Spacing(FECHIP[uChipStored].hitLatest[uChannelStored]));
01243                  }
01244                }
01245                
01246                
01247                
01248                
01249                
01250                
01251                if( ((FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading() 
01252                          < uEpochBufferStart &&
01253                    (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleLeading() 
01254                          == uCycleBufferStart) ||
01255                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleLeading() 
01256                          < uCycleBufferStart )
01257                {
01258                   if( 0 == uCurrentBlockBuffer )
01259                      v_HitUnpBlock[ fRocPar->uNbBuffers - 1 ].push_back( FECHIP[uChipStored].hitCurrent[uChannelStored] );
01260                      else v_HitUnpBlock[ uCurrentBlockBuffer - 1 ].push_back( 
01261                                                     FECHIP[uChipStored].hitCurrent[uChannelStored] );
01262                   Message(0, "Shifting this hit back, its falling edge was in this epoch but it started before!");
01263                   Message(0, "Chan %2d (Chip %2d) TS = %9d, Epoch = %9d, Cycle = %9d, ToT = %9d, Block = %9d, buffer %d",
01264                         FECHIP[uChipStored].hitCurrent[uChannelStored].GetFullChan(),
01265                         FECHIP[uChipStored].hitCurrent[uChannelStored].GetGet4Index(),
01266                         FECHIP[uChipStored].hitCurrent[uChannelStored].GetTsLeading(),
01267                         FECHIP[uChipStored].hitCurrent[uChannelStored].GetEpochLeading(),
01268                         FECHIP[uChipStored].hitCurrent[uChannelStored].GetEpochCycleLeading(),
01269                         FECHIP[uChipStored].hitCurrent[uChannelStored].GetRawTOT(),
01270                            uBlockIndexLast, uCurrentBlockBuffer );
01271                   Message(0, "EpochBufferStart %10d, CycleBufferStart %10d", uEpochBufferStart, uCycleBufferStart);
01272                }
01273                else
01274                   v_HitUnpBlock[ uCurrentBlockBuffer ].push_back( FECHIP[uChipStored].hitCurrent[uChannelStored] );
01275 
01276                
01277                
01278                (FECHIP[uChipStored].hitLatest[uChannelStored]) = (FECHIP[uChipStored].hitCurrent[uChannelStored]);
01279                (FECHIP[uChipStored].hitCurrent[uChannelStored]).ClearHit();
01280             }
01281          }
01282          catch( CENoGET4DataEvent& error_obj )
01283          {
01284             cout << "Chip " <<uChipStored<<" ";
01285             cout << "Wrong message type!: "<<(UInt_t)error_obj.ucMessType<<" ";
01286             cout << "This is not a GET4 Data Event. ";
01287             cout << "Should not happen..." << endl;
01288          }
01289          catch( CELeadingEdgeAlreadySet )
01290          {
01291              
01292              
01293              fReconErrLE->Fill( uFullChannelStored );
01294          }
01295          catch( CETrailingEdgeAlreadySet )
01296          {
01297              
01298              
01299             fReconErrTE->Fill( uFullChannelStored );
01300          }
01301          catch( CEGivesNegativeToT )
01302          {
01303              
01304              
01305              
01306             fReconErrNegToT->Fill( uFullChannelStored );
01307          }
01308          catch( CEOutOfTimeGate )
01309          {
01310              
01311              
01312              
01313             fReconErrTimeGate->Fill( uFullChannelStored );
01314          }
01315          catch( CEOutOfTimeGateDetail& error_obj )
01316          {
01317              
01318              
01319              
01320              
01321              
01322              
01323             fReconErrTimeGate->Fill( uFullChannelStored );
01324             Message(0,"****** tot past chip= %2d chan= %2d fc= %5d, %6d %7d %9d, %6d %7d %9d, %2d, %4d, %6d %7d",
01325                   uChipStored, uChannelStored, uFullChannelStored,
01326                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleLeading(),
01327                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01328                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(),
01329                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleTrailing(),
01330                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing(),
01331                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing(),
01332                   (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing()
01333                     - (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01334                   (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing()
01335                     -(Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(),
01336                   storedEpochCycle, storedEpoch );
01337 
01338             if( 1 == fRpcPar->uManualDebug )
01339                if( 0.0 < error_obj.tot_past && error_obj.tot_past < 50.0 )
01340                { 
01341                   Message(2,"****** Falling edge delay chip= %2d chan= %2d fc= %5d, %6d %7d %9d, %6d %7d %9d, %2d, %4d, %6d %7d",
01342                         uChipStored, uChannelStored, uFullChannelStored,
01343                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleLeading(),  
01344                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01345                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(), 
01346                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleTrailing(),
01347                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing(), 
01348                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing(),
01349                         (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing() 
01350                           - (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01351                         (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing()
01352                           -(Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(),
01353                         storedEpochCycle, storedEpoch );
01354                }
01355          }
01356          catch( CEGivesNegativeToTDetail& error_obj )
01357          {
01358              
01359              
01360              
01361              
01362              
01363              
01364             fReconErrNegToT->Fill( uFullChannelStored );
01365             Message(0,"****** tot fut chip= %2d chan= %2d fc= %5d, %6d %7d %9d, %6d %7d %9d, %2d, %4d, %6d %7d",
01366                   uChipStored, uChannelStored, uFullChannelStored,
01367                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleLeading(),
01368                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01369                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(),
01370                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleTrailing(),
01371                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing(),
01372                   (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing(),
01373                   (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing()
01374                      - (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01375                   (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing()
01376                      -(Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(),
01377                   storedEpochCycle, storedEpoch  );
01378 
01379             if( 1 == fRpcPar->uManualDebug )
01380                if( 0.0 < error_obj.tot_fut && error_obj.tot_fut < 50.0 )
01381                {
01382                   Message(2,"****** Rising  edge delay chip= %2d chan= %2d fc= %5d, %6d %7d %9d, %6d %7d %9d, %2d, %4d, %6d %7d",
01383                         uChipStored, uChannelStored, uFullChannelStored,
01384                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleLeading(),
01385                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01386                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(),
01387                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochCycleTrailing(),
01388                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing(),
01389                         (FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing(),
01390                         (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochTrailing() 
01391                            - (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetEpochLeading(),
01392                         (Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsTrailing()
01393                            -(Int_t)(FECHIP[uChipStored].hitCurrent[uChannelStored]).GetTsLeading(),
01394                         storedEpochCycle, storedEpoch  );
01395                }
01396          }
01397          catch( CEHitIsNotComplete )
01398          {
01399             cout << "The Hit data is not complete. ";
01400             cout << "Should not happen..." << endl; 
01401          }
01402       } 
01403    } 
01404 
01405    
01406    
01407    if( fRocPar->uNbBuffers - 1  == uCurrentBlockBuffer ) 
01408    {
01409       if( kFALSE == TimeOrderBlock( 0 ) )
01410          return kFALSE;
01411    }
01412       else
01413       {
01414          if( kFALSE == TimeOrderBlock( uCurrentBlockBuffer + 1) )
01415             return kFALSE;
01416       }
01417    
01418    
01419    
01420    if( kFALSE == fRocPar->noTrigger )
01421    {
01422       if( kFALSE == TimeOrderBlock( uCurrentBlockBuffer ) )
01423          return kFALSE;
01424    } 
01425    
01426    uLastEpochLastBlock = uCurrentEpoch2;
01427    uLastCycleLastBlock = uCurrentCycle2;
01428 
01429 
01430         
01431    uCurrentBlockBuffer = (uCurrentBlockBuffer + 1)%fRocPar->uNbBuffers;
01432    
01433    return kTRUE;
01434 }
01435 
01436 
01437 
01438 
01439 
01440 
01441 Bool_t TRPCProc::TimeOrderBlock(UInt_t bBufferToSort)
01442 {    
01443    
01444    
01445    if( 0 == fRpcPar->uBlockOrderingEnable )
01446    {
01447       v_HitUnpBlock[ bBufferToSort ].clear();
01448             
01449       uBlockIndex ++ ;
01450          
01451       return kTRUE;
01452    }
01453    if( 0 == (v_HitUnpBlock[ bBufferToSort ]).size() )
01454    {
01455       uBlockIndex ++ ;
01456       return kTRUE;
01457    }
01458               
01459    std::list< TGet4HitUnpacked > lTempBuffSort;
01460    lTempBuffSort.insert( lTempBuffSort.begin(), (v_HitUnpBlock[ bBufferToSort ]).begin(),
01461                                                 (v_HitUnpBlock[ bBufferToSort ]).end() );
01462    lTempBuffSort.sort( );
01463    
01464    for ( UInt_t uChip = 0; uChip < fRocPar->uNbFeets *2; uChip++ )
01465       for ( UInt_t uChan = 0; uChan < NB_CHAN_GET4; uChan++ )
01466       {
01467          (FECHIP[uChip].hitLatestBlock[uChan]).ClearHit();
01468          (FECHIP[uChip].hitCurrentBlock[uChan]).ClearHit();
01469       }
01470    
01471    Bool_t bFirstHits = kTRUE;
01472    TGet4HitUnpacked hitTemp;
01473    
01474    
01475    while( !lTempBuffSort.empty() )
01476    {
01477       
01478       hitTemp.ClearHit();
01479       hitTemp = lTempBuffSort.front();
01480       
01481       UInt_t uChip     = hitTemp.GetGet4Index();
01482       UInt_t uChan     = hitTemp.GetChannel();
01483       UInt_t uFullChan = hitTemp.GetFullChan();
01484       
01485       
01486       if( uFullChan == fRocPar->uNbFeets*8 ) 
01487       {
01488          (fOutputEvent->fUnpackedHits).push_back(hitTemp);
01489          continue; 
01490       }
01491          else                               
01492          {
01493             (fOutputEvent->fUnpackedHits).push_back(hitTemp);
01494             bHitInThisEvent[uFullChan] = kTRUE;
01495             
01496             if( ( 1 == fRpcPar->uCleanOuputEnable || 1 == fRpcPar->uRootDisplay) && 1 == fRpcPar->uAddGet4DataInTree )
01497             {
01498                UInt_t uFullChan = hitTemp.GetFullChan();
01499                (*vuHitNumber)[uFullChan] ++;
01500                (*vuTime)[uFullChan].push_back( hitTemp.GetTsLeading() );
01501                (*vuEpochTime)[uFullChan].push_back( hitTemp.GetEpochLeading() );
01502                (*viTot)[uFullChan].push_back( hitTemp.GetRawTOT() );
01503             } 
01504          }
01505       
01506       if( 0 == fRocPar->uGet4Active[uChip] )
01507       {
01508          lTempBuffSort.pop_front();
01509          continue;
01510       }
01511 
01512       
01513       if( lastHit.Complete() )
01514       {
01515          if( lastHit.Spacing( hitTemp ) < 0.0 )
01516          {
01517             if( 0 == fRocPar->uSilentMode )
01518             {
01519                Message(3,"****** Block time ordering error: spacing = %9.2f in event %u, ordering buffer %d, First flag %1d ",
01520                         lastHit.Spacing( hitTemp ), uNbEvents, bBufferToSort, bFirstHits );
01521                Message(3, "Chan %2d (Chip %2d) TS = %9d, Epoch = %9d, Cycle = %9d, ToT = %9d, Block = %9d before",
01522                         lastHit.GetFullChan(), lastHit.GetGet4Index(), lastHit.GetTsLeading(),
01523                         lastHit.GetEpochLeading(), lastHit.GetEpochCycleLeading(), lastHit.GetRawTOT(),
01524                         uBlockIndexLast );
01525                Message(3, "Chan %2d (Chip %2d) TS = %9d, Epoch = %9d, Cycle = %9d, ToT = %9d, Block = %9d ", uFullChan,
01526                         hitTemp.GetGet4Index(),
01527                         hitTemp.GetTsLeading(),
01528                         hitTemp.GetEpochLeading(),
01529                         hitTemp.GetEpochCycleLeading(),
01530                         hitTemp.GetRawTOT(),
01531                         uBlockIndex );
01532                Message(3, "Switching chip %2d OFF", lastHit.GetGet4Index() );
01533             }
01534             fMapOrderErrors->Fill(lastHit.GetFullChan(), uFullChan);
01535             fMapOrderErrorsChips->Fill( lastHit.GetFullChan()/4, uFullChan/4);
01536 
01537             fRocPar->uGet4Active[lastHit.GetGet4Index()] = 0;
01538             cout<<"Get4 Activated:  |-      ";
01539             for(UInt_t temp_index = 0; temp_index < 2*fRocPar->uNbFeets; temp_index++)
01540             {
01541                cout.width(2);
01542                cout<<temp_index<<" ";
01543             }
01544             cout<<endl<<"                 |->     ";
01545             for(UInt_t temp_index = 0; temp_index < 2*fRocPar->uNbFeets; temp_index++)
01546             {
01547                cout.width(2);
01548                cout<<fRocPar->uGet4Active[temp_index]<<" ";
01549             }
01550             cout<<endl;
01551 
01552             lTempBuffSort.clear();
01553             v_HitUnpBlock[ bBufferToSort ].clear();
01554             lastHit.ClearHit();
01555             lastHit = hitTemp;
01556 
01557             uBlockIndex ++ ;
01558 
01559             return kFALSE; 
01560          }
01561       }
01562       
01563       FECHIP[uChip].hitCurrentBlock[uChan] = hitTemp;
01564       if( kTRUE == bFirstHits  && 1 == fRocPar->uDebugHistoOn )
01565       {
01566          fGet4BlocksEvol->Fill((FECHIP[uChip].hitCurrentBlock[uChan]).GetEpochCycleLeading());
01567       }
01568       if( uFullChan < fRocPar->uNbFeets*8 && (FECHIP[uChip].hitCurrentBlock[uChan]).Complete())
01569       {
01570          fGet4HitsNb->Fill( uFullChan );
01571          fGet4HitsEvol->Fill( (FECHIP[uChip].hitCurrentBlock[uChan]).GetFullTimeSeconds() );
01572          if( 1 == fRocPar->uDebugHistoOn )
01573             (FECHIP[uChip].fGet4HitsNbEvolution[uChan])->Fill( (FECHIP[uChip].hitCurrentBlock[uChan]).GetFullTimeSeconds());
01574       }
01575          else if( uFullChan < fRocPar->uNbFeets*8  && 1 == fRocPar->uDebugHistoOn)
01576             fGet4IncompletHitsEvol->Fill((FECHIP[uChip].hitCurrentBlock[uChan]).GetFullTimeSeconds());
01577 
01578       if( kTRUE == bFirstHits )
01579          bFirstHits = kFALSE;
01580       
01581       lastHit.ClearHit();
01582       lastHit = (FECHIP[uChip].hitCurrentBlock[uChan]);
01583       uBlockIndexLast = uBlockIndex;
01584       
01585       if( uFullChan < fRocPar->uNbFeets*8 )
01586       {
01587          if( (FECHIP[uChip].hitLatestBlock[uChan]).Complete())
01588          {
01589             if( (FECHIP[uChip].hitLatestBlock[uChan]).Spacing( (FECHIP[uChip].hitCurrentBlock[uChan])) != 0 && 1 != fRpcPar->uNbHitMeanRate)
01590             {
01591                if( FECHIP[uChip].uInstantRateCounter[uChan] < fRpcPar->uNbHitMeanRate )
01592                {
01593                   FECHIP[uChip].dInstantRateMean[uChan] += 
01594                                                  ( (FECHIP[uChip].hitLatestBlock[uChan]).Spacing( (FECHIP[uChip].hitCurrentBlock[uChan])) )
01595                                                  / fRpcPar->uNbHitMeanRate;
01596                   FECHIP[uChip].dInstantRateOld[uChan][FECHIP[uChip].uInstantRateCounter[uChan]]  = 
01597                                                   ( (FECHIP[uChip].hitLatestBlock[uChan]).Spacing( (FECHIP[uChip].hitCurrentBlock[uChan])) )
01598                                                   /fRpcPar->uNbHitMeanRate;
01599      
01600                   FECHIP[uChip].uInstantRateCounter[uChan]++;
01601                }
01602                else
01603                {
01604                   FECHIP[uChip].dInstantRateMean[uChan] -= FECHIP[uChip].dInstantRateOld[uChan][FECHIP[uChip].uInstantRateCounter[uChan] 
01605                                                  - fRpcPar->uNbHitMeanRate];
01606                   FECHIP[uChip].dInstantRateMean[uChan] += 
01607                                                   ( (FECHIP[uChip].hitLatestBlock[uChan]).Spacing( (FECHIP[uChip].hitCurrentBlock[uChan])) ) 
01608                                                   / fRpcPar->uNbHitMeanRate;
01609                   FECHIP[uChip].dInstantRateOld[uChan][FECHIP[uChip].uInstantRateCounter[uChan] - fRpcPar->uNbHitMeanRate]  =
01610                                                    ( (FECHIP[uChip].hitLatestBlock[uChan]).Spacing( (FECHIP[uChip].hitCurrentBlock[uChan])) )
01611                                                    /fRpcPar->uNbHitMeanRate;
01612 
01613                   FECHIP[uChip].uInstantRateCounter[uChan]++;
01614                }
01615                if( (fRpcPar->uNbHitMeanRate - 1) < FECHIP[uChip].uInstantRateCounter[uChan] )
01616                {
01617                   (FECHIP[uChip].fGet4InstantRate[uChan])->Fill( 1000000000.0/FECHIP[uChip].dInstantRateMean[uChan], 
01618                                                      (FECHIP[uChip].hitCurrentBlock[uChan]).GetEpochCycleLeading() );
01619                }
01620                   
01621                if( 2*fRpcPar->uNbHitMeanRate == FECHIP[uChip].uInstantRateCounter[uChan] )
01622                   FECHIP[uChip].uInstantRateCounter[uChan] = fRpcPar->uNbHitMeanRate;
01623             }
01624          }
01625       }
01626       
01627       
01628       Double_t dTimeToDistanceFactor = 10.0;
01629          
01630       
01631       for( UInt_t uChipOne = 0; uChipOne < 2*fRocPar->uNbFeets; uChipOne++ )
01632       {       
01633          UInt_t uIndex = 0;
01634          for(Int_t iChanOne = 0; iChanOne < NB_CHAN_GET4; iChanOne++)
01635          {
01636             Int_t iFullChanOne = NB_CHAN_GET4*uChipOne + iChanOne;
01637             Int_t iFullChanSec = 0;
01638             
01639             
01640             for(Int_t iChanSec = iChanOne + 1; iChanSec < NB_CHAN_GET4; iChanSec++)
01641             {
01642                iFullChanSec = NB_CHAN_GET4*uChipOne + iChanSec;
01643                
01644                
01645                
01646                
01647                if ( iFullChanOne == (Int_t)uFullChan && FECHIP[uChipOne].hitLatestBlock[iChanSec].Complete() )
01648                {
01649                   FillCorrelationHistograms( uIndex, uChipOne, iChanOne, uChipOne, iChanSec);
01650                } 
01651                else if ( iFullChanSec == (Int_t)uFullChan && FECHIP[uChipOne].hitLatestBlock[iChanOne].Complete() )
01652                {
01653                   FillCorrelationHistogramsInv( uIndex, uChipOne, iChanOne, uChipOne, iChanSec);
01654                } 
01655                uIndex++;
01656             } 
01657             for(UInt_t uChipSec = uChipOne + 1; uChipSec < 2*fRocPar->uNbFeets; uChipSec++)
01658             {
01659                for(Int_t iChanSec = 0; iChanSec < NB_CHAN_GET4; iChanSec++)
01660                {
01661                   iFullChanSec = NB_CHAN_GET4*uChipSec + iChanSec;
01662                   
01663                   
01664                   
01665                   
01666                   if ( iFullChanOne == (Int_t)uFullChan && FECHIP[uChipSec].hitLatestBlock[iChanSec].Complete() )
01667                   {
01668                      FillCorrelationHistograms( uIndex, uChipOne, iChanOne, uChipSec, iChanSec);
01669                   } 
01670                   else if ( iFullChanSec == (Int_t)uFullChan && FECHIP[uChipOne].hitLatestBlock[iChanOne].Complete() )
01671                   {
01672                      FillCorrelationHistogramsInv( uIndex, uChipOne, iChanOne, uChipSec, iChanSec);
01673                   } 
01674                   uIndex++;
01675                } 
01676             } 
01677             
01678             
01679             for( UInt_t uStripIndex = 0; uStripIndex < fRpcPar->uNbStrips; uStripIndex++)
01680                if( iFullChanOne == (Int_t)fRpcPar->uStripLeftList[uStripIndex] )
01681                {
01682                   UInt_t uChipSec = fRpcPar->uStripRightList[uStripIndex] / NB_CHAN_GET4;
01683                   UInt_t uChanSec = fRpcPar->uStripRightList[uStripIndex] % NB_CHAN_GET4;
01684                   if( FECHIP[uChipOne].hitLatestBlock[iChanOne].Complete() && 
01685                       FECHIP[uChipSec].hitLatestBlock[uChanSec].Complete() )
01686                   { 
01687                      fBeamProfileHDRPC->Fill( dTimeToDistanceFactor *
01688                         FECHIP[uChipOne].hitLatestBlock[iChanOne].Spacing( FECHIP[uChipSec].hitLatestBlock[uChanSec] ) 
01689                                               - fRpcPar->dOffsetList[uStripIndex],
01690                                              uStripIndex - ( (Double_t)fRpcPar->uNbStrips / 2.0 ) );
01691                   } 
01692                }
01693          } 
01694       } 
01695 
01696       
01697       if( -1 != iIsPadChannelX[uFullChan] )
01698          fBeamProfilePRPC->Fill( iIsPadChannelX[uFullChan] - (fRpcPar->uNbPadsX/2.0), iIsPadChannelY[uFullChan] - (fRpcPar->uNbPadsY/2.0) );
01699               
01700       (FECHIP[uChip].hitLatestBlock[uChan]).ClearHit(); 
01701       FECHIP[uChip].hitLatestBlock[uChan] = FECHIP[uChip].hitCurrentBlock[uChan];
01702       (FECHIP[uChip].hitCurrentBlock[uChan]).ClearHit();
01703       
01704       lTempBuffSort.pop_front();
01705    }
01706    
01707    lTempBuffSort.clear();
01708    v_HitUnpBlock[ bBufferToSort ].clear();
01709                    
01710    uBlockIndex ++ ;
01711       
01712    return kTRUE;
01713 }
01714 
01715 
01716 Bool_t TRPCProc::FillCorrelationHistograms( UInt_t uIndexHisto,
01717        UInt_t uChipOne, Int_t iChanOne, UInt_t uChipSec, Int_t iChanSec)
01718 {
01719    Double_t dCorrValue = FECHIP[uChipOne].hitCurrentBlock[iChanOne].Spacing( 
01720                          FECHIP[uChipSec].hitLatestBlock[ iChanSec]);
01721    if( -fRpcPar->fCorrelationGate <= dCorrValue && dCorrValue <= fRpcPar->fCorrelationGate)
01722       FECHIP[uChipOne].fVGetTimeCorrelation[uIndexHisto]->Fill( dCorrValue );
01723    
01724    if( 1 == fRpcPar->uTotCorrelationHistOn )
01725    {   
01726       FECHIP[uChipOne].fVGetTotCorrelation[uIndexHisto]->Fill(FECHIP[uChipOne].hitCurrentBlock[iChanOne].GetTOT(),
01727                                                               FECHIP[uChipSec].hitLatestBlock[ iChanSec].GetTOT());
01728    }
01729    if( 1 == fRpcPar->uCorrelationHistoOn )
01730    {
01731       if( -fRpcPar->fCorrelationCheck <= dCorrValue && dCorrValue <= fRpcPar->fCorrelationCheck)
01732          for( UInt_t uChipTer = 0; uChipTer < 2*fRocPar->uNbFeets; uChipTer++ )
01733          for(Int_t iChanTer = 0; iChanTer < NB_CHAN_GET4; iChanTer++)
01734          if( ( uChipTer != uChipOne || iChanTer != iChanOne ) &&
01735              ( uChipTer != uChipSec || iChanTer != iChanSec ) )
01736          {
01737          if( FECHIP[uChipTer].hitLatestBlock[ iChanTer].Complete() )
01738          {
01739             Double_t dCorrValue2 = FECHIP[uChipOne].hitCurrentBlock[iChanOne].Spacing( 
01740                                    FECHIP[uChipTer].hitLatestBlock[ iChanTer]);
01741             Double_t dCorrValue3 = FECHIP[uChipSec].hitLatestBlock[ iChanSec].Spacing( 
01742                                    FECHIP[uChipTer].hitLatestBlock[ iChanTer]);
01743             if(-fRpcPar->fCorrelationCheck <= dCorrValue2 && dCorrValue2 <= fRpcPar->fCorrelationCheck &&
01744                -fRpcPar->fCorrelationCheck <= dCorrValue3 && dCorrValue3 <= fRpcPar->fCorrelationCheck)
01745             {
01746                FECHIP[uChipOne].fVCheckCorrelation[uIndexHisto]->Fill( uChipTer*NB_CHAN_GET4 + iChanTer );
01747                
01748                for( UInt_t uChipQua = 0; uChipQua < 2*fRocPar->uNbFeets; uChipQua++ )
01749                for(Int_t iChanQua = 0; iChanQua < NB_CHAN_GET4; iChanQua++)
01750                if( ( uChipQua != uChipOne || iChanQua != iChanOne ) &&
01751                    ( uChipQua != uChipSec || iChanQua != iChanSec ) &&
01752                    ( uChipQua != uChipTer || iChanQua != iChanTer ) )
01753                {
01754                if( FECHIP[uChipQua].hitLatestBlock[ iChanQua].Complete() )
01755                {
01756                   Double_t dCorrValue4 = FECHIP[uChipOne].hitCurrentBlock[iChanOne].Spacing( 
01757                                          FECHIP[uChipQua].hitLatestBlock[ iChanQua]);
01758                   Double_t dCorrValue5 = FECHIP[uChipSec].hitLatestBlock[ iChanSec].Spacing( 
01759                                          FECHIP[uChipQua].hitLatestBlock[ iChanQua]);
01760                   Double_t dCorrValue6 = FECHIP[uChipTer].hitLatestBlock[ iChanTer].Spacing( 
01761                                          FECHIP[uChipQua].hitLatestBlock[ iChanQua]);
01762                   if(-fRpcPar->fCorrelationCheck <= dCorrValue4 && dCorrValue4 <= fRpcPar->fCorrelationCheck &&
01763                      -fRpcPar->fCorrelationCheck <= dCorrValue5 && dCorrValue5 <= fRpcPar->fCorrelationCheck &&
01764                      -fRpcPar->fCorrelationCheck <= dCorrValue6 && dCorrValue6 <= fRpcPar->fCorrelationCheck )
01765                      FECHIP[uChipOne].fVCheckCorrelation4[uIndexHisto]->Fill( uChipTer*NB_CHAN_GET4 + iChanTer,
01766                                                                               uChipQua*NB_CHAN_GET4 + iChanQua );
01767                }
01768                }
01769             }
01770          } 
01771          } 
01772          else
01773             FECHIP[uChipOne].fVCheckCorrelation[uIndexHisto]->Fill( uChipTer*NB_CHAN_GET4 + iChanTer );
01774    } 
01775    
01776    return kTRUE;
01777 }
01778 
01779 
01780 Bool_t TRPCProc::FillCorrelationHistogramsInv( UInt_t uIndexHisto,
01781        UInt_t uChipOne, Int_t iChanOne, UInt_t uChipSec, Int_t iChanSec)
01782 {
01783    Double_t dCorrValue = FECHIP[uChipOne].hitLatestBlock[ iChanOne].Spacing( 
01784                          FECHIP[uChipSec].hitCurrentBlock[iChanSec]);
01785    if( -fRpcPar->fCorrelationGate <= dCorrValue && dCorrValue <= fRpcPar->fCorrelationGate)
01786       FECHIP[uChipOne].fVGetTimeCorrelation[uIndexHisto]->Fill( dCorrValue );
01787    
01788    if( 1 == fRpcPar->uTotCorrelationHistOn )
01789    {   
01790       FECHIP[uChipOne].fVGetTotCorrelation[uIndexHisto]->Fill(FECHIP[uChipOne].hitLatestBlock[ iChanOne].GetTOT(),
01791                                                               FECHIP[uChipSec].hitCurrentBlock[iChanSec].GetTOT());  
01792    }
01793    if( 1 == fRpcPar->uCorrelationHistoOn )
01794    {
01795       FECHIP[uChipOne].fVGetTotCorrelation[uIndexHisto]->Fill(FECHIP[uChipOne].hitLatestBlock[ iChanOne].GetTOT(),
01796                                                               FECHIP[uChipSec].hitCurrentBlock[iChanSec].GetTOT());
01797       if( -fRpcPar->fCorrelationCheck <= dCorrValue && dCorrValue <= fRpcPar->fCorrelationCheck)
01798          for( UInt_t uChipTer = 0; uChipTer < 2*fRocPar->uNbFeets; uChipTer++ )
01799          for(Int_t iChanTer = 0; iChanTer < NB_CHAN_GET4; iChanTer++)
01800          if( ( uChipTer != uChipOne || iChanTer != iChanOne ) &&
01801              ( uChipTer != uChipSec || iChanTer != iChanSec ) )
01802          {
01803          if( FECHIP[uChipTer].hitLatestBlock[ iChanTer].Complete() )
01804          {
01805             Double_t dCorrValue2 = FECHIP[uChipOne].hitLatestBlock[ iChanOne].Spacing( 
01806                                    FECHIP[uChipTer].hitLatestBlock[ iChanTer]);
01807             Double_t dCorrValue3 = FECHIP[uChipSec].hitCurrentBlock[iChanSec].Spacing( 
01808                                    FECHIP[uChipTer].hitLatestBlock[ iChanTer]);
01809             if(-fRpcPar->fCorrelationCheck <= dCorrValue2 && dCorrValue2 <= fRpcPar->fCorrelationCheck &&
01810                -fRpcPar->fCorrelationCheck <= dCorrValue3 && dCorrValue3 <= fRpcPar->fCorrelationCheck)
01811             {
01812                FECHIP[uChipOne].fVCheckCorrelation[uIndexHisto]->Fill( uChipTer*NB_CHAN_GET4 + iChanTer );
01813                
01814                for( UInt_t uChipQua = 0; uChipQua < 2*fRocPar->uNbFeets; uChipQua++ )
01815                for(Int_t iChanQua = 0; iChanQua < NB_CHAN_GET4; iChanQua++)
01816                if( ( uChipQua != uChipOne || iChanQua != iChanOne ) &&
01817                    ( uChipQua != uChipSec || iChanQua != iChanSec ) &&
01818                    ( uChipQua != uChipTer || iChanQua != iChanTer ) )
01819                {
01820                if( FECHIP[uChipQua].hitLatestBlock[ iChanQua].Complete() )
01821                {
01822                   Double_t dCorrValue4 = FECHIP[uChipOne].hitLatestBlock[ iChanOne].Spacing( 
01823                                          FECHIP[uChipQua].hitLatestBlock[ iChanQua]);
01824                   Double_t dCorrValue5 = FECHIP[uChipSec].hitCurrentBlock[iChanSec].Spacing( 
01825                                          FECHIP[uChipQua].hitLatestBlock[ iChanQua]);
01826                   Double_t dCorrValue6 = FECHIP[uChipTer].hitLatestBlock[ iChanTer].Spacing( 
01827                                          FECHIP[uChipQua].hitLatestBlock[ iChanQua]);
01828                   if(-fRpcPar->fCorrelationCheck <= dCorrValue4 && dCorrValue4 <= fRpcPar->fCorrelationCheck &&
01829                      -fRpcPar->fCorrelationCheck <= dCorrValue5 && dCorrValue5 <= fRpcPar->fCorrelationCheck &&
01830                      -fRpcPar->fCorrelationCheck <= dCorrValue6 && dCorrValue6 <= fRpcPar->fCorrelationCheck )
01831                      FECHIP[uChipOne].fVCheckCorrelation4[uIndexHisto]->Fill( uChipTer*NB_CHAN_GET4 + iChanTer,
01832                                                                               uChipQua*NB_CHAN_GET4 + iChanQua );
01833                }
01834                }
01835             }
01836          } 
01837          } 
01838          else
01839             FECHIP[uChipOne].fVCheckCorrelation[uIndexHisto]->Fill( uChipTer*NB_CHAN_GET4 + iChanTer );
01840    } 
01841    
01842    return kTRUE;
01843 }
01844