CMS 3D CMS Logo

EcalSimple2007H4TBAnalyzer.cc
Go to the documentation of this file.
1 
8 //
9 //
10 //
11 
19 
21 
25 
26 //#include<fstream>
27 
28 #include "TFile.h"
29 #include "TH1.h"
30 #include "TH2.h"
31 #include "TF1.h"
32 
33 #include <iostream>
34 #include <string>
35 #include <stdexcept>
36 //
37 // constants, enums and typedefs
38 //
39 
40 //
41 // static data member definitions
42 //
43 
44 //
45 // constructors and destructor
46 //
47 
48 
49 //========================================================================
51 //========================================================================
52 {
53  //now do what ever initialization is needed
54  rootfile_ = iConfig.getUntrackedParameter<std::string>("rootfile","ecalSimpleTBanalysis.root");
55  digiCollection_ = iConfig.getParameter<std::string>("digiCollection");
56  digiProducer_ = iConfig.getParameter<std::string>("digiProducer");
57  hitCollection_ = iConfig.getParameter<std::string>("hitCollection");
58  hitProducer_ = iConfig.getParameter<std::string>("hitProducer");
59  hodoRecInfoCollection_ = iConfig.getParameter<std::string>("hodoRecInfoCollection");
60  hodoRecInfoProducer_ = iConfig.getParameter<std::string>("hodoRecInfoProducer");
61  tdcRecInfoCollection_ = iConfig.getParameter<std::string>("tdcRecInfoCollection");
62  tdcRecInfoProducer_ = iConfig.getParameter<std::string>("tdcRecInfoProducer");
63  eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection");
64  eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer");
65 
66 
67  std::cout << "EcalSimple2007H4TBAnalyzer: fetching hitCollection: " << hitCollection_.c_str()
68  << " produced by " << hitProducer_.c_str() << std::endl;
69 
70 }
71 
72 
73 //========================================================================
75 //========================================================================
76 {
77  // do anything here that needs to be done at desctruction time
78  // (e.g. close files, deallocate resources etc.)
79  // Amplitude vs TDC offset
80 // if (h_ampltdc)
81 // delete h_ampltdc;
82 
83 // // Reconstructed energies
84 // delete h_e1x1;
85 // delete h_e3x3;
86 // delete h_e5x5;
87 
88 // delete h_bprofx;
89 // delete h_bprofy;
90 
91 // delete h_qualx;
92 // delete h_qualy;
93 
94 // delete h_slopex;
95 // delete h_slopey;
96 
97 // delete h_mapx;
98 // delete h_mapy;
99 
100 }
101 
102 //========================================================================
103 void
105 //========================================================================
106 
108  iSetup.get<CaloGeometryRecord>().get(pG);
109 
110 
111  theTBGeometry_ = &(*pG);
112 // const std::vector<DetId>& validIds=theTBGeometry_->getValidDetIds(DetId::Ecal,EcalEndcap);
113 // std::cout << "Found " << validIds.size() << " channels in the geometry" << std::endl;
114 // for (unsigned int i=0;i<validIds.size();++i)
115 // std::cout << EEDetId(validIds[i]) << std::endl;
116 
117 // Amplitude vs TDC offset
118  h_ampltdc = new TH2F("h_ampltdc","Max Amplitude vs TDC offset", 100,0.,1.,1000, 0., 4000.);
119 
120  // Reconstructed energies
121  h_tableIsMoving = new TH1F("h_tableIsMoving","TableIsMoving", 100000, 0., 100000.);
122 
123  h_e1x1 = new TH1F("h_e1x1","E1x1 energy", 1000, 0., 4000.);
124  h_e3x3 = new TH1F("h_e3x3","E3x3 energy", 1000, 0., 4000.);
125  h_e5x5 = new TH1F("h_e5x5","E5x5 energy", 1000, 0., 4000.);
126 
127  h_e1x1_center = new TH1F("h_e1x1_center","E1x1 energy", 1000, 0., 4000.);
128  h_e3x3_center = new TH1F("h_e3x3_center","E3x3 energy", 1000, 0., 4000.);
129  h_e5x5_center = new TH1F("h_e5x5_center","E5x5 energy", 1000, 0., 4000.);
130 
131  h_e1e9 = new TH1F("h_e1e9","E1/E9 ratio", 600, 0., 1.2);
132  h_e1e25 = new TH1F("h_e1e25","E1/E25 ratio", 600, 0., 1.2);
133  h_e9e25 = new TH1F("h_e9e25","E9/E25 ratio", 600, 0., 1.2);
134 
135  h_S6 = new TH1F("h_S6","Amplitude S6", 1000, 0., 4000.);
136 
137  h_bprofx = new TH1F("h_bprofx","Beam Profile X",100,-20.,20.);
138  h_bprofy = new TH1F("h_bprofy","Beam Profile Y",100,-20.,20.);
139 
140  h_qualx = new TH1F("h_qualx","Beam Quality X",5000,0.,5.);
141  h_qualy = new TH1F("h_qualy","Beam Quality X",5000,0.,5.);
142 
143  h_slopex = new TH1F("h_slopex","Beam Slope X",500, -5e-4 , 5e-4 );
144  h_slopey = new TH1F("h_slopey","Beam Slope Y",500, -5e-4 , 5e-4 );
145 
146  char hname[50];
147  char htitle[50];
148  for (unsigned int icry=0;icry<25;icry++)
149  {
150  sprintf(hname,"h_mapx_%d",icry);
151  sprintf(htitle,"Max Amplitude vs X %d",icry);
152  h_mapx[icry] = new TH2F(hname,htitle,80,-20,20,1000,0.,4000.);
153  sprintf(hname,"h_mapy_%d",icry);
154  sprintf(htitle,"Max Amplitude vs Y %d",icry);
155  h_mapy[icry] = new TH2F(hname,htitle,80,-20,20,1000,0.,4000.);
156  }
157 
158  h_e1e9_mapx = new TH2F("h_e1e9_mapx","E1/E9 vs X",80,-20,20,600,0.,1.2);
159  h_e1e9_mapy = new TH2F("h_e1e9_mapy","E1/E9 vs Y",80,-20,20,600,0.,1.2);
160 
161  h_e1e25_mapx = new TH2F("h_e1e25_mapx","E1/E25 vs X",80,-20,20,600,0.,1.2);
162  h_e1e25_mapy = new TH2F("h_e1e25_mapy","E1/E25 vs Y",80,-20,20,600,0.,1.2);
163 
164  h_e9e25_mapx = new TH2F("h_e9e25_mapx","E9/E25 vs X",80,-20,20,600,0.,1.2);
165  h_e9e25_mapy = new TH2F("h_e9e25_mapy","E9/E25 vs Y",80,-20,20,600,0.,1.2);
166 
167  h_Shape_ = new TH2F("h_Shape_","Xtal in Beam Shape",250,0,10,350,0,3500);
168 
169 }
170 
171 //========================================================================
172 void
174 //========================================================================
175 
176  TFile f(rootfile_.c_str(),"RECREATE");
177 
178  // Amplitude vs TDC offset
179  h_ampltdc->Write();
180 
181  // Reconstructed energies
182  h_e1x1->Write();
183  h_e3x3->Write();
184  h_e5x5->Write();
185 
186  h_e1x1_center->Write();
187  h_e3x3_center->Write();
188  h_e5x5_center->Write();
189 
190  h_e1e9->Write();
191  h_e1e25->Write();
192  h_e9e25->Write();
193 
194  h_S6->Write();
195  h_bprofx->Write();
196  h_bprofy->Write();
197 
198  h_qualx->Write();
199  h_qualy->Write();
200 
201  h_slopex->Write();
202  h_slopey->Write();
203 
204  h_Shape_->Write();
205 
206  for (unsigned int icry=0;icry<25;icry++)
207  {
208  h_mapx[icry]->Write();
209  h_mapy[icry]->Write();
210  }
211 
212  h_e1e9_mapx->Write();
213  h_e1e9_mapy->Write();
214 
215  h_e1e25_mapx->Write();
216  h_e1e25_mapy->Write();
217 
218  h_e9e25_mapx->Write();
219  h_e9e25_mapy->Write();
220 
221  h_tableIsMoving->Write();
222 
223  f.Close();
224 }
225 
226 //
227 // member functions
228 //
229 
230 //========================================================================
231 void
233 //========================================================================
234 
235  using namespace edm;
236  using namespace cms;
237 
238 
239 
241  const EEDigiCollection* digis=nullptr;
242  //std::cout << "EcalSimple2007H4TBAnalyzer::analyze getting product with label: " << digiProducer_.c_str()<< " prodname: " << digiCollection_.c_str() << endl;
243  iEvent.getByLabel( digiProducer_, digiCollection_,pdigis);
244  if ( pdigis.isValid() ) {
245  digis = pdigis.product(); // get a ptr to the product
246  //iEvent.getByLabel( hitProducer_, phits);
247  } else {
248  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << digiCollection_;
249  }
250 
251  // fetch the digis and compute signal amplitude
253  const EEUncalibratedRecHitCollection* hits=nullptr;
254  //std::cout << "EcalSimple2007H4TBAnalyzer::analyze getting product with label: " << digiProducer_.c_str()<< " prodname: " << digiCollection_.c_str() << endl;
255  iEvent.getByLabel( hitProducer_, hitCollection_,phits);
256  if (phits.isValid()) {
257  hits = phits.product(); // get a ptr to the product
258  //iEvent.getByLabel( hitProducer_, phits);
259  } else {
260  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << hitCollection_;
261  }
262 
264  const EcalTBHodoscopeRecInfo* recHodo=nullptr;
265  //std::cout << "EcalSimple2007H4TBAnalyzer::analyze getting product with label: " << digiProducer_.c_str()<< " prodname: " << digiCollection_.c_str() << endl;
267  if ( pHodo.isValid() ) {
268  recHodo = pHodo.product(); // get a ptr to the product
269  } else {
270  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << hodoRecInfoCollection_;
271  }
272 
274  const EcalTBTDCRecInfo* recTDC=nullptr;
275  //std::cout << "EcalSimple2007H4TBAnalyzer::analyze getting product with label: " << digiProducer_.c_str()<< " prodname: " << digiCollection_.c_str() << endl;
277  if ( pTDC.isValid() ) {
278  recTDC = pTDC.product(); // get a ptr to the product
279  } else {
280  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << tdcRecInfoCollection_;
281  }
282 
283  Handle<EcalTBEventHeader> pEventHeader;
284  const EcalTBEventHeader* evtHeader=nullptr;
285  //std::cout << "EcalSimple2007H4TBAnalyzer::analyze getting product with label: " << digiProducer_.c_str()<< " prodname: " << digiCollection_.c_str() << endl;
286  iEvent.getByLabel( eventHeaderProducer_ , pEventHeader );
287  if ( pEventHeader.isValid() ) {
288  evtHeader = pEventHeader.product(); // get a ptr to the product
289  } else {
290  edm::LogError("EcalSimple2007H4TBAnalyzerError") << "Error! can't get the product " << eventHeaderProducer_;
291  }
292 
293 
294  if (!hits)
295  {
296  // std::cout << "1" << std::endl;
297  return;
298  }
299 
300  if (!recTDC)
301  {
302  // std::cout << "2" << std::endl;
303  return;
304  }
305 
306  if (!recHodo)
307  {
308  // std::cout << "3" << std::endl;
309  return;
310  }
311 
312  if (!evtHeader)
313  {
314  // std::cout << "4" << std::endl;
315  return;
316  }
317 
318  if (hits->empty())
319  {
320  // std::cout << "5" << std::endl;
321  return;
322  }
323 
324  //Accessing various event information
325  if (evtHeader->tableIsMoving())
326  h_tableIsMoving->Fill(evtHeader->eventNumber());
327 
328 // std::cout << "event " << evtHeader->eventNumber()
329 // << "\trun number " << evtHeader->runNumber()
330 // << "\tburst number " << evtHeader->burstNumber()
331 // << "\tbeginLV1A " << evtHeader->begBurstLV1A()
332 // << "\tendLV1A " << evtHeader->endBurstLV1A()
333 // << "\ttime " << evtHeader->date()
334 // << "\thas errors " << int(evtHeader->syncError())
335 // << std::endl;
336 
337 // std::cout << "scaler";
338 // for (int iscaler=0;iscaler < 36;iscaler++)
339 // std::cout << "\t#" << iscaler << " " << evtHeader->scaler(iscaler);
340 // std::cout<<std::endl;
341 
342  //S6 beam scintillator
343  h_S6->Fill(evtHeader->S6ADC());
344 
345  if (xtalInBeamTmp.null())
346  {
348  xtalInBeam_ = EEDetId( 35 - ((xtalInBeamTmp.ic()-1)%20) ,int(int(xtalInBeamTmp.ic())/int(20))+51, -1);
349  std::cout<< "Xtal In Beam is " << xtalInBeam_.ic() << xtalInBeam_ << std::endl;
350  for (unsigned int icry=0;icry<25;icry++)
351  {
352  unsigned int row = icry / 5;
353  unsigned int column= icry %5;
354  int ix=xtalInBeam_.ix()+row-2;
355  int iy=xtalInBeam_.iy()+column-2;
356  EEDetId tempId(ix, iy, xtalInBeam_.zside());
357  //Selecting matrix of xtals used in 2007H4TB
358  if (tempId.ix()<16 || tempId.ix()>35 || tempId.iy()<51 || tempId.iy()>75)
359  Xtals5x5[icry]=EEDetId(0);
360  else
361  {
362  Xtals5x5[icry]=tempId;
364  if (!cell)
365  continue;
366  const TruncatedPyramid* tp ( dynamic_cast<const TruncatedPyramid*>(cell) ) ;
367  std::cout << "** Xtal in the matrix **** row " << row << ", column " << column << ", xtal " << Xtals5x5[icry] << " Position " << tp->getPosition(0.) << std::endl;
368  }
369  }
370  }
371  else
372  if (xtalInBeamTmp != EBDetId(1,evtHeader->crystalInBeam(),EBDetId::SMCRYSTALMODE)) //run analysis only on first xtal in beam
373  return;
374 
375  //Avoid moving table events
376  if (evtHeader->tableIsMoving())
377  {
378  std::cout << "Table is moving" << std::endl;
379  return;
380  }
381 
382 
383 
384  // Searching for max amplitude xtal alternative to use xtalInBeam_
385  EEDetId maxHitId(0);
386  float maxHit= -999999.;
387  for(EEUncalibratedRecHitCollection::const_iterator ithit = hits->begin(); ithit != hits->end(); ++ithit)
388  {
389  if (ithit->amplitude()>=maxHit)
390  {
391  maxHit=ithit->amplitude();
392  maxHitId=ithit->id();
393  }
394 
395  }
396  if (maxHitId==EEDetId(0))
397  {
398  std::cout << "No maxHit found" << std::endl;
399  return;
400  }
401 
402 
403  //Filling the digis shape for the xtalInBeam
404  double samples_save[10]; for(int i=0; i < 10; ++i) samples_save[i]=0.0;
405 
406  double eMax = 0.;
407  for ( EEDigiCollection::const_iterator digiItr= digis->begin();digiItr != digis->end();
408  ++digiItr )
409  {
410  if ( EEDetId((*digiItr).id()) != xtalInBeam_ )
411  continue;
412 
413  EEDataFrame myDigi = (*digiItr);
414  for (int sample = 0; sample < myDigi.size(); ++sample)
415  {
416  double analogSample = myDigi.sample(sample).adc();
417  samples_save[sample] = analogSample;
418  // std::cout << analogSample << " ";
419  if ( eMax < analogSample )
420  {
421  eMax = analogSample;
422  }
423  }
424  // std::cout << std::endl;
425  }
426 
427  for(int i =0; i < 10; ++i)
428  h_Shape_->Fill(double(i)+recTDC->offset(),samples_save[i]);
429 
430 
431 
432  // Taking amplitudes in 5x5
433  double amplitude[25];
434  double amplitude3x3=0;
435  double amplitude5x5=0;
436  for (unsigned int icry=0;icry<25;icry++)
437  {
438  if (!Xtals5x5[icry].null())
439  {
440  amplitude[icry]=(hits->find(Xtals5x5[icry]))->amplitude();
441  amplitude5x5 += amplitude[icry];
442  // Is in 3x3?
443  if ( icry == 6 || icry == 7 || icry == 8 ||
444  icry == 11 || icry == 12 || icry ==13 ||
445  icry == 16 || icry == 17 || icry ==18 )
446  {
447  amplitude3x3+=amplitude[icry];
448  }
449  }
450  }
451 
452  //Filling amplitudes
453  h_e1x1->Fill(amplitude[12]);
454  h_e3x3->Fill(amplitude3x3);
455  h_e5x5->Fill(amplitude5x5);
456 
457  h_e1e9->Fill(amplitude[12]/amplitude3x3);
458  h_e1e25->Fill(amplitude[12]/amplitude5x5);
459  h_e9e25->Fill(amplitude3x3/amplitude5x5);
460 
461  //Checking stability of amplitude vs TDC
462  if (recTDC)
463  h_ampltdc->Fill(recTDC->offset(),amplitude[12]);
464 
465  //Various amplitudes as a function of hodoscope coordinates
466  if (recHodo)
467  {
468  float x=recHodo->posX();
469  float y=recHodo->posY();
470  float xslope=recHodo->slopeX();
471  float yslope=recHodo->slopeY();
472  float xqual=recHodo->qualX();
473  float yqual=recHodo->qualY();
474 
475  //Filling beam profiles
476  h_bprofx->Fill(x);
477  h_bprofy->Fill(y);
478  h_qualx->Fill(xqual);
479  h_qualy->Fill(yqual);
480  h_slopex->Fill(xslope);
481  h_slopey->Fill(yslope);
482 
483  //Fill central events
484 
485 
486  if ( fabs(x + 2.5) < 2.5 && fabs(y + 0.5) < 2.5)
487  {
488  h_e1x1_center->Fill(amplitude[12]);
489  h_e3x3_center->Fill(amplitude3x3);
490  h_e5x5_center->Fill(amplitude5x5);
491  }
492 
493  for (unsigned int icry=0;icry<25;icry++)
494  {
495  h_mapx[icry]->Fill(x,amplitude[icry]);
496  h_mapy[icry]->Fill(y,amplitude[icry]);
497  }
498 
499  h_e1e9_mapx->Fill(x,amplitude[12]/amplitude3x3);
500  h_e1e9_mapy->Fill(y,amplitude[12]/amplitude3x3);
501 
502  h_e1e25_mapx->Fill(x,amplitude[12]/amplitude5x5);
503  h_e1e25_mapy->Fill(y,amplitude[12]/amplitude5x5);
504 
505  h_e9e25_mapx->Fill(x,amplitude3x3/amplitude5x5);
506  h_e9e25_mapy->Fill(y,amplitude3x3/amplitude5x5);
507  }
508 
509 }
510 
511 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool tableIsMoving() const
Tell if the table is Moving.
void beginRun(edm::Run const &, edm::EventSetup const &) override
std::vector< EcalUncalibratedRecHit >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
const_iterator begin() const
int crystalInBeam() const
Returns the crystal which is being hit by the beam (in the internal SM numbering scheme) ...
int size() const
Definition: EcalDataFrame.h:26
int iEvent
Definition: GenABIO.cc:230
int S6ADC() const
returns S6 ADC value
double f[11][100]
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:464
void analyze(edm::Event const &, edm::EventSetup const &) override
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
const_iterator end() const
T const * product() const
Definition: Handle.h:81
const GlobalPoint getPosition(CCGFloat depth) const
const T & get() const
Definition: EventSetup.h:55
EcalSimple2007H4TBAnalyzer(const edm::ParameterSet &)
bool null() const
is this a null id ?
Definition: DetId.h:45
int eventNumber() const
Returns the event number.
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
const_iterator end() const
iterator find(key_type k)
HLT enums.
const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
Definition: CaloGeometry.cc:78
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
float offset() const
const_iterator begin() const
Definition: Run.h:43
int adc() const
get the ADC sample (12 bits)
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:47