CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Calibration/HcalConnectivity/src/HcalCableMapper.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00006 #include <iostream>
00007 #include <cstdio>
00008 
00009 using namespace std;
00010 
00011 /*$Date: 2012/01/11 16:20:48 $
00012 version 3.1 02-13-07 
00013 
00014 author Kevin Klapoetke - Minnesota*/
00015 
00016 class HcalCableMapper : public edm::EDAnalyzer {
00017 public:
00018   explicit HcalCableMapper(edm::ParameterSet const& conf);
00019   virtual void analyze(edm::Event const& e, edm::EventSetup const& c);
00020   virtual void endJob ();
00021   //std::string sourceDigi_;
00022 private:
00023   typedef std::vector<HcalQIESample> SampleSet;
00024   
00025   typedef std::map<HcalDetId,SampleSet> PathSet;
00026   typedef std::map<HcalDetId,HcalElectronicsId> IdMap;
00027   
00028   void process(const PathSet& ps, const IdMap& im);
00029   
00030   
00031 
00032 
00033   std::map<HcalDetId,std::vector<SampleSet> > fullHistory_;
00034   IdMap IdSet;
00035   edm::InputTag hbheLabel_,hoLabel_,hfLabel_;
00036 
00037   template <class DigiCollection>
00038   void record(const DigiCollection& digis) {
00039 
00040     for (typename DigiCollection::const_iterator digi=digis.begin(); digi!=digis.end(); digi++) {
00041 
00042       SampleSet q;
00043       for (int i=0; i<digi->size(); i++)
00044         q.push_back(digi->sample(i));
00045       
00046       if (fullHistory_.find(digi->id())==fullHistory_.end()) fullHistory_.insert(std::pair<HcalDetId,std::vector<SampleSet> >(digi->id(),std::vector<SampleSet>()));
00047       if (IdSet.find(digi->id())==IdSet.end()) IdSet.insert(std::pair<HcalDetId,HcalElectronicsId>(digi->id(),HcalElectronicsId())); 
00048       fullHistory_[digi->id()].push_back(q);
00049       IdSet[digi->id()]=digi->elecId();
00050     }
00051   }
00052 
00053 
00054 };
00055 
00056 
00057 HcalCableMapper::HcalCableMapper(edm::ParameterSet const& conf) :
00058   hbheLabel_(conf.getParameter<edm::InputTag>("hbheLabel")),
00059   hoLabel_(conf.getParameter<edm::InputTag>("hoLabel")),
00060   hfLabel_(conf.getParameter<edm::InputTag>("hfLabel")){
00061   
00062 }
00063 
00064 static const char* det_names[] = {"Zero","HcalBarrel","HcalEndcap","HcalForward","HcalOuter"};
00065 
00066 
00067 
00068 void HcalCableMapper::process(const PathSet& ps, const IdMap& im){
00069   
00070   PathSet::const_iterator iii;
00071   IdMap::const_iterator ij;
00072   
00073   for (iii=ps.begin();iii!=ps.end();iii++){
00074     
00075     
00076     SampleSet ss = iii->second;
00077     const HcalDetId dd = iii->first;
00078     
00079     ij=im.find(dd);
00080     HcalElectronicsId eid=ij->second;
00081 
00082     int header = ((ss[0].adc())&0x7F);
00083     int ieta  = ((ss[1].adc())&0x3F);
00084     int z_ieta = (((ss[1].adc())>>6)&0x1);
00085     int iphi = ((ss[2].adc())&0x7F);
00086     int depth = ((ss[3].adc())&0x7);
00087     int det = (((ss[3].adc())>>3)&0xF);
00088     int spigot = ((ss[4].adc())&0xF);
00089     int fiber = (((ss[4].adc())>>4)&0x7);
00090     int crate  = ((ss[5].adc())&0x1F);
00091     int fiber_chan= (((ss[5].adc())>>5)&0x3);
00092     int G_Dcc  = ((ss[6].adc())&0x3F);
00093     int H_slot  = ((ss[7].adc())&0x1F);
00094     int TB = (((ss[7].adc())>>5)&0x1);
00095     int RBX_7 = (((ss[7].adc())>>6)&0x1);
00096     int RBX = ((ss[8].adc())&0x7F);
00097     int RM = ((ss[9].adc())&0x3);
00098     int RM_card= (((ss[9].adc())>>2)&0x3);
00099     int RM_chan= (((ss[9].adc())>>4)&0x7);
00100     string eta_sign;
00101     std::string det_name;
00102     if (det>4 || det<0) {
00103       char c[20];
00104       snprintf(c,20,"Det=%d",det);
00105       det_name=c;
00106     } else det_name=det_names[det];
00107     
00108     
00109     if (z_ieta==1){
00110       eta_sign = "+";
00111     }else{eta_sign = "-";}
00112     string is_header;
00113     if (header == 0x75){
00114      
00115       //NO SHIFT
00116       if((spigot==eid.spigot())&&(fiber+1==eid.fiberIndex())&&(fiber_chan==eid.fiberChanId())&&(H_slot==eid.htrSlot())&&(G_Dcc==eid.dccid())&&(crate==eid.readoutVMECrateId())&&(iphi==dd.iphi())&&(depth==dd.depth())&&(ieta==dd.ietaAbs())&&(TB==eid.htrTopBottom())&&(det==dd.subdet())){//&&(z_ieta==dd.zside())
00117         std::cout <<"Pathway match"<<std::endl;
00118       }else{
00119         
00120         is_header=" Header found";
00121         
00122         std::cout <<" Digi ID: " << dd << is_header<< " ieta: "<< eta_sign << ieta << " iphi: "<< iphi << " Depth: " << depth << " Detector: " << det_name << " Spigot: "<< spigot<<"/"<<eid.spigot() << " Fiber: " << fiber+1<<"/"<<eid.fiberIndex() << " Fiber Channel: "<< fiber_chan <<"/"<<eid.fiberChanId()<< " Crate: " << crate<<"/"<<eid.readoutVMECrateId() << " Global Dcc: " << G_Dcc <<"/"<<eid.dccid() << " HTR Slot: " << H_slot <<"/ " <<eid.htrSlot()<< " Top/Bottom: " << TB<<"/"<< eid.htrTopBottom() << " RBX: " << (RBX_7*128+RBX) << " RM: " << RM+1 << " RM Card: " << RM_card+1 << " RM Channel: " << RM_chan << std::endl;
00123       }    
00124     }else if (ieta+64==0x75){
00125       
00126       ieta  = ((ss[2].adc())&0x3F);
00127       z_ieta = (((ss[2].adc())>>6)&0x1);
00128       iphi = ((ss[3].adc())&0x7F);
00129       depth = ((ss[4].adc())&0x7);
00130       det = (((ss[4].adc())>>3)&0xF);
00131       spigot = ((ss[5].adc())&0xF);
00132       fiber = (((ss[5].adc())>>4)&0x7);
00133       crate  = ((ss[6].adc())&0x1F);
00134       fiber_chan= (((ss[6].adc())>>5)&0x3);
00135       G_Dcc  = ((ss[7].adc())&0x3F);
00136       H_slot  = ((ss[8].adc())&0x1F);
00137       TB = (((ss[8].adc())>>5)&0x1);
00138       RBX_7 = (((ss[8].adc())>>6)&0x1);
00139       RBX = ((ss[9].adc())&0x7F);
00140       
00141 
00142       //SHIFT
00143         if((spigot==eid.spigot())&&(fiber+1==eid.fiberIndex())&&(fiber_chan==eid.fiberChanId())&&(H_slot==eid.htrSlot())&&(G_Dcc==eid.dccid())&&(TB==eid.htrTopBottom())&&(crate==eid.readoutVMECrateId())&&(iphi==dd.iphi())&&(depth==dd.depth())&&(det==dd.subdet())&&(ieta==dd.ietaAbs())){//&&(z_ieta==dd.zside())
00144 
00145         std::cout <<"Pathway match (SHIFT)"<<std::endl;
00146       }else{
00147 
00148 
00149       is_header=" DATA SHIFT";
00150       
00151      std::cout <<" Digi ID: " << dd << is_header<< " ieta: "<< eta_sign << ieta << " iphi: "<< iphi << " Depth: " << depth << " Detector: " << det_name << " Spigot: "<< spigot<<"/"<<eid.spigot() << " Fiber: " << fiber+1<<"/"<<eid.fiberIndex() << " Fiber Channel: "<< fiber_chan <<"/"<<eid.fiberChanId()<< " Crate: " << crate<<"/"<<eid.readoutVMECrateId() << " Global Dcc: " << G_Dcc <<"/"<<eid.dccid() << " HTR Slot: " << H_slot <<"/ " <<eid.htrSlot()<< " Top/Bottom: " << TB<<"/"<< eid.htrTopBottom() << " RBX: " << (RBX_7*128+RBX) << std::endl;
00152       
00153         }
00154     }else { std::cout<<" Digi ID: " <<dd << " +NO HEADER+  " << " RBX: " << (RBX_7*128+RBX) << std::endl;
00155     }
00156   }
00157 }
00158 
00159 
00160 void HcalCableMapper::analyze(edm::Event const& e, edm::EventSetup const& c) {
00161    
00162   edm::Handle<HBHEDigiCollection> hbhe;
00163   e.getByLabel(hbheLabel_,hbhe);
00164 
00165   edm::Handle<HFDigiCollection> hf;
00166   e.getByLabel(hfLabel_,hf);
00167   edm::Handle<HODigiCollection> ho;
00168   e.getByLabel(hoLabel_,ho);
00169   
00170    
00171   record(*hbhe);
00172   record(*hf);  
00173   record(*ho);
00174 }
00175 
00176 
00177 
00178 
00179 void HcalCableMapper::endJob(){
00180   
00181   
00182   std::vector<SampleSet>::iterator j; 
00183   int c [128];
00184   int k,ii,kk;
00185   int c_max=0;
00186   
00187   std::map<HcalDetId,std::vector<SampleSet> >::iterator i;
00188   
00189   PathSet consensus;
00190  
00191   for (i=fullHistory_.begin(); i!=fullHistory_.end(); i++) {
00192     //i.first --> id
00193     //i.second --> vector<SampleSet>
00194     SampleSet s;
00195     for (k=0; k<10; k++) {
00196       for (ii=0; ii<128; ii++) c[ii]=0;
00197 
00198       for (j=i->second.begin();j!=i->second.end();j++){//word number
00199         if (int(j->size())>k) 
00200           c[(*j)[k].adc()]++;
00201         
00202     
00203       }//j loop
00204       //sort c-array
00205       for (kk=0;kk<128;kk++){  
00206         if (c[kk]>c[c_max]){
00207           c_max = kk;
00208         }
00209       }    
00210       
00211       s.push_back(((c_max&0x7F)));
00212 
00213       c_max=0;
00214     }//k-loop    
00215   consensus[i->first]=s;
00216   
00217   }//i loop
00218  
00219   process(consensus,IdSet);
00220     
00221    
00222 
00223 
00224 
00225 }//end of endjob 
00226   
00227 
00228 
00229 
00230 #include "FWCore/PluginManager/interface/ModuleDef.h"
00231 #include "FWCore/Framework/interface/MakerMacros.h"
00232 
00233 
00234 DEFINE_FWK_MODULE(HcalCableMapper);
00235