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