CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DataFormats/TrackerCommon/interface/ClusterSummary.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    ClusterSummary
00004 // Class:      ClusterSummary
00005 // 
00013 //
00014 // Original Author:  Michael Segala
00015 //         Created:  Wed Feb 23 17:36:23 CST 2011
00016 // $Id: ClusterSummary.h,v 1.2 2012/02/02 18:19:10 msegala Exp $
00017 //
00018 //
00019 
00020 
00021 #ifndef CLUSTERSUMMARY
00022 #define CLUSTERSUMMARY
00023 
00024 // system include files
00025 #include <memory>
00026 #include <string>
00027 #include <map>
00028 #include <vector>
00029 #include<iostream>
00030 #include <string.h>
00031 #include <sstream>
00032 #include "FWCore/Utilities/interface/Exception.h"
00033 
00034 // user include files
00035 
00036 #include "FWCore/Framework/interface/Frameworkfwd.h"
00037 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00038 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00039 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00040 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00041 
00042 
00043 #include "RecoLocalTracker/SiStripClusterizer/interface/SiStripClusterInfo.h"
00044 #include "DataFormats/SiStripDigi/interface/SiStripProcessedRawDigi.h"
00045 #include "DataFormats/Common/interface/DetSetVector.h"
00046 
00047 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00048 #include "DataFormats/DetId/interface/DetId.h" 
00049 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00050 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00051 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00052 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00053 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00054 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00055 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00056 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00057 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00058 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00059 
00060 /*****************************************************************************************
00061 
00062 How to use ClusterSummary class:
00063 
00064 ClusterSummary provides summary inforation for a number of cluster dependent variables.
00065 All the variables are stored within variables_
00066 The modules selected are stored within modules_
00067 The number of variables for each module is stored within iterator_
00068 
00069 [If putting ClusterSummary into producer]
00070 
00071 1) In beginJob() of Producer, set the method   
00072 
00073   Cluster.SetUserContent(v_userContent);
00074   Cluster.SetUserIterator();
00075 
00076   where v_userContent is a vector of strings of the varibales you are getting info on
00077    
00078 
00079 2) In produce() of Prodcuer, fill the output vectors
00080 
00081    // Tell ClusterSummary which Tracker Partitions you want summary information from
00082    Cluster.SetUserModules( mod ) 
00083 
00084    // Fill Summary ARRAYS with the summary information
00085    Cluster.SetNType( mod );
00086    Cluster.SetClusterSize( mod, Summaryinfo.clusterSize() );
00087    Cluster.SetClusterCharge( mod, Summaryinfo.charge() );
00088 
00089    //++++++++++++++++++++++//
00090    These methods are obsolete and you should use the SetGenericVariable() methods
00091    //++++++++++++++++++++++//
00092 
00093    --or--
00094 
00095    //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
00096    cCluster.SetGenericVariable( "sHits", mod_pair2, 1 );
00097    cCluster.SetGenericVariable( "sSize", mod_pair2, Summaryinfo.clusterSize() );
00098    cCluster.SetGenericVariable( "sCharge", mod_pair2, Summaryinfo.charge() );
00099 
00100 
00101    // Once the loop over all detIds have finsihed fill the Output vectors
00102    Cluster.SetUserVariables( mod );
00103 
00104 
00105   // Dont forget to clear all the vectors and arrays at end of each event
00106 
00107 
00108 
00109 
00110 [If putting reading back ClusterSummary from anlayzer]
00111 
00112    You can access all the summary vectors in the following way
00113 
00114    Handle< ClusterSummary  > class_;
00115    iEvent.getByLabel( _class, class_);
00116       
00117    genericVariables_ = class_ -> GetGenericVariable();   
00118 
00119    //You can access the variables by genericVariables_[i][j] where 'i' is the order in which the variable was stored, see enum VariablePlacement
00120    cout << genericVariables_[0][1] << endl;
00121    cout << genericVariables_[1][1]/genericVariables_[0][1] << endl;
00122    cout << genericVariables_[2][2]/genericVariables_[0][2] << endl;
00123 
00124    --or--
00125    
00126    //You can access the variables by the variable and partition name.
00127    cout << class_ -> GetGenericVariable("cHits", ClusterSummary::TIB) << endl;
00128    cout << class_ -> GetGenericVariable("cSize", ClusterSummary::TIB)/class_ -> GetGenericVariable("cHits", ClusterSummary::TIB) << endl;
00129    cout << class_ -> GetGenericVariable("cCharge", ClusterSummary::TOB)/class_ -> GetGenericVariable("cHits", ClusterSummary::TOB) << endl;
00130 
00131 
00132 
00133 
00134 ********************************************************************************************/
00135 
00136 
00137 class ClusterSummary {
00138 
00139  public:
00140   
00141   ClusterSummary():genericVariablesTmp_(6, std::vector<double>(80,0) ){}
00142 
00143   // Enum for each partition within Tracer
00144   enum CMSTracker { TRACKER = 0,
00145                     TIB = 1,
00146                     TIB_1 = 11, TIB_2 = 12, TIB_3 = 13, TIB_4 = 14,
00147                     TOB = 2,
00148                     TOB_1 = 21, TOB_2 = 22, TOB_3 = 23, TOB_4 = 24, TOB_5 = 25, TOB_6 = 26,
00149                     TID = 3,
00150                     TIDM = 31, TIDP = 32, 
00151                     TIDM_1 = 311, TIDM_2 = 312, TIDM_3 = 313,
00152                     TIDP_1 = 321, TIDP_2 = 322, TIDP_3 = 323,
00153                     TIDMR_1 = 3110, TIDMR_2 = 3120, TIDMR_3 = 3130,
00154                     TIDPR_1 = 3210, TIDPR_2 = 3220, TIDPR_3 = 3230,
00155                     TEC = 4,
00156                     TECM = 41, TECP = 42, 
00157                     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,
00158                     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, 
00159                     TECMR_1 = 4110, TECMR_2 = 4120, TECMR_3 = 4130, TECMR_4 = 4140, TECMR_5 = 4150, TECMR_6 = 4160, TECMR_7 = 4170, 
00160                     TECPR_1 = 4210, TECPR_2 = 4220, TECPR_3 = 4230, TECPR_4 = 4240, TECPR_5 = 4250, TECPR_6 = 4260, TECPR_7 = 4270,  
00161                     PIXEL = 5,
00162                     FPIX = 6, 
00163                     FPIXM = 61, FPIXP = 62,
00164                     BPIX = 7};
00165 
00166   // Enum which describes the ordering of the summary variables inside vector variables_
00167   enum VariablePlacement{ NMODULES = 0,
00168                           CLUSTERSIZE = 1,
00169                           CLUSTERCHARGE = 2,
00170                           NMODULESPIXELS = 3,
00171                           CLUSTERSIZEPIXELS = 4,
00172                           CLUSTERCHARGEPIXELS = 5};
00173  
00174 
00175   //===================+++++++++++++========================
00176   //
00177   //                 Main methods to fill 
00178   //                      Variables
00179   //
00180   //===================+++++++++++++========================
00181 
00182   
00183   //Get value of any variable given location of the variable within userContent and the module number based on enum CMSTracker
00184   double GetGenericVariable( int variableLocation, int module ) const { return genericVariables_[variableLocation][GetModuleLocation(module)]; }
00185 
00186   //Get value of any variable given variable name and the module number based on enum CMSTracker
00187   double GetGenericVariable( std::string variableName, int module ) const { 
00188 
00189     int position = GetVariableLocation(variableName);
00190     int mposition = GetModuleLocation(module);
00191 
00192     return genericVariables_[position][mposition];    
00193   }
00194 
00195   //Get specific varibale for all modules using the variable name
00196   std::vector<double> GetGenericVariable( std::string variableName ) const {     
00197     return genericVariables_[GetVariableLocation(variableName)];
00198   }
00199 
00200   //Get specific varibale for all modules using the location of the variable within userContent
00201   std::vector<double> GetGenericVariable( int variableLocation ) const {     
00202     return genericVariables_[variableLocation];
00203   }
00204 
00205   //Get the vector genericVariables_
00206   std::vector< std::vector<double> > GetGenericVariable() const { return genericVariables_; }  
00207 
00208   //Set the vector genericVariables_ based on the location of the variable within userContent and the module number based on enum CMSTracker
00209   void SetGenericVariable( int variableLocation, int module, double value ) { genericVariablesTmp_[variableLocation][GetModuleLocation(module)] += value; } 
00210 
00211   //Set the vector genericVariables_ given the variable name and the module number based on enum CMSTracker
00212   void SetGenericVariable( std::string variableName, int module, double value ) { 
00213     
00214     /*
00215       genericVariablesTmp[ variable ][ module ]
00216       
00217       This will fill the values in the order as they are filled in the produced.
00218       
00219       1) Find where the variableName lives in userContent
00220       2) Find where module lives in modules_
00221 
00222     */
00223 
00224     int position = GetVariableLocation(variableName);
00225     int mposition = GetModuleLocation(module);
00226 
00227     genericVariablesTmp_[position][mposition] += value;    
00228   } 
00229 
00230   //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.
00231   void PrepairGenericVariable() { 
00232     
00233     genericVariables_ = genericVariablesTmp_;
00234     
00235     for (unsigned int i = 0; i < userContent.size(); ++i){
00236       genericVariables_[i].erase(std::remove(genericVariables_[i].begin(), genericVariables_[i].end(), 0), genericVariables_[i].end());
00237     }
00238   } 
00239 
00240   //Clear genericVariablesTmp_. Must be done at the end of each event.
00241   void ClearGenericVariable() { 
00242     
00243     //genericVariablesTmp_.clear();
00244 
00245     for (unsigned int i = 0; i < genericVariablesTmp_.size(); ++i){
00246       for (unsigned int j = 0; j < genericVariablesTmp_[i].size(); ++j){
00247         genericVariablesTmp_[i][j] = 0;
00248       }
00249     }    
00250   } 
00251 
00252 
00253 
00254   // Setter and Getter for the User Content. You can also return the size and what is stored in the UserContent 
00255   void SetUserContent(std::vector<std::string> Content)  const { userContent = Content;}
00256   std::vector<std::string> GetUserContent()  { return userContent;}
00257   int GetUserContentSize()  { return userContent.size(); }
00258   void  GetUserContentInfo() const  { 
00259     std::cout << "Saving info for " ;
00260     for (unsigned int i = 0; i < userContent.size(); ++i){ std::cout << userContent.at(i) << " " ;}
00261     std::cout << std::endl;
00262   }
00263   int GetVariableLocation ( std::string var ) const;
00264 
00265 
00266   //Set and Get modules_
00267   void SetUserModules( int value ) { modules_.push_back( value ); }
00268   std::vector<int> GetUserModules( ) const { return modules_;  }
00269   void ClearUserModules( ) { modules_.clear(); }
00270   // Return the location of desired module within modules_. 
00271   int GetModuleLocation ( int mod ) const;
00272 
00273 
00274   //Set and Get iterator_
00275   void SetUserIterator() { iterator_.push_back( GetUserContentSize()  );}
00276   std::vector<int> GetUserIterator() const { return iterator_; }
00277   void ClearUserIterator() { iterator_.clear(); }
00278     
00279   // Return a vector of the modules that summary infomation was requested for. This should come from the provenance information. 
00280   std::vector<std::string> DecodeProvInfo(std::string ProvInfo) const;
00281 
00282   // Class which determines if a detId is part of a desired partition
00283   class ModuleSelection{
00284   public:
00285     ModuleSelection(std::string gs){
00286       geosearch = gs;
00287     };
00288     virtual std::pair<int,int> IsStripSelected (int DetId);
00289     virtual std::pair<int,int> IsPixelSelected (int DetId);
00290   private:
00291     std::string geosearch; // string of selected modules        
00292   };
00293 
00294 
00295 
00296 
00297  private:
00298   
00299 
00300   // String which stores the name of the variables the user is getting the summary info for
00301   mutable std::vector<std::string>        userContent;
00302 
00303   std::vector<int>    iterator_;   // <number of varibale for Module1, number of varibale for Module2 ...>
00304   std::vector<int>    modules_;    // <Module1, Module2 ...>
00305 
00306   std::vector< std::vector<double> > genericVariables_; 
00307   mutable std::vector< std::vector<double> > genericVariablesTmp_; 
00308 
00309 };
00310 
00311 
00312 #endif
00313 
00314 
00315 
00316 
00317 
00318 
00319