CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDigiSelector.cc
Go to the documentation of this file.
1 #include <vector>
22 #include <TMath.h>
23 #include <iostream>
24 #include <set>
25 
26 
27 using namespace reco;
29 {
30  selectedEcalEBDigiCollection_ = ps.getParameter<std::string>("selectedEcalEBDigiCollection");
31  selectedEcalEEDigiCollection_ = ps.getParameter<std::string>("selectedEcalEEDigiCollection");
32 
33  barrelSuperClusterProducer_ = ps.getParameter<edm::InputTag>("barrelSuperClusterProducer");
34  endcapSuperClusterProducer_ = ps.getParameter<edm::InputTag>("endcapSuperClusterProducer");
35 
36  EcalEBDigiTag_ = ps.getParameter<edm::InputTag>("EcalEBDigiTag");
37  EcalEEDigiTag_ = ps.getParameter<edm::InputTag>("EcalEEDigiTag");
38 
39  EcalEBRecHitTag_ = ps.getParameter<edm::InputTag>("EcalEBRecHitTag");
40  EcalEERecHitTag_ = ps.getParameter<edm::InputTag>("EcalEERecHitTag");
41 
42  cluster_pt_thresh_ = ps.getParameter<double>("cluster_pt_thresh");
43  single_cluster_thresh_ = ps.getParameter<double>("single_cluster_thresh");
44 
45  nclus_sel_ = ps.getParameter<int>("nclus_sel");
46  produces<EBDigiCollection>(selectedEcalEBDigiCollection_);
47  produces<EEDigiCollection>(selectedEcalEEDigiCollection_);
48 
49 }
50 
51 
53 {
54 }
55 
57 {
58 
59  //Get BarrelSuperClusters to start.
60  edm::Handle<reco::SuperClusterCollection> pBarrelSuperClusters;
61 
62  evt.getByLabel(barrelSuperClusterProducer_, pBarrelSuperClusters);
63  if (!pBarrelSuperClusters.isValid()){
64  edm::LogError("EcalDigiSelector")
65  << "can't get collection with label " << barrelSuperClusterProducer_ ;
66  }
67  const reco::SuperClusterCollection & BarrelSuperClusters = *pBarrelSuperClusters;
68  //Got BarrelSuperClusters
69 
70  //Get BarrelSuperClusters to start.
71  edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
72 
73  evt.getByLabel(endcapSuperClusterProducer_, pEndcapSuperClusters);
74  if (!pEndcapSuperClusters.isValid()){
75  edm::LogError("EcalDigiSelector")
76  << "Error! can't get collection with label " << endcapSuperClusterProducer_;
77  }
78  const reco::SuperClusterCollection & EndcapSuperClusters = *pEndcapSuperClusters;
79  //Got EndcapSuperClusters
80 
81  reco::SuperClusterCollection saveBarrelSuperClusters;
82  reco::SuperClusterCollection saveEndcapSuperClusters;
83  bool meet_single_thresh = false;
84  //Loop over barrel superclusters, and apply threshold
85  for (int loop=0;loop<int(BarrelSuperClusters.size());loop++){
86  SuperCluster clus1 = BarrelSuperClusters[loop];
87  float eta1 = clus1.eta();
88  float energy1 = clus1.energy();
89  float theta1 = 2*atan(exp(-1.*eta1));
90  float cluspt1 = energy1 * sin(theta1);
91  if (cluspt1 > cluster_pt_thresh_){
92  saveBarrelSuperClusters.push_back(clus1);
93  if (cluspt1 > single_cluster_thresh_)
94  meet_single_thresh = true;
95 
96  }
97  }
98 
99  //Loop over endcap superclusters, and apply threshold
100  for (int loop=0;loop<int(EndcapSuperClusters.size());loop++){
101  SuperCluster clus1 = EndcapSuperClusters[loop];
102  float eta1 = clus1.eta();
103  float energy1 = clus1.energy();
104  float theta1 = 2*atan(exp(-1.*eta1));
105  float cluspt1 = energy1 * sin(theta1);
106  if (cluspt1 > cluster_pt_thresh_){
107  saveEndcapSuperClusters.push_back(clus1);
108  if (cluspt1 > single_cluster_thresh_)
109  meet_single_thresh = true;
110  }
111  }
112 
113  std::auto_ptr<EBDigiCollection> SEBDigiCol(new EBDigiCollection);
114  std::auto_ptr<EEDigiCollection> SEEDigiCol(new EEDigiCollection);
115  int TotClus = saveBarrelSuperClusters.size() + saveEndcapSuperClusters.size();
116  // std::cout << "Barrel Clusters: " << saveBarrelSuperClusters.size();
117  // std::cout << " Endcap Clusters: " << saveEndcapSuperClusters.size();
118  // std::cout << " Total: " << TotClus << std::endl;
119  if (TotClus >= nclus_sel_ || meet_single_thresh){
120  EcalClusterLazyTools tooly(evt, es, EcalEBRecHitTag_, EcalEERecHitTag_);
121  if (saveBarrelSuperClusters.size() > 0){
122 
123  //Get barrel rec hit collection
124 // edm::Handle<EcalRecHitCollection> ecalhitsCollH;
125 // evt.getByLabel(EcalEBRecHitTag_, ecalhitsCollH);
126 // const EcalRecHitCollection* rechitsCollection = ecalhitsCollH.product();
127 // std::set<DetId> saveTheseDetIds;
128 
129  //get barrel digi collection
131  const EBDigiCollection* digis=0;
132  evt.getByLabel(EcalEBDigiTag_,pdigis);
133  if (!pdigis.isValid()){
134  edm::LogError("EcalDigiSelector")
135  << "can't get collection with label " << EcalEBDigiTag_ ;
136  } else {
137  digis = pdigis.product(); // get a ptr to the product
138  }
139  if ( digis ) {
140  std::vector<DetId> saveTheseDetIds;
141  //pick out the detids for the 3x3 in each of the selected superclusters
142  for (int loop = 0;loop < int(saveBarrelSuperClusters.size());loop++){
143  SuperCluster clus1 = saveBarrelSuperClusters[loop];
144  CaloClusterPtr bcref = clus1.seed();
145  const BasicCluster *bc = bcref.get();
146  //Get the maximum detid
147  std::pair<DetId, float> EDetty = tooly.getMaximum(*bc);
148  //get the 3x3 array centered on maximum detid.
149  std::vector<DetId> detvec = tooly.matrixDetId(EDetty.first, -1, 1, -1, 1);
150  //Loop over the 3x3
151  for (int ik = 0;ik<int(detvec.size());++ik)
152  saveTheseDetIds.push_back(detvec[ik]);
153  //saveTheseDetIds.insert(detvec[ik]);
154  }
155  for (int detloop=0; detloop < int(saveTheseDetIds.size());++detloop){
156  EBDetId detL = EBDetId(saveTheseDetIds[detloop]);
157  // int ebcounter=0;
158  for (EBDigiCollection::const_iterator blah = digis->begin();
159  blah!=digis->end();blah++){
160 
161  if (detL == blah->id()){
162  EBDataFrame myDigi = (*blah);
163  SEBDigiCol->push_back(detL);
164  //SEBDigiCol->push_back(detL, myDigi);
165  EBDataFrame df( SEBDigiCol->back());
166  for (int iq =0;iq<myDigi.size();++iq){
167  df.setSample(iq, myDigi.sample(iq).raw());
168  }
169  //ebcounter++;
170  }
171  }
172  //if (ebcounter >= int(saveTheseDetIds.size())) break;
173  }//loop over dets
174 
175 
176  // std::cout << "size of new digi container contents: " << SEBDigiCol->size() << std::endl;
177 
178  }
179 
180  }//If barrel superclusters need saving.
181 
182 
183  if (saveEndcapSuperClusters.size() > 0){
184  //Get endcap rec hit collection
185  //get endcap digi collection
187  const EEDigiCollection* digis=0;
188  evt.getByLabel(EcalEEDigiTag_,pdigis);
189  if (!pdigis.isValid()){
190  edm::LogError("EcalDigiSelector")
191  << "can't get collection with label " << EcalEEDigiTag_ ;
192  } else {
193  digis = pdigis.product(); // get a ptr to the product
194  }
195  if ( digis ) {
196  //std::vector<DetId> saveTheseDetIds;
197  std::set<DetId> saveTheseDetIds;
198  //pick out the digis for the 3x3 in each of the selected superclusters
199  for (int loop = 0;loop < int(saveEndcapSuperClusters.size());loop++){
200  SuperCluster clus1 = saveEndcapSuperClusters[loop];
201  CaloClusterPtr bcref = clus1.seed();
202  const BasicCluster *bc = bcref.get();
203  //Get the maximum detid
204  std::pair<DetId, float> EDetty = tooly.getMaximum(*bc);
205  //get the 3x3 array centered on maximum detid.
206  std::vector<DetId> detvec = tooly.matrixDetId(EDetty.first, -1, 1, -1, 1);
207  //Loop over the 3x3
208  for (int ik = 0;ik<int(detvec.size());++ik)
209  //saveTheseDetIds.push_back(detvec[ik]);
210  saveTheseDetIds.insert(detvec[ik]);
211  }
212  int eecounter=0;
213  for (EEDigiCollection::const_iterator blah = digis->begin();
214  blah!=digis->end();blah++){
215  std::set<DetId>::const_iterator finder = saveTheseDetIds.find(blah->id());
216  if (finder!=saveTheseDetIds.end()){
217  EEDetId detL = EEDetId(*finder);
218 
219  if (detL == blah->id()){
220  EEDataFrame myDigi = (*blah);
221  SEEDigiCol->push_back(detL);
222  EEDataFrame df( SEEDigiCol->back());
223  for (int iq =0;iq<myDigi.size();++iq){
224  df.setSample(iq, myDigi.sample(iq).raw());
225  }
226  eecounter++;
227 
228  }
229  }
230  if (eecounter >= int(saveTheseDetIds.size())) break;
231  }//loop over digis
232  // std::cout << "Current new digi container contents: " << SEEDigiCol->size() << std::endl;
233  }
234  }//If endcap superclusters need saving.
235 
236  }//If we're actually saving stuff
237 
238  //Okay, either my collections have been filled with the requisite Digis, or they haven't.
239 
240  //std::cout << "Saving: " << SEBDigiCol->size() << " barrel digis and " << SEEDigiCol->size() << " endcap digis." << std::endl;
241 
242  //Empty collection, or full, still put in event.
243  SEBDigiCol->sort();
244  SEEDigiCol->sort();
245  evt.put(SEBDigiCol, selectedEcalEBDigiCollection_);
246  evt.put(SEEDigiCol, selectedEcalEEDigiCollection_);
247 
248 }
T getParameter(std::string const &) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:30
const_iterator begin() const
uint16_t raw() const
get the raw word
int size() const
Definition: EcalDataFrame.h:27
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:160
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
EcalDigiSelector(const edm::ParameterSet &ps)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
double energy() const
cluster energy
Definition: CaloCluster.h:120
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void produce(edm::Event &, const edm::EventSetup &)
std::pair< DetId, float > getMaximum(const reco::BasicCluster &cluster)
T const * product() const
Definition: Handle.h:74
const_iterator end() const
virtual ~EcalDigiSelector()
void setSample(int i, EcalMGPASample sam)
Definition: EcalDataFrame.h:44
std::vector< DetId > matrixDetId(DetId id, int ixMin, int ixMax, int iyMin, int iyMax)
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:62