Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:10

0001 /**
0002  * Author: Giovanni Franzoni, UMN
0003  * Created: 08 May 2012
0004  * $Id: EcalSampleMask.cc,v 1.1 2012/05/10 08:22:09 argiro Exp $
0005  **/
0006 
0007 #include <cassert>
0008 #include "CondFormats/EcalObjects/interface/EcalSampleMask.h"
0009 #include "DataFormats/EcalDigi/interface/EcalDataFrame.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 using edm::LogError;
0013 
0014 EcalSampleMask::EcalSampleMask() {
0015   // by default, all samples are set as active
0016   sampleMaskEB_ = pow(2, EcalDataFrame::MAXSAMPLES) - 1;
0017   sampleMaskEE_ = pow(2, EcalDataFrame::MAXSAMPLES) - 1;
0018 }
0019 
0020 EcalSampleMask::EcalSampleMask(const unsigned int ebmask, const unsigned int eemask) {
0021   sampleMaskEB_ = ebmask;
0022   sampleMaskEE_ = eemask;
0023 }
0024 
0025 EcalSampleMask::EcalSampleMask(const std::vector<unsigned int> &ebmask, const std::vector<unsigned int> &eemask) {
0026   setEcalSampleMaskRecordEB(ebmask);
0027   setEcalSampleMaskRecordEE(eemask);
0028 }
0029 
0030 EcalSampleMask::~EcalSampleMask() {}
0031 
0032 void EcalSampleMask::setEcalSampleMaskRecordEB(const std::vector<unsigned int> &ebmask) {
0033   // check that size of the vector is adequate
0034   if (ebmask.size() != static_cast<unsigned int>(EcalDataFrame::MAXSAMPLES)) {
0035     LogError("DataMismatch") << " in EcalSampleMask::setEcalSampleMaskRecordEB size of ebmask (" << ebmask.size()
0036                              << ") need to be: " << EcalDataFrame::MAXSAMPLES << ". Bailing out." << std::endl;
0037     assert(0);
0038   }
0039 
0040   // check that values of vector are allowed
0041   for (unsigned int s = 0; s < ebmask.size(); s++) {
0042     if (ebmask.at(s) == 0 || ebmask.at(s) == 1) {
0043       ;
0044     } else {
0045       LogError("DataMismatch")
0046           << "in EcalSampleMask::setEcalSampleMaskRecordEB ebmask can only have values 0 or 1, while " << ebmask.at(s)
0047           << " was found. Bailing out. " << std::endl;
0048       assert(0);
0049     }
0050   }
0051 
0052   // ordering of bits:
0053   // ebmask.at(0)                         refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
0054   // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last  sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
0055   sampleMaskEB_ = 0;
0056   for (unsigned int sampleId = 0; sampleId < ebmask.size(); sampleId++) {
0057     sampleMaskEB_ |= (0x1 << (EcalDataFrame::MAXSAMPLES - (sampleId + 1)));
0058   }
0059 }
0060 
0061 void EcalSampleMask::setEcalSampleMaskRecordEE(const std::vector<unsigned int> &eemask) {
0062   // check that size of the vector is adequate
0063   if (eemask.size() != static_cast<unsigned int>(EcalDataFrame::MAXSAMPLES)) {
0064     LogError("DataMismatch") << " in EcalSampleMask::setEcalSampleMaskRecordEE size of eemask (" << eemask.size()
0065                              << ") need to be: " << EcalDataFrame::MAXSAMPLES << ". Bailing out." << std::endl;
0066     assert(0);
0067   }
0068 
0069   // check that values of vector are allowed
0070   for (unsigned int s = 0; s < eemask.size(); s++) {
0071     if (eemask.at(s) == 0 || eemask.at(s) == 1) {
0072       ;
0073     } else {
0074       LogError("DataMismatch")
0075           << "in EcalSampleMask::setEcalSampleMaskRecordEE eemask can only have values 0 or 1, while " << eemask.at(s)
0076           << " was found. Bailing out. " << std::endl;
0077       assert(0);
0078     }
0079   }
0080 
0081   // ordering of bits:
0082   // eemask.at(0)                         refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEE_
0083   // eemask.at(EcalDataFrame::MAXSAMPLES) refers to the last  sample read out and is mapped into the _least_ significant bit of sampleMaskEE_
0084   sampleMaskEE_ = 0;
0085   for (unsigned int sampleId = 0; sampleId < eemask.size(); sampleId++) {
0086     sampleMaskEE_ |= (0x1 << (EcalDataFrame::MAXSAMPLES - (sampleId + 1)));
0087   }
0088 }
0089 
0090 bool EcalSampleMask::useSampleEB(const int sampleId) const {
0091   if (sampleId >= EcalDataFrame::MAXSAMPLES) {
0092     LogError("DataMismatch") << "in EcalSampleMask::useSampleEB only sampleId up to: " << EcalDataFrame::MAXSAMPLES
0093                              << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
0094     assert(0);
0095   }
0096 
0097   // ordering convention:
0098   // ebmask.at(0)                         refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
0099   // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last  sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
0100   return (sampleMaskEB_ & (0x1 << (EcalDataFrame::MAXSAMPLES - (sampleId + 1))));
0101 }
0102 
0103 bool EcalSampleMask::useSampleEE(const int sampleId) const {
0104   if (sampleId >= EcalDataFrame::MAXSAMPLES) {
0105     LogError("DataMismatch") << "in EcalSampleMask::useSampleEE only sampleId up to: " << EcalDataFrame::MAXSAMPLES
0106                              << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
0107     assert(0);
0108   }
0109 
0110   // ordering convention:
0111   // ebmask.at(0)                         refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
0112   // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last  sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
0113   return (sampleMaskEE_ & (0x1 << (EcalDataFrame::MAXSAMPLES - (sampleId + 1))));
0114 }
0115 
0116 bool EcalSampleMask::useSample(const int sampleId, DetId &theCrystalId) const {
0117   if (sampleId >= EcalDataFrame::MAXSAMPLES) {
0118     LogError("DataMismatch") << "in EcalSampleMask::useSample only sampleId up to: " << EcalDataFrame::MAXSAMPLES
0119                              << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
0120     assert(0);
0121   }
0122 
0123   if (theCrystalId.subdetId() == EcalBarrel) {
0124     return useSampleEB(sampleId);
0125   } else if (theCrystalId.subdetId() == EcalEndcap) {
0126     return useSampleEE(sampleId);
0127   } else {
0128     LogError("DataMismatch")
0129         << "EcalSampleMaskuseSample::useSample can only be called for EcalBarrel or EcalEndcap DetID" << std::endl;
0130     assert(0);
0131   }
0132 }
0133 
0134 //  LocalWords:  eemask