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
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  std::auto_ptr< reco::BasicClusterCollection> basicClusters_p(new reco::BasicClusterCollection);
125  basicClusters_p->assign(basicClusters.begin(), basicClusters.end());
127  evt.put(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  std::auto_ptr< reco::SuperClusterCollection>
185  superClusters_p(new reco::SuperClusterCollection);
186  superClusters_p->assign(superClusters.begin(), superClusters.end());
187 
188  evt.put(superClusters_p, scCollection_);
189 
190  LogTrace("EcalCleaning")<<"Clusters (Basic/Super) added to the Event! :-)";
191 
192  // ----- debugging ----------
193  // print the new collection SC quantities
194  // print out the clean collection SC
195  LogTrace("EcalCleaning") << "Clean Collection SC ";
196  for (int i=0; i < cleanSize; ++i) {
197  const reco::SuperCluster csc = cleanSC[i];
198  LogTrace("EcalCleaning") << " >>> clean #" << i << "; Energy: " << csc.energy()
199  << " eta: " << csc.eta()
200  << " sc seed detid: " << csc.seed()->seed().rawId();
201  }
202  // the unclean SC
203  LogTrace("EcalCleaning") << "Unclean Collection SC ";
204  for (int i=0; i < uncleanSize; ++i) {
205  const reco::SuperCluster usc = uncleanSC[i];
206  LogTrace("EcalCleaning") << " >>> unclean #" << i << "; Energy: " << usc.energy()
207  << " eta: " << usc.eta()
208  << " sc seed detid: " << usc.seed()->seed().rawId();
209  }
210  // the new collection
211  LogTrace("EcalCleaning")<<"The new SC clean collection with size "<< superClusters.size();
212  for (unsigned int i=0; i < superClusters.size(); ++i) {
213  const reco::SuperCluster nsc = superClusters[i];
214  LogTrace("EcalCleaning")<< " >>> newSC #" << i << "; Energy: " << nsc.energy()
215  << " eta: " << nsc.eta() << " isClean="
216  << nsc.isInClean() << " isUnclean=" << nsc.isInUnclean()
217  << " sc seed detid: " << nsc.seed()->seed().rawId();
218  }
219 }
UncleanSCRecoveryProducer(const edm::ParameterSet &ps)
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:126
int i
Definition: DBlmapReader.cc:9
bool isInUnclean() const
Definition: CaloCluster.h:181
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:141
edm::Ptr< CaloCluster > CaloClusterPtr
const edm::EDGetTokenT< reco::SuperClusterCollection > uncleanScCollection_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:163
const edm::EDGetTokenT< reco::SuperClusterCollection > cleanScCollection_
void setFlags(uint32_t flags)
Definition: CaloCluster.h:176
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
double energy() const
cluster energy
Definition: CaloCluster.h:121
#define LogTrace(id)
bool isInClean() const
Definition: CaloCluster.h:180
const edm::EDGetTokenT< reco::BasicClusterCollection > uncleanBcCollection_
T const * product() const
Definition: Handle.h:81
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:75
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78