CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReducedRecHitCollectionProducer.cc
Go to the documentation of this file.
2 
6 
8 
11 
13 
16 
20 
21 #include <iostream>
22 
24 {
25 
26  recHitsLabel_ = iConfig.getParameter< edm::InputTag > ("recHitsLabel");
27  interestingDetIdCollections_ = iConfig.getParameter< std::vector<edm::InputTag> > ("interestingDetIdCollections");
28 
29  reducedHitsCollection_ = iConfig.getParameter<std::string>("reducedHitsCollection");
30 
31  //register your products
32  produces< EcalRecHitCollection > (reducedHitsCollection_) ;
33 
34 }
35 
36 
38 {}
39 
40 
41 // ------------ method called to produce the data ------------
42 void
44  const edm::EventSetup& iSetup)
45 {
46  using namespace edm;
47  using namespace std;
48 
49  if (interestingDetIdCollections_.size() < 1)
50  {
51  edm::LogError("ReducedRecHitCollectionProducer") << "VInputTag collections empty" ;
52  return;
53  }
54 
55 
57  iEvent.getByLabel(interestingDetIdCollections_[0],detIds);
58  std::vector<DetId> xtalsToStore((*detIds).size());
59  std::copy( (*detIds).begin() , (*detIds).end() , xtalsToStore.begin() );
60 
61  //Merging DetIds from different collections
62  for( unsigned int t = 1; t < interestingDetIdCollections_.size(); ++t )
63  {
66  if( !detId.isValid() ){
67  edm::LogError("MissingInput")<<"no reason to skip detid from :"<<interestingDetIdCollections_[t];
68  continue;
69  }
70 
71  for (unsigned int ii=0;ii<(*detId).size();ii++)
72  {
73  if (std::find(xtalsToStore.begin(),xtalsToStore.end(),(*detId)[ii]) == xtalsToStore.end())
74  xtalsToStore.push_back((*detId)[ii]);
75  }
76  }
77 
78  Handle<EcalRecHitCollection> recHitsHandle;
79  iEvent.getByLabel(recHitsLabel_,recHitsHandle);
80  if( !recHitsHandle.isValid() )
81  {
82  edm::LogError("ReducedRecHitCollectionProducer") << "RecHit collection not found";
83  return;
84  }
85 
86  //Create empty output collections
87  std::auto_ptr< EcalRecHitCollection > miniRecHitCollection (new EcalRecHitCollection) ;
88 
89  for (unsigned int iCry=0;iCry<xtalsToStore.size();iCry++)
90  {
91  EcalRecHitCollection::const_iterator iRecHit = recHitsHandle->find(xtalsToStore[iCry]);
92  if ( (iRecHit != recHitsHandle->end()) && (miniRecHitCollection->find(xtalsToStore[iCry]) == miniRecHitCollection->end()) )
93  miniRecHitCollection->push_back(*iRecHit);
94  }
95 
96  std::sort(xtalsToStore.begin(), xtalsToStore.end());
97  std::unique(xtalsToStore.begin(), xtalsToStore.end());
98 
99  // std::cout << "New Collection " << reducedHitsCollection_ << " size is " << miniRecHitCollection->size() << " original is " << recHitsHandle->size() << std::endl;
100  iEvent.put( miniRecHitCollection,reducedHitsCollection_ );
101 }
T getParameter(std::string const &) const
std::vector< EcalRecHit >::const_iterator const_iterator
int ii
Definition: cuy.py:588
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< edm::InputTag > interestingDetIdCollections_
bool isValid() const
Definition: HandleBase.h:76
ReducedRecHitCollectionProducer(const edm::ParameterSet &)
ctor
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual void produce(edm::Event &, const edm::EventSetup &)
producer