CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/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.2 2012/02/02 18:17:38 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 };
00090 
00091 
00092 ClusterAnalyzer::ClusterAnalyzer(const edm::ParameterSet& iConfig)
00093 {
00094   
00095   _class    = iConfig.getParameter<edm::InputTag>("clusterSum");
00096 
00097   _firstPass = true;
00098   _verbose = true;    //set to true to see the event by event summary info
00099 
00100 }
00101 
00102 
00103 ClusterAnalyzer::~ClusterAnalyzer(){}
00104 
00105 void
00106 ClusterAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00107 {
00108    using namespace edm;
00109 
00110    
00111    Handle< ClusterSummary  > class_;
00112    iEvent.getByLabel( _class, class_);
00113       
00114    if (_firstPass){
00115    
00116      modules_ . clear();
00117      modules_ = class_ -> GetUserModules();
00118 
00119      //  Provenance Information
00120      const Provenance& prov = iEvent.getProvenance(class_.id());
00121      edm::ParameterSet pSet=getParameterSet( prov.psetID() );   
00122      ProvInfo = pSet.getParameter<string>("stripModule");
00123      cout << "From provenance infomation the selected strip modules are = "<< ProvInfo << endl;
00124 
00125      ProvInfo_vars = pSet.getParameter<string>("stripVariables");
00126      cout << "From provenance infomation the avaliable strip variables are = "<< ProvInfo_vars << endl;
00127 
00128 
00129      ProvInfoPixels = pSet.getParameter<string>("pixelModule");
00130      cout << "From provenance infomation the selected pixel modules are = "<< ProvInfoPixels << endl;
00131 
00132      ProvInfoPixels_vars = pSet.getParameter<string>("pixelVariables");
00133      cout << "From provenance infomation the avaliable pixel variables are = "<< ProvInfoPixels_vars << endl;
00134      
00135      // Define the Modules to get the summary info out of  
00136      v_moduleTypes = class_ -> DecodeProvInfo( ProvInfo + "," + ProvInfoPixels );
00137      v_variables = class_ -> DecodeProvInfo( ProvInfo_vars + "," + ProvInfoPixels_vars );
00138 
00139    }
00140    
00141    class_ -> SetUserContent( v_variables );   
00142         
00143    genericVariables_ = class_ -> GetGenericVariable();   
00144    
00145    //cout << class_ -> GetGenericVariable("cHits", ClusterSummary::TIB) << endl;
00146 
00147    if ( _firstPass ){ //only do on the first event
00148  
00149      // Loop over all the modules to create a Map of Histograms to fill
00150      int n = 0;
00151      for ( vector<int>::const_iterator mod = modules_ . begin(); mod != modules_ . end(); mod++ ){
00152 
00153        //cout << "Creating histograms for " << *mod << endl;
00154        cout << "Creating histograms for " << v_moduleTypes.at(n) << endl;
00155        
00156        std::string tmpstr = v_moduleTypes.at(n);
00157 
00158        histos1D_[ (tmpstr + "nclusters").c_str() ] = fs->make< TH1D >( (tmpstr + "nclusters").c_str() , (tmpstr + "nclusters").c_str() , 1000 , 0 , 3000   ); 
00159        histos1D_[ (tmpstr + "nclusters").c_str() ]->SetXTitle( ("number of Clusters in " + tmpstr).c_str() );    
00160   
00161        histos1D_[ (tmpstr + "avgCharge").c_str() ] = fs->make< TH1D >( (tmpstr + "avgCharge").c_str() , (tmpstr + "avgCharge").c_str() , 500 , 0 , 1000   ); 
00162        histos1D_[ (tmpstr + "avgCharge").c_str() ]->SetXTitle( ("average cluster charge in " + tmpstr).c_str() );    
00163   
00164        histos1D_[ (tmpstr + "avgSize").c_str() ] = fs->make< TH1D >( (tmpstr + "avgSize").c_str() , (tmpstr + "avgSize").c_str() , 30 , 0 , 10   ); 
00165        histos1D_[ (tmpstr + "avgSize").c_str() ]->SetXTitle( ("average cluster size in " + tmpstr).c_str() );    
00166 
00167        maps.push_back( (tmpstr + "nclusters").c_str() );
00168        maps.push_back( (tmpstr + "avgSize").c_str() );
00169        maps.push_back( (tmpstr + "avgCharge").c_str() );
00170        
00171        ++n;
00172 
00173      }
00174 
00175      _firstPass = false;
00176    
00177    }
00178 
00179    int n = 0;
00180    for ( vector<int>::const_iterator mod = modules_ . begin(); mod != modules_ . end(); mod++ ){
00181   
00182      std::string tmpstr = v_moduleTypes.at(n);
00183 
00184      //Trick to see if it comes from a strip or pixel variable. If the first digit is < 6 then it is from the strips.
00185      int mod_tmp = *mod;
00186      while (mod_tmp > 9 ){
00187        mod_tmp /= 10;
00188      }
00189      
00190      if ( mod_tmp < 6 ){
00191 
00192        histos1D_[ (tmpstr + "nclusters").c_str() ] -> Fill( class_ -> GetGenericVariable("cHits", *mod) );
00193        histos1D_[ (tmpstr + "avgSize").c_str()   ] -> Fill( class_ -> GetGenericVariable("cSize", *mod)  /class_ -> GetGenericVariable("cHits", *mod) );
00194        histos1D_[ (tmpstr + "avgCharge").c_str() ] -> Fill( class_ -> GetGenericVariable("cCharge", *mod)/class_ -> GetGenericVariable("cHits", *mod) );
00195 
00196        cout << "n"<<tmpstr <<", avg size, avg charge = "<< class_ -> GetGenericVariable( "cHits",*mod ); 
00197        cout << ", "<< class_ -> GetGenericVariable( "cSize",*mod )  /class_ -> GetGenericVariable( "cHits",*mod ); 
00198        cout << ", "<< class_ -> GetGenericVariable( "cCharge",*mod )/class_ -> GetGenericVariable( "cHits",*mod ) <<  endl;
00199 
00200      }
00201      else{
00202 
00203        histos1D_[ (tmpstr + "nclusters").c_str() ] -> Fill( class_ -> GetGenericVariable("pHits", *mod) );
00204        histos1D_[ (tmpstr + "avgSize").c_str()   ] -> Fill( class_ -> GetGenericVariable("pSize", *mod)/class_ -> GetGenericVariable("pHits", *mod) );
00205        histos1D_[ (tmpstr + "avgCharge").c_str() ] -> Fill( class_ -> GetGenericVariable("pCharge", *mod)/class_ -> GetGenericVariable("pHits", *mod) );
00206        
00207        cout << "n"<<tmpstr <<", avg size, avg charge = "<< class_ -> GetGenericVariable( "pHits",*mod );
00208        cout << ", "<< class_ -> GetGenericVariable( "pSize",*mod )  /class_ -> GetGenericVariable( "pHits",*mod );
00209        cout << ", "<< class_ -> GetGenericVariable( "pCharge",*mod )/class_ -> GetGenericVariable( "pHits",*mod ) <<  endl;
00210 
00211      }
00212      
00213      ++n;
00214 
00215    }
00216    
00217    cout << "----------------------------------------------------" << endl;
00218    
00219 
00220 }
00221 
00222 
00223 // ------------ method called once each job just before starting event loop  ------------
00224 void 
00225 ClusterAnalyzer::beginJob(){}
00226 
00227 //define this as a plug-in
00228 DEFINE_FWK_MODULE(ClusterAnalyzer);