CMS 3D CMS Logo

EcalMIPRecHitFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalMIPRecHitFilter
4 // Class: EcalMIPRecHitFilter
5 //
13 //
14 // Original Author: Giovanni FRANZONI
15 // Created: Wed Sep 19 16:21:29 CEST 2007
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <vector>
22 
23 // user include files
28 
32 
34 
38 
42 
47 
50 
51 //
52 // class declaration
53 //
54 
56 public:
57  explicit EcalMIPRecHitFilter(const edm::ParameterSet&);
58  ~EcalMIPRecHitFilter() override;
59 
60  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
61 
62 private:
63  bool filter(edm::Event &, edm::EventSetup const &) override;
64 
65  // ----------member data ---------------------------
67  const double minAmp1_;
68  const double minAmp2_;
69  const double minSingleAmp_;
70  const std::vector<int> maskedList_;
71  const int side_;
72 
73 };
74 
75 //
76 // constructors and destructor
77 //
79  EcalRecHitToken_( consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EcalRecHitCollection")) ),
80  minAmp1_( iConfig.getUntrackedParameter<double>("AmpMinSeed", 0.063) ),
81  minAmp2_( iConfig.getUntrackedParameter<double>("AmpMin2", 0.045) ),
82  minSingleAmp_( iConfig.getUntrackedParameter<double>("SingleAmpMin", 0.108) ),
83  maskedList_( iConfig.getUntrackedParameter<std::vector<int>>("maskedChannels", std::vector<int>{}) ), // this is using the ashed index
84  side_( iConfig.getUntrackedParameter<int>("side", 3) )
85 {
86  // now do what ever initialization is needed
87 }
88 
89 
91 {
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 }
95 
96 
97 //
98 // member functions
99 //
100 
101 // ------------ method called on each new Event ------------
102 bool
104 {
105  using namespace edm;
106 
107  // getting very basic uncalRH
109  if (not iEvent.getByToken(EcalRecHitToken_, recHits))
110  {
113  LogWarning("EcalMIPRecHitFilter") << "InputTag: label = \"" << labels.module << "\", instance = \"" << labels.productInstance << "\", process = \"" << labels.process << "\" is not available";
114  return false;
115  }
116 
118  iSetup.get<CaloTopologyRecord>().get(caloTopo);
119 
120  // Intercalib constants
122  iSetup.get<EcalIntercalibConstantsRcd>().get(pIcal);
123  const EcalIntercalibConstants* ical = pIcal.product();
124  const EcalIntercalibConstantMap& icalMap=ical->getMap();
125 
127  iSetup.get<EcalLaserDbRecord>().get( pLaser );
128 
130  iSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
131  const EcalADCToGeVConstant* agc = pAgc.product();
132  //std::cout << "Global EB ADC->GeV scale: " << agc->getEBValue() << " GeV/ADC count" ;
133  float adcconst = agc->getEBValue();
134 
135  bool thereIsSignal = false;
136  // loop on rechits
137  for ( auto hitItr = recHits->begin(); hitItr != recHits->end(); ++hitItr ) {
138 
139  EcalRecHit const & hit = *hitItr;
140 
141  // masking noisy channels //KEEP this for now, just in case a few show up
142  auto result = std::find( maskedList_.begin(), maskedList_.end(), EBDetId(hit.id()).hashedIndex() );
143  if (result != maskedList_.end())
144  // LogWarning("EcalFilter") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli_ ;
145  continue;
146 
147  float ampli_ = hit.energy();
148  EBDetId ebDet = hit.id();
149 
150  // find intercalib constant for this xtal
151  auto icalit=icalMap.find(ebDet);
152  EcalIntercalibConstant icalconst = 1.;
153  if( icalit!=icalMap.end() ){
154  icalconst = (*icalit);
155  //LogDebug("EcalRecHitDebug") << "Found intercalib for xtal " << EBDetId(it->id()).ic() << " " << icalconst ;
156  } else {
157  //edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(ebDet) << "! something wrong with EcalIntercalibConstants in your DB? " ;
158  }
159  float lasercalib = pLaser->getLaserCorrection( EBDetId(ebDet), iEvent.time() );
160 
161  ampli_ /= (icalconst * lasercalib * adcconst);
162  // seeking channels with signal and displaced jitter
163  if (ampli_ >= minSingleAmp_ )
164  {
165  //std::cout << " THIS AMPLITUDE WORKS " << ampli_ << std::endl;
166  thereIsSignal = true;
167  // LogWarning("EcalFilter") << "at evet: " << iEvent.id().event()
168  // << " and run: " << iEvent.id().run()
169  // << " there is OUT OF TIME signal at chanel: " << ic
170  // << " with amplitude " << ampli_ << " and max at: " << jitter_;
171  break;
172  }
173 
174  //Check for more robust selection other than just single crystal cosmics
175  if (ampli_ >= minAmp1_)
176  {
177  //std::cout << " THIS AMPLITUDE WORKS " << ampli_ << std::endl;
178  std::vector<DetId> neighbors = caloTopo->getWindow(ebDet,side_,side_);
179  float secondMin = 0.;
180  for(std::vector<DetId>::const_iterator detitr = neighbors.begin(); detitr != neighbors.end(); ++detitr)
181  {
182  auto thishit = recHits->find((*detitr));
183  if (thishit == recHits->end())
184  {
185  //LogWarning("EcalMIPRecHitFilter") << "No RecHit available, for "<< EBDetId(*detitr);
186  continue;
187  }
188  if ((*thishit).id() != ebDet)
189  {
190  float thisamp = (*thishit).energy();
191  // find intercalib constant for this xtal
192  auto icalit2=icalMap.find((*thishit).id());
193  EcalIntercalibConstant icalconst2 = 1.;
194  if( icalit2!=icalMap.end() ){
195  icalconst2 = (*icalit2);
196  // LogDebug("EcalRecHitDebug") << "Found intercalib for xtal " << EBDetId(it->id()).ic() << " " << icalconst ;
197  } else {
198  //edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(ebDet) << "! something wrong with EcalIntercalibConstants in your DB? " ;
199  }
200  float lasercalib2 = pLaser->getLaserCorrection( EBDetId((*thishit).id()), iEvent.time() );
201  thisamp /= (icalconst2 * lasercalib2 * adcconst);
202  if (thisamp > secondMin) secondMin = thisamp;
203  }
204  }
205 
206  if (secondMin > minAmp2_ )
207  {
208  thereIsSignal = true;
209  break;
210  }
211  }
212  }
213  //std::cout << " Ok is There one of THEM " << thereIsSignal << std::endl;
214  return thereIsSignal;
215 }
216 
219 
220  desc.add<edm::InputTag>("EcalRecHitCollection", edm::InputTag("ecalRecHit","EcalRecHitsEB"));
221  desc.addUntracked<double>("AmpMinSeed", 0.045);
222  desc.addUntracked<double>("AmpMin2", 0.045);
223  desc.addUntracked<double>("SingleAmpMin", 0.108);
224  desc.addUntracked<std::vector<int>>("maskedChannels", std::vector<int>{});
225  desc.addUntracked<int>("side", 3);
226 
227  descriptions.add("ecalMIPRecHitFilter", desc);
228 }
229 
230 
231 // declare this class as a framework plugin
bool filter(edm::Event &, edm::EventSetup const &) override
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
EcalMIPRecHitFilter(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const self & getMap() const
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const edm::EDGetTokenT< EcalRecHitCollection > EcalRecHitToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
char const * process
Definition: ProductLabels.h:7
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:42
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
Get the neighbors of the given cell in a window of given size.
Definition: CaloTopology.cc:67
float energy() const
Definition: EcalRecHit.h:68
const std::vector< int > maskedList_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
char const * module
Definition: ProductLabels.h:5
const_iterator end() const
DetId id() const
get the id
Definition: EcalRecHit.h:77
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
char const * productInstance
Definition: ProductLabels.h:6
iterator find(key_type k)
HLT enums.
T get() const
Definition: EventSetup.h:71
const_iterator find(uint32_t rawId) const
const_iterator end() const
T const * product() const
Definition: ESHandle.h:86
edm::Timestamp time() const
Definition: EventBase.h:60
const_iterator begin() const
float EcalIntercalibConstant