CMS 3D CMS Logo

EcalDigiSelector.cc
Go to the documentation of this file.
1 #include <vector>
17 #include <TMath.h>
18 #include <iostream>
19 #include <set>
20 
21 
22 using namespace reco;
24 {
25  selectedEcalEBDigiCollection_ = ps.getParameter<std::string>("selectedEcalEBDigiCollection");
26  selectedEcalEEDigiCollection_ = ps.getParameter<std::string>("selectedEcalEEDigiCollection");
27 
28  barrelSuperClusterProducer_ =
29  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("barrelSuperClusterProducer"));
30  endcapSuperClusterProducer_ =
31  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSuperClusterProducer"));
32 
33 
34  EcalEBRecHitToken_ =
35  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalEBRecHitTag"));
36  EcalEERecHitToken_ =
37  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalEERecHitTag"));
38 
39  EcalEBDigiToken_ =
40  consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EcalEBDigiTag"));
41  EcalEEDigiToken_ =
42  consumes<EEDigiCollection>(ps.getParameter<edm::InputTag>("EcalEEDigiTag"));
43 
44  cluster_pt_thresh_ = ps.getParameter<double>("cluster_pt_thresh");
45  single_cluster_thresh_ = ps.getParameter<double>("single_cluster_thresh");
46 
47  nclus_sel_ = ps.getParameter<int>("nclus_sel");
48  produces<EBDigiCollection>(selectedEcalEBDigiCollection_);
49  produces<EEDigiCollection>(selectedEcalEEDigiCollection_);
50 
51 }
52 
54 {
55 
56  //Get BarrelSuperClusters to start.
57  edm::Handle<reco::SuperClusterCollection> pBarrelSuperClusters;
58 
59  evt.getByToken(barrelSuperClusterProducer_, pBarrelSuperClusters);
60 
61  const reco::SuperClusterCollection & BarrelSuperClusters = *pBarrelSuperClusters;
62  //Got BarrelSuperClusters
63 
64  //Get BarrelSuperClusters to start.
65  edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
66 
67  evt.getByToken(endcapSuperClusterProducer_, pEndcapSuperClusters);
68 
69  const reco::SuperClusterCollection & EndcapSuperClusters = *pEndcapSuperClusters;
70  //Got EndcapSuperClusters
71 
72  reco::SuperClusterCollection saveBarrelSuperClusters;
73  reco::SuperClusterCollection saveEndcapSuperClusters;
74  bool meet_single_thresh = false;
75  //Loop over barrel superclusters, and apply threshold
76  for (int loop=0;loop<int(BarrelSuperClusters.size());loop++){
77  SuperCluster clus1 = BarrelSuperClusters[loop];
78  float eta1 = clus1.eta();
79  float energy1 = clus1.energy();
80  float theta1 = 2*atan(exp(-1.*eta1));
81  float cluspt1 = energy1 * sin(theta1);
82  if (cluspt1 > cluster_pt_thresh_){
83  saveBarrelSuperClusters.push_back(clus1);
84  if (cluspt1 > single_cluster_thresh_)
85  meet_single_thresh = true;
86 
87  }
88  }
89 
90  //Loop over endcap superclusters, and apply threshold
91  for (int loop=0;loop<int(EndcapSuperClusters.size());loop++){
92  SuperCluster clus1 = EndcapSuperClusters[loop];
93  float eta1 = clus1.eta();
94  float energy1 = clus1.energy();
95  float theta1 = 2*atan(exp(-1.*eta1));
96  float cluspt1 = energy1 * sin(theta1);
97  if (cluspt1 > cluster_pt_thresh_){
98  saveEndcapSuperClusters.push_back(clus1);
99  if (cluspt1 > single_cluster_thresh_)
100  meet_single_thresh = true;
101  }
102  }
103 
104  auto SEBDigiCol = std::make_unique<EBDigiCollection>();
105  auto SEEDigiCol = std::make_unique<EEDigiCollection>();
106  int TotClus = saveBarrelSuperClusters.size() + saveEndcapSuperClusters.size();
107 
108  if (TotClus >= nclus_sel_ || meet_single_thresh){
109 
110  if (!saveBarrelSuperClusters.empty()){
111 
112 
113  edm::ESHandle<CaloTopology> pTopology;
114  es.get<CaloTopologyRecord>().get(pTopology);
115  const CaloTopology *topology = pTopology.product();
116 
117  //get barrel digi collection
119  const EBDigiCollection* digis=nullptr;
120  evt.getByToken(EcalEBDigiToken_,pdigis);
121  digis = pdigis.product(); // get a ptr to the product
122 
124  const EcalRecHitCollection* rechits=nullptr;
125  evt.getByToken(EcalEBRecHitToken_,prechits);
126  rechits = prechits.product(); // get a ptr to the product
127 
128 
129  if ( digis ) {
130  std::vector<DetId> saveTheseDetIds;
131  //pick out the detids for the 3x3 in each of the selected superclusters
132  for (int loop = 0;loop < int(saveBarrelSuperClusters.size());loop++){
133  SuperCluster clus1 = saveBarrelSuperClusters[loop];
134  const CaloClusterPtr& bcref = clus1.seed();
135  const BasicCluster *bc = bcref.get();
136  //Get the maximum detid
137  DetId maxDetId = EcalClusterTools::getMaximum(*bc,rechits).first;
138  // Loop over the 3x3 array centered on maximum detid
139  for(DetId detId : CaloRectangleRange(1, maxDetId, *topology)) saveTheseDetIds.push_back(detId);
140 
141  }
142  for (int detloop=0; detloop < int(saveTheseDetIds.size());++detloop){
143  EBDetId detL = EBDetId(saveTheseDetIds[detloop]);
144 
145  for (EBDigiCollection::const_iterator blah = digis->begin();
146  blah!=digis->end();blah++){
147 
148  if (detL == blah->id()){
149  EBDataFrame myDigi = (*blah);
150  SEBDigiCol->push_back(detL);
151 
152  EBDataFrame df( SEBDigiCol->back());
153  for (int iq =0;iq<myDigi.size();++iq){
154  df.setSample(iq, myDigi.sample(iq).raw());
155  }
156  //ebcounter++;
157  }
158  }
159  //if (ebcounter >= int(saveTheseDetIds.size())) break;
160  }//loop over dets
161 
162  }
163 
164  }//If barrel superclusters need saving.
165 
166 
167  if (!saveEndcapSuperClusters.empty()){
168 
169  edm::ESHandle<CaloTopology> pTopology;
170  es.get<CaloTopologyRecord>().get(pTopology);
171  const CaloTopology *topology = pTopology.product();
172 
173  //Get endcap rec hit collection
174  //get endcap digi collection
176  const EEDigiCollection* digis=nullptr;
177  evt.getByToken(EcalEEDigiToken_,pdigis);
178  digis = pdigis.product(); // get a ptr to the product
179 
181  const EcalRecHitCollection* rechits=nullptr;
182  evt.getByToken(EcalEERecHitToken_,prechits);
183  rechits = prechits.product(); // get a ptr to the product
184 
185  if ( digis ) {
186  //std::vector<DetId> saveTheseDetIds;
187  std::set<DetId> saveTheseDetIds;
188  //pick out the digis for the 3x3 in each of the selected superclusters
189  for (int loop = 0;loop < int(saveEndcapSuperClusters.size());loop++){
190  SuperCluster clus1 = saveEndcapSuperClusters[loop];
191  const CaloClusterPtr& bcref = clus1.seed();
192  const BasicCluster *bc = bcref.get();
193  //Get the maximum detid
194  DetId maxDetId = EcalClusterTools::getMaximum(*bc,rechits).first;
195  // Loop over the 3x3 array centered on maximum detid
196  for(DetId detId : CaloRectangleRange(1, maxDetId, *topology)) saveTheseDetIds.insert(detId);
197  }
198  int eecounter=0;
199  for (EEDigiCollection::const_iterator blah = digis->begin();
200  blah!=digis->end();blah++){
201  std::set<DetId>::const_iterator finder = saveTheseDetIds.find(blah->id());
202  if (finder!=saveTheseDetIds.end()){
203  EEDetId detL = EEDetId(*finder);
204 
205  if (detL == blah->id()){
206  EEDataFrame myDigi = (*blah);
207  SEEDigiCol->push_back(detL);
208  EEDataFrame df( SEEDigiCol->back());
209  for (int iq =0;iq<myDigi.size();++iq){
210  df.setSample(iq, myDigi.sample(iq).raw());
211  }
212  eecounter++;
213 
214  }
215  }
216  if (eecounter >= int(saveTheseDetIds.size())) break;
217  }//loop over digis
218  }
219  }//If endcap superclusters need saving.
220 
221  }//If we're actually saving stuff
222 
223  //Okay, either my collections have been filled with the requisite Digis, or they haven't.
224 
225 
226  //Empty collection, or full, still put in event.
227  SEBDigiCol->sort();
228  SEEDigiCol->sort();
229  evt.put(std::move(SEBDigiCol), selectedEcalEBDigiCollection_);
230  evt.put(std::move(SEEDigiCol), selectedEcalEEDigiCollection_);
231 
232 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
const_iterator begin() const
uint16_t raw() const
get the raw word
int size() const
Definition: EcalDataFrame.h:26
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:168
EcalDigiSelector(const edm::ParameterSet &ps)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
double energy() const
cluster energy
Definition: CaloCluster.h:126
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:74
const_iterator end() const
fixed size matrix
void setSample(int i, EcalMGPASample sam)
Definition: EcalDataFrame.h:43
T get() const
Definition: EventSetup.h:71
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511