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

CDPreFilterModule.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Program name: CDPreFilterModule.cxx
00004 //
00005 // Package: CalDetTracker
00006 //
00007 // Purpose: Only pass snarls with something interesting
00008 //
00009 // Contact: Chris Smith, Ryan Nichol, Leo Jenner or Jeff Hartnell
00011 
00012 #include <cstdio>
00013 #include <fstream>
00014 
00015 #include "TObject.h"
00016 
00017 #include "MessageService/MsgService.h"
00018 #include "MinosObjectMap/MomNavigator.h"
00019 #include "JobControl/JobCommand.h"
00020 #include "JobControl/JobCModuleRegistry.h"
00021 #include "RawData/RawRecord.h"
00022 #include "RawData/RawHeader.h"
00023 #include "RawData/RawDaqSnarlHeader.h"
00024 #include "RawData/RawTOFBlock.h"
00025 #include "RawData/RawDeadChipBlock.h"
00026 #include "RawData/RawChannelId.h"
00027 #include "RawData/RawDigit.h"
00028 #include "RawData/RawQieDigit.h"
00029 #include "RawData/RawVaDigit.h"
00030 #include "RawData/RawDigitDataBlock.h"
00031 #include "RawData/RawVarcErrorInTfBlock.h"
00032 
00033 #include "CalDetTracker/CDPreFilterModule.h"
00034 
00035 CVSID("$Id: CDPreFilterModule.cxx,v 1.12 2005/08/28 01:41:37 rhatcher Exp $");
00036 
00037 JOBMODULE(CDPreFilterModule,"CDPreFilterModule",
00038           "Only Pass Interesting Snarls");
00039 
00040 //......................................................................
00041 
00042 CDPreFilterModule::CDPreFilterModule()
00043 {
00044   //don't cut on any trigger bits by default
00045   fplanetrig=0;
00046   fnplane=0;
00047   fbeamonly=0;
00048   fcerenkov=0;
00049   fnodeadchips=0;
00050   fli=0;
00051   ftof=0;
00052   fNoNdErrors=0;
00053   fNoFdErrors=0;
00054   fBigSnarls=0;
00055 
00056   //initialise the counters
00057   fPlaneTrigCounter=0;
00058   fBeamOnlyCounter=0;
00059   fCerenkovCounter=0;
00060   fNoDeadChipsCounter=0;
00061   fLiCounter=0;
00062   fTofCounter=0;
00063   fTotalPassedCounter=0;
00064   fTotalFailedCounter=0;
00065   fTotalInputCounter=0;
00066   fNoNdErrorsCounter=0;
00067   fNoFdErrorsCounter=0;
00068   fBigSnarlsCounter=0;
00069 
00070   //error counters
00071   fNdSnarlErrorCounter=0;
00072   fNdSnarlFFFFCounter=0;
00073   fFdSnarlErrorCounter=0;
00074   fDigitCounter=0;
00075   fNdDigitCounter=0;
00076   fFdDigitCounter=0;
00077   fNdDigitErrorCounter=0;
00078   fNdDigitFFFFCounter=0;
00079   fFdDigitErrorCounter=0;
00080 
00081   //specific error counters
00082   fNdParityErrorCounter=0;
00083   fNdCapIdErrorCounter=0;
00084   fNdMisCountErrorCounter=0;
00085   fNdPriorityTruncateCounter=0;
00086   fFdAdcNegativeCounter=0;
00087   fFdNonStdDataCounter=0;
00088   fFdWarningStateCounter=0;
00089   fFdParityErr0Counter=0;
00090   fFdParityErr1Counter=0;
00091   fFdWordBitErr0Counter=0;
00092   fFdWordBitErr1Counter=0;
00093 
00094   //variables for cutting on snarl size
00095   fMinNumDigitsHit=100;
00096   fMinNumChannelsHit=100;
00097 
00098   //other
00099   fDetector=Detector::kUnknown;
00100 }
00101 
00102 //......................................................................
00103 
00104 void CDPreFilterModule::HandleCommand(JobCommand* cmd)
00105 {
00106 
00107   if (cmd->HaveCmd()) {       // If we have a command...
00108     string sc=cmd->PopCmd();// Get the command
00109     
00110     if (sc == "PlaneTrig"){
00111       if(cmd->HaveOpt()){
00112         Int_t tempPlanes=cmd->PopIntOpt();
00113         if (tempPlanes==0 || tempPlanes==1){
00114           fplanetrig=0;//no point having a 0 or 1 out of M plane trig
00115         }
00116         else if (tempPlanes<0){
00117           fplanetrig=0;
00118           MSG("CDPreFilterModule",Msg::kWarning) 
00119             <<"Can't do plane trigger with negative number of planes!"
00120             <<" Not cutting on plane trigger"<<endl;
00121         }
00122         else{
00123           fplanetrig=1;
00124           fnplane=tempPlanes;
00125         }
00126       }
00127       else {
00128         fplanetrig=0;
00129         MSG("CDPreFilterModule",Msg::kWarning) 
00130           << "PlaneTrig command given without number of planes option."
00131           << " Not cutting on Plane Trigger"  << endl;
00132       }
00133       
00134       MSG("CDPreFilterModule",Msg::kVerbose) 
00135         <<"Plane trigger control flag fplanetrig="<<fplanetrig
00136         <<endl;
00137       return;
00138     }
00139     else if (sc == "BeamSpill") {
00140       fbeamonly=1;
00141       if(cmd->HaveOpt()) {
00142         string opt=cmd->PopOpt();
00143         if(opt == "yes") fbeamonly=1; 
00144         else if(opt == "no") fbeamonly=-1;
00145         else if(opt == "off") fbeamonly=0;
00146         else if(opt == "tof") {
00147           if(cmd->HaveOpt()) {
00148             string opt2=cmd->PopOpt();
00149             if(opt2 == "yes") fbeamonly=2;
00150             else if(opt2 == "no") fbeamonly=-2;
00151             else {
00152               MSG("CDPreFilterModule",Msg::kWarning) 
00153                 << "Don't understand '" << opt2.c_str() << "'\n" 
00154                 << "Module will be ignoring "<<sc.c_str()<<" triggers"
00155                 << endl;
00156               fbeamonly=0;
00157             }
00158           }
00159           else {
00160             MSG("CDPreFilterModule",Msg::kWarning) 
00161               << "No option specified with " 
00162               << sc.c_str() << " " << opt.c_str() 
00163               << " needed for this Handle Command" 
00164               << "Module ignoring " << sc.c_str()<<" triggers"<<endl;
00165             fbeamonly=0;
00166           }
00167         }
00168         else {
00169           MSG("CDPreFilterModule",Msg::kWarning) 
00170             <<"Don't understand '" << opt.c_str() << "'\n" 
00171             <<"Module will be ignoring " << sc.c_str()<<" triggers"
00172             <<endl;
00173           fbeamonly=0;
00174         }
00175       }
00176       return;
00177     }
00178     else if(sc == "Cerenkov") {
00179       fcerenkov=1;
00180       if(cmd->HaveOpt()){
00181         string opt=cmd->PopOpt();
00182         if(opt == "yes") fcerenkov=1; 
00183         else if(opt == "no") fcerenkov=-1;
00184         else if(opt == "off") fcerenkov=0;
00185         else {
00186           MSG("CDPreFilterModule",Msg::kWarning) 
00187             << "Don't understand '" << opt.c_str() << "'\n" 
00188             <<"Module will be accepting "<<sc.c_str()<<" triggers"
00189             <<endl;
00190         }
00191       }
00192       return;
00193     }
00194     else if(sc == "LI") {
00195       fli=1;
00196       if(cmd->HaveOpt()){
00197         string opt=cmd->PopOpt();
00198         if(opt == "yes") fli=1; 
00199         else if(opt == "no") fli=-1;
00200         else if(opt == "off") fli=0;
00201         else {
00202           MSG("CDPreFilterModule",Msg::kWarning) 
00203             << "Don't understand '" << opt.c_str() << "'\n" 
00204             <<"Module will be accepting "<<sc.c_str()<<" triggers"
00205             <<endl;
00206         }   
00207       }
00208       return;
00209     }
00210     else if(sc == "TOF") {
00211       ftof=1;
00212       if(cmd->HaveOpt()){
00213         string opt=cmd->PopOpt();
00214         if(opt == "yes") ftof=1; 
00215         else if(opt == "no") ftof=-1;
00216         else if(opt == "off") ftof=0;
00217         else {
00218           MSG("CDPreFilterModule",Msg::kWarning) 
00219             << "Don't understand '" << opt.c_str() << "'\n" 
00220             <<"Module will be accepting "<<sc.c_str()<<" triggers"
00221             <<endl;
00222         }
00223       }
00224       return;
00225     }
00226     else if(sc == "NoDeadChips") {
00227       fnodeadchips=1;
00228       if(cmd->HaveOpt()){
00229         string opt=cmd->PopOpt();
00230         if(opt == "yes") fnodeadchips=1;
00231         else if(opt == "no") fnodeadchips=-1;
00232         else if(opt == "off") fnodeadchips=0;
00233         else {
00234           MSG("CDPreFilterModule",Msg::kWarning) 
00235             << "Don't understand '" << opt.c_str() << "'\n" 
00236             <<"Module will be requiring "<<sc.c_str()<<" triggers"
00237             <<endl;
00238         }
00239       }
00240       return;
00241     }
00242     else if(sc =="NoNdErrors"){
00243       fNoNdErrors=1;
00244       if(cmd->HaveOpt()){
00245         string opt=cmd->PopOpt();
00246         if(opt == "yes") fNoNdErrors=1;
00247         else if(opt == "no") fNoNdErrors=-1;
00248         else if(opt == "off") fNoNdErrors=0;
00249         else {
00250           MSG("CDPreFilterModule",Msg::kWarning) 
00251             << "Don't understand '" << opt.c_str() << "'\n" 
00252             <<"Module will be requiring "<<sc.c_str()<<endl;
00253         }
00254       }
00255       return;
00256     }
00257     else if(sc =="NoFdErrors"){
00258       fNoFdErrors=1;
00259       if(cmd->HaveOpt()){
00260         string opt=cmd->PopOpt();
00261         if(opt == "yes") fNoFdErrors=1;
00262         else if(opt == "no") fNoFdErrors=-1;
00263         else if(opt == "off") fNoFdErrors=0;
00264         else {
00265           MSG("CDPreFilterModule",Msg::kWarning) 
00266             << "Don't understand '" << opt.c_str() << "'\n" 
00267             <<"Module will be requiring "<<sc.c_str()<<endl;
00268         }
00269       }
00270       return;
00271     }
00272     else if(sc =="BigSnarls"){
00273       fBigSnarls=1;
00274       if(cmd->HaveOpt()){
00275         string opt=cmd->PopOpt();
00276         if(opt == "yes") fBigSnarls=1;
00277         else if(opt == "no") fBigSnarls=-1;
00278         else if(opt == "off") fBigSnarls=0;
00279         else {
00280           MSG("CDPreFilterModule",Msg::kWarning) 
00281             << "Don't understand '" << opt.c_str() << "'\n" 
00282             <<"Module will be requiring "<<sc.c_str()<<endl;
00283         }
00284       }
00285       return;
00286     }
00287     else{
00288       MSG("CDPreFilterModule",Msg::kWarning)
00289         << "Don't understand '" << sc.c_str() << "'\n";
00290     }
00291   }
00292 }
00293 
00294 //......................................................................
00295 
00296 JobCResult CDPreFilterModule::Ana(const MomNavigator *mom) 
00297 {
00298   JobCResult result(JobCResult::kPassed);
00299 
00300   //count every snarl that is input
00301   //this should stay at the top of the method
00302   fTotalInputCounter++;
00303 
00304   //the master/deciding cut variable, this MUST ONLY be set to TRUE
00305   //in the code below, setting it to false would override previous
00306   //decissions
00307   Bool_t rejectSnarl=false;
00308   //Note that the setting of "result" is mostly irrelevant
00309   //but it makes it clearer what passed and what failed.
00310 
00311   RawRecord *rr=dynamic_cast<RawRecord *>
00312     (mom->GetFragment("RawRecord"));
00313   if (rr==0) {
00314     MSG("CDPreFilterModule", Msg::kWarning) 
00315       << "No RawRecord in MOM." << endl;
00316     result.SetFailed();//added by JJH 12/Dec/2003
00317     return result;
00318   }
00319 
00320   const RawHeader* rawHdr=
00321     dynamic_cast<const RawHeader*>(rr->GetRawHeader());
00322   if(!rawHdr){
00323     MSG("CDPreFilterModule", Msg::kWarning) 
00324       << "No RawHeader in RawRecord" << endl;
00325     //result.SetFailed();
00326     //return result;
00327   }
00328   else{
00329     fDetector=rawHdr->GetVldContext().GetDetector();
00330   }
00331 
00332   Int_t num_tof_digits=0;
00333   const RawTOFBlock* tofblock=
00334     dynamic_cast<const RawTOFBlock*>(rr->FindRawBlock("RawTOFBlock"));
00335   if (tofblock) {
00336     num_tof_digits=tofblock->GetNumberOfDigits();
00337   }
00338 
00339   UInt_t trigword=0;
00340   const RawDaqSnarlHeader* snarlHdr =
00341     dynamic_cast<const RawDaqSnarlHeader*>(rr->GetRawHeader());
00342   if (snarlHdr) {
00343     trigword=snarlHdr->GetTrigSrc();
00344   }
00345 
00346   Int_t num_dead_chips=0;
00347   const RawDeadChipBlock* deadblock =
00348     dynamic_cast<const RawDeadChipBlock*>
00349     (rr->FindRawBlock("RawDeadChipBlock"));
00350   if(deadblock) {
00351     num_dead_chips=deadblock->GetNumberOfEntries();
00352   }
00353 
00354   //check the plane trigger
00355   if(fplanetrig==1) {
00356     if((trigword & 0x4) && (trigword>>8)>=fnplane)
00357       result.SetPassed();
00358     else {
00359       result.SetFailed();
00360       rejectSnarl=true;
00361       fPlaneTrigCounter++;
00362       //return result;
00363     }
00364   }
00365   
00366   //check the tof hits
00367   if(fbeamonly!=0) {
00368     if(fbeamonly==1 && (trigword & 0x80)) result.SetPassed();
00369     else if(fbeamonly==2 && num_tof_digits>0) result.SetPassed();
00370     else if(fbeamonly==-1 && !(trigword & 0x80)) result.SetPassed();
00371     else if(fbeamonly==-2 && num_tof_digits==0) result.SetPassed();
00372     else {
00373       result.SetFailed();
00374       rejectSnarl=true;
00375       fBeamOnlyCounter++;
00376       //return result;
00377     }
00378   }
00379 
00380   //check the cerenkov hits
00381   if(fcerenkov!=0) {
00382     if(fcerenkov==1 && 
00383        ((trigword & 0x10) || (trigword & 0x20) || (trigword & 0x40))){
00384       result.SetPassed();
00385     }
00386     else if(fcerenkov==-1 && 
00387             !(trigword&0x10) && !(trigword&0x20) && !(trigword&0x40)){
00388       result.SetPassed();
00389     }
00390     else {
00391       result.SetFailed();
00392       rejectSnarl=true;
00393       fCerenkovCounter++;
00394       //return result;
00395     }
00396   }
00397   
00398   //check the light injection
00399   if(fli!=0){
00400     if(fli==1 && (trigword & 0x2)) result.SetPassed();
00401     else if(fli==-1 && !(trigword & 0x2)) result.SetPassed();
00402     else {
00403       result.SetFailed();
00404       rejectSnarl=true;
00405       fLiCounter++;
00406       //return result;
00407     }
00408   }
00409 
00410   //check the tofs again??? JJH
00411   if(ftof!=0){
00412     if(ftof==1 && (trigword & 0x8)) result.SetPassed();
00413     else if(ftof==-1 && !(trigword & 0x8)) result.SetPassed();
00414     else {
00415       result.SetFailed();
00416       rejectSnarl=true;
00417       fTofCounter++;
00418       //return result;
00419     }
00420   }
00421 
00422   //check the dead chips
00423   if(fnodeadchips!=0) {
00424     if(fnodeadchips==1 && num_dead_chips==0) result.SetPassed();
00425     else if(fnodeadchips==-1 && num_dead_chips>0) result.SetPassed();
00426     else {
00427       result.SetFailed();
00428       rejectSnarl=true;
00429       fNoDeadChipsCounter++;
00430       //return result;
00431     }
00432   }
00433 
00434   //if any of the digit filters are enabled
00435   if (fNoNdErrors || fNoFdErrors || fBigSnarls){
00436     //get the raw digit data block
00437     const RawDigitDataBlock* rddb=dynamic_cast<const RawDigitDataBlock*>
00438       (rr->FindRawBlock("RawDigitDataBlock"));
00439     if (!rddb){
00440       MSG("CDPreFilterModule",Msg::kWarning) 
00441         <<"No RawDigitDataBlock in RawRecord"<<endl;
00442       //return JobCResult::kFailed;
00443     }
00444     else{
00445       //look at the digit errors
00446       if (fNoNdErrors || fNoFdErrors){
00447         Bool_t reject=this->FilterSnarlForErrors(rddb);
00448         if (reject) rejectSnarl=true;
00449       }
00450       //look at the digit size
00451       if (fBigSnarls){
00452         Bool_t reject=this->FilterOnSnarlSize(rddb);
00453         if (reject) rejectSnarl=true;
00454       }
00455     }
00456   }
00457   
00458   //gave up on this bit, you have to loop to get all the 
00459   //raw records and also over the raw records themselves to get
00460   //all the rvebs since there are 16 of them per rr!!!!
00461 
00462   //const RawVarcErrorInTfBlock* rveb=
00463   //dynamic_cast<const RawVarcErrorInTfBlock*>
00464   //(rr->FindRawBlock("RawVarcErrorInTfBlock"));
00465   //if (!rveb){
00466   //MAXMSG("CDPreFilterModule",Msg::kWarning,10) 
00467   //  <<"No RawVarcErrorInTfBlock in RawRecord"<<endl;
00468   //return JobCResult::kFailed;
00469   //}
00470   //else{
00471   //MAXMSG("CDPreFilterModule",Msg::kInfo,200) 
00472   //  <<"Found RawVarcErrorInTfBlock, Num SparsErrors="
00473   //  <<rveb->GetNumberOfSparsErrors()
00474   //  <<", Num EtcErrors="<<rveb->GetNumberOfEtcErrors()
00475   //  <<endl;
00476   //rveb->Print();
00477   //}
00478 
00479   //check the final result
00480   if (rejectSnarl){
00481     //fail the event
00482     result.SetFailed();
00483     //count the events failed
00484     fTotalFailedCounter++;
00485   }
00486   else {
00487     //pass the event
00488     result.SetPassed();
00489     //count the events passed
00490     fTotalPassedCounter++;
00491   }
00492 
00493   //return the final result
00494   return result;
00495 }
00496 
00497 //......................................................................
00498 
00499 void CDPreFilterModule::PrintFilterSummary() const
00500 {
00501   MSG("CDPreFilterModule",Msg::kVerbose)
00502     <<"Running PrintFilterSummary method..."<<endl;
00503 
00505 
00506   if (fTotalInputCounter>=0){
00507     Int_t totalHits=0;
00508     totalHits=fTotalFailedCounter+fTotalPassedCounter;
00509     
00510     MSG("CDPreFilterModule",Msg::kInfo) 
00511       <<endl 
00512       <<" ** Filter Summary Information: **"<<endl
00513       <<"  Total snarls input="<<fTotalInputCounter<<endl
00514       <<"    Snarls passed="<<fTotalPassedCounter
00515       <<" ("<<Pct(fTotalPassedCounter,totalHits)<<"%)"<<endl      
00516       <<"    Snarls failed="<<fTotalFailedCounter
00517       <<" ("<<Pct(fTotalFailedCounter,totalHits)<<"%)"<<endl      
00518       <<"    Sum of hits passed or failed="<<totalHits<<endl;
00519 
00520     MSG("CDPreFilterModule",Msg::kInfo) 
00521       <<"  Data Summary:"<<endl
00522       <<"    PlaneTrigger cut="<<fPlaneTrigCounter
00523       <<" ("<<Pct(fPlaneTrigCounter,totalHits)<<"%)"
00524       <<" ("<<GetCutStatus(fplanetrig)<<")"<<endl
00525       <<"    BeamOnly cut="<<fBeamOnlyCounter
00526       <<" ("<<Pct(fBeamOnlyCounter,totalHits)<<"%)"
00527       <<" ("<<GetCutStatus(fbeamonly)<<")"<<endl
00528       <<"    Cerenkov cut="<<fCerenkovCounter
00529       <<" ("<<Pct(fCerenkovCounter,totalHits)<<"%)"
00530       <<" ("<<GetCutStatus(fcerenkov)<<")"<<endl
00531       <<"    NoDeadChips cut="<<fNoDeadChipsCounter
00532       <<" ("<<Pct(fNoDeadChipsCounter,totalHits)<<"%)"
00533       <<" ("<<GetCutStatus(fnodeadchips)<<")"<<endl
00534       <<"    Li cut="<<fLiCounter
00535       <<" ("<<Pct(fLiCounter,totalHits)<<"%)"
00536       <<" ("<<GetCutStatus(fli)<<")"<<endl
00537       <<"    Tof cut="<<fTofCounter
00538       <<" ("<<Pct(fTofCounter,totalHits)<<"%)"
00539       <<" ("<<GetCutStatus(ftof)<<")"<<endl
00540       <<"    ND Error cut="<<fNoNdErrorsCounter
00541       <<" ("<<Pct(fNoNdErrorsCounter,totalHits)<<"%)"
00542       <<" ("<<GetCutStatus(fNoNdErrors)<<")"<<endl
00543       <<"    FD Error cut="<<fNoFdErrorsCounter
00544       <<" ("<<Pct(fNoFdErrorsCounter,totalHits)<<"%)"
00545       <<" ("<<GetCutStatus(fNoFdErrors)<<")"<<endl
00546       <<"    Big Snarls cut="<<fBigSnarlsCounter
00547       <<" ("<<Pct(fBigSnarlsCounter,totalHits)<<"%)"
00548       <<" ("<<GetCutStatus(fBigSnarls)<<")"<<endl;
00549 
00550     //now print out the errors
00551     if (fNoNdErrors || fNoFdErrors){
00552       MSG("CDPreFilterModule",Msg::kInfo) 
00553         <<this->GetErrorString();
00554     }
00555 
00556     MSG("CDPreFilterModule",Msg::kInfo) 
00557       <<" ** End of Filter Summary Information ** "<<endl; 
00558   }
00559   else {
00560     MSG("CDPreFilterModule",Msg::kInfo) 
00561       <<" ** No data input to prefilter **"<<endl<<endl;
00562   }
00563 
00564   MSG("CDPreFilterModule",Msg::kVerbose) 
00565     <<"Finished PrintFilterSummary method"<<endl;
00566 }
00567 
00568 //......................................................................
00569  
00570 string CDPreFilterModule::Pct(Double_t top,Double_t bottom) const
00571 {
00573   Double_t percent=-1;
00574   string sPercent="notset";
00575   if (bottom!=0){
00576     percent=top/bottom;
00577     percent*=100;
00578     sPercent=Form("%.1f",percent);
00579   }
00580   else{
00581     sPercent="fpe!";
00582   }
00583   return sPercent;
00584 }
00585 
00586 //......................................................................
00587 
00588 string CDPreFilterModule::SForm(Int_t number) const
00589 {
00590   string sNumber="";
00591   sNumber=Form("%d",number);
00592   return sNumber;
00593 }
00594 
00595 //......................................................................
00596 
00597 string CDPreFilterModule::GetErrorString() const
00598 {
00600 
00601   Int_t totalHits=0;
00602   totalHits=fTotalFailedCounter+fTotalPassedCounter;
00603  
00604   string sErrors="  Snarl Error and FFFF Summary:\n";
00605   string sNdErrors="";
00606   sNdErrors=
00607     "    Num ND Snarls with Errors  ="+SForm(fNdSnarlErrorCounter)+
00608     " ("+Pct(fNdSnarlErrorCounter,totalHits)+"%)"+"\n"
00609     +"      -Parity errors           ="+SForm(fNdParityErrorCounter)
00610     +" ("+Pct(fNdParityErrorCounter,totalHits)+"%)"+"\n"
00611     +"      -CapId errors            ="+SForm(fNdCapIdErrorCounter)
00612     +" ("+Pct(fNdCapIdErrorCounter,totalHits)+"%)"+"\n"
00613     +"      -MisCount errors         ="+SForm(fNdMisCountErrorCounter)
00614     +" ("+Pct(fNdMisCountErrorCounter,totalHits)+"%)"+"\n"
00615     +"      -PriorityTruncate errors ="+
00616     SForm(fNdPriorityTruncateCounter)
00617     +" ("+Pct(fNdPriorityTruncateCounter,totalHits)+"%)"+"\n"
00618     +"    Num ND Snarls with FFFFs   ="+SForm(fNdSnarlFFFFCounter)
00619     +" ("+Pct(fNdSnarlFFFFCounter,totalHits)+"%)"+"\n";
00620   string sFdErrors="";
00621   sFdErrors=
00622     "    Num FD Snarls (VMM<5 - if CalDet) with Errors="+
00623     SForm(fFdSnarlErrorCounter)
00624     +" ("+Pct(fFdSnarlErrorCounter,totalHits)+"%)"+"\n"
00625     +"      -AdcNegative errors      ="+SForm(fFdAdcNegativeCounter)
00626     +" ("+Pct(fFdAdcNegativeCounter,totalHits)+"%)"+"\n"
00627     +"      -NonStdData errors       ="+SForm(fFdNonStdDataCounter)
00628     +" ("+Pct(fFdNonStdDataCounter,totalHits)+"%)"+"\n"
00629     +"      -WarningState errors     ="+SForm(fFdWarningStateCounter)
00630     +" ("+Pct(fFdWarningStateCounter,totalHits)+"%)"+"\n"
00631     +"      -ParityErr0 errors       ="+SForm(fFdParityErr0Counter)
00632     +" ("+Pct(fFdParityErr0Counter,totalHits)+"%)"+"\n"
00633     +"      -ParityErr1 errors       ="+SForm(fFdParityErr1Counter)
00634     +" ("+Pct(fFdParityErr1Counter,totalHits)+"%)"+"\n"
00635     +"      -WordBitErr0 errors      ="+SForm(fFdWordBitErr0Counter)
00636     +" ("+Pct(fFdWordBitErr0Counter,totalHits)+"%)"+"\n"
00637     +"      -WordBitErr1 errors      ="+SForm(fFdWordBitErr1Counter)
00638     +" ("+Pct(fFdWordBitErr1Counter,totalHits)+"%)"+"\n";
00639 
00640   string sDigitErrors="";
00641   sDigitErrors="  Digit Error and FFFF Summary:\n";
00642   sDigitErrors+="    Total Number of Digits="+SForm(fDigitCounter)+"\n";
00643 
00644   string sFdDigits="";
00645   sFdDigits=
00646     "      -Num FD Digits="+SForm(fFdDigitCounter)
00647     +" ("+Pct(fFdDigitCounter,fDigitCounter)+"%)"+"\n";
00648   string sNdDigits="";
00649   sNdDigits=
00650     "      -Num ND Digits="+SForm(fNdDigitCounter)
00651     +" ("+Pct(fNdDigitCounter,fDigitCounter)+"%)"+"\n";
00652     
00653   string sFdDigitErrors="";
00654   sFdDigitErrors=
00655     "    Num FD Digits with Errors="+SForm(fFdDigitErrorCounter)
00656     +" ("+Pct(fFdDigitErrorCounter,fDigitCounter)+"%)"+"\n";
00657   string sNdDigitErrors="";
00658   sNdDigitErrors=
00659     "    Num ND Digits with Errors="+SForm(fNdDigitErrorCounter)
00660     +" ("+Pct(fNdDigitErrorCounter,fNdDigitCounter)+"%)"+"\n"
00661     +"    Num ND Digits with FFFFs="+SForm(fNdDigitFFFFCounter)
00662     +" ("+Pct(fNdDigitFFFFCounter,fNdDigitCounter)+"%)"+"\n";
00663 
00664   //work out what to print...
00665   if (fNoNdErrors) sErrors+=sNdErrors;
00666   if (fNoFdErrors) sErrors+=sFdErrors;
00667   sErrors+=sDigitErrors;
00668   if (fNoNdErrors) sErrors+=sNdDigits;
00669   if (fNoFdErrors) sErrors+=sFdDigits;
00670   if (fNoNdErrors) sErrors+=sNdDigitErrors;
00671   if (fNoFdErrors) sErrors+=sFdDigitErrors;
00672 
00673   return sErrors;
00674 }
00675 
00676 //......................................................................
00677  
00678 string CDPreFilterModule::GetCutStatus(Int_t cut) const
00679 {
00680   string status="";
00681   if (cut==0) status="disabled";
00682   else if (cut==1) status="enabled";
00683   else if (cut==-1) status="anti-enabled";
00684   else if (cut==2) status="enabled, special";
00685   else if (cut==-2) status="anti-enabled, special";
00686   else status="Cut not recognised";
00687 
00688   return status;
00689 }
00690 
00691 //......................................................................
00692 
00693 void CDPreFilterModule::EndJob() 
00694 {
00695   //print what was found and what was filtered
00696   this->PrintFilterSummary();
00697 }
00698 
00699 //......................................................................
00700 
00701 Bool_t CDPreFilterModule::FilterSnarlForErrors(const 
00702                                                RawDigitDataBlock* rddb)
00703 {  
00704   //counting snarls control variables
00705   Bool_t foundNdError=false;
00706   Bool_t foundNdFFFF=false;
00707   Bool_t foundFdError=false;
00708 
00709   //counting snarl error control variables
00710   Bool_t foundParityError=false;
00711   Bool_t foundCapIdError=false;
00712   Bool_t foundMisCountError=false;
00713   Bool_t foundPriorityTruncate=false;
00714   Bool_t foundAdcNegative=false;
00715   Bool_t foundNonStdData=false;
00716   Bool_t foundWarningState=false;
00717   Bool_t foundParityErr0=false;
00718   Bool_t foundParityErr1=false;
00719   Bool_t foundWordBitErr0=false;
00720   Bool_t foundWordBitErr1=false;
00721 
00722   TIter datit = rddb->GetDatumIter();
00723   while (TObject *tobd=datit()){
00724 
00725     //get the raw digit
00726     RawDigit *rd=dynamic_cast<RawDigit *>(tobd);
00727 
00728     //count the digits
00729     fDigitCounter++;
00730 
00731     //check the digit for errors and FFFF
00732 
00733     //look at far detector digits if fNoFdErrors is non-zero
00734     if (rd->GetChannel().GetElecType()==ElecType::kVA){
00735       if (fNoFdErrors){//allows to only count ND errors
00736         //count the FD digits
00737         fFdDigitCounter++;
00738 
00739         //check if there is an error (and that the vmm was <5 if CalDet)
00740         if (rd->GetErrorCode() && (rd->GetChannel().GetVmm()<5 
00741                                    || fDetector!=
00742                                    Detector::kCalDet)){
00743 
00744           //count the digits with errors
00745           fFdDigitErrorCounter++;
00746 
00747           //count the snarls with errors
00748           if (!foundFdError){
00749             foundFdError=true;
00750             fFdSnarlErrorCounter++;
00751           }
00752 
00753           //count the individual error types occurance in snarls
00754           Char_t errCode=rd->GetErrorCode();
00755           Bool_t errorRecognised=false;
00756           if ((errCode&0x1)==RawVaDigit::kAdcNegative){//bit0
00757             if (!foundAdcNegative) fFdAdcNegativeCounter++;
00758             foundAdcNegative=true;
00759             errorRecognised=true;
00760           }
00761           if ((errCode&0x2)==RawVaDigit::kNonStdData){//bit1
00762             if (!foundNonStdData) fFdNonStdDataCounter++;
00763             foundNonStdData=true;
00764             errorRecognised=true;
00765             static Int_t msgCounter=0;
00766             if (msgCounter<100){
00767               RawChannelId rcid=rd->GetChannel();
00768               MSG("CDPreFilterModule",Msg::kDebug)
00769                 <<"Error: NonStdData on VA("<<rcid.GetCrate()<<","
00770                 <<rcid.GetVarcId()<<","<<rcid.GetVmm()<<","
00771                 <<rcid.GetVaAdcSel()<<","<<rcid.GetVaChip()<<","
00772                 <<rcid.GetVaChannel()<<")"<<endl;
00773             }
00774             else if (msgCounter==100){
00775               MSG("CDPreFilterModule",Msg::kDebug)
00776                 <<"Not printing any more NonStdData errors"<<endl;
00777             }
00778             msgCounter++;
00779           }
00780           if ((errCode&0x4)==RawVaDigit::kWarningState){//bit2
00781             if (!foundWarningState) fFdWarningStateCounter++;
00782             foundWarningState=true;
00783             errorRecognised=true;
00784           }
00785           if ((errCode&0x8)==RawVaDigit::kParityErr0){//bit3
00786             if (!foundParityErr0) fFdParityErr0Counter++;
00787             foundParityErr0=true;
00788             errorRecognised=true;
00789 
00790             static Int_t msgCounter=0;
00791             if (msgCounter<100){
00792               RawChannelId rcid=rd->GetChannel();
00793               MSG("CDPreFilterModule",Msg::kDebug)
00794                 <<"Error: ParityErr0 on VA("<<rcid.GetCrate()<<","
00795                 <<rcid.GetVarcId()<<","<<rcid.GetVmm()<<","
00796                 <<rcid.GetVaAdcSel()<<","<<rcid.GetVaChip()<<","
00797                 <<rcid.GetVaChannel()<<")"<<endl;
00798             }
00799             else if (msgCounter==100){
00800               MSG("CDPreFilterModule",Msg::kDebug)
00801                 <<"Not printing any more ParityErr0 errors"<<endl;
00802             }
00803             msgCounter++;
00804           }
00805           if ((errCode&0x10)==RawVaDigit::kParityErr1){//bit4
00806             if (!foundParityErr1) fFdParityErr1Counter++;
00807             foundParityErr1=true;
00808             errorRecognised=true;
00809           }
00810           if ((errCode&0x20)==RawVaDigit::kWordBitErr0){//bit5
00811             if (!foundWordBitErr0) fFdWordBitErr0Counter++;
00812             foundWordBitErr0=true;
00813             errorRecognised=true;
00814           }
00815           if ((errCode&0x40)==RawVaDigit::kWordBitErr1){//bit6
00816             if (!foundWordBitErr1) fFdWordBitErr1Counter++;
00817             foundWordBitErr1=true;
00818             errorRecognised=true;
00819           }
00820 
00821           //check that the error was recognised 
00822           if (!errorRecognised){
00823             RawChannelId rcid=rd->GetChannel();
00824             MSG("CDPreFilterModule",Msg::kWarning)
00825               <<"EVaErrorCode not recognised: "
00826               <<static_cast<Int_t>(errCode)
00827               //have to cast it as it might not be a printable character
00828               <<" VA("<<rcid.GetCrate()<<","
00829               <<rcid.GetVarcId()<<","<<rcid.GetVmm()<<","
00830               <<rcid.GetVaAdcSel()<<","<<rcid.GetVaChip()<<","
00831               <<rcid.GetVaChannel()<<")"<<endl;
00832           }
00833         }
00834       }
00835     }
00836     //look at near detector digits if fNoNdErrors is non-zero
00837     else if (rd->GetChannel().GetElecType()==ElecType::kQIE){
00838       if (fNoNdErrors){//allows to only count FD errors
00839         //count the ND digits
00840         fNdDigitCounter++;
00841 
00842         //check for FFFFs
00843         if (rd->GetADC()==0xFFFF){
00844           fNdDigitFFFFCounter++;
00845           //count the snarls with errors
00846           if (!foundNdFFFF){
00847             foundNdFFFF=true;
00848             fNdSnarlFFFFCounter++;
00849           }
00850         }
00851       
00852         //check for errors
00853         if (rd->GetErrorCode()){
00854 
00855           //count the digits with errors
00856           fNdDigitErrorCounter++;
00857 
00858           //count the snarls with errors
00859           if (!foundNdError){
00860             foundNdError=true;
00861             fNdSnarlErrorCounter++;
00862 
00863             //count the individual error types occurance in snarls
00864             Char_t errCode=rd->GetErrorCode();
00865             Bool_t errorRecognised=false;
00866             if ((errCode&0x1)==RawQieDigit::kParityError){//bit0
00867               if (!foundParityError) fNdParityErrorCounter++;
00868               foundParityError=true;
00869               errorRecognised=true;
00870             }
00871             if ((errCode&0x2)==RawQieDigit::kCapIdError){//bit1
00872               if (!foundCapIdError) fNdCapIdErrorCounter++;
00873               foundCapIdError=true;
00874               errorRecognised=true;
00875               static Int_t msgCounter=0;
00876               if (msgCounter<100){
00877                 RawChannelId rcid=rd->GetChannel();
00878                 MSG("CDPreFilterModule",Msg::kDebug)
00879                   <<"Error: CapIdError on QIE("
00880                   <<rcid.GetCrate()<<","
00881                   <<rcid.GetGeographicAddress()<<","
00882                   <<rcid.GetMasterChannel()<<","
00883                   <<rcid.GetMinderChannel()<<")"<<endl;
00884               }
00885               else if (msgCounter==100){
00886                 MSG("CDPreFilterModule",Msg::kDebug)
00887                   <<"Not printing any more CapId errors"<<endl;
00888               }
00889               msgCounter++;
00890             }
00891             if ((errCode&0x4)==RawQieDigit::kMisCountError){//bit2
00892               if (!foundMisCountError) fNdMisCountErrorCounter++;
00893               foundMisCountError=true;
00894               errorRecognised=true;
00895             }
00896             if ((errCode&0x8)==RawQieDigit::kPriorityTruncate){//bit3
00897               if (!foundPriorityTruncate) fNdPriorityTruncateCounter++;
00898               foundPriorityTruncate=true;
00899               errorRecognised=true;
00900             }
00901 
00902             if (!errorRecognised){
00903               RawChannelId rcid=rd->GetChannel();
00904               MSG("CDPreFilterModule",Msg::kWarning)
00905                 <<"EQieErrorCode not recognised: "
00906                 <<static_cast<Int_t>(errCode)
00907                 <<" QIE("
00908                 <<rcid.GetCrate()<<","
00909                 <<rcid.GetGeographicAddress()<<","
00910                 <<rcid.GetMasterChannel()<<","
00911                 <<rcid.GetMinderChannel()<<")"<<endl;
00912             }
00913           }
00914           //check the type of error here as well
00915           //
00916         }
00917       }
00918     }
00919     else{
00920       MSG("CDPreFilterModule",Msg::kWarning)
00921         <<"ElecType not recognised: "
00922         <<ElecType::AsString(rd->GetChannel().GetElecType())<<endl;
00923     }
00924   }
00925 
00927   //Section to actually reject the snarls based on the errors
00929 
00930   Bool_t rejectSnarl=false;
00931 
00932   //check the ND errors
00933   //only pass snarls without errors
00934   if (fNoNdErrors==1){
00935     if (foundNdError || foundNdFFFF) rejectSnarl=true;
00936     if (rejectSnarl) fNoNdErrorsCounter++;
00937 
00938     MSG("CDPreFilterModule",Msg::kVerbose)
00939       <<"enabled, foundNdError="<<foundNdError
00940       <<", foundNdFFFF="<<foundNdFFFF<<", reject="<<rejectSnarl
00941       <<", counter="<<fNoNdErrorsCounter<<endl;
00942   }
00943   //if anti-enabled only pass snarls WITH errors
00944   else if (fNoNdErrors==-1){
00945     //don't reject if found an error, only reject with errors!
00946     if (!foundNdError && !foundNdFFFF) rejectSnarl=true;
00947     if (rejectSnarl) fNoNdErrorsCounter++;
00948 
00949     MSG("CDPreFilterModule",Msg::kVerbose)
00950       <<"anti-enabled, foundNdError="<<foundNdError
00951       <<", foundNdFFFF="<<foundNdFFFF<<", reject="<<rejectSnarl
00952       <<", counter="<<fNoNdErrorsCounter<<endl;
00953   }
00954   else if (fNoNdErrors==0){
00955     //don't do anything in this case
00956   }
00957   else {
00958     MSG("CDPreFilterModule",Msg::kWarning)
00959       <<"Not cutting on NoNdErrors"
00960       <<", control variable value not recognised: "
00961       <<"fNoNdErrors="<<fNoNdErrors<<endl;
00962   } 
00963 
00964   //check the FD errors
00965   //only pass snarls without errors
00966   if (fNoFdErrors==1){
00967     if (foundFdError){
00968       rejectSnarl=true;
00969       fNoFdErrorsCounter++;
00970     }
00971   }
00972   //if anti-enabled only pass snarls WITH errors
00973   else if (fNoFdErrors==-1){
00974     if (!foundFdError){
00975       rejectSnarl=true;
00976       fNoFdErrorsCounter++;
00977     }
00978   }
00979   else if (fNoFdErrors==0){
00980     //don't do anything in this case
00981   }
00982   else {
00983     MSG("CDPreFilterModule",Msg::kWarning)
00984       <<"Not cutting on NoFdErrors"
00985       <<", control variable value not recognised: "
00986       <<"fNoFdErrors="<<fNoFdErrors<<endl;
00987   }
00988 
00989   //return the decision
00990   return rejectSnarl;
00991 }
00992 
00993 //......................................................................
00994 
00995 Bool_t CDPreFilterModule::FilterOnSnarlSize(const 
00996                                             RawDigitDataBlock* rddb)
00997 {  
00998   Bool_t rejectSnarl=false;
00999 
01000   //variables to be evaluated before filtering the snarl
01001   Bool_t lowNumDigits=false;
01002   Bool_t lowNumChannels=false;
01003   Bool_t highNumDigits=false;
01004   Bool_t highNumChannels=false;
01005 
01006   //check snarl initially on the number of digits (buckets+vaHits)
01007   if (rddb->GetNumberOfDigits()<static_cast<Int_t>(fMinNumDigitsHit)){
01008     lowNumDigits=true;
01009   }
01010   //check that snarls over fMinNumDigitsHit satisfy the channel cut
01011   else{
01012     highNumDigits=true;
01013 
01014     //variables for counting up the hits
01015     map<UInt_t,UInt_t> qieChannelsHit;
01016     UInt_t vaChannelsHit=0;
01017     UInt_t qieDigitCounter=0;
01018     UInt_t vaDigitCounter=0;
01019 
01020     //loop over digits
01021     TIter datit = rddb->GetDatumIter();
01022     while (TObject *tobd=datit()){
01023       
01024       //get the raw digit
01025       RawDigit *rd=dynamic_cast<RawDigit *>(tobd);
01026 
01027       //count the hits
01028       if (rd->GetChannel().GetElecType()==ElecType::kQIE){
01029         //count up the buckets
01030         qieChannelsHit[rd->GetChannel().GetEncoded()]++;
01031         qieDigitCounter++;
01032       }
01033       else if (rd->GetChannel().GetElecType()==ElecType::kVA){
01034         //only count the scint channels at CalDet
01035         if (rd->GetChannel().GetVmm()<5 || 
01036             fDetector!=Detector::kCalDet){
01037           vaChannelsHit++;
01038           vaDigitCounter++;
01039         }
01040       }
01041       else{
01042         MSG("CDPreFilterModule",Msg::kWarning)
01043           <<"ElecType not recognised: "
01044           <<ElecType::AsString(rd->GetChannel().GetElecType())<<endl;
01045       }
01046     }
01047 
01048     //check the number of channels
01049     if (vaChannelsHit+qieChannelsHit.size()<fMinNumChannelsHit){
01050       lowNumChannels=true;
01051 
01052       //print message
01053       static Int_t msgCounter=0;
01054       if (msgCounter<100){
01055         MSG("CDPreFilterModule",Msg::kDebug)
01056           <<"Snarl with low num channels: vaCh="<<vaChannelsHit
01057           <<", qieCh="<<qieChannelsHit.size()
01058           <<", totalDig="<<rddb->GetNumberOfDigits()
01059           <<", vaDig="<<vaDigitCounter
01060           <<", qieDig="<<qieDigitCounter
01061           <<endl;
01062       }
01063       else if (msgCounter==100){
01064         MSG("CDPreFilterModule",Msg::kDebug)
01065           <<"Not printing any more snarls with low num channels"<<endl;
01066       }
01067       msgCounter++;
01068     }
01069     else{
01070       highNumChannels=true;
01071     }
01072   }
01073 
01075   //Section to actually reject the snarls based on the sizes
01077 
01078   //only reject the snarl if the cut 
01079   //is enabled (1) not anti-enabled (-1)
01080   if (fBigSnarls==1){
01081     if (lowNumDigits || lowNumChannels) rejectSnarl=true;
01082   }
01083   //check if the cut is anti-enabled (-1) rather than enabled (1)
01084   //so here you cut on snarls over fMinNumDigitsHit & fMinNumChannelsHit
01085   else if (fBigSnarls==-1){
01086     if (highNumDigits || highNumChannels) rejectSnarl=true;
01087   }
01088   else {
01089     MSG("CDPreFilterModule",Msg::kWarning)
01090       <<"Not cutting on BigSnarls"
01091       <<", control variable value not recognised: "
01092       <<"fBigSnarls="<<fBigSnarls<<endl;
01093   }
01094 
01095   //count the rejected snarls
01096   if (rejectSnarl) fBigSnarlsCounter++;
01097 
01098   //return the result
01099   return rejectSnarl;
01100 }
01101 
01102 //......................................................................
01103 
01104 const Registry& CDPreFilterModule::DefaultConfig() const
01105 {
01107 
01108   MSG("CDPreFilterModule", Msg::kDebug)
01109     << "Running CDPreFilterModule::DefaultConfig..." << endl;
01110     
01111   static Registry r;
01112 
01113   string name=this->JobCModule::GetName();
01114   name+=".config.default";
01115   r.SetName(name.c_str());
01116   r.UnLockValues();
01117 
01118   r.Set("MinNumDigitsHit",0);
01119   r.Set("MinNumChannelsHit",0);
01120 
01121   r.LockValues();
01122 
01123   return r;
01124 }
01125 
01126 //......................................................................
01127 
01128 void CDPreFilterModule::Config(const Registry &r)
01129 {
01131 
01132   MSG("CDPreFilterModule", Msg::kDebug) 
01133     <<"CDPreFilterModule::Config"<<endl;
01134 
01135   Int_t temp=0;
01136 
01137   temp=0;
01138   //set fMinNumDigitsHit
01139   if (r.Get("MinNumDigitsHit",temp)) {
01140     fMinNumDigitsHit=temp;
01141   }
01142 
01143   temp=0;
01144   //set fMinNumChannelsHit
01145   if (r.Get("MinNumChannelsHit",temp)) {
01146     fMinNumChannelsHit=temp;
01147   }
01148 }
01149 
01150 //......................................................................

Generated on Mon Feb 15 11:06:30 2010 for loon by  doxygen 1.3.9.1