In case of overlap merge signal and background collections.
loop over the SPU - collecting thr data by layer do the overlay by igas layer in a chamber
for the non-precision strips, all the 4 layers in a chamber are in the same SPU, we need to recover the data by chamber layer
287{
289
290
291 unsigned int nSigSamples = bkgCollection->
numSamples();
292 unsigned int nOvlSamples = signalCollection->
numSamples();
293
294
295 unsigned int dataSamplingTime = bkgCollection->
rate();
296 unsigned int ovlSamplingTime = signalCollection->
rate();
297
298 if ( dataSamplingTime != ovlSamplingTime ) {
299 ATH_MSG_ERROR(
"Overlay of inconsistent data - sampling times not the same "
300 << dataSamplingTime << " ns " << ovlSamplingTime << " ns");
301 throw std::runtime_error("mergeCollections(): sampling time mismatch");
302 }
303
304 if ( nSigSamples != nOvlSamples ) {
305 ATH_MSG_ERROR(
"Overlay of inconsistent data - number of samples not the same "
306 << nSigSamples << " " << nOvlSamples);
307 throw std::runtime_error("mergeCollections(): number of samples mismatch");
308 }
309
312 uint16_t clusterCounts[] = {0,0,0,0,0,0,0,0,0,0};
314 for ( uint16_t spuID=0; spuID<10; ++spuID) {
315
316 std::vector<const CscRawData*> sigData;
317 this->
spuData(bkgCollection, spuID, sigData);
318
319 std::vector<const CscRawData*> ovlData;
320 this->
spuData(signalCollection, spuID, ovlData);
321
325 if ( spuID == 4 || spuID == 9 )
layer=4;
326 for (
int j=0; j<=
layer; ++j ) {
327 std::map< int,std::vector<uint16_t> > sigSamples;
328 std::map< int,std::vector<uint16_t> > ovlSamples;
332 uint32_t ovlAddress = this->
stripData( ovlData, nOvlSamples, ovlSamples, ovlHash, spuID, j ,
false);
333 if (sigSamples.size()==0 && ovlSamples.size()==0) continue;
334
336 uint32_t address = std::min( sigAddress, ovlAddress );
337 if (sigSamples.size()!=0 && ovlSamples.size()!=0 &&
needtoflip(address)){
338 ATH_MSG_DEBUG(
"Looking for overlap of hashes and addresses within widths because needtoflip");
339 msg() << MSG::VERBOSE ;
340 std::set<int>
sig;
int lastindex=-1;
341 for (std::map< int,std::vector<uint16_t> >::const_iterator si=sigSamples.begin(); si!=sigSamples.end(); ++si) {
342 if (si!=sigSamples.begin() && si->first-lastindex!=1) break;
343 lastindex=si->first;
344 sig.insert(si->first);
msg() << si->first <<
" ";
345 }
347 bool overlap=false;
348 msg() <<MSG::VERBOSE ;
349 for (std::map< int,std::vector<uint16_t> >::const_iterator so=ovlSamples.begin(); so!=ovlSamples.end(); ++so) {
350
351 msg() << (so->first)-1 <<
" ";
352 if (
sig.find((so->first)-1)!=
sig.end()) {overlap=
true;
msg() <<
"!!";}
353 msg() << (so->first) <<
" ";
354 if (
sig.find((so->first))!=
sig.end()) {overlap=
true;
msg() <<
"!!";}
355 msg() << (so->first)+1 <<
" ";
356 if (
sig.find((so->first)+1)!=
sig.end()) {overlap=
true;
msg() <<
"!!";}
357 }
359 if (!overlap){
360 ATH_MSG_DEBUG(
"Taking max of hashes and addresses because needtoflip and no overlap");
361 hash = std::max( sigHash, ovlHash );
362 address = std::max( sigAddress, ovlAddress );
363 }
364 }
365
366
367 std::set<int> insertedstrips, readstrips;
368 for (std::map<
int,std::vector<uint16_t> >::const_iterator s=sigSamples.begin(); s!=sigSamples.end(); ++s){readstrips.insert(
s->first);}
369 for (std::map< int,std::vector<uint16_t> >::const_iterator si=ovlSamples.begin(); si!=ovlSamples.end(); ++si){readstrips.insert(si->first);}
370
371 std::vector<CscRawData*> datums = this->
overlay(sigSamples, ovlSamples,address, spuID,
outputCollection->identify(), hash, rndmEngine);
373 for (unsigned int di=0; di<datums.size(); ++di){
377 int stripstart = ( address & 0x000000FF) + 1 + 0;
378 ATH_MSG_DEBUG(
"Datum in layer="<<j<<
" has hash="<<hash<<
" address="<<address<<
" stripstart="<<stripstart<<
", "<< *datum );
379 if (datum->
width()==0) {
381 continue;
382 }
383
384
385 int stationName = ( ( address & 0x00010000) >> 16 ) + 50;
386 int stationEta = ( ((address & 0x00001000) >> 12 ) == 0x0) ? -1 : 1;
387 int stationPhi = ( ( address & 0x0000E000) >> 13 ) + 1;
388 Identifier me=
m_idHelperSvc->cscIdHelper().elementID(stationName,stationEta,stationPhi);
389 ATH_MSG_VERBOSE(
"stationName,Eta,Phi="<<stationName<<
","<<stationEta<<
","<<stationPhi<<
" - me="<<me);
391 for (
unsigned int j=0; j<datum->
width(); ++j) {
392 int chamberLayer = ( (address & 0x00000800) >> 11) + 1;
393 int wireLayer = ( (address & 0x00000600) >> 9) + 1;
394 int measuresPhi = ( (address & 0x00000100) >> 8);
395 int strip = ( address & 0x000000FF) + 1 + j;
396 ATH_MSG_VERBOSE(
"chamberlayer,wirelayer,measuresphi,strip="<<chamberLayer<<
","<<wireLayer<<
","<<measuresPhi<<
","<<
strip);
397
398 if (measuresPhi) {
399 int stationEta = ( ((address & 0x00001000) >> 12 ) == 0x0) ? -1 : 1;
400 if (stationEta>0) {
403 }
404 }
405 insertedstrips.insert(
strip);
406 Identifier mechan=
m_idHelperSvc->cscIdHelper().channelID(me,chamberLayer,wireLayer,measuresPhi,
strip);
410 ATH_MSG_WARNING(
"Invalid CSC Identifier in merge! - skipping " << channelId );
412 }
413 else{
ATH_MSG_DEBUG(
"Valid CSC Identifier in merge " << channelId);}
414 }
416 else{ continue; }
417
418
419 if (spuID <10) clusterCounts[spuID] += 1;
420 if ( spuID <= 4 ) rpuCount[0] = 5;
421 else if ( spuID > 4 && spuID <= 9 ) rpuCount[1] = 11;
422 }
423
424
425 if (readstrips!=insertedstrips){
427 std::ostringstream readstream;
428 for (std::set<int>::const_iterator i = readstrips.begin(); i!=readstrips.end(); ++i){readstream<<*
i<<
" ";}
430 std::ostringstream insertstream;
431 for (std::set<int>::const_iterator i = insertedstrips.begin(); i!=insertedstrips.end(); ++i){insertstream<<*
i<<
" ";}
433 }
434
435 }
436 }
438 for (
unsigned int i=0;
i<2; ++
i) {
if (rpuCount[i] != 0)
outputCollection->addRPU(rpuCount[i]); }
439
441}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
void spuData(const CscRawDataCollection *coll, const uint16_t spuID, std::vector< const CscRawData * > &data) const
get the data in one SPU of a chamber
uint32_t stripData(const std::vector< const CscRawData * > &data, const unsigned int numSamples, std::map< int, std::vector< uint16_t > > &samples, uint32_t &hash, const uint16_t spuID, const int gasLayer, bool isdata) const
data in one gas lauer
bool needtoflip(const int address) const
Gaudi::Property< bool > m_isDataOverlay
uint16_t numSamples() const
uint8_t rate() const
the rate could be 25 or 50 ns
constexpr uint8_t stationPhi
station Phi 1 to 8
constexpr uint8_t stationEta
1 to 3