CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelLorentzAngleDB.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <iostream>
4 #include <fstream>
14 
15 
20 
21 using namespace std;
22 using namespace edm;
23 
24  //Constructor
25 
27  conf_(conf){
28  magneticField_ = conf_.getParameter<double>("magneticField");
29  recordName_ = conf_.getUntrackedParameter<std::string>("record","SiPixelLorentzAngleRcd");
30 // bPixLorentzAnglePerTesla_ = (float)conf_.getParameter<double>("bPixLorentzAnglePerTesla");
31 // fPixLorentzAnglePerTesla_ = (float)conf_.getParameter<double>("fPixLorentzAnglePerTesla");
32  useFile_ = conf_.getParameter<bool>("useFile");
33  fileName_ = conf_.getParameter<string>("fileName");
34 
37 }
38 
39  //BeginJob
40 
42 
43 }
44 // Virtual destructor needed.
45 
47 
48 }
49 
50 // Analyzer: Functions that gets called by framework every event
51 
53 {
54 
55  SiPixelLorentzAngle* LorentzAngle = new SiPixelLorentzAngle();
56 
57 
59  es.get<TrackerDigiGeometryRecord>().get( pDD );
60  edm::LogInfo("SiPixelLorentzAngle") <<" There are "<<pDD->detUnits().size() <<" detectors"<<std::endl;
61 
62  for(TrackerGeometry::DetUnitContainer::const_iterator it = pDD->detUnits().begin(); it != pDD->detUnits().end(); it++){
63 
64  if( dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
65  DetId detid=(*it)->geographicalId();
66 
67  // fill bpix values for LA
68  if(detid.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
69 
70  PXBDetId pxdetid = PXBDetId(detid);
71  cout << " hp:barrel:" << " layer=" << pxdetid.layer() << " ladder=" << pxdetid.ladder() << " module=" << pxdetid.module() << endl;
72 
73  if(!useFile_){
74 /*hp
75  if ( ! LorentzAngle->putLorentzAngle(detid.rawId(),bPixLorentzAnglePerTesla_) )
76  edm::LogError("SiPixelLorentzAngleDB")<<"[SiPixelLorentzAngleDB::analyze] detid already exists"<<std::endl;
77 */
78 //hp
79  for(Parameters::iterator it = BPixParameters_.begin(); it != BPixParameters_.end(); ++it) {
80 // cout << " PSet: " << *it << ", module = " << it->getParameter<unsigned int>("module") << endl;
81  if( it->getParameter<unsigned int>("module") == pxdetid.module() && it->getParameter<unsigned int>("layer") == pxdetid.layer() )
82  {
83  float lorentzangle = (float)it->getParameter<double>("angle");
84  LorentzAngle->putLorentzAngle(detid.rawId(),lorentzangle);
85  }
86  }
87 
88  } else {
89 // cout << "method for reading file not implemented yet" << endl;
90  edm::LogError("SiPixelLorentzAngleDB")<<"[SiPixelLorentzAngleDB::analyze] method for reading file not implemented yet" << std::endl;
91  }
92 
93  // fill fpix values for LA
94  } else if(detid.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
95 
96 //hp
97  PXFDetId pxdetid = PXFDetId(detid);
98  cout << " hp:endcap:" << " side=" << pxdetid.side() << " disk=" << pxdetid.disk() << " blade=" << pxdetid.blade() << " panel=" << pxdetid.panel() << " module=" << pxdetid.module() << endl;
99 /*hp
100  if ( ! LorentzAngle->putLorentzAngle(detid.rawId(),fPixLorentzAnglePerTesla_) ) edm::LogError("SiPixelLorentzAngleDB")<<"[SiPixelLorentzAngleDB::analyze] detid already exists"<<std::endl;
101 */
102 
103 //hp
104  for(Parameters::iterator it = FPixParameters_.begin(); it != FPixParameters_.end(); ++it) {
105 // cout << " PSet: " << *it << ", module = " << it->getParameter<unsigned int>("module") << endl;
106  if( it->getParameter<unsigned int>("side") == pxdetid.side() && it->getParameter<unsigned int>("disk") == pxdetid.disk() && it->getParameter<unsigned int>("HVgroup") == HVgroup(pxdetid.panel(),pxdetid.module()) )
107  {
108  float lorentzangle = (float)it->getParameter<double>("angle");
109  LorentzAngle->putLorentzAngle(detid.rawId(),lorentzangle);
110  }
111  }
112 
113  } else {
114  edm::LogError("SiPixelLorentzAngleDB")<<"[SiPixelLorentzAngleDB::analyze] detid is Pixel but neither bpix nor fpix"<<std::endl;
115  }
116 
117  }
118 
119  }
120 
121 
123  if( mydbservice.isAvailable() ){
124  try{
125  if( mydbservice->isNewTagRequest(recordName_) ){
126  mydbservice->createNewIOV<SiPixelLorentzAngle>(LorentzAngle,
127  mydbservice->beginOfTime(),
128  mydbservice->endOfTime(),
129  recordName_);
130  } else {
131  mydbservice->appendSinceTime<SiPixelLorentzAngle>(LorentzAngle,
132  mydbservice->currentTime(),
133  recordName_);
134  }
135  }catch(const cond::Exception& er){
136  edm::LogError("SiPixelLorentzAngleDB")<<er.what()<<std::endl;
137  }catch(const std::exception& er){
138  edm::LogError("SiPixelLorentzAngleDB")<<"caught std::exception "<<er.what()<<std::endl;
139  }catch(...){
140  edm::LogError("SiPixelLorentzAngleDB")<<"Funny error"<<std::endl;
141  }
142  }else{
143  edm::LogError("SiPixelLorentzAngleDB")<<"Service is unavailable"<<std::endl;
144  }
145 
146 
147 }
148 
149 
150 unsigned int SiPixelLorentzAngleDB::HVgroup(unsigned int panel, unsigned int module){
151 
152  if( 1 == panel && ( 1 == module || 2 == module )) {
153  return 1;
154  }
155  else if( 1 == panel && ( 3 == module || 4 == module )) {
156  return 2;
157  }
158  else if( 2 == panel && 1 == module ) {
159  return 1;
160  }
161  else if( 2 == panel && ( 2 == module || 3 == module )) {
162  return 2;
163  }
164  else {
165  cout << " *** error *** in SiPixelLorentzAngleDB::HVgroup(...), panel = " << panel << ", module = " << module << endl;
166  return 0;
167  }
168 
169 }
170 
171 
173 
174 
175 }
176 
177 
virtual char const * what() const
Definition: Exception.cc:141
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
unsigned int panel() const
panel id
Definition: PXFDetId.h:52
unsigned int ladder() const
ladder id
Definition: PXBDetId.h:39
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
unsigned int blade() const
blade id
Definition: PXFDetId.h:48
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:47
unsigned int module() const
det id
Definition: PXBDetId.h:43
SiPixelLorentzAngleDB(const edm::ParameterSet &conf)
unsigned int module() const
det id
Definition: PXFDetId.h:56
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool putLorentzAngle(const uint32_t &, float &)
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
tuple conf
Definition: dbtoconf.py:185
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
std::vector< edm::ParameterSet > Parameters
unsigned int HVgroup(unsigned int panel, unsigned int module)
unsigned int side() const
positive or negative id
Definition: PXFDetId.h:38
tuple cout
Definition: gather_cfg.py:121
Definition: vlib.h:209