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.8 2010/07/06 16:46:09 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
43 
44 
45 
46 //
47 // class decleration
48 //
49 
51  public:
54 
55  private:
56  virtual void beginJob() ;
57  virtual void produce(edm::Event&, const edm::EventSetup&);
58  double phiangle (double testphi);
59  virtual void endJob() ;
60 
61  // ----------member data ---------------------------
63  typedef ROOT::Math::RhoEtaPhiPoint TowerPoint;
64  typedef ROOT::Math::RhoZPhiPoint CellPoint;
65  typedef std::vector<reco::CastorTower> CastorTowerCollection;
66  typedef std::vector<reco::CastorCluster> CastorClusterCollection;
67  std::string input_, basicjets_;
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 const double MYR2D = 180/M_PI;
76 
77 //
78 // static data member definitions
79 //
80 
81 //
82 // constructor and destructor
83 //
84 
86  input_(iConfig.getUntrackedParameter<std::string>("inputtowers","")),
87  basicjets_(iConfig.getUntrackedParameter<std::string>("basicjets","")),
88  clusteralgo_(iConfig.getUntrackedParameter<bool>("ClusterAlgo",false))
89 {
90  // register your products
91  produces<CastorClusterCollection>();
92  // now do what ever other initialization is needed
93 }
94 
95 
97 {
98  // do anything here that needs to be done at desctruction time
99  // (e.g. close files, deallocate resources etc.)
100 }
101 
102 
103 //
104 // member functions
105 //
106 
107 // ------------ method called to produce the data ------------
109 
110  using namespace edm;
111  using namespace reco;
112  using namespace TMath;
113 
114  LogDebug("CastorClusterProducer")
115  <<"3. entering CastorClusterProducer";
116 
117  if ( input_ != "") {
118 
119  // Produce CastorClusters from CastorTowers
120 
122  iEvent.getByLabel(input_, InputTowers);
123 
124  std::auto_ptr<CastorClusterCollection> OutputClustersfromClusterAlgo (new CastorClusterCollection);
125 
126  // get and check input size
127  int nTowers = InputTowers->size();
128 
129  if (nTowers==0) LogDebug("CastorClusterProducer")<<"Warning: You are trying to run the Cluster algorithm with 0 input towers.";
130 
131  CastorTowerRefVector posInputTowers, negInputTowers;
132 
133  for (size_t i = 0; i < InputTowers->size(); ++i) {
134  reco::CastorTowerRef tower_p = reco::CastorTowerRef(InputTowers, i);
135  if (tower_p->eta() > 0.) posInputTowers.push_back(tower_p);
136  if (tower_p->eta() < 0.) negInputTowers.push_back(tower_p);
137  }
138 
139  // build cluster from ClusterAlgo
140  if (clusteralgo_ == true) {
141  // code
142  iEvent.put(OutputClustersfromClusterAlgo);
143  }
144 
145  }
146 
147  if ( basicjets_ != "") {
148 
149  Handle<BasicJetCollection> bjCollection;
150  iEvent.getByLabel(basicjets_,bjCollection);
151 
152  Handle<CastorTowerCollection> ctCollection;
153  iEvent.getByLabel("CastorTowerReco",ctCollection);
154 
155  std::auto_ptr<CastorClusterCollection> OutputClustersfromBasicJets (new CastorClusterCollection);
156 
157  if (bjCollection->size()==0) LogDebug("CastorClusterProducer")<< "Warning: You are trying to run the Cluster algorithm with 0 input basicjets.";
158 
159  for (unsigned i=0; i< bjCollection->size();i++) {
160  const BasicJet* bj = &(*bjCollection)[i];
161 
162  double energy = bj->energy();
163  TowerPoint temp(88.5,bj->eta(),bj->phi());
165  double emEnergy = 0.;
166  double hadEnergy = 0.;
167  double width = 0.;
168  double depth = 0.;
169  double fhot = 0.;
170  double sigmaz = 0.;
171  CastorTowerRefVector usedTowers;
172  double zmean = 0.;
173  double z2mean = 0.;
174 
175  std::vector<CandidatePtr> ccp = bj->getJetConstituents();
176  std::vector<CandidatePtr>::const_iterator itParticle;
177  for (itParticle=ccp.begin();itParticle!=ccp.end();++itParticle){
178  const CastorTower* castorcand = dynamic_cast<const CastorTower*>(itParticle->get());
179  //cout << " castortowercandidate reference energy = " << castorcand->castorTower()->energy() << endl;
180  //cout << " castortowercandidate reference eta = " << castorcand->castorTower()->eta() << endl;
181  //cout << " castortowercandidate reference phi = " << castorcand->castorTower()->phi() << endl;
182  //cout << " castortowercandidate reference depth = " << castorcand->castorTower()->depth() << endl;
183 
184  //CastorTowerCollection *ctc = new CastorTowerCollection();
185  //ctc->push_back(*castorcand);
186  //CastorTowerRef towerref = CastorTowerRef(ctc,0);
187 
188  size_t thisone = 0;
189  for (size_t l=0;l<ctCollection->size();l++) {
190  const CastorTower ct = (*ctCollection)[l];
191  if ( std::abs(ct.phi() - castorcand->phi()) < 0.0001 ) { thisone = l;}
192  }
193 
194  CastorTowerRef towerref(ctCollection,thisone);
195  usedTowers.push_back(towerref);
196  emEnergy += castorcand->emEnergy();
197  hadEnergy += castorcand->hadEnergy();
198  depth += castorcand->depth()*castorcand->energy();
199  width += pow(phiangle(castorcand->phi() - bj->phi()),2)*castorcand->energy();
200  fhot += castorcand->fhot()*castorcand->energy();
201 
202  // loop over cells
203  for (CastorCell_iterator it = castorcand->cellsBegin(); it != castorcand->cellsEnd(); it++) {
204  CastorCellRef cell_p = *it;
205  Point rcell = cell_p->position();
206  double Ecell = cell_p->energy();
207  zmean += Ecell*cell_p->z();
208  z2mean += Ecell*cell_p->z()*cell_p->z();
209  } // end loop over cells
210  }
211  //cout << "" << endl;
212 
213  depth = depth/energy;
214  width = sqrt(width/energy);
215  fhot = fhot/energy;
216 
217  zmean = zmean/energy;
218  z2mean = z2mean/energy;
219  double sigmaz2 = z2mean - zmean*zmean;
220  if(sigmaz2 > 0) sigmaz = sqrt(sigmaz2);
221 
222  CastorCluster cc(energy,position,emEnergy,hadEnergy,emEnergy/energy,width,depth,fhot,sigmaz,usedTowers);
223  OutputClustersfromBasicJets->push_back(cc);
224  }
225 
226  iEvent.put(OutputClustersfromBasicJets);
227 
228  }
229 
230 }
231 
232 // help function to calculate phi within [-pi,+pi]
233 double CastorClusterProducer::phiangle (double testphi) {
234  double phi = testphi;
235  while (phi>M_PI) phi -= (2*M_PI);
236  while (phi<-M_PI) phi += (2*M_PI);
237  return phi;
238 }
239 
240 // ------------ method called once each job just before starting event loop ------------
242  LogDebug("CastorClusterProducer")
243  <<"Starting CastorClusterProducer";
244 }
245 
246 // ------------ method called once each job just after ending the event loop ------------
248  LogDebug("CastorClusterProducer")
249  <<"Ending CastorClusterProducer";
250 }
251 
252 //define this as a plug-in
#define LogDebug(id)
CastorCell_iterator cellsEnd() const
last iterator over CastorCell constituents
Definition: CastorTower.h:67
double emEnergy() const
tower em energy
Definition: CastorTower.h:46
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
CastorCell_iterator cellsBegin() const
fist iterator over CastorCell constituents
Definition: CastorTower.h:64
#define abs(x)
Definition: mlp_lapack.h:159
double phiangle(double testphi)
edm::Ref< CastorTowerCollection > CastorTowerRef
Definition: CastorTower.h:133
Jets made from CaloTowers.
Definition: BasicJet.h:21
virtual double eta() const
momentum pseudorapidity
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
CastorClusterProducer(const edm::ParameterSet &)
virtual double energy() const
energy
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::vector< reco::CastorCluster > CastorClusterCollection
T sqrt(T t)
Definition: SSEVec.h:28
std::vector< reco::CastorTower > CastorTowerCollection
ROOT::Math::RhoEtaPhiPoint TowerPoint
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
double energy() const
tower energy
Definition: CastorTower.h:40
#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:58
double depth() const
tower depth in z
Definition: CastorTower.h:55
double hadEnergy() const
tower had energy
Definition: CastorTower.h:49
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:61
virtual double phi() const
momentum azimuthal angle
double phi() const
azimuthal angle of tower centroid
Definition: CastorTower.h:91
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:349
Definition: DDAxes.h:10