Go to the documentation of this file.00001 #include "L1Trigger/RegionalCaloTrigger/interface/MaskedRctInputDigiProducer.h"
00002
00003 #include <vector>
00004 #include <string>
00005 #include <fstream>
00006 #include <iostream>
00007 using std::ifstream;
00008 using std::vector;
00009 using std::endl;
00010
00011
00012
00013
00014
00015 MaskedRctInputDigiProducer::MaskedRctInputDigiProducer(const edm::ParameterSet& iConfig):
00016 useEcal_(iConfig.getParameter<bool>("useEcal")),
00017 useHcal_(iConfig.getParameter<bool>("useHcal")),
00018 ecalDigisLabel_(iConfig.getParameter<edm::InputTag>("ecalDigisLabel")),
00019 hcalDigisLabel_(iConfig.getParameter<edm::InputTag>("hcalDigisLabel")),
00020 maskFile_(iConfig.getParameter<edm::FileInPath>("maskFile"))
00021 {
00022
00023
00024
00025
00026
00027
00028
00029
00030 produces<EcalTrigPrimDigiCollection>();
00031 produces<HcalTrigPrimDigiCollection>();
00032
00033
00034
00035 }
00036
00037
00038 MaskedRctInputDigiProducer::~MaskedRctInputDigiProducer()
00039 {
00040
00041
00042
00043
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 void
00053 MaskedRctInputDigiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00054 {
00055 using namespace edm;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 edm::Handle<EcalTrigPrimDigiCollection> ecal;
00068 edm::Handle<HcalTrigPrimDigiCollection> hcal;
00069
00070 if (useEcal_) { iEvent.getByLabel(ecalDigisLabel_, ecal); }
00071 if (useHcal_) { iEvent.getByLabel(hcalDigisLabel_, hcal); }
00072
00073 EcalTrigPrimDigiCollection ecalColl;
00074 HcalTrigPrimDigiCollection hcalColl;
00075 if (ecal.isValid()) { ecalColl = *ecal; }
00076 if (hcal.isValid()) { hcalColl = *hcal; }
00077
00078
00079
00080
00081
00082
00083
00084 ifstream maskFileStream(maskFile_.fullPath().c_str());
00085 if (!maskFileStream.is_open())
00086 {
00087 throw cms::Exception("FileInPathError")
00088 << "RCT mask file not opened" << std::endl;;
00089 }
00090
00091
00092
00093 std::string junk;
00094
00095 do
00096 {
00097
00098 maskFileStream >> junk;
00099 }
00100 while (junk.compare("ECAL:") != 0);
00101
00102
00103 std::vector<std::vector<std::vector<unsigned short> > > ecalMask(2,std::vector<std::vector<unsigned short> >(72,std::vector<unsigned short>(28,1)));
00104 std::vector<std::vector<std::vector<unsigned short> > > hcalMask(2,std::vector<std::vector<unsigned short> >(72,std::vector<unsigned short>(28,1)));
00105 std::vector<std::vector<std::vector<unsigned short> > > hfMask(2,std::vector<std::vector<unsigned short> >(18,std::vector<unsigned short>(8,1)));
00106
00107
00108
00109 for (int i = 1; i <= 72; i++)
00110 {
00111 int phi_index = (72 + 18 - i) % 72;
00112 if (phi_index == 0) {phi_index = 72;}
00113
00114 for (int j = 28; j >= 1; j--)
00115 {
00116 maskFileStream >> junk;
00117 if (junk.compare("-") == 0)
00118 {}
00119 else if ((junk.compare("X") == 0) || (junk.compare("x") == 0))
00120 {
00121 ecalMask.at(0).at(phi_index-1).at(j-1) = 0;
00122 }
00123 else
00124 {
00125 std::cerr << "RCT mask producer: error -- unrecognized character" << std::endl;
00126 }
00127 }
00128 for (int j = 1; j <= 28; j++)
00129 {
00130 maskFileStream >> junk;
00131 if(junk.compare("-") == 0)
00132 {}
00133 else if((junk.compare("X") == 0) || (junk.compare("x") == 0))
00134 {
00135 ecalMask.at(1).at(phi_index-1).at(j-1) = 0;
00136 }
00137 else
00138 {
00139 std::cerr << "RCT mask producer: error -- unrecognized character" << std::endl;
00140 }
00141 }
00142 }
00143
00144
00145 maskFileStream >> junk;
00146 if (junk.compare("HCAL:") != 0)
00147 {
00148 throw cms::Exception("FileInPathError")
00149 << "RCT mask producer: error reading ECAL mask" << std::endl;;
00150 }
00151
00152
00153
00154
00155
00156 for (int i = 1; i <= 72; i++)
00157 {
00158 int phi_index = (72 + 18 - i) % 72;
00159 if (phi_index == 0) {phi_index = 72;}
00160
00161 for (int j = 28; j >= 1; j--)
00162 {
00163 maskFileStream >> junk;
00164 if (junk.compare("-") == 0)
00165 {}
00166 else if ((junk.compare("X") == 0) || (junk.compare("x") == 0))
00167 {
00168 hcalMask.at(0).at(phi_index-1).at(j-1) = 0;
00169 }
00170 else
00171 {
00172 std::cerr << "RCT mask producer: error -- unrecognized character" << std::endl;
00173 }
00174 }
00175 for (int j = 1; j <= 28; j++)
00176 {
00177 maskFileStream >> junk;
00178 if(junk.compare("-") == 0)
00179 {}
00180 else if((junk.compare("X") == 0) || (junk.compare("x") == 0))
00181 {
00182 hcalMask.at(1).at(phi_index-1).at(j-1) = 0;
00183 }
00184 else
00185 {
00186 std::cerr << "RCT mask producer: error -- unrecognized character" << std::endl;
00187 }
00188 }
00189 }
00190
00191 maskFileStream >> junk;
00192 if (junk.compare("HF:") != 0)
00193 {
00194 throw cms::Exception("FileInPathError")
00195 << "RCT mask producer: error reading HCAL mask" << std::endl;;
00196 }
00197
00198
00199 for(int i = 0; i < 18; i++)
00200 {
00201
00202 for (int j = 4; j >= 1; j--)
00203 {
00204 if (maskFileStream >> junk) {}
00205 else { std::cerr << "RCT mask producer: error reading HF mask" << std::endl; }
00206 if (junk.compare("-") == 0)
00207 {}
00208 else if ((junk.compare("X") == 0) || (junk.compare("x") == 0))
00209 {
00210 hfMask.at(0).at(i).at(j-1) = 0;
00211 }
00212 else
00213 {
00214 std::cerr << "RCT mask producer: error -- unrecognized character" << std::endl;
00215 }
00216 }
00217 for (int j = 1; j <= 4; j++)
00218 {
00219 if (maskFileStream >> junk) {}
00220 else { std::cerr << "RCT mask producer: error reading HF mask" << std::endl; }
00221 if (junk.compare("-") == 0)
00222 {}
00223 else if ((junk.compare("X") == 0) || (junk.compare("x") == 0))
00224 {
00225 hfMask.at(1).at(i).at(j-1) = 0;
00226 }
00227 else
00228 {
00229 std::cerr << "RCT mask producer: error -- unrecognized character" << std::endl;
00230 }
00231 }
00232 }
00233
00234
00235
00236 maskFileStream.close();
00237
00238
00239
00240
00241
00242 std::auto_ptr<EcalTrigPrimDigiCollection>
00243 maskedEcalTPs(new EcalTrigPrimDigiCollection());
00244 std::auto_ptr<HcalTrigPrimDigiCollection>
00245 maskedHcalTPs(new HcalTrigPrimDigiCollection());
00246 maskedEcalTPs->reserve(56*72);
00247 maskedHcalTPs->reserve(56*72+18*8);
00248 int nEcalSamples = 0;
00249 int nHcalSamples = 0;
00250
00251 for (unsigned int i = 0; i < ecalColl.size(); i++)
00252 {
00253 nEcalSamples = ecalColl[i].size();
00254 short ieta = (short) ecalColl[i].id().ieta();
00255 unsigned short absIeta = (unsigned short) abs(ieta);
00256 int sign = ieta / absIeta;
00257 short iphi = (unsigned short) ecalColl[i].id().iphi();
00258
00259
00260
00261 EcalTriggerPrimitiveDigi
00262 ecalDigi(EcalTrigTowerDetId(sign, EcalTriggerTower, absIeta, iphi));
00263 ecalDigi.setSize(nEcalSamples);
00264
00265 for (int nSample = 0; nSample < nEcalSamples; nSample++)
00266 {
00267
00268 int energy = 0;
00269 bool fineGrain = false;
00270
00271 if (sign < 0)
00272 {
00273
00274 energy = ecalMask.at(0).at(iphi-1).at(absIeta-1) * ecalColl[i].sample(nSample).compressedEt();
00275 fineGrain = ecalMask.at(0).at(iphi-1).at(absIeta-1) * ecalColl[i].sample(nSample).fineGrain();
00276 }
00277 else if (sign > 0)
00278 {
00279
00280 energy = ecalMask.at(1).at(iphi-1).at(absIeta-1) * ecalColl[i].sample(nSample).compressedEt();
00281 fineGrain = ecalMask.at(1).at(iphi-1).at(absIeta-1) * ecalColl[i].sample(nSample).fineGrain();
00282 }
00283
00284 ecalDigi.setSample(nSample, EcalTriggerPrimitiveSample(energy,
00285 fineGrain,
00286 0));
00287 }
00288 maskedEcalTPs->push_back(ecalDigi);
00289 }
00290
00291
00292
00293 for (unsigned int i = 0; i < hcalColl.size(); i++)
00294 {
00295 nHcalSamples = hcalColl[i].size();
00296
00297 short ieta = (short) hcalColl[i].id().ieta();
00298 unsigned short absIeta = (unsigned short) abs(ieta);
00299 int sign = ieta / absIeta;
00300 short iphi = (unsigned short) hcalColl[i].id().iphi();
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 HcalTriggerPrimitiveDigi
00312 hcalDigi(HcalTrigTowerDetId(ieta,iphi));
00313 hcalDigi.setSize(nHcalSamples);
00314 hcalDigi.setPresamples(hcalColl[i].presamples());
00315
00316 for (int nSample = 0; nSample < nHcalSamples; nSample++)
00317 {
00318
00319 int energy = 0;
00320 bool fineGrain = false;
00321
00322 if (absIeta < 29)
00323 {
00324 if (sign < 0)
00325 {
00326 energy = hcalMask.at(0).at(iphi-1).at(absIeta-1) * hcalColl[i].sample(nSample).compressedEt();
00327 fineGrain = hcalMask.at(0).at(iphi-1).at(absIeta-1) * hcalColl[i].sample(nSample).fineGrain();
00328 }
00329 else if (sign > 0)
00330 {
00331 energy = hcalMask.at(1).at(iphi-1).at(absIeta-1) * hcalColl[i].sample(nSample).compressedEt();
00332 fineGrain = hcalMask.at(1).at(iphi-1).at(absIeta-1) * hcalColl[i].sample(nSample).fineGrain();
00333 }
00334 }
00335 else if ((absIeta >= 29) && (absIeta <= 32))
00336 {
00337
00338 short hf_phi_index = iphi/4;
00339
00340
00341 if (sign < 0)
00342 {
00343
00344
00345 energy = hfMask.at(0).at(hf_phi_index).at(absIeta-29) * hcalColl[i].sample(nSample).compressedEt();
00346 fineGrain = hfMask.at(0).at(hf_phi_index).at(absIeta-29) * hcalColl[i].sample(nSample).fineGrain();
00347 }
00348 else if (sign > 0)
00349 {
00350
00351
00352 energy = hfMask.at(1).at(hf_phi_index).at(absIeta-29) * hcalColl[i].sample(nSample).compressedEt();
00353 fineGrain = hfMask.at(1).at(hf_phi_index).at(absIeta-29) * hcalColl[i].sample(nSample).fineGrain();
00354 }
00355
00356
00357 }
00358
00359 hcalDigi.setSample(nSample, HcalTriggerPrimitiveSample(energy,
00360 fineGrain,
00361 0, 0));
00362
00363
00364
00365
00366
00367
00368 }
00369 maskedHcalTPs->push_back(hcalDigi);
00370 }
00371
00372
00373
00374
00375 iEvent.put(maskedEcalTPs);
00376 iEvent.put(maskedHcalTPs);
00377
00378 }
00379
00380
00381
00382
00383
00384 void
00385 MaskedRctInputDigiProducer::endJob() {
00386 }
00387
00388
00389 DEFINE_FWK_MODULE(MaskedRctInputDigiProducer);