• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

onlinemonitor/trbmonitor/TTrbProc.cxx (r4864/r4410)

Go to the documentation of this file.
00001 #include "TTrbProc.h"
00002 
00003 #include "TClass.h"
00004 #include "TROOT.h"
00005 #include "TSystem.h"
00006 #include "TGo4MbsEvent.h"
00007 #include "TGo4MbsSubEvent.h"
00008 #include "TGo4UserException.h"
00009 #include "TGo4Log.h"
00010 
00011 #include "TGo4Analysis.h"
00012 
00013 #include "base/commons.h"
00014 
00015 #include "TTrbEvent.h"
00016 
00017 #include "TGo4Picture.h"
00018 
00019 #define EPRINT( args ...) if(fPar->printEvent) printf( args )
00020 
00021 const TString TTrbProc::leadingcoarseallname = "LeadingCoarseAllChans";
00022 const TString TTrbProc::leadingfineallname = "LeadingFineAllChans";
00023 const TString TTrbProc::leadingdeltacalallname = "LeadingDeltaCalAllChans";
00024 
00025 const TString TTrbProc::trailingcoarseallname = "TrailingCoarseAllChans";
00026 const TString TTrbProc::trailingfineallname = "TrailingFineAllChans";
00027 const TString TTrbProc::trailingdeltacalallname = "TrailingDeltaCalAllChans";
00028 
00038 void TTrbProc::GenHistos1 (TString dirname, Int_t b, Int_t t)
00039 {
00040    TString obname;
00041    TString obtitle;
00042 
00043    UInt_t tbins = 0;
00044    Int_t trange = 0;
00045 
00046    obname.Form("%s/%s_%02d_%02d", dirname.Data(), leadingcoarseallname.Data(), b, t);
00047    obtitle.Form("Leading Coarse time  TRB %02d TDC %02d all channels", b, t);
00048    tbins = TRB_TDC3_COARSEBINS;
00049    trange = TRB_TDC3_EPOCHUNIT;
00050    hLeadingCoarseAll[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (ns)");
00051 
00052    obname.Form("%s/%s_%02d_%02d", dirname.Data(), leadingfineallname.Data(), b, t);
00053    obtitle.Form("Leading Fine time TRB %02d TDC %02d all channels", b, t);
00054    tbins = TRB_TDC3_FINEBINS;
00055    trange = TRB_TDC3_FINEBINS;
00056    hLeadingFineAll[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (bin) ");
00057 
00058    obname.Form("%s/%s_%02d_%02d", dirname.Data(), leadingdeltacalallname.Data(), b, t);
00059    obtitle.Form("Leading Delta time (calibr.) TRB %02d TDC %02d all channels", b,t);
00060    tbins = TRB_TDC3_DELTAHISTBINS / 8;
00061    trange = TRB_TDC3_DELTAHISTBINS;
00062    hLeadingDeltaCalAll[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), 200000, -1e6, 1e6, "t (ns)");
00063 
00064    obname.Form("%s/%sFine_%02d_%02d", dirname.Data(), leadingdeltacalallname.Data(), b, t);
00065    obtitle.Form("Leading Delta time (calibr.) TRB %02d TDC %02d all channels", b,t);
00066    hLeadingDeltaCalAllFine[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), 2000, -1000., +1000., "t (ns)");
00067 
00068 
00069    if (fPar->processTrailing) {
00070       obname.Form("%s/%s_%02d_%02d", dirname.Data(), trailingcoarseallname.Data(), b, t);
00071       obtitle.Form("Trailing Coarse time TRB %02d TDC %02d all channels", b,t);
00072       tbins = TRB_TDC3_COARSEBINS;
00073       trange = TRB_TDC3_EPOCHUNIT;
00074       hTrailingCoarseAll[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (ns)");
00075 
00076       obname.Form("%s/%s_%02d_%02d", dirname.Data(), trailingfineallname.Data(), b,t);
00077       obtitle.Form("Trailing Fine time TRB %02d TDC %02d all channels", b,t);
00078       tbins = TRB_TDC3_FINEBINS;
00079       trange = TRB_TDC3_FINEBINS;
00080       hTrailingFineAll[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (bin) ");
00081 
00082       obname.Form("%s/%s_%02d_%02d", dirname.Data(), trailingdeltacalallname.Data(), b, t);
00083       obtitle.Form("Trailing Delta Ftime (calibr.) TRB %02d TDC %02d all channels", b, t);
00084       tbins = TRB_TDC3_DELTAHISTBINS / 8;
00085       trange = TRB_TDC3_DELTAHISTBINS;
00086       hTrailingDeltaCalAll[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, -trange / 2, trange / 2, "t (ns)");
00087    }
00088 
00089    obname.Form("%s/Epoch_%02d_%02d", dirname.Data(), b, t);
00090    obtitle.Form("Epoch TRB %02d TDC %02d", b, t);
00091    tbins = TRB_TDC3_EPOCHBINS / 1024;
00092    Double_t drange = (Double_t)TRB_TDC3_EPOCHUNIT * (Double_t)TRB_TDC3_EPOCHBINS;
00093    hEpoch[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, drange, "t (bin)");
00094 }
00095 
00103 void TTrbProc::GenHistos2 (TString dirname, Int_t b, Int_t t, Int_t i)
00104 {
00105    TString obname;
00106    TString obtitle;
00107    TString legendx;
00108    TString legendy;
00109 
00110    UInt_t tbins = 0;
00111    Int_t trange = 0;
00112 
00113    obname.Form("%s/Chan%02d/LeadingCoarseTime_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00114    obtitle.Form("Coarse time  Leading edge TRB %02d TDC %02d Channel %02d", b, t, i);
00115    tbins = TRB_TDC3_COARSEBINS;
00116    trange = TRB_TDC3_EPOCHUNIT;
00117    hLeadingCoarse[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (ns)");
00118 
00119    obname.Form("%s/Chan%02d/LeadingFineTime_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00120    obtitle.Form("Fine time Leading edge TRB %02d TDC %02d Channel %02d", b, t, i);
00121    tbins = TRB_TDC3_FINEBINS;
00122    trange = TRB_TDC3_FINEBINS;
00123    hLeadingFine[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (bin)");
00124 
00125    if (IsAnyCalibration()) {
00126       obname.Form("%s/Chan%02d/LeadingFineTimeBuffer_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00127       obtitle.Form("Fine time Leading edge TRB %02d TDC %02d Channel %02d (calibration buffer)", b, t, i);
00128       tbins = TRB_TDC3_FINEBINS;
00129       trange = TRB_TDC3_FINEBINS;
00130       hLeadingFineBuffer[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (bin)");
00131    }
00132 
00133    obname.Form("%s/Chan%02d/LeadingDeltaTimeCal_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00134    obtitle.Form("Delta time Leading edge calibrated TRB %02d TDC %02d Channel %02d", b, t, i);
00135    tbins = TRB_TDC3_DELTAHISTBINS / 8;
00136    trange = TRB_TDC3_DELTAHISTBINS;
00137    hLeadingDeltaCal[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), 3000, -1500, 1500, "t (ns)");
00138 
00139    obname.Form("%s/Chan%02d/LeadingDeltaTimeRef_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00140    obtitle.Form("Delta time to refer channel Leading edge calibrated TRB %02d TDC %02d Channel %02d", b, t, i);
00141    tbins = TRB_TDC3_DELTAHISTBINS / 8;
00142    trange = TRB_TDC3_DELTAHISTBINS;
00143    hLeadingDeltaRef[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), 3000, -1500, 1500, "t (ns)");
00144 
00145 #ifdef CREATEMAPS
00146    obname.Form("%s/Chan%02d/LeadingCorrelationRaw_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00147    obtitle.Form("Raw Correlation Leading edge TRB %02d TDC %02d to reference of channel %02d", b, t, i);
00148    legendx.Form("Channel %d", i);
00149    legendy.Form("TRB %d TDC %d Channel %d", b, t, fPar->refChannel);
00150    tbins = TRB_TDC3_FINEBINS;
00151    trange = TRB_TDC3_FINEBINS;
00152    hLeadingCorrelFine[b][t][i] = MakeTH2('I', obname.Data(), obtitle.Data(), tbins, 0, trange, tbins, 0, trange, legendx.Data(), legendy.Data());
00153    hLeadingCorrelFine[b][t][i]->SetYTitle(legendy.Data());
00154 #endif // CREATEMAPS
00155 }
00156 
00164 void TTrbProc::GenHistos3 (TString dirname, Int_t b, Int_t t, Int_t i)
00165 {
00166    TString obname;
00167    TString obtitle;
00168    TString legendx;
00169    TString legendy;
00170 
00171    UInt_t tbins = 0;
00172    Int_t trange = 0;
00173 
00174    obname.Form("%s/Chan%02d/TrailingCoarseTime_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00175    obtitle.Form("Coarse time Trailing edge TRB %02d TDC %02d Channel %02d", b, t, i);
00176    tbins = TRB_TDC3_COARSEBINS;
00177    trange = TRB_TDC3_EPOCHUNIT;
00178    hTrailingCoarse[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (ns)");
00179 
00180    obname.Form("%s/Chan%02d/TrailingFineTime_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00181    obtitle.Form("Fine time Trailing edge TRB %02d TDC %02d Channel %02d", b, t, i);
00182    tbins = TRB_TDC3_FINEBINS;
00183    trange = TRB_TDC3_FINEBINS;
00184    hTrailingFine[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (bin)");
00185 
00186    obname.Form("%s/Chan%02d/TrailingFineTimeBuffer_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00187    obtitle.Form("Fine time Trailing edge TRB %02d TDC %02d Channel %02d (calibration buffer)", b, t, i);
00188    tbins = TRB_TDC3_FINEBINS;
00189    trange = TRB_TDC3_FINEBINS;
00190    hTrailingFineBuffer[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, 0, trange, "t (bin)");
00191 
00192    obname.Form("%s/Chan%02d/TrailingDeltaTimeCal_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00193    obtitle.Form("Delta time Trailing edge calibrated  TRB %02d TDC %02d Channel %02d", b, t, i);
00194    tbins = TRB_TDC3_DELTAHISTBINS / 8;
00195    trange = TRB_TDC3_DELTAHISTBINS;
00196    hTrailingDeltaCal[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, -trange / 2, trange / 2, "t (ns)");
00197 
00198    obname.Form("%s/Chan%02d/TrailingDeltaTimeRef_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00199    obtitle.Form("Delta time to ref channel trailing edge calibrated  TRB %02d TDC %02d Channel %02d", b, t, i);
00200    tbins = TRB_TDC3_DELTAHISTBINS / 8;
00201    trange = TRB_TDC3_DELTAHISTBINS;
00202    hTrailingDeltaRef[b][t][i] = MakeTH1('I', obname.Data(), obtitle.Data(), tbins, -trange / 2, trange / 2, "t (ns)");
00203 
00204 #ifdef CREATEMAPS
00205    obname.Form("%s/Chan%02d/TrailingCorrelationRaw_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00206    obtitle.Form("Raw Correlation Trailing edge TRB %02d TDC %02d to reference of channel %02d", b, t, i);
00207    legendx.Form("Channel %d", i);
00208    legendy.Form("TRB %d TDC %d Channel %d", b, t, fPar->refChannel);
00209    tbins = TRB_TDC3_FINEBINS;
00210    trange = TRB_TDC3_FINEBINS;
00211    hTrailingCorrelFine[b][t][i] = MakeTH2('I', obname.Data(), obtitle.Data(), tbins, 0, trange, tbins, 0, trange, legendx.Data(), legendy.Data());
00212    hTrailingCorrelFine[b][t][i]->SetYTitle(legendy.Data());
00213 #endif // CREATEMAPS
00214 }
00215 
00216 TTrbProc::TTrbProc () :
00217               TCBMBeamtimeProc ()
00218 {
00219 }
00220 
00221 TTrbProc::TTrbProc (const char* name) :
00222               TCBMBeamtimeProc (name)
00223 {
00224    TGo4Log::Info("TTrbProc create instance %s", GetName());
00225 
00226    fOutEvent = 0;
00227 
00229    fPar = (TTrbParam *) MakeParameter ("TrbPar", "TTrbParam", "set_TrbPar.C");
00230    if (fPar)
00231       fPar->SetConfigTrbs();
00232    else {
00233       TGo4Log::Error("Cannot create TTrbParam object");
00234       return;
00235    }
00236 
00237    fPar->fEventCount = 0;
00238 
00239    fLastTriggerId = 0;
00240    fLostTriggerCnt = 0;
00241    fTakenTriggerCnt = 0;
00242 
00244 
00245    hSubevSize = MakeTH1('I', "TRB/SubEventsSize", "Size of TRB subevents", 1024, 0, 1024*32, "size, B");;  // subevents size
00246 
00247 
00248    TString obname;
00249    TString obtitle;
00250    TString dirname;
00251    TString hname;
00252 
00253    hTDCDataVolume = MakeTH1('I', "TRB/TDCDataVolume", "Volume of data (in bytes) from each TDC", 16, 0, 16, "TDC board number");
00254 
00255    hLostRate = MakeTH1('I', "TRB/TRBLostRate", "Relative number of lost packets", 1000, 0, 1., "data lost");
00256 
00257    /* -------------------------------------------------------------------------------------- */
00258 
00259    dirname.Form("TRB");
00260    obname.Form("%s/ChannelCount", dirname.Data());
00261    obtitle.Form("Package count");
00262    hTrbTriggerCount = MakeTH1('I', obname.Data(), obtitle.Data(), 6, 0, 6, "channel number");
00263    if (IsObjMade())
00264    {
00265       hTrbTriggerCount->GetXaxis()->SetBinLabel(1, "TOTAL");
00266       hTrbTriggerCount->GetXaxis()->SetBinLabel(2, "INVALID");
00267       hTrbTriggerCount->GetXaxis()->SetBinLabel(3, "TDC");
00268       hTrbTriggerCount->GetXaxis()->SetBinLabel(4, "CENTR_HUB");
00269       hTrbTriggerCount->GetXaxis()->SetBinLabel(5, "DUMMY");
00270       hTrbTriggerCount->GetXaxis()->SetBinLabel(6, "CTS");
00271    }
00272 
00273    // Explicitly reset all pointers in the beginning
00274 
00275    for (Int_t b=0; b<TRB_TDC3_NUMBOARDS; ++b)
00276       for (Int_t t=0; t<TRB_TDC3_NUMTDC; ++t) {
00277 
00278          hEventMultipl[b][t] = 0;
00279          hPulserMultipl[b][t] = 0;
00280          hChannelCount[b][t] = 0;
00281          hLeadingCoarseAll[b][t] = 0;
00282          hLeadingFineAll[b][t] = 0;
00283          hLeadingDeltaCalAll[b][t] = 0;
00284 
00285          hLeadingCoarseAllChans[b][t] = 0;
00286          hLeadingFineAllChans[b][t] = 0;
00287 
00288          hTrailingCoarseAll[b][t] = 0;
00289          hTrailingCoarseAllChans[b][t] = 0;
00290          hTrailingFineAll[b][t] = 0;
00291          hTrailingFineAllChans[b][t] = 0;
00292          hTrailingDeltaCalAll[b][t] = 0;
00293          hLeadingDeltaCalAllFine[b][t] = 0;
00294 
00295          for (Int_t i=0; i<TRB_TDC3_CHANNELS; ++i) {
00296             fbHasCalibration[b][t][i] = kFALSE;
00297             hCalcBinWidth[b][t][i] = 0;
00298             hCalBinTime[b][t][i] = 0;
00299 
00300             hLeadingCoarse[b][t][i] = 0;
00301             hLeadingFine[b][t][i] = 0;
00302             hLeadingFineBuffer[b][t][i] = 0;
00303             hLeadingDeltaCal[b][t][i] = 0;
00304             hLeadingDeltaRef[b][t][i] = 0;
00305 
00306             hTrailingCoarse[b][t][i] = 0;
00307             hTrailingFine[b][t][i] = 0;
00308             hTrailingFineBuffer[b][t][i] = 0;
00309             hTrailingDeltaCal[b][t][i] = 0;
00310             hTrailingDeltaRef[b][t][i] = 0;
00311 
00312 #ifdef CREATEMAPS
00313             hLeadingCorrelFine[b][t][i] = 0;
00314 #endif
00315          }
00316       }
00317 
00318 
00319 
00320    for (Int_t b=0; b<TRB_TDC3_NUMBOARDS; ++b)
00321    {
00322       if (!TTrbEvent::AssertTRB(b)) continue;
00323 
00324       for (Int_t t=0; t<TRB_TDC3_NUMTDC; ++t)
00325       {
00326          if (!TTrbEvent::AssertTDC(b,t)) continue;
00327 
00328          dirname.Form("TRB/TRB%02d_TDC%02d", b, t);
00329          obname.Form("%s/ChannelCountTRB%02d_TDC%02d", dirname.Data(), b, t);
00330          obtitle.Form("Channel hit count TRB %02d TDC %02d", b, t);
00331          hChannelCount[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), TRB_TDC3_CHANNELS, 0, TRB_TDC3_CHANNELS);
00332 
00333          obname.Form("%s/MultiplicityTRB%02d_TDC%02d", dirname.Data(), b, t);
00334          obtitle.Form("Event multiplicity of TRB %02d TDC %02d", b, t);
00335          hEventMultipl[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), 50, 0, 50., "multipl");
00336 
00337          obname.Form("%s/PulserMultiplTRB%02d_TDC%02d", dirname.Data(), b, t);
00338          obtitle.Form("Pulser multiplicity of TRB %02d TDC %02d", b, t);
00339          hPulserMultipl[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), 50, 0, 50., "multipl");
00340 
00341          GenHistos1 (dirname, b, t);
00342 
00343          for (Int_t i=0; i<TRB_TDC3_CHANNELS; ++i)
00344          {
00346             fbHasCalibration[b][t][i] = kFALSE;
00347 
00348             dirname.Form("TRB/TRB%02d_TDC%02d", b, t);
00349 
00352             if (fPar->fillRaw)
00353                GenHistos2(dirname, b, t, i);
00354 
00356             if (fPar->fillRaw && fPar->processTrailing)
00357                GenHistos3(dirname, b, t, i);
00358 
00359             if (WithoutCalibration()) continue;
00360 
00362             dirname.Form("TRB/TimeCalibration/TRB%02d/TDC%02d", b, t);
00363             obname.Form("%s/Chan%02d/BinWidth_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00364             obtitle.Form("Binwidth Histogram of TRB %02d TDC %02d Channel %02d", b, t, i);
00365             hCalcBinWidth[b][t][i] = MakeTH1('D', obname.Data(), obtitle.Data(), TRB_TDC3_FINEBINS, 0, TRB_TDC3_FINEBINS, "???", "???");
00366             if (IsObjMade()) {
00368                for (int fb=0; fb<TRB_TDC3_FINEBINS; ++fb)
00369                   hCalcBinWidth[b][t][i]->SetBinContent(fb + 1, 1.0);
00370             }
00371 
00372             obname.Form("%s/Chan%02d/CalTableBinTime_%02d_%02d_%02d", dirname.Data(), i, b, t, i);
00373             obtitle.Form("Calibration Table of TRB %02d TDC %02d Channel %02d", b, t, i);
00374             hCalBinTime[b][t][i] = MakeTH1('D', obname.Data(), obtitle.Data(), TRB_TDC3_FINEBINS, 0, TRB_TDC3_FINEBINS, "in bin", "time (ns)");
00375             if (IsObjMade()) {
00377                for (int fb=0; fb<TRB_TDC3_FINEBINS; ++fb)
00378                   hCalBinTime[b][t][i]->SetBinContent(fb + 1, TRB_TDC3_COARSEUNIT * fb / TRB_TDC3_FINEBINS);
00379             }
00380 
00381          } // for i - through channels
00382 
00383          dirname.Form("TRB/TRB%02d_TDC%02d", b, t);
00384 
00387          obname.Form("%s/LeadingCoarseChannelsMap_%02d_%02d", dirname.Data(), b, t);
00388          obtitle.Form("Coarse times Leading edges of all channels TRB %02d TDC %02d", b, t);
00389          Int_t tbins = TRB_TDC3_COARSEBINS / 2;
00390          Double_t trange = TRB_TDC3_EPOCHUNIT;
00391          hLeadingCoarseAllChans[b][t] = MakeTH2('I', obname.Data(), obtitle.Data(), TRB_TDC3_CHANNELS, 0, TRB_TDC3_CHANNELS, tbins, 0, trange, "channel", "t (ns)");
00392 
00393          obname.Form("%s/LeadingFineChannelsMap_%02d_%02d", dirname.Data(), b, t);
00394          obtitle.Form("Fine times Leading edges of all channels TRB %02d TDC %02d", b, t);
00395          tbins = TRB_TDC3_FINEBINS / 4;
00396          trange = TRB_TDC3_FINEBINS;
00397          hLeadingFineAllChans[b][t] = MakeTH2('I', obname.Data(), obtitle.Data(), TRB_TDC3_CHANNELS, 0, TRB_TDC3_CHANNELS, tbins, 0, trange, "channel", "t (bin)");
00398 
00400          if (fPar->processTrailing) {
00401             obname.Form("%s/TrailingCoarseChannelsMap_%02d_%02d", dirname.Data(), b, t);
00402             obtitle.Form("Coarse times Trailing edges of all channels  TRB %02d TDC %02d", b, t);
00403             tbins = TRB_TDC3_COARSEBINS / 2;
00404             trange = TRB_TDC3_EPOCHUNIT;
00405             hTrailingCoarseAllChans[b][t] = MakeTH2('I', obname.Data(), obtitle.Data(), TRB_TDC3_CHANNELS, 0, TRB_TDC3_CHANNELS, tbins, 0, trange, "channel", "t (ns)");
00406 
00407             obname.Form("%s/TrailingFineChannelsMap_%02d_%02d", dirname.Data(), b, t);
00408             obtitle.Form("Fine times Trailing edges of all channels  TRB %02d TDC %02d", b, t);
00409             tbins = TRB_TDC3_FINEBINS / 4;
00410             trange = TRB_TDC3_FINEBINS;
00411             hTrailingFineAllChans[b][t] = MakeTH2('I', obname.Data(), obtitle.Data(), TRB_TDC3_CHANNELS, 0, TRB_TDC3_CHANNELS, tbins, 0, trange, "channel", "t (bin)");
00412          }
00413 
00432          {
00433             obname.Form("%s/TriggerScaler_%02d_%02d", dirname.Data(), b, t);
00434             obtitle.Form("Empty vs Filled events TRB %02d TDC %02d", b, t);
00435             hTriggerCount[b][t] = MakeTH1('I', obname.Data(), obtitle.Data(), 10 + TRB_TDC3_CHANNELS, 0, 10 + TRB_TDC3_CHANNELS);
00436             if (IsObjMade())
00437             {
00438                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(1, "TOTAL");
00439                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(2, "INVALID");
00440                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(3, "LEADING");
00441                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(4, "TRAILING");
00442                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(5, "EPOCH");
00443                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(6, "HEADER");
00444                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(7, "DEBUG");
00445                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(8, "RESERVED");
00446                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(9, "");
00447                hTriggerCount[b][t]->GetXaxis()->SetBinLabel(10, "");
00448 
00449                TString text;
00450                for (int c = 0; c < TRB_TDC3_CHANNELS; ++c)
00451                {
00452                   text.Form("PAIRS-CH%02d", c);
00453                   hTriggerCount[b][t]->GetXaxis()->SetBinLabel(c + 11, text.Data());
00454                }
00455             }
00456          }
00457 
00459          {
00461             obname.Form("%s/LeadingCoarseTimeGate_%02d_%02d", dirname.Data(), b, t);
00462             hname.Form("%s_%02d_%02d", leadingcoarseallname.Data(), b, t);
00463             cLeadingCoarseTimeGate[b][t] = MakeWinCond(obname.Data(),
00464                   TRB_TDC3_COARSE_COND_LOW, TRB_TDC3_COARSE_COND_HIGH,
00465                   hname.Data());
00466 
00467             obname.Form("%s/LeadingFineTimeGate_%02d_%02d", dirname.Data(), b, t);
00468             hname.Form("%s_%02d_%02d", leadingfineallname.Data(), b, t);
00469             cLeadingFineTimeGate[b][t] = MakeWinCond(obname.Data(),
00470                   TRB_TDC3_FINE_COND_LOW, TRB_TDC3_FINE_COND_HIGH,
00471                   hname.Data());
00472 
00474             if (fPar->processTrailing) {
00475                obname.Form("%s/TrailingCoarseTimeGate_%02d_%02d", dirname.Data(), b, t);
00476                hname.Form("%s_%02d_%02d", trailingcoarseallname.Data(), b, t);
00477                cTrailingCoarseTimeGate[b][t] = MakeWinCond(obname.Data(),
00478                      TRB_TDC3_COARSE_COND_LOW, TRB_TDC3_COARSE_COND_HIGH,
00479                      hname.Data());
00480 
00481                obname.Form("%s/TrailingFineTimeGate_%02d_%02d", dirname.Data(), b, t);
00482                hname.Form("%s_%02d_%02d", trailingfineallname.Data(), b, t);
00483                cTrailingFineTimeGate[b][t] = MakeWinCond(obname.Data(),
00484                      TRB_TDC3_FINE_COND_LOW, TRB_TDC3_FINE_COND_HIGH,
00485                      hname.Data());
00486             }
00487 
00489             obname.Form("%s/LeadingDeltaTimeGate_%02d_%02d", dirname.Data(), b, t);
00490             hname.Form("%sFine_%02d_%02d", leadingdeltacalallname.Data(), b, t);
00491             cLeadingDeltaTimeGate[b][t] = MakeWinCond(obname.Data(),
00492                   TRB_TDC3_LdeltaT_COND_LOW, TRB_TDC3_LdeltaT_COND_HIGH,
00493                   hname.Data());
00494 
00496             if (fPar->processTrailing) {
00497                obname.Form("%s/TrailingDeltaTimeGate_%02d_%02d", dirname.Data(), b, t);
00498                hname.Form("%s_%02d_%02d", trailingdeltacalallname.Data(), b, t);
00499                cTrailingDeltaTimeGate[b][t] = MakeWinCond(obname.Data(),
00500                      TRB_TDC3_TdeltaT_COND_LOW, TRB_TDC3_TdeltaT_COND_HIGH,
00501                      hname.Data());
00502             }
00503          }
00504 
00506          {
00508             obname.Form("LeadingFineTimes_%02d_%02d", b, t);
00509             if (GetPicture(obname.Data()) == 0)
00510             {
00511                obtitle.Form("Overview all Leading edge Fine Times TRB %02d TDC %02d", b, t);
00512                TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00513                int numy = 4;
00514                int numx = TRB_TDC3_CHANNELS / numy;
00515                if (numx * numy < (TRB_TDC3_CHANNELS))
00516                   numx++;
00517                pic->SetDivision(numy, numx);
00518                for (int ch = 0; ch < TRB_TDC3_CHANNELS; ch++)
00519                {
00520                   int nx = (ch) / numy;
00521                   int ny = (ch) % numy;
00522                   pic->Pic(ny, nx)->AddObject(hLeadingFine[b][t][ch]);
00523                   pic->Pic(ny, nx)->SetFillAtt(6, 3001); // pattern
00524                   pic->Pic(ny, nx)->SetLineAtt(6, 1, 1);
00525                   //pic->Pic(ny, nx)->SetLogScale(1);
00526                }
00527                AddPicture(pic, dirname.Data());
00528             }
00529 
00531             if (fPar->processTrailing) {
00532                obname.Form("TrailingFineTimes_%02d_%02d", b, t);
00533                if (GetPicture(obname.Data()) == 0)
00534                {
00535                   obtitle.Form("Overview all Trailing edge Fine Times TRB %02d TDC %02d", b, t);
00536                   TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00537                   int numy = 4;
00538                   int numx = TRB_TDC3_CHANNELS / numy;
00539                   if (numx * numy < (TRB_TDC3_CHANNELS))
00540                      numx++;
00541                   pic->SetDivision(numy, numx);
00542                   for (int ch = 0; ch < TRB_TDC3_CHANNELS; ch++)
00543                   {
00544                      int nx = (ch) / numy;
00545                      int ny = (ch) % numy;
00546                      pic->Pic(ny, nx)->AddObject(hTrailingFine[b][t][ch]);
00547                      pic->Pic(ny, nx)->SetFillAtt(6, 3001); // pattern
00548                      pic->Pic(ny, nx)->SetLineAtt(6, 1, 1);
00549                      //pic->Pic(ny, nx)->SetLogScale(1);
00550                   }
00551                   AddPicture(pic, dirname.Data());
00552                }
00553             }
00554          }
00555 
00556       } // for t - through TDCs
00557 
00558    }    // for b - through boards
00559    /* -------------------------------------------------------------------------------------- */
00560 
00562    ExecuteScript("set_TrbCond.C");
00563 
00565    TGo4Analysis::Instance()->ProtectObjects ("TRB/TimeCalibration", "+C");
00566 }
00567 
00568 
00569 TTrbProc::~TTrbProc ()
00570 {
00571 }
00572 
00573 void TTrbProc::InitEvent (TGo4EventElement* outevnt)
00574 {
00579    if (fOutEvent == 0)
00580    {
00581       TCBMBeamtimeEvent* btevent = dynamic_cast <TCBMBeamtimeEvent*> (outevnt);
00582       if (btevent)
00583          fOutEvent = dynamic_cast <TTrbEvent*> (btevent->GetSubEvent("TRB"));
00584       else
00585          fOutEvent = dynamic_cast <TTrbEvent*> (outevnt);
00586 
00587       if (fOutEvent==0)
00588          GO4_STOP_ANALYSIS_MESSAGE ("**** TTrbProc: Fatal error: output event is not a TTrbEvent!!! STOP GO4");
00589    }
00590 }
00591 
00592 void TTrbProc::ProcessSubevent (TGo4MbsSubEvent* psubevt)
00593 {
00594 #if __GO4BUILDVERSION__ > 40500
00595    Bool_t oldevent = IsKeepInputEvent();
00596    SetKeepInputEvent(kFALSE);   
00597    if(oldevent) return;         
00598 #endif
00599 
00600    if (psubevt->GetProcid() != roc::proc_TRBEvent) return;
00601 
00602    //   printf("Start TRB processing\n");
00603 
00604    for (Int_t b=0; b<TRB_TDC3_NUMBOARDS; ++b)
00605       for (Int_t t=0; t<TRB_TDC3_NUMTDC; ++t) fNumHitsSelected[b][t] = 0;
00606 
00607 
00608    Int_t *pdata = psubevt->GetDataField();
00609    Int_t lwords = psubevt->GetIntLen();
00610    if (lwords * sizeof(Int_t) < sizeof(Trb_Event))
00611    {
00612       GO4_STOP_ANALYSIS_MESSAGE ("Problem: subevent length 0x%x not big enough for hadaq event header!!", lwords*sizeof(Int_t));
00613    }
00614 
00615    char* cursor = (char*) pdata;
00616    char* datastart = (char*) pdata;
00617    EPRINT ("*** Start cursor %p\n", cursor);
00618 
00619    // reset times at the beginning - trigger time can only be assigned once,
00620    // but used for processing of many TRB3 events
00621    ResetTDCV3TriggerTimes();
00622 
00623    // printf("Start TRB subevent\n");
00624 
00625    Int_t bufbytes = lwords * sizeof(Int_t);
00626    while (bufbytes > 0)
00627    {
00629       Trb_Event* hadevent = (Trb_Event*) (cursor);
00630       EPRINT ("*** Found hadaq event #0x%x, full id=0x%x , size 0x%x\n", hadevent->GetSeqNr(), hadevent->GetId(), (unsigned) hadevent->GetSize());
00631 
00632       cursor += sizeof(Trb_Event);
00633       int evlen = hadevent->GetSize();
00634       evlen -= sizeof(Trb_Event);
00635       bufbytes -= sizeof(Trb_Event);
00636 
00637       int sub = 0;      
00638 
00639       fCurrentTriggerType = 0;
00640 
00641       while (evlen > 0)
00642       {
00643          Trb_Subevent* hadsubevent = (Trb_Subevent*) (cursor);
00644          EPRINT ("*** --- hadaq subevent no.0x%x of size 0x%x, decoding=0x%x, id=0x%x, trig=0x%x, swapped=0x%x \n",
00645                sub, (unsigned) hadsubevent->GetSize(), hadsubevent->GetDecoding(), hadsubevent->GetId(), hadsubevent->GetTrigNr(), hadsubevent->IsSwapped());
00646 
00647 
00648          // this is code to check sequence id of TRB events and discover lost data
00649 
00650          unsigned subid = (hadsubevent->GetTrigNr() >> 8) & 0xffff;
00651 
00652          if (fLastTriggerId==0) {
00653             fLostTriggerCnt = 0;
00654             fTakenTriggerCnt = 0;
00655          } else {
00656             unsigned diff = (subid - fLastTriggerId) & 0xffff;
00657             if ((diff > 0x8000) || (diff==0)) {
00658                // ignore this, most probable it is some mistake
00659                if (fPar->printErrors)
00660                   printf("STRANGE TRB subevent diff %u from %x till %x\n", diff, fLastTriggerId, subid);
00661             } else
00662             if (diff==1) {
00663                fTakenTriggerCnt++;
00664             } else {
00665                fLostTriggerCnt+=(diff-1);
00666                if (fPar->printErrors)
00667                    printf("LOST %u packets from %x till %x\n", diff-1, fLastTriggerId, subid);
00668             }
00669          }
00670 
00671          fLastTriggerId = subid;
00672 
00673 //         printf("*** --- hadaq subevent sequence id trig=0x%x\n",
00674 //                 );
00675 
00676          hSubevSize->Fill(hadsubevent->GetSize());
00677 
00678          ProcessTrbSubevent(hadsubevent);
00679 
00680          cursor += hadsubevent->GetSize();
00681          evlen -= hadsubevent->GetSize();
00682          bufbytes -= hadsubevent->GetSize();
00683 
00685          while (((((long) cursor - (long) datastart)) % 8) != 0)                
00686          {
00687             EPRINT ("*** --- skipping subevent padding byte..\n");
00688             cursor++;
00689             evlen--;
00690             bufbytes--;
00691          }
00692          sub++;
00693       }
00694    }
00695 
00696    if (fTakenTriggerCnt + fLostTriggerCnt > 100) {
00697       double lostratio = 1.*fLostTriggerCnt / (fTakenTriggerCnt + fLostTriggerCnt + 0.);
00698       hLostRate->Fill(lostratio);
00699       fTakenTriggerCnt = 0;
00700       fLostTriggerCnt = 0;
00701    }
00702 
00703    for (Int_t b=0; b<TRB_TDC3_NUMBOARDS; ++b)
00704       for (Int_t t=0; t<TRB_TDC3_NUMTDC; ++t) {
00705          TH1* h1 = GetTriggerNumber() < 8 ? hEventMultipl[b][t] : hPulserMultipl[b][t];
00706          if (h1) h1->Fill(fNumHitsSelected[b][t]);
00707       }
00708 }
00709 
00710 void TTrbProc::ResetTDCV3TriggerTimes()
00711 {
00713    fCanAssignTrigger = true;
00714 
00715    for (Int_t i=0; i<TRB_TDC3_NUMBOARDS; i++)
00716       for (Int_t j=0; j<TRB_TDC3_NUMTDC; j++)
00717       {
00718          fLastTrigTime[i][j][0] = 0.;     // For leading
00719          fLastTrigTime[i][j][1] = 0.;     // For trailing
00720       }
00721 }
00722 
00723 
00724 
00725 void TTrbProc::ProcessTrbSubevent (Trb_Subevent* hadsubevent)
00726 {
00727    if (hadsubevent == 0) return;
00728 
00729    switch (hadsubevent->GetId())
00730    {
00731    case 0x8000:
00732    case 0x8001:
00733 
00734       fCurrentTriggerType = 0;
00735 
00736       if (fPar->printEvent) DumpData(hadsubevent);
00737       ProcessTDCV3 (hadsubevent);
00738 
00739       if (fSubeventStatus != 0x00000001)
00740          if (fPar->printErrors)
00741             printf ("!!! found invalid subevent data, status:0x%x \n", fSubeventStatus);
00742 
00743       if ((fCurrentTriggerType & 0x3) == 1)  {
00744          fCanAssignTrigger = true;
00745       } else {
00746          fCanAssignTrigger = false;
00747       }
00748 
00749       for (int brd=0; brd<TRB_TDC3_NUMBOARDS; ++brd)
00750       {
00751          if (TTrbEvent::AssertTRB(brd))
00752             EvaluateTDCV3Data(brd);
00753          fRawHits[brd].clear();
00754       }
00755 
00756       break;
00757 
00758    default:
00759       if (fPar->printEvent) DumpData (hadsubevent);
00760       break;
00761    };
00762 
00763    fPar->fEventCount++;
00764 }
00765 
00766 void TTrbProc::ProcessTDCV3 (Trb_Subevent* hadsubevent)
00767 {
00768    unsigned ix = 0;                             // cursor
00769 
00770    int data;                                    // 32 bits
00771 
00772    unsigned tdcLen = 0;         // 16 bits - tdc header
00773    unsigned curTRB = 0;                 // 4 bits - tdc header
00774    unsigned curTDC = 0;                 // 4 bits - tdc header
00775 
00776    unsigned tmpBits;                    // 3 bits
00777 
00778    unsigned err = 0;                    // 16 bits - data header
00779 
00780    unsigned curChan = 0;                // 7 bits - data word
00781    unsigned tfine = 0;                  // 10 bits - data word
00782    bool isrising = false;       // 1 bit - data word
00783    unsigned tcoarse = 0;                // 11 bits - data word
00784 
00785    int res = 0;                         // 29 bits - reserved word
00786    int curEpoch = -1;           // 28 bits - epoch word (signed int must be enough. So I use -1 for the uninitialized value)
00787 
00790    unsigned trbSubEvSize = hadsubevent->GetSize() / 4 - 4;
00791 
00792    while (ix < trbSubEvSize)
00793    {
00795       data = hadsubevent->Data(ix++);
00796 
00797       // ===========  this is header for TDC, build inside the TRB3 =================
00798       if (((data >> 8) & 0xFF) == 0xB0) {
00799          // do that ever you want
00800          int curBrd = (data  & 0xFF);
00801          tdcLen = ((data >> 16) & 0xFFFF);
00802          EPRINT ("***  --- tdc header: 0x%08x, TRB3-buildin TDC-FPGA brd=%d, size=%d  IGNORED\n", data, curBrd, tdcLen);
00803          ix+=tdcLen;
00804          continue;
00805       }
00806 
00808       if (((data >> 8) & 0xFF) == 0xC0)
00809       {
00810          curTDC = 0;  // must be elimenated
00811          curTRB = (data  & 0xFF);
00812          tdcLen = ((data >> 16) & 0xFFFF);
00813 
00814          hTDCDataVolume->Fill(curTRB,tdcLen);
00815 
00816          EPRINT ("***  --- tdc header: 0x%08x, brd=%d, size=%d\n", data, curTRB, tdcLen);
00817 
00818          if (!TTrbEvent::AssertTRB(curTRB)) {
00819             EPRINT ("*** --- Found package with TRB number %d that is not configured. Skipping.\n", curTRB);
00820             ix += tdcLen;
00821             continue;
00822          }
00823 
00824          hTriggerCount[curTRB][curTDC]->Fill(5);                
00825          hTriggerCount[curTRB][curTDC]->Fill(0);                
00826          hTrbTriggerCount->Fill(2);                                     
00827          hTrbTriggerCount->Fill(0);                                     
00828 
00830          while (tdcLen-- > 0)
00831          {
00833             data = hadsubevent->Data(ix++);
00834 
00836             if (((data >> 31) & 0x1) == 0x1)
00837             {
00838                res = ((data >> 29) & 0x3);
00839                curChan = ((data >> 22) & 0x7F);
00840                tcoarse = (data & 0x7FF);
00841                tfine = ((data >> 12) & 0x3FF);
00842                isrising = (((data >> 11) & 0x1) == 0x1);
00843 
00844                EPRINT("***  --- tdc data: 0x%08x  time: %12.2f  isrising: %d  chan: 0x%x  tc: 0x%03x  tf: 0x%03x  reserved: 0x%x\n",
00845                      data, curEpoch*5.*2048 + tcoarse*5. + tfine*0.011, isrising, curChan,  tcoarse, tfine , res );
00846 
00847                if (curEpoch<0) {
00848                   EPRINT("*** LOST EPOCH - ignore next data ***\n");
00849                } else
00850                   if (tcoarse > 0x7ff) {
00851                      EPRINT("*** SUSPECTED coarse counter %x - IGNORE ***\n", tcoarse);
00852                      curEpoch = -1;
00853                   } else
00854                      if (TTrbEvent::AssertTDC(curTRB, curTDC) && (curChan < TRB_TDC3_CHANNELS))
00855                      {
00856                         // we do not check if output event for specified TRB board exists
00857                         // this will be done when data will be filled to the output event
00858 
00859                         /*
00860                                            TTrbData* theTRB = dynamic_cast <TTrbData*> (fOutEvent->getEventElement(curTRB));
00861                                                 if(theTRB==0) {
00862                                                         cout << "**** TTrbProc: Skipping subevent with not configured TRB id "
00863                                                                 << curTDC << ", please check trb output event setup!" << endl;
00864                                                         return;
00865                                                 }
00866                                                 theTRB->SetValid(kTRUE);        //! need this to enable clearing!
00867                          */
00868 
00869                         // Here we can put a check that if curEpoch == -1 then something is wrong
00870                         // because each event must contain an epoch counter
00871                         // Otherwise we have to make a buffer for data packages until the first epoch is found in the event
00872 
00874                         TTrbRawHit theRawHit (curTDC, curChan, isrising, curEpoch, tcoarse, tfine);
00875 
00876                         /*
00877                                                 EPRINT ("Raw hit push_back:\t\ttdc=%d,\tch=%d,\tisrising=%d,\tepoch=%d,\tcoarse=%d,\tfine=%d\n",
00878                                                                 curTDC, curChan, isrising, curEpoch, tcoarse, tfine);
00879                          */
00880                         fRawHits[curTRB].push_back (theRawHit);
00883                         if (isrising)
00884                            hTriggerCount[curTRB][curTDC]->Fill(2);              
00885                         else
00886                            hTriggerCount[curTRB][curTDC]->Fill(3);              
00887                         hTriggerCount[curTRB][curTDC]->Fill(0);                 
00888                         hTrbTriggerCount->Fill(2);                              
00889                         hTrbTriggerCount->Fill(0);                              
00890 
00891                         curEpoch = -1; // reset epoch marker - may be changed in next firmware
00892                      }
00893                      else
00894                      {
00895                         GO4_STOP_ANALYSIS_MESSAGE ("Data index out of range error trb:0x%x tdc:0x%x channel:0x%x !!!", curTRB, curTDC, curChan);
00896                      }
00897 
00898                continue; // next word in tdc data
00899             }
00900 
00901             tmpBits = ((data >> 29) & 0x7);
00902 
00903             switch (tmpBits) {
00904             case 0x1: {  
00905                err = (data & 0xFFFF);
00906                res = ((data >> 16) & 0x1FFF);
00907                EPRINT ("***  --- tdc head: 0x%08x, reserved=0x%x, errorbits=0x%x\n", data, res, err);
00908                hTriggerCount[curTRB][curTDC]->Fill(5);          
00909                hTriggerCount[curTRB][curTDC]->Fill(0);          
00910                hTrbTriggerCount->Fill(2);                       
00911                hTrbTriggerCount->Fill(0);                       
00912                if (err) {
00913                   EPRINT ("!!! found error bits: 0x%x at tdc 0x%x\n", err, curTDC);
00914                   hTriggerCount[curTRB][curTDC]->Fill(1);               
00915                }
00916                break;
00917             }
00918 
00919             case 0x3: { 
00920                res = ((data >> 28) & 0x1);
00921                curEpoch = (data & 0xFFFFFFF);
00922                EPRINT("***  --- tdc epch: 0x%08x  time: %12.2f  reserved=0x%x, epoch=0x%x\n", data, curEpoch*5.*2048, res, curEpoch);
00923 
00924                hEpoch[curTRB][curTDC]->Fill(curEpoch);
00925 
00926                hTriggerCount[curTRB][curTDC]->Fill(4);          
00927                hTriggerCount[curTRB][curTDC]->Fill(0);          
00928                hTrbTriggerCount->Fill(2);                       
00929                hTrbTriggerCount->Fill(0);                       
00930                break;
00931             }
00932 
00933             case 0x2: { 
00934                UShort_t bits = (data & 0xFFFFFF);
00935                UShort_t mode = ((data >> 24) & 0x1F);
00936                EPRINT ("***  --- debug word: 0x%08x, mode=0x%x, bits=0x%x\n", data, mode, bits);
00937                hTriggerCount[curTRB][curTDC]->Fill(6);          
00938                hTriggerCount[curTRB][curTDC]->Fill(0);          
00939                hTrbTriggerCount->Fill(2);                       
00940                hTrbTriggerCount->Fill(0);                       
00941                continue;
00942             }
00943 
00944             case 0x0: { 
00945                res = (data & 0x1FFFFFFF);
00946                EPRINT ("***  --- reserved word: 0x%08x, reserved=0x%x\n", data, res);
00947                hTriggerCount[curTRB][curTDC]->Fill(7);          
00948                hTriggerCount[curTRB][curTDC]->Fill(0);          
00949                hTrbTriggerCount->Fill(2);                       
00950                hTrbTriggerCount->Fill(0);                       
00951                break;
00952             }
00953 
00954             default: printf("Unknows bits 0x%x in header\n", tmpBits);
00955             }
00956          }      // end of loop inside the TDC data
00957 
00958          continue; // go to next block
00959       } // end of if TDC header
00960 
00961 
00963       if ((data & 0xFFFF) == 0x8000) {
00964          unsigned centHubLen = ((data >>16) & 0xFFFF);
00965          EPRINT ("***  --- CTS header: 0x%x, size=%d\n", data, centHubLen);
00966          hTrbTriggerCount->Fill(5);                             
00967          hTrbTriggerCount->Fill(0);                             
00968 
00969 
00970          data = hadsubevent->Data(ix++);
00971          unsigned trigtype = (data & 0xFFFF);
00972          unsigned trignum = (data >> 16) & 0xF;
00973          EPRINT("***  --- CTS trigtype: 0x%x, trignum=0x%x\n", trigtype, trignum);
00974          fCurrentTriggerType = trigtype;
00975 
00976 
00977          // printf("trigtype = %x trignum\n", trigtype & 0x3);
00978          centHubLen--;
00979 
00980          while (centHubLen-- > 1) {
00982             data = hadsubevent->Data(ix++);
00983             EPRINT ("***  --- CTS word: 0x%x, skipping\n", data);
00984             hTrbTriggerCount->Fill(5);                  
00985             hTrbTriggerCount->Fill(0);                  
00986          }
00988          data = hadsubevent->Data(++ix);
00989          int syncNum = (data & 0xFFFFFF);
00990          EPRINT ("***  --- CTS word - SYNC number: 0x%x, num=%d\n", data, syncNum);
00991          hTrbTriggerCount->Fill(5);                     
00992          hTrbTriggerCount->Fill(0);                     
00993          continue;
00994       }
00995 
00997       if ((data & 0xFFFF) == 0x5555) {
00998          unsigned centHubLen = ((data >>16) & 0xFFFF);
00999          EPRINT ("***  --- dummy header: 0x%x, size=%d\n", data, centHubLen);
01000          hTrbTriggerCount->Fill(4);                             
01001          hTrbTriggerCount->Fill(0);                             
01002          while (centHubLen-- > 0)
01003          {
01005             data = hadsubevent->Data(ix++);
01006             EPRINT ("***  --- status word: 0x%x\n", data);
01007             hTrbTriggerCount->Fill(4);                  
01008             hTrbTriggerCount->Fill(0);                  
01009             fSubeventStatus = data;
01010             if (fSubeventStatus != 0x00000001)
01011                hTrbTriggerCount->Fill(1);               
01012          }
01013       }
01014    }
01015 }
01016 
01017 void TTrbProc::EvaluateTDCV3Data (UShort_t board)
01018 {
01019    unsigned int i;
01020    unsigned int refchCounter[TRB_TDC3_NUMTDC];
01021    unsigned int datachCounter[TRB_TDC3_NUMTDC];
01022 
01024    UShort_t refbinindex[2*TRB_TDC3_NUMTDC];
01025    for (i=0; i<TRB_TDC3_NUMTDC*2; i++) refbinindex[i] = 0;
01026 
01028    if (fPar->generalCalibration && fPar->continuousCalibration)
01029       GO4_STOP_ANALYSIS_MESSAGE ("Parameter Error: General Calibration and Continious Calibration can't be activated together!");
01030 
01032    TTrbData* theTRB = dynamic_cast<TTrbData*> (fOutEvent->getEventElement(board));
01033    if (theTRB == 0)
01034    {
01035       TGo4Log::Error("TTrbProc: Skipping subevent with not configured TRB id %d, please check trb output event setup!", board);
01036       return;
01037    }
01038 
01040    if (fSubeventStatus != 0x00000001)
01041    {
01042       EPRINT ("Skipping event at EvaluateTDCV3Data because of the error status.\n");
01043       theTRB->SetValid (kFALSE);
01044       return;
01045    }
01046 
01047    theTRB->SetValid(kTRUE);
01048 
01049    TTrbRawHit* refHit[TRB_TDC3_NUMTDC];
01050    UShort_t curTDC;
01051    UShort_t curChannel;
01052    TTrbRawHit* curHit;
01053 
01055    Bool_t calibNeeded = IsAnyCalibration() && fPar->fEventCount && ((fPar->fEventCount % fPar->calibrationPeriod) == 0);
01056 
01060 
01062    for (i=0; i<TRB_TDC3_NUMTDC; i++) {
01063       refHit[i] = 0;
01064       refchCounter[i] = 0;
01065       datachCounter[i] = 0;
01066    }
01067 
01068 
01071    for (i=0; i<fRawHits[board].size(); i++)
01072    {
01073       curHit = &fRawHits[board].at(i);
01074       curChannel = curHit->GetChannel();
01075       curTDC = curHit->GetTDC();
01076 
01077       if ((curChannel == fPar->refChannel) && fCanAssignTrigger) {
01078          refchCounter[curTDC]++;
01079          refHit[curTDC] = curHit;
01080          if (calibNeeded)                       
01081             DoCalibration (board, curTDC, curChannel, fPar->generalCalibration, fPar->continuousCalibration);
01082       } else {
01083          datachCounter[curTDC]++;
01084       }
01085    }
01086 
01089    Bool_t everythingIsFine = kTRUE;
01090    for (i=0; i<TRB_TDC3_NUMTDC; i++)
01091    {
01092       if (!TTrbEvent::AssertTDC(board,i)) continue;
01093 
01094       // if trigger time already assigned - ignore any other data in the channel
01095       if ((fLastTrigTime[board][i][0]!=0) || (fLastTrigTime[board][i][1]!=0)) continue;
01096 
01097       if ((datachCounter[i] != 0) && (refchCounter[i] != 1))
01098          everythingIsFine = kFALSE;
01099    }
01100 
01101    if (everythingIsFine)
01102    {
01103       EPRINT ("Perfect! We have only one hit in the reference (trigger time) channel.\n");
01104    }
01105    else
01106    {
01107       EPRINT ("!!! Very bad! There is no data in the reference channel of some TDC or\n");
01108       EPRINT ("!!! we have too much data in the reference (trigger time) channel.\n");
01109       EPRINT ("!!! No further processing - skipping the whole event.\n");
01110       return;
01111    }
01112 
01116    Bool_t flagComputeDiff[TRB_TDC3_NUMTDC];
01117 
01118    for (i=0; i<TRB_TDC3_NUMTDC; i++)
01119    {
01120       flagComputeDiff[i] = kFALSE;
01121 
01122       // if trigger time already assigned - use it
01123       if ((fLastTrigTime[board][i][0]!=0) || (fLastTrigTime[board][i][1]!=0)) {
01124          flagComputeDiff[i] = kTRUE;
01125          continue;
01126       }
01127 
01128       if (refHit[i] == 0) {
01129          // can put some error output, for the moment ignore
01130          continue;
01131       }
01132 
01133       if (!TTrbEvent::AssertTDC(board,i)) continue;
01134 
01135       if (WithoutCalibration()) {
01136          flagComputeDiff[i] = kTRUE;
01137 
01138          fLastTrigTime[board][i][0] =
01139                1.*refHit[i]->GetLEpoch() * TRB_TDC3_EPOCHUNIT +
01140                1.*refHit[i]->GetLCTime() * TRB_TDC3_COARSEUNIT -
01141                GetLinearFineCalibration(refHit[i]->GetLFTime());
01142          refbinindex[i] = refHit[i]->GetLFTime();
01143 
01144          if (fPar->processTrailing) {
01145             fLastTrigTime[board][i][1] =
01146                   1.*refHit[i]->GetTEpoch() * TRB_TDC3_EPOCHUNIT +
01147                   1.*refHit[i]->GetTCTime() * TRB_TDC3_COARSEUNIT -
01148                   GetLinearFineCalibration(refHit[i]->GetTFTime());
01149             refbinindex[i+TRB_TDC3_NUMTDC] = refHit[i]->GetTFTime();
01150          }
01151 
01152          continue;
01153       }
01154 
01155 
01156       if (fbHasCalibration[board][i][fPar->refChannel])
01157       {
01158          flagComputeDiff[i] = kTRUE;
01159          //                     EPRINT ("!!! Reference channel for TDC %d calibrated.\n", i);
01160 
01162          fLastTrigTime[board][i][0] =
01163                1.*refHit[i]->GetLEpoch() * TRB_TDC3_EPOCHUNIT +
01164                1.*refHit[i]->GetLCTime() * TRB_TDC3_COARSEUNIT +
01165                hCalBinTime[board][i][fPar->refChannel]->GetBinContent(refHit[i]->GetLFTime() + 1);
01166          refbinindex[i] = refHit[i]->GetLFTime();
01167 
01169          if (fPar->processTrailing) {
01170 
01171             fLastTrigTime[board][i][1] =
01172                   1.*refHit[i]->GetTEpoch() * TRB_TDC3_EPOCHUNIT +
01173                   1.*refHit[i]->GetTCTime() * TRB_TDC3_COARSEUNIT +
01174                   hCalBinTime[board][i][fPar->refChannel]->GetBinContent(refHit[i]->GetTFTime() + 1);
01175             refbinindex[i+TRB_TDC3_NUMTDC] = refHit[i]->GetTFTime();
01176          }
01177       }
01178    }
01179 
01180    //   printf("Place 3 %u\n", fRawHits[board].size());
01181 
01182 
01184    for (i=0; i<fRawHits[board].size(); i++)
01185    {
01186       curHit = &fRawHits[board].at(i);
01187       curTDC = curHit->GetTDC();
01188       curChannel = curHit->GetChannel();
01189 
01190       if (curHit->IsLeading()) {
01191 
01192          Double_t curVal = curHit->GetLCTime () * TRB_TDC3_COARSEUNIT;
01193          hLeadingCoarseAll[board][curTDC]->Fill(curVal);
01194 
01195          // TODO: check if condition required
01196          if (cLeadingCoarseTimeGate[board][curTDC]->Test(curVal))
01197          {
01198             if (hLeadingCoarse[board][curTDC][curChannel])
01199                hLeadingCoarse[board][curTDC][curChannel]->Fill(curVal);
01200 
01201             if (hLeadingCoarseAllChans[board][curTDC])
01202                hLeadingCoarseAllChans[board][curTDC]->Fill(curChannel, curVal);
01203 
01204             if (hChannelCount[board][curTDC])
01205                hChannelCount[board][curTDC]->Fill(curChannel);
01206          }
01207 
01209          UShort_t cur_fcnt = curHit->GetLFTime ();
01210          hLeadingFineAll[board][curTDC]->Fill (cur_fcnt);
01211 
01212          // TODO: check if condition required
01213          if (cLeadingFineTimeGate[board][curTDC]->Test(cur_fcnt))
01214          {
01215             if (hLeadingFine[board][curTDC][curChannel])
01216                hLeadingFine[board][curTDC][curChannel]->Fill(cur_fcnt);
01217 
01218             if (hLeadingFineAllChans[board][curTDC])
01219                hLeadingFineAllChans[board][curTDC]->Fill(curChannel, cur_fcnt);
01220 
01221             if (hLeadingFineBuffer[board][curTDC][curChannel])
01222                hLeadingFineBuffer[board][curTDC][curChannel]->Fill(cur_fcnt);
01223          }
01224       }
01225 
01226 
01227       if (fPar->processTrailing && curHit->IsTrailing()) {
01229          Double_t curVal = curHit->GetTCTime () * TRB_TDC3_COARSEUNIT;
01230          hTrailingCoarseAll[board][curTDC]->Fill(curVal);
01231 
01232          if (cTrailingCoarseTimeGate[board][curTDC]->Test(curVal))
01233          {
01234             if (hTrailingCoarse[board][curTDC][curChannel])
01235                hTrailingCoarse[board][curTDC][curChannel]->Fill(curVal);
01236 
01237             if(hTrailingCoarseAllChans[board][curTDC])
01238                hTrailingCoarseAllChans[board][curTDC]->Fill(curChannel, curVal);
01239 
01240             if(hChannelCount[board][curTDC])
01241                hChannelCount[board][curTDC]->Fill(curChannel);
01242          }
01243 
01245          UShort_t cur_fcnt = curHit->GetTFTime();
01246          hTrailingFineAll[board][curTDC]->Fill(cur_fcnt);
01247 
01248          if (cTrailingFineTimeGate[board][curTDC]->Test(cur_fcnt))
01249          {
01250             if (hTrailingFine[board][curTDC][curChannel])
01251                hTrailingFine[board][curTDC][curChannel]->Fill(cur_fcnt);
01252             if (hTrailingFineAllChans[board][curTDC])
01253                hTrailingFineAllChans[board][curTDC]->Fill(curChannel, cur_fcnt);
01254             if (hTrailingFineBuffer[board][curTDC][curChannel])
01255                hTrailingFineBuffer[board][curTDC][curChannel]->Fill(cur_fcnt);
01256          }
01257       }
01258 
01260       //  Should we skip it? For a moment, keep it
01261       //                if (curChannel == fPar->refChannel) {
01262       //                        EPRINT ("Skipping computing difference of the reference channel itself.\n");
01263       //                        continue;
01264       //                }
01265 
01268       if (calibNeeded)
01269       {
01270          //                     EPRINT ("Calibrating %d TDC %d channel\n", curTDC, curChannel);
01271          DoCalibration (board, curTDC, curChannel, fPar->generalCalibration, fPar->continuousCalibration);
01272       }
01273 
01274       if (!flagComputeDiff[curTDC])
01275       {
01276          //                     EPRINT ("Falling out\n");
01277          continue;
01278       }
01279 
01281       //                if (fPar->refChannel < 0 || fPar->refChannel > TRB_TDC3_CHANNELS) continue;
01282 
01283       TTrbData* refTRB = dynamic_cast<TTrbData*> (fOutEvent->getEventElement(board));
01284       if (refTRB == 0)
01285       {
01286          continue;
01287          // cout << "**** TTrbProc: Skipping subevent with not configured reference TRB id " << rboard << ", please check trb output event setup!" << endl;
01288          // return;
01289       }
01290 
01292       UShort_t binindex = 0;
01293       Double_t fine_cal = 0.;
01294       Double_t curFull = 0.;
01295 
01297 
01299       Double_t deltaT = 0.;
01300 
01301 
01302       if (curHit->IsLeading()) {
01304          binindex = curHit->GetLFTime();
01305 
01306          if (fbHasCalibration[board][curTDC][curChannel])
01307             fine_cal = hCalBinTime[board][curTDC][curChannel]->GetBinContent(binindex + 1);
01308          else
01309             fine_cal = GetLinearFineCalibration(binindex);
01310 
01311          curFull = 1.*curHit->GetLEpoch() * TRB_TDC3_EPOCHUNIT +
01312                1.*curHit->GetLCTime() * TRB_TDC3_COARSEUNIT - fine_cal;
01313 
01314 
01316          deltaT = curFull - fLastTrigTime[board][curTDC][0];
01317          curHit->SetLeadingTimeCorr(deltaT);
01318 
01320          hTriggerCount[board][curTDC]->Fill(curChannel + 10);     
01321 #ifdef CREATEMAPS
01322          hLeadingCorrelFine[board][curTDC][curChannel]->Fill(binindex, refbinindex[curTDC]);
01323 #endif // CREATEMAPS
01324 
01325          if (hLeadingDeltaCal[board][curTDC][curChannel])
01326             hLeadingDeltaCal[board][curTDC][curChannel]->Fill(deltaT);
01327 
01328          if (hLeadingDeltaCalAll[board][curTDC] && (curChannel>0))
01329             hLeadingDeltaCalAll[board][curTDC]->Fill(deltaT);
01330 
01331          if (hLeadingDeltaCalAllFine[board][curTDC] && (curChannel>0))
01332             hLeadingDeltaCalAllFine[board][curTDC]->Fill(deltaT);
01333 
01335          if (cLeadingDeltaTimeGate[board][curTDC]->Test(deltaT)) {
01336             TTrbOutputHit outHit(curTDC, curChannel, 1, curFull, deltaT);
01337             theTRB->fHits.push_back (outHit);
01338             fNumHitsSelected[board][curTDC]++;
01339          }
01340       }
01341 
01342       if (fPar->processTrailing && curHit->IsTrailing()) {
01344          binindex = curHit->GetTFTime();
01345 
01346          if (fbHasCalibration[board][curTDC][curChannel])
01347             fine_cal = hCalBinTime[board][curTDC][curChannel]->GetBinContent(binindex + 1);
01348          else
01349             fine_cal = GetLinearFineCalibration(binindex);
01350 
01351          curFull = 1.*curHit->GetTEpoch() * TRB_TDC3_EPOCHUNIT +
01352                1.*curHit->GetTCTime() * TRB_TDC3_COARSEUNIT - fine_cal;
01353 
01355          deltaT = curFull - fLastTrigTime[board][curTDC][1];
01356          curHit->SetTrailingTimeCorr (deltaT);
01357 
01359          hTriggerCount[board][curTDC]->Fill(curChannel + 10);     
01360 #ifdef CREATEMAPS
01361          hTrailingCorrelFine[board][curTDC][curChannel]->Fill(binindex, refbinindex[curTDC+TRB_TDC3_NUMTDC]);
01362 #endif // CREATEMAPS
01363 
01364          hTrailingDeltaCal[board][curTDC][curChannel]->Fill(deltaT);
01365          hTrailingDeltaCalAll[board][curTDC]->Fill(deltaT);
01366 
01368          //TODO implement
01369       }
01370 
01371    }    // loop through the vector of hits
01372 }
01373 
01374 void TTrbProc::DoCalibration (UShort_t board, UShort_t tdc, UShort_t ch, Bool_t generalcal, Bool_t contcal)
01375 {
01376    TH1* hfinecal = 0;
01377 
01379    if (generalcal)
01380    {
01381       hfinecal = (TH1*) hLeadingFine[board][tdc][ch]->Clone("calbuf");
01382       if (fPar->processTrailing)
01383          hfinecal->Add(hTrailingFine[board][tdc][ch]);
01384    }
01385    else if (contcal)
01386    {
01387       hfinecal = (TH1*) hLeadingFineBuffer[board][tdc][ch]->Clone("calbuf");
01388       if (fPar->processTrailing)
01389          hfinecal->Add(hTrailingFineBuffer[board][tdc][ch]);
01390    }
01391    else
01392    {
01393       return;
01394    }
01395 
01396    UInt_t sum = hfinecal->GetEntries();
01397    if (sum < fPar->calibrationEntries)
01398    {
01399       //                cout << "DO CALIBRATION for("<<board<<","<<tdc<<","<<ch<<"): Calibration histogram has only:"
01400       //                        <<sum<<"entries, needs at least "<<fPar->calibrationEntries<<"! At Event:"<<fPar->fEventCount << endl;
01401       delete hfinecal;
01402       return;
01403    }
01404    else
01405    {
01406       //                cout << "DOING CALIBRATION for("<<board<<","<<tdc<<","<<ch<<") at event"<< fPar->fEventCount
01407       //                        <<": Calibration histogram with "<<sum<<"entries!" << endl;
01408    }
01409 
01410    for (int fb=0; fb<TRB_TDC3_FINEBINS; ++fb)
01411    {
01412       Double_t binwidth = 1.;
01413       Double_t binhits = hfinecal->GetBinContent(fb + 1);
01414       if (sum)
01415          binwidth = (TRB_TDC3_COARSEUNIT * binhits) / sum;
01416       hCalcBinWidth[board][tdc][ch]->SetBinContent(fb + 1, binwidth);
01417 
01418       Double_t calbintime = 1.;
01419       if (fb == 0)
01420          calbintime = hCalcBinWidth[board][tdc][ch]->GetBinContent(fb + 1) / 2;
01421       else
01422          calbintime = hCalBinTime[board][tdc][ch]->GetBinContent(fb)
01423          + (hCalcBinWidth[board][tdc][ch]->GetBinContent(fb) + hCalcBinWidth[board][tdc][ch]->GetBinContent(fb + 1)) / 2;
01424 
01425       hCalBinTime[board][tdc][ch]->SetBinContent(fb + 1, calbintime);
01426    }
01427 
01428    if (contcal)
01429    {
01430       hLeadingFineBuffer[board][tdc][ch]->Reset();
01431       if (fPar->processTrailing)
01432          hTrailingFineBuffer[board][tdc][ch]->Reset();
01433    }
01434 
01435    delete hfinecal;     
01436    //   cout << "Deleted hfinecal=" << hex << (int) hfinecal << dec << endl;
01437    fbHasCalibration[board][tdc][ch] = kTRUE;
01438 }
01439 
01440 void TTrbProc::DumpData (Trb_Subevent* hadsubevent)
01441 {
01442    int align = hadsubevent->Alignment();
01443    int dtype = (hadsubevent->GetDecoding() >> 8) & 0xFF;
01444 
01445    printf("*** ---  data align:%d, data type:%d\n", align, dtype);
01446 
01447    for (int ix=0; ix<(int)((hadsubevent->GetSize() - sizeof(Trb_Subevent)) / align); ix++)
01448    {
01449       printf("*** %08x\t", hadsubevent->Data(ix));
01450       if (((ix + 1) % 8) == 0)
01451          printf(("\n"));
01452    }
01453 
01454    printf("\n");
01455 }

Generated on Tue Dec 10 2013 04:52:23 for ROCsoft by  doxygen 1.7.1