CMS 3D CMS Logo

EcalTBMCInfoProducer.cc
Go to the documentation of this file.
1 /*
2  * \file EcalTBMCInfoProducer.cc
3  *
4  *
5  */
6 
7 #include "CLHEP/Random/RandFlat.h"
12 
14 
15 #include <fstream>
16 #include <iostream>
17 #include <vector>
18 
19 using namespace std;
20 using namespace cms;
21 
23  produces<PEcalTBInfo>();
24 
26  GenVtxToken = consumes<edm::HepMCProduct>(edm::InputTag("moduleLabelVtx", "source"));
27  double fMinEta = ps.getParameter<double>("MinEta");
28  double fMaxEta = ps.getParameter<double>("MaxEta");
29  double fMinPhi = ps.getParameter<double>("MinPhi");
30  double fMaxPhi = ps.getParameter<double>("MaxPhi");
31  beamEta = (fMaxEta + fMinEta) / 2.;
32  beamPhi = (fMaxPhi + fMinPhi) / 2.;
33  beamTheta = 2.0 * atan(exp(-beamEta));
34  beamXoff = ps.getParameter<double>("BeamMeanX");
35  beamYoff = ps.getParameter<double>("BeamMeanX");
36 
37  string fullMapName = CrystalMapFile.fullPath();
38  theTestMap = new EcalTBCrystalMap(fullMapName);
39  crysNumber = 0;
40 
41  double deltaEta = 999.;
42  double deltaPhi = 999.;
43  for (int cryIndex = 1; cryIndex <= EcalTBCrystalMap::NCRYSTAL; ++cryIndex) {
44  double eta = 0;
45  double phi = 0.;
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;
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") << "EcalTBMCInfoProducer requires the RandomNumberGeneratorService\n"
94  "which is not present in the configuration file. You must add the "
95  "service\n"
96  "in the configuration file or remove the modules that require it.";
97  }
98 }
99 
101 
104  CLHEP::HepRandomEngine *engine = &rng->getEngine(event.streamID());
105 
106  unique_ptr<PEcalTBInfo> product(new PEcalTBInfo());
107 
108  // Fill the run information
109 
110  product->setCrystal(crysNumber);
111 
112  product->setBeamDirection(beamEta, beamPhi);
113  product->setBeamOffset(beamXoff, beamYoff);
114 
115  // Compute the event x,y vertex coordinates in the beam reference system
116  // e.g. in the place orthogonal to the beam average direction
117 
118  partXhodo = partYhodo = 0.;
119 
121  event.getByToken(GenVtxToken, GenEvt);
122 
123  const HepMC::GenEvent *Evt = GenEvt->GetEvent();
124  HepMC::GenEvent::vertex_const_iterator Vtx = Evt->vertices_begin();
125 
126  math::XYZPoint eventCMSVertex((*Vtx)->position().x(), (*Vtx)->position().y(), (*Vtx)->position().z());
127 
128  LogDebug("EcalTBInfo") << "Generated vertex position = " << eventCMSVertex.x() << " " << eventCMSVertex.y() << " "
129  << eventCMSVertex.z();
130 
131  math::XYZPoint eventTBVertex = (*fromCMStoTB) * eventCMSVertex;
132 
133  LogDebug("EcalTBInfo") << "Rotated vertex position = " << eventTBVertex.x() << " " << eventTBVertex.y() << " "
134  << eventTBVertex.z();
135 
136  partXhodo = eventTBVertex.x();
137  partYhodo = eventTBVertex.y();
138 
139  product->setBeamPosition(partXhodo, partYhodo);
140 
141  // Asynchronous phase shift
142  double thisPhaseShift = CLHEP::RandFlat::shoot(engine);
143 
144  product->setPhaseShift(thisPhaseShift);
145  LogDebug("EcalTBInfo") << "Asynchronous Phaseshift = " << thisPhaseShift;
146 
147  // store the object in the framework event
148 
149  event.put(std::move(product));
150 }
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
geometryCSVtoXML.yz
yz
Definition: geometryCSVtoXML.py:19
RandomNumberGenerator.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle< edm::HepMCProduct >
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
edm::FileInPath
Definition: FileInPath.h:64
EcalTBMCInfoProducer.h
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
spr::deltaEta
static const double deltaEta
Definition: CaloConstants.h:8
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
EcalTBMCInfoProducer::EcalTBMCInfoProducer
EcalTBMCInfoProducer(const edm::ParameterSet &ps)
Constructor.
Definition: EcalTBMCInfoProducer.cc:22
Service.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
EcalTBCrystalMap
Definition: EcalTBCrystalMap.h:17
EcalTBMCInfoProducer::~EcalTBMCInfoProducer
~EcalTBMCInfoProducer() override
Destructor.
Definition: EcalTBMCInfoProducer.cc:100
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
PEcalTBInfo
Definition: PEcalTBInfo.h:18
geometryCSVtoXML.xz
xz
Definition: geometryCSVtoXML.py:19
edm::Service< edm::RandomNumberGenerator >
edm::EventSetup
Definition: EventSetup.h:57
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
EcalTBCrystalMap::NCRYSTAL
static const int NCRYSTAL
Definition: EcalTBCrystalMap.h:27
ecalTB2006H4_GenSimDigiReco_cfg.CrystalMapFile
CrystalMapFile
Definition: ecalTB2006H4_GenSimDigiReco_cfg.py:182
Exception
Definition: hltDiff.cc:246
Point3D.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
EcalTBMCInfoProducer::produce
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
Produce digis out of raw data.
Definition: EcalTBMCInfoProducer.cc:102
edm::InputTag
Definition: InputTag.h:15
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21