2626#include " DataFormatsGlobalTracking/RecoContainer.h"
2727#include " DataFormatsITSMFT/TrkClusRef.h"
2828#include " DataFormatsITSMFT/ClustersPerLayer.h"
29+ #include " ITSMFTReconstruction/ChipMappingITS.h"
2930#include " DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h"
3031#include " ReconstructionDataFormats/TrackTPCITS.h"
3132#include " ReconstructionDataFormats/GlobalTrackID.h"
@@ -106,6 +107,7 @@ class CheckResidSpec final : public Task
106107 void postProcessHistos ();
107108 void drawHistos ();
108109
110+ o2::itsmft::ChipMappingITS mChipMap ;
109111 o2::globaltracking::RecoContainer* mRecoData = nullptr ;
110112 int mNThreads = 1 ;
111113 bool mMeanVertexUpdated = false ;
@@ -632,6 +634,7 @@ bool CheckResidSpec::refitITStrack(o2::track::TrackParCov& track, GTrackID gid)
632634void CheckResidSpec::fillHistos (const o2::checkresid::Track& trc)
633635{
634636 const auto & params = CheckResidConfig::Instance ();
637+ auto geom = o2::its::GeometryTGeo::Instance ();
635638 int np = trc.points .size ();
636639 auto pt = trc.track .getPt ();
637640 if (pt < params.minPt || pt > params.maxPt ) {
@@ -662,6 +665,21 @@ void CheckResidSpec::fillHistos(const o2::checkresid::Track& trc)
662665 mHMan ->getHisto2F (il * 10 + 1 * 100 + 5 + 2000 )->Fill (pt, pull);
663666 mHMan ->getHisto2F (il * 10 + 1 * 100 + 5 + 3000 )->Fill (trc.track .getTgl (), pull);
664667 }
668+ if (pnt.lr >= 0 && pnt.sens >= 0 && geom->getLayer (pnt.sens ) == pnt.lr ) {
669+ const int halfBarrel = geom->getHalfBarrel (pnt.sens );
670+ const int chip = geom->getFirstChipIndex (pnt.lr ) + geom->getChipIdInLayer (pnt.sens );
671+ const int chipHistoID = (2 * il + halfBarrel) * 100 + 15000 ;
672+ if (halfBarrel >= 0 && halfBarrel < 2 ) {
673+ mHMan ->getHisto2F (chipHistoID)->Fill (chip, pnt.dy );
674+ mHMan ->getHisto2F (chipHistoID + 10 )->Fill (chip, pnt.dz );
675+ if (pnt.sig2y > 0 ) {
676+ mHMan ->getHisto2F (chipHistoID + 5 )->Fill (chip, pnt.dy / std::sqrt (pnt.sig2y ));
677+ }
678+ if (pnt.sig2z > 0 ) {
679+ mHMan ->getHisto2F (chipHistoID + 15 )->Fill (chip, pnt.dz / std::sqrt (pnt.sig2z ));
680+ }
681+ }
682+ }
665683 }
666684 // --------------
667685 if (trc.trIBOut .getX () > 1 && std::abs (trc.trIBOut .getX () - trc.trOBInw .getX ()) < 0.1 ) {
@@ -726,6 +744,18 @@ void CheckResidSpec::bookHistos()
726744 mHMan ->addHisto (htgl2, il * 10 + iyz * 100 + 3000 );
727745 auto htgl2p = new TH2F (fmt::format (" {}_{}_{}_pull" , dname, lrName, " tgl" ).c_str (), fmt::format (" pull {}_{{{}}} vs {};tg#lambda; pull{}" , dtit, lrName, " tg#lambda" , dtit).c_str (), params.nBinsTgl , -params.maxTgl , params.maxTgl , params.nBinsRes , -params.maxPull , params.maxPull );
728746 mHMan ->addHisto (htgl2p, il * 10 + iyz * 100 + 5 + 3000 );
747+
748+ if (il > 0 ) {
749+ const int ilr = il - 1 ;
750+ const int nChips = mChipMap .getNChipsOnLayer (ilr) / 2 ;
751+ for (int ib = 0 ; ib < 2 ; ++ib) { // chips per halfbarrel
752+ const int startChip = ib * nChips + mChipMap .getFirstChipsOnLayer (ilr);
753+ auto h2 = new TH2F (fmt::format (" {}_{}_{}" , dname, lrName, ib).c_str (), fmt::format (" {} Lr{} HB{};chip;{}" , dname, lrName, ib, dtit).c_str (), nChips, startChip - 0.5 , startChip - 0.5 + nChips, params.nBinsRes , -params.maxDYZ [il], params.maxDYZ [il]);
754+ mHMan ->addHisto (h2, (2 * il + ib) * 100 + iyz * 10 + 15000 );
755+ auto h2p = new TH2F (fmt::format (" {}_{}_{}_pull" , dname, lrName, ib).c_str (), fmt::format (" {} Lr{} HB{} pull;chip;pull{}" , dname, lrName, ib, dtit).c_str (), nChips, startChip - 0.5 , startChip - 0.5 + nChips, params.nBinsRes , -params.maxPull , params.maxPull );
756+ mHMan ->addHisto (h2p, (2 * il + ib) * 100 + iyz * 10 + 5 + 15000 );
757+ }
758+ }
729759 }
730760 }
731761
@@ -805,14 +835,23 @@ void CheckResidSpec::postProcessHistos()
805835 }
806836 }
807837 }
808- histm->write ();
838+ for (int il = 1 ; il < 8 ; il++) {
839+ for (int ib = 0 ; ib < 2 ; ib++) {
840+ for (int iyz = 0 ; iyz < 2 ; iyz++) {
841+ for (int iht = 0 ; iht < 2 ; iht++) {
842+ const int offsV = iht == 0 ? 0 : 5 ;
843+ fitSlices ((2 * il + ib) * 100 + iyz * 10 + offsV + 15000 );
844+ }
845+ }
846+ }
847+ }
809848 }
810849 delete gs;
811850}
812851
813852void CheckResidSpec::drawHistos ()
814853{
815- gROOT ->SetBatch (true );
854+ // gROOT->SetBatch(true);
816855 gStyle ->SetTitleX (0.2 );
817856 gStyle ->SetTitleY (0.88 );
818857 gStyle ->SetTitleW (0.25 );
@@ -928,6 +967,8 @@ void CheckResidSpec::drawHistos()
928967 }
929968 TCanvas cly (" cly" , " " , 600 , 800 ), clz (" clz" , " " , 600 , 800 ), clpar (" clpar" , " " , 600 , 800 );
930969 TCanvas czly (" czly" , " " , 600 , 800 ), czlz (" czlz" , " " , 600 , 800 ), czlpar (" czlpar" , " " , 600 , 800 );
970+ TCanvas cchip (" cchip" , " " , 600 , 800 );
971+ constexpr std::array<const char *, 4 > chipTitles{" #DeltaY" , " pull #DeltaY" , " #DeltaZ" , " pull #DeltaZ" };
931972 auto AddLabel = [](const char * txt, float x = 0.1 , float y = 0.9 , int color = kBlack , float size = 0.04 ) {
932973 TLatex* lt = new TLatex (x, y, txt);
933974 lt->SetNDC ();
@@ -1062,6 +1103,94 @@ void CheckResidSpec::drawHistos()
10621103 AddLabel (" IB-OB tracks params differences at R = 12 cm" , 0.2 , 0.8 );
10631104 czlpar.Print (Form (" %s_hman.pdf" , params.outname .c_str ()));
10641105
1106+ auto getHMinMax = [this ](int id, float marginFrac, 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 ();
1145+ for (int il = 1 ; il < 8 ; ++il) {
1146+ for (int ib = 0 ; ib < 2 ; ib++) {
1147+ cchip.Clear ();
1148+ cchip.Divide (1 , 4 );
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 ;
1182+ }
1183+ }
1184+ if (firstAuto) {
1185+ firstAuto->SetMaximum (maxAuto * 1.25 );
1186+ gPad ->SetGrid ();
1187+ gPad ->Modified ();
1188+ }
1189+ }
1190+ cchip.Print (Form (" %s_hman.pdf" , params.outname .c_str ()));
1191+ }
1192+ }
1193+ }
10651194 cly.Print (Form (" %s_hman.pdf]" , params.outname .c_str ()));
10661195}
10671196
@@ -1074,6 +1203,13 @@ void CheckResidSpec::endOfStream(EndOfStreamContext& ec)
10741203 if (mDraw ) {
10751204 drawHistos ();
10761205 }
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+ }
10771213}
10781214
10791215void CheckResidSpec::finaliseCCDB (ConcreteDataMatcher& matcher, void * obj)
0 commit comments