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.3 2012/09/26 18:39:46 eulisse Exp $
10 
12 #include <cassert>
17 #include <sstream>
18 
19 void SiStripDelay::fillNewDelay(const SiStripBaseDelay& baseDelay, const int sumSign,
20  const std::pair<std::string, std::string> & recordLabelPair)
21 {
22  baseDelayVector_.push_back(&baseDelay);
23  sumSignVector_.push_back(sumSign);
24  recordLabelPair_.push_back(recordLabelPair);
25 }
26 
27 float SiStripDelay::getDelay(const uint32_t detId) const
28 {
29  boost::unordered_map<uint32_t, double>::const_iterator it = delays_.find(detId);
30  if( it != delays_.end() ) {
31  return it->second;
32  }
33  return 0.;
34 }
35 
37 {
38  if( baseDelayVector_.empty() ) {
39  return false;
40  }
41  std::vector<const SiStripBaseDelay*>::const_iterator it = baseDelayVector_.begin();
42  // Check for consistent size in all baseDelays
43  if( baseDelayVector_.size() > 1 ) {
44  for( ; it != baseDelayVector_.end()-1; ++it ) {
45  if( (*it)->delaysSize() != (*(it+1))->delaysSize() ) {
46  std::cout << "makeDelay: Error, size of base delays is different!!" << std::endl;
47  return false;
48  }
49  }
50  }
51 
52 // // All checks done, fill the boost::unoredered_map with the first one (initialization)
53 // int sumSignIndex = 0;
54 // int sumSign = 0;
55 // std::vector<uint32_t>::const_iterator detIdIt;
56 // for( it = baseDelayVector_.begin(); it != baseDelayVector_.end(); ++it, ++sumSignIndex ) {
57 // std::vector<uint32_t> detIds;
58 // (*it)->detIds(detIds);
59 // sumSign = sumSignVector_[sumSignIndex];
60 // for( detIdIt = detIds.begin(); detIdIt != detIds.end(); ++detIdIt ) {
61 // // Check if is alread there so that we never rely on the default initialization
62 // boost::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
63 // if( delayIt != delays_.end() ) {
64 // std::cout << "second delay = " << (*it)->delay(*detIdIt)*sumSign << std::endl;
65 // delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
66 // std::cout << "Full delay = " << delays_[*detIdIt] << std::endl;
67 // }
68 // else {
69 // std::cout << "first delay = " << (*it)->delay(*detIdIt)*sumSign << std::endl;
70 // delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
71 // }
72 // }
73 // }
74 
75  // All checks done, fill the boost::unoredered_map with the first one (initialization)
76  int sumSignIndex = 0;
77  int sumSign = sumSignVector_[sumSignIndex];
78  it = baseDelayVector_.begin();
79  std::vector<uint32_t> detIds;
80  (*it)->detIds(detIds);
81  std::vector<uint32_t>::const_iterator detIdIt = detIds.begin();
82  for( ; detIdIt != detIds.end(); ++detIdIt ) {
83  delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
84  }
85  ++it;
86  ++sumSignIndex;
87  // Fill all the others
88  for( ; it != baseDelayVector_.end(); ++it, ++sumSignIndex ) {
89  std::vector<uint32_t> detIds;
90  (*it)->detIds(detIds);
91  detIdIt = detIds.begin();
92  sumSign = sumSignVector_[sumSignIndex];
93  for( ; detIdIt != detIds.end(); ++detIdIt ) {
94  // The same detIds should be in both maps, if not don't rely on the default initialization
95  boost::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
96  if( delayIt != delays_.end() ) {
97  delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
98  }
99  else {
100  std::cout << "makeDelay: Warning, detId = " << *detIdIt << " not present, summing to 0..." << std::cout;
101  std::cout << "This means that the two baseDelay tags have different detIds. PLEASE, CHECK THAT THIS IS EXPECTED." << std::cout;
102  delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
103  }
104  }
105  }
106 
107  return true;
108 }
109 
111 {
112  baseDelayVector_.clear();
113  sumSignVector_.clear();
114  recordLabelPair_.clear();
115  delays_.clear();
116 }
117 
118 void SiStripDelay::printDebug(std::stringstream & ss) const
119 {
120  boost::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
121  for( ; it != delays_.end(); ++it ) {
122  ss << "detId = " << it->first << " delay = " << it->second << std::endl;
123  }
124 }
125 
126 void SiStripDelay::printSummary(std::stringstream& ss) const
127 {
128  SiStripDetSummary summaryDelays;
129  boost::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
130  for( ; it != delays_.end(); ++it ) {
131  summaryDelays.add(it->first, it->second);
132  }
133  summaryDelays.print(ss);
134 }
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:19
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:36
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:27
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...