CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTBMCInfoProducer.cc
Go to the documentation of this file.
1 /*
2  * \file EcalTBMCInfoProducer.cc
3  *
4  * $Id: EcalTBMCInfoProducer.cc,v 1.12 2009/04/03 09:38:15 fabiocos Exp $
5  *
6 */
7 
11 #include "CLHEP/Random/RandFlat.h"
13 
15 
16 using namespace std;
17 using namespace cms;
18 
20 
21  produces<PEcalTBInfo>();
22 
24  GenVtxLabel = ps.getUntrackedParameter<string>("moduleLabelVtx","source");
25  double fMinEta = ps.getParameter<double>("MinEta");
26  double fMaxEta = ps.getParameter<double>("MaxEta");
27  double fMinPhi = ps.getParameter<double>("MinPhi");
28  double fMaxPhi = ps.getParameter<double>("MaxPhi");
29  beamEta = (fMaxEta+fMinEta)/2.;
30  beamPhi = (fMaxPhi+fMinPhi)/2.;
31  beamTheta = 2.0*atan(exp(-beamEta));
32  beamXoff = ps.getParameter<double>("BeamMeanX");
33  beamYoff = ps.getParameter<double>("BeamMeanX");
34 
35  string fullMapName = CrystalMapFile.fullPath();
36  theTestMap = new EcalTBCrystalMap(fullMapName);
37  crysNumber = 0;
38 
39  double deltaEta = 999.;
40  double deltaPhi = 999.;
41  for ( int cryIndex = 1; cryIndex <= EcalTBCrystalMap::NCRYSTAL; ++cryIndex) {
42  double eta = 0;
43  double phi = 0.;
44  theTestMap->findCrystalAngles(cryIndex, eta, phi);
45  if ( fabs(beamEta - eta) < deltaEta && fabs(beamPhi - phi) < deltaPhi ) {
46  deltaEta = fabs(beamEta - eta);
47  deltaPhi = fabs(beamPhi - phi);
48  crysNumber = cryIndex;
49  }
50  else if (fabs(beamEta - eta)<deltaEta && fabs(beamPhi - phi)>deltaPhi ) {
51  if ( fabs(beamPhi - phi) < 0.017 ) {
52  deltaEta = fabs(beamEta - eta);
53  deltaPhi = fabs(beamPhi - phi);
54  crysNumber = cryIndex;
55  }
56  }
57  else if (fabs(beamEta - eta)>deltaEta && fabs(beamPhi - phi)<deltaPhi ) {
58  if ( fabs(beamEta - eta) < 0.017 ) {
59  deltaEta = fabs(beamEta - eta);
60  deltaPhi = fabs(beamPhi - phi);
61  crysNumber = cryIndex;
62  }
63  }
64  }
65 
66  edm::LogInfo("EcalTBInfo") << "Initialize TB MC ECAL info producer with parameters: \n"
67  << "Crystal map file: " << CrystalMapFile << "\n"
68  << "Beam average eta = " << beamEta << "\n"
69  << "Beam average phi = " << beamPhi << "\n"
70  << "Corresponding to crystal number = " << crysNumber << "\n"
71  << "Beam X offset = " << beamXoff << "\n"
72  << "Beam Y offset = " << beamYoff;
73 
74  // rotation matrix to move from the CMS reference frame to the test beam one
75 
76  double xx = -cos(beamTheta)*cos(beamPhi);
77  double xy = -cos(beamTheta)*sin(beamPhi);
78  double xz = sin(beamTheta);
79 
80  double yx = sin(beamPhi);
81  double yy = -cos(beamPhi);
82  double yz = 0.;
83 
84  double zx = sin(beamTheta)*cos(beamPhi);
85  double zy = sin(beamTheta)*sin(beamPhi);
86  double zz = cos(beamTheta);
87 
88  fromCMStoTB = new ROOT::Math::Rotation3D(xx, xy, xz, yx, yy, yz, zx, zy, zz);
89 
90  // random number
92  if ( ! rng.isAvailable()) {
93  throw cms::Exception("Configuration")
94  << "EcalTBMCInfoProducer requires the RandomNumberGeneratorService\n"
95  "which is not present in the configuration file. You must add the service\n"
96  "in the configuration file or remove the modules that require it.";
97  }
98  CLHEP::HepRandomEngine& engine = rng->getEngine();
99  flatDistribution_ = new CLHEP::RandFlat(engine);
100 
101 }
102 
104 
105  delete flatDistribution_;
106  delete theTestMap;
107 
108 }
109 
111 {
112  auto_ptr<PEcalTBInfo> product(new PEcalTBInfo());
113 
114  // Fill the run information
115 
116  product->setCrystal(crysNumber);
117 
118  product->setBeamDirection(beamEta, beamPhi);
119  product->setBeamOffset(beamXoff, beamYoff);
120 
121  // Compute the event x,y vertex coordinates in the beam reference system
122  // e.g. in the place orthogonal to the beam average direction
123 
124  partXhodo = partYhodo = 0.;
125 
127  event.getByLabel(GenVtxLabel,GenEvt);
128 
129  const HepMC::GenEvent* Evt = GenEvt->GetEvent() ;
130  HepMC::GenEvent::vertex_const_iterator Vtx = Evt->vertices_begin();
131 
132  math::XYZPoint eventCMSVertex((*Vtx)->position().x(),
133  (*Vtx)->position().y(),
134  (*Vtx)->position().z());
135 
136  LogDebug("EcalTBInfo") << "Generated vertex position = "
137  << eventCMSVertex.x() << " "
138  << eventCMSVertex.y() << " "
139  << eventCMSVertex.z();
140 
141  math::XYZPoint eventTBVertex = (*fromCMStoTB)*eventCMSVertex;
142 
143  LogDebug("EcalTBInfo") << "Rotated vertex position = "
144  << eventTBVertex.x() << " "
145  << eventTBVertex.y() << " "
146  << eventTBVertex.z();
147 
148  partXhodo = eventTBVertex.x();
149  partYhodo = eventTBVertex.y();
150 
151  product->setBeamPosition(partXhodo, partYhodo);
152 
153  // Asynchronous phase shift
154  double thisPhaseShift = flatDistribution_->fire();
155 
156  product->setPhaseShift(thisPhaseShift);
157  LogDebug("EcalTBInfo") << "Asynchronous Phaseshift = " << thisPhaseShift;
158 
159  // store the object in the framework event
160 
161  event.put(product);
162 }
163 
164 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static const int NCRYSTAL
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T eta() const
CLHEP::RandFlat * flatDistribution_
virtual ~EcalTBMCInfoProducer()
Destructor.
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
bool isAvailable() const
Definition: Service.h:47
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
EcalTBCrystalMap * theTestMap
void produce(edm::Event &event, const edm::EventSetup &eventSetup)
Produce digis out of raw data.
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
void findCrystalAngles(const int thisCrysIndex, double &thisEta, double &thisPhi)
ROOT::Math::Rotation3D * fromCMStoTB
EcalTBMCInfoProducer(const edm::ParameterSet &ps)
Constructor.
Definition: DDAxes.h:10