00001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTProducer.h"
00002
00003
00004 #include "CondFormats/RunInfo/interface/RunInfo.h"
00005 #include "FWCore/Framework/interface/Run.h"
00006 #include "FWCore/Framework/interface/LuminosityBlock.h"
00007
00008 #include <vector>
00009 using std::vector;
00010 #include <iostream>
00011
00012
00013
00014 using std::cout;
00015 using std::endl;
00016 const int L1RCTProducer::crateFED[18][5]=
00017 {{613, 614, 603, 702, 718},
00018 {611, 612, 602, 700, 718},
00019 {627, 610, 601, 716, 722},
00020 {625, 626, 609, 714, 722},
00021 {623, 624, 608, 712, 722},
00022 {621, 622, 607, 710, 720},
00023 {619, 620, 606, 708, 720},
00024 {617, 618, 605, 706, 720},
00025 {615, 616, 604, 704, 718},
00026 {631, 632, 648, 703, 719},
00027 {629, 630, 647, 701, 719},
00028 {645, 628, 646, 717, 723},
00029 {643, 644, 654, 715, 723},
00030 {641, 642, 653, 713, 723},
00031 {639, 640, 652, 711, 721},
00032 {637, 638, 651, 709, 721},
00033 {635, 636, 650, 707, 721},
00034 {633, 634, 649, 705, 719}};
00035
00036
00037
00038 L1RCTProducer::L1RCTProducer(const edm::ParameterSet& conf) :
00039 rctLookupTables(new L1RCTLookupTables),
00040 rct(new L1RCT(rctLookupTables)),
00041 useEcal(conf.getParameter<bool>("useEcal")),
00042 useHcal(conf.getParameter<bool>("useHcal")),
00043 ecalDigis(conf.getParameter<std::vector<edm::InputTag> >("ecalDigis")),
00044 hcalDigis(conf.getParameter<std::vector<edm::InputTag> >("hcalDigis")),
00045 bunchCrossings(conf.getParameter<std::vector<int> >("BunchCrossings")),
00046 getFedsFromOmds(conf.getParameter<bool>("getFedsFromOmds")),
00047 queryDelayInLS(conf.getParameter<unsigned int>("queryDelayInLS")),
00048 queryIntervalInLS(conf.getParameter<unsigned int>("queryIntervalInLS")),
00049 fedUpdatedMask(0)
00050 {
00051 produces<L1CaloEmCollection>();
00052 produces<L1CaloRegionCollection>();
00053
00054 }
00055
00056 L1RCTProducer::~L1RCTProducer()
00057 {
00058 if(rct != 0) delete rct;
00059 if(rctLookupTables != 0) delete rctLookupTables;
00060 if(fedUpdatedMask != 0) delete fedUpdatedMask;
00061 }
00062
00063
00064 void L1RCTProducer::beginRun(edm::Run& run, const edm::EventSetup& eventSetup)
00065 {
00066
00067
00068 updateConfiguration(eventSetup);
00069
00070 int runNumber = run.run();
00071 updateFedVector(eventSetup,false,runNumber);
00072
00073 }
00074
00075
00076 void L1RCTProducer::beginLuminosityBlock(edm::LuminosityBlock& lumiSeg,const edm::EventSetup& context)
00077 {
00078
00079
00080 if (getFedsFromOmds)
00081 {
00082 unsigned int nLumi = lumiSeg.luminosityBlock();
00083
00084 if ( ( (nLumi - 1) == queryDelayInLS)
00085 || (queryIntervalInLS > 0 && nLumi % queryIntervalInLS == 0 ) )
00086 {
00087 int runNumber = lumiSeg.run();
00088
00089 updateFedVector(context,true,runNumber);
00090 }
00091 else if (queryIntervalInLS <= 0)
00092 {
00093
00094 }
00095 }
00096 }
00097
00098
00099
00100 void L1RCTProducer::updateConfiguration(const edm::EventSetup& eventSetup)
00101 {
00102
00103
00104
00105
00106
00107 edm::ESHandle<L1RCTParameters> rctParameters;
00108 eventSetup.get<L1RCTParametersRcd>().get(rctParameters);
00109 const L1RCTParameters* r = rctParameters.product();
00110
00111
00112
00113
00114 edm::ESHandle<L1CaloEtScale> emScale;
00115 eventSetup.get<L1EmEtScaleRcd>().get(emScale);
00116 const L1CaloEtScale* s = emScale.product();
00117
00118
00119 edm::ESHandle<L1CaloEcalScale> ecalScale;
00120 eventSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
00121 const L1CaloEcalScale* e = ecalScale.product();
00122
00123
00124 edm::ESHandle<L1CaloHcalScale> hcalScale;
00125 eventSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
00126 const L1CaloHcalScale* h = hcalScale.product();
00127
00128
00129 rctLookupTables->setEcalScale(e);
00130 rctLookupTables->setHcalScale(h);
00131
00132 rctLookupTables->setRCTParameters(r);
00133 rctLookupTables->setL1CaloEtScale(s);
00134 }
00135
00136
00137 void L1RCTProducer::updateFedVector(const edm::EventSetup& eventSetup, bool getFromOmds, int runNumber)
00138 {
00139
00140 edm::ESHandle<L1RCTChannelMask> channelMask;
00141 eventSetup.get<L1RCTChannelMaskRcd>().get(channelMask);
00142 const L1RCTChannelMask* cEs = channelMask.product();
00143
00144
00145
00146 edm::ESHandle<L1RCTNoisyChannelMask> hotChannelMask;
00147 eventSetup.get<L1RCTNoisyChannelMaskRcd>().get(hotChannelMask);
00148 const L1RCTNoisyChannelMask* cEsNoise = hotChannelMask.product();
00149 rctLookupTables->setNoisyChannelMask(cEsNoise);
00150
00151
00152
00153
00154
00155
00156
00157 if(fedUpdatedMask!=0) delete fedUpdatedMask;
00158
00159 fedUpdatedMask = new L1RCTChannelMask();
00160
00161 for (int i = 0; i < 18; i++)
00162 {
00163 for (int j = 0; j < 2; j++)
00164 {
00165 for (int k = 0; k < 28; k++)
00166 {
00167 fedUpdatedMask->ecalMask[i][j][k] = cEs->ecalMask[i][j][k];
00168 fedUpdatedMask->hcalMask[i][j][k] = cEs->hcalMask[i][j][k] ;
00169 }
00170 for (int k = 0; k < 4; k++)
00171 {
00172 fedUpdatedMask->hfMask[i][j][k] = cEs->hfMask[i][j][k];
00173 }
00174 }
00175 }
00176
00177
00178
00179
00180 const std::vector<int> Feds = getFromOmds ? getFedVectorFromOmds(eventSetup) : getFedVectorFromRunInfo(eventSetup);
00181
00182
00183
00184
00185
00186
00187
00188 std::vector<int> caloFeds;
00189
00190
00191 for(std::vector<int>::const_iterator cf = Feds.begin(); cf != Feds.end(); ++cf)
00192 {
00193 int fedNum = *cf;
00194 if(fedNum > 600 && fedNum <724)
00195 caloFeds.push_back(fedNum);
00196 }
00197
00198 for(int cr = 0; cr < 18; ++cr)
00199 {
00200
00201 for(crateSection cs = c_min; cs <= c_max; cs = crateSection(cs +1))
00202 {
00203 bool fedFound = false;
00204
00205
00206
00207 std::vector<int>::iterator fv = std::find(caloFeds.begin(),caloFeds.end(),crateFED[cr][cs]);
00208 if(fv!=caloFeds.end())
00209 fedFound = true;
00210
00211 if(!fedFound) {
00212 int eta_min=0;
00213 int eta_max=0;
00214 bool phi_even[2] = {false};
00215 bool ecal=false;
00216
00217 switch (cs) {
00218 case ebEvenFed :
00219 eta_min = minBarrel;
00220 eta_max = maxBarrel;
00221 phi_even[0] = true;
00222 ecal = true;
00223 break;
00224
00225 case ebOddFed:
00226 eta_min = minBarrel;
00227 eta_max = maxBarrel;
00228 phi_even[1] = true;
00229 ecal = true;
00230 break;
00231
00232 case eeFed:
00233 eta_min = minEndcap;
00234 eta_max = maxEndcap;
00235 phi_even[0] = true;
00236 phi_even[1] = true;
00237 ecal = true;
00238 break;
00239
00240 case hbheFed:
00241 eta_min = minBarrel;
00242 eta_max = maxEndcap;
00243 phi_even[0] = true;
00244 phi_even[1] = true;
00245 ecal = false;
00246 break;
00247
00248 case hfFed:
00249 eta_min = minHF;
00250 eta_max = maxHF;
00251
00252 phi_even[0] = true;
00253 phi_even[1] = true;
00254 ecal = false;
00255 break;
00256 default:
00257 break;
00258
00259 }
00260 for(int ieta = eta_min; ieta <= eta_max; ++ieta)
00261 {
00262 if(ieta<=28)
00263 for(int even = 0; even<=1 ; even++)
00264 {
00265 if(phi_even[even])
00266 {
00267 if(ecal)
00268 fedUpdatedMask->ecalMask[cr][even][ieta-1] = true;
00269 else
00270 fedUpdatedMask->hcalMask[cr][even][ieta-1] = true;
00271 }
00272 }
00273 else
00274 for(int even = 0; even<=1 ; even++)
00275 if(phi_even[even])
00276 fedUpdatedMask->hfMask[cr][even][ieta-29] = true;
00277
00278 }
00279 }
00280 }
00281 }
00282
00283 rctLookupTables->setChannelMask(fedUpdatedMask);
00284
00285 }
00286
00287 const std::vector<int> L1RCTProducer::getFedVectorFromRunInfo(const edm::EventSetup& eventSetup)
00288 {
00289
00290
00291 edm::ESHandle<RunInfo> sum;
00292 eventSetup.get<RunInfoRcd>().get(sum);
00293 const RunInfo* summary=sum.product();
00294 const std::vector<int> fedvector = summary->m_fed_in;
00295
00296 return fedvector;
00297 }
00298
00299
00300 const std::vector<int> L1RCTProducer::getFedVectorFromOmds(const edm::EventSetup& eventSetup)
00301 {
00302
00303
00304
00305
00306 edm::ESHandle<RunInfo> sum;
00307 eventSetup.get<RunInfoRcd>().get("OmdsFedVector",sum);
00308 if (sum.isValid())
00309 {
00310 const RunInfo* summary=sum.product();
00311 const std::vector<int> fedvector = summary->m_fed_in;
00312
00313 return fedvector;
00314 }
00315 else
00316 {
00317 return getFedVectorFromRunInfo(eventSetup);
00318 }
00319
00320 }
00321
00322
00323
00324 void L1RCTProducer::produce(edm::Event& event, const edm::EventSetup& eventSetup)
00325 {
00326
00327
00328 std::auto_ptr<L1CaloEmCollection> rctEmCands (new L1CaloEmCollection);
00329 std::auto_ptr<L1CaloRegionCollection> rctRegions (new L1CaloRegionCollection);
00330
00331
00332 if(!(ecalDigis.size()==hcalDigis.size()&&hcalDigis.size()==bunchCrossings.size()))
00333 throw cms::Exception("BadInput")
00334 << "From what I see the number of your your ECAL input digi collections.\n"
00335 <<"is different from the size of your HCAL digi input collections\n"
00336 <<"or the size of your BX factor collection"
00337 <<"They must be the same to correspond to the same Bxs\n"
00338 << "It does not matter if one of them is empty\n";
00339
00340
00341
00342
00343
00344 for (unsigned short sample = 0; sample < bunchCrossings.size(); sample++)
00345 {
00346 edm::Handle<EcalTrigPrimDigiCollection> ecal;
00347 edm::Handle<HcalTrigPrimDigiCollection> hcal;
00348
00349 EcalTrigPrimDigiCollection ecalIn;
00350 HcalTrigPrimDigiCollection hcalIn;
00351
00352
00353 if(useHcal&&event.getByLabel(hcalDigis[sample], hcal))
00354 hcalIn = *hcal;
00355
00356 if(useEcal&&event.getByLabel(ecalDigis[sample],ecal))
00357 ecalIn = *ecal;
00358
00359 rct->digiInput(ecalIn,hcalIn);
00360 rct->processEvent();
00361
00362
00363 for (int j = 0; j<18; j++)
00364 {
00365 L1CaloEmCollection isolatedEGObjects = rct->getIsolatedEGObjects(j);
00366 L1CaloEmCollection nonisolatedEGObjects = rct->getNonisolatedEGObjects(j);
00367 for (int i = 0; i<4; i++)
00368 {
00369 isolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
00370 nonisolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
00371 rctEmCands->push_back(isolatedEGObjects.at(i));
00372 rctEmCands->push_back(nonisolatedEGObjects.at(i));
00373 }
00374 }
00375
00376
00377 for (int i = 0; i < 18; i++)
00378 {
00379 std::vector<L1CaloRegion> regions = rct->getRegions(i);
00380 for (int j = 0; j < 22; j++)
00381 {
00382 regions.at(j).setBx(bunchCrossings[sample]);
00383 rctRegions->push_back(regions.at(j));
00384 }
00385 }
00386
00387 }
00388
00389
00390
00391 event.put(rctEmCands);
00392 event.put(rctRegions);
00393
00394 }
00395
00396
00397 void L1RCTProducer::printFedVector(const std::vector<int> fedVector)
00398 {
00399 std::cout << "Contents of given fedVector: ";
00400 std::copy(fedVector.begin(), fedVector.end(), std::ostream_iterator<int>(std::cout, ", "));
00401 std::cout << std::endl;
00402 }
00403
00404
00405 void L1RCTProducer::printUpdatedFedMask()
00406 {
00407 if (fedUpdatedMask != 0)
00408 {
00409 fedUpdatedMask->print(std::cout);
00410 }
00411 else
00412 {
00413 std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
00414 }
00415 }
00416
00417
00418 void L1RCTProducer::printUpdatedFedMaskVerbose()
00419 {
00420 if (fedUpdatedMask != 0)
00421 {
00422
00423 std::cout << "Contents of fedUpdatedMask: ";
00424
00425 std::cout << "--> ECAL mask: " << std::endl;
00426 for (int i = 0; i < 18; i++)
00427 {
00428 for (int j = 0; j < 2; j++)
00429 {
00430 for (int k = 0; k < 28; k++)
00431 {
00432 std::cout << fedUpdatedMask->ecalMask[i][j][k] << ", ";
00433 }
00434 }
00435 }
00436 std::cout << "--> HCAL mask: " << std::endl;
00437 for (int i = 0; i < 18; i++)
00438 {
00439 for (int j = 0; j < 2; j++)
00440 {
00441 for (int k = 0; k < 28; k++)
00442 {
00443 std::cout << fedUpdatedMask->hcalMask[i][j][k] << ", ";
00444 }
00445 }
00446 }
00447 std::cout << "--> HF mask: " << std::endl;
00448 for (int i = 0; i < 18; i++)
00449 {
00450 for (int j = 0; j < 2; j++)
00451 {
00452 for (int k = 0; k < 4; k++)
00453 {
00454 std::cout << fedUpdatedMask->hfMask[i][j][k] << ", ";
00455 }
00456 }
00457 }
00458
00459 std::cout << std::endl;
00460 }
00461 else
00462 {
00463
00464 std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
00465 }
00466 }