Skip to content

Commit

Permalink
Migrate SiStripGainsPCLWorker to concurrent and global DQM
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Mar 7, 2018
1 parent a6f7e8e commit ec655a6
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 315 deletions.
143 changes: 96 additions & 47 deletions CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h
Original file line number Diff line number Diff line change
@@ -1,67 +1,116 @@
#ifndef CALIBTRACKER_SISTRIPCHANNELGAIN_APVGAINHELPERS_H
#define CALIBTRACKER_SISTRIPCHANNELGAIN_APVGAINHELPERS_H

#include "CalibTracker/SiStripChannelGain/interface/APVGainStruct.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DQMServices/Core/interface/ConcurrentMonitorElement.h"
#include "DQMServices/Core/interface/MonitorElement.h"

#include <string>
#include <vector>
#include <utility>
#include <cstdint>

#include <unordered_map>

namespace APVGain {
int subdetectorId(uint32_t);
int subdetectorId(const std::string&);
int subdetectorSide(uint32_t,const TrackerTopology*);
int subdetectorSide(const std::string&);
int subdetectorPlane(uint32_t,const TrackerTopology*);
int subdetectorPlane(const std::string&);

std::vector<std::pair<std::string,std::string>> monHnames(std::vector<std::string>,bool,const char* tag);

struct APVmon{

public:

APVmon(int v1, int v2, int v3, MonitorElement* v4) :
m_subdetectorId(v1),m_subdetectorSide(v2),m_subdetectorPlane(v3),m_monitor(v4){}

int getSubdetectorId(){
return m_subdetectorId;
}

int getSubdetectorSide(){
return m_subdetectorSide;
}
int subdetectorId(uint32_t);
int subdetectorId(const std::string&);
int subdetectorSide(uint32_t,const TrackerTopology*);
int subdetectorSide(const std::string&);
int subdetectorPlane(uint32_t,const TrackerTopology*);
int subdetectorPlane(const std::string&);

int getSubdetectorPlane(){
return m_subdetectorPlane;
}
std::vector<std::pair<std::string,std::string>> monHnames(std::vector<std::string>,bool,const char* tag);

MonitorElement* getMonitor(){
return m_monitor;
}

void printAll(){
LogDebug("APVGainHelpers")<< "subDetectorID:" << m_subdetectorId << std::endl;
LogDebug("APVGainHelpers")<< "subDetectorSide:" << m_subdetectorSide << std::endl;
LogDebug("APVGainHelpers")<< "subDetectorPlane:" << m_subdetectorPlane << std::endl;
LogDebug("APVGainHelpers")<< "histoName:" << m_monitor->getName() << std::endl;
return;
}

private:

int m_subdetectorId;
int m_subdetectorSide;
int m_subdetectorPlane;
MonitorElement* m_monitor;
struct APVmon{

public:

};
APVmon(int v1, int v2, int v3,MonitorElement* v4) :
m_subdetectorId(v1),m_subdetectorSide(v2),m_subdetectorPlane(v3),m_monitor(v4){}

int getSubdetectorId(){
return m_subdetectorId;
}

int getSubdetectorSide(){
return m_subdetectorSide;
}

int getSubdetectorPlane(){
return m_subdetectorPlane;
}

MonitorElement* getMonitor(){
return m_monitor;
}

void printAll(){
LogDebug("APVGainHelpers")<< "subDetectorID:" << m_subdetectorId << std::endl;
LogDebug("APVGainHelpers")<< "subDetectorSide:" << m_subdetectorSide << std::endl;
LogDebug("APVGainHelpers")<< "subDetectorPlane:" << m_subdetectorPlane << std::endl;
LogDebug("APVGainHelpers")<< "histoName:" << m_monitor->getName() << std::endl;
return;
}

private:

int m_subdetectorId;
int m_subdetectorSide;
int m_subdetectorPlane;
MonitorElement* m_monitor;

};

struct APVGainHistograms {
public:
APVGainHistograms():
Charge_Vs_Index(7),
Charge_1(),
Charge_2(),
Charge_3(),
Charge_4(),
Charge_Vs_PathlengthTIB(7),
Charge_Vs_PathlengthTOB(7),
Charge_Vs_PathlengthTIDP(7),
Charge_Vs_PathlengthTIDM(7),
Charge_Vs_PathlengthTECP1(7),
Charge_Vs_PathlengthTECP2(7),
Charge_Vs_PathlengthTECM1(7),
Charge_Vs_PathlengthTECM2(7),
NStripAPVs(0),
NPixelDets(0),
APVsCollOrdered(),
APVsColl()
{
}

std::vector<ConcurrentMonitorElement> Charge_Vs_Index; /*!< Charge per cm for each detector id */
std::array< std::vector<ConcurrentMonitorElement>,7 > Charge_1; /*!< Charge per cm per layer / wheel */
std::array< std::vector<ConcurrentMonitorElement>,7 > Charge_2; /*!< Charge per cm per layer / wheel without G2 */
std::array< std::vector<ConcurrentMonitorElement>,7 > Charge_3; /*!< Charge per cm per layer / wheel without G1 */
std::array< std::vector<ConcurrentMonitorElement>,7 > Charge_4; /*!< Charge per cm per layer / wheel without G1 and G1*/

std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTIB; /*!< Charge vs pathlength in TIB */
std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTOB; /*!< Charge vs pathlength in TOB */
std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTIDP; /*!< Charge vs pathlength in TIDP */
std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTIDM; /*!< Charge vs pathlength in TIDM */
std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTECP1; /*!< Charge vs pathlength in TECP thin */
std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTECP2; /*!< Charge vs pathlength in TECP thick */
std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTECM1; /*!< Charge vs pathlength in TECP thin */
std::vector<ConcurrentMonitorElement> Charge_Vs_PathlengthTECM2; /*!< Charge vs pathlength in TECP thick */
mutable std::atomic<unsigned int> NStripAPVs;
mutable std::atomic<unsigned int> NPixelDets;
std::vector<std::shared_ptr<stAPVGain> > APVsCollOrdered;
std::unordered_map<unsigned int, std::shared_ptr<stAPVGain> > APVsColl;

};

std::vector<MonitorElement*> FetchMonitor(std::vector<APVmon>, uint32_t, const TrackerTopology* topo=nullptr);
std::vector<unsigned int> FetchIndices(std::map<unsigned int,APVloc>, uint32_t, const TrackerTopology* topo=nullptr);

std::vector<MonitorElement*> FetchMonitor(std::vector<APVmon>, uint32_t, const TrackerTopology* topo=nullptr);
};

#endif
22 changes: 22 additions & 0 deletions CalibTracker/SiStripChannelGain/interface/APVGainStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CALIBTRACKER_SISTRIPCHANNELGAIN_STAPVGAIN_H

class TH1F;
#include <string>

struct stAPVGain{
unsigned int Index;
Expand Down Expand Up @@ -32,6 +33,27 @@ struct stAPVGain{
bool isMasked;
};

struct APVloc{

public:

APVloc(int v1, int v2, int v3,const std::string& s) :
m_subdetectorId(v1),m_subdetectorSide(v2),m_subdetectorPlane(v3),m_string(s){}

int m_subdetectorId;
int m_subdetectorSide;
int m_subdetectorPlane;
std::string m_string;

bool operator==(const APVloc& a) const
{
return (m_subdetectorId == a.m_subdetectorId &&
m_subdetectorSide == a.m_subdetectorSide &&
m_subdetectorPlane == a.m_subdetectorPlane);
}

};

enum statistic_type {None=-1, StdBunch, StdBunch0T, FaABunch, FaABunch0T, IsoBunch, IsoBunch0T, Harvest};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class SiStripGainsPCLHarvester : public DQMEDHarvester {

void gainQualityMonitor(DQMStore::IBooker& ibooker_, const MonitorElement* Charge_Vs_Index) const;


int statCollectionFromMode(const char* tag) const;

void algoComputeMPVandGain(const MonitorElement* Charge_Vs_Index);
Expand Down Expand Up @@ -88,8 +87,6 @@ class SiStripGainsPCLHarvester : public DQMEDHarvester {

std::vector<std::string> dqm_tag_;



int CalibrationLevel;

edm::ESHandle<TrackerGeometry> tkGeom_;
Expand Down
120 changes: 40 additions & 80 deletions CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "CalibTracker/Records/interface/SiStripGainRcd.h"
#include "CalibTracker/Records/interface/SiStripQualityRcd.h"
#include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
Expand All @@ -48,6 +48,7 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "Geometry/CommonDetUnit/interface/GeomDetType.h"
#include "Geometry/CommonDetUnit/interface/GeomDet.h"
#include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
Expand All @@ -71,49 +72,25 @@
// class declaration
//

class SiStripGainsPCLWorker : public DQMEDAnalyzer {
class SiStripGainsPCLWorker : public DQMGlobalEDAnalyzer<APVGain::APVGainHistograms> {
public:
explicit SiStripGainsPCLWorker(const edm::ParameterSet&);

void bookHistograms(DQMStore::ConcurrentBooker &, edm::Run const&, edm::EventSetup const&, APVGain::APVGainHistograms &) const override;
void dqmAnalyze(edm::Event const&, edm::EventSetup const&, APVGain::APVGainHistograms const&) const override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void beginJob() override;
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
void dqmBeginRun(edm::Run const&, edm::EventSetup const&) override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;

void processEvent(const TrackerTopology* topo); //what really does the job
virtual void checkBookAPVColls(const edm::EventSetup& setup);
void beginJob() override ;
void dqmBeginRun(edm::Run const&, edm::EventSetup const&, APVGain::APVGainHistograms &) const override;
void endJob() override ;
void checkBookAPVColls(const TrackerGeometry *bareTkGeomPtr,APVGain::APVGainHistograms & histograms) const;


std::vector<std::string> dqm_tag_;

int statCollectionFromMode(const char* tag) const;

std::vector<MonitorElement*> Charge_Vs_Index; /*!< Charge per cm for each detector id */
std::array< std::vector<APVGain::APVmon>,7 > Charge_1; /*!< Charge per cm per layer / wheel */
std::array< std::vector<APVGain::APVmon>,7 > Charge_2; /*!< Charge per cm per layer / wheel without G2 */
std::array< std::vector<APVGain::APVmon>,7 > Charge_3; /*!< Charge per cm per layer / wheel without G1 */
std::array< std::vector<APVGain::APVmon>,7 > Charge_4; /*!< Charge per cm per layer / wheel without G1 and G1*/

std::vector<MonitorElement*> Charge_Vs_PathlengthTIB; /*!< Charge vs pathlength in TIB */
std::vector<MonitorElement*> Charge_Vs_PathlengthTOB; /*!< Charge vs pathlength in TOB */
std::vector<MonitorElement*> Charge_Vs_PathlengthTIDP; /*!< Charge vs pathlength in TIDP */
std::vector<MonitorElement*> Charge_Vs_PathlengthTIDM; /*!< Charge vs pathlength in TIDM */
std::vector<MonitorElement*> Charge_Vs_PathlengthTECP1; /*!< Charge vs pathlength in TECP thin */
std::vector<MonitorElement*> Charge_Vs_PathlengthTECP2; /*!< Charge vs pathlength in TECP thick */
std::vector<MonitorElement*> Charge_Vs_PathlengthTECM1; /*!< Charge vs pathlength in TECP thin */
std::vector<MonitorElement*> Charge_Vs_PathlengthTECM2; /*!< Charge vs pathlength in TECP thick */

unsigned int NEvent;
unsigned int NTrack;
unsigned int NClusterStrip;
unsigned int NClusterPixel;
int NStripAPVs;
int NPixelDets;
unsigned int SRun;
unsigned int ERun;

double MinTrackMomentum;
double MaxTrackMomentum;
Expand All @@ -133,43 +110,33 @@ class SiStripGainsPCLWorker : public DQMEDAnalyzer {
std::string m_DQMdir; /*!< DQM folder hosting the charge statistics and the monitor plots */
std::string m_calibrationMode; /*!< Type of statistics for the calibration */
std::vector<std::string> VChargeHisto; /*!< Charge monitor plots to be output */

edm::ESHandle<TrackerGeometry> tkGeom_;
const TrackerGeometry *bareTkGeomPtr_; // ugly hack to fill APV colls only once, but checks


//Data members for processing

//Event data
unsigned int eventnumber =0;
unsigned int runnumber =0;
const std::vector<bool>* TrigTech =nullptr; edm::EDGetTokenT<std::vector<bool> > TrigTech_token_;

// Track data
const std::vector<double>* trackchi2ndof =nullptr; edm::EDGetTokenT<std::vector<double> > trackchi2ndof_token_;
const std::vector<float>* trackp =nullptr; edm::EDGetTokenT<std::vector<float> > trackp_token_;
const std::vector<float>* trackpt =nullptr; edm::EDGetTokenT<std::vector<float> > trackpt_token_;
const std::vector<double>* tracketa =nullptr; edm::EDGetTokenT<std::vector<double> > tracketa_token_;
const std::vector<double>* trackphi =nullptr; edm::EDGetTokenT<std::vector<double> > trackphi_token_;
const std::vector<unsigned int>* trackhitsvalid =nullptr; edm::EDGetTokenT<std::vector<unsigned int> > trackhitsvalid_token_;
const std::vector<int>* trackalgo =nullptr; edm::EDGetTokenT<std::vector<int> > trackalgo_token_;

// CalibTree data
const std::vector<int>* trackindex =nullptr; edm::EDGetTokenT<std::vector<int> > trackindex_token_;
const std::vector<unsigned int>* rawid =nullptr; edm::EDGetTokenT<std::vector<unsigned int> > rawid_token_;
const std::vector<double>* localdirx =nullptr; edm::EDGetTokenT<std::vector<double> > localdirx_token_;
const std::vector<double>* localdiry =nullptr; edm::EDGetTokenT<std::vector<double> > localdiry_token_;
const std::vector<double>* localdirz =nullptr; edm::EDGetTokenT<std::vector<double> > localdirz_token_;
const std::vector<unsigned short>* firststrip =nullptr; edm::EDGetTokenT<std::vector<unsigned short> > firststrip_token_;
const std::vector<unsigned short>* nstrips =nullptr; edm::EDGetTokenT<std::vector<unsigned short> > nstrips_token_;
const std::vector<bool>* saturation =nullptr; edm::EDGetTokenT<std::vector<bool> > saturation_token_;
const std::vector<bool>* overlapping =nullptr; edm::EDGetTokenT<std::vector<bool> > overlapping_token_;
const std::vector<bool>* farfromedge =nullptr; edm::EDGetTokenT<std::vector<bool> > farfromedge_token_;
const std::vector<unsigned int>* charge =nullptr; edm::EDGetTokenT<std::vector<unsigned int> > charge_token_;
const std::vector<double>* path =nullptr; edm::EDGetTokenT<std::vector<double> > path_token_;
const std::vector<double>* chargeoverpath =nullptr; edm::EDGetTokenT<std::vector<double> > chargeoverpath_token_;
const std::vector<unsigned char>* amplitude =nullptr; edm::EDGetTokenT<std::vector<unsigned char> > amplitude_token_;
const std::vector<double>* gainused =nullptr; edm::EDGetTokenT<std::vector<double> > gainused_token_;
const std::vector<double>* gainusedTick =nullptr; edm::EDGetTokenT<std::vector<double> > gainusedTick_token_;
edm::EDGetTokenT<std::vector<bool> > TrigTech_token_;
edm::EDGetTokenT<std::vector<double> > trackchi2ndof_token_;
edm::EDGetTokenT<std::vector<float> > trackp_token_;
edm::EDGetTokenT<std::vector<float> > trackpt_token_;
edm::EDGetTokenT<std::vector<double> > tracketa_token_;
edm::EDGetTokenT<std::vector<double> > trackphi_token_;
edm::EDGetTokenT<std::vector<unsigned int> > trackhitsvalid_token_;
edm::EDGetTokenT<std::vector<int> > trackalgo_token_;
edm::EDGetTokenT<std::vector<int> > trackindex_token_;
edm::EDGetTokenT<std::vector<unsigned int> > rawid_token_;
edm::EDGetTokenT<std::vector<double> > localdirx_token_;
edm::EDGetTokenT<std::vector<double> > localdiry_token_;
edm::EDGetTokenT<std::vector<double> > localdirz_token_;
edm::EDGetTokenT<std::vector<unsigned short> > firststrip_token_;
edm::EDGetTokenT<std::vector<unsigned short> > nstrips_token_;
edm::EDGetTokenT<std::vector<bool> > saturation_token_;
edm::EDGetTokenT<std::vector<bool> > overlapping_token_;
edm::EDGetTokenT<std::vector<bool> > farfromedge_token_;
edm::EDGetTokenT<std::vector<unsigned int> > charge_token_;
edm::EDGetTokenT<std::vector<double> > path_token_;
edm::EDGetTokenT<std::vector<double> > chargeoverpath_token_;
edm::EDGetTokenT<std::vector<unsigned char> > amplitude_token_;
edm::EDGetTokenT<std::vector<double> > gainused_token_;
edm::EDGetTokenT<std::vector<double> > gainusedTick_token_;

std::string EventPrefix_; //("");
std::string EventSuffix_; //("");
Expand All @@ -178,9 +145,9 @@ class SiStripGainsPCLWorker : public DQMEDAnalyzer {
std::string CalibPrefix_; //("GainCalibration");
std::string CalibSuffix_; //("");

std::vector<std::shared_ptr<stAPVGain> > APVsCollOrdered;
std::unordered_map<unsigned int, std::shared_ptr<stAPVGain> > APVsColl;
// maps histograms index to topology
std::map<unsigned int,APVloc> theTopologyMap;

};

inline int
Expand All @@ -192,15 +159,8 @@ SiStripGainsPCLWorker::statCollectionFromMode(const char* tag) const
it++;
}

if (std::string(tag)=="") return 0; // return StdBunch calibration mode for backward compatibility
if (std::string(tag).empty()) return 0; // return StdBunch calibration mode for backward compatibility

return None;
}

template<typename T>
inline edm::Handle<T> connect(const T* &ptr, edm::EDGetTokenT<T> token, const edm::Event &evt) {
edm::Handle<T> handle;
evt.getByToken(token, handle);
ptr = handle.product();
return handle; //return handle to keep alive pointer (safety first)
}
Loading

0 comments on commit ec655a6

Please sign in to comment.