CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorClusterProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Castor
4 // Class: CastorClusterProducer
5 //
12 //
13 // Original Author: Hans Van Haevermaet, Benoit Roland
14 // Created: Wed Jul 9 14:00:40 CEST 2008
15 // $Id: CastorClusterProducer.cc,v 1.10 2011/02/24 09:36:46 hvanhaev Exp $
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
33 
34 // Castor Object include
44 
45 
46 
47 //
48 // class decleration
49 //
50 
52  public:
55 
56  private:
57  virtual void beginJob() ;
58  virtual void produce(edm::Event&, const edm::EventSetup&);
59  double phiangle (double testphi);
60  virtual void endJob() ;
61 
62  // ----------member data ---------------------------
64  typedef ROOT::Math::RhoEtaPhiPoint TowerPoint;
65  typedef ROOT::Math::RhoZPhiPoint CellPoint;
66  typedef std::vector<reco::CastorTower> CastorTowerCollection;
67  typedef std::vector<reco::CastorCluster> CastorClusterCollection;
70 };
71 
72 //
73 // constants, enums and typedefs
74 //
75 
76 const double MYR2D = 180/M_PI;
77 
78 //
79 // static data member definitions
80 //
81 
82 //
83 // constructor and destructor
84 //
85 
87  input_(iConfig.getUntrackedParameter<std::string>("inputtowers","")),
88  basicjets_(iConfig.getUntrackedParameter<std::string>("basicjets","")),
89  clusteralgo_(iConfig.getUntrackedParameter<bool>("ClusterAlgo",false))
90 {
91  // register your products
92  produces<CastorClusterCollection>();
93  // now do what ever other initialization is needed
94 }
95 
96 
98 {
99  // do anything here that needs to be done at desctruction time
100  // (e.g. close files, deallocate resources etc.)
101 }
102 
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to produce the data ------------
110 
111  using namespace edm;
112  using namespace reco;
113  using namespace TMath;
114 
115  LogDebug("CastorClusterProducer")
116  <<"3. entering CastorClusterProducer";
117 
118  if ( input_ != "") {
119 
120  // Produce CastorClusters from CastorTowers
121 
123  iEvent.getByLabel(input_, InputTowers);
124 
125  std::auto_ptr<CastorClusterCollection> OutputClustersfromClusterAlgo (new CastorClusterCollection);
126 
127  // get and check input size
128  int nTowers = InputTowers->size();
129 
130  if (nTowers==0) LogDebug("CastorClusterProducer")<<"Warning: You are trying to run the Cluster algorithm with 0 input towers.";
131 
132  CastorTowerRefVector posInputTowers, negInputTowers;
133 
134  for (size_t i = 0; i < InputTowers->size(); ++i) {
135  reco::CastorTowerRef tower_p = reco::CastorTowerRef(InputTowers, i);
136  if (tower_p->eta() > 0.) posInputTowers.push_back(tower_p);
137  if (tower_p->eta() < 0.) negInputTowers.push_back(tower_p);
138  }
139 
140  // build cluster from ClusterAlgo
141  if (clusteralgo_ == true) {
142  // code
143  iEvent.put(OutputClustersfromClusterAlgo);
144  }
145 
146  }
147 
148  if ( basicjets_ != "") {
149 
150  Handle<BasicJetCollection> bjCollection;
151  iEvent.getByLabel(basicjets_,bjCollection);
152 
153  Handle<CastorTowerCollection> ctCollection;
154  iEvent.getByLabel("CastorTowerReco",ctCollection);
155 
156  std::auto_ptr<CastorClusterCollection> OutputClustersfromBasicJets (new CastorClusterCollection);
157 
158  if (bjCollection->size()==0) LogDebug("CastorClusterProducer")<< "Warning: You are trying to run the Cluster algorithm with 0 input basicjets.";
159 
160  for (unsigned i=0; i< bjCollection->size();i++) {
161  const BasicJet* bj = &(*bjCollection)[i];
162 
163  double energy = bj->energy();
164  TowerPoint temp(88.5,bj->eta(),bj->phi());
166  double emEnergy = 0.;
167  double hadEnergy = 0.;
168  double width = 0.;
169  double depth = 0.;
170  double fhot = 0.;
171  double sigmaz = 0.;
172  CastorTowerRefVector usedTowers;
173  double zmean = 0.;
174  double z2mean = 0.;
175 
176  std::vector<CandidatePtr> ccp = bj->getJetConstituents();
177  std::vector<CandidatePtr>::const_iterator itParticle;
178  for (itParticle=ccp.begin();itParticle!=ccp.end();++itParticle){
179  const CastorTower* castorcand = dynamic_cast<const CastorTower*>(itParticle->get());
180  //cout << " castortowercandidate reference energy = " << castorcand->castorTower()->energy() << endl;
181  //cout << " castortowercandidate reference eta = " << castorcand->castorTower()->eta() << endl;
182  //cout << " castortowercandidate reference phi = " << castorcand->castorTower()->phi() << endl;
183  //cout << " castortowercandidate reference depth = " << castorcand->castorTower()->depth() << endl;
184 
185  //CastorTowerCollection *ctc = new CastorTowerCollection();
186  //ctc->push_back(*castorcand);
187  //CastorTowerRef towerref = CastorTowerRef(ctc,0);
188 
189  size_t thisone = 0;
190  for (size_t l=0;l<ctCollection->size();l++) {
191  const CastorTower ct = (*ctCollection)[l];
192  if ( std::abs(ct.phi() - castorcand->phi()) < 0.0001 ) { thisone = l;}
193  }
194 
195  CastorTowerRef towerref(ctCollection,thisone);
196  usedTowers.push_back(towerref);
197  emEnergy += castorcand->emEnergy();
198  hadEnergy += castorcand->hadEnergy();
199  depth += castorcand->depth()*castorcand->energy();
200  width += pow(phiangle(castorcand->phi() - bj->phi()),2)*castorcand->energy();
201  fhot += castorcand->fhot()*castorcand->energy();
202 
203  // loop over rechits
204  for (edm::RefVector<edm::SortedCollection<CastorRecHit> >::iterator it = castorcand->rechitsBegin(); it != castorcand->rechitsEnd(); it++) {
206  double Erechit = rechit_p->energy();
207  HcalCastorDetId id = rechit_p->id();
208  int module = id.module();
209  double zrechit = 0;
210  if (module < 3) zrechit = -14390 - 24.75 - 49.5*(module-1);
211  if (module > 2) zrechit = -14390 - 99 - 49.5 - 99*(module-3);
212  zmean += Erechit*zrechit;
213  z2mean += Erechit*zrechit*zrechit;
214  } // end loop over rechits
215  }
216  //cout << "" << endl;
217 
218  depth = depth/energy;
219  width = sqrt(width/energy);
220  fhot = fhot/energy;
221 
222  zmean = zmean/energy;
223  z2mean = z2mean/energy;
224  double sigmaz2 = z2mean - zmean*zmean;
225  if(sigmaz2 > 0) sigmaz = sqrt(sigmaz2);
226 
227  CastorCluster cc(energy,position,emEnergy,hadEnergy,emEnergy/energy,width,depth,fhot,sigmaz,usedTowers);
228  OutputClustersfromBasicJets->push_back(cc);
229  }
230 
231  iEvent.put(OutputClustersfromBasicJets);
232 
233  }
234 
235 }
236 
237 // help function to calculate phi within [-pi,+pi]
238 double CastorClusterProducer::phiangle (double testphi) {
239  double phi = testphi;
240  while (phi>M_PI) phi -= (2*M_PI);
241  while (phi<-M_PI) phi += (2*M_PI);
242  return phi;
243 }
244 
245 // ------------ method called once each job just before starting event loop ------------
247  LogDebug("CastorClusterProducer")
248  <<"Starting CastorClusterProducer";
249 }
250 
251 // ------------ method called once each job just after ending the event loop ------------
253  LogDebug("CastorClusterProducer")
254  <<"Ending CastorClusterProducer";
255 }
256 
257 //define this as a plug-in
#define LogDebug(id)
double emEnergy() const
tower em energy
Definition: CastorTower.h:49
virtual double energy() const GCC11_FINAL
energy
int i
Definition: DBlmapReader.cc:9
module()
Definition: vlib.cc:994
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
#define abs(x)
Definition: mlp_lapack.h:159
double phiangle(double testphi)
edm::Ref< CastorTowerCollection > CastorTowerRef
Definition: CastorTower.h:130
CastorRecHitRefs::iterator rechitsBegin() const
fist iterator over CastorRecHit constituents
Definition: CastorTower.h:67
Jets made from CaloTowers.
Definition: BasicJet.h:21
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
CastorClusterProducer(const edm::ParameterSet &)
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< reco::CastorCluster > CastorClusterCollection
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< reco::CastorTower > CastorTowerCollection
ROOT::Math::RhoEtaPhiPoint TowerPoint
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
#define M_PI
Definition: BFit3D.cc:3
ROOT::Math::RhoZPhiPoint CellPoint
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double > > XYZPointD
point in space with cartesian internal representation
Definition: Point3D.h:9
const double MYR2D
double fhot() const
tower hotcell/tot ratio
Definition: CastorTower.h:61
double depth() const
tower depth in z
Definition: CastorTower.h:58
double hadEnergy() const
tower had energy
Definition: CastorTower.h:52
CastorRecHitRefs::iterator rechitsEnd() const
last iterator over CastorRecHit constituents
Definition: CastorTower.h:70
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
Definition: vlib.h:209
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
virtual Constituents getJetConstituents() const
list of constituents
Definition: Jet.cc:351
Definition: DDAxes.h:10