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 {
40 
43 
44  // get the parameters
45  // the cleaned collection:
47  consumes<BasicClusterCollection>(ps.getParameter<edm::InputTag>("cleanBcCollection"));
49  consumes<SuperClusterCollection>(ps.getParameter<edm::InputTag>("cleanScCollection"));
50 
51  // the uncleaned collection
53  consumes<BasicClusterCollection>(ps.getParameter<edm::InputTag>("uncleanBcCollection"));
55  consumes<SuperClusterCollection>(ps.getParameter<edm::InputTag>("uncleanScCollection"));
56  // the names of the products to be produced:
57  bcCollection_ = ps.getParameter<std::string>("bcCollection");
58  scCollection_ = ps.getParameter<std::string>("scCollection");
59  // the products:
60  produces< reco::BasicClusterCollection >(bcCollection_);
61  produces< reco::SuperClusterCollection >(scCollection_);
62 
63 
64 }
65 
66 
68  const edm::EventSetup& es)
69 {
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
92  << ", uncleanSize: " << uncleanSize;
93 
94  // collections are all taken now ____________________________________________
95  //
96  // the collections to be produced ___________________________________________
97  reco::BasicClusterCollection basicClusters;
98  reco::SuperClusterCollection superClusters;
99  //
100  //
101  // collect all the basic clusters of the SC that belong to the unclean
102  // collection and put them into the basicClusters vector
103  // keep the information of which SC they belong to
104  //
105  // loop over the unclean sc: all SC will join the new collection
106  std::vector< std::pair<int, int> > basicClusterOwner; // counting all
107 
108  std::vector<DetId> scUncleanSeedDetId; // counting the unclean
109  for (int isc =0; isc< uncleanSize; ++isc) {
110  const reco::SuperCluster unsc = uncleanSC[isc];
111  scUncleanSeedDetId.push_back(unsc.seed()->seed());
113  for (; bciter != unsc.clustersEnd(); ++bciter) {
114  // the basic clusters
115  basicClusters.push_back(**bciter);
116  // index of the unclean SC
117  basicClusterOwner.push_back( std::make_pair(isc,0) );
118  }
119  }
120  // loop over the clean: only the ones which are in common with the unclean
121  // are taken into account
122 
123  std::vector<DetId> scCleanSeedDetId; // counting the clean
124  std::vector<int> isToBeKept;
125  for (int isc =0; isc< cleanSize; ++isc) {
126  reco::SuperClusterRef cscRef( pCleanSC, isc );
127  scCleanSeedDetId.push_back(cscRef->seed()->seed());
128  for (reco::CaloCluster_iterator bciter = cscRef->clustersBegin(); bciter != cscRef->clustersEnd(); ++bciter) {
129  // the basic clusters
130  basicClusters.push_back(**bciter);
131  // index of the clean SC
132  basicClusterOwner.push_back( std::make_pair(isc,1) );
133  }
134  if (cscRef->isInUnclean()) isToBeKept.push_back(1);
135  else isToBeKept.push_back(0);
136  }
137  //
138  // now export the basic clusters into the event and get them back
139  std::auto_ptr< reco::BasicClusterCollection> basicClusters_p(new reco::BasicClusterCollection);
140  basicClusters_p->assign(basicClusters.begin(), basicClusters.end());
142  evt.put(basicClusters_p, bcCollection_);
143  if (!(bccHandle.isValid())) {
144 
145  edm::LogWarning("MissingInput") << "could not handle the new BasicClusters!";
146  return;
147  }
148  reco::BasicClusterCollection basicClustersProd = *bccHandle;
149 
150  LogTrace("EcalCleaning") <<"Got the BasicClusters from the event again";
151  int bcSize = bccHandle->size();
152  //
153  // now we can create the SC collection
154  //
155  // run over the unclean SC: all to be kept here
156  for (int isc=0; isc< uncleanSize; ++isc) {
157  reco::CaloClusterPtrVector clusterPtrVector;
158  // the seed is the basic cluster with the highest energy
160  for (int jbc=0; jbc< bcSize; ++jbc) {
161  std::pair<int,int> theBcOwner = basicClusterOwner[jbc];
162  if (theBcOwner.first == isc && theBcOwner.second == 0) {
163  reco::CaloClusterPtr currentClu=reco::CaloClusterPtr(bccHandle,jbc);
164  clusterPtrVector.push_back(currentClu);
165  if (scUncleanSeedDetId[isc] == currentClu->seed()) {
166  seed = currentClu;
167  }
168  }
169  }
170  const reco::SuperCluster unsc = uncleanSC[isc];
171  reco::SuperCluster newSC(unsc.energy(), unsc.position(), seed, clusterPtrVector );
173  superClusters.push_back(newSC);
174  }
175  // run over the clean SC: only those who are in common between the
176  // clean and unclean collection are kept
177  for (int isc=0; isc< cleanSize; ++isc) {
178  reco::SuperClusterRef cscRef( pCleanSC, isc);
179  if (not cscRef->isInUnclean()) continue;
180  reco::CaloClusterPtrVector clusterPtrVector;
181  // the seed is the basic cluster with the highest energy
183  for (int jbc=0; jbc< bcSize; ++jbc) {
184  std::pair<int,int> theBcOwner = basicClusterOwner[jbc];
185  if (theBcOwner.first == isc && theBcOwner.second == 1) {
186  reco::CaloClusterPtr currentClu=reco::CaloClusterPtr(bccHandle,jbc);
187  clusterPtrVector.push_back(currentClu);
188  if (scCleanSeedDetId[isc] == currentClu->seed()) {
189  seed = currentClu;
190  }
191  }
192  }
193  reco::SuperCluster newSC(cscRef->energy(), cscRef->position(),
194  seed, clusterPtrVector );
196  superClusters.push_back(newSC);
197  }
198 
199  std::auto_ptr< reco::SuperClusterCollection>
200  superClusters_p(new reco::SuperClusterCollection);
201  superClusters_p->assign(superClusters.begin(), superClusters.end());
202 
203  evt.put(superClusters_p, scCollection_);
204 
205  LogTrace("EcalCleaning")<<"Clusters (Basic/Super) added to the Event! :-)";
206 
207  // ----- debugging ----------
208  // print the new collection SC quantities
209  // print out the clean collection SC
210  LogTrace("EcalCleaning") << "Clean Collection SC ";
211  for (int i=0; i < cleanSize; ++i) {
212  const reco::SuperCluster csc = cleanSC[i];
213  LogTrace("EcalCleaning") << " >>> clean #" << i << "; Energy: " << csc.energy()
214  << " eta: " << csc.eta()
215  << " sc seed detid: " << csc.seed()->seed().rawId();
216  }
217  // the unclean SC
218  LogTrace("EcalCleaning") << "Unclean Collection SC ";
219  for (int i=0; i < uncleanSize; ++i) {
220  const reco::SuperCluster usc = uncleanSC[i];
221  LogTrace("EcalCleaning") << " >>> unclean #" << i << "; Energy: " << usc.energy()
222  << " eta: " << usc.eta()
223  << " sc seed detid: " << usc.seed()->seed().rawId();
224  }
225  // the new collection
226  LogTrace("EcalCleaning")<<"The new SC clean collection with size "<< superClusters.size();
227  for (unsigned int i=0; i < superClusters.size(); ++i) {
228  const reco::SuperCluster nsc = superClusters[i];
229  LogTrace("EcalCleaning")<< " >>> newSC #" << i << "; Energy: " << nsc.energy()
230  << " eta: " << nsc.eta() << " isClean="
231  << nsc.isInClean() << " isUnclean=" << nsc.isInUnclean()
232  << " sc seed detid: " << nsc.seed()->seed().rawId();
233  }
234 }
UncleanSCRecoveryProducer(const edm::ParameterSet &ps)
T getParameter(std::string const &) const
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
virtual void produce(edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:139
edm::Ptr< CaloCluster > CaloClusterPtr
edm::EDGetTokenT< reco::SuperClusterCollection > cleanScCollection_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:163
edm::EDGetTokenT< reco::BasicClusterCollection > cleanBcCollection_
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:113
edm::EDGetTokenT< reco::SuperClusterCollection > uncleanScCollection_
double energy() const
cluster energy
Definition: CaloCluster.h:121
#define LogTrace(id)
bool isInClean() const
Definition: CaloCluster.h:180
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
edm::EDGetTokenT< reco::BasicClusterCollection > uncleanBcCollection_
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78