CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/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   //DTHistos = 1000;
00736   theDTFile->cd();
00737    
00738   if ( dbeDT_ ) {
00739     dbeDT_->setCurrentFolder("MuonDTHitsV/DTHitsValidationTask");
00740     //    cout << " DTFile.size " << DToutputFile_.size() << " dbeDT " << dbeDT_ << endl;
00741     dbeDT_->save(DToutputFile_);
00742   } 
00743 
00744 //  gDirectory->pwd();
00745 //  theDTFile->ls();
00746 // theDTFile->GetList()->ls();
00747 //  hmgr->save(DTHistos); 
00748 }
00749 
00750 void MuonSimHitsValidAnalyzer::saveHistos_RPC()
00751 {
00752   //int RPCHistos;
00753   //RPCHistos = 3000;
00754   theRPCFile->cd();
00755 
00756   if ( dbeRPC_ ) {
00757     dbeRPC_->setCurrentFolder("MuonRPCHitsV/RPCHitsValidationTask");
00758     //    cout << " RPCFile.size " << RPCoutputFile_.size() << " dbeRPC " << dbeRPC_ << endl;
00759     dbeRPC_->save(RPCoutputFile_);
00760   }
00761 
00762 
00763 
00764 
00765 //  gDirectory->pwd();
00766 //  theRPCFile->ls();
00767 //  theRPCFile->GetList()->ls();
00768 //  hmgr->save(RPCHistos);
00769 }
00770 
00771 void MuonSimHitsValidAnalyzer::saveHistos_CSC()
00772 {
00773   //int CSCHistos;
00774   //CSCHistos = 2000;
00775   theCSCFile->cd();
00776  
00777   if ( dbeCSC_ ) {
00778     dbeCSC_->setCurrentFolder("MuonCSCHitsV/CSCHitsValidationTask");
00779     //    cout << " CSCFile.size " << CSCoutputFile_.size() << " dbeCSC " << dbeCSC_ << endl;
00780     dbeCSC_->save(CSCoutputFile_);
00781   }
00782 
00783 
00784 
00785 //  gDirectory->pwd();
00786 //  theCSCFile->ls();
00787 //  theCSCFile->GetList()->ls();
00788 //     hmgr->save(CSCHistos);
00789 }
00790 
00791 void MuonSimHitsValidAnalyzer::endJob()
00792 {
00793 
00794  if ( DToutputFile_.size() != 0 ) {
00795   saveHistos_DT();
00796   LogInfo("OutputInfo") << " DT MuonHits histos already saved" ;
00797  } else {
00798     LogInfo("OutputInfo") << " DT MuonHits histos NOT saved";
00799   }
00800 
00801 
00802 
00803 //  saveHistos_CSC();
00804 //  saveHistos_RPC(); 
00805   if (verbosity > 0)
00806     edm::LogInfo ("MuonSimHitsValidAnalyzer::endJob") 
00807       << "Terminating having processed " << count << " events.";
00808   return;
00809 
00810 }
00811 
00812 void MuonSimHitsValidAnalyzer::analyze(const edm::Event& iEvent, 
00813                                const edm::EventSetup& iSetup)
00814 {
00816   ++count;
00817 
00819   int nrun = iEvent.id().run();
00820   int nevt = iEvent.id().event();
00821 
00822   if (verbosity > 0) {
00823     edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
00824       << "Processing run " << nrun << ", event " << nevt;
00825   }
00826 
00828   if (getAllProvenances) {
00829 
00830     std::vector<const edm::Provenance*> AllProv;
00831     iEvent.getAllProvenance(AllProv);
00832 
00833     if (verbosity > 0)
00834       edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
00835         << "Number of Provenances = " << AllProv.size();
00836 
00837     if (printProvenanceInfo && (verbosity > 0)) {
00838       TString eventout("\nProvenance info:\n");
00839       
00840       for (unsigned int i = 0; i < AllProv.size(); ++i) {
00841         eventout += "\n       ******************************";
00842         eventout += "\n       Module       : ";
00843         eventout += AllProv[i]->moduleLabel();
00844         eventout += "\n       ProductID    : ";
00845         eventout += AllProv[i]->productID().id();
00846         eventout += "\n       ClassName    : ";
00847         eventout += AllProv[i]->className();
00848         eventout += "\n       InstanceName : ";
00849         eventout += AllProv[i]->productInstanceName();
00850         eventout += "\n       BranchName   : ";
00851         eventout += AllProv[i]->branchName();
00852       }
00853       eventout += "       ******************************\n";
00854       edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << eventout << "\n";
00855     }
00856   }
00857  
00859 
00861 //    fillCSC(iEvent, iSetup);
00862     fillDT(iEvent, iSetup);
00863  //   fillRPC(iEvent, iSetup);
00864 
00865   if (verbosity > 0)
00866     edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
00867       << "Done gathering data from event.";
00868 
00869   return;
00870 }
00871 
00872 
00873 
00874 void MuonSimHitsValidAnalyzer::fillCSC(const edm::Event& iEvent, 
00875                                  const edm::EventSetup& iSetup)
00876 {
00877 
00878   TString eventout;
00879   if (verbosity > 0)
00880     eventout = "\nGathering CSC info:";  
00881 
00883   edm::PSimHitContainer::const_iterator itHit;
00884 
00887   edm::ESHandle<CSCGeometry> theCSCGeometry;
00888   iSetup.get<MuonGeometryRecord>().get(theCSCGeometry);
00889   if (!theCSCGeometry.isValid()) {
00890     edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00891       << "Unable to find MuonGeometryRecord for the CSCGeometry in event!";
00892     return;
00893   }
00894   const CSCGeometry& theCSCMuon(*theCSCGeometry);
00895 
00897   edm::Handle<edm::PSimHitContainer> MuonCSCContainer;
00898   iEvent.getByLabel(CSCHitsSrc_,MuonCSCContainer);
00899 //  iEvent.getByLabel("g4SimHits","MuonCSCHits",MuonCSCContainer);
00900   if (!MuonCSCContainer.isValid()) {
00901     edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00902       << "Unable to find MuonCSCHits in event!";
00903     return;
00904   }
00905 
00906   nummu_CSC =0;
00907   meAllCSCHits->Fill( MuonCSCContainer->size() );
00908 
00910   int i = 0, j = 0;
00911   for (itHit = MuonCSCContainer->begin(); itHit != MuonCSCContainer->end(); 
00912        ++itHit) {
00913     ++i;
00914 
00915 
00917     DetId theDetUnitId(itHit->detUnitId());
00918     int detector = theDetUnitId.det();
00919     int subdetector = theDetUnitId.subdetId();
00920 
00922     if ((detector == dMuon) && 
00923         (subdetector == sdMuonCSC)) {
00924 
00926       const GeomDetUnit *theDet = theCSCMuon.idToDetUnit(theDetUnitId);
00927     
00928       if (!theDet) {
00929         edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00930           << "Unable to get GeomDetUnit from theCSCMuon for hit " << i;
00931         continue;
00932       }
00933      
00934       ++j;
00935 
00937    //   const BoundPlane& bsurf = theDet->surface();
00938 
00940 
00941       if ( abs(itHit->particleType()) == 13 ) {
00942 
00943       nummu_CSC++;
00944 
00945  /* Comment out for the moment
00946       const CSCDetId& id=CSCDetId(itHit->detUnitId());
00947 
00948       int cscid=id.endcap()*100000 + id.station()*10000 +
00949                 id.ring()*1000     + id.chamber()*10 +id.layer(); 
00950 
00951       int iden = cscid/1000;
00952 
00953       hmgr->getHisto1(iden+2000)->Fill( itHit->energyLoss()*pow6 );
00954       hmgr->getHisto1(iden+2200)->Fill( itHit->tof() );
00955  */
00956       }
00957     } else {
00958       edm::LogWarning("MuonSimHitsValidAnalyzer::fillCSC")
00959         << "MuonCsc PSimHit " << i 
00960         << " is expected to be (det,subdet) = (" 
00961         << dMuon << "," << sdMuonCSC
00962         << "); value returned is: ("
00963         << detector << "," << subdetector << ")";
00964       continue;
00965     } 
00966   } 
00967 
00968   if (verbosity > 1) {
00969     eventout += "\n          Number of CSC muon Hits collected:......... ";
00970     eventout += j;
00971   }  
00972 
00973    meMuCSCHits->Fill( (float) nummu_CSC );
00974 
00975   if (verbosity > 0)
00976     edm::LogInfo("MuonSimHitsValidAnalyzer::fillCSC") << eventout << "\n";
00977 
00978   return;
00979 }
00980 
00981 
00982 void MuonSimHitsValidAnalyzer::fillDT(const edm::Event& iEvent, 
00983                                  const edm::EventSetup& iSetup)
00984 {
00985  TString eventout;
00986   if (verbosity > 0)
00987     eventout = "\nGathering DT info:";  
00988 
00990   edm::PSimHitContainer::const_iterator itHit;
00991 
00994   edm::ESHandle<DTGeometry> theDTGeometry;
00995   iSetup.get<MuonGeometryRecord>().get(theDTGeometry);
00996   if (!theDTGeometry.isValid()) {
00997     edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
00998       << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
00999     return;
01000   }
01001   const DTGeometry& theDTMuon(*theDTGeometry);
01002 
01004   edm::Handle<edm::PSimHitContainer> MuonDTContainer;
01005   iEvent.getByLabel(DTHitsSrc_,MuonDTContainer);
01006 //  iEvent.getByLabel("g4SimHits","MuonDTHits",MuonDTContainer);
01007   if (!MuonDTContainer.isValid()) {
01008     edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
01009       << "Unable to find MuonDTHits in event!";
01010     return;
01011   }
01012 
01013   touch1 = 0;
01014   touch4 = 0;
01015   nummu_DT = 0 ;
01016 
01017   meAllDTHits->Fill( MuonDTContainer->size() );
01018 
01020   int i = 0, j = 0;
01021   for (itHit = MuonDTContainer->begin(); itHit != MuonDTContainer->end(); 
01022        ++itHit) {
01023 
01024     ++i;
01025 
01027     DetId theDetUnitId(itHit->detUnitId());
01028     int detector = theDetUnitId.det();
01029     int subdetector = theDetUnitId.subdetId();
01030 
01032     if ((detector == dMuon) && 
01033         (subdetector == sdMuonDT)) {
01034        
01036       const GeomDetUnit *theDet = theDTMuon.idToDetUnit(theDetUnitId);
01037     
01038       if (!theDet) {
01039         edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT") 
01040           << "Unable to get GeomDetUnit from theDTMuon for hit " << i;
01041         continue;
01042       }
01043      
01044       ++j;
01045 
01047       const BoundPlane& bsurf = theDet->surface();
01048     
01050 
01051       if ( abs(itHit->particleType()) == 13 ) {
01052 
01053        nummu_DT++;
01054        meToF->Fill( itHit->tof() );
01055        meEnergyLoss->Fill( itHit->energyLoss()*pow6 );     
01056 
01057        iden = itHit->detUnitId();
01058        
01059        wheel = ((iden>>15) & 0x7 ) -3  ;
01060        station = ((iden>>22) & 0x7 ) ;
01061        sector = ((iden>>18) & 0xf ) ;
01062        superlayer = ((iden>>13) & 0x3 ) ;
01063        layer = ((iden>>10) & 0x7 ) ;
01064        wire = ((iden>>3) & 0x7f ) ;
01065 
01066        meWheelOccup->Fill((float)wheel);
01067        meStationOccup->Fill((float) station);
01068        meSectorOccup->Fill((float) sector);
01069        meSuperLOccup->Fill((float) superlayer);
01070        meLayerOccup->Fill((float) layer);
01071        meWireOccup->Fill((float) wire);
01072 
01073    // Define a quantity to take into account station, splayer and layer being hit.
01074        path = (station-1) * 40 + superlayer * 10 + layer;
01075        mePathMuon->Fill((float) path); 
01076 
01077    // Define a quantity to take into chamber being hit.
01078        pathchamber = (wheel+2) * 50 + (station-1) * 12 + sector;
01079        meChamberOccup->Fill((float) pathchamber);
01080 
01082        if (station == 1 )
01083         {
01084          if (touch1 == 0)
01085          {
01086           mom1=itHit->pabs();  
01087           meMomentumMB1->Fill(mom1);
01088           touch1 = 1;
01089          }
01090         }
01091    
01093        if (station == 4 )
01094         {
01095          if ( touch4 == 0)
01096          {
01097           mom4=itHit->pabs();
01098           touch4 = 1;
01099           meMomentumMB4->Fill(mom4);
01100           if (touch1 == 1 )
01101           {
01102            meLossMomIron->Fill(mom1-mom4);
01103           }
01104          } 
01105         }
01106 
01108        meLocalXvsZ->Fill(itHit->localPosition().x(), itHit->localPosition().z() ); 
01109    
01111        meLocalXvsY->Fill(itHit->localPosition().x(), itHit->localPosition().y() );
01112 
01114        
01115       globposz =  bsurf.toGlobal(itHit->localPosition()).z();
01116       globposeta = bsurf.toGlobal(itHit->localPosition()).eta();
01117       globposphi = bsurf.toGlobal(itHit->localPosition()).phi(); 
01118 
01119       radius = globposz* ( 1.+ exp(-2.* globposeta) ) / ( 1. - exp(-2.* globposeta ) ) ; 
01120 
01121       costeta = ( 1. - exp(-2.*globposeta) ) /( 1. + exp(-2.* globposeta) ) ;
01122       sinteta = 2. * exp(-globposeta) /( 1. + exp(-2.*globposeta) );
01123 
01126       globposx = radius*sinteta*cos(globposphi); 
01127       globposy = radius*sinteta*sin(globposphi);
01128 
01129       meGlobalXvsZ->Fill(globposz, globposx);
01130       meGlobalXvsY->Fill(globposx, globposy); 
01131 
01132 //  New Histos
01133       if (wheel == -2) {
01134       meGlobalXvsZWm2->Fill(globposz, globposx);
01135       meGlobalXvsYWm2->Fill(globposx, globposy);
01136       }
01137       if (wheel == -1) {
01138       meGlobalXvsZWm1->Fill(globposz, globposx);
01139       meGlobalXvsYWm1->Fill(globposx, globposy);
01140       }
01141       if (wheel == 0) {
01142       meGlobalXvsZW0->Fill(globposz, globposx);
01143       meGlobalXvsYW0->Fill(globposx, globposy);
01144       }
01145       if (wheel == 1) {
01146       meGlobalXvsZWp1->Fill(globposz, globposx);
01147       meGlobalXvsYWp1->Fill(globposx, globposy);
01148       }
01149       if (wheel == 2) {
01150       meGlobalXvsZWp2->Fill(globposz, globposx);
01151       meGlobalXvsYWp2->Fill(globposx, globposy);
01152       }
01153 // 
01154       meHitRadius->Fill(radius);
01155       meCosTheta->Fill(costeta);
01156       meGlobalEta->Fill(globposeta);
01157       meGlobalPhi->Fill(globposphi);
01158 
01159       }
01160     } else {
01161       edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
01162         << "MuonDT PSimHit " << i 
01163         << " is expected to be (det,subdet) = (" 
01164         << dMuon << "," << sdMuonDT
01165         << "); value returned is: ("
01166         << detector << "," << subdetector << ")";
01167       continue;
01168     }
01169   }
01170 
01171   if (verbosity > 1) {
01172     eventout += "\n          Number of DT muon Hits collected:......... ";
01173     eventout += j;
01174   }  
01175   meMuDTHits->Fill( (float) nummu_DT );
01176    
01177   if (verbosity > 0)
01178     edm::LogInfo("MuonSimHitsValidAnalyzer::fillDT") << eventout << "\n";
01179 return;
01180 }
01181 
01182 
01183 void MuonSimHitsValidAnalyzer::fillRPC(const edm::Event& iEvent, 
01184                                  const edm::EventSetup& iSetup)
01185 {
01186   TString eventout;
01187   if (verbosity > 0)
01188     eventout = "\nGathering RPC info:";  
01189 
01191   edm::PSimHitContainer::const_iterator itHit;
01192 
01195   edm::ESHandle<RPCGeometry> theRPCGeometry;
01196   iSetup.get<MuonGeometryRecord>().get(theRPCGeometry);
01197   if (!theRPCGeometry.isValid()) {
01198     edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01199       << "Unable to find MuonGeometryRecord for the RPCGeometry in event!";
01200     return;
01201   }
01202   const RPCGeometry& theRPCMuon(*theRPCGeometry);
01203 
01204   // get Muon RPC information
01205   edm::Handle<edm::PSimHitContainer> MuonRPCContainer;
01206   iEvent.getByLabel(RPCHitsSrc_,MuonRPCContainer);
01207 //  iEvent.getByLabel("g4SimHits","MuonRPCHits",MuonRPCContainer);
01208   if (!MuonRPCContainer.isValid()) {
01209     edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01210       << "Unable to find MuonRPCHits in event!";
01211     return;
01212   }
01213 
01214   touch1 = 0;
01215   touch4 = 0;
01216   touche1 = 0;
01217   touche4 = 0; 
01218   nummu_RPC = 0 ;
01219 
01220   meAllRPCHits->Fill( MuonRPCContainer->size() );
01221 
01223   int i = 0, j = 0;
01224   for (itHit = MuonRPCContainer->begin(); itHit != MuonRPCContainer->end(); 
01225        ++itHit) {
01226 
01227     ++i;
01228 
01230     DetId theDetUnitId(itHit->detUnitId());
01231     int detector = theDetUnitId.det();
01232     int subdetector = theDetUnitId.subdetId();
01233 
01235     if ((detector == dMuon) && 
01236         (subdetector == sdMuonRPC)) {
01237 
01239       const GeomDetUnit *theDet = theRPCMuon.idToDetUnit(theDetUnitId);
01240     
01241       if (!theDet) {
01242         edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01243           << "Unable to get GeomDetUnit from theRPCMuon for hit " << i;
01244         continue;
01245       }
01246      
01247       ++j;
01248 
01250       const BoundPlane& bsurf = theDet->surface();
01251     
01253 
01254       if ( abs(itHit->particleType()) == 13 ) {
01255 
01256        nummu_RPC++;
01257 
01258        iden = itHit->detUnitId();
01259        
01260        region = ( ((iden>>0) & 0X3) -1 )  ;
01261        ring = ((iden>>2) & 0X7 ) ;
01262 
01263        if ( ring < 3 )
01264        {
01265         if ( region == 0 ) cout << "Region - Ring inconsistency" << endl;
01266         ring += 1 ;
01267        } else {
01268         ring -= 5 ;
01269        }
01270 
01271        station =  ( ((iden>>5) & 0X3) + 1 ) ;
01272        sector =  ( ((iden>>7) & 0XF) + 1 ) ;
01273        layer = ( ((iden>>11) & 0X1) + 1 ) ;
01274        subsector =  ( ((iden>>12) & 0X7) + 1 ) ;   //  ! Beware: mask says 0x7 !!
01275        roll =  ( (iden>>15) & 0X7)  ;
01276   
01277        meRegionOccup->Fill((float)region);                  // Region
01278        if (region == 0 )   // Barrel
01279         {  
01280           meRingOccBar->Fill((float) ring);  
01281           meStatOccBar->Fill((float) station); 
01282           meSectorOccBar->Fill((float) sector);
01283           meLayerOccBar->Fill((float) layer);
01284           meSubSectOccBar->Fill((float) subsector);
01285           meRollOccBar->Fill((float) roll);
01286 
01287           meElossBar->Fill(itHit->energyLoss()*pow6 );
01288         }
01289        if (region != 0 )   // Endcaps
01290         {
01291            meRingOccEndc->Fill((float)ring);
01292            meStatOccEndc->Fill((float) station);
01293            meSectorOccEndc->Fill((float) sector);
01294            meLayerOccEndc->Fill((float) layer);
01295            meSubSectOccEndc->Fill((float) subsector);
01296            meRollOccEndc->Fill((float) roll);  
01297 
01298            meElossEndc->Fill(itHit->energyLoss()*pow6 );
01299         } 
01300 
01301    // Define a quantity to take into account station, splayer and layer being hit.
01302         path = (region+1) * 50 + (ring+2) * 10 + (station -1) *2+ layer;
01303         if (region != 0) path -= 10 ;
01304         mepathRPC->Fill((float)path);
01305 
01307         if ( region == 0 )  //  BARREL
01308        {
01309          if (station == 1 && layer == 1 ) 
01310          {
01311           if (touch1 == 0)
01312           {
01313            mom1=itHit->pabs();
01314            meMomRB1->Fill(mom1);
01315            touch1 = 1;
01316           }
01317          }
01319 
01320          if (station == 4 )
01321          {
01322           if ( touch4 == 0)
01323           { 
01324            mom4=itHit->pabs();
01325            meMomRB4->Fill(mom4);
01326            touch4 = 1;
01328            if (touch1 == 1 )
01329             {
01330              meLossMomBar->Fill(mom1-mom4);
01331             }
01332           }
01333          }
01334        }  // End of Barrel 
01335 
01337         if ( region != 0 )  //  ENDCAPS
01338        {
01339          if (station == 1 )
01340          { 
01341           if (touche1 == 0)
01342           {
01343            mome1=itHit->pabs();
01344            meMomRE1->Fill(mome1);
01345            touche1 = 1;
01346           }
01347          }  
01349          if (station == 4 )
01350          {
01351           if ( touche4 == 0)
01352           {
01353            mome4=itHit->pabs();
01354            meMomRE4->Fill(mome4);
01355            touche4 = 1;
01357            if (touche1 == 1 )
01358             {
01359              meLossMomEndc->Fill(mome1-mome4); 
01360             } 
01361           }
01362          }
01363        }  // End of Endcaps 
01364 
01365   //  X-Local Coordinate vs Y-Local Coordinate
01366        meLocalXvsYBar->Fill(itHit->localPosition().x(), itHit->localPosition().y() );
01367 
01369        globposz =  bsurf.toGlobal(itHit->localPosition()).z();
01370        globposeta = bsurf.toGlobal(itHit->localPosition()).eta();
01371        globposphi = bsurf.toGlobal(itHit->localPosition()).phi();
01372 
01373        radius = globposz* ( 1.+ exp(-2.* globposeta) ) / ( 1. - exp(-2.* globposeta ) ) ;
01374        costeta = ( 1. - exp(-2.*globposeta) ) /( 1. + exp(-2.* globposeta) ) ;
01375        sinteta = 2. * exp(-globposeta) /( 1. + exp(-2.*globposeta) );
01376 
01377        globposx = radius*sinteta*cos(globposphi);
01378        globposy = radius*sinteta*sin(globposphi);
01379 
01380        if (region == 0 ) // Barrel 
01381         { 
01382          meHitRadiusBar->Fill(radius);
01383          meCosThetaBar->Fill(costeta);
01384          meGlobalXvsZBar->Fill(globposz, globposx);
01385          meGlobalXvsYBar->Fill(globposx, globposy);
01386         } 
01387        if (region != 0 ) // Endcaps
01388         {
01389          meHitRadiusEndc->Fill(radius); 
01390          meCosThetaEndc->Fill(costeta);
01391          meGlobalXvsZEndc->Fill(globposz, globposx);
01392          meGlobalXvsYEndc->Fill(globposx, globposy);
01393         }  
01394 
01395       }
01396     
01397     } else {
01398       edm::LogWarning("MuonSimHitsValidAnalyzer::fillRPC")
01399         << "MuonRpc PSimHit " << i 
01400         << " is expected to be (det,subdet) = (" 
01401         << dMuon << "," << sdMuonRPC
01402         << "); value returned is: ("
01403         << detector << "," << subdetector << ")";
01404       continue;
01405     }
01406   }
01407 
01408   if (verbosity > 1) {
01409     eventout += "\n          Number of RPC muon Hits collected:......... ";
01410     eventout += j;
01411   }  
01412 
01413   meMuRPCHits->Fill( (float) nummu_RPC );
01414 
01415   if (verbosity > 0)
01416     edm::LogInfo("MuonSimHitsValidAnalyzer::fillRPC") << eventout << "\n";
01417 
01418 return;
01419 }
01420