CMS 3D CMS Logo

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