@@ -845,7 +845,6 @@ void CheckResidSpec::postProcessHistos()
845845 }
846846 }
847847 }
848- histm->write ();
849848 }
850849 delete gs;
851850}
@@ -1104,37 +1103,94 @@ void CheckResidSpec::drawHistos()
11041103 AddLabel (" IB-OB tracks params differences at R = 12 cm" , 0.2 , 0.8 );
11051104 czlpar.Print (Form (" %s_hman.pdf" , params.outname .c_str ()));
11061105
1106+ auto getHMinMax = [this ](int id, float marginFrac = 0.2 , float maxDev, int roundToMicrons) -> std::tuple<float , float , float > {
1107+ float maxV = std::numeric_limits<float >::min (), minV = std::numeric_limits<float >::max ();
1108+ const int nh = this ->mHManV .size ();
1109+ for (int j = 0 ; j < nh; j++) {
1110+ if (auto histo = this ->mHManV [j]->getHisto (id); histo != nullptr ) {
1111+ const int nb = histo->GetNbinsX ();
1112+ for (int ib = 1 ; ib <= nb; ib++) {
1113+ float v = histo->GetBinContent (ib);
1114+ maxV = std::max (maxV, v);
1115+ minV = std::min (minV, v);
1116+ }
1117+ }
1118+ }
1119+ if (maxV < minV) {
1120+ return {0 .f , 1 .f , 0 .1f };
1121+ }
1122+ auto delta = maxV - minV;
1123+ maxV += delta * marginFrac;
1124+ minV -= delta * marginFrac;
1125+ if (roundToMicrons > 0 ) {
1126+ maxV = ((int (std::ceil (maxV * 1e4 )) / roundToMicrons + 1 ) * roundToMicrons) * 1e-4 ;
1127+ minV = ((int (std::floor (minV * 1e4 )) / roundToMicrons - 1 ) * roundToMicrons) * 1e-4 ;
1128+ }
1129+ minV = std::max (minV, -maxDev);
1130+ maxV = std::min (maxV, maxDev);
1131+ return {minV, maxV, std::max (std::abs (minV), std::abs (maxV))};
1132+ };
1133+ auto collectSpread = [](TH1 * hin, TH1 * hout) {
1134+ const int nb = hin->GetNbinsX ();
1135+ for (int ib = 1 ; ib <= nb; ib++) {
1136+ if (hin->GetBinError (ib) != 0 ) {
1137+ hout->Fill (hin->GetBinContent (ib));
1138+ }
1139+ }
1140+ hout->SetLineColor (hin->GetLineColor ());
1141+ hout->SetMarkerColor (hin->GetMarkerColor ());
1142+ hout->SetMarkerStyle (hin->GetMarkerStyle ());
1143+ };
1144+ int nh = this ->mHManV .size ();
11071145 for (int il = 1 ; il < 8 ; ++il) {
11081146 for (int ib = 0 ; ib < 2 ; ib++) {
11091147 cchip.Clear ();
11101148 cchip.Divide (1 , 4 );
1111- for (int iv = 0 ; iv < 4 ; ++iv) {
1112- cchip.cd (iv + 1 );
1113- const int iyz = iv / 2 ;
1114- const float yRange = iyz == 0 ? params.resMMLrY [il] : params.resMMLrZ [il];
1115- int nh = this ->mHManV .size ();
1116- bool drawn = false ;
1117- for (int j = 0 ; j < nh; j++) {
1118- auto hman = this ->mHManV [j].get ();
1119- const int id = 15000 + iyz * 10 + (2 * il + ib) * 100 + 1 + (iv % 2 );
1120- auto histo = hman->getHisto (id);
1121- if (histo) {
1122- histo->SetMaximum (yRange);
1123- histo->SetMinimum ((iv % 2 ) ? 0 : -yRange);
1124- if (il > 3 ) {
1125- histo->SetMarkerSize (0.3 );
1126- histo->SetLineStyle (3 );
1149+ for (int iyz = 0 ; iyz < 2 ; iyz++) {
1150+ for (int iv = 0 ; iv < 2 ; iv++) { // mean or sigma
1151+ const float yRange = iyz == 0 ? params.resMMLrY [il] : params.resMMLrZ [il];
1152+ bool drawn = false ;
1153+ const int id = 15000 + iyz * 10 + (2 * il + ib) * 100 + 1 + iv;
1154+ auto [minV, maxV, absMax] = getHMinMax (id, 0.15 , (iv == 0 ? 2 : 4 ) * yRange, 10 );
1155+ TH1 * firstAuto = nullptr ;
1156+ float maxAuto = 0 .f ;
1157+ for (int j = 0 ; j < nh; j++) {
1158+ auto hman = this ->mHManV [j].get ();
1159+ auto histo = hman->getHisto (id);
1160+ if (histo) {
1161+ histo->SetMaximum (absMax);
1162+ histo->SetMinimum (iv ? 0 : -absMax);
1163+ if (il > 3 ) {
1164+ histo->SetMarkerSize (0.3 );
1165+ histo->SetLineStyle (3 );
1166+ }
1167+ cchip.cd (2 * iv + 1 );
1168+ histo->Draw (drawn ? " same" : " " );
1169+ if (!drawn) {
1170+ gPad ->SetGrid ();
1171+ }
1172+ auto hmeans = new TH1F (Form (" %s_spread" , histo->GetName ()), Form (" %s spread" , histo->GetTitle ()), params.nBinsRes , iv == 0 ? minV : std::max (0 .f , minV), maxV);
1173+ collectSpread (histo, hmeans);
1174+ hman->addHisto (hmeans, id + 2 );
1175+ cchip.cd (2 * iv + 2 );
1176+ if (!drawn) {
1177+ firstAuto = hmeans;
1178+ }
1179+ maxAuto = std::max (maxAuto, (float )hmeans->GetMaximum ());
1180+ hmeans->Draw (drawn ? " same" : " " );
1181+ drawn = true ;
11271182 }
1128- histo->Draw (drawn ? " same" : " " );
1129- drawn = true ;
1183+ }
1184+ if (firstAuto) {
1185+ firstAuto->SetMaximum (maxAuto * 1.25 );
1186+ gPad ->SetGrid ();
1187+ gPad ->Modified ();
11301188 }
11311189 }
1132- gPad -> SetGrid ( );
1190+ cchip. Print ( Form ( " %s_hman.pdf " , params. outname . c_str ()) );
11331191 }
1134- cchip.Print (Form (" %s_hman.pdf" , params.outname .c_str ()));
11351192 }
11361193 }
1137-
11381194 cly.Print (Form (" %s_hman.pdf]" , params.outname .c_str ()));
11391195}
11401196
@@ -1147,6 +1203,13 @@ void CheckResidSpec::endOfStream(EndOfStreamContext& ec)
11471203 if (mDraw ) {
11481204 drawHistos ();
11491205 }
1206+ if (auto nh = mHManV .size (); nh > 0 ) {
1207+ for (int ihm = 0 ; ihm < nh; ihm++) {
1208+ if (mHManV [ihm]) {
1209+ mHManV [ihm].get ()->write ();
1210+ }
1211+ }
1212+ }
11501213}
11511214
11521215void CheckResidSpec::finaliseCCDB (ConcreteDataMatcher& matcher, void * obj)
0 commit comments