| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

TsESumTriggerTool.cc

Go to the documentation of this file.
00001 #include "TsESumTriggerTool.h"
00002 
00003 #include "Conventions/Electronics.h"
00004 #include "Conventions/Detectors.h"
00005 #include "Conventions/Trigger.h"
00006 #include "Conventions/Site.h"
00007 
00008 #include "Event/ElecCrateHeader.h"
00009 #include "Event/ElecFeeCrate.h"
00010 
00011 #include "Event/SimTrigCommand.h"
00012 #include "Event/SimTrigCommandHeader.h"
00013 #include "Event/SimTrigCommandCollection.h"
00014 
00015 
00016 TsESumTriggerTool::TsESumTriggerTool(const std::string& type,
00017                    const std::string& name, 
00018                    const IInterface* parent)
00019     : GaudiTool(type,name,parent)
00020 {
00021   declareInterface< ITsTriggerTool >(this) ;
00022   // for now add all but RPC's as default.
00023   m_detectorsToProcess.push_back("DayaBayAD1");
00024   m_detectorsToProcess.push_back("DayaBayAD2");
00025   m_detectorsToProcess.push_back("DayaBayIWS");
00026   m_detectorsToProcess.push_back("DayaBayOWS");
00027   m_detectorsToProcess.push_back("LingAoAD1");
00028   m_detectorsToProcess.push_back("LingAoAD2");
00029   m_detectorsToProcess.push_back("LingAoIWS");
00030   m_detectorsToProcess.push_back("LingAoOWS"); 
00031   m_detectorsToProcess.push_back("FarAD1");
00032   m_detectorsToProcess.push_back("FarAD2");
00033   m_detectorsToProcess.push_back("FarAD3");
00034   m_detectorsToProcess.push_back("FarAD4");
00035   m_detectorsToProcess.push_back("FarIWS");
00036   m_detectorsToProcess.push_back("FarOWS");
00037   
00038   m_UpperLowerThresholdMap["DayaBayAD1"]=DayaBay::Trigger::kADESumThreshold;
00039   m_UpperLowerThresholdMap["DayaBayAD2"]=DayaBay::Trigger::kADESumThreshold;
00040   m_UpperLowerThresholdMap["DayaBayIWS"]=DayaBay::Trigger::kNearIWSESumThreshold;
00041   m_UpperLowerThresholdMap["DayaBayOWS"]=DayaBay::Trigger::kNearOWSESumThreshold;
00042   m_UpperLowerThresholdMap["LingAoAD1"]=DayaBay::Trigger::kADESumThreshold;
00043   m_UpperLowerThresholdMap["LingAoAD2"]=DayaBay::Trigger::kADESumThreshold;
00044   m_UpperLowerThresholdMap["LingAoIWS"]=DayaBay::Trigger::kNearIWSESumThreshold;
00045   m_UpperLowerThresholdMap["LingAoOWS"]=DayaBay::Trigger::kNearOWSESumThreshold;
00046   m_UpperLowerThresholdMap["FarAD1"]=DayaBay::Trigger::kADESumThreshold;
00047   m_UpperLowerThresholdMap["FarAD2"]=DayaBay::Trigger::kADESumThreshold;
00048   m_UpperLowerThresholdMap["FarAD3"]=DayaBay::Trigger::kADESumThreshold;
00049   m_UpperLowerThresholdMap["FarAD4"]=DayaBay::Trigger::kADESumThreshold;
00050   m_UpperLowerThresholdMap["FarIWS"]=DayaBay::Trigger::kFarIWSESumThreshold;
00051   m_UpperLowerThresholdMap["FarOWS"]=DayaBay::Trigger::kFarOWSESumThreshold;
00052   
00053   m_TotalDigitalThresholdMap["DayaBayAD1"]=DayaBay::Trigger::kADESumThreshold;
00054   m_TotalDigitalThresholdMap["DayaBayAD2"]=DayaBay::Trigger::kADESumThreshold;
00055   m_TotalDigitalThresholdMap["DayaBayIWS"]=DayaBay::Trigger::kNearIWSESumThreshold;
00056   m_TotalDigitalThresholdMap["DayaBayOWS"]=DayaBay::Trigger::kNearOWSESumThreshold;
00057   m_TotalDigitalThresholdMap["LingAoAD1"]=DayaBay::Trigger::kADESumThreshold;
00058   m_TotalDigitalThresholdMap["LingAoAD2"]=DayaBay::Trigger::kADESumThreshold;
00059   m_TotalDigitalThresholdMap["LingAoIWS"]=DayaBay::Trigger::kNearIWSESumThreshold;
00060   m_TotalDigitalThresholdMap["LingAoOWS"]=DayaBay::Trigger::kNearOWSESumThreshold;
00061   m_TotalDigitalThresholdMap["FarAD1"]=DayaBay::Trigger::kADESumThreshold;
00062   m_TotalDigitalThresholdMap["FarAD2"]=DayaBay::Trigger::kADESumThreshold;
00063   m_TotalDigitalThresholdMap["FarAD3"]=DayaBay::Trigger::kADESumThreshold;
00064   m_TotalDigitalThresholdMap["FarAD4"]=DayaBay::Trigger::kADESumThreshold;
00065   m_TotalDigitalThresholdMap["FarIWS"]=DayaBay::Trigger::kFarIWSESumThreshold;
00066   m_TotalDigitalThresholdMap["FarOWS"]=DayaBay::Trigger::kFarOWSESumThreshold;
00067 
00068   
00069   declareProperty("DetectorsToProcess",m_detectorsToProcess,
00070                   "List of detectors to process with this tool");
00071   declareProperty("RecoveryTime",m_recoveryCycles=20,
00072                "Number of esum (200 MHz) clock cycles for trigger dead time");
00073   declareProperty("UpperLowerThresholdMap",m_UpperLowerThresholdMap,
00074                   "Map indexed by detector name with value of Thrshold in volts");
00075   declareProperty("DigitalTotalThresholdMap",m_TotalDigitalThresholdMap,
00076                   "Map indexed by detector name with value of Thrshold in volts");
00077 }
00078 
00079 TsESumTriggerTool::~TsESumTriggerTool(){}
00080 
00081 StatusCode TsESumTriggerTool::initialize()
00082 {
00083   std::vector<std::string>::iterator it;
00084 
00085   // loop over detectors 
00086   for(it = m_detectorsToProcess.begin(); 
00087       it != m_detectorsToProcess.end(); 
00088       ++it){    
00089         short int detId =  DayaBay::Detector::siteDetPackedFromString(*it);
00090         DayaBay::Detector det(detId);
00091         info() << det 
00092                << " is setup with Upper Lower threshold " 
00093                << getULThreshold(det) 
00094                << endreq;
00095         info() << det 
00096                << " is setup with Digital Total threshold " 
00097                << getDTThreshold(det) 
00098                << endreq;   
00099     }
00100       
00101     return StatusCode::SUCCESS;
00102 }
00103 
00104 StatusCode TsESumTriggerTool::finalize()
00105 {
00106   return StatusCode::SUCCESS;
00107 }
00108 
00109 StatusCode TsESumTriggerTool::fillTriggers(DayaBay::SimTrigHeader* trigHeader,
00110                                         const DayaBay::ElecHeader& elecHeader)
00111 {
00112   debug() << "running fillTriggers()" << endreq;
00113   DayaBay::SimTrigCommandHeader* trigCH 
00114     = const_cast<DayaBay::SimTrigCommandHeader*>(trigHeader->commandHeader());
00115   
00116   const DayaBay::ElecCrateHeader* crateHeader = elecHeader.crateHeader();
00117   DayaBay::ElecCrateHeader::CrateMap cmap = crateHeader->crates();
00118   DayaBay::ElecCrateHeader::CrateMap::iterator detIterator;
00119   
00120   std::vector<std::string>::iterator it;
00121   debug() << "processing " << m_detectorsToProcess.size() 
00122           << " detectors." << endreq;
00123   
00124   // loop over detectors 
00125   for(it = m_detectorsToProcess.begin(); 
00126       it != m_detectorsToProcess.end(); 
00127       ++it){
00128     short int detId =  DayaBay::Detector::siteDetPackedFromString(*it);
00129     DayaBay::Detector det(detId);
00130     verbose() << "Processing " << *it << " which is " << det << endreq;
00131     
00132     const DayaBay::SimTrigCommandHeader::detCollMap trigCollMap = trigCH->collections();
00133     
00134 
00135     detIterator = cmap.find(det);
00136     if(detIterator != cmap.end()){
00137       // A crate was found for this detector
00138       debug() << "A crate was found for " << det 
00139               << " processing..." << endreq;
00140       
00141       DayaBay::SimTrigCommandCollection *tcc = 0;
00142       if( trigCollMap.find(det) == trigCollMap.end() ){
00143           tcc = new DayaBay::SimTrigCommandCollection();
00144           tcc->setHeader(trigCH);
00145           tcc->setDetector(det);
00146           trigCH->addCollection(tcc);
00147       }
00148       
00149       
00150       // Get the crate from the header object
00151       DayaBay::ElecFeeCrate *crate 
00152                         = dynamic_cast<DayaBay::ElecFeeCrate*>(cmap[det]);
00153       
00154       // get esum hits...
00155       DayaBay::AnalogSignal& upperEsum = crate->esumUpper();
00156       DayaBay::AnalogSignal& lowerEsum = crate->esumLower();
00157       DayaBay::AnalogSignal& totalEsum = crate->esumTotal();
00158       DayaBay::DigitalSignal& totalAdc = crate->esumADC();    
00159                     
00160       // threshold for upper and lower esums.
00161       double ULthreshold = getULThreshold(det);
00162       
00163       // threshold for digital and total esums.
00164       double DTthreshold = getDTThreshold(det);
00165       
00166       verbose() << "UL Trigger Threshold " << ULthreshold  << endreq;
00167       verbose() << "DT Trigger Threshold " << DTthreshold  << endreq;
00168       
00169       //
00170       // IN ALL CASES BELOW THE FOLLOWING APPLIES 
00171       //
00172       // convert the esum clock to the next Nhit clock cycle 
00173       // for the trigger command.  by default this will report the 
00174       // 200MHz esum clock to a 80 MHz adc clock cycle so it's 
00175       // properly handeled by the readout.
00176       // 2*(1 + (previous ADC cycle)) --> trigger reported at next 80 MHz
00177       //                                 clock cycle
00178       // The Esum Triggers are checked at 40MHz but ReadoutSim expectes them
00179       // to be reported at 80MHz, so its calculate at 40 then doubled
00180       // to 80.
00181       //
00182       
00183       // Do upperEsumTriggers
00184       
00185       for( unsigned int i = 0; i < upperEsum.size() ; ++i )
00186       {
00187           if ( upperEsum[i] >= ULthreshold )
00188           {
00189               DayaBay::Trigger::TriggerType_t type = getTriggerType(det);
00190               type = DayaBay::Trigger::TriggerType_t(type | DayaBay::Trigger::kESumLow);
00191               
00192               unsigned int trigcycle = 2* ( 1 + 
00193                            (i * DayaBay::AdcCycles) / (DayaBay::EsumCycles) );
00194               DayaBay::SimTrigCommand *tc = 
00195                              new DayaBay::SimTrigCommand(det,type,trigcycle,0,totalAdc[i],DayaBay::ESumComp::kESumHigh);
00196               debug() << "Adding Upper Esum Trigger at cycle\t" <<  i
00197                       << " With type " << type 
00198                       << " \n\t Nhit clock cycle: " << trigcycle
00199                       << " \n\t Esum clock cycle: " << i << endreq;
00200               verbose() << "Waiting " << m_recoveryCycles 
00201                         << " cycles to recover" << endreq;           
00202               i += m_recoveryCycles;
00203               trigCH->addCommand(tc);
00204               
00205           }
00206       }
00207       
00208       // Do lowerEsumTriggers
00209       
00210       for( unsigned int i = 0; i < lowerEsum.size() ; ++i )
00211       {
00212           if ( lowerEsum[i] >= ULthreshold )
00213           {
00214               DayaBay::Trigger::TriggerType_t type = getTriggerType(det);
00215               type = DayaBay::Trigger::TriggerType_t( DayaBay::Trigger::kESumHigh);
00216               
00217               unsigned int trigcycle = 2* ( 1 + 
00218                            (i * DayaBay::AdcCycles) / (DayaBay::EsumCycles) );
00219               DayaBay::SimTrigCommand *tc = 
00220                              new DayaBay::SimTrigCommand(det,type,trigcycle,0,totalAdc[i],DayaBay::ESumComp::kESumLow);
00221               debug() << "Adding Lower Esum Trigger at cycle\t" <<  i
00222                       << " With type " << type 
00223                       << " \n\t Nhit clock cycle: " << trigcycle
00224                       << " \n\t Esum clock cycle: " << i << endreq;
00225               verbose() << "Waiting " << m_recoveryCycles 
00226                         << " cycles to recover" << endreq;           
00227               i += m_recoveryCycles;
00228               trigCH->addCommand(tc);
00229               
00230           }
00231       }
00232       
00233       // Do TotalEsumTriggers
00234       for( unsigned int i = 0; i < totalEsum.size() ; ++i )
00235       {
00236           if ( totalEsum[i] >= DTthreshold )
00237           {
00238               DayaBay::Trigger::TriggerType_t type = getTriggerType(det);
00239               type = DayaBay::Trigger::TriggerType_t(DayaBay::Trigger::kESumAll);
00240 
00241               unsigned int trigcycle = 2* ( 1 + 
00242                            (i * DayaBay::AdcCycles) / (DayaBay::EsumCycles) );
00243               DayaBay::SimTrigCommand *tc = 
00244                              new DayaBay::SimTrigCommand(det,type,trigcycle,0,totalAdc[i],DayaBay::ESumComp::kESumTotal);
00245               debug() << "Adding Total Esum Trigger at cycle\t" <<  i
00246                       << " With type " << type 
00247                       << " \n\t Nhit clock cycle: " << trigcycle
00248                       << " \n\t Esum clock cycle: " << i << endreq;
00249               verbose() << "Waiting " << m_recoveryCycles 
00250                         << " cycles to recover" << endreq;           
00251               i += m_recoveryCycles;
00252               trigCH->addCommand(tc);
00253               
00254           }
00255       }
00256       
00257       // Do DigitalEsumTriggers
00258       for( unsigned int i = 0; i < totalAdc.size() ; ++i )
00259       {
00260           if ( totalAdc[i] >= getDigitalValue(DTthreshold) )
00261           {
00262               DayaBay::Trigger::TriggerType_t type = getTriggerType(det);
00263               type = DayaBay::Trigger::TriggerType_t(DayaBay::Trigger::kESumADC);
00264 
00265               unsigned int trigcycle = 2* ( 1 + 
00266                            (i * DayaBay::AdcCycles) / (DayaBay::EsumCycles) );
00267               DayaBay::SimTrigCommand *tc = 
00268                              new DayaBay::SimTrigCommand(det,type,trigcycle,0,totalAdc[i],0);
00269               debug() << "Adding ADC Esum Trigger at cycle\t" <<  i
00270                       << " With type " << type 
00271                       << " \n\t Nhit clock cycle: " << trigcycle
00272                       << " \n\t Esum clock cycle: " << i << endreq;
00273               verbose() << "Waiting " << m_recoveryCycles 
00274                         << " cycles to recover" << endreq;           
00275               i += m_recoveryCycles;
00276               trigCH->addCommand(tc);
00277               
00278           }
00279       }
00280         
00281     }// end if crate exists
00282   }
00283   return StatusCode::SUCCESS;                               
00284 }
00285 
00286 // provide mutate to satisfy interface ITsTriggerTool.
00287 StatusCode TsESumTriggerTool::mutate(DayaBay::SimTrigHeader* trigHeader,
00288                                      const DayaBay::ElecHeader& elecHeader)
00289 {     
00290   return fillTriggers(trigHeader,elecHeader);
00291 }
00292 
00293 // provide interfaces so the defualt way of assigning threshods / 
00294 // types can be transparantly changed.
00295 
00296 double TsESumTriggerTool::getULThreshold(DayaBay::Detector det){
00297     if( m_UpperLowerThresholdMap.find(det.detName()) 
00298                    != m_UpperLowerThresholdMap.end() ){
00299         return m_UpperLowerThresholdMap[det.detName()];
00300     }
00301     warning() << "Requesting a esum threshold for " << det.detName() 
00302               << " but none was specified in imput map " << endreq;
00303     warning() << "Using default value as defined in Conventions/Trigger.h"
00304               << endreq;
00305   if(det.detectorId() == DetectorId::kAD1 || 
00306      det.detectorId() == DetectorId::kAD2 ||
00307      det.detectorId() == DetectorId::kAD3 || 
00308      det.detectorId() == DetectorId::kAD4 ){
00309     return DayaBay::Trigger::kADESumThreshold;
00310   }
00311   if(det.detectorId() == DetectorId::kIWS){
00312     if(det.site() == Site::kFar){
00313        return DayaBay::Trigger::kFarIWSESumThreshold;
00314     }else{
00315        return DayaBay::Trigger::kNearIWSESumThreshold;
00316     }
00317   }
00318   if(det.detectorId() == DetectorId::kOWS){
00319     if(det.site() == Site::kFar){
00320        return DayaBay::Trigger::kFarOWSESumThreshold;
00321     }else{
00322        return DayaBay::Trigger::kNearOWSESumThreshold;
00323     }
00324   }
00325   return 0.0;
00326 }
00327 
00328 double TsESumTriggerTool::getDTThreshold(DayaBay::Detector det){
00329   if( m_TotalDigitalThresholdMap.find(det.detName()) 
00330                  != m_TotalDigitalThresholdMap.end() ){
00331       return m_TotalDigitalThresholdMap[det.detName()];
00332   }
00333   
00334   warning() << "Requesting a esum threshold for " << det.detName() 
00335             << " but none was specified in imput map " << endreq;
00336   warning() << "Using default value as defined in Conventions/Trigger.h"
00337             << endreq;
00338             
00339   if(det.detectorId() == DetectorId::kAD1 || 
00340      det.detectorId() == DetectorId::kAD2 ||
00341      det.detectorId() == DetectorId::kAD3 || 
00342      det.detectorId() == DetectorId::kAD4 ){
00343     return DayaBay::Trigger::kADESumThreshold;
00344   }
00345   if(det.detectorId() == DetectorId::kIWS){
00346     if(det.site() == Site::kFar){
00347        return DayaBay::Trigger::kFarIWSESumThreshold;
00348     }else{
00349        return DayaBay::Trigger::kNearIWSESumThreshold;
00350     }
00351   }
00352   if(det.detectorId() == DetectorId::kOWS){
00353     if(det.site() == Site::kFar){
00354        return DayaBay::Trigger::kFarOWSESumThreshold;
00355     }else{
00356        return DayaBay::Trigger::kNearOWSESumThreshold;
00357     }
00358   }
00359   return 0.0;
00360 }
00361 
00362 DayaBay::Trigger::TriggerType_t TsESumTriggerTool::getTriggerType(DayaBay::Detector det){
00363   DayaBay::Trigger::TriggerType_t type = DayaBay::Trigger::kUnknown;
00364   if(det.detectorId() == DetectorId::kAD1) type = DayaBay::Trigger::kAD1;
00365   if(det.detectorId() == DetectorId::kAD2) type = DayaBay::Trigger::kAD2;
00366   if(det.detectorId() == DetectorId::kAD3) type = DayaBay::Trigger::kAD3;
00367   if(det.detectorId() == DetectorId::kAD4) type = DayaBay::Trigger::kAD4;
00368   if(det.detectorId() == DetectorId::kIWS) type = DayaBay::Trigger::kIWS;
00369   if(det.detectorId() == DetectorId::kOWS) type = DayaBay::Trigger::kOWS;
00370   if( type == DayaBay::Trigger::kUnknown) return type;
00371   return DayaBay::Trigger::TriggerType_t(DayaBay::Trigger::kESum | type); 
00372 }
00373 
00374 int TsESumTriggerTool::getDigitalValue(double analogThresh){
00375     analogThresh=0; // yes compliler I am used, please don't warn me.
00376     return 4095; // essentially turn it off right now
00377     //return (unsigned int) analogThresh;
00378 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:50:03 2011 for TrigSim by doxygen 1.4.7