15 #include "CLHEP/Random/RandFlat.h"
16 #include "CLHEP/Random/RandGauss.h"
32 edm::LogInfo(
"SiStripGainCosmicCalculator::SiStripGainCosmicCalculator");
34 edm::LogInfo(
"SiStripApvGainCalculator::SiStripApvGainCalculator")
50 edm::LogInfo(
"SiStripApvGainCalculator") <<
"The calibration for these DetIds will be set to a default value";
54 edm::LogInfo(
"SiStripApvGainCalculator") <<
"exclude detid = " << *imod;
59 tTopoToken_ = esConsumes<edm::Transition::BeginRun>();
65 edm::LogInfo(
"SiStripGainCosmicCalculator::~SiStripGainCosmicCalculator");
75 std::cout <<
"SiStripGainCosmicCalculator::algoBeginJob called" << std::endl;
80 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrections"), Form(
"APVPairCorrections"), 50, -1., 4.));
81 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTIB1mono"), Form(
"APVPairCorrectionsTIB1mono"), 50, -1., 4.));
83 new TH1F(Form(
"APVPairCorrectionsTIB1stereo"), Form(
"APVPairCorrectionsTIB1stereo"), 50, -1., 4.));
84 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTIB2"), Form(
"APVPairCorrectionsTIB2"), 50, -1., 4.));
85 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTOB1"), Form(
"APVPairCorrectionsTOB1"), 50, -1., 4.));
86 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTOB2"), Form(
"APVPairCorrectionsTOB2"), 50, -1., 4.));
87 HlistOtherHistos->Add(
new TH1F(Form(
"LocalAngle"), Form(
"LocalAngle"), 70, -0.1, 3.4));
88 HlistOtherHistos->Add(
new TH1F(Form(
"LocalAngleAbsoluteCosine"), Form(
"LocalAngleAbsoluteCosine"), 48, -0.1, 1.1));
89 HlistOtherHistos->Add(
new TH1F(Form(
"LocalPosition_cm"), Form(
"LocalPosition_cm"), 100, -5., 5.));
90 HlistOtherHistos->Add(
new TH1F(Form(
"LocalPosition_normalized"), Form(
"LocalPosition_normalized"), 100, -1.1, 1.1));
91 TH1F* local_histo =
new TH1F(Form(
"SiStripRecHitType"), Form(
"SiStripRecHitType"), 2, 0.5, 2.5);
93 local_histo->GetXaxis()->SetBinLabel(1,
"simple");
94 local_histo->GetXaxis()->SetBinLabel(2,
"matched");
109 if (dynamic_cast<const StripGeomDetUnit*>(det) !=
nullptr) {
110 uint32_t detid = det->geographicalId().rawId();
112 double module_thickness =
116 thickness_map.insert(std::make_pair(detid, module_thickness));
118 const bool is_active_detector =
121 const bool exclude_this_detid =
125 if (is_active_detector &&
126 (!exclude_this_detid)) {
128 unsigned short NAPVPairs = p.
nstrips() / 256;
129 if (NAPVPairs < 2 || NAPVPairs > 3) {
131 <<
"Problem with Number of strips in detector: " << p.
nstrips() <<
" Exiting program";
134 for (
int iapp = 0; iapp < NAPVPairs; iapp++) {
135 TString hid = Form(
"ChargeAPVPair_%i_%i", detid, iapp);
137 new TH1F(hid, hid, 45, 0., 1350.));
165 for (reco::TrackCollection::const_iterator itr =
tracks->begin(); itr !=
tracks->end();
170 std::vector<std::pair<const TrackingRecHit*, float> >
173 for (
std::vector<std::pair<const TrackingRecHit*, float> >::const_iterator hitangle_iter = hitangle.begin();
174 hitangle_iter != hitangle.end();
177 float local_angle = hitangle_iter->second;
184 if (sistripsimplehit) {
187 const auto& ampls = cluster->amplitudes();
188 uint32_t thedetid = 0;
191 ((TH1F*)
HlistOtherHistos->FindObject(
"LocalPosition_normalized"))->
Fill(local_position.
x() / module_width);
193 int ifirststrip = cluster->firstStrip();
194 int theapvpairid = int(
float(ifirststrip) / 256.);
195 TH1F* histopointer = (TH1F*)
HlistAPVPairs->FindObject(Form(
"ChargeAPVPair_%i_%i", thedetid, theapvpairid));
198 for (
unsigned int iampl = 0; iampl < ampls.size(); iampl++) {
199 cCharge += ampls[iampl];
201 double cluster_charge_over_path = ((double)cCharge) * fabs(
cos(local_angle)) / (10. * module_thickness);
202 histopointer->Fill(cluster_charge_over_path);
205 if (sistripmatchedhit)
218 double nr_of_entries = inputHisto->GetEntries();
220 return std::make_pair(adcs, error);
232 std::unique_ptr<TF1> fitfunction(
new TF1(
"landaufit",
"landau"));
233 inputHisto->Fit(fitfunction.get(),
"0Q");
234 adcs = fitfunction->GetParameter(
"MPV");
235 error = fitfunction->GetParError(1);
236 double chi2 = fitfunction->GetChisquare();
237 double ndf = fitfunction->GetNDF();
238 double chi2overndf = chi2 / ndf;
240 if (adcs < 2. || (error / adcs) > 1.8) {
241 inputHisto->Fit(fitfunction.get(),
"0Q",
nullptr, 0., 400.);
242 std::cout <<
"refitting landau for histogram " << inputHisto->GetTitle() << std::endl;
243 std::cout <<
"initial error/adcs =" << error <<
" / " << adcs << std::endl;
244 std::cout <<
"new error/adcs =" << fitfunction->GetParError(1) <<
" / " << fitfunction->GetParameter(
"MPV")
246 adcs = fitfunction->GetParameter(
"MPV");
247 error = fitfunction->GetParError(1);
248 chi2 = fitfunction->GetChisquare();
249 ndf = fitfunction->GetNDF();
250 chi2overndf = chi2 / ndf;
257 return std::make_pair(adcs, error);
263 double module_width = 0.;
265 if (dynamic_cast<const StripGeomDetUnit*>(it) ==
nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) ==
nullptr) {
266 std::cout <<
"this detID doesn't seem to belong to the Tracker" << std::endl;
276 double module_thickness = 0.;
278 if (dynamic_cast<const StripGeomDetUnit*>(it) ==
nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) ==
nullptr) {
279 std::cout <<
"this detID doesn't seem to belong to the Tracker" << std::endl;
283 return module_thickness;
288 std::cout <<
"SiStripGainCosmicCalculator::getNewObject called" << std::endl;
292 TH1F* ChargeOfEachAPVPair =
new TH1F(
"ChargeOfEachAPVPair",
"ChargeOfEachAPVPair", 1, 0, 1);
293 ChargeOfEachAPVPair->SetCanExtend(TH1::kAllAxes);
294 TH1F* EntriesApvPairs =
new TH1F(
"EntriesApvPairs",
"EntriesApvPairs", 1, 0, 1);
295 EntriesApvPairs->SetCanExtend(TH1::kAllAxes);
297 new TH1F(
"NrOfEntries",
"NrOfEntries", 351, -0.5, 350.5);
298 TH1F* ModuleThickness =
new TH1F(
"ModuleThickness",
"ModuleThickness", 2, 0.5, 2.5);
300 ModuleThickness->GetXaxis()->SetBinLabel(1,
"320mu");
301 ModuleThickness->GetXaxis()->SetBinLabel(2,
"500mu");
302 ModuleThickness->SetYTitle(
"Nr APVPairs");
303 TH1F* ModuleWidth =
new TH1F(
"ModuleWidth",
"ModuleWidth", 5, 0.5, 5.5);
305 ModuleWidth->GetXaxis()->SetBinLabel(1,
"6.144cm");
306 ModuleWidth->GetXaxis()->SetBinLabel(2,
"7.14cm");
307 ModuleWidth->GetXaxis()->SetBinLabel(3,
"9.3696cm");
308 ModuleWidth->GetXaxis()->SetBinLabel(4,
"10.49cm");
309 ModuleWidth->GetXaxis()->SetBinLabel(5,
"12.03cm");
310 ModuleWidth->SetYTitle(
"Nr APVPairs");
314 double MeanCharge = 0.;
315 double NrOfApvPairs = 0.;
316 TH1F* MyHisto = (TH1F*)hiterator();
318 TString histo_title = MyHisto->GetTitle();
319 if (histo_title.Contains(
"ChargeAPVPair_")) {
321 double local_nrofadcs = two_values.first;
322 double local_sigma = two_values.second;
323 ChargeOfEachAPVPair->Fill(histo_title, local_nrofadcs);
324 int ichbin = ChargeOfEachAPVPair->GetXaxis()->FindBin(histo_title.Data());
325 ChargeOfEachAPVPair->SetBinError(ichbin, local_sigma);
326 EntriesApvPairs->Fill(histo_title, MyHisto->GetEntries());
327 NrOfEntries->Fill(MyHisto->GetEntries());
328 if (local_nrofadcs > 0) {
329 MeanCharge += local_nrofadcs;
333 MyHisto = (TH1F*)hiterator();
335 ChargeOfEachAPVPair->LabelsDeflate(
"X");
336 EntriesApvPairs->LabelsDeflate(
"X");
340 MeanCharge = MeanCharge / NrOfApvPairs;
342 TH1F* CorrectionOfEachAPVPair = (TH1F*)ChargeOfEachAPVPair->Clone(
"CorrectionOfEachAPVPair");
343 TH1F* ChargeOfEachAPVPairControlView =
344 new TH1F(
"ChargeOfEachAPVPairControlView",
"ChargeOfEachAPVPairControlView", 1, 0, 1);
345 ChargeOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
346 TH1F* CorrectionOfEachAPVPairControlView =
347 new TH1F(
"CorrectionOfEachAPVPairControlView",
"CorrectionOfEachAPVPairControlView", 1, 0, 1);
348 CorrectionOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
349 std::ofstream APVPairTextOutput(
"apvpair_corrections.txt");
350 APVPairTextOutput <<
"# MeanCharge = " << MeanCharge << std::endl;
351 APVPairTextOutput <<
"# Nr. of APVPairs = " << NrOfApvPairs << std::endl;
352 for (
int ibin = 1; ibin <= ChargeOfEachAPVPair->GetNbinsX(); ibin++) {
353 TString local_bin_label = ChargeOfEachAPVPair->GetXaxis()->GetBinLabel(ibin);
354 double local_charge_over_path = ChargeOfEachAPVPair->GetBinContent(ibin);
355 if (local_bin_label.Contains(
"ChargeAPVPair_") &&
356 local_charge_over_path > 0.0000001) {
357 uint32_t extracted_detid;
358 std::istringstream read_label((local_bin_label(14, 9)).Data());
359 read_label >> extracted_detid;
360 unsigned short extracted_apvpairid;
361 std::istringstream read_apvpair((local_bin_label(24, 1)).Data());
362 read_apvpair >> extracted_apvpairid;
363 double local_error_of_charge = ChargeOfEachAPVPair->GetBinError(ibin);
364 double local_correction = -0.5;
365 double local_error_correction = 0.;
367 MeanCharge / local_charge_over_path;
368 local_error_correction = local_correction * local_error_of_charge / local_charge_over_path;
369 if (local_error_correction > 1.8) {
370 std::cout <<
"too large error " << local_error_correction <<
" for histogram " << local_bin_label << std::endl;
372 double nr_of_entries = EntriesApvPairs->GetBinContent(ibin);
373 APVPairTextOutput << local_bin_label <<
" " << local_correction <<
" " << local_charge_over_path <<
" "
374 << nr_of_entries << std::endl;
375 CorrectionOfEachAPVPair->SetBinContent(ibin, local_correction);
376 CorrectionOfEachAPVPair->SetBinError(ibin, local_error_correction);
379 unsigned int generalized_layer = 0;
387 edm::LogError(
"ClusterMTCCFilter") <<
"WRONGGGG" << std::endl;
390 generalized_layer = 10 * thedetId.
subdetId();
395 if (generalized_layer == 31) {
398 if (generalized_layer == 32) {
401 if (generalized_layer == 33) {
404 if (generalized_layer == 51) {
407 if (generalized_layer == 52) {
413 std::ostringstream local_key;
415 local_key <<
"fecCrate" << fedchannelconnection.
fecCrate() <<
"_fecSlot" << fedchannelconnection.
fecSlot()
416 <<
"_fecRing" << fedchannelconnection.
fecRing() <<
"_ccuAddr" << fedchannelconnection.
ccuAddr()
417 <<
"_ccuChan" << fedchannelconnection.
ccuChan() <<
"_apvPair" << extracted_apvpairid;
418 TString control_key = local_key.str();
419 ChargeOfEachAPVPairControlView->Fill(control_key, local_charge_over_path);
420 int ibin1 = ChargeOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
421 ChargeOfEachAPVPairControlView->SetBinError(ibin1, local_error_of_charge);
422 CorrectionOfEachAPVPairControlView->Fill(control_key, local_correction);
423 int ibin2 = CorrectionOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
424 CorrectionOfEachAPVPairControlView->SetBinError(ibin2, local_error_correction);
427 if (fabs(module_thickness - 0.032) < 0.001)
428 ModuleThickness->Fill(1);
429 if (fabs(module_thickness - 0.05) < 0.001)
430 ModuleThickness->Fill(2);
432 double module_width =
moduleWidth(extracted_detid);
433 if (fabs(module_width - 6.144) < 0.01)
434 ModuleWidth->Fill(1);
435 if (fabs(module_width - 7.14) < 0.01)
436 ModuleWidth->Fill(2);
437 if (fabs(module_width - 9.3696) < 0.01)
438 ModuleWidth->Fill(3);
439 if (fabs(module_width - 10.49) < 0.01)
440 ModuleWidth->Fill(4);
441 if (fabs(module_width - 12.03) < 0.01)
442 ModuleWidth->Fill(5);
446 ChargeOfEachAPVPairControlView->LabelsDeflate(
"X");
447 CorrectionOfEachAPVPairControlView->LabelsDeflate(
"X");
459 auto obj = std::make_unique<SiStripApvGain>();
const uint16_t & fecSlot() const
TObjArray * HlistAPVPairs
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
uint32_t total_nr_of_events
std::vector< uint32_t > SelectedDetIds
double ExpectedChargeDeposition
const uint16_t & fecCrate() const
const FedChannelConnection & getConnection(uint32_t det_id, unsigned short apv_pair) const
void getTIBDetectors(const std::vector< uint32_t > &inputDetRawIds, std::vector< uint32_t > &tibDetRawIds, const TrackerTopology *trackerTopology, uint32_t layer=0, uint32_t bkw_frw=0, uint32_t int_ext=0, uint32_t string=0)
const SiStripDetCabling * siStripDetCabling_
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
unsigned int tibLayer(const DetId &id) const
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
double moduleThickness(const uint32_t detid)
void algoBeginJob(const edm::EventSetup &) override
TObjArray * HlistOtherHistos
constexpr uint32_t rawId() const
get the raw id
std::vector< Track > TrackCollection
collection of Tracks
~SiStripGainCosmicCalculator() override
const Bounds & bounds() const
auto const & tracks
cannot be loose
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
bool outputHistogramsInRootFile
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const Plane & surface() const
The nominal surface of the GeomDet.
std::pair< double, double > getPeakOfLandau(TH1F *inputHisto)
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
virtual float thickness() const =0
bool getData(T &iHolder) const
unsigned int MinNrEntries
const uint16_t & fecRing() const
Class containning control, module, detector and connection information, at the level of a FED channel...
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::vector< uint32_t > activeDets
Cos< T >::type cos(const T &t)
const TrackerTopology * tTopo_
const uint16_t & ccuChan() const
SiStripGainCosmicCalculator(const edm::ParameterSet &)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::map< uint32_t, double > thickness_map
const TrackerGeometry * tkGeom_
ClusterRef cluster() const
static constexpr auto TOB
const uint16_t & ccuAddr() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::unique_ptr< SiStripApvGain > getNewObject() override
Log< level::Info, false > LogInfo
static constexpr auto TIB
uint32_t tibGlued(const DetId &id) const
std::vector< uint32_t > detModulesToBeExcluded
T getParameter(std::string const &) const
edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > detCablingToken_
void getTOBDetectors(const std::vector< uint32_t > &inputDetRawIds, std::vector< uint32_t > &tobDetRawIds, const TrackerTopology *trackerTopology, uint32_t layer=0, uint32_t bkw_frw=0, uint32_t rod=0)
uint32_t tibStereo(const DetId &id) const
double moduleWidth(const uint32_t detid)
virtual LocalPoint localPosition() const =0
virtual float width() const =0
void algoEndJob() override
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
unsigned int tobLayer(const DetId &id) const