CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Validation/MuonHits/src/MuonSimHitsValidAnalyzer.cc

Go to the documentation of this file.
00001 #include "Validation/MuonHits/src/MuonSimHitsValidAnalyzer.h"
00002 
00003 #include "TFile.h"
00004 #include "TTree.h"
00005 #include "TBranch.h"
00006 #include "TH1F.h"
00007 
00008 #include <iostream>
00009 #include <string>
00010 
00011 using namespace edm;
00012 using namespace std;
00013 
00014 
00015 MuonSimHitsValidAnalyzer::MuonSimHitsValidAnalyzer(const edm::ParameterSet& iPSet) :
00016   fName(""), verbosity(0), label(""), getAllProvenances(false),
00017   printProvenanceInfo(false), nRawGenPart(0), count(0)
00018 
00019 {
00021   fName = iPSet.getUntrackedParameter<std::string>("Name");
00022   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
00023   label = iPSet.getParameter<std::string>("Label");
00024   edm::ParameterSet m_Prov =
00025     iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
00026   getAllProvenances = 
00027     m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
00028   printProvenanceInfo = 
00029     m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
00030 
00031    nRawGenPart = 0;
00032  // ROOT Histos output files
00033    DToutputFile_ =  iPSet.getUntrackedParameter<std::string>("DT_outputFile", ""); 
00034    //  CSCoutputFile_ =  iPSet.getUntrackedParameter<std::string>("CSC_outputFile", "");
00035    //  RPCoutputFile_ =  iPSet.getUntrackedParameter<std::string>("RPC_outputFile", "");
00036    
00037    
00039    //  CSCHitsSrc_ = iPSet.getParameter<edm::InputTag>("CSCHitsSrc");
00040    DTHitsSrc_  = iPSet.getParameter<edm::InputTag>("DTHitsSrc");
00041    //  RPCHitsSrc_ = iPSet.getParameter<edm::InputTag>("RPCHitsSrc");
00042    
00044    if (verbosity) {
00045      edm::LogInfo ("MuonSimHitsValidAnalyzer::MuonSimHitsValidAnalyzer") 
00046        << "\n===============================\n"
00047        << "Initialized as EDAnalyzer with parameter values:\n"
00048        << "    Name      = " << fName << "\n"
00049        << "    Verbosity = " << verbosity << "\n"
00050        << "    Label     = " << label << "\n"
00051        << "    GetProv   = " << getAllProvenances << "\n"
00052        << "    PrintProv = " << printProvenanceInfo << "\n"
00053        //    << "    CSCHitsSrc=  " <<CSCHitsSrc_.label() 
00054        //    << ":" << CSCHitsSrc_.instance() << "\n"
00055        << "    DTHitsSrc =  " <<DTHitsSrc_.label()
00056        << ":" << DTHitsSrc_.instance() << "\n"
00057        //     << "    RPCHitsSrc=  " <<RPCHitsSrc_.label()
00058        //     << ":" << RPCHitsSrc_.instance() << "\n"
00059        << "===============================\n";
00060    }
00061    
00062    // ----------------------
00063    // get hold of back-end interface DT
00064    dbeDT_ = 0;
00065    dbeDT_ = Service<DQMStore>().operator->();
00066    if ( dbeDT_ ) {
00067      if ( verbosity ) {
00068        dbeDT_->setVerbose(1);
00069      } else {
00070        dbeDT_->setVerbose(0);
00071      }
00072    }
00073    if ( dbeDT_ ) {
00074      if ( verbosity ) dbeDT_->showDirStructure();
00075    }
00076    
00077    // ----------------------
00078    
00079    bookHistos_DT();
00080  
00081    /*
00082    // get hold of back-end interface CSC
00083    dbeCSC_ = 0;
00084    dbeCSC_ = Service<DQMStore>().operator->();
00085    if ( dbeCSC_ ) {
00086    if ( verbosity ) {
00087    dbeCSC_->setVerbose(1);
00088    } else {
00089    dbeCSC_->setVerbose(0);
00090    }
00091    }
00092    if ( dbeCSC_ ) {
00093    if ( verbosity ) dbeCSC_->showDirStructure();
00094    }
00095    
00096    // ----------------------
00097    
00098    bookHistos_CSC();
00099    
00100    // get hold of back-end interface RPC
00101    dbeRPC_ = 0;
00102    dbeRPC_ = Service<DQMStore>().operator->();
00103    if ( dbeRPC_ ) {
00104    if ( verbosity ) {
00105    dbeRPC_->setVerbose(1);
00106    } else {
00107    dbeRPC_->setVerbose(0);
00108    }
00109    }
00110    if ( dbeRPC_ ) {
00111    if ( verbosity ) dbeRPC_->showDirStructure();
00112    }
00113    
00114    // ----------------------
00115    
00116    bookHistos_RPC();
00117    */
00118    
00119    pow6=1000000.0; 
00120    mom4 =0.;
00121    mom1 = 0; 
00122    costeta = 0.;
00123    radius = 0;
00124    sinteta = 0.;
00125    globposx = 0.;
00126    globposy = 0;
00127    nummu_DT = 0; 
00128    nummu_CSC =0;
00129    nummu_RPC=0;
00130    
00131 }
00132 
00133 MuonSimHitsValidAnalyzer::~MuonSimHitsValidAnalyzer() 
00134 {
00135  if ( DToutputFile_.size() != 0 ) 
00136    {
00137     LogInfo("OutputInfo") << " DT MuonHits histos file is closed " ;
00138     theDTFile->Close();
00139    }   
00140    
00141 // theCSCFile->Close();
00142 // theRPCFile->Close();
00143 }
00144 
00145 void MuonSimHitsValidAnalyzer::beginJob()
00146 {
00147   return;
00148 }
00149 
00150 void MuonSimHitsValidAnalyzer::bookHistos_DT()
00151 {
00152   meAllDTHits =0 ;
00153   meMuDTHits =0 ;
00154   meToF =0 ;
00155   meEnergyLoss =0 ;
00156   meMomentumMB1 =0 ;
00157   meMomentumMB4 =0 ;
00158   meLossMomIron =0 ;
00159   meLocalXvsZ =0 ;
00160   meLocalXvsY =0 ;
00161   meGlobalXvsZ =0 ;
00162   meGlobalXvsY =0 ;
00163   meGlobalXvsZWm2 =0 ;
00164   meGlobalXvsZWm1 =0 ; 
00165   meGlobalXvsZW0 =0 ;
00166   meGlobalXvsZWp1 =0 ;
00167   meGlobalXvsZWp2 =0 ;
00168   meGlobalXvsYWm2 =0 ;
00169   meGlobalXvsYWm1 =0 ;
00170   meGlobalXvsYW0 =0 ;
00171   meGlobalXvsYWp1 =0 ;
00172   meGlobalXvsYWp2 =0 ;
00173   meWheelOccup =0 ;
00174   meStationOccup =0 ;
00175   meSectorOccup =0 ;
00176   meSuperLOccup =0 ;
00177   meLayerOccup =0 ;
00178   meWireOccup =0 ;
00179   mePathMuon =0 ;
00180   meChamberOccup =0 ;
00181   meHitRadius =0 ;
00182   meCosTheta =0 ;
00183   meGlobalEta =0 ;
00184   meGlobalPhi =0 ;
00185 
00186   if ( DToutputFile_.size() != 0 ) {
00187    theDTFile = new TFile(DToutputFile_.c_str(),"RECREATE");
00188    theDTFile->cd();
00189    LogInfo("OutputInfo") << " DT MuonHits histograms will be saved to '" << DToutputFile_.c_str() << "'";
00190   } else {
00191    LogInfo("OutputInfo") << " DT MuonHits histograms will NOT be saved";
00192   }
00193 
00194 
00195   Char_t histo_n[100];
00196   Char_t histo_t[100];
00197 
00198   if ( dbeDT_ ) {
00199     dbeDT_->setCurrentFolder("MuonDTHitsV/DTHitsValidationTask");
00200  
00201     sprintf (histo_n, "Number_of_all_DT_hits" );
00202     sprintf (histo_t, "Number_of_all_DT_hits" );
00203     meAllDTHits = dbeDT_->book1D(histo_n, histo_t,  200, 1.0, 201.0) ;
00204  
00205     sprintf (histo_n, "Number_of_muon_DT_hits" );
00206     sprintf (histo_t, "Number_of_muon_DT_hits" );
00207     meMuDTHits  = dbeDT_->book1D(histo_n, histo_t, 150, 1.0, 151.0);
00208 
00209     sprintf (histo_n, "Tof_of_hits " );
00210     sprintf (histo_t, "Tof_of_hits " );
00211     meToF = dbeDT_->book1D(histo_n, histo_t, 100, -0.5, 50.) ;
00212 
00213     sprintf (histo_n, "DT_energy_loss_keV" );
00214     sprintf (histo_t, "DT_energy_loss_keV" );
00215     meEnergyLoss  = dbeDT_->book1D(histo_n, histo_t, 100, 0.0, 10.0);
00216 
00217     sprintf (histo_n, "Momentum_at_MB1" );
00218     sprintf (histo_t, "Momentum_at_MB1" );
00219     meMomentumMB1 = dbeDT_->book1D(histo_n, histo_t, 100, 10.0, 200.0);
00220 
00221     sprintf (histo_n, "Momentum_at_MB4" );
00222     sprintf (histo_t, "Momentum_at_MB4" );
00223     meMomentumMB4 = dbeDT_->book1D(histo_n, histo_t, 100, 10.0, 200.0) ;
00224 
00225     sprintf (histo_n, "Loss_of_muon_Momentum_in_Iron" );
00226     sprintf (histo_t, "Loss_of_muon_Momentum_in_Iron" );
00227     meLossMomIron  = dbeDT_->book1D(histo_n, histo_t, 80, 0.0, 40.0) ;
00228 
00229     sprintf (histo_n, "Local_x-coord_vs_local_z-coord_of_muon_hit" );    
00230     sprintf (histo_t, "Local_x-coord_vs_local_z-coord_of_muon_hit" );
00231     meLocalXvsZ = dbeDT_->book2D(histo_n, histo_t,100, -150., 150., 100, -0.8, 0.8 ) ;
00232 
00233     sprintf (histo_n, "local_x-coord_vs_local_y-coord_of_muon_hit" );
00234     sprintf (histo_t, "local_x-coord_vs_local_y-coord_of_muon_hit" );
00235     meLocalXvsY = dbeDT_->book2D(histo_n, histo_t, 100, -150., 150., 100, -150., 150. );
00236 
00237     sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit" );
00238     sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit" );
00239     meGlobalXvsZ = dbeDT_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. ) ;
00240 
00241     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit" );
00242     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit" );
00243     meGlobalXvsY = dbeDT_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. ) ; 
00244 
00245 //   New histos
00246 
00247     sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2" );
00248     sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2" );
00249     meGlobalXvsZWm2 = dbeDT_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00250 
00251     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2" );
00252     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2" );
00253     meGlobalXvsYWm2 = dbeDT_->book2D(histo_n, histo_t,  100, -800., 800., 100, -800., 800. );
00254  
00255     sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1" );
00256     sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1" );
00257     meGlobalXvsZWm1 = dbeDT_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00258 
00259     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1" );
00260     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1" );
00261     meGlobalXvsYWm1 = dbeDT_->book2D(histo_n, histo_t,  100, -800., 800., 100, -800., 800. );
00262   
00263     sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0" );
00264     sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0" );
00265     meGlobalXvsZW0 = dbeDT_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00266 
00267     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0" );
00268     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0" );
00269     meGlobalXvsYW0 = dbeDT_->book2D(histo_n, histo_t,  100, -800., 800., 100, -800., 800. );
00270 
00271     sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1" );
00272     sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1" );
00273     meGlobalXvsZWp1 = dbeDT_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00274 
00275     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1" );
00276     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1" );
00277     meGlobalXvsYWp1 = dbeDT_->book2D(histo_n, histo_t,  100, -800., 800., 100, -800., 800. );
00278 
00279     sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2" );
00280     sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2" );
00281     meGlobalXvsZWp2 = dbeDT_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00282 
00283     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2" );
00284     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2" );
00285     meGlobalXvsYWp2 = dbeDT_->book2D(histo_n, histo_t,  100, -800., 800., 100, -800., 800. );
00286 
00287 //
00288 
00289     sprintf (histo_n, "Wheel_occupancy" );
00290     sprintf (histo_t, "Wheel_occupancy" );
00291     meWheelOccup = dbeDT_->book1D(histo_n, histo_t, 10, -5.0, 5.0) ;
00292 
00293     sprintf (histo_n, "Station_occupancy" );
00294     sprintf (histo_t, "Station_occupancy" );
00295     meStationOccup = dbeDT_->book1D(histo_n, histo_t, 6, 0., 6.0) ; 
00296 
00297     sprintf (histo_n, "Sector_occupancy" );
00298     sprintf (histo_t, "Sector_occupancy" );
00299     meSectorOccup = dbeDT_->book1D(histo_n, histo_t, 20, 0., 20.) ;
00300 
00301     sprintf (histo_n, "SuperLayer_occupancy" );
00302     sprintf (histo_t, "SuperLayer_occupancy" );
00303     meSuperLOccup = dbeDT_->book1D(histo_n, histo_t, 5, 0., 5.) ;
00304 
00305     sprintf (histo_n, "Layer_occupancy" );
00306     sprintf (histo_t, "Layer_occupancy" );
00307     meLayerOccup = dbeDT_->book1D(histo_n, histo_t,6, 0., 6.) ;
00308 
00309     sprintf (histo_n, "Wire_occupancy" );
00310     sprintf (histo_t, "Wire_occupancy" );
00311     meWireOccup = dbeDT_->book1D(histo_n, histo_t, 100, 0., 100.) ;
00312 
00313     sprintf (histo_n, "path_followed_by_muon" );
00314     sprintf (histo_t, "path_followed_by_muon" );
00315     mePathMuon = dbeDT_->book1D(histo_n, histo_t, 160, 0., 160.) ;
00316  
00317     sprintf (histo_n, "chamber_occupancy" ); 
00318     sprintf (histo_t, "chamber_occupancy" );
00319     meChamberOccup = dbeDT_->book1D(histo_n, histo_t,  251, 0., 251.) ;
00320 
00321     sprintf (histo_n, "radius_of_hit");
00322     sprintf (histo_t, "radius_of_hit");
00323     meHitRadius = dbeDT_->book1D(histo_n, histo_t, 100, 0., 1200. );
00324 
00325     sprintf (histo_n, "costheta_of_hit" ); 
00326     sprintf (histo_t, "costheta_of_hit" );
00327     meCosTheta = dbeDT_->book1D(histo_n, histo_t,  100, -1., 1.) ;
00328 
00329     sprintf (histo_n, "global_eta_of_hit" );
00330     sprintf (histo_t, "global_eta_of_hit" );
00331     meGlobalEta = dbeDT_->book1D(histo_n, histo_t, 60, -2.7, 2.7 ); 
00332  
00333     sprintf (histo_n, "global_phi_of_hit" ); 
00334     sprintf (histo_t, "global_phi_of_hit" );
00335     meGlobalPhi = dbeDT_->book1D(histo_n, histo_t, 60, -3.14, 3.14);
00336 
00337   }
00338 
00339 }
00340 
00341 void MuonSimHitsValidAnalyzer::bookHistos_RPC()
00342 {
00343   meAllRPCHits = 0 ;
00344   meMuRPCHits = 0 ; 
00345   meRegionOccup = 0 ;
00346   meRingOccBar = 0 ;
00347   meRingOccEndc = 0 ;
00348   meStatOccBar = 0 ;
00349   meStatOccEndc = 0 ;
00350   meSectorOccBar = 0 ;
00351   meSectorOccEndc = 0 ;
00352   meLayerOccBar = 0 ;
00353   meLayerOccEndc = 0 ;
00354   meSubSectOccBar = 0 ;
00355   meSubSectOccEndc = 0 ;
00356   meRollOccBar = 0 ;
00357   meRollOccEndc = 0 ;
00358   meElossBar = 0 ;
00359   meElossEndc = 0 ;
00360   mepathRPC = 0 ;
00361   meMomRB1 = 0 ;
00362   meMomRB4 = 0 ;
00363   meLossMomBar = 0 ;
00364   meMomRE1 = 0 ;
00365   meMomRE4 = 0 ;
00366   meLossMomEndc = 0 ;
00367   meLocalXvsYBar = 0 ;
00368   meGlobalXvsZBar = 0 ;
00369   meGlobalXvsYBar = 0 ;
00370   meLocalXvsYEndc = 0 ;
00371   meGlobalXvsZEndc = 0 ;
00372   meGlobalXvsYEndc = 0 ;
00373   meHitRadiusBar = 0 ;
00374   meCosThetaBar = 0 ;
00375   meHitRadiusEndc = 0 ;
00376   meCosThetaEndc = 0 ;
00377   
00378   theRPCFile = new TFile(RPCoutputFile_.c_str(),"RECREATE");
00379   theRPCFile->cd();
00380  
00381   Char_t histo_n[100];
00382   Char_t histo_t[100];
00383 
00384    if ( dbeRPC_ ) {
00385     dbeRPC_->setCurrentFolder("MuonRPCHitsV/RPCHitsValidationTask");
00386 
00387     sprintf (histo_n, "Number_of_all_RPC_hits" );
00388     sprintf (histo_t, "Number_of_all_RPC_hits" );
00389     meAllRPCHits = dbeRPC_->book1D(histo_n, histo_t,  100, 1.0, 101.0) ;
00390 
00391     sprintf (histo_n, "Number_of_muon_RPC_hits" );
00392     sprintf (histo_t, "Number_of_muon_RPC_hits" );
00393     meMuRPCHits = dbeRPC_->book1D(histo_n, histo_t,  50, 1., 51.);
00394 
00395     sprintf (histo_n, "Region_occupancy");
00396     sprintf (histo_t, "Region_occupancy");
00397     meRegionOccup  = dbeRPC_->book1D(histo_n, histo_t, 6, -3.0, 3.0) ;
00398 
00399     sprintf (histo_n, "Ring_occupancy_barrel");
00400     sprintf (histo_t, "Ring_occupancy_barrel");
00401     meRingOccBar = dbeRPC_->book1D(histo_n, histo_t, 8, -3., 5.0) ;
00402 
00403     sprintf (histo_n, "Ring_occupancy_endcaps");
00404     sprintf (histo_t, "Ring_occupancy_endcaps");
00405     meRingOccEndc = dbeRPC_->book1D(histo_n, histo_t, 8, -3., 5.0) ;
00406  
00407     sprintf (histo_n, "Station_occupancy_barrel");
00408     sprintf (histo_t, "Station_occupancy_barrel");
00409     meStatOccBar = dbeRPC_->book1D(histo_n, histo_t, 8, 0., 8.);
00410 
00411     sprintf (histo_n, "Station_occupancy_endcaps" );
00412     sprintf (histo_t, "Station_occupancy_endcaps" );
00413     meStatOccEndc = dbeRPC_->book1D(histo_n, histo_t, 8, 0., 8.);
00414 
00415     sprintf (histo_n, "Sector_occupancy_barrel" );
00416     sprintf (histo_t, "Sector_occupancy_barrel" );
00417     meSectorOccBar = dbeRPC_->book1D(histo_n, histo_t, 16, 0., 16.) ;
00418  
00419     sprintf (histo_n, "Sector_occupancy_endcaps" ); 
00420     sprintf (histo_t, "Sector_occupancy_endcaps" );
00421     meSectorOccEndc = dbeRPC_->book1D(histo_n, histo_t, 16, 0., 16.) ;
00422 
00423     sprintf (histo_n, "Layer_occupancy_barrel" );
00424     sprintf (histo_t, "Layer_occupancy_barrel" );
00425     meLayerOccBar = dbeRPC_->book1D(histo_n, histo_t,4, 0., 4.) ;
00426 
00427     sprintf (histo_n, "Layer_occupancy_endcaps" );
00428     sprintf (histo_t, "Layer_occupancy_endcaps" );
00429     meLayerOccEndc = dbeRPC_->book1D(histo_n, histo_t,4, 0., 4.) ;
00430   
00431     sprintf (histo_n, "Subsector_occupancy_barrel" );
00432     sprintf (histo_t, "Subsector_occupancy_barrel" );
00433     meSubSectOccBar = dbeRPC_->book1D(histo_n, histo_t, 10, 0., 10.) ;
00434 
00435     sprintf (histo_n, "Subsector_occupancy_endcaps" );
00436     sprintf (histo_t, "Subsector_occupancy_endcaps" );
00437     meSubSectOccEndc = dbeRPC_->book1D(histo_n, histo_t, 10, 0., 10.) ;
00438 
00439     sprintf (histo_n, "Roll_occupancy_barrel" );
00440     sprintf (histo_t, "Roll_occupancy_barrel" );
00441     meRollOccBar = dbeRPC_->book1D(histo_n, histo_t,  6, 0., 6.) ;
00442 
00443     sprintf (histo_n, "Roll_occupancy_endcaps" );
00444     sprintf (histo_t, "Roll_occupancy_endcaps" );
00445     meRollOccEndc = dbeRPC_->book1D(histo_n, histo_t,  6, 0., 6.) ;
00446  
00447     sprintf (histo_n, "RPC_energy_loss_barrel" );   
00448     sprintf (histo_t, "RPC_energy_loss_barrel" );
00449     meElossBar = dbeRPC_->book1D(histo_n, histo_t, 50, 0.0, 10.0) ;
00450 
00451     sprintf (histo_n, "RPC_energy_loss_endcaps" );
00452     sprintf (histo_t, "RPC_energy_loss_endcaps" );
00453     meElossEndc = dbeRPC_->book1D(histo_n, histo_t, 50, 0.0, 10.0) ;
00454 
00455     sprintf (histo_n, "path_followed_by_muon" );
00456     sprintf (histo_t, "path_followed_by_muon" );
00457     mepathRPC = dbeRPC_->book1D(histo_n, histo_t, 160, 0., 160.) ;
00458 
00459     sprintf (histo_n, "Momentum_at_RB1") ;
00460     sprintf (histo_t, "Momentum_at_RB1") ;
00461     meMomRB1 = dbeRPC_->book1D(histo_n, histo_t, 80, 10.0, 200.0) ;
00462 
00463     sprintf (histo_n, "Momentum_at_RB4") ;
00464     sprintf (histo_t, "Momentum_at_RB4") ;
00465     meMomRB4 = dbeRPC_->book1D(histo_n, histo_t, 80, 10.0, 200.0) ;
00466 
00467     sprintf (histo_n, "Loss_of_muon_Momentum_in_Iron_barrel" );
00468     sprintf (histo_t, "Loss_of_muon_Momentum_in_Iron_barrel" );
00469     meLossMomBar = dbeRPC_->book1D(histo_n, histo_t,  80, 0.0, 40.0) ;
00470 
00471     sprintf (histo_n, "Momentum_at_RE1");
00472     sprintf (histo_t, "Momentum_at_RE1");
00473     meMomRE1 = dbeRPC_->book1D(histo_n, histo_t,  100, 10.0, 300.0);
00474 
00475     sprintf (histo_n, "Momentum_at_RE4");
00476     sprintf (histo_t, "Momentum_at_RE4");
00477     meMomRE4 = dbeRPC_->book1D(histo_n, histo_t,  100, 10.0, 300.0);
00478  
00479     sprintf (histo_n, "Loss_of_muon_Momentum_in_Iron_endcap" );
00480     sprintf (histo_t, "Loss_of_muon_Momentum_in_Iron_endcap" );
00481     meLossMomEndc = dbeRPC_->book1D(histo_n, histo_t, 80, 0.0, 40.0) ;
00482 
00483     sprintf (histo_n, "local_x-coord_vs_local_y-coord_of_muon_hit") ;
00484     sprintf (histo_t, "local_x-coord_vs_local_y-coord_of_muon_hit") ;
00485     meLocalXvsYBar = dbeRPC_->book2D(histo_n, histo_t, 100, -150., 150., 100, -100., 100. );
00486 
00487     sprintf (histo_n, "Global_z-coord_vs_global_x-coord_of_muon_hit_barrel" );
00488     sprintf (histo_t, "Global_z-coord_vs_global_x-coord_of_muon_hit_barrel" );
00489     meGlobalXvsZBar = dbeRPC_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00490  
00491     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_barrel" );
00492     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_barrel" );
00493     meGlobalXvsYBar = dbeRPC_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00494 
00495     sprintf (histo_n, "radius_of_hit_barrel" );
00496     sprintf (histo_t, "radius_of_hit_barrel" );
00497     meHitRadiusBar = dbeRPC_->book1D(histo_n, histo_t, 100, 0., 1200.) ;
00498 
00499     sprintf (histo_n, "radius_of_hit_endcaps" );
00500     sprintf (histo_t, "radius_of_hit_endcaps" );
00501     meHitRadiusEndc = dbeRPC_->book1D(histo_n, histo_t, 100, 0., 1300.) ;
00502 
00503     sprintf (histo_n, "costheta_of_hit_barrel" ) ;
00504     sprintf (histo_t, "costheta_of_hit_barrel" ) ;
00505     meCosThetaBar = dbeRPC_->book1D(histo_n, histo_t,  100, -1., 1.);
00506 
00507     sprintf (histo_n, "costheta_of_hit_endcaps" );
00508     sprintf (histo_t, "costheta_of_hit_endcaps" );
00509     meCosThetaEndc = dbeRPC_->book1D(histo_n, histo_t,  100, -1., 1.);
00510 
00511     sprintf (histo_n, "Global_z-coord_vs_global_x-coord_of_muon_hit_endcaps" );
00512     sprintf (histo_t, "Global_z-coord_vs_global_x-coord_of_muon_hit_endcaps" );
00513     meGlobalXvsZEndc = dbeRPC_->book2D(histo_n, histo_t,  100, -1200., 1200., 100, -800., 800. ) ;
00514 
00515     sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_endcaps" );
00516     sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_endcaps" );
00517     meGlobalXvsYEndc = dbeRPC_->book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
00518 
00519   } 
00520 
00521 }
00522 
00523 void MuonSimHitsValidAnalyzer::bookHistos_CSC()
00524 {
00525   meAllCSCHits =0 ;
00526   meMuCSCHits =0 ;
00527   meEnergyLoss_111 =0 ;
00528   meToF_311 =0 ;
00529   meEnergyLoss_112 =0 ;
00530   meToF_312 =0 ;
00531   meEnergyLoss_113 =0 ;
00532   meToF_313 =0 ;
00533   meEnergyLoss_114 =0 ;
00534   meToF_314 =0 ;
00535   meEnergyLoss_121 =0 ;
00536   meToF_321 =0 ;
00537   meEnergyLoss_122 =0 ;
00538   meToF_322 =0 ;
00539   meEnergyLoss_131 =0 ;
00540   meToF_331 =0 ;
00541   meEnergyLoss_132 =0 ;
00542   meToF_332 =0 ;
00543   meEnergyLoss_141 =0 ;
00544   meToF_341 =0 ;
00545   meEnergyLoss_211 =0 ;
00546   meToF_411 =0 ;
00547   meEnergyLoss_212 =0 ;
00548   meToF_412 =0 ;
00549   meEnergyLoss_213 =0 ;
00550   meToF_413 =0 ;
00551   meEnergyLoss_214 =0 ;
00552   meToF_414 =0 ;
00553   meEnergyLoss_221 =0 ;
00554   meToF_421 =0 ;
00555   meEnergyLoss_222 =0 ;
00556   meToF_422 =0 ;
00557   meEnergyLoss_231 =0 ;
00558   meToF_431 =0 ;
00559   meEnergyLoss_232 =0 ;
00560   meToF_432 =0 ;
00561   meEnergyLoss_241 =0 ;
00562   meToF_441 =0 ;
00563  
00564 
00565    theCSCFile = new TFile(CSCoutputFile_.c_str(),"RECREATE");
00566    theCSCFile->cd();
00567 
00568    Char_t histo_n[100];
00569    Char_t histo_t[100];
00570 
00571    if ( dbeCSC_ ) {
00572     dbeCSC_->setCurrentFolder("MuonCSCHitsV/CSCHitsValidationTask");
00573  
00574     sprintf (histo_n, "Number_of_all_CSC_hits " );
00575     sprintf (histo_t, "Number_of_all_CSC_hits " );
00576     meAllCSCHits = dbeCSC_->book1D(histo_n, histo_t,  100, 1.0, 101.0) ;
00577 
00578     sprintf (histo_n, "Number_of_muon_CSC_hits" );
00579     sprintf (histo_t, "Number_of_muon_CSC_hits" );
00580     meMuCSCHits = dbeCSC_->book1D(histo_n, histo_t, 50, 1.0, 51.0); 
00581 
00582     sprintf (histo_n, "111__energy_loss");
00583     sprintf (histo_t, "111__energy_loss");
00584     meEnergyLoss_111 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00585 
00586     sprintf (histo_n, "311_tof");
00587     sprintf (histo_t, "311_tof");
00588     meToF_311 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00589 
00590     sprintf (histo_n, "112__energy_loss");
00591     sprintf (histo_t, "112__energy_loss");
00592     meEnergyLoss_112 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00593 
00594     sprintf (histo_n, "312_tof");
00595     sprintf (histo_t, "312_tof");
00596     meToF_312 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00597 
00598     sprintf (histo_n, "113__energy_loss");
00599     sprintf (histo_t, "113__energy_loss");
00600     meEnergyLoss_111 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00601 
00602     sprintf (histo_n, "313_tof");
00603     sprintf (histo_t, "313_tof");
00604     meToF_313 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00605  
00606     sprintf (histo_n, "114__energy_loss");
00607     sprintf (histo_t, "114__energy_loss");
00608     meEnergyLoss_114 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00609 
00610     sprintf (histo_n, "314_tof");
00611     sprintf (histo_t, "314_tof");
00612     meToF_314 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00613 
00614     sprintf (histo_n, "121__energy_loss");
00615     sprintf (histo_t, "121__energy_loss");
00616     meEnergyLoss_121 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00617 
00618     sprintf (histo_n, "321_tof");
00619     sprintf (histo_t, "321_tof");
00620     meToF_321 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00621 
00622     sprintf (histo_n, "122__energy_loss");
00623     sprintf (histo_t, "122__energy_loss");
00624     meEnergyLoss_122 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00625 
00626     sprintf (histo_n, "322_tof");
00627     sprintf (histo_t, "322_tof");
00628     meToF_322 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00629 
00630     sprintf (histo_n, "131__energy_loss");
00631     sprintf (histo_t, "131__energy_loss");
00632     meEnergyLoss_131 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00633 
00634     sprintf (histo_n, "331_tof");
00635     sprintf (histo_t, "331_tof");
00636     meToF_331 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00637 
00638     sprintf (histo_n, "132__energy_loss");
00639     sprintf (histo_t, "132__energy_loss");
00640     meEnergyLoss_132 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00641 
00642     sprintf (histo_n, "332_tof");
00643     sprintf (histo_t, "332_tof");
00644     meToF_332 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00645 
00646     sprintf (histo_n, "141__energy_loss");
00647     sprintf (histo_t, "141__energy_loss");
00648     meEnergyLoss_141 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00649 
00650     sprintf (histo_n, "341_tof");
00651     sprintf (histo_t, "341_tof");
00652     meToF_341 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00653 
00654     
00655     
00656     sprintf (histo_n, "211__energy_loss");
00657     sprintf (histo_t, "211__energy_loss");
00658     meEnergyLoss_211 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00659 
00660     sprintf (histo_n, "411_tof");
00661     sprintf (histo_t, "411_tof");
00662     meToF_411 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00663 
00664     sprintf (histo_n, "212__energy_loss");
00665     sprintf (histo_t, "212__energy_loss");
00666     meEnergyLoss_212 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00667 
00668     sprintf (histo_n, "412_tof");
00669     sprintf (histo_t, "412_tof");
00670     meToF_412 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00671 
00672     sprintf (histo_n, "213__energy_loss");
00673     sprintf (histo_t, "213__energy_loss");
00674     meEnergyLoss_211 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00675 
00676     sprintf (histo_n, "413_tof");
00677     sprintf (histo_t, "413_tof");
00678     meToF_413 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00679 
00680     sprintf (histo_n, "214__energy_loss");
00681     sprintf (histo_t, "214__energy_loss");
00682     meEnergyLoss_214 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00683 
00684     sprintf (histo_n, "414_tof");
00685     sprintf (histo_t, "414_tof");
00686     meToF_414 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00687 
00688     sprintf (histo_n, "221__energy_loss");
00689     sprintf (histo_t, "221__energy_loss");
00690     meEnergyLoss_221 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00691 
00692     sprintf (histo_n, "421_tof");
00693     sprintf (histo_t, "421_tof");
00694     meToF_421 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00695 
00696     sprintf (histo_n, "222__energy_loss");
00697     sprintf (histo_t, "222__energy_loss");
00698     meEnergyLoss_222 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00699 
00700     sprintf (histo_n, "422_tof");
00701     sprintf (histo_t, "422_tof");
00702     meToF_422 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00703 
00704     sprintf (histo_n, "231__energy_loss");
00705     sprintf (histo_t, "231__energy_loss");
00706     meEnergyLoss_231 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00707 
00708     sprintf (histo_n, "431_tof");
00709     sprintf (histo_t, "431_tof");
00710     meToF_431 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00711 
00712     sprintf (histo_n, "232__energy_loss");
00713     sprintf (histo_t, "232__energy_loss");
00714     meEnergyLoss_232 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00715 
00716     sprintf (histo_n, "432_tof");
00717     sprintf (histo_t, "432_tof");
00718     meToF_432 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00719 
00720     sprintf (histo_n, "241__energy_loss");
00721     sprintf (histo_t, "241__energy_loss");
00722     meEnergyLoss_241 = dbeCSC_->book1D(histo_n, histo_t,50, 0.0, 50.0) ;
00723 
00724     sprintf (histo_n, "441_tof");
00725     sprintf (histo_t, "441_tof");
00726     meToF_441 = dbeCSC_->book1D(histo_n, histo_t, 60, 0.0, 60.0) ;
00727 
00728    }
00729 
00730 }
00731 
00732 void MuonSimHitsValidAnalyzer::saveHistos_DT()
00733 {
00734   int DTHistos;
00735 
00736   DTHistos = 1000;
00737   theDTFile->cd();
00738    
00739   if ( dbeDT_ ) {
00740     dbeDT_->setCurrentFolder("MuonDTHitsV/DTHitsValidationTask");
00741     //    cout << " DTFile.size " << DToutputFile_.size() << " dbeDT " << dbeDT_ << endl;
00742     dbeDT_->save(DToutputFile_);
00743   } 
00744 
00745 //  gDirectory->pwd();
00746 //  theDTFile->ls();
00747 // theDTFile->GetList()->ls();
00748 //  hmgr->save(DTHistos); 
00749 }
00750 
00751 void MuonSimHitsValidAnalyzer::saveHistos_RPC()
00752 {
00753   int RPCHistos;
00754   RPCHistos = 3000;
00755   theRPCFile->cd();
00756 
00757   if ( dbeRPC_ ) {
00758     dbeRPC_->setCurrentFolder("MuonRPCHitsV/RPCHitsValidationTask");
00759     //    cout << " RPCFile.size " << RPCoutputFile_.size() << " dbeRPC " << dbeRPC_ << endl;
00760     dbeRPC_->save(RPCoutputFile_);
00761   }
00762 
00763 
00764 
00765 
00766 //  gDirectory->pwd();
00767 //  theRPCFile->ls();
00768 //  theRPCFile->GetList()->ls();
00769 //  hmgr->save(RPCHistos);
00770 }
00771 
00772 void MuonSimHitsValidAnalyzer::saveHistos_CSC()
00773 {
00774   int CSCHistos;
00775   CSCHistos = 2000;
00776   theCSCFile->cd();
00777  
00778   if ( dbeCSC_ ) {
00779     dbeCSC_->setCurrentFolder("MuonCSCHitsV/CSCHitsValidationTask");
00780     //    cout << " CSCFile.size " << CSCoutputFile_.size() << " dbeCSC " << dbeCSC_ << endl;
00781     dbeCSC_->save(CSCoutputFile_);
00782   }
00783 
00784 
00785 
00786 //  gDirectory->pwd();
00787 //  theCSCFile->ls();
00788 //  theCSCFile->GetList()->ls();
00789 //     hmgr->save(CSCHistos);
00790 }
00791 
00792 void MuonSimHitsValidAnalyzer::endJob()
00793 {
00794 
00795  if ( DToutputFile_.size() != 0 ) {
00796   saveHistos_DT();
00797   LogInfo("OutputInfo") << " DT MuonHits histos already saved" ;
00798  } else {
00799     LogInfo("OutputInfo") << " DT MuonHits histos NOT saved";
00800   }
00801 
00802 
00803 
00804 //  saveHistos_CSC();
00805 //  saveHistos_RPC(); 
00806   if (verbosity > 0)
00807     edm::LogInfo ("MuonSimHitsValidAnalyzer::endJob") 
00808       << "Terminating having processed " << count << " events.";
00809   return;
00810 
00811 }
00812 
00813 void MuonSimHitsValidAnalyzer::analyze(const edm::Event& iEvent, 
00814                                const edm::EventSetup& iSetup)
00815 {
00817   ++count;
00818 
00820   int nrun = iEvent.id().run();
00821   int nevt = iEvent.id().event();
00822 
00823   if (verbosity > 0) {
00824     edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
00825       << "Processing run " << nrun << ", event " << nevt;
00826   }
00827 
00829   if (getAllProvenances) {
00830 
00831     std::vector<const edm::Provenance*> AllProv;
00832     iEvent.getAllProvenance(AllProv);
00833 
00834     if (verbosity > 0)
00835       edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
00836         << "Number of Provenances = " << AllProv.size();
00837 
00838     if (printProvenanceInfo && (verbosity > 0)) {
00839       TString eventout("\nProvenance info:\n");
00840       
00841       for (unsigned int i = 0; i < AllProv.size(); ++i) {
00842         eventout += "\n       ******************************";
00843         eventout += "\n       Module       : ";
00844         eventout += AllProv[i]->moduleLabel();
00845         eventout += "\n       ProductID    : ";
00846         eventout += AllProv[i]->productID().id();
00847         eventout += "\n       ClassName    : ";
00848         eventout += AllProv[i]->className();
00849         eventout += "\n       InstanceName : ";
00850         eventout += AllProv[i]->productInstanceName();
00851         eventout += "\n       BranchName   : ";
00852         eventout += AllProv[i]->branchName();
00853       }
00854       eventout += "       ******************************\n";
00855       edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << eventout << "\n";
00856     }
00857   }
00858  
00860 
00862 //    fillCSC(iEvent, iSetup);
00863     fillDT(iEvent, iSetup);
00864  //   fillRPC(iEvent, iSetup);
00865 
00866   if (verbosity > 0)
00867     edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
00868       << "Done gathering data from event.";
00869 
00870   return;
00871 }
00872 
00873 
00874 
00875 void MuonSimHitsValidAnalyzer::fillCSC(const edm::Event& iEvent, 
00876                                  const edm::EventSetup& iSetup)
00877 {
00878 
00879   TString eventout;
00880   if (verbosity > 0)
00881     eventout = "\nGathering CSC info:";  
00882 
00884   edm::PSimHitContainer::const_iterator itHit;
00885 
00888   edm::ESHandle<CSCGeometry> theCSCGeometry;
00889   iSetup.get<MuonGeometryRecord>().get(theCSCGeometry);
00890   if (!theCSCGeometry.isValid()) {
00891     edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00892       << "Unable to find MuonGeometryRecord for the CSCGeometry in event!";
00893     return;
00894   }
00895   const CSCGeometry& theCSCMuon(*theCSCGeometry);
00896 
00898   edm::Handle<edm::PSimHitContainer> MuonCSCContainer;
00899   iEvent.getByLabel(CSCHitsSrc_,MuonCSCContainer);
00900 //  iEvent.getByLabel("g4SimHits","MuonCSCHits",MuonCSCContainer);
00901   if (!MuonCSCContainer.isValid()) {
00902     edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00903       << "Unable to find MuonCSCHits in event!";
00904     return;
00905   }
00906 
00907   nummu_CSC =0;
00908   meAllCSCHits->Fill( MuonCSCContainer->size() );
00909 
00911   int i = 0, j = 0;
00912   for (itHit = MuonCSCContainer->begin(); itHit != MuonCSCContainer->end(); 
00913        ++itHit) {
00914     ++i;
00915 
00916 
00918     DetId theDetUnitId(itHit->detUnitId());
00919     int detector = theDetUnitId.det();
00920     int subdetector = theDetUnitId.subdetId();
00921 
00923     if ((detector == dMuon) && 
00924         (subdetector == sdMuonCSC)) {
00925 
00927       const GeomDetUnit *theDet = theCSCMuon.idToDetUnit(theDetUnitId);
00928     
00929       if (!theDet) {
00930         edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00931           << "Unable to get GeomDetUnit from theCSCMuon for hit " << i;
00932         continue;
00933       }
00934      
00935       ++j;
00936 
00938    //   const BoundPlane& bsurf = theDet->surface();
00939 
00941 
00942       if ( abs(itHit->particleType()) == 13 ) {
00943 
00944       nummu_CSC++;
00945 
00946  /* Comment out for the moment
00947       const CSCDetId& id=CSCDetId(itHit->detUnitId());
00948 
00949       int cscid=id.endcap()*100000 + id.station()*10000 +
00950                 id.ring()*1000     + id.chamber()*10 +id.layer(); 
00951 
00952       int iden = cscid/1000;
00953 
00954       hmgr->getHisto1(iden+2000)->Fill( itHit->energyLoss()*pow6 );
00955       hmgr->getHisto1(iden+2200)->Fill( itHit->tof() );
00956  */
00957       }
00958     } else {
00959       edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00960         << "MuonCsc PSimHit " << i 
00961         << " is expected to be (det,subdet) = (" 
00962         << dMuon << "," << sdMuonCSC
00963         << "); value returned is: ("
00964         << detector << "," << subdetector << ")";
00965       continue;
00966     } 
00967   } 
00968 
00969   if (verbosity > 1) {
00970     eventout += "\n          Number of CSC muon Hits collected:......... ";
00971     eventout += j;
00972   }  
00973 
00974    meMuCSCHits->Fill( (float) nummu_CSC );
00975 
00976   if (verbosity > 0)
00977     edm::LogInfo("MuonSimHitsValidAnalyzer::fillCSC") << eventout << "\n";
00978 
00979   return;
00980 }
00981 
00982 
00983 void MuonSimHitsValidAnalyzer::fillDT(const edm::Event& iEvent, 
00984                                  const edm::EventSetup& iSetup)
00985 {
00986  TString eventout;
00987   if (verbosity > 0)
00988     eventout = "\nGathering DT info:";  
00989 
00991   edm::PSimHitContainer::const_iterator itHit;
00992 
00995   edm::ESHandle<DTGeometry> theDTGeometry;
00996   iSetup.get<MuonGeometryRecord>().get(theDTGeometry);
00997   if (!theDTGeometry.isValid()) {
00998     edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
00999       << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
01000     return;
01001   }
01002   const DTGeometry& theDTMuon(*theDTGeometry);
01003 
01005   edm::Handle<edm::PSimHitContainer> MuonDTContainer;
01006   iEvent.getByLabel(DTHitsSrc_,MuonDTContainer);
01007 //  iEvent.getByLabel("g4SimHits","MuonDTHits",MuonDTContainer);
01008   if (!MuonDTContainer.isValid()) {
01009     edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
01010       << "Unable to find MuonDTHits in event!";
01011     return;
01012   }
01013 
01014   touch1 = 0;
01015   touch4 = 0;
01016   nummu_DT = 0 ;
01017 
01018   meAllDTHits->Fill( MuonDTContainer->size() );
01019 
01021   int i = 0, j = 0;
01022   for (itHit = MuonDTContainer->begin(); itHit != MuonDTContainer->end(); 
01023        ++itHit) {
01024 
01025     ++i;
01026 
01028     DetId theDetUnitId(itHit->detUnitId());
01029     int detector = theDetUnitId.det();
01030     int subdetector = theDetUnitId.subdetId();
01031 
01033     if ((detector == dMuon) && 
01034         (subdetector == sdMuonDT)) {
01035        
01037       const GeomDetUnit *theDet = theDTMuon.idToDetUnit(theDetUnitId);
01038     
01039       if (!theDet) {
01040         edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT") 
01041           << "Unable to get GeomDetUnit from theDTMuon for hit " << i;
01042         continue;
01043       }
01044      
01045       ++j;
01046 
01048       const BoundPlane& bsurf = theDet->surface();
01049     
01051 
01052       if ( abs(itHit->particleType()) == 13 ) {
01053 
01054        nummu_DT++;
01055        meToF->Fill( itHit->tof() );
01056        meEnergyLoss->Fill( itHit->energyLoss()*pow6 );     
01057 
01058        iden = itHit->detUnitId();
01059        
01060        wheel = ((iden>>15) & 0x7 ) -3  ;
01061        station = ((iden>>22) & 0x7 ) ;
01062        sector = ((iden>>18) & 0xf ) ;
01063        superlayer = ((iden>>13) & 0x3 ) ;
01064        layer = ((iden>>10) & 0x7 ) ;
01065        wire = ((iden>>3) & 0x7f ) ;
01066 
01067        meWheelOccup->Fill((float)wheel);
01068        meStationOccup->Fill((float) station);
01069        meSectorOccup->Fill((float) sector);
01070        meSuperLOccup->Fill((float) superlayer);
01071        meLayerOccup->Fill((float) layer);
01072        meWireOccup->Fill((float) wire);
01073 
01074    // Define a quantity to take into account station, splayer and layer being hit.
01075        path = (station-1) * 40 + superlayer * 10 + layer;
01076        mePathMuon->Fill((float) path); 
01077 
01078    // Define a quantity to take into chamber being hit.
01079        pathchamber = (wheel+2) * 50 + (station-1) * 12 + sector;
01080        meChamberOccup->Fill((float) pathchamber);
01081 
01083        if (station == 1 )
01084         {
01085          if (touch1 == 0)
01086          {
01087           mom1=itHit->pabs();  
01088           meMomentumMB1->Fill(mom1);
01089           touch1 = 1;
01090          }
01091         }
01092    
01094        if (station == 4 )
01095         {
01096          if ( touch4 == 0)
01097          {
01098           mom4=itHit->pabs();
01099           touch4 = 1;
01100           meMomentumMB4->Fill(mom4);
01101           if (touch1 == 1 )
01102           {
01103            meLossMomIron->Fill(mom1-mom4);
01104           }
01105          } 
01106         }
01107 
01109        meLocalXvsZ->Fill(itHit->localPosition().x(), itHit->localPosition().z() ); 
01110    
01112        meLocalXvsY->Fill(itHit->localPosition().x(), itHit->localPosition().y() );
01113 
01115        
01116       globposz =  bsurf.toGlobal(itHit->localPosition()).z();
01117       globposeta = bsurf.toGlobal(itHit->localPosition()).eta();
01118       globposphi = bsurf.toGlobal(itHit->localPosition()).phi(); 
01119 
01120       radius = globposz* ( 1.+ exp(-2.* globposeta) ) / ( 1. - exp(-2.* globposeta ) ) ; 
01121 
01122       costeta = ( 1. - exp(-2.*globposeta) ) /( 1. + exp(-2.* globposeta) ) ;
01123       sinteta = 2. * exp(-globposeta) /( 1. + exp(-2.*globposeta) );
01124 
01127       globposx = radius*sinteta*cos(globposphi); 
01128       globposy = radius*sinteta*sin(globposphi);
01129 
01130       meGlobalXvsZ->Fill(globposz, globposx);
01131       meGlobalXvsY->Fill(globposx, globposy); 
01132 
01133 //  New Histos
01134       if (wheel == -2) {
01135       meGlobalXvsZWm2->Fill(globposz, globposx);
01136       meGlobalXvsYWm2->Fill(globposx, globposy);
01137       }
01138       if (wheel == -1) {
01139       meGlobalXvsZWm1->Fill(globposz, globposx);
01140       meGlobalXvsYWm1->Fill(globposx, globposy);
01141       }
01142       if (wheel == 0) {
01143       meGlobalXvsZW0->Fill(globposz, globposx);
01144       meGlobalXvsYW0->Fill(globposx, globposy);
01145       }
01146       if (wheel == 1) {
01147       meGlobalXvsZWp1->Fill(globposz, globposx);
01148       meGlobalXvsYWp1->Fill(globposx, globposy);
01149       }
01150       if (wheel == 2) {
01151       meGlobalXvsZWp2->Fill(globposz, globposx);
01152       meGlobalXvsYWp2->Fill(globposx, globposy);
01153       }
01154 // 
01155       meHitRadius->Fill(radius);
01156       meCosTheta->Fill(costeta);
01157       meGlobalEta->Fill(globposeta);
01158       meGlobalPhi->Fill(globposphi);
01159 
01160       }
01161     } else {
01162       edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
01163         << "MuonDT PSimHit " << i 
01164         << " is expected to be (det,subdet) = (" 
01165         << dMuon << "," << sdMuonDT
01166         << "); value returned is: ("
01167         << detector << "," << subdetector << ")";
01168       continue;
01169     }
01170   }
01171 
01172   if (verbosity > 1) {
01173     eventout += "\n          Number of DT muon Hits collected:......... ";
01174     eventout += j;
01175   }  
01176   meMuDTHits->Fill( (float) nummu_DT );
01177    
01178   if (verbosity > 0)
01179     edm::LogInfo("MuonSimHitsValidAnalyzer::fillDT") << eventout << "\n";
01180 return;
01181 }
01182 
01183 
01184 void MuonSimHitsValidAnalyzer::fillRPC(const edm::Event& iEvent, 
01185                                  const edm::EventSetup& iSetup)
01186 {
01187   TString eventout;
01188   if (verbosity > 0)
01189     eventout = "\nGathering RPC info:";  
01190 
01192   edm::PSimHitContainer::const_iterator itHit;
01193 
01196   edm::ESHandle<RPCGeometry> theRPCGeometry;
01197   iSetup.get<MuonGeometryRecord>().get(theRPCGeometry);
01198   if (!theRPCGeometry.isValid()) {
01199     edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01200       << "Unable to find MuonGeometryRecord for the RPCGeometry in event!";
01201     return;
01202   }
01203   const RPCGeometry& theRPCMuon(*theRPCGeometry);
01204 
01205   // get Muon RPC information
01206   edm::Handle<edm::PSimHitContainer> MuonRPCContainer;
01207   iEvent.getByLabel(RPCHitsSrc_,MuonRPCContainer);
01208 //  iEvent.getByLabel("g4SimHits","MuonRPCHits",MuonRPCContainer);
01209   if (!MuonRPCContainer.isValid()) {
01210     edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01211       << "Unable to find MuonRPCHits in event!";
01212     return;
01213   }
01214 
01215   touch1 = 0;
01216   touch4 = 0;
01217   touche1 = 0;
01218   touche4 = 0; 
01219   nummu_RPC = 0 ;
01220 
01221   meAllRPCHits->Fill( MuonRPCContainer->size() );
01222 
01224   int i = 0, j = 0;
01225   for (itHit = MuonRPCContainer->begin(); itHit != MuonRPCContainer->end(); 
01226        ++itHit) {
01227 
01228     ++i;
01229 
01231     DetId theDetUnitId(itHit->detUnitId());
01232     int detector = theDetUnitId.det();
01233     int subdetector = theDetUnitId.subdetId();
01234 
01236     if ((detector == dMuon) && 
01237         (subdetector == sdMuonRPC)) {
01238 
01240       const GeomDetUnit *theDet = theRPCMuon.idToDetUnit(theDetUnitId);
01241     
01242       if (!theDet) {
01243         edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01244           << "Unable to get GeomDetUnit from theRPCMuon for hit " << i;
01245         continue;
01246       }
01247      
01248       ++j;
01249 
01251       const BoundPlane& bsurf = theDet->surface();
01252     
01254 
01255       if ( abs(itHit->particleType()) == 13 ) {
01256 
01257        nummu_RPC++;
01258 
01259        iden = itHit->detUnitId();
01260        
01261        region = ( ((iden>>0) & 0X3) -1 )  ;
01262        ring = ((iden>>2) & 0X7 ) ;
01263 
01264        if ( ring < 3 )
01265        {
01266         if ( region == 0 ) cout << "Region - Ring inconsistency" << endl;
01267         ring += 1 ;
01268        } else {
01269         ring -= 5 ;
01270        }
01271 
01272        station =  ( ((iden>>5) & 0X3) + 1 ) ;
01273        sector =  ( ((iden>>7) & 0XF) + 1 ) ;
01274        layer = ( ((iden>>11) & 0X1) + 1 ) ;
01275        subsector =  ( ((iden>>12) & 0X7) + 1 ) ;   //  ! Beware: mask says 0x7 !!
01276        roll =  ( (iden>>15) & 0X7)  ;
01277   
01278        meRegionOccup->Fill((float)region);                  // Region
01279        if (region == 0 )   // Barrel
01280         {  
01281           meRingOccBar->Fill((float) ring);  
01282           meStatOccBar->Fill((float) station); 
01283           meSectorOccBar->Fill((float) sector);
01284           meLayerOccBar->Fill((float) layer);
01285           meSubSectOccBar->Fill((float) subsector);
01286           meRollOccBar->Fill((float) roll);
01287 
01288           meElossBar->Fill(itHit->energyLoss()*pow6 );
01289         }
01290        if (region != 0 )   // Endcaps
01291         {
01292            meRingOccEndc->Fill((float)ring);
01293            meStatOccEndc->Fill((float) station);
01294            meSectorOccEndc->Fill((float) sector);
01295            meLayerOccEndc->Fill((float) layer);
01296            meSubSectOccEndc->Fill((float) subsector);
01297            meRollOccEndc->Fill((float) roll);  
01298 
01299            meElossEndc->Fill(itHit->energyLoss()*pow6 );
01300         } 
01301 
01302    // Define a quantity to take into account station, splayer and layer being hit.
01303         path = (region+1) * 50 + (ring+2) * 10 + (station -1) *2+ layer;
01304         if (region != 0) path -= 10 ;
01305         mepathRPC->Fill((float)path);
01306 
01308         if ( region == 0 )  //  BARREL
01309        {
01310          if (station == 1 && layer == 1 ) 
01311          {
01312           if (touch1 == 0)
01313           {
01314            mom1=itHit->pabs();
01315            meMomRB1->Fill(mom1);
01316            touch1 = 1;
01317           }
01318          }
01320 
01321          if (station == 4 )
01322          {
01323           if ( touch4 == 0)
01324           { 
01325            mom4=itHit->pabs();
01326            meMomRB4->Fill(mom4);
01327            touch4 = 1;
01329            if (touch1 == 1 )
01330             {
01331              meLossMomBar->Fill(mom1-mom4);
01332             }
01333           }
01334          }
01335        }  // End of Barrel 
01336 
01338         if ( region != 0 )  //  ENDCAPS
01339        {
01340          if (station == 1 )
01341          { 
01342           if (touche1 == 0)
01343           {
01344            mome1=itHit->pabs();
01345            meMomRE1->Fill(mome1);
01346            touche1 = 1;
01347           }
01348          }  
01350          if (station == 4 )
01351          {
01352           if ( touche4 == 0)
01353           {
01354            mome4=itHit->pabs();
01355            meMomRE4->Fill(mome4);
01356            touche4 = 1;
01358            if (touche1 == 1 )
01359             {
01360              meLossMomEndc->Fill(mome1-mome4); 
01361             } 
01362           }
01363          }
01364        }  // End of Endcaps 
01365 
01366   //  X-Local Coordinate vs Y-Local Coordinate
01367        meLocalXvsYBar->Fill(itHit->localPosition().x(), itHit->localPosition().y() );
01368 
01370        globposz =  bsurf.toGlobal(itHit->localPosition()).z();
01371        globposeta = bsurf.toGlobal(itHit->localPosition()).eta();
01372        globposphi = bsurf.toGlobal(itHit->localPosition()).phi();
01373 
01374        radius = globposz* ( 1.+ exp(-2.* globposeta) ) / ( 1. - exp(-2.* globposeta ) ) ;
01375        costeta = ( 1. - exp(-2.*globposeta) ) /( 1. + exp(-2.* globposeta) ) ;
01376        sinteta = 2. * exp(-globposeta) /( 1. + exp(-2.*globposeta) );
01377 
01378        globposx = radius*sinteta*cos(globposphi);
01379        globposy = radius*sinteta*sin(globposphi);
01380 
01381        if (region == 0 ) // Barrel 
01382         { 
01383          meHitRadiusBar->Fill(radius);
01384          meCosThetaBar->Fill(costeta);
01385          meGlobalXvsZBar->Fill(globposz, globposx);
01386          meGlobalXvsYBar->Fill(globposx, globposy);
01387         } 
01388        if (region != 0 ) // Endcaps
01389         {
01390          meHitRadiusEndc->Fill(radius); 
01391          meCosThetaEndc->Fill(costeta);
01392          meGlobalXvsZEndc->Fill(globposz, globposx);
01393          meGlobalXvsYEndc->Fill(globposx, globposy);
01394         }  
01395 
01396       }
01397     
01398     } else {
01399       edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01400         << "MuonRpc PSimHit " << i 
01401         << " is expected to be (det,subdet) = (" 
01402         << dMuon << "," << sdMuonRPC
01403         << "); value returned is: ("
01404         << detector << "," << subdetector << ")";
01405       continue;
01406     }
01407   }
01408 
01409   if (verbosity > 1) {
01410     eventout += "\n          Number of RPC muon Hits collected:......... ";
01411     eventout += j;
01412   }  
01413 
01414   meMuRPCHits->Fill( (float) nummu_RPC );
01415 
01416   if (verbosity > 0)
01417     edm::LogInfo("MuonSimHitsValidAnalyzer::fillRPC") << eventout << "\n";
01418 
01419 return;
01420 }
01421