CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // system include
21 #include <memory>
22 #include <vector>
23 #include <iostream>
24 #include <TMath.h>
25 #include <TRandom3.h>
26 
27 // 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&);
55 
56  private:
57  virtual void produce(edm::Event&, const edm::EventSetup&) override;
58  virtual void ComputeTowerVariable(const edm::RefVector<edm::SortedCollection<CastorRecHit> >& usedRecHits, double& Ehot, double& depth);
59 
60  // member data
62  typedef ROOT::Math::RhoEtaPhiPoint TowerPoint;
63  typedef ROOT::Math::RhoZPhiPoint CellPoint;
65  typedef std::vector<reco::CastorTower> CastorTowerCollection;
68  double towercut_;
69  double mintime_;
70  double maxtime_;
71 };
72 
73 //
74 // constants, enums and typedefs
75 //
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 {
91  tok_input_ = consumes<CastorRecHitCollection>(iConfig.getParameter<std::string>("inputprocess"));
92  //register your products
93  produces<CastorTowerCollection>();
94  //now do what ever other initialization is needed
95 }
96 
97 
99 {
100  // do anything here that needs to be done at desctruction time
101  // (e.g. close files, deallocate resources etc.)
102 }
103 
104 
105 //
106 // member functions
107 //
108 
109 // ------------ method called to produce the data ------------
111 
112  using namespace edm;
113  using namespace reco;
114  using namespace TMath;
115 
116  // Produce CastorTowers from CastorCells
117 
119  iEvent.getByToken(tok_input_,InputRecHits);
120 
121  std::auto_ptr<CastorTowerCollection> OutputTowers (new CastorTowerCollection);
122 
123  // get and check input size
124  int nRecHits = InputRecHits->size();
125 
126  LogDebug("CastorTowerProducer")
127  <<"2. entering CastorTowerProducer"<<std::endl;
128 
129  if (nRecHits==0)
130  LogDebug("CastorTowerProducer") <<"Warning: You are trying to run the Tower algorithm with 0 input rechits.";
131 
132  // declare castor array
133  // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position
134 
135  double poscastortowerarray[4][16];
136  double negcastortowerarray[4][16];
137 
138  CastorRecHitRefVector poscastorusedrechits[16];
139  CastorRecHitRefVector negcastorusedrechits[16];
140 
141  // set phi values and everything else to zero
142  for (int j = 0; j < 16; j++) {
143  poscastortowerarray[3][j] = -2.94524 + j*0.3927;
144  poscastortowerarray[0][j] = 0.;
145  poscastortowerarray[1][j] = 0.;
146  poscastortowerarray[2][j] = 0.;
147 
148  negcastortowerarray[3][j] = -2.94524 + j*0.3927;
149  negcastortowerarray[0][j] = 0.;
150  negcastortowerarray[1][j] = 0.;
151  negcastortowerarray[2][j] = 0.;
152  }
153 
154  // retrieve the channel quality lists from database
156  iSetup.get<CastorChannelQualityRcd>().get(p);
157  std::vector<DetId> channels = p->getAllChannels();
158 
159  // loop over rechits to build castortowerarray[4][16] and castorusedrechits[16]
160  for (unsigned int i = 0; i < InputRecHits->size(); i++) {
161 
163 
164  HcalCastorDetId id = rechit_p->id();
165  DetId genericID=(DetId)id;
166 
167  // first check if the rechit is in the BAD channel list
168  bool bad = false;
169  for (std::vector<DetId>::iterator channel = channels.begin();channel != channels.end();channel++) {
170  if (channel->rawId() == genericID.rawId()) {
171  // if the rechit is found in the list, set it bad
172  bad = true; break;
173  }
174  }
175  // if bad, continue the loop to the next rechit
176  if (bad) continue;
177 
178  double Erechit = rechit_p->energy();
179  int module = id.module();
180  int sector = id.sector();
181  double zrechit = 0;
182  if (module < 3) zrechit = -14390 - 24.75 - 49.5*(module-1);
183  if (module > 2) zrechit = -14390 - 99 - 49.5 - 99*(module-3);
184  double phirechit = -100;
185  if (sector < 9) phirechit = 0.19635 + (sector-1)*0.3927;
186  if (sector > 8) phirechit = -2.94524 + (sector - 9)*0.3927;
187 
188  // add time conditions for the rechit
189  if (rechit_p->time() > mintime_ && rechit_p->time() < maxtime_) {
190 
191  // loop over the 16 towers possibilities
192  for ( int j=0;j<16;j++) {
193 
194  // phi matching condition
195  if (TMath::Abs(phirechit - poscastortowerarray[3][j]) < 0.0001) {
196 
197  // condition over rechit z value
198  if (zrechit > 0.) {
199  poscastortowerarray[0][j]+=Erechit;
200  if (module < 3) {poscastortowerarray[1][j]+=Erechit;} else {poscastortowerarray[2][j]+=Erechit;}
201  poscastorusedrechits[j].push_back(rechit_p);
202  } else {
203  negcastortowerarray[0][j]+=Erechit;
204  if (module < 3) {negcastortowerarray[1][j]+=Erechit;} else {negcastortowerarray[2][j]+=Erechit;}
205  negcastorusedrechits[j].push_back(rechit_p);
206  } // end condition over rechit z value
207  } // end phi matching condition
208  } // end loop over the 16 towers possibilities
209  } // end time conditions
210 
211  } // end loop over rechits to build castortowerarray[4][16] and castorusedrechits[16]
212 
213  // make towers of the arrays
214 
215  double fem, Ehot, depth;
216  double rhoTower = 88.5;
217 
218  // loop over the 16 towers possibilities
219  for (int k=0;k<16;k++) {
220 
221  fem = 0;
222  Ehot = 0;
223  depth = 0;
224 
225  // select the positive towers with E > sqrt(Nusedrechits)*Ecut
226  if (poscastortowerarray[0][k] > sqrt(poscastorusedrechits[k].size())*towercut_) {
227 
228  fem = poscastortowerarray[1][k]/poscastortowerarray[0][k];
229  CastorRecHitRefVector usedRecHits = poscastorusedrechits[k];
230  ComputeTowerVariable(usedRecHits,Ehot,depth);
231 
232  LogDebug("CastorTowerProducer")
233  <<"tower "<<k+1<<": fem = "<<fem<<" ,depth = "<<depth<<" ,Ehot = "<<Ehot<<std::endl;
234 
235  TowerPoint temptowerposition(rhoTower,5.9,poscastortowerarray[3][k]);
236  Point towerposition(temptowerposition);
237 
238  CastorTower newtower(poscastortowerarray[0][k],towerposition,poscastortowerarray[1][k],poscastortowerarray[2][k],fem,depth,Ehot,
239  poscastorusedrechits[k]);
240  OutputTowers->push_back(newtower);
241  } // end select the positive towers with E > Ecut
242 
243  // select the negative towers with E > sqrt(Nusedrechits)*Ecut
244  if (negcastortowerarray[0][k] > sqrt(negcastorusedrechits[k].size())*towercut_) {
245 
246  fem = negcastortowerarray[1][k]/negcastortowerarray[0][k];
247  CastorRecHitRefVector usedRecHits = negcastorusedrechits[k];
248  ComputeTowerVariable(usedRecHits,Ehot,depth);
249 
250  LogDebug("CastorTowerProducer")
251  <<"tower "<<k+1 << " energy = " << negcastortowerarray[0][k] << "EM = " << negcastortowerarray[1][k] << "HAD = " << negcastortowerarray[2][k] << "phi = " << negcastortowerarray[3][k] << ": fem = "<<fem<<" ,depth = "<<depth<<" ,Ehot = "<<Ehot<<std::endl;
252 
253  TowerPoint temptowerposition(rhoTower,-5.9,negcastortowerarray[3][k]);
254  Point towerposition(temptowerposition);
255 
256  CastorTower newtower(negcastortowerarray[0][k],towerposition,negcastortowerarray[1][k],negcastortowerarray[2][k],fem,depth,Ehot,
257  negcastorusedrechits[k]);
258  OutputTowers->push_back(newtower);
259  } // end select the negative towers with E > Ecut
260 
261  } // end loop over the 16 towers possibilities
262 
263  iEvent.put(OutputTowers);
264 }
265 
266 
268 
269  using namespace reco;
270 
271  double Etot = 0;
272 
273  // loop over the cells used in the tower k
274  for (CastorRecHitRefVector::iterator it = usedRecHits.begin(); it != usedRecHits.end(); it++) {
275  edm::Ref<CastorRecHitCollection> rechit_p = *it;
276 
277  double Erechit = rechit_p->energy();
278  HcalCastorDetId id = rechit_p->id();
279  int module = id.module();
280  double zrechit = 0;
281  if (module < 3) zrechit = -14390 - 24.75 - 49.5*(module-1);
282  if (module > 2) zrechit = -14390 - 99 - 49.5 - 99*(module-3);
283 
284  if(Erechit > Ehot) Ehot = Erechit;
285  depth+=Erechit*zrechit;
286  Etot+=Erechit;
287  }
288 
289  depth/=Etot;
290  Ehot/=Etot;
291 }
292 
293 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::SortedCollection< CastorRecHit > CastorRecHitCollection
ROOT::Math::RhoZPhiPoint CellPoint
module()
Definition: vlib.cc:994
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< reco::CastorTower > CastorTowerCollection
ROOT::Math::RhoEtaPhiPoint TowerPoint
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
int bad(Items const &cont)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
T sqrt(T t)
Definition: SSEVec.h:48
edm::RefVector< CastorRecHitCollection > CastorRecHitRefVector
T Abs(T a)
Definition: MathUtil.h:49
int j
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &, const edm::EventSetup &) override
Definition: DetId.h:18
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)
const T & get() const
Definition: EventSetup.h:56
Definition: vlib.h:208
tuple size
Write out results.