Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation of T**DetId in CalibTracker #19393

Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include "TROOT.h"
#include "TFile.h"
#include "TDirectory.h"
Expand All @@ -19,13 +17,17 @@
#include "PlotFunction.h"

#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
#include "DataFormats/SiStripDetId/interface/TIBDetId.h"
#include "DataFormats/SiStripDetId/interface/TIDDetId.h"
#include "DataFormats/SiStripDetId/interface/TOBDetId.h"
#include "DataFormats/SiStripDetId/interface/TECDetId.h"
#include "DataFormats/TrackerCommon/interface/StandaloneTrackerTopology.h"

// IMPORTANT: to run this macro, first load the required library
// with the following line, inside ROOT:
// gSystem->Load("libDataFormatsTrackerCommon.so")


TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXML(std::string(gSystem->Getenv("CMSSW_RELEASE_BASE"))+"src/Geometry/TrackerCommonData/data/trackerParameters.xml");

#include<vector>
#include<tdrstyle.C>
#include"tdrstyle.C"

std::map<unsigned int, double> RunToIntLumi;

Expand Down Expand Up @@ -413,31 +415,27 @@ void GetAverageGain(string input, string moduleName, stLayerData& layerData )
t1->GetEntry(ientry);
SiStripDetId SSdetId(tree_DetId);

char LayerName[255];
char LayerName[255];

int LayerID=tree_SubDet*1000;
switch(tree_SubDet){
case 3:{
TIBDetId tibid = TIBDetId(tree_DetId);
LayerID += tibid.layer();
sprintf(LayerName,"lTIB%i",tibid.layer());
switch (tree_SubDet) {
case SiStripDetId::TIB:{
LayerID += tTopo.tibLayer(tree_DetId);
sprintf(LayerName,"lTIB%i",tTopo.tibLayer(tree_DetId));
}break;
case 4:{
TIDDetId tidid = TIDDetId(tree_DetId);
LayerID += tidid.side()*100;
LayerID += tidid.ring();
sprintf(LayerName,"rTID%c%i",tidid.side()==1?'-':'+', tidid.ring());
case SiStripDetId::TID:{
LayerID += tTopo.tidSide(tree_DetId)*100;
LayerID += tTopo.tidRing(tree_DetId);
sprintf(LayerName,"rTID%c%i",tTopo.tidSide(tree_DetId)==1?'-':'+', tTopo.tidRing(tree_DetId));
}break;
case 5:{
TOBDetId tobid = TOBDetId(tree_DetId);
LayerID += tobid.layer();
sprintf(LayerName,"lTOB%i",tobid.layer());
case SiStripDetId::TOB:{
LayerID += tTopo.tobLayer(tree_DetId);
sprintf(LayerName,"lTOB%i",tTopo.tobLayer(tree_DetId));
}break;
case 6:{
TECDetId tecid = TECDetId(tree_DetId);
LayerID += tecid.side()*100;
LayerID += tecid.ring();
sprintf(LayerName,"rTEC%c%i",tecid.side()==1?'-':'+', tecid.ring());
case SiStripDetId::TEC:{
LayerID += tTopo.tecSide(tree_DetId)*100;
LayerID += tTopo.tecRing(tree_DetId);
sprintf(LayerName,"rTEC%c%i",tTopo.tecSide(tree_DetId)==1?'-':'+', tTopo.tecRing(tree_DetId));
}break;
default:
break;
Expand All @@ -449,18 +447,16 @@ void GetAverageGain(string input, string moduleName, stLayerData& layerData )


LayerID=tree_SubDet*1000;
switch(tree_SubDet){
case 4:{
TIDDetId tidid = TIDDetId(tree_DetId);
LayerID += (2+tidid.side())*100;
LayerID += tidid.wheel();
sprintf(LayerName,"wTID%c%i",tidid.side()==1?'-':'+', tidid.wheel());
switch (tree_SubDet) {
case SiStripDetId::TID:{
LayerID += (2+tTopo.tidSide(tree_DetId))*100;
LayerID += tTopo.tidWheel(tree_DetId);
sprintf(LayerName,"wTID%c%i",tTopo.tidSide(tree_DetId)==1?'-':'+', tTopo.tidWheel(tree_DetId));
}break;
case 6:{
TECDetId tecid = TECDetId(tree_DetId);
LayerID += (2+tecid.side())*100;
LayerID += tecid.wheel();
sprintf(LayerName,"wTEC%c%i",tecid.side()==1?'-':'+', tecid.wheel());
case SiStripDetId::TEC:{
LayerID += (2+tTopo.tecSide(tree_DetId))*100;
LayerID += tTopo.tecWheel(tree_DetId);
sprintf(LayerName,"wTEC%c%i",tTopo.tecSide(tree_DetId)==1?'-':'+', tTopo.tecWheel(tree_DetId));
}break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions CalibTracker/SiStripLorentzAngle/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<use name="DataFormats/SiStripDetId"/>
<use name="root"/>
<use name="DataFormats/SiStripCluster"/>
<use name="DataFormats/TrackerCommon" />
<export>
<lib name="1"/>
</export>
25 changes: 14 additions & 11 deletions CalibTracker/SiStripLorentzAngle/interface/LA_Filler_Fitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <string>
#include <vector>
#include <map>
#include "DataFormats/SiStripDetId/interface/TOBDetId.h"
#include "DataFormats/SiStripDetId/interface/TIBDetId.h"
#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
#include "CalibTracker/SiStripCommon/interface/Book.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include <TTree.h>
#include "SymmetryFit.h"
class TProfile;
Expand All @@ -15,26 +15,28 @@ class LA_Filler_Fitter {

public:

//ensemble constructor
LA_Filler_Fitter(int methods, int M, int N, double low, double up, unsigned max) :
//ensemble constructor
LA_Filler_Fitter(int methods, int M, int N, double low, double up, unsigned max, const TrackerTopology *tTopo) :
ensembleSize_(M),
ensembleBins_(N),ensembleLow_(low),ensembleUp_(up),
byLayer_(true),byModule_(false),
localYbin_(0),
stripsPerBin_(0),
maxEvents_(max),
methods_(methods) {};

methods_(methods),
tTopo_(tTopo) {}

//measurement constructor
LA_Filler_Fitter(int methods, bool layer, bool module, float localybin, unsigned stripbin, unsigned max) :
LA_Filler_Fitter(int methods, bool layer, bool module, float localybin, unsigned stripbin, unsigned max, const TrackerTopology *tTopo) :
ensembleSize_(0),
ensembleBins_(0),ensembleLow_(0),ensembleUp_(0),
byLayer_(layer),byModule_(module),
localYbin_(localybin),
stripsPerBin_(stripbin),
maxEvents_(max),
methods_(methods) {};

methods_(methods),
tTopo_(tTopo) {}

enum Method { WIDTH =1<<0, FIRST_METHOD=1<<0,
PROB1 =1<<1,
AVGV2 =1<<2,
Expand Down Expand Up @@ -80,7 +82,7 @@ class LA_Filler_Fitter {
poly<std::string> granularity(const SiStripDetId, const float, const Long64_t, const float, const unsigned) const;
static std::string subdetLabel(const SiStripDetId);
static std::string moduleLabel(const SiStripDetId);
static std::string layerLabel(const SiStripDetId);
std::string layerLabel(const SiStripDetId) const;
static unsigned layer_index(bool TIB, bool stereo, unsigned layer) { return layer + (TIB?0:6) +(stereo?1:0) + ( (layer>2)?1:(layer==1)?-1:0 );}

//Located in src/LA_Fitter.cc
Expand All @@ -100,7 +102,7 @@ class LA_Filler_Fitter {
static std::map< std::string, std::vector<EnsembleSummary> > ensemble_summary(const Book& );
static std::pair<std::pair<float,float>, std::pair<float,float> > offset_slope(const std::vector<EnsembleSummary>&);
static float pull(const std::vector<EnsembleSummary>&);

private:

const int ensembleSize_, ensembleBins_;
Expand All @@ -110,6 +112,7 @@ class LA_Filler_Fitter {
const unsigned stripsPerBin_;
const Long64_t maxEvents_;
const int methods_;
const TrackerTopology* tTopo_;
};

std::ostream& operator<<(std::ostream&, const LA_Filler_Fitter::Result&);
Expand Down
19 changes: 13 additions & 6 deletions CalibTracker/SiStripLorentzAngle/plugins/EnsembleCalibrationLA.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "CalibTracker/SiStripLorentzAngle/plugins/EnsembleCalibrationLA.h"
#include "CalibTracker/SiStripCommon/interface/Book.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "Geometry/Records/interface/TrackerTopologyRcd.h"
#include <TChain.h>
#include <TFile.h>
#include <boost/foreach.hpp>
Expand All @@ -21,17 +23,15 @@ EnsembleCalibrationLA::EnsembleCalibrationLA(const edm::ParameterSet& conf) :
vMethods( conf.getParameter<std::vector<int> >("Methods"))
{}

void EnsembleCalibrationLA::
endJob()
void EnsembleCalibrationLA::endJob()
{
Book book("la_ensemble");
TChain*const chain = new TChain("la_ensemble");
BOOST_FOREACH(std::string file, inputFiles) chain->Add((file+inFileLocation).c_str());

int methods = 0; BOOST_FOREACH(unsigned method, vMethods) methods|=method;

LA_Filler_Fitter
laff(methods,samples,nbins,lowBin,highBin,maxEvents);
LA_Filler_Fitter laff(methods,samples,nbins,lowBin,highBin,maxEvents,tTopo_);
laff.fill(chain,book);
laff.fit(book);
laff.summarize_ensembles(book);
Expand All @@ -42,8 +42,15 @@ endJob()
write_calibrations();
}

void EnsembleCalibrationLA::
write_ensembles_text(const Book& book) {
void EnsembleCalibrationLA::endRun(const edm::Run&, const edm::EventSetup& eSetup)
{
edm::ESHandle<TrackerTopology> tTopoHandle;
eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
tTopo_ = tTopoHandle.product();
}

void EnsembleCalibrationLA::write_ensembles_text(const Book& book)
{
std::pair<std::string, std::vector<LA_Filler_Fitter::EnsembleSummary> > ensemble;
BOOST_FOREACH(ensemble, LA_Filler_Fitter::ensemble_summary(book)) {
std::fstream file((Prefix+ensemble.first+".dat").c_str(),std::ios::out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class EnsembleCalibrationLA : public edm::EDAnalyzer {

explicit EnsembleCalibrationLA(const edm::ParameterSet&);
void analyze(const edm::Event&, const edm::EventSetup&) {}
void endRun(const edm::Run&, const edm::EventSetup&);
void endJob();

private:
Expand All @@ -38,6 +39,7 @@ class EnsembleCalibrationLA : public edm::EDAnalyzer {
};
std::map<std::string,MethodCalibrations> calibrations;

const TrackerTopology* tTopo_;
};
}
#endif
38 changes: 23 additions & 15 deletions CalibTracker/SiStripLorentzAngle/plugins/MeasureLA.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "CalibTracker/SiStripLorentzAngle/plugins/MeasureLA.h"
#include "CalibTracker/SiStripLorentzAngle/interface/LA_Filler_Fitter.h"
#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
#include "DataFormats/TrackerCommon/interface/StandaloneTrackerTopology.h"

#include <boost/lexical_cast.hpp>
#include <TChain.h>
#include <TFile.h>


namespace sistrip {

void MeasureLA::
Expand All @@ -26,7 +29,8 @@ MeasureLA::MeasureLA(const edm::ParameterSet& conf) :
methods(0), byModule(false), byLayer(false),
localybin(conf.getUntrackedParameter<double>("LocalYBin",0.0)),
stripsperbin(conf.getUntrackedParameter<unsigned>("StripsPerBin",0)),
maxEvents( conf.getUntrackedParameter<unsigned>("MaxEvents",0))
maxEvents( conf.getUntrackedParameter<unsigned>("MaxEvents",0)),
tTopo_(StandaloneTrackerTopology::fromTrackerParametersXML(conf.getParameter<edm::FileInPath>("TrackerParameters").fullPath()))
{
store_methods_and_granularity( reports );
store_methods_and_granularity( measurementPreferences );
Expand All @@ -35,10 +39,10 @@ MeasureLA::MeasureLA(const edm::ParameterSet& conf) :
TChain*const chain = new TChain("la_data");
BOOST_FOREACH(const std::string file, inputFiles) chain->Add((file+inFileLocation).c_str());

LA_Filler_Fitter laff(methods, byLayer, byModule, localybin, stripsperbin, maxEvents);
LA_Filler_Fitter laff(methods, byLayer, byModule, localybin, stripsperbin, maxEvents, &tTopo_);
laff.fill(chain, book);
laff.fit(book);
summarize_module_muH_byLayer();
summarize_module_muH_byLayer(laff);
process_reports();

setWhatProduced(this,&MeasureLA::produce);
Expand All @@ -60,15 +64,18 @@ produce(const SiStripLorentzAngleRcd& ) {
return lorentzAngle;
}




void MeasureLA::
summarize_module_muH_byLayer() {
summarize_module_muH_byLayer(const LA_Filler_Fitter& laff) {
for(int m = LA_Filler_Fitter::FIRST_METHOD; m <= LA_Filler_Fitter::LAST_METHOD; m<<=1) {
const LA_Filler_Fitter::Method method = (LA_Filler_Fitter::Method)m;
std::pair<uint32_t,LA_Filler_Fitter::Result> result;
BOOST_FOREACH(result, LA_Filler_Fitter::module_results(book, method)) {

calibrate( calibration_key(result.first,method), result.second);
std::string label = LA_Filler_Fitter::layerLabel(result.first) + granularity(MODULESUMMARY) + LA_Filler_Fitter::method(method);
std::string label = laff.layerLabel(result.first) + granularity(MODULESUMMARY) + LA_Filler_Fitter::method(method);
label = boost::regex_replace(label,boost::regex("layer"),"");

const double mu_H = -result.second.calMeasured.first / result.second.field;
Expand All @@ -93,7 +100,7 @@ process_reports() const {
write_report_plots( name, method, gran);
switch(gran) {
case LAYER: write_report_text( name, method, LA_Filler_Fitter::layer_results(book, method) ); break;
case MODULE: write_report_text( name, method, LA_Filler_Fitter::module_results(book, method)); break;
case MODULE: write_report_text( name, method, LA_Filler_Fitter::module_results(book, method) ); break;
case MODULESUMMARY: write_report_text_ms( name, method); break;
}
}
Expand All @@ -104,7 +111,7 @@ process_reports() const {
}

void MeasureLA::
write_report_plots(std::string name, LA_Filler_Fitter::Method method, GRANULARITY gran ) const {
write_report_plots(std::string name, LA_Filler_Fitter::Method method, GRANULARITY gran) const {
TFile file((name+".root").c_str(),"RECREATE");
const std::string key = ".*" + granularity(gran) + ".*("+LA_Filler_Fitter::method(method)+"|"+LA_Filler_Fitter::method(method,0)+".*)";
for(Book::const_iterator hist = book.begin(key); hist!=book.end(); ++hist)
Expand Down Expand Up @@ -168,20 +175,21 @@ calibrate(const std::pair<unsigned,LA_Filler_Fitter::Method> key, LA_Filler_Fitt
}

std::pair<uint32_t,LA_Filler_Fitter::Method> MeasureLA::
calibration_key(const std::string layer, const LA_Filler_Fitter::Method method) {
calibration_key(const std::string layer, const LA_Filler_Fitter::Method method) const {
boost::regex format(".*(T[IO]B)_layer(\\d)([as]).*");
const bool TIB = "TIB" == boost::regex_replace(layer, format, "\\1");
const bool isTIB = "TIB" == boost::regex_replace(layer, format, "\\1");
const bool stereo = "s" == boost::regex_replace(layer, format, "\\3");
const unsigned layerNum = boost::lexical_cast<unsigned>(boost::regex_replace(layer, format, "\\2"));
return std::make_pair(LA_Filler_Fitter::layer_index(TIB,stereo,layerNum),method);
return std::make_pair(LA_Filler_Fitter::layer_index(isTIB,stereo,layerNum),method);
}

std::pair<uint32_t,LA_Filler_Fitter::Method> MeasureLA::
calibration_key(const uint32_t detid, const LA_Filler_Fitter::Method method) {
const bool TIB = SiStripDetId(detid).subDetector() == SiStripDetId::TIB;
const bool stereo = TIB ? TIBDetId(detid).stereo() : TOBDetId(detid).stereo();
const unsigned layer = TIB ? TIBDetId(detid).layer() : TOBDetId(detid).layer();
return std::make_pair(LA_Filler_Fitter::layer_index(TIB,stereo,layer),method);
calibration_key(const uint32_t detid, const LA_Filler_Fitter::Method method) const {
const bool isTIB = SiStripDetId(detid).subDetector() == SiStripDetId::TIB;
const bool stereo = isTIB ? tTopo_.tibStereo(detid) : tTopo_.tobStereo(detid);
const unsigned layer = isTIB ? tTopo_.tibLayer(detid) : tTopo_.tobStereo(detid);

return std::make_pair(LA_Filler_Fitter::layer_index(isTIB,stereo,layer),method);
}

}
8 changes: 5 additions & 3 deletions CalibTracker/SiStripLorentzAngle/plugins/MeasureLA.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ESProducer.h"

#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
#include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
#include "CalibTracker/SiStripLorentzAngle/interface/LA_Filler_Fitter.h"
Expand Down Expand Up @@ -32,16 +33,16 @@ class MeasureLA : public edm::ESProducer {
void store_calibrations();
void store_methods_and_granularity(const edm::VParameterSet&);

void summarize_module_muH_byLayer();
void summarize_module_muH_byLayer(const LA_Filler_Fitter&);
void process_reports() const;
template<class T>
void write_report_text(const std::string, const LA_Filler_Fitter::Method&, const std::map<T,LA_Filler_Fitter::Result>&) const;
void write_report_text_ms(const std::string, const LA_Filler_Fitter::Method ) const;
void write_report_plots(const std::string, const LA_Filler_Fitter::Method, const GRANULARITY) const;

void calibrate(const std::pair<unsigned,LA_Filler_Fitter::Method>, LA_Filler_Fitter::Result&) const;
static std::pair<unsigned,LA_Filler_Fitter::Method> calibration_key(const std::string layer, const LA_Filler_Fitter::Method);
static std::pair<unsigned,LA_Filler_Fitter::Method> calibration_key(const uint32_t detid, const LA_Filler_Fitter::Method);
std::pair<unsigned,LA_Filler_Fitter::Method> calibration_key(const std::string layer, const LA_Filler_Fitter::Method) const;
std::pair<unsigned,LA_Filler_Fitter::Method> calibration_key(const uint32_t detid, const LA_Filler_Fitter::Method) const ;

const std::vector<std::string> inputFiles;
const std::string inFileLocation;
Expand All @@ -54,6 +55,7 @@ class MeasureLA : public edm::ESProducer {
const unsigned stripsperbin,maxEvents;
Book book;

TrackerTopology tTopo_;
};

}
Expand Down