CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CalibCalorimetry/EcalLaserAnalyzer/src/MELaserPrim.cc

Go to the documentation of this file.
00001 #define MELaserPrim_cxx
00002 #include <assert.h>
00003 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MELaserPrim.h"
00004 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEGeom.h"
00005 #include <cassert>
00006 #include <cstdlib>
00007 
00008 TString MELaserPrim::apdpn_arrayName[MELaserPrim::iSizeArray_apdpn] = {"APD", "APDoPN", "APDoPNA", "APDoPNB","APDoAPD","APDoAPDA", "APDoAPDB", "Time"};
00009 TString MELaserPrim::apdpn_varName[MELaserPrim::iSize_apdpn] = { "Mean", "RMS", "M3", "Nevt", "Min", "Max"};
00010 TString MELaserPrim::apdpn_varUnit[MELaserPrim::iSizeArray_apdpn][MELaserPrim::iSize_apdpn] = 
00011  
00012   { { " (ADC Counts)", " (ADC Counts)", " (ADC Counts)" ,"", " (ADC Counts)", " (ADC Counts)"},
00013     {"", "", "", "", "", ""},
00014     {"", "", "", "", "", ""},
00015     {"", "", "", "", "", ""},
00016     {"", "", "", "", "", ""},
00017     {"", "", "", "", "", ""},
00018     {" (25 ns)", " (25 ns)", " (25 ns)", "", " (25 ns)", " (25 ns)"} };
00019 TString MELaserPrim::apdpn_extraVarName[MELaserPrim::iSizeExtra_apdpn] = { "ShapeCor" };
00020 TString MELaserPrim::apdpn_extraVarUnit[MELaserPrim::iSizeExtra_apdpn] = { "" };
00021 TString MELaserPrim::ab_varName[MELaserPrim::iSize_ab] = { "alpha", "beta", "width", "chi2" };
00022 TString MELaserPrim::mtq_varName[MELaserPrim::iSize_mtq] = {"peak", "sigma", "fit", "ampl", "trise", "fwhm", "fw20", "fw80", "sliding" };
00023 TString MELaserPrim::mtq_varUnit[MELaserPrim::iSize_mtq] = 
00024   {"(nanoseconds)", "(nanoseconds)", "(nanoseconds)", 
00025    "(ADC counts)", "(nanoseconds)",
00026    "(nanoseconds)", "(nanoseconds)", "(nanoseconds)", "(ADC counts)"};
00027 
00028 TString MELaserPrim::separator = "__";
00029 
00030 //ClassImp( MELaserPrim )
00031 
00032 MELaserPrim::MELaserPrim(  ME::Header header, ME::Settings settings, 
00033                            const char* inpath, const char* outfile )
00034 : init_ok(false), _isBarrel(true), _inpath(inpath), _outfile(outfile)
00035 {
00036   apdpn_file =0;
00037   ab_file    =0;
00038   mtq_file   =0;
00039   tpapd_file =0;
00040   apdpn_tree =0;
00041   ab_tree    =0;
00042   pn_tree    =0;
00043   mtq_tree   =0;
00044   tpapd_tree =0;
00045   tppn_tree  =0;
00046   ixmin      =0;
00047   ixmax      =0;
00048   iymin      =0;
00049   iymax      =0;
00050 
00051   _dcc    = header.dcc;
00052   _side   = header.side;
00053   _run    = header.run;
00054   _lb     = header.lb;
00055   _events = header.events;
00056   _ts     = header.ts_beg;
00057   _ts_beg = header.ts_beg;
00058   _ts_end = header.ts_end;
00059 
00060   _type     = settings.type;
00061   _color    = settings.wavelength;
00062   _power    = settings.power;
00063   _filter   = settings.filter;
00064   _delay    = settings.delay;
00065   _mgpagain = settings.mgpagain; 
00066   _memgain  = settings.memgain; 
00067 
00068   if( _type==ME::iLaser )
00069     {
00070       _primStr     = lmfLaserName( ME::iLmfLaserPrim,   _type, _color )+separator;
00071       _pnPrimStr   = lmfLaserName( ME::iLmfLaserPnPrim, _type, _color )+separator;
00072       _pulseStr    = lmfLaserName( ME::iLmfLaserPulse,  _type, _color )+separator;
00073     }
00074   else if( _type==ME::iTestPulse )
00075     {
00076       _tpPrimStr    = lmfLaserName( ME::iLmfTestPulsePrim, _type   )+separator;
00077       _tpPnPrimStr  = lmfLaserName( ME::iLmfTestPulsePnPrim, _type )+separator;
00078     }
00079 
00080   _lmr = ME::lmr( _dcc, _side );
00081   ME::regionAndSector( _lmr, _reg, _sm, _dcc, _side );    
00082   _isBarrel = (_reg==ME::iEBM || _reg==ME::iEBP);
00083   _sectorStr  = ME::smName( _lmr );
00084   _regionStr  = _sectorStr;
00085   _regionStr += "_"; _regionStr  += _side;
00086 
00087   init();
00088   bookHistograms();
00089   //fillHistograms();
00090   //writeHistograms();
00091 }
00092 
00093 TString
00094 MELaserPrim::channelViewName( int iname )
00095 {
00096   switch( iname )
00097     {
00098     case iECAL:                 return "ECAL";
00099     case iECAL_LMR:             return "ECAL_LMR";
00100     case iEB_crystal_number:    return "EB_crystal_number";
00101     case iEB_LM_LMM:            return "EB_LM_LMM";
00102     case iEB_LM_PN:             return "EB_LM_PN";
00103     case iEE_crystal_number:    return "EE_crystal_number";
00104     case iEE_LM_LMM:            return "EE_LM_LMM";
00105     case iEE_LM_PN:             return "EE_LM_PN";
00106     default:
00107       abort();
00108     }
00109   return "";
00110 }
00111 
00112 int
00113 MELaserPrim::logicId( int channelView, int id1, int id2 )
00114 {
00115   assert( channelView>=iECAL && channelView<iSize_cv );
00116   return 1000000*channelView + 10000*id1 + id2;
00117 }
00118 
00119 bool 
00120 MELaserPrim::getViewIds( int logic_id, int& channelView, int& id1, int& id2 )
00121 {
00122   bool out = true;
00123   int channelView_ = logic_id/1000000;
00124   if( channelView!=0 && channelView_!=channelView ) out=false;
00125   channelView = channelView_;
00126   id1 = (logic_id%1000000)/10000;
00127   id2 = logic_id%10000;
00128   return out;
00129 }
00130 
00131 void 
00132 MELaserPrim::init()
00133 {
00134   bool verbose_ = false;
00135 
00136   if( _inpath=="0" )
00137     {
00138       if( verbose_ ) std::cout << "no input file" << std::endl;
00139       init_ok = true;
00140       return; // GHM
00141     }
00142 
00143   TString cur(_inpath);
00144   if( !cur.EndsWith("/") ) cur+="/";
00145 
00146   if( _type==ME::iLaser )
00147     {
00148       TString _APDPN_fname =cur; _APDPN_fname += "APDPN_LASER.root";
00149       TString _AB_fname    =cur; _AB_fname    += "AB.root"; 
00150       TString _MTQ_fname   =cur; _MTQ_fname   += "MATACQ.root";
00151 
00152       bool apdpn_ok, ab_ok, pn_ok, mtq_ok;
00153       apdpn_ok=false; ab_ok=false; pn_ok=false; mtq_ok=false;
00154 
00155       FILE *test; 
00156       test = fopen( _APDPN_fname,"r");  
00157       if (test) {
00158         apdpn_ok = true;
00159         pn_ok = true;
00160         fclose( test );
00161       }
00162       test = fopen( _AB_fname,"r");  
00163       if (test) 
00164         {
00165           ab_ok = true;
00166           fclose( test );
00167         }
00168       test = fopen( _MTQ_fname,"r");  
00169       if (test) 
00170         {
00171           mtq_ok = true;
00172           fclose( test );
00173         }
00174 
00175       if(apdpn_ok) apdpn_file = TFile::Open( _APDPN_fname );
00176       if(ab_ok)    ab_file    = TFile::Open(    _AB_fname );
00177       if(mtq_ok)  mtq_file   = TFile::Open(   _MTQ_fname );
00178 
00179       if( verbose_ )
00180         {
00181           std::cout << _APDPN_fname << " ok=" << apdpn_ok << std::endl;
00182           std::cout << _AB_fname    << " ok=" << ab_ok    << std::endl;
00183           std::cout << _MTQ_fname   << " ok=" << mtq_ok    << std::endl;
00184         }
00185       if (!apdpn_ok || !pn_ok ) return; // FIXME !
00186   
00187       TString apdpn_tree_name;
00188       TString    ab_tree_name;
00189       TString    pn_tree_name;
00190       TString   mtq_tree_name; 
00191 
00192       apdpn_tree_name = "APDCol";
00193       ab_tree_name    = "ABCol";
00194       pn_tree_name    = "PNCol";   
00195       mtq_tree_name   = "MatacqCol";
00196   
00197       apdpn_tree_name += _color;
00198       ab_tree_name    += _color;
00199       pn_tree_name    += _color;
00200       mtq_tree_name   += _color;
00201 
00202       if(mtq_ok)  {
00203         TTree *ckeckMtq = (TTree*) mtq_file->Get(mtq_tree_name);
00204         if( ckeckMtq ==0 ) mtq_ok = false;
00205       }
00206 
00207       if( _color != ME::iIRed && _color != ME::iBlue ){ 
00208         std::cout << "MELaserPrim::init() -- Fatal Error -- Wrong Laser Color : " << _color << " ---- Abort " << std::endl;
00209         return;
00210       }
00211       
00212       apdpn_tree = (TTree*) apdpn_file->Get(apdpn_tree_name);
00213       assert( apdpn_tree!=0 );
00214       apdpn_tree->SetMakeClass(1);
00215       apdpn_tree->SetBranchAddress("dccID", &apdpn_dccID, &b_apdpn_dccID);
00216       apdpn_tree->SetBranchAddress("towerID", &apdpn_towerID, &b_apdpn_towerID);
00217       apdpn_tree->SetBranchAddress("channelID", &apdpn_channelID, &b_apdpn_channelID);
00218       apdpn_tree->SetBranchAddress("moduleID", &apdpn_moduleID, &b_apdpn_moduleID);
00219       apdpn_tree->SetBranchAddress("side", &apdpn_side, &b_apdpn_side);
00220       apdpn_tree->SetBranchAddress("ieta", &apdpn_ieta, &b_apdpn_ieta);
00221       apdpn_tree->SetBranchAddress("iphi", &apdpn_iphi, &b_apdpn_iphi);
00222       apdpn_tree->SetBranchAddress("flag", &apdpn_flag, &b_apdpn_flag);
00223       if( apdpn_tree->GetBranchStatus("ShapeCor")) apdpn_tree->SetBranchAddress("ShapeCor", &apdpn_ShapeCor, &b_apdpn_ShapeCor);
00224       else apdpn_ShapeCor = 0.0;
00225       for( int jj=0; jj<iSizeArray_apdpn; jj++ )
00226         {
00227           TString name_ = apdpn_arrayName[jj];
00228           apdpn_tree->SetBranchAddress(name_, apdpn_apdpn[jj], &b_apdpn_apdpn[jj]);
00229         }
00230   
00231       if(ab_ok)  {
00232       ab_tree = (TTree*) ab_file->Get(ab_tree_name);
00233       assert( ab_tree!=0 );
00234       ab_tree->SetMakeClass(1);
00235       ab_tree->SetBranchAddress("dccID",     &ab_dccID,     &b_ab_dccID     );
00236       ab_tree->SetBranchAddress("towerID",   &ab_towerID,   &b_ab_towerID   );
00237       ab_tree->SetBranchAddress("channelID", &ab_channelID, &b_ab_channelID );
00238       ab_tree->SetBranchAddress("ieta",      &ab_ieta,      &b_ab_ieta      );
00239       ab_tree->SetBranchAddress("iphi",      &ab_iphi,      &b_ab_iphi      );
00240       ab_tree->SetBranchAddress("flag",      &ab_flag,      &b_ab_flag      );
00241       for( int ii=0; ii<iSize_ab; ii++ )
00242         {
00243           ab_tree->SetBranchAddress( ab_varName[ii], &ab_ab[ii], &b_ab_ab[ii] );
00244         }
00245       }
00246 
00247       pn_tree = (TTree*) apdpn_file->Get(pn_tree_name);
00248       assert( pn_tree!=0 );
00249       pn_tree->SetMakeClass(1);
00250       pn_tree->SetBranchAddress( "side",     &pn_side,     &b_pn_side     );
00251       pn_tree->SetBranchAddress( "pnID",     &pn_pnID,     &b_pn_pnID     );
00252       pn_tree->SetBranchAddress( "moduleID", &pn_moduleID, &b_pn_moduleID );
00253       pn_tree->SetBranchAddress( "PN",        pn_PN,       &b_pn_PN       );
00254       pn_tree->SetBranchAddress( "PNoPN",     pn_PNoPN,    &b_pn_PNoPN    );
00255       pn_tree->SetBranchAddress( "PNoPNA",    pn_PNoPNA,   &b_pn_PNoPNA   );
00256       pn_tree->SetBranchAddress( "PNoPNB",    pn_PNoPNB,   &b_pn_PNoPNB   );
00257 
00258 
00259       if( mtq_ok ) {
00260         mtq_tree = (TTree*) mtq_file->Get(mtq_tree_name);
00261         assert( mtq_tree!=0 );
00262         mtq_tree->SetMakeClass(1);
00263         mtq_tree->SetBranchAddress("side",        &mtq_side,       &b_mtq_side  );
00264     
00265         for( int ii=0; ii<iSize_mtq; ii++ )
00266           {
00267             mtq_tree->SetBranchAddress( mtq_varName[ii],  &mtq_mtq[ii], &b_mtq_mtq[ii] );
00268           }
00269       }
00270     }
00271   else if( _type==ME::iTestPulse )
00272     {
00273       TString _TPAPD_fname =cur; _TPAPD_fname += "APDPN_TESTPULSE.root";
00274 
00275       bool tpapd_ok;
00276       tpapd_ok=false; 
00277 
00278       FILE *test; 
00279       test = fopen( _TPAPD_fname,"r");  
00280       if (test) {
00281         tpapd_ok = true;
00282         fclose( test );
00283       }
00284 
00285       if(tpapd_ok) tpapd_file = TFile::Open( _TPAPD_fname );
00286 
00287       if( verbose_ )
00288         {
00289           std::cout << _TPAPD_fname << " ok=" << tpapd_ok << std::endl;
00290         }
00291       if (!tpapd_ok ) return;
00292   
00293       TString tpapd_tree_name;
00294       TString tppn_tree_name;
00295 
00296       tpapd_tree_name = "TPAPD";
00297       tppn_tree_name  = "TPPN";   
00298     
00299       tpapd_tree = (TTree*) tpapd_file->Get(tpapd_tree_name);
00300       assert( tpapd_tree!=0 );
00301       tpapd_tree->SetMakeClass(1);
00302       tpapd_tree->SetBranchAddress("ieta", &tpapd_ieta, &b_tpapd_ieta);
00303       tpapd_tree->SetBranchAddress("iphi", &tpapd_iphi, &b_tpapd_iphi);
00304       tpapd_tree->SetBranchAddress("dccID", &tpapd_dccID, &b_tpapd_dccID);
00305       tpapd_tree->SetBranchAddress("side", &tpapd_side, &b_tpapd_side);
00306       tpapd_tree->SetBranchAddress("towerID", &tpapd_towerID, &b_tpapd_towerID);
00307       tpapd_tree->SetBranchAddress("channelID", &tpapd_channelID, &b_tpapd_channelID);
00308       tpapd_tree->SetBranchAddress("moduleID", &tpapd_moduleID, &b_tpapd_moduleID);
00309       tpapd_tree->SetBranchAddress("flag", &tpapd_flag, &b_tpapd_flag);
00310       tpapd_tree->SetBranchAddress("gain", &tpapd_gain, &b_tpapd_gain);
00311       tpapd_tree->SetBranchAddress("APD",   tpapd_APD,  &b_tpapd_APD );
00312 
00313       tppn_tree = (TTree*) tpapd_file->Get(tppn_tree_name);
00314       assert( tppn_tree!=0 );
00315       tppn_tree->SetMakeClass(1);
00316       tppn_tree->SetBranchAddress( "side",     &tppn_side,     &b_tppn_side     );
00317       tppn_tree->SetBranchAddress( "pnID",     &tppn_pnID,     &b_tppn_pnID     );
00318       tppn_tree->SetBranchAddress( "moduleID", &tppn_moduleID, &b_tppn_moduleID );
00319       tppn_tree->SetBranchAddress( "gain",     &tppn_gain,     &b_tppn_gain     );
00320       tppn_tree->SetBranchAddress( "PN",        tppn_PN,       &b_tppn_PN       );
00321     }
00322   init_ok = true;
00323 }
00324 
00325 void
00326 MELaserPrim::bookHistograms()
00327 {
00328   if( !init_ok ) return;
00329   refresh();
00330 
00331   TString i_name, d_name;
00332       
00333   if( _isBarrel )
00334     {
00335       ixmin=0;
00336       ixmax=85;
00337       nx   =ixmax-ixmin;
00338       iymin=0;
00339       iymax=20;
00340       ny   =iymax-iymin;
00341 
00342 //       for( int ilmod=1; ilmod<=9; ilmod++ )
00343 //      {
00344 //        _pn[ilmod] = MEEBGeom::pn( ilmod );
00345 //      }
00346     }
00347   else   // fixme --- to be implemented
00348     {
00349       ixmin=1;
00350       ixmax=101;
00351       nx   =ixmax-ixmin;
00352       iymin=1;
00353       iymax=101;
00354       ny   =iymax-iymin;
00355 //       for( int ilmod=1; ilmod<=21; ilmod++ )  // modules 20 and 21 are fake...
00356 //      {
00357 //        _pn[ilmod] = MEEEGeom::pn( ilmod );
00358 //      }
00359       //      abort();
00360     }
00361 
00362   TString t_name; 
00363 
00364   //
00365   // Laser Run
00366   //
00367   t_name = "LMF_RUN_DAT";
00368   addBranchI( t_name, "LOGIC_ID"       );
00369   addBranchI( t_name, "NEVENTS"        );
00370   addBranchI( t_name, "QUALITY_FLAG"   );
00371 
00372   //
00373   // Laser Run IOV
00374   //
00375   t_name = "LMF_RUN_IOV";
00376   addBranchI( t_name, "TAG_ID"         );
00377   addBranchI( t_name, "SUB_RUN_NUM"    );
00378   addBranchI( t_name, "SUB_RUN_START_LOW"   );
00379   addBranchI( t_name, "SUB_RUN_START_HIGH"  );
00380   addBranchI( t_name, "SUB_RUN_END_LOW"     );
00381   addBranchI( t_name, "SUB_RUN_END_HIGH"    );
00382   addBranchI( t_name, "DB_TIMESTAMP_LOW"    );
00383   addBranchI( t_name, "DB_TIMESTAMP_HIGH"   );
00384   addBranchC( t_name, "SUB_RUN_TYPE"   );
00385 
00386   if( _type==ME::iLaser )
00387     {  
00388       //
00389       // Laser ADC Primitives
00390       //
00391       bookHistoI( _primStr, "LOGIC_ID" );
00392       bookHistoI( _primStr, "FLAG" );
00393       bookHistoF( _primStr, "MEAN" );
00394       bookHistoF( _primStr, "RMS" );
00395       bookHistoF( _primStr, "M3" );
00396       bookHistoF( _primStr, "APD_OVER_PNA_MEAN" );
00397       bookHistoF( _primStr, "APD_OVER_PNA_RMS" );
00398       bookHistoF( _primStr, "APD_OVER_PNA_M3" );
00399       bookHistoF( _primStr, "APD_OVER_PNB_MEAN" );
00400       bookHistoF( _primStr, "APD_OVER_PNB_RMS" );
00401       bookHistoF( _primStr, "APD_OVER_PNB_M3" );
00402       bookHistoF( _primStr, "APD_OVER_PN_MEAN" );
00403       bookHistoF( _primStr, "APD_OVER_PN_RMS" );
00404       bookHistoF( _primStr, "APD_OVER_PN_M3" );
00405       bookHistoF( _primStr, "APD_OVER_APDA_MEAN" );
00406       bookHistoF( _primStr, "APD_OVER_APDA_RMS" );
00407       bookHistoF( _primStr, "APD_OVER_APDA_M3" );
00408       bookHistoF( _primStr, "APD_OVER_APDB_MEAN" );
00409       bookHistoF( _primStr, "APD_OVER_APDB_RMS" );
00410       bookHistoF( _primStr, "APD_OVER_APDB_M3" );
00411       bookHistoF( _primStr, "SHAPE_COR" );
00412       bookHistoF( _primStr, "ALPHA" );
00413       bookHistoF( _primStr, "BETA" );
00414       // NEW GHM 08/06 --> SCHEMA MODIFIED?
00415       bookHistoF( _primStr, "TIME_MEAN" ); 
00416       bookHistoF( _primStr, "TIME_RMS"  );
00417       bookHistoF( _primStr, "TIME_M3"   );  
00418       bookHistoF( _primStr, "TIME_NEVT" );
00419 
00420       //
00421       // Laser PN Primitives
00422       //
00423       t_name = lmfLaserName( ME::iLmfLaserPnPrim, _type, _color );
00424       addBranchI( t_name, "LOGIC_ID" );
00425       addBranchI( t_name, "FLAG"     );
00426       addBranchF( t_name, "MEAN"     );
00427       addBranchF( t_name, "RMS"      );
00428       addBranchF( t_name, "M3"     );
00429       addBranchF( t_name, "PNA_OVER_PNB_MEAN"     );
00430       addBranchF( t_name, "PNA_OVER_PNB_RMS"      );
00431       addBranchF( t_name, "PNA_OVER_PNB_M3"       );
00432 
00433       //
00434       // Laser Pulse
00435       //
00436       t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00437       addBranchI( t_name, "LOGIC_ID" );
00438       addBranchI( t_name, "FIT_METHOD"   );
00439       addBranchF( t_name, "MTQ_AMPL"     );
00440       addBranchF( t_name, "MTQ_TIME"     );
00441       addBranchF( t_name, "MTQ_RISE"     );
00442       addBranchF( t_name, "MTQ_FWHM"     );
00443       addBranchF( t_name, "MTQ_FW20"     );
00444       addBranchF( t_name, "MTQ_FW80"     );
00445       addBranchF( t_name, "MTQ_SLIDING"  );
00446 
00447       //
00448       // Laser Config
00449       //
00450       t_name = lmfLaserName( ME::iLmfLaserConfig, _type );
00451       addBranchI( t_name, "LOGIC_ID"       );
00452       addBranchI( t_name, "WAVELENGTH"     );
00453       addBranchI( t_name, "VFE_GAIN"       );
00454       addBranchI( t_name, "PN_GAIN"        );
00455       addBranchI( t_name, "LSR_POWER"      );
00456       addBranchI( t_name, "LSR_ATTENUATOR" );
00457       addBranchI( t_name, "LSR_CURRENT"    );
00458       addBranchI( t_name, "LSR_DELAY_1"    );
00459       addBranchI( t_name, "LSR_DELAY_2"    );
00460 
00461       //
00462       // Laser LaserRun config dat
00463       //
00464       t_name = "RUN_LASERRUN_CONFIG_DAT";
00465       addBranchI( t_name, "LOGIC_ID"       );
00466       addBranchC( t_name, "LASER_SEQUENCE_TYPE"    );
00467       addBranchC( t_name, "LASER_SEQUENCE_COND"  );
00468 
00469     }
00470   else if( _type==ME::iTestPulse )
00471     {
00472       //
00473       // Test Pulse ADC Primitives
00474       //
00475       bookHistoI( _tpPrimStr, "LOGIC_ID" );
00476       bookHistoI( _tpPrimStr, "FLAG" );
00477       bookHistoF( _tpPrimStr, "MEAN" );
00478       bookHistoF( _tpPrimStr, "RMS" );
00479       bookHistoF( _tpPrimStr, "M3" );
00480       bookHistoF( _tpPrimStr, "NEVT" );
00481 
00482       //
00483       // Test Pulse PN Primitives
00484       //
00485       t_name = lmfLaserName( ME::iLmfTestPulsePnPrim, _type );
00486       addBranchI( t_name, "LOGIC_ID" );
00487       addBranchI( t_name, "FLAG"     );
00488       addBranchI( t_name, "GAIN"     );
00489       addBranchF( t_name, "MEAN"     );
00490       addBranchF( t_name, "RMS"      );
00491       addBranchF( t_name, "M3"     );
00492 
00493       //
00494       // Test Pulse Config
00495       //
00496       t_name = lmfLaserName( ME::iLmfTestPulseConfig, _type );
00497       addBranchI( t_name, "LOGIC_ID"       );
00498       addBranchI( t_name, "VFE_GAIN"       );
00499       addBranchI( t_name, "PN_GAIN"        );
00500     }
00501 }
00502 
00503 void
00504 MELaserPrim::fillHistograms()
00505 {
00506   TString t_name; 
00507 
00508   if( !init_ok ) return;
00509 
00510   Long64_t nentries = 0;
00511   Long64_t ientry   = 0;
00512 
00513   int channelView_(0);
00514   int id1_(0), id2_(0);
00515   int logic_id_(0);
00516 
00517   if( _type==ME::iLaser )
00518     {
00519 
00520       nentries = apdpn_tree->GetEntriesFast();
00521       for( Long64_t jentry=0; jentry<nentries; jentry++ ) 
00522         {      
00523           ientry = apdpn_tree->LoadTree( jentry );
00524           assert( ientry>=0 );
00525           apdpn_tree->GetEntry( jentry );
00526 
00527           if(ab_tree){
00528             ientry = ab_tree->LoadTree( jentry );
00529             assert( ientry>=0 );
00530             ab_tree->GetEntry( jentry );
00531           }
00532 
00533 
00534           if( apdpn_iphi<0 ) continue;      
00535 
00536           // fixme remove until coordinated are fine
00537           //if(ab_tree) assert( apdpn_ieta==ab_ieta && apdpn_iphi==ab_iphi );
00538       
00539           int ix(0);
00540           int iy(0);
00541           if( _isBarrel )
00542             {
00543               // Barrel, global coordinates
00544               id1_ = _sm;   
00545               if ( apdpn_side != _side ) continue; 
00546               int ieta=apdpn_ieta;
00547               int iphi=apdpn_iphi;
00548               MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord( ieta, iphi );
00549               ix = xy_.first;
00550               iy = xy_.second;
00551               id2_ = MEEBGeom::crystal_channel( ix, iy ); 
00552               channelView_ = iEB_crystal_number;
00553             }
00554           else
00555             {
00556               // EndCaps, global coordinates
00557               id1_ = apdpn_iphi;
00558               id2_ = apdpn_ieta; 
00559               ix = id1_;
00560               iy = id2_;
00561               channelView_ = iEE_crystal_number;
00562             }
00563 
00564           logic_id_ = logicId( channelView_, id1_, id2_ );
00565 
00566           int flag = apdpn_flag;
00567 
00568           setInt( "LOGIC_ID",           ix, iy,  logic_id_ );
00569           setInt( "FLAG",               ix, iy,  flag );
00570           setVal( "MEAN",               ix, iy,  apdpn_apdpn[iAPD][iMean] );
00571           setVal( "RMS",                ix, iy,  apdpn_apdpn[iAPD][iRMS] );
00572           setVal( "M3",                 ix, iy,  apdpn_apdpn[iAPD][iM3] );  // fixme --- peak?
00573           setVal( "APD_OVER_PNA_MEAN",  ix, iy,  apdpn_apdpn[iAPDoPNA][iMean] );
00574           setVal( "APD_OVER_PNA_RMS",   ix, iy,  apdpn_apdpn[iAPDoPNA][iRMS] );
00575           setVal( "APD_OVER_PNA_M3",    ix, iy,  apdpn_apdpn[iAPDoPNA][iM3] );  // fixme
00576           setVal( "APD_OVER_PNB_MEAN",  ix, iy,  apdpn_apdpn[iAPDoPNB][iMean] );
00577           setVal( "APD_OVER_PNB_RMS",   ix, iy,  apdpn_apdpn[iAPDoPNB][iRMS] );
00578           setVal( "APD_OVER_PNB_M3",    ix, iy,  apdpn_apdpn[iAPDoPNB][iM3] );  // fixme
00579           setVal( "APD_OVER_PN_MEAN",   ix, iy,  apdpn_apdpn[iAPDoPN][iMean] );
00580           setVal( "APD_OVER_PN_RMS",    ix, iy,  apdpn_apdpn[iAPDoPN][iRMS] );
00581           setVal( "APD_OVER_PN_M3",     ix, iy,  apdpn_apdpn[iAPDoPN][iM3] );  // fixme
00582           // JM
00583           setVal( "APD_OVER_APD_MEAN",  ix, iy,  apdpn_apdpn[iAPDoAPDA][iMean] );
00584           setVal( "APD_OVER_APD_RMS",   ix, iy,  apdpn_apdpn[iAPDoAPDA][iRMS] );
00585           setVal( "APD_OVER_APD_M3",    ix, iy,  apdpn_apdpn[iAPDoAPDA][iM3] );  // fixme
00586           setVal( "APD_OVER_APDA_MEAN",  ix, iy,  apdpn_apdpn[iAPDoAPDA][iMean] );
00587           setVal( "APD_OVER_APDA_RMS",   ix, iy,  apdpn_apdpn[iAPDoAPDA][iRMS] );
00588           setVal( "APD_OVER_APDA_M3",    ix, iy,  apdpn_apdpn[iAPDoAPDA][iM3] );  // fixme
00589           setVal( "APD_OVER_APDB_MEAN",  ix, iy,  apdpn_apdpn[iAPDoAPDB][iMean] );
00590           setVal( "APD_OVER_APDB_RMS",   ix, iy,  apdpn_apdpn[iAPDoAPDB][iRMS] );
00591           setVal( "APD_OVER_APDB_M3",    ix, iy,  apdpn_apdpn[iAPDoAPDB][iM3] );  // fixme
00592           // JM
00593           setVal( "SHAPE_COR",          ix, iy,  apdpn_ShapeCor );
00594           if(ab_tree){
00595             setVal( "ALPHA",              ix, iy,  ab_ab[iAlpha] );
00596             setVal( "BETA",               ix, iy,  ab_ab[iBeta] );
00597           }else{
00598             setVal( "ALPHA",              ix, iy,  0. );
00599             setVal( "BETA",               ix, iy,  0. );
00600           }
00601           // NEW GHM 08/06
00602           setVal( "TIME_MEAN",          ix, iy,  apdpn_apdpn[iTime][iMean] );
00603           setVal( "TIME_RMS",           ix, iy,  apdpn_apdpn[iTime][iRMS]  );
00604           setVal( "TIME_M3",            ix, iy,  apdpn_apdpn[iTime][iM3]   );
00605           setVal( "TIME_NEVT",          ix, iy,  apdpn_apdpn[iTime][iNevt] );
00606 
00607         }
00608 
00609 
00610       //
00611       // PN primitives
00612       //
00613       t_name = lmfLaserName( ME::iLmfLaserPnPrim, _type, _color );
00614 
00615       nentries = pn_tree->GetEntriesFast();
00616       assert( nentries%2==0 );
00617       int module_(0);
00618       id1_=_sm; id2_=0;
00619   
00620       Long64_t jentry=0;
00621 
00622       while( jentry<nentries ) 
00623         {      
00624           for( int jj=0; jj<2; jj++ )
00625             {
00626               // jj=0 --> PNA
00627               // jj=1 --> PNB
00628               
00629               int zentry = jentry+jj;
00630               assert( zentry<nentries );
00631               
00632               ientry = pn_tree->LoadTree( zentry );
00633               assert( ientry>=0 );
00634               pn_tree->GetEntry( zentry );
00635               
00636               if( _side!=pn_side ) break;
00637                   
00638               if( jj==1 ) assert( pn_moduleID==module_ );
00639               module_ = pn_moduleID;
00640               assert( pn_pnID==jj );
00641               
00642               // get the PN number
00643               std::pair<int,int> memPn_ = ME::pn( _lmr, module_, (ME::PN)jj );
00644               if( _isBarrel )
00645                 {
00646                   //              assert( memPn_.first%600==_dcc%600 );
00647                   id1_ = _sm;
00648                   id2_ = memPn_.second;
00649                 }
00650               else
00651                 {
00652                   int dee_ = MEEEGeom::dee( _lmr );
00653                   //              int mem_ = memPn_.first%600;
00654 //                if(      dee_==1 )
00655 //                  {
00656 //                    if( jj==ME::iPNA ) assert( mem_==50 );
00657 //                    else               assert( mem_==51 );
00658 //                  }
00659 //                else if( dee_==2 )
00660 //                  {
00661 //                    if( jj==ME::iPNA ) assert( mem_==47 );  // warning !
00662 //                    else               assert( mem_==46 );
00663 //                    //                      assert( mem_==46 || mem_==47 );
00664 //                  }
00665 //                else if( dee_==3 )
00666 //                  {
00667 //                    if( jj==ME::iPNA ) assert( mem_==1 );
00668 //                    else               assert( mem_==2 );
00669 //                  }
00670 //                else if( dee_==4 )
00671 //                  {
00672 //                    if( jj==ME::iPNA ) assert( mem_==5 );
00673 //                    else               assert( mem_==6 );
00674 //                  }
00675                   id1_ = dee_;
00676                   id2_ = (jj+1)*100+memPn_.second;
00677                 }
00678               
00679               if( _isBarrel )
00680                 {
00681                   channelView_ = iEB_LM_PN;
00682                 }
00683               else
00684                 {
00685                   channelView_ = iEE_LM_PN;
00686                 }
00687               logic_id_ = logicId( channelView_, id1_, id2_ );
00688               
00689               i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00690               f_t[t_name+separator+"MEAN"]  = pn_PN[iMean];
00691               f_t[t_name+separator+"RMS"]   = pn_PN[iRMS];
00692               f_t[t_name+separator+"M3"]  = pn_PN[iM3];    
00693               f_t[t_name+separator+"PNA_OVER_PNB_MEAN"]  = (jj==0) ? pn_PNoPNB[iMean] : pn_PNoPNA[iMean];
00694               f_t[t_name+separator+"PNA_OVER_PNB_RMS" ]  = (jj==0) ? pn_PNoPNB[iRMS]  : pn_PNoPNA[iRMS];
00695               f_t[t_name+separator+"PNA_OVER_PNB_M3"]  = (jj==0) ? pn_PNoPNB[iM3] : pn_PNoPNA[iM3];
00696               
00697               t_t[t_name]->Fill();
00698               
00699             }
00700           //      std::cout << "Module=" << module_ << "\tPNA=" << pn_[0] << "\tPNB=" << pn_[1] << std::endl;
00701 
00702 //        if( _isBarrel )
00703 //          jentry += 4;
00704 //        else
00705 //          jentry += 2;
00706           jentry += 2;
00707         }
00708 
00709       logic_id_  = logicId( iECAL_LMR, _lmr );
00710 
00711       //
00712       // MATACQ primitives
00713       //
00714 
00715       if(mtq_tree){
00716 
00717         t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00718     
00719         nentries = mtq_tree->GetEntriesFast();
00720         assert( nentries==2 );
00721         for( Long64_t jentry=0; jentry<nentries; jentry++ ) 
00722           {        
00723             ientry = mtq_tree->LoadTree( jentry );
00724             assert( ientry>=0 );
00725             mtq_tree->GetEntry( jentry );
00726             
00727             if ( mtq_side != _side ) continue; 
00728             
00729             i_t[t_name+separator+"LOGIC_ID"]       = logic_id_;
00730             i_t[t_name+separator+"FIT_METHOD"]     = 0 ;   // fixme  --- what's this? ? ?
00731             f_t[t_name+separator+"MTQ_AMPL"]       = mtq_mtq[iAmpl];
00732             f_t[t_name+separator+"MTQ_TIME"]       = mtq_mtq[iPeak];
00733             f_t[t_name+separator+"MTQ_RISE"]       = mtq_mtq[iTrise];
00734             f_t[t_name+separator+"MTQ_FWHM"]       = mtq_mtq[iFwhm];
00735             f_t[t_name+separator+"MTQ_FW20"]       = mtq_mtq[iFw20];
00736             f_t[t_name+separator+"MTQ_FW80"]       = mtq_mtq[iFw80];
00737             f_t[t_name+separator+"MTQ_SLIDING"]    = mtq_mtq[iSlide];      // fixme  --- sliding: max of average in sliding window
00738         
00739             t_t[t_name]->Fill();
00740           }
00741       }else{
00742 
00743         t_name = lmfLaserName( ME::iLmfLaserPulse, _type, _color );
00744 
00745         i_t[t_name+separator+"LOGIC_ID"]       = logic_id_;
00746         i_t[t_name+separator+"FIT_METHOD"]     =  0 ;   // fixme 
00747         f_t[t_name+separator+"MTQ_AMPL"]       = 0.0;
00748         f_t[t_name+separator+"MTQ_TIME"]       = 0.0;
00749         f_t[t_name+separator+"MTQ_RISE"]       = 0.0;
00750         f_t[t_name+separator+"MTQ_FWHM"]       = 0.0;
00751         f_t[t_name+separator+"MTQ_FW20"]       = 0.0;
00752         f_t[t_name+separator+"MTQ_FW80"]       = 0.0;
00753         f_t[t_name+separator+"MTQ_SLIDING"]    = 0.0;  
00754 
00755         t_t[t_name]->Fill();
00756       }
00757 
00758       //
00759       // Laser Run
00760       //
00761       t_name = lmfLaserName( ME::iLmfLaserRun, _type );
00762       //std::cout << "Fill "<< t_name << std::endl;
00763       i_t[t_name+separator+"LOGIC_ID"]       = logic_id_; 
00764       i_t[t_name+separator+"NEVENTS"]        =  _events;
00765       i_t[t_name+separator+"QUALITY_FLAG"]   = 1;                // fixme
00766       t_t[t_name]->Fill();
00767   
00768       //
00769       // Laser Config
00770       //
00771       t_name = lmfLaserName( ME::iLmfLaserConfig, _type );
00772       //std::cout << "Fill "<< t_name << std::endl;
00773       i_t[t_name+separator+"LOGIC_ID"]        = logic_id_;
00774       i_t[t_name+separator+"WAVELENGTH"]      = _color;
00775       i_t[t_name+separator+"VFE_GAIN"]        = _mgpagain; // fixme 
00776       i_t[t_name+separator+"PN_GAIN"]         = _memgain;  // fixme
00777       i_t[t_name+separator+"LSR_POWER"]       = _power; // will be available from MATACQ data
00778       i_t[t_name+separator+"LSR_ATTENUATOR"]  = _filter; // idem
00779       i_t[t_name+separator+"LSR_CURRENT"]     = 0; // idem
00780       i_t[t_name+separator+"LSR_DELAY_1"]     = _delay; // idem
00781       i_t[t_name+separator+"LSR_DELAY_2"]     = 0; // idem
00782       t_t[t_name]->Fill();
00783 
00784     }
00785   else if( _type==ME::iTestPulse )
00786     {
00787 
00788 //       nentries = tpapd_tree->GetEntriesFast();
00789 //       for( Long64_t jentry=0; jentry<nentries; jentry++ ) 
00790 //      {      
00791 //        ientry = tpapd_tree->LoadTree( jentry );
00792 //        assert( ientry>=0 );
00793 //        nb     = tpapd_tree->GetEntry( jentry );
00794 
00795 //        if( tpapd_iphi<0 ) continue;      
00796 
00797 //        const bool new_= true;
00798       
00799 //        int ix;
00800 //        int iy;
00801 //        int id2;
00802 //        if( new_ )
00803 //          {
00804 //            // for Cruzet3 , global coordinates
00805 //            if ( tpapd_side != _side ) continue; 
00806 //            int ieta=tpapd_ieta;
00807 //            int iphi=tpapd_iphi;
00808 //            MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord( ieta, iphi );
00809 //            ix = xy_.first;
00810 //            iy = xy_.second;
00811 //            id2 = ix*20 + iy;  // !!! TO BE CHECKED !!!
00812 //          }
00813 //        else
00814 //          {
00815 //            // for Cruzet2 , local coordinates
00816 //            ix = tpapd_ieta;
00817 //            iy = 19-tpapd_iphi;
00818 //            id2 = ix*20 + (20 - iy);  // !!! TO BE CHECKED !!!
00819 //          }
00820 //        // 
00821 
00822 //        int id1 = _sm;   // fixme --- this is for barrel
00823 //        int logic_id_ = 1011000000;    // fixme
00824 //        logic_id_ += 10000*id1 + id2;
00825 
00826 //        int flag = tpapd_flag;
00827 
00828 //        setInt( "LOGIC_ID",           ix, iy,  logic_id_ );
00829 //        setInt( "FLAG",               ix, iy,  flag );
00830 //        setVal( "MEAN",               ix, iy,  tpapd_APD[iMean] );
00831 //        setVal( "RMS",                ix, iy,  tpapd_APD[iRMS] );
00832 //        setVal( "M3",                 ix, iy,  tpapd_APD[iM3] ); 
00833 //        setVal( "NEVT",               ix, iy,  tpapd_APD[iNevt] );
00834 //      }
00835 
00836 //       //
00837 //       // PN primitives
00838 //       //
00839 //       t_name = lmfLaserName( ME::iLmfTestPulsePnPrim, _type );
00840 
00841 //       nentries = tppn_tree->GetEntriesFast();
00842 //       assert( nentries%2==0 );
00843 //       int module_, pn_[2];
00844 //       int id1_(_sm), id2_(0);
00845 //       int logic_id_(0);
00846   
00847 //       Long64_t jentry=0;
00848 //       if( _side==1 ) jentry+=2;  // fixme : true also for endcaps?
00849 //       while( jentry<nentries ) 
00850 //      {      
00851 //        for( int jj=0; jj<2; jj++ )
00852 //          {
00853 //            // jj=0 --> PNA
00854 //            // jj=1 --> PNB
00855           
00856 //            int zentry = jentry+jj;
00857 //            assert( zentry<nentries );
00858           
00859 //            ientry = tppn_tree->LoadTree( zentry );
00860 //            assert( ientry>=0 );
00861 //            nb     = tppn_tree->GetEntry( zentry );
00862 
00863 //            if( jj==1 ) assert( tppn_moduleID==module_ );
00864 //            module_ = tppn_moduleID;
00865 //            assert( tppn_pnID==jj );
00866           
00867 //            pn_[jj] = ( jj==0 ) ? _pn[module_].first : _pn[module_].second;
00868 //            id2_ = pn_[jj];
00869 //            logic_id_ = 1131000000 ;
00870 //            //          logic_id_ = 0;    // fixme
00871 //            logic_id_ += 10000*id1_ + id2_;
00872           
00873 //            i_t[t_name+separator+"LOGIC_ID"] = logic_id_;
00874 //            i_t[t_name+separator+"GAIN"]  = tppn_gain;
00875 //            f_t[t_name+separator+"MEAN"]  = tppn_PN[iMean];
00876 //            f_t[t_name+separator+"RMS"]   = tppn_PN[iRMS];
00877 //            f_t[t_name+separator+"M3"]    = tppn_PN[iM3];     // fixme --- peak?
00878 
00879 //            t_t[t_name]->Fill();
00880 
00881 //          }
00882 
00883 //        //      std::cout << "Module=" << module_ << "\tPNA=" << pn_[0] << "\tPNB=" << pn_[1] << std::endl;
00884 
00885 //        jentry += 4;
00886 //      }
00887 
00888 //       logic_id_ = 1041000000;
00889 //       logic_id_ += 10000*id1_;
00890 //       logic_id_ += id1_;
00891   
00892 //       //
00893 //       // Test Pulse Run
00894 //       //
00895 //       t_name = lmfLaserName( ME::iLmfTestPulseRun, _type );
00896 //       //std::cout << "Fill "<< t_name << std::endl;
00897 //       i_t[t_name+separator+"LOGIC_ID"]       = logic_id_;  // fixme --- is there a channelview for this?
00898 //       i_t[t_name+separator+"NEVENTS"]        =  _events;
00899 //       i_t[t_name+separator+"QUALITY_FLAG"]   = 1;                // fixme
00900 //       t_t[t_name]->Fill();
00901   
00902 //       //
00903 //       // Test Pulse Config
00904 //       //
00905 //       t_name = lmfLaserName( ME::iLmfTestPulseConfig, _type );
00906 //       //std::cout << "Fill "<< t_name << std::endl;
00907 //       i_t[t_name+separator+"LOGIC_ID"]        = logic_id_;  // fixme
00908 //       i_t[t_name+separator+"VFE_GAIN"]        = _mgpagain; // fixme 
00909 //       i_t[t_name+separator+"PN_GAIN"]         = _memgain;  // fixme
00910 //       t_t[t_name]->Fill();
00911     }
00912 
00913   //
00914   // Laser Run IOV
00915   //
00916   t_name = "LMF_RUN_IOV";
00917   //std::cout << "Fill "<< t_name << std::endl;
00918   i_t[t_name+separator+"TAG_ID"]        = 0;       // fixme
00919   i_t[t_name+separator+"SUB_RUN_NUM"]   = _run;      // fixme
00920   i_t[t_name+separator+"SUB_RUN_START_LOW" ] = ME::time_low( _ts_beg );
00921   i_t[t_name+separator+"SUB_RUN_START_HIGH"] = ME::time_high( _ts_beg );
00922   i_t[t_name+separator+"SUB_RUN_END_LOW"   ] = ME::time_low( _ts_end );
00923   i_t[t_name+separator+"SUB_RUN_END_HIGH"  ] = ME::time_high( _ts_end );
00924   i_t[t_name+separator+"DB_TIMESTAMP_LOW"  ] = ME::time_low( _ts ); 
00925   i_t[t_name+separator+"DB_TIMESTAMP_HIGH" ] = ME::time_high( _ts );
00926   c_t[t_name+separator+"SUB_RUN_TYPE"]  = "LASER TEST CRUZET"; //fixme
00927   t_t[t_name]->Fill();
00928 
00929 }
00930 
00931 void
00932 MELaserPrim::writeHistograms()
00933 {
00934   if( !init_ok ) return;
00935 
00936   out_file = new TFile( _outfile, "RECREATE" );
00937   //  out_file->cd();
00938 
00939   std::map< TString, TH2* >::iterator it;
00940 
00941   for( it=i_h.begin(); it!=i_h.end(); it++ )
00942     {
00943       it->second->Write();
00944       delete it->second;
00945     }
00946 
00947   for( it=f_h.begin(); it!=f_h.end(); it++ )
00948     {
00949       it->second->Write();
00950       delete it->second;
00951     }
00952 
00953   std::map< TString, TTree* >::iterator it_t;
00954   for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
00955     {
00956       it_t->second->Write();
00957       delete it_t->second;
00958     }
00959 
00960   //  std::cout << "Closing " << _outfile << std::endl;
00961   out_file->Close();
00962   delete out_file;
00963   out_file=0;
00964 }
00965 
00966 MELaserPrim::~MELaserPrim()
00967 {
00968   delete apdpn_tree;
00969   delete ab_tree;
00970   delete pn_tree;
00971   delete mtq_tree;
00972   delete tpapd_tree;
00973   delete tppn_tree;
00974   if( apdpn_file!=0 )
00975     {
00976       //      std::cout << "Closing apdpn_file " << std::endl;
00977       apdpn_file->Close();
00978       delete apdpn_file;
00979       apdpn_file = 0;
00980     }
00981   if( ab_file!=0 )
00982     {
00983       //      std::cout << "Closing ab_file " << std::endl;
00984       ab_file->Close();
00985       delete ab_file;
00986       ab_file = 0;
00987     }
00988   if( mtq_file!=0 )
00989     {
00990       //      std::cout << "Closing mtq_file " << std::endl;
00991       mtq_file->Close();
00992       delete mtq_file;
00993       mtq_file = 0;
00994     }
00995   if( tpapd_file!=0 )
00996     {
00997       //      std::cout << "Closing tpapd_file " << std::endl;
00998       tpapd_file->Close();
00999       delete tpapd_file;
01000       tpapd_file = 0;
01001     }
01002 }
01003 
01004 void 
01005 MELaserPrim::print( ostream& o )
01006 {
01007   o << "DCC/SM/side/type/color/run/ts " << _dcc << "/" << _sm << "/" << _side << "/" 
01008     << _type << "/" << _color << "/" << _run << "/" << _ts << std::endl;
01009   
01010 //   for( int ix=ixmin; ix<ixmax; ix++ )
01011 //     {
01012 //       for( int iy=iymin; iy<iymax; iy++ )
01013 //      {
01014 //        int flag     = getInt( _primStr+"FLAG", ix, iy );
01015 //        if( flag==0 ) continue;
01016 //        int logic_id = getInt( _primStr+"LOGIC_ID", ix, iy );
01017 //        float   apd = getVal( _primStr+"MEAN", ix, iy );
01018 //        o << "Crystal ieta=" << ix << "\tiphi=" << iy << "\tlogic_id=" << logic_id << "\tAPD=" << apd <<  endl;
01019 //      }
01020 //     }
01021 }
01022 
01023 TString 
01024 MELaserPrim::lmfLaserName( int table, int type, int color )
01025 {
01026   TString str("LMF_ERROR");
01027   if( table<0 || table>=ME::iSizeLmf )  return str;
01028   if( color<0 || color>=ME::iSizeC )    return str;
01029 
01030   if( type==ME::iLaser )
01031     {
01032       TString colstr;
01033       switch( color )
01034         {
01035         case ME::iBlue:   colstr = "_BLUE"; break;
01036         case ME::iGreen:  colstr = "_GREEN"; break;
01037         case ME::iRed:    colstr = "_RED";  break;
01038         case ME::iIRed:   colstr = "_IRED";  break;
01039         default:  abort();
01040         }
01041       str = "LMF_LASER";
01042       switch( table )
01043         {
01044         case ME::iLmfLaserRun:      str  = "LMF_RUN";                 break; 
01045         case ME::iLmfLaserConfig:   str += "_CONFIG";                 break; 
01046         case ME::iLmfLaserPulse:    str += colstr; str += "_PULSE";   break; 
01047         case ME::iLmfLaserPrim:     str += colstr; str += "_PRIM";    break; 
01048         case ME::iLmfLaserPnPrim:   str += colstr; str += "_PN_PRIM"; break; 
01049         default:  abort();
01050         }
01051     }
01052   else if( type==ME::iTestPulse )
01053     {
01054       str = "LMF_TEST_PULSE";
01055       switch( table )
01056         {
01057         case ME::iLmfTestPulseRun:     str = "LMF_RUN";     break;
01058         case ME::iLmfTestPulseConfig:  str += "_CONFIG";    break;
01059         case ME::iLmfTestPulsePrim:    str += "_PRIM";      break;        
01060         case ME::iLmfTestPulsePnPrim:  str += "_PN_PRIM";   break;
01061         default: abort();
01062         }
01063     }
01064   str += "_DAT";
01065   return str;
01066 }
01067 
01068 void
01069 MELaserPrim::addBranchI( const char* t_name_, const char* v_name_ )
01070 {
01071   TString slashI("/i"); // Warning: always unsigned
01072   TString t_name(t_name_);
01073   TString v_name(v_name_);
01074   if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01075   t_t[t_name]->Branch(v_name, &i_t[t_name+separator+v_name],v_name+slashI);  
01076 }
01077 
01078 void
01079 MELaserPrim::addBranchF( const char* t_name_, const char* v_name_ )
01080 {
01081   TString slashF("/F");
01082   TString t_name(t_name_);
01083   TString v_name(v_name_);
01084   if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01085   t_t[t_name]->Branch(v_name, &f_t[t_name+separator+v_name],v_name+slashF);
01086 }
01087 
01088 void
01089 MELaserPrim::addBranchC( const char* t_name_, const char* v_name_ )
01090 {
01091   TString slashC("/C");
01092   TString t_name(t_name_);
01093   TString v_name(v_name_);
01094   if( t_t.count(t_name)==0 ) t_t[t_name] = new TTree(t_name, t_name);
01095   t_t[t_name]->Branch(v_name, &c_t[t_name+separator+v_name],v_name+slashC);
01096 }
01097 
01098 void 
01099 MELaserPrim::bookHistoI( const char* h_name_, const char* v_name_ )
01100 {
01101   TString i_name = TString(h_name_)+TString(v_name_);
01102   TH2* h_ = new TH2I(i_name,i_name,nx,ixmin,ixmax,ny,iymin,iymax);
01103   setHistoStyle( h_ );
01104   i_h[i_name] = h_;
01105 }
01106 
01107 void 
01108 MELaserPrim::bookHistoF( const char* h_name_, const char* v_name_ )
01109 {
01110   TString d_name = TString(h_name_)+TString(v_name_);
01111   TH2* h_ = new TH2F(d_name,d_name,nx,ixmin,ixmax,ny,iymin,iymax);
01112   setHistoStyle( h_ );
01113   f_h[d_name] = h_;
01114 }
01115 
01116 
01117 bool    
01118 MELaserPrim::setInt( const char* name, int ix, int iy, int ival )
01119 {
01120   TString name_;
01121   if( _type==ME::iLaser ) name_=_primStr+name;
01122   else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
01123  
01124   int _ival = getInt( name_, ix, iy );
01125   assert( _ival!=-99 );
01126   if( _ival!=0 ) return false; 
01127 
01128   TH2I* h_ = (TH2I*) i_h[name_];
01129   assert( h_!=0 );
01130   h_->Fill( ix+0.5, iy+0.5, ival );
01131 
01132   return true;
01133 }
01134 
01135 bool    
01136 MELaserPrim::setVal( const char* name, int ix, int iy, float val )
01137 {
01138   TString name_;
01139   if( _type==ME::iLaser ) name_=_primStr+name;
01140   else if( _type==ME::iTestPulse ) name_=_tpPrimStr+name;
01141  
01142   float _val = getVal( name_, ix, iy );
01143   assert( _val!=-99 );
01144   if( _val!=0 ) return false; 
01145 
01146   TH2F* h_ = (TH2F*) f_h[name_];
01147   assert( h_!=0 );
01148   
01149   h_->Fill( ix+0.5, iy+0.5, val );
01150 
01151   return true;
01152 }
01153 
01154 Int_t    
01155 MELaserPrim::getInt( const char* name, int ix, int iy )
01156 {
01157   Int_t ival=-99;
01158   if( i_h.count(name)==1 )
01159     {
01160       TH2I* h_ = (TH2I*) i_h[name];
01161       assert( h_!=0 );
01162       int binx = h_->GetXaxis()->FindBin( ix+0.5 );
01163       int biny = h_->GetYaxis()->FindBin( iy+0.5 );
01164       ival =  (Int_t) h_->GetCellContent( binx, biny );
01165     }
01166   return ival;
01167 }
01168 
01169 Float_t    
01170 MELaserPrim::getVal( const char* name, int ix, int iy )
01171 {
01172   Float_t val=-99.;
01173   if( f_h.count(name)==1 )
01174     {
01175       TH2F* h_ = (TH2F*) f_h[name];
01176       assert( h_!=0 );
01177       int binx = h_->GetXaxis()->FindBin( ix+0.5 );
01178       int biny = h_->GetYaxis()->FindBin( iy+0.5 );
01179       val =  h_->GetCellContent( binx, biny );
01180     }
01181   return val;
01182 }
01183 
01184 bool
01185 MELaserPrim::setInt( const char* tname, const char* vname, int ival )
01186 {
01187   TString key_(tname); key_ += separator; key_ += vname;
01188   assert( i_t.count(key_)==1 );
01189   i_t[key_] = ival;
01190   return true;
01191 }
01192 
01193 bool
01194 MELaserPrim::setVal( const char* tname, const char* vname, float val )
01195 {
01196   TString key_(tname); key_ += separator; key_ += vname;
01197 
01198   // ghm
01199   if( f_t.count(key_)!=1 )
01200     {
01201       std::cout << key_ << std::endl;
01202     }
01203   assert( f_t.count(key_)==1 );
01204   f_t[key_]  = val;
01205   return true;
01206 }
01207 
01208 bool
01209 MELaserPrim::fill( const char* tname )
01210 {
01211   TString key_( tname );
01212   assert( t_t.count(key_)==1 );
01213   t_t[key_] -> Fill();
01214   return true;
01215 }
01216 
01217 void 
01218 MELaserPrim::setHistoStyle( TH1* h )
01219 {
01220   if( h==0 ) return;
01221   
01222   float _scale = 1;
01223 
01224   h->SetLineColor(4);
01225   h->SetLineWidth(1);
01226   h->SetFillColor(38);
01227   TAxis* axis[3];
01228   axis[0] = h->GetXaxis();
01229   axis[1] = h->GetYaxis();
01230   axis[2] = h->GetZaxis();
01231   for( int ii=0; ii<3; ii++ )
01232     {
01233       TAxis* a = axis[ii];
01234       if( !a ) continue;
01235       a->SetLabelFont(132);
01236       a->SetLabelOffset(_scale*0.005);
01237       a->SetLabelSize(_scale*0.04);
01238       a->SetTitleFont(132);
01239       a->SetTitleOffset(_scale*1);
01240       a->SetTitleSize(_scale*0.04);
01241     } 
01242   h->SetStats( kTRUE );
01243 }
01244 
01245 void
01246 MELaserPrim::refresh()
01247 {
01248   std::map< TString, TH2* >::iterator it;
01249 
01250   for( it=i_h.begin(); it!=i_h.end(); it++ )
01251     {
01252       delete it->second;
01253       it->second = 0;
01254     }
01255   i_h.clear();
01256 
01257   for( it=f_h.begin(); it!=f_h.end(); it++ )
01258     {
01259       delete it->second;
01260       it->second = 0;
01261     }
01262   f_h.clear();
01263 
01264   std::map< TString, TTree* >::iterator it_t;
01265   for( it_t=t_t.begin(); it_t!=t_t.end(); it_t++ )
01266     {
01267       delete it_t->second;
01268       it->second = 0;
01269     }
01270   t_t.clear();
01271 }