CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InvMatrixUtils.cc
Go to the documentation of this file.
1 
10 #include "TStyle.h"
11 #include "TROOT.h"
12 #include "CLHEP/Geometry/Point3D.h"
13 //#include "ConfigParser.h"
15 
16 #include <iostream>
17 #include <string>
18 #include <fstream>
19 #include <sstream>
20 #include <vector>
21 #include <cassert>
22 
24 void setStyle ()
25 {
26  gROOT->SetStyle ("Plain") ;
27  gStyle->SetTextSize(0.5);
28  //gStyle->SetOptStat (1111111) ;
29  gStyle->SetOptStat (0) ;
30  //gStyle->SetOptFit (1111) ;
31  gStyle->SetOptFit (0) ;
32  gStyle->SetTitleBorderSize (0) ;
33  gStyle->SetTitleX (0.08) ;
34  gStyle->SetTitleY (0.97) ;
35  gStyle->SetPalette (1,0) ;
36  gStyle->SetStatColor (0) ;
37  gStyle->SetFrameFillStyle (0) ;
38  gStyle->SetFrameFillColor (0) ;
39  return ;
40 }
41 
42 
43 // -----------------------------------------------------------------
44 
45 
46 TCanvas * getGlobalCanvas (std::string name)
47 {
48  setStyle () ;
49  TCanvas * globalCanvas = static_cast<TCanvas*>
50  (gROOT->FindObject (name.c_str ())) ;
51  if (globalCanvas)
52  {
53  globalCanvas->Clear () ;
54  globalCanvas->UseCurrentStyle () ;
55  globalCanvas->SetWindowSize (700, 600) ;
56 
57  }
58  else
59  {
60  globalCanvas = new TCanvas (name.c_str (),name.c_str (), 700, 600) ;
61  }
62  return globalCanvas ;
63 }
64 
65 // -----------------------------------------------------------------
66 
67 
68 TFile * getGlobalTFile (std::string name)
69 {
70 // std::cout << "writing " << name << std::endl ;
71 // setStyle () ;
72  TFile * globalTFile = (TFile*) gROOT->FindObject (name.c_str()) ;
73  if (!globalTFile)
74  {
75 // std::cout << "does not exist. creating it " << std::endl;
76  globalTFile = new TFile (name.c_str(),"RECREATE") ;
77  }
78 
79  return globalTFile ;
80 }
81 
82 
83 // -----------------------------------------------------------------
84 
85 
86 int saveGlobalTFile (std::string name)
87 {
88  TFile * globalTFile = static_cast<TFile*>
89  (gROOT->FindObject (name.c_str ())) ;
90  if (!globalTFile) return 1 ;
91  globalTFile->Write () ;
92  globalTFile->Close () ;
93  delete globalTFile ;
94  return 0 ;
95 }
96 
97 
98 // -----------------------------------------------------------------
99 
100 
101 CLHEP::HepMatrix * getSavedMatrix (const std::string & name)
102 {
103  matrixSaver reader ;
104  CLHEP::HepMatrix * savedMatrix ;
105  if (reader.touch (name))
106  {
107  savedMatrix = static_cast<CLHEP::HepMatrix *> (
108  reader.getMatrix (name)
109  );
110  }
111  else
112  {
113  savedMatrix = new CLHEP::HepMatrix (SCMaxEta,SCMaxPhi,0) ;
114  }
115 
116  return savedMatrix ;
117 }
118 
119 
120 
121 //========================================================================
122 //da usare
123 //HepGeom::Point3D<double> TBimpactPoint = TBposition (amplitude,m_beamEnergy) ;
124 
125 /*
126 dove trovare il codice di Chiara in CMSSW, per la ricostruzione
127 della posizione:
128 
129 http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/RecoTBCalo/EcalTBAnalysisCoreTools/src/TBPositionCalc.cc?rev=1.1&cvsroot=CMSSW&content-type=text/vnd.viewcvs-markup
130 
131 */
132 
134 HepGeom::Point3D<Float_t>
135 TBposition (const Float_t amplit[7][7],
136  const Float_t beamEne,
137  const Float_t w0,
138  const Float_t x0,
139  const Float_t a0,
140  const Float_t sideX, // crystal geometry, in mm
141  const Float_t sideY)
142 {
143  // variables
144  Float_t caloX = 0. ;
145  Float_t caloY = 0. ;
146  Float_t sumWeight = 0. ;
147  Float_t depth = x0 * (log (beamEne)+ a0) ; // shower depthh, in mm
148  Float_t sin3 = 0.052335956 ; // sin (3 degrees) , sin3 = sin(3.*3.141592654/180.)
149 
150  Float_t invE3x3 = 1. / get3x3 (amplit) ;
151 
152  // loop over 3x3 crystals
153  for (int eta = 2; eta <= 4; eta++)
154  {
155  for (int phi = 2; phi <= 4; phi++)
156  {
157  Float_t weight = log( amplit[eta][phi] * invE3x3) + w0 ;
158  if ( weight>0 )
159  {
160  caloX += (eta-3) * sideX * weight;
161  caloY -= (phi-3) * sideY * weight;
162  sumWeight += weight;
163  }
164  }
165  }
166 
167  caloX /=sumWeight;
168  caloY /=sumWeight;
169 
170  // correction for shower depthh
171  caloX -= depth*sin3;
172  caloY -= depth*sin3;
173 
174  // FIXME the z set to zero
175  HepGeom::Point3D<Float_t> TBposition (caloX, caloY, 0) ;
176 
177  return TBposition ;
178 
179 }
180 
181 // -----------------------------------------------------------------
182 
183 
186 double get5x5 (const Float_t energy[7][7])
187 {
188  double total = 0. ;
189 
190  for (int eta=1 ; eta<6 ; ++eta)
191  for (int phi=1 ; phi<6 ; ++phi)
192  total += energy[eta][phi] ;
193 
194  return total ;
195 }
196 
197 
198 // -----------------------------------------------------------------
199 
200 
203 double get3x3 (const Float_t energy[7][7])
204 {
205  double total = 0. ;
206 
207  for (int eta=2 ; eta<5 ; ++eta)
208  for (int phi=2 ; phi<5 ; ++phi)
209  total += energy[eta][phi] ;
210 
211  return total ;
212 }
213 
214 
215 // -----------------------------------------------------------------
216 
217 
219 /* int parseConfigFile (const TString& config)
220 {
221  if (gConfigParser) return 1 ;
222 
223  std::cout << "parsing "
224  << config << " file"
225  << std::endl ;
226 
227 
228  gConfigParser = new ConfigParser () ;
229  if ( !(gConfigParser->init(config)) )
230  {
231  std::cout << "Analysis::parseConfigFile: Could not open configuration file "
232  << config << std::endl;
233  perror ("Analysis::parseConfigFile: ") ;
234  exit (-1) ;
235  }
236  gConfigParser->print () ;
237  return 0 ;
238 }*/
239 
240 
241 // -----------------------------------------------------------------
242 
243 
244 // per un certo eta, il cristallo puo' essere qualsiasi intero
245 // Calibrationtra xmin e xmax
246 // lo posso fissare solo sfruttando anche phi
247 int xtalFromEtaPhi (const int & myEta, const int & myPhi)
248 {
249  int xMin = 20 * myEta + 1 ;
250  int xMax = 20 * (myEta + 1) + 1 ;
251 
252  int myCryst = 999999 ;
253 
254  for (int x = xMin ; x < xMax ; x++)
255  {
256  if (phiFromXtal (x) == myPhi)
257  myCryst = x ;
258  }
259  return myCryst ;
260 }
261 
262 
263 // -----------------------------------------------------------------
264 
265 
266 int xtalFromiEtaiPhi (const int & iEta, const int & iPhi)
267 {
268  assert (iEta >= 1) ;
269  assert (iEta <= 85) ;
270  assert (iPhi >= 1) ;
271  assert (iPhi <= 20) ;
272  return 20 * (iEta-1) + 21 - iPhi ;
273 }
274 
275 
276 // -----------------------------------------------------------------
277 
278 
279 int etaFromXtal (const int & xtal)
280 {
281 // return floor (static_cast<double> ((xtal-1) / 20)) ;
282  return int (floor ((xtal-1) / 20) );
283 }
284 
285 
286 // -----------------------------------------------------------------
287 
288 
289 int phiFromXtal (const int & xtal)
290 {
291  int phi = (xtal-1) - 20 * etaFromXtal (xtal) ;
292  return (20 - phi - 1) ;
293 }
294 
295 
296 // -----------------------------------------------------------------
297 
298 
299 int ietaFromXtal (const int & xtal)
300 {
301  return etaFromXtal (xtal) + 1 ;
302 }
303 
304 
305 // -----------------------------------------------------------------
306 
307 
308 int iphiFromXtal (const int & xtal)
309 {
310  return phiFromXtal (xtal) + 1 ;
311 }
312 
313 
314 // -----------------------------------------------------------------
315 
316 
317 int extract (std::vector<int> * output , const std::string & dati)
318  {
319  std::ifstream _dati (dati.c_str ()) ;
320  // loop over the file
321  while (!_dati.eof())
322  {
323  // get the line
324  std::string dataline ;
325  do { getline (_dati, dataline,'\n') ; }
326  while (*dataline.begin () == '#') ;
327  std::stringstream linea (dataline) ;
328  // loop over the line
329  while (!linea.eof ())
330  {
331  int buffer = -1 ;
332  linea >> buffer ;
333  if (buffer != -1) output->push_back (buffer) ;
334  } // loop over the line
335  } // loop over the file
336  return output->size () ;
337  }
338 
339 
340 // -----------------------------------------------------------------
341 
342 
343 // FIXME questi eta, phi sono quelli della matrice CLHEP,
344 // FIXME non quelli del super-modulo, giusto?
345 int writeCalibTxt (const CLHEP::HepMatrix & AmplitudeMatrix,
346  const CLHEP::HepMatrix & SigmaMatrix,
347  const CLHEP::HepMatrix & StatisticMatrix,
348  std::string fileName)
349 {
350  // look for the reference crystal
351  double reference = 0. ;
352  for (int eta = 0 ; eta<SCMaxEta ; ++eta)
353  for (int phi = 0 ; phi<SCMaxPhi ; ++phi)
354  {
355  if (AmplitudeMatrix[eta][phi] &&
356  SigmaMatrix[eta][phi] < 100 /*FIXME sigmaCut*/)
357  {
358  reference = AmplitudeMatrix[eta][phi] ;
359  std::cout << "[InvMatrixUtils][writeCalibTxt] reference crystal: "
360  << "(" << eta << "," << phi << ") -> "
361  << reference << "\n" ;
362  break ;
363  }
364  }
365  if (!reference)
366  {
367  std::cerr << "ERROR: no calibration coefficients found" << std::endl ;
368  return 1 ;
369  }
370 
371  // open the file for output
372  std::ofstream txt_outfile ;
373  txt_outfile.open (fileName.c_str ()) ;
374  txt_outfile << "# xtal\tcoeff\tsigma\tevt\tisGood\n" ;
375 
376  // loop over the crystals
377  for (int eta = 0 ; eta<SCMaxEta ; ++eta)
378  for (int phi = 0 ; phi<SCMaxPhi ; ++phi)
379  {
380  int isGood = 1 ;
381  if (AmplitudeMatrix[eta][phi] == 0) isGood = 0 ;
382  if (SigmaMatrix[eta][phi] > 100 /*FIXME sigmaCut*/) isGood = 0 ;
383  txt_outfile << xtalFromEtaPhi (eta,phi)
384  << "\t" << AmplitudeMatrix[eta][phi]/reference
385  << "\t" << SigmaMatrix[eta][phi]
386  << "\t" << StatisticMatrix[eta][phi]
387  << "\t" << isGood <<"\n" ;
388  }
389 
390  // save and close the file
391  txt_outfile.close () ;
392  return 0 ;
393 }
394 
395 
396 // -----------------------------------------------------------------
397 
398 
399 int writeCMSSWCoeff (const CLHEP::HepMatrix & amplMatrix,
400  double calibThres,
401  float ERef,
402  const CLHEP::HepMatrix & sigmaMatrix,
403  const CLHEP::HepMatrix & statisticMatrix,
404  std::string fileName,
405  std::string genTag,
406  std::string method,
407  std::string version,
408  std::string type)
409 {
410  // open the file for output
411  std::ofstream txt_outfile ;
412  txt_outfile.open (fileName.c_str ()) ;
413  txt_outfile << "1\n" ; // super-module number
414  txt_outfile << "-1\n" ; // number of events
415  txt_outfile << genTag << "\n" ;
416  txt_outfile << method << "\n" ;
417  txt_outfile << version << "\n" ;
418  txt_outfile << type << "\n" ;
419 
420  double reference = ERef ;
421 
422  // loop over crystals
423  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
424  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
425  {
426  if (amplMatrix[eta][phi] <= calibThres)
427  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
428  << "\t" << 1
429  << "\t" << -1
430  << "\t" << -1
431  << "\t" << 0 <<"\n" ;
432  else
433  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
434  << "\t" << reference / amplMatrix[eta][phi]
435  << "\t" << sigmaMatrix[eta][phi]
436  << "\t" << statisticMatrix[eta][phi]
437  << "\t" << 1 <<"\n" ;
438  } // loop over crystals
439 
440  // save and close the file
441  txt_outfile.close () ;
442  return 0 ;
443 }
444 
445 
446 // -----------------------------------------------------------------
447 
448 
449 int writeCMSSWCoeff (const CLHEP::HepMatrix & amplMatrix,
450  double calibThres,
451  int etaRef, int phiRef,
452  const CLHEP::HepMatrix & sigmaMatrix,
453  const CLHEP::HepMatrix & statisticMatrix,
454  std::string fileName,
455  std::string genTag,
456  std::string method,
457  std::string version,
458  std::string type)
459 {
460  // open the file for output
461  std::ofstream txt_outfile ;
462  txt_outfile.open (fileName.c_str ()) ;
463  txt_outfile << "1\n" ; // super-module number
464  txt_outfile << "-1\n" ; // number of events
465  txt_outfile << genTag << "\n" ;
466  txt_outfile << method << "\n" ;
467  txt_outfile << version << "\n" ;
468  txt_outfile << type << "\n" ;
469 
470  if (amplMatrix[etaRef-1][phiRef-1] == 0)
471  {
472  std::cerr << "The reference crystal: ("
473  << etaRef << "," << phiRef
474  << ") is out of range\n" ;
475  return 1 ;
476  }
477  double reference = amplMatrix[etaRef-1][phiRef-1] ;
478 
479  // loop over crystals
480  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
481  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
482  {
483  if (amplMatrix[eta][phi] <= calibThres)
484  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
485  << "\t" << 1
486  << "\t" << -1
487  << "\t" << -1
488  << "\t" << 0 <<"\n" ;
489  else
490  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
491  << "\t" << reference / amplMatrix[eta][phi]
492  << "\t" << sigmaMatrix[eta][phi]
493  << "\t" << statisticMatrix[eta][phi]
494  << "\t" << 1 <<"\n" ;
495  } // loop over crystals
496 
497  // save and close the file
498  txt_outfile.close () ;
499  return 0 ;
500 }
501 
502 
503 // -----------------------------------------------------------------
504 
505 
506 int translateCoeff (const CLHEP::HepMatrix & calibcoeff,
507  const CLHEP::HepMatrix & sigmaMatrix,
508  const CLHEP::HepMatrix & statisticMatrix,
509  std::string SMnumber,
510  double calibThres,
511  std::string fileName,
512  std::string genTag,
513  std::string method,
514  std::string version,
515  std::string type)
516 {
517  // open the file for output
518  std::ofstream txt_outfile ;
519  txt_outfile.open (fileName.c_str ()) ;
520  txt_outfile << SMnumber << "\n" ; // super-module number
521  txt_outfile << "-1\n" ; // number of events
522  txt_outfile << genTag << "\n" ;
523  txt_outfile << method << "\n" ;
524  txt_outfile << version << "\n" ;
525  txt_outfile << type << "\n" ;
526 
527  // loop over crystals
528  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
529  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
530  {
531  if (calibcoeff[eta][phi] < calibThres)
532  {
533  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
534  << "\t" << 1
535  << "\t" << -1
536  << "\t" << -1
537  << "\t" << 0 <<"\n" ;
538  std::cout << "[translateCoefff][" << SMnumber
539  << "]\t WARNING crystal " << xtalFromiEtaiPhi (eta+1,phi+1)
540  << " calib coeff below threshold: "
541  << "\t" << 1
542  << "\t" << -1
543  << "\t" << -1
544  << "\t" << 0 <<"\n" ;
545  }
546  else
547  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
548  << "\t" << calibcoeff[eta][phi]
549  << "\t" << sigmaMatrix[eta][phi]
550  << "\t" << statisticMatrix[eta][phi]
551  << "\t" << 1 <<"\n" ;
552  } // loop over crystals
553 
554  // save and close the file
555  txt_outfile.close () ;
556  return 0 ;
557 }
558 
559 
560 // -----------------------------------------------------------------
561 
562 
563 int readCMSSWcoeff (CLHEP::HepMatrix & calibcoeff,
564  const std::string & inputFileName,
565  double defaultVal)
566 {
567  std::ifstream CMSSWfile ;
568  CMSSWfile.open (inputFileName.c_str ()) ;
569  std::string buffer ;
570  CMSSWfile >> buffer ;
571  CMSSWfile >> buffer ;
572  CMSSWfile >> buffer ;
573  CMSSWfile >> buffer ;
574  CMSSWfile >> buffer ;
575  CMSSWfile >> buffer ;
576  while (!CMSSWfile.eof ())
577  {
578  int xtalnum ;
579  CMSSWfile >> xtalnum ;
580  double coeff ;
581  CMSSWfile >> coeff ;
582  double buffer ;
583  CMSSWfile >> buffer ;
584  int good ;
585  CMSSWfile >> good ;
586  CMSSWfile >> good ;
587  if (!good) coeff = defaultVal ; //FIXME 0 o 1?
588  calibcoeff[etaFromXtal (xtalnum)][phiFromXtal (xtalnum)] = coeff ;
589  }
590  return 0 ;
591 
592 }
593 
594 
595 // -----------------------------------------------------------------
596 
597 
598 int readCMSSWcoeffForComparison (CLHEP::HepMatrix & calibcoeff,
599  const std::string & inputFileName)
600 {
601  std::ifstream CMSSWfile ;
602  CMSSWfile.open (inputFileName.c_str ()) ;
603  std::string buffer ;
604  CMSSWfile >> buffer ;
605  CMSSWfile >> buffer ;
606  CMSSWfile >> buffer ;
607  CMSSWfile >> buffer ;
608  CMSSWfile >> buffer ;
609  CMSSWfile >> buffer ;
610  while (!CMSSWfile.eof ())
611  {
612  int xtalnum ;
613  CMSSWfile >> xtalnum ;
614  double coeff ;
615  CMSSWfile >> coeff ;
616  double buffer ;
617  CMSSWfile >> buffer ;
618  int good ;
619  CMSSWfile >> good ;
620  CMSSWfile >> good ;
621  if (!good) coeff = 0. ; //FIXME 0 o 1?
622  calibcoeff[etaFromXtal (xtalnum)][phiFromXtal (xtalnum)] = coeff ;
623  }
624  return 0 ;
625 
626 }
627 
628 
629 // -----------------------------------------------------------------
630 
631 
632 TH1D * smartProfile (TH2F * strip, double width)
633 {
634  TProfile * stripProfile = strip->ProfileX () ;
635 
636  // (from FitSlices of TH2.h)
637 
638  double xmin = stripProfile->GetXaxis ()->GetXmin () ;
639  double xmax = stripProfile->GetXaxis ()->GetXmax () ;
640  int profileBins = stripProfile->GetNbinsX () ;
641 
642  std::string name = strip->GetName () ;
643  name += "_smart" ;
644  TH1D * prof = new TH1D
645  (name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ;
646 
647  int cut = 0 ; // minimum number of entries per fitted bin
648  int nbins = strip->GetXaxis ()->GetNbins () ;
649  int binmin = 1 ;
650  int ngroup = 1 ; // bins per step
651  int binmax = nbins ;
652 
653  // loop over the strip bins
654  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
655  {
656  TH1D *hpy = strip->ProjectionY ("_temp",bin,bin+ngroup-1,"e") ;
657  if (hpy == 0) continue ;
658  int nentries = Int_t (hpy->GetEntries ()) ;
659  if (nentries == 0 || nentries < cut) {delete hpy ; continue ;}
660 
661  Int_t biny = bin + ngroup/2 ;
662 
663  hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (),
664  hpy->GetMean () + width * hpy->GetRMS ()) ;
665  prof->Fill (strip->GetXaxis ()->GetBinCenter (biny),
666  hpy->GetMean ()) ;
667  prof->SetBinError (biny,hpy->GetRMS()) ;
668 
669  delete hpy ;
670  } // loop over the bins
671 
672  delete stripProfile ;
673  return prof ;
674 }
675 
676 
677 // -----------------------------------------------------------------
678 
679 
680 TH1D * smartGausProfile (TH2F * strip, double width)
681 {
682  TProfile * stripProfile = strip->ProfileX () ;
683 
684  // (from FitSlices of TH2.h)
685 
686  double xmin = stripProfile->GetXaxis ()->GetXmin () ;
687  double xmax = stripProfile->GetXaxis ()->GetXmax () ;
688  int profileBins = stripProfile->GetNbinsX () ;
689 
690  std::string name = strip->GetName () ;
691  name += "_smartGaus" ;
692  TH1D * prof = new TH1D
693  (name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ;
694 
695  int cut = 0 ; // minimum number of entries per fitted bin
696  int nbins = strip->GetXaxis ()->GetNbins () ;
697  int binmin = 1 ;
698  int ngroup = 1 ; // bins per step
699  int binmax = nbins ;
700 
701  // loop over the strip bins
702  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
703  {
704  TH1D *hpy = strip->ProjectionY ("_temp",bin,bin+ngroup-1,"e") ;
705  if (hpy == 0) continue ;
706  int nentries = Int_t (hpy->GetEntries ()) ;
707  if (nentries == 0 || nentries < cut) {delete hpy ; continue ;}
708 
709  Int_t biny = bin + ngroup/2 ;
710 
711  TF1 * gaussian = new TF1 ("gaussian","gaus", hpy->GetMean () - width * hpy->GetRMS (),
712  hpy->GetMean () + width * hpy->GetRMS ()) ;
713  gaussian->SetParameter (1,hpy->GetMean ()) ;
714  gaussian->SetParameter (2,hpy->GetRMS ()) ;
715  hpy->Fit ("gaussian","RQL") ;
716 
717  hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (),
718  hpy->GetMean () + width * hpy->GetRMS ()) ;
719  prof->Fill (strip->GetXaxis ()->GetBinCenter (biny),
720  gaussian->GetParameter (1)) ;
721  prof->SetBinError (biny,gaussian->GetParameter (2)) ;
722 
723  delete gaussian ;
724  delete hpy ;
725  } // loop over the bins
726 
727  delete stripProfile ;
728  return prof ;
729 }
730 
731 
732 // -----------------------------------------------------------------
733 
734 
735 TH1D * smartError (TH1D * strip)
736 {
737 
738  double xmin = strip->GetXaxis ()->GetXmin () ;
739  double xmax = strip->GetXaxis ()->GetXmax () ;
740  int stripsBins = strip->GetNbinsX () ;
741 
742  std::string name = strip->GetName () ;
743  name += "_error" ;
744  TH1D * error = new TH1D
745  (name.c_str (),strip->GetTitle (),stripsBins,xmin,xmax) ;
746 
747  int binmin = 1 ;
748  int ngroup = 1 ; // bins per step
749  int binmax = stripsBins ;
750  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
751  {
752  double dummyError = strip->GetBinError (bin) ;
753  error->SetBinContent (bin,dummyError) ;
754  }
755  return error;
756 }
757 
758 
759 // -----------------------------------------------------------------
760 
761 
762 double effectiveSigma (TH1F & histogram, int vSteps)
763 {
764  double totInt = histogram.Integral () ;
765  int maxBin = histogram.GetMaximumBin () ;
766  int maxBinVal = int(histogram.GetBinContent (maxBin)) ;
767  int totBins = histogram.GetNbinsX () ;
768  double area = totInt ;
769  double threshold = 0 ;
770  double vStep = maxBinVal / vSteps ;
771  int leftBin = 1 ;
772  int rightBin = totBins - 1 ;
773  //loop over the vertical range
774  while (area/totInt > 0.683)
775  {
776  threshold += vStep ;
777  // loop toward the left
778  for (int back = maxBin ; back > 0 ; --back)
779  {
780  if (histogram.GetBinContent (back) < threshold)
781  {
782  leftBin = back ;
783  break ;
784  }
785  } // loop toward the left
786 
787  // loop toward the right
788  for (int fwd = maxBin ; fwd < totBins ; ++fwd)
789  {
790  if (histogram.GetBinContent (fwd) < threshold)
791  {
792  rightBin = fwd ;
793  break ;
794  }
795  } // loop toward the right
796  area = histogram.Integral (leftBin,rightBin) ;
797  } //loop over the vertical range
798 
799  histogram.GetXaxis ()->SetRange (leftBin,rightBin) ;
800  // double sigmaEff = histogram.GetRMS () ;
801  double halfWidthRange = 0.5 * (histogram.GetBinCenter (rightBin) - histogram.GetBinCenter (leftBin)) ;
802  return halfWidthRange ;
803 }
804 
805 
806 // -----------------------------------------------------------------
807 
808 
809 std::pair<int,int> findSupport (TH1F & histogram, double thres)
810 {
811  int totBins = histogram.GetNbinsX () ;
812  if (thres >= histogram.GetMaximum ())
813  return std::pair<int,int> (0, totBins) ;
814 
815  int leftBin = totBins - 1 ;
816  // search from left for the minimum
817  for (int bin=1 ; bin<totBins ; ++bin)
818  {
819  if (histogram.GetBinContent (bin) > thres)
820  {
821  leftBin = bin ;
822  break ;
823  }
824  } // search from left for the minimum
825  int rightBin = 1 ;
826  // search from right for the maximum
827  for (int bin=totBins - 1 ; bin> 0 ; --bin)
828  {
829  if (histogram.GetBinContent (bin) > thres)
830  {
831  rightBin = bin ;
832  break ;
833  }
834  } // search from right for the maximum
835  return std::pair<int,int> (leftBin,rightBin) ;
836 }
837 
838 
839 // -----------------------------------------------------------------
840 
841 
842 void
844  CLHEP::HepMatrix * input,
845  double Default)
846 {
847  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
848  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
849  {
850  if ((*input)[eta][phi])
851  output[eta][phi] = (*input)[eta][phi] ;
852  else output[eta][phi] = Default ;
853  }
854  return ;
855 }
856 
857 // -----------------------------------------------------------------
858 
859 double etaCorrE1E25 (int eta)
860 {
861  double p0 = 0.807883 ;
862  double p1 = 0.000182551 ;
863  double p2 = -5.76961e-06 ;
864  double p3 = 7.41903e-08 ;
865  double p4 = -2.25384e-10 ;
866 
867  double corr ;
868  if (eta < 6) corr = p0 ;
869  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
870  return corr/p0 ;
871 }
872 // -----------------------------------------------------------------
873 
874 double etaCorrE1E49 (int eta)
875 {
876  double p0 = 0.799895 ;
877  double p1 = 0.000235487 ;
878  double p2 = -8.26496e-06 ;
879  double p3 = 1.21564e-07 ;
880  double p4 = -4.83286e-10 ;
881 
882  double corr ;
883  if (eta < 8) corr = p0 ;
884  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
885  return corr/p0 ;
886 }
887 // -----------------------------------------------------------------
888 
889 double etaCorrE1E9 (int eta)
890 {
891  if (eta < 4) return 1.0 ;
892  // grazie Paolo
893  double p0 = 0.834629 ;
894  double p1 = 0.00015254 ;
895  double p2 = -4.91784e-06 ;
896  double p3 = 6.54652e-08 ;
897  double p4 = -2.4894e-10 ;
898 
899  double corr ;
900  if (eta < 6) corr = p0 ;
901  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
902  return corr/p0 ;
903 }
904 
type
Definition: HCALResponse.h:22
TH1D * smartError(TH1D *strip)
#define SCMaxEta
#define Default
Definition: vmac.h:109
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
int readCMSSWcoeff(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName, double defaultVal=1.)
#define SCMaxPhi
double etaCorrE1E49(int eta)
void mtrTransfer(double output[SCMaxEta][SCMaxPhi], CLHEP::HepMatrix *input, double Default)
int readCMSSWcoeffForComparison(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName)
double effectiveSigma(TH1F &histogram, int vSteps=100)
T eta() const
void setStyle()
int iphiFromXtal(const int &xtal)
return((rh^lh)&mask)
int writeCMSSWCoeff(const CLHEP::HepMatrix &amplMatrix, double calibThres, float ERef, const CLHEP::HepMatrix &sigmaMatrix, const CLHEP::HepMatrix &statisticMatrix, std::string fileName="calibOutput.txt", std::string genTag="CAL_GENTAG", std::string method="CAL_METHOD", std::string version="CAL_VERSION", std::string type="CAL_TYPE")
TH1D * smartProfile(TH2F *strip, double width)
int phiFromXtal(const int &xtal)
TH1D * smartGausProfile(TH2F *strip, double width)
float threshold
Definition: crabWrap.py:319
int writeCalibTxt(const CLHEP::HepMatrix &AmplitudeMatrix, const CLHEP::HepMatrix &SigmaMatrix, const CLHEP::HepMatrix &StatisticMatrix, std::string fileName="calibOutput.txt")
save (read) CLHEP::HepMatrix to (from) text files
Definition: matrixSaver.h:26
double p4[4]
Definition: TauolaWrapper.h:92
TFile * getGlobalTFile(std::string name="Inv MatrixTFile.root")
int touch(std::string inputFileName)
Definition: matrixSaver.cc:138
TCanvas * getGlobalCanvas(std::string name="Inv MatrixCanvas")
double p2[4]
Definition: TauolaWrapper.h:90
int translateCoeff(const CLHEP::HepMatrix &calibcoeff, const CLHEP::HepMatrix &sigmaMatrix, const CLHEP::HepMatrix &statisticMatrix, std::string SMnumber="1", double calibThres=0.01, std::string fileName="calibOutput.txt", std::string genTag="CAL_GENTAG", std::string method="CAL_METHOD", std::string version="CAL_VERSION", std::string type="CAL_TYPE")
JetCorrectorParameters corr
Definition: classes.h:9
tuple input
Definition: collect_tpl.py:10
int saveGlobalTFile(std::string name="Inv MatrixFile.root")
CLHEP::HepGenMatrix * getMatrix(std::string inputFileName)
Definition: matrixSaver.cc:147
int extract(std::vector< int > *output, const std::string &dati)
tuple cut
Definition: align_tpl.py:88
double get3x3(const Float_t energy[7][7])
int ietaFromXtal(const int &xtal)
Log< T >::type log(const T &t)
Definition: Log.h:22
double get5x5(const Float_t energy[7][7])
double p1[4]
Definition: TauolaWrapper.h:89
std::pair< int, int > findSupport(TH1F &histogram, double thres=0.)
double etaCorrE1E9(int eta)
tuple cout
Definition: gather_cfg.py:41
CLHEP::HepMatrix * getSavedMatrix(const std::string &name)
int xtalFromEtaPhi(const int &myEta, const int &myPhi)
double etaCorrE1E25(int eta)
HepGeom::Point3D< Float_t > TBposition(const Float_t amplit[7][7], const Float_t beamEne, const Float_t w0=4.0, const Float_t x0=8.9, const Float_t a0=6.2, const Float_t sideX=24.06, const Float_t sideY=22.02)
int etaFromXtal(const int &xtal)
double p3[4]
Definition: TauolaWrapper.h:91
Definition: DDAxes.h:10