CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterSummary.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ClusterSummary
4 // Class: ClusterSummary
5 //
13 //
14 // Original Author: Michael Segala
15 // Created: Wed Feb 23 17:36:23 CST 2011
16 //
17 //
18 
19 #ifndef CLUSTERSUMMARY
20 #define CLUSTERSUMMARY
21 
22 // system include files
23 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
24 #include <atomic>
25 #endif
26 #include <memory>
27 #include <string>
28 #include <map>
29 #include <vector>
30 #include<iostream>
31 #include <string.h>
32 #include <sstream>
34 
35 // user include files
36 
41 
42 
45 
56 
57 /*****************************************************************************************
58 
59 How to use ClusterSummary class:
60 
61 ClusterSummary provides summary inforation for a number of cluster dependent variables.
62 All the variables are stored within variables_
63 The modules selected are stored within modules_
64 The number of variables for each module is stored within iterator_
65 
66 [If putting ClusterSummary into producer]
67 
68 1) In beginJob() of Producer, set the method
69 
70  Cluster.SetUserContent(v_userContent);
71  Cluster.SetUserIterator();
72 
73  where v_userContent is a vector of strings of the varibales you are getting info on
74 
75 
76 2) In produce() of Prodcuer, fill the output vectors
77 
78  // Tell ClusterSummary which Tracker Partitions you want summary information from
79  Cluster.SetUserModules( mod )
80 
81 
82  //Fill generic vector to hold any variables. You can fill the vector based on the name of the variables or the location of the variable within userContent
83  cCluster.SetGenericVariable( "sHits", mod_pair2, 1 );
84  cCluster.SetGenericVariable( "sSize", mod_pair2, Summaryinfo.clusterSize() );
85  cCluster.SetGenericVariable( "sCharge", mod_pair2, Summaryinfo.charge() );
86 
87 
88  // Once the loop over all detIds have finsihed fill the Output vectors
89  Cluster.SetUserVariables( mod );
90 
91 
92  // Dont forget to clear all the vectors and arrays at end of each event
93 
94 
95 
96 
97 [If putting reading back ClusterSummary from anlayzer]
98 
99  You can access all the summary vectors in the following way
100 
101  Handle< ClusterSummary > class_;
102  iEvent.getByLabel( _class, class_);
103 
104  genericVariables_ = class_ -> GetGenericVariable();
105 
106  //You can access the variables by genericVariables_[i][j] where 'i' is the order in which the variable was stored, see enum VariablePlacement
107  cout << genericVariables_[0][1] << endl;
108  cout << genericVariables_[1][1]/genericVariables_[0][1] << endl;
109  cout << genericVariables_[2][2]/genericVariables_[0][2] << endl;
110 
111  --or--
112 
113  //You can access the variables by the variable and partition name.
114  cout << class_ -> GetGenericVariable("cHits", ClusterSummary::TIB) << endl;
115  cout << class_ -> GetGenericVariable("cSize", ClusterSummary::TIB)/class_ -> GetGenericVariable("cHits", ClusterSummary::TIB) << endl;
116  cout << class_ -> GetGenericVariable("cCharge", ClusterSummary::TOB)/class_ -> GetGenericVariable("cHits", ClusterSummary::TOB) << endl;
117 
118 
119 
120 
121 ********************************************************************************************/
122 
123 
125 
126  public:
127 
128  ClusterSummary();
129  ~ClusterSummary();
130  // swap function
131  void swap(ClusterSummary& other);
132  // copy ctor
134  // copy assingment operator
136 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
138 #endif
139 
140  // Enum for each partition within Tracer
141  enum CMSTracker { TRACKER = 0,
142  TIB = 1,
143  TIB_1 = 11, TIB_2 = 12, TIB_3 = 13, TIB_4 = 14, //TIB layer 1-4
144  TOB = 2,
145  TOB_1 = 21, TOB_2 = 22, TOB_3 = 23, TOB_4 = 24, TOB_5 = 25, TOB_6 = 26, //TOB layer 1-6
146  TID = 3,
147  TIDM = 31, TIDP = 32, //TID minus and plus
148  TIDM_1 = 311, TIDM_2 = 312, TIDM_3 = 313, //TID minus layer 1-3
149  TIDP_1 = 321, TIDP_2 = 322, TIDP_3 = 323, //TID plus layer 1-3
150  TIDMR_1 = 3110, TIDMR_2 = 3120, TIDMR_3 = 3130, //TID minus ring 1-3
151  TIDPR_1 = 3210, TIDPR_2 = 3220, TIDPR_3 = 3230, //TID plus ring 1-3
152  TEC = 4,
153  TECM = 41, TECP = 42, //TEC minus and plus
154  TECM_1 = 411, TECM_2 = 412, TECM_3 = 413, TECM_4 = 414, TECM_5 = 415, TECM_6 = 416, TECM_7 = 417, TECM_8 = 418, TECM_9 = 419, //TEC minus layer 1-9
155  TECP_1 = 421, TECP_2 = 422, TECP_3 = 423, TECP_4 = 424, TECP_5 = 425, TECP_6 = 426, TECP_7 = 427, TECP_8 = 428, TECP_9 = 429, //TEC plus layer 1-9
156  TECMR_1 = 4110, TECMR_2 = 4120, TECMR_3 = 4130, TECMR_4 = 4140, TECMR_5 = 4150, TECMR_6 = 4160, TECMR_7 = 4170, //TEC minus ring 1-9
157  TECPR_1 = 4210, TECPR_2 = 4220, TECPR_3 = 4230, TECPR_4 = 4240, TECPR_5 = 4250, TECPR_6 = 4260, TECPR_7 = 4270, //TEC plus ring 1-9
158  //PIXELS
159  PIXEL = 5,
160  FPIX = 6, // Pixel endcaps
161  FPIX_1 = 61,FPIX_2 = 62,FPIX_3 = 63, // Endcaps disks 1-3
162  FPIXM = 611, FPIXP = 612, // Pixel endcaps minus and plus side
163  FPIXM_1 = 6110, FPIXM_2 = 6120, FPIXM_3 = 6130, // Endcap minus disk 1-3
164  FPIXP_1 = 6210, FPIXP_2 = 6220, FPIXP_3 = 6230, // Endcap plus disk 1-3
165  BPIX = 7, //Pixel barrel
166  BPIX_1 = 71, BPIX_2 = 72, BPIX_3 = 73 //Pixel barrel layer 1-3
167 
168  };
169 
170  // Enum which describes the ordering of the summary variables inside vector variables_
177 
178 
179  //===================+++++++++++++========================
180  //
181  // Main methods to fill
182  // Variables
183  //
184  //===================+++++++++++++========================
185 
186 
187  //Get value of any variable given location of the variable within userContent and the module number based on enum CMSTracker
188  double GetGenericVariable( int variableLocation, int module ) const {
189  return GetModuleLocation(module) < 0 ? 0. : genericVariables_[variableLocation][GetModuleLocation(module)]; }
190 
191  //Get value of any variable given variable name and the module number based on enum CMSTracker
192  double GetGenericVariable( std::string variableName, int module ) const {
193 
194  int position = GetVariableLocation(variableName);
195  int mposition = GetModuleLocation(module);
196 
197  return mposition < 0 ? 0. : genericVariables_[position][mposition];
198  }
199 
200  //Get specific varibale for all modules using the variable name
201  std::vector<double> GetGenericVariable( std::string variableName ) const {
202  return genericVariables_[GetVariableLocation(variableName)];
203  }
204 
205  //Get specific varibale for all modules using the location of the variable within userContent
206  std::vector<double> GetGenericVariable( int variableLocation ) const {
207  return genericVariables_[variableLocation];
208  }
209 
210  //Get the vector genericVariables_
211  std::vector< std::vector<double> > GetGenericVariable() const { return genericVariables_; }
212 
213  //Set the vector genericVariables_ based on the location of the variable within userContent and the module number based on enum CMSTracker
214  void SetGenericVariable( int variableLocation, int module, double value ) {
215  if(GetModuleLocation(module) >=0) genericVariablesTmp_[variableLocation][GetModuleLocation(module)] += value; }
216 
217  //Set the vector genericVariables_ given the variable name and the module number based on enum CMSTracker
218  void SetGenericVariable( std::string variableName, int module, double value ) {
219 
220  /*
221  genericVariablesTmp[ variable ][ module ]
222 
223  This will fill the values in the order as they are filled in the produced.
224 
225  1) Find where the variableName lives in userContent
226  2) Find where module lives in modules_
227 
228  */
229 
230  int position = GetVariableLocation(variableName);
231  int mposition = GetModuleLocation(module);
232 
233  if(mposition >=0) genericVariablesTmp_[position][mposition] += value;
234  }
235 
236  //Prepair the final vector to be put into the producer. Remove any remaining 0's and copy the Tmp to the vector over to genericVariables_. Must be done at the end of each event.
237  void PrepairGenericVariable();
238 
239  //Clear genericVariablesTmp_. Must be done at the end of each event.
241 
242  //genericVariablesTmp_.clear();
243 
244  for (unsigned int i = 0; i < genericVariablesTmp_.size(); ++i){
245  for (unsigned int j = 0; j < genericVariablesTmp_[i].size(); ++j){
246  genericVariablesTmp_[i][j] = 0;
247  }
248  }
249  }
250 
251 
252 
253  // Setter and Getter for the User Content. You can also return the size and what is stored in the UserContent
254  void SetUserContent(const std::vector<std::string>& Content) const;
255  std::vector<std::string> GetUserContent();
256  int GetUserContentSize();
257  void GetUserContentInfo() const;
258  int GetVariableLocation ( std::string var ) const;
259 
260 
261  //Set and Get modules_
262  void SetUserModules( int value ) { modules_.push_back( value ); }
263  std::vector<int> GetUserModules( ) const { return modules_; }
264  void ClearUserModules( ) { modules_.clear(); }
265  // Return the location of desired module within modules_.
266  int GetModuleLocation ( int mod ) const;
267 
268 
269  //Set and Get iterator_
270  void SetUserIterator() { iterator_.push_back( GetUserContentSize() );}
271  std::vector<int> GetUserIterator() const { return iterator_; }
272  void ClearUserIterator() { iterator_.clear(); }
273 
274  // Return a vector of the modules that summary infomation was requested for. This should come from the provenance information.
275  std::vector<std::string> DecodeProvInfo(std::string ProvInfo) const;
276 
277  // Class which determines if a detId is part of a desired partition
279  public:
281  virtual ~ModuleSelection();
282  virtual std::pair<int,int> IsStripSelected (int DetId);
283  virtual std::pair<int,int> IsPixelSelected (int DetId);
284  private:
285  std::string geosearch; // string of selected modules
286  };
287 
288 
289 
290 
291  private:
292 
293 
294  // String which stores the name of the variables the user is getting the summary info for
295 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
296  mutable std::atomic<std::vector<std::string>*> userContent;
297 #else
298  mutable std::vector<std::string>* userContent;
299 #endif
300 
301  std::vector<int> iterator_; // <number of varibale for Module1, number of varibale for Module2 ...>
302  std::vector<int> modules_; // <Module1, Module2 ...>
303 
304  std::vector< std::vector<double> > genericVariables_;
305  // CMS-THREADSAFE: this mutable member data used in non-const functions
306  mutable std::vector< std::vector<double> > genericVariablesTmp_;
307 
308 };
309 
310 
311 #endif
312 
313 
314 
315 
316 
317 
318 
std::vector< std::string > DecodeProvInfo(std::string ProvInfo) const
int i
Definition: DBlmapReader.cc:9
std::atomic< std::vector< std::string > * > userContent
void SetGenericVariable(int variableLocation, int module, double value)
virtual std::pair< int, int > IsPixelSelected(int DetId)
std::vector< double > GetGenericVariable(int variableLocation) const
std::vector< int > modules_
std::vector< int > GetUserIterator() const
std::vector< std::vector< double > > GetGenericVariable() const
std::vector< std::vector< double > > genericVariablesTmp_
void SetUserContent(const std::vector< std::string > &Content) const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
void ClearUserIterator()
void SetUserIterator()
std::vector< std::vector< double > > genericVariables_
std::vector< int > GetUserModules() const
virtual std::pair< int, int > IsStripSelected(int DetId)
int j
Definition: DBlmapReader.cc:9
double GetGenericVariable(int variableLocation, int module) const
double GetGenericVariable(std::string variableName, int module) const
int GetVariableLocation(std::string var) const
void swap(ClusterSummary &other)
std::vector< std::string > GetUserContent()
Definition: DetId.h:18
std::vector< double > GetGenericVariable(std::string variableName) const
void PrepairGenericVariable()
ClusterSummary & operator=(const ClusterSummary &rhs)
void SetUserModules(int value)
void SetGenericVariable(std::string variableName, int module, double value)
void ClearGenericVariable()
void GetUserContentInfo() const
int GetModuleLocation(int mod) const
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
Definition: vlib.h:208
void ClearUserModules()
std::vector< int > iterator_