CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibTracker/SiStripLorentzAngle/plugins/SiStripCalibLorentzAngle.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <string>
00003 #include <iostream>
00004 #include <fstream>
00005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00006 #include "CalibTracker/SiStripLorentzAngle/interface/SiStripCalibLorentzAngle.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00009 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00010 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "CLHEP/Random/RandGauss.h"
00013 #include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
00014 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00015 #include "DQMServices/Core/interface/MonitorElement.h"
00016 #include "DQMServices/Core/interface/DQMStore.h"
00017 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00018 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00019 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00020 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00021 
00022 SiStripCalibLorentzAngle::SiStripCalibLorentzAngle(edm::ParameterSet const& conf) : ConditionDBWriter<SiStripLorentzAngle>(conf) , tTopo(nullptr), conf_(conf) {}
00023 
00024 void SiStripCalibLorentzAngle::algoBeginJob(const edm::EventSetup& c){
00025   //Retrieve tracker topology from geometry
00026   edm::ESHandle<TrackerTopology> tTopoHandle;
00027   c.get<IdealGeometryRecord>().get(tTopoHandle);
00028   tTopo = tTopoHandle.product();
00029 
00030   c.get<TrackerDigiGeometryRecord>().get(estracker);
00031   tracker=&(*estracker); 
00032   
00033   //get magnetic field and geometry from ES
00034   edm::ESHandle<MagneticField> magfield_;
00035   c.get<IdealMagneticFieldRecord>().get(magfield_);
00036 
00037   edm::ESHandle<SiStripLorentzAngle> SiStripLorentzAngle_;
00038   c.get<SiStripLorentzAngleRcd>().get(SiStripLorentzAngle_);
00039   detid_la= SiStripLorentzAngle_->getLorentzAngles();
00040   
00041   DQMStore* dbe_ = edm::Service<DQMStore>().operator->();
00042   
00043   std::string inputFile_ =conf_.getUntrackedParameter<std::string>("fileName", "LAProfiles.root");
00044   std::string LAreport_ =conf_.getUntrackedParameter<std::string>("LA_Report", "LA_Report.txt");
00045   std::string NoEntriesHisto_ =conf_.getUntrackedParameter<std::string>("NoEntriesHisto", "NoEntriesHisto.txt");
00046   std::string Dir_Name_ =conf_.getUntrackedParameter<std::string>("Dir_Name", "SiStrip");
00047   
00048   LayerDB = conf_.getUntrackedParameter<bool>("LayerDB", false);
00049   
00050   CalibByMC = conf_.getUntrackedParameter<bool>("CalibByMC", false);
00051   
00052   dbe_->open(inputFile_);
00053   
00054   // use SistripHistoId for producing histogram id (and title)
00055   SiStripHistoId hidmanager;
00056   
00057   edm::LogInfo("SiStripCalibLorentzAngle")<<"### DIR-NAME = "<<Dir_Name_;
00058   histolist= dbe_->getAllContents(Dir_Name_);
00059   std::vector<MonitorElement*>::iterator histo;
00060   
00061   hFile = new TFile (conf_.getUntrackedParameter<std::string>("out_fileName").c_str(), "RECREATE" );
00062     
00063   LorentzAngle_Plots = hFile->mkdir("LorentzAngle_Plots");
00064   Rootple = LorentzAngle_Plots->mkdir("Rootple");
00065   MuH = LorentzAngle_Plots->mkdir("MuH");
00066   TIB_MuH = MuH->mkdir("TIB_MuH");
00067   TOB_MuH = MuH->mkdir("TOB_MuH");
00068   MuH_vs_Phi = LorentzAngle_Plots->mkdir("MuH_vs_Phi");
00069   TIB_Phi = MuH_vs_Phi->mkdir("TIB_Phi");
00070   TOB_Phi = MuH_vs_Phi->mkdir("TOB_Phi");
00071   MuH_vs_Eta = LorentzAngle_Plots->mkdir("MuH_vs_Eta");
00072   TIB_Eta = MuH_vs_Eta->mkdir("TIB_Eta");
00073   TOB_Eta = MuH_vs_Eta->mkdir("TOB_Eta");
00074   FirstIT_GoodFit_Histos = LorentzAngle_Plots->mkdir("1IT_GoodFit_Histos");
00075   TIB_1IT_GoodFit = FirstIT_GoodFit_Histos->mkdir("TIB_1IT_GoodFit");
00076   TOB_1IT_GoodFit = FirstIT_GoodFit_Histos->mkdir("TOB_1IT_GoodFit");
00077   SecondIT_GoodFit_Histos = LorentzAngle_Plots->mkdir("2IT_GoodFit_Histos");
00078   TIB_2IT_GoodFit = SecondIT_GoodFit_Histos->mkdir("TIB_2IT_GoodFit");
00079   TOB_2IT_GoodFit = SecondIT_GoodFit_Histos->mkdir("TOB_2IT_GoodFit");
00080   SecondIT_BadFit_Histos = LorentzAngle_Plots->mkdir("2IT_BadFit_Histos");
00081   TIB_2IT_BadFit = SecondIT_BadFit_Histos->mkdir("TIB_2IT_BadFit");
00082   TOB_2IT_BadFit = SecondIT_BadFit_Histos->mkdir("TOB_2IT_BadFit");
00083     
00084   TH1Ds["LA_TIB"] = new TH1D("TanLAPerTesla TIB","TanLAPerTesla TIB",1000,-0.5,0.5);
00085   TH1Ds["LA_TIB"]->SetDirectory(MuH);
00086   TH1Ds["LA_TOB"] = new TH1D("TanLAPerTesla TOB","TanLAPerTesla TOB",1000,-0.5,0.5);
00087   TH1Ds["LA_TOB"]->SetDirectory(MuH);
00088   TH1Ds["LA_err_TIB"] = new TH1D("TanLAPerTesla Error TIB","TanLAPerTesla Error TIB",1000,0,1);
00089   TH1Ds["LA_err_TIB"]->SetDirectory(MuH);
00090   TH1Ds["LA_err_TOB"] = new TH1D("TanLAPerTesla Error TOB","TanLAPerTesla Error TOB",1000,0,1);
00091   TH1Ds["LA_err_TOB"]->SetDirectory(MuH);
00092   TH1Ds["LA_chi2norm_TIB"] = new TH1D("TanLAPerTesla Chi2norm TIB","TanLAPerTesla Chi2norm TIB",2000,0,10);
00093   TH1Ds["LA_chi2norm_TIB"]->SetDirectory(MuH);
00094   TH1Ds["LA_chi2norm_TOB"] = new TH1D("TanLAPerTesla Chi2norm TOB","TanLAPerTesla Chi2norm TOB",2000,0,10);
00095   TH1Ds["LA_chi2norm_TOB"]->SetDirectory(MuH);
00096   TH1Ds["MagneticField"] = new TH1D("MagneticField","MagneticField",500,0,5);
00097   TH1Ds["MagneticField"]->SetDirectory(MuH);
00098   
00099   TH2Ds["LA_TIB_graph"] = new TH2D("TanLAPerTesla TIB Layers","TanLAPerTesla TIB Layers",60,0,5,1000,-0.3,0.3);
00100   TH2Ds["LA_TIB_graph"]->SetDirectory(MuH);
00101   TH2Ds["LA_TIB_graph"]->SetNdivisions(6);
00102   TH2Ds["LA_TOB_graph"] = new TH2D("TanLAPerTesla TOB Layers","TanLAPerTesla TOB Layers",80,0,7,1000,-0.3,0.3);
00103   TH2Ds["LA_TOB_graph"]->SetDirectory(MuH);
00104   TH2Ds["LA_TOB_graph"]->SetNdivisions(8);
00105 
00106   TH1Ds["LA_TIB_1"] = new TH1D("TanLAPerTesla TIB1","TanLAPerTesla TIB1",2000,-0.5,0.5);
00107   TH1Ds["LA_TIB_1"]->SetDirectory(TIB_MuH);
00108   TH1Ds["LA_TIB_1_mono"] = new TH1D("TanLAPerTesla TIB1 MONO","TanLAPerTesla TIB1 MONO",2000,-0.5,0.5);
00109   TH1Ds["LA_TIB_1_mono"]->SetDirectory(TIB_MuH);
00110   TH1Ds["LA_TIB_1_stereo"] = new TH1D("TanLAPerTesla TIB1 STEREO","TanLAPerTesla TIB1 STEREO",2000,-0.5,0.5);
00111   TH1Ds["LA_TIB_1_stereo"]->SetDirectory(TIB_MuH);
00112   TH1Ds["LA_TIB_2"] = new TH1D("TanLAPerTesla TIB2","TanLAPerTesla TIB2",2000,-0.5,0.5);
00113   TH1Ds["LA_TIB_2"]->SetDirectory(TIB_MuH);
00114   TH1Ds["LA_TIB_2_mono"] = new TH1D("TanLAPerTesla TIB2 MONO","TanLAPerTesla TIB2 MONO",2000,-0.5,0.5);
00115   TH1Ds["LA_TIB_2_mono"]->SetDirectory(TIB_MuH);
00116   TH1Ds["LA_TIB_2_stereo"] = new TH1D("TanLAPerTesla TIB2 STEREO","TanLAPerTesla TIB2 STEREO",2000,-0.5,0.5);
00117   TH1Ds["LA_TIB_2_stereo"]->SetDirectory(TIB_MuH);
00118   TH1Ds["LA_TIB_3"] = new TH1D("TanLAPerTesla_TIB 3","TanLAPerTesla TIB3",2000,-0.5,0.5);
00119   TH1Ds["LA_TIB_3"]->SetDirectory(TIB_MuH);
00120   TH1Ds["LA_TIB_4"] = new TH1D("TanLAPerTesla_TIB 4","TanLAPerTesla TIB4",2000,-0.5,0.5);
00121   TH1Ds["LA_TIB_4"]->SetDirectory(TIB_MuH);
00122   
00123   TH1Ds["LA_TOB_1"] = new TH1D("TanLAPerTesla TOB1","TanLAPerTesla TOB1",2000,-0.5,0.5);
00124   TH1Ds["LA_TOB_1"]->SetDirectory(TOB_MuH);
00125   TH1Ds["LA_TOB_1_mono"] = new TH1D("TanLAPerTesla TOB1 MONO","TanLAPerTesla TOB1 MONO",2000,-0.5,0.5);
00126   TH1Ds["LA_TOB_1_mono"]->SetDirectory(TOB_MuH);
00127   TH1Ds["LA_TOB_1_stereo"] = new TH1D("TanLAPerTesla TOB1 STEREO","TanLAPerTesla TOB1 STEREO",2000,-0.5,0.5);
00128   TH1Ds["LA_TOB_1_stereo"]->SetDirectory(TOB_MuH);
00129   TH1Ds["LA_TOB_2"] = new TH1D("TanLAPerTesla TOB2","TanLAPerTesla TOB2",2000,-0.5,0.5);
00130   TH1Ds["LA_TOB_2"]->SetDirectory(TOB_MuH);
00131   TH1Ds["LA_TOB_2_mono"] = new TH1D("TanLAPerTesla TOB2 MONO","TanLAPerTesla TOB2 MONO",2000,-0.5,0.5);
00132   TH1Ds["LA_TOB_2_mono"]->SetDirectory(TOB_MuH);
00133   TH1Ds["LA_TOB_2_stereo"] = new TH1D("TanLAPerTesla TOB2 STEREO","TanLAPerTesla TOB2 STEREO",2000,-0.5,0.5);
00134   TH1Ds["LA_TOB_2_stereo"]->SetDirectory(TOB_MuH);
00135   TH1Ds["LA_TOB_3"] = new TH1D("TanLAPerTesla TOB3","TanLAPerTesla TOB3",2000,-0.5,0.5);
00136   TH1Ds["LA_TOB_3"]->SetDirectory(TOB_MuH);
00137   TH1Ds["LA_TOB_4"] = new TH1D("TanLAPerTesla TOB4","TanLAPerTesla TOB4",2000,-0.5,0.5);
00138   TH1Ds["LA_TOB_4"]->SetDirectory(TOB_MuH);
00139   TH1Ds["LA_TOB_5"] = new TH1D("TanLAPerTesla TOB5","TanLAPerTesla TOB5",2000,-0.5,0.5);
00140   TH1Ds["LA_TOB_5"]->SetDirectory(TOB_MuH);
00141   TH1Ds["LA_TOB_6"] = new TH1D("TanLAPerTesla TOB6","TanLAPerTesla TOB6",2000,-0.5,0.5); 
00142   TH1Ds["LA_TOB_6"]->SetDirectory(TOB_MuH);
00143     
00144   TH2Ds["LA_phi_TIB"] = new TH2D("TanLAPerTesla vs Phi TIB","TanLAPerTesla vs Phi TIB",800,-4,4,600,-0.3,0.3);
00145   TH2Ds["LA_phi_TIB"]->SetDirectory(MuH_vs_Phi);
00146   TH2Ds["LA_phi_TOB"] = new TH2D("TanLAPerTesla vs Phi TOB","TanLAPerTesla vs Phi TOB",800,-4,4,600,-0.3,0.3);
00147   TH2Ds["LA_phi_TOB"]->SetDirectory(MuH_vs_Phi);
00148   
00149   TH2Ds["LA_phi_TIB1"] = new TH2D("TanLAPerTesla vs Phi TIB1","TanLAPerTesla vs Phi TIB1",800,-4,4,600,-0.3,0.3);
00150   TH2Ds["LA_phi_TIB1"]->SetDirectory(TIB_Phi);
00151   TH2Ds["LA_phi_TIB1_mono"] = new TH2D("TanLAPerTesla vs Phi TIB1 MONO","TanLAPerTesla vs Phi TIB1 MONO",800,-4,4,600,-0.3,0.3);
00152   TH2Ds["LA_phi_TIB1_mono"]->SetDirectory(TIB_Phi);
00153   TH2Ds["LA_phi_TIB1_stereo"] = new TH2D("TanLAPerTesla vs Phi TIB1 STEREO","TanLAPerTesla vs Phi TIB1 STEREO",800,-4,4,600,-0.3,0.3);
00154   TH2Ds["LA_phi_TIB1_stereo"]->SetDirectory(TIB_Phi);
00155   TH2Ds["LA_phi_TIB2"] = new TH2D("TanLAPerTesla vs Phi TIB2","TanLAPerTesla vs Phi TIB2",800,-4,4,600,-0.3,0.3);
00156   TH2Ds["LA_phi_TIB2"]->SetDirectory(TIB_Phi);
00157   TH2Ds["LA_phi_TIB2_mono"] = new TH2D("TanLAPerTesla vs Phi TIB2 MONO","TanLAPerTesla vs Phi TIB2 MONO",800,-4,4,600,-0.3,0.3);
00158   TH2Ds["LA_phi_TIB2_mono"]->SetDirectory(TIB_Phi);
00159   TH2Ds["LA_phi_TIB2_stereo"] = new TH2D("TanLAPerTesla vs Phi TIB2 STEREO","TanLAPerTesla vs Phi TIB2 STEREO",800,-4,4,600,-0.3,0.3);
00160   TH2Ds["LA_phi_TIB2_stereo"]->SetDirectory(TIB_Phi);
00161   TH2Ds["LA_phi_TIB3"] = new TH2D("TanLAPerTesla vs Phi TIB3","TanLAPerTesla vs Phi TIB3",800,-4,4,600,-0.3,0.3);
00162   TH2Ds["LA_phi_TIB3"]->SetDirectory(TIB_Phi);
00163   TH2Ds["LA_phi_TIB4"] = new TH2D("TanLAPerTesla vs Phi TIB4","TanLAPerTesla vs Phi TIB4",800,-4,4,600,-0.3,0.3);
00164   TH2Ds["LA_phi_TIB4"]->SetDirectory(TIB_Phi);
00165   
00166   TH2Ds["LA_phi_TOB1"] = new TH2D("TanLAPerTesla vs Phi TOB1","TanLAPerTesla vs Phi TOB1",800,-4,4,600,-0.3,0.3);
00167   TH2Ds["LA_phi_TOB1"]->SetDirectory(TOB_Phi);
00168   TH2Ds["LA_phi_TOB1_mono"] = new TH2D("TanLAPerTesla vs Phi TOB1 MONO","TanLAPerTesla vs Phi TOB1 MONO",800,-4,4,600,-0.3,0.3);
00169   TH2Ds["LA_phi_TOB1_mono"]->SetDirectory(TOB_Phi);
00170   TH2Ds["LA_phi_TOB1_stereo"] = new TH2D("TanLAPerTesla vs Phi TOB1 STEREO","TanLAPerTesla vs Phi TOB1 STEREO",800,-4,4,600,-0.3,0.3);
00171   TH2Ds["LA_phi_TOB1_stereo"]->SetDirectory(TOB_Phi);
00172   TH2Ds["LA_phi_TOB2"] = new TH2D("TanLAPerTesla vs Phi TOB2","TanLAPerTesla vs Phi TOB2",800,-4,4,600,-0.3,0.3);
00173   TH2Ds["LA_phi_TOB2"]->SetDirectory(TOB_Phi);
00174   TH2Ds["LA_phi_TOB2_mono"] = new TH2D("TanLAPerTesla vs Phi TOB2 MONO","TanLAPerTesla vs Phi TOB2 MONO",800,-4,4,600,-0.3,0.3);
00175   TH2Ds["LA_phi_TOB2_mono"]->SetDirectory(TOB_Phi);
00176   TH2Ds["LA_phi_TOB2_stereo"] = new TH2D("TanLAPerTesla vs Phi TOB2 STEREO","TanLAPerTesla vs Phi TOB2 STEREO",800,-4,4,600,-0.3,0.3);
00177   TH2Ds["LA_phi_TOB2_stereo"]->SetDirectory(TOB_Phi);
00178   TH2Ds["LA_phi_TOB3"] = new TH2D("TanLAPerTesla vs Phi TOB3","TanLAPerTesla vs Phi TOB3",800,-4,4,600,-0.3,0.3);
00179   TH2Ds["LA_phi_TOB3"]->SetDirectory(TOB_Phi);
00180   TH2Ds["LA_phi_TOB4"] = new TH2D("TanLAPerTesla vs Phi TOB4","TanLAPerTesla vs Phi TOB4",800,-4,4,600,-0.3,0.3);
00181   TH2Ds["LA_phi_TOB4"]->SetDirectory(TOB_Phi);
00182   TH2Ds["LA_phi_TOB5"] = new TH2D("TanLAPerTesla vs Phi TOB5","TanLAPerTesla vs Phi TOB5",800,-4,4,600,-0.3,0.3);
00183   TH2Ds["LA_phi_TOB5"]->SetDirectory(TOB_Phi);
00184   TH2Ds["LA_phi_TOB6"] = new TH2D("TanLAPerTesla vs Phi TOB6","TanLAPerTesla vs Phi TOB6",800,-4,4,600,-0.3,0.3);
00185   TH2Ds["LA_phi_TOB6"]->SetDirectory(TOB_Phi);
00186   
00187   TH2Ds["LA_eta_TIB"] = new TH2D("TanLAPerTesla vs Eta TIB","TanLAPerTesla vs Eta TIB",800,-2.6,2.6,600,-0.3,0.3);
00188   TH2Ds["LA_eta_TIB"]->SetDirectory(MuH_vs_Eta);
00189   TH2Ds["LA_eta_TOB"] = new TH2D("TanLAPerTesla vs Eta TOB","TanLAPerTesla vs Eta TOB",800,-2.6,2.6,600,-0.3,0.3);
00190   TH2Ds["LA_eta_TOB"]->SetDirectory(MuH_vs_Eta);
00191   
00192   TH2Ds["LA_eta_TIB1"] = new TH2D("TanLAPerTesla vs Eta TIB1","TanLAPerTesla vs Eta TIB1",800,-2.6,2.6,600,-0.3,0.3);
00193   TH2Ds["LA_eta_TIB1"]->SetDirectory(TIB_Eta);
00194   TH2Ds["LA_eta_TIB1_mono"] = new TH2D("TanLAPerTesla vs Eta TIB1 MONO","TanLAPerTesla vs Eta TIB1 MONO",800,-2.6,2.6,600,-0.3,0.3);
00195   TH2Ds["LA_eta_TIB1_mono"]->SetDirectory(TIB_Eta);
00196   TH2Ds["LA_eta_TIB1_stereo"] = new TH2D("TanLAPerTesla vs Eta TIB1 STEREO","TanLAPerTesla vs Eta TIB1 STEREO",800,-2.6,2.6,600,-0.3,0.3);
00197   TH2Ds["LA_eta_TIB1_stereo"]->SetDirectory(TIB_Eta);
00198   TH2Ds["LA_eta_TIB2"] = new TH2D("TanLAPerTesla vs Eta TIB2","TanLAPerTesla vs Eta TIB2",800,-2.6,2.6,600,-0.3,0.3);
00199   TH2Ds["LA_eta_TIB2"]->SetDirectory(TIB_Eta);
00200   TH2Ds["LA_eta_TIB2_mono"] = new TH2D("TanLAPerTesla vs Eta TIB2 MONO","TanLAPerTesla vs Eta TIB2 MONO",800,-2.6,2.6,600,-0.3,0.3);
00201   TH2Ds["LA_eta_TIB2_mono"]->SetDirectory(TIB_Eta);
00202   TH2Ds["LA_eta_TIB2_stereo"] = new TH2D("TanLAPerTesla vs Eta TIB2 STEREO","TanLAPerTesla vs Eta TIB2 STEREO",800,-2.6,2.6,600,-0.3,0.3);
00203   TH2Ds["LA_eta_TIB2_stereo"]->SetDirectory(TIB_Eta);
00204   TH2Ds["LA_eta_TIB3"] = new TH2D("TanLAPerTesla vs Eta TIB3","TanLAPerTesla vs Eta TIB3",800,-2.6,2.6,600,-0.3,0.3);
00205   TH2Ds["LA_eta_TIB3"]->SetDirectory(TIB_Eta);
00206   TH2Ds["LA_eta_TIB4"] = new TH2D("TanLAPerTesla vs Eta TIB4","TanLAPerTesla vs Eta TIB4",800,-2.6,2.6,600,-0.3,0.3);
00207   TH2Ds["LA_eta_TIB4"]->SetDirectory(TIB_Eta);
00208   
00209   TH2Ds["LA_eta_TOB1"] = new TH2D("TanLAPerTesla vs Eta TOB1","TanLAPerTesla vs Eta TOB1",800,-2.6,2.6,600,-0.3,0.3);
00210   TH2Ds["LA_eta_TOB1"]->SetDirectory(TIB_Eta);
00211   TH2Ds["LA_eta_TOB1_mono"] = new TH2D("TanLAPerTesla vs Eta TOB1 MONO","TanLAPerTesla vs Eta TOB1 MONO",800,-2.6,2.6,600,-0.3,0.3);
00212   TH2Ds["LA_eta_TOB1_mono"]->SetDirectory(TIB_Eta);
00213   TH2Ds["LA_eta_TOB1_stereo"] = new TH2D("TanLAPerTesla vs Eta TOB1 STEREO","TanLAPerTesla vs Eta TOB1 STEREO",800,-2.6,2.6,600,-0.3,0.3);
00214   TH2Ds["LA_eta_TOB1_stereo"]->SetDirectory(TIB_Eta);
00215   TH2Ds["LA_eta_TOB2"] = new TH2D("TanLAPerTesla vs Eta TOB2","TanLAPerTesla vs Eta TOB2",800,-2.6,2.6,600,-0.3,0.3);
00216   TH2Ds["LA_eta_TOB2"]->SetDirectory(TIB_Eta);
00217   TH2Ds["LA_eta_TOB2_mono"] = new TH2D("TanLAPerTesla vs Eta TOB2 MONO","TanLAPerTesla vs Eta TOB2 MONO",800,-2.6,2.6,600,-0.3,0.3);
00218   TH2Ds["LA_eta_TOB2_mono"]->SetDirectory(TIB_Eta);
00219   TH2Ds["LA_eta_TOB2_stereo"] = new TH2D("TanLAPerTesla vs Eta TOB2 STEREO","TanLAPerTesla vs Eta TOB2 STEREO",800,-2.6,2.6,600,-0.3,0.3);
00220   TH2Ds["LA_eta_TOB2_stereo"]->SetDirectory(TIB_Eta);
00221   TH2Ds["LA_eta_TOB3"] = new TH2D("TanLAPerTesla vs Eta TOB3","TanLAPerTesla vs Eta TOB3",800,-2.6,2.6,600,-0.3,0.3);
00222   TH2Ds["LA_eta_TOB3"]->SetDirectory(TIB_Eta);
00223   TH2Ds["LA_eta_TOB4"] = new TH2D("TanLAPerTesla vs Eta TOB4","TanLAPerTesla vs Eta TOB4",800,-2.6,2.6,600,-0.3,0.3);
00224   TH2Ds["LA_eta_TOB4"]->SetDirectory(TIB_Eta);
00225   TH2Ds["LA_eta_TOB5"] = new TH2D("TanLAPerTesla vs Eta TOB5","TanLAPerTesla vs Eta TOB5",800,-2.6,2.6,600,-0.3,0.3);
00226   TH2Ds["LA_eta_TOB5"]->SetDirectory(TIB_Eta);
00227   TH2Ds["LA_eta_TOB6"] = new TH2D("TanLAPerTesla vs Eta TOB6","TanLAPerTesla vs Eta TOB6",800,-2.6,2.6,600,-0.3,0.3);
00228   TH2Ds["LA_eta_TOB6"]->SetDirectory(TIB_Eta);
00229   
00230   ModuleTree = new TTree("ModuleTree", "ModuleTree");
00231   ModuleTree->Branch("histoEntries", &histoEntries, "histoEntries/F");
00232   ModuleTree->Branch("globalX", &globalX, "globalX/F");
00233   ModuleTree->Branch("globalY", &globalY, "globalY/F");
00234   ModuleTree->Branch("globalZ", &globalZ, "globalZ/F");
00235   ModuleTree->Branch("gphi", &gphi, "gphi/F");
00236   ModuleTree->Branch("geta", &geta, "geta/F");
00237   ModuleTree->Branch("gR", &gR, "gR/F");
00238   ModuleTree->Branch("goodFit", &goodFit, "goodFit/I");
00239   ModuleTree->Branch("goodFit1IT", &goodFit1IT, "goodFit1IT/I");
00240   ModuleTree->Branch("badFit", &badFit, "badFit/I");
00241   ModuleTree->Branch("TIB", &TIB, "TIB/I");
00242   ModuleTree->Branch("TOB", &TOB, "TOB/I");
00243   ModuleTree->Branch("Layer", &Layer, "Layer/I");
00244   ModuleTree->Branch("MonoStereo", &MonoStereo, "MonoStereo/I");
00245   ModuleTree->Branch("theBfield", &theBfield, "theBfield/F");
00246   ModuleTree->Branch("muH", &muH, "muH/F");
00247   
00248   ModuleTree->SetDirectory(Rootple);
00249      
00250   int histocounter = 0;
00251   int NotEnoughEntries = 0;
00252   int ZeroEntries = 0;
00253   int GoodFit = 0;
00254   int FirstIT_goodfit = 0;
00255   int FirstIT_badfit = 0;
00256   int SecondIT_badfit = 0;
00257   int SecondIT_goodfit = 0;
00258   int no_mod_histo = 0;
00259   float chi2norm = 0;
00260   LocalPoint p =LocalPoint(0,0,0);
00261   
00262   double ModuleRangeMin=conf_.getParameter<double>("ModuleFitXMin");
00263   double ModuleRangeMax=conf_.getParameter<double>("ModuleFitXMax");
00264   double ModuleRangeMin2IT=conf_.getParameter<double>("ModuleFit2ITXMin");
00265   double ModuleRangeMax2IT=conf_.getParameter<double>("ModuleFit2ITXMax");
00266   double FitCuts_Entries=conf_.getParameter<double>("FitCuts_Entries");
00267   double FitCuts_p0=conf_.getParameter<double>("FitCuts_p0");
00268   double FitCuts_p1=conf_.getParameter<double>("FitCuts_p1");
00269   double FitCuts_p2=conf_.getParameter<double>("FitCuts_p2");
00270   double FitCuts_chi2=conf_.getParameter<double>("FitCuts_chi2");
00271   double FitCuts_ParErr_p0=conf_.getParameter<double>("FitCuts_ParErr_p0");
00272   double p0_guess=conf_.getParameter<double>("p0_guess");
00273   double p1_guess=conf_.getParameter<double>("p1_guess");
00274   double p2_guess=conf_.getParameter<double>("p2_guess");
00275   
00276   double TIB1calib = 1.;
00277   double TIB2calib = 1.;
00278   double TIB3calib = 1.;
00279   double TIB4calib = 1.;
00280   double TOB1calib = 1.;
00281   double TOB2calib = 1.;
00282   double TOB3calib = 1.;
00283   double TOB4calib = 1.;
00284   double TOB5calib = 1.;
00285   double TOB6calib = 1.;
00286   
00287   if(CalibByMC==true){
00288   //Calibration factors evaluated by using MC analysis
00289   TIB1calib=conf_.getParameter<double>("TIB1calib");
00290   TIB2calib=conf_.getParameter<double>("TIB2calib");
00291   TIB3calib=conf_.getParameter<double>("TIB3calib");
00292   TIB4calib=conf_.getParameter<double>("TIB4calib");
00293   TOB1calib=conf_.getParameter<double>("TOB1calib");
00294   TOB2calib=conf_.getParameter<double>("TOB2calib");
00295   TOB3calib=conf_.getParameter<double>("TOB3calib");
00296   TOB4calib=conf_.getParameter<double>("TOB4calib");
00297   TOB5calib=conf_.getParameter<double>("TOB5calib");
00298   TOB6calib=conf_.getParameter<double>("TOB6calib");
00299   }
00300   
00301   
00302   TF1 *fitfunc= new TF1("fitfunc","([4]/[3])*[1]*(TMath::Abs(x-[0]))+[2]",-1,1);
00303   TF1 *fitfunc2IT= new TF1("fitfunc2IT","([4]/[3])*[1]*(TMath::Abs(x-[0]))+[2]",-1,1);
00304  
00305   ofstream NoEntries;
00306   NoEntries.open(NoEntriesHisto_.c_str());
00307   ofstream Rep;
00308   Rep.open(LAreport_.c_str());
00309   
00310   gStyle->SetOptStat(1110);
00311   
00312   for(histo=histolist.begin();histo!=histolist.end();++histo){
00313   
00314   FitFunction = 0;
00315   FitFunction2IT = 0;
00316   bool Good2ITFit = false;
00317   bool ModuleHisto = true;
00318   
00319   histoEntries = -99;
00320   gphi=-99;
00321   geta=-99;
00322   gz = -99;
00323   gR=-1;
00324   globalX = -99;
00325   globalY = -99;
00326   globalZ = -99;
00327   goodFit = 0;
00328   goodFit1IT = 0;
00329   badFit = 0;
00330   muH = -1;
00331   TIB = 0;
00332   TOB = 0;
00333   MonoStereo = -1;
00334   
00335     uint32_t id=hidmanager.getComponentId((*histo)->getName());
00336     DetId detid(id);
00337     StripSubdetector subid(id);
00338     const GeomDetUnit * stripdet;
00339     MonoStereo = subid.stereo();
00340     
00341     if(!(stripdet=tracker->idToDetUnit(subid))){
00342     no_mod_histo++;
00343     ModuleHisto=false;
00344     edm::LogInfo("SiStripCalibLorentzAngle")<<"### NO MODULE HISTOGRAM";}
00345     
00346     if(stripdet!=0 && ModuleHisto==true){
00347     
00348       if(subid.subdetId() == int (StripSubdetector::TIB)){
00349       
00350       Layer = tTopo->tibLayer(detid);
00351       TIB = 1;}     
00352       if(subid.subdetId() == int (StripSubdetector::TOB)){
00353       
00354       Layer = tTopo->tobLayer(detid);
00355       TOB = 1;}
00356       
00357     //get module coordinates
00358     const GlobalPoint gposition = (stripdet->surface()).toGlobal(p);
00359     histoEntries = (*histo)->getEntries();
00360     globalX = gposition.x();
00361     globalY = gposition.y();
00362     globalZ = gposition.z();
00363     gphi = gposition.phi();
00364     geta = gposition.eta();
00365     gR = sqrt(pow(gposition.x(),2)+pow(gposition.y(),2));
00366     gz = gposition.z();
00367     
00368     //get magnetic field
00369     const StripGeomDetUnit* det = dynamic_cast<const StripGeomDetUnit*>(estracker->idToDetUnit(detid));
00370     if (det==0){
00371     edm::LogError("SiStripCalibLorentzAngle") << "[SiStripCalibLorentzAngle::getNewObject] the detID " << id << " doesn't seem to belong to Tracker" <<std::endl;       
00372     continue;
00373     }
00374     LocalVector lbfield=(det->surface()).toLocal(magfield_->inTesla(det->surface().position()));
00375     theBfield = lbfield.mag();
00376     theBfield = (theBfield > 0) ? theBfield : 0.00001; 
00377     TH1Ds["MagneticField"]->Fill(theBfield);    
00378     }
00379     if(stripdet==0)continue;
00380       
00381     if(((*histo)->getEntries()<=FitCuts_Entries)&&ModuleHisto==true){
00382     if(((*histo)->getEntries()==0)&&ModuleHisto==true){    
00383     NoEntries<<"NO ENTRIES MODULE, ID = "<<id<<std::endl;    
00384     edm::LogInfo("SiStripCalibLorentzAngle")<<"### HISTOGRAM WITH 0 ENTRIES => TYPE:"<<subid.subdetId();
00385     ZeroEntries++;
00386     }else{    
00387     edm::LogInfo("SiStripCalibLorentzAngle")<<"### HISTOGRAM WITH NR. ENTRIES <= ENTRIES_CUT => TYPE:"<<subid.subdetId();
00388     NotEnoughEntries++;}    
00389     }
00390     
00391       std::string name;
00392       if(TIB==1){
00393       name+="TIB";
00394       }else{
00395       name+="TOB";}
00396       std::stringstream LayerStream;
00397       LayerStream<<Layer;
00398       name+=LayerStream.str();    
00399       std::stringstream idnum;
00400       idnum<<id;
00401       name+="_Id_";
00402       name+=idnum.str();
00403       
00404     gStyle->SetOptFit(111);  
00405     
00406     //Extract TProfile from Monitor Element to ProfileMap
00407     Profiles[name.c_str()] = new TProfile;   
00408     TProfile* theProfile=ExtractTObject<TProfile>().extract(*histo);   
00409     theProfile->Copy(*Profiles[name.c_str()]);    
00410     Profiles[name.c_str()]->SetName(name.c_str());
00411   
00412     if(((*histo)->getEntries()>FitCuts_Entries) && ModuleHisto==true){   
00413       histocounter++;            
00414       if(TIB==1){
00415       edm::LogInfo("SiStripCalibLorentzAngle")<<"TIB layer = "<<Layer;}    
00416       if(TOB==1){
00417       edm::LogInfo("SiStripCalibLorentzAngle")<<"TOB layer = "<<Layer;}     
00418       edm::LogInfo("SiStripCalibLorentzAngle")<<"id: "<<id;    
00419             
00420       float thickness=stripdet->specificSurface().bounds().thickness();
00421       const StripTopology& topol=(const StripTopology&)stripdet->topology();
00422       float pitch = topol.localPitch(p);
00423                   
00424       fitfunc->SetParameter(0, p0_guess);
00425       fitfunc->SetParameter(1, p1_guess);
00426       fitfunc->SetParameter(2, p2_guess);
00427       fitfunc->FixParameter(3, pitch);
00428       fitfunc->FixParameter(4, thickness);
00429       
00430       Profiles[name.c_str()]->Fit("fitfunc","E","",ModuleRangeMin, ModuleRangeMax);
00431             
00432       FitFunction = Profiles[name.c_str()]->GetFunction("fitfunc");
00433       chi2norm = FitFunction->GetChisquare()/FitFunction->GetNDF();
00434       
00435       if(FitFunction->GetParameter(0)>FitCuts_p0 || FitFunction->GetParameter(1)<FitCuts_p1 || FitFunction->GetParameter(2)<FitCuts_p2 || chi2norm>FitCuts_chi2 || FitFunction->GetParError(0)<FitCuts_ParErr_p0){
00436       
00437       FirstIT_badfit++;   
00438             
00439       fitfunc2IT->SetParameter(0, p0_guess);
00440       fitfunc2IT->SetParameter(1, p1_guess);
00441       fitfunc2IT->SetParameter(2, p2_guess);
00442       fitfunc2IT->FixParameter(3, pitch);
00443       fitfunc2IT->FixParameter(4, thickness);
00444       
00445       //2nd Iteration
00446       Profiles[name.c_str()]->Fit("fitfunc2IT","E","",ModuleRangeMin2IT, ModuleRangeMax2IT);
00447       
00448       FitFunction = Profiles[name.c_str()]->GetFunction("fitfunc2IT");
00449       chi2norm = FitFunction->GetChisquare()/FitFunction->GetNDF();
00450                 
00451       //2nd Iteration failed
00452       
00453       if(FitFunction->GetParameter(0)>FitCuts_p0 || FitFunction->GetParameter(1)<FitCuts_p1 || FitFunction->GetParameter(2)<FitCuts_p2 || chi2norm>FitCuts_chi2 || FitFunction->GetParError(0)<FitCuts_ParErr_p0){
00454       
00455       if(subid.subdetId() == int (StripSubdetector::TIB)){
00456       Profiles[name.c_str()]->SetDirectory(TIB_2IT_BadFit);
00457       }else{
00458       Profiles[name.c_str()]->SetDirectory(TOB_2IT_BadFit);} 
00459             
00460       SecondIT_badfit++;
00461       badFit=1;     
00462           
00463       }
00464       
00465       //2nd Iteration ok
00466      
00467       if(FitFunction->GetParameter(0)<FitCuts_p0 && FitFunction->GetParameter(1)>FitCuts_p1 && FitFunction->GetParameter(2)>FitCuts_p2 && chi2norm<FitCuts_chi2 && FitFunction->GetParError(0)>FitCuts_ParErr_p0){
00468       
00469       if(subid.subdetId() == int (StripSubdetector::TIB)){
00470       Profiles[name.c_str()]->SetDirectory(TIB_2IT_GoodFit);
00471       }else{
00472       Profiles[name.c_str()]->SetDirectory(TOB_2IT_GoodFit);} 
00473       
00474       SecondIT_goodfit++;      
00475       Good2ITFit = true;
00476       
00477       }
00478             
00479       }  
00480                        
00481       if(FitFunction->GetParameter(0)<FitCuts_p0 && FitFunction->GetParameter(1)>FitCuts_p1 && FitFunction->GetParameter(2)>FitCuts_p2 && chi2norm<FitCuts_chi2 && FitFunction->GetParError(0)>FitCuts_ParErr_p0){
00482       
00483         if(Good2ITFit==false){
00484         
00485         FirstIT_goodfit++;
00486         goodFit1IT = 1;
00487         
00488         if(subid.subdetId() == int (StripSubdetector::TIB)){
00489         Profiles[name.c_str()]->SetDirectory(TIB_1IT_GoodFit);
00490         }else{
00491         Profiles[name.c_str()]->SetDirectory(TOB_1IT_GoodFit);} 
00492         
00493         }
00494         
00495         GoodFit++;
00496         goodFit=1;
00497         
00498         LorentzAngle_Plots->cd();
00499             
00500         edm::LogInfo("SiStripCalibLorentzAngle")<<FitFunction->GetParameter(0);
00501         
00502         muH = -(FitFunction->GetParameter(0))/theBfield;
00503         
00504         if(TIB==1){
00505         if(Layer==1) muH = muH/TIB1calib;
00506         if(Layer==2) muH = muH/TIB2calib;
00507         if(Layer==3) muH = muH/TIB3calib;
00508         if(Layer==4) muH = muH/TIB4calib;
00509         }
00510         if(TOB==1){
00511         if(Layer==1) muH = muH/TOB1calib;
00512         if(Layer==2) muH = muH/TOB2calib;
00513         if(Layer==3) muH = muH/TOB3calib;
00514         if(Layer==4) muH = muH/TOB4calib;
00515         if(Layer==5) muH = muH/TOB5calib;
00516         if(Layer==6) muH = muH/TOB6calib;
00517         }
00518         
00519         detid_la[id]= muH;
00520         
00521         if(TIB==1){
00522         
00523         TH1Ds["LA_TIB"]->Fill(muH);
00524         TH1Ds["LA_err_TIB"]->Fill(FitFunction->GetParError(0)/theBfield);
00525         TH1Ds["LA_chi2norm_TIB"]->Fill(chi2norm);
00526         TH2Ds["LA_phi_TIB"]->Fill(gphi,muH);
00527         TH2Ds["LA_eta_TIB"]->Fill(geta,muH);
00528         TH2Ds["LA_TIB_graph"]->Fill(Layer,muH);
00529         
00530         if(Layer==1){
00531         TH1Ds["LA_TIB_1"]->Fill(muH);
00532         TH2Ds["LA_phi_TIB1"]->Fill(gphi,muH);
00533         TH2Ds["LA_eta_TIB1"]->Fill(geta,muH);
00534         if(MonoStereo==0){
00535         TH1Ds["LA_TIB_1_mono"]->Fill(muH);
00536         TH2Ds["LA_phi_TIB1_mono"]->Fill(gphi,muH);
00537         TH2Ds["LA_eta_TIB1_mono"]->Fill(geta,muH);}
00538         if(MonoStereo==1){
00539         TH1Ds["LA_TIB_1_stereo"]->Fill(muH);
00540         TH2Ds["LA_phi_TIB1_stereo"]->Fill(gphi,muH);
00541         TH2Ds["LA_eta_TIB1_stereo"]->Fill(geta,muH);}
00542         }
00543         
00544         if(Layer==2){
00545         TH1Ds["LA_TIB_2"]->Fill(muH);
00546         TH2Ds["LA_phi_TIB2"]->Fill(gphi,muH);
00547         TH2Ds["LA_eta_TIB2"]->Fill(geta,muH);
00548         if(MonoStereo==0){
00549         TH1Ds["LA_TIB_2_mono"]->Fill(muH);
00550         TH2Ds["LA_phi_TIB2_mono"]->Fill(gphi,muH);
00551         TH2Ds["LA_eta_TIB2_mono"]->Fill(geta,muH);}
00552         if(MonoStereo==1){
00553         TH1Ds["LA_TIB_2_stereo"]->Fill(muH);
00554         TH2Ds["LA_phi_TIB2_stereo"]->Fill(gphi,muH);
00555         TH2Ds["LA_eta_TIB2_stereo"]->Fill(geta,muH);}
00556         }
00557         
00558         if(Layer==3){
00559         TH1Ds["LA_TIB_3"]->Fill(muH);
00560         TH2Ds["LA_phi_TIB3"]->Fill(gphi,muH);
00561         TH2Ds["LA_eta_TIB3"]->Fill(geta,muH);
00562         }
00563         
00564         if(Layer==4){
00565         TH1Ds["LA_TIB_4"]->Fill(muH);
00566         TH2Ds["LA_phi_TIB4"]->Fill(gphi,muH);
00567         TH2Ds["LA_eta_TIB4"]->Fill(geta,muH);
00568         }
00569         }       
00570         
00571         if(TOB==1){
00572         
00573         TH1Ds["LA_TOB"]->Fill(muH);
00574         TH1Ds["LA_err_TOB"]->Fill(FitFunction->GetParError(0)/theBfield);
00575         TH1Ds["LA_chi2norm_TOB"]->Fill(chi2norm);
00576         TH2Ds["LA_phi_TOB"]->Fill(gphi,muH);
00577         TH2Ds["LA_eta_TOB"]->Fill(geta,muH);
00578         TH2Ds["LA_TOB_graph"]->Fill(Layer,muH);
00579         
00580         if(Layer==1){
00581         TH1Ds["LA_TOB_1"]->Fill(muH);
00582         TH2Ds["LA_phi_TOB1"]->Fill(gphi,muH);
00583         TH2Ds["LA_eta_TOB1"]->Fill(geta,muH);
00584         if(MonoStereo==0){
00585         TH1Ds["LA_TOB_1_mono"]->Fill(muH);
00586         TH2Ds["LA_phi_TOB1_mono"]->Fill(gphi,muH);
00587         TH2Ds["LA_eta_TOB1_mono"]->Fill(geta,muH);}
00588         if(MonoStereo==1){
00589         TH1Ds["LA_TOB_1_stereo"]->Fill(muH);
00590         TH2Ds["LA_phi_TOB1_stereo"]->Fill(gphi,muH);
00591         TH2Ds["LA_eta_TOB1_stereo"]->Fill(geta,muH);}
00592         }
00593         
00594         if(Layer==2){
00595         TH1Ds["LA_TOB_2"]->Fill(muH);
00596         TH2Ds["LA_phi_TOB2"]->Fill(gphi,muH);
00597         TH2Ds["LA_eta_TOB2"]->Fill(geta,muH);
00598         if(MonoStereo==0){
00599         TH1Ds["LA_TOB_2_mono"]->Fill(muH);
00600         TH2Ds["LA_phi_TOB2_mono"]->Fill(gphi,muH);
00601         TH2Ds["LA_eta_TOB2_mono"]->Fill(geta,muH);}
00602         if(MonoStereo==1){
00603         TH1Ds["LA_TOB_2_stereo"]->Fill(muH);
00604         TH2Ds["LA_phi_TOB2_stereo"]->Fill(gphi,muH);
00605         TH2Ds["LA_eta_TOB2_stereo"]->Fill(geta,muH);}
00606         }
00607         
00608         if(Layer==3){
00609         TH1Ds["LA_TOB_3"]->Fill(muH);
00610         TH2Ds["LA_phi_TOB3"]->Fill(gphi,muH);
00611         TH2Ds["LA_eta_TOB3"]->Fill(geta,muH);
00612         }
00613         
00614         if(Layer==4){
00615         TH1Ds["LA_TOB_4"]->Fill(muH);
00616         TH2Ds["LA_phi_TOB4"]->Fill(gphi,muH);
00617         TH2Ds["LA_eta_TOB4"]->Fill(geta,muH);
00618         }
00619         
00620         if(Layer==5){
00621         TH1Ds["LA_TOB_5"]->Fill(muH);
00622         TH2Ds["LA_phi_TOB5"]->Fill(gphi,muH);
00623         TH2Ds["LA_eta_TOB5"]->Fill(geta,muH);
00624         }
00625         
00626         if(Layer==6){
00627         TH1Ds["LA_TOB_6"]->Fill(muH);
00628         TH2Ds["LA_phi_TOB6"]->Fill(gphi,muH);
00629         TH2Ds["LA_eta_TOB6"]->Fill(geta,muH);
00630         }
00631         }
00632         
00633        }
00634     }
00635     
00636     ModuleTree->Fill();
00637      
00638   }
00639   
00640   double GaussFitRange=conf_.getParameter<double>("GaussFitRange");
00641   
00642   TH1Ds["LA_TIB_1"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00643   mean_TIB1 = TH1Ds["LA_TIB_1"]->GetFunction("gaus")->GetParameter(1);
00644   float err_mean_TIB1 = TH1Ds["LA_TIB_1"]->GetFunction("gaus")->GetParError(1);
00645   float rms_TIB1 = TH1Ds["LA_TIB_1"]->GetFunction("gaus")->GetParameter(2);
00646   TH1Ds["LA_TIB_2"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00647   mean_TIB2 = TH1Ds["LA_TIB_2"]->GetFunction("gaus")->GetParameter(1);
00648   float err_mean_TIB2 = TH1Ds["LA_TIB_2"]->GetFunction("gaus")->GetParError(1);
00649   float rms_TIB2 = TH1Ds["LA_TIB_2"]->GetFunction("gaus")->GetParameter(2);
00650   TH1Ds["LA_TIB_3"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00651   mean_TIB3 = TH1Ds["LA_TIB_3"]->GetFunction("gaus")->GetParameter(1);
00652   float err_mean_TIB3 = TH1Ds["LA_TIB_3"]->GetFunction("gaus")->GetParError(1);
00653   float rms_TIB3 = TH1Ds["LA_TIB_3"]->GetFunction("gaus")->GetParameter(2);
00654   TH1Ds["LA_TIB_4"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00655   mean_TIB4 = TH1Ds["LA_TIB_4"]->GetFunction("gaus")->GetParameter(1);
00656   float err_mean_TIB4 = TH1Ds["LA_TIB_4"]->GetFunction("gaus")->GetParError(1);
00657   float rms_TIB4 = TH1Ds["LA_TIB_4"]->GetFunction("gaus")->GetParameter(2);
00658 
00659   TH1Ds["LA_TOB_1"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00660   mean_TOB1 = TH1Ds["LA_TOB_1"]->GetFunction("gaus")->GetParameter(1);
00661   float err_mean_TOB1 = TH1Ds["LA_TOB_1"]->GetFunction("gaus")->GetParError(1);
00662   float rms_TOB1 = TH1Ds["LA_TOB_1"]->GetFunction("gaus")->GetParameter(2);
00663   TH1Ds["LA_TOB_2"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00664   mean_TOB2 = TH1Ds["LA_TOB_2"]->GetFunction("gaus")->GetParameter(1);
00665   float err_mean_TOB2 = TH1Ds["LA_TOB_2"]->GetFunction("gaus")->GetParError(1);
00666   float rms_TOB2 = TH1Ds["LA_TOB_2"]->GetFunction("gaus")->GetParameter(2);
00667   TH1Ds["LA_TOB_3"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00668   mean_TOB3 = TH1Ds["LA_TOB_3"]->GetFunction("gaus")->GetParameter(1);
00669   float err_mean_TOB3 = TH1Ds["LA_TOB_3"]->GetFunction("gaus")->GetParError(1);
00670   float rms_TOB3 = TH1Ds["LA_TOB_3"]->GetFunction("gaus")->GetParameter(2);
00671   TH1Ds["LA_TOB_4"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00672   mean_TOB4 = TH1Ds["LA_TOB_4"]->GetFunction("gaus")->GetParameter(1);
00673   float err_mean_TOB4 = TH1Ds["LA_TOB_4"]->GetFunction("gaus")->GetParError(1);
00674   float rms_TOB4 = TH1Ds["LA_TOB_4"]->GetFunction("gaus")->GetParameter(2);
00675   TH1Ds["LA_TOB_5"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00676   mean_TOB5 = TH1Ds["LA_TOB_5"]->GetFunction("gaus")->GetParameter(1);
00677   float err_mean_TOB5 = TH1Ds["LA_TOB_5"]->GetFunction("gaus")->GetParError(1);
00678   float rms_TOB5 = TH1Ds["LA_TOB_5"]->GetFunction("gaus")->GetParameter(2);
00679   TH1Ds["LA_TOB_6"]->Fit("gaus","","",-GaussFitRange,GaussFitRange);  
00680   mean_TOB6 = TH1Ds["LA_TOB_6"]->GetFunction("gaus")->GetParameter(1);
00681   float err_mean_TOB6 = TH1Ds["LA_TOB_6"]->GetFunction("gaus")->GetParError(1);
00682   float rms_TOB6 = TH1Ds["LA_TOB_6"]->GetFunction("gaus")->GetParameter(2);
00683 
00684 int nlayersTIB = 4;
00685 float TIBx[4]={1,2,3,4};
00686 float TIBex[4]={0,0,0,0};
00687 float TIBy[4]={mean_TIB1, mean_TIB2, mean_TIB3, mean_TIB4};
00688 float TIBey[4]={err_mean_TIB1, err_mean_TIB2, err_mean_TIB3, err_mean_TIB4};
00689 
00690 int nlayersTOB = 6;
00691 float TOBx[6]={1,2,3,4,5,6};
00692 float TOBex[6]={0,0,0,0,0,0};
00693 float TOBy[6]={mean_TOB1, mean_TOB2, mean_TOB3, mean_TOB4, mean_TOB5, mean_TOB6};
00694 float TOBey[6]={err_mean_TOB1, err_mean_TOB2, err_mean_TOB3, err_mean_TOB4, err_mean_TOB5, err_mean_TOB6};
00695 
00696 TIB_graph = new TGraphErrors(nlayersTIB,TIBx,TIBy,TIBex,TIBey);
00697 TOB_graph = new TGraphErrors(nlayersTOB,TOBx,TOBy,TOBex,TOBey);
00698 
00699 //TF1 *fit_TIB= new TF1("fit_TIB","[0]",0,4);
00700 //TF1 *fit_TOB= new TF1("fit_TOB","[0]",0,6);
00701 
00702 gStyle->SetOptFit(111);
00703 gStyle->SetOptStat(111);
00704 
00705 TIB_graph->SetTitle("TIB Layers #mu_{H}");
00706 TIB_graph->GetXaxis()->SetTitle("Layers");
00707 TIB_graph->GetXaxis()->SetNdivisions(4);
00708 TIB_graph->GetYaxis()->SetTitle("#mu_{H}");
00709 TIB_graph->SetMarkerStyle(20);
00710 TIB_graph->GetYaxis()->SetTitleOffset(1.3);
00711 TIB_graph->Fit("fit_TIB","E","",1,4);
00712 meanMobility_TIB = TIB_graph->GetFunction("fit_TIB")->GetParameter(0);
00713 
00714 TOB_graph->SetTitle("TOB Layers #mu_{H}");
00715 TOB_graph->GetXaxis()->SetTitle("Layers");
00716 TOB_graph->GetXaxis()->SetNdivisions(6);
00717 TOB_graph->GetYaxis()->SetTitle("#mu_{H}");
00718 TOB_graph->SetMarkerStyle(20);
00719 TOB_graph->GetYaxis()->SetTitleOffset(1.3);
00720 TOB_graph->Fit("fit_TOB","E","",1,6);
00721 meanMobility_TOB = TOB_graph->GetFunction("fit_TOB")->GetParameter(0);
00722 
00723   TIB_graph->Write("TIB_graph");
00724   TOB_graph->Write("TOB_graph");
00725 
00726   Rep<<"- NR.OF TIB AND TOB MODULES = 7932"<<std::endl<<std::endl<<std::endl;
00727   Rep<<"- NO MODULE HISTOS FOUND = "<<no_mod_histo<<std::endl<<std::endl;
00728   Rep<<"- NR.OF HISTOS WITH ENTRIES > "<<FitCuts_Entries<<" = "<<histocounter<<std::endl<<std::endl;
00729   Rep<<"- NR.OF HISTOS WITH ENTRIES <= "<<FitCuts_Entries<<" (!=0) = "<<NotEnoughEntries<<std::endl<<std::endl;
00730   Rep<<"- NR.OF HISTOS WITH 0 ENTRIES = "<<ZeroEntries<<std::endl<<std::endl<<std::endl;
00731   Rep<<"- NR.OF GOOD FIT (FIRST IT + SECOND IT GOOD FIT)= "<<GoodFit<<std::endl<<std::endl;
00732   Rep<<"- NR.OF FIRST IT GOOD FIT = "<<FirstIT_goodfit<<std::endl<<std::endl;
00733   Rep<<"- NR.OF SECOND IT GOOD FIT = "<<SecondIT_goodfit<<std::endl<<std::endl;
00734   Rep<<"- NR.OF FIRST IT BAD FIT = "<<FirstIT_badfit<<std::endl<<std::endl;
00735   Rep<<"- NR.OF SECOND IT BAD FIT = "<<SecondIT_badfit<<std::endl<<std::endl<<std::endl;
00736   
00737   Rep<<"--------------- Mean MuH values per Layer -------------------"<<std::endl<<std::endl<<std::endl;
00738   Rep<<"TIB1 = "<<mean_TIB1<<" +- "<<err_mean_TIB1<<" RMS = "<<rms_TIB1<<std::endl;
00739   Rep<<"TIB2 = "<<mean_TIB2<<" +- "<<err_mean_TIB2<<" RMS = "<<rms_TIB2<<std::endl;
00740   Rep<<"TIB3 = "<<mean_TIB3<<" +- "<<err_mean_TIB3<<" RMS = "<<rms_TIB3<<std::endl;
00741   Rep<<"TIB4 = "<<mean_TIB4<<" +- "<<err_mean_TIB4<<" RMS = "<<rms_TIB4<<std::endl;
00742   Rep<<"TOB1 = "<<mean_TOB1<<" +- "<<err_mean_TOB1<<" RMS = "<<rms_TOB1<<std::endl;
00743   Rep<<"TOB2 = "<<mean_TOB2<<" +- "<<err_mean_TOB2<<" RMS = "<<rms_TOB2<<std::endl;
00744   Rep<<"TOB3 = "<<mean_TOB3<<" +- "<<err_mean_TOB3<<" RMS = "<<rms_TOB3<<std::endl;
00745   Rep<<"TOB4 = "<<mean_TOB4<<" +- "<<err_mean_TOB4<<" RMS = "<<rms_TOB4<<std::endl;
00746   Rep<<"TOB5 = "<<mean_TOB5<<" +- "<<err_mean_TOB5<<" RMS = "<<rms_TOB5<<std::endl;
00747   Rep<<"TOB6 = "<<mean_TOB6<<" +- "<<err_mean_TOB6<<" RMS = "<<rms_TOB6<<std::endl<<std::endl;
00748   Rep<<"Mean Hall Mobility TIB = "<<meanMobility_TIB<<" +- "<<TIB_graph->GetFunction("fit_TIB")->GetParError(0)<<std::endl;
00749   Rep<<"Mean Hall Mobility TOB = "<<meanMobility_TOB<<" +- "<<TOB_graph->GetFunction("fit_TOB")->GetParError(0)<<std::endl<<std::endl<<std::endl;
00750         
00751   Rep.close();
00752   NoEntries.close(); 
00753   
00754 hFile->Write();
00755 hFile->Close();
00756     
00757 }
00758 
00759 // Virtual destructor needed.
00760 
00761 SiStripCalibLorentzAngle::~SiStripCalibLorentzAngle(){
00762  delete hFile;
00763 }
00764   
00765 
00766 // Analyzer: Functions that gets called by framework every event
00767    
00768 SiStripLorentzAngle* SiStripCalibLorentzAngle::getNewObject(){
00769 
00770   SiStripLorentzAngle* LorentzAngle = new SiStripLorentzAngle();
00771   
00772   if(!LayerDB){
00773   for(std::map<uint32_t, float>::iterator it = detid_la.begin(); it != detid_la.end(); it++){
00774     
00775     float langle=it->second;
00776     if ( ! LorentzAngle->putLorentzAngle(it->first,langle) )
00777       edm::LogError("SiStripCalibLorentzAngle")<<"[SiStripCalibLorentzAngle::analyze] detid already exists"<<std::endl;
00778   }
00779   }
00780   
00781   else{
00782   
00783     const TrackerGeometry::DetIdContainer& Id = estracker->detIds();
00784     TrackerGeometry::DetIdContainer::const_iterator Iditer; 
00785        
00786     for(Iditer=Id.begin();Iditer!=Id.end();Iditer++){
00787   
00788     StripSubdetector subid(Iditer->rawId());
00789     
00790     hallMobility = 0.;
00791     
00792     if(subid.subdetId() == int (StripSubdetector::TIB)){
00793     
00794     uint32_t tibLayer = tTopo->tibLayer(*Iditer);
00795     if(tibLayer==1){
00796     hallMobility=mean_TIB1;}
00797     if(tibLayer==2){
00798     hallMobility=mean_TIB2;}
00799     if(tibLayer==3){
00800     hallMobility=mean_TIB3;}
00801     if(tibLayer==4){
00802     hallMobility=mean_TIB4;}
00803     if (!LorentzAngle->putLorentzAngle(Iditer->rawId(),hallMobility)) edm::LogError("SiStripLorentzAngleGenerator")<<" detid already exists"<<std::endl;
00804     }
00805     
00806     if(subid.subdetId() == int (StripSubdetector::TOB)){
00807     
00808     uint32_t tobLayer = tTopo->tobLayer(*Iditer);
00809     if(tobLayer==1){
00810     hallMobility=mean_TOB1;}
00811     if(tobLayer==2){
00812     hallMobility=mean_TOB2;}
00813     if(tobLayer==3){
00814     hallMobility=mean_TOB3;}
00815     if(tobLayer==4){
00816     hallMobility=mean_TOB4;}
00817     if(tobLayer==5){
00818     hallMobility=mean_TOB5;}
00819     if(tobLayer==6){
00820     hallMobility=mean_TOB6;}
00821     if (!LorentzAngle->putLorentzAngle(Iditer->rawId(),hallMobility)) edm::LogError("SiStripLorentzAngleGenerator")<<" detid already exists"<<std::endl;
00822     } 
00823      
00824     if( subid.subdetId() == int(StripSubdetector::TID) ) {
00825     hallMobility=meanMobility_TIB;
00826     if (!LorentzAngle->putLorentzAngle(Iditer->rawId(),hallMobility)) edm::LogError("SiStripLorentzAngleGenerator")<<" detid already exists"<<std::endl;
00827     } 
00828     
00829     if( subid.subdetId() == int(StripSubdetector::TEC) ) {
00830     
00831     if(tTopo->tecRing(subid)<5 ) {
00832     hallMobility=meanMobility_TIB;
00833     }else{
00834     hallMobility=meanMobility_TOB;
00835     }
00836     if (!LorentzAngle->putLorentzAngle(Iditer->rawId(),hallMobility)) edm::LogError("SiStripLorentzAngleGenerator")<<" detid already exists"<<std::endl;
00837     }
00838                  
00839   }
00840   }
00841   
00842   return LorentzAngle;
00843   
00844 }
00845 
00846 
00847 
00848 
00849 
00850   
00851   
00852   
00853 
00854