Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DQRawDigits.cxx

Go to the documentation of this file.
00001 #include "DQRawDigits.h"
00002 #include "RawChip.h"
00003 
00004 #include "RawData/RawDigit.h"
00005 #include "MessageService/MsgService.h"
00006  
00007 //
00008 // $Log $
00009 //
00010 
00011 ClassImp(DQRawDigits)
00012  
00013 CVSID("$Id: DQRawDigits.cxx,v 1.4 2006/09/19 13:11:27 blake Exp $");
00014 
00015 DQRawDigits::DQRawDigits() :
00016   fTime(-1), 
00017   fBaseTime(0),
00018   fTriggerTime(-99999),
00019   fTriggerBaseTime(0),
00020   fSnarl(-1),
00021   fPreTriggerDigits(0),
00022   fPostTriggerDigits(0), 
00023   fSnarlMultiplicity(0),
00024   fSnarlPassFail(0),
00025   fRawReadout(0), 
00026   fRawDigitsList(0),
00027   fReadoutErrorList(0),
00028   fReadoutBusyList(0)
00029 {
00030   fRawReadout = new RawReadout();
00031 
00032   fRawDigitsList = new TObjArray();
00033   fReadoutErrorList = new TObjArray();
00034   fReadoutBusyList = new TObjArray();
00035 }
00036  
00037 DQRawDigits::DQRawDigits(const DQRawDigits& rhs) :
00038   TObject(rhs),
00039   fTime(rhs.fTime), 
00040   fBaseTime(rhs.fBaseTime),
00041   fTriggerTime(rhs.fTriggerTime), 
00042   fTriggerBaseTime(rhs.fTriggerBaseTime), 
00043   fSnarl(rhs.fSnarl),
00044   fPreTriggerDigits(rhs.fPreTriggerDigits),
00045   fPostTriggerDigits(rhs.fPostTriggerDigits),
00046   fSnarlMultiplicity(rhs.fSnarlMultiplicity),
00047   fSnarlPassFail(rhs.fSnarlPassFail),
00048   fRawReadout(rhs.fRawReadout),
00049   fRawDigitsList(rhs.fRawDigitsList),
00050   fReadoutErrorList(rhs.fReadoutErrorList),
00051   fReadoutBusyList(rhs.fReadoutBusyList)
00052 {
00053  
00054 }
00055    
00056 DQRawDigits::~DQRawDigits()
00057 {
00058   delete fRawReadout;
00059 
00060   fReadoutErrorList->Delete();
00061   delete fReadoutErrorList;
00062 
00063   fReadoutBusyList->Delete();
00064   delete fReadoutBusyList;
00065 
00066   fRawDigitsList->Clear();
00067   delete fRawDigitsList;
00068 }
00069 
00070 void DQRawDigits::Process(RawDaqHeader*)
00071 {
00072   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits::Process(RawDaqHeader) " << endl;  
00073 
00074 }
00075 
00076 void DQRawDigits::Process(RawDaqSnarlHeader* hdr)
00077 {
00078   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits::Process(RawDaqSnarlHeader) " << endl;
00079 
00080   fTime = hdr->GetVldContext().GetTimeStamp().GetSec();
00081   fTriggerTime = hdr->GetVldContext().GetTimeStamp().GetNanoSec();
00082   fSnarl = hdr->GetSnarl();
00083   fSnarlPassFail = 0;
00084 
00085   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits [" << fSnarl << "] [" << fTime << "|" << fTriggerTime << "] [" << fBaseTime << "|" << fTriggerBaseTime << "]" << endl;
00086 }
00087 
00088 void DQRawDigits::Process(RawDaqHeaderBlock* hdr)
00089 {
00090   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits::Process(RawDaqHeaderBlock) " << endl;  
00091 
00092   fTime = -1;
00093   fTriggerTime = -99999;
00094   fSnarl = -1;
00095   fSnarlPassFail = 0;
00096 
00097   fBaseTime = hdr->GetVldContext().GetTimeStamp().GetSec();
00098   fTriggerBaseTime = hdr->GetVldContext().GetTimeStamp().GetNanoSec();
00099 
00100   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits [" << fSnarl << "] [" << fTime << "|" << fTriggerTime << "] [" << fBaseTime << "|" << fTriggerBaseTime << "]" << endl;
00101 }
00102 
00103 void DQRawDigits::Process(RawSnarlHeaderBlock* rdb)
00104 {
00105   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits::Process(RawSnarlHeaderBlock) " << endl;
00106 
00107   fTime = rdb->GetTriggerTime().GetSec();
00108   fTriggerTime = rdb->GetTriggerTime().GetNanoSec();
00109   fSnarl = rdb->GetSnarl();
00110   fSnarlPassFail = 0;
00111   
00112   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits [" << fSnarl << "] [" << fTime << "|" << fTriggerTime << "] [" << fBaseTime << "|" << fTriggerBaseTime << "]" << endl;
00113 }
00114 
00115 void DQRawDigits::Process(RawDigitDataBlock* rdb)
00116 {
00117   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits::Process(RawDigitDataBlock) " << endl;
00118 
00119   MSG("DataQuality",Msg::kVerbose) << " DQRawDigits [" << fSnarl << "] [" << fTime << "|" << fTriggerTime << "] [" << fBaseTime << "|" << fTriggerBaseTime << "]" << endl;
00120   MSG("DataQuality",Msg::kVerbose) << " Subtracted time (+" << fTime-fBaseTime << ",+" << fTriggerTime-fTriggerBaseTime << ")" << endl;
00121   MSG("DataQuality",Msg::kVerbose) << " Number of Raw Digits [" << rdb->GetNumberOfDigits() << "]" << endl;
00122 
00123   Int_t i,j,k;
00124   Int_t chid;
00125   
00126   VldContext vldc = (VldContext)(rdb->GetVldContext());
00127   
00128   fPreTriggerDigits = 0;
00129   fPostTriggerDigits = 0;
00130   fSnarlMultiplicity = 0;
00131   fSnarlPassFail = 0;
00132 
00133   // Reset the lists of busy/error chips
00134   fReadoutErrorList->Delete();
00135   fReadoutBusyList->Delete();
00136   fRawDigitsList->Clear();
00137 
00138   // Bail out of snarl if number of digits is too high
00139   if( vldc.GetDetector()==Detector::kFar
00140    && rdb->GetNumberOfDigits()>10000 ){
00141     fPreTriggerDigits = 0;
00142     fPostTriggerDigits = rdb->GetNumberOfDigits();
00143     fSnarlMultiplicity = rdb->GetNumberOfDigits();
00144     fSnarlPassFail = 0;
00145     MSG("DataQuality",Msg::kWarning) << " RAW DIGITS > 10,000, BAILING OUT !!! " << endl;
00146     return;
00147   }
00148 
00149   // Iterate over raw digits and record any pre-trigger 
00150   // hits along with any hits containing readout errors
00151   // ==================================================
00152   TIter digitr = rdb->GetDatumIter();
00153   while(RawDigit *rd = (RawDigit*)(digitr())){
00154     if(rd){
00155       RawChannelId rawch = (RawChannelId)(rd->GetChannel());
00156       
00157       Int_t adc = (Int_t)(rd->GetADC());
00158       Int_t tdc = (Int_t)(rd->GetTDC());
00159       Int_t errorcode = (Int_t)(rd->GetErrorCode());
00160       RawReadout::ReadoutType_t readout = fRawReadout->GetReadoutType(rawch);
00161 
00162       // Near Detector, QIE Electronics
00163       // ==============================
00164       if( vldc.GetDetector()==Detector::kNear
00165        && rawch.GetElecType()==ElecType::kQIE ){
00166 
00167         // Readout Errors
00168         if( errorcode>0 ){
00169           // (don't check for duplicates in ND)
00170           // chid=-1;
00171           // for(i=0;chid<0&&i<1+fReadoutErrorList->GetLast();i++){
00172           //   RawChip* chip = (RawChip*)(fReadoutErrorList->At(i));
00173           //   if( chip->IsSameMenu(rawch) && chip->GetTdc()==tdc ) chid=i;
00174           // }
00175           RawChip* chip = new RawChip(rawch,adc,tdc,readout,RawChip::kError,errorcode);
00176           fReadoutErrorList->Add(chip);
00177         }
00178 
00179         // Overflowing TDC values (TDC>TF+1ms)
00180         if( tdc>53100000+53100 ){
00181           // (don't check for duplicates in ND)
00182           // chid=-1;
00183           // for(i=0;chid<0&&i<1+fReadoutErrorList->GetLast();i++){
00184           //   RawChip* chip = (RawChip*)(fReadoutErrorList->At(i));
00185           //   if( chip->IsSameMenu(rawch) && chip->GetTdc()==tdc ) chid=i;
00186           // }
00187           RawChip* chip = new RawChip(rawch,adc,tdc,readout,RawChip::kError,errorcode);
00188           fReadoutErrorList->Add(chip);
00189         }
00190 
00191         // Pre-Trigger Hits
00192         if( fTime==fBaseTime
00193          && (Double_t)((1000.0/53.1)*(tdc+1.0))-(Double_t)(fTriggerTime-fTriggerBaseTime)<0.0 ){
00194           // (don't check for duplicates in ND)
00195           // chid=-1;
00196           // for(i=0;chid<0&&i<1+fReadoutBusyList->GetLast();i++){
00197           //   RawChip* chip = (RawChip*)(fReadoutBusyList->At(i));
00198           //   if( chip->IsSameMenu(rawch) && chip->GetTdc()==tdc ) chid=i;
00199           // }
00200           RawChip* chip = new RawChip(rawch,adc,tdc,readout,RawChip::kBusy,0);
00201           fReadoutBusyList->Add(chip);
00202           fPreTriggerDigits++;
00203         }
00204         else{
00205           fPostTriggerDigits++;
00206           if( readout==RawReadout::kDetector ){
00207             fSnarlMultiplicity++;
00208           }
00209         }
00210       }
00211 
00212       // Far Detector, VA Electronics
00213       // ============================
00214       if( vldc.GetDetector()==Detector::kFar
00215        && rawch.GetElecType()==ElecType::kVA ){
00216 
00217         // Readout Errors
00218         if( errorcode>0 ){
00219           chid=-1;
00220           for(i=0;chid<0&&i<1+fReadoutErrorList->GetLast();i++){
00221             RawChip* chip = (RawChip*)(fReadoutErrorList->At(i));
00222             if( chip->IsSameVaChip(rawch) && chip->GetTdc()==tdc ) chid=i;
00223           }
00224           if( chid<0 ){
00225             RawChip* chip = new RawChip(rawch,adc,tdc,readout,RawChip::kError,errorcode);
00226             fReadoutErrorList->Add(chip);
00227           }
00228           else{
00229             RawChip* chip = (RawChip*)(fReadoutErrorList->At(chid));
00230             chip->AddChannel(rawch,adc,tdc,errorcode);
00231           }
00232         }
00233 
00234         // Overflowing TDC values (TDC>TF+1ms)
00235         if( tdc>640000000+640000 ){
00236           chid=-1;
00237           for(i=0;chid<0&&i<1+fReadoutErrorList->GetLast();i++){
00238             RawChip* chip = (RawChip*)(fReadoutErrorList->At(i));
00239             if( chip->IsSameVaChip(rawch) && chip->GetTdc()==tdc ) chid=i;
00240           }
00241           if( chid<0 ){
00242             RawChip* chip = new RawChip(rawch,adc,tdc,readout,RawChip::kError,errorcode);
00243             fReadoutErrorList->Add(chip);
00244           }
00245           else{
00246             RawChip* chip = (RawChip*)(fReadoutErrorList->At(chid));
00247             chip->AddChannel(rawch,adc,tdc,errorcode);
00248           }
00249         }
00250 
00251         // Pre-Trigger Hits
00252         if( fTime==fBaseTime
00253          && (Double_t)((1000.0/640.0)*(tdc+1.0))-(Double_t)(fTriggerTime-fTriggerBaseTime)<0.0 ){
00254           chid=-1;
00255           for(i=0;chid<0&&i<1+fReadoutBusyList->GetLast();i++){
00256             RawChip* chip = (RawChip*)(fReadoutBusyList->At(i));
00257             if( chip->IsSameVaChip(rawch) && chip->GetTdc()==tdc ) chid=i;
00258           }
00259           if( chid<0 ){
00260             RawChip* chip = new RawChip(rawch,adc,tdc,readout,RawChip::kBusy,0);
00261             fReadoutBusyList->Add(chip);
00262           }
00263           else{
00264             RawChip* chip = (RawChip*)(fReadoutBusyList->At(chid));
00265             chip->AddChannel(rawch,adc,tdc,errorcode);
00266           }
00267           fPreTriggerDigits++;
00268         }
00269         else{
00270           fPostTriggerDigits++;
00271           if( readout==RawReadout::kDetector ){
00272             fSnarlMultiplicity++;
00273           }
00274         }
00275       }
00276 
00277     }
00278   }
00279 
00280   // Now sort throught the list of pre-trigger hits 
00281   // to determine which chips were actually busy.
00282 
00283   // Far Detector, VA Electronics
00284   if( vldc.GetDetector()==Detector::kFar ){
00285 
00286     // Busy VA Electronics:
00287     // This assumes 2/36 VARC trigger in detector but not in shield.
00288     // The VARC-triggered hits are read out in the following order:
00289     //   (vaadc,vachip)=(0,0)->(0,1)->(0,2)->(1,0)->(1,1)->(1,2)
00290     // It's assumed that no triggered hits get sparsified away.
00291     // The parameters used are:
00292     //   VaTriggerTime = VA Trigger Window 
00293     //                  (1ns in shield, 400ns in detector)
00294     //   VaReadoutTime = VA Readout Time
00295     //                  (5000ns)
00296 
00297     Int_t n,ntmp;
00298     Int_t prehits[6];
00299     Int_t VaTriggerTime=400;
00300     Int_t VaReadoutTime=5000;
00301     
00302     for(i=0;i<1+fReadoutBusyList->GetLast();i++){
00303       RawChip* chip = (RawChip*)(fReadoutBusyList->At(i));
00304       
00305       n=0; 
00306       for(k=0;k<6;k++){ prehits[k]=0; }
00307       if( chip->GetReadoutType()==RawReadout::kDetector ) VaTriggerTime=400; 
00308       else VaTriggerTime=1;
00309       
00310       for(j=0;j<1+fReadoutBusyList->GetLast();j++){
00311         RawChip* prechip = (RawChip*)(fReadoutBusyList->At(j));
00312         if(chip->IsSameVmm(prechip)){
00313           if( prechip->GetNanosec()-chip->GetNanosec()<+VaTriggerTime
00314            && prechip->GetNanosec()-chip->GetNanosec()>=-VaTriggerTime
00315            && prechip->GetVaPriority()<=chip->GetVaPriority() ) n++;
00316           for(k=0;k<6;k++){
00317             if( prechip->GetNanosec()-chip->GetNanosec()<-VaTriggerTime
00318              && prechip->GetNanosec()-chip->GetNanosec()<-k*VaReadoutTime
00319              && prechip->GetNanosec()-chip->GetNanosec()>=-(k+1)*VaReadoutTime ) prehits[k]++;
00320           }
00321         }
00322       }
00323 
00324       for(j=0;j<6;j++){
00325         ntmp=0;
00326         for(k=0;k<j+1;k++){
00327           ntmp+=prehits[k];
00328         }
00329         if(ntmp>j) n+=ntmp;
00330       }
00331 
00332       if( chip->GetNanosec()-fTriggerTime>-n*VaReadoutTime ){
00333         fRawDigitsList->Add(chip);
00334       }
00335     }
00336 
00337     // VA Readout Errors
00338     for(i=0;i<1+fReadoutErrorList->GetLast();i++){
00339       RawChip* chip = (RawChip*)(fReadoutErrorList->At(i));
00340       fRawDigitsList->Add(chip);
00341     }
00342 
00343   }
00344 
00345   // Near Detector, QIE Electronics
00346   if( vldc.GetDetector()==Detector::kNear ){
00347 
00348     // Busy QIE Electronics:
00349     // assume it's deadtime-less for now
00350 
00351     // QIE Readout Errors
00352     for(i=0;i<1+fReadoutErrorList->GetLast();i++){
00353       RawChip* chip = (RawChip*)(fReadoutErrorList->At(i));
00354       fRawDigitsList->Add(chip);
00355     }
00356   }
00357 
00358   // Reached the end of the snarl okay
00359   fSnarlPassFail=1;
00360 
00361   MSG("DataQuality",Msg::kVerbose) << " Found " << 1+this->GetLast() << " bad chips " << endl;
00362 
00363 }
00364   
00365 Int_t DQRawDigits::GetLast() const
00366 {
00367   return fRawDigitsList->GetLast();
00368 }
00369    
00370 TObject* DQRawDigits::At(Int_t i) const
00371 {
00372   return (TObject*)(fRawDigitsList->At(i));
00373 }

Generated on Mon Nov 23 05:26:39 2009 for loon by  doxygen 1.3.9.1