CMS 3D CMS Logo

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