From bec9a31ff24b5a0c18afb17fec9c28c8f804d15a Mon Sep 17 00:00:00 2001 From: yuanchao Date: Tue, 14 Sep 2021 00:23:35 +0800 Subject: [PATCH] add back duplicated file removal in #35105 --- .../DTRawToDigi/interface/DTROS25Data.h | 61 +++++++ .../ESRawToDigi/interface/ESCrcKchipFast.h | 50 +++++ .../interface/ECALUnpackerException.h | 32 ++++ .../EcalRawToDigi/interface/MyWatcher.h | 43 +++++ .../RPCRawToDigi/interface/RPCRawSynchro.h | 1 + EventFilter/Utilities/interface/ModuleWeb.h | 51 ++++++ EventFilter/Utilities/interface/config_json.h | 43 +++++ .../interface/BPHMuonChargeSelect.h | 54 ++++++ .../interface/BPHParticleChargeSelect.h | 73 ++++++++ IOPool/Common/interface/CustomStreamer.h | 58 ++++++ .../interface/BoxNDScanner.h | 172 ++++++++++++++++++ .../interface/MultivariateFunctorScanner.h | 77 ++++++++ .../interface/rescanArray.h | 122 +++++++++++++ .../interface/CorrectedMETProducerT.h | 110 +++++++++++ 14 files changed, 947 insertions(+) create mode 100644 EventFilter/DTRawToDigi/interface/DTROS25Data.h create mode 100644 EventFilter/ESRawToDigi/interface/ESCrcKchipFast.h create mode 100644 EventFilter/EcalRawToDigi/interface/ECALUnpackerException.h create mode 100644 EventFilter/EcalRawToDigi/interface/MyWatcher.h create mode 100644 EventFilter/RPCRawToDigi/interface/RPCRawSynchro.h create mode 100644 EventFilter/Utilities/interface/ModuleWeb.h create mode 100644 EventFilter/Utilities/interface/config_json.h create mode 100644 HeavyFlavorAnalysis/SpecificDecay/interface/BPHMuonChargeSelect.h create mode 100644 HeavyFlavorAnalysis/SpecificDecay/interface/BPHParticleChargeSelect.h create mode 100644 IOPool/Common/interface/CustomStreamer.h create mode 100644 JetMETCorrections/InterpolationTables/interface/BoxNDScanner.h create mode 100644 JetMETCorrections/InterpolationTables/interface/MultivariateFunctorScanner.h create mode 100644 JetMETCorrections/InterpolationTables/interface/rescanArray.h create mode 100644 JetMETCorrections/Type1MET/interface/CorrectedMETProducerT.h diff --git a/EventFilter/DTRawToDigi/interface/DTROS25Data.h b/EventFilter/DTRawToDigi/interface/DTROS25Data.h new file mode 100644 index 0000000000000..57ea5ecaa1df0 --- /dev/null +++ b/EventFilter/DTRawToDigi/interface/DTROS25Data.h @@ -0,0 +1,61 @@ +#ifndef DTRawToDigi_DTROS25Data_h +#define DTRawToDigi_DTROS25Data_h + +/** \class DTROS25Data + * The collection containing DT ROS25 status data. + * + * \author M. Zanetti - INFN Padova + */ + +#include + +#include + + +typedef std::pair DTTDCData; + +class DTROS25Data { + +public: + + /// Constructors + DTROS25Data(int ROSId = 0): theROSId(ROSId) {} + + + /// Destructor + virtual ~DTROS25Data() {} + + /// Setters + inline void setROSId(const int & ID) { theROSId = ID; } + + inline void addROSTrailer( const DTROSTrailerWord & word) { theROSTrailers.push_back(word); } + inline void addROSError( const DTROSErrorWord & word) { theROSErrors.push_back(word); } + inline void addROSDebug( const DTROSDebugWord & word) { theROSDebugs.push_back(word); } + inline void addROBTrailer( const DTROBTrailerWord & word) { theROBTrailers.push_back(word); } + inline void addTDCMeasurement( const DTTDCMeasurementWord & word) { theTDCMeasurements.push_back(word); } + inline void addTDCData( const DTTDCData & tdcData) { theTDCData.push_back(tdcData); } + + /// Getters + inline int getROSID() const { return theROSId; } + + inline const std::vector& getROSTrailers() const {return theROSTrailers;} + inline const std::vector& getROSErrors() const {return theROSErrors;} + inline const std::vector& getROSDebugs() const {return theROSDebugs;} + inline const std::vector& getROBTrailers() const {return theROBTrailers;} + inline const std::vector& getTDCMeasurements() const {return theTDCMeasurements;} + inline const std::vector& getTDCData() const {return theTDCData;} + +private: + + int theROSId; + + std::vector theROSTrailers; + std::vector theROSErrors; + std::vector theROSDebugs; + std::vector theROBTrailers; + std::vector theTDCMeasurements; + std::vector theTDCData; + +}; + +#endif diff --git a/EventFilter/ESRawToDigi/interface/ESCrcKchipFast.h b/EventFilter/ESRawToDigi/interface/ESCrcKchipFast.h new file mode 100644 index 0000000000000..206cbc5c734dc --- /dev/null +++ b/EventFilter/ESRawToDigi/interface/ESCrcKchipFast.h @@ -0,0 +1,50 @@ +#ifndef ESCrcKchipFast_H +#define ESCrcKchipFast_H + +#include + +class ESCrcKchipFast { + + private : + + uint32_t crc; + + public: + + ESCrcKchipFast() { + init(); + reset() ; + }; + + void init() { + crc = 0x0ffff ; + } + + void reset() { + crc = 0x0ffff ; + } ; + + void add(unsigned int data) { + for (int i=0;i<16;i++) + { + if ((crc&0x0001) == (data&0x0001)) + crc=crc>>1; + else + crc=(crc>>1)^0x8408; // flipped 0x1021; + data=(data>>1); + } + }; + + uint32_t get_crc() { + return crc ; + }; + + bool isCrcOk(unsigned int crcin=0x0000) { + return ((get_crc()==crcin) ? true : false ); + }; + + ~ESCrcKchipFast() { } ; + +}; + +#endif diff --git a/EventFilter/EcalRawToDigi/interface/ECALUnpackerException.h b/EventFilter/EcalRawToDigi/interface/ECALUnpackerException.h new file mode 100644 index 0000000000000..a9f1e57d0cdb2 --- /dev/null +++ b/EventFilter/EcalRawToDigi/interface/ECALUnpackerException.h @@ -0,0 +1,32 @@ +// Date : 30/05/2005 +// Author : N.Almeida (LIP) + +#ifndef ECALUNPACKEREXCEPTION_H +#define ECALUNPACKEREXCEPTION_H + +#include +#include +#include + + +class ECALUnpackerException { + public : + + /** + * Constructor + */ + ECALUnpackerException(std::ostringstream a){ info_=a.str(); } + + ECALUnpackerException(std::string a){info_=a;} + /** + * Exception's discription + */ + std::string what() const throw() { return info_;} + + protected : + + std::string info_; + +}; + +#endif diff --git a/EventFilter/EcalRawToDigi/interface/MyWatcher.h b/EventFilter/EcalRawToDigi/interface/MyWatcher.h new file mode 100644 index 0000000000000..5d26a0df24808 --- /dev/null +++ b/EventFilter/EcalRawToDigi/interface/MyWatcher.h @@ -0,0 +1,43 @@ +#ifndef MyWATCHER_H +#define MyWATCHER_H + +#include "TStopwatch.h" +#include +#include + +#ifdef EDM_ML_DEBUG +class MyWatcher : public TStopwatch { + public: + MyWatcher(const std::string n=""):name(n),total(0) {} + ~MyWatcher(){} + + std::string start(bool r=true){Start(r); return " [Start]";} + std::string continu(){Continue(); return " [Continue]";} + std::string reset(){Reset(); return " [Reset]";} + std::string stop() {Stop(); return " [Stop]";} + std::string lap() { + std::stringstream o; + double r=RealTime(); + total+=r; + o<<"\n "< +#include +#include + + + + namespace evf + { + + + namespace moduleweb { + class ForkParams { + public: + ForkParams():slotId(-1),restart(0),isMaster(-1){} + int slotId; + bool restart; + int isMaster; + }; + class ForkInfoObj { + public: + ForkInfoObj() + { + control_sem_ = new sem_t; + sem_init(control_sem_,0,0); + stopCondition=0; + receivedStop_=false; + } + ~ForkInfoObj() + { + sem_destroy(control_sem_); + delete control_sem_; + } + void lock() {if (mst_lock_) pthread_mutex_lock(mst_lock_);} + void unlock() {if (mst_lock_) pthread_mutex_unlock(mst_lock_);} + void (*forkHandler) (void *); + ForkParams forkParams; + unsigned int stopCondition; + bool receivedStop_; + sem_t *control_sem_; + pthread_mutex_t * mst_lock_; + void * fuAddr; + }; + } + +} +#endif diff --git a/EventFilter/Utilities/interface/config_json.h b/EventFilter/Utilities/interface/config_json.h new file mode 100644 index 0000000000000..5d334cbc5e6b9 --- /dev/null +++ b/EventFilter/Utilities/interface/config_json.h @@ -0,0 +1,43 @@ +#ifndef JSON_CONFIG_H_INCLUDED +# define JSON_CONFIG_H_INCLUDED + +/// If defined, indicates that json library is embedded in CppTL library. +//# define JSON_IN_CPPTL 1 + +/// If defined, indicates that json may leverage CppTL library +//# define JSON_USE_CPPTL 1 +/// If defined, indicates that cpptl vector based map should be used instead of std::map +/// as Value container. +//# define JSON_USE_CPPTL_SMALLMAP 1 +/// If defined, indicates that Json specific container should be used +/// (hash table & simple deque container with customizable allocator). +/// THIS FEATURE IS STILL EXPERIMENTAL! +//# define JSON_VALUE_USE_INTERNAL_MAP 1 +/// Force usage of standard new/malloc based allocator instead of memory pool based allocator. +/// The memory pools allocator used optimization (initializing Value and ValueInternalLink +/// as if it was a POD) that may cause some validation tool to report errors. +/// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined. +//# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1 + +/// If defined, indicates that Json use exception to report invalid type manipulation +/// instead of C assert macro. +# define JSON_USE_EXCEPTION 1 + +# ifdef JSON_IN_CPPTL +# include +# ifndef JSON_USE_CPPTL +# define JSON_USE_CPPTL 1 +# endif +# endif + +# ifdef JSON_IN_CPPTL +# define JSON_API CPPTL_API +# elif defined(JSON_DLL_BUILD) +# define JSON_API __declspec(dllexport) +# elif defined(JSON_DLL) +# define JSON_API __declspec(dllimport) +# else +# define JSON_API +# endif + +#endif // JSON_CONFIG_H_INCLUDED diff --git a/HeavyFlavorAnalysis/SpecificDecay/interface/BPHMuonChargeSelect.h b/HeavyFlavorAnalysis/SpecificDecay/interface/BPHMuonChargeSelect.h new file mode 100644 index 0000000000000..3f7d574ed79fc --- /dev/null +++ b/HeavyFlavorAnalysis/SpecificDecay/interface/BPHMuonChargeSelect.h @@ -0,0 +1,54 @@ +#ifndef HeavyFlavorAnalysis_SpecificDecay_BPHMuonChargeSelect_h +#define HeavyFlavorAnalysis_SpecificDecay_BPHMuonChargeSelect_h +/** \class BPHMuonChargeSelect + * + * Description: + * Class for muon selection by charge + * + * \author Paolo Ronchese INFN Padova + * + */ + +//---------------------- +// Base Class Headers -- +//---------------------- +#include "HeavyFlavorAnalysis/SpecificDecay/interface/BPHParticleChargeSelect.h" + +//------------------------------------ +// Collaborating Class Declarations -- +//------------------------------------ +#include "DataFormats/PatCandidates/interface/Muon.h" + +//--------------- +// C++ Headers -- +//--------------- + +// --------------------- +// -- Class Interface -- +// --------------------- + +class BPHMuonChargeSelect : public BPHParticleChargeSelect { +public: + /** Constructor + */ + BPHMuonChargeSelect(int c) : BPHParticleChargeSelect(c) {} + + // deleted copy constructor and assignment operator + BPHMuonChargeSelect(const BPHMuonChargeSelect& x) = delete; + BPHMuonChargeSelect& operator=(const BPHMuonChargeSelect& x) = delete; + + /** Destructor + */ + ~BPHMuonChargeSelect() override {} + + /** Operations + */ + /// select muon + bool accept(const reco::Candidate& cand) const override { + if (dynamic_cast(&cand) == nullptr) + return false; + return BPHParticleChargeSelect::accept(cand); + }; +}; + +#endif diff --git a/HeavyFlavorAnalysis/SpecificDecay/interface/BPHParticleChargeSelect.h b/HeavyFlavorAnalysis/SpecificDecay/interface/BPHParticleChargeSelect.h new file mode 100644 index 0000000000000..e85f05677bad2 --- /dev/null +++ b/HeavyFlavorAnalysis/SpecificDecay/interface/BPHParticleChargeSelect.h @@ -0,0 +1,73 @@ +#ifndef HeavyFlavorAnalysis_SpecificDecay_BPHParticleChargeSelect_h +#define HeavyFlavorAnalysis_SpecificDecay_BPHParticleChargeSelect_h +/** \class BPHParticleChargeSelect + * + * Description: + * Class for particle selection by charge + * + * \author Paolo Ronchese INFN Padova + * + */ + +//---------------------- +// Base Class Headers -- +//---------------------- +#include "HeavyFlavorAnalysis/RecoDecay/interface/BPHRecoSelect.h" + +//------------------------------------ +// Collaborating Class Declarations -- +//------------------------------------ +#include "DataFormats/RecoCandidate/interface/RecoCandidate.h" + +//--------------- +// C++ Headers -- +//--------------- + +// --------------------- +// -- Class Interface -- +// --------------------- + +class BPHParticleChargeSelect : public BPHRecoSelect { +public: + /** Constructor + */ + BPHParticleChargeSelect(int c) : charge(c ? (c > 0 ? 1 : -1) : 0) {} + + // deleted copy constructor and assignment operator + BPHParticleChargeSelect(const BPHParticleChargeSelect& x) = delete; + BPHParticleChargeSelect& operator=(const BPHParticleChargeSelect& x) = delete; + + /** Destructor + */ + ~BPHParticleChargeSelect() override {} + + /** Operations + */ + /// select particle + bool accept(const reco::Candidate& cand) const override { + switch (charge) { + default: + case 0: + return (cand.charge() != 0); + case 1: + return (cand.charge() > 0); + case -1: + return (cand.charge() < 0); + } + return true; + }; + + /// set selection charge + void setCharge(int c) { + charge = (c ? (c > 0 ? 1 : -1) : 0); + return; + } + + /// get selection charge + double getCharge() const { return charge; } + +private: + int charge; +}; + +#endif diff --git a/IOPool/Common/interface/CustomStreamer.h b/IOPool/Common/interface/CustomStreamer.h new file mode 100644 index 0000000000000..5f07f3e7fd904 --- /dev/null +++ b/IOPool/Common/interface/CustomStreamer.h @@ -0,0 +1,58 @@ +#ifndef IOPool_Common_CustomStreamer_h +#define IOPool_Common_CustomStreamer_h + +#include +#include "TClass.h" +#include "TClassStreamer.h" +#include "TClassRef.h" +#include "FWCore/Utilities/interface/TypeID.h" +#include "TBuffer.h" + +namespace edm { + template + class CustomStreamer : public TClassStreamer { + public: + typedef T element_type; + CustomStreamer(); + void operator() (TBuffer &R__b, void *objp); + private: + std::string className_; + TClassRef cl_; + }; + + template + CustomStreamer::CustomStreamer() : + className_(TypeID(typeid(T)).className()), + cl_(className_.c_str()) + {} + + template + void + CustomStreamer::operator()(TBuffer &R__b, void *objp) { + if (R__b.IsReading()) { + cl_->ReadBuffer(R__b, objp); + } else { + cl_->WriteBuffer(R__b, objp); + } + } + + template + void + SetCustomStreamer() { + TClass *cl = TClass::GetClass(typeid(T)); + if (cl->GetStreamer() == 0) { + cl->AdoptStreamer(new CustomStreamer()); + } + } + + template + void + SetCustomStreamer(T const&) { + TClass *cl = TClass::GetClass(typeid(T)); + if (cl->GetStreamer() == 0) { + cl->AdoptStreamer(new CustomStreamer()); + } + } +} + +#endif diff --git a/JetMETCorrections/InterpolationTables/interface/BoxNDScanner.h b/JetMETCorrections/InterpolationTables/interface/BoxNDScanner.h new file mode 100644 index 0000000000000..44d32c6b037da --- /dev/null +++ b/JetMETCorrections/InterpolationTables/interface/BoxNDScanner.h @@ -0,0 +1,172 @@ +#ifndef NPSTAT_BOXNDSCANNER_HH_ +#define NPSTAT_BOXNDSCANNER_HH_ + +/*! +// \file BoxNDScanner.h +// +// \brief Iteration over uniformly spaced coordinates inside +// a multidimensional box +// +// Author: I. Volobouev +// +// March 2010 +*/ + +#include "JetMETCorrections/InterpolationTables/interface/BoxND.h" + +namespace npstat { + /** + * A class for iterating over all coordinates in a multidimensional box + * (but not a full-fledeged iterator). The expected usage pattern is as + * follows: + * + * @code + * double* coords = ... (the buffer size should be at least box.dim()) + * for (BoxNDScanner scan(box,shape); scan.isValid(); ++scan) + * { + * scan.getCoords(coords, coordsBufferSize); + * .... Do what is necessary with coordinates .... + * .... Extract linear bin number: .............. + * scan.state(); + * } + * @endcode + * + * The coordinates will be in the middle of the bins (imagine + * a multivariate histogram with boundaries defined by the given box). + */ + template + class BoxNDScanner + { + public: + //@{ + /** + // Constructor from a bounding box and a multidimensional + // array shape + */ + inline BoxNDScanner(const BoxND& box, + const std::vector& shape) + : box_(box), state_(0UL) + {initialize(shape.empty() ? static_cast(0) : + &shape[0], shape.size());} + + inline BoxNDScanner(const BoxND& box, + const unsigned* shape, const unsigned lenShape) + : box_(box), state_(0UL) {initialize(shape, lenShape);} + //@} + + /** Dimensionality of the scan */ + inline unsigned dim() const {return box_.dim();} + + /** Retrieve current state (i.e., linear index of the scan) */ + inline unsigned long state() const {return state_;} + + /** Maximum possible state (i.e., linear index of the scan) */ + inline unsigned long maxState() const {return maxState_;} + + /** Returns false when iteration is complete */ + inline bool isValid() const {return state_ < maxState_;} + + /** Retrieve current coordinates inside the box */ + void getCoords(Numeric* x, unsigned nx) const; + + /** Retrieve current multidimensional index */ + void getIndex(unsigned* index, unsigned indexBufferLen) const; + + /** Reset the state (as if the object has just been constructed) */ + inline void reset() {state_ = 0UL;} + + /** Prefix increment */ + inline BoxNDScanner& operator++() + {if (state_ < maxState_) ++state_; return *this;} + + /** Postfix increment (distinguished by the dummy "int" parameter) */ + inline void operator++(int) {if (state_ < maxState_) ++state_;} + + /** Set the state directly */ + inline void setState(const unsigned long state) + {state_ = state <= maxState_ ? state : maxState_;} + + private: + BoxNDScanner(); + + void initialize(const unsigned* shape, unsigned lenShape); + + BoxND box_; + std::vector strides_; + std::vector bw_; + unsigned long state_; + unsigned long maxState_; + }; +} + +#include +#include "JetMETCorrections/InterpolationTables/interface/NpstatException.h" + +namespace npstat { + template + void BoxNDScanner::initialize(const unsigned* shape, + const unsigned dim) + { + if (!(dim && box_.dim() == dim)) throw npstat::NpstatInvalidArgument( + "In npstat::BoxNDScanner::initialize: incompatible scan shape"); + assert(shape); + for (unsigned j=0; j0; --j) + strides_[j - 1] = strides_[j]*shape[j]; + maxState_ = strides_[0]*shape[0]; + + bw_.reserve(dim); + for (unsigned j=0; j + void BoxNDScanner::getCoords(Numeric* x, const unsigned nx) const + { + const unsigned dim = strides_.size(); + if (nx < dim) throw npstat::NpstatInvalidArgument( + "In npstat::BoxNDScanner::getCoords: " + "insufficient length of the output buffer"); + if (state_ >= maxState_) throw npstat::NpstatRuntimeError( + "In npstat::BoxNDScanner::getCoords: invalid scanner state"); + assert(x); + + unsigned long l = state_; + for (unsigned i=0; i + void BoxNDScanner::getIndex(unsigned* ix, const unsigned nx) const + { + const unsigned dim = strides_.size(); + if (nx < dim) throw npstat::NpstatInvalidArgument( + "In npstat::BoxNDScanner::getIndex: " + "insufficient length of the output buffer"); + if (state_ >= maxState_) throw npstat::NpstatRuntimeError( + "In npstat::BoxNDScanner::getIndex: invalid scanner state"); + assert(ix); + + unsigned long l = state_; + for (unsigned i=0; i(idx); + l -= (idx * strides_[i]); + } + } +} + + +#endif // NPSTAT_BOXNDSCANNER_HH_ + diff --git a/JetMETCorrections/InterpolationTables/interface/MultivariateFunctorScanner.h b/JetMETCorrections/InterpolationTables/interface/MultivariateFunctorScanner.h new file mode 100644 index 0000000000000..c34494d45b63e --- /dev/null +++ b/JetMETCorrections/InterpolationTables/interface/MultivariateFunctorScanner.h @@ -0,0 +1,77 @@ +#ifndef NPSTAT_MULTIVARIATEFUNCTORSCANNER_HH_ +#define NPSTAT_MULTIVARIATEFUNCTORSCANNER_HH_ + +/*! +// \file MultivariateFunctorScanner.h +// +// \brief Adapts any AbsMultivariateFunctor for use with ArrayND method +// "functorFill" +// +// Author: I. Volobouev +// +// July 2012 +*/ + +#include +#include +#include "JetMETCorrections/InterpolationTables/interface/NpstatException.h" + +#include "JetMETCorrections/InterpolationTables/interface/AbsMultivariateFunctor.h" + +namespace npstat { + /** + // This class adapts an object derived from AbsMultivariateFunctor + // so that it can be used with ArrayND method "functorFill" and such + */ + template + class MultivariateFunctorScanner + { + public: + /** + // A mapper for each coordinate in the "maps" argument will + // convert the array index into a proper argument for the scanned + // density. + // + // This functor will NOT make copies of either "fcn" or "maps" + // parameters. These parameters will be used by reference only + // (aliased). It is up to the user of this class to ensure proper + // lifetime of these objects. + */ + inline MultivariateFunctorScanner(const AbsMultivariateFunctor& fcn, + const std::vector& maps) + : fcn_(fcn), mapping_(maps), buf_(fcn.minDim()), dim_(fcn.minDim()) + { + if (!(dim_ && dim_ == maps.size())) throw npstat::NpstatInvalidArgument( + "In npstat::MultivariateFunctorScanner constructor: " + "incompatible arguments"); + if (dim_ != fcn.maxDim()) throw npstat::NpstatInvalidArgument( + "In npstat::MultivariateFunctorScanner constructor: " + "functors of variable dimensionality are not supported"); + } + + /** Calculate the functor value for the given array indices */ + inline double operator()(const unsigned* index, + const unsigned indexLen) const + { + if (dim_ != indexLen) throw npstat::NpstatInvalidArgument( + "In npstat::MultivariateFunctorScanner::operator(): " + "incompatible input point dimensionality"); + assert(index); + double* x = &buf_[0]; + for (unsigned i=0; i& mapping_; + mutable std::vector buf_; + unsigned dim_; + }; +} + +#endif // NPSTAT_MULTIVARIATEFUNCTORSCANNER_HH_ + diff --git a/JetMETCorrections/InterpolationTables/interface/rescanArray.h b/JetMETCorrections/InterpolationTables/interface/rescanArray.h new file mode 100644 index 0000000000000..08742b7113908 --- /dev/null +++ b/JetMETCorrections/InterpolationTables/interface/rescanArray.h @@ -0,0 +1,122 @@ +#ifndef NPSTAT_RESCANARRAY_HH_ +#define NPSTAT_RESCANARRAY_HH_ + +/*! +// \file rescanArray.h +// +// \brief Fill a multidimensional array using values from another array +// with a different shape +// +// Author: I. Volobouev +// +// October 2010 +*/ + +#include "JetMETCorrections/InterpolationTables/interface/ArrayND.h" + +namespace npstat { + /** + // A utility for filling one array using values of another. The + // array shapes do not have to be the same but the ranks have to be. + // Roughly, the arrays are treated as values of histogram bins inside + // the unit box. The array "to" is filled either with the closest bin + // value of the array "from" or with an interpolated value (if + // "interpolationDegree" parameter is not 0). + // + // interpolationDegree parameter must be one of 0, 1, or 3. + */ + template + void rescanArray(const ArrayND& from, + ArrayND* to, + unsigned interpolationDegree=0); +} + +#include +#include "JetMETCorrections/InterpolationTables/interface/NpstatException.h" + +#include "JetMETCorrections/InterpolationTables/interface/LinearMapper1d.h" + +namespace npstat { + namespace Private { + template + class ArrayMapper + { + public: + ArrayMapper(const ArrayND& from, + const ArrayND& to, + const unsigned interpolationDegree) + : mapped_(from.rank()), + from_(from), + dim_(from.rank()), + ideg_(interpolationDegree) + { + assert(dim_ == to.rank()); + if (dim_) + { + mappers_.reserve(dim_); + for (unsigned i=0; i mappers_; + mutable std::vector mapped_; + const ArrayND& from_; + unsigned dim_; + unsigned ideg_; + }; + } + + template + void rescanArray(const ArrayND& from, + ArrayND* to, + const unsigned interpolationDegree) + { + assert(to); + if (from.rank() != to->rank()) throw npstat::NpstatInvalidArgument( + "In npstat::rescanArray: incompatible dimensionalities " + "of input and output arrays"); + if (!(interpolationDegree == 0U || + interpolationDegree == 1U || + interpolationDegree == 3U)) throw npstat::NpstatInvalidArgument( + "In npstat::rescanArray: unsupported interpolation degree"); + to->functorFill(Private::ArrayMapper( + from, *to, interpolationDegree)); + } +} + + +#endif // NPSTAT_RESCANARRAY_HH_ + diff --git a/JetMETCorrections/Type1MET/interface/CorrectedMETProducerT.h b/JetMETCorrections/Type1MET/interface/CorrectedMETProducerT.h new file mode 100644 index 0000000000000..298d28b228224 --- /dev/null +++ b/JetMETCorrections/Type1MET/interface/CorrectedMETProducerT.h @@ -0,0 +1,110 @@ +#ifndef JetMETCorrections_Type1MET_CorrectedMETProducer_h +#define JetMETCorrections_Type1MET_CorrectedMETProducer_h + +/** \class CorrectedMETProducerT + * + * Produce MET collections with Type 1 / Type 1 + 2 corrections applied + * + * NOTE: This file defines the generic template. + * Concrete instances for CaloMET and PFMET are defined in + * JetMETCorrections/Type1MET/plugins/CorrectedCaloMETProducer.cc + * JetMETCorrections/Type1MET/plugins/CorrectedPFMETProducer.cc + * + * \authors Michael Schmitt, Richard Cavanaugh, The University of Florida + * Florent Lacroix, University of Illinois at Chicago + * Christian Veelken, LLR + * + * + * + */ + +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" + +#include "JetMETCorrections/Type1MET/interface/METCorrectionAlgorithm.h" +#include "DataFormats/METReco/interface/CorrMETData.h" +#include "DataFormats/Candidate/interface/Candidate.h" + +#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" + +#include + +namespace CorrectedMETProducer_namespace { + template + reco::Candidate::LorentzVector correctedP4(const T& rawMEt, const CorrMETData& correction) { + double correctedMEtPx = rawMEt.px() + correction.mex; + double correctedMEtPy = rawMEt.py() + correction.mey; + double correctedMEtPt = sqrt(correctedMEtPx * correctedMEtPx + correctedMEtPy * correctedMEtPy); + return reco::Candidate::LorentzVector(correctedMEtPx, correctedMEtPy, 0., correctedMEtPt); + } + + template + double correctedSumEt(const T& rawMEt, const CorrMETData& correction) { + return rawMEt.sumEt() + correction.sumet; + } + + template + class CorrectedMETFactoryT { + public: + T operator()(const T&, const CorrMETData&) const { + assert(0); // "place-holder" for template instantiations for concrete T types only, **not** to be called + } + }; +} // namespace CorrectedMETProducer_namespace + +template +class CorrectedMETProducerT : public edm::stream::EDProducer<> { + typedef std::vector METCollection; + +public: + explicit CorrectedMETProducerT(const edm::ParameterSet& cfg) + : moduleLabel_(cfg.getParameter("@module_label")), algorithm_(0) { + token_ = consumes(cfg.getParameter("src")); + + algorithm_ = new METCorrectionAlgorithm(cfg, consumesCollector()); + + produces(""); + } + ~CorrectedMETProducerT() { delete algorithm_; } + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("src", edm::InputTag("corrPfMetType1", "type1")); + descriptions.add(defaultModuleLabel >(), desc); + } + +private: + void produce(edm::Event& evt, const edm::EventSetup& es) { + std::unique_ptr correctedMEtCollection(new METCollection); + + edm::Handle rawMEtCollection; + evt.getByToken(token_, rawMEtCollection); + + for (typename METCollection::const_iterator rawMEt = rawMEtCollection->begin(); rawMEt != rawMEtCollection->end(); + ++rawMEt) { + CorrMETData correction = algorithm_->compMETCorrection(evt); + + static const CorrectedMETProducer_namespace::CorrectedMETFactoryT correctedMET_factory{}; + T correctedMEt = correctedMET_factory(*rawMEt, correction); + + correctedMEtCollection->push_back(correctedMEt); + } + + //--- add collection of MET objects with Type 1 / Type 1 + 2 corrections applied to the event + evt.put(std::move(correctedMEtCollection)); + } + + std::string moduleLabel_; + + edm::EDGetTokenT token_; + + METCorrectionAlgorithm* algorithm_; // algorithm for computing Type 1 / Type 1 + 2 MET corrections +}; + +#endif