CMS 3D CMS Logo

CastorTowerProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Castor
4 // Class: CastorTowerProducer
5 //
6 
13 //
14 // Original Author: Hans Van Haevermaet, Benoit Roland
15 // Created: Wed Jul 9 14:00:40 CEST 2008
16 //
17 //
18 
19 // system include
20 #include <memory>
21 #include <vector>
22 #include <iostream>
23 #include <TMath.h>
24 #include <TRandom3.h>
25 
26 // user include
36 
37 // Castor Object include
41 
42 // Channel quality
46 
47 //
48 // class declaration
49 //
50 
52 public:
53  explicit CastorTowerProducer(const edm::ParameterSet&);
54  ~CastorTowerProducer() override;
55 
56 private:
57  void produce(edm::Event&, const edm::EventSetup&) override;
59  double& Ehot,
60  double& depth);
61 
62  // member data
64  typedef ROOT::Math::RhoEtaPhiPoint TowerPoint;
65  typedef ROOT::Math::RhoZPhiPoint CellPoint;
67  typedef std::vector<reco::CastorTower> CastorTowerCollection;
71  double towercut_;
72  double mintime_;
73  double maxtime_;
74 };
75 
76 //
77 // constants, enums and typedefs
78 //
79 
80 //
81 // static data member definitions
82 //
83 
84 //
85 // constructor and destructor
86 //
87 
89  : towercut_(iConfig.getParameter<double>("towercut")),
90  mintime_(iConfig.getParameter<double>("mintime")),
91  maxtime_(iConfig.getParameter<double>("maxtime")) {
92  tok_input_ = consumes<CastorRecHitCollection>(iConfig.getParameter<std::string>("inputprocess"));
93  tok_channelQuality_ = esConsumes<CastorChannelQuality, CastorChannelQualityRcd>();
94  //register your products
95  produces<CastorTowerCollection>();
96  //now do what ever other initialization is needed
97 }
98 
100  // do anything here that needs to be done at desctruction time
101  // (e.g. close files, deallocate resources etc.)
102 }
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to produce the data ------------
110  using namespace edm;
111  using namespace reco;
112  using namespace TMath;
113 
114  // Produce CastorTowers from CastorCells
115 
117  iEvent.getByToken(tok_input_, InputRecHits);
118 
119  auto OutputTowers = std::make_unique<CastorTowerCollection>();
120 
121  // get and check input size
122  int nRecHits = InputRecHits->size();
123 
124  LogDebug("CastorTowerProducer") << "2. entering CastorTowerProducer" << std::endl;
125 
126  if (nRecHits == 0)
127  LogDebug("CastorTowerProducer") << "Warning: You are trying to run the Tower algorithm with 0 input rechits.";
128 
129  // declare castor array
130  // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position
131 
132  double poscastortowerarray[4][16];
133  double negcastortowerarray[4][16];
134 
135  CastorRecHitRefVector poscastorusedrechits[16];
136  CastorRecHitRefVector negcastorusedrechits[16];
137 
138  // set phi values and everything else to zero
139  for (int j = 0; j < 16; j++) {
140  poscastortowerarray[3][j] = -2.94524 + j * 0.3927;
141  poscastortowerarray[0][j] = 0.;
142  poscastortowerarray[1][j] = 0.;
143  poscastortowerarray[2][j] = 0.;
144 
145  negcastortowerarray[3][j] = -2.94524 + j * 0.3927;
146  negcastortowerarray[0][j] = 0.;
147  negcastortowerarray[1][j] = 0.;
148  negcastortowerarray[2][j] = 0.;
149  }
150 
151  // retrieve the channel quality lists from database
153  std::vector<DetId> channels = p->getAllChannels();
154 
155  // loop over rechits to build castortowerarray[4][16] and castorusedrechits[16]
156  for (unsigned int i = 0; i < InputRecHits->size(); i++) {
158 
159  HcalCastorDetId id = rechit_p->id();
160  DetId genericID = (DetId)id;
161 
162  // first check if the rechit is in the BAD channel list
163  bool bad = false;
164  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); channel++) {
165  if (channel->rawId() == genericID.rawId()) {
166  // if the rechit is found in the list, set it bad
167  bad = true;
168  break;
169  }
170  }
171  // if bad, continue the loop to the next rechit
172  if (bad)
173  continue;
174 
175  double Erechit = rechit_p->energy();
176  int module = id.module();
177  int sector = id.sector();
178  double zrechit = 0;
179  if (module < 3)
180  zrechit = -14390 - 24.75 - 49.5 * (module - 1);
181  if (module > 2)
182  zrechit = -14390 - 99 - 49.5 - 99 * (module - 3);
183  double phirechit = -100;
184  if (sector < 9)
185  phirechit = 0.19635 + (sector - 1) * 0.3927;
186  if (sector > 8)
187  phirechit = -2.94524 + (sector - 9) * 0.3927;
188 
189  // add time conditions for the rechit
190  if (rechit_p->time() > mintime_ && rechit_p->time() < maxtime_) {
191  // loop over the 16 towers possibilities
192  for (int j = 0; j < 16; j++) {
193  // phi matching condition
194  if (TMath::Abs(phirechit - poscastortowerarray[3][j]) < 0.0001) {
195  // condition over rechit z value
196  if (zrechit > 0.) {
197  poscastortowerarray[0][j] += Erechit;
198  if (module < 3) {
199  poscastortowerarray[1][j] += Erechit;
200  } else {
201  poscastortowerarray[2][j] += Erechit;
202  }
203  poscastorusedrechits[j].push_back(rechit_p);
204  } else {
205  negcastortowerarray[0][j] += Erechit;
206  if (module < 3) {
207  negcastortowerarray[1][j] += Erechit;
208  } else {
209  negcastortowerarray[2][j] += Erechit;
210  }
211  negcastorusedrechits[j].push_back(rechit_p);
212  } // end condition over rechit z value
213  } // end phi matching condition
214  } // end loop over the 16 towers possibilities
215  } // end time conditions
216 
217  } // end loop over rechits to build castortowerarray[4][16] and castorusedrechits[16]
218 
219  // make towers of the arrays
220 
221  double fem, Ehot, depth;
222  double rhoTower = 88.5;
223 
224  // loop over the 16 towers possibilities
225  for (int k = 0; k < 16; k++) {
226  fem = 0;
227  Ehot = 0;
228  depth = 0;
229 
230  // select the positive towers with E > sqrt(Nusedrechits)*Ecut
231  if (poscastortowerarray[0][k] > sqrt(poscastorusedrechits[k].size()) * towercut_) {
232  fem = poscastortowerarray[1][k] / poscastortowerarray[0][k];
233  CastorRecHitRefVector usedRecHits = poscastorusedrechits[k];
234  ComputeTowerVariable(usedRecHits, Ehot, depth);
235 
236  LogDebug("CastorTowerProducer") << "tower " << k + 1 << ": fem = " << fem << " ,depth = " << depth
237  << " ,Ehot = " << Ehot << std::endl;
238 
239  TowerPoint temptowerposition(rhoTower, 5.9, poscastortowerarray[3][k]);
240  Point towerposition(temptowerposition);
241 
242  CastorTower newtower(poscastortowerarray[0][k],
243  towerposition,
244  poscastortowerarray[1][k],
245  poscastortowerarray[2][k],
246  fem,
247  depth,
248  Ehot,
249  poscastorusedrechits[k]);
250  OutputTowers->push_back(newtower);
251  } // end select the positive towers with E > Ecut
252 
253  // select the negative towers with E > sqrt(Nusedrechits)*Ecut
254  if (negcastortowerarray[0][k] > sqrt(negcastorusedrechits[k].size()) * towercut_) {
255  fem = negcastortowerarray[1][k] / negcastortowerarray[0][k];
256  CastorRecHitRefVector usedRecHits = negcastorusedrechits[k];
257  ComputeTowerVariable(usedRecHits, Ehot, depth);
258 
259  LogDebug("CastorTowerProducer") << "tower " << k + 1 << " energy = " << negcastortowerarray[0][k]
260  << "EM = " << negcastortowerarray[1][k] << "HAD = " << negcastortowerarray[2][k]
261  << "phi = " << negcastortowerarray[3][k] << ": fem = " << fem
262  << " ,depth = " << depth << " ,Ehot = " << Ehot << std::endl;
263 
264  TowerPoint temptowerposition(rhoTower, -5.9, negcastortowerarray[3][k]);
265  Point towerposition(temptowerposition);
266 
267  CastorTower newtower(negcastortowerarray[0][k],
268  towerposition,
269  negcastortowerarray[1][k],
270  negcastortowerarray[2][k],
271  fem,
272  depth,
273  Ehot,
274  negcastorusedrechits[k]);
275  OutputTowers->push_back(newtower);
276  } // end select the negative towers with E > Ecut
277 
278  } // end loop over the 16 towers possibilities
279 
280  iEvent.put(std::move(OutputTowers));
281 }
282 
284  double& Ehot,
285  double& depth) {
286  using namespace reco;
287 
288  double Etot = 0;
289 
290  // loop over the cells used in the tower k
291  for (CastorRecHitRefVector::iterator it = usedRecHits.begin(); it != usedRecHits.end(); it++) {
292  edm::Ref<CastorRecHitCollection> rechit_p = *it;
293 
294  double Erechit = rechit_p->energy();
295  HcalCastorDetId id = rechit_p->id();
296  int module = id.module();
297  double zrechit = 0;
298  if (module < 3)
299  zrechit = -14390 - 24.75 - 49.5 * (module - 1);
300  if (module > 2)
301  zrechit = -14390 - 99 - 49.5 - 99 * (module - 3);
302 
303  if (Erechit > Ehot)
304  Ehot = Erechit;
305  depth += Erechit * zrechit;
306  Etot += Erechit;
307  }
308 
309  depth /= Etot;
310  Ehot /= Etot;
311 }
312 
313 //define this as a plug-in
CastorTowerProducer::CastorRecHitRefVector
edm::RefVector< CastorRecHitCollection > CastorRecHitRefVector
Definition: CastorTowerProducer.cc:68
CastorChannelQualityRcd.h
CastorTowerProducer::ComputeTowerVariable
virtual void ComputeTowerVariable(const edm::RefVector< edm::SortedCollection< CastorRecHit > > &usedRecHits, double &Ehot, double &depth)
Definition: CastorTowerProducer.cc:283
mps_fire.i
i
Definition: mps_fire.py:428
CastorTower.h
ESHandle.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CastorTowerProducer::tok_channelQuality_
edm::ESGetToken< CastorChannelQuality, CastorChannelQualityRcd > tok_channelQuality_
Definition: CastorTowerProducer.cc:70
CastorTowerProducer::tok_input_
edm::EDGetTokenT< CastorRecHitCollection > tok_input_
Definition: CastorTowerProducer.cc:69
CastorTowerProducer::maxtime_
double maxtime_
Definition: CastorTowerProducer.cc:73
EDProducer.h
edm::SortedCollection
Definition: SortedCollection.h:49
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
edm::RefVector
Definition: EDProductfwd.h:27
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
CastorTowerProducer::towercut_
double towercut_
Definition: CastorTowerProducer.cc:71
edm::Ref
Definition: AssociativeIterator.h:58
DetId
Definition: DetId.h:17
MakerMacros.h
CastorTowerProducer::Point
math::XYZPointD Point
Definition: CastorTowerProducer.cc:63
CastorTowerProducer::CastorRecHitCollection
edm::SortedCollection< CastorRecHit > CastorRecHitCollection
Definition: CastorTowerProducer.cc:66
CastorChannelStatus.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Abs
T Abs(T a)
Definition: MathUtil.h:49
CastorTowerProducer::TowerPoint
ROOT::Math::RhoEtaPhiPoint TowerPoint
Definition: CastorTowerProducer.cc:64
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::ESHandle
Definition: DTSurvey.h:22
dqmdumpme.k
k
Definition: dqmdumpme.py:60
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalCastorDetId
Definition: HcalCastorDetId.h:23
Point
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
math::XYZPointD
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double > > XYZPointD
point in space with cartesian internal representation
Definition: Point3D.h:8
CastorTowerProducer::CastorTowerCollection
std::vector< reco::CastorTower > CastorTowerCollection
Definition: CastorTowerProducer.cc:67
CastorTowerProducer::CastorTowerProducer
CastorTowerProducer(const edm::ParameterSet &)
Definition: CastorTowerProducer.cc:88
CastorTowerProducer::mintime_
double mintime_
Definition: CastorTowerProducer.cc:72
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
edm::ESGetToken< CastorChannelQuality, CastorChannelQualityRcd >
CastorTowerProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CastorTowerProducer.cc:109
CastorTowerProducer::~CastorTowerProducer
~CastorTowerProducer() override
Definition: CastorTowerProducer.cc:99
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CastorTowerProducer::CellPoint
ROOT::Math::RhoZPhiPoint CellPoint
Definition: CastorTowerProducer.cc:65
Frameworkfwd.h
ewkTauDQM_cfi.channels
channels
Definition: ewkTauDQM_cfi.py:14
edm::RefVectorIterator
Definition: EDProductfwd.h:33
Point3D.h
EventSetup.h
reco::CastorTower
Definition: CastorTower.h:26
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CastorChannelQuality.h
CastorRecHit.h
ParameterSet.h
HcalCastorDetId.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
CastorTowerProducer
Definition: CastorTowerProducer.cc:51
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443