CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoLocalTracker/SubCollectionProducers/src/ClusterAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    ClusterAnalyzer
00004 // Class:      ClusterAnalyzer
00005 // 
00013 //
00014 // Original Author:  Michael Segala
00015 //         Created:  Wed Feb 23 17:36:23 CST 2011
00016 // $Id: ClusterAnalyzer.cc,v 1.3 2012/04/24 15:44:32 msegala Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "TTree.h"
00033 #include "FWCore/ServiceRegistry/interface/Service.h" 
00034 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00035 #include <TH1.h>
00036 #include <TFile.h>
00037 #include "DataFormats/TrackerCommon/interface/ClusterSummary.h"
00038 
00039 
00040 //
00041 // class declaration
00042 //
00043 
00044 class ClusterSummary;
00045 
00046 
00047 using namespace std;
00048 
00049 class ClusterAnalyzer : public edm::EDAnalyzer {
00050    public:
00051       explicit ClusterAnalyzer(const edm::ParameterSet&);
00052       ~ClusterAnalyzer();
00053 
00054 
00055    private:
00056       virtual void beginJob() ;
00057       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00058    
00059    
00060       // ----------member data ---------------------------
00061 
00062       edm::InputTag _class;
00063 
00064       std::map<int, std::string> enumModules_;
00065       std::map< std::string, TH1D* > histos1D_;
00066   
00067       std::vector<int>   modules_;  
00068   
00069       std::vector<int> nType_; 
00070       std::vector<double> clusterSize_; 
00071       std::vector<double> clusterCharge_;
00072 
00073       std::vector<std::string>  v_moduleTypes;
00074       std::vector<std::string>  v_variables;
00075 
00076       std::vector< std::vector<double> > genericVariables_; 
00077 
00078       bool _firstPass;
00079       edm::Service<TFileService> fs;
00080       std::vector<string> maps;
00081 
00082       bool _verbose;
00083 
00084       std::string ProvInfo;
00085       std::string ProvInfo_vars;
00086       std::string ProvInfoPixels;
00087       std::string ProvInfoPixels_vars;
00088 
00089       bool doStrips;
00090       bool doPixels;
00091 };
00092 
00093 
00094 ClusterAnalyzer::ClusterAnalyzer(const edm::ParameterSet& iConfig)
00095 {
00096   
00097   _class    = iConfig.getParameter<edm::InputTag>("clusterSum");
00098 
00099   _firstPass = true;
00100   _verbose = true;    //set to true to see the event by event summary info
00101 
00102 }
00103 
00104 
00105 ClusterAnalyzer::~ClusterAnalyzer(){}
00106 
00107 void
00108 ClusterAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00109 {
00110    using namespace edm;
00111 
00112    
00113    Handle< ClusterSummary  > class_;
00114    iEvent.getByLabel( _class, class_);
00115       
00116    if (_firstPass){
00117    
00118      modules_ . clear();
00119      modules_ = class_ -> GetUserModules();
00120 
00121      //  Provenance Information
00122      const Provenance& prov = iEvent.getProvenance(class_.id());
00123      edm::ParameterSet pSet=getParameterSet( prov.psetID() );   
00124 
00125      ProvInfo = "";
00126      ProvInfo_vars = "";
00127      ProvInfoPixels = "";
00128      ProvInfoPixels_vars = "";
00129 
00130      std::string ProvString = "";
00131      std::string VarString = "";
00132        
00133      doStrips = pSet.getParameter<bool>("doStrips");
00134      doPixels = pSet.getParameter<bool>("doPixels");
00135 
00136      if (doStrips){
00137        ProvInfo = pSet.getParameter<string>("stripModule");
00138        cout << "From provenance infomation the selected strip modules are = "<< ProvInfo << endl;
00139        ProvInfo_vars = pSet.getParameter<string>("stripVariables");
00140        cout << "From provenance infomation the avaliable strip variables are = "<< ProvInfo_vars << endl;
00141 
00142      }
00143      if (doPixels){
00144        ProvInfoPixels = pSet.getParameter<string>("pixelModule");
00145        cout << "From provenance infomation the selected pixel modules are = "<< ProvInfoPixels << endl;
00146        ProvInfoPixels_vars = pSet.getParameter<string>("pixelVariables");
00147        cout << "From provenance infomation the avaliable pixel variables are = "<< ProvInfoPixels_vars << endl;
00148      }
00149 
00150 
00151      if (doStrips && doPixels) {
00152        ProvString = ProvInfo + "," + ProvInfoPixels;
00153        VarString = ProvInfo_vars + "," + ProvInfoPixels_vars;
00154      }
00155      else if (doStrips && !doPixels) {
00156        ProvString = ProvInfo;
00157        VarString = ProvInfo_vars;
00158      }
00159      else if (!doStrips && doPixels) {
00160        ProvString = ProvInfoPixels;
00161        VarString = ProvInfoPixels_vars;
00162      }
00163      
00164      // Define the Modules to get the summary info out of  
00165      v_moduleTypes = class_ -> DecodeProvInfo( ProvString );
00166      v_variables = class_ -> DecodeProvInfo( VarString );
00167 
00168    }
00169    
00170    class_ -> SetUserContent( v_variables );   
00171         
00172    genericVariables_ = class_ -> GetGenericVariable();   
00173    
00174    //cout << class_ -> GetGenericVariable("cHits", ClusterSummary::TIB) << endl;
00175 
00176    if ( _firstPass ){ //only do on the first event
00177  
00178      // Loop over all the modules to create a Map of Histograms to fill
00179      int n = 0;
00180      for ( vector<int>::const_iterator mod = modules_ . begin(); mod != modules_ . end(); mod++ ){
00181 
00182        //cout << "Creating histograms for " << *mod << endl;
00183        cout << "Creating histograms for " << v_moduleTypes.at(n) << endl;
00184        
00185        std::string tmpstr = v_moduleTypes.at(n);
00186 
00187        histos1D_[ (tmpstr + "nclusters").c_str() ] = fs->make< TH1D >( (tmpstr + "nclusters").c_str() , (tmpstr + "nclusters").c_str() , 1000 , 0 , 3000   ); 
00188        histos1D_[ (tmpstr + "nclusters").c_str() ]->SetXTitle( ("number of Clusters in " + tmpstr).c_str() );    
00189   
00190        histos1D_[ (tmpstr + "avgCharge").c_str() ] = fs->make< TH1D >( (tmpstr + "avgCharge").c_str() , (tmpstr + "avgCharge").c_str() , 500 , 0 , 1000   ); 
00191        histos1D_[ (tmpstr + "avgCharge").c_str() ]->SetXTitle( ("average cluster charge in " + tmpstr).c_str() );    
00192   
00193        histos1D_[ (tmpstr + "avgSize").c_str() ] = fs->make< TH1D >( (tmpstr + "avgSize").c_str() , (tmpstr + "avgSize").c_str() , 30 , 0 , 10   ); 
00194        histos1D_[ (tmpstr + "avgSize").c_str() ]->SetXTitle( ("average cluster size in " + tmpstr).c_str() );    
00195 
00196        maps.push_back( (tmpstr + "nclusters").c_str() );
00197        maps.push_back( (tmpstr + "avgSize").c_str() );
00198        maps.push_back( (tmpstr + "avgCharge").c_str() );
00199        
00200        ++n;
00201 
00202      }
00203 
00204      _firstPass = false;
00205    
00206    }
00207 
00208    int n = 0;
00209    for ( vector<int>::const_iterator mod = modules_ . begin(); mod != modules_ . end(); mod++ ){
00210   
00211      std::string tmpstr = v_moduleTypes.at(n);
00212 
00213      //Trick to see if it comes from a strip or pixel variable. If the first digit is < 6 then it is from the strips.
00214      int mod_tmp = *mod;
00215      while (mod_tmp > 9 ){
00216        mod_tmp /= 10;
00217      }
00218      
00219      if ( mod_tmp < 6 ){
00220 
00221        histos1D_[ (tmpstr + "nclusters").c_str() ] -> Fill( class_ -> GetGenericVariable("cHits", *mod) );
00222        histos1D_[ (tmpstr + "avgSize").c_str()   ] -> Fill( class_ -> GetGenericVariable("cSize", *mod)  /class_ -> GetGenericVariable("cHits", *mod) );
00223        histos1D_[ (tmpstr + "avgCharge").c_str() ] -> Fill( class_ -> GetGenericVariable("cCharge", *mod)/class_ -> GetGenericVariable("cHits", *mod) );
00224 
00225        cout << "n"<<tmpstr <<", avg size, avg charge = "<< class_ -> GetGenericVariable( "cHits",*mod ); 
00226        cout << ", "<< class_ -> GetGenericVariable( "cSize",*mod )  /class_ -> GetGenericVariable( "cHits",*mod ); 
00227        cout << ", "<< class_ -> GetGenericVariable( "cCharge",*mod )/class_ -> GetGenericVariable( "cHits",*mod ) <<  endl;
00228 
00229      }
00230      else{
00231        histos1D_[ (tmpstr + "nclusters").c_str() ] -> Fill( class_ -> GetGenericVariable("pHits", *mod) );
00232        histos1D_[ (tmpstr + "avgSize").c_str()   ] -> Fill( class_ -> GetGenericVariable("pSize", *mod)/class_ -> GetGenericVariable("pHits", *mod) );
00233        histos1D_[ (tmpstr + "avgCharge").c_str() ] -> Fill( class_ -> GetGenericVariable("pCharge", *mod)/class_ -> GetGenericVariable("pHits", *mod) );
00234        
00235        cout << "n"<<tmpstr <<", avg size, avg charge = "<< class_ -> GetGenericVariable( "pHits",*mod );
00236        cout << ", "<< class_ -> GetGenericVariable( "pSize",*mod )  /class_ -> GetGenericVariable( "pHits",*mod );
00237        cout << ", "<< class_ -> GetGenericVariable( "pCharge",*mod )/class_ -> GetGenericVariable( "pHits",*mod ) <<  endl;
00238 
00239      }
00240      
00241      ++n;
00242 
00243    }
00244    
00245    cout << "----------------------------------------------------" << endl;
00246    
00247 
00248 }
00249 
00250 
00251 // ------------ method called once each job just before starting event loop  ------------
00252 void 
00253 ClusterAnalyzer::beginJob(){}
00254 
00255 //define this as a plug-in
00256 DEFINE_FWK_MODULE(ClusterAnalyzer);