CMS 3D CMS Logo

EcalSampleMask.cc
Go to the documentation of this file.
1 
7 #include <cassert>
10 
12 {
13  // by default, all samples are set as active
16 }
17 
18 
19 EcalSampleMask::EcalSampleMask(const unsigned int ebmask, const unsigned int eemask) {
20  sampleMaskEB_ = ebmask;
21  sampleMaskEE_ = eemask;
22 }
23 
24 
25 EcalSampleMask::EcalSampleMask( const std::vector<unsigned int> &ebmask, const std::vector<unsigned int> &eemask) {
26  setEcalSampleMaskRecordEB( ebmask );
27  setEcalSampleMaskRecordEB( eemask );
28 }
29 
30 
32 
33 }
34 
35 
36 void EcalSampleMask::setEcalSampleMaskRecordEB( const std::vector<unsigned int> & ebmask ) {
37 
38  // check that size of the vector is adequate
39  if( ebmask.size() != static_cast<unsigned int>(EcalDataFrame::MAXSAMPLES) ){
40  std::cout << " in EcalSampleMask::setEcalSampleMaskRecordEB size of ebmask (" << ebmask.size() << ") need to be: " << EcalDataFrame::MAXSAMPLES
41  << ". Bailing out."<< std::endl;
42  assert(0);
43  }
44 
45  // check that values of vector are allowed
46  for (unsigned int s=0; s<ebmask.size(); s++ ) {
47  if ( ebmask.at(s)==0 || ebmask.at(s)==1 ) {;}
48  else {
49  std::cout << "in EcalSampleMask::setEcalSampleMaskRecordEB ebmask can only have values 0 or 1, while " << ebmask.at(s) << " was found. Bailing out. " << std::endl;
50  assert(0);
51  }
52  }
53 
54  // ordering of bits:
55  // ebmask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
56  // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
57  sampleMaskEB_=0;
58  for (unsigned int sampleId=0; sampleId<ebmask.size(); sampleId++ ) {
59  sampleMaskEB_ |= (0x1 << (EcalDataFrame::MAXSAMPLES -(sampleId+1) ));
60  }
61 
62 }
63 
64 void EcalSampleMask::setEcalSampleMaskRecordEE( const std::vector<unsigned int> & eemask ) {
65 
66  // check that size of the vector is adequate
67  if( eemask.size() != static_cast<unsigned int>(EcalDataFrame::MAXSAMPLES) ){
68  std::cout << " in EcalSampleMask::setEcalSampleMaskRecordEE size of eemask (" << eemask.size() << ") need to be: " << EcalDataFrame::MAXSAMPLES
69  << ". Bailing out."<< std::endl;
70  assert(0);
71  }
72 
73  // check that values of vector are allowed
74  for (unsigned int s=0; s<eemask.size(); s++ ) {
75  if ( eemask.at(s)==0 || eemask.at(s)==1 ) {;}
76  else {
77  std::cout << "in EcalSampleMask::setEcalSampleMaskRecordEE eemask can only have values 0 or 1, while " << eemask.at(s) << " was found. Bailing out. " << std::endl;
78  assert(0);
79  }
80  }
81 
82  // ordering of bits:
83  // eemask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEE_
84  // eemask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEE_
85  sampleMaskEE_=0;
86  for (unsigned int sampleId=0; sampleId<eemask.size(); sampleId++ ) {
87  sampleMaskEE_ |= (0x1 << (EcalDataFrame::MAXSAMPLES -(sampleId+1) ));
88  }
89 
90 }
91 
92 
93 bool EcalSampleMask::useSampleEB (const int sampleId) const {
94 
95  if( sampleId >= EcalDataFrame::MAXSAMPLES ){
96  std::cout << "in EcalSampleMask::useSampleEB only sampleId up to: " << EcalDataFrame::MAXSAMPLES
97  << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
98  assert(0);
99  }
100 
101  // ordering convention:
102  // ebmask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
103  // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
104  return ( sampleMaskEB_ & ( 0x1<< (EcalDataFrame::MAXSAMPLES -(sampleId+1) )) );
105 
106 }
107 
108 
109 bool EcalSampleMask::useSampleEE (const int sampleId) const {
110 
111  if( sampleId >= EcalDataFrame::MAXSAMPLES ){
112  std::cout << "in EcalSampleMask::useSampleEE only sampleId up to: " << EcalDataFrame::MAXSAMPLES
113  << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
114  assert(0);
115  }
116 
117  // ordering convention:
118  // ebmask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
119  // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
120  return ( sampleMaskEE_ & ( 0x1<< (EcalDataFrame::MAXSAMPLES -(sampleId+1) )) );
121 
122 }
123 
124 
125 bool EcalSampleMask::useSample (const int sampleId, DetId &theCrystalId) const {
126 
127  if( sampleId >= EcalDataFrame::MAXSAMPLES ){
128  std::cout << "in EcalSampleMask::useSample only sampleId up to: " << EcalDataFrame::MAXSAMPLES
129  << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
130  assert(0);
131  }
132 
133 
134  if (theCrystalId.subdetId()==EcalBarrel) {
135  return useSampleEB ( sampleId );
136  }
137  else if (theCrystalId.subdetId()==EcalEndcap) {
138  return useSampleEE ( sampleId );
139  }
140  else {
141  std::cout << "EcalSampleMaskuseSample::useSample can only be called for EcalBarrel or EcalEndcap DetID" << std::endl;
142  assert(0);
143  }
144 
145 }
146 
147 // LocalWords: eemask
void setEcalSampleMaskRecordEE(const unsigned int mask)
unsigned int sampleMaskEB_
bool useSample(const int sampleId, DetId &theCrystal) const
bool useSampleEB(const int sampleId) const
unsigned int sampleMaskEE_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
void setEcalSampleMaskRecordEB(const unsigned int mask)
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool useSampleEE(const int sampleId) const