CMS 3D CMS Logo

APVGainHelpers.cc
Go to the documentation of this file.
3 
5 
15 int APVGain::subdetectorId(uint32_t det_id) {
16  return DetId(det_id).subdetId();
17 };
18 
19 
33  std::string d = tag.substr(0,3);
34  if ( d=="TIB" ) return 3;
35  if ( d=="TID" ) return 4;
36  if ( d=="TOB" ) return 5;
37  if ( d=="TEC" ) return 6;
38  return 0;
39 };
40 
47 int APVGain::subdetectorSide(uint32_t det_id, const TrackerTopology* topo) {
48  return topo->side( det_id );
49 }
50 
51 
62  std::size_t m = tag.find("minus");
63  std::size_t p = tag.find("plus");
64  if (m!=std::string::npos) return 1;
65  if (p!=std::string::npos) return 2;
66  return 0;
67 }
68 
69 
77 int APVGain::subdetectorPlane(uint32_t det_id, const TrackerTopology* topo) {
78  if( topo ) {
79  if( APVGain::subdetectorId(det_id)==StripSubdetector::TIB ) return topo->tibLayer(det_id);
80  else if( APVGain::subdetectorId(det_id)==StripSubdetector::TID ) return (2*topo->tidSide(det_id)-3)*topo->tidWheel(det_id);
81  else if( APVGain::subdetectorId(det_id)==StripSubdetector::TOB ) return topo->tobLayer(det_id);
82  else if( APVGain::subdetectorId(det_id)==StripSubdetector::TEC ) return (2*topo->tecSide(det_id)-3)*topo->tecWheel(det_id);
83  }
84  return 0;
85 };
86 
93  std::size_t p = (tag.find("layer")!=std::string::npos)? tag.find("layer") : tag.find("wheel");
94  if (p!=std::string::npos) {
95  std::size_t start = tag.find("_",p+1) + 1;
96  std::size_t stop = tag.find('_',start);
97  std::string plane = tag.substr(start,stop-start);
98  return atoi( plane.c_str());
99  }
100  return 0;
101 };
102 
103 
106 std::vector<MonitorElement*> APVGain::FetchMonitor(std::vector<APVGain::APVmon> histos, uint32_t det_id,
107  const TrackerTopology* topo) {
108 
109  std::vector<MonitorElement*> found = std::vector<MonitorElement*>();
110  int sId = APVGain::subdetectorId(det_id);
111  int sPlane = APVGain::subdetectorPlane(det_id, topo);
112  int sSide = APVGain::subdetectorSide(det_id, topo);
113  auto it = histos.begin();
114 
115  LogDebug("APVGainHelpers")<<"sId: "<<sId<<" sPlane: "<<sPlane<<" sSide: "<<sSide<<std::endl;
116 
117  while (it!=histos.end()) {
118  std::string tag = (*it).getMonitor()->getName();
119  int subdetectorId = (*it).getSubdetectorId();
120  int subdetectorSide = (*it).getSubdetectorSide();
121  int subdetectorPlane = (*it).getSubdetectorPlane();
122 
123  bool match = (subdetectorId==0 || subdetectorId==sId) && (subdetectorPlane==0 || subdetectorPlane==sPlane) && (subdetectorSide==0 || subdetectorSide==sSide);
124 
125  if (match) {
126  found.emplace_back((*it).getMonitor());
127  LogDebug("APVGainHelpers")<<det_id<<" found: "<< tag << std::endl;
128  (*it).printAll();
129  }
130  it++;
131  }
132  return found;
133 }
134 
137 std::vector<unsigned int> APVGain::FetchIndices(std::map<unsigned int,APVloc> theMap, uint32_t det_id, const TrackerTopology* topo){
138 
139  std::vector<unsigned int> found_indices = std::vector<unsigned int>();
140 
141  int sId = APVGain::subdetectorId(det_id);
142  int sPlane = APVGain::subdetectorPlane(det_id, topo);
143  int sSide = APVGain::subdetectorSide(det_id, topo);
144 
145  for(auto &element : theMap){
146 
147  int subdetectorId = element.second.m_subdetectorId;
148  int subdetectorSide = element.second.m_subdetectorSide;
149  int subdetectorPlane = element.second.m_subdetectorPlane;
150 
151  bool match = (subdetectorId==0 || subdetectorId==sId) && (subdetectorPlane==0 || subdetectorPlane==sPlane) && (subdetectorSide==0 || subdetectorSide==sSide);
152 
153  if (match ){
154  found_indices.push_back(element.first);
155  }
156  }
157  return found_indices;
158 }
159 
160 std::vector<std::pair<std::string,std::string>>
161 APVGain::monHnames(std::vector<std::string> VH, bool allPlanes, const char* tag) {
162 
163  std::vector<std::pair<std::string,std::string>> out;
164 
165  // total number of measurement layers/wheels in the Strips Tracker
166  // 4(TIB) + 6(TOB) + 3(TID+) + 3(TID-) + 9(TEC+) + 9(TEC-)
167  constexpr int countOfPlanes = 34;
168 
169  int re = (allPlanes)? countOfPlanes + VH.size() : VH.size();
170  out.reserve( re );
171 
172  std::string Tag = tag;
173  if (Tag.length()) Tag = "__" + Tag;
174 
175  std::string h_tag = "";
176  std::string h_tit = "";
177 
178  if (allPlanes) {
179  // Names of monitoring histogram for TIB layers
180  constexpr int TIBlayers = 4; //number of TIB layers.
181  for(int i=1; i<=TIBlayers; i++) {
182  h_tag = "TIB_layer_" + std::to_string(i) + Tag;
183  h_tit = h_tag; std::replace(h_tit.begin(),h_tit.end(),'_',' ');
184  out.push_back(std::pair<std::string,std::string>(h_tag,h_tit));
185  }
186  // Names of monitoring histogram for TOB layers
187  constexpr int TOBlayers = 6; //number of TOB layers
188  for(int i=1; i<=TOBlayers; i++) {
189  h_tag = "TOB_layer_" + std::to_string(i) + Tag;
190  h_tit = h_tag; std::replace(h_tit.begin(),h_tit.end(),'_',' ');
191  out.push_back(std::pair<std::string,std::string>(h_tag,h_tit));
192  }
193  // Names of monitoring histogram for TID wheels
194  constexpr int TIDwheels = 3; //number of TID wheels
195  for(int i=-TIDwheels; i<=TIDwheels; i++) {
196  if (i==0) continue;
197  if (i<0) h_tag = "TIDminus_wheel_" + std::to_string(i) + Tag;
198  else h_tag = "TIDplus_wheel_" + std::to_string(i) + Tag;
199  h_tit = h_tag; std::replace(h_tit.begin(),h_tit.end(),'_',' ');
200  out.push_back(std::pair<std::string,std::string>(h_tag,h_tit));
201  }
202  // Names of monitoring histogram for TEC wheels
203  constexpr int TECwheels = 9; //number of TEC wheels
204  for(int i=-TECwheels; i<=TECwheels; i++) {
205  if (i==0) continue;
206  if (i<0) h_tag = "TECminus_wheel_" + std::to_string(i) + Tag;
207  else h_tag = "TECplus_wheel_" + std::to_string(i) + Tag;
208  h_tit = h_tag; std::replace(h_tit.begin(),h_tit.end(),'_',' ');
209  out.push_back(std::pair<std::string,std::string>(h_tag,h_tit));
210  }
211  }
212 
213  for(unsigned int i=0; i<VH.size();i++) {
214  h_tag = VH[i] + Tag;
215  h_tit = h_tag; std::replace(h_tit.begin(),h_tit.end(),'_',' ');
216  out.push_back(std::pair<std::string,std::string>(h_tag,h_tit));
217  }
218 
219  return out;
220 }
221 
222 
223 
#define LogDebug(id)
Definition: start.py:1
unsigned int tibLayer(const DetId &id) const
unsigned int side(const DetId &id) const
int subdetectorPlane(uint32_t, const TrackerTopology *)
def replace(string, replacements)
unsigned int tidWheel(const DetId &id) const
#define constexpr
std::vector< MonitorElement * > FetchMonitor(std::vector< APVmon >, uint32_t, const TrackerTopology *topo=0)
unsigned int tidSide(const DetId &id) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
std::vector< unsigned int > FetchIndices(std::map< unsigned int, APVloc >, uint32_t, const TrackerTopology *topo=0)
Definition: DetId.h:18
int subdetectorSide(uint32_t, const TrackerTopology *)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::vector< std::pair< std::string, std::string > > monHnames(std::vector< std::string >, bool, const char *tag)
unsigned int tecWheel(const DetId &id) const
int subdetectorId(uint32_t)
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const