Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
#ifndef MusEcal_hh
#define MusEcal_hh

#include <map>

//
// MusEcal : Monitoring and Useful Survey of CMS Ecal
//                  Clever Analysis of Laser
//
// Authors  : Gautier Hamel de Monchenault and Julie Malcles, Saclay 
//
#include <TROOT.h>
#include <TH1.h>
#include <TH2.h>
#include <TTree.h>
#include <TFile.h>

#include "../../interface/ME.h"

class MERunManager;
class MERun;
class MEChannel;

// #include "MEIntervals.hh"
// #include "MECorrector2Var.hh"

class MusEcal
{

public:

  typedef std::map< ME::Time, MERun* >              RunMap;
  typedef std::map< ME::Time, float >               FloatTimeMap;
  typedef std::map< ME::Time, bool >                BoolTimeMap;
  typedef std::pair< float, bool >              Var;
  typedef std::map< ME::Time, Var >                 VarTimeMap;
  typedef std::vector<Var>                      VarVec;
  typedef std::map< ME::Time, VarVec* >             VarVecTimeMap;
  typedef RunMap::iterator             RunIterator;
  typedef RunMap::const_iterator  RunConstIterator;

  enum HistCateg  { iH_APD=0, iH_PN, iH_MTQ, iSizeHC };
  enum HistType   { iHIST=0, iVS_CHANNEL, iMAP, iSizeHT }; 

  // MusEcal: Laser variables
  enum { iNLS, iCorNLS, iAPDoPNA, iAPDoPNB, iAPDoPN, iAPD, iAPDTime, 
	 iPNA, iPNB, iPNBoPNA, iAlphaBeta, iAlphaBeta_used, iShapeCor, 
	 iMTQTrise, iMTQAmpl, iMTQFwhm, iMTQFw20, iMTQFw80, iMTQTime,
	 iSizeLV };  

  // MusEcal: TP variables
  enum { iTPAPD_0, iTPAPD_1, iTPAPD_2, iTPPNA_0, iTPPNA_1, iTPPNB_0, iTPPNB_1, iSizeTPV };  

  // Zoom
  enum { iOneHundredPercent, iFiftyPercent, iThirtyPercent, iTenPercent,
	 iFivePercent, iThreePercent, iPercent, 
	 iFivePerMil, iThreePerMil, iPerMil, iZero };

  static TString historyVarTitle[iSizeLV];
  static TString historyVarName[iSizeLV];
  static int iGVar[iSizeLV];
  static int historyVarZoom[ME::iSizeC][iSizeLV];
  static int historyVarColor[iSizeLV];
  static TString historyTPVarName[iSizeTPV];
  static TString historyTPVarTitle[iSizeTPV];
  static int iGTPVar[iSizeTPV];
  static int historyTPVarColor[iSizeTPV];
  static int historyTPVarZoom[iSizeTPV];
  static TString zoomName[ iZero ];
  static double zoomRange[ iZero ];
  static TString mgrName( int lmr, int type, int color );
  static int firstRun;
  static int lastRun;

  // contructors/destructor
  MusEcal( int type=ME::iLaser, int color=ME::iBlue );
  virtual  ~MusEcal();

  // access to run manager for given laser monitoring region
  MERunManager* runMgr( int lmr ) { return runMgr(  lmr, _type, _color ); }
  MERunManager* runMgr()          { return runMgr( _lmr, _type, _color ); }

  // access to run manager for current laser monitoring region
  MERunManager* curMgr()          { return runMgr( _lmr ); }

  // set type (Laser, TestPulse, Pedestal) and color if applicable
  virtual void setType( int type, int color=ME::iBlue );

  // set laser monitoring region
  virtual void setLMRegion( int lmr );

  // set current time
  virtual void setTime( ME::Time );
  
  // set granularity and channel
  virtual void setChannel( MEChannel* );
  virtual void setChannel( int ig, int ieta, int iphi, bool useEtaPhi=true );

  // channel navigation
  void oneLevelUp();

  // set default time
  void setDefaultTime();

  // set run & sequence in run
  void setRunAndSequence( unsigned int run, int seq=1 );

  // next sequence
  bool nextSequence();

  // set laser monitoring variable
  void setVar( int var=MusEcal::iAPD ) { _var = var; _zoom = 0; }
  
  // dump vector for current channel and variable (ascii)
  void dumpVector( int ivar );

  // histograms
  void histConfig();
  void bookHistograms();
  void bookEBAPDHistograms();
  void bookEBPNHistograms();
  void bookEEAPDHistograms();
  void bookEEPNHistograms();
  void fillHistograms();
  void fillEBGlobalHistograms();
  void fillEBLocalHistograms();
  void fillEEGlobalHistograms();
  void fillEELocalHistograms();
  void writeGlobalHistograms();

  // verbosity
  static bool verbose;

protected:

  virtual void refresh();

  // map of run managers
  std::map< TString, MERunManager* > _runMgr;

  // access to run managers
  MERunManager* runMgr( int lmr, int type, int color );

  // current monitoring region
  int _lmr;
  bool isBarrel();

  // current run type (Laser, Test Pulse, Pedestal)
  int _type; 

  // current color
  int _color;

  // current channel or group of channels
  MEChannel* _leaf; 

  // current level of detector  
  int _ig;         

  // reference time
  ME::Time _time;

  // current laser monitoring variable
  int _var;
  
  // current zoom
  int _zoom;

  // debug
  bool _debug;

  // GUI
  bool _isGUI;

  //
  // Histograms
  //
  bool _histoBooked;
  bool _ebHistoBooked;
  bool _eeHistoBooked;

  TFile* _febgeom;
  TH2 *_eb_h, *_eb_loc_h;
  std::map< TString, TH1* > _eb_m;
  std::map< TString, TH1* > _eb_loc_m;

  TFile* _feegeom;
  TH2* _ee_h; 
  TH2* _ee_loc_h[10];
  std::map< TString, TH1* > _ee_m;
  std::map< TString, TH1* > _ee_loc_m;

  // histogam limits
  std::map< TString,  int  > _eb_nbin;
  std::map< TString, float > _eb_min;
  std::map< TString, float > _eb_max;
  std::map< TString,  int  > _ee_nbin;
  std::map< TString, float > _ee_min;
  std::map< TString, float > _ee_max;
  int   hist_nbin( TString& );
  float hist_min(  TString& );
  float hist_max(  TString& );

  TTree* _seq_t;    // sequence rootuple
  Int_t _seq_run;   // run number
  Int_t _seq_lb;    // lumi block of first LMR
  Int_t _seq_tbeg;  // time at beginning of sequence
  Int_t _seq_tlmr[92]; // array of times, -1 LMR not present

  TBranch        *b_seq_run;   //!
  TBranch        *b_seq_lb;   //!
  TBranch        *b_seq_tbeg;   //!
  TBranch        *b_seq_tlmr[92];   //!

//   // validity intervals
//   void setMtqVar( int mtqVar0, int mtqVar1, int mtqLevel );
//   void setPnVar(  int  pnVar0, int  pnVar1, int  pnLevel );

//   MEIntervals* mtqIntervals( int type );
//   MEKeyInterval* topMtqInterval( int type ) { return mtqIntervals(type)->topInterval(); }

//   MEIntervals* pnIntervals( int type );
//   MEKeyInterval* topPnInterval( int type ) { return pnIntervals(type)->topInterval(); }
//   std::map< MEKeyInterval*, int >& choices( int type ) { return _choices[type]; }
 
//   // create corrections
//   virtual void createCorrectors();
  
//   // apply corrections
//   void applyCorrections( MELeaf* leaf, int type, int var0, int var1, 
// 			 std::vector< MERunKey>& keys, std::vector< MERunKey>& altkeys,
// 			 std::vector< double >& val, std::vector< double >& cor_val, std::vector< double >& glued_val, std::vector< double >& cor_and_glued_val,
// 			 std::vector< bool   >&  ok, std::vector< bool   >& cor_ok , std::vector< bool   >& glued_ok,  std::vector< bool   >& cor_and_glued_ok  );

//   void rabouteVector( MEKeyInterval*, int level, const std::vector< MERunKey >& keys, std::vector< double >& val, std::vector< bool >& ok, 
// 		      MERunKey curKey=0, unsigned nbuf=2, unsigned nave=10 );
//   void rabouteVector( MEKeyInterval*, int level, MEVarMap& val, MEBoolMap& ok, 
// 		      MERunKey curKey=0, unsigned nbuf=2, unsigned nave=10 );
  
//   void dumpHistory();

//   // current variable
//   int _var;
  
//   // current zoom
//   int _zoom;

//   // current channel of group of channels
//   bool _newVar;
//   bool _newSelection;
//   bool _newRange;
//   bool _newReference;
//   bool _iSelect;

//   // validity intervals the Side level, based on MATACQ variables
//   bool _mtqTwoVar;
//   int  _mtqLevel;
//   int  _mtqVar0;
//   int  _mtqVar1;

//   // validity intervals at the Module level, based on the PNA and PNB signal variations
//   bool _pnTwoVar;
//   int  _pnLevel;
//   int  _pnVar0;
//   int  _pnVar1;

//   // variable to correct against
//   int _corVar0;
//   int _corVar1;
//   int _corZoom0;
//   int _corZoom1;
//   unsigned _corFitDegree;
//   double _corX0;
//   double _corY0;
//   std::vector< double > _corBeta;
 
//   // intervals, as a function of the Leaf (at the Side or Module level)
//   std::map< MELeaf*, MEIntervals* > _intervals[MusEcalHist::iSizeT];

//   // choice of variables in PN intervals
//   std::map< MEKeyInterval*, int > _choices[MusEcalHist::iSizeT];

  
//   // range range and normalisation
//   bool _normalize;

//   // reference key
//   MERunKey _refKey[MusEcalHist::iSizeT];


  
//   virtual void buildMtqIntervals( int type );
//   virtual void buildPnIntervals( int type );

public:

  // declare to ROOT dictionary
  ClassDef(MusEcal,0) // MusEcal -- Monitoring utility for survey of Ecal
};

#endif