CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
CleanAndMergeProducer Class Reference

#include <CleanAndMergeProducer.h>

Inheritance diagram for CleanAndMergeProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CleanAndMergeProducer (const edm::ParameterSet &ps)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
 ~CleanAndMergeProducer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

std::string bcCollection_
 
edm::EDGetTokenT
< reco::SuperClusterCollection
cleanScToken_
 
std::string refScCollection_
 
std::string scCollection_
 
edm::EDGetTokenT
< reco::SuperClusterCollection
uncleanScToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 17 of file CleanAndMergeProducer.h.

Constructor & Destructor Documentation

CleanAndMergeProducer::CleanAndMergeProducer ( const edm::ParameterSet ps)

Definition at line 53 of file CleanAndMergeProducer.cc.

References bcCollection_, cleanScToken_, edm::ParameterSet::getParameter(), refScCollection_, scCollection_, AlCaHLTBitMon_QueryRunRegistry::string, and uncleanScToken_.

54 {
55 
56  // get the parameters
57  // the cleaned collection:
58  cleanScToken_ =
59  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("cleanScInputTag"));
61  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("uncleanScInputTag"));
62 
63  // the names of the products to be produced:
64  bcCollection_ = ps.getParameter<std::string>("bcCollection");
65  scCollection_ = ps.getParameter<std::string>("scCollection");
66  refScCollection_ = ps.getParameter<std::string>("refScCollection");
67 
68  std::map<std::string,double> providedParameters;
69  providedParameters.insert(std::make_pair("LogWeighted",ps.getParameter<bool>("posCalc_logweight")));
70  providedParameters.insert(std::make_pair("T0_barl",ps.getParameter<double>("posCalc_t0")));
71  providedParameters.insert(std::make_pair("W0",ps.getParameter<double>("posCalc_w0")));
72  providedParameters.insert(std::make_pair("X0",ps.getParameter<double>("posCalc_x0")));
73 
74 
75  // the products:
76  produces< reco::BasicClusterCollection >(bcCollection_);
77  produces< reco::SuperClusterCollection >(scCollection_);
78  produces< reco::SuperClusterRefVector >(refScCollection_);
79 
80 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::SuperClusterCollection > uncleanScToken_
edm::EDGetTokenT< reco::SuperClusterCollection > cleanScToken_
CleanAndMergeProducer::~CleanAndMergeProducer ( )

Definition at line 82 of file CleanAndMergeProducer.cc.

82 {;}

Member Function Documentation

void CleanAndMergeProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
virtual

Implements edm::stream::EDProducerBase.

Definition at line 84 of file CleanAndMergeProducer.cc.

References bcCollection_, cleanScToken_, relval_parameters_module::energy, plotBeamSpotDB::first, edm::Event::getByToken(), i, edm::OrphanHandleBase::isValid(), LogDebug, LogTrace, edm::RefVector< C, T, F >::push_back(), edm::PtrVector< T >::push_back(), edm::Event::put(), refScCollection_, scCollection_, fileCollector::seed, edm::RefVector< C, T, F >::size(), and uncleanScToken_.

86 {
87  // get the input collections
88  // ______________________________________________________________________________________
89  //
90  // cluster collections:
91 
94 
95  evt.getByToken(cleanScToken_, pCleanSC);
96  evt.getByToken(uncleanScToken_, pUncleanSC);
97 
98  //
99  // collections are all taken now _____________________________________________________
100  //
101  //
102  // the collections to be produced:
103  reco::BasicClusterCollection basicClusters;
104  reco::SuperClusterCollection superClusters;
106 
107  //
108  // run over the uncleaned SC and check how many of them are matched to the cleaned ones
109  // if you find a matched one, create a reference to the cleaned collection and store it
110  // if you find an unmatched one, then keep all its basic clusters in the basic Clusters
111  // vector
112  int uncleanSize = pUncleanSC->size();
113  int cleanSize = pCleanSC->size();
114 
115  LogTrace("EcalCleaning") << "Size of Clean Collection: " << cleanSize
116  << ", uncleanSize: " << uncleanSize << std::endl;
117  //
118  // keep whether the SC in unique in the uncleaned collection
119  std::vector<int> isUncleanOnly; // 1 if unique in the uncleaned
120  std::vector<int> basicClusterOwner; // contains the index of the SC that owns that BS
121  std::vector<int> isSeed; // if this basic cluster is a seed it is 1
122  for (int isc =0; isc< uncleanSize; ++isc) {
123  reco::SuperClusterRef unscRef( pUncleanSC, isc );
124  const std::vector< std::pair<DetId, float> > & uhits = unscRef->hitsAndFractions();
125  int uhitsSize = uhits.size();
126  bool foundTheSame = false;
127  for (int jsc=0; jsc < cleanSize; ++jsc) { // loop over the cleaned SC
128  reco::SuperClusterRef cscRef( pCleanSC, jsc );
129  const std::vector< std::pair<DetId, float> > & chits = cscRef->hitsAndFractions();
130  int chitsSize = chits.size();
131  foundTheSame = true;
132  if (unscRef->seed()->seed() == cscRef->seed()->seed() && chitsSize == uhitsSize) {
133  // if the clusters are exactly the same then because the clustering
134  // algorithm works in a deterministic way, the order of the rechits
135  // will be the same
136  for (int i=0; i< chitsSize; ++i) {
137  if (uhits[i].first != chits[i].first ) { foundTheSame=false; break;}
138  }
139  if (foundTheSame) { // ok you have found it!
140  // make the reference
141  //scRefs->push_back( edm::Ref<reco::SuperClusterCollection>(pCleanSC, jsc) );
142  scRefs->push_back( cscRef );
143  isUncleanOnly.push_back(0);
144  break;
145  }
146  }
147  }
148  if (not foundTheSame) {
149  // mark it as unique in the uncleaned
150  isUncleanOnly.push_back(1);
151  // keep all its basic clusters
152  for (reco::CaloCluster_iterator bciter = unscRef->clustersBegin(); bciter != unscRef->clustersEnd(); ++bciter) {
153  // the basic clusters
154  basicClusters.push_back(**bciter);
155  basicClusterOwner.push_back(isc);
156  }
157  }
158  }
159  int bcSize = basicClusters.size();
160 
161  LogDebug("EcalCleaning") << "Found cleaned SC: " << cleanSize << " uncleaned SC: "
162  << uncleanSize << " from which " << scRefs->size()
163  << " will become refs to the cleaned collection" ;
164 
165 
166  // now you have the collection of basic clusters of the SC to be remain in the
167  // in the clean collection, export them to the event
168  // you will need to reread them later in order to make correctly the refs to the SC
169  std::auto_ptr< reco::BasicClusterCollection> basicClusters_p(new reco::BasicClusterCollection);
170  basicClusters_p->assign(basicClusters.begin(), basicClusters.end());
172  evt.put(basicClusters_p, bcCollection_);
173  if (!(bccHandle.isValid())) {
174  edm::LogWarning("MissingInput")<<"could not get a handle on the BasicClusterCollection!" << std::endl;
175  return;
176  }
177 
178  LogDebug("EcalCleaning")<< "Got the BasicClusters from the event again";
179  // now you have to create again your superclusters
180  // you run over the uncleaned SC, but now you know which of them are
181  // the ones that are needed and which are their basic clusters
182  for (int isc=0; isc< uncleanSize; ++isc) {
183  if (isUncleanOnly[isc]==1) { // look for sc that are unique in the unclean collection
184  // make the basic cluster collection
185  reco::CaloClusterPtrVector clusterPtrVector;
186  reco::CaloClusterPtr seed; // the seed is the basic cluster with the highest energy
187  double energy = -1;
188  for (int jbc=0; jbc< bcSize; ++jbc) {
189  if (basicClusterOwner[jbc]==isc) {
190  reco::CaloClusterPtr currentClu = reco::CaloClusterPtr(bccHandle, jbc);
191  clusterPtrVector.push_back(currentClu);
192  if (energy< currentClu->energy()) {
193  energy = currentClu->energy(); seed = currentClu;
194  }
195  }
196  }
197  reco::SuperClusterRef unscRef( pUncleanSC, isc );
198  reco::SuperCluster newSC(unscRef->energy(), unscRef->position(), seed, clusterPtrVector );
199  superClusters.push_back(newSC);
200  }
201 
202  }
203  // export the collection of references to the clean collection
204  std::auto_ptr< reco::SuperClusterRefVector > scRefs_p( scRefs );
205  evt.put(scRefs_p, refScCollection_);
206 
207  // the collection of basic clusters is already in the event
208  // the collection of uncleaned SC
209  std::auto_ptr< reco::SuperClusterCollection > superClusters_p(new reco::SuperClusterCollection);
210  superClusters_p->assign(superClusters.begin(), superClusters.end());
211  evt.put(superClusters_p, scCollection_);
212  LogDebug("EcalCleaning")<< "Hybrid Clusters (Basic/Super) added to the Event! :-)";
213 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:139
edm::EDGetTokenT< reco::SuperClusterCollection > uncleanScToken_
edm::Ptr< CaloCluster > CaloClusterPtr
edm::EDGetTokenT< reco::SuperClusterCollection > cleanScToken_
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
#define LogTrace(id)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
edm::RefVector< SuperClusterCollection > SuperClusterRefVector
vector of references to objects in the same colletion of SuperCluster objects

Member Data Documentation

std::string CleanAndMergeProducer::bcCollection_
private

Definition at line 35 of file CleanAndMergeProducer.h.

Referenced by CleanAndMergeProducer(), and produce().

edm::EDGetTokenT<reco::SuperClusterCollection> CleanAndMergeProducer::cleanScToken_
private

Definition at line 31 of file CleanAndMergeProducer.h.

Referenced by CleanAndMergeProducer(), and produce().

std::string CleanAndMergeProducer::refScCollection_
private

Definition at line 37 of file CleanAndMergeProducer.h.

Referenced by CleanAndMergeProducer(), and produce().

std::string CleanAndMergeProducer::scCollection_
private

Definition at line 36 of file CleanAndMergeProducer.h.

Referenced by CleanAndMergeProducer(), and produce().

edm::EDGetTokenT<reco::SuperClusterCollection> CleanAndMergeProducer::uncleanScToken_
private

Definition at line 32 of file CleanAndMergeProducer.h.

Referenced by CleanAndMergeProducer(), and produce().