CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/SiStripChannelChargeFilter/src/ClusterMTCCFilter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     SiStripChannelChargeFilter
00004 // Class  :     ClusterMTCCFilter
00005 // 
00006 //
00007 // Original Author:  dkcira
00008 
00009 
00010 #include "EventFilter/SiStripChannelChargeFilter/interface/ClusterMTCCFilter.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "DataFormats/Common/interface/DetSetVector.h"
00013 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00014 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00015 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 using namespace std;
00019 
00020 namespace cms
00021 {
00022 
00023 ClusterMTCCFilter::ClusterMTCCFilter(const edm::ParameterSet& ps){
00024    //
00025    ModulesToBeExcluded.clear();
00026    ModulesToBeExcluded = ps.getParameter< std::vector<unsigned> >("ModulesToBeExcluded");
00027    edm::LogInfo("ClusterMTCCFilter")<<"Clusters from "<<ModulesToBeExcluded.size()<<" modules will be ignored in the filter:";
00028    for( std::vector<uint32_t>::const_iterator imod = ModulesToBeExcluded.begin(); imod != ModulesToBeExcluded.end(); imod++){
00029      edm::LogInfo("ClusterMTCCFilter")<< *imod;
00030    }
00031    //
00032    ChargeThresholdTIB=ps.getParameter<int>("ChargeThresholdTIB");
00033    ChargeThresholdTOB=ps.getParameter<int>("ChargeThresholdTOB");
00034    ChargeThresholdTEC=ps.getParameter<int>("ChargeThresholdTEC");
00035    MinClustersDiffComponents=ps.getParameter<int>("MinClustersDiffComponents");
00036    clusterProducer = ps.getParameter<string>("ClusterProducer");
00037    //
00038    produces <int>();
00039    produces <unsigned int >();
00040    produces < map<unsigned int,vector<SiStripCluster> > >();
00041 }
00042 
00043 bool ClusterMTCCFilter::filter(edm::Event & e, edm::EventSetup const& c) {
00044   //get SiStripCluster
00045   edm::Handle< edm::DetSetVector<SiStripCluster> > h;
00046   e.getByLabel(clusterProducer,h);
00047 
00048 
00049   //
00050   unsigned int sum_of_cluster_charges=0;
00051   clusters_in_subcomponents.clear();
00052   // first find all clusters that are over the threshold
00053   for (edm::DetSetVector<SiStripCluster>::const_iterator it=h->begin();it!=h->end();it++) {
00054     for(vector<SiStripCluster>::const_iterator vit=(it->data).begin(); vit!=(it->data).end(); vit++){
00055       // calculate sum of amplitudes
00056       unsigned int amplclus=0;
00057       for(vector<uint8_t>::const_iterator ia=vit->amplitudes().begin(); ia!=vit->amplitudes().end(); ia++) {
00058         if ((*ia)>0) amplclus+=(*ia); // why should this be negative?
00059       }
00060       sum_of_cluster_charges += amplclus;
00061       DetId thedetId = DetId(it->detId());
00062       unsigned int generalized_layer = 0;
00063       bool exclude_this_detid = false;
00064       for( std::vector<uint32_t>::const_iterator imod = ModulesToBeExcluded.begin(); imod != ModulesToBeExcluded.end(); imod++ ){
00065           if(*imod == thedetId.rawId()) exclude_this_detid = true; // found in exclusion list
00066       }
00067       // apply different thresholds for TIB/TOB/TEC
00068       if( ! exclude_this_detid ){ // only consider if not in exclusion list
00069         if ( ( thedetId.subdetId()==StripSubdetector::TIB && amplclus>ChargeThresholdTIB )
00070           || ( thedetId.subdetId()==StripSubdetector::TOB && amplclus>ChargeThresholdTOB )
00071           || ( thedetId.subdetId()==StripSubdetector::TEC && amplclus>ChargeThresholdTEC )
00072           ){
00073           // calculate generalized_layer:  31 = TIB1, 32 = TIB2, 33 = TIB3, 50 = TOB, 60 = TEC
00074           if(thedetId.subdetId()==StripSubdetector::TIB){
00075              TIBDetId ptib = TIBDetId(thedetId.rawId());
00076              generalized_layer = 10*thedetId.subdetId() + ptib.layer() + ptib.stereo();
00077            if (ptib.layer()==2){
00078              generalized_layer++;
00079              if (ptib.glued()) edm::LogError("ClusterMTCCFilter")<<"WRONGGGG"<<endl;
00080            }
00081           }else{
00082             generalized_layer = 10*thedetId.subdetId();
00083           if(thedetId.subdetId()==StripSubdetector::TOB){
00084             TOBDetId ptob = TOBDetId(thedetId.rawId());
00085             generalized_layer += ptob.layer();
00086           }
00087           }
00088           // fill clusters_in_subcomponents
00089           map<unsigned int,vector<SiStripCluster> >::iterator layer_it = clusters_in_subcomponents.find(generalized_layer);
00090           if(layer_it==clusters_in_subcomponents.end()){ // if layer not found yet, create DATA vector and generate map KEY + DATA
00091             vector<SiStripCluster> local_vector;
00092             local_vector.push_back(*vit);
00093             clusters_in_subcomponents.insert( std::make_pair( generalized_layer, local_vector) );
00094           }else{ // push into already existing vector
00095              (layer_it->second).push_back(*vit);
00096           }
00097         }
00098       }
00099     }
00100   }
00101 
00102   bool decision=false; // default value, only accept if set true in this loop
00103   unsigned int nr_of_subcomps_with_clusters=0;
00104 // dk: 2006.08.24 - change filter decision as proposed by V. Ciulli. || TIB1 TIB2 counted as 1, TEC excluded
00105 //  if( clusters_in_subcomponents[31].size()>0 ) nr_of_subcomps_with_clusters++; // TIB1
00106 //  if( clusters_in_subcomponents[32].size()>0 ) nr_of_subcomps_with_clusters++; // TIB2
00107 //  if( clusters_in_subcomponents[60].size()>0 ) nr_of_subcomps_with_clusters++; // TEC
00108   if( clusters_in_subcomponents[31].size()>0 ||  clusters_in_subcomponents[32].size()>0 ) nr_of_subcomps_with_clusters++; // TIB1 || TIB2
00109   if( clusters_in_subcomponents[33].size()>0 ) nr_of_subcomps_with_clusters++; // TIB3
00110   if( clusters_in_subcomponents[51].size()>0 ) nr_of_subcomps_with_clusters++; // TOB1
00111   if( clusters_in_subcomponents[52].size()>0 ) nr_of_subcomps_with_clusters++; // TOB2
00112   if(
00113      nr_of_subcomps_with_clusters >= MinClustersDiffComponents // more than 'MinClustersDiffComponents' components have at least 1 cluster
00114      ) {
00115       decision = true; // accept event
00116   }
00117 
00118   std::auto_ptr< int > output_decision( new int(decision) );
00119   e.put(output_decision);
00120 
00121   std::auto_ptr< unsigned int > output_sumofcharges( new unsigned int(sum_of_cluster_charges) );
00122   e.put(output_sumofcharges);
00123 
00124   std::auto_ptr< map<unsigned int,vector<SiStripCluster> > > output_clusters(new map<unsigned int,vector<SiStripCluster> > (clusters_in_subcomponents));
00125   e.put(output_clusters);
00126 
00127   return decision;
00128 }
00129 }