CMS 3D CMS Logo

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