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  delete theCommonMode;
122  delete theMask;
123  delete thePedestal;
124  delete theNoise;
125  return;
126  }
127  } else {
128  cout << "ApvAnalysisFactory: algorithm " << theAlgorithmType_ << " not supported" << endl;
129  delete theCommonMode;
130  return;
131  }
132 
133  if (theCommonMode)
134  theCM->setCM(theCommonMode);
135  if (thePedestal)
136  theAPV->setPedestalCalculator(*thePedestal);
137  if (theNoise)
138  theAPV->setNoiseCalculator(*theNoise);
139  if (theMask)
140  theAPV->setMask(*theMask);
141  if (theCM)
142  theAPV->setCommonModeCalculator(*theCM);
143 }
144 
145 void ApvAnalysisFactory::updatePair(uint32_t detId, size_t pairNumber, const edm::DetSet<SiStripRawDigi>& in) {
146  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
147  if (apvAnalysisIt != apvMap_.end()) {
148  size_t iter = 0;
149 
150  for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
151  apvIt != (apvAnalysisIt->second).end();
152  apvIt++) {
153  if (iter == pairNumber * 2 || iter == (2 * pairNumber + 1)) {
154  // cout << "ApvAnalysisFactory::updatePair pair number " << pairNumber << endl;
155  // cout << "ApvAnlysis will be updated for the apv # " << iter << endl;
156 
157  edm::DetSet<SiStripRawDigi> tmpRawDigi;
158  tmpRawDigi.data.reserve(128);
159 
160  size_t startStrip = 128 * (iter % 2);
161  size_t stopStrip = startStrip + 128;
162 
163  for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
164  if (in.data.size() <= istrip)
165  tmpRawDigi.data.push_back(SiStripRawDigi(0));
166  else
167  tmpRawDigi.data.push_back(in.data[istrip]); //maybe dangerous
168  }
169 
170  (*apvIt)->newEvent();
171  (*apvIt)->updateCalibration(tmpRawDigi);
172  }
173 
174  iter++;
175  }
176  }
177 
178 } // void
179 
181  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
182  if (apvAnalysisIt != apvMap_.end()) {
183  size_t i = 0;
184  for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
185  apvIt != (apvAnalysisIt->second).end();
186  apvIt++) {
187  edm::DetSet<SiStripRawDigi> tmpRawDigi;
188  //it is missing the detId ...
189  tmpRawDigi.data.reserve(128);
190  size_t startStrip = 128 * i;
191  size_t stopStrip = startStrip + 128;
192 
193  for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
194  if (in.data.size() <= istrip)
195  tmpRawDigi.data.push_back(SiStripRawDigi(0));
196  else
197  tmpRawDigi.data.push_back(in.data[istrip]); //maybe dangerous
198  }
199 
200  (*apvIt)->newEvent();
201  (*apvIt)->updateCalibration(tmpRawDigi);
202  i++;
203  }
204  }
205 }
206 
208  //Get the pedestal for a given apv
209  peds.clear();
210  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
211  if (apvAnalysisIt != apvMap_.end()) {
212  vector<ApvAnalysis*> myApvs = apvAnalysisIt->second;
213  peds = myApvs[apvNumber]->pedestalCalculator().pedestal();
214  }
215 }
216 
218  //Get the pedestal for a given apv
219  peds.clear();
220  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
221  if (apvAnalysisIt != apvMap_.end()) {
222  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
223  for (vector<ApvAnalysis*>::const_iterator it = theApvs.begin(); it != theApvs.end(); it++) {
224  ApvAnalysis::PedestalType tmp = (*it)->pedestalCalculator().pedestal();
225  for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
226  peds.push_back(*pit);
227  }
228  }
229 }
230 float ApvAnalysisFactory::getStripPedestal(uint32_t detId, int stripNumber) {
231  //Get the pedestal for a given apv
233  int apvNumb = int(stripNumber / 128.);
234  int stripN = (stripNumber - apvNumb * 128);
235 
236  getPedestal(detId, apvNumb, temp);
237  return temp[stripN];
238 }
240  //Get the pedestal for a given apv
241  noise.clear();
242  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
243  if (apvAnalysisIt != apvMap_.end()) {
244  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
245 
246  noise = theApvs[apvNumber]->noiseCalculator().noise();
247  }
248 }
249 
250 float ApvAnalysisFactory::getStripNoise(uint32_t detId, int stripNumber) {
251  //Get the pedestal for a given apv
253  int apvNumb = int(stripNumber / 128.);
254  int stripN = (stripNumber - apvNumb * 128);
255 
256  getNoise(detId, apvNumb, temp);
257  return temp[stripN];
258 }
259 
261  //Get the pedestal for a given apv
262  peds.clear();
263  map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
264  if (theApvs_map != apvMap_.end()) {
265  vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
266  for (; theApvs != (theApvs_map->second).end(); theApvs++) {
267  ApvAnalysis::PedestalType tmp = (*theApvs)->noiseCalculator().noise();
268  for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
269  peds.push_back(*pit);
270  }
271  }
272 }
273 
275  //Get the pedestal for a given apv
276  noise.clear();
277  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
278  if (apvAnalysisIt != apvMap_.end()) {
279  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
280 
281  noise = theApvs[apvNumber]->pedestalCalculator().rawNoise();
282  }
283 }
284 
285 float ApvAnalysisFactory::getStripRawNoise(uint32_t detId, int stripNumber) {
286  //Get the pedestal for a given apv
288  int apvNumb = int(stripNumber / 128.);
289  int stripN = (stripNumber - apvNumb * 128);
290 
291  getRawNoise(detId, apvNumb, temp);
292  return temp[stripN];
293 }
294 
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  vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
301  for (; theApvs != (theApvs_map->second).end(); theApvs++) {
302  ApvAnalysis::PedestalType tmp = (*theApvs)->pedestalCalculator().rawNoise();
303  for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
304  peds.push_back(*pit);
305  }
306  }
307 }
308 
309 vector<float> ApvAnalysisFactory::getCommonMode(uint32_t detId, int apvNumber) {
310  vector<float> tmp;
311  tmp.clear();
312  map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
313  if (theApvs_map != apvMap_.end()) {
314  vector<ApvAnalysis*> theApvs = theApvs_map->second;
315 
316  tmp = theApvs[apvNumber]->commonModeCalculator().commonMode()->returnAsVector();
317  }
318  return tmp;
319 }
321  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
322  if (apvAnalysisIt != apvMap_.end()) {
323  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
324  for (unsigned int i = 0; i < theApvs.size(); i++) {
325  //To be fixed. We return only the first one in the vector.
326  vector<float> tmp_cm = theApvs[i]->commonModeCalculator().commonMode()->returnAsVector();
327  for (unsigned int it = 0; it < tmp_cm.size(); it++)
328  tmp.push_back(tmp_cm[it]);
329  }
330  }
331 }
332 
334  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(det_id);
335  if (apvAnalysisIt != apvMap_.end()) {
336  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
337  for (unsigned int i = 0; i < theApvs.size(); i++) {
338  TkApvMask::MaskType theMaskType = (theApvs[i]->mask()).mask();
339  //cout <<"theMaskType size "<<theMaskType.size()<<endl;
340 
341  for (unsigned int ii = 0; ii < theMaskType.size(); ii++) {
342  tmp.push_back(theMaskType[ii]);
343  //cout <<"The Value "<<theMaskType[ii]<<" "<<ii<<endl;
344  }
345  }
346  }
347 }
349  bool updating = true;
350  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
351  if (apvAnalysisIt != apvMap_.end()) {
352  for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
353  apvIt != (apvAnalysisIt->second).end();
354  apvIt++) {
355  if (!((*apvIt)->pedestalCalculator().status()->isUpdating()))
356  updating = false;
357  }
358  }
359  return updating;
360 }
361 
363  delete &(apv->pedestalCalculator());
364  delete &(apv->noiseCalculator());
365  delete &(apv->mask());
366  delete &(apv->commonModeCalculator().commonMode()->topology());
367  delete (apv->commonModeCalculator().commonMode());
368  delete &(apv->commonModeCalculator());
369  delete apv;
370 }
371 //
372 // -- Get Common Mode Slope
373 //
374 float ApvAnalysisFactory::getCommonModeSlope(uint32_t detId, int apvNumber) {
375  map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
376  float tmp = -100.0;
377  if (theApvs_map != apvMap_.end()) {
378  vector<ApvAnalysis*> theApvs = theApvs_map->second;
379  tmp = theApvs[apvNumber]->commonModeCalculator().getCMSlope();
380  return tmp;
381  }
382  return tmp;
383 }
385  tmp.clear();
386  map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
387  if (apvAnalysisIt != apvMap_.end()) {
388  vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
389  for (unsigned int i = 0; i < theApvs.size(); i++) {
390  tmp.push_back(theApvs[i]->commonModeCalculator().getCMSlope());
391  }
392  }
393 }
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)
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