CMS 3D CMS Logo

CleanAndMergeProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
6 // Framework
12 // Reconstruction Classes
21 
22 // Geometry
30 
31 // Class header file
35 
36 /*
37 CleanAndMergeProducer:
38 ^^^^^^^^^^^^^^^^^^^^^^
39 
40 Takes as input the cleaned and the uncleaned collection of SC
41 and produces an uncleaned collection of SC without the duplicates
42 and a collection of references to the cleaned collection of SC
43 
44 25 June 2010
45 Nikolaos Rompotis and Chris Seez - Imperial College London
46 many thanks to Shahram Rahatlou and Federico Ferri
47 
48 
49 */
50 
52  // get the parameters
53  // the cleaned collection:
54  cleanScToken_ = consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("cleanScInputTag"));
55  uncleanScToken_ = consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("uncleanScInputTag"));
56 
57  // the names of the products to be produced:
58  bcCollection_ = ps.getParameter<std::string>("bcCollection");
59  scCollection_ = ps.getParameter<std::string>("scCollection");
60  refScCollection_ = ps.getParameter<std::string>("refScCollection");
61 
62  std::map<std::string, double> providedParameters;
63  providedParameters.insert(std::make_pair("LogWeighted", ps.getParameter<bool>("posCalc_logweight")));
64  providedParameters.insert(std::make_pair("T0_barl", ps.getParameter<double>("posCalc_t0")));
65  providedParameters.insert(std::make_pair("W0", ps.getParameter<double>("posCalc_w0")));
66  providedParameters.insert(std::make_pair("X0", ps.getParameter<double>("posCalc_x0")));
67 
68  // the products:
69  produces<reco::BasicClusterCollection>(bcCollection_);
70  produces<reco::SuperClusterCollection>(scCollection_);
71  produces<reco::SuperClusterRefVector>(refScCollection_);
72 }
73 
75 
77  // get the input collections
78  // ______________________________________________________________________________________
79  //
80  // cluster collections:
81 
84 
85  evt.getByToken(cleanScToken_, pCleanSC);
86  evt.getByToken(uncleanScToken_, pUncleanSC);
87 
88  //
89  // collections are all taken now _____________________________________________________
90  //
91  //
92  // the collections to be produced:
93  reco::BasicClusterCollection basicClusters;
96 
97  //
98  // run over the uncleaned SC and check how many of them are matched to the cleaned ones
99  // if you find a matched one, create a reference to the cleaned collection and store it
100  // if you find an unmatched one, then keep all its basic clusters in the basic Clusters
101  // vector
102  int uncleanSize = pUncleanSC->size();
103  int cleanSize = pCleanSC->size();
104 
105  LogTrace("EcalCleaning") << "Size of Clean Collection: " << cleanSize << ", uncleanSize: " << uncleanSize
106  << std::endl;
107  //
108  // keep whether the SC in unique in the uncleaned collection
109  std::vector<int> isUncleanOnly; // 1 if unique in the uncleaned
110  std::vector<int> basicClusterOwner; // contains the index of the SC that owns that BS
111  std::vector<int> isSeed; // if this basic cluster is a seed it is 1
112  for (int isc = 0; isc < uncleanSize; ++isc) {
113  reco::SuperClusterRef unscRef(pUncleanSC, isc);
114  const std::vector<std::pair<DetId, float> >& uhits = unscRef->hitsAndFractions();
115  int uhitsSize = uhits.size();
116  bool foundTheSame = false;
117  for (int jsc = 0; jsc < cleanSize; ++jsc) { // loop over the cleaned SC
118  reco::SuperClusterRef cscRef(pCleanSC, jsc);
119  const std::vector<std::pair<DetId, float> >& chits = cscRef->hitsAndFractions();
120  int chitsSize = chits.size();
121  foundTheSame = true;
122  if (unscRef->seed()->seed() == cscRef->seed()->seed() && chitsSize == uhitsSize) {
123  // if the clusters are exactly the same then because the clustering
124  // algorithm works in a deterministic way, the order of the rechits
125  // will be the same
126  for (int i = 0; i < chitsSize; ++i) {
127  if (uhits[i].first != chits[i].first) {
128  foundTheSame = false;
129  break;
130  }
131  }
132  if (foundTheSame) { // ok you have found it!
133  // make the reference
134  //scRefs->push_back( edm::Ref<reco::SuperClusterCollection>(pCleanSC, jsc) );
135  scRefs->push_back(cscRef);
136  isUncleanOnly.push_back(0);
137  break;
138  }
139  }
140  }
141  if (not foundTheSame) {
142  // mark it as unique in the uncleaned
143  isUncleanOnly.push_back(1);
144  // keep all its basic clusters
145  for (reco::CaloCluster_iterator bciter = unscRef->clustersBegin(); bciter != unscRef->clustersEnd(); ++bciter) {
146  // the basic clusters
147  basicClusters.push_back(**bciter);
148  basicClusterOwner.push_back(isc);
149  }
150  }
151  }
152  int bcSize = basicClusters.size();
153 
154  LogDebug("EcalCleaning") << "Found cleaned SC: " << cleanSize << " uncleaned SC: " << uncleanSize << " from which "
155  << scRefs->size() << " will become refs to the cleaned collection";
156 
157  // now you have the collection of basic clusters of the SC to be remain in the
158  // in the clean collection, export them to the event
159  // you will need to reread them later in order to make correctly the refs to the SC
160  auto basicClusters_p = std::make_unique<reco::BasicClusterCollection>();
161  basicClusters_p->assign(basicClusters.begin(), basicClusters.end());
163  if (!(bccHandle.isValid())) {
164  edm::LogWarning("MissingInput") << "could not get a handle on the BasicClusterCollection!" << std::endl;
165  return;
166  }
167 
168  LogDebug("EcalCleaning") << "Got the BasicClusters from the event again";
169  // now you have to create again your superclusters
170  // you run over the uncleaned SC, but now you know which of them are
171  // the ones that are needed and which are their basic clusters
172  for (int isc = 0; isc < uncleanSize; ++isc) {
173  if (isUncleanOnly[isc] == 1) { // look for sc that are unique in the unclean collection
174  // make the basic cluster collection
175  reco::CaloClusterPtrVector clusterPtrVector;
176  reco::CaloClusterPtr seed; // the seed is the basic cluster with the highest energy
177  double energy = -1;
178  for (int jbc = 0; jbc < bcSize; ++jbc) {
179  if (basicClusterOwner[jbc] == isc) {
180  reco::CaloClusterPtr currentClu = reco::CaloClusterPtr(bccHandle, jbc);
181  clusterPtrVector.push_back(currentClu);
182  if (energy < currentClu->energy()) {
183  energy = currentClu->energy();
184  seed = currentClu;
185  }
186  }
187  }
188  reco::SuperClusterRef unscRef(pUncleanSC, isc);
189  reco::SuperCluster newSC(unscRef->energy(), unscRef->position(), seed, clusterPtrVector);
190  superClusters.push_back(newSC);
191  }
192  }
193  // export the collection of references to the clean collection
194  std::unique_ptr<reco::SuperClusterRefVector> scRefs_p(scRefs);
195  evt.put(std::move(scRefs_p), refScCollection_);
196 
197  // the collection of basic clusters is already in the event
198  // the collection of uncleaned SC
199  auto superClusters_p = std::make_unique<reco::SuperClusterCollection>();
200  superClusters_p->assign(superClusters.begin(), superClusters.end());
201  evt.put(std::move(superClusters_p), scCollection_);
202  LogDebug("EcalCleaning") << "Hybrid Clusters (Basic/Super) added to the Event! :-)";
203 }
EcalPreshowerTopology.h
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
PositionCalc.h
MessageLogger.h
ESHandle.h
reco::SuperCluster
Definition: SuperCluster.h:18
BasicCluster.h
CleanAndMergeProducer::refScCollection_
std::string refScCollection_
Definition: CleanAndMergeProducer.h:32
EBDetId.h
EcalBarrelTopology.h
edm::PtrVectorItr
Definition: PtrVector.h:51
CleanAndMergeProducer::uncleanScToken_
edm::EDGetTokenT< reco::SuperClusterCollection > uncleanScToken_
Definition: CleanAndMergeProducer.h:27
edm::RefVector
Definition: EDProductfwd.h:27
edm::Handle
Definition: AssociativeIterator.h:50
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
reco::CaloClusterPtr
edm::Ptr< CaloCluster > CaloClusterPtr
Definition: CaloClusterFwd.h:21
BasicClusterFwd.h
edm::Ref< SuperClusterCollection >
HLT_FULL_cff.superClusters
superClusters
Definition: HLT_FULL_cff.py:15171
fileCollector.seed
seed
Definition: fileCollector.py:127
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
edm::PtrVector< CaloCluster >
CleanAndMergeProducer::CleanAndMergeProducer
CleanAndMergeProducer(const edm::ParameterSet &ps)
Definition: CleanAndMergeProducer.cc:51
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
reco::BasicClusterCollection
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
Definition: BasicClusterFwd.h:16
CaloGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::PtrVector::push_back
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
CaloSubdetectorGeometry.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
EcalEndcapTopology.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup
Definition: EventSetup.h:57
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
edm::OrphanHandleBase::isValid
bool isValid() const
Definition: OrphanHandleBase.h:53
EcalRecHit.h
edm::Ptr< CaloCluster >
CaloCellGeometry.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::OrphanHandle
Definition: EDProductfwd.h:39
SuperClusterFwd.h
SuperCluster.h
CaloGeometry.h
CleanAndMergeProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CleanAndMergeProducer.cc:76
CleanAndMergeProducer::cleanScToken_
edm::EDGetTokenT< reco::SuperClusterCollection > cleanScToken_
Definition: CleanAndMergeProducer.h:26
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
reco::SuperClusterRefVector
edm::RefVector< SuperClusterCollection > SuperClusterRefVector
vector of references to objects in the same colletion of SuperCluster objects
Definition: SuperClusterFwd.h:21
CleanAndMergeProducer.h
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
CleanAndMergeProducer::~CleanAndMergeProducer
~CleanAndMergeProducer() override
Definition: CleanAndMergeProducer.cc:74
edm::Event
Definition: Event.h:73
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
EcalChannelStatus.h
edm::InputTag
Definition: InputTag.h:15
EcalChannelStatusRcd.h
CleanAndMergeProducer::bcCollection_
std::string bcCollection_
Definition: CleanAndMergeProducer.h:30
CleanAndMergeProducer::scCollection_
std::string scCollection_
Definition: CleanAndMergeProducer.h:31
CaloCluster.h