CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CondTools/Ecal/src/EcalTestDevDB.cc

Go to the documentation of this file.
00001 #include "FWCore/ServiceRegistry/interface/Service.h"
00002 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00003 
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 
00008 #include "DataFormats/Common/interface/Handle.h"
00009 
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
00013 
00014 #include "DataFormats/Provenance/interface/Timestamp.h"
00015 
00016 #include "CondTools/Ecal/interface/EcalTestDevDB.h"
00017 
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 #include <map>
00021 #include <vector>
00022 
00023 using namespace std;
00024 
00025 EcalTestDevDB::EcalTestDevDB(const edm::ParameterSet& iConfig) :
00026   m_timetype(iConfig.getParameter<std::string>("timetype")),
00027   m_cacheIDs(),
00028   m_records()
00029 {
00030 
00031   std::string container;
00032   std::string tag;
00033   std::string record;
00034 
00035   m_firstRun=static_cast<unsigned long>(atoi( iConfig.getParameter<std::string>("firstRun").c_str()));
00036   m_lastRun=static_cast<unsigned long>(atoi( iConfig.getParameter<std::string>("lastRun").c_str()));
00037   m_interval=static_cast<unsigned long>(atoi( iConfig.getParameter<std::string>("interval").c_str()));
00038 
00039   typedef std::vector< edm::ParameterSet > Parameters;
00040   Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
00041   for(Parameters::iterator i = toCopy.begin(); i != toCopy.end(); ++i) {
00042     container = i->getParameter<std::string>("container");
00043     record = i->getParameter<std::string>("record");
00044     m_cacheIDs.insert( std::make_pair(container, 0) );
00045     m_records.insert( std::make_pair(container, record) );
00046   }
00047   
00048 }
00049 
00050 
00051 EcalTestDevDB::~EcalTestDevDB()
00052 {
00053   
00054 }
00055 
00056 void EcalTestDevDB::analyze( const edm::Event& evt, const edm::EventSetup& evtSetup)
00057 {
00058 
00059   edm::Service<cond::service::PoolDBOutputService> dbOutput;
00060   if ( !dbOutput.isAvailable() ) {
00061     throw cms::Exception("PoolDBOutputService is not available");
00062   }
00063 
00064  
00065 
00066   std::string container;
00067   std::string record;
00068   typedef std::map<std::string, std::string>::const_iterator recordIter;
00069   for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
00070     container = (*i).first;
00071     record = (*i).second;
00072 
00073     std::string recordName = m_records[container];
00074 
00075     
00076     // Loop through each of the runs
00077 
00078     unsigned long nrec=(m_lastRun-m_firstRun)/m_interval+1;
00079     unsigned long nstart=0;
00080     if (m_firstRun == 0 && m_lastRun == 0) {
00081        // it should do at least once the loop
00082       nstart=0;
00083       nrec=1;
00084     }
00085 
00086     for(unsigned long i=nstart; i<nrec; i++) {
00087       unsigned long irun=m_firstRun+i*m_interval;
00088  
00089  
00090       // Arguments 0 0 mean infinite IOV
00091       if (m_firstRun == 0 && m_lastRun == 0) {
00092         std::cout << "Infinite IOV mode" << std::endl;
00093         irun = edm::IOVSyncValue::endOfTime().eventID().run();
00094       }
00095 
00096       std::cout << "Starting Transaction for run " << irun << "..." << std::flush;
00097     
00098       if (container == "EcalPedestals") {
00099         EcalPedestals* condObject= generateEcalPedestals();
00100 
00101         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00102           // create new
00103           std::cout<<"First One "<<std::endl;
00104           dbOutput->createNewIOV<const EcalPedestals>( condObject, dbOutput->beginOfTime(),dbOutput->endOfTime() ,recordName);
00105         } else {
00106           // append
00107           std::cout<<"Old One "<<std::endl;
00108           dbOutput->appendSinceTime<const EcalPedestals>( condObject, irun , recordName);
00109         }
00110         
00111       } else if (container == "EcalADCToGeVConstant") {
00112         
00113         EcalADCToGeVConstant* condObject= generateEcalADCToGeVConstant();
00114         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00115           // create new
00116           std::cout<<"First One "<<std::endl;
00117           dbOutput->createNewIOV<const EcalADCToGeVConstant>( condObject, dbOutput->beginOfTime(),dbOutput->endOfTime() ,recordName);
00118         } else {
00119           // append
00120           std::cout<<"Old One "<<std::endl;
00121           dbOutput->appendSinceTime<const EcalADCToGeVConstant>( condObject, irun , recordName);
00122         }
00123         
00124         
00125       } else if (container == "EcalIntercalibConstants") {
00126         EcalIntercalibConstants* condObject= generateEcalIntercalibConstants();
00127         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00128           // create new
00129           std::cout<<"First One "<<std::endl;
00130           dbOutput->createNewIOV<const EcalIntercalibConstants>( condObject, dbOutput->beginOfTime(),dbOutput->endOfTime() ,recordName);
00131         } else {
00132           // append
00133           std::cout<<"Old One "<<std::endl;
00134           dbOutput->appendSinceTime<const EcalIntercalibConstants>( condObject, irun , recordName);
00135         }
00136       } else if (container == "EcalLinearCorrections") {
00137         EcalLinearCorrections* condObject= generateEcalLinearCorrections();
00138         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00139           // create new
00140           std::cout<<"First One "<<std::endl;
00141           dbOutput->createNewIOV<const EcalLinearCorrections>( condObject, dbOutput->beginOfTime(),dbOutput->endOfTime() ,recordName);
00142         } else {
00143           // append
00144           std::cout<<"Old One "<<std::endl;
00145           dbOutput->appendSinceTime<const EcalLinearCorrections>( condObject, irun , recordName);
00146         }
00147         
00148       } else if (container == "EcalGainRatios") {
00149         EcalGainRatios* condObject= generateEcalGainRatios();
00150         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00151           // create new
00152           std::cout<<"First One "<<std::endl;
00153           dbOutput->createNewIOV<const EcalGainRatios>( condObject,dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00154         } else {
00155           // append
00156           std::cout<<"Old One "<<std::endl;
00157           dbOutput->appendSinceTime<const EcalGainRatios>( condObject, irun , recordName);
00158         }
00159         
00160       } else if (container == "EcalWeightXtalGroups") {
00161         EcalWeightXtalGroups* condObject= generateEcalWeightXtalGroups();
00162         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00163           // create new
00164           std::cout<<"First One "<<std::endl;
00165           dbOutput->createNewIOV<const EcalWeightXtalGroups>( condObject, dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00166         } else {
00167           // append
00168           std::cout<<"Old One "<<std::endl;
00169           dbOutput->appendSinceTime<const EcalWeightXtalGroups>( condObject, irun , recordName);
00170         }
00171         
00172       } else if (container == "EcalTBWeights") {
00173         EcalTBWeights* condObject= generateEcalTBWeights();
00174         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00175           // create new
00176           std::cout<<"First One "<<std::endl;
00177           dbOutput->createNewIOV<const EcalTBWeights>( condObject, dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00178         } else {
00179           // append
00180           std::cout<<"Old One "<<std::endl;
00181           dbOutput->appendSinceTime<const EcalTBWeights>( condObject, irun , recordName);
00182         }
00183         
00184       } else if (container == "EcalLaserAPDPNRatios") {
00185         EcalLaserAPDPNRatios* condObject= generateEcalLaserAPDPNRatios(irun);
00186         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00187           // create new
00188           std::cout<<"First One "<<std::endl;
00189           dbOutput->createNewIOV<const EcalLaserAPDPNRatios>( condObject,dbOutput->beginOfTime(),  dbOutput->endOfTime() ,recordName);
00190         } else {
00191           // append
00192           std::cout<<"Old One "<<std::endl;
00193           dbOutput->appendSinceTime<const EcalLaserAPDPNRatios>( condObject, irun , recordName);
00194         }
00195       } else if (container == "EcalLaserAPDPNRatiosRef") {
00196         EcalLaserAPDPNRatiosRef* condObject= generateEcalLaserAPDPNRatiosRef();
00197         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00198           // create new
00199           std::cout<<"First One "<<std::endl;
00200           dbOutput->createNewIOV<const EcalLaserAPDPNRatiosRef>( condObject, dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00201         } else {
00202           // append
00203           std::cout<<"Old One "<<std::endl;
00204           dbOutput->appendSinceTime<const EcalLaserAPDPNRatiosRef>( condObject, irun , recordName);
00205         }
00206       } else if (container == "EcalLaserAlphas") {
00207         EcalLaserAlphas* condObject= generateEcalLaserAlphas();
00208         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00209           // create new
00210           std::cout<<"First One "<<std::endl;
00211           dbOutput->createNewIOV<const EcalLaserAlphas>( condObject,dbOutput->beginOfTime(),  dbOutput->endOfTime() ,recordName);
00212         } else {
00213           // append
00214           std::cout<<"Old One "<<std::endl;
00215           dbOutput->appendSinceTime<const EcalLaserAlphas>( condObject, irun , recordName);
00216         }
00217       } else {
00218         std::cout << "it does not work yet for " << container << "..." << std::flush;
00219         
00220       }
00221       
00222       
00223     }
00224     
00225     
00226   }
00227   
00228   
00229 }
00230 
00231 
00232 //-------------------------------------------------------------
00233 EcalPedestals*
00234 EcalTestDevDB::generateEcalPedestals() {
00235 //-------------------------------------------------------------
00236 
00237   EcalPedestals* peds = new EcalPedestals();
00238   EcalPedestals::Item item;
00239   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00240     if(iEta==0) continue;
00241     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00242       item.mean_x1  = 200.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00243       item.rms_x1   = (double)std::rand()/(double(RAND_MAX)+double(1));
00244       item.mean_x6  = 1200.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00245       item.rms_x6   = 6.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00246       item.mean_x12 = 2400.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00247       item.rms_x12  = 12.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00248 
00249       EBDetId ebdetid(iEta,iPhi);
00250       peds->insert(std::make_pair(ebdetid.rawId(),item));
00251     }
00252   }
00253   return peds;
00254 }
00255 
00256 //-------------------------------------------------------------
00257 EcalADCToGeVConstant*
00258 EcalTestDevDB::generateEcalADCToGeVConstant() {
00259 //-------------------------------------------------------------
00260   
00261   double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00262   EcalADCToGeVConstant* agc = new EcalADCToGeVConstant(36.+r*4., 60.+r*4);
00263   return agc;
00264 }
00265 
00266 //-------------------------------------------------------------
00267 EcalIntercalibConstants*
00268 EcalTestDevDB::generateEcalIntercalibConstants() {
00269 //-------------------------------------------------------------
00270 
00271   EcalIntercalibConstants* ical = new EcalIntercalibConstants();
00272 
00273   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00274     if(ieta==0) continue;
00275     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId:: MAX_IPHI; ++iphi) {
00276 
00277       EBDetId ebid(ieta,iphi);
00278 
00279       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00280       ical->setValue( ebid.rawId(), 0.85 + r*0.3 );
00281     } // loop over phi
00282   } // loop over eta
00283   return ical;
00284 }
00285 
00286 //-------------------------------------------------------------
00287 EcalLinearCorrections*
00288 EcalTestDevDB::generateEcalLinearCorrections() {
00289 //-------------------------------------------------------------
00290 
00291   EcalLinearCorrections* ical = new EcalLinearCorrections();
00292 
00293   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00294     if(ieta==0) continue;
00295     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00296       if (EBDetId::validDetId(ieta,iphi)) {
00297         EBDetId ebid(ieta,iphi);
00298         
00299 
00300         EcalLinearCorrections::Values pairAPDPN;
00301         pairAPDPN.p1 = 1.0;
00302         pairAPDPN.p2 = 1.0;
00303         pairAPDPN.p3 = 1.0;
00304         ical->setValue( ebid, pairAPDPN );
00305       }
00306     }
00307   }
00308 
00309   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00310     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00311       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals                                                           
00312       if (EEDetId::validDetId(iX,iY,1)) {
00313         
00314         EEDetId eedetidpos(iX,iY,1);
00315 
00316         EcalLinearCorrections::Values pairAPDPN;
00317         pairAPDPN.p1 = 1.0;
00318         pairAPDPN.p2 = 1.0;
00319         pairAPDPN.p3 = 1.0;
00320 
00321         ical->setValue( eedetidpos, pairAPDPN );
00322       }
00323 
00324       if (EEDetId::validDetId(iX,iY,-1)) {
00325         
00326         EEDetId eedetidneg(iX,iY,-1);
00327 
00328         EcalLinearCorrections::Values pairAPDPN;
00329         pairAPDPN.p1 = 1.0;
00330         pairAPDPN.p2 = 1.0;
00331         pairAPDPN.p3 = 1.0;
00332 
00333         ical->setValue( eedetidneg, pairAPDPN );
00334       }
00335     }
00336   }
00337 
00338   EcalLinearCorrections::Times TimeStamp;
00339   for(int i=0; i<92; i++){
00340 
00341       TimeStamp.t1 = edm::Timestamp(0);
00342       TimeStamp.t2 = edm::Timestamp(edm::Timestamp::endOfTime().value());
00343       TimeStamp.t3 = edm::Timestamp(edm::Timestamp::endOfTime().value());
00344 
00345       ical->setTime(i, TimeStamp);
00346 
00347 
00348   }
00349 
00350 
00351 
00352 
00353   return ical;
00354 }
00355 
00356 //-------------------------------------------------------------
00357 EcalGainRatios*
00358 EcalTestDevDB::generateEcalGainRatios() {
00359 //-------------------------------------------------------------
00360 
00361   // create gain ratios
00362   EcalGainRatios* gratio = new EcalGainRatios;
00363 
00364   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00365     if(ieta==0) continue;
00366     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId:: MAX_IPHI; ++iphi) {
00367 
00368       EBDetId ebid(ieta,iphi);
00369 
00370       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00371 
00372       EcalMGPAGainRatio gr;
00373       gr.setGain12Over6( 1.9 + r*0.2 );
00374       gr.setGain6Over1( 5.9 + r*0.2 );
00375 
00376       gratio->setValue( ebid.rawId(), gr );
00377 
00378     } // loop over phi
00379   } // loop over eta
00380   return gratio;
00381 }
00382 
00383 //-------------------------------------------------------------
00384 EcalWeightXtalGroups*
00385 EcalTestDevDB::generateEcalWeightXtalGroups() {
00386 //-------------------------------------------------------------
00387 
00388   EcalWeightXtalGroups* xtalGroups = new EcalWeightXtalGroups();
00389   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00390     if(ieta==0) continue;
00391     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId:: MAX_IPHI; ++iphi) {
00392       EBDetId ebid(ieta,iphi);
00393       xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId(ieta) ); // define rings in eta
00394     }
00395   }
00396   return xtalGroups;
00397 }
00398 
00399 //-------------------------------------------------------------
00400 EcalTBWeights*
00401 EcalTestDevDB::generateEcalTBWeights() {
00402 //-------------------------------------------------------------
00403 
00404   EcalTBWeights* tbwgt = new EcalTBWeights();
00405 
00406   // create weights for each distinct group ID
00407   int nMaxTDC = 10;
00408   for(int igrp=-EBDetId::MAX_IETA; igrp<=EBDetId::MAX_IETA; ++igrp) {
00409     if(igrp==0) continue;
00410     for(int itdc=1; itdc<=nMaxTDC; ++itdc) {
00411       // generate random number
00412       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00413 
00414       // make a new set of weights
00415       EcalWeightSet wgt;
00416       EcalWeightSet::EcalWeightMatrix& mat1 = wgt.getWeightsBeforeGainSwitch();
00417       EcalWeightSet::EcalWeightMatrix& mat2 = wgt.getWeightsAfterGainSwitch();
00418 
00419       for(size_t i=0; i<3; ++i) {
00420         for(size_t j=0; j<10; ++j) {
00421           double ww = igrp*itdc*r + i*10. + j;
00422           //std::cout << "row: " << i << " col: " << j << " -  val: " << ww  << std::endl;
00423           mat1(i,j)=ww;
00424           mat2(i,j)=100+ww;
00425         }
00426       }
00427 
00428       // fill the chi2 matrcies
00429       r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00430       EcalWeightSet::EcalChi2WeightMatrix& mat3 = wgt.getChi2WeightsBeforeGainSwitch();
00431       EcalWeightSet::EcalChi2WeightMatrix& mat4 = wgt.getChi2WeightsAfterGainSwitch();
00432       for(size_t i=0; i<10; ++i) {
00433         for(size_t j=0; j<10; ++j) {
00434           double ww = igrp*itdc*r + i*10. + j;
00435           mat3(i,j)=1000+ww;
00436           mat4(i,j)=1000+100+ww;
00437         }
00438       }
00439 
00440       // put the weight in the container
00441       tbwgt->setValue(std::make_pair(igrp,itdc), wgt);
00442     }
00443   }
00444   return tbwgt;
00445 }
00446 
00447 
00448 
00449 //--------------------------------------------------------------
00450 EcalLaserAPDPNRatios*
00451 EcalTestDevDB::generateEcalLaserAPDPNRatios(uint32_t i_run) {
00452 //--------------------------------------------------------------
00453 
00454   EcalLaserAPDPNRatios* laser = new EcalLaserAPDPNRatios();
00455 
00456   EcalLaserAPDPNRatios::EcalLaserAPDPNpair APDPNpair;
00457   EcalLaserAPDPNRatios::EcalLaserTimeStamp TimeStamp;
00458 
00459   //  if((m_firstRun == 0 && i_run == 0) || (m_firstRun == 1 && i_run == 1)){ 
00460 
00461   std::cout << "First & last run: " << i_run << " " << m_firstRun << " " << m_lastRun << " " << std::endl;
00462   if (m_firstRun == i_run && (i_run == 0 || i_run == 1) ) {
00463 
00464     APDPNpair.p1= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10))))/double(2);
00465     APDPNpair.p2= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10)+double(10))))/double(2);
00466     APDPNpair.p3= double(0);
00467     std::cout << i_run << " " << m_firstRun << " " << APDPNpair.p1 << " " << APDPNpair.p2 << std::endl;
00468 
00469     for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00470       if(iEta==0) continue;
00471       for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00472         //APDPNpair.p1= double(1);
00473         //APDPNpair.p2= double(1);
00474         
00475         EBDetId ebid(iEta,iPhi);        
00476         int hi = ebid.hashedIndex();
00477 
00478         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00479           laser->setValue(hi, APDPNpair);
00480         } else {
00481           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00482           continue;
00483         }
00484       }
00485     }
00486 
00487     for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00488       for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00489         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00490 
00491         if (!EEDetId::validDetId(iX,iY,1))
00492           continue;
00493 
00494         EEDetId eedetidpos(iX,iY,1);
00495         //APDPNpair.p1 = double(1);
00496         //APDPNpair.p2 = double(1);
00497         
00498         int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00499         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00500           laser->setValue(hi, APDPNpair);
00501         } else {
00502           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00503           continue;
00504         }
00505         
00506         if (!EEDetId::validDetId(iX,iY,-1))
00507           continue;
00508 
00509         EEDetId eedetidneg(iX,iY,-1);
00510         //APDPNpair.p1 = double(1);
00511         //APDPNpair.p2 = double(1);
00512         hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00513         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00514           laser->setValue(hi, APDPNpair);
00515         } else {
00516               edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;             
00517               continue;
00518         }
00519       }
00520     }
00521     
00522     std::cout << std::endl;
00523     for(int i=0; i<92; i++){
00524       if (i< static_cast<int>(laser->getTimeMap().size())) {
00525         TimeStamp.t1 = edm::Timestamp(1380*(i_run-m_firstRun) + 15*i);
00526         TimeStamp.t2 = edm::Timestamp(1380*(i_run-m_firstRun + 1) + 15*i);
00527         laser->setTime(i, TimeStamp);
00528         //std::cout << " Timestamp for " << i << " : " << TimeStamp.t1.value() << " , " << TimeStamp.t2.value() << std::endl;
00529       } else {
00530         edm::LogError("EcalTestDevDB") << "error with laser Map (time)!" << std::endl;            
00531         continue;
00532       }
00533     }
00534     
00535   }else{
00536 
00537     APDPNpair.p1= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10))))/double(2);
00538     APDPNpair.p2= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10)+double(10))))/double(2);
00539     APDPNpair.p3= double(0);
00540     std::cout << i_run << " " << m_firstRun << " " << APDPNpair.p1 << " " << APDPNpair.p2 << std::endl;
00541 
00542     for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00543       if(iEta==0) continue;
00544       for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00545         EBDetId ebid(iEta,iPhi);
00546         int hi = ebid.hashedIndex();
00547 
00548         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00549           laser->setValue(hi, APDPNpair);
00550         } else {
00551           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00552         }
00553       }
00554     }
00555     for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00556       for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00557         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00558 
00559         if (!EEDetId::validDetId(iX,iY,1))
00560           continue;
00561         
00562         EEDetId eedetidpos(iX,iY,1);    
00563         int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00564         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00565           laser->setValue(hi, APDPNpair);
00566         } else {
00567           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00568           continue;
00569         }
00570         
00571         if (!EEDetId::validDetId(iX,iY,-1))
00572           continue;    
00573         
00574         EEDetId eedetidneg(iX,iY,-1);
00575         hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00576         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00577           laser->setValue(hi, APDPNpair);
00578         } else {
00579           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00580           continue;
00581         }
00582       }           
00583     }
00584  
00585     std::cout << std::endl;
00586     for(int i=0; i<92; i++){
00587       if (i< static_cast<int>(laser->getTimeMap().size())) {
00588         TimeStamp.t1 = edm::Timestamp(1380*(i_run-m_firstRun) + 15*i);
00589         TimeStamp.t2 = edm::Timestamp(1380*(i_run-m_firstRun + 1) + 15*i);
00590         laser->setTime(i, TimeStamp);
00591         //std::cout << " Timestamp for " << i << " : " << TimeStamp.t1.value() << " , " << TimeStamp.t2.value() << std::endl;
00592       } else {
00593         edm::LogError("EcalTestDevDB") << "error with laser Map (time)!" << std::endl;            
00594         continue;
00595       }
00596     }
00597     
00598   }
00599 
00600   return laser;
00601 }
00602 
00603 
00604 //--------------------------------------------------------------
00605 EcalLaserAPDPNRatiosRef*
00606 EcalTestDevDB::generateEcalLaserAPDPNRatiosRef() {
00607 //--------------------------------------------------------------
00608 
00609   EcalLaserAPDPNRatiosRef* laser = new EcalLaserAPDPNRatiosRef();
00610 
00611   EcalLaserAPDPNref APDPNref;
00612  
00613  
00614   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00615     if(iEta==0) continue;
00616     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00617       APDPNref=double(1.5);   
00618       EBDetId ebid(iEta,iPhi);
00619 
00620       int hi = ebid.hashedIndex();
00621       if (hi< static_cast<int>(laser->getMap().size())) {
00622         laser->setValue(hi, APDPNref);
00623       } else {
00624         edm::LogError("EcalTestDevDB") << "error with laser Map (ref)!" << std::endl;             
00625       }
00626       
00627     }
00628   }
00629 
00630   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00631     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00632       
00633       if (!EEDetId::validDetId(iX,iY,1))
00634         continue;         
00635       
00636       EEDetId eedetidpos(iX,iY,1);
00637       APDPNref=double(1.5);
00638       
00639       int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00640       if (hi< static_cast<int>(laser->getMap().size())) {
00641         laser->setValue(hi, APDPNref);
00642       } else {
00643         edm::LogError("EcalTestDevDB") << "error with laser Map (ref)!" << std::endl;             
00644       }
00645       
00646       if (!EEDetId::validDetId(iX,iY,-1))
00647         continue;         
00648   
00649       EEDetId eedetidneg(iX,iY,-1);
00650       APDPNref=double(1.5);
00651       
00652       hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00653       if (hi< static_cast<int>(laser->getMap().size())) {
00654         laser->setValue(hi, APDPNref);
00655       } else {
00656         edm::LogError("EcalTestDevDB") << "error with laser Map (ref)!" << std::endl;             
00657       }
00658     }   
00659   }
00660 
00661   return laser;
00662 }
00663 
00664 //--------------------------------------------------------------
00665 EcalLaserAlphas*
00666 EcalTestDevDB::generateEcalLaserAlphas() {
00667 //--------------------------------------------------------------
00668 
00669   EcalLaserAlphas* laser = new EcalLaserAlphas();
00670 
00671   EcalLaserAlpha Alpha;
00672  
00673   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00674     if(iEta==0) continue;
00675     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00676       Alpha = double(1.55);
00677       EBDetId ebid(iEta,iPhi);
00678 
00679       int hi = ebid.hashedIndex();
00680       if (hi< static_cast<int>(laser->getMap().size())) {
00681         laser->setValue(hi, Alpha);
00682       } else {
00683         edm::LogError("EcalTestDevDB") << "error with laser Map (alpha)!" << std::endl;                 
00684       }
00685     }
00686   }
00687 
00688   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00689     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00690 
00691       if (!EEDetId::validDetId(iX,iY,1))
00692         continue;         
00693 
00694       EEDetId eedetidpos(iX,iY,1);
00695       Alpha = double(1.55);
00696       
00697       int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00698       if (hi< static_cast<int>(laser->getMap().size())) {
00699         laser->setValue(hi, Alpha);
00700       } else {
00701         edm::LogError("EcalTestDevDB") << "error with laser Map (alpha)!" << std::endl;           
00702       }
00703       
00704       if (!EEDetId::validDetId(iX,iY,-1))
00705         continue;         
00706       EEDetId eedetidneg(iX,iY,-1);
00707       Alpha = double(1.55);
00708       
00709       hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00710       if (hi< static_cast<int>(laser->getMap().size())) {
00711         laser->setValue(hi, Alpha);
00712       } else {
00713         edm::LogError("EcalTestDevDB") << "error with laser Map (alpha)!" << std::endl;           
00714       }
00715     }
00716   }
00717   
00718   return laser;
00719 }