CMS 3D CMS Logo

RecHitCorrector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecHitCorrector
4 // Class: RecHitCorrector
5 //
13 //
14 // Original Author: Hans Van Haevermaet
15 // Created: Wed Feb 23 11:29:43 CET 2011
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
31 
33 
42 
43 //
44 // class declaration
45 //
46 
48  public:
49  explicit RecHitCorrector(const edm::ParameterSet&);
50  ~RecHitCorrector() override;
51 
52  private:
53  void produce(edm::Event&, const edm::EventSetup&) override;
54 
55  // ----------member data ---------------------------
57  double factor_;
59 };
60 
61 //
62 // constants, enums and typedefs
63 //
64 
65 
66 //
67 // static data member definitions
68 //
69 
70 //
71 // constructors and destructor
72 //
74 factor_(iConfig.getParameter<double>("revertFactor")),
75 doInterCalib_(iConfig.getParameter<bool>("doInterCalib"))
76 {
77  tok_input_ = consumes<CastorRecHitCollection>(iConfig.getParameter<edm::InputTag>("rechitLabel"));
78  //register your products
79  produces<CastorRecHitCollection>();
80  //now do what ever other initialization is needed
81 }
82 
83 
85 {
86 
87  // do anything here that needs to be done at desctruction time
88  // (e.g. close files, deallocate resources etc.)
89 
90 }
91 
92 
93 //
94 // member functions
95 //
96 
97 // ------------ method called to produce the data ------------
98 void
100 {
101  using namespace edm;
102 
103  // get original rechits
105  iEvent.getByToken(tok_input_,rechits);
106 
107  // get conditions
109  iSetup.get<CastorDbRecord>().get(conditions);
110 
112  iSetup.get<CastorChannelQualityRcd>().get(p);
114 
115  if (!rechits.isValid()) edm::LogWarning("CastorRecHitCorrector") << "No valid CastorRecHitCollection found, please check the InputLabel...";
116 
118 
119  auto rec = std::make_unique<CastorRecHitCollection>();
120 
121  for (unsigned int i=0;i<rechits->size();i++) {
122  CastorRecHit rechit = (*rechits)[i];
123  double time = rechit.time();
124  double correctedenergy = factor_*rechit.energy();
125 
126  if (doInterCalib_) {
127  // do proper gain calibration reading the latest entries in the condDB
128  const CastorCalibrations& calibrations=conditions->getCastorCalibrations(rechit.id());
129  int capid = 0; // take some capid, gains are the same for all capid's
130  correctedenergy *= calibrations.gain(capid);
131  }
132 
133  // now check the channelquality of this rechit
134  bool ok = true;
135  DetId detcell=(DetId)rechit.id();
136  std::vector<DetId> channels = myqual->getAllChannels();
137  for (auto channel : channels) {
138  if (channel.rawId() == detcell.rawId()) {
139  const CastorChannelStatus* mydigistatus=myqual->getValues(channel);
140  if (mydigistatus->getValue() == 2989) {
141  ok = false; // 2989 = BAD
142  break;
143  }
144  }
145  }
146 
147  if (ok) {
148  rec->emplace_back(rechit.id(),correctedenergy,time);
149  }
150  }
151 
152  iEvent.put(std::move(rec));
153 
154  delete myqual;
155 
156 }
157 
158 
159 //define this as a plug-in
constexpr float energy() const
Definition: CaloRecHit.h:31
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::EDGetTokenT< CastorRecHitCollection > tok_input_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void produce(edm::Event &, const edm::EventSetup &) override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< DetId > getAllChannels() const
const CastorCalibrations & getCastorCalibrations(const HcalGenericDetId &fId) const
~RecHitCorrector() override
const Item * getValues(DetId fId, bool throwOnFail=true) const
HcalCastorDetId id() const
get the id
Definition: CastorRecHit.h:15
RecHitCorrector(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
uint32_t getValue() const
constexpr float time() const
Definition: CaloRecHit.h:33
bool isValid() const
Definition: HandleBase.h:74
Definition: DetId.h:18
double gain(int fCapId) const
get gain for capid=0..3
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:71
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511