00001
00012 #include "HLTrigger/HLTcore/interface/TriggerSummaryProducerAOD.h"
00013 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00014
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016
00017 #include<string>
00018
00019 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00020 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
00021 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00022 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00023 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00024 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00025 #include "DataFormats/JetReco/interface/CaloJet.h"
00026 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00027 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
00028 #include "DataFormats/Candidate/interface/CompositeCandidateFwd.h"
00029 #include "DataFormats/METReco/interface/MET.h"
00030 #include "DataFormats/METReco/interface/METFwd.h"
00031 #include "DataFormats/METReco/interface/CaloMET.h"
00032 #include "DataFormats/METReco/interface/CaloMETFwd.h"
00033 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
00034 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
00035
00036 #include "DataFormats/L1Trigger/interface/L1HFRingsFwd.h"
00037 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00038 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
00039 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00040 #include "DataFormats/L1Trigger/interface/L1EtMissParticleFwd.h"
00041
00042 #include "DataFormats/L1Trigger/interface/L1HFRings.h"
00043 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00044 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
00045 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00046 #include "DataFormats/L1Trigger/interface/L1EtMissParticle.h"
00047
00048 #include <algorithm>
00049 #include <typeinfo>
00050
00051
00052
00053
00054
00055 TriggerSummaryProducerAOD::TriggerSummaryProducerAOD(const edm::ParameterSet& ps) :
00056 pn_(ps.getParameter<std::string>("processName")),
00057 selector_(edm::ProcessNameSelector(pn_)),
00058 tns_(),
00059 filterTagsEvent_(pn_!="*"),
00060 filterTagsGlobal_(pn_!="*"),
00061 collectionTagsEvent_(pn_!="*"),
00062 collectionTagsGlobal_(pn_!="*"),
00063 toc_(),
00064 tags_(),
00065 offset_(),
00066 fobs_(),
00067 keys_(),
00068 ids_(),
00069 maskFilters_()
00070 {
00071 if (pn_=="@") {
00072
00073 if (edm::Service<edm::service::TriggerNamesService>().isAvailable()) {
00074
00075 tns_ = edm::Service<edm::service::TriggerNamesService>().operator->();
00076 if (tns_!=0) {
00077 pn_=tns_->getProcessName();
00078 } else {
00079 edm::LogError("TriggerSummaryProducerAOD") << "HLT Error: TriggerNamesService pointer = 0!";
00080 pn_="*";
00081 }
00082 } else {
00083 edm::LogError("TriggerSummaryProducerAOD") << "HLT Error: TriggerNamesService not available!";
00084 pn_="*";
00085 }
00086 selector_=edm::ProcessNameSelector(pn_);
00087 filterTagsEvent_ =InputTagSet(pn_!="*");
00088 filterTagsGlobal_ =InputTagSet(pn_!="*");
00089 collectionTagsEvent_ =InputTagSet(pn_!="*");
00090 collectionTagsGlobal_=InputTagSet(pn_!="*");
00091 }
00092 LogDebug("TriggerSummaryProducerAOD") << "Using process name: '" << pn_ <<"'";
00093
00094 filterTagsGlobal_.clear();
00095 collectionTagsGlobal_.clear();
00096
00097 produces<trigger::TriggerEvent>();
00098
00099 }
00100
00101 TriggerSummaryProducerAOD::~TriggerSummaryProducerAOD()
00102 {
00103 }
00104
00105
00106
00107
00108
00109 namespace {
00110 inline void
00111 tokenizeTag(const std::string& tag, std::string& label, std::string& instance, std::string& process){
00112
00113 using std::string;
00114
00115 const char token(':');
00116 const string empty;
00117
00118 label=tag;
00119 const string::size_type i1(label.find(token));
00120 if (i1==string::npos) {
00121 instance=empty;
00122 process=empty;
00123 } else {
00124 instance=label.substr(i1+1);
00125 label.resize(i1);
00126 const string::size_type i2(instance.find(token));
00127 if (i2==string::npos) {
00128 process=empty;
00129 } else {
00130 process=instance.substr(i2+1);
00131 instance.resize(i2);
00132 }
00133 }
00134 }
00135 }
00136
00137
00138 void
00139 TriggerSummaryProducerAOD::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00140 {
00141 using namespace std;
00142 using namespace edm;
00143 using namespace reco;
00144 using namespace l1extra;
00145 using namespace trigger;
00146
00149 fobs_.clear();
00150 iEvent.getMany(selector_,fobs_);
00151 const unsigned int nfob(fobs_.size());
00152 LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects found: " << nfob;
00153
00154 string tagLabel,tagInstance,tagProcess;
00155
00161 maskFilters_.clear();
00162 maskFilters_.resize(nfob);
00163 filterTagsEvent_.clear();
00164 collectionTagsEvent_.clear();
00165 unsigned int nf(0);
00166 for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
00167 maskFilters_[ifob]=false;
00168 const vector<string>& collectionTags_(fobs_[ifob]->getCollectionTagsAsStrings());
00169 const unsigned int ncol(collectionTags_.size());
00170 if (ncol>0) {
00171 nf++;
00172 maskFilters_[ifob]=true;
00173 const string& label (fobs_[ifob].provenance()->moduleLabel());
00174 const string& instance (fobs_[ifob].provenance()->productInstanceName());
00175 const string& process (fobs_[ifob].provenance()->processName());
00176 filterTagsEvent_.insert(InputTag(label,instance,process));
00177 for (unsigned int icol=0; icol!=ncol; ++icol) {
00178
00179 tokenizeTag(collectionTags_[icol],tagLabel,tagInstance,tagProcess);
00180 collectionTagsEvent_.insert(InputTag(tagLabel,tagInstance,pn_));
00181 }
00182 }
00183 }
00185 if (filterTagsEvent_.size()!=nf) {
00186 LogError("TriggerSummaryProducerAOD")
00187 << "Mismatch in number of filter tags: "
00188 << filterTagsEvent_.size() << "!=" << nf ;
00189 }
00190
00192 collectionTagsGlobal_.insert(collectionTagsEvent_.begin(),collectionTagsEvent_.end());
00193 filterTagsGlobal_.insert(filterTagsEvent_.begin(),filterTagsEvent_.end());
00194
00196 if (isDebugEnabled()) {
00197
00199 const unsigned int nc(collectionTagsEvent_.size());
00200 LogTrace("TriggerSummaryProducerAOD") << "Number of unique collections requested " << nc;
00201 const InputTagSet::const_iterator cb(collectionTagsEvent_.begin());
00202 const InputTagSet::const_iterator ce(collectionTagsEvent_.end());
00203 for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
00204 LogTrace("TriggerSummaryProducerAOD") << distance(cb,ci) << " " << ci->encode();
00205 }
00206 const unsigned int nf(filterTagsEvent_.size());
00207 LogTrace("TriggerSummaryProducerAOD") << "Number of unique filters requested " << nf;
00208 const InputTagSet::const_iterator fb(filterTagsEvent_.begin());
00209 const InputTagSet::const_iterator fe(filterTagsEvent_.end());
00210 for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
00211 LogTrace("TriggerSummaryProducerAOD") << distance(fb,fi) << " " << fi->encode();
00212 }
00213
00214 }
00215
00221 toc_.clear();
00222 tags_.clear();
00223 keys_.clear();
00224 offset_.clear();
00225 fillTriggerObjectCollections< RecoEcalCandidateCollection>(iEvent);
00226 fillTriggerObjectCollections< ElectronCollection>(iEvent);
00227 fillTriggerObjectCollections< RecoChargedCandidateCollection>(iEvent);
00228 fillTriggerObjectCollections< CaloJetCollection>(iEvent);
00229 fillTriggerObjectCollections< CompositeCandidateCollection>(iEvent);
00230 fillTriggerObjectCollections< METCollection>(iEvent);
00231 fillTriggerObjectCollections< CaloMETCollection>(iEvent);
00232 fillTriggerObjectCollections<IsolatedPixelTrackCandidateCollection>(iEvent);
00234 fillTriggerObjectCollections< L1EmParticleCollection>(iEvent);
00235 fillTriggerObjectCollections< L1MuonParticleCollection>(iEvent);
00236 fillTriggerObjectCollections< L1JetParticleCollection>(iEvent);
00237 fillTriggerObjectCollections< L1EtMissParticleCollection>(iEvent);
00238 fillTriggerObjectCollections< L1HFRingsCollection>(iEvent);
00240 const unsigned int nk(tags_.size());
00241 LogDebug("TriggerSummaryProducerAOD") << "Number of collections found: " << nk;
00242 const unsigned int no(toc_.size());
00243 LogDebug("TriggerSummaryProducerAOD") << "Number of physics objects found: " << no;
00244
00247 auto_ptr<TriggerEvent> product(new TriggerEvent(pn_,nk,no,nf));
00248
00250 product->addCollections(tags_,keys_);
00251 product->addObjects(toc_);
00252
00254 for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
00255 if (maskFilters_[ifob]) {
00256 const string& label (fobs_[ifob].provenance()->moduleLabel());
00257 const string& instance (fobs_[ifob].provenance()->productInstanceName());
00258 const string& process (fobs_[ifob].provenance()->processName());
00259 const edm::InputTag filterTag(label,instance,process);
00260 ids_.clear();
00261 keys_.clear();
00262 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->photonIds() ,fobs_[ifob]->photonRefs());
00263 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->electronIds() ,fobs_[ifob]->electronRefs());
00264 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->muonIds() ,fobs_[ifob]->muonRefs());
00265 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->jetIds() ,fobs_[ifob]->jetRefs());
00266 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->compositeIds(),fobs_[ifob]->compositeRefs());
00267 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->basemetIds() ,fobs_[ifob]->basemetRefs());
00268 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->calometIds() ,fobs_[ifob]->calometRefs());
00269 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->pixtrackIds() ,fobs_[ifob]->pixtrackRefs());
00270 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1emIds() ,fobs_[ifob]->l1emRefs());
00271 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1muonIds() ,fobs_[ifob]->l1muonRefs());
00272 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1jetIds() ,fobs_[ifob]->l1jetRefs());
00273 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1etmissIds() ,fobs_[ifob]->l1etmissRefs());
00274 fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1hfringsIds(),fobs_[ifob]->l1hfringsRefs());
00275 product->addFilter(filterTag,ids_,keys_);
00276 }
00277 }
00278
00279 OrphanHandle<TriggerEvent> ref = iEvent.put(product);
00280 LogTrace("TriggerSummaryProducerAOD") << "Number of physics objects packed: " << ref->sizeObjects();
00281 LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects packed: " << ref->sizeFilters();
00282
00283 }
00284
00285 template <typename C>
00286 void TriggerSummaryProducerAOD::fillTriggerObjectCollections(const edm::Event& iEvent) {
00287
00291
00292 using namespace std;
00293 using namespace edm;
00294 using namespace reco;
00295 using namespace l1extra;
00296 using namespace trigger;
00297
00298 vector<Handle<C> > collections;
00299 iEvent.getMany(selector_,collections);
00300 const unsigned int nc(collections.size());
00301
00302 for (unsigned int ic=0; ic!=nc; ++ic) {
00303 const Provenance& provenance(*(collections[ic].provenance()));
00304 const string& label (provenance.moduleLabel());
00305 const string& instance (provenance.productInstanceName());
00306 const string& process (provenance.processName());
00307 const InputTag collectionTag(label,instance,process);
00308
00309 if (collectionTagsEvent_.find(collectionTag)!=collectionTagsEvent_.end()) {
00310 const ProductID pid(collections[ic].provenance()->productID());
00311 if (offset_.find(pid)!=offset_.end()) {
00312 LogError("TriggerSummaryProducerAOD") << "Duplicate pid!";
00313 }
00314 offset_[pid]=toc_.size();
00315 const unsigned int n(collections[ic]->size());
00316 for (unsigned int i=0; i!=n; ++i) {
00317 fillTriggerObject( (*collections[ic])[i] );
00318 }
00319 tags_.push_back(collectionTag.encode());
00320 keys_.push_back(toc_.size());
00321 }
00322
00323 }
00324 }
00325
00326 template <typename T>
00327 void TriggerSummaryProducerAOD::fillTriggerObject(const T& object) {
00328
00329 using namespace trigger;
00330 toc_.push_back( TriggerObject(object) );
00331
00332 return;
00333 }
00334
00335 void TriggerSummaryProducerAOD::fillTriggerObject(const l1extra::L1HFRings& object) {
00336
00337 using namespace l1extra;
00338 using namespace trigger;
00339
00340 toc_.push_back(TriggerObject(TriggerL1HfRingEtSums,
00341 object.hfEtSum(L1HFRings::kRing1PosEta),
00342 object.hfEtSum(L1HFRings::kRing1NegEta),
00343 object.hfEtSum(L1HFRings::kRing2PosEta),
00344 object.hfEtSum(L1HFRings::kRing2NegEta) ) );
00345 toc_.push_back(TriggerObject(TriggerL1HfBitCounts,
00346 object.hfBitCount(L1HFRings::kRing1PosEta),
00347 object.hfBitCount(L1HFRings::kRing1NegEta),
00348 object.hfBitCount(L1HFRings::kRing2PosEta),
00349 object.hfBitCount(L1HFRings::kRing2NegEta) ) );
00350
00351 return;
00352 }
00353
00354 void TriggerSummaryProducerAOD::fillTriggerObject(const l1extra::L1EtMissParticle& object) {
00355
00356 using namespace l1extra;
00357 using namespace trigger;
00358
00359 toc_.push_back( TriggerObject(object) );
00360 if (object.type()==L1EtMissParticle::kMET) {
00361 toc_.push_back(TriggerObject(TriggerL1ETT,object.etTotal(),0.0,0.0,0.0));
00362 } else if (object.type()==L1EtMissParticle::kMHT) {
00363 toc_.push_back(TriggerObject(TriggerL1HTT,object.etTotal(),0.0,0.0,0.0));
00364 } else {
00365 toc_.push_back(TriggerObject(0, object.etTotal(),0.0,0.0,0.0));
00366 }
00367
00368 return;
00369 }
00370
00371 void TriggerSummaryProducerAOD::fillTriggerObject(const reco::CaloMET& object) {
00372
00373 using namespace reco;
00374 using namespace trigger;
00375
00376 toc_.push_back( TriggerObject(object) );
00377 toc_.push_back(TriggerObject(TriggerTET ,object.sumEt() ,0.0,0.0,0.0));
00378 toc_.push_back(TriggerObject(TriggerMETSig ,object.mEtSig() ,0.0,0.0,0.0));
00379 toc_.push_back(TriggerObject(TriggerELongit,object.e_longitudinal(),0.0,0.0,0.0));
00380
00381 return;
00382 }
00383
00384 void TriggerSummaryProducerAOD::fillTriggerObject(const reco::MET& object) {
00385
00386 using namespace reco;
00387 using namespace trigger;
00388
00389 toc_.push_back( TriggerObject(object) );
00390 toc_.push_back(TriggerObject(TriggerTHT ,object.sumEt() ,0.0,0.0,0.0));
00391 toc_.push_back(TriggerObject(TriggerMHTSig ,object.mEtSig() ,0.0,0.0,0.0));
00392 toc_.push_back(TriggerObject(TriggerHLongit,object.e_longitudinal(),0.0,0.0,0.0));
00393
00394 return;
00395 }
00396
00397 template <typename C>
00398 void TriggerSummaryProducerAOD::fillFilterObjectMembers(const edm::Event& iEvent, const edm::InputTag& tag, const trigger::Vids& ids, const std::vector<edm::Ref<C> >& refs) {
00399
00403
00404 using namespace std;
00405 using namespace edm;
00406 using namespace reco;
00407 using namespace l1extra;
00408 using namespace trigger;
00409
00410 if (ids.size()!=refs.size()) {
00411 LogError("TriggerSummaryProducerAOD") << "Vector length is different: "
00412 << ids.size() << " " << refs.size();
00413 }
00414
00415 const unsigned int n(min(ids.size(),refs.size()));
00416 for (unsigned int i=0; i!=n; ++i) {
00417 const ProductID pid(refs[i].id());
00418 if (offset_.find(pid)==offset_.end()) {
00419 const string& label(iEvent.getProvenance(pid).moduleLabel());
00420 const string& instance(iEvent.getProvenance(pid).productInstanceName());
00421 const string& process(iEvent.getProvenance(pid).processName());
00422 LogError("TriggerSummaryProducerAOD")
00423 << "Uunknown pid:"
00424 << " FilterTag/Key: " << tag.encode()
00425 << "/" << i
00426 << " CollectionTag/Key: "
00427 << InputTag(label,instance,process).encode()
00428 << "/" << refs[i].key()
00429 << " CollectionType: " << typeid(C).name();
00430 } else {
00431 fillFilterObjectMember(offset_[pid],ids[i],refs[i]);
00432 }
00433 }
00434 return;
00435
00436 }
00437
00438 template <typename C>
00439 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<C> & ref) {
00440
00441 keys_.push_back(offset+ref.key());
00442 ids_.push_back(id);
00443
00444 return;
00445 }
00446
00447 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<l1extra::L1HFRingsCollection> & ref) {
00448
00449 using namespace trigger;
00450
00451 if (id==TriggerL1HfBitCounts) {
00452 keys_.push_back(offset+2*ref.key()+1);
00453 } else {
00454 keys_.push_back(offset+2*ref.key()+0);
00455 }
00456 ids_.push_back(id);
00457
00458 return;
00459 }
00460
00461 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<l1extra::L1EtMissParticleCollection> & ref) {
00462
00463 using namespace trigger;
00464
00465 if ( (id==TriggerL1ETT) || (id==TriggerL1HTT) ) {
00466 keys_.push_back(offset+2*ref.key()+1);
00467 } else {
00468 keys_.push_back(offset+2*ref.key()+0);
00469 }
00470 ids_.push_back(id);
00471
00472 return;
00473 }
00474
00475 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<reco::CaloMETCollection> & ref) {
00476
00477 using namespace trigger;
00478
00479 if ( (id==TriggerTHT) || (id==TriggerTET) ) {
00480 keys_.push_back(offset+4*ref.key()+1);
00481 } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
00482 keys_.push_back(offset+4*ref.key()+2);
00483 } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
00484 keys_.push_back(offset+4*ref.key()+3);
00485 } else {
00486 keys_.push_back(offset+4*ref.key()+0);
00487 }
00488 ids_.push_back(id);
00489
00490 return;
00491 }
00492
00493 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<reco::METCollection> & ref) {
00494
00495 using namespace trigger;
00496
00497 if ( (id==TriggerTHT) || (id==TriggerTET) ) {
00498 keys_.push_back(offset+4*ref.key()+1);
00499 } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
00500 keys_.push_back(offset+4*ref.key()+2);
00501 } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
00502 keys_.push_back(offset+4*ref.key()+3);
00503 } else {
00504 keys_.push_back(offset+4*ref.key()+0);
00505 }
00506 ids_.push_back(id);
00507
00508 return;
00509 }
00510
00511 void TriggerSummaryProducerAOD::endJob() {
00512
00513 using namespace std;
00514 using namespace edm;
00515 using namespace trigger;
00516
00517 LogVerbatim("TriggerSummaryProducerAOD") << endl;
00518 LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::endJob - accumulated tags:" << endl;
00519
00520 const unsigned int nc(collectionTagsGlobal_.size());
00521 const unsigned int nf(filterTagsGlobal_.size());
00522 LogVerbatim("TriggerSummaryProducerAOD") << " Overall number of Collections/Filters: "
00523 << nc << "/" << nf << endl;
00524
00525 LogVerbatim("TriggerSummaryProducerAOD") << " The collections: " << nc << endl;
00526 const InputTagSet::const_iterator cb(collectionTagsGlobal_.begin());
00527 const InputTagSet::const_iterator ce(collectionTagsGlobal_.end());
00528 for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
00529 LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(cb,ci) << " " << ci->encode() << endl;
00530 }
00531
00532 LogVerbatim("TriggerSummaryProducerAOD") << " The filters:" << nf << endl;
00533 const InputTagSet::const_iterator fb(filterTagsGlobal_.begin());
00534 const InputTagSet::const_iterator fe(filterTagsGlobal_.end());
00535 for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
00536 LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(fb,fi) << " " << fi->encode() << endl;
00537 }
00538
00539 LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::endJob." << endl;
00540 LogVerbatim("TriggerSummaryProducerAOD") << endl;
00541
00542 return;
00543
00544 }