00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CalibTracker/SiPixelTools/interface/SiPixelOfflineCalibAnalysisBase.h"
00022 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00023 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00024 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00025
00026 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00027 #include "CondFormats/SiPixelObjects/interface/ElectronicIndex.h"
00028 #include "CondFormats/SiPixelObjects/interface/DetectorIndex.h"
00029 #include "CondFormats/SiPixelObjects/interface/LocalPixel.h"
00030 #include "TList.h"
00031
00032 TF1* SiPixelOfflineCalibAnalysisBase::fitFunction_ = NULL;
00033 std::vector<short> SiPixelOfflineCalibAnalysisBase::vCalValues_(0);
00034
00035
00036 SiPixelOfflineCalibAnalysisBase::SiPixelOfflineCalibAnalysisBase(const edm::ParameterSet& iConfig):runnumbers_(0),eventCounter_(0)
00037 {
00038 siPixelCalibDigiProducer_ = iConfig.getParameter<edm::InputTag>("DetSetVectorSiPixelCalibDigiTag");
00039 createOutputFile_ = iConfig.getUntrackedParameter<bool>("saveFile",false);
00040 outputFileName_ = iConfig.getParameter<std::string>("outputFileName");
00041 daqBE_ = &*edm::Service<DQMStore>();
00042 folderMaker_ = new SiPixelFolderOrganizer();
00043
00044 }
00045
00046 SiPixelOfflineCalibAnalysisBase::SiPixelOfflineCalibAnalysisBase()
00047 {
00048 throw cms::Exception("") << "ERROR: Classes derived from SiPixelOfflineCalibAnalysisBase must call SiPixelOfflineCalibAnalysisBase::SiPixelOfflineCalibAnalysisBase(const edm::ParameterSet& iConfig) from their constructor." << std::endl;
00049 }
00050
00051 SiPixelOfflineCalibAnalysisBase::~SiPixelOfflineCalibAnalysisBase()
00052 {
00053 }
00054
00055
00056
00057
00058
00059
00060
00061 void
00062 SiPixelOfflineCalibAnalysisBase::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00063 {
00064 using namespace edm;
00065
00066 iSetup.get<TrackerDigiGeometryRecord>().get( geom_ );
00067 iSetup.get<SiPixelFedCablingMapRcd>().get(theCablingMap_);
00068 iSetup.get<SiPixelCalibConfigurationRcd>().get(calib_);
00069 if(eventCounter_==0)
00070 this->calibrationSetup(iSetup);
00071 eventCounter_++;
00072
00073
00074 if(!checkCorrectCalibrationType())
00075 return;
00076
00077 uint32_t runnumber=iEvent.id().run();
00078 if(runnumbers_.size()==0)
00079 runnumbers_.push_back(runnumber);
00080 else{
00081 bool foundnumber=false;
00082 for(size_t iter=0; iter<runnumbers_.size() && !foundnumber; ++ iter){
00083 if(runnumbers_[iter]==runnumber){
00084 foundnumber=true;
00085 continue;
00086 }
00087 }
00088 if(!foundnumber)
00089 runnumbers_.push_back(runnumber);
00090 }
00091
00092 Handle<DetSetVector<SiPixelCalibDigi> > thePlaquettes;
00093 iEvent.getByLabel(siPixelCalibDigiProducer_, thePlaquettes);
00094
00095 DetSetVector<SiPixelCalibDigi>::const_iterator digiIter;
00096
00097
00098 for(digiIter=thePlaquettes->begin(); digiIter!=thePlaquettes->end(); ++digiIter)
00099 {
00100 uint32_t detId = digiIter->id;
00101
00102 if (detIdsEntered_.find(detId) == detIdsEntered_.end())
00103 {
00104 detIdsEntered_.insert(std::make_pair(detId, 0));
00105 detIdNames_.insert(std::make_pair(detId, translateDetIdToString(detId)));
00106 newDetID(detId);
00107 }
00108 DetSet<SiPixelCalibDigi>::const_iterator ipix;
00109
00110 for(ipix=digiIter->data.begin(); ipix!=digiIter->end(); ++ipix)
00111 {
00112
00113 this->doFits(detId, ipix);
00114 }
00115 }
00116
00117 }
00118
00119 void SiPixelOfflineCalibAnalysisBase::beginRun(const edm::Run &, const edm::EventSetup &iSetup)
00120 {
00121
00122 iSetup.get<SiPixelCalibConfigurationRcd>().get(calib_);
00123 iSetup.get<TrackerDigiGeometryRecord>().get( geom_ );
00124 iSetup.get<SiPixelFedCablingMapRcd>().get(theCablingMap_);
00125
00126 calibrationMode_ = calib_->getCalibrationMode();
00127 nTriggers_ = calib_->getNTriggers();
00128 vCalValues_ = calib_->getVCalValues();
00129 std::cout << "!!!! in beginRun" << std::endl;
00130 edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Calibration file loaded. Mode: " << calibrationMode_ << " nTriggers: " << nTriggers_ << " Vcal steps: " << vCalValues_.size() << std::endl;
00131
00132 this->calibrationSetup(iSetup);
00133 theHistogramIdWorker_ = new SiPixelHistogramId(siPixelCalibDigiProducer_.label());
00134 }
00135 void
00136 SiPixelOfflineCalibAnalysisBase::beginJob()
00137 {
00138
00139 }
00140
00141
00142
00143 void
00144 SiPixelOfflineCalibAnalysisBase::endJob() {
00145 this->calibrationEnd();
00146 edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Running end job... output file name is: " << outputFileName_;
00147 if (!outputFileName_.empty() && createOutputFile_)
00148 {
00149 edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "Writing ROOT file to: " << outputFileName_ << std::endl;
00150 daqBE_->save(outputFileName_);
00151 }
00152 }
00153
00154
00155
00156 const std::vector<short>*
00157 SiPixelOfflineCalibAnalysisBase::getVcalValues()
00158 {
00159 return &vCalValues_;
00160 }
00161
00162 std::string
00163 SiPixelOfflineCalibAnalysisBase::translateDetIdToString(uint32_t detid)
00164 {
00165 std::map<uint32_t, std::string>::iterator detNameIter = detIdNames_.find(detid);
00166 if (detNameIter != detIdNames_.end()) {
00167 return detNameIter->second;
00168 }
00169 std::string output = "DetID translation error";
00170 DetId detId(detid);
00171 uint32_t detSubId = detId.subdetId();
00172 if (detSubId > 2 || detSubId < 1)
00173 {
00174 edm::LogError("SiPixelOfflineCalibAnalysisBase") << "ERROR: Expected a pixel detector ID (1 - barrel, 2 - forward) but got " << detSubId << std::endl;
00175 return output;
00176 }
00177 if (detSubId == 2)
00178 {
00179 PixelEndcapName nameworker(detid);
00180 output = nameworker.name();
00181 } else
00182 {
00183 PixelBarrelName nameworker(detid);
00184 output = nameworker.name();
00185 }
00186 detIdNames_.insert(std::make_pair(detid, output));
00187 return output;
00188 }
00189
00190 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX)
00191 {
00192 std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
00193 return daqBE_->book1D(hid, title, nchX, lowX, highX);
00194 }
00195
00196 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, float *xbinsize)
00197 {
00198 std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
00199 return daqBE_->book1D(hid, title, nchX, xbinsize);
00200 }
00201
00202 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistogram2D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
00203 {
00204 std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
00205 return daqBE_->book2D(hid, title, nchX, lowX, highX, nchY, lowY, highY);
00206 }
00207
00208 MonitorElement* SiPixelOfflineCalibAnalysisBase::bookDQMHistoPlaquetteSummary2D(uint32_t detid, std::string name,std::string title){
00209 DetId detId(detid);
00210 const TrackerGeometry &theTracker(*geom_);
00211 const PixelGeomDetUnit *theGeomDet = dynamic_cast<const PixelGeomDetUnit*> ( theTracker.idToDet(detId) );
00212 int maxcol = theGeomDet->specificTopology().ncolumns();
00213 int maxrow = theGeomDet->specificTopology().nrows();
00214
00215
00216 std::string hid = theHistogramIdWorker_->setHistoId(name,detid);
00217 return daqBE_->book2D(hid,title,maxcol,0,maxcol,maxrow,0,maxrow);
00218 }
00219
00220 bool
00221 SiPixelOfflineCalibAnalysisBase::setDQMDirectory(std::string dirName)
00222 {
00223 daqBE_->setCurrentFolder(dirName);
00224 return daqBE_->dirExists(dirName);
00225 }
00226
00227 bool
00228 SiPixelOfflineCalibAnalysisBase::setDQMDirectory(uint32_t detID)
00229 {
00230 return folderMaker_->setModuleFolder(detID,0);
00231 }
00232
00233
00234
00235 bool
00236 SiPixelOfflineCalibAnalysisBase::checkCorrectCalibrationType()
00237 {
00238 return true;
00239 }
00240
00241 bool
00242 SiPixelOfflineCalibAnalysisBase::doFits(uint32_t detid, std::vector<SiPixelCalibDigi>::const_iterator ipix)
00243 {
00244 short row=ipix->row();
00245 short col=ipix->col();
00246 std::vector<uint8_t> nentries = ipix->getnentries();
00247 std::vector<uint32_t> sum = ipix->getsum();
00248 std::vector<uint32_t> sumquares = ipix->getsumsquares();
00249
00250
00251
00252
00253 std::cout << "Row: " << row << " Col: " << col << std::endl;
00254 for (unsigned int i = 0; i < sum.size(); i++)
00255 {
00256 std::cout << sum[i] << " ";
00257 }
00258 std::cout << std::endl;
00259 return false;
00260
00261 }
00262
00263 void
00264 SiPixelOfflineCalibAnalysisBase::calibrationSetup(const edm::EventSetup&)
00265 {
00266
00267 }
00268
00269 void SiPixelOfflineCalibAnalysisBase::calibrationEnd()
00270 {
00271
00272 }
00273 void
00274 SiPixelOfflineCalibAnalysisBase::newDetID(uint32_t detid)
00275 {
00276
00277 edm::LogInfo("SiPixelOfflineCalibAnalysisBase") << "SiPixelOfflineCalibAnalysisBase - Found new DetID: " << detid << " Name: " << detIdNames_[detid];
00278 }
00279
00280 bool
00281 SiPixelOfflineCalibAnalysisBase::checkPixel(uint32_t detid,short row, short col)
00282 {
00283
00284 int thefedid = -1;
00285 for(int fedid=0; fedid<=40 && thefedid==-1; ++fedid)
00286 {
00287 SiPixelFrameConverter converter(theCablingMap_.product(),fedid);
00288 if(converter.hasDetUnit(detid))
00289 {
00290 thefedid=fedid;
00291 }
00292 }
00293 if(thefedid==-1)
00294 return false;
00295
00296 SiPixelFrameConverter formatter(theCablingMap_.product(),thefedid);
00297 sipixelobjects::DetectorIndex detector ={detid, row, col};
00298 sipixelobjects::ElectronicIndex cabling;
00299
00300 formatter.toCabling(cabling,detector);
00301
00302
00303
00304 sipixelobjects::LocalPixel::DcolPxid loc;
00305 loc.dcol = cabling.dcol;
00306 loc.pxid = cabling.pxid;
00307 sipixelobjects::LocalPixel locpixel(loc);
00308 short localrow = locpixel.rocRow();
00309 short localcol = locpixel.rocCol();
00310
00311
00312 std::vector<short> calibcols = calib_->getColumnPattern();
00313 std::vector<short> calibrows = calib_->getRowPattern();
00314
00315 for(size_t irow=0; irow<calibrows.size(); ++irow)
00316 {
00317 if(calibrows[irow]==localrow)
00318 {
00319
00320 for(size_t icol=0; icol<calibcols.size(); ++icol)
00321 {
00322 if(calibcols[icol]==localcol)
00323 return true;
00324 }
00325 }
00326 }
00327
00328 return false;
00329 }
00330
00331
00332 void SiPixelOfflineCalibAnalysisBase::addTF1ToDQMMonitoringElement(MonitorElement *ele, TF1 *func){
00333
00334 if(func){
00335 ele->getTH1()->GetListOfFunctions()->Add(func);
00336 }
00337 return;
00338 }
00339
00340 DEFINE_FWK_MODULE(SiPixelOfflineCalibAnalysisBase);