CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: RecHitCorrector.cc,v 1.3 2011/05/13 13:20:14 hvanhaev Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
32 
34 
43 
44 //
45 // class declaration
46 //
47 
49  public:
50  explicit RecHitCorrector(const edm::ParameterSet&);
52 
53  private:
54  virtual void beginJob() ;
55  virtual void produce(edm::Event&, const edm::EventSetup&);
56  virtual void endJob() ;
57 
58  // ----------member data ---------------------------
60  double factor_;
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77 inputLabel_(iConfig.getParameter<edm::InputTag>("rechitLabel")),
78 factor_(iConfig.getParameter<double>("revertFactor")),
79 doInterCalib_(iConfig.getParameter<bool>("doInterCalib"))
80 {
81  //register your products
82  produces<CastorRecHitCollection>();
83  //now do what ever other initialization is needed
84 }
85 
86 
88 {
89 
90  // do anything here that needs to be done at desctruction time
91  // (e.g. close files, deallocate resources etc.)
92 
93 }
94 
95 
96 //
97 // member functions
98 //
99 
100 // ------------ method called to produce the data ------------
101 void
103 {
104  using namespace edm;
105 
106  // get original rechits
109 
110  // get conditions
112  iSetup.get<CastorDbRecord>().get(conditions);
113 
115  iSetup.get<CastorChannelQualityRcd>().get(p);
116  CastorChannelQuality* myqual = new CastorChannelQuality(*p.product());
117 
118  if (!rechits.isValid()) std::cout << "No valid CastorRecHitCollection found, please check the InputLabel..." << std::endl;
119 
120  CastorCalibrations calibrations;
121 
122  std::auto_ptr<CastorRecHitCollection> rec(new CastorRecHitCollection);
123 
124  for (unsigned int i=0;i<rechits->size();i++) {
125  CastorRecHit rechit = (*rechits)[i];
126  //std::cout << "rechit energy = " << rechit.energy() << std::endl;
127  double fC = factor_*rechit.energy();
128  double time = rechit.time();
129  //std::cout << "rechit energy(fC) = " << fC << " time = " << time << std::endl;
130 
131  // do proper gain calibration reading the latest entries in the condDB
132  const CastorCalibrations& calibrations=conditions->getCastorCalibrations(rechit.id());
133  int capid = 0; // take some capid, gains are the same for all capid's
134 
135  double correctedenergy = 0;
136  if (doInterCalib_) {
137  if (rechit.id().module() <= 2) {
138  correctedenergy = 0.5*fC*calibrations.gain(capid);
139  //std::cout << " correctedenergy = " << correctedenergy << " gain = " << calibrations.gain(capid) << std::endl;
140  } else {
141  correctedenergy = fC*calibrations.gain(capid);
142  }
143  } else {
144  if (rechit.id().module() <= 2) {
145  correctedenergy = 0.5*fC;
146  } else {
147  correctedenergy = fC;
148  }
149  }
150 
151  // now check the channelquality of this rechit
152  bool ok = true;
153  DetId detcell=(DetId)rechit.id();
154  std::vector<DetId> channels = myqual->getAllChannels();
155  //std::cout << "number of specified quality flags = " << channels.size() << std::endl;
156  for (std::vector<DetId>::iterator channel = channels.begin();channel != channels.end();channel++) {
157  if (channel->rawId() == detcell.rawId()) {
158  const CastorChannelStatus* mydigistatus=myqual->getValues(*channel);
159  //std::cout << "CastorChannelStatus = " << mydigistatus->getValue() << std::endl;
160  if (mydigistatus->getValue() == 2989) ok = false; // 2989 = BAD
161  }
162  }
163 
164  if (ok) {
165  CastorRecHit *correctedhit = new CastorRecHit(rechit.id(),correctedenergy,time);
166  rec->push_back(*correctedhit);
167  }
168  }
169 
170  iEvent.put(rec);
171 
172 }
173 
174 // ------------ method called once each job just before starting event loop ------------
175 void
177 {
178 }
179 
180 // ------------ method called once each job just after ending the event loop ------------
181 void
183 }
184 
185 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int module() const
get the module (1-2 for EM, 1-12 for HAD)
float time() const
Definition: CaloRecHit.h:21
HcalCastorDetId id() const
get the id
Definition: CastorRecHit.h:15
RecHitCorrector(const edm::ParameterSet &)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
virtual void produce(edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:243
uint32_t getValue() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
float energy() const
Definition: CaloRecHit.h:19
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
Definition: DetId.h:20
double gain(int fCapId) const
get gain for capid=0..3
edm::InputTag inputLabel_
virtual void endJob()
const T & get() const
Definition: EventSetup.h:55
tuple cout
Definition: gather_cfg.py:121
struct factor_s factor_
virtual void beginJob()