/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #include "TsMultTriggerTool.h" 00002 00003 #include "Conventions/Detectors.h" 00004 #include "Conventions/Trigger.h" 00005 #include "Conventions/Site.h" 00006 00007 #include "Event/ElecCrateHeader.h" 00008 #include "Event/ElecFeeCrate.h" 00009 00010 #include "Event/SimTrigCommand.h" 00011 #include "Event/SimTrigCommandHeader.h" 00012 #include "Event/SimTrigCommandCollection.h" 00013 00014 00015 TsMultTriggerTool::TsMultTriggerTool(const std::string& type, 00016 const std::string& name, 00017 const IInterface* parent) 00018 : GaudiTool(type,name,parent) 00019 { 00020 declareInterface< ITsTriggerTool >(this) ; 00021 // for now add all but RPC's as default. 00022 m_detectorsToProcess.push_back("DayaBayAD1"); 00023 m_detectorsToProcess.push_back("DayaBayAD2"); 00024 m_detectorsToProcess.push_back("DayaBayIWS"); 00025 m_detectorsToProcess.push_back("DayaBayOWS"); 00026 m_detectorsToProcess.push_back("LingAoAD1"); 00027 m_detectorsToProcess.push_back("LingAoAD2"); 00028 m_detectorsToProcess.push_back("LingAoIWS"); 00029 m_detectorsToProcess.push_back("LingAoOWS"); 00030 m_detectorsToProcess.push_back("FarAD1"); 00031 m_detectorsToProcess.push_back("FarAD2"); 00032 m_detectorsToProcess.push_back("FarAD3"); 00033 m_detectorsToProcess.push_back("FarAD4"); 00034 m_detectorsToProcess.push_back("FarIWS"); 00035 m_detectorsToProcess.push_back("FarOWS"); 00036 00037 m_NHitThresholdMap["DayaBayAD1"]=DayaBay::Trigger::kADthreshold; 00038 m_NHitThresholdMap["DayaBayAD2"]=DayaBay::Trigger::kADthreshold; 00039 m_NHitThresholdMap["DayaBayIWS"]=DayaBay::Trigger::kNearIWSthreshold; 00040 m_NHitThresholdMap["DayaBayOWS"]=DayaBay::Trigger::kNearOWSthreshold; 00041 m_NHitThresholdMap["LingAoAD1"]=DayaBay::Trigger::kADthreshold; 00042 m_NHitThresholdMap["LingAoAD2"]=DayaBay::Trigger::kADthreshold; 00043 m_NHitThresholdMap["LingAoIWS"]=DayaBay::Trigger::kNearIWSthreshold; 00044 m_NHitThresholdMap["LingAoOWS"]=DayaBay::Trigger::kNearOWSthreshold; 00045 m_NHitThresholdMap["FarAD1"]=DayaBay::Trigger::kADthreshold; 00046 m_NHitThresholdMap["FarAD2"]=DayaBay::Trigger::kADthreshold; 00047 m_NHitThresholdMap["FarAD3"]=DayaBay::Trigger::kADthreshold; 00048 m_NHitThresholdMap["FarAD4"]=DayaBay::Trigger::kADthreshold; 00049 m_NHitThresholdMap["FarIWS"]=DayaBay::Trigger::kFarIWSthreshold; 00050 m_NHitThresholdMap["FarOWS"]=DayaBay::Trigger::kFarOWSthreshold; 00051 00052 00053 declareProperty("DetectorsToProcess",m_detectorsToProcess, 00054 "List of detectors to process with this tool"); 00055 declareProperty("RecoveryTime",m_recoveryCycles=8, 00056 "Number of nhit (80MHz) clock cycles for trigger dead time"); 00057 declareProperty("NHitTriggerThreshold",m_NHitThresholdMap, 00058 "Map indexed by detector name with Nhit Thresold"); 00059 00060 declareProperty("ADThreshold", 00061 m_ADThreshold = DayaBay::Trigger::kADthreshold, 00062 "DEPRICATED NHit threshold for AD Multiplicty Trigger"); 00063 declareProperty("FarIWSThreshold", 00064 m_FarIWSThreshold=DayaBay::Trigger::kFarIWSthreshold, 00065 "DEPRICATED NHit threshold for FarIWS Multiplicity Trigger"); 00066 declareProperty("FarOWSThreshold", 00067 m_FarOWSThreshold=DayaBay::Trigger::kFarOWSthreshold, 00068 "DEPRICATED NHit threshold for FarOWS Multiplicity Trigger"); 00069 declareProperty("NearIWSThreshold", 00070 m_NearIWSThreshold=DayaBay::Trigger::kNearIWSthreshold, 00071 "NHit threshold for NearIWS Multiplicity Trigger"); 00072 declareProperty("NearOWSThreshold", 00073 m_NearOWSThreshold=DayaBay::Trigger::kNearOWSthreshold, 00074 "DEPRICATED NHit threshold for NearOWS Multiplicity Trigger"); 00075 } 00076 00077 TsMultTriggerTool::~TsMultTriggerTool(){} 00078 00079 StatusCode TsMultTriggerTool::initialize() 00080 { 00081 std::vector<std::string>::iterator it; 00082 00083 // loop over detectors 00084 for(it = m_detectorsToProcess.begin(); 00085 it != m_detectorsToProcess.end(); 00086 ++it){ 00087 short int detId = DayaBay::Detector::siteDetPackedFromString(*it); 00088 DayaBay::Detector det(detId); 00089 info() << det 00090 << " is setup with threshold " 00091 << getThreshold(det) 00092 << endreq; 00093 } 00094 00095 if(m_ADThreshold != (int) DayaBay::Trigger::kADthreshold){ 00096 warning() << "ADThreshold Depricated use NHitTriggerThreshold" 00097 << endreq; 00098 } 00099 if(m_NearIWSThreshold != (int) DayaBay::Trigger::kNearIWSthreshold){ 00100 warning() << "NearIWSThreshold Depricated use NHitTriggerThreshold" 00101 << endreq; 00102 } 00103 if(m_NearOWSThreshold != (int) DayaBay::Trigger::kNearOWSthreshold){ 00104 warning() << "NearOWSThreshold Depricated use NHitTriggerThreshold" 00105 << endreq; 00106 } 00107 if(m_FarIWSThreshold != (int) DayaBay::Trigger::kFarIWSthreshold){ 00108 warning() << "FarIWSThreshold Depricated use NHitTriggerThreshold" 00109 << endreq; 00110 } 00111 if(m_FarOWSThreshold != (int) DayaBay::Trigger::kFarOWSthreshold){ 00112 warning() << "FarOWSThreshold Depricated use NHitTriggerThreshold" 00113 << endreq; 00114 } 00115 00116 return StatusCode::SUCCESS; 00117 } 00118 00119 StatusCode TsMultTriggerTool::finalize() 00120 { 00121 return StatusCode::SUCCESS; 00122 } 00123 00124 StatusCode TsMultTriggerTool::fillTriggers(DayaBay::SimTrigHeader* trigHeader, 00125 const DayaBay::ElecHeader& elecHeader) 00126 { 00127 debug() << "running fillTriggers()" << endreq; 00128 DayaBay::SimTrigCommandHeader* trigCH 00129 = const_cast<DayaBay::SimTrigCommandHeader*>(trigHeader->commandHeader()); 00130 00131 const DayaBay::ElecCrateHeader* crateHeader = elecHeader.crateHeader(); 00132 DayaBay::ElecCrateHeader::CrateMap cmap = crateHeader->crates(); 00133 DayaBay::ElecCrateHeader::CrateMap::iterator detIterator; 00134 00135 std::vector<std::string>::iterator it; 00136 debug() << "processing " << m_detectorsToProcess.size() << " detectors." << endreq; 00137 00138 // loop over detectors 00139 for(it = m_detectorsToProcess.begin(); 00140 it != m_detectorsToProcess.end(); 00141 ++it){ 00142 short int detId = DayaBay::Detector::siteDetPackedFromString(*it); 00143 DayaBay::Detector det(detId); 00144 verbose() << "Processing " << *it << " which is " << det << endreq; 00145 00146 const DayaBay::SimTrigCommandHeader::detCollMap trigCollMap = trigCH->collections(); 00147 00148 detIterator = cmap.find(det); 00149 if(detIterator != cmap.end()){ 00150 // A crate was found for this detector 00151 debug() << "A crate was found for " << det 00152 << " processing..." << endreq; 00153 00154 // Only create and add triggers if there is a crate for it... 00155 00156 if(trigCollMap.find(det) == trigCollMap.end()){ 00157 DayaBay::SimTrigCommandCollection *tcc = new DayaBay::SimTrigCommandCollection(); 00158 tcc->setHeader(trigCH); 00159 tcc->setDetector(det); 00160 trigCH->addCollection(tcc); 00161 } 00162 // Get the crate from the header object 00163 DayaBay::ElecFeeCrate *crate 00164 = dynamic_cast<DayaBay::ElecFeeCrate*>(cmap[det]); 00165 00166 DayaBay::ElecFeeCrate::DigitalMap hits = crate->nhit(); 00167 DayaBay::ElecFeeCrate::DigitalMap::iterator brIt; 00168 DayaBay::DigitalSignal bSum; 00169 00170 // make running sum over all boards 00171 for(brIt = hits.begin(); brIt != hits.end(); ++brIt){ 00172 if(bSum.empty()) bSum.resize((brIt->second).size(),0); 00173 DayaBay::DigitalSignal bSig= brIt->second; 00174 00175 for(size_t i = 0; i != bSig.size(); ++i){ 00176 //info() << *it << "\t" << endreq; 00177 bSum.at(i)+=bSig.at(i); 00178 } 00179 } // end make running sum 00180 00181 unsigned int threshold = getThreshold(det); 00182 verbose() << "Trigger Threshold " << threshold 00183 << " Board Sum Size " << bSum.size() << endreq; 00184 00185 00186 int maxNsum = -1; 00187 for(unsigned int i=0; i < bSum.size(); ++i){ 00188 if( maxNsum < bSum[i] ) maxNsum = bSum[i]; 00189 } 00190 debug() << "Max multiplicity for " << det << " is " << maxNsum << endreq; 00191 00192 // issue trigger if detector goes over threshold 00193 for(unsigned int i=0; i < bSum.size(); ++i){ 00194 verbose() << "Board sum entry for cycle #"<< i << "\t is " << bSum[i] << endreq; 00195 if ( (unsigned int)bSum[i] >= threshold ){ 00196 DayaBay::Trigger::TriggerType_t type = getTriggerType(det); 00199 DayaBay::SimTrigCommand *tc = new DayaBay::SimTrigCommand(det,type,i,bSum[i],0,0); 00200 debug() << "Adding Trigger at cycle\t" << i 00201 << " With type " << type << endreq; 00202 verbose() << "Waiting " << m_recoveryCycles << " cycles to recover" << endreq; 00203 i += m_recoveryCycles; 00204 trigCH->addCommand(tc); 00205 } 00206 }// end issue trigger 00207 00208 }// end if crate exists 00209 } 00210 return StatusCode::SUCCESS; 00211 } 00212 00213 // provide mutate to satisfy interface ITsTriggerTool. 00214 StatusCode TsMultTriggerTool::mutate(DayaBay::SimTrigHeader* trigHeader, 00215 const DayaBay::ElecHeader& elecHeader) 00216 { 00217 return fillTriggers(trigHeader,elecHeader); 00218 } 00219 00220 // provide interfaces so the defualt way of assigning threshods / types can be transparantly changed. 00221 00222 unsigned int TsMultTriggerTool::getThreshold(DayaBay::Detector det){ 00223 if( m_NHitThresholdMap.find(det.detName()) 00224 != m_NHitThresholdMap.end() ){ 00225 return m_NHitThresholdMap[det.detName()]; 00226 } 00227 { 00228 static int count = 10; 00229 if (count) { 00230 --count; 00231 warning() << "Requesting a NHit threshold for " << det.detName() 00232 << " but none was specified in input map " 00233 << "Using default value as defined in Conventions/Trigger.h. Warning you " 00234 << count << " more times" 00235 << endreq; 00236 } 00237 } 00238 if(det.detectorId() == DetectorId::kAD1 || 00239 det.detectorId() == DetectorId::kAD2 || 00240 det.detectorId() == DetectorId::kAD3 || 00241 det.detectorId() == DetectorId::kAD4 ){ 00242 return DayaBay::Trigger::kADthreshold; 00243 } 00244 if(det.detectorId() == DetectorId::kIWS){ 00245 if(det.site() == Site::kFar){ 00246 return DayaBay::Trigger::kFarIWSthreshold; 00247 }else{ 00248 return DayaBay::Trigger::kNearIWSthreshold; 00249 } 00250 } 00251 if(det.detectorId() == DetectorId::kOWS){ 00252 if(det.site() == Site::kFar){ 00253 return DayaBay::Trigger::kFarOWSthreshold; 00254 }else{ 00255 return DayaBay::Trigger::kNearOWSthreshold; 00256 } 00257 } 00258 return 0; 00259 } 00260 00261 DayaBay::Trigger::TriggerType_t TsMultTriggerTool::getTriggerType(DayaBay::Detector det){ 00262 return DayaBay::Trigger::kMult; 00263 }