CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripDelay.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripObjects
4 // Class : SiStripDelay
5 // Implementation:
6 // <Notes on implementation>
7 // Original Author: M. De Mattia
8 // Created: 26/10/2010
9 // $Id: SiStripDelay.cc,v 1.2 2010/11/04 14:31:55 demattia Exp $
10 
16 #include <sstream>
17 
18 void SiStripDelay::fillNewDelay(const SiStripBaseDelay& baseDelay, const int sumSign,
19  const std::pair<std::string, std::string> & recordLabelPair)
20 {
21  baseDelayVector_.push_back(&baseDelay);
22  sumSignVector_.push_back(sumSign);
23  recordLabelPair_.push_back(recordLabelPair);
24 }
25 
26 float SiStripDelay::getDelay(const uint32_t detId) const
27 {
28  boost::unordered_map<uint32_t, double>::const_iterator it = delays_.find(detId);
29  if( it != delays_.end() ) {
30  return it->second;
31  }
32  return 0.;
33 }
34 
36 {
37  if( baseDelayVector_.empty() ) {
38  return false;
39  }
40  std::vector<const SiStripBaseDelay*>::const_iterator it = baseDelayVector_.begin();
41  // Check for consistent size in all baseDelays
42  if( baseDelayVector_.size() > 1 ) {
43  for( ; it != baseDelayVector_.end()-1; ++it ) {
44  if( (*it)->delaysSize() != (*(it+1))->delaysSize() ) {
45  std::cout << "makeDelay: Error, size of base delays is different!!" << std::endl;
46  return false;
47  }
48  }
49  }
50 
51 // // All checks done, fill the boost::unoredered_map with the first one (initialization)
52 // int sumSignIndex = 0;
53 // int sumSign = 0;
54 // std::vector<uint32_t>::const_iterator detIdIt;
55 // for( it = baseDelayVector_.begin(); it != baseDelayVector_.end(); ++it, ++sumSignIndex ) {
56 // std::vector<uint32_t> detIds;
57 // (*it)->detIds(detIds);
58 // sumSign = sumSignVector_[sumSignIndex];
59 // for( detIdIt = detIds.begin(); detIdIt != detIds.end(); ++detIdIt ) {
60 // // Check if is alread there so that we never rely on the default initialization
61 // boost::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
62 // if( delayIt != delays_.end() ) {
63 // std::cout << "second delay = " << (*it)->delay(*detIdIt)*sumSign << std::endl;
64 // delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
65 // std::cout << "Full delay = " << delays_[*detIdIt] << std::endl;
66 // }
67 // else {
68 // std::cout << "first delay = " << (*it)->delay(*detIdIt)*sumSign << std::endl;
69 // delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
70 // }
71 // }
72 // }
73 
74  // All checks done, fill the boost::unoredered_map with the first one (initialization)
75  int sumSignIndex = 0;
76  int sumSign = sumSignVector_[sumSignIndex];
77  it = baseDelayVector_.begin();
78  std::vector<uint32_t> detIds;
79  (*it)->detIds(detIds);
80  std::vector<uint32_t>::const_iterator detIdIt = detIds.begin();
81  for( ; detIdIt != detIds.end(); ++detIdIt ) {
82  delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
83  }
84  ++it;
85  ++sumSignIndex;
86  // Fill all the others
87  for( ; it != baseDelayVector_.end(); ++it, ++sumSignIndex ) {
88  std::vector<uint32_t> detIds;
89  (*it)->detIds(detIds);
90  detIdIt = detIds.begin();
91  sumSign = sumSignVector_[sumSignIndex];
92  for( ; detIdIt != detIds.end(); ++detIdIt ) {
93  // The same detIds should be in both maps, if not don't rely on the default initialization
94  boost::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
95  if( delayIt != delays_.end() ) {
96  delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
97  }
98  else {
99  std::cout << "makeDelay: Warning, detId = " << *detIdIt << " not present, summing to 0..." << std::cout;
100  std::cout << "This means that the two baseDelay tags have different detIds. PLEASE, CHECK THAT THIS IS EXPECTED." << std::cout;
101  delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
102  }
103  }
104  }
105 
106  return true;
107 }
108 
110 {
111  baseDelayVector_.clear();
112  sumSignVector_.clear();
113  recordLabelPair_.clear();
114  delays_.clear();
115 }
116 
117 void SiStripDelay::printDebug(std::stringstream & ss) const
118 {
119  boost::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
120  for( ; it != delays_.end(); ++it ) {
121  ss << "detId = " << it->first << " delay = " << it->second << std::endl;
122  }
123 }
124 
125 void SiStripDelay::printSummary(std::stringstream& ss) const
126 {
127  SiStripDetSummary summaryDelays;
128  boost::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
129  for( ; it != delays_.end(); ++it ) {
130  summaryDelays.add(it->first, it->second);
131  }
132  summaryDelays.print(ss);
133 }
void printSummary(std::stringstream &ss) const
Prints the average value of the delays for all layers and wheels in the SiStripTracker.
void fillNewDelay(const SiStripBaseDelay &baseDelay, const int sumSign, const std::pair< std::string, std::string > &recordLabelPair)
Definition: SiStripDelay.cc:18
std::vector< std::pair< std::string, std::string > > recordLabelPair_
Definition: SiStripDelay.h:98
std::vector< const SiStripBaseDelay * > baseDelayVector_
Definition: SiStripDelay.h:96
void printDebug(std::stringstream &ss) const
Prints the delays for all the detIds.
bool makeDelay()
Builds the boost::unordered_map.
Definition: SiStripDelay.cc:35
void print(std::stringstream &ss, const bool mean=true) const
boost::unordered_map< uint32_t, double > delays_
Definition: SiStripDelay.h:99
float getDelay(const uint32_t detId) const
Return the delay combining all the baseDelays.
Definition: SiStripDelay.cc:26
tuple cout
Definition: gather_cfg.py:121
void clear()
Empty all the containers.
std::vector< int > sumSignVector_
Definition: SiStripDelay.h:97
void add(const DetId &detid, const float &value)
Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo...