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,
8  int theNumCMstripsInGroup,
9  int theMaskCalcFlag,
10  float theMaskNoiseCut,
11  float theMaskDeadCut,
12  float theMaskTruncCut,
13  float theCutToAvoidSignal,
14  int theEventInitNumber,
15  int theEventIterNumber) {
16  theAlgorithmType_ = theAlgorithmType;
17  theNumCMstripsInGroup_ = theNumCMstripsInGroup;
18  theMaskCalcFlag_ = theMaskCalcFlag;
19  theMaskNoiseCut_ = theMaskNoiseCut;
20  theMaskDeadCut_ = theMaskDeadCut;
21  theMaskTruncCut_ = theMaskTruncCut;
22  theCutToAvoidSignal_ = theCutToAvoidSignal;
23  theEventInitNumber_ = theEventInitNumber;
24  theEventIterNumber_ = theEventIterNumber;
25 }
26 
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 //----------------------------------
46  ApvAnalysisFactory::ApvAnalysisMap::iterator it = apvMap_.begin();
47  for (; it != apvMap_.end(); it++) {
48  vector<ApvAnalysis*>::iterator myApv = (*it).second.begin();
49  for (; myApv != (*it).second.end(); myApv++)
50  deleteApv(*myApv);
51  }
52  apvMap_.clear();
53 }
54 
55 //----------------------------------
56 
57 bool ApvAnalysisFactory::instantiateApvs(uint32_t detId, int numberOfApvs) {
58  ApvAnalysisFactory::ApvAnalysisMap::iterator CPos = apvMap_.find(detId);
59  if (CPos != apvMap_.end()) {
60  cout << " APVs for Detector Id " << detId << " already created !!!" << endl;
61  ;
62  return false;
63  }
64  vector<ApvAnalysis*> temp;
65  for (int i = 0; i < numberOfApvs; i++) {
66  ApvAnalysis* apvTmp = new ApvAnalysis(theEventIterNumber_);
67  // constructAuxiliaryApvClasses(apvTmp);
68  constructAuxiliaryApvClasses(apvTmp, detId, i);
69  temp.push_back(apvTmp);
70  }
71  apvMap_.insert(pair<uint32_t, vector<ApvAnalysis*> >(detId, temp));
72  return true;
73 }
74 
75 std::vector<ApvAnalysis*> ApvAnalysisFactory::getApvAnalysis(const uint32_t nDET_ID) {
76  ApvAnalysisMap::const_iterator _apvAnalysisIter = apvMap_.find(nDET_ID);
77 
78  return apvMap_.end() != _apvAnalysisIter ? _apvAnalysisIter->second : std::vector<ApvAnalysis*>();
79 }
80 
82  //----------------------------------------------------------------
83  // Create the ped/noise/CMN calculators, zero suppressors etc.
84  // (Is called by addDetUnitAndConstructApvs()).
85  //
86  // N.B. Don't call this twice for the same APV!
87  //-----------------------------------------------------------------
88  // cout<<"VirtualApvAnalysisFactory::constructAuxiliaryApvClasses"<<endl;
89  TkPedestalCalculator* thePedestal = nullptr;
90  TkNoiseCalculator* theNoise = nullptr;
91  TkApvMask* theMask = nullptr;
92  TkCommonModeCalculator* theCM = nullptr;
93 
94  TkCommonMode* theCommonMode = new TkCommonMode();
95  TkCommonModeTopology* theTopology = new TkCommonModeTopology(128, theNumCMstripsInGroup_);
96  theCommonMode->setTopology(theTopology);
97 
98  // Create desired algorithms.
99  if (theAlgorithmType_ == "TT6") {
100  theMask = new TT6ApvMask(theMaskCalcFlag_, theMaskNoiseCut_, theMaskDeadCut_, theMaskTruncCut_);
101  theNoise = new TT6NoiseCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
102  thePedestal = new TT6PedestalCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
103  theCM = new TT6CommonModeCalculator(theNoise, theMask, theCutToAvoidSignal_);
104  } else if ("TT6NT" == theAlgorithmType_) {
105  theMask = new TT6ApvMask(theMaskCalcFlag_, theMaskNoiseCut_, theMaskDeadCut_, theMaskTruncCut_);
106  theNoise = new TT6NoiseCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
107  thePedestal = new TT6NTPedestalCalculator;
108  theCM = new TT6CommonModeCalculator(theNoise, theMask, theCutToAvoidSignal_);
109  } else if (theAlgorithmType_ == "MIX") {
110  // the mask as to be defined also for SimplePedCalculator
111  theMask = new TT6ApvMask(theMaskCalcFlag_, theMaskNoiseCut_, theMaskDeadCut_, theMaskTruncCut_);
112 
113  thePedestal = new SimplePedestalCalculator(theEventInitNumber_);
114 
115  theNoise = new SimpleNoiseCalculator(theEventInitNumber_, useDB_);
116 
117  if (theCMType_ == "Median") {
118  theCM = new MedianCommonModeCalculator();
119  } else {
120  cout << "Sorry Only Median is available for now, Mean and FastLinear are coming soon" << endl;
121  }
122  }
123 
124  if (theCommonMode)
125  theCM->setCM(theCommonMode);
126  if (thePedestal)
127  theAPV->setPedestalCalculator(*thePedestal);
128  if (theNoise)
129  theAPV->setNoiseCalculator(*theNoise);
130  if (theMask)
131  theAPV->setMask(*theMask);
132  if (theCM)
133  theAPV->setCommonModeCalculator(*theCM);
134 }
135 
136 void ApvAnalysisFactory::updatePair(uint32_t detId, size_t pairNumber, const edm::DetSet<SiStripRawDigi>& in) {
137  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
138  if (apvAnalysisIt != apvMap_.end()) {
139  size_t iter = 0;
140 
141  for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
142  apvIt != (apvAnalysisIt->second).end();
143  apvIt++) {
144  if (iter == pairNumber * 2 || iter == (2 * pairNumber + 1)) {
145  // cout << "ApvAnalysisFactory::updatePair pair number " << pairNumber << endl;
146  // cout << "ApvAnlysis will be updated for the apv # " << iter << endl;
147 
148  edm::DetSet<SiStripRawDigi> tmpRawDigi;
149  tmpRawDigi.data.reserve(128);
150 
151  size_t startStrip = 128 * (iter % 2);
152  size_t stopStrip = startStrip + 128;
153 
154  for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
155  if (in.data.size() <= istrip)
156  tmpRawDigi.data.push_back(SiStripRawDigi(0));
157  else
158  tmpRawDigi.data.push_back(in.data[istrip]); //maybe dangerous
159  }
160 
161  (*apvIt)->newEvent();
162  (*apvIt)->updateCalibration(tmpRawDigi);
163  }
164 
165  iter++;
166  }
167  }
168 
169 } // void
170 
172  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
173  if (apvAnalysisIt != apvMap_.end()) {
174  size_t i = 0;
175  for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
176  apvIt != (apvAnalysisIt->second).end();
177  apvIt++) {
178  edm::DetSet<SiStripRawDigi> tmpRawDigi;
179  //it is missing the detId ...
180  tmpRawDigi.data.reserve(128);
181  size_t startStrip = 128 * i;
182  size_t stopStrip = startStrip + 128;
183 
184  for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
185  if (in.data.size() <= istrip)
186  tmpRawDigi.data.push_back(SiStripRawDigi(0));
187  else
188  tmpRawDigi.data.push_back(in.data[istrip]); //maybe dangerous
189  }
190 
191  (*apvIt)->newEvent();
192  (*apvIt)->updateCalibration(tmpRawDigi);
193  i++;
194  }
195  }
196 }
197 
199  //Get the pedestal for a given apv
200  peds.clear();
201  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
202  if (apvAnalysisIt != apvMap_.end()) {
203  vector<ApvAnalysis*> myApvs = apvAnalysisIt->second;
204  peds = myApvs[apvNumber]->pedestalCalculator().pedestal();
205  }
206 }
207 
209  //Get the pedestal for a given apv
210  peds.clear();
211  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
212  if (apvAnalysisIt != apvMap_.end()) {
213  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
214  for (vector<ApvAnalysis*>::const_iterator it = theApvs.begin(); it != theApvs.end(); it++) {
215  ApvAnalysis::PedestalType tmp = (*it)->pedestalCalculator().pedestal();
216  for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
217  peds.push_back(*pit);
218  }
219  }
220 }
221 float ApvAnalysisFactory::getStripPedestal(uint32_t detId, int stripNumber) {
222  //Get the pedestal for a given apv
224  int apvNumb = int(stripNumber / 128.);
225  int stripN = (stripNumber - apvNumb * 128);
226 
227  getPedestal(detId, apvNumb, temp);
228  return temp[stripN];
229 }
231  //Get the pedestal for a given apv
232  noise.clear();
233  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
234  if (apvAnalysisIt != apvMap_.end()) {
235  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
236 
237  noise = theApvs[apvNumber]->noiseCalculator().noise();
238  }
239 }
240 
241 float ApvAnalysisFactory::getStripNoise(uint32_t detId, int stripNumber) {
242  //Get the pedestal for a given apv
244  int apvNumb = int(stripNumber / 128.);
245  int stripN = (stripNumber - apvNumb * 128);
246 
247  getNoise(detId, apvNumb, temp);
248  return temp[stripN];
249 }
250 
252  //Get the pedestal for a given apv
253  peds.clear();
254  map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
255  if (theApvs_map != apvMap_.end()) {
256  vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
257  for (; theApvs != (theApvs_map->second).end(); theApvs++) {
258  ApvAnalysis::PedestalType tmp = (*theApvs)->noiseCalculator().noise();
259  for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
260  peds.push_back(*pit);
261  }
262  }
263 }
264 
266  //Get the pedestal for a given apv
267  noise.clear();
268  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
269  if (apvAnalysisIt != apvMap_.end()) {
270  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
271 
272  noise = theApvs[apvNumber]->pedestalCalculator().rawNoise();
273  }
274 }
275 
276 float ApvAnalysisFactory::getStripRawNoise(uint32_t detId, int stripNumber) {
277  //Get the pedestal for a given apv
279  int apvNumb = int(stripNumber / 128.);
280  int stripN = (stripNumber - apvNumb * 128);
281 
282  getRawNoise(detId, apvNumb, temp);
283  return temp[stripN];
284 }
285 
287  //Get the pedestal for a given apv
288  peds.clear();
289  map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
290  if (theApvs_map != apvMap_.end()) {
291  vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
292  for (; theApvs != (theApvs_map->second).end(); theApvs++) {
293  ApvAnalysis::PedestalType tmp = (*theApvs)->pedestalCalculator().rawNoise();
294  for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
295  peds.push_back(*pit);
296  }
297  }
298 }
299 
300 vector<float> ApvAnalysisFactory::getCommonMode(uint32_t detId, int apvNumber) {
301  vector<float> tmp;
302  tmp.clear();
303  map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
304  if (theApvs_map != apvMap_.end()) {
305  vector<ApvAnalysis*> theApvs = theApvs_map->second;
306 
307  tmp = theApvs[apvNumber]->commonModeCalculator().commonMode()->returnAsVector();
308  }
309  return tmp;
310 }
312  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
313  if (apvAnalysisIt != apvMap_.end()) {
314  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
315  for (unsigned int i = 0; i < theApvs.size(); i++) {
316  //To be fixed. We return only the first one in the vector.
317  vector<float> tmp_cm = theApvs[i]->commonModeCalculator().commonMode()->returnAsVector();
318  for (unsigned int it = 0; it < tmp_cm.size(); it++)
319  tmp.push_back(tmp_cm[it]);
320  }
321  }
322 }
323 
325  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(det_id);
326  if (apvAnalysisIt != apvMap_.end()) {
327  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
328  for (unsigned int i = 0; i < theApvs.size(); i++) {
329  TkApvMask::MaskType theMaskType = (theApvs[i]->mask()).mask();
330  //cout <<"theMaskType size "<<theMaskType.size()<<endl;
331 
332  for (unsigned int ii = 0; ii < theMaskType.size(); ii++) {
333  tmp.push_back(theMaskType[ii]);
334  //cout <<"The Value "<<theMaskType[ii]<<" "<<ii<<endl;
335  }
336  }
337  }
338 }
340  bool updating = true;
341  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
342  if (apvAnalysisIt != apvMap_.end()) {
343  for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
344  apvIt != (apvAnalysisIt->second).end();
345  apvIt++) {
346  if (!((*apvIt)->pedestalCalculator().status()->isUpdating()))
347  updating = false;
348  }
349  }
350  return updating;
351 }
352 
354  delete &(apv->pedestalCalculator());
355  delete &(apv->noiseCalculator());
356  delete &(apv->mask());
357  delete &(apv->commonModeCalculator().commonMode()->topology());
358  delete (apv->commonModeCalculator().commonMode());
359  delete &(apv->commonModeCalculator());
360  delete apv;
361 }
362 //
363 // -- Get Common Mode Slope
364 //
365 float ApvAnalysisFactory::getCommonModeSlope(uint32_t detId, int apvNumber) {
366  map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
367  float tmp = -100.0;
368  if (theApvs_map != apvMap_.end()) {
369  vector<ApvAnalysis*> theApvs = theApvs_map->second;
370  tmp = theApvs[apvNumber]->commonModeCalculator().getCMSlope();
371  return tmp;
372  }
373  return tmp;
374 }
376  tmp.clear();
377  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
378  if (apvAnalysisIt != apvMap_.end()) {
379  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
380  for (unsigned int i = 0; i < theApvs.size(); i++) {
381  tmp.push_back(theApvs[i]->commonModeCalculator().getCMSlope());
382  }
383  }
384 }
std::vector< StripMaskType > MaskType
Definition: TkApvMask.h:15
std::vector< float > PedestalType
Definition: ApvAnalysis.h:44
virtual void setCM(TkCommonMode *)=0
TkCommonModeCalculator & commonModeCalculator()
Definition: ApvAnalysis.h:58
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)
constexpr uint32_t mask
Definition: gpuClustering.h:26
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:56
bool instantiateApvs(uint32_t det_id, int numberOfApvs)
void setPedestalCalculator(TkPedestalCalculator &in)
Definition: ApvAnalysis.h:54
void setNoiseCalculator(TkNoiseCalculator &in)
Definition: ApvAnalysis.h:55
void setCommonModeCalculator(TkCommonModeCalculator &in)
Definition: ApvAnalysis.h:53
TkPedestalCalculator & pedestalCalculator()
Definition: ApvAnalysis.h:59
void getCommonMode(uint32_t det_id, ApvAnalysis::PedestalType &tmp)
ii
Definition: cuy.py:589
virtual TkCommonModeTopology & topology()
Definition: TkCommonMode.h:17
ApvAnalysisVector getApvAnalysis(const uint32_t nDET_ID)
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:80
void constructAuxiliaryApvClasses(ApvAnalysis *theApv, uint32_t det_id, int thisApv)
float getStripPedestal(uint32_t det_id, int stripNumber)
bool isUpdating(uint32_t detId)
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
tmp
align.sh
Definition: createJobs.py:716
TkApvMask & mask()
Definition: ApvAnalysis.h:61
TkNoiseCalculator & noiseCalculator()
Definition: ApvAnalysis.h:60