CMS 3D CMS Logo

ApvAnalysisFactory.cc
Go to the documentation of this file.
2 //#include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
3 
5 
6 using namespace std;
7 ApvAnalysisFactory::ApvAnalysisFactory(string theAlgorithmType, int theNumCMstripsInGroup, int theMaskCalcFlag, float theMaskNoiseCut,
8  float theMaskDeadCut,
9  float theMaskTruncCut,
10  float theCutToAvoidSignal,
11  int theEventInitNumber,
12  int theEventIterNumber){
13 
14  theAlgorithmType_ = theAlgorithmType;
15  theNumCMstripsInGroup_ = theNumCMstripsInGroup;
16  theMaskCalcFlag_ = theMaskCalcFlag;
17  theMaskNoiseCut_ = theMaskNoiseCut;
18  theMaskDeadCut_ = theMaskDeadCut;
19  theMaskTruncCut_ = theMaskTruncCut;
20  theCutToAvoidSignal_ = theCutToAvoidSignal;
21  theEventInitNumber_ = theEventInitNumber;
22  theEventIterNumber_ = theEventIterNumber;
23 
24 }
25 
27 
28  theCMType_ = pset.getParameter<string>("CMType");
29  useDB_ = pset.getParameter<bool>("useDB");
30 
31  theAlgorithmType_ = pset.getParameter<string>("CalculatorAlgorithm");
32  theNumCMstripsInGroup_ = pset.getParameter<int>("NumCMstripsInGroup");
33  theMaskCalcFlag_ = pset.getParameter<int>("MaskCalculationFlag");
34 
35  theMaskNoiseCut_ = pset.getParameter<double>("MaskNoiseCut");
36  theMaskDeadCut_ = pset.getParameter<double>("MaskDeadCut");
37  theMaskTruncCut_ = pset.getParameter<double>("MaskTruncationCut");
38  theCutToAvoidSignal_ = pset.getParameter<double>("CutToAvoidSignal");
39 
40  theEventInitNumber_ = pset.getParameter<int>("NumberOfEventsForInit");
41  theEventIterNumber_ = pset.getParameter<int>("NumberOfEventsForIteration");
42  apvMap_.clear();
43 
44 
45 }
46 //----------------------------------
48  ApvAnalysisFactory::ApvAnalysisMap::iterator it = apvMap_.begin();
49  for(;it!=apvMap_.end();it++)
50  {
51  vector<ApvAnalysis*>::iterator myApv = (*it).second.begin();
52  for(;myApv!=(*it).second.end();myApv++)
53  deleteApv(*myApv);
54  }
55  apvMap_.clear();
56 }
57 
58 //----------------------------------
59 
60 bool ApvAnalysisFactory::instantiateApvs(uint32_t detId, int numberOfApvs){
61 
62 
63  ApvAnalysisFactory::ApvAnalysisMap::iterator CPos = apvMap_.find(detId);
64  if(CPos != apvMap_.end()) {
65  cout << " APVs for Detector Id " << detId << " already created !!!" << endl;;
66  return false;
67  }
68  vector< ApvAnalysis* > temp;
69  for(int i=0;i<numberOfApvs;i++)
70  {
71  ApvAnalysis* apvTmp = new ApvAnalysis(theEventIterNumber_);
72  // constructAuxiliaryApvClasses(apvTmp);
73  constructAuxiliaryApvClasses(apvTmp,detId,i);
74  temp.push_back(apvTmp);
75  }
76  apvMap_.insert(pair< uint32_t, vector< ApvAnalysis* > >(detId, temp));
77  return true;
78 }
79 
80 std::vector<ApvAnalysis *> ApvAnalysisFactory::getApvAnalysis( const uint32_t nDET_ID)
81 {
82  ApvAnalysisMap::const_iterator _apvAnalysisIter = apvMap_.find( nDET_ID);
83 
84  return apvMap_.end() != _apvAnalysisIter ? _apvAnalysisIter->second : std::vector<ApvAnalysis *>();
85 }
86 
88  uint32_t detId,
89  int thisApv )
90 {
91  //----------------------------------------------------------------
92  // Create the ped/noise/CMN calculators, zero suppressors etc.
93  // (Is called by addDetUnitAndConstructApvs()).
94  //
95  // N.B. Don't call this twice for the same APV!
96  //-----------------------------------------------------------------
97  // cout<<"VirtualApvAnalysisFactory::constructAuxiliaryApvClasses"<<endl;
98  TkPedestalCalculator* thePedestal =nullptr;
99  TkNoiseCalculator* theNoise=nullptr;
100  TkApvMask* theMask=nullptr;
101  TkCommonModeCalculator* theCM=nullptr;
102 
103  TkCommonMode* theCommonMode = new TkCommonMode();
104  TkCommonModeTopology* theTopology = new TkCommonModeTopology(128, theNumCMstripsInGroup_);
105  theCommonMode->setTopology(theTopology);
106 
107  // Create desired algorithms.
108  if( theAlgorithmType_ == "TT6") {
109  theMask = new TT6ApvMask(theMaskCalcFlag_,theMaskNoiseCut_,theMaskDeadCut_,theMaskTruncCut_);
110  theNoise = new TT6NoiseCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
111  thePedestal = new TT6PedestalCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
112  theCM = new TT6CommonModeCalculator (theNoise, theMask, theCutToAvoidSignal_);
113  } else if( "TT6NT" == theAlgorithmType_) {
114  theMask = new TT6ApvMask( theMaskCalcFlag_,
115  theMaskNoiseCut_,
116  theMaskDeadCut_,
117  theMaskTruncCut_);
118  theNoise = new TT6NoiseCalculator( theEventInitNumber_,
119  theEventIterNumber_,
120  theCutToAvoidSignal_);
121  thePedestal = new TT6NTPedestalCalculator;
122  theCM = new TT6CommonModeCalculator( theNoise,
123  theMask,
124  theCutToAvoidSignal_);
125  } else if (theAlgorithmType_ == "MIX") {
126  // the mask as to be defined also for SimplePedCalculator
127  theMask = new TT6ApvMask(theMaskCalcFlag_,theMaskNoiseCut_,theMaskDeadCut_,theMaskTruncCut_);
128 
129  thePedestal = new SimplePedestalCalculator(theEventInitNumber_);
130 
131  theNoise = new SimpleNoiseCalculator(theEventInitNumber_, useDB_);
132 
133  if (theCMType_ == "Median"){
134  theCM = new MedianCommonModeCalculator ();
135  } else {
136  cout << "Sorry Only Median is available for now, Mean and FastLinear are coming soon" << endl;
137  }
138  }
139 
140 
141  if(theCommonMode)
142  theCM->setCM(theCommonMode);
143  if(thePedestal)
144  theAPV->setPedestalCalculator(*thePedestal);
145  if(theNoise)
146  theAPV->setNoiseCalculator(*theNoise);
147  if(theMask)
148  theAPV->setMask(*theMask);
149  if(theCM)
150  theAPV->setCommonModeCalculator(*theCM);
151 
152 
153 
154 }
155 
156 
157 void ApvAnalysisFactory::updatePair(uint32_t detId, size_t pairNumber, const edm::DetSet<SiStripRawDigi>& in)
158 {
159  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
160  if(apvAnalysisIt != apvMap_.end())
161  {
162  size_t iter=0;
163 
164  for(vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin(); apvIt != (apvAnalysisIt->second).end(); apvIt++)
165  {
166 
167  if (iter==pairNumber*2 || iter==(2*pairNumber+1)){
168 
169  // cout << "ApvAnalysisFactory::updatePair pair number " << pairNumber << endl;
170  // cout << "ApvAnlysis will be updated for the apv # " << iter << endl;
171 
172  edm::DetSet<SiStripRawDigi> tmpRawDigi;
173  tmpRawDigi.data.reserve(128);
174 
175  size_t startStrip = 128*(iter%2);
176  size_t stopStrip = startStrip + 128;
177 
178  for( size_t istrip = startStrip; istrip < stopStrip;istrip++)
179  {
180  if(in.data.size() <= istrip) tmpRawDigi.data.push_back( 0);
181  else tmpRawDigi.data.push_back(in.data[istrip]); //maybe dangerous
182  }
183 
184  (*apvIt)->newEvent();
185  (*apvIt)->updateCalibration(tmpRawDigi);
186 
187  }
188 
189  iter++;
190  }
191  }
192 
193 }// void
194 
195 
196 
197 
198 
200 {
201  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
202  if(apvAnalysisIt != apvMap_.end())
203  {
204  size_t i=0;
205  for(vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin(); apvIt != (apvAnalysisIt->second).end(); apvIt++)
206  {
207  edm::DetSet<SiStripRawDigi> tmpRawDigi;
208  //it is missing the detId ...
209  tmpRawDigi.data.reserve(128);
210  size_t startStrip = 128*i;
211  size_t stopStrip = startStrip + 128;
212 
213  for( size_t istrip = startStrip; istrip < stopStrip;istrip++)
214  {
215  if( in.data.size() <= istrip) tmpRawDigi.data.push_back(0);
216  else tmpRawDigi.data.push_back(in.data[istrip]); //maybe dangerous
217  }
218 
219  (*apvIt)->newEvent();
220  (*apvIt)->updateCalibration(tmpRawDigi);
221  i++;
222  }
223  }
224 
225 }
226 
227 
228 
229 void ApvAnalysisFactory::getPedestal(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& peds)
230 {
231  //Get the pedestal for a given apv
232  peds.clear();
233  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
234  if(apvAnalysisIt != apvMap_.end())
235  {
236  vector<ApvAnalysis*> myApvs = apvAnalysisIt->second;
237  peds = myApvs[apvNumber]->pedestalCalculator().pedestal();
238 
239  }
240 }
241 
243 {
244  //Get the pedestal for a given apv
245  peds.clear();
246  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
247  if(apvAnalysisIt != apvMap_.end())
248  {
249  vector<ApvAnalysis* > theApvs = apvAnalysisIt->second;
250  for(vector<ApvAnalysis*>::const_iterator it = theApvs.begin(); it != theApvs.end();it++)
251  {
252  ApvAnalysis::PedestalType tmp = (*it)->pedestalCalculator().pedestal();
253  for(ApvAnalysis::PedestalType::const_iterator pit =tmp.begin(); pit!=tmp.end(); pit++)
254  peds.push_back(*pit);
255  }
256  }
257 }
258 float ApvAnalysisFactory::getStripPedestal(uint32_t detId, int stripNumber)
259 {
260  //Get the pedestal for a given apv
262  int apvNumb = int(stripNumber / 128.);
263  int stripN = (stripNumber - apvNumb*128);
264 
265  getPedestal(detId, apvNumb, temp);
266  return temp[stripN];
267 
268 }
269  void ApvAnalysisFactory::getNoise(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& noise)
270 {
271  //Get the pedestal for a given apv
272  noise.clear();
273  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
274  if(apvAnalysisIt != apvMap_.end())
275  {
276  vector<ApvAnalysis* > theApvs = apvAnalysisIt->second;
277 
278  noise = theApvs[apvNumber]->noiseCalculator().noise();
279  }
280 }
281 
282 float ApvAnalysisFactory::getStripNoise(uint32_t detId, int stripNumber)
283 {
284  //Get the pedestal for a given apv
286  int apvNumb = int(stripNumber / 128.);
287  int stripN = (stripNumber - apvNumb*128);
288 
289  getNoise(detId, apvNumb, temp);
290  return temp[stripN];
291 
292 }
293 
295 {
296  //Get the pedestal for a given apv
297  peds.clear();
298  map<uint32_t, vector<ApvAnalysis* > >::const_iterator theApvs_map = apvMap_.find(detId);
299  if(theApvs_map != apvMap_.end())
300  {
301  vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
302  for(; theApvs != (theApvs_map->second).end();theApvs++)
303  {
304  ApvAnalysis::PedestalType tmp = (*theApvs)->noiseCalculator().noise();
305  for(ApvAnalysis::PedestalType::const_iterator pit =tmp.begin(); pit!=tmp.end(); pit++)
306  peds.push_back(*pit);
307  }
308  }
309 }
310 
311 
312  void ApvAnalysisFactory::getRawNoise(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& noise)
313 {
314  //Get the pedestal for a given apv
315  noise.clear();
316  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
317  if(apvAnalysisIt != apvMap_.end())
318  {
319  vector<ApvAnalysis* > theApvs = apvAnalysisIt->second;
320 
321  noise = theApvs[apvNumber]->pedestalCalculator().rawNoise();
322  }
323 }
324 
325 float ApvAnalysisFactory::getStripRawNoise(uint32_t detId, int stripNumber)
326 {
327  //Get the pedestal for a given apv
329  int apvNumb = int(stripNumber / 128.);
330  int stripN = (stripNumber - apvNumb*128);
331 
332  getRawNoise(detId, apvNumb, temp);
333  return temp[stripN];
334 
335 }
336 
338 {
339  //Get the pedestal for a given apv
340  peds.clear();
341  map<uint32_t, vector<ApvAnalysis* > >::const_iterator theApvs_map = apvMap_.find(detId);
342  if(theApvs_map != apvMap_.end())
343  {
344  vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
345  for(; theApvs != (theApvs_map->second).end();theApvs++)
346  {
347  ApvAnalysis::PedestalType tmp = (*theApvs)->pedestalCalculator().rawNoise();
348  for(ApvAnalysis::PedestalType::const_iterator pit =tmp.begin(); pit!=tmp.end(); pit++)
349  peds.push_back(*pit);
350  }
351  }
352 }
353 
354 
355 
356 vector<float> ApvAnalysisFactory::getCommonMode(uint32_t detId, int apvNumber)
357 {
358  vector<float> tmp;
359  tmp.clear();
360  map<uint32_t, vector<ApvAnalysis* > >::const_iterator theApvs_map = apvMap_.find(detId);
361  if(theApvs_map != apvMap_.end())
362  {
363  vector<ApvAnalysis* > theApvs = theApvs_map->second;
364 
365  tmp = theApvs[apvNumber]->commonModeCalculator().commonMode()->returnAsVector();
366  }
367  return tmp;
368 }
370 {
371 
372  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
373  if(apvAnalysisIt != apvMap_.end())
374  {
375  vector<ApvAnalysis* > theApvs = apvAnalysisIt->second;
376  for( unsigned int i=0; i< theApvs.size(); i++)
377  {
378  //To be fixed. We return only the first one in the vector.
379  vector<float> tmp_cm = theApvs[i]->commonModeCalculator().commonMode()->returnAsVector();
380  for( unsigned int it = 0; it < tmp_cm.size(); it++)
381  tmp.push_back( tmp_cm[it]);
382  }
383  }
384 }
385 
387 {
388 
389  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(det_id);
390  if(apvAnalysisIt != apvMap_.end()) {
391  vector<ApvAnalysis* > theApvs = apvAnalysisIt->second;
392  for( unsigned int i=0; i< theApvs.size(); i++)
393  {
394  TkApvMask::MaskType theMaskType = ( theApvs[i]->mask()).mask();
395  //cout <<"theMaskType size "<<theMaskType.size()<<endl;
396 
397  for( unsigned int ii=0;ii<theMaskType.size();ii++)
398  {
399  tmp.push_back(theMaskType[ii]);
400  //cout <<"The Value "<<theMaskType[ii]<<" "<<ii<<endl;
401  }
402  }
403  }
404 }
405 bool ApvAnalysisFactory::isUpdating(uint32_t detId)
406 {
407  bool updating = true;
408  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
409  if(apvAnalysisIt != apvMap_.end())
410  {
411  for(vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin(); apvIt != (apvAnalysisIt->second).end(); apvIt++)
412  {
413  if(!( (*apvIt)->pedestalCalculator().status()->isUpdating() ))
414  updating = false;
415  }
416  }
417  return updating;
418 
419 }
420 
422  delete &(apv->pedestalCalculator());
423  delete &(apv->noiseCalculator());
424  delete &(apv->mask());
425  delete &(apv->commonModeCalculator().commonMode()->topology());
426  delete (apv->commonModeCalculator().commonMode());
427  delete &(apv->commonModeCalculator());
428  delete apv;
429 
430 }
431 //
432 // -- Get Common Mode Slope
433 //
434 float ApvAnalysisFactory::getCommonModeSlope(uint32_t detId, int apvNumber){
435  map<uint32_t, vector<ApvAnalysis* > >::const_iterator theApvs_map = apvMap_.find(detId);
436  float tmp = -100.0;
437  if(theApvs_map != apvMap_.end()) {
438  vector<ApvAnalysis* > theApvs = theApvs_map->second;
439  tmp = theApvs[apvNumber]->commonModeCalculator().getCMSlope();
440  return tmp;
441  }
442  return tmp;
443 }
445 {
446  tmp.clear();
447  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
448  if(apvAnalysisIt != apvMap_.end()) {
449  vector<ApvAnalysis* > theApvs = apvAnalysisIt->second;
450  for( unsigned int i=0; i< theApvs.size(); i++) {
451  tmp.push_back(theApvs[i]->commonModeCalculator().getCMSlope());
452  }
453  }
454 }
std::vector< StripMaskType > MaskType
Definition: TkApvMask.h:17
T getParameter(std::string const &) const
std::vector< float > PedestalType
Definition: ApvAnalysis.h:48
virtual void setCM(TkCommonMode *)=0
TkCommonModeCalculator & commonModeCalculator()
Definition: ApvAnalysis.h:62
void getPedestal(uint32_t det_id, int apvNumber, ApvAnalysis::PedestalType &peds)
void getCommonModeSlope(uint32_t det_id, ApvAnalysis::PedestalType &tmp)
void getNoise(uint32_t det_id, int apvNumber, ApvAnalysis::PedestalType &noise)
void update(uint32_t det_id, const edm::DetSet< SiStripRawDigi > &in)
void getMask(uint32_t det_id, TkApvMask::MaskType &tmp)
float getStripNoise(uint32_t det_id, int stripNumber)
virtual TkCommonMode * commonMode()=0
void getRawNoise(uint32_t det_id, int apvNumber, ApvAnalysis::PedestalType &noise)
void deleteApv(ApvAnalysis *apv)
float getStripRawNoise(uint32_t det_id, int stripNumber)
virtual void setTopology(TkCommonModeTopology *in)
Definition: TkCommonMode.h:18
void updatePair(uint32_t det_id, size_t apvPair, const edm::DetSet< SiStripRawDigi > &in)
void setMask(TkApvMask &in)
Definition: ApvAnalysis.h:60
bool instantiateApvs(uint32_t det_id, int numberOfApvs)
void setPedestalCalculator(TkPedestalCalculator &in)
Definition: ApvAnalysis.h:58
void setNoiseCalculator(TkNoiseCalculator &in)
Definition: ApvAnalysis.h:59
void setCommonModeCalculator(TkCommonModeCalculator &in)
Definition: ApvAnalysis.h:57
#define end
Definition: vmac.h:39
TkPedestalCalculator & pedestalCalculator()
Definition: ApvAnalysis.h:63
void getCommonMode(uint32_t det_id, ApvAnalysis::PedestalType &tmp)
ii
Definition: cuy.py:590
virtual TkCommonModeTopology & topology()
Definition: TkCommonMode.h:17
ApvAnalysisVector getApvAnalysis(const uint32_t nDET_ID)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
ApvAnalysisFactory(std::string theAlgorithmType, int theNumCMstripsInGroup, int theMaskCalcFlag, float theMaskNoiseCut, float theMaskDeadCut, float theMaskTruncCut, float theCutToAvoidSignal, int theEventInitNumber, int theEventIterNumber)
collection_type data
Definition: DetSet.h:78
void constructAuxiliaryApvClasses(ApvAnalysis *theApv, uint32_t det_id, int thisApv)
#define begin
Definition: vmac.h:32
float getStripPedestal(uint32_t det_id, int stripNumber)
bool isUpdating(uint32_t detId)
TkApvMask & mask()
Definition: ApvAnalysis.h:65
TkNoiseCalculator & noiseCalculator()
Definition: ApvAnalysis.h:64