Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:01

0001 // -*- C++ -*-
0002 //
0003 // Package:     SiStripChannelChargeFilter
0004 // Class  :     TECClusterFilter
0005 //
0006 //
0007 // Original Author: sfricke
0008 
0009 #include "EventFilter/SiStripChannelChargeFilter/interface/TECClusterFilter.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011 #include "DataFormats/Common/interface/DetSetVector.h"
0012 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 
0015 using namespace std;
0016 
0017 namespace cms {
0018 
0019   TECClusterFilter::TECClusterFilter(const edm::ParameterSet& ps) {
0020     //
0021     ModulesToBeExcluded.clear();
0022     ModulesToBeExcluded = ps.getParameter<std::vector<unsigned> >("ModulesToBeExcluded");
0023     edm::LogInfo("TECClusterFilter") << "Clusters from " << ModulesToBeExcluded.size()
0024                                      << " modules will be ignored in the filter:";
0025     for (std::vector<uint32_t>::const_iterator imod = ModulesToBeExcluded.begin(); imod != ModulesToBeExcluded.end();
0026          imod++) {
0027       edm::LogInfo("TECClusterFilter") << *imod;
0028     }
0029     //
0030     ChargeThresholdTEC = ps.getParameter<int>("ChargeThresholdTEC");
0031     edm::LogInfo("TECClusterFilter") << "ChargeThresholdTEC" << ChargeThresholdTEC;
0032     minNrOfTECClusters = ps.getParameter<int>("MinNrOfTECClusters");
0033     edm::LogInfo("TECClusterFilter") << "MinNrOfTECClusters" << minNrOfTECClusters;
0034     clusterProducer = ps.getParameter<string>("ClusterProducer");
0035     edm::LogInfo("TECClusterFilter") << "ClusterProducer" << clusterProducer;
0036 
0037     // also put decision in the event
0038     produces<int>();
0039   }
0040 
0041   bool TECClusterFilter::filter(edm::Event& e, edm::EventSetup const& c) {
0042     edm::Handle<edm::DetSetVector<SiStripCluster> > h;  //get SiStripCluster
0043     e.getByLabel(clusterProducer, h);
0044     bool decision = false;  // default value, only accept if set true in this loop
0045     unsigned int nr_clusters_above_threshold = 0;
0046     for (edm::DetSetVector<SiStripCluster>::const_iterator it = h->begin(); it != h->end(); it++) {
0047       DetId thedetId = DetId(it->detId());
0048       bool exclude_this_detid = false;
0049       for (vector<SiStripCluster>::const_iterator vit = (it->data).begin(); vit != (it->data).end(); vit++) {
0050         for (std::vector<uint32_t>::const_iterator imod = ModulesToBeExcluded.begin();
0051              imod != ModulesToBeExcluded.end();
0052              imod++) {
0053           if (*imod == thedetId.rawId())
0054             exclude_this_detid = true;
0055         }  // found in exclusion list
0056         if ((!exclude_this_detid) &&
0057             (thedetId.subdetId() == StripSubdetector::TEC))  // if not excluded and if TEC module
0058         {                                                    // calculate sum of amplitudes
0059           unsigned int amplclus = 0;
0060           // int amplclus=0;
0061           for (auto ia = vit->amplitudes().begin(); ia != vit->amplitudes().end(); ia++) {
0062             if ((*ia) > 0)
0063               amplclus += (*ia);
0064           }  // why should this be negative?
0065           if (amplclus > ChargeThresholdTEC)
0066             nr_clusters_above_threshold++;
0067         }
0068       }
0069     }
0070     if (nr_clusters_above_threshold >= minNrOfTECClusters)
0071       decision = true;
0072     e.put(std::make_unique<int>(decision));
0073     return decision;
0074   }
0075 }  // namespace cms