CMS 3D CMS Logo

UncleanSCRecoveryProducer.cc
Go to the documentation of this file.
1 /*
2 UncleanSCRecoveryProducer:
3 ^^^^^^^^^^^^^^^^^^^^^^^^^^
4 
5 takes the collections of flagged clean and unclean only SC
6 (this is the output of UnifiedSCCollectionProducer) and
7 recovers the original collection of unclean SC.
8 
9 18 Aug 2010
10 Nikolaos Rompotis and Chris Seez - Imperial College London
11 many thanks to David Wardrope, Shahram Rahatlou and Federico Ferri
12 */
13 
29 
30 #include <iostream>
31 #include <memory>
32 #include <vector>
33 
35 public:
37 
38  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
39 
40 private:
41  // the clean collection
44  // the uncleaned collection
47  // the names of the products to be produced:
50 };
51 
54 
56  : cleanBcCollection_(consumes<reco::BasicClusterCollection>(ps.getParameter<edm::InputTag>("cleanBcCollection"))),
57  cleanScCollection_(consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("cleanScCollection"))),
58  uncleanBcCollection_(
59  consumes<reco::BasicClusterCollection>(ps.getParameter<edm::InputTag>("uncleanBcCollection"))),
60  uncleanScCollection_(
61  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("uncleanScCollection"))),
62  bcCollection_(ps.getParameter<std::string>("bcCollection")),
63  scCollection_(ps.getParameter<std::string>("scCollection")) {
64  // the products:
65  produces<reco::BasicClusterCollection>(bcCollection_);
66  produces<reco::SuperClusterCollection>(scCollection_);
67 }
68 
70  // __________________________________________________________________________
71  //
72  // cluster collections:
75  //
78  // clean collections ________________________________________________________
79  evt.getByToken(cleanScCollection_, pCleanSC);
80  const reco::SuperClusterCollection cleanSC = *(pCleanSC.product());
81 
82  // unclean collections ______________________________________________________
83  evt.getByToken(uncleanBcCollection_, pUncleanBC);
84  const reco::BasicClusterCollection uncleanBC = *(pUncleanBC.product());
85  //
86  evt.getByToken(uncleanScCollection_, pUncleanSC);
87  const reco::SuperClusterCollection uncleanSC = *(pUncleanSC.product());
88  int uncleanSize = pUncleanSC->size();
89  int cleanSize = pCleanSC->size();
90 
91  LogTrace("EcalCleaning") << "Size of Clean Collection: " << cleanSize << ", uncleanSize: " << uncleanSize;
92 
93  // collections are all taken now ____________________________________________
94  //
95  // the collections to be produced ___________________________________________
96  reco::BasicClusterCollection basicClusters;
98  //
99  //
100  // collect all the basic clusters of the SC that belong to the unclean
101  // collection and put them into the basicClusters vector
102  // keep the information of which SC they belong to
103  //
104  // loop over the unclean sc: all SC will join the new collection
105  std::vector<std::pair<int, int> > basicClusterOwner; // counting all
106 
107  std::vector<DetId> scUncleanSeedDetId; // counting the unclean
108  for (int isc = 0; isc < uncleanSize; ++isc) {
109  const reco::SuperCluster& unsc = uncleanSC[isc];
110  scUncleanSeedDetId.push_back(unsc.seed()->seed());
112  for (; bciter != unsc.clustersEnd(); ++bciter) {
113  // the basic clusters
114  basicClusters.push_back(**bciter);
115  // index of the unclean SC
116  basicClusterOwner.push_back(std::make_pair(isc, 0));
117  }
118  }
119  // loop over the clean: only the ones which are in common with the unclean
120  // are taken into account
121 
122  std::vector<DetId> scCleanSeedDetId; // counting the clean
123  std::vector<int> isToBeKept;
124  for (int isc = 0; isc < cleanSize; ++isc) {
125  reco::SuperClusterRef cscRef(pCleanSC, isc);
126  scCleanSeedDetId.push_back(cscRef->seed()->seed());
127  for (reco::CaloCluster_iterator bciter = cscRef->clustersBegin(); bciter != cscRef->clustersEnd(); ++bciter) {
128  // the basic clusters
129  basicClusters.push_back(**bciter);
130  // index of the clean SC
131  basicClusterOwner.push_back(std::make_pair(isc, 1));
132  }
133  if (cscRef->isInUnclean())
134  isToBeKept.push_back(1);
135  else
136  isToBeKept.push_back(0);
137  }
138  //
139  // now export the basic clusters into the event and get them back
140  auto basicClusters_p = std::make_unique<reco::BasicClusterCollection>();
141  basicClusters_p->assign(basicClusters.begin(), basicClusters.end());
143  if (!(bccHandle.isValid())) {
144  edm::LogWarning("MissingInput") << "could not handle the new BasicClusters!";
145  return;
146  }
147 
148  LogTrace("EcalCleaning") << "Got the BasicClusters from the event again";
149  int bcSize = bccHandle->size();
150  //
151  // now we can create the SC collection
152  //
153  // run over the unclean SC: all to be kept here
154  for (int isc = 0; isc < uncleanSize; ++isc) {
155  reco::CaloClusterPtrVector clusterPtrVector;
156  // the seed is the basic cluster with the highest energy
158  for (int jbc = 0; jbc < bcSize; ++jbc) {
159  std::pair<int, int> theBcOwner = basicClusterOwner[jbc];
160  if (theBcOwner.first == isc && theBcOwner.second == 0) {
161  reco::CaloClusterPtr currentClu = reco::CaloClusterPtr(bccHandle, jbc);
162  clusterPtrVector.push_back(currentClu);
163  if (scUncleanSeedDetId[isc] == currentClu->seed()) {
164  seed = currentClu;
165  }
166  }
167  }
168  const reco::SuperCluster& unsc = uncleanSC[isc];
169  reco::SuperCluster newSC(unsc.energy(), unsc.position(), seed, clusterPtrVector);
171  superClusters.push_back(newSC);
172  }
173  // run over the clean SC: only those who are in common between the
174  // clean and unclean collection are kept
175  for (int isc = 0; isc < cleanSize; ++isc) {
176  reco::SuperClusterRef cscRef(pCleanSC, isc);
177  if (not cscRef->isInUnclean())
178  continue;
179  reco::CaloClusterPtrVector clusterPtrVector;
180  // the seed is the basic cluster with the highest energy
182  for (int jbc = 0; jbc < bcSize; ++jbc) {
183  std::pair<int, int> theBcOwner = basicClusterOwner[jbc];
184  if (theBcOwner.first == isc && theBcOwner.second == 1) {
185  reco::CaloClusterPtr currentClu = reco::CaloClusterPtr(bccHandle, jbc);
186  clusterPtrVector.push_back(currentClu);
187  if (scCleanSeedDetId[isc] == currentClu->seed()) {
188  seed = currentClu;
189  }
190  }
191  }
192  reco::SuperCluster newSC(cscRef->energy(), cscRef->position(), seed, clusterPtrVector);
194  superClusters.push_back(newSC);
195  }
196 
197  auto superClusters_p = std::make_unique<reco::SuperClusterCollection>();
198  superClusters_p->assign(superClusters.begin(), superClusters.end());
199 
200  evt.put(std::move(superClusters_p), scCollection_);
201 
202  LogTrace("EcalCleaning") << "Clusters (Basic/Super) added to the Event! :-)";
203 
204  // ----- debugging ----------
205  // print the new collection SC quantities
206  // print out the clean collection SC
207  LogTrace("EcalCleaning") << "Clean Collection SC ";
208  for (int i = 0; i < cleanSize; ++i) {
209  const reco::SuperCluster& csc = cleanSC[i];
210  LogTrace("EcalCleaning") << " >>> clean #" << i << "; Energy: " << csc.energy() << " eta: " << csc.eta()
211  << " sc seed detid: " << csc.seed()->seed().rawId();
212  }
213  // the unclean SC
214  LogTrace("EcalCleaning") << "Unclean Collection SC ";
215  for (int i = 0; i < uncleanSize; ++i) {
216  const reco::SuperCluster& usc = uncleanSC[i];
217  LogTrace("EcalCleaning") << " >>> unclean #" << i << "; Energy: " << usc.energy() << " eta: " << usc.eta()
218  << " sc seed detid: " << usc.seed()->seed().rawId();
219  }
220  // the new collection
221  LogTrace("EcalCleaning") << "The new SC clean collection with size " << superClusters.size();
222  for (unsigned int i = 0; i < superClusters.size(); ++i) {
223  const reco::SuperCluster nsc = superClusters[i];
224  LogTrace("EcalCleaning") << " >>> newSC #" << i << "; Energy: " << nsc.energy() << " eta: " << nsc.eta()
225  << " isClean=" << nsc.isInClean() << " isUnclean=" << nsc.isInUnclean()
226  << " sc seed detid: " << nsc.seed()->seed().rawId();
227  }
228 }
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
UncleanSCRecoveryProducer(const edm::ParameterSet &ps)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:152
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:88
T const * product() const
Definition: Handle.h:70
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
edm::Ptr< CaloCluster > CaloClusterPtr
const edm::EDGetTokenT< reco::SuperClusterCollection > uncleanScCollection_
#define LogTrace(id)
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:91
const edm::EDGetTokenT< reco::SuperClusterCollection > cleanScCollection_
void setFlags(uint32_t flags)
Definition: CaloCluster.h:194
bool isInUnclean() const
Definition: CaloCluster.h:199
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
const edm::EDGetTokenT< reco::BasicClusterCollection > cleanBcCollection_
bool isInClean() const
Definition: CaloCluster.h:198
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: L1Track.h:19
double energy() const
cluster energy
Definition: CaloCluster.h:149
const edm::EDGetTokenT< reco::BasicClusterCollection > uncleanBcCollection_
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:79
fixed size matrix
HLT enums.
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511