18 #include "CLHEP/Random/RandFlat.h" 19 #include "CLHEP/Random/RandGauss.h" 39 edm::LogInfo(
"SiStripGainCosmicCalculator::SiStripGainCosmicCalculator");
41 edm::LogInfo(
"SiStripApvGainCalculator::SiStripApvGainCalculator")
57 edm::LogInfo(
"SiStripApvGainCalculator") <<
"The calibration for these DetIds will be set to a default value";
61 edm::LogInfo(
"SiStripApvGainCalculator") <<
"exclude detid = " << *imod;
69 edm::LogInfo(
"SiStripGainCosmicCalculator::~SiStripGainCosmicCalculator");
88 std::cout <<
"SiStripGainCosmicCalculator::algoBeginJob called" << std::endl;
93 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrections"), Form(
"APVPairCorrections"), 50, -1., 4.));
94 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTIB1mono"), Form(
"APVPairCorrectionsTIB1mono"), 50, -1., 4.));
96 new TH1F(Form(
"APVPairCorrectionsTIB1stereo"), Form(
"APVPairCorrectionsTIB1stereo"), 50, -1., 4.));
97 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTIB2"), Form(
"APVPairCorrectionsTIB2"), 50, -1., 4.));
98 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTOB1"), Form(
"APVPairCorrectionsTOB1"), 50, -1., 4.));
99 HlistOtherHistos->Add(
new TH1F(Form(
"APVPairCorrectionsTOB2"), Form(
"APVPairCorrectionsTOB2"), 50, -1., 4.));
100 HlistOtherHistos->Add(
new TH1F(Form(
"LocalAngle"), Form(
"LocalAngle"), 70, -0.1, 3.4));
101 HlistOtherHistos->Add(
new TH1F(Form(
"LocalAngleAbsoluteCosine"), Form(
"LocalAngleAbsoluteCosine"), 48, -0.1, 1.1));
102 HlistOtherHistos->Add(
new TH1F(Form(
"LocalPosition_cm"), Form(
"LocalPosition_cm"), 100, -5., 5.));
103 HlistOtherHistos->Add(
new TH1F(Form(
"LocalPosition_normalized"), Form(
"LocalPosition_normalized"), 100, -1.1, 1.1));
104 TH1F* local_histo =
new TH1F(Form(
"SiStripRecHitType"), Form(
"SiStripRecHitType"), 2, 0.5, 2.5);
106 local_histo->GetXaxis()->SetBinLabel(1,
"simple");
107 local_histo->GetXaxis()->SetBinLabel(2,
"matched");
112 std::vector<uint32_t> activeDets;
125 for (TrackerGeometry::DetContainer::const_iterator it = tkGeom->
dets().begin(); it != tkGeom->
dets().end();
127 if (dynamic_cast<const StripGeomDetUnit*>((*it)) !=
nullptr) {
128 uint32_t detid = ((*it)->geographicalId()).rawId();
130 double module_thickness =
135 thickness_map.insert(std::make_pair(detid, module_thickness));
137 bool is_active_detector =
false;
140 if (*iactive == detid) {
141 is_active_detector =
true;
146 bool exclude_this_detid =
false;
151 exclude_this_detid =
true;
155 if (is_active_detector &&
156 (!exclude_this_detid)) {
158 unsigned short NAPVPairs = p.
nstrips() / 256;
159 if (NAPVPairs < 2 || NAPVPairs > 3) {
161 <<
"Problem with Number of strips in detector: " << p.
nstrips() <<
" Exiting program";
164 for (
int iapp = 0; iapp < NAPVPairs; iapp++) {
165 TString hid = Form(
"ChargeAPVPair_%i_%i", detid, iapp);
167 new TH1F(hid, hid, 45, 0., 1350.));
195 for (reco::TrackCollection::const_iterator itr = tracks->begin(); itr != tracks->end();
200 std::vector<std::pair<const TrackingRecHit*, float> >
203 for (std::vector<std::pair<const TrackingRecHit*, float> >::const_iterator hitangle_iter = hitangle.begin();
204 hitangle_iter != hitangle.end();
207 float local_angle = hitangle_iter->second;
214 if (sistripsimplehit) {
217 const auto& ampls = cluster->amplitudes();
218 uint32_t thedetid = 0;
221 ((TH1F*)
HlistOtherHistos->FindObject(
"LocalPosition_normalized"))->
Fill(local_position.
x() / module_width);
223 int ifirststrip = cluster->firstStrip();
224 int theapvpairid =
int(
float(ifirststrip) / 256.);
225 TH1F* histopointer = (TH1F*)
HlistAPVPairs->FindObject(Form(
"ChargeAPVPair_%i_%i", thedetid, theapvpairid));
228 for (
unsigned int iampl = 0; iampl < ampls.size(); iampl++) {
229 cCharge += ampls[iampl];
231 double cluster_charge_over_path = ((double)cCharge) * fabs(
cos(local_angle)) / (10. * module_thickness);
232 histopointer->Fill(cluster_charge_over_path);
235 if (sistripmatchedhit)
248 double nr_of_entries = inputHisto->GetEntries();
250 return std::make_pair(adcs, error);
262 std::unique_ptr<TF1> fitfunction(
new TF1(
"landaufit",
"landau"));
263 inputHisto->Fit(fitfunction.get(),
"0Q");
264 adcs = fitfunction->GetParameter(
"MPV");
265 error = fitfunction->GetParError(1);
266 double chi2 = fitfunction->GetChisquare();
267 double ndf = fitfunction->GetNDF();
268 double chi2overndf = chi2 / ndf;
270 if (adcs < 2. || (error / adcs) > 1.8) {
271 inputHisto->Fit(fitfunction.get(),
"0Q",
nullptr, 0., 400.);
272 std::cout <<
"refitting landau for histogram " << inputHisto->GetTitle() << std::endl;
273 std::cout <<
"initial error/adcs =" << error <<
" / " << adcs << std::endl;
274 std::cout <<
"new error/adcs =" << fitfunction->GetParError(1) <<
" / " << fitfunction->GetParameter(
"MPV")
276 adcs = fitfunction->GetParameter(
"MPV");
277 error = fitfunction->GetParError(1);
278 chi2 = fitfunction->GetChisquare();
279 ndf = fitfunction->GetNDF();
280 chi2overndf = chi2 / ndf;
287 return std::make_pair(adcs, error);
293 double module_width = 0.;
295 if (dynamic_cast<const StripGeomDetUnit*>(it) ==
nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) ==
nullptr) {
296 std::cout <<
"this detID doesn't seem to belong to the Tracker" << std::endl;
306 double module_thickness = 0.;
308 if (dynamic_cast<const StripGeomDetUnit*>(it) ==
nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) ==
nullptr) {
309 std::cout <<
"this detID doesn't seem to belong to the Tracker" << std::endl;
313 return module_thickness;
318 std::cout <<
"SiStripGainCosmicCalculator::getNewObject called" << std::endl;
322 TH1F* ChargeOfEachAPVPair =
new TH1F(
"ChargeOfEachAPVPair",
"ChargeOfEachAPVPair", 1, 0, 1);
323 ChargeOfEachAPVPair->SetCanExtend(TH1::kAllAxes);
324 TH1F* EntriesApvPairs =
new TH1F(
"EntriesApvPairs",
"EntriesApvPairs", 1, 0, 1);
325 EntriesApvPairs->SetCanExtend(TH1::kAllAxes);
327 new TH1F(
"NrOfEntries",
"NrOfEntries", 351, -0.5, 350.5);
328 TH1F* ModuleThickness =
new TH1F(
"ModuleThickness",
"ModuleThickness", 2, 0.5, 2.5);
330 ModuleThickness->GetXaxis()->SetBinLabel(1,
"320mu");
331 ModuleThickness->GetXaxis()->SetBinLabel(2,
"500mu");
332 ModuleThickness->SetYTitle(
"Nr APVPairs");
333 TH1F* ModuleWidth =
new TH1F(
"ModuleWidth",
"ModuleWidth", 5, 0.5, 5.5);
335 ModuleWidth->GetXaxis()->SetBinLabel(1,
"6.144cm");
336 ModuleWidth->GetXaxis()->SetBinLabel(2,
"7.14cm");
337 ModuleWidth->GetXaxis()->SetBinLabel(3,
"9.3696cm");
338 ModuleWidth->GetXaxis()->SetBinLabel(4,
"10.49cm");
339 ModuleWidth->GetXaxis()->SetBinLabel(5,
"12.03cm");
340 ModuleWidth->SetYTitle(
"Nr APVPairs");
344 double MeanCharge = 0.;
345 double NrOfApvPairs = 0.;
346 TH1F* MyHisto = (TH1F*)hiterator();
348 TString histo_title = MyHisto->GetTitle();
349 if (histo_title.Contains(
"ChargeAPVPair_")) {
351 double local_nrofadcs = two_values.first;
352 double local_sigma = two_values.second;
353 ChargeOfEachAPVPair->Fill(histo_title, local_nrofadcs);
354 int ichbin = ChargeOfEachAPVPair->GetXaxis()->FindBin(histo_title.Data());
355 ChargeOfEachAPVPair->SetBinError(ichbin, local_sigma);
356 EntriesApvPairs->Fill(histo_title, MyHisto->GetEntries());
357 NrOfEntries->Fill(MyHisto->GetEntries());
358 if (local_nrofadcs > 0) {
359 MeanCharge += local_nrofadcs;
363 MyHisto = (TH1F*)hiterator();
365 ChargeOfEachAPVPair->LabelsDeflate(
"X");
366 EntriesApvPairs->LabelsDeflate(
"X");
370 MeanCharge = MeanCharge / NrOfApvPairs;
372 TH1F* CorrectionOfEachAPVPair = (TH1F*)ChargeOfEachAPVPair->Clone(
"CorrectionOfEachAPVPair");
373 TH1F* ChargeOfEachAPVPairControlView =
374 new TH1F(
"ChargeOfEachAPVPairControlView",
"ChargeOfEachAPVPairControlView", 1, 0, 1);
375 ChargeOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
376 TH1F* CorrectionOfEachAPVPairControlView =
377 new TH1F(
"CorrectionOfEachAPVPairControlView",
"CorrectionOfEachAPVPairControlView", 1, 0, 1);
378 CorrectionOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
379 std::ofstream APVPairTextOutput(
"apvpair_corrections.txt");
380 APVPairTextOutput <<
"# MeanCharge = " << MeanCharge << std::endl;
381 APVPairTextOutput <<
"# Nr. of APVPairs = " << NrOfApvPairs << std::endl;
382 for (
int ibin = 1; ibin <= ChargeOfEachAPVPair->GetNbinsX(); ibin++) {
383 TString local_bin_label = ChargeOfEachAPVPair->GetXaxis()->GetBinLabel(ibin);
384 double local_charge_over_path = ChargeOfEachAPVPair->GetBinContent(ibin);
385 if (local_bin_label.Contains(
"ChargeAPVPair_") &&
386 local_charge_over_path > 0.0000001) {
387 uint32_t extracted_detid;
388 std::istringstream read_label((local_bin_label(14, 9)).Data());
389 read_label >> extracted_detid;
390 unsigned short extracted_apvpairid;
391 std::istringstream read_apvpair((local_bin_label(24, 1)).Data());
392 read_apvpair >> extracted_apvpairid;
393 double local_error_of_charge = ChargeOfEachAPVPair->GetBinError(ibin);
394 double local_correction = -0.5;
395 double local_error_correction = 0.;
397 MeanCharge / local_charge_over_path;
398 local_error_correction = local_correction * local_error_of_charge / local_charge_over_path;
399 if (local_error_correction > 1.8) {
400 std::cout <<
"too large error " << local_error_correction <<
" for histogram " << local_bin_label << std::endl;
402 double nr_of_entries = EntriesApvPairs->GetBinContent(ibin);
403 APVPairTextOutput << local_bin_label <<
" " << local_correction <<
" " << local_charge_over_path <<
" " 404 << nr_of_entries << std::endl;
405 CorrectionOfEachAPVPair->SetBinContent(ibin, local_correction);
406 CorrectionOfEachAPVPair->SetBinError(ibin, local_error_correction);
409 unsigned int generalized_layer = 0;
417 edm::LogError(
"ClusterMTCCFilter") <<
"WRONGGGG" << std::endl;
420 generalized_layer = 10 * thedetId.
subdetId();
425 if (generalized_layer == 31) {
428 if (generalized_layer == 32) {
431 if (generalized_layer == 33) {
434 if (generalized_layer == 51) {
437 if (generalized_layer == 52) {
443 std::ostringstream local_key;
445 local_key <<
"fecCrate" << fedchannelconnection.
fecCrate() <<
"_fecSlot" << fedchannelconnection.
fecSlot()
446 <<
"_fecRing" << fedchannelconnection.
fecRing() <<
"_ccuAddr" << fedchannelconnection.
ccuAddr()
447 <<
"_ccuChan" << fedchannelconnection.
ccuChan() <<
"_apvPair" << extracted_apvpairid;
448 TString control_key = local_key.str();
449 ChargeOfEachAPVPairControlView->Fill(control_key, local_charge_over_path);
450 int ibin1 = ChargeOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
451 ChargeOfEachAPVPairControlView->SetBinError(ibin1, local_error_of_charge);
452 CorrectionOfEachAPVPairControlView->Fill(control_key, local_correction);
453 int ibin2 = CorrectionOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
454 CorrectionOfEachAPVPairControlView->SetBinError(ibin2, local_error_correction);
457 if (fabs(module_thickness - 0.032) < 0.001)
458 ModuleThickness->Fill(1);
459 if (fabs(module_thickness - 0.05) < 0.001)
460 ModuleThickness->Fill(2);
462 double module_width =
moduleWidth(extracted_detid);
463 if (fabs(module_width - 6.144) < 0.01)
464 ModuleWidth->Fill(1);
465 if (fabs(module_width - 7.14) < 0.01)
466 ModuleWidth->Fill(2);
467 if (fabs(module_width - 9.3696) < 0.01)
468 ModuleWidth->Fill(3);
469 if (fabs(module_width - 10.49) < 0.01)
470 ModuleWidth->Fill(4);
471 if (fabs(module_width - 12.03) < 0.01)
472 ModuleWidth->Fill(5);
476 ChargeOfEachAPVPairControlView->LabelsDeflate(
"X");
477 CorrectionOfEachAPVPairControlView->LabelsDeflate(
"X");
489 auto obj = std::make_unique<SiStripApvGain>();
const uint16_t & fecSlot() const
T getParameter(std::string const &) const
TObjArray * HlistAPVPairs
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)
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
unsigned int tibLayer(const DetId &id) const
double moduleThickness(const uint32_t detid)
void algoBeginJob(const edm::EventSetup &) override
TObjArray * HlistOtherHistos
TrackerGeometry const * tkGeom
constexpr uint32_t rawId() const
get the raw id
std::vector< Track > TrackCollection
collection of Tracks
~SiStripGainCosmicCalculator() override
const Bounds & bounds() const
bool outputHistogramsInRootFile
const Plane & surface() const
The nominal surface of the GeomDet.
std::pair< double, double > getPeakOfLandau(TH1F *inputHisto)
virtual float width() const =0
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
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)
Cos< T >::type cos(const T &t)
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
ClusterRef cluster() const
static constexpr auto TOB
SiStripDetCabling const * siStripDetCabling
virtual LocalPoint localPosition() const =0
const uint16_t & ccuAddr() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::unique_ptr< SiStripApvGain > getNewObject() override
static constexpr auto TIB
uint32_t tibGlued(const DetId &id) const
const TrackerTopology * tTopo
T const * product() const
virtual float thickness() const =0
virtual int nstrips() const =0
std::vector< uint32_t > detModulesToBeExcluded
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)
T const * product() const
void algoEndJob() override
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
unsigned int tobLayer(const DetId &id) const