CMS 3D CMS Logo

EcalSimple2007H4TBAnalyzer.cc
Go to the documentation of this file.
1 
8 //
9 //
10 //
11 
13 
17 
18 //#include<fstream>
19 
20 #include "TFile.h"
21 #include "TF1.h"
22 
23 //
24 // constants, enums and typedefs
25 //
26 
27 //
28 // static data member definitions
29 //
30 
31 //
32 // constructors and destructor
33 //
34 
35 //========================================================================
37  : rootfile_(iConfig.getUntrackedParameter<std::string>("rootfile", "ecalSimpleTBanalysis.root")),
38  digiCollection_(iConfig.getParameter<std::string>("digiCollection")),
39  digiProducer_(iConfig.getParameter<std::string>("digiProducer")),
40  hitCollection_(iConfig.getParameter<std::string>("hitCollection")),
41  hitProducer_(iConfig.getParameter<std::string>("hitProducer")),
42  hodoRecInfoCollection_(iConfig.getParameter<std::string>("hodoRecInfoCollection")),
43  hodoRecInfoProducer_(iConfig.getParameter<std::string>("hodoRecInfoProducer")),
44  tdcRecInfoCollection_(iConfig.getParameter<std::string>("tdcRecInfoCollection")),
45  tdcRecInfoProducer_(iConfig.getParameter<std::string>("tdcRecInfoProducer")),
46  eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
47  eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
48  eeDigiToken_(consumes<>(edm::InputTag(digiProducer_, digiCollection_))),
49  eeUncalibratedRecHitToken_(consumes<>(edm::InputTag(hitProducer_, hitCollection_))),
50  tbHodoscopeRecInfoToken_(consumes<>(edm::InputTag(hodoRecInfoProducer_, hodoRecInfoCollection_))),
51  tbTDCRecInfoToken_(consumes<>(edm::InputTag(tdcRecInfoProducer_, tdcRecInfoCollection_))),
52  tbEventHeaderToken_(consumes<>(edm::InputTag(eventHeaderProducer_))),
53  geometryToken_(esConsumes<edm::Transition::BeginRun>()),
54  xtalInBeam_(0)
55 //========================================================================
56 {
57  //now do what ever initialization is needed
58  edm::LogVerbatim("EcalSimple2007H4TBAnalyzer")
59  << "EcalSimple2007H4TBAnalyzer: fetching hitCollection: " << hitCollection_.c_str() << " produced by "
60  << hitProducer_.c_str();
61 }
62 
63 //========================================================================
65 //========================================================================
66 {
67  // do anything here that needs to be done at desctruction time
68  // (e.g. close files, deallocate resources etc.)
69  // Amplitude vs TDC offset
70  // if (h_ampltdc)
71  // delete h_ampltdc;
72 
73  // // Reconstructed energies
74  // delete h_e1x1;
75  // delete h_e3x3;
76  // delete h_e5x5;
77 
78  // delete h_bprofx;
79  // delete h_bprofy;
80 
81  // delete h_qualx;
82  // delete h_qualy;
83 
84  // delete h_slopex;
85  // delete h_slopey;
86 
87  // delete h_mapx;
88  // delete h_mapy;
89 }
90 
91 //========================================================================
93  //========================================================================
94 
96 
97  // Amplitude vs TDC offset
98  h_ampltdc = new TH2F("h_ampltdc", "Max Amplitude vs TDC offset", 100, 0., 1., 1000, 0., 4000.);
99 
100  // Reconstructed energies
101  h_tableIsMoving = new TH1F("h_tableIsMoving", "TableIsMoving", 100000, 0., 100000.);
102 
103  h_e1x1 = new TH1F("h_e1x1", "E1x1 energy", 1000, 0., 4000.);
104  h_e3x3 = new TH1F("h_e3x3", "E3x3 energy", 1000, 0., 4000.);
105  h_e5x5 = new TH1F("h_e5x5", "E5x5 energy", 1000, 0., 4000.);
106 
107  h_e1x1_center = new TH1F("h_e1x1_center", "E1x1 energy", 1000, 0., 4000.);
108  h_e3x3_center = new TH1F("h_e3x3_center", "E3x3 energy", 1000, 0., 4000.);
109  h_e5x5_center = new TH1F("h_e5x5_center", "E5x5 energy", 1000, 0., 4000.);
110 
111  h_e1e9 = new TH1F("h_e1e9", "E1/E9 ratio", 600, 0., 1.2);
112  h_e1e25 = new TH1F("h_e1e25", "E1/E25 ratio", 600, 0., 1.2);
113  h_e9e25 = new TH1F("h_e9e25", "E9/E25 ratio", 600, 0., 1.2);
114 
115  h_S6 = new TH1F("h_S6", "Amplitude S6", 1000, 0., 4000.);
116 
117  h_bprofx = new TH1F("h_bprofx", "Beam Profile X", 100, -20., 20.);
118  h_bprofy = new TH1F("h_bprofy", "Beam Profile Y", 100, -20., 20.);
119 
120  h_qualx = new TH1F("h_qualx", "Beam Quality X", 5000, 0., 5.);
121  h_qualy = new TH1F("h_qualy", "Beam Quality X", 5000, 0., 5.);
122 
123  h_slopex = new TH1F("h_slopex", "Beam Slope X", 500, -5e-4, 5e-4);
124  h_slopey = new TH1F("h_slopey", "Beam Slope Y", 500, -5e-4, 5e-4);
125 
126  char hname[50];
127  char htitle[50];
128  for (unsigned int icry = 0; icry < 25; icry++) {
129  sprintf(hname, "h_mapx_%d", icry);
130  sprintf(htitle, "Max Amplitude vs X %d", icry);
131  h_mapx[icry] = new TH2F(hname, htitle, 80, -20, 20, 1000, 0., 4000.);
132  sprintf(hname, "h_mapy_%d", icry);
133  sprintf(htitle, "Max Amplitude vs Y %d", icry);
134  h_mapy[icry] = new TH2F(hname, htitle, 80, -20, 20, 1000, 0., 4000.);
135  }
136 
137  h_e1e9_mapx = new TH2F("h_e1e9_mapx", "E1/E9 vs X", 80, -20, 20, 600, 0., 1.2);
138  h_e1e9_mapy = new TH2F("h_e1e9_mapy", "E1/E9 vs Y", 80, -20, 20, 600, 0., 1.2);
139 
140  h_e1e25_mapx = new TH2F("h_e1e25_mapx", "E1/E25 vs X", 80, -20, 20, 600, 0., 1.2);
141  h_e1e25_mapy = new TH2F("h_e1e25_mapy", "E1/E25 vs Y", 80, -20, 20, 600, 0., 1.2);
142 
143  h_e9e25_mapx = new TH2F("h_e9e25_mapx", "E9/E25 vs X", 80, -20, 20, 600, 0., 1.2);
144  h_e9e25_mapy = new TH2F("h_e9e25_mapy", "E9/E25 vs Y", 80, -20, 20, 600, 0., 1.2);
145 
146  h_Shape_ = new TH2F("h_Shape_", "Xtal in Beam Shape", 250, 0, 10, 350, 0, 3500);
147 }
148 
149 //========================================================================
151 //========================================================================
152 
153 //========================================================================
155  //========================================================================
156 
157  TFile f(rootfile_.c_str(), "RECREATE");
158 
159  // Amplitude vs TDC offset
160  h_ampltdc->Write();
161 
162  // Reconstructed energies
163  h_e1x1->Write();
164  h_e3x3->Write();
165  h_e5x5->Write();
166 
167  h_e1x1_center->Write();
168  h_e3x3_center->Write();
169  h_e5x5_center->Write();
170 
171  h_e1e9->Write();
172  h_e1e25->Write();
173  h_e9e25->Write();
174 
175  h_S6->Write();
176  h_bprofx->Write();
177  h_bprofy->Write();
178 
179  h_qualx->Write();
180  h_qualy->Write();
181 
182  h_slopex->Write();
183  h_slopey->Write();
184 
185  h_Shape_->Write();
186 
187  for (unsigned int icry = 0; icry < 25; icry++) {
188  h_mapx[icry]->Write();
189  h_mapy[icry]->Write();
190  }
191 
192  h_e1e9_mapx->Write();
193  h_e1e9_mapy->Write();
194 
195  h_e1e25_mapx->Write();
196  h_e1e25_mapy->Write();
197 
198  h_e9e25_mapx->Write();
199  h_e9e25_mapy->Write();
200 
201  h_tableIsMoving->Write();
202 
203  f.Close();
204 }
205 
206 //
207 // member functions
208 //
209 
210 //========================================================================
212  //========================================================================
213 
214  using namespace edm;
215  using namespace cms;
216 
218  const EEDigiCollection* digis = nullptr;
219  iEvent.getByToken(eeDigiToken_, pdigis);
220  if (pdigis.isValid()) {
221  digis = pdigis.product(); // get a ptr to the product
222  } else {
223  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << digiCollection_;
224  }
225 
226  // fetch the digis and compute signal amplitude
228  const EEUncalibratedRecHitCollection* hits = nullptr;
230  if (phits.isValid()) {
231  hits = phits.product(); // get a ptr to the product
232  } else {
233  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << hitCollection_;
234  }
235 
237  const EcalTBHodoscopeRecInfo* recHodo = nullptr;
238  iEvent.getByToken(tbHodoscopeRecInfoToken_, pHodo);
239  if (pHodo.isValid()) {
240  recHodo = pHodo.product(); // get a ptr to the product
241  } else {
242  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << hodoRecInfoCollection_;
243  }
244 
246  const EcalTBTDCRecInfo* recTDC = nullptr;
247  iEvent.getByToken(tbTDCRecInfoToken_, pTDC);
248  if (pTDC.isValid()) {
249  recTDC = pTDC.product(); // get a ptr to the product
250  } else {
251  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << tdcRecInfoCollection_;
252  }
253 
254  Handle<EcalTBEventHeader> pEventHeader;
255  const EcalTBEventHeader* evtHeader = nullptr;
256  iEvent.getByToken(tbEventHeaderToken_, pEventHeader);
257  if (pEventHeader.isValid()) {
258  evtHeader = pEventHeader.product(); // get a ptr to the product
259  } else {
260  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << eventHeaderProducer_;
261  }
262 
263  if (!hits) {
264  return;
265  }
266 
267  if (!recTDC) {
268  return;
269  }
270 
271  if (!recHodo) {
272  return;
273  }
274 
275  if (!evtHeader) {
276  return;
277  }
278 
279  if (hits->empty()) {
280  return;
281  }
282 
283  //Accessing various event information
284  if (evtHeader->tableIsMoving())
285  h_tableIsMoving->Fill(evtHeader->eventNumber());
286 
287  //S6 beam scintillator
288  h_S6->Fill(evtHeader->S6ADC());
289 
290  if (xtalInBeamTmp.null()) {
292  xtalInBeam_ = EEDetId(35 - ((xtalInBeamTmp.ic() - 1) % 20), int(int(xtalInBeamTmp.ic()) / int(20)) + 51, -1);
293  edm::LogVerbatim("EcalSimple2007H4TBAnalyzer") << "Xtal In Beam is " << xtalInBeam_.ic() << xtalInBeam_;
294  for (unsigned int icry = 0; icry < 25; icry++) {
295  unsigned int row = icry / 5;
296  unsigned int column = icry % 5;
297  int ix = xtalInBeam_.ix() + row - 2;
298  int iy = xtalInBeam_.iy() + column - 2;
299  EEDetId tempId(ix, iy, xtalInBeam_.zside());
300  //Selecting matrix of xtals used in 2007H4TB
301  if (tempId.ix() < 16 || tempId.ix() > 35 || tempId.iy() < 51 || tempId.iy() > 75)
302  Xtals5x5[icry] = EEDetId(0);
303  else {
304  Xtals5x5[icry] = tempId;
305  auto cell = theTBGeometry_->getGeometry(Xtals5x5[icry]);
306  if (!cell)
307  continue;
308  edm::LogVerbatim("EcalSimple2007H4TBAnalyzer")
309  << "** Xtal in the matrix **** row " << row << ", column " << column << ", xtal " << Xtals5x5[icry]
310  << " Position " << cell->getPosition(0.);
311  }
312  }
313  } else if (xtalInBeamTmp !=
314  EBDetId(1, evtHeader->crystalInBeam(), EBDetId::SMCRYSTALMODE)) //run analysis only on first xtal in beam
315  return;
316 
317  //Avoid moving table events
318  if (evtHeader->tableIsMoving()) {
319  edm::LogVerbatim("EcalSimple2007H4TBAnalyzer") << "Table is moving";
320  return;
321  }
322 
323  // Searching for max amplitude xtal alternative to use xtalInBeam_
324  EEDetId maxHitId(0);
325  float maxHit = -999999.;
326  for (EEUncalibratedRecHitCollection::const_iterator ithit = hits->begin(); ithit != hits->end(); ++ithit) {
327  if (ithit->amplitude() >= maxHit) {
328  maxHit = ithit->amplitude();
329  maxHitId = ithit->id();
330  }
331  }
332  if (maxHitId == EEDetId(0)) {
333  edm::LogVerbatim("EcalSimple2007H4TBAnalyzer") << "No maxHit found";
334  return;
335  }
336 
337  //Filling the digis shape for the xtalInBeam
338  double samples_save[10];
339  for (int i = 0; i < 10; ++i)
340  samples_save[i] = 0.0;
341 
342  double eMax = 0.;
343  for (EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
344  if (EEDetId((*digiItr).id()) != xtalInBeam_)
345  continue;
346 
347  EEDataFrame myDigi = (*digiItr);
348  for (int sample = 0; sample < myDigi.size(); ++sample) {
349  double analogSample = myDigi.sample(sample).adc();
350  samples_save[sample] = analogSample;
351  if (eMax < analogSample) {
352  eMax = analogSample;
353  }
354  }
355  }
356 
357  for (int i = 0; i < 10; ++i)
358  h_Shape_->Fill(double(i) + recTDC->offset(), samples_save[i]);
359 
360  // Taking amplitudes in 5x5
361  double amplitude[25];
362  double amplitude3x3 = 0;
363  double amplitude5x5 = 0;
364  for (unsigned int icry = 0; icry < 25; icry++) {
365  if (!Xtals5x5[icry].null()) {
366  amplitude[icry] = (hits->find(Xtals5x5[icry]))->amplitude();
367  amplitude5x5 += amplitude[icry];
368  // Is in 3x3?
369  if (icry == 6 || icry == 7 || icry == 8 || icry == 11 || icry == 12 || icry == 13 || icry == 16 || icry == 17 ||
370  icry == 18) {
371  amplitude3x3 += amplitude[icry];
372  }
373  }
374  }
375 
376  //Filling amplitudes
377  h_e1x1->Fill(amplitude[12]);
378  h_e3x3->Fill(amplitude3x3);
379  h_e5x5->Fill(amplitude5x5);
380 
381  h_e1e9->Fill(amplitude[12] / amplitude3x3);
382  h_e1e25->Fill(amplitude[12] / amplitude5x5);
383  h_e9e25->Fill(amplitude3x3 / amplitude5x5);
384 
385  //Checking stability of amplitude vs TDC
386  if (recTDC)
387  h_ampltdc->Fill(recTDC->offset(), amplitude[12]);
388 
389  //Various amplitudes as a function of hodoscope coordinates
390  if (recHodo) {
391  float x = recHodo->posX();
392  float y = recHodo->posY();
393  float xslope = recHodo->slopeX();
394  float yslope = recHodo->slopeY();
395  float xqual = recHodo->qualX();
396  float yqual = recHodo->qualY();
397 
398  //Filling beam profiles
399  h_bprofx->Fill(x);
400  h_bprofy->Fill(y);
401  h_qualx->Fill(xqual);
402  h_qualy->Fill(yqual);
403  h_slopex->Fill(xslope);
404  h_slopey->Fill(yslope);
405 
406  //Fill central events
407 
408  if (fabs(x + 2.5) < 2.5 && fabs(y + 0.5) < 2.5) {
409  h_e1x1_center->Fill(amplitude[12]);
410  h_e3x3_center->Fill(amplitude3x3);
411  h_e5x5_center->Fill(amplitude5x5);
412  }
413 
414  for (unsigned int icry = 0; icry < 25; icry++) {
415  h_mapx[icry]->Fill(x, amplitude[icry]);
416  h_mapy[icry]->Fill(y, amplitude[icry]);
417  }
418 
419  h_e1e9_mapx->Fill(x, amplitude[12] / amplitude3x3);
420  h_e1e9_mapy->Fill(y, amplitude[12] / amplitude3x3);
421 
422  h_e1e25_mapx->Fill(x, amplitude[12] / amplitude5x5);
423  h_e1e25_mapy->Fill(y, amplitude[12] / amplitude5x5);
424 
425  h_e9e25_mapx->Fill(x, amplitude3x3 / amplitude5x5);
426  h_e9e25_mapy->Fill(y, amplitude3x3 / amplitude5x5);
427  }
428 }
Log< level::Info, true > LogVerbatim
int crystalInBeam() const
Returns the crystal which is being hit by the beam (in the internal SM numbering scheme) ...
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::EDGetTokenT< EcalTBTDCRecInfo > tbTDCRecInfoToken_
void beginRun(edm::Run const &, edm::EventSetup const &) override
T const * product() const
Definition: Handle.h:70
int ix() const
Definition: EEDetId.h:77
std::vector< T >::const_iterator const_iterator
const edm::EDGetTokenT< EEDigiCollection > eeDigiToken_
const edm::EDGetTokenT< EEUncalibratedRecHitCollection > eeUncalibratedRecHitToken_
Log< level::Error, false > LogError
const edm::EDGetTokenT< EcalTBHodoscopeRecInfo > tbHodoscopeRecInfoToken_
const edm::EDGetTokenT< EcalTBEventHeader > tbEventHeaderToken_
int ic() const
Definition: EEDetId.cc:245
int size() const
Definition: EcalDataFrame.h:26
int eventNumber() const
Returns the event number.
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
int iEvent
Definition: GenABIO.cc:224
TupleMultiplicity< TrackerTraits > const *__restrict__ TrackingRecHitSoAConstView< TrackerTraits > TrackerTraits::tindex_type *__restrict__ double *__restrict__ phits
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:41
int S6ADC() const
returns S6 ADC value
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
Definition: CaloGeometry.cc:60
Transition
Definition: Transition.h:12
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
double f[11][100]
bool tableIsMoving() const
Tell if the table is Moving.
void analyze(edm::Event const &, edm::EventSetup const &) override
const_iterator end() const
Namespace of DDCMS conversion namespace.
int zside() const
Definition: EEDetId.h:71
const_iterator begin() const
The iterator returned can not safely be used across threads.
EcalSimple2007H4TBAnalyzer(const edm::ParameterSet &)
float offset() const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
int adc() const
get the ADC sample (12 bits)
static const int SMCRYSTALMODE
Definition: EBDetId.h:159
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:45
int iy() const
Definition: EEDetId.h:83