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)", 100, -2., +2.)),
50  h_de_y(new TH1D("", ";#Deltay (mm)", 100, -2., +2.))
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  auto it = hOpticalFunctions->find(rpId);
111 
112  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_beam = { 0., 0., 0., 0., 0. };
114  it->second.transport(k_in_beam, k_out_beam);
115 
116  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in = { -pr.vx(), -pr.thetaX(), pr.vy(), pr.thetaY(), pr.xi() }; // conversions: CMS --> LHC convention
118  it->second.transport(k_in, k_out);
119 
120  const double de_x = (k_out.x - k_out_beam.x) * 10. - tr->getX(); // conversions: cm --> mm
121  const double de_y = (k_out.y - k_out_beam.y) * 10. - tr->getY(); // conversions: cm --> mm
122 
123  rp_plots_[rpDecId].fill(de_x, de_y);
124  }
125  }
126 }
127 
128 //----------------------------------------------------------------------------------------------------
129 
131 {
132  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
133 
134  for (const auto& p : rp_plots_) {
135  gDirectory = f_out->mkdir(Form("%u", p.first));
136  p.second.write();
137  }
138 }
139 
140 //----------------------------------------------------------------------------------------------------
141 
143 
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
uint32_t arm() const
Definition: CTPPSDetId.h:51
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.