CMS 3D CMS Logo

SiStripApvShotCleaner.cc
Go to the documentation of this file.
2 #include <algorithm>
3 #include <boost/foreach.hpp>
4 
5 //Uncomment the following #define to have print debug
6 //#define DEBUGME
7 
10  maxNumOfApvs(6), //FED Default: 6 (i.e. max num apvs )
11  stripsPerApv(128),
12  stripsForMedian(64){}
13 
14 
15 
18  if(in.size()<64)
19  return false;
20 
21  if(loop(in)){
22  reset(scan,end);
23  return true;
24  }
25  return false;
26 }
27 
30 
31 #ifdef DEBUGME
32  std::stringstream ss;
33  ss << __func__ << " working on detid " << in.detId() << " for a digi.size=" << in.size();
34 #endif
35 
36  shots_=false;
37  for (auto& val :shotApv_) val=false;
38 
39  cacheDetId=in.detId();
40 
41  //Find the position in the DetSet where the first strip of an apv should be inserted
42  // needed to deduce if at least stripsForMedian strips per apv have been fired
43  for(size_t i=0;i<=maxNumOfApvs;++i){
44 
45  SiStripDigi d(i*stripsPerApv,0); //Fake digi, at the edge of the apv
46  pFirstDigiOfApv[i] = std::lower_bound(in.begin(),in.end(),d);
47 
48  //if satisfied it means that the number of digis in the apv i-1 is above stripsForMedia -> apvShot
50  shots_=true;
51  shotApv_[i-1]=true;
52 #ifdef DEBUGME
53  ss << " found an apv shot of " << pFirstDigiOfApv[i]-pFirstDigiOfApv[i-1] << " digis in detid " << in.detId() << " apv " << i << std::endl;
54 #endif
55  }
56 
57  //---------------------
58  //Just for debug REMOVE
59  /*
60  if(i>0){
61  ss << "detid " << in.detId() << " apv " << i-1 << " number digis " << pFirstDigiOfApv[i]-pFirstDigiOfApv[i-1] << " \t shot " << shotApv_[i-1] << std::endl;
62  if(pFirstDigiOfApv[i]-pFirstDigiOfApv[i-1]>stripsForMedian-2){
63  edm::DetSet<SiStripDigi>::const_iterator dig=pFirstDigiOfApv[i-1];
64  while(dig!=pFirstDigiOfApv[i]){
65  ss << "\t strip " << dig->strip() << " dig.adc " << dig->adc();
66  dig++;
67  }
68  ss << std::endl;
69  }
70  }
71  */
72  //-------------------------------
73  }
74 
75 #ifdef DEBUGME
76  edm::LogInfo("ApvShot") << ss.str();
77 #endif
78 
79  if(!shots_)
80  return false;
81 
83  return true;
84 }
85 
88  vdigis.clear();
89  //loop on Apvs and remove shots. if an apv doesn't have shots, copy it
90  for(size_t i=0;i<maxNumOfApvs;++i){
91  apvDigis.clear();
92 
93  if(shotApv_[i]){
94  apvDigis.insert(apvDigis.end(),pFirstDigiOfApv[i],pFirstDigiOfApv[i+1]);
95  subtractCM();
96  std::stable_sort(apvDigis.begin(),apvDigis.end());
97  vdigis.insert(vdigis.end(),apvDigis.begin(),apvDigis.end());
98  }else{
99  vdigis.insert(vdigis.end(),pFirstDigiOfApv[i],pFirstDigiOfApv[i+1]);
100  }
101  }
102 
103 #ifdef DEBUGME
104  std::stringstream ss;
105  ss <<"detid " << cacheDetId << " new digi.size " << vdigis.size() << "\n";
106  for(size_t i=0;i<vdigis.size();++i)
107  ss << "\t " << i << " strip " << vdigis[i].strip() << " adc " << vdigis[i].adc() ;
108  edm::LogInfo("ApvShot") << ss.str() << std::endl;
109 #endif
110 }
111 
113 
114  //order by charge
115  std::stable_sort(apvDigis.begin(),apvDigis.end(),
116  [](SiStripDigi const& a, SiStripDigi const& b) {return a.adc() > b.adc();});
117 
118  //ignore case where 64th strip is 0ADC
119  if(apvDigis[stripsForMedian].adc()==0){
120 #ifdef DEBUGME
121  std::stringstream ss;
122  ss << "case with strip64=0 --> detid= "<<cacheDetId<< "\n";
123  edm::LogInfo("ApvShot") << ss.str();
124 #endif
125  return;
126  }
127 
128  //Find the Median
129  float CM = 0.5f*(apvDigis[stripsForMedian].adc()+apvDigis[stripsForMedian-1].adc());
130 
131 
132  if(CM<=0)
133  return;
134 
135  //Subtract the median
136  size_t i=0;
137  for(;i<stripsForMedian&&apvDigis[i].adc()>CM;++i){
138  uint16_t adc=apvDigis[i].adc()>253?apvDigis[i].adc():(uint16_t)(apvDigis[i].adc()-CM);
139  apvDigis[i]=SiStripDigi(apvDigis[i].strip(),adc);
140  }
141  apvDigis.resize(i);
142 
143 #ifdef DEBUGME
144  std::stringstream ss;
145  ss << "[subtractCM] detid " << cacheDetId << " CM is " << CM << " the remaining strips after CM subtraction are " << i;
146  edm::LogInfo("ApvShot") << ss.str();
147 #endif
148 }
149 
150 
154  pDetSet->data.swap(vdigis);
155  a=pDetSet->begin();
156  b=pDetSet->end();
157 }
int adc(sample_type sample)
get the ADC sample (12 bits)
iterator end()
Definition: DetSet.h:60
edm::DetSet< SiStripDigi >::const_iterator pFirstDigiOfApv[7]
int i
Definition: DBlmapReader.cc:9
void dumpInVector(edm::DetSet< SiStripDigi >::const_iterator *, size_t)
det_id_type detId() const
Definition: DetSet.h:72
std::vector< SiStripDigi > vdigis
size_type size() const
Definition: DetSet.h:63
void reset(edm::DetSet< SiStripDigi >::const_iterator &a, edm::DetSet< SiStripDigi >::const_iterator &b)
#define end
Definition: vmac.h:37
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
std::unique_ptr< edm::DetSet< SiStripDigi > > pDetSet
bool loop(const edmNew::DetSet< SiStripDigi > &in)
iterator begin()
Definition: DetSet.h:59
double b
Definition: hdecay.h:120
std::vector< SiStripDigi > apvDigis
double a
Definition: hdecay.h:121
bool clean(const edmNew::DetSet< SiStripDigi > &in, edmNew::DetSet< SiStripDigi >::const_iterator &scan, edmNew::DetSet< SiStripDigi >::const_iterator &end)
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
const uint16_t & adc() const
Definition: SiStripDigi.h:41