CMS 3D CMS Logo

CTPPSTrackDistributionPlotter.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of CTPPS validation software
4  * Authors:
5  * Jan Kašpar
6  * Laurent Forthomme
7  *
8  ****************************************************************************/
9 
12 
15 
17 
21 
22 #include "TFile.h"
23 #include "TH2D.h"
24 #include "TProfile.h"
25 #include "TProfile2D.h"
26 #include "TGraph.h"
27 
28 #include <map>
29 #include <memory>
30 
31 //----------------------------------------------------------------------------------------------------
32 
34 public:
36 
37  ~CTPPSTrackDistributionPlotter() override {}
38 
39 private:
40  void analyze(const edm::Event&, const edm::EventSetup&) override;
41  void endJob() override;
42 
44 
45  double x_pitch_pixels_;
46 
48 
49  unsigned int events_total_;
50  std::map<unsigned int, unsigned int> events_per_arm_;
51 
52  struct RPPlots {
53  bool initialized;
54 
55  std::unique_ptr<TH2D> h2_y_vs_x;
56  std::unique_ptr<TProfile> p_y_vs_x;
57  std::unique_ptr<TH1D> h_x;
58  std::unique_ptr<TH1D> h_y;
59  std::unique_ptr<TH1D> h_time;
60 
62 
63  void init(bool pixel, double pitch) {
64  const double bin_size_x = (pixel) ? pitch * cos(18.4 / 180. * M_PI) : 100E-3;
65 
66  h2_y_vs_x = std::make_unique<TH2D>("", "", 300, -10., +70., 600, -30., +30.);
67  p_y_vs_x = std::make_unique<TProfile>("", "", 300, -10., +70.);
68 
69  int n_mi = ceil(10. / bin_size_x);
70  int n_pl = ceil(70. / bin_size_x);
71 
72  h_x = std::make_unique<TH1D>("", "", n_mi + n_pl, -n_mi * bin_size_x, +n_pl * bin_size_x);
73 
74  h_y = std::make_unique<TH1D>("", "", 300, -15., +15.);
75 
76  h_time = std::make_unique<TH1D>("", ";time", 500, -50., +50.);
77 
78  initialized = true;
79  }
80 
81  void fill(double x, double y, double time) {
82  h2_y_vs_x->Fill(x, y);
83  p_y_vs_x->Fill(x, y);
84  h_x->Fill(x);
85  h_y->Fill(y);
86  h_time->Fill(time);
87  }
88 
89  void write() const {
90  h2_y_vs_x->Write("h2_y_vs_x");
91  p_y_vs_x->Write("p_y_vs_x");
92  h_x->Write("h_x");
93  h_y->Write("h_y");
94  h_time->Write("h_time");
95  }
96  };
97 
98  std::map<unsigned int, RPPlots> rpPlots;
99 
100  struct ArmPlots {
101  unsigned int rpId_N, rpId_F;
102 
103  std::unique_ptr<TH1D> h_de_x, h_de_y;
104  std::unique_ptr<TProfile> p_de_x_vs_x, p_de_y_vs_x;
105  std::unique_ptr<TProfile2D> p2_de_x_vs_x_y, p2_de_y_vs_x_y;
106  std::unique_ptr<TH2D> h2_de_x_vs_x, h2_de_y_vs_x;
107  std::unique_ptr<TH2D> h2_de_y_vs_de_x;
108 
109  struct Stat {
110  unsigned int sN = 0, s1 = 0;
111  };
112 
113  std::map<unsigned int, std::map<unsigned int, Stat>> m_stat;
114 
116  : h_de_x(new TH1D("", ";x^{F} - x^{N}", 100, -1., +1.)),
117  h_de_y(new TH1D("", ";y^{F} - y^{N}", 100, -1., +1.)),
118  p_de_x_vs_x(new TProfile("", ";x^{N};x^{F} - x^{N}", 40, 0., 40.)),
119  p_de_y_vs_x(new TProfile("", ";x^{N};y^{F} - y^{N}", 40, 0., 40.)),
120  p2_de_x_vs_x_y(new TProfile2D("", ";x;y", 40, 0., 40., 40, -20., +20.)),
121  p2_de_y_vs_x_y(new TProfile2D("", ";x;y", 40, 0., 40., 40, -20., +20.)),
122  h2_de_x_vs_x(new TH2D("", ";x^{N};x^{F} - x^{N}", 80, 0., 40., 100, -1., +1.)),
123  h2_de_y_vs_x(new TH2D("", ";x^{N};y^{F} - y^{N}", 80, 0., 40., 100, -1., +1.)),
124  h2_de_y_vs_de_x(new TH2D("", ";x^{F} - x^{N};y^{F} - y^{N}", 100, -1., +1., 100, -1., +1.)) {}
125 
126  void fill(double x_N, double y_N, double x_F, double y_F) {
127  h_de_x->Fill(x_F - x_N);
128  h_de_y->Fill(y_F - y_N);
129 
130  p_de_x_vs_x->Fill(x_N, x_F - x_N);
131  p_de_y_vs_x->Fill(x_N, y_F - y_N);
132 
133  p2_de_x_vs_x_y->Fill(x_N, y_N, x_F - x_N);
134  p2_de_y_vs_x_y->Fill(x_N, y_N, y_F - y_N);
135 
136  h2_de_x_vs_x->Fill(x_N, x_F - x_N);
137  h2_de_y_vs_x->Fill(x_N, y_F - y_N);
138 
139  h2_de_y_vs_de_x->Fill(x_F - x_N, y_F - y_N);
140  }
141 
142  void write() const {
143  h_de_x->Write("h_de_x");
144  h_de_y->Write("h_de_y");
145 
146  p_de_x_vs_x->Write("p_de_x_vs_x");
147  p_de_y_vs_x->Write("p_de_y_vs_x");
148 
149  p2_de_x_vs_x_y->Write("p2_de_x_vs_x_y");
150  p2_de_y_vs_x_y->Write("p2_de_y_vs_x_y");
151 
152  h2_de_x_vs_x->Write("h2_de_x_vs_x");
153  h2_de_y_vs_x->Write("h2_de_y_vs_x");
154 
155  h2_de_y_vs_de_x->Write("h2_de_y_vs_de_x");
156 
157  for (const auto& rp : m_stat) {
158  TGraph* g = new TGraph();
159 
160  char buf[100];
161  sprintf(buf, "g_mean_track_mult_run_%u", rp.first);
162  g->SetName(buf);
163 
164  for (const auto& lsp : rp.second) {
165  const int idx = g->GetN();
166  const double m = (lsp.second.s1 > 0) ? double(lsp.second.sN) / lsp.second.s1 : 0.;
167  g->SetPoint(idx, lsp.first, m);
168  }
169 
170  g->Write();
171  }
172  }
173  };
174 
175  std::map<unsigned int, ArmPlots> armPlots;
176 };
177 
178 //----------------------------------------------------------------------------------------------------
179 
181  : tracksToken_(consumes<CTPPSLocalTrackLiteCollection>(iConfig.getParameter<edm::InputTag>("tagTracks"))),
182  x_pitch_pixels_(iConfig.getUntrackedParameter<double>("x_pitch_pixels", 150E-3)),
183  outputFile_(iConfig.getParameter<std::string>("outputFile")),
184  events_total_(0) {
185  armPlots[0].rpId_N = iConfig.getParameter<unsigned int>("rpId_45_N");
186  armPlots[0].rpId_F = iConfig.getParameter<unsigned int>("rpId_45_F");
187 
188  armPlots[1].rpId_N = iConfig.getParameter<unsigned int>("rpId_56_N");
189  armPlots[1].rpId_F = iConfig.getParameter<unsigned int>("rpId_56_F");
190 }
191 
192 //----------------------------------------------------------------------------------------------------
193 
195  // get input
197  iEvent.getByToken(tracksToken_, tracks);
198 
199  // process tracks
200  std::map<unsigned int, unsigned int> m_mult;
201 
202  for (const auto& trk : *tracks) {
203  CTPPSDetId rpId(trk.rpId());
204  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
205  bool rpPixel = (rpId.subdetId() == CTPPSDetId::sdTrackingPixel);
206 
207  auto& pl = rpPlots[rpDecId];
208  if (!pl.initialized)
209  pl.init(rpPixel, x_pitch_pixels_);
210 
211  pl.fill(trk.x(), trk.y(), trk.time());
212 
213  m_mult[rpId.arm()]++;
214  }
215 
216  for (unsigned int arm = 0; arm < 2; ++arm) {
217  auto& st = armPlots[arm].m_stat[iEvent.id().run()][iEvent.id().luminosityBlock()];
218  st.s1++;
219  st.sN += m_mult[arm];
220  }
221 
222  for (const auto& t1 : *tracks) {
223  const CTPPSDetId rpId1(t1.rpId());
224 
225  for (const auto& t2 : *tracks) {
226  const CTPPSDetId rpId2(t2.rpId());
227 
228  if (rpId1.arm() != rpId2.arm())
229  continue;
230 
231  auto& ap = armPlots[rpId1.arm()];
232 
233  const unsigned int rpDecId1 = rpId1.arm() * 100 + rpId1.station() * 10 + rpId1.rp();
234  const unsigned int rpDecId2 = rpId2.arm() * 100 + rpId2.station() * 10 + rpId2.rp();
235 
236  if (rpDecId1 == ap.rpId_N && rpDecId2 == ap.rpId_F)
237  ap.fill(t1.x(), t1.y(), t2.x(), t2.y());
238  }
239  }
240 
241  // update counters
242  events_total_++;
243 
244  if (m_mult[0] > 0)
245  events_per_arm_[0]++;
246  if (m_mult[1] > 0)
247  events_per_arm_[1]++;
248 }
249 
250 //----------------------------------------------------------------------------------------------------
251 
253  edm::LogInfo("CTPPSTrackDistributionPlotter")
254  << " events processed: " << events_total_ << " (" << std::scientific << double(events_total_) << ")\n"
255  << " events with tracks in sector 45: " << events_per_arm_[0] << " (" << double(events_per_arm_[0]) << ")\n"
256  << " events with tracks in sector 56: " << events_per_arm_[1] << " (" << double(events_per_arm_[1]) << ")";
257 
258  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
259 
260  for (const auto& it : rpPlots) {
261  gDirectory = f_out->mkdir(Form("RP %u", it.first));
262  it.second.write();
263  }
264 
265  for (const auto& it : armPlots) {
266  gDirectory = f_out->mkdir(Form("arm %u", it.first));
267  it.second.write();
268  }
269 }
270 
271 //----------------------------------------------------------------------------------------------------
272 
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
CTPPSTrackDistributionPlotter::events_total_
unsigned int events_total_
Definition: CTPPSTrackDistributionPlotter.cc:54
DDAxes::y
CTPPSLocalTrackLiteCollection
std::vector< CTPPSLocalTrackLite > CTPPSLocalTrackLiteCollection
Collection of CTPPSLocalTrackLite objects.
Definition: CTPPSLocalTrackLiteFwd.h:18
CTPPSTrackDistributionPlotter::RPPlots::h_y
std::unique_ptr< TH1D > h_y
Definition: CTPPSTrackDistributionPlotter.cc:63
CTPPSTrackDistributionPlotter::ArmPlots::p_de_y_vs_x
std::unique_ptr< TProfile > p_de_y_vs_x
Definition: CTPPSTrackDistributionPlotter.cc:109
EDAnalyzer.h
funct::false
false
Definition: Factorize.h:29
CTPPSTrackDistributionPlotter::CTPPSTrackDistributionPlotter
CTPPSTrackDistributionPlotter(const edm::ParameterSet &)
Definition: CTPPSTrackDistributionPlotter.cc:179
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection >
CTPPSTrackDistributionPlotter::ArmPlots::rpId_N
unsigned int rpId_N
Definition: CTPPSTrackDistributionPlotter.cc:106
edm
HLT enums.
Definition: AlignableModifier.h:19
CTPPSTrackDistributionPlotter::~CTPPSTrackDistributionPlotter
~CTPPSTrackDistributionPlotter() override
Definition: CTPPSTrackDistributionPlotter.cc:42
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
muonClassificationByHits_cfi.pixel
pixel
Definition: muonClassificationByHits_cfi.py:9
protons_cff.time
time
Definition: protons_cff.py:39
CTPPSLocalTrackLite.h
CTPPSTrackDistributionPlotter::ArmPlots::Stat
Definition: CTPPSTrackDistributionPlotter.cc:114
DDAxes::x
CTPPSTrackDistributionPlotter::RPPlots
Definition: CTPPSTrackDistributionPlotter.cc:57
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
CTPPSTrackDistributionPlotter::ArmPlots::write
void write() const
Definition: CTPPSTrackDistributionPlotter.cc:147
edm::Handle
Definition: AssociativeIterator.h:50
CTPPSTrackDistributionPlotter::RPPlots::RPPlots
RPPlots()
Definition: CTPPSTrackDistributionPlotter.cc:66
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
CTPPSTrackDistributionPlotter::ArmPlots::h2_de_y_vs_de_x
std::unique_ptr< TH2D > h2_de_y_vs_de_x
Definition: CTPPSTrackDistributionPlotter.cc:112
MakerMacros.h
CTPPSTrackDistributionPlotter::endJob
void endJob() override
Definition: CTPPSTrackDistributionPlotter.cc:251
CTPPSTrackDistributionPlotter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CTPPSTrackDistributionPlotter.cc:193
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
CTPPSTrackDistributionPlotter::ArmPlots::ArmPlots
ArmPlots()
Definition: CTPPSTrackDistributionPlotter.cc:120
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::ceil
constexpr int32_t ceil(float num)
Definition: constexpr_cmath.h:7
CTPPSTrackDistributionPlotter::RPPlots::h_x
std::unique_ptr< TH1D > h_x
Definition: CTPPSTrackDistributionPlotter.cc:62
CTPPSTrackDistributionPlotter::armPlots
std::map< unsigned int, ArmPlots > armPlots
Definition: CTPPSTrackDistributionPlotter.cc:180
CTPPSTrackDistributionPlotter::ArmPlots::h2_de_y_vs_x
std::unique_ptr< TH2D > h2_de_y_vs_x
Definition: CTPPSTrackDistributionPlotter.cc:111
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
CTPPSTrackDistributionPlotter::ArmPlots::fill
void fill(double x_N, double y_N, double x_F, double y_F)
Definition: CTPPSTrackDistributionPlotter.cc:131
CTPPSTrackDistributionPlotter::ArmPlots::h_de_x
std::unique_ptr< TH1D > h_de_x
Definition: CTPPSTrackDistributionPlotter.cc:108
CTPPSTrackDistributionPlotter::ArmPlots::m_stat
std::map< unsigned int, std::map< unsigned int, Stat > > m_stat
Definition: CTPPSTrackDistributionPlotter.cc:118
CTPPSDetId::sdTrackingPixel
Definition: CTPPSDetId.h:44
CTPPSTrackDistributionPlotter::ArmPlots::p_de_x_vs_x
std::unique_ptr< TProfile > p_de_x_vs_x
Definition: CTPPSTrackDistributionPlotter.cc:109
CTPPSTrackDistributionPlotter::ArmPlots::Stat::sN
unsigned int sN
Definition: CTPPSTrackDistributionPlotter.cc:115
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSTrackDistributionPlotter::RPPlots::h_time
std::unique_ptr< TH1D > h_time
Definition: CTPPSTrackDistributionPlotter.cc:64
CTPPSTrackDistributionPlotter::RPPlots::p_y_vs_x
std::unique_ptr< TProfile > p_y_vs_x
Definition: CTPPSTrackDistributionPlotter.cc:61
edm::ParameterSet
Definition: ParameterSet.h:47
CTPPSTrackDistributionPlotter::rpPlots
std::map< unsigned int, RPPlots > rpPlots
Definition: CTPPSTrackDistributionPlotter.cc:103
Event.h
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
CTPPSTrackDistributionPlotter::tracksToken_
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > tracksToken_
Definition: CTPPSTrackDistributionPlotter.cc:48
CTPPSDetId
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:31
iEvent
int iEvent
Definition: GenABIO.cc:224
CTPPSTrackDistributionPlotter::ArmPlots::h2_de_x_vs_x
std::unique_ptr< TH2D > h2_de_x_vs_x
Definition: CTPPSTrackDistributionPlotter.cc:111
CTPPSTrackDistributionPlotter::ArmPlots::p2_de_x_vs_x_y
std::unique_ptr< TProfile2D > p2_de_x_vs_x_y
Definition: CTPPSTrackDistributionPlotter.cc:110
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
CTPPSTrackDistributionPlotter::RPPlots::init
void init(bool pixel, double pitch)
Definition: CTPPSTrackDistributionPlotter.cc:68
edm::EventSetup
Definition: EventSetup.h:58
CTPPSTrackDistributionPlotter
Definition: CTPPSTrackDistributionPlotter.cc:32
CTPPSTrackDistributionPlotter::RPPlots::initialized
bool initialized
Definition: CTPPSTrackDistributionPlotter.cc:58
CTPPSTrackDistributionPlotter::x_pitch_pixels_
double x_pitch_pixels_
Definition: CTPPSTrackDistributionPlotter.cc:50
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
protons_cff.arm
arm
Definition: protons_cff.py:43
profile_2016_postTS2_cff.rpId
rpId
Definition: profile_2016_postTS2_cff.py:21
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
CTPPSLocalTrackLiteFwd.h
CTPPSTrackDistributionPlotter::ArmPlots::h_de_y
std::unique_ptr< TH1D > h_de_y
Definition: CTPPSTrackDistributionPlotter.cc:108
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CTPPSDetId.h
CTPPSTrackDistributionPlotter::RPPlots::h2_y_vs_x
std::unique_ptr< TH2D > h2_y_vs_x
Definition: CTPPSTrackDistributionPlotter.cc:60
CTPPSTrackDistributionPlotter::RPPlots::fill
void fill(double x, double y, double time)
Definition: CTPPSTrackDistributionPlotter.cc:86
ParameterSet.h
CTPPSTrackDistributionPlotter::outputFile_
std::string outputFile_
Definition: CTPPSTrackDistributionPlotter.cc:52
CTPPSTrackDistributionPlotter::events_per_arm_
std::map< unsigned int, unsigned int > events_per_arm_
Definition: CTPPSTrackDistributionPlotter.cc:55
CTPPSTrackDistributionPlotter::RPPlots::write
void write() const
Definition: CTPPSTrackDistributionPlotter.cc:94
CTPPSTrackDistributionPlotter::ArmPlots::rpId_F
unsigned int rpId_F
Definition: CTPPSTrackDistributionPlotter.cc:106
edm::Event
Definition: Event.h:73
CTPPSTrackDistributionPlotter::ArmPlots::Stat::s1
unsigned int s1
Definition: CTPPSTrackDistributionPlotter.cc:115
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
CTPPSTrackDistributionPlotter::ArmPlots::p2_de_y_vs_x_y
std::unique_ptr< TProfile2D > p2_de_y_vs_x_y
Definition: CTPPSTrackDistributionPlotter.cc:110