CMS 3D CMS Logo

CTPPSProtonReconstructionValidator.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  ****************************************************************************/
5 
11 
14 
16 
19 
23 
24 #include "TFile.h"
25 #include "TH1D.h"
26 
27 #include <map>
28 #include <string>
29 
30 //----------------------------------------------------------------------------------------------------
31 
33 {
34  public:
36 
37  private:
38  void analyze(const edm::Event&, const edm::EventSetup&) override;
39  void endJob() override;
40 
42  double chiSqCut_;
44 
45  struct RPPlots
46  {
47  std::unique_ptr<TH1D> h_de_x, h_de_y;
48  RPPlots() :
49  h_de_x(new TH1D("", ";#Deltax (mm)", 1000, -1., +1.)),
50  h_de_y(new TH1D("", ";#Deltay (mm)", 1000, -1., +1.))
51  {}
52 
53  void fill(double de_x, double de_y) {
54  h_de_x->Fill(de_x);
55  h_de_y->Fill(de_y);
56  }
57 
58  void write() const {
59  h_de_x->Write("h_de_x");
60  h_de_y->Write("h_de_y");
61  }
62  };
63 
64  std::map<unsigned int, RPPlots> rp_plots_;
65 };
66 
67 //----------------------------------------------------------------------------------------------------
68 
69 using namespace std;
70 using namespace edm;
71 
72 //----------------------------------------------------------------------------------------------------
73 
75  tokenRecoProtons_(consumes<reco::ForwardProtonCollection>(iConfig.getParameter<edm::InputTag>("tagRecoProtons"))),
76  chiSqCut_ (iConfig.getParameter<double>("chiSqCut")),
77  outputFile_(iConfig.getParameter<string>("outputFile"))
78 {}
79 
80 //----------------------------------------------------------------------------------------------------
81 
83 {
84  // get conditions
86  iSetup.get<CTPPSInterpolatedOpticsRcd>().get(hOpticalFunctions);
87 
88  // stop if conditions invalid
89  if (hOpticalFunctions->empty())
90  return;
91 
92  // get input
94  iEvent.getByToken(tokenRecoProtons_, hRecoProtons);
95 
96  // process tracks
97  for (const auto &pr : *hRecoProtons)
98  {
99  if (! pr.validFit())
100  continue;
101 
102  if (pr.chi2() > chiSqCut_)
103  continue;
104 
105  for (const auto &tr : pr.contributingLocalTracks())
106  {
107  CTPPSDetId rpId(tr->getRPId());
108  unsigned int rpDecId = rpId.arm()*100 + rpId.station()*10 + rpId.rp();
109 
110  // skip other than tracking RPs
111  if (rpId.subdetId() != CTPPSDetId::sdTrackingStrip && rpId.subdetId() != CTPPSDetId::sdTrackingPixel)
112  continue;
113 
114  // try to get optics for the RP
115  auto it = hOpticalFunctions->find(rpId);
116  if (it == hOpticalFunctions->end())
117  continue;
118 
119  // do propagation
120  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_beam = { 0., 0., 0., 0., 0. };
122  it->second.transport(k_in_beam, k_out_beam);
123 
124  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in = { -pr.vx(), -pr.thetaX(), pr.vy(), pr.thetaY(), pr.xi() }; // conversions: CMS --> LHC convention
126  it->second.transport(k_in, k_out);
127 
128  // fill plots
129  const double de_x = (k_out.x - k_out_beam.x) * 10. - tr->getX(); // conversions: cm --> mm
130  const double de_y = (k_out.y - k_out_beam.y) * 10. - tr->getY(); // conversions: cm --> mm
131 
132  rp_plots_[rpDecId].fill(de_x, de_y);
133  }
134  }
135 }
136 
137 //----------------------------------------------------------------------------------------------------
138 
140 {
141  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
142 
143  for (const auto& p : rp_plots_) {
144  gDirectory = f_out->mkdir(Form("%u", p.first));
145  p.second.write();
146  }
147 }
148 
149 //----------------------------------------------------------------------------------------------------
150 
152 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtons_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:71
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.