7 #include "CLHEP/Random/RandFlat.h" 23 produces<PEcalTBInfo>();
26 GenVtxToken = consumes<edm::HepMCProduct>(
edm::InputTag(
"moduleLabelVtx",
"source"));
31 beamEta = (fMaxEta + fMinEta) / 2.;
32 beamPhi = (fMaxPhi + fMinPhi) / 2.;
33 beamTheta = 2.0 * atan(
exp(-beamEta));
37 string fullMapName = CrystalMapFile.fullPath();
46 theTestMap->findCrystalAngles(cryIndex, eta, phi);
47 if (fabs(beamEta - eta) < deltaEta && fabs(beamPhi - phi) < deltaPhi) {
48 deltaEta = fabs(beamEta - eta);
49 deltaPhi = fabs(beamPhi - phi);
50 crysNumber = cryIndex;
51 }
else if (fabs(beamEta - eta) < deltaEta && fabs(beamPhi - phi) > deltaPhi) {
52 if (fabs(beamPhi - phi) < 0.017) {
53 deltaEta = fabs(beamEta - eta);
54 deltaPhi = fabs(beamPhi - phi);
55 crysNumber = cryIndex;
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;
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;
76 double xx = -
cos(beamTheta) *
cos(beamPhi);
77 double xy = -
cos(beamTheta) *
sin(beamPhi);
78 double xz =
sin(beamTheta);
80 double yx =
sin(beamPhi);
81 double yy = -
cos(beamPhi);
84 double zx =
sin(beamTheta) *
cos(beamPhi);
85 double zy =
sin(beamTheta) *
sin(beamPhi);
86 double zz =
cos(beamTheta);
88 fromCMStoTB =
new ROOT::Math::Rotation3D(xx, xy, xz, yx, yy, yz, zx, zy, zz);
93 throw cms::Exception(
"Configuration") <<
"EcalTBMCInfoProducer requires the RandomNumberGeneratorService\n" 94 "which is not present in the configuration file. You must add the " 96 "in the configuration file or remove the modules that require it.";
106 unique_ptr<PEcalTBInfo> product(
new PEcalTBInfo());
110 product->setCrystal(crysNumber);
112 product->setBeamDirection(beamEta, beamPhi);
113 product->setBeamOffset(beamXoff, beamYoff);
118 partXhodo = partYhodo = 0.;
121 event.getByToken(GenVtxToken, GenEvt);
124 HepMC::GenEvent::vertex_const_iterator Vtx = Evt->vertices_begin();
126 math::XYZPoint eventCMSVertex((*Vtx)->position().x(), (*Vtx)->position().y(), (*Vtx)->position().z());
128 LogDebug(
"EcalTBInfo") <<
"Generated vertex position = " << eventCMSVertex.x() <<
" " << eventCMSVertex.y() <<
" " 129 << eventCMSVertex.z();
133 LogDebug(
"EcalTBInfo") <<
"Rotated vertex position = " << eventTBVertex.x() <<
" " << eventTBVertex.y() <<
" " 134 << eventTBVertex.z();
136 partXhodo = eventTBVertex.x();
137 partYhodo = eventTBVertex.y();
139 product->setBeamPosition(partXhodo, partYhodo);
142 double thisPhaseShift = CLHEP::RandFlat::shoot(engine);
144 product->setPhaseShift(thisPhaseShift);
145 LogDebug(
"EcalTBInfo") <<
"Asynchronous Phaseshift = " << thisPhaseShift;
T getParameter(std::string const &) const
static const int NCRYSTAL
Sin< T >::type sin(const T &t)
~EcalTBMCInfoProducer() override
Destructor.
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
static const double deltaEta
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
Produce digis out of raw data.
Cos< T >::type cos(const T &t)
Namespace of DDCMS conversion namespace.
const HepMC::GenEvent * GetEvent() const
XYZPointD XYZPoint
point in space with cartesian internal representation
StreamID streamID() const
EcalTBMCInfoProducer(const edm::ParameterSet &ps)
Constructor.