CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoLocalTracker/SubCollectionProducers/src/ClusterSummaryProducer.cc

Go to the documentation of this file.
00001 #include "RecoLocalTracker/SubCollectionProducers/interface/ClusterSummaryProducer.h"
00002 
00003 ClusterSummaryProducer::ClusterSummaryProducer(const edm::ParameterSet& iConfig)
00004   : stripClustersLabel(iConfig.getParameter<edm::InputTag>("stripClusters")),
00005     pixelClustersLabel(iConfig.getParameter<edm::InputTag>("pixelClusters")),
00006     stripModules(iConfig.getParameter<std::string>("stripModule")),
00007     pixelModules(iConfig.getParameter<std::string>("pixelModule")),
00008     stripVariables(iConfig.getParameter<std::string>("stripVariables")),
00009     pixelVariables(iConfig.getParameter<std::string>("pixelVariables")),
00010     doStrips(iConfig.getParameter<bool>("doStrips")),
00011     doPixels(iConfig.getParameter<bool>("doPixels")),
00012     verbose(iConfig.getParameter<bool>("verbose"))
00013 {
00014  
00015   //register your products
00016   produces<ClusterSummary>().setBranchAlias("SummaryCollection");
00017   
00018   firstpass = true;
00019   firstpass_mod = true;
00020   firstpassPixel = true;
00021   firstpassPixel_mod = true;
00022 
00023 }
00024 
00025 
00026 void
00027 ClusterSummaryProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00028 {
00029    using namespace edm;
00030 
00031    cCluster.ClearUserModules();
00032    
00033    //===================++++++++++++========================
00034    //
00035    //                   For SiStrips
00036    //
00037    //===================++++++++++++========================
00038    if (doStrips){
00039      edm::Handle<edmNew::DetSetVector<SiStripCluster> > stripClusters;
00040      iEvent.getByLabel(stripClustersLabel, stripClusters);
00041 
00042      ModuleSelectionVect.clear();
00043      for ( std::vector<std::string>::iterator it=v_stripModuleTypes.begin() ; it < v_stripModuleTypes.end(); it++ ){
00044        ModuleSelectionVect.push_back ( new ClusterSummary::ModuleSelection(*it) );
00045      }
00046  
00047      firstpass_mod = true;
00048    
00049      int CurrMod = -1;
00050      //Loop over all the ModuleSelectors
00051      for ( unsigned int i = 0; i < ModuleSelectionVect.size(); i++){
00052      
00053        // Loop over the strip clusters
00054        edmNew::DetSetVector<SiStripCluster>::const_iterator itClusters=stripClusters->begin();
00055        for(;itClusters!=stripClusters->end();++itClusters){
00056          uint32_t id = itClusters->id();
00057          for(edmNew::DetSet<SiStripCluster>::const_iterator cluster=itClusters->begin(); cluster!=itClusters->end();++cluster){
00058 
00059            const ClusterVariables Summaryinfo(*cluster);
00060       
00061            // For each ModuleSelector, check if the detID belongs to a desired module. If so, update the summary information for that module
00062 
00063            std::pair<int, int> ModSelect = ModuleSelectionVect.at(i) -> IsStripSelected( id );
00064            int mod_pair = ModSelect.first;
00065            int mod_pair2 = ModSelect.second;
00066 
00067            if ( mod_pair ){
00068              if ( firstpass_mod ) {
00069                CurrMod = mod_pair2;
00070                cCluster.SetUserModules( mod_pair2 ) ;
00071              }
00072            
00073              firstpass_mod = false;
00074              int CurrModTmp = mod_pair2;
00075 
00076              if ( CurrMod != CurrModTmp ) {
00077                cCluster.SetUserModules( mod_pair2 ) ;
00078                CurrMod = CurrModTmp;
00079              }
00080 
00081              cCluster.SetGenericVariable( "cHits", mod_pair2, 1 );
00082              cCluster.SetGenericVariable( "cSize", mod_pair2, Summaryinfo.clusterSize() );
00083              cCluster.SetGenericVariable( "cCharge", mod_pair2, Summaryinfo.charge() );
00084 
00085            }
00086          }
00087        }
00088      }
00089 
00090    }
00091 
00092    //===================++++++++++++========================
00093    //
00094    //                   For SiPixels
00095    //
00096    //===================++++++++++++========================
00097    if (doPixels){
00098      edm::Handle<edmNew::DetSetVector<SiPixelCluster> > pixelClusters;
00099      iEvent.getByLabel(pixelClustersLabel, pixelClusters);
00100 
00101      ModuleSelectionVectPixels.clear();
00102      for ( std::vector<std::string>::iterator it=v_pixelModuleTypes.begin() ; it < v_pixelModuleTypes.end(); it++ ){
00103        ModuleSelectionVectPixels.push_back ( new ClusterSummary::ModuleSelection(*it) );
00104      }
00105 
00106      firstpassPixel_mod = true;
00107 
00108      int CurrModPixel = -1;
00109      //Loop over all the ModuleSelectors
00110      for ( unsigned int i = 0; i < ModuleSelectionVectPixels.size(); i++){
00111 
00112        // Loop over the pixel clusters
00113        edmNew::DetSetVector<SiPixelCluster>::const_iterator itClusters=pixelClusters->begin();
00114        for(;itClusters!=pixelClusters->end();++itClusters){
00115          uint32_t detid = itClusters->detId();    
00116          for(edmNew::DetSet<SiPixelCluster>::const_iterator cluster=itClusters->begin(); cluster!=itClusters->end();++cluster){
00117 
00118            // For each ModuleSelector, check if the detID belongs to a desired module. If so, update the summary information for that module
00119          
00120            std::pair<int, int> ModSelectPixel = ModuleSelectionVectPixels.at(i) -> IsPixelSelected( detid );
00121            int mod_pair = ModSelectPixel.first;
00122            int mod_pair2 = ModSelectPixel.second;
00123            if ( mod_pair ){
00124              if ( firstpassPixel_mod ) {
00125                CurrModPixel = mod_pair2;
00126                cCluster.SetUserModules( mod_pair2 ) ;
00127              }
00128              firstpassPixel_mod = false;
00129              int CurrModTmp = mod_pair2;
00130              if ( CurrModPixel != CurrModTmp ) {
00131                cCluster.SetUserModules( mod_pair2 ) ;
00132                CurrModPixel = CurrModTmp;
00133              }
00134 
00135              cCluster.SetGenericVariable( "pHits", mod_pair2, 1 );
00136              cCluster.SetGenericVariable( "pSize", mod_pair2, cluster->size() );
00137              cCluster.SetGenericVariable( "pCharge", mod_pair2, float(cluster->charge())/1000. );
00138 
00139            }
00140          }
00141        }
00142      }
00143    
00144    }
00145 
00146 
00147    //===================+++++++++++++========================
00148    //
00149    //                   Fill Producer
00150    //
00151    //===================+++++++++++++========================
00152 
00153 
00154    unsigned int n = 0;
00155    int n_pixel = 0;
00156 
00157    cCluster.PrepairGenericVariable( );
00158    
00159    std::vector<int> _mod = cCluster.GetUserModules( );
00160    for(std::vector<int>::iterator it = _mod.begin(); it != _mod.end(); ++it) {
00161      
00162      if ( n < v_stripModuleTypes.size() && doStrips ){
00163        if (verbose) std::cout << "n" << v_stripModuleTypes.at(n) <<", avg size, avg charge = "<< cCluster.GetGenericVariable( "cHits",*it ) << ", " << cCluster.GetGenericVariable( "cSize",*it )/cCluster.GetGenericVariable( "cHits",*it ) << ", "<< cCluster.GetGenericVariable( "cCharge",*it )/cCluster.GetGenericVariable( "cHits",*it )  << std::endl;
00164        delete ModuleSelectionVect[n];
00165      }
00166      else if (doPixels) {     
00167        if (verbose) {
00168          std::cout << "n" << v_pixelModuleTypes.at(n_pixel) << ", avg size, avg charge = "<< cCluster.GetGenericVariable( "pHits",*it ) << ", " << cCluster.GetGenericVariable( "pSize",*it )/cCluster.GetGenericVariable( "pHits",*it ) << ", "<< cCluster.GetGenericVariable( "pCharge",*it )/cCluster.GetGenericVariable( "pHits",*it )  << std::endl;
00169        }
00170        delete ModuleSelectionVectPixels[n_pixel];
00171        ++n_pixel;
00172      } 
00173      ++n;
00174    }
00175    
00176    if (verbose) std::cout << "-------------------------------------------------------" << std::endl;
00177    
00178    firstpass = false;
00179    firstpassPixel = false;
00180 
00181    //Put the filled class into the producer
00182    std::auto_ptr<ClusterSummary> result(new ClusterSummary (cCluster) );
00183    iEvent.put( result );
00184 
00185    cCluster.ClearGenericVariable();
00186 
00187 }
00188 
00189 
00190 void 
00191 ClusterSummaryProducer::beginJob()
00192 {
00193    
00194   if (doStrips) decodeInput(v_stripModuleTypes,stripModules.c_str());
00195   if (doStrips) decodeInput(v_stripVariables,stripVariables.c_str());  
00196   if (doPixels) decodeInput(v_pixelModuleTypes,pixelModules.c_str());
00197   if (doPixels) decodeInput(v_pixelVariables,pixelVariables.c_str());  
00198 
00199   if (doStrips){
00200   if (verbose){
00201     std::cout << "+++++++++++++++++++++++++++++++ "  << std::endl;
00202     std::cout << "FOR STRIPS: "  << std::endl;
00203     std::cout << "Getting info on " ;
00204     for (unsigned int ii = 0; ii < v_stripModuleTypes.size( ); ++ii) {
00205       std::cout << v_stripModuleTypes[ii] << " " ;
00206     }
00207     std::cout << std::endl;
00208   }
00209   
00210   if (verbose) std::cout << "Getting info on strip variables " ;
00211   for (unsigned int ii = 0; ii < v_stripVariables.size( ); ++ii) {
00212     if (verbose) std::cout << v_stripVariables[ii] << " " ;
00213     v_userContent.push_back(v_stripVariables[ii]);
00214   }
00215   if (verbose) std::cout << std::endl;
00216   }
00217   
00218   if (doPixels){
00219   if (verbose){
00220     std::cout << "FOR PIXELS: " << std::endl;
00221     std::cout << "Getting info on " ;
00222     for (unsigned int ii = 0; ii < v_pixelModuleTypes.size( ); ++ii) {
00223       std::cout << v_pixelModuleTypes[ii] << " " ;
00224     }
00225     std::cout << std::endl;
00226   }
00227   
00228   if (verbose) std::cout << "Getting info on pixel variables " ;
00229   for (unsigned int ii = 0; ii < v_pixelVariables.size( ); ++ii) {
00230     if (verbose) std::cout << v_pixelVariables[ii] << " " ;
00231     v_userContent.push_back(v_pixelVariables[ii]);
00232   }
00233   if (verbose) std::cout << std::endl;
00234   if (verbose) std::cout << "+++++++++++++++++++++++++++++++ "  << std::endl;
00235   }
00236 
00237   //Create the summary info for output 
00238   cCluster.SetUserContent(v_userContent);
00239   cCluster.SetUserIterator();
00240 }
00241 
00242 
00243 
00244 
00245 void 
00246 ClusterSummaryProducer::decodeInput(std::vector<std::string> & vec, std::string mod)
00247 {
00248 
00249   // Define the Modules to get the summary info out of  
00250   std::string::size_type i = 0;
00251   std::string::size_type j = mod.find(',');
00252 
00253   if ( j == std::string::npos ){
00254     vec.push_back(mod);
00255   }
00256   else{
00257     while (j != std::string::npos) {
00258       vec.push_back(mod.substr(i, j-i));
00259       i = ++j;
00260       j = mod.find(',', j);
00261       if (j == std::string::npos)
00262         vec.push_back(mod.substr(i, mod.length( )));
00263     }
00264   }
00265 
00266 
00267 }
00268 
00269 
00270 
00271 #include "FWCore/PluginManager/interface/ModuleDef.h"
00272 #include "FWCore/Framework/interface/MakerMacros.h"
00273 DEFINE_FWK_MODULE(ClusterSummaryProducer);
00274 
00275