@@ -79,6 +79,15 @@ class CTPPSDiamondDQMSource : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<
7979 void globalEndLuminosityBlock (const edm::LuminosityBlock&, const edm::EventSetup&) override ;
8080
8181private:
82+ // Helper method to transform coordinates to local coordinate system
83+ CTPPSGeometry::Vector transformToLocalCoordinates (const CTPPSDetId& detId_pot,
84+ double x, double y, double z = 0 ) const {
85+ auto localVector = CTPPSGeometry::Vector (x, y, z);
86+ localVector -= diamTranslations_.at (detId_pot);
87+ localVector = diamRotations_.at (detId_pot).Inverse () * localVector;
88+ return localVector;
89+ }
90+
8291 // Constants
8392 // / Number of seconds per lumisection: used to compute hit rates in Hz
8493 static constexpr double SEC_PER_LUMI_SECTION = 23.31 ;
@@ -229,6 +238,9 @@ class CTPPSDiamondDQMSource : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<
229238 double global, withPixels;
230239 };
231240 std::unordered_map<CTPPSDetId, DiamondShifts> diamShifts_;
241+ std::unordered_map<CTPPSDetId, double > diamHalfWidths_;
242+ std::unordered_map<CTPPSDetId, ROOT::Math::Rotation3D> diamRotations_;
243+ std::unordered_map<CTPPSDetId, ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double >>> diamTranslations_;
232244 std::vector<std::pair<edm::EventRange, int >> runParameters_;
233245 int centralOOT_;
234246 unsigned int verbosity_;
@@ -661,6 +673,10 @@ void CTPPSDiamondDQMSource::dqmBeginRun(const edm::Run& iRun, const edm::EventSe
661673 const CTPPSDiamondDetId diam_id (it->first );
662674 const auto diam = geom.sensor (it->first );
663675 diamShifts_[diam_id].global = diam->translation ().x () - diam->getDiamondDimensions ().xHalfWidth ;
676+ diamRotations_[diam_id] = diam->rotation ();
677+ diamTranslations_[diam_id] = diam->translation ();
678+ diamHalfWidths_[diam_id] = diam->getDiamondDimensions ().xHalfWidth ;
679+
664680 if (iRun.run () > FIRST_RUN_W_PIXELS) { // pixel installed
665681 const CTPPSPixelDetId pixid (diam_id.arm (), CTPPS_PIXEL_STATION_ID, CTPPS_PIXEL_FAR_RP_ID);
666682 auto pix = geom.sensor (pixid);
@@ -934,7 +950,6 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
934950 auto lumiCache = luminosityBlockCache (event.getLuminosityBlock ().index ());
935951 for (const auto & rechits : *diamondRecHits) {
936952 const CTPPSDiamondDetId detId (rechits.detId ()), detId_pot (detId.rpId ());
937- const auto & x_shift = diamShifts_.at (detId_pot);
938953
939954 for (const auto & rechit : rechits) {
940955 planes_inclusive[detId_pot].insert (detId.plane ());
@@ -947,6 +962,9 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
947962 continue ;
948963
949964 potPlots_[detId_pot].recHitTime ->Fill (rechit.time ());
965+ // coordinates of the rechit in the local coordinate system are needed for the rotated pot
966+ auto localRecHit = transformToLocalCoordinates (detId_pot, rechit.x (), rechit.y (), rechit.z ());
967+ auto localRecHitLeftX = localRecHit.x () + diamHalfWidths_.at (detId_pot) - 0.5 * rechit.xWidth ();
950968
951969 float UFSDShift = 0.0 ;
952970 if (rechit.yWidth () < 3 )
@@ -955,15 +973,15 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
955973 if (rechit.toT () != 0 && centralOOT_ != -999 && rechit.ootIndex () == centralOOT_) {
956974 TH2F* hitHistoTmp = potPlots_[detId_pot].hitDistribution2d ->getTH2F ();
957975 TAxis* hitHistoTmpYAxis = hitHistoTmp->GetYaxis ();
958- int startBin = hitHistoTmpYAxis->FindBin (rechit. x () - x_shift. global - 0.5 * rechit. xWidth () );
976+ int startBin = hitHistoTmpYAxis->FindBin (localRecHitLeftX );
959977 int numOfBins = rechit.xWidth () * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
960978 for (int i = 0 ; i < numOfBins; ++i)
961979 hitHistoTmp->Fill (detId.plane () + UFSDShift, hitHistoTmpYAxis->GetBinCenter (startBin + i));
962980
963981 if (!perLSsaving_ && plotOnline_) {
964982 hitHistoTmp = lumiCache->hitDistribution2dMap [detId_pot].get ();
965983 hitHistoTmpYAxis = hitHistoTmp->GetYaxis ();
966- startBin = hitHistoTmpYAxis->FindBin (rechit. x () - x_shift. global - 0.5 * rechit. xWidth () );
984+ startBin = hitHistoTmpYAxis->FindBin (localRecHitLeftX );
967985 numOfBins = rechit.xWidth () * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
968986 for (int i = 0 ; i < numOfBins; ++i)
969987 hitHistoTmp->Fill (detId.plane () + UFSDShift, hitHistoTmpYAxis->GetBinCenter (startBin + i));
@@ -977,7 +995,7 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
977995
978996 TH2F* hitHistoOOTTmp = potPlots_[detId_pot].hitDistribution2dOOT ->getTH2F ();
979997 TAxis* hitHistoOOTTmpYAxis = hitHistoOOTTmp->GetYaxis ();
980- int startBin = hitHistoOOTTmpYAxis->FindBin (rechit. x () - x_shift. global - 0.5 * rechit. xWidth () );
998+ int startBin = hitHistoOOTTmpYAxis->FindBin (localRecHitLeftX );
981999 int numOfBins = rechit.xWidth () * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
9821000 for (int i = 0 ; i < numOfBins; ++i)
9831001 hitHistoOOTTmp->Fill (detId.plane () + 1 . / windowsNum_ * rechit.ootIndex (),
@@ -987,7 +1005,7 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
9871005 // Only leading
9881006 TH2F* hitHistoOOTTmp = potPlots_[detId_pot].hitDistribution2dOOT_le ->getTH2F ();
9891007 TAxis* hitHistoOOTTmpYAxis = hitHistoOOTTmp->GetYaxis ();
990- int startBin = hitHistoOOTTmpYAxis->FindBin (rechit. x () - x_shift. global - 0.5 * rechit. xWidth () );
1008+ int startBin = hitHistoOOTTmpYAxis->FindBin (localRecHitLeftX );
9911009 int numOfBins = rechit.xWidth () * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
9921010 for (int i = 0 ; i < numOfBins; ++i)
9931011 hitHistoOOTTmp->Fill (detId.plane () + 1 . / windowsNum_ * rechit.ootIndex (),
@@ -996,9 +1014,6 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
9961014 if (rechit.ootIndex () != CTPPSDiamondRecHit::TIMESLICE_WITHOUT_LEADING &&
9971015 potPlots_[detId_pot].activity_per_bx .count (rechit.ootIndex ()) > 0 )
9981016 potPlots_[detId_pot].activity_per_bx .at (rechit.ootIndex ())->Fill (event.bunchCrossing ());
999-
1000- // if(plotOffline_)
1001- // potPlots_[detId_pot].TOTVsLS->Fill(event.luminosityBlock(),rechit.toT());
10021017 }
10031018 }
10041019
@@ -1012,6 +1027,8 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
10121027 for (const auto & tracks : *diamondLocalTracks) {
10131028 const CTPPSDiamondDetId detId (tracks.detId ()), detId_pot (detId.rpId ());
10141029 const auto & x_shift = diamShifts_.at (detId_pot);
1030+ // extract the rotation angle for the diamond pot
1031+ auto cosRotAngle = diamRotations_.at (detId_pot) * CTPPSGeometry::Vector (1 , 0 , 0 );
10151032
10161033 for (const auto & track : tracks) {
10171034 if (!track.isValid ())
@@ -1032,7 +1049,11 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
10321049
10331050 if (centralOOT_ != -999 && track.ootIndex () == centralOOT_) {
10341051 TH1F* trackHistoInTimeTmp = potPlots_[detId_pot].trackDistribution ->getTH1F ();
1035- int startBin = trackHistoInTimeTmp->FindBin (track.x0 () - x_shift.global - track.x0Sigma ());
1052+
1053+ // X coordinate of the left edge of the track in the local coordinate system
1054+ auto localTrackX = (track.x0 () - diamTranslations_.at (detId_pot).x () + diamHalfWidths_.at (detId_pot) - track.x0Sigma ()) / cosRotAngle.x ();
1055+
1056+ int startBin = trackHistoInTimeTmp->FindBin ((localTrackX));
10361057 int numOfBins = 2 * track.x0Sigma () * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
10371058 for (int i = 0 ; i < numOfBins; ++i)
10381059 trackHistoInTimeTmp->Fill (trackHistoInTimeTmp->GetBinCenter (startBin + i));
@@ -1195,7 +1216,9 @@ void CTPPSDiamondDQMSource::analyze(const edm::Event& event, const edm::EventSet
11951216 if (planePlots_.count (detId_plane) != 0 ) {
11961217 if (centralOOT_ != -999 && rechit.ootIndex () == centralOOT_) {
11971218 TH1F* hitHistoTmp = planePlots_[detId_plane].hitProfile ->getTH1F ();
1198- int startBin = hitHistoTmp->FindBin (rechit.x () - diamShifts_.at (detId_pot).global - 0.5 * rechit.xWidth ());
1219+ // coordinates of the rechit in the local coordinate system are needed for the rotated pot
1220+ auto localRecHit = transformToLocalCoordinates (detId_pot, rechit.x (), rechit.y (), rechit.z ());
1221+ int startBin = hitHistoTmp->FindBin (localRecHit.x () + diamHalfWidths_.at (detId_pot) - 0.5 * rechit.xWidth ());
11991222 int numOfBins = rechit.xWidth () * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
12001223 for (int i = 0 ; i < numOfBins; ++i)
12011224 hitHistoTmp->Fill (hitHistoTmp->GetBinCenter (startBin + i));
0 commit comments