CMS 3D CMS Logo

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