LMD/TFndLmdMon.cxx

00001 // @(#)fROOT/LMD:$Name:  $:$Id: TFndLmdMon.cxx,v 1.37 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 // Original Author: Piergiorgio Cerello <mailto:cerello@to.infn.it>
00004 
00006 //                TFndLmdMon                 //
00007 //                                           //
00008 //  - LMD-Histogram collection and filling   //
00009 //  - LMD shared memories management         //
00010 //                                           //
00011 // (see GTS relative class for descriptions) //
00012 //                                           //
00014 
00015 #include <TF1.h>
00016 #include <TSystem.h>
00017 
00018 #include "TFndRun.h"
00019 #include "TFndRunConfiguration.h"
00020 #include "TFndGenInfo.h"
00021 #include "TFndHLmd.h"
00022 #include "TFndHdt.h"
00023 #include "TFndLmdMon.h"
00024 
00025 ClassImp(TFndLmdMon)
00026 
00027 //______________________________________
00028 TFndLmdMon::TFndLmdMon(const TString &fmode,Int_t lmd_adc_bins,Double_t lmd_adc_min,Double_t lmd_adc_max,Int_t lmd_tdc_bins,Double_t lmd_tdc_min,Double_t lmd_tdc_max):
00029   fout(),flmd(),
00030   mlmd(),mlmd_adc(),mlmd_tdc(),
00031   fMustRecoverHistos(kFALSE),
00032   fSharedMemName_Main(),fSharedMemName_Adc(),fSharedMemName_Tdc(),
00033   fSharedFileName_Main(),fSharedFileName_Adc(),fSharedFileName_Tdc(),
00034   lmdmult(),lmdmult_good(),lmd_i_o_mult(),lmdmap(),lmdmap_good(),lmdmapadc0(),lmdmapadc(),lmdmapadce(),lmdmapadcp(),
00035   lmdmaptdc0(),lmdmaptdc(),lmdmaptdce(),lmdmaptdcp(),
00036   lmd_all_mapadctdc(),lmd_all_adc_tdc(),lmd_all_adce(),lmd_all_adcp(),lmd_all_mul(),
00037   lmd_all_aepat(),lmd_all_appat(),lmd_all_tepat(),lmd_all_tppat(),
00038   lmd_all_vp(),lmd_all_crg(),lmd_all_zet(),lmd_all_adc(),lmd_all_tdce(),lmd_all_tdcp(),lmd_all_tdf(),lmd_all_tmean(),lmd_all_tdc(),
00039   lmd_all_dhits(),lmd_all_dhits_tdc_dopp(),lmd_all_dhits_adc_dopp(),lmd_all_dhits_tdc_cell(),lmd_all_dhits_adc_cell(),
00040   lmdadce(),lmdadcp(),lmdcrg(),lmdzet(),lmdtdce(),lmdtdcp(),lmdtdf(),lmdtmean(),
00041   lmd1d(),lmd2d(),fLine()
00042 {
00043   
00044   Init();
00045   OpenSharedFiles(fmode);
00046   InitHistos(lmd_adc_bins,lmd_adc_min,lmd_adc_max,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);  
00047 
00048 }
00049 
00050 //______________________________________
00051 TFndLmdMon::TFndLmdMon():
00052   fout(),flmd(),
00053   mlmd(),mlmd_adc(),mlmd_tdc(),
00054   fMustRecoverHistos(kFALSE),
00055   fSharedMemName_Main(),fSharedMemName_Adc(),fSharedMemName_Tdc(),
00056   fSharedFileName_Main(),fSharedFileName_Adc(),fSharedFileName_Tdc(),
00057   lmdmult(),lmdmult_good(),lmd_i_o_mult(),lmdmap(),lmdmap_good(),lmdmapadc0(),lmdmapadc(),lmdmapadce(),lmdmapadcp(),
00058   lmdmaptdc0(),lmdmaptdc(),lmdmaptdce(),lmdmaptdcp(),
00059   lmd_all_mapadctdc(),lmd_all_adc_tdc(),lmd_all_adce(),lmd_all_adcp(),lmd_all_mul(),
00060   lmd_all_aepat(),lmd_all_appat(),lmd_all_tepat(),lmd_all_tppat(),
00061   lmd_all_vp(),lmd_all_crg(),lmd_all_zet(),lmd_all_adc(),lmd_all_tdce(),lmd_all_tdcp(),lmd_all_tdf(),lmd_all_tmean(),lmd_all_tdc(),
00062   lmd_all_dhits(),lmd_all_dhits_tdc_dopp(),lmd_all_dhits_adc_dopp(),lmd_all_dhits_tdc_cell(),lmd_all_dhits_adc_cell(),
00063   lmdadce(),lmdadcp(),lmdcrg(),lmdzet(),lmdtdce(),lmdtdcp(),lmdtdf(),lmdtmean(),
00064   lmd1d(),lmd2d(),fLine()
00065 {
00066   // This constructor was used by the consumer,
00067   // but now there is no need to open the shared memory
00068   // in read/update mode here... commented all (Diego - 03/03/2005)
00069   Init();
00070 
00071 }
00072 
00073 //______________________________________
00074 TFndLmdMon::TFndLmdMon(const TFndLmdMon &lmdmon):
00075   fout(),flmd(),
00076   mlmd(),mlmd_adc(),mlmd_tdc(),
00077   fMustRecoverHistos(kFALSE),
00078   fSharedMemName_Main(),fSharedMemName_Adc(),fSharedMemName_Tdc(),
00079   fSharedFileName_Main(),fSharedFileName_Adc(),fSharedFileName_Tdc(),
00080   lmdmult(),lmdmult_good(),lmd_i_o_mult(),lmdmap(),lmdmap_good(),lmdmapadc0(),lmdmapadc(),lmdmapadce(),lmdmapadcp(),
00081   lmdmaptdc0(),lmdmaptdc(),lmdmaptdce(),lmdmaptdcp(),
00082   lmd_all_mapadctdc(),lmd_all_adc_tdc(),lmd_all_adce(),lmd_all_adcp(),lmd_all_mul(),
00083   lmd_all_aepat(),lmd_all_appat(),lmd_all_tepat(),lmd_all_tppat(),
00084   lmd_all_vp(),lmd_all_crg(),lmd_all_zet(),lmd_all_adc(),lmd_all_tdce(),lmd_all_tdcp(),lmd_all_tdf(),lmd_all_tmean(),lmd_all_tdc(),
00085   lmd_all_dhits(),lmd_all_dhits_tdc_dopp(),lmd_all_dhits_adc_dopp(),lmd_all_dhits_tdc_cell(),lmd_all_dhits_adc_cell(),
00086   lmdadce(),lmdadcp(),lmdcrg(),lmdzet(),lmdtdce(),lmdtdcp(),lmdtdf(),lmdtmean(),
00087   lmd1d(),lmd2d(),fLine()
00088 {
00089   //
00090   Init();
00091 }
00092 
00093 //______________________________________
00094 TFndLmdMon::TFndLmdMon(TString *filename):
00095   fout(),flmd(),
00096   mlmd(),mlmd_adc(),mlmd_tdc(),
00097   fMustRecoverHistos(kFALSE),
00098   fSharedMemName_Main(),fSharedMemName_Adc(),fSharedMemName_Tdc(),
00099   fSharedFileName_Main(),fSharedFileName_Adc(),fSharedFileName_Tdc(),
00100   lmdmult(),lmdmult_good(),lmd_i_o_mult(),lmdmap(),lmdmap_good(),lmdmapadc0(),lmdmapadc(),lmdmapadce(),lmdmapadcp(),
00101   lmdmaptdc0(),lmdmaptdc(),lmdmaptdce(),lmdmaptdcp(),
00102   lmd_all_mapadctdc(),lmd_all_adc_tdc(),lmd_all_adce(),lmd_all_adcp(),lmd_all_mul(),
00103   lmd_all_aepat(),lmd_all_appat(),lmd_all_tepat(),lmd_all_tppat(),
00104   lmd_all_vp(),lmd_all_crg(),lmd_all_zet(),lmd_all_adc(),lmd_all_tdce(),lmd_all_tdcp(),lmd_all_tdf(),lmd_all_tmean(),lmd_all_tdc(),
00105   lmd_all_dhits(),lmd_all_dhits_tdc_dopp(),lmd_all_dhits_adc_dopp(),lmd_all_dhits_tdc_cell(),lmd_all_dhits_adc_cell(),
00106   lmdadce(),lmdadcp(),lmdcrg(),lmdzet(),lmdtdce(),lmdtdcp(),lmdtdf(),lmdtmean(),
00107   lmd1d(),lmd2d(),fLine()
00108 {
00109 
00110   Init();
00111 
00112   flmd = new TFile(filename->Data());
00113   TString hname = TString("lmdmult");
00114   lmdmult = (TH1F *) flmd->Get(hname.Data()); 
00115   hname = TString("lmdmult_good");
00116   lmdmult_good = (TH1F *) flmd->Get(hname.Data()); 
00117   hname = TString("lmd_i_o_mult");
00118   lmd_i_o_mult = (TH2F *) flmd->Get(hname.Data()); 
00119   hname = TString("lmdmap");
00120   lmdmap = (TH2F *) flmd->Get(hname.Data()); 
00121   hname = TString("lmdmap_good");
00122   lmdmap_good = (TH2F *) flmd->Get(hname.Data()); 
00123   hname = TString("lmdmapadc0");
00124   lmdmapadc0 = (TH2F *) flmd->Get(hname.Data()); 
00125   hname = TString("lmdmapadc");
00126   lmdmapadc = (TH2F *) flmd->Get(hname.Data()); 
00127   hname = TString("lmdmapadce");
00128   lmdmapadce = (TH2F *) flmd->Get(hname.Data()); 
00129   hname = TString("lmdmapadcp");
00130   lmdmapadcp = (TH2F *) flmd->Get(hname.Data()); 
00131   hname = TString("lmdmaptdc0");
00132   lmdmaptdc0 = (TH2F *) flmd->Get(hname.Data()); 
00133   hname = TString("lmdmaptdc");
00134   lmdmaptdc = (TH2F *) flmd->Get(hname.Data()); 
00135   hname = TString("lmdmaptdce");
00136   lmdmaptdce = (TH2F *) flmd->Get(hname.Data()); 
00137   hname = TString("lmdmaptdcp");
00138   lmdmaptdcp = (TH2F *) flmd->Get(hname.Data()); 
00139 
00140   for (Int_t i=0;i<K_N_LMD_LAYERS;i++) {    
00141     //    cout << "Layer: " << i+1 << endl;
00142     for (Int_t j=0;j<K_N_LMD_CHAMS_PER_LAYER;j++) {     
00143       //cout << "Chamber: " << j+1 << endl;
00144       Int_t nwire = K_N_LMD_INNER_WIRES;
00145       if(i == 1) nwire = K_N_LMD_OUTER_WIRES;
00146       
00147       Int_t idx1 = j+i*K_N_LMD_CHAMS_PER_LAYER;
00148       //cout << "idx1: " << idx1 << endl;
00149       Char_t chname[20];
00150       sprintf(chname,"_%d_%d",i+1,j+1);
00151 
00152       hname = TString("lmd_all_mapadctdc");
00153       hname.Append(chname);
00154       lmd_all_mapadctdc[idx1] = (TH2F *) flmd->Get(hname.Data()); 
00155       hname = TString("lmd_all_zet");
00156       hname.Append(chname);
00157       lmd_all_zet[idx1] = (TH2F *) flmd->Get(hname.Data()); 
00158       hname = TString("lmd_all_crg");
00159       hname.Append(chname);
00160       lmd_all_crg[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00161       // 
00162       // prove Elena
00163       hname = TString("lmd_all_vp");
00164       hname.Append(chname);
00165       lmd_all_vp[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00166       // 
00167       hname = TString("lmd_all_adce");
00168       hname.Append(chname);
00169       lmd_all_adce[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00170       hname = TString("lmd_all_adcp");
00171       hname.Append(chname);
00172       lmd_all_adcp[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00173 
00174       hname = TString("lmd_all_mul");
00175       hname.Append(chname);
00176       lmd_all_mul[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00177       //
00178       hname = TString("lmd_all_aepat");
00179       hname+=chname;
00180       lmd_all_aepat[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00181       
00182       hname = TString("lmd_all_appat");
00183       hname+=chname;
00184       lmd_all_appat[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00185       
00186       hname = TString("lmd_all_tepat");
00187       hname+=chname;
00188       lmd_all_tepat[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00189       
00190       hname = TString("lmd_all_tppat");
00191       hname+=chname;
00192       lmd_all_tppat[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00193       
00194       //
00195       hname = TString("lmd_all_adc");
00196       hname.Append(chname);
00197       lmd_all_adc[idx1] = (TH2F *) flmd->Get(hname.Data()); 
00198       hname = TString("lmd_all_adc_tdc");
00199       hname.Append(chname);
00200       lmd_all_adc_tdc[idx1] = (TH2F *) flmd->Get(hname.Data()); 
00201 
00202       hname = TString("lmd_all_tdce");
00203       hname.Append(chname);
00204       lmd_all_tdce[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00205       hname = TString("lmd_all_tdcp");
00206       hname.Append(chname);
00207       lmd_all_tdcp[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00208       hname = TString("lmd_all_tdf");
00209       hname.Append(chname);
00210       lmd_all_tdf[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00211       hname = TString("lmd_all_tmean");
00212       hname.Append(chname);
00213       lmd_all_tmean[idx1] = (TH1F *) flmd->Get(hname.Data()); 
00214       hname = TString("lmd_all_tdc");
00215       hname.Append(chname);
00216       lmd_all_tdc[idx1] = (TH2F *) flmd->Get(hname.Data()); 
00217 
00218       
00219       for (Int_t l=0;l<nwire;l++) {
00220         //cout << "Wire: " << l+1 << endl;
00221         Int_t idx = l+j*nwire+i*K_N_LMD_INNER_WIRES*K_N_LMD_CHAMS_PER_LAYER;
00222         Char_t chname[20];
00223         sprintf(chname,"_%d_%d_%d",i+1,j+1,l+1);
00224         
00225         hname = TString("lmdtdce");
00226         hname.Append(chname);
00227         lmdtdce[idx] = (TH1F *) flmd->Get(hname.Data()); 
00228         hname = TString("lmdtdcp");
00229         hname.Append(chname);
00230         lmdtdcp[idx] = (TH1F *) flmd->Get(hname.Data()); 
00231         hname = TString("lmdtmean");
00232         hname.Append(chname);
00233         lmdtmean[idx] = (TH1F *) flmd->Get(hname.Data()); 
00234         hname = TString("lmdtdf");
00235         hname.Append(chname);
00236         lmdtdf[idx] = (TH1F *) flmd->Get(hname.Data()); 
00237         
00238         hname = TString("lmdadce");
00239         hname.Append(chname);
00240         lmdadce[idx] = (TH1F *) flmd->Get(hname.Data()); 
00241         hname = TString("lmdadcp");
00242         hname.Append(chname);
00243         lmdadcp[idx] = (TH1F *) flmd->Get(hname.Data()); 
00244         hname = TString("lmdcrg");
00245         hname.Append(chname);
00246         lmdcrg[idx] = (TH1F *) flmd->Get(hname.Data()); 
00247         hname = TString("lmdzet");
00248         hname.Append(chname);
00249         lmdzet[idx] = (TH1F *) flmd->Get(hname.Data()); 
00250       }
00251     }
00252   }
00253   //  flmd->Close();
00254 
00255   lmd1d = 0;
00256   lmd2d = 0;
00257   fLine = 0;
00258 }
00259 
00260 //______________________________________
00261 TFndLmdMon::~TFndLmdMon() {
00262   
00263   delete fLine;
00264 
00265   delete lmdmult;
00266   delete lmdmult_good; // LMD selected multiplicity
00267   delete lmd_i_o_mult;   // LMD multiplicity
00268   delete lmdmap;         // LMD map
00269   delete lmdmap_good;         // LMD map
00270 
00271   delete lmdmapadc0; // LMD ADC map (e || p |= 0)
00272   delete lmdmapadc;   // LMD ADC map (e && p != 0)
00273   delete lmdmapadce;  // LMD e-side ADC map
00274   delete lmdmapadcp;  // LMD p-side ADC map
00275 
00276   delete lmdmaptdc0;  // LMD TDC map (e || p |= 0) 
00277   delete lmdmaptdc;    // LMD TDC map (e && p != 0)  
00278   delete lmdmaptdce;  // LMD e-side TDC map   
00279   delete lmdmaptdcp;  // LMD p-side TDC map  
00280 
00281   for(Int_t i=0; i<K_N_LMD_TOT_CHAMS; i++) {
00282     delete lmd_all_mapadctdc[i];           // LMD ADC vs TDC existence 
00283     delete lmd_all_adc_tdc[i];        // LMD ADC vs TDC 
00284     delete lmd_all_adce[i];           // e-side ADC
00285     delete lmd_all_adcp[i];           // p-side  ADC
00286     delete lmd_all_mul[i];
00287     delete lmd_all_aepat[i];
00288     delete lmd_all_appat[i];
00289     delete lmd_all_tepat[i];
00290     delete lmd_all_tppat[i];
00291     delete lmd_all_crg[i];            // ADC (e+p)
00292     delete lmd_all_vp[i];            // propag. velocity
00293     delete lmd_all_zet[i];            // ADC (e-p)/(e+p)
00294     delete lmd_all_adc[i];            // ADC (e-side vs p-side)      
00295     delete lmd_all_tdce[i];           // e-side TDC
00296     delete lmd_all_tdcp[i];           // p-side  TDC
00297     delete lmd_all_tdf[i];            // Time difference
00298     delete lmd_all_tmean[i];          // (Te+Tp)/2
00299     delete lmd_all_tdc[i];            // TDC (e-side vs p-side)
00300     
00301     delete lmd_all_dhits[i];          // Double Lmd Hits
00302     delete lmd_all_dhits_tdc_dopp[i]; // Double Lmd Hits TDC
00303     delete lmd_all_dhits_adc_dopp[i]; // Double Lmd Hits ADC
00304     delete lmd_all_dhits_tdc_cell[i]; // Double Lmd Hits TDC
00305     delete lmd_all_dhits_adc_cell[i];  // Double Lmd Hits ADC
00306   }
00307   for(Int_t i=0; i<n_lmd_hist; i++) {
00308     delete lmdadce[i];           // e-side ADC
00309     delete lmdadcp[i];           // p-side  ADC
00310     delete lmdcrg[i];            // ADC (e+p)
00311     delete lmdzet[i];            // ADC (e-p)/(e+p)
00312     delete lmdtdce[i];           // e-side TDC
00313     delete lmdtdcp[i];           // p-side  TDC
00314     delete lmdtdf[i];            // Time difference
00315     delete lmdtmean[i];          // (Te+Tp)/2
00316   }
00317 
00318   if(! shmflg){
00319     if(flmd) flmd->Close();
00320     delete flmd;
00321   }
00322   
00323   if(fout) fout->Close();
00324   delete fout;
00325 
00326   if(mlmd){ mlmd->Close(); mlmd = 0; }
00327   else delete mlmd;
00328   
00329   for(Int_t kk=0;kk<2;kk++){
00330     if(mlmd_adc[kk]){ mlmd_adc[kk]->Close(); mlmd_adc[kk] = 0; }
00331     else delete mlmd_adc[kk];
00332   }
00333   
00334   //   if(mlmd_o_adc){ mlmd_o_adc->Close(); mlmd_o_adc = 0; }
00335   //   else delete mlmd_o_adc;
00336   
00337   for(Int_t kk=0;kk<2;kk++){
00338     if(mlmd_tdc[kk]){ mlmd_tdc[kk]->Close(); mlmd_tdc[kk] = 0; }
00339     else delete mlmd_tdc[kk];  
00340   }
00341   
00342 }
00343 
00344 //______________________________________
00345 void TFndLmdMon::Init(){
00346   
00347   fZetaAdjust[0] = LmdZetaGeoAdjust(E_FIN_INNER_LAYER);
00348   fZetaAdjust[1] = LmdZetaGeoAdjust(E_FIN_OUTER_LAYER);
00349   
00350   fSharedMemName_Main   = FROOT::ExpandPathName("$FND_SHR/lmd.map");
00351   fSharedMemName_Adc[0] = FROOT::ExpandPathName("$FND_SHR/lmd_i_adc.map");
00352   fSharedMemName_Adc[1] = FROOT::ExpandPathName("$FND_SHR/lmd_o_adc.map");
00353   fSharedMemName_Tdc[0] = FROOT::ExpandPathName("$FND_SHR/lmd_i_tdc.map");
00354   fSharedMemName_Tdc[1] = FROOT::ExpandPathName("$FND_SHR/lmd_o_tdc.map");
00355   
00356   fSharedFileName_Main   = FROOT::ExpandPathName("lmd.file.map");
00357   fSharedFileName_Adc[0] = FROOT::ExpandPathName("lmd_i_adc.file.map");
00358   fSharedFileName_Adc[1] = FROOT::ExpandPathName("lmd_o_adc.file.map");
00359   fSharedFileName_Tdc[0] = FROOT::ExpandPathName("lmd_i_tdc.file.map");
00360   fSharedFileName_Tdc[1] = FROOT::ExpandPathName("lmd_o_tdc.file.map");
00361 
00362 }
00363 
00364 //______________________________________
00365 void TFndLmdMon::InitHistos(const Int_t &lmd_adc_bins,const Double_t &lmd_adc_min,const Double_t &lmd_adc_max,const Int_t &lmd_tdc_bins,const Double_t &lmd_tdc_min,const Double_t &lmd_tdc_max){
00366   // try to recover histograms from shared file (if still available...)
00367 
00368   if(shmflg && ( !mlmd || !mlmd_adc[0] || !mlmd_adc[1] || !mlmd_tdc[0] || !mlmd_tdc[1]) ){
00369     Warning("InitHistos","Map-files not available: exiting method");
00370     return;
00371   }
00372 
00373   TString hname;
00374   TString htitle;
00375 
00377   if(shmflg) mlmd->cd();
00378 
00379   hname = "lmdmult";
00380   htitle = "Lmd multiplicity";
00381   lmdmult = (fMustRecoverHistos) ? 
00382     ((TH1F*) (mlmd->Get(hname))) :
00383     new TH1F(hname,htitle,200,-0.5,199.5);
00384   
00385   hname = "lmdmult_good";
00386   htitle = "Lmd selected mult.";
00387   lmdmult_good = (fMustRecoverHistos) ? 
00388     ((TH1F*) (mlmd->Get(hname))) :
00389     new TH1F(hname,htitle,20,-0.5,19.5);
00390 
00391   hname = "lmd_i_o_mult";
00392   htitle = "Lmd inner vs outer mult.";
00393   lmd_i_o_mult = (fMustRecoverHistos) ? 
00394     ((TH2F*) (mlmd->Get(hname))) :
00395     new TH2F(hname,htitle,10,-0.5,9.5,10,-0.5,9.5);
00396 
00397   hname = "lmdmap";
00398   htitle = "Lmd Hit Map (Wire vs Drift Number)";
00399   lmdmap = (fMustRecoverHistos) ? 
00400     ((TH2F*) (mlmd->Get(hname))) :
00401     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00402 
00403   hname = "lmdmap_good";
00404   htitle = "Lmd Selected Hit Map (Wire vs Drift Number)";
00405   lmdmap_good = (fMustRecoverHistos) ? 
00406     ((TH2F*) (mlmd->Get(hname))) :
00407     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00408 
00409   hname = "lmdmapadc0";
00410   htitle = "Lmd ADC map (e||p!=0)";
00411   lmdmapadc0 = (fMustRecoverHistos) ? 
00412     ((TH2F*) (mlmd->Get(hname))) :
00413     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00414 
00415   hname = "lmdmapadc";
00416   htitle = "Lmd ADC map (e&&p!=0)";
00417   lmdmapadc = (fMustRecoverHistos) ? 
00418     ((TH2F*) (mlmd->Get(hname))) :
00419     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00420 
00421   hname = "lmdmapadce";
00422   htitle = "Lmd ADC map (e-side)";
00423   lmdmapadce = (fMustRecoverHistos) ? 
00424     ((TH2F*) (mlmd->Get(hname))) :
00425     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00426 
00427   hname = "lmdmapadcp";
00428   htitle = "Lmd ADC map (p-side)";
00429   lmdmapadcp = (fMustRecoverHistos) ? 
00430     ((TH2F*) (mlmd->Get(hname))) :
00431     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00432   
00433   // ---
00434 
00435   hname = "lmdmaptdc0";
00436   htitle = "Lmd TDC map (e||p!=0)";
00437   lmdmaptdc0 = (fMustRecoverHistos) ? 
00438     ((TH2F*) (mlmd->Get(hname))) :
00439     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00440 
00441   hname = "lmdmaptdc";
00442   htitle = "Lmd TDC map (e&&p!=0)";
00443   lmdmaptdc = (fMustRecoverHistos) ? 
00444     ((TH2F*) (mlmd->Get(hname))) :
00445     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00446 
00447   hname = "lmdmaptdce";
00448   htitle = "Lmd TDC map (e-side)";
00449   lmdmaptdce = (fMustRecoverHistos) ? 
00450     ((TH2F*) (mlmd->Get(hname))) :
00451     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00452 
00453   hname = "lmdmaptdcp";
00454   htitle = "Lmd TDC map (p-side)";
00455   lmdmaptdcp = (fMustRecoverHistos) ? 
00456     ((TH2F*) (mlmd->Get(hname))) :
00457     new TH2F(hname,htitle,20,10.5,30.5,24,0.5,24.5);   
00458 
00459   // ---  
00460   
00461   for (Int_t ji=0;ji<K_N_LMD_LAYERS;ji++) {     
00462     for (Int_t j=0;j<K_N_LMD_CHAMS_PER_LAYER;j++) {
00463       Int_t id = K_N_LMD_CHAMS_PER_LAYER*ji + j;     
00464       hname.Form("lmd_all_mapadctdc_%d_%d",ji+1,j+1);
00465       htitle.Form("ADC E/P vs TDC E/P, dch %d, layer %d",j+1,ji+1);
00466       lmd_all_mapadctdc[id] = (fMustRecoverHistos) ? 
00467         ((TH2F*) (mlmd->Get(hname))) :
00468         new TH2F(hname,htitle,4,-0.5,3.5,4,-0.5,3.5);
00469       
00470       hname.Form("lmd_all_adc_tdc_%d_%d",ji+1,j+1);
00471       htitle.Form("ADC vs TDC, dch %d, layer %d",j+1,ji+1);
00472       lmd_all_adc_tdc[id] = (fMustRecoverHistos) ? 
00473         ((TH2F*) (mlmd->Get(hname))) :
00474         new TH2F(hname,htitle,50,lmd_tdc_min,lmd_tdc_max,50,lmd_adc_min,lmd_adc_max);
00475       
00476       hname.Form("lmd_all_dhits_%d_%d",ji+1,j+1);
00477       htitle.Form("Wire with Dij = -1, dch %d, layer %d",j+1,ji+1);
00478       lmd_all_dhits[id] = (fMustRecoverHistos) ? 
00479         ((TH1F*) (mlmd->Get(hname))) :
00480         new TH1F(hname,htitle,22,0.5,22.5);
00481       
00482       hname.Form("lmd_all_dhits_tdc_dopp_%d_%d",ji+1,j+1);
00483       htitle.Form("T(i) vs T(i+1), dch %d, layer %d",j+1,ji+1);
00484       lmd_all_dhits_tdc_dopp[id] = (fMustRecoverHistos) ? 
00485         ((TH2F*) (mlmd->Get(hname))) :
00486         new TH2F(hname,htitle,lmd_tdc_bins/4,lmd_tdc_min,lmd_tdc_max,lmd_tdc_bins/4,lmd_tdc_min,lmd_tdc_max);
00487       
00488       hname.Form("lmd_all_dhits_tdc_cell_%d_%d",ji+1,j+1);
00489       htitle.Form("T(i) vs T(i+1), dch %d, layer %d",j+1,ji+1);
00490       lmd_all_dhits_tdc_cell[id] = (fMustRecoverHistos) ? 
00491         ((TH2F*) (mlmd->Get(hname))) :
00492         new TH2F(hname,htitle,lmd_tdc_bins/4,lmd_tdc_min,lmd_tdc_max,lmd_tdc_bins/4,lmd_tdc_min,lmd_tdc_max);
00493       
00494       hname.Form("lmd_all_dhits_adc_dopp_%d_%d",ji+1,j+1);
00495       htitle.Form("Q(i) vs Q(i+1) for dch: %d in layer: %d",j+1,ji+1);
00496       lmd_all_dhits_adc_dopp[id] = (fMustRecoverHistos) ? 
00497         ((TH2F*) (mlmd->Get(hname))) :
00498         new TH2F(hname,htitle,lmd_adc_bins/4,lmd_adc_min,2.*lmd_adc_max,lmd_adc_bins/4,lmd_adc_min,2.*lmd_adc_max);
00499       
00500       hname.Form("lmd_all_dhits_adc_cell_%d_%d",ji+1,j+1);
00501       htitle.Form("Q(i) vs Q(i+1) (cell), dch %d, layer %d",j+1,ji+1);
00502       lmd_all_dhits_adc_cell[id] = (fMustRecoverHistos) ? 
00503         ((TH2F*) (mlmd->Get(hname))) :
00504         new TH2F(hname,htitle,lmd_adc_bins/4,lmd_adc_min,2.*lmd_adc_max,lmd_adc_bins/4,lmd_adc_min,2.*lmd_adc_max);
00505       
00506       // ---
00507       Int_t nwir = K_N_LMD_INNER_WIRES;
00508       if(ji==1) nwir = K_N_LMD_OUTER_WIRES;
00509       hname.Form("lmd_all_mul_%d_%d",ji+1,j+1);
00510       htitle.Form("Multiplicity, dch %d, layer %d",j+1,ji+1);
00511       lmd_all_mul[id] = (fMustRecoverHistos) ? 
00512         ((TH1F*) (mlmd->Get(hname))) :
00513         new TH1F(hname,htitle,nwir+1,-0.5,nwir+0.5);
00514       lmd_all_mul[id]->SetLineColor(4); // break here in recovery
00515       lmd_all_mul[id]->SetLineWidth(2);
00516     }
00517   }   
00518   
00520   //   LMD  ADC    
00521 
00522   for(Int_t kk=0;kk<K_N_LMD_LAYERS;kk++) {
00523     
00524     Int_t nwires = 12 + kk*10;
00525     if(shmflg) mlmd_adc[kk]->cd();
00526 
00527     for (Int_t jj=0;jj<K_N_LMD_CHAMS_PER_LAYER;jj++) {     
00528       Int_t j = K_N_LMD_CHAMS_PER_LAYER*kk+jj;
00529       hname.Form("lmd_all_adce_%d_%d",kk+1,jj+1);
00530       htitle.Form("ADC e-side, dch %d, layer %d",jj+1,kk+1);
00531       lmd_all_adce[j] = (fMustRecoverHistos) ? 
00532         ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00533         new TH1F(hname,htitle,lmd_adc_bins,lmd_adc_min,lmd_adc_max);
00534       lmd_all_adce[j]->SetLineColor(4);
00535       
00536       hname.Form("lmd_all_adcp_%d_%d",kk+1,jj+1);
00537       htitle.Form("ADC p-side, dch %d, layer %d",jj+1,kk+1);
00538       lmd_all_adcp[j] = (fMustRecoverHistos) ? 
00539         ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00540         new TH1F(hname,htitle,lmd_adc_bins,lmd_adc_min,lmd_adc_max);
00541       lmd_all_adcp[j]->SetLineColor(2); 
00542 
00543       Int_t nwir = K_N_LMD_INNER_WIRES;
00544       if(kk==1) nwir = K_N_LMD_OUTER_WIRES;
00545 
00546       //
00547       hname.Form("lmd_all_aepat_%d_%d",kk+1,jj+1);
00548       htitle.Form("Wire-Patt (ADC-e), dch %d, layer %d",jj+1,kk+1);
00549       lmd_all_aepat[j] = (fMustRecoverHistos) ? 
00550         ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00551         new TH1F(hname,htitle,nwir+1,-0.5,nwir+0.5);
00552       lmd_all_aepat[j]->SetLineColor(4);
00553       lmd_all_aepat[j]->SetLineWidth(2);
00554 
00555       hname.Form("lmd_all_appat_%d_%d",kk+1,jj+1);
00556       htitle.Form("Wire-Patt (ADC-p), dch %d, layer %d",jj+1,kk+1);
00557       lmd_all_appat[j] = (fMustRecoverHistos) ? 
00558         ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00559         new TH1F(hname,htitle,nwir+1,-0.5,nwir+0.5);
00560       lmd_all_appat[j]->SetLineColor(4);
00561       lmd_all_appat[j]->SetLineWidth(2);
00562 
00563       //     
00564       hname.Form("lmd_all_crg_%d_%d",kk+1,jj+1);
00565       htitle.Form("ADC (e+p)-side, dch %d, layer %d",jj+1,kk+1);
00566       lmd_all_crg[j] = (fMustRecoverHistos) ? 
00567         ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00568         new TH1F(hname,htitle,lmd_adc_bins,2*lmd_adc_min,2*lmd_adc_max);
00569       lmd_all_crg[j]->SetFillColor(9);
00570 
00571       // prove Elena      
00572       hname.Form("lmd_all_vp_%d_%d",kk+1,jj+1);
00573       htitle.Form("Drift velocity, dch %d, layer %d",jj+1,kk+1);
00574       lmd_all_vp[j] = (fMustRecoverHistos) ? 
00575         ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00576         new TH1F(hname,htitle,60,0.,30.);
00577       lmd_all_vp[j]->SetFillColor(4);
00578       // 
00579       hname.Form("lmd_all_zet_%d_%d",kk+1,jj+1);
00580       htitle.Form("Time vs Z, dch %d, layer %d",jj+1,kk+1);
00581       lmd_all_zet[j] = (fMustRecoverHistos) ? 
00582         ((TH2F*) (mlmd_adc[kk]->Get(hname))) :
00583         new TH2F(hname,htitle,101,-fZetaAdjust[kk],fZetaAdjust[kk],lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max/2);
00584       
00585       hname.Form("lmd_all_adc_%d_%d",kk+1,jj+1);
00586       htitle.Form("ADC e vs p-side, dch %d, layer %d",jj+1,kk+1);
00587       lmd_all_adc[j] = (fMustRecoverHistos) ? 
00588         ((TH2F*) (mlmd_adc[kk]->Get(hname))) :
00589         new TH2F(hname,htitle,lmd_adc_bins,lmd_adc_min,lmd_adc_max,lmd_adc_bins,lmd_adc_min,lmd_adc_max);
00590       
00591       for (Int_t l=0;l<nwires;l++) {
00592         
00593         Int_t k = K_N_LMD_INNER_WIRES*K_N_LMD_CHAMS_PER_LAYER*kk+l+jj*nwires;
00594         
00595         hname.Form("lmdadce_%d_%d_%d",kk+1,jj+1,l+1);
00596         htitle.Form("ADC e-side, wire %d, dch %d, layer %d",l+1,jj+1,kk+1);
00597         lmdadce[k] = (fMustRecoverHistos) ? 
00598           ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00599           new TH1F(hname,htitle,lmd_adc_bins,lmd_adc_min,lmd_adc_max);
00600         lmdadce[k]->SetLineColor(4); 
00601         
00602         hname.Form("lmdadcp_%d_%d_%d",kk+1,jj+1,l+1);
00603         htitle.Form("ADC p-side, wire %d, dch %d, layer %d",l+1,jj+1,kk+1);
00604         lmdadcp[k] = (fMustRecoverHistos) ? 
00605           ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00606           new TH1F(hname,htitle,lmd_adc_bins,lmd_adc_min,lmd_adc_max);
00607         lmdadcp[k]->SetLineColor(2); 
00608         
00609         hname.Form("lmdcrg_%d_%d_%d",kk+1,jj+1,l+1);
00610         htitle.Form("ADC (e+p)-side, wire %d, dch %d, layer %d",l+1,jj+1,kk+1);
00611         lmdcrg[k] = (fMustRecoverHistos) ? 
00612           ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00613           new TH1F(hname,htitle,lmd_adc_bins,2*lmd_adc_min,2*lmd_adc_max);
00614         lmdcrg[k]->SetFillColor(9);
00615         
00616         hname.Form("lmdzet_%d_%d_%d",kk+1,jj+1,l+1);
00617         htitle.Form("zeta (cm), wire %d, dch %d, layer %d",l+1,jj+1,kk+1);
00618         lmdzet[k] = (fMustRecoverHistos) ? 
00619           ((TH1F*) (mlmd_adc[kk]->Get(hname))) :
00620           new TH1F(hname,htitle,101,-fZetaAdjust[kk],fZetaAdjust[kk]);
00621       }
00622     }
00623     
00625     //   LMD    TDC
00626     if(shmflg) mlmd_tdc[kk]->cd();
00627     
00628     for (Int_t jk=0;jk<K_N_LMD_CHAMS_PER_LAYER;jk++) {     
00629       Int_t ij = K_N_LMD_CHAMS_PER_LAYER*kk+jk;
00630       hname.Form("lmd_all_tdce_%d_%d",kk+1,jk+1);
00631       htitle.Form("TDC e-side, dch %d, layer %d",jk+1,kk+1);
00632       lmd_all_tdce[ij] = (fMustRecoverHistos) ? 
00633         ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00634         new TH1F(hname,htitle,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);
00635       lmd_all_tdce[ij]->SetLineColor(4);
00636       
00637       hname.Form("lmd_all_tdcp_%d_%d",kk+1,jk+1);
00638       htitle.Form("TDC p-side, dch %d, layer %d",jk+1,kk+1);
00639       lmd_all_tdcp[ij] = (fMustRecoverHistos) ? 
00640         ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00641         new TH1F(hname,htitle,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);
00642       lmd_all_tdcp[ij]->SetLineColor(2); 
00643       
00644       hname.Form("lmd_all_tdf_%d_%d",kk+1,jk+1);
00645       htitle.Form("TDC (e-p)-side, dch %d, layer %d",jk+1,kk+1);
00646       lmd_all_tdf[ij] = (fMustRecoverHistos) ? 
00647         ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00648         new TH1F(hname,htitle,25,-50.,50.);
00649       lmd_all_tdf[ij]->SetFillColor(9);
00650       
00651       hname.Form("lmd_all_tmean_%d_%d",kk+1,jk+1);
00652       htitle.Form("TDC (e+p-side)/2, dch %d, layer %d",jk+1,kk+1);
00653       lmd_all_tmean[ij] = (fMustRecoverHistos) ? 
00654         ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00655         new TH1F(hname,htitle,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);
00656       lmd_all_tmean[ij]->SetFillColor(7);
00657       
00658       hname.Form("lmd_all_tdc_%d_%d",kk+1,jk+1);
00659       htitle.Form("TDC e vs p side, dch %d, layer %d",jk+1,kk+1);
00660       lmd_all_tdc[ij] = (fMustRecoverHistos) ? 
00661         ((TH2F*) (mlmd_tdc[kk]->Get(hname))) :
00662         new TH2F(hname,htitle,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);
00663 
00665       Int_t nwir = K_N_LMD_INNER_WIRES;
00666       if(kk==1) nwir = K_N_LMD_OUTER_WIRES;
00667 
00668       hname.Form("lmd_all_tepat_%d_%d",kk+1,jk+1);
00669       htitle.Form("Wire-Patt (TDC-e), dch %d, layer %d",jk+1,kk+1);
00670       lmd_all_tepat[ij] = (fMustRecoverHistos) ? 
00671         ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00672         new TH1F(hname,htitle,nwir+1,-0.5,nwir+0.5);
00673       lmd_all_tepat[ij]->SetLineColor(4);
00674       lmd_all_tepat[ij]->SetLineWidth(2);
00675       
00676       hname.Form("lmd_all_tppat_%d_%d",kk+1,jk+1);
00677       htitle.Form("Wire-Patt (TDC-p), dch %d, layer %d",jk+1,kk+1);
00678       lmd_all_tppat[ij] = (fMustRecoverHistos) ? 
00679         ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00680         new TH1F(hname,htitle,nwir+1,-0.5,nwir+0.5);
00681       lmd_all_tppat[ij]->SetLineColor(4);
00682       lmd_all_tppat[ij]->SetLineWidth(2);
00684 
00685       for (Int_t l=0;l<nwires;l++) {
00686         Int_t k = K_N_LMD_INNER_WIRES*K_N_LMD_CHAMS_PER_LAYER*kk+l+jk*nwires;
00687         
00688         hname.Form("lmdtdce_%d_%d_%d",kk+1,jk+1,l+1);
00689         htitle.Form("TDC e-side, wire %d, dch %d, layer %d",l+1,jk+1,kk+1);
00690         lmdtdce[k] = (fMustRecoverHistos) ? 
00691           ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00692           new TH1F(hname,htitle,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);
00693         lmdtdce[k]->SetLineColor(4); 
00694         
00695         hname.Form("lmdtdcp_%d_%d_%d",kk+1,jk+1,l+1);
00696         htitle.Form("TDC p-side, wire %d, dch %d, layer %d",l+1,jk+1,kk+1);
00697         lmdtdcp[k] = (fMustRecoverHistos) ? 
00698           ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00699           new TH1F(hname,htitle,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);
00700         lmdtdcp[k]->SetLineColor(2);      
00701         
00702         hname.Form("lmdtdf_%d_%d_%d",kk+1,jk+1,l+1);
00703         htitle.Form("TDC (e-p)-side, wire %d, dch %d, layer %d",l+1,jk+1,kk+1);
00704         //      lmdtdf[k] = new TH1F(hname,htitle,100,-50,50);
00705         lmdtdf[k] = (fMustRecoverHistos) ? 
00706           ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00707           new TH1F(hname,htitle,20,-40.,40.);
00708         lmdtdf[k]->SetFillColor(9);
00709         
00710         hname.Form("lmdtmean_%d_%d_%d",kk+1,jk+1,l+1);
00711         htitle.Form("TDC (e+p -side)/2, wire %d, dch %d, layer %d",l+1,jk+1,kk+1);
00712         lmdtmean[k] = (fMustRecoverHistos) ? 
00713           ((TH1F*) (mlmd_tdc[kk]->Get(hname))) :
00714           new TH1F(hname,htitle,lmd_tdc_bins,lmd_tdc_min,lmd_tdc_max);
00715         lmdtmean[k]->SetFillColor(9);
00716       }
00717     }
00718   }
00719 
00720 }
00721 
00722 
00723 //______________________________________
00724 void TFndLmdMon::OpenSharedFiles(const TString &fmode){
00725   // will handle shared memories/files creation
00726    
00727   shmflg = fndrun->Onlflg();
00728   cout << "Lmd Shm flag is " << shmflg << endl;
00729 
00730   TString fhist = "_lmd.root";
00731   
00732   TString lmdnam_str = (fmode.IsNull())? "ONLM" : fmode;
00733   lmdnam_str+=fhist;
00734 
00735   flmd = 0;
00736   flmd = new TFile(lmdnam_str.Data(),"RECREATE","Lmd Histogram File");   
00737   
00738   mlmd = 0;
00739   if(shmflg) {
00740 #if defined _FND_ONL_USE_MAP_FILES_
00741     mlmd = TMapFile::Create(fSharedMemName_Main,"RECREATE",(Int_t)(1048576*FROOT::K_LmdMapSize),"Lmd memory mapped file with histograms");
00742     mlmd->Print();
00743 #elif defined _FND_ONL_USE_SHARED_FILES_
00744     if(gSystem->AccessPathName(fSharedFileName_Main)){
00745       cout << "Shared file missing: creating it now..." << endl;
00746       mlmd = new TFile(fSharedFileName_Main,"RECREATE");
00747     }
00748     else{
00749       cout << "Shared file found: histograms will be recovered..." << endl;
00750       mlmd = TFile::Open(fSharedFileName_Main,"UPDATE");
00751       fMustRecoverHistos = kTRUE;
00752       //mlmd->ls();
00753     }
00754 #endif
00755   }
00756 
00757   for(Int_t kk=0;kk<K_N_LMD_LAYERS;kk++) {
00758     
00759     //   LMD  ADC    
00760     if(shmflg) {
00761 #if defined _FND_ONL_USE_MAP_FILES_
00762       mlmd_adc[kk] = TMapFile::Create(fSharedMemName_Adc[kk],"RECREATE",(Int_t)(1048576*FROOT::K_LmdIadcMapSize),"Lmd memory mapped file with INNER ADC histograms");
00763       mlmd_adc[kk]->Print();
00764 #elif defined _FND_ONL_USE_SHARED_FILES_
00765       if( gSystem->AccessPathName(fSharedFileName_Adc[kk]) && fMustRecoverHistos == kTRUE){
00766         cout << "Shared file missing: creating it now..." << endl;
00767         mlmd_adc[kk] = new TFile(fSharedFileName_Adc[kk],"RECREATE");
00768         fMustRecoverHistos = kFALSE;
00769       }
00770       else{
00771         cout << "Shared file found: histograms will be recovered..." << endl;
00772         mlmd_adc[kk] = TFile::Open(fSharedFileName_Adc[kk],"UPDATE");
00773         //mlmd_adc[kk]->ls();
00774       }
00775 #endif
00776     }
00777     
00778     //   LMD    TDC
00779     if(shmflg) {
00780 #if defined _FND_ONL_USE_MAP_FILES_
00781       mlmd_tdc[kk] = TMapFile::Create(fSharedMemName_Tdc[kk],"RECREATE",(Int_t)(1048576*FROOT::K_LmdItdcMapSize),"Lmd memory mapped file with INNER TDC histograms");
00782       mlmd_tdc[kk]->Print();
00783 #elif defined _FND_ONL_USE_SHARED_FILES_
00784       if( gSystem->AccessPathName(fSharedFileName_Tdc[kk]) && fMustRecoverHistos == kTRUE){
00785         cout << "Shared file missing: creating it now..." << endl;
00786         mlmd_tdc[kk] = new TFile(fSharedFileName_Tdc[kk],"RECREATE");
00787         fMustRecoverHistos = kFALSE;
00788       }
00789       else{
00790         cout << "Shared file found: histograms will be recovered..." << endl;
00791         mlmd_tdc[kk] = TFile::Open(fSharedFileName_Tdc[kk],"UPDATE");
00792         //mlmd_tdc[kk]->ls();
00793       }
00794 #endif
00795     }
00796     
00797   }
00798   
00799 }
00800 
00801 //______________________________________
00802 void TFndLmdMon::Fill() {
00803   
00804   TClonesArray *cl = fndrun->GetCurrentHdt()->GetLmdHits();
00805   Fill(*cl);
00806   
00807 }
00808 
00809 //______________________________________
00810 void TFndLmdMon::Fill(const TClonesArray &LmdHits) {
00811  
00812   Int_t nhlmd = LmdHits.GetEntries();
00813   lmdmult->Fill((Float_t) nhlmd);   // multiplicity before selection
00814 
00815   Int_t jgood = 0;
00816   Int_t n_inn = 0;
00817   Int_t n_out = 0;
00818   Int_t DchMul[K_N_LMD_TOT_CHAMS] = {0};
00819 
00820   for (Int_t j=0; j<nhlmd; j++) {
00821     TFndHLmd *hlmd = (TFndHLmd*) LmdHits[j];
00822     
00823     Int_t lay = hlmd->GetLayer();
00824     Int_t dch = hlmd->GetChamber();
00825     Int_t wire = hlmd->GetWire();
00826     
00827     Int_t dch_index = (10 *lay) + dch;
00828     
00829     Float_t ae = (Float_t ) hlmd->GetAdcE();
00830     Float_t ap = (Float_t ) hlmd->GetAdcP();
00831     Float_t te = (Float_t ) hlmd->GetTdcE();
00832     Float_t tp = (Float_t ) hlmd->GetTdcP();
00833     Float_t loc_z = hlmd->GetLocal_Z();    
00834 
00835 
00836     if(ap <=0 && ae <=0 && tp <=0 && te <=0) continue; // simply a (safe) check
00837 
00838     //if(te*tp != 0. && ae+ap == 0) hlmd->Print();
00839     Float_t tmean = (te+tp) /2;
00840     //
00841 
00842     //
00843     // Pedestal subtraction 
00844     //
00845 
00846     Float_t pede = 0.;
00847     Float_t pedp = 0.;
00848     Float_t t0e = 0.;
00849     Float_t t0p = 0.;
00850 
00851     Bool_t i_ae_ok = kFALSE;
00852     Bool_t i_ap_ok = kFALSE;
00853     Bool_t i_te_ok = kFALSE;
00854     Bool_t i_tp_ok = kFALSE;     
00855     if(ae > 0)i_ae_ok = kTRUE; // D. Faso (still not using database)
00856     if(ap > 0)i_ap_ok = kTRUE; // D. Faso (still not using database)
00857     if(te > 0)i_te_ok = kTRUE; // D. Faso (still not using database)
00858     if(tp > 0)i_tp_ok = kTRUE; // D. Faso (still not using database)
00859 
00860     // keeping "i_*_ok" for further selection-modes
00861 
00862     //     if(lmd_det && fndrun->RunConfiguration()->LmdPedestalSubtraction()) {
00863     //       pede = lmd_det->PedE(dch_index/10,dch_index%10,wire);
00864     //       pedp = lmd_det->PedP(dch_index/10,dch_index%10,wire);
00865     //       ae -= pede; ap -= pedp;
00866     //       //      cout << "ae: " << ae << ", ap: " << ap << endl;
00867     
00868     //       // Bad ADC
00869     //       //attenzione PG!      
00870     //       if(ae < 10. || ae > 4097.-pede) iaebad = 1;
00871     //       if(ap < 10. || ap > 4097.-pedp) iapbad = 1;
00872     //     }
00873     
00874     
00875     //     if(lmd_det) {
00876     //       t0e = lmd_det->TZeroE(dch_index/10,dch_index%10,wire);
00877     //       t0p = lmd_det->TZeroP(dch_index/10,dch_index%10,wire);
00878     
00879     // Bad TDC
00880     
00881     //   if(te < 900. || (te > t0e && t0e > 0.)) itebad = 1;
00882     //   if(tp < 900. || (tp > t0p && t0p > 0.)) itpbad = 1;     
00883     // attenzione PG!
00884     //     if((te > t0e && t0e > 0.) || te < (t0e-K_DRIFT_MAX_TIME)) itebad = 1;
00885     //     if((tp > t0p && t0p > 0.) || tp < (t0p-K_DRIFT_MAX_TIME)) itpbad = 1;
00886     //     }
00887     
00888     // Charge Scaling
00889     //     if(lmd_det && fndrun->RunConfiguration()->LmdChargeEqualisation()) {
00890     //       Float_t che = lmd_det->ChargeE(dch_index/10,dch_index%10,wire); 
00891     //       Float_t chp = lmd_det->ChargeP(dch_index/10,dch_index%10,wire);
00892     //       if(che) ae *= che;
00893     //       if(chp) ap *= chp;
00894     //       //      cout << "ae: " << ae << ", ap: " << ap << endl;
00895     //     }
00896     
00897     Int_t il = 0;
00898     Int_t sf = 0;
00899     Int_t idx = 0;
00900     Int_t nwire = 0;
00901     if(dch_index >= 11 && dch_index <= 18) { 
00902       sf = dch_index-11;
00903       il = 0;
00904       nwire = 12;
00905     }
00906     if(dch_index >=21 && dch_index <= 28) {
00907       sf = dch_index-21;
00908       il = 1;
00909       nwire = 22;
00910     }
00911     idx = sf+K_N_LMD_CHAMS_PER_LAYER*il;    
00912     
00913     Int_t itdc = TFndHit::E_HIT_NO_CH;
00914     if(i_te_ok  &&  i_tp_ok) itdc = TFndHit::E_HIT_BOTH_CH;
00915     if(i_te_ok  && !i_tp_ok) itdc = TFndHit::E_HIT_E_CH;
00916     if(!i_te_ok &&  i_tp_ok) itdc = TFndHit::E_HIT_P_CH;
00917     
00918     Int_t iadc = TFndHit::E_HIT_NO_CH;
00919     if(i_ae_ok  &&  i_ap_ok) iadc = TFndHit::E_HIT_BOTH_CH;
00920     if(i_ae_ok  && !i_ap_ok) iadc = TFndHit::E_HIT_E_CH;
00921     if(!i_ae_ok &&  i_ap_ok) iadc = TFndHit::E_HIT_P_CH;
00922 
00923     
00924     if( iadc != TFndHit::E_HIT_NO_CH || itdc != TFndHit::E_HIT_NO_CH ) DchMul[idx]++;
00925     if( iadc == TFndHit::E_HIT_BOTH_CH || iadc == TFndHit::E_HIT_E_CH ) lmd_all_aepat[idx]->Fill(wire);
00926     if( iadc == TFndHit::E_HIT_BOTH_CH || iadc == TFndHit::E_HIT_P_CH ) lmd_all_appat[idx]->Fill(wire);
00927     if( itdc == TFndHit::E_HIT_BOTH_CH || itdc == TFndHit::E_HIT_E_CH ) lmd_all_tepat[idx]->Fill(wire);
00928     if( itdc == TFndHit::E_HIT_BOTH_CH || itdc == TFndHit::E_HIT_P_CH ) lmd_all_tppat[idx]->Fill(wire);
00929 
00930     //
00931     // MOLTO IMPORTANTE !!!
00932     if( iadc != TFndHit::E_HIT_NO_CH || itdc != TFndHit::E_HIT_NO_CH ) lmd_all_mapadctdc[idx]->Fill(itdc,iadc);
00933     //
00934     if(ae>=0 && te >=0) lmd_all_adc_tdc[idx]->Fill(te,ae);
00935 
00936     jgood++; // no selection for now
00937     if(iadc == TFndHit::E_HIT_BOTH_CH && itdc == TFndHit::E_HIT_BOTH_CH ) lmdmap_good->Fill((Float_t) dch_index,(Float_t) wire);
00938     if(iadc!=TFndHit::E_HIT_NO_CH && itdc!=TFndHit::E_HIT_NO_CH && iadc==itdc){ // at least one side ADC && TDC
00939       lmdmap->Fill((Float_t) dch_index,(Float_t) wire);
00940     }
00941     
00942     if(iadc!=TFndHit::E_HIT_NO_CH || itdc!=TFndHit::E_HIT_NO_CH){ // at least one ADC or TDC
00943       if(dch_index >= 11 && dch_index <= 18) n_inn++;
00944       if(dch_index >= 21 && dch_index <= 28) n_out++;
00945     }
00946 
00947     // Fill histograms
00948 
00949     if(iadc != TFndHit::E_HIT_NO_CH)   lmdmapadc0->Fill((Float_t) dch_index,(Float_t) wire); // or
00950     if(iadc == TFndHit::E_HIT_BOTH_CH) lmdmapadc ->Fill((Float_t) dch_index,(Float_t) wire); // and
00951     if(i_ae_ok) lmdmapadce->Fill((Float_t) dch_index,(Float_t) wire); // e-side
00952     if(i_ap_ok) lmdmapadcp->Fill((Float_t) dch_index,(Float_t) wire); // p-side
00953     
00954     if(itdc != TFndHit::E_HIT_NO_CH) lmdmaptdc0->Fill((Float_t) dch_index,(Float_t) wire); // or
00955     if(itdc == TFndHit::E_HIT_BOTH_CH) lmdmaptdc ->Fill((Float_t) dch_index,(Float_t) wire); // and
00956     if(i_te_ok) lmdmaptdce->Fill((Float_t) dch_index,(Float_t) wire); // e-side
00957     if(i_tp_ok) lmdmaptdcp->Fill((Float_t) dch_index,(Float_t) wire); // p-side
00958     
00959     if(ae >=0) lmd_all_adce[idx]->Fill(ae);
00960     if(ap >=0) lmd_all_adcp[idx]->Fill(ap);
00961     if(ae >=0 && ap >=0){
00962       lmd_all_adc[idx]->Fill(ap,ae);
00963       lmd_all_crg[idx]->Fill(ae+ap);
00964     }
00965     //     Float_t zeta = 0.;
00966     if(ae >0 && ap >0) {
00967       //       zeta = fZetaAdjust[dch_index/10-1]*(ae-ap)/(ae+ap);
00968       lmd_all_zet[idx]->Fill(loc_z,tmean);
00969     }
00970     
00971     if(te >=0) lmd_all_tdce[idx]->Fill(te);
00972     if(tp >=0) lmd_all_tdcp[idx]->Fill(tp);
00973     if (te >0 && tp >0){
00974       lmd_all_tdc[idx]->Fill(tp,te);
00975       lmd_all_tdf[idx]->Fill(te-tp);
00976       lmd_all_tmean[idx]->Fill(tmean);
00977     }
00978     
00979     //     Float_t time_e = 0.;
00980     //     Float_t time_p = 0.;
00981     //     Float_t vp = 0.;
00982     //    if(fndrun->RunConfiguration()->LmdZeroTimeSubtraction()) {
00983     //      time_e = t0e - te;  // tempo di deriva lato e in tdc ch.
00984     //       time_p = t0p - tp;  // tempo di deriva lato p in tdc ch.
00985     //       vp = - 2. * zeta / (time_e - time_p);
00986     //       if(ae+ap != 0 && time_e > -15. && time_p > -15.) lmd_all_vp[idx]->Fill(vp);
00987     //     }
00988 
00989     // wire histograms
00990 
00991     sf = wire-1+nwire*sf+K_N_LMD_INNER_WIRES*K_N_LMD_CHAMS_PER_LAYER*il;
00992     
00993     if(ae >=0) lmdadce[sf]->Fill(ae);
00994     if(ap >=0) lmdadcp[sf]->Fill(ap);
00995     if(ae >=0 && ap >=0){
00996       lmdcrg[sf]->Fill(ae+ap);
00997       lmdzet[sf]->Fill(loc_z);
00998     }
00999 
01000     if(te >=0) lmdtdce[sf]->Fill(te); // November 29, 2006 ( if(te) )
01001     if(tp >=0) lmdtdcp[sf]->Fill(tp);
01002     if (te >0 && tp >0){
01003       lmdtdf[sf]->Fill(te-tp);
01004       lmdtmean[sf]->Fill(tmean);          
01005     }
01006   }
01007   lmdmult_good->Fill((Float_t) jgood);
01008   lmd_i_o_mult->Fill((Float_t) n_out,(Float_t) n_inn);
01009 
01010   for(Int_t id=0;id<K_N_LMD_TOT_CHAMS;id++) lmd_all_mul[id]->Fill(DchMul[id]);
01011 }
01012 
01013 //______________________________________
01014 void TFndLmdMon::Update(Bool_t purge) {
01015 
01016 #if defined _FND_ONL_USE_MAP_FILES_
01017   mlmd->Update();
01018   if(mlmd_adc[0] && mlmd_adc[0]->IsWritable() ) mlmd_adc[0]->Update();
01019   if(mlmd_tdc[0] && mlmd_tdc[0]->IsWritable() ) mlmd_tdc[0]->Update();
01020   if(mlmd_adc[1] && mlmd_adc[1]->IsWritable() ) mlmd_adc[1]->Update();
01021   if(mlmd_tdc[1] && mlmd_tdc[1]->IsWritable() ) mlmd_tdc[1]->Update();
01022 #elif defined _FND_ONL_USE_SHARED_FILES_
01023   WriteToFile(0,kTRUE);
01024 
01025   mlmd->cd();
01026   if(purge) mlmd->Purge();
01027   mlmd->Flush();
01028   //
01029   mlmd_adc[0]->cd();
01030   if(purge) mlmd_adc[0]->Purge();
01031   mlmd_adc[0]->Flush();
01032   //
01033   mlmd_adc[1]->cd();
01034   if(purge) mlmd_adc[1]->Purge();
01035   mlmd_adc[1]->Flush();
01036   //
01037   mlmd_tdc[0]->cd();
01038   if(purge) mlmd_tdc[0]->Purge();
01039   mlmd_tdc[0]->Flush();
01040   //
01041   mlmd_tdc[1]->cd();
01042   if(purge) mlmd_tdc[1]->Purge();
01043   mlmd_tdc[1]->Flush();
01044   //
01045 
01046   // --- copy shared files from here to shared directory
01047   //     (NFS safe)
01048   TString comm_cp = "";
01049   comm_cp.Form("cp ./lmd.file.map %s",FROOT::ExpandPathName("$FND_SHR/lmd.file.map").Data());
01050   gSystem->Exec(comm_cp);
01051   comm_cp.Form("cp ./lmd_i_adc.file.map %s",FROOT::ExpandPathName("$FND_SHR/lmd_i_adc.file.map").Data());
01052   gSystem->Exec(comm_cp);
01053   comm_cp.Form("cp ./lmd_o_adc.file.map %s",FROOT::ExpandPathName("$FND_SHR/lmd_o_adc.file.map").Data());
01054   gSystem->Exec(comm_cp);
01055   comm_cp.Form("cp ./lmd_i_tdc.file.map %s",FROOT::ExpandPathName("$FND_SHR/lmd_i_tdc.file.map").Data());
01056   gSystem->Exec(comm_cp);
01057   comm_cp.Form("cp ./lmd_o_tdc.file.map %s",FROOT::ExpandPathName("$FND_SHR/lmd_o_tdc.file.map").Data());
01058   gSystem->Exec(comm_cp);
01059 
01060 
01061 
01062 #endif  
01063 
01064   Info("Update","LMD histograms updated (producer)");
01065 
01066 }
01067 
01068 //______________________________________
01069 void TFndLmdMon::ResetHistos(){
01070 
01071   if(lmdmult) lmdmult->Reset();
01072   if(lmdmult_good) lmdmult_good->Reset();
01073   if(lmd_i_o_mult) lmd_i_o_mult->Reset();
01074   if(lmdmap) lmdmap->Reset();
01075   if(lmdmap_good) lmdmap_good->Reset();
01076   if(lmdmapadc0) lmdmapadc0->Reset();
01077   if(lmdmapadc) lmdmapadc->Reset();
01078   if(lmdmapadce) lmdmapadce->Reset();
01079   if(lmdmapadcp) lmdmapadcp->Reset();
01080   if(lmdmaptdc0) lmdmaptdc0->Reset();
01081   if(lmdmaptdc) lmdmaptdc->Reset();
01082   if(lmdmaptdce) lmdmaptdce->Reset();
01083   if(lmdmaptdcp) lmdmaptdcp->Reset();
01084 
01085   for (Int_t j=0;j<K_N_LMD_CHAMS_PER_LAYER;j++) {     
01086     for(Int_t ik=0;ik<2;ik++) {
01087       Int_t jk = ik*K_N_LMD_CHAMS_PER_LAYER + j;
01088       if(lmd_all_mapadctdc[jk]) lmd_all_mapadctdc[jk]->Reset();
01089       if(lmd_all_adc_tdc[jk]) lmd_all_adc_tdc[jk]->Reset();
01090       if(lmd_all_dhits[jk]) lmd_all_dhits[jk]->Reset();
01091       if(lmd_all_dhits_tdc_dopp[jk]) lmd_all_dhits_tdc_dopp[jk]->Reset();
01092       if(lmd_all_dhits_tdc_cell[jk]) lmd_all_dhits_tdc_cell[jk]->Reset();
01093       if(lmd_all_dhits_adc_dopp[jk]) lmd_all_dhits_adc_dopp[jk]->Reset();
01094       if(lmd_all_dhits_adc_cell[jk]) lmd_all_dhits_adc_cell[jk]->Reset();
01095       if(lmd_all_adce[jk]) lmd_all_adce[jk]->Reset();
01096       if(lmd_all_adcp[jk]) lmd_all_adcp[jk]->Reset();
01097       if(lmd_all_mul[jk]) lmd_all_mul[jk]->Reset();
01098       if(lmd_all_aepat[jk]) lmd_all_aepat[jk]->Reset();
01099       if(lmd_all_appat[jk]) lmd_all_appat[jk]->Reset();
01100       if(lmd_all_tepat[jk]) lmd_all_tepat[jk]->Reset();
01101       if(lmd_all_tppat[jk]) lmd_all_tppat[jk]->Reset();
01102       if(lmd_all_crg[jk]) lmd_all_crg[jk]->Reset();
01103       if(lmd_all_vp[jk]) lmd_all_vp[jk]->Reset();
01104       if(lmd_all_zet[jk]) lmd_all_zet[jk]->Reset();
01105       if(lmd_all_adc[jk]) lmd_all_adc[jk]->Reset();
01106       if(lmd_all_tdce[jk]) lmd_all_tdce[jk]->Reset();
01107       if(lmd_all_tdcp[jk]) lmd_all_tdcp[jk]->Reset();
01108       if(lmd_all_tdf[jk]) lmd_all_tdf[jk]->Reset();
01109       if(lmd_all_tmean[jk]) lmd_all_tmean[jk]->Reset();
01110       if(lmd_all_tdc[jk]) lmd_all_tdc[jk]->Reset();
01111     }
01112 
01113     for (Int_t l=0;l<(K_N_LMD_INNER_WIRES+K_N_LMD_OUTER_WIRES);l++) {
01114       Int_t k = l+j*(K_N_LMD_INNER_WIRES+K_N_LMD_OUTER_WIRES);
01115       if(lmdadce[k]) lmdadce[k]->Reset();
01116       if(lmdadcp[k]) lmdadcp[k]->Reset();
01117       if(lmdcrg[k]) lmdcrg[k]->Reset();
01118       if(lmdzet[k]) lmdzet[k]->Reset();
01119       // if(lmdadc[k]) lmdadc[k]->Reset();
01120       if(lmdtdce[k]) lmdtdce[k]->Reset();
01121       if(lmdtdcp[k]) lmdtdcp[k]->Reset();
01122       if(lmdtdf[k]) lmdtdf[k]->Reset();
01123       if(lmdtmean[k]) lmdtmean[k]->Reset();
01124       // if(lmdtdc[k]) lmdtdc[k]->Reset();
01125     }
01126   }       
01127 
01128 }
01129 
01130 //______________________________________
01131 void TFndLmdMon::WriteToFile(TString file,Bool_t IsShared) {
01132   // COMPLETARE per files in online-mode
01133 
01134   if(IsShared){
01135     //    Info("TFndLmdMon::WriteToFile","Writing histograms in on-line mode");
01136     mlmd->cd();
01137   }
01138   else{
01139     if(file.IsNull()) 
01140       flmd->cd();
01141     else {
01142       fout = new TFile(file.Data(),"RECREATE","Lmd Histogram File");
01143       fout->cd();
01144     }
01145   }
01146   
01147   if(lmdmult) lmdmult->Write();
01148   if(lmdmult_good) lmdmult_good->Write();
01149   if(lmd_i_o_mult) lmd_i_o_mult->Write();
01150   if(lmdmap) lmdmap->Write();
01151   if(lmdmap_good) lmdmap_good->Write();
01152   if(lmdmapadc0) lmdmapadc0->Write();
01153   if(lmdmapadc) lmdmapadc->Write();
01154   if(lmdmapadce) lmdmapadce->Write();
01155   if(lmdmapadcp) lmdmapadcp->Write();
01156   if(lmdmaptdc0) lmdmaptdc0->Write();
01157   if(lmdmaptdc) lmdmaptdc->Write();
01158   if(lmdmaptdce) lmdmaptdce->Write();
01159   if(lmdmaptdcp) lmdmaptdcp->Write();
01160   
01161   for (Int_t ji=0;ji<K_N_LMD_LAYERS;ji++) {     
01162     for (Int_t j=0;j<K_N_LMD_CHAMS_PER_LAYER;j++) {
01163       Int_t id = K_N_LMD_CHAMS_PER_LAYER*ji + j;     
01164       lmd_all_mapadctdc[id]->Write();
01165       lmd_all_adc_tdc[id]->Write();
01166       lmd_all_dhits[id]->Write();
01167       lmd_all_dhits_tdc_dopp[id]->Write();
01168       lmd_all_dhits_tdc_cell[id]->Write();
01169       lmd_all_dhits_adc_dopp[id]->Write();
01170       lmd_all_dhits_adc_cell[id]->Write();
01171       lmd_all_mul[id]->Write();
01172     }
01173   }   
01174   
01175   for(Int_t kk=0;kk<K_N_LMD_LAYERS;kk++) {
01176     Int_t nwires = 12 + kk*10;
01177 
01178     //ADC
01179     if(IsShared){
01180       //      Info("TFndLmdMon::WriteToFile","Writing histograms in on-line mode (ADCs: layer %d)",kk);
01181       mlmd_adc[kk]->cd();
01182       //       if(kk==0) mlmd_adc[0]->cd();
01183       //       else mlmd_o_adc->cd();
01184     }
01185     for (Int_t jj=0;jj<K_N_LMD_CHAMS_PER_LAYER;jj++) {     
01186       Int_t j = K_N_LMD_CHAMS_PER_LAYER*kk+jj;
01187       lmd_all_adce[j]->Write();
01188       lmd_all_adcp[j]->Write();
01189 
01190       Int_t nwir = K_N_LMD_INNER_WIRES;
01191       if(kk==1) nwir = K_N_LMD_OUTER_WIRES;
01192       lmd_all_crg[j]->Write();
01193       lmd_all_vp[j]->Write();
01194       lmd_all_zet[j]->Write();
01195       lmd_all_adc[j]->Write();
01196       lmd_all_aepat[j]->Write();
01197       lmd_all_appat[j]->Write();
01198       
01199       for (Int_t l=0;l<nwires;l++) {
01200         Int_t k = K_N_LMD_INNER_WIRES*K_N_LMD_CHAMS_PER_LAYER*kk+l+jj*nwires;   
01201         lmdadce[k]->Write();
01202         lmdadcp[k]->Write();
01203         lmdcrg[k]->Write();
01204         lmdzet[k]->Write();
01205       }
01206     }
01207 
01208     //TDC
01209     if(IsShared) mlmd_tdc[kk]->cd();
01210 
01211     for (Int_t jk=0;jk<K_N_LMD_CHAMS_PER_LAYER;jk++) {     
01212       Int_t ij = K_N_LMD_CHAMS_PER_LAYER*kk+jk;
01213       lmd_all_tdce[ij]->Write();
01214       lmd_all_tdcp[ij]->Write();
01215       lmd_all_tdf[ij]->Write();
01216       lmd_all_tmean[ij]->Write();
01217       lmd_all_tdc[ij]->Write();
01218       lmd_all_tepat[ij]->Write();
01219       lmd_all_tppat[ij]->Write();
01220       
01221       for (Int_t l=0;l<nwires;l++) {
01222         Int_t k = K_N_LMD_INNER_WIRES*K_N_LMD_CHAMS_PER_LAYER*kk+l+jk*nwires;
01223         
01224         lmdtdce[k]->Write();
01225         lmdtdcp[k]->Write();
01226         lmdtdf[k]->Write();
01227         lmdtmean[k]->Write();
01228       }
01229     }
01230   }
01231   
01232   //   for (Int_t j=0;j<K_N_LMD_CHAMS_PER_LAYER;j++) {     
01233   //     for(Int_t ik=0;ik<2;ik++) {
01234   //       Int_t jk = ik*K_N_LMD_CHAMS_PER_LAYER + j;
01235   //       if(lmd_all_mapadctdc[jk]) lmd_all_mapadctdc[jk]->Write();
01236   //       if(lmd_all_adc_tdc[jk]) lmd_all_adc_tdc[jk]->Write();
01237   //       if(lmd_all_dhits[jk]) lmd_all_dhits[jk]->Write();
01238   //       if(lmd_all_dhits_tdc_dopp[jk]) lmd_all_dhits_tdc_dopp[jk]->Write();
01239   //       if(lmd_all_dhits_tdc_cell[jk]) lmd_all_dhits_tdc_cell[jk]->Write();
01240   //       if(lmd_all_dhits_adc_dopp[jk]) lmd_all_dhits_adc_dopp[jk]->Write();
01241   //       if(lmd_all_dhits_adc_cell[jk]) lmd_all_dhits_adc_cell[jk]->Write();
01242   //       if(lmd_all_adce[jk]) lmd_all_adce[jk]->Write();
01243   //       if(lmd_all_adcp[jk]) lmd_all_adcp[jk]->Write();
01244   //       if(lmd_all_adceped[jk]) lmd_all_adceped[jk]->Write();
01245   //       if(lmd_all_adcpped[jk]) lmd_all_adcpped[jk]->Write();
01246   //       if(lmd_all_crg[jk]) lmd_all_crg[jk]->Write();
01247   //       if(lmd_all_vp[jk]) lmd_all_vp[jk]->Write();
01248   //       if(lmd_all_zet[jk]) lmd_all_zet[jk]->Write();
01249   //       if(lmd_all_adc[jk]) lmd_all_adc[jk]->Write();
01250   //       if(lmd_all_tdce[jk]) lmd_all_tdce[jk]->Write();
01251   //       if(lmd_all_tdcp[jk]) lmd_all_tdcp[jk]->Write();
01252   //       if(lmd_all_tdf[jk]) lmd_all_tdf[jk]->Write();
01253   //       if(lmd_all_tmean[jk]) lmd_all_tmean[jk]->Write();
01254   //       if(lmd_all_tdc[jk]) lmd_all_tdc[jk]->Write();
01255   //     }
01256   //   }
01257   //
01258   //     for (Int_t l=0;l<(K_N_LMD_INNER_WIRES+K_N_LMD_OUTER_WIRES);l++) {
01259   //       Int_t k = l+j*(K_N_LMD_INNER_WIRES+K_N_LMD_OUTER_WIRES);
01260   //       if(lmdadce[k]) lmdadce[k]->Write();
01261   //       if(lmdadcp[k]) lmdadcp[k]->Write();
01262   //       if(lmdcrg[k]) lmdcrg[k]->Write();
01263   //       if(lmdzet[k]) lmdzet[k]->Write();
01264   //       // if(lmdadc[k]) lmdadc[k]->Write();
01265   //     }
01266   //     for (Int_t l=0;l<(K_N_LMD_INNER_WIRES+K_N_LMD_OUTER_WIRES);l++) {
01267   //       Int_t k = l+j*(K_N_LMD_INNER_WIRES+K_N_LMD_OUTER_WIRES);
01268   //       if(lmdtdce[k]) lmdtdce[k]->Write();
01269   //       if(lmdtdcp[k]) lmdtdcp[k]->Write();
01270   //       if(lmdtdf[k]) lmdtdf[k]->Write();
01271   //       if(lmdtmean[k]) lmdtmean[k]->Write();
01272   //       // if(lmdtdc[k]) lmdtdc[k]->Write();
01273   //     }
01274   //   }       
01275   // if(file.IsNull()) flmd->Close();
01276   // else fout->Close();
01277   
01278 }
01279 
01280 //______________________________________
01281 void TFndLmdMon::TimeCalibration(Int_t layer, Int_t dch, Int_t wire, Float_t scal_fac){
01282 
01283   /*
01284     if(layer < 1 || layer > K_N_LMD_LAYERS) {
01285     cout << "Wrong layer number" << endl;
01286     return;
01287     }
01288     if(dch < 1 || dch > K_N_LMD_CHAMS_PER_LAYER) {
01289     cout << "Wrong chamber number" << endl;
01290     return;
01291     }
01292     Int_t wmax = K_N_LMD_INNER_WIRES;
01293     if(layer == 2) wmax = K_N_LMD_OUTER_WIRES;
01294     if(wire < 1 || wire > wmax) {
01295     cout << "Wrong wire number" << endl;
01296     return;
01297     }
01298 
01299     cout << "Layer: " << layer << ", Chamber: " << dch << ", Wire: " << wire << endl;
01300     for(Int_t k=0; k<3; k++) ZeroTime[layer-1][dch-1][wire-1][k] = 0.;
01301 
01302     Int_t idx = wire-1+(dch-1)*wmax;
01303     if(layer == 2) idx += K_N_LMD_CHAMS_PER_LAYER*K_N_LMD_INNER_WIRES;
01304 
01305     Int_t lmd_tdc_bins = lmdtmean[idx]->GetNbinsX();
01306     Float_t lmd_tdc_min = lmdtmean[idx]->GetBinLowEdge(1);
01307     Float_t lmd_tdc_max = lmdtmean[idx]->GetBinLowEdge(lmd_tdc_bins);
01308     Float_t binsize = (lmd_tdc_max-lmd_tdc_min)/(lmd_tdc_bins-1);
01309     cout << "binsize: " << binsize << endl;
01310     const Int_t nwidth = 16;
01311     const Float_t cell_length = 24900.;
01312 
01313     Float_t high = 1600.;
01314     Float_t low  = 1100.;  // anche low = 1200. !
01315     TF1 *plateau = new TF1("plateau", "pol1", low, high);
01316 
01317     TH1F *h1[3];
01318     h1[0] = lmdtdce[idx];
01319     h1[1] = lmdtdcp[idx];
01320     h1[2] = lmdtmean[idx];
01321 
01322     Float_t t1 = 0;
01323     for(Int_t k = 0; k < 3; k++) {
01324     h1[k]->Fit("plateau","RQ");
01325     Float_t ChiSquared = (Float_t) plateau->GetChisquare();
01326     Int_t NDF = plateau->GetNumberFitPoints() - plateau->GetNpar();
01327     //    Float_t plat = (Float_t) plateau->GetParameter(0)/scal_fac;
01328     Float_t plat1 = (Float_t) plateau->GetParameter(0);
01329     Float_t plat2 = (Float_t) plateau->GetParameter(1);
01330     Float_t plat = plat1 + plat2*(high+low)/2.;
01331     plat /= scal_fac;
01332     //printf("end of cell\n");
01333     Int_t nbins = h1[k]->GetNbinsX();
01334     //lmdtmean[idx]->GetNbinsX();
01335     Int_t nb = 0;
01336     for(nb=0; nb<nbins/2; nb++) {
01337     if(h1[k]->GetBinContent(nb+1) > plat) break;
01338     }
01339     TF1 *endcell = new TF1("endcell", "pol1", lmd_tdc_min+binsize*(nb-nwidth), lmd_tdc_min+binsize*(nb+nwidth));
01340     endcell->SetLineColor(2);
01341     h1[k]->Fit("endcell","RQ");
01342     ChiSquared = (Float_t) endcell->GetChisquare();
01343     NDF = endcell->GetNumberFitPoints() - endcell->GetNpar();
01344     Float_t endc1 = (Float_t) endcell->GetParameter(0);
01345     Float_t endc2 = (Float_t) endcell->GetParameter(1);
01346 
01347     if(endc2 != 0 && k == 2) t1 = (plat-endc1)/endc2;
01348     for(Int_t nnb=nbins/2; nnb<nbins; nnb++) {
01349     Bool_t lfit = 0;
01350     lfit = h1[k]->GetBinContent(nnb+1) < plat && h1[k]->GetBinContent(nnb+2) < plat && h1[k]->GetBinContent(nnb+3) < plat;
01351     Float_t b1 = 0;
01352     Float_t b2 = 0;
01353     if(lfit) {
01354     b1 = h1[k]->GetBinContent(nnb);
01355     b2 = h1[k]->GetBinContent(nnb+1);
01356     if(b1 != b2) ZeroTime[layer-1][dch-1][wire-1][k] = h1[k]->GetBinLowEdge(nnb) + binsize*(0.5+(b1-plat)/(b1-b2));
01357     break;
01358     }
01359     }
01360     }
01361   
01362     if(t1 != ZeroTime[layer-1][dch-1][wire-1][2])
01363     DriftSpeed[layer-1][dch-1][wire-1] = 2.*cell_length/(ZeroTime[layer-1][dch-1][wire-1][2]-t1);  // micron/ns
01364 
01365     cout << "ZeroTime[" << layer-1 << "][" << dch-1 << "][" << wire-1 << "][0]: " <<  ZeroTime[layer-1][dch-1][wire-1][0] << endl;
01366     cout << "ZeroTime[" << layer-1 << "][" << dch-1 << "][" << wire-1 << "][1]: " <<  ZeroTime[layer-1][dch-1][wire-1][1] << endl;
01367     cout << "ZeroTime[" << layer-1 << "][" << dch-1 << "][" << wire-1 << "][2]: " <<  ZeroTime[layer-1][dch-1][wire-1][2] << endl;
01368   */
01369 }
01370 
01371 //______________________________________
01372 void TFndLmdMon::TimeCalibration(Int_t layer, Int_t dch, Float_t scal_fac){
01373 
01374   /*
01375     if(layer < 1 || layer > K_N_LMD_LAYERS) {
01376     cout << "Wrong layer number" << endl;
01377     return;
01378     }
01379     if(dch < 1 || dch > K_N_LMD_CHAMS_PER_LAYER) {
01380     cout << "Wrong chamber number" << endl;
01381     return;
01382     }
01383     Int_t wires = K_N_LMD_INNER_WIRES;
01384     if(layer == 2) wires = K_N_LMD_OUTER_WIRES;
01385     for(Int_t i=1; i<=wires; i++) TimeCalibration(layer,dch,i,scal_fac);
01386   */
01387 }
01388 
01389 //______________________________________
01390 void TFndLmdMon::TimeCalibration(Float_t scal_fac){
01391 
01392   for(Int_t i=1; i<=K_N_LMD_LAYERS; i++) 
01393     for(Int_t j=1; j<=K_N_LMD_CHAMS_PER_LAYER; j++)
01394       TimeCalibration(i,j,scal_fac);
01395 }
01396 
01397 //______________________________________
01398 void TFndLmdMon::ChargeCalibration(Int_t layer, Int_t dch, Int_t wire){
01399 
01400   /*
01401     if(layer < 1 || layer > K_N_LMD_LAYERS) {
01402     cout << "Wrong layer number" << endl;
01403     return;
01404     }
01405     if(dch < 1 || dch > K_N_LMD_CHAMS_PER_LAYER) {
01406     cout << "Wrong chamber number" << endl;
01407     return;
01408     }
01409     Int_t wmax = K_N_LMD_INNER_WIRES;
01410     if(layer == 2) wmax = K_N_LMD_OUTER_WIRES;
01411     if(wire < 1 || wire > wmax) {
01412     cout << "Wrong wire number" << endl;
01413     return;
01414     }
01415 
01416     cout << "ADC Calibration Parameters for Layer: " << layer << ", Dch: " << dch << ", Wire: " << wire << endl;
01417     for(Int_t k=0; k<2; k++) ChargeCalib[layer-1][dch-1][wire-1][k] = 1.;
01418 
01419     Int_t idx = wire-1+(dch-1)*wmax;
01420     if(layer == 2) idx += K_N_LMD_CHAMS_PER_LAYER*K_N_LMD_INNER_WIRES;
01421   
01422     Float_t calpars[5];
01423 
01424     Float_t average = 400.;
01425     Float_t width = 100.;
01426     Float_t norm = average;
01427     Float_t adc_cut = 150.;
01428     //  Float_t e_p_scal = 1.0;  // E to P side scaling factor
01429 
01430     TH1F *h1[2];
01431     h1[0] = lmdadce[idx];
01432     h1[1] = lmdadcp[idx];
01433     for(Int_t j=0; j<2; j++) {
01434     Int_t lmd_bins = h1[j]->GetNbinsX();
01435     Float_t lmd_min = h1[j]->GetBinLowEdge(1);
01436     Float_t lmd_max = h1[j]->GetBinLowEdge(lmd_bins);
01437     Float_t binsize = (lmd_max-lmd_min)/(lmd_bins-1);
01438     Int_t maxcont = 0;
01439     for(Int_t k=0; k<lmd_bins; k++) {
01440     Int_t newcont = (Int_t) h1[j]->GetBinContent(k);
01441     if(lmd_min + k*binsize > adc_cut) {
01442     if(newcont > maxcont) {
01443     maxcont = newcont;
01444     average = lmd_min + k*binsize;
01445     }
01446     }
01447       
01448     }
01449     
01450     TF1 *ga = new TF1("ga","gaus",average-width,average+width);
01451   */
01452 }
01453 
01454 //______________________________________
01455 void TFndLmdMon::ChargeCalibration(Int_t layer, Int_t dch){
01456 
01457   /*
01458     if(layer < 1 || layer > K_N_LMD_LAYERS) {
01459     cout << "Wrong layer number" << endl;
01460     return;
01461     }
01462     if(dch < 1 || dch > K_N_LMD_CHAMS_PER_LAYER) {
01463     cout << "Wrong chamber number" << endl;
01464     return;
01465     }
01466     Int_t wires = K_N_LMD_INNER_WIRES;
01467     if(layer == 2) wires = K_N_LMD_OUTER_WIRES;
01468     for(Int_t i=1; i<=wires; i++) ChargeCalibration(layer,dch,i);
01469   */
01470 }
01471 
01472 //______________________________________
01473 void TFndLmdMon::ChargeCalibration(){
01474   for(Int_t i=1; i<=K_N_LMD_LAYERS; i++) 
01475     for(Int_t j=1; j<=K_N_LMD_CHAMS_PER_LAYER; j++)
01476       ChargeCalibration(i,j);
01477 }
01478 
01479 //______________________________________
01480 void TFndLmdMon::PedestalsEvaluation(){
01481 
01482   /*
01483     for (Int_t kk=0;kk<K_N_LMD_LAYERS;kk++) {     
01484     Int_t wires = 12 + kk*10;
01485     for (Int_t jj=0;jj<K_N_LMD_CHAMS_PER_LAYER;jj++) {     
01486     for (Int_t l=0;l<wires;l++) {
01487     Int_t k = K_N_LMD_INNER_WIRES*K_N_LMD_CHAMS_PER_LAYER*kk+l+jj*wires;
01488     cout << "Layer: " << kk+1 << ", Dch: " << jj+1 << ", Wire: " << l+1 << endl;
01489     Float_t pede = (Float_t) lmdadce[k]->GetMean();
01490     Float_t sigf = (Float_t) lmdadce[k]->GetRMS();
01491     Float_t pedp = (Float_t) lmdadcp[k]->GetMean();
01492     Float_t sigr = (Float_t) lmdadcp[k]->GetRMS();
01493     cout << "Pede: " << pede << ", Pedp: " << pedp << endl;
01494     lmd_all_adceped[kk*K_N_LMD_CHAMS_PER_LAYER+jj]->Fill(Float_t (l+1),pede);
01495     lmd_all_adceped[kk*K_N_LMD_CHAMS_PER_LAYER+jj]->SetBinError(l+1,sigf);
01496     lmd_all_adcpped[kk*K_N_LMD_CHAMS_PER_LAYER+jj]->Fill(Float_t (l+1),pedp);
01497     lmd_all_adcpped[kk*K_N_LMD_CHAMS_PER_LAYER+jj]->SetBinError(l+1,sigr);
01498     }
01499     }
01500     }
01501   */
01502 }
01503 
01504 //______________________________________
01505 void TFndLmdMon::WritePedestalsToMsql(){
01506   
01507   /*
01508     cout << "Write Lmd Msql Pedestal file" << endl;
01509     TString *lmd_ped_file = new TString("lmd_pedestals.msql");
01510     FILE *flmd_ped;
01511     flmd_ped = fopen(lmd_ped_file->Data(),"w+");
01512     fprintf(flmd_ped,"# Host: localhost    Database: LmdDB\n");
01513     fprintf(flmd_ped,"# Table structure for table 'pede'\n");
01514     fprintf(flmd_ped,"CREATE TABLE pede (\n");
01515     fprintf(flmd_ped,"  w   INT,\n");
01516     fprintf(flmd_ped,"  A   INT,\n");
01517     fprintf(flmd_ped,"  Z   INT,\n");
01518     fprintf(flmd_ped,"  p0e  REAL,\n");
01519     fprintf(flmd_ped,"  p0p  REAL\n");
01520     fprintf(flmd_ped,")g\n");
01521 
01522     TString *lmd_ped_asc = new TString("lmd_pedestals.cal");
01523     FILE *flmd_p_asc;
01524     flmd_p_asc = fopen(lmd_ped_asc->Data(),"w+");
01525 
01526     Int_t start_time = 11111;
01527     Int_t stop_time = 2000000000;
01528 
01529     for(Int_t i=0; i<K_N_LMD_LAYERS;i++){ 
01530     for(Int_t j=0; j<K_N_LMD_CHAMS_PER_LAYER;j++){ 
01531     Int_t nwires = K_N_LMD_INNER_WIRES;
01532     if(i==1) nwires = K_N_LMD_OUTER_WIRES;
01533     Int_t dch = 1000*(i+1)+100*(j+1);
01534     for(Int_t k=0; k<nwires;k++){ 
01535     Int_t wire = dch+k+1;
01536     Float_t pedef = 0;
01537     Float_t peder = 0;
01538         
01539     TString line_start = TString("INSERT INTO pede VALUES (");
01540     pedef = lmd_all_adceped[i*K_N_LMD_CHAMS_PER_LAYER+j]->GetBinContent(k+1);
01541     peder = lmd_all_adcpped[i*K_N_LMD_CHAMS_PER_LAYER+j]->GetBinContent(k+1);
01542           
01543     line_start+=wire;
01544     line_start+=",";
01545     line_start+=start_time;
01546     line_start+=",";
01547     line_start+=stop_time;
01548     line_start+=",";
01549     line_start+=pedef;
01550     line_start+=",";
01551     line_start+=peder;
01552     line_start+=")g";
01553     fprintf(flmd_ped,"%s\n",line_start.Data());
01554           
01555     TString line_start2 = TString("UpLmdDbP ");
01556     line_start2+=wire;
01557     line_start2+=" ";
01558     line_start2+=start_time;
01559     line_start2+=" ";
01560     line_start2+=pedef;
01561     line_start2+=" ";
01562     line_start2+=peder;
01563     fprintf(flmd_p_asc,"%s\n",line_start2.Data());
01564     }
01565     }
01566     }
01567     fclose(flmd_ped);
01568     fclose(flmd_p_asc);
01569   */
01570 }
01571 
01572 //______________________________________
01573 void TFndLmdMon::WritePedestalsToMsql(Int_t runtime){
01574 
01575   /*  
01576       cout << "Write Lmd Msql Pedestal file" << endl;
01577 
01578       TString *lmd_ped_asc = new TString("lmd_pedestals.cal");
01579       FILE *flmd_p_asc;
01580       flmd_p_asc = fopen(lmd_ped_asc->Data(),"w+");
01581 
01582       Int_t start_time = runtime;
01583       //  Int_t start_time = 11111; 
01584 
01585       for(Int_t i=0; i<K_N_LMD_LAYERS;i++){ 
01586       for(Int_t j=0; j<K_N_LMD_CHAMS_PER_LAYER;j++){ 
01587       Int_t nwires = K_N_LMD_INNER_WIRES;
01588       if(i==1) nwires = K_N_LMD_OUTER_WIRES;
01589       Int_t dch = 1000*(i+1)+100*(j+1);
01590       for(Int_t k=0; k<nwires;k++){ 
01591       Int_t wire = dch+k+1;
01592       Float_t pedef = 0;
01593       Float_t peder = 0;        
01594       pedef = lmd_all_adceped[i*K_N_LMD_CHAMS_PER_LAYER+j]->GetBinContent(k+1);
01595       peder = lmd_all_adcpped[i*K_N_LMD_CHAMS_PER_LAYER+j]->GetBinContent(k+1);
01596       // stringa da scrivere: LmdDBUpdate P w a p0p p0e
01597       TString line_start = TString("./LmdDBUpdate P ");
01598       line_start+=wire;
01599       line_start+=" ";
01600       line_start+=start_time;
01601       line_start+=" ";
01602       line_start+=peder;   // controllare che cpdr corrisponda al lato p
01603       line_start+=" ";
01604       line_start+=pedef;   // controllare che cpdf corrisponda al lato e
01605       fprintf(flmd_p_asc,"%s\n",line_start.Data());
01606       }
01607       }    
01608       }
01609       fclose(flmd_p_asc);
01610   */
01611 }
01612 
01613 //______________________________________
01614 void TFndLmdMon::WriteTimeToMsql(Int_t runtime,Char_t *ev_type){
01615   // ev_type: "C" (From vertex Center) ; "T" (Cosmic Event)
01616 
01617   /*
01618     cout << "Write Lmd Msql Time Calibration file" << endl;
01619 
01620     TString *lmd_time_asc = new TString("lmd_time.cal");
01621     FILE *flmd_time_asc;
01622     flmd_time_asc = fopen(lmd_time_asc->Data(),"w+");
01623 
01624     Int_t start_time = runtime;
01625     Int_t stop_time = 2000000000;  // ok per costanti nuove!
01626 
01627     for(Int_t i=0; i<K_N_LMD_LAYERS;i++){ 
01628     for(Int_t j=0; j<K_N_LMD_CHAMS_PER_LAYER;j++){ 
01629     Int_t nwires = K_N_LMD_INNER_WIRES;
01630     if(i==1) nwires = K_N_LMD_OUTER_WIRES;
01631     Int_t dch = 1000*(i+1)+100*(j+1);
01632     for(Int_t k=0; k<nwires;k++){ 
01633     Int_t wire = dch+k+1;
01634     // stringa da scrivere: LmdDBUpdate T w a z t0p t0e t0
01635     TString line_start = TString("./LmdDBUpdate ");
01636     line_start+=ev_type;
01637     line_start+=" ";
01638     line_start+=wire;
01639     line_start+=" ";
01640     line_start+=start_time;
01641     line_start+=" ";
01642     line_start+=stop_time;
01643     line_start+=" ";
01644     line_start+=ZeroTime[i][j][k][1];
01645     line_start+=" ";
01646     line_start+=ZeroTime[i][j][k][0];
01647     line_start+=" ";
01648     line_start+=ZeroTime[i][j][k][2];
01649     fprintf(flmd_time_asc,"%s\n",line_start.Data());
01650     }
01651     }
01652     }
01653     fclose(flmd_time_asc);
01654   */
01655 }
01656 
01657 //______________________________________
01658 void TFndLmdMon::WriteChargeToMsql(){
01659   
01660   /*
01661     cout << "Write Lmd Msql Charge Calibration file" << endl;
01662     TString *lmd_charge_cal_file = new TString("lmd_charge_calibration.msql");
01663     FILE *flmd_charge_cal;
01664     flmd_charge_cal = fopen(lmd_charge_cal_file->Data(),"w+");
01665     fprintf(flmd_charge_cal,"# Host: localhost    Database: LmdDB\n");
01666     fprintf(flmd_charge_cal,"# Table structure for table 'cal'\n");
01667     fprintf(flmd_charge_cal,"CREATE TABLE charge_cal (\n");
01668     fprintf(flmd_charge_cal,"  w INT,\n");
01669     fprintf(flmd_charge_cal,"  A INT,\n");
01670     fprintf(flmd_charge_cal,"  Z INT,\n");
01671     fprintf(flmd_charge_cal,"  q0p REAL,\n");
01672     fprintf(flmd_charge_cal,"  q0e REAL,\n");
01673     fprintf(flmd_charge_cal,"  q1p REAL,\n");
01674     fprintf(flmd_charge_cal,"  q1e REAL\n");
01675     fprintf(flmd_charge_cal,")g\n");
01676 
01677     TString *lmd_crg_asc = new TString("lmd_charge.cal");
01678     FILE *flmd_charge_asc;
01679     flmd_charge_asc = fopen(lmd_crg_asc->Data(),"w+");
01680 
01681 
01682     Int_t start_time = 11111;
01683     Int_t stop_time = 2000000000;
01684     Float_t q1p = 33333;
01685     Float_t q1e = 44444;
01686     for(Int_t ii=0; ii<K_N_LMD_LAYERS;ii++){ 
01687     for(Int_t ij=0; ij<K_N_LMD_CHAMS_PER_LAYER;ij++){ 
01688     Int_t nwires = K_N_LMD_INNER_WIRES;
01689     if(ii==1) nwires = K_N_LMD_OUTER_WIRES;
01690     Int_t dch = 1000*(ii+1)+100*(ij+1);
01691     for(Int_t ik=0; ik<nwires;ik++){ 
01692     Int_t wire = dch+ik+1;
01693     TString line_start = TString("INSERT INTO charge_cal VALUES (");
01694     line_start+=wire;            line_start+=",";
01695     line_start+=start_time;      line_start+=",";
01696     line_start+=stop_time;       line_start+=",";
01697     line_start+=ChargeCalib[ii][ij][ik][1];  line_start+=","; // cq0p
01698     line_start+=ChargeCalib[ii][ij][ik][0];  line_start+=","; // cq0e
01699     line_start+=q1p;  line_start+=",";  // cq1p
01700     line_start+=q1e;  line_start+=")g"; // cq1e
01701     fprintf(flmd_charge_cal,"%s\n",line_start.Data());
01702 
01703     TString line_start2 = TString("UpLmdDbQ ");
01704     line_start2+=wire;         line_start2+=" ";
01705     line_start2+=start_time;   line_start2+=" ";
01706     line_start2+=ChargeCalib[ii][ij][ik][1];  line_start2+=" ";  // cq0p
01707     line_start2+=ChargeCalib[ii][ij][ik][0];  // cq0e
01708     fprintf(flmd_charge_asc,"%s\n",line_start2.Data());
01709     }
01710     }
01711     }
01712     fclose(flmd_charge_cal);
01713     fclose(flmd_charge_asc);
01714   */
01715 } 
01716   
01717 //______________________________________
01718 void TFndLmdMon::WriteChargeToMsql(Int_t runtime){
01719   
01720   /*
01721     cout << "Write Lmd Msql Charge Calibration file" << endl;
01722 
01723     TString *lmd_crg_asc = new TString("lmd_charge.cal");
01724     FILE *flmd_charge_asc;
01725     flmd_charge_asc = fopen(lmd_crg_asc->Data(),"w+");
01726 
01727     Int_t start_time = runtime;
01728 
01729     for(Int_t ii=0; ii<K_N_LMD_LAYERS;ii++){ 
01730     for(Int_t ij=0; ij<K_N_LMD_CHAMS_PER_LAYER;ij++){ 
01731     Int_t nwires = K_N_LMD_INNER_WIRES;
01732     if(ii==1) nwires = K_N_LMD_OUTER_WIRES;
01733     Int_t dch = 1000*(ii+1)+100*(ij+1);
01734     for(Int_t ik=0; ik<nwires;ik++){ 
01735     //cout << "Layer: " << ii+1 << ", Chamber: " << ij+1 << ", Wire: " << ik+1 << endl;
01736     Int_t wire = dch+ik+1;
01737     // stringa da scrivere: LmdDBUpdate C w a q0p q0e
01738     TString line_start = TString("./LmdDBUpdate Q ");
01739     line_start+=wire;
01740     line_start+=" ";
01741     line_start+=start_time;
01742     line_start+=" ";
01743     line_start+=ChargeCalib[ii][ij][ik][1];
01744     line_start+=" ";
01745     line_start+=ChargeCalib[ii][ij][ik][0];
01746     fprintf(flmd_charge_asc,"%s\n",line_start.Data());
01747     }
01748     }
01749     }
01750     fclose(flmd_charge_asc);
01751   */
01752 } 
01753 
01754 //______________________________________
01755 void TFndLmdMon::Add(TFndLmdMon *lmdmon) {
01756 
01757   for (Int_t i=0;i<K_N_LMD_LAYERS;i++) {    
01758     for (Int_t j=0;j<K_N_LMD_CHAMS_PER_LAYER;j++) {     
01759       Int_t nwire = K_N_LMD_INNER_WIRES;
01760       if(i == 1) nwire = K_N_LMD_OUTER_WIRES;
01761       Int_t idx1 = j+i*K_N_LMD_CHAMS_PER_LAYER;
01762       lmd_all_mapadctdc[idx1]->Add((const TH2 *) lmdmon->LmdAllMapAdcTdc(idx1));
01763       lmd_all_adc[idx1]->Add((const TH2 *) lmdmon->LmdAllAdc(idx1));
01764       lmd_all_adce[idx1]->Add((const TH1 *) lmdmon->LmdAllAdcE(idx1));
01765       lmd_all_adcp[idx1]->Add((const TH1 *) lmdmon->LmdAllAdcP(idx1));
01766       lmd_all_adc_tdc[idx1]->Add((const TH2 *) lmdmon->LmdAllAdcTdc(idx1));
01767       lmd_all_mul[idx1]->Add((const TH1 *) lmdmon->LmdAllMul(idx1));
01768       lmd_all_aepat[idx1]->Add((const TH1 *) lmdmon->LmdAllAdcEPat(idx1));
01769       lmd_all_appat[idx1]->Add((const TH1 *) lmdmon->LmdAllAdcPPat(idx1));
01770       lmd_all_tepat[idx1]->Add((const TH1 *) lmdmon->LmdAllTdcEPat(idx1));
01771       lmd_all_tppat[idx1]->Add((const TH1 *) lmdmon->LmdAllTdcPPat(idx1));
01772       lmd_all_crg[idx1]->Add((const TH1 *) lmdmon->LmdAllCrg(idx1));
01773       lmd_all_zet[idx1]->Add((const TH2 *) lmdmon->LmdAllZet(idx1));
01774 
01775       lmd_all_tdc[idx1]->Add((const TH2 *) lmdmon->LmdAllTdc(idx1));
01776       lmd_all_tdce[idx1]->Add((const TH1 *) lmdmon->LmdAllTdcE(idx1));
01777       lmd_all_tdcp[idx1]->Add((const TH1 *) lmdmon->LmdAllTdcP(idx1));
01778       lmd_all_tdf[idx1]->Add((const TH1 *) lmdmon->LmdAllTdf(idx1));
01779       lmd_all_tmean[idx1]->Add((const TH1 *) lmdmon->LmdAllTmean(idx1));
01780 
01781       for (Int_t l=0;l<nwire;l++) {
01782         Int_t idx = l + j * nwire + i *K_N_LMD_INNER_WIRES * K_N_LMD_CHAMS_PER_LAYER;
01783         lmdadce[idx]->Add((const TH1 *) lmdmon->LmdAdcE(idx));
01784         lmdadcp[idx]->Add((const TH1 *) lmdmon->LmdAdcP(idx));
01785         lmdcrg[idx]->Add((const TH1 *) lmdmon->LmdCrg(idx));
01786         lmdzet[idx]->Add((const TH1 *) lmdmon->LmdZet(idx));
01787 
01788         lmdtdce[idx]->Add((const TH1 *) lmdmon->LmdTdcE(idx));
01789         lmdtdcp[idx]->Add((const TH1 *) lmdmon->LmdTdcP(idx));
01790         lmdtmean[idx]->Add((const TH1 *) lmdmon->LmdTmean(idx));
01791         lmdtdf[idx]->Add((const TH1 *) lmdmon->LmdTdf(idx));
01792       }
01793     }
01794   }
01795 }
01796 
01797 
01798 
01799 
01801 // Following code were in TFndLmdMon::Fill
01802 // still keeping it here:
01803 //
01804 // last line still present in "TFndLmdMon::Fill":
01805 //     lmd_all_adc_tdc[idx]->Fill(tp,ap);
01806     
01809 //
01810 // Loop to search for double hits and clean-up
01811 /*
01812   for (Int_t jj=j+1; jj<nhlmd; jj++) {
01813   TFndHLmd *hlmd1 = (TFndHLmd*) LmdHits.At(jj);
01814     
01815   Int_t dch1 = hlmd1->GetCham();
01816   Int_t wire1 = hlmd1->GetWire();
01817   Float_t ae1 =  (Float_t ) hlmd1->GetAdcE();
01818   Float_t ap1 =  (Float_t ) hlmd1->GetAdcP();
01819   Float_t te1 =  (Float_t ) hlmd1->GetTdcE();
01820   Float_t tp1 =  (Float_t ) hlmd1->GetTdcP();
01821   Float_t tmean1 = 0.5*(te1+tp1);
01822       
01823   // Pedestal subtraction
01824       
01825   //       Float_t pede = 0.;
01826   //       Float_t pedp = 0.;
01827   //       if(lmd_det && fndrun->RunConfiguration()->LmdPedestalSubtraction()) {
01828   //    pede = lmd_det->PedE(dch1/10,dch1%10,wire1);
01829   //    pedp = lmd_det->PedP(dch1/10,dch1%10,wire1);
01830   //    ae1 -= pede; ap1 -= pedp;
01831   //       }
01832       
01833   // Charge Scaling
01834       
01835   //       if(lmd_det && fndrun->RunConfiguration()->LmdChargeEqualisation()) {
01836   //    //cout << "Charge scaling" << endl;
01837   //    Float_t che = lmd_det->ChargeE(dch1/10,dch1%10,wire1); 
01838   //    Float_t chp = lmd_det->ChargeP(dch1/10,dch1%10,wire1);
01839   //    if(che) ae1 *= che;
01840   //    if(chp) ap1 *= chp;
01841   //       }
01842       
01843   Int_t il1 = 0;
01844   Int_t sf1 = 0;
01845   Int_t idx1 = 0;
01846 
01847   if(dch1 <= 18 && dch1 >= 11) { 
01848   sf1 = dch1-11;
01849   il1 = 0;
01850   }
01851   if(dch1 <= 28 && dch1 >=21) {
01852   sf1 = dch1-21;
01853   il1 = 1;
01854   }
01855   idx1 = sf1+K_N_LMD_CHAMS_PER_LAYER*il1;    
01856 
01857   if(dch == dch1) {
01858   if(wire-wire1 == 1) {
01859   lmd_all_dhits[idx1]->Fill((Float_t) wire1);
01860   if(wire%2) {
01861   lmd_all_dhits_tdc_cell[idx1]->Fill(tmean,tmean1);
01862   //        if(tmean < 2500. && tmean1 < 2500.) {
01863   lmd_all_dhits_adc_cell[idx1]->Fill(ae+ap,ae1+ap1);
01864   if(ae+ap < ae1+ap1)
01865   iskip[j] = 1;
01866   else
01867   iskip[jj] = 1;
01868   } 
01869   else {
01870   //        if(ae+ap < 1000. && ae1+ap1>1000. || ae1+ap1 < 1000. && ae+ap>1000.) 
01871   lmd_all_dhits_tdc_dopp[idx1]->Fill(tmean,tmean1);
01872   lmd_all_dhits_adc_dopp[idx1]->Fill(ae+ap,ae1+ap1);
01873   }
01874   } 
01875   else if (wire1-wire == 1) {
01876   lmd_all_dhits[idx1]->Fill((Float_t) wire);
01877   if(wire%2) {
01878   //        if(ae+ap < 1000 || ae1+ap1 < 1000.) 
01879   lmd_all_dhits_tdc_dopp[idx1]->Fill(tmean1,tmean);
01880   lmd_all_dhits_adc_dopp[idx1]->Fill(ae1+ap1,ae+ap);
01881   } 
01882   else {
01883   lmd_all_dhits_tdc_cell[idx1]->Fill(tmean1,tmean);
01884   //        if(tmean < 2500. && tmean1 < 2500.) {
01885   lmd_all_dhits_adc_cell[idx1]->Fill(ae1+ap1,ae+ap);
01886   if(ae+ap < ae1+ap1)
01887   iskip[j] = 1;
01888   else
01889   iskip[jj] = 1;
01890   }
01891   }
01892   }
01893   }
01894 */
01897 
01898 
01899 // skip double hits
01900 //if(iskip[j] == 1) continue;

Generated on Tue Oct 16 15:40:47 2007 by  doxygen 1.5.2