37 #include "TGraphErrors.h" 44 #include "TPaveStats.h" 55 SiStripNoisesTest() :
cond::payloadInspector::Histogram1D<
SiStripNoises>(
"SiStrip Noise test",
56 "SiStrip Noise test", 10,0.0,10.0),
62 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
63 for (
auto const & iov: iovs) {
70 ss <<
"Summary of strips noises:" << std::endl;
73 payload->printSummary(ss,&m_trackerTopo);
75 std::vector<uint32_t> detid;
76 payload->getDetIds(detid);
106 SiStripNoiseValue() :
cond::payloadInspector::Histogram1D<
SiStripNoises>(
"SiStrip Noise values",
107 "SiStrip Noise values", 100,0.0,10.0){
108 Base::setSingleIov(
true );
111 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
112 for (
auto const & iov: iovs) {
113 std::shared_ptr<SiStripNoises> payload = Base::fetchPayload( std::get<1>(iov) );
116 std::vector<uint32_t> detid;
117 payload->getDetIds(detid);
119 for (
const auto &
d : detid) {
121 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
122 auto noise = payload->getNoise(it,range);
124 fillWithValue(noise);
141 SiStripNoiseValueComparison() :
cond::payloadInspector::PlotImage<
SiStripNoises>(
"SiStrip Noise values comparison"){
142 setSingleIov(
false );
145 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
147 std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
150 std::sort(
begin(sorted_iovs),
end(sorted_iovs), [](
auto const &t1,
auto const &
t2) {
151 return std::get<0>(t1) < std::get<0>(
t2);
154 auto firstiov = sorted_iovs.front();
155 auto lastiov = sorted_iovs.back();
157 std::shared_ptr<SiStripNoises> f_payload = fetchPayload( std::get<1>(firstiov) );
158 std::shared_ptr<SiStripNoises> l_payload = fetchPayload( std::get<1>(lastiov) );
160 auto h_first = std::unique_ptr<TH1F>(
new TH1F(
"f_Noise",Form(
"Strip noise values comparison [%s,%s];Strip Noise [ADC counts];n. strips",std::to_string(std::get<0>(firstiov)).c_str(),std::to_string(std::get<0>(lastiov)).c_str()),100,0.1,10.));
161 h_first->SetStats(
false);
163 auto h_last = std::unique_ptr<TH1F>(
new TH1F(
"l_Noise",Form(
"Strip noise values comparison [%s,%s];Strip Noise [ADC counts];n. strips",std::to_string(std::get<0>(firstiov)).c_str(),std::to_string(std::get<0>(lastiov)).c_str()),100,0.1,10.));
164 h_last->SetStats(
false);
166 std::vector<uint32_t> f_detid;
167 f_payload->getDetIds(f_detid);
170 for (
const auto &
d : f_detid) {
172 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
173 float noise = f_payload->getNoise(it,range);
175 h_first->Fill(noise);
179 std::vector<uint32_t> l_detid;
180 l_payload->getDetIds(l_detid);
183 for (
const auto &
d : l_detid) {
185 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
186 float noise = l_payload->getNoise(it,range);
193 h_first->GetYaxis()->CenterTitle(
true);
194 h_last->GetYaxis()->CenterTitle(
true);
196 h_first->GetXaxis()->CenterTitle(
true);
197 h_last->GetXaxis()->CenterTitle(
true);
199 h_first->SetLineWidth(2);
200 h_last->SetLineWidth(2);
202 h_first->SetLineColor(kBlack);
203 h_last->SetLineColor(kBlue);
206 TCanvas
canvas(
"Partion summary",
"partition summary",1200,1000);
208 canvas.SetBottomMargin(0.11);
209 canvas.SetLeftMargin(0.13);
210 canvas.SetRightMargin(0.05);
213 float theMax = (h_first->GetMaximum() > h_last->GetMaximum()) ? h_first->GetMaximum() : h_last->GetMaximum();
215 h_first->SetMaximum(theMax*1.30);
216 h_last->SetMaximum(theMax*1.30);
219 h_last->Draw(
"same");
221 TLegend
legend = TLegend(0.52,0.82,0.95,0.9);
222 legend.SetHeader(
"SiStrip Noise comparison",
"C");
223 legend.AddEntry(h_first.get(),(
"IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),
"F");
224 legend.AddEntry(h_last.get(), (
"IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),
"F");
225 legend.SetTextSize(0.025);
245 setSingleIov(
true );
248 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
249 auto iov = iovs.front();
250 std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
254 std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(
new TrackerMap(
"SiStripNoises"));
255 tmap->setTitle(titleMap);
259 std::map<unsigned int,float> info_per_detid;
263 std::vector<float> vstripnoise;
265 for(;rit!=erit;++rit){
266 Nstrips = (rit->iend-rit->ibegin)*8/9;
267 vstripnoise.resize(Nstrips);
268 payload->allNoises(vstripnoise,make_pair(payload->getDataVectorBegin()+rit->ibegin,payload->getDataVectorBegin()+rit->iend));
269 mean=0; rms=0; min=10000; max=0;
271 DetId detId(rit->detid);
273 for(
size_t i=0;
i<Nstrips;++
i){
274 mean+=vstripnoise[
i];
275 rms+=vstripnoise[
i]*vstripnoise[
i];
276 if(vstripnoise[
i]<min) min=vstripnoise[
i];
277 if(vstripnoise[
i]>max) max=vstripnoise[
i];
281 if((rms/Nstrips-mean*mean)>0.){
282 rms =
sqrt(rms/Nstrips-mean*mean);
289 info_per_detid[rit->detid]=
min;
292 info_per_detid[rit->detid]=
max;
295 info_per_detid[rit->detid]=
mean;
298 info_per_detid[rit->detid]=
rms;
307 for (
const auto &item : info_per_detid){
308 tmap->fill(item.first,item.second);
317 tmap->save(
true,0.,range.second,
fileName);
319 tmap->save(
true,range.first,range.second,
fileName);
326 typedef SiStripNoiseTrackerMap<SiStripPI::min> SiStripNoiseMin_TrackerMap;
327 typedef SiStripNoiseTrackerMap<SiStripPI::max> SiStripNoiseMax_TrackerMap;
328 typedef SiStripNoiseTrackerMap<SiStripPI::mean> SiStripNoiseMean_TrackerMap;
329 typedef SiStripNoiseTrackerMap<SiStripPI::rms> SiStripNoiseRMS_TrackerMap;
340 setSingleIov(
true );
343 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
344 auto iov = iovs.front();
345 std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
351 std::map<unsigned int, SiStripDetSummary::Values>
map = summaryNoise.getCounts();
354 TCanvas
canvas(
"Partion summary",
"partition summary",1200,1000);
356 auto h1 = std::unique_ptr<TH1F>(
new TH1F(
"byRegion",Form(
"Average by partition of %s SiStrip Noise per module;;average SiStrip Noise %s [ADC counts]",
estimatorType(est).c_str(),
estimatorType(est).c_str()),map.size(),0.,map.size()));
358 canvas.SetBottomMargin(0.18);
359 canvas.SetLeftMargin(0.17);
360 canvas.SetRightMargin(0.05);
363 std::vector<int> boundaries;
369 for (
const auto &element : map){
371 int count = element.second.count;
372 double mean = (element.second.mean)/count;
373 double rms = (element.second.rms)/count - mean*mean;
380 if(currentDetector.empty()) currentDetector=
"TIB";
382 switch ((element.first)/1000)
398 h1->SetBinContent(iBin,mean);
400 h1->GetXaxis()->LabelsOption(
"v");
402 if(detector!=currentDetector) {
403 boundaries.push_back(iBin);
408 h1->SetMarkerStyle(20);
409 h1->SetMarkerSize(1);
410 h1->SetMaximum(h1->GetMaximum()*1.1);
416 TLine
l[boundaries.size()];
418 for (
const auto &
line : boundaries){
420 l[
i].SetLineWidth(1);
421 l[
i].SetLineStyle(9);
422 l[
i].SetLineColor(2);
427 TLegend legend = TLegend(0.52,0.82,0.95,0.9);
428 legend.SetHeader((std::get<1>(iov)).c_str(),
"C");
429 legend.AddEntry(h1.get(),(
"IOV: "+std::to_string(std::get<0>(iov))).c_str(),
"PL");
430 legend.SetTextSize(0.025);
442 typedef SiStripNoiseByRegion<SiStripPI::mean> SiStripNoiseMeanByRegion;
443 typedef SiStripNoiseByRegion<SiStripPI::min> SiStripNoiseMinByRegion;
444 typedef SiStripNoiseByRegion<SiStripPI::max> SiStripNoiseMaxByRegion;
445 typedef SiStripNoiseByRegion<SiStripPI::rms> SiStripNoiseRMSByRegion;
453 SiStripNoiseComparatorByRegion() :
cond::payloadInspector::PlotImage<
SiStripNoises>(
"SiStrip Noise "+
estimatorType(est)+
" comparator by Region" ),
456 setSingleIov(
false );
459 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
461 std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
464 std::sort(
begin(sorted_iovs),
end(sorted_iovs), [](
auto const &t1,
auto const &
t2) {
465 return std::get<0>(t1) < std::get<0>(
t2);
468 auto firstiov = sorted_iovs.front();
469 auto lastiov = sorted_iovs.back();
471 std::shared_ptr<SiStripNoises> f_payload = fetchPayload( std::get<1>(firstiov) );
472 std::shared_ptr<SiStripNoises> l_payload = fetchPayload( std::get<1>(lastiov) );
480 std::map<unsigned int, SiStripDetSummary::Values> f_map = f_summaryNoise.getCounts();
481 std::map<unsigned int, SiStripDetSummary::Values> l_map = l_summaryNoise.getCounts();
484 TCanvas
canvas(
"Partion summary",
"partition summary",1200,1000);
487 auto hfirst = std::unique_ptr<TH1F>(
new TH1F(
"f_byRegion",Form(
"Average by partition of %s SiStrip Noise per module;;average SiStrip Noise %s [ADC counts]",
estimatorType(est).c_str(),
estimatorType(est).c_str()),f_map.size(),0.,f_map.size()));
488 hfirst->SetStats(
false);
490 auto hlast = std::unique_ptr<TH1F>(
new TH1F(
"l_byRegion",Form(
"Average by partition of %s SiStrip Noise per module;;average SiStrip Noise %s [ADC counts]",
estimatorType(est).c_str(),
estimatorType(est).c_str()),l_map.size(),0.,l_map.size()));
491 hlast->SetStats(
false);
493 canvas.SetBottomMargin(0.18);
494 canvas.SetLeftMargin(0.17);
495 canvas.SetRightMargin(0.05);
498 std::vector<int> boundaries;
504 for (
const auto &element : f_map){
506 int count = element.second.count;
507 double mean = (element.second.mean)/count;
508 double rms = (element.second.rms)/count - mean*mean;
515 if(currentDetector.empty()) currentDetector=
"TIB";
517 switch ((element.first)/1000)
533 hfirst->SetBinContent(iBin,mean);
536 hfirst->GetXaxis()->LabelsOption(
"v");
538 if(detector!=currentDetector) {
539 boundaries.push_back(iBin);
547 for (
const auto &element : l_map){
549 int count = element.second.count;
550 double mean = (element.second.mean)/count;
551 double rms = (element.second.rms)/count - mean*mean;
558 hlast->SetBinContent(iBin,mean);
561 hlast->GetXaxis()->LabelsOption(
"v");
564 float theMax = (hfirst->GetMaximum() > hlast->GetMaximum()) ? hfirst->GetMaximum() : hlast->GetMaximum();
565 float theMin = (hfirst->GetMinimum() < hlast->GetMinimum()) ? hfirst->GetMinimum() : hlast->GetMinimum();
567 hfirst->SetMarkerStyle(20);
568 hfirst->SetMarkerSize(1);
569 hfirst->GetYaxis()->SetTitleOffset(1.3);
570 hfirst->GetYaxis()->SetRangeUser(theMin*0.9,theMax*1.1);
571 hfirst->Draw(
"HIST");
572 hfirst->Draw(
"Psame");
574 hlast->SetMarkerStyle(21);
575 hlast->SetMarkerSize(1);
576 hlast->SetMarkerColor(kBlue);
577 hlast->SetLineColor(kBlue);
578 hlast->GetYaxis()->SetTitleOffset(1.3);
579 hlast->GetYaxis()->SetRangeUser(theMin*0.9,theMax*1.1);
580 hlast->Draw(
"HISTsame");
581 hlast->Draw(
"Psame");
585 TLine l[boundaries.size()];
587 for (
const auto &
line : boundaries){
588 l[
i] = TLine(hfirst->GetBinLowEdge(
line),
canvas.GetUymin(),hfirst->GetBinLowEdge(
line),
canvas.GetUymax());
589 l[
i].SetLineWidth(1);
590 l[
i].SetLineStyle(9);
591 l[
i].SetLineColor(2);
596 TLegend legend = TLegend(0.52,0.82,0.95,0.9);
597 legend.SetHeader((
"SiStrip Noise "+
estimatorType(est)+
" by region").c_str(),
"C");
598 legend.AddEntry(hfirst.get(),(
"IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),
"PL");
599 legend.AddEntry(hlast.get(), (
"IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),
"PL");
600 legend.SetTextSize(0.025);
612 typedef SiStripNoiseComparatorByRegion<SiStripPI::mean> SiStripNoiseComparatorMeanByRegion;
613 typedef SiStripNoiseComparatorByRegion<SiStripPI::min> SiStripNoiseComparatorMinByRegion;
614 typedef SiStripNoiseComparatorByRegion<SiStripPI::max> SiStripNoiseComparatorMaxByRegion;
615 typedef SiStripNoiseComparatorByRegion<SiStripPI::rms> SiStripNoiseComparatorRMSByRegion;
622 SiStripNoiseLinearity() :
cond::payloadInspector::PlotImage<
SiStripNoises>(
"Linearity of Strip Noise as a fuction of strip length" ){
623 setSingleIov(
true );
626 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override{
627 auto iov = iovs.front();
628 std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
633 std::vector<uint32_t> detid;
634 payload->getDetIds(detid);
636 std::map<float,std::tuple<int,float,float> > noisePerStripLength;
638 for (
const auto &
d : detid) {
640 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
641 auto noise = payload->getNoise(it,range);
644 std::get<0>(noisePerStripLength[stripL])+=1;
645 std::get<1>(noisePerStripLength[stripL])+=noise;
646 std::get<2>(noisePerStripLength[stripL])+=(noise*noise);
650 TCanvas
canvas(
"Noise linearity",
"noise linearity",1200,1000);
653 std::vector<float>
x; x.reserve(noisePerStripLength.size());
654 std::vector<float>
y; y.reserve(noisePerStripLength.size());
655 std::vector<float> ex; ex.reserve(noisePerStripLength.size());
656 std::vector<float> ey; ey.reserve(noisePerStripLength.size());
658 for (
const auto &element : noisePerStripLength ){
659 x.push_back(element.first);
661 float sum = std::get<1>(element.second);
662 float sum2 = std::get<2>(element.second);
663 float nstrips = std::get<0>(element.second);
664 float mean = sum/nstrips;
665 float rms = (sum2/nstrips-mean*
mean)>0. ?
sqrt(sum2/nstrips-mean*mean) : 0.;
671 auto graph = std::unique_ptr<TGraphErrors>(
new TGraphErrors(noisePerStripLength.size(),&x[0], &y[0],&ex[0],&ey[0]));
672 graph->SetTitle(
"SiStrip Noise Linearity");
673 graph->GetXaxis()->SetTitle(
"Strip length [cm]");
674 graph->GetYaxis()->SetTitle(
"Average Strip Noise [ADC counts]");
675 graph->SetMarkerColor(kBlue);
676 graph->SetMarkerStyle(20);
677 graph->SetMarkerSize(1.5);
678 canvas.SetBottomMargin(0.13);
679 canvas.SetLeftMargin(0.17);
680 canvas.SetTopMargin(0.08);
681 canvas.SetRightMargin(0.05);
685 graph->GetXaxis()->CenterTitle(
true);
686 graph->GetYaxis()->CenterTitle(
true);
687 graph->GetXaxis()->SetTitleFont(42);
688 graph->GetYaxis()->SetTitleFont(42);
689 graph->GetXaxis()->SetTitleSize(0.05);
690 graph->GetYaxis()->SetTitleSize(0.05);
691 graph->GetXaxis()->SetTitleOffset(1.1);
692 graph->GetYaxis()->SetTitleOffset(1.3);
693 graph->GetXaxis()->SetLabelFont(42);
694 graph->GetYaxis()->SetLabelFont(42);
695 graph->GetYaxis()->SetLabelSize(.05);
696 graph->GetXaxis()->SetLabelSize(.05);
701 TF1 *
f1 = graph->GetFunction(
"pol1");
703 f1->SetLineColor(kBlue);
706 auto fits = std::unique_ptr<TPaveText>(
new TPaveText(0.2,0.72,0.6,0.9,
"NDC"));
708 sprintf(buffer,
"fit function: p_{0} + p_{1} * l_{strip}");
709 fits->AddText(buffer);
710 sprintf(buffer,
"p_{0} : %5.2f [ADC counts]",f1->GetParameter(0));
711 fits->AddText(buffer);
712 sprintf(buffer,
"p_{1} : %5.2f [ADC counts/cm]",f1->GetParameter(1));
713 fits->AddText(buffer);
714 sprintf(buffer,
"#chi^{2}/ndf = %5.2f / %i ",f1->GetChisquare(),f1->GetNDF());
715 fits->AddText(buffer);
716 fits->SetTextFont(42);
717 fits->SetTextColor(kBlue);
718 fits->SetFillColor(0);
719 fits->SetTextSize(0.03);
720 fits->SetBorderSize(1);
721 fits->SetLineColor(kBlue);
722 fits->SetMargin(0.05);
723 fits->SetTextAlign(12);
745 std::pair<double,double> getFromPayload(
SiStripNoises& payload )
override{
747 std::vector<uint32_t> detid;
751 float sum=0., sum2=0.;
752 for (
const auto &
d : detid) {
754 if(subid!=sub)
continue;
756 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
758 auto noise = payload.
getNoise(it,range);
764 float mean = sum/nStrips;
765 float rms = (sum2/nStrips-mean*
mean)>0. ?
sqrt(sum2/nStrips-mean*mean) : 0.;
767 return std::make_pair(mean,rms);
772 typedef NoiseHistory<StripSubdetector::TIB> TIBNoiseHistory;
773 typedef NoiseHistory<StripSubdetector::TOB> TOBNoiseHistory;
774 typedef NoiseHistory<StripSubdetector::TID> TIDNoiseHistory;
775 typedef NoiseHistory<StripSubdetector::TEC> TECNoiseHistory;
787 std::pair<double,double> getFromPayload(
SiStripNoises& payload )
override{
789 std::vector<uint32_t> detid;
793 float sum=0., sum2=0.;
794 for (
const auto &
d : detid) {
796 if(subid!=sub)
continue;
798 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
800 auto noise = payload.
getNoise(it,range);
806 float mean = sum/nStrips;
807 float rms = (sum2/nStrips-mean*
mean)>0. ?
sqrt(sum2/nStrips-mean*mean) : 0.;
809 return std::make_pair(mean,rms);
814 typedef NoiseRunHistory<StripSubdetector::TIB> TIBNoiseRunHistory;
815 typedef NoiseRunHistory<StripSubdetector::TOB> TOBNoiseRunHistory;
816 typedef NoiseRunHistory<StripSubdetector::TID> TIDNoiseRunHistory;
817 typedef NoiseRunHistory<StripSubdetector::TEC> TECNoiseRunHistory;
828 std::pair<double,double> getFromPayload(
SiStripNoises& payload )
override{
830 std::vector<uint32_t> detid;
834 float sum=0., sum2=0.;
835 for (
const auto &
d : detid) {
837 if(subid!=sub)
continue;
839 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
841 auto noise = payload.
getNoise(it,range);
847 float mean = sum/nStrips;
848 float rms = (sum2/nStrips-mean*
mean)>0. ?
sqrt(sum2/nStrips-mean*mean) : 0.;
850 return std::make_pair(mean,rms);
855 typedef NoiseTimeHistory<StripSubdetector::TIB> TIBNoiseTimeHistory;
856 typedef NoiseTimeHistory<StripSubdetector::TOB> TOBNoiseTimeHistory;
857 typedef NoiseTimeHistory<StripSubdetector::TID> TIDNoiseTimeHistory;
858 typedef NoiseTimeHistory<StripSubdetector::TEC> TECNoiseTimeHistory;
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
void fillNoiseDetSummary(SiStripDetSummary &summaryNoise, std::shared_ptr< SiStripNoises > payload, SiStripPI::estimator est)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
static float getNoise(uint16_t strip, const Range &range)
std::pair< float, float > getTheRange(std::map< uint32_t, float > values, const float nsigma)
auto const T2 &decltype(t1.eta()) t2
Registry::const_iterator RegistryIterator
std::string getStringFromSubdet(StripSubdetector::SubDetector sub)
void fillWithValue(float value, float weight=1)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::string estimatorType(SiStripPI::estimator e)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::pair< int, const char * > regionType(int index)
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
void setSingleIov(bool flag)
const Range getRange(const uint32_t detID) const
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
std::string fullPath() const
std::pair< ContainerIterator, ContainerIterator > Range