CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/L1Trigger/HardwareValidation/src/L1Comparator.cc

Go to the documentation of this file.
00001 #include "L1Trigger/HardwareValidation/interface/L1Comparator.h"
00002 #include "FWCore/Framework/interface/ESHandle.h"
00003 
00004 using namespace dedefs;
00005 
00006 L1Comparator::L1Comparator(const edm::ParameterSet& iConfig) {
00007 
00008   verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag",0);
00009 
00010   if(verbose())
00011     std::cout << "\nL1COMPARATOR constructor...\n" << std::flush;
00012 
00013   std::vector<unsigned int> dosys(0,DEnsys); 
00014   dosys = 
00015     iConfig.getUntrackedParameter<std::vector<unsigned int> >("COMPARE_COLLS", dosys);
00016   
00017   if((int)dosys.size()!=DEnsys)
00018     edm::LogError("L1Comparator") 
00019       << "wrong selection of systems to be compared\n"
00020       << "\t the size of the mask COMPARE_COLLS (" << dosys.size() 
00021       << ") is not " << DEnsys << std::endl;
00022   assert((int)dosys.size()==DEnsys);
00023   
00024   for(int isys=0; isys<DEnsys; isys++)
00025     if( dosys[isys]!=0 && dosys[isys]!=1 ) 
00026       throw cms::Exception("Invalid configuration") 
00027         << "L1Comparator: comparison flag for system " << isys 
00028         << " is non boolean: " << dosys[isys] << ". Exiting.\n";
00029     
00030   for(int i=0; i<DEnsys; i++)
00031     m_doSys[i] = dosys[i];
00032   
00033   if(verbose()) {
00034     std::cout << "[L1Comparator] do sys? ";
00035     for(int i=0; i<DEnsys; i++)
00036       std::cout << m_doSys[i] << " ";
00037     std::cout << std::endl;
00038 
00039     std::cout << "[L1Comparator] list of systems to process: ";
00040     for(int i=0; i<DEnsys; i++) 
00041       if(m_doSys[i]) 
00042         std::cout << SystLabel[i] << " ";
00043     std::cout << std::endl;
00044   }
00045 
00047   assert(ETP==0); assert(HTP==1); assert(RCT== 2); assert(GCT== 3);
00048   assert(DTP==4); assert(DTF==5); assert(CTP== 6); assert(CTF== 7);
00049   assert(RPC==8); assert(LTC==9); assert(GMT==10); assert(GLT==11);
00050 
00051   if(verbose())
00052     std::cout << "[L1Comparator] debug print collection labels\n";
00053 
00054   m_DEsource[ETP][0] = iConfig.getParameter<edm::InputTag>("ETPsourceData");
00055   m_DEsource[ETP][1] = iConfig.getParameter<edm::InputTag>("ETPsourceEmul");
00056   m_DEsource[HTP][0] = iConfig.getParameter<edm::InputTag>("HTPsourceData");
00057   m_DEsource[HTP][1] = iConfig.getParameter<edm::InputTag>("HTPsourceEmul");
00058   m_DEsource[RCT][0] = iConfig.getParameter<edm::InputTag>("RCTsourceData");
00059   m_DEsource[RCT][1] = iConfig.getParameter<edm::InputTag>("RCTsourceEmul");
00060   m_DEsource[GCT][0] = iConfig.getParameter<edm::InputTag>("GCTsourceData");
00061   m_DEsource[GCT][1] = iConfig.getParameter<edm::InputTag>("GCTsourceEmul");
00062   m_DEsource[DTP][0] = iConfig.getParameter<edm::InputTag>("DTPsourceData");
00063   m_DEsource[DTP][1] = iConfig.getParameter<edm::InputTag>("DTPsourceEmul");
00064   m_DEsource[DTF][0] = iConfig.getParameter<edm::InputTag>("DTFsourceData");
00065   m_DEsource[DTF][1] = iConfig.getParameter<edm::InputTag>("DTFsourceEmul");
00066   m_DEsource[CTP][0] = iConfig.getParameter<edm::InputTag>("CTPsourceData");
00067   m_DEsource[CTP][1] = iConfig.getParameter<edm::InputTag>("CTPsourceEmul");
00068   m_DEsource[CTF][0] = iConfig.getParameter<edm::InputTag>("CTFsourceData");
00069   m_DEsource[CTF][1] = iConfig.getParameter<edm::InputTag>("CTFsourceEmul");
00070   m_DEsource[CTF][2] = iConfig.getParameter<edm::InputTag>("CTTsourceData");
00071   m_DEsource[CTF][3] = iConfig.getParameter<edm::InputTag>("CTTsourceEmul");
00072   m_DEsource[RPC][0] = iConfig.getParameter<edm::InputTag>("RPCsourceData");
00073   m_DEsource[RPC][1] = iConfig.getParameter<edm::InputTag>("RPCsourceEmul");
00074   m_DEsource[LTC][0] = iConfig.getParameter<edm::InputTag>("LTCsourceData");
00075   m_DEsource[LTC][1] = iConfig.getParameter<edm::InputTag>("LTCsourceEmul");
00076   m_DEsource[GMT][0] = iConfig.getParameter<edm::InputTag>("GMTsourceData");
00077   m_DEsource[GMT][1] = iConfig.getParameter<edm::InputTag>("GMTsourceEmul");
00078   m_DEsource[GLT][0] = iConfig.getParameter<edm::InputTag>("GLTsourceData");
00079   m_DEsource[GLT][1] = iConfig.getParameter<edm::InputTag>("GLTsourceEmul");
00080 
00081   for(int sys=0; sys<DEnsys; sys++) {
00082     std::string data_label = SystLabel[sys] + "sourceData";
00083     std::string emul_label = SystLabel[sys] + "sourceEmul";
00084     //m_DEsource[sys][0] = iConfig.getParameter<edm::InputTag>(data_label);
00085     //m_DEsource[sys][1] = iConfig.getParameter<edm::InputTag>(emul_label);
00086     //if(sys==CTF) {
00087     //  std::string data_label(""); data_label+="CTTsourceData";
00088     //  std::string emul_label(""); emul_label+="CTTsourceEmul";
00089     //  m_DEsource[sys][2] = iConfig.getParameter<edm::InputTag>(data_label);
00090     //  m_DEsource[sys][3] = iConfig.getParameter<edm::InputTag>(emul_label);
00091     //}
00092     if(m_doSys[sys] && verbose()) {
00093       std::cout << " sys:"   << sys << " label:" << SystLabel[sys]  
00094                 << "\n\tdt:" << data_label << " : " <<m_DEsource[sys][0]
00095                 << "\n\tem:" << emul_label << " : " <<m_DEsource[sys][1]
00096                 << std::endl;
00097       if(sys==CTF) {
00098         std::cout << "\tdt:"     << data_label << " : " <<m_DEsource[sys][2]
00099                   << "\n\tem:" << emul_label << " : " <<m_DEsource[sys][3]
00100                   << std::endl;
00101       }
00102     }
00103   }
00104 
00105   
00106   m_fedId = iConfig.getUntrackedParameter<int>("FEDid", 0);
00107   m_FEDsource[0] = 
00108     iConfig.getUntrackedParameter<edm::InputTag>("FEDsourceData",edm::InputTag());
00109   m_FEDsource[1] = 
00110     iConfig.getUntrackedParameter<edm::InputTag>("FEDsourceEmul",edm::InputTag());
00111 
00112 
00114   m_dumpMode = iConfig.getUntrackedParameter<int>("DumpMode",0);  
00115   m_dumpFileName = iConfig.getUntrackedParameter<std::string>("DumpFile","");
00116   if(m_dumpMode) {
00117     m_dumpFile.open(m_dumpFileName.c_str(), std::ios::out);
00118     if(!m_dumpFile.good())
00119       edm::LogInfo("L1ComparatorDumpFileOpenError")
00120         << " L1Comparator::L1Comparator() : "
00121         << " couldn't open dump file " << m_dumpFileName.c_str() << std::endl;
00122   }
00123 
00124   m_match = true;
00125   dumpEvent_ = true;
00126   nevt_=-1;
00127 
00128   for(int i=0; i<DEnsys; i++) {
00129     for(int j=0; j<2; j++) 
00130       DEncand[i][j] = 0;
00131     DEmatchEvt[i] = true;
00132   }
00133 
00134   m_dedigis.clear();
00136   produces<L1DataEmulRecord>().setBranchAlias("L1DataEmulRecord");  
00137 
00138   if(verbose())
00139     std::cout << "\nL1Comparator constructor...done.\n" << std::flush;
00140 }
00141 
00142 
00143 L1Comparator::~L1Comparator(){}
00144 
00145 void L1Comparator::beginJob(void) {}
00146 
00147 void L1Comparator::beginRun(edm::Run& iRun, const edm::EventSetup& iSetup) {
00148 
00149   if(verbose())
00150     std::cout << "\nL1COMPARATOR beginRun...\n" << std::flush;
00151 
00152 
00153   // disable subsystem if not included in current run configuration
00154   try 
00155     {
00156       edm::ESHandle< L1TriggerKey > pKey ;
00157       iSetup.get< L1TriggerKeyRcd >().get( pKey ) ;
00158 
00159       m_doSys[RCT] &= (!(pKey->subsystemKey( L1TriggerKey::kRCT)  .empty()));
00160       m_doSys[GCT] &= (!(pKey->subsystemKey( L1TriggerKey::kGCT)  .empty()));
00161       m_doSys[DTF] &= (!(pKey->subsystemKey( L1TriggerKey::kDTTF) .empty()));
00162       m_doSys[CTF] &= (!(pKey->subsystemKey( L1TriggerKey::kCSCTF).empty()));
00163       m_doSys[RPC] &= (!(pKey->subsystemKey( L1TriggerKey::kRPC)  .empty()));
00164       m_doSys[GMT] &= (!(pKey->subsystemKey( L1TriggerKey::kGMT)  .empty()));
00165       m_doSys[GLT] &= (!(pKey->subsystemKey( L1TriggerKey::kGT)   .empty()));
00166 
00167      if(verbose()) {
00168         if ( pKey->subsystemKey( L1TriggerKey::kRCT  ).empty() )
00169           std::cout << "RCT   key is empty. Sub-systems is disabled ("<<m_doSys[RCT]<<")\n";
00170         if ( pKey->subsystemKey( L1TriggerKey::kGCT  ).empty() )
00171           std::cout << "GCT   key is empty. Sub-systems is disabled ("<<m_doSys[GCT]<<")\n";
00172         if ( pKey->subsystemKey( L1TriggerKey::kDTTF ).empty() )
00173           std::cout << "DTTF  key is empty. Sub-systems is disabled ("<<m_doSys[DTF]<<")\n";
00174         if ( pKey->subsystemKey( L1TriggerKey::kCSCTF).empty() )
00175           std::cout << "CSCTF key is empty. Sub-systems is disabled ("<<m_doSys[CTF]<<")\n";
00176         if ( pKey->subsystemKey( L1TriggerKey::kRPC  ).empty() )
00177           std::cout << "RPC   key is empty. Sub-systems is disabled ("<<m_doSys[RPC]<<")\n";
00178         if ( pKey->subsystemKey( L1TriggerKey::kGMT  ).empty() )
00179           std::cout << "GMT   key is empty. Sub-systems is disabled ("<<m_doSys[GMT]<<")\n";
00180         if ( pKey->subsystemKey( L1TriggerKey::kGT   ).empty() )
00181           std::cout << "GT    key is empty. Sub-systems is disabled ("<<m_doSys[GLT]<<")\n";
00182         std::cout << "TSC key = " << pKey->tscKey() << std::endl; 
00183       }
00184 
00185       //access subsystem key if needed, eg:
00186       //std::cout << "RCT key:" << pKey->subsystemKey( L1TriggerKey::kRCT ) << std::endl;
00187     } 
00188   catch( cms::Exception& ex ) 
00189     {
00190       edm::LogWarning("L1Comparator") 
00191         << "No L1TriggerKey found." 
00192         << std::endl;
00193     }  
00194 
00195   if(verbose())
00196     std::cout << "L1COMPARATOR beginRun... done\n" << std::flush;
00197 
00198 }
00199 
00200 void L1Comparator::endJob() {
00201   if(m_dumpMode)
00202     m_dumpFile << "\n\n-------\n"
00203                << "Global data|emulator agreement: " 
00204                << m_match << std::endl;
00205   m_dumpFile.close();
00206 }
00207 
00208 void
00209 L1Comparator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00210 
00211   nevt_++;
00212   evtNum_ = iEvent.id().event();
00213   runNum_ = iEvent.id().run();
00214 
00215   if(verbose())
00216     std::cout << "\nL1COMPARATOR entry:" << nevt_ << " | evt:" << evtNum_ 
00217               << " | run:" << runNum_ << "\n" << std::flush;
00218 
00219   //flag whether event id has already been written to dumpFile
00220   dumpEvent_ = true;
00221 
00222   //reset event holder quantities
00223   for(int i=0; i<DEnsys; i++) {
00224     for(int j=0; j<2; j++) 
00225       DEncand[i][j] = 0;
00226     DEmatchEvt[i] = true;
00227   }
00228   m_dedigis.clear();
00229 
00230 
00232 
00233   // -- ETP [electromagnetic calorimeter trigger primitives]
00234   edm::Handle<EcalTrigPrimDigiCollection> ecal_tp_data;
00235   edm::Handle<EcalTrigPrimDigiCollection> ecal_tp_emul;
00236   if(m_doSys[ETP]) {
00237     iEvent.getByLabel(m_DEsource[ETP][0], ecal_tp_data);
00238     iEvent.getByLabel(m_DEsource[ETP][1], ecal_tp_emul);
00239   }
00240 
00241   // -- HTP [hadronic calorimeter trigger primitives]
00242   edm::Handle<HcalTrigPrimDigiCollection> hcal_tp_data;
00243   edm::Handle<HcalTrigPrimDigiCollection> hcal_tp_emul;
00244   if(m_doSys[HTP]) {
00245     iEvent.getByLabel(m_DEsource[HTP][0], hcal_tp_data);
00246     iEvent.getByLabel(m_DEsource[HTP][1], hcal_tp_emul);
00247   }
00248 
00249   // -- RCT [regional calorimeter trigger]
00250   edm::Handle<L1CaloEmCollection> rct_em_data;
00251   edm::Handle<L1CaloEmCollection> rct_em_emul;
00252   edm::Handle<L1CaloRegionCollection> rct_rgn_data;
00253   edm::Handle<L1CaloRegionCollection> rct_rgn_emul;
00254   if(m_doSys[RCT]) {
00255     iEvent.getByLabel(m_DEsource[RCT][0], rct_em_data);
00256     iEvent.getByLabel(m_DEsource[RCT][1], rct_em_emul);
00257     iEvent.getByLabel(m_DEsource[RCT][0], rct_rgn_data);
00258     iEvent.getByLabel(m_DEsource[RCT][1], rct_rgn_emul);
00259   }
00260 
00261   // -- GCT [global calorimeter trigger]
00262   edm::Handle<L1GctEmCandCollection>  gct_isolaem_data;
00263   edm::Handle<L1GctEmCandCollection>  gct_isolaem_emul;
00264   edm::Handle<L1GctEmCandCollection>  gct_noisoem_data;
00265   edm::Handle<L1GctEmCandCollection>  gct_noisoem_emul;
00266   edm::Handle<L1GctJetCandCollection> gct_cenjets_data;
00267   edm::Handle<L1GctJetCandCollection> gct_cenjets_emul;
00268   edm::Handle<L1GctJetCandCollection> gct_forjets_data;
00269   edm::Handle<L1GctJetCandCollection> gct_forjets_emul;
00270   edm::Handle<L1GctJetCandCollection> gct_taujets_data;
00271   edm::Handle<L1GctJetCandCollection> gct_taujets_emul;
00272 
00273   edm::Handle<L1GctEtHadCollection>       gct_ht_data;
00274   edm::Handle<L1GctEtHadCollection>       gct_ht_emul;
00275   edm::Handle<L1GctEtMissCollection>      gct_etmiss_data;
00276   edm::Handle<L1GctEtMissCollection>      gct_etmiss_emul;
00277   edm::Handle<L1GctEtTotalCollection>     gct_ettota_data;
00278   edm::Handle<L1GctEtTotalCollection>     gct_ettota_emul;
00279   edm::Handle<L1GctHtMissCollection>      gct_htmiss_data;
00280   edm::Handle<L1GctHtMissCollection>      gct_htmiss_emul;
00281   edm::Handle<L1GctHFRingEtSumsCollection>gct_hfring_data;
00282   edm::Handle<L1GctHFRingEtSumsCollection>gct_hfring_emul;
00283   edm::Handle<L1GctHFBitCountsCollection> gct_hfbcnt_data;
00284   edm::Handle<L1GctHFBitCountsCollection> gct_hfbcnt_emul;
00285   edm::Handle<L1GctJetCountsCollection>   gct_jetcnt_data;  
00286   edm::Handle<L1GctJetCountsCollection>   gct_jetcnt_emul;
00287 
00288   if(m_doSys[GCT]) {
00289    iEvent.getByLabel(m_DEsource[GCT][0].label(),"isoEm",   gct_isolaem_data);
00290    iEvent.getByLabel(m_DEsource[GCT][1].label(),"isoEm",   gct_isolaem_emul);
00291    iEvent.getByLabel(m_DEsource[GCT][0].label(),"nonIsoEm",gct_noisoem_data);
00292    iEvent.getByLabel(m_DEsource[GCT][1].label(),"nonIsoEm",gct_noisoem_emul);
00293    iEvent.getByLabel(m_DEsource[GCT][0].label(),"cenJets", gct_cenjets_data);
00294    iEvent.getByLabel(m_DEsource[GCT][1].label(),"cenJets", gct_cenjets_emul);
00295    iEvent.getByLabel(m_DEsource[GCT][0].label(),"forJets", gct_forjets_data);
00296    iEvent.getByLabel(m_DEsource[GCT][1].label(),"forJets", gct_forjets_emul);
00297    iEvent.getByLabel(m_DEsource[GCT][0].label(),"tauJets", gct_taujets_data);
00298    iEvent.getByLabel(m_DEsource[GCT][1].label(),"tauJets", gct_taujets_emul);
00299 
00300    iEvent.getByLabel(m_DEsource[GCT][0],gct_ht_data);     
00301    iEvent.getByLabel(m_DEsource[GCT][1],gct_ht_emul);    
00302    iEvent.getByLabel(m_DEsource[GCT][0],gct_etmiss_data);  
00303    iEvent.getByLabel(m_DEsource[GCT][1],gct_etmiss_emul);
00304    iEvent.getByLabel(m_DEsource[GCT][0],gct_ettota_data);         
00305    iEvent.getByLabel(m_DEsource[GCT][1],gct_ettota_emul); 
00306    iEvent.getByLabel(m_DEsource[GCT][0],gct_htmiss_data);  
00307    iEvent.getByLabel(m_DEsource[GCT][1],gct_htmiss_emul);
00308    iEvent.getByLabel(m_DEsource[GCT][0],gct_hfring_data);
00309    iEvent.getByLabel(m_DEsource[GCT][1],gct_hfring_emul);
00310    iEvent.getByLabel(m_DEsource[GCT][0],gct_hfbcnt_data);
00311    iEvent.getByLabel(m_DEsource[GCT][1],gct_hfbcnt_emul);
00312    iEvent.getByLabel(m_DEsource[GCT][0],gct_jetcnt_data);  
00313    iEvent.getByLabel(m_DEsource[GCT][1],gct_jetcnt_emul);
00314   }
00315 
00316   // -- DTP [drift tube trigger primitive]
00317   edm::Handle<L1MuDTChambPhContainer> dtp_ph_data_;
00318   edm::Handle<L1MuDTChambPhContainer> dtp_ph_emul_;
00319   edm::Handle<L1MuDTChambThContainer> dtp_th_data_;
00320   edm::Handle<L1MuDTChambThContainer> dtp_th_emul_;
00321   if(m_doSys[DTP]) {
00322     iEvent.getByLabel(m_DEsource[DTP][0],dtp_ph_data_);
00323     iEvent.getByLabel(m_DEsource[DTP][1],dtp_ph_emul_);
00324     iEvent.getByLabel(m_DEsource[DTP][0],dtp_th_data_);
00325     iEvent.getByLabel(m_DEsource[DTP][1],dtp_th_emul_);
00326   }
00327   L1MuDTChambPhDigiCollection const* dtp_ph_data = 0; 
00328   L1MuDTChambPhDigiCollection const* dtp_ph_emul = 0; 
00329   L1MuDTChambThDigiCollection const* dtp_th_data = 0; 
00330   L1MuDTChambThDigiCollection const* dtp_th_emul = 0; 
00331 
00332   if(dtp_ph_data_.isValid()) dtp_ph_data = dtp_ph_data_->getContainer();
00333   if(dtp_ph_emul_.isValid()) dtp_ph_emul = dtp_ph_emul_->getContainer();
00334   if(dtp_th_data_.isValid()) dtp_th_data = dtp_th_data_->getContainer();
00335   if(dtp_th_emul_.isValid()) dtp_th_emul = dtp_th_emul_->getContainer();
00336 
00337   // -- DTF [drift tube track finder]
00338   edm::Handle<L1MuRegionalCandCollection> dtf_data;
00339   edm::Handle<L1MuRegionalCandCollection> dtf_emul;
00340   edm::Handle<L1MuDTTrackContainer>       dtf_trk_data_;
00341   edm::Handle<L1MuDTTrackContainer>       dtf_trk_emul_;
00342   L1MuRegionalCandCollection const* dtf_trk_data = 0;
00343   L1MuRegionalCandCollection const* dtf_trk_emul = 0;
00344   if(m_doSys[DTF]) {
00345     iEvent.getByLabel(m_DEsource[DTF][0].label(),"DT",dtf_data);
00346     iEvent.getByLabel(m_DEsource[DTF][1].label(),"DT",dtf_emul);
00347   //iEvent.getByLabel(m_DEsource[DTF][0].label(),"DTTF",dtf_trk_data_);
00348     iEvent.getByLabel(m_DEsource[DTF][0].label(),"DATA",dtf_trk_data_);
00349     iEvent.getByLabel(m_DEsource[DTF][1].label(),"DTTF",dtf_trk_emul_);
00350   } 
00351   //extract the regional cands
00352   typedef std::vector<L1MuDTTrackCand> L1MuDTTrackCandCollection;
00353   L1MuRegionalCandCollection dtf_trk_data_v, dtf_trk_emul_v;
00354   dtf_trk_data_v.clear(); dtf_trk_emul_v.clear();
00355   if(dtf_trk_data_.isValid()) {
00356     L1MuDTTrackCandCollection *dttc = dtf_trk_data_->getContainer();
00357     for(L1MuDTTrackCandCollection::const_iterator  it=dttc->begin(); 
00358         it!=dttc->end(); it++)
00359       dtf_trk_data_v.push_back(L1MuRegionalCand(*it)); 
00360   }
00361   if(dtf_trk_emul_.isValid()) {
00362     L1MuDTTrackCandCollection *dttc = dtf_trk_emul_->getContainer();
00363     for(L1MuDTTrackCandCollection::const_iterator  it=dttc->begin(); 
00364         it!=dttc->end(); it++)
00365       dtf_trk_emul_v.push_back(L1MuRegionalCand(*it)); 
00366   }  
00367   dtf_trk_data =&dtf_trk_data_v;
00368   dtf_trk_emul =&dtf_trk_emul_v;
00369   
00370   // -- CTP [cathode strip chamber trigger primitive]
00371   edm::Handle<CSCALCTDigiCollection>          ctp_ano_data_;
00372   edm::Handle<CSCALCTDigiCollection>          ctp_ano_emul_;
00373   edm::Handle<CSCCLCTDigiCollection>          ctp_cat_data_;
00374   edm::Handle<CSCCLCTDigiCollection>          ctp_cat_emul_;
00375   edm::Handle<CSCCorrelatedLCTDigiCollection> ctp_lct_data_;
00376   edm::Handle<CSCCorrelatedLCTDigiCollection> ctp_lct_emul_;
00377   CSCALCTDigiCollection_          const* ctp_ano_data = 0;
00378   CSCALCTDigiCollection_          const* ctp_ano_emul = 0;
00379   CSCCLCTDigiCollection_          const* ctp_cat_data = 0;
00380   CSCCLCTDigiCollection_          const* ctp_cat_emul = 0;
00381   CSCCorrelatedLCTDigiCollection_ const* ctp_lct_data = 0;
00382   CSCCorrelatedLCTDigiCollection_ const* ctp_lct_emul = 0;
00383   if(m_doSys[CTP]) {
00384     if(m_DEsource[CTP][0].label().find("tf")!=std::string::npos) {
00385       //if correlated LCTs from TF, read needed info from TP data digis
00386       iEvent.getByLabel("muonCSCDigis", "MuonCSCALCTDigi"     ,ctp_ano_data_);
00387       iEvent.getByLabel("muonCSCDigis", "MuonCSCCLCTDigi"     ,ctp_cat_data_);
00388       iEvent.getByLabel(m_DEsource[CTP][0]                    ,ctp_lct_data_);
00389     } else {
00390       iEvent.getByLabel(m_DEsource[CTP][0].label(),"MuonCSCALCTDigi",ctp_ano_data_);
00391       iEvent.getByLabel(m_DEsource[CTP][0].label(),"MuonCSCCLCTDigi",ctp_cat_data_);
00392       iEvent.getByLabel(m_DEsource[CTP][0].label(),"MuonCSCCorrelatedLCTDigi",ctp_lct_data_);
00393     }
00394     iEvent.getByLabel(m_DEsource[CTP][1]                    ,ctp_ano_emul_);
00395     iEvent.getByLabel(m_DEsource[CTP][1]                    ,ctp_cat_emul_);
00396     iEvent.getByLabel(m_DEsource[CTP][1]                    ,ctp_lct_emul_);
00397   }
00398 
00400   //Anode LCT
00401   CSCALCTDigiCollection_ ctp_ano_data_v, ctp_ano_emul_v;
00402   ctp_ano_data_v.clear(); ctp_ano_emul_v.clear();
00403   if(ctp_ano_data_.isValid() && ctp_ano_emul_.isValid()) {
00404     // The following numbers should come from config. database eventually...
00405     int fifo_pretrig     = 10;
00406     int fpga_latency     =  6;
00407     int l1a_window_width =  7;
00408     // Time offset of raw hits w.r.t. the full 12-bit BXN.
00409     int rawhit_tbin_offset =
00410       (fifo_pretrig - fpga_latency) + (l1a_window_width-1)/2;
00411     // Extra difference due to additional register stages; determined
00412     // empirically.
00413     int register_delay =  2;
00414     typedef CSCALCTDigiCollection::DigiRangeIterator mapIt;
00415     typedef CSCALCTDigiCollection::const_iterator    vecIt;
00416     for (mapIt mit = ctp_ano_data_->begin(); mit != ctp_ano_data_->end(); mit++)
00417       for (vecIt vit = ctp_ano_data_->get((*mit).first).first; 
00418            vit != ctp_ano_data_->get((*mit).first).second; vit++) 
00419         ctp_ano_data_v.push_back(*vit);
00420     for (mapIt mit = ctp_ano_emul_->begin(); mit != ctp_ano_emul_->end(); mit++)
00421       for (vecIt vit = ctp_ano_emul_->get((*mit).first).first; 
00422            vit != ctp_ano_emul_->get((*mit).first).second; vit++) {
00423         int emul_bx_corr =
00424           (*vit).getBX() - rawhit_tbin_offset + register_delay;
00425         CSCALCTDigi alct((*vit).isValid(),        (*vit).getQuality(),
00426                          (*vit).getAccelerator(), (*vit).getCollisionB(),
00427                          (*vit).getKeyWG(),       emul_bx_corr,
00428                          (*vit).getTrknmb()); 
00429         ctp_ano_emul_v.push_back(alct);
00430       }
00431   }
00432   ctp_ano_data =&ctp_ano_data_v;
00433   ctp_ano_emul =&ctp_ano_emul_v;
00434   //Cathode LCT
00435   CSCCLCTDigiCollection_ ctp_cat_data_v, ctp_cat_emul_v;
00436   ctp_cat_data_v.clear(); ctp_cat_emul_v.clear();
00437   if(ctp_cat_data_.isValid() && ctp_cat_emul_.isValid()) {
00438     int tbin_cathode_offset = 7, emul_bx_corr;
00439     typedef CSCCLCTDigiCollection::DigiRangeIterator mapIt;
00440     typedef CSCCLCTDigiCollection::const_iterator    vecIt;
00441     for (mapIt mit = ctp_cat_data_->begin(); mit != ctp_cat_data_->end(); mit++)
00442       for (vecIt vit = ctp_cat_data_->get((*mit).first).first; 
00443            vit != ctp_cat_data_->get((*mit).first).second; vit++) 
00444         ctp_cat_data_v.push_back(*vit);
00445     for (mapIt mit = ctp_cat_emul_->begin(); mit != ctp_cat_emul_->end(); mit++) {
00446       const CSCDetId& detid = (*mit).first;
00447 
00448       // Extract full 12-bit BX word from CLCT data collections.
00449       int full_cathode_bx = -999;
00450       const CSCCLCTDigiCollection::Range& crange = ctp_cat_data_->get(detid);
00451       for (vecIt digiIt = crange.first; digiIt != crange.second; digiIt++) {
00452         if ((*digiIt).isValid()) {
00453           full_cathode_bx = (*digiIt).getFullBX();
00454           break;
00455         }
00456       }
00457 
00458       for (vecIt vit = ctp_cat_emul_->get(detid).first; 
00459            vit != ctp_cat_emul_->get(detid).second; vit++) {
00460         int emul_bx = (*vit).getBX();
00461         if (full_cathode_bx != -999)
00462           emul_bx_corr =
00463             (full_cathode_bx + emul_bx - tbin_cathode_offset) & 0x03;
00464         else
00465           emul_bx_corr = emul_bx & 0x03;
00466         CSCCLCTDigi clct((*vit).isValid(),    (*vit).getQuality(),
00467                          (*vit).getPattern(), (*vit).getStripType(),
00468                          (*vit).getBend(),    (*vit).getStrip(),
00469                          (*vit).getCFEB(),    emul_bx_corr,
00470                          (*vit).getTrknmb());
00471         ctp_cat_emul_v.push_back(clct);
00472       }
00473     }
00474   }
00475   ctp_cat_data =&ctp_cat_data_v;
00476   ctp_cat_emul =&ctp_cat_emul_v;
00477   //Correlated (anode+cathode) LCTs
00478   CSCCorrelatedLCTDigiCollection_ ctp_lct_data_v, ctp_lct_emul_v;
00479   ctp_lct_data_v.clear(); ctp_lct_emul_v.clear();
00480   if(ctp_lct_data_.isValid() && ctp_lct_emul_.isValid()) {
00481     int tbin_anode_offset = 5, emul_bx_corr;
00482     typedef CSCCorrelatedLCTDigiCollection::DigiRangeIterator mapIt;//map iterator
00483     typedef CSCCorrelatedLCTDigiCollection::const_iterator    vecIt;//vec iterator
00484     //loop over data (map<idx,vec_digi>)
00485     for (mapIt mit = ctp_lct_data_->begin(); mit != ctp_lct_data_->end(); mit++)
00486       //get vec_digi range(pair)  corresponding to idx of map
00487       //loop over digi vector (ie between begin and end pointers in range)
00488       //CSCCorrelatedLCTDigiCollection::Range ctpRange = ctp_lct_data_->get((*mit).first)
00489       //for (vecIt vit = ctpRange.first; vit != ctpRange.second; vit++) {
00490       for (vecIt vit = ctp_lct_data_->get((*mit).first).first; 
00491            vit != ctp_lct_data_->get((*mit).first).second; vit++) 
00492         ctp_lct_data_v.push_back(*vit);
00493     for (mapIt mit = ctp_lct_emul_->begin(); mit != ctp_lct_emul_->end(); mit++) {
00494       const CSCDetId& detid = (*mit).first;
00495 
00496       // Extract full 12-bit BX word from ALCT data collections.
00497       int full_anode_bx = -999;
00498       if(ctp_ano_data_.isValid()) {
00499         const CSCALCTDigiCollection::Range& arange = ctp_ano_data_->get(detid);
00500         for (CSCALCTDigiCollection::const_iterator digiIt = arange.first;
00501              digiIt != arange.second; digiIt++) {
00502           if ((*digiIt).isValid()) {
00503             full_anode_bx = (*digiIt).getFullBX();
00504             break;
00505           }
00506         }
00507       }
00508 
00509       for (vecIt vit = ctp_lct_emul_->get(detid).first; 
00510            vit != ctp_lct_emul_->get(detid).second; vit++) {
00511         int emul_bx = (*vit).getBX();
00512         if (full_anode_bx != -999) {
00513           emul_bx_corr = (full_anode_bx + emul_bx - tbin_anode_offset) & 0x01;
00514         }
00515         else { // This should never happen for default config. settings.
00516           emul_bx_corr = emul_bx & 0x01;
00517         }
00518 
00519         // If one compares correlated LCTs after the muon port card, an
00520         // additional offset is needed.
00521         if (m_DEsource[CTP][1].instance() == "MPCSORTED") emul_bx_corr += 5;
00522 
00523         CSCCorrelatedLCTDigi lct((*vit).getTrknmb(),  (*vit).isValid(),
00524                                  (*vit).getQuality(), (*vit).getKeyWG(),
00525                                  (*vit).getStrip(),   (*vit).getPattern(),
00526                                  (*vit).getBend(),    emul_bx_corr,
00527                                  (*vit).getMPCLink(), (*vit).getBX0(),
00528                                  (*vit).getSyncErr(), (*vit).getCSCID());
00529         ctp_lct_emul_v.push_back(lct);
00530       }
00531     }
00532   }
00533   ctp_lct_data =&ctp_lct_data_v;
00534   ctp_lct_emul =&ctp_lct_emul_v;
00535 
00536 
00537   // -- CTF [cathode strip chamber track finder]
00538 
00539   edm::Handle<L1MuRegionalCandCollection> ctf_data, ctf_emul;
00540   edm::Handle<L1CSCTrackCollection> ctf_trk_data_, ctf_trk_emul_; 
00541 
00542   CSCCorrelatedLCTDigiCollection_ const* ctf_trk_data(new CSCCorrelatedLCTDigiCollection_);
00543   CSCCorrelatedLCTDigiCollection_ const* ctf_trk_emul(new CSCCorrelatedLCTDigiCollection_);
00544 
00545   //L1MuRegionalCandCollection      const* ctf_trc_data(new L1MuRegionalCandCollection);
00546   //L1MuRegionalCandCollection      const* ctf_trc_emul(new L1MuRegionalCandCollection);
00547 
00548   edm::Handle<L1CSCStatusDigiCollection> ctf_sta_data_;
00549   edm::Handle<L1CSCStatusDigiCollection> ctf_sta_emul_;
00550 
00551   L1CSCSPStatusDigiCollection_    const* ctf_sta_data(new L1CSCSPStatusDigiCollection_);
00552   L1CSCSPStatusDigiCollection_    const* ctf_sta_emul(new L1CSCSPStatusDigiCollection_);
00553 
00554   if(m_doSys[CTF]) {
00555     iEvent.getByLabel(m_DEsource[CTF][2],ctf_trk_data_);
00556     iEvent.getByLabel(m_DEsource[CTF][3],ctf_trk_emul_);
00557     //note: unpacker different label: MounL1CSCTrackCollection
00558     iEvent.getByLabel(m_DEsource[CTF][0],ctf_data);
00559     iEvent.getByLabel(m_DEsource[CTF][1],ctf_emul);
00560     //note: unpacker only
00561     iEvent.getByLabel(m_DEsource[CTF][0].label(),"MuonL1CSCStatusDigiCollection",ctf_sta_data_);
00562     iEvent.getByLabel(m_DEsource[CTF][1].label(),"MuonL1CSCStatusDigiCollection",ctf_sta_emul_);
00563   }
00564 
00565   if(ctf_sta_data_.isValid())
00566     ctf_sta_data = &(ctf_sta_data_->second);
00567 
00568   if(ctf_sta_emul_.isValid())
00569     ctf_sta_emul = &(ctf_sta_emul_->second);
00570 
00571   CSCCorrelatedLCTDigiCollection_ ctf_trk_data_v, ctf_trk_emul_v; //vector
00572   L1MuRegionalCandCollection      ctf_trc_data_v, ctf_trc_emul_v; //vector
00573 
00574   if(ctf_trk_data_.isValid() && ctf_trk_emul_.isValid()) {
00575     typedef CSCCorrelatedLCTDigiCollection::DigiRangeIterator mapIt;//map iterator
00576     typedef CSCCorrelatedLCTDigiCollection::const_iterator    vecIt;//vec iterator
00577     typedef L1CSCTrackCollection::const_iterator ctcIt;
00578 
00579     //loop over csc-tracks (ie pairs<l1track,digi_vec>)
00580     for(ctcIt tcit=ctf_trk_data_->begin(); tcit!=ctf_trk_data_->end(); tcit++) {
00582       if((tcit->first.bx() < -1) || (tcit->first.bx() > 1))
00583         continue;
00584       //store the muon candidate
00585       //csc::L1Track ttr = tcit->first;
00586       //L1MuRegionalCand cand(ttr);    
00587       //ctf_trc_data_v.push_back(tcit->first);
00588       ctf_trc_data_v.push_back(L1MuRegionalCand(tcit->first.getDataWord(), tcit->first.bx()));
00589       CSCCorrelatedLCTDigiCollection ldc = tcit->second; //muondigicollection=map
00590       //get the lct-digi-collection (ie muon-digi-collection)
00591       //loop over data (map<idx,vec_digi>)
00592       for (mapIt mit = ldc.begin(); mit != ldc.end(); mit++)
00593         //get vec_digi range(pair)  corresponding to idx of map
00594         //loop over digi vector (ie between begin and end pointers in range)
00595         //CSCCorrelatedLCTDigiCollection::Range ctpRange = ctp_lct_data_->get((*mit).first)
00596         //for (vecIt vit = ctpRange.first; vit != ctpRange.second; vit++) {
00597         for (vecIt vit = ldc.get((*mit).first).first; 
00598              vit != ldc.get((*mit).first).second; vit++) 
00599           ctf_trk_data_v.push_back(*vit);
00600     }
00601 
00602     //ctf_trk_data = &ctf_trk_data_v;
00603     //ctf_trc_data = &ctf_trc_data_v;
00604 
00605     //same for emulator collection
00606     for(ctcIt tcit=ctf_trk_emul_->begin();tcit!=ctf_trk_emul_->end(); tcit++) {
00607       if((tcit->first.bx() < -1) || (tcit->first.bx() > 1))
00608         continue;
00609       ctf_trc_emul_v.push_back(L1MuRegionalCand(tcit->first.getDataWord(), tcit->first.bx()));
00610       CSCCorrelatedLCTDigiCollection ldc = tcit->second;
00611       for (mapIt mit = ldc.begin(); mit != ldc.end(); mit++)
00612         for (vecIt vit = ldc.get((*mit).first).first; 
00613              vit != ldc.get((*mit).first).second; vit++) 
00614           ctf_trk_emul_v.push_back(*vit);
00615     }
00616 
00617     ctf_trk_emul = &ctf_trk_emul_v;
00618     //ctf_trc_emul = &ctf_trc_emul_v;
00619 
00620   }
00621   
00622   // -- RPC [resistive plate chambers regional trigger] 
00623   edm::Handle<L1MuRegionalCandCollection> rpc_cen_data;
00624   edm::Handle<L1MuRegionalCandCollection> rpc_cen_emul;
00625   edm::Handle<L1MuRegionalCandCollection> rpc_for_data;
00626   edm::Handle<L1MuRegionalCandCollection> rpc_for_emul;
00627   if(m_doSys[RPC]) {
00628     iEvent.getByLabel(m_DEsource[RPC][0].label(),"RPCb",rpc_cen_data);
00629     iEvent.getByLabel(m_DEsource[RPC][1].label(),"RPCb",rpc_cen_emul);
00630     iEvent.getByLabel(m_DEsource[RPC][0].label(),"RPCf",rpc_for_data);
00631     iEvent.getByLabel(m_DEsource[RPC][1].label(),"RPCf",rpc_for_emul);
00632   } 
00633 
00634   // -- LTC [local trigger controller]
00635   edm::Handle<LTCDigiCollection> ltc_data;
00636   edm::Handle<LTCDigiCollection> ltc_emul;
00637   if(m_doSys[LTC]) {
00638     iEvent.getByLabel(m_DEsource[LTC][0],ltc_data);
00639     iEvent.getByLabel(m_DEsource[LTC][1],ltc_emul);
00640   }
00641 
00642   // -- GMT [global muon trigger]
00643   edm::Handle<L1MuGMTCandCollection> gmt_data;
00644   edm::Handle<L1MuGMTCandCollection> gmt_emul;
00645   edm::Handle<L1MuGMTReadoutCollection> gmt_rdt_data_;
00646   edm::Handle<L1MuGMTReadoutCollection> gmt_rdt_emul_;
00647   L1MuRegionalCandCollection const* gmt_rdt_data(new L1MuRegionalCandCollection);
00648   L1MuRegionalCandCollection const* gmt_rdt_emul(new L1MuRegionalCandCollection);
00649   //tbd: may compare extended candidates
00650   L1MuGMTCandCollection const *gmt_can_data(new L1MuGMTCandCollection);
00651   L1MuGMTCandCollection const *gmt_can_emul(new L1MuGMTCandCollection);
00652   if(m_doSys[GMT]) {
00653     iEvent.getByLabel(m_DEsource[GMT][0], gmt_data);
00654     iEvent.getByLabel(m_DEsource[GMT][1], gmt_emul);
00655     iEvent.getByLabel(m_DEsource[GMT][0], gmt_rdt_data_);
00656     iEvent.getByLabel(m_DEsource[GMT][1], gmt_rdt_emul_);
00657   }  
00658   L1MuGMTCandCollection      gmt_can_data_vec, gmt_can_emul_vec;
00659   L1MuRegionalCandCollection gmt_rdt_data_vec, gmt_rdt_emul_vec;
00660   gmt_can_data_vec.clear();  gmt_can_emul_vec.clear();
00661   gmt_rdt_data_vec.clear();  gmt_rdt_emul_vec.clear();
00662   if( gmt_rdt_data_.isValid() && gmt_rdt_emul_.isValid() ) {
00663     typedef std::vector<L1MuGMTReadoutRecord>::const_iterator GmtRrIt;
00664     //get record vector for data 
00665     std::vector<L1MuGMTReadoutRecord> gmt_rdt_data_bx = gmt_rdt_data_->getRecords();
00666     for(GmtRrIt igmtrr=gmt_rdt_data_bx.begin(); igmtrr!=gmt_rdt_data_bx.end(); igmtrr++) {
00667       //get gmt cands
00668       typedef std::vector<L1MuGMTExtendedCand>::const_iterator GmtECIt;
00669       std::vector<L1MuGMTExtendedCand> gmc;
00670       gmc = igmtrr->getGMTCands();
00671       for(GmtECIt iter1=gmc.begin(); iter1!=gmc.end(); iter1++) {
00672         L1MuGMTCand cand(iter1->getDataWord(),iter1->bx());
00673         cand.setPhiValue(iter1->phiValue());
00674         cand.setEtaValue(iter1->etaValue());
00675         cand.setPtValue (iter1->ptValue ());
00676         gmt_can_data_vec.push_back(cand);
00677       }
00678       //get reg cands
00679       typedef L1MuRegionalCandCollection::const_iterator GmtRCIt;
00680       L1MuRegionalCandCollection rmc;
00681       rmc.clear();
00682       rmc = igmtrr->getDTBXCands();
00683       gmt_rdt_data_vec.insert(gmt_rdt_data_vec.end(),rmc.begin(),rmc.end());
00684       rmc.clear();
00685       rmc = igmtrr->getCSCCands();
00686       gmt_rdt_data_vec.insert(gmt_rdt_data_vec.end(),rmc.begin(),rmc.end());
00687       rmc.clear();
00688       rmc = igmtrr->getBrlRPCCands();
00689       gmt_rdt_data_vec.insert(gmt_rdt_data_vec.end(),rmc.begin(),rmc.end());
00690       rmc.clear();
00691       rmc = igmtrr->getFwdRPCCands();
00692       gmt_rdt_data_vec.insert(gmt_rdt_data_vec.end(),rmc.begin(),rmc.end());
00693     }
00694     //get record vector for emul 
00695     std::vector<L1MuGMTReadoutRecord> gmt_rdt_emul_bx = gmt_rdt_emul_->getRecords();
00696     for(GmtRrIt igmtrr=gmt_rdt_emul_bx.begin(); igmtrr!=gmt_rdt_emul_bx.end(); igmtrr++) {
00697       //get gmt cands
00698       typedef std::vector<L1MuGMTExtendedCand>::const_iterator GmtECIt;
00699       std::vector<L1MuGMTExtendedCand> gmc;
00700       gmc = igmtrr->getGMTCands();
00701       for(GmtECIt iter1=gmc.begin(); iter1!=gmc.end(); iter1++) {
00702         gmt_can_emul_vec.push_back(L1MuGMTCand(iter1->getDataWord(),iter1->bx()));
00703       }
00704       //get reg cands
00705       typedef L1MuRegionalCandCollection::const_iterator GmtRCIt;
00706       L1MuRegionalCandCollection rmc;
00707       rmc.clear();
00708       rmc = igmtrr->getDTBXCands();
00709       gmt_rdt_emul_vec.insert(gmt_rdt_emul_vec.end(),rmc.begin(),rmc.end());
00710       rmc.clear();
00711       rmc = igmtrr->getCSCCands();
00712       gmt_rdt_emul_vec.insert(gmt_rdt_emul_vec.end(),rmc.begin(),rmc.end());
00713       rmc.clear();
00714       rmc = igmtrr->getBrlRPCCands();
00715       gmt_rdt_emul_vec.insert(gmt_rdt_emul_vec.end(),rmc.begin(),rmc.end());
00716       rmc.clear();
00717       rmc = igmtrr->getFwdRPCCands();
00718       gmt_rdt_emul_vec.insert(gmt_rdt_emul_vec.end(),rmc.begin(),rmc.end());
00719     }
00720   }
00721   gmt_rdt_data = &gmt_rdt_data_vec;
00722   gmt_rdt_emul = &gmt_rdt_emul_vec;
00723   gmt_can_data = &gmt_can_data_vec;
00724   gmt_can_emul = &gmt_can_emul_vec;
00725 
00726   // -- GLT [global trigger]
00727   edm::Handle<L1GlobalTriggerReadoutRecord>    glt_rdt_data;
00728   edm::Handle<L1GlobalTriggerReadoutRecord>    glt_rdt_emul;
00729   edm::Handle<L1GlobalTriggerEvmReadoutRecord> glt_evm_data;
00730   edm::Handle<L1GlobalTriggerEvmReadoutRecord> glt_evm_emul;
00731   edm::Handle<L1GlobalTriggerObjectMapRecord>  glt_obj_data;
00732   edm::Handle<L1GlobalTriggerObjectMapRecord>  glt_obj_emul;
00733   if(m_doSys[GLT]) {
00734     iEvent.getByLabel(m_DEsource[GLT][0], glt_rdt_data);
00735     iEvent.getByLabel(m_DEsource[GLT][1], glt_rdt_emul);
00736     iEvent.getByLabel(m_DEsource[GLT][0], glt_evm_data);
00737     iEvent.getByLabel(m_DEsource[GLT][1], glt_evm_emul);
00738     iEvent.getByLabel(m_DEsource[GLT][0], glt_obj_data);
00739     iEvent.getByLabel(m_DEsource[GLT][1], glt_obj_emul);
00740   }
00741   
00743 
00744   //check collections validity
00745   bool isValidDE[DEnsys][2];// = {false};
00746   for(int i=0; i<DEnsys; i++) for(int j=0; j<2; j++) isValidDE[i][j]=false;
00747 
00748   isValidDE[ETP][0] =     ecal_tp_data .isValid(); isValidDE[ETP][1] =    ecal_tp_emul .isValid();
00749   isValidDE[HTP][0] =     hcal_tp_data .isValid(); isValidDE[HTP][1] =    hcal_tp_emul .isValid();
00750   isValidDE[RCT][0] =      rct_em_data .isValid(); isValidDE[RCT][1] =     rct_em_emul .isValid();
00751   isValidDE[RCT][0]&=     rct_rgn_data .isValid(); isValidDE[RCT][1] =    rct_rgn_emul .isValid();
00752   isValidDE[GCT][0] = gct_isolaem_data .isValid(); isValidDE[GCT][1] =gct_isolaem_emul .isValid();
00753   isValidDE[GCT][0]&= gct_noisoem_data .isValid(); isValidDE[GCT][1]&=gct_noisoem_emul .isValid();
00754   isValidDE[GCT][0]&= gct_cenjets_data .isValid(); isValidDE[GCT][1]&=gct_cenjets_emul .isValid();
00755   isValidDE[GCT][0]&= gct_forjets_data .isValid(); isValidDE[GCT][1]&=gct_forjets_emul .isValid();
00756   isValidDE[GCT][0]&= gct_taujets_data .isValid(); isValidDE[GCT][1]&=gct_taujets_emul .isValid();
00757   isValidDE[GCT][0]&=  gct_etmiss_data .isValid(); isValidDE[GCT][1]&= gct_etmiss_emul .isValid();
00758   isValidDE[GCT][0]&=  gct_ettota_data .isValid(); isValidDE[GCT][1]&= gct_ettota_emul .isValid();
00759   isValidDE[GCT][0]&=  gct_htmiss_data .isValid(); isValidDE[GCT][1]&= gct_htmiss_emul .isValid();
00760   isValidDE[GCT][0]&=  gct_hfring_data .isValid(); isValidDE[GCT][1]&= gct_hfring_emul .isValid();
00761   isValidDE[GCT][0]&=  gct_hfbcnt_data .isValid(); isValidDE[GCT][1]&= gct_hfbcnt_emul .isValid();
00762 //isValidDE[GCT][0]&=  gct_jetcnt_data .isValid(); isValidDE[GCT][1]&= gct_jetcnt_emul .isValid(); #temporary
00763   isValidDE[DTP][0] =      dtp_ph_data_.isValid(); isValidDE[DTP][1] =     dtp_ph_emul_.isValid();
00764   isValidDE[DTP][0]&=      dtp_th_data_.isValid(); isValidDE[DTP][1]&=     dtp_th_emul_.isValid();
00765   isValidDE[DTF][0] =     dtf_trk_data_.isValid(); isValidDE[DTF][1] =    dtf_trk_emul_.isValid();
00766 //isValidDE[DTF][0]&=         dtf_data .isValid(); isValidDE[DTF][1]&=        dtf_emul .isValid();
00767   isValidDE[CTP][0] =     ctp_lct_data_.isValid(); isValidDE[CTP][1] =    ctp_lct_emul_.isValid();
00768   if (m_DEsource[CTP][0].label().find("tf") == std::string::npos) {
00769   isValidDE[CTP][0]&=     ctp_ano_data_.isValid(); isValidDE[CTP][1]&=    ctp_ano_emul_.isValid();
00770   isValidDE[CTP][0]&=     ctp_cat_data_.isValid(); isValidDE[CTP][1]&=    ctp_cat_emul_.isValid();
00771   }
00772   isValidDE[CTF][0] =         ctf_data .isValid(); isValidDE[CTF][1] =        ctf_emul .isValid();
00773   isValidDE[CTF][0]&=    ctf_trk_data_ .isValid(); isValidDE[CTF][1]&=   ctf_trk_emul_ .isValid();
00774   //isValidDE[CTF][0]&=    ctf_sta_data_ .isValid(); isValidDE[CTF][1]&=   ctf_sta_emul_ .isValid();
00775   isValidDE[RPC][0] =     rpc_cen_data .isValid(); isValidDE[RPC][1] =    rpc_cen_emul .isValid();
00776   isValidDE[RPC][0]&=     rpc_for_data .isValid(); isValidDE[RPC][1]&=    rpc_for_emul .isValid();
00777   isValidDE[LTC][0] =         ltc_data .isValid(); isValidDE[LTC][1] =        ltc_emul .isValid();
00778   isValidDE[GMT][0] =         gmt_data .isValid(); isValidDE[GMT][1] =        gmt_emul .isValid();
00779 //isValidDE[GMT][0]&=     gmt_rdt_data_.isValid(); isValidDE[GMT][1]&=    gmt_rdt_emul_.isValid();
00780   isValidDE[GLT][0] =     glt_rdt_data .isValid(); isValidDE[GLT][1] =    glt_rdt_emul .isValid();
00781 //isValidDE[GLT][0]&=     glt_evm_data .isValid(); isValidDE[GLT][1]&=    glt_evm_emul .isValid();
00782 //isValidDE[GLT][0]&=     glt_obj_data .isValid(); isValidDE[GLT][1]&=    glt_obj_emul .isValid();
00783 
00784   bool isValid[DEnsys];
00785   for(int i=0; i<DEnsys; i++) {
00786     isValid[i]=true;
00787     for(int j=0; j<2; j++) {
00788       isValid[i] &= isValidDE[i][j];
00789     }
00790   }
00791 
00792   if(verbose()) {
00793     std::cout << "L1Comparator sys isValid?  (evt:" << nevt_ << ") ";
00794     std::cout << "\n\t&: ";
00795     for(int i=0; i<DEnsys; i++)
00796       std::cout << isValid[i] << " ";
00797     std::cout << "\n\td: ";
00798     for(int i=0; i<DEnsys; i++)
00799       std::cout << isValidDE[i][0] << " ";
00800     std::cout << "\n\te: ";
00801     for(int i=0; i<DEnsys; i++)
00802       std::cout << isValidDE[i][1] << " ";
00803     std::cout << std::endl;
00804   }
00805   
00806   //reset flags...
00807   //for(int i=0; i<DEnsys; i++) isValid[i]=true;
00808 
00809   if(verbose())
00810     std::cout << "L1Comparator start processing the collections.\n" << std::flush;
00811 
00813   if(m_doSys[ETP]&&isValid[ETP]) process<EcalTrigPrimDigiCollection>     (    ecal_tp_data,     ecal_tp_emul, ETP,ECALtp);
00814   if(m_doSys[HTP]&&isValid[HTP]) process<HcalTrigPrimDigiCollection>     (    hcal_tp_data,     hcal_tp_emul, HTP,HCALtp);
00815   if(m_doSys[RCT]&&isValid[RCT]) process<L1CaloEmCollection>             (     rct_em_data,      rct_em_emul, RCT,RCTem);
00816   if(m_doSys[RCT]&&isValid[RCT]) process<L1CaloRegionCollection>         (    rct_rgn_data,     rct_rgn_emul, RCT,RCTrgn);
00817   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctEmCandCollection>          (gct_isolaem_data, gct_isolaem_emul, GCT,GCTisolaem);
00818   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctEmCandCollection>          (gct_noisoem_data, gct_noisoem_emul, GCT,GCTnoisoem);
00819   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctJetCandCollection>         (gct_cenjets_data, gct_cenjets_emul, GCT,GCTcenjets);
00820   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctJetCandCollection>         (gct_forjets_data, gct_forjets_emul, GCT,GCTforjets);
00821   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctJetCandCollection>         (gct_taujets_data, gct_taujets_emul, GCT,GCTtaujets);
00822   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctEtHadCollection>           (     gct_ht_data,      gct_ht_emul, GCT,GCTethad);
00823   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctEtMissCollection>          ( gct_etmiss_data,  gct_etmiss_emul, GCT,GCTetmiss);
00824   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctEtTotalCollection>         ( gct_ettota_data , gct_ettota_emul, GCT,GCTettot);
00825   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctHtMissCollection>          ( gct_htmiss_data,  gct_htmiss_emul, GCT,GCThtmiss);
00826   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctHFRingEtSumsCollection>    ( gct_hfring_data,  gct_hfring_emul, GCT,GCThfring);
00827   if(m_doSys[GCT]&&isValid[GCT]) process<L1GctHFBitCountsCollection>     ( gct_hfbcnt_data,  gct_hfbcnt_emul, GCT,GCThfbit);
00828 //if(m_doSys[GCT]&&isValid[GCT]) process<L1GctJetCountsCollection>       ( gct_jetcnt_data,  gct_jetcnt_emul, GCT,GCTjetcnt);#missing in emulator
00829   if(m_doSys[DTP]&&isValid[DTP]) process<L1MuDTChambPhDigiCollection>    (     dtp_ph_data,      dtp_ph_emul, DTP,DTtpPh);
00830   if(m_doSys[DTP]&&isValid[DTP]) process<L1MuDTChambThDigiCollection>    (     dtp_th_data,      dtp_th_emul, DTP,DTtpTh);
00831   if(m_doSys[DTF]&&isValid[DTF]) process<L1MuRegionalCandCollection>     (        dtf_data,         dtf_emul, DTF,DTtf);
00832   if(m_doSys[DTF]&&isValid[DTF]) process<L1MuRegionalCandCollection>     (    dtf_trk_data,     dtf_trk_emul, DTF,DTtftrk);
00833   if(m_DEsource[CTP][0].label().find("tf") == std::string::npos) {
00834   if(m_doSys[CTP]&&isValid[CTP]) process<CSCALCTDigiCollection_>         (    ctp_ano_data,     ctp_ano_emul, CTP,CSCtpa);
00835   if(m_doSys[CTP]&&isValid[CTP]) process<CSCCLCTDigiCollection_>         (    ctp_cat_data,     ctp_cat_emul, CTP,CSCtpc);
00836   }
00837   if(m_doSys[CTP]&&isValid[CTP]) process<CSCCorrelatedLCTDigiCollection_>(    ctp_lct_data,     ctp_lct_emul, CTP,CSCtpl);
00838   if(m_doSys[CTF]&&isValid[CTF]) process<L1MuRegionalCandCollection>     (        ctf_data,         ctf_emul, CTF,CSCtf);
00839   if(m_doSys[CTF]&&isValid[CTF]) process<CSCCorrelatedLCTDigiCollection_>(    ctf_trk_data,     ctf_trk_emul, CTF,CSCtftrk);
00840   //if(m_doSys[CTF]&&isValid[CTF]) process<L1MuRegionalCandCollection>     (    ctf_trc_data,     ctf_trc_emul, CTF,CSCtftrc);
00841   if(m_doSys[CTF]&&isValid[CTF]) process<L1CSCSPStatusDigiCollection_>   (    ctf_sta_data,     ctf_sta_emul, CTF,CSCtfsta);
00842   if(m_doSys[RPC]&&isValid[RPC]) process<L1MuRegionalCandCollection>     (    rpc_cen_data,     rpc_cen_emul, RPC,RPCcen);
00843   if(m_doSys[RPC]&&isValid[RPC]) process<L1MuRegionalCandCollection>     (    rpc_for_data,     rpc_for_emul, RPC,RPCfor);
00844   if(m_doSys[LTC]&&isValid[LTC]) process<LTCDigiCollection>              (        ltc_data,         ltc_emul, LTC,LTCi);
00845   if(m_doSys[GMT]&&isValid[GMT]) process<L1MuGMTCandCollection>          (        gmt_data,         gmt_emul, GMT,GMTmain);
00846   if(m_doSys[GMT]&&isValid[GMT]) process<L1MuRegionalCandCollection>     (    gmt_rdt_data,     gmt_rdt_emul, GMT,GMTrdt);
00847   if(m_doSys[GMT]&&isValid[GMT]) process<L1MuGMTCandCollection>          (    gmt_can_data,     gmt_can_emul, GMT,GMTcnd);
00848 
00849   // >>---- GLT ---- <<  
00850   GltDEDigi gltdigimon;
00851   
00852   if(m_doSys[GLT] && isValid[GLT] ) {
00853 
00855     bool prt = false; 
00856     if(!m_dumpMode)
00857       prt = false;
00858     else if(m_dumpMode==-1)
00859       prt=true;
00860 
00861     if(dumpEvent_ && prt) {
00862       m_dumpFile << "\nEntry: " << nevt_ 
00863                  << " (event:"  << evtNum_
00864                  << " | run:"   << runNum_ 
00865                  << ")\n"       << std::flush;
00866       dumpEvent_=false;
00867     }
00868 
00869     m_dumpFile << "\n  GT...\n";
00870 
00871     if(glt_rdt_data.isValid() && glt_rdt_emul.isValid()) {
00872       
00873       //fill gt mon info
00874       bool globalDBit[2];
00875       std::vector<bool> gltDecBits[2], gltTchBits[2];
00876       globalDBit[0] = glt_rdt_data->decision();
00877       globalDBit[1] = glt_rdt_emul->decision();
00878       gltDecBits[0] = glt_rdt_data->decisionWord();
00879       gltDecBits[1] = glt_rdt_emul->decisionWord();
00880       //gltTchBits[0] = glt_rdt_data->gtFdlWord().gtTechnicalTriggerWord();
00881       //gltTchBits[1] = glt_rdt_emul->gtFdlWord().gtTechnicalTriggerWord();
00882       gltTchBits[0] = glt_rdt_data->technicalTriggerWord();
00883       gltTchBits[1] = glt_rdt_emul->technicalTriggerWord();
00884       gltdigimon.set(globalDBit, gltDecBits, gltTchBits);
00885 
00886       DEncand[GLT][0]=1; DEncand[GLT][1]=1;
00887       DEmatchEvt[GLT]  = compareCollections(glt_rdt_data, glt_rdt_emul);  
00888     }
00889 
00891     if(glt_evm_data.isValid() && glt_evm_emul.isValid())
00892       DEmatchEvt[GLT] &= compareCollections(glt_evm_data, glt_evm_emul);  
00893     if(glt_obj_data.isValid() && glt_obj_emul.isValid())
00894       DEmatchEvt[GLT] &= compareCollections(glt_obj_data, glt_obj_emul);  
00895 
00896     char ok[10];
00897     char dumptofile[1000];
00898     if(DEmatchEvt[GLT]) sprintf(ok,"successful");
00899     else         sprintf(ok,"failed");
00900     sprintf(dumptofile,"  ...GT data and emulator comparison: %s\n", ok); 
00901     m_dumpFile<<dumptofile;
00902   }
00903 
00904   if(verbose())
00905     std::cout << "L1Comparator done processing all collections.\n" << std::flush;
00906 
00907   if(verbose()) {
00908     std::cout << "[L1Comparator] sys match? << evt." << nevt_ << ": ";
00909     for(int i=0; i<DEnsys; i++)
00910       std::cout << DEmatchEvt[i] << " ";
00911     std::cout << std::endl;
00912   }
00913 
00914 
00915   // >>---- Event match? ---- <<  
00916 
00917   bool evt_match  = true;
00918   for(int i=0; i<DEnsys; i++)
00919     evt_match &= DEmatchEvt[i];
00920 
00921   
00922   /* char ok[10];
00923      if(evt_match) sprintf(ok,"GOOD :]");
00924      else      sprintf(ok,"BAD !!!"); 
00925      char dumptofile[1000];
00926      sprintf(dumptofile,"\n -> event data and emulator match... %s\n", ok);
00927      m_dumpFile<<dumptofile;
00928   */
00929 
00930   // >>---- Global match? ---- <<  
00931   m_match &= evt_match;
00932   m_dumpFile << std::flush;
00933 
00934   //if collection is empty, add empty digi
00935   if(m_dedigis.size()==0) {
00936     if(verbose())
00937       std::cout << "\n [L1Comparator] adding empty collection to DErecord\n";
00938     m_dedigis.push_back(L1DataEmulDigi());
00939   }
00940   
00941   // >>---- d|e record ---- <<  
00942   std::auto_ptr<L1DataEmulRecord> record
00943     (new L1DataEmulRecord(evt_match,m_doSys,DEmatchEvt,DEncand,m_dedigis, gltdigimon));
00944   if(verbose()) {
00945     std::cout << "\n [L1Comparator] printing DErecord" 
00946               << "(entry:"<< nevt_ 
00947               << "|evt:"  << evtNum_
00948               << "|run:"  << runNum_ 
00949               << "):\n"    << std::flush;
00950     std::cout << *record 
00951               << "\n" << std::flush;
00952   }
00953 
00954   iEvent.put(record);
00955 
00957   bool dorawdata = false;
00958   if(dorawdata) {
00959     edm::Handle<FEDRawDataCollection> raw_fedcoll_data;
00960     edm::Handle<FEDRawDataCollection> raw_fedcoll_emul;
00961     iEvent.getByLabel(m_FEDsource[0], raw_fedcoll_data);
00962     iEvent.getByLabel(m_FEDsource[1], raw_fedcoll_emul);
00963     bool rawval=true;
00964     rawval &= raw_fedcoll_data.isValid();
00965     rawval &= raw_fedcoll_emul.isValid();
00966     if(rawval) 
00967       compareFedRawCollections(raw_fedcoll_data,raw_fedcoll_emul, m_fedId);
00968   }
00969   
00970   if(verbose())
00971     std::cout << "L1comparator::analize() end. " << nevt_ << std::endl;
00972   
00973 }
00974 
00975 
00976 template <class T> 
00977 void L1Comparator::process(T const* data, T const* emul, const int sys, const int cid) {
00978 
00979   if(verbose())
00980     std::cout << "L1Comparator::process -ing system:" << sys 
00981               << " (" << SystLabel[sys] << "), data type " << cid 
00982               << "...\n" << std::flush;
00983   if(verbose())
00984   std::cout << "L1Comparator::process debug "
00985             << " (size "  << data->size() << "," <<emul->size() << ")"   
00986             << ".\n" << std::flush;
00987 
00989   bool prt = false; 
00990   if(!m_dumpMode)
00991     prt = false;
00992   else if(m_dumpMode==-1)
00993     prt=true;
00994   else if(m_dumpMode>0) {
00995     DEcompare<T> tmp(data,emul);
00996     if(tmp.get_ncand(0)==0 && tmp.get_ncand(1)==0)
00997       prt=false;
00998     else
00999     prt = !tmp.do_compare(m_dumpFile,0);
01000   }
01001 
01002   //declare de compare object
01003   DEcompare<T> cmp(data,emul);
01004 
01005   int ndata = cmp.get_ncand(0);
01006   int nemul = cmp.get_ncand(1);
01007   
01008   if(verbose())
01009     std::cout << "L1Comparator::process " 
01010               << " system:" << SystLabel[sys] << "(id " << sys << ")" 
01011               << " type:"   << cmp.GetName(0) << "(" << cmp.de_type() << ")"
01012               << " ndata:"  << ndata
01013               << " nemul:"  << nemul
01014               << " (size "  << data->size() << "," <<emul->size() << ")"   
01015               << ".\n" << std::flush;
01016   
01017   if(ndata==0&&nemul==0) {
01018     if(verbose())
01019       std::cout << "L1Comparator::process " 
01020                 << "empty collections -- exiting!\n" << std::flush;
01021     return;
01022   }
01023   
01024   m_dumpFile << std::setiosflags(std::ios::showpoint | std::ios::fixed 
01025                                  | std::ios::right | std::ios::adjustfield);
01026   std::cout  << std::setiosflags(std::ios::showpoint | std::ios::fixed 
01027                                  | std::ios::right | std::ios::adjustfield);
01028   
01029   if(dumpEvent_ &&  prt ) {
01030     m_dumpFile << "\nEntry: " << nevt_ 
01031                << " (event:"  << evtNum_
01032                << " | run:"   << runNum_ 
01033                << ")\n"       << std::flush;
01034     dumpEvent_=false;
01035   }
01036   
01037   if(prt)
01038     m_dumpFile << "\n  sys:" << SystLabel[sys] 
01039                << " (" << sys << "), type:" << cid //cmp.GetName() 
01040                << " ...\n";
01041   
01042   if(verbose())
01043     std::cout << "L1Comparator::process print:\n" << std::flush
01044               << cmp.print()
01045               << std::flush;
01046   
01048   DEmatchEvt[sys] &= cmp.do_compare(m_dumpFile,m_dumpMode);
01049   
01051   L1DEDigiCollection dg = cmp.getDEDigis();
01052 
01053   if(verbose())
01054     for(L1DEDigiCollection::iterator it=dg.begin(); it!=dg.end();it++)
01055       std::cout << *it << "\n";
01056 
01058   for(L1DEDigiCollection::iterator it=dg.begin(); it!=dg.end();it++)
01059     it->setSid(sys);
01061   for(L1DEDigiCollection::iterator it=dg.begin(); it!=dg.end();it++)
01062     it->setCid(cid);
01063 
01065   m_dedigis.insert(m_dedigis.end(), dg.begin(), dg.end()); 
01066   for(int i=0; i<2; i++)
01067     DEncand[sys][i] += cmp.get_ncand(i);
01068 
01069   if(verbose())
01070     std::cout << "L1Comparator::process " 
01071               << " system:" << SystLabel[sys] 
01072               << " type:"   << cmp.GetName(0) 
01073               << " ndata:"  << DEncand[sys][0]
01074               << " nemul:"  << DEncand[sys][1]
01075               << " (size "  << data->size() << "," <<emul->size() << ")"   
01076               << " ndigis:" << dg.size()
01077               << " agree? " << DEmatchEvt[sys]
01078               << std::endl;
01079 
01080   if(verbose())
01081     std::cout << "L1Comparator::process -ing system:" 
01082               << sys << " (" << SystLabel[sys] << ")...done.\n" 
01083               << std::flush;
01084 }
01085 
01086 //--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--
01087 
01088 bool
01089 L1Comparator::compareCollections(edm::Handle<L1GlobalTriggerReadoutRecord> data, 
01090                                  edm::Handle<L1GlobalTriggerReadoutRecord> emul) {
01091 
01092   if(verbose())
01093     std::cout << "L1Comparator -- result of GT embedded comparison.\n"
01094               << "L1GlobalTriggerReadoutRecord:: data and emulator agree? "
01095               << ((*data==*emul)?"yes":"no")
01096               << std::endl;
01097   
01098   m_dumpFile << "\n L1GlobalTriggerReadoutRecord candidates...\n";
01099 
01100   bool thematch = true;
01101   
01102   thematch &= (*data==*emul);
01103   
01104   bool match = thematch;
01105 
01106   if(m_dumpMode==0 && match)
01107     return match;    
01108   
01109   //expand to check mismatching  stage
01110 
01111   //need to create new objects due to lack of suitable accessors
01112   // needed only for accessing gtPsbVector()
01113   std::auto_ptr<L1GlobalTriggerReadoutRecord> 
01114     data_( new L1GlobalTriggerReadoutRecord(*(data.product())));
01115   std::auto_ptr<L1GlobalTriggerReadoutRecord> 
01116     emul_( new L1GlobalTriggerReadoutRecord(*(emul.product())));
01117 
01118   match = true;
01119   m_dumpFile << "\tmatch stage: ";
01120   match &= (data->gtfeWord()            == emul->gtfeWord()     );
01121   m_dumpFile << " gtfeWord:" << match;          
01122   match &= (data->gtFdlWord()           == emul->gtFdlWord()    );
01123   m_dumpFile << " gtFdlWord:" << match;                 
01124   match &= (data->muCollectionRefProd() == emul->muCollectionRefProd());
01125   m_dumpFile << " muCollectionRefProd:" << match << "\n"; 
01126   boost::uint16_t dt_psb_bid=0, em_psb_bid=0;    
01127   size_t npsbw = (data_->gtPsbVector().size()>emul_->gtPsbVector().size())?
01128     emul_->gtPsbVector().size():data_->gtPsbVector().size();
01129   for(int idx=0; idx<(int)npsbw; idx++) {
01130     if(data_->gtPsbVector().at(idx) != emul_->gtPsbVector().at(idx) ) {
01131       //match &= false;
01132       dt_psb_bid = data_->gtPsbVector().at(idx).boardId();
01133       em_psb_bid = emul_->gtPsbVector().at(idx).boardId();
01134       break;
01135     }
01136   }
01137   match &= (data->gtPsbWord(dt_psb_bid) == emul->gtPsbWord(em_psb_bid) );
01138   //if(!match) {
01139   //  m_dumpFile << "  data"; data_->gtPsbWord(dt_psb_bid).print(m_dumpFile);
01140   //  m_dumpFile << "\nemul"; emul_->gtPsbWord(em_psb_bid).print(m_dumpFile);
01141   //}
01142   //problem: vector not accessible from handle (only reference non-const)
01143   //std::vector<L1GtPsbWord>& data_psbVec = data_->gtPsbVector();
01144   //std::vector<L1GtPsbWord>& emul_psbVec = emul_->gtPsbVector();
01145   m_dumpFile << " gtPsbWord("<<dt_psb_bid<<","<<em_psb_bid<<"):" << match << "\n"; 
01146 
01148 
01149   // gt decision
01150   m_dumpFile << "\n\tGlobal decision: "
01151            << data->decision() << " (data) "
01152            << emul->decision() << " (emul) "
01153            << std::endl;
01154 
01155   // gt decision word
01156   m_dumpFile << "\n\tDecisionWord  (bits: 63:0, 127:64)";
01157   int nbitword = 64; 
01158   std::vector<bool> data_gtword = data->decisionWord();
01159   std::vector<bool> emul_gtword = emul->decisionWord();
01160   m_dumpFile << "\n\tdata: ";
01161   for(int i=0; i<nbitword; i++) {
01162     if (i%16==0) m_dumpFile << " ";
01163     m_dumpFile << (data_gtword.at(nbitword-1-i)  ? '1' : '0');
01164   }
01165   m_dumpFile << "\n\t      ";
01166   for(int i=0; i<nbitword; i++) {
01167     if (i%16==0) m_dumpFile << " ";
01168     m_dumpFile << (data_gtword.at(nbitword*2-1-i)  ? '1' : '0');
01169   }
01170   m_dumpFile << "\n\temul: ";
01171   for(int i=0; i<nbitword; i++) {
01172     if (i%16==0) m_dumpFile << " ";
01173     m_dumpFile << (emul_gtword.at(nbitword-1-i)  ? '1' : '0');
01174   }
01175   m_dumpFile << "\n\t      ";
01176   for(int i=0; i<nbitword; i++) {
01177     if (i%16==0) m_dumpFile << " ";
01178     m_dumpFile << (emul_gtword.at(nbitword*2-1-i)  ? '1' : '0');
01179   }
01180   m_dumpFile << std::endl;
01181  
01182   m_dumpFile << "\n\tDecisionWordExtended  (bits: 0:63)";
01183   std::vector<bool> data_decwext = data->gtFdlWord().gtDecisionWordExtended();
01184   std::vector<bool> emul_decwext = emul->gtFdlWord().gtDecisionWordExtended();
01185   m_dumpFile << "\n\tdata: ";
01186   for(int i=0; i<nbitword; i++) {
01187     if (i%16==0) m_dumpFile << " ";
01188     m_dumpFile << (data_decwext.at(nbitword-1-i)  ? '1' : '0');
01189   }
01190   m_dumpFile << "\n\temul: ";
01191   for(int i=0; i<nbitword; i++) {
01192     if (i%16==0) m_dumpFile << " ";
01193     m_dumpFile << (emul_decwext.at(nbitword-1-i)  ? '1' : '0');
01194   }
01195   m_dumpFile << std::endl;
01196 
01197   m_dumpFile << "\n\tTechnical triggers (bits: 0:63)";
01198   std::vector<bool> data_fdlttw = data->gtFdlWord().gtTechnicalTriggerWord();
01199   std::vector<bool> emul_fdlttw = emul->gtFdlWord().gtTechnicalTriggerWord();
01200   assert((int)data_fdlttw.size()==nbitword); 
01201   m_dumpFile << "\n\tdata: ";
01202   for(int i=0; i<nbitword; i++) {
01203     if (i%16==0) m_dumpFile << " ";
01204     m_dumpFile << (data_fdlttw.at(nbitword-1-i)  ? '1' : '0');
01205   }
01206   m_dumpFile << "\n\temul: ";
01207   for(int i=0; i<nbitword; i++) {
01208     if (i%16==0) m_dumpFile << " ";
01209     m_dumpFile << (emul_fdlttw.at(nbitword-1-i)  ? '1' : '0');
01210   }
01211   m_dumpFile << std::endl;
01212 
01213   m_dumpFile << "\n\tL1GtFdlWord";
01214   m_dumpFile << "\n\tdata: "
01215            << " BoardId:"   << data->gtFdlWord().boardId()
01216            << " BxInEvent:" << data->gtFdlWord().bxInEvent()
01217            << " BxNr:"      << data->gtFdlWord().bxNr()
01218            << " EventNr:"   << data->gtFdlWord().eventNr()
01219            << " NoAlgo:"    << data->gtFdlWord().noAlgo()
01220            << " FinalOR:"   << data->gtFdlWord().finalOR()
01221            << " LocalBxNr:" << data->gtFdlWord().localBxNr();
01222   m_dumpFile << "\n\temul: "
01223            << " BoardId:"   << emul->gtFdlWord().boardId()
01224            << " BxInEvent:" << emul->gtFdlWord().bxInEvent()
01225            << " BxNr:"      << emul->gtFdlWord().bxNr()
01226            << " EventNr:"   << emul->gtFdlWord().eventNr()
01227            << " NoAlgo:"    << emul->gtFdlWord().noAlgo()
01228            << " FinalOR:"   << emul->gtFdlWord().finalOR()
01229            << " LocalBxNr:" << emul->gtFdlWord().localBxNr()
01230            << std::endl;
01231 
01232   m_dumpFile << "\n\tL1GtfeWord";
01233   m_dumpFile << "\n\tdata: " 
01234            << " BoardId:"        << data->gtfeWord().boardId()
01235            << " RecordLength:"   << data->gtfeWord().recordLength()
01236            << " BxNr:"           << data->gtfeWord().bxNr() 
01237            << " SetupVersion:"   << data->gtfeWord().setupVersion()
01238            << " ActiveBoards:"   << data->gtfeWord().activeBoards()
01239            << " TotalTriggerNr:" << data->gtfeWord().totalTriggerNr();
01240   m_dumpFile << "\n\temul: " 
01241            << " BoardId:"        << emul->gtfeWord().boardId()
01242            << " RecordLength:"   << emul->gtfeWord().recordLength()
01243            << " BxNr:"           << emul->gtfeWord().bxNr() 
01244            << " SetupVersion:"   << emul->gtfeWord().setupVersion()
01245            << " ActiveBoards:"   << emul->gtfeWord().activeBoards()
01246            << " TotalTriggerNr:" << emul->gtfeWord().totalTriggerNr()
01247            << std::endl;
01248 
01249   //uint16_t psb_bid = (uint16_t)idx; //need to find relevant board-id to dump
01250   m_dumpFile << "\n\tgtPsbWord";
01251   m_dumpFile << "\n\tdata: "
01252            << " Board Id:"  << data->gtPsbWord(dt_psb_bid).boardId()
01253            << " BxInEvent:" << data->gtPsbWord(dt_psb_bid).bxInEvent()
01254            << " BxNr:"      << data->gtPsbWord(dt_psb_bid).bxNr()
01255            << " LocalBxNr:" << data->gtPsbWord(dt_psb_bid).localBxNr()
01256            << " EventNr:"   << data->gtPsbWord(dt_psb_bid).eventNr();
01257   m_dumpFile << "\n\temul: "
01258            << " Board Id:"  << emul->gtPsbWord(em_psb_bid).boardId()
01259            << " BxInEvent:" << emul->gtPsbWord(em_psb_bid).bxInEvent()
01260            << " BxNr:"      << emul->gtPsbWord(em_psb_bid).bxNr()
01261            << " LocalBxNr:" << emul->gtPsbWord(em_psb_bid).localBxNr()
01262            << " EventNr:"   << emul->gtPsbWord(em_psb_bid).eventNr()
01263            << std::endl;
01264   
01265   // m_dumpFile << "\n\tA,B_Data_CH7:0"
01266   //       << " ...waiting for data accessors in dataformats!\n\n";
01267   //#include "DataFormats/L1GlobalTrigger/src/L1GtPsbWord.cc"
01268   
01269   m_dumpFile << "\n\tA_Data_CH7:0";
01270   m_dumpFile << "\n\tdata: ";
01271   for (int i=0; i<8; ++i)
01272     m_dumpFile << data->gtPsbWord(dt_psb_bid).aData(7-i) << " ";
01273   m_dumpFile << "\n\temul: ";
01274   for (int i=0; i<8; ++i)
01275     m_dumpFile << emul->gtPsbWord(em_psb_bid).aData(7-i) << " ";
01276   m_dumpFile << std::endl;
01277   
01278   m_dumpFile << "\n\tA_Data_CH7:0";
01279   m_dumpFile << "\n\tdata: ";
01280   for (int i=0; i<8; ++i)
01281     m_dumpFile << data->gtPsbWord(dt_psb_bid).bData(7-i) << " ";
01282   m_dumpFile << "\n\temul: ";
01283   for (int i=0; i<8; ++i)
01284     m_dumpFile << emul->gtPsbWord(em_psb_bid).bData(7-i) << " ";
01285   m_dumpFile << "\n" << std::endl;
01286 
01287 
01289 
01291   if(false) {
01292     m_dumpFile << "---debug: print full gt record---";
01293     m_dumpFile << "\n\tdata: ";   
01294     data->print(m_dumpFile);
01295     m_dumpFile << "\n\temul: ";   
01296     emul->print(m_dumpFile);
01297     m_dumpFile << "\n"; 
01298     m_dumpFile << "---debug: print full gt record Done.---\n\n";
01299   }
01300 
01301   char ok[10];
01302   if(match) sprintf(ok,"successful");
01303   else      sprintf(ok,"failed");
01304   m_dumpFile << " ...L1GlobalTriggerReadoutRecord data and emulator comparison: " 
01305            << ok << std::endl;
01306 
01307   return thematch;
01308 }
01309 
01310 
01311 bool
01312 L1Comparator::compareCollections(edm::Handle<L1GlobalTriggerEvmReadoutRecord> data, 
01313                                  edm::Handle<L1GlobalTriggerEvmReadoutRecord> emul) {
01314 
01315   if(verbose())
01316     std::cout << "L1Comparator -- result of GT embedded comparison.\n"
01317               << "L1GlobalTriggerEvmReadoutRecord data and emulator agree? "
01318               << ((*data==*emul)?"yes":"no")
01319               << std::endl;
01320   
01321   m_dumpFile << "\n  L1GlobalTriggerEvmReadoutRecord candidates...\n";
01322   
01323   bool match = true;
01324   match &= (*data==*emul);
01325   
01326   if(m_dumpMode==0 && match)
01327     return match;
01328   
01329   // gt decision
01330   m_dumpFile << "\n\tGlobal decision: "
01331              << data->decision() << " (data) "
01332              << emul->decision() << " (emul) "
01333              << std::endl;
01334 
01335   // gt decision word
01336   m_dumpFile << "\n\tDecisionWord  (bits: 0:63, 127:64)";
01337   int nbitword = 64; 
01338   std::vector<bool> data_gtword = data->decisionWord();
01339   std::vector<bool> emul_gtword = emul->decisionWord();
01340   m_dumpFile << "\n\tdata: ";
01341   for(int i=0; i<nbitword; i++) {
01342     if (i%16==0) m_dumpFile << " ";
01343     m_dumpFile << (data_gtword.at(nbitword-1-i)  ? '1' : '0');
01344   }
01345   m_dumpFile << "\n\t      ";
01346   for(int i=0; i<nbitword; i++) {
01347     if (i%16==0) m_dumpFile << " ";
01348     m_dumpFile << (data_gtword.at(nbitword*2-1-i)  ? '1' : '0');
01349   }
01350   m_dumpFile << "\n\temul: ";
01351   for(int i=0; i<nbitword; i++) {
01352     if (i%16==0) m_dumpFile << " ";
01353     m_dumpFile << (emul_gtword.at(nbitword-1-i)  ? '1' : '0');
01354   }
01355   m_dumpFile << "\n\t      ";
01356   for(int i=0; i<nbitword; i++) {
01357     if (i%16==0) m_dumpFile << " ";
01358     m_dumpFile << (emul_gtword.at(nbitword*2-1-i)  ? '1' : '0');
01359   }
01360   m_dumpFile << std::endl;
01361 
01362   m_dumpFile << "\n\tDecisionWordExtended  (bits: 0:63)";
01363   std::vector<bool> data_decwext = data->gtFdlWord().gtDecisionWordExtended();
01364   std::vector<bool> emul_decwext = emul->gtFdlWord().gtDecisionWordExtended();
01365   m_dumpFile << "\n\tdata: ";
01366   for(int i=0; i<nbitword; i++) {
01367     if (i%16==0) m_dumpFile << " ";
01368     m_dumpFile << (data_decwext.at(nbitword-1-i)  ? '1' : '0');
01369   }
01370   m_dumpFile << "\n\temul: ";
01371   for(int i=0; i<nbitword; i++) {
01372     if (i%16==0) m_dumpFile << " ";
01373     m_dumpFile << (emul_decwext.at(nbitword-1-i)  ? '1' : '0');
01374   }
01375   m_dumpFile << std::endl;
01376 
01377   m_dumpFile << "\n\tTechnical triggers (bits: 0:63)";
01378   std::vector<bool> data_fdlttw = data->gtFdlWord().gtTechnicalTriggerWord();
01379   std::vector<bool> emul_fdlttw = emul->gtFdlWord().gtTechnicalTriggerWord();
01380   assert((int)data_fdlttw.size()==nbitword); 
01381   m_dumpFile << "\n\tdata: ";
01382   for(int i=0; i<nbitword; i++) {
01383     if (i%16==0) m_dumpFile << " ";
01384     m_dumpFile << (data_fdlttw.at(nbitword-1-i)  ? '1' : '0');
01385   }
01386   m_dumpFile << "\n\temul: ";
01387   for(int i=0; i<nbitword; i++) {
01388     if (i%16==0) m_dumpFile << " ";
01389     m_dumpFile << (emul_fdlttw.at(nbitword-1-i)  ? '1' : '0');
01390   }
01391   m_dumpFile << std::endl;
01392 
01393   m_dumpFile << "\n\tL1GtFdlWord";
01394   m_dumpFile << "\n\tdata: "
01395              << " BoardId:"   << data->gtFdlWord().boardId()
01396              << " BxInEvent:" << data->gtFdlWord().bxInEvent()
01397              << " BxNr:"      << data->gtFdlWord().bxNr()
01398              << " EventNr:"   << data->gtFdlWord().eventNr()
01399              << " NoAlgo:"    << data->gtFdlWord().noAlgo()
01400              << " FinalOR:"   << data->gtFdlWord().finalOR()
01401              << " LocalBxNr:" << data->gtFdlWord().localBxNr();
01402   m_dumpFile << "\n\temul: "
01403              << " BoardId:"   << emul->gtFdlWord().boardId()
01404              << " BxInEvent:" << emul->gtFdlWord().bxInEvent()
01405              << " BxNr:"      << emul->gtFdlWord().bxNr()
01406              << " EventNr:"   << emul->gtFdlWord().eventNr()
01407              << " NoAlgo:"    << emul->gtFdlWord().noAlgo()
01408              << " FinalOR:"   << emul->gtFdlWord().finalOR()
01409              << " LocalBxNr:" << emul->gtFdlWord().localBxNr()
01410              << std::endl;
01411 
01412   m_dumpFile << "\n\tL1GtfeWord";
01413   m_dumpFile << "\n\tdata: " 
01414              << " BoardId:"        << data->gtfeWord().boardId()
01415              << " RecordLength:"   << data->gtfeWord().recordLength()
01416              << " BxNr:"           << data->gtfeWord().bxNr() 
01417              << " SetupVersion:"   << data->gtfeWord().setupVersion()
01418              << " ActiveBoards:"   << data->gtfeWord().activeBoards()
01419              << " TotalTriggerNr:" << data->gtfeWord().totalTriggerNr();
01420   m_dumpFile << "\n\temul: " 
01421              << " BoardId:"        << emul->gtfeWord().boardId()
01422              << " RecordLength:"   << emul->gtfeWord().recordLength()
01423              << " BxNr:"           << emul->gtfeWord().bxNr() 
01424              << " SetupVersion:"   << emul->gtfeWord().setupVersion()
01425              << " ActiveBoards:"   << emul->gtfeWord().activeBoards()
01426              << " TotalTriggerNr:" << emul->gtfeWord().totalTriggerNr()
01427              << std::endl;
01428 
01429   // -- tcs 
01430   m_dumpFile << "\n\ttcsWord";
01431   m_dumpFile << "\n\tdata:"
01432              << " DaqNr:"              << data->tcsWord().daqNr()
01433              << " TriggerType:"        << data->tcsWord().triggerType()
01434              << " Status:"             << data->tcsWord().status()
01435              << " BxNr:"               << data->tcsWord().bxNr()
01436              << " PartTrigNr:"         << data->tcsWord().partTrigNr()
01437              << " EventNr:"            << data->tcsWord().eventNr() << "\n\t"
01438              << " AssignedPartitions:" << data->tcsWord().assignedPartitions()
01439              << " PartRunNr:"          << data->tcsWord().partTrigNr()
01440              << " OrbitNr:"            << data->tcsWord().orbitNr();
01441   m_dumpFile << "\n\temul:"                                                  
01442              << " DaqNr:"              << emul->tcsWord().daqNr()
01443              << " TriggerType:"        << emul->tcsWord().triggerType()
01444              << " Status:"             << emul->tcsWord().status()
01445              << " BxNr:"               << emul->tcsWord().bxNr()
01446              << " PartTrigNr:"         << emul->tcsWord().partTrigNr()
01447              << " EventNr:"            << emul->tcsWord().eventNr() << "\n\t"       
01448              << " AssignedPartitions:" << emul->tcsWord().assignedPartitions()
01449              << " PartRunNr:"          << emul->tcsWord().partTrigNr()
01450              << " OrbitNr:"            << emul->tcsWord().orbitNr()
01451              << "\n" << std::endl;
01452 
01453   char ok[10];
01454   if(match) sprintf(ok,"successful");
01455   else      sprintf(ok,"failed");
01456   m_dumpFile << " ...L1GlobalTriggerEvmReadoutRecord data and emulator comparison: " 
01457              << ok << std::endl;
01458 
01459   return match;
01460 }
01461 
01462 /*following record is not produced by hardware, included for sw dump/tests only*/
01463 bool
01464 L1Comparator::compareCollections(edm::Handle<L1GlobalTriggerObjectMapRecord> data, 
01465                                  edm::Handle<L1GlobalTriggerObjectMapRecord> emul) {
01466 
01467   m_dumpFile << "\n  L1GlobalTriggerObjectMapRecord candidates...\n";
01468 
01469   bool match = true;
01470   //match &= (*data==*emul);
01471 
01472   const std::vector<L1GlobalTriggerObjectMap>& data_ovec = data->gtObjectMap();
01473   const std::vector<L1GlobalTriggerObjectMap>& emul_ovec = emul->gtObjectMap();
01474 
01475   for(std::vector<L1GtLogicParser::OperandToken>::size_type idx=0; idx<data_ovec.size(); idx++) {
01476     match &= ( data_ovec.at(idx).algoName()               == emul_ovec.at(idx).algoName()               );
01477     match &= ( data_ovec.at(idx).algoBitNumber()          == emul_ovec.at(idx).algoBitNumber()          );
01478     match &= ( data_ovec.at(idx).algoGtlResult()          == emul_ovec.at(idx).algoGtlResult()          );
01479     match &= ( data_ovec.at(idx).combinationVector()      == emul_ovec.at(idx).combinationVector()      );
01480     match &= ( data_ovec.at(idx).operandTokenVector().size()==emul_ovec.at(idx).operandTokenVector().size());
01481     if(match) {
01482       for(std::vector<L1GtLogicParser::OperandToken>::size_type i=0; i<data_ovec.at(idx).operandTokenVector().size(); i++) {
01483         match &= ( data_ovec.at(idx).operandTokenVector().at(i).tokenName ==
01484                    emul_ovec.at(idx).operandTokenVector().at(i).tokenName );
01485         match &= ( data_ovec.at(idx).operandTokenVector().at(i).tokenNumber ==
01486                    emul_ovec.at(idx).operandTokenVector().at(i).tokenNumber );
01487         match &= ( data_ovec.at(idx).operandTokenVector().at(i).tokenResult ==
01488                    emul_ovec.at(idx).operandTokenVector().at(i).tokenResult );
01489       }
01490     }
01491   }
01492 
01493   if(m_dumpMode==0 && match)
01494     return match;
01495   
01496   // dump
01497   int idx = 0;
01498   m_dumpFile << "\n\tL1GlobalTriggerObjectMap";
01499   m_dumpFile << "\n\tdata: "
01500              << " algorithmName:"         << data_ovec.at(idx).algoName()
01501              << " Bitnumber:"             << data_ovec.at(idx).algoBitNumber()
01502              << " GTLresult:"             << data_ovec.at(idx).algoGtlResult()
01503              << " combinationVectorSize:" << data_ovec.at(idx).combinationVector().size()
01504              << " operandTokenVector:"    << data_ovec.at(idx).operandTokenVector().size(); 
01505   m_dumpFile << "\n\temul: "
01506              << " algorithmName:"         << emul_ovec.at(idx).algoName()
01507              << " Bitnumber:"             << emul_ovec.at(idx).algoBitNumber()
01508              << " GTLresult:"             << emul_ovec.at(idx).algoGtlResult()
01509              << " combinationVectorSize:" << emul_ovec.at(idx).combinationVector().size()
01510              << " operandTokenVector:"    << emul_ovec.at(idx).operandTokenVector().size() 
01511              << "\n" << std::endl;
01512 
01513   char ok[10];
01514   if(match) sprintf(ok,"successful");
01515   else      sprintf(ok,"failed");
01516   m_dumpFile << " ...L1GlobalTriggerObjectMapRecord data and emulator comparison: " 
01517              << ok << std::endl;
01518   
01519   return match;
01520 }
01521 
01522 
01523 bool
01524 L1Comparator::compareFedRawCollections(edm::Handle<FEDRawDataCollection> data, 
01525                                        edm::Handle<FEDRawDataCollection> emul, int fedId) {
01526   if(verbose())
01527     std::cout << "[L1Comparator]  fedraw start processing :" << std::endl << std::flush;
01528   if(dumpEvent_) {
01529     m_dumpFile << "\nEvent: " << nevt_ << std::endl;
01530     dumpEvent_=false;
01531   }
01532   m_dumpFile << "\n  FEDRawData candidates...\n";
01533   const FEDRawData& raw_fed_data = data->FEDData(fedId);
01534   const FEDRawData& raw_fed_emul = emul->FEDData(fedId);
01535   bool raw_match=true;
01536   for(int i=0; i!=(int)raw_fed_data.size();i++) {
01537     raw_match &= ( raw_fed_data.data()[i] == raw_fed_emul.data()[i] );
01538   }
01539   unsigned long dd = 0, de = 0;
01540   for(int i=0; i<(int)raw_fed_data.size()/4;i++) {
01541     dd=0; de=0;
01542     for(int j=0; j<4; j++)
01543       dd += ((raw_fed_data.data()[i*4+j]&0xff)<<(8*j));
01544     for(int j=0; j<4; j++) 
01545       de += ((raw_fed_emul.data()[i*4+j]&0xff)<<(8*j));
01546     if(m_dumpMode==-1 || (m_dumpMode==1 && dd!=de) ) {
01547       m_dumpFile << "\n\tdata: " << std::setw(8) << std::setfill('0') << std::hex << dd;
01548       m_dumpFile << "\n\temul: " << std::setw(8) << std::setfill('0') << std::hex << de;
01549     }
01550     m_dumpFile << std::endl;
01551   }
01552   char ok[10];
01553   if(raw_match) sprintf(ok,"successful");
01554   else          sprintf(ok,"failed");
01555   m_dumpFile << " ...FEDRawData data and emulator comparison: " 
01556              << ok << std::endl;
01557   return raw_match;
01558 }
01559 
01560 template <class myCol> 
01561 bool L1Comparator::CompareCollections( edm::Handle<myCol> data, edm::Handle<myCol> emul) {
01562   bool match = true;
01563   typedef typename myCol::size_type col_sz;
01564   typedef typename myCol::iterator col_it;
01565   col_sz ndata = data->size();
01566   col_sz nemul = emul->size();
01567   if(ndata!=nemul) {
01568     match &= false;
01569     m_dumpFile << " #cand mismatch!"
01570                << "\tdata: " << ndata
01571                << "\temul: " << nemul
01572                << std::endl;
01573   }
01574   col_it itd = data -> begin();
01575   col_it itm = emul -> begin();
01576   for (col_sz i=0; i<ndata; i++) {
01577     match &= dumpCandidate(*itd++,*itm++, m_dumpFile);
01578   }  
01579   return match; 
01580 }
01581 
01582 template <class T> 
01583 bool L1Comparator::dumpCandidate( const T& dt, const T& em, std::ostream& s) {
01584   if(dt==em)
01585     return true;
01586   s<<dt<<std::endl; 
01587   s<<em<<std::endl<<std::endl;
01588   return false;
01589 }