CMS 3D CMS Logo

EcalUnpackerWorker.h

Go to the documentation of this file.
00001 #ifndef EcalUnpackerWorker_H
00002 #define EcalUnpackerWorker_H
00003 
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00006 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "EventFilter/EcalRawToDigiDev/interface/DCCDataUnpacker.h"
00010 #include "EventFilter/EcalRawToDigiDev/interface/EcalElectronicsMapper.h"
00011 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00012 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00013 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00014 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitRecWeightsAlgo.h"
00015 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
00016 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
00017 #include "CondFormats/EcalObjects/interface/EcalWeightXtalGroups.h"
00018 #include "CondFormats/EcalObjects/interface/EcalTBWeights.h"
00019 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalRecHitAbsAlgo.h"
00020 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00021 #include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
00022 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00023 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
00024 #include "EventFilter/EcalRawToDigi/interface/EcalUnpackerWorkerRecord.h"
00025 #include "EventFilter/EcalRawToDigi/interface/EcalRegionCabling.h"
00026 
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 
00029 #include "EventFilter/EcalRawToDigi/interface/MyWatcher.h"
00030 
00031 //forward declaration. just to be friend
00032 class EcalRawToRecHitByproductProducer;
00033 
00034 class EcalUnpackerWorker {
00035  public:
00036 
00037   EcalUnpackerWorker(const edm::ParameterSet & conf);
00038   
00039   ~EcalUnpackerWorker();
00040   
00041   // the method that does it all
00042   std::auto_ptr<EcalRecHitCollection> work(const uint32_t & i, const FEDRawDataCollection&) const;
00043   
00044   // method to set things up once per event
00045   void update(const edm::Event & e) const;
00046   
00047   void write(edm::Event &e) const;
00048 
00049   void setHandles(const EcalUnpackerWorkerRecord & iRecord);
00050   
00051  private:
00052 
00053   mutable const edm::Event * evt;
00054 
00055   DCCDataUnpacker * unpacker_;
00056 
00057   EcalElectronicsMapper * myMap_;
00058   mutable std::auto_ptr<EBDigiCollection> productDigisEB;
00059   mutable std::auto_ptr<EEDigiCollection> productDigisEE;
00060 
00061   friend class EcalRawToRecHitByproductProducer;
00062   mutable std::auto_ptr<EcalRawDataCollection> productDccHeaders;
00063   mutable std::auto_ptr< EBDetIdCollection> productInvalidGains;
00064   mutable std::auto_ptr< EBDetIdCollection> productInvalidGainsSwitch;
00065   mutable std::auto_ptr< EBDetIdCollection> productInvalidChIds;
00066   mutable std::auto_ptr< EEDetIdCollection> productInvalidEEGains;
00067   mutable std::auto_ptr<EEDetIdCollection> productInvalidEEGainsSwitch;
00068   mutable std::auto_ptr<EEDetIdCollection> productInvalidEEChIds;
00069   mutable std::auto_ptr<EBSrFlagCollection> productEBSrFlags;
00070   mutable std::auto_ptr<EESrFlagCollection> productEESrFlags;
00071   mutable std::auto_ptr<EcalTrigPrimDigiCollection> productTps;
00072   mutable std::auto_ptr<EcalElectronicsIdCollection> productInvalidTTIds;
00073   mutable std::auto_ptr<EcalElectronicsIdCollection> productInvalidBlockLengths;
00074   mutable std::auto_ptr<EcalPnDiodeDigiCollection> productPnDiodeDigis;
00075   mutable std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemTtIds;
00076   mutable std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemBlockSizes;
00077   mutable std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemChIds;
00078   mutable std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemGains;
00079 
00080   edm::ESHandle<EcalRegionCabling> cabling;  
00081 
00082   EcalUncalibRecHitRecWeightsAlgo<EBDataFrame> * uncalibMaker_barrel_;
00083   EcalUncalibRecHitRecWeightsAlgo<EEDataFrame> * uncalibMaker_endcap_;
00084 
00085   edm::ESHandle<EcalPedestals> peds;
00086   edm::ESHandle<EcalGainRatios>  gains;
00087   edm::ESHandle<EcalWeightXtalGroups>  grps;
00088   edm::ESHandle<EcalTBWeights> wgts;
00089 
00090   EcalRecHitAbsAlgo * rechitMaker_;
00091 
00092   edm::ESHandle<EcalIntercalibConstants> ical;
00093   edm::ESHandle<EcalADCToGeVConstant> agc;
00094   edm::ESHandle<EcalChannelStatus> chStatus;
00095   std::vector<int> v_chstatus_;
00096   edm::ESHandle<EcalLaserDbService> laser;
00097 
00098  public:
00099 
00100   template <class DID> void work(EcalDigiCollection::const_iterator & beginDigi,
00101                                  EcalDigiCollection::const_iterator & endDigi,
00102                                  std::auto_ptr<EcalUncalibratedRecHitCollection> & uncalibRecHits,
00103                                  std::auto_ptr< EcalRecHitCollection > & calibRechits)const{
00104     MyWatcher watcher("<Worker>");
00105     LogDebug("EcalRawToRecHit|Worker")<<"ready to work on digis."<<watcher.lap();
00106 
00107     EcalDigiCollection::const_iterator itdg = beginDigi;
00108     /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"iterator check." ;
00109     EcalTBWeights::EcalTBWeightMap const & wgtsMap = wgts->getMap();
00110     /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"weight map check."<<watcher.lap();
00111 
00112 
00113     
00114     //for the uncalibrated rechits
00115     const EcalPedestals::Item* aped = 0;
00116     const EcalMGPAGainRatio* aGain = 0;
00117     const EcalXtalGroupId * gid = 0;
00118     double pedVec[3];
00119     double gainRatios[3];
00120     // use a fake TDC iD for now until it become available in raw data
00121     EcalTBWeights::EcalTDCId tdcid(1);
00122     const EcalWeightSet::EcalWeightMatrix* weights[2];
00123     const EcalWeightSet::EcalChi2WeightMatrix* chi2mat[2];
00124 
00125     //for the calibrated rechits.
00126     const EcalIntercalibConstantMap& icalMap=ical->getMap();  
00127     if (DID::subdet()==EcalEndcap){ 
00128       rechitMaker_->setADCToGeVConstant(float(agc->getEEValue())); 
00129       /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"ADCtoGeV constant set in EE: "<<agc->getEEValue() 
00130                                               <<watcher.lap(); 
00131     } 
00132     else{ 
00133       rechitMaker_->setADCToGeVConstant(float(agc->getEBValue())); 
00134       /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"ADCtoGeV constant set in EB: "<<agc->getEBValue() 
00135                                               <<watcher.lap(); 
00136     } 
00137 
00138     for(; itdg != endDigi; ++itdg) 
00139       {
00140         /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"starting dealing with one digi." 
00141                                                 <<watcher.lap();
00142         DID detid(itdg->id());
00143 
00144         //check if the channel is masked
00145         EcalChannelStatusMap::const_iterator chit = chStatus->find(itdg->id());
00146         EcalChannelStatusCode chStatusCode = 1;
00147         if ( chit != chStatus->end() ) {
00148           chStatusCode = *chit;
00149         } else {
00150           edm::LogError("EcalRawToRecHit|Worker") << "No channel status found for xtal " << detid << "! something wrong with EcalChannelStatus in your DB? ";
00151           continue;
00152         }
00153         if ( v_chstatus_.size() > 0) {
00154           std::vector<int>::const_iterator res = std::find( v_chstatus_.begin(), v_chstatus_.end(), chStatusCode.getStatusCode() );
00155           if ( res != v_chstatus_.end() ) {
00156             continue;
00157           }
00158         }
00159         
00160 
00161         //get the uncalibrated rechit
00162         EcalUncalibratedRecHit EURH;
00163         {
00164           unsigned int hashedIndex = detid.hashedIndex();
00165           // ### pedestal and gain first and groupid
00166           if (DID::subdet()==EcalEndcap){
00167             /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"EndCap id, getting pedestals, gains and group id.\n"
00168                                                     <<"detid: "<<detid<<"\n has hashed index: "<<hashedIndex
00169                                                     <<watcher.lap();
00170             aped=&peds->endcap(hashedIndex);
00171             aGain=&gains->endcap(hashedIndex);
00172             gid=&grps->endcap(hashedIndex);}
00173           else {
00174             /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"Barrel id, getting pedestals, gains and group id.\n"
00175                                                     <<"detid: "<<detid<<"\n has hashed index: "<<hashedIndex
00176                                                     <<watcher.lap();
00177             aped=&peds->barrel(hashedIndex);
00178             aGain=&gains->barrel(hashedIndex);
00179             gid=&grps->barrel(hashedIndex);}
00180           
00181           pedVec[0]=aped->mean_x12;pedVec[1]=aped->mean_x6;pedVec[2]=aped->mean_x1;
00182           gainRatios[0]=1.;gainRatios[1]=aGain->gain12Over6();gainRatios[2]=aGain->gain6Over1()*aGain->gain12Over6();
00183           /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"peds and gains loaded.";
00184           
00185         
00186           // now lookup the correct weights in the map
00187           EcalTBWeights::EcalTBWeightMap::const_iterator wit;
00188           wit = wgtsMap.find( std::make_pair(*gid,tdcid) );
00189           if( wit == wgtsMap.end() ) {
00190             edm::LogError("EcalUncalibRecHitError") << "No weights found for EcalGroupId: " << gid->id() << " and  EcalTDCId: " << tdcid
00191                                                     << "\n  skipping digi with id: " << detid
00192                                                     <<watcher.lap();
00193             /*R*/ LogDebug("EcalUncalibRecHitError") << "No weights found for EcalGroupId: " << gid->id() << " and  EcalTDCId: " << tdcid
00194                                                      << "\n  skipping digi with id: " << detid
00195                                                      <<watcher.lap();
00196             continue;
00197           }
00198           const EcalWeightSet& wset = wit->second; // this is the EcalWeightSet
00199           
00200           const EcalWeightSet::EcalWeightMatrix& mat1 = wset.getWeightsBeforeGainSwitch();
00201           const EcalWeightSet::EcalWeightMatrix& mat2 = wset.getWeightsAfterGainSwitch();
00202           const EcalWeightSet::EcalChi2WeightMatrix& mat3 = wset.getChi2WeightsBeforeGainSwitch();
00203           const EcalWeightSet::EcalChi2WeightMatrix& mat4 = wset.getChi2WeightsAfterGainSwitch();
00204           
00205           weights[0]=&mat1;
00206           weights[1]=&mat2;
00207           
00208           chi2mat[0]=&mat3;
00209           chi2mat[1]=&mat4;
00210           /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"weights loaded."
00211                                                   <<"creating an unaclibrated rechit."
00212                                                   <<watcher.lap();
00213         if (DID::subdet()==EcalEndcap)
00214           EURH = uncalibMaker_endcap_->makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat);
00215         else
00216           EURH = uncalibMaker_barrel_->makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat);
00217         uncalibRecHits->push_back(EURH);
00218         /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"created."
00219                                                 <<watcher.lap();
00220         }//uncalib rechits
00221     
00222         //######### get the rechit #########
00223         {
00224           // first intercalibration constants
00225           EcalIntercalibConstantMap::const_iterator icalit=icalMap.find(detid);
00226           EcalIntercalibConstant icalconst = 1;
00227           if( icalit!=icalMap.end() ){
00228             icalconst = (*icalit);
00229           } else {
00230             edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << detid<< "! something wrong with EcalIntercalibConstants in your DB? ";
00231             LogDebug("EcalRecHitError") << "No intercalib const found for xtal " << detid<< "! something wrong with EcalIntercalibConstants in your DB? ";
00232           }
00233           /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"intercalibration constant loaded."
00234                                                   <<watcher.lap();
00235 
00236           // get laser coefficient
00237           float lasercalib = laser->getLaserCorrection( detid, evt->time());
00238           /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"laser correction diode."
00239                                                   <<watcher.lap();
00240       
00241           // make the rechit and put in the output collection
00242           /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"creating a rechit."
00243                                                   <<watcher.lap();
00244           calibRechits->push_back(EcalRecHit( rechitMaker_->makeRecHit(EURH, icalconst * lasercalib) ));
00245           /*R*/ LogDebug("EcalRawToRecHit|Worker")<<"created."
00246                                                   <<watcher.lap();
00247         }//get the rechit
00248 
00249       }//loop over digis
00250   }
00251 
00252 };
00253 
00254 
00255 #endif

Generated on Tue Jun 9 17:34:32 2009 for CMSSW by  doxygen 1.5.4