CMS 3D CMS Logo

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