CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:25:38 2009 for CMSSW by  doxygen 1.5.4