CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Validation/MuonDTDigis/src/MuonDTDigis.cc

Go to the documentation of this file.
00001 
00009 #include "MuonDTDigis.h"
00010 
00011 #include <iostream>
00012 #include <string>
00013 
00014 #include "TFile.h"
00015 
00016 #include "SimMuon/DTDigitizer/test/Histograms.h"
00017 
00018 using namespace edm;
00019 using namespace std;
00020 
00021 MuonDTDigis::MuonDTDigis(const ParameterSet& pset){
00022   
00023   // ---------------------- 
00024   // Get the debug parameter for verbose output
00025   verbose_ = pset.getUntrackedParameter<bool>("verbose",false);
00026 
00027   // the name of the Digi collection
00028   SimHitLabel = pset.getUntrackedParameter<string>("SimHitLabel");  
00029 
00030   // the name of the Digi collection
00031   DigiLabel = pset.getUntrackedParameter<string>("DigiLabel");  
00032 
00033   // ---------------------- 
00034   // DQM ROOT output 
00035   outputFile_ =  pset.getUntrackedParameter<std::string>("outputFile", ""); 
00036   if ( outputFile_.size() != 0 ) {
00037     LogInfo("OutputInfo") << " DT Muon Digis Task histograms will be saved to '" << outputFile_.c_str() << "'";
00038   } else {
00039     LogInfo("OutputInfo") << " DT Muon Digis Task histograms will NOT be saved";
00040   }
00041 
00042   string::size_type loc = outputFile_.find( ".root", 0 );
00043   std::string outputFile_more_plots_;
00044   if( loc != string::npos ) {
00045     outputFile_more_plots_ = outputFile_.substr(0,loc)+"_more_plots.root";
00046   } else {
00047     outputFile_more_plots_ = " DTDigis_more_plots.root";
00048   }
00049 
00050  //    Please, uncomment next lines if you want a secong root file with additional histos
00051  
00052 //  file_more_plots = new TFile(outputFile_more_plots_.c_str(),"RECREATE");
00053 //  file_more_plots->cd();
00054 //  if(file_more_plots->IsOpen()) cout<<"File for additional plots: " << outputFile_more_plots_ << "  open!"<<endl;
00055 //  else cout<<"*** Error in opening file for additional plots ***"<<endl;
00056 
00057  hDigis_global = new hDigis("Global");
00058  hDigis_W0 = new hDigis("Wheel0");
00059  hDigis_W1 = new hDigis("Wheel1");
00060  hDigis_W2 = new hDigis("Wheel2");
00061  hAllHits = new hHits("AllHits");
00062 
00063 // End of comment . See more in Destructor (~MuonDTDigis) method
00064 
00065   
00066 
00067   // ----------------------                 
00068   // get hold of back-end interface 
00069   dbe_ = 0;
00070   dbe_ = Service<DQMStore>().operator->();
00071   if ( dbe_ ) {
00072     if ( verbose_ ) {
00073       dbe_->setVerbose(1);
00074     } else {
00075       dbe_->setVerbose(0);
00076     }
00077   }
00078   if ( dbe_ ) {
00079     if ( verbose_ ) dbe_->showDirStructure();
00080   }
00081 
00082   // ----------------------                 
00083   
00084   meDigiTimeBox_          = 0;
00085   meDigiTimeBox_wheel2m_  = 0;
00086   meDigiTimeBox_wheel1m_  = 0;
00087   meDigiTimeBox_wheel0_   = 0;
00088   meDigiTimeBox_wheel1p_  = 0;
00089   meDigiTimeBox_wheel2p_  = 0;
00090   meDigiEfficiency_       = 0;
00091   meDigiEfficiencyMu_     = 0;
00092   meDoubleDigi_           = 0;
00093   meSimvsDigi_            = 0;
00094   meWire_DoubleDigi_      = 0;
00095 
00096   meMB1_sim_occup_        = 0;
00097   meMB1_digi_occup_       = 0;
00098   meMB2_sim_occup_        = 0;
00099   meMB2_digi_occup_       = 0;
00100   meMB3_sim_occup_        = 0;
00101   meMB3_digi_occup_       = 0;
00102   meMB4_sim_occup_        = 0;
00103   meMB4_digi_occup_       = 0;
00104 
00105 //meDigiTimeBox_SL_       = 0;
00106   meDigiHisto_            = 0;
00107 
00108 
00109   // ----------------------                 
00110   // We go 
00111   // ---------------------- 
00112 
00113   Char_t histo_n[100];
00114   Char_t histo_t[100];
00115 
00116   if ( dbe_ ) {
00117     dbe_->setCurrentFolder("MuonDTDigisV/DTDigiValidationTask");
00118 
00119     sprintf (histo_n, "DigiTimeBox" );
00120     sprintf (histo_t, "Digi Time Box" );
00121     meDigiTimeBox_ = dbe_->book1D(histo_n, histo_t, 1536,0,1200);
00122 
00123     sprintf (histo_n, "DigiTimeBox_wheel2m" );
00124     sprintf (histo_t, "Digi Time Box wheel -2" );
00125     meDigiTimeBox_wheel2m_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
00126 
00127     sprintf (histo_n, "DigiTimeBox_wheel1m" );
00128     sprintf (histo_t, "Digi Time Box wheel -1" );
00129     meDigiTimeBox_wheel1m_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
00130 
00131     sprintf (histo_n, "DigiTimeBox_wheel0" );
00132     sprintf (histo_t, "Digi Time Box wheel 0" );
00133     meDigiTimeBox_wheel0_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
00134 
00135     sprintf (histo_n, "DigiTimeBox_wheel1p" );
00136     sprintf (histo_t, "Digi Time Box wheel 1" );
00137     meDigiTimeBox_wheel1p_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
00138 
00139     sprintf (histo_n, "DigiTimeBox_wheel2p" );
00140     sprintf (histo_t, "Digi Time Box wheel 2" );
00141     meDigiTimeBox_wheel2p_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
00142 
00143     sprintf (histo_n, "DigiEfficiencyMu" );
00144     sprintf (histo_t, "Ratio (#Digis Mu)/(#SimHits Mu)" );
00145     meDigiEfficiencyMu_ = dbe_->book1D(histo_n, histo_t, 100, 0., 5.);
00146 
00147     sprintf (histo_n, "DigiEfficiency" );
00148     sprintf (histo_t, "Ratio (#Digis)/(#SimHits)" );
00149     meDigiEfficiency_ = dbe_->book1D(histo_n, histo_t, 100, 0., 5.); 
00150 
00151     sprintf (histo_n, "Number_Digi_per_layer" );
00152     sprintf (histo_t, "Number_Digi_per_layer" );
00153     meDoubleDigi_ = dbe_->book1D(histo_n, histo_t, 10,0.,10.);  
00154 
00155     sprintf (histo_n, "Number_simhit_vs_digi" );
00156     sprintf (histo_t, "Number_simhit_vs_digi" );
00157     meSimvsDigi_ = dbe_->book2D(histo_n, histo_t, 100, 0., 140., 100, 0., 140.);
00158 
00159     sprintf (histo_n, "Wire_Number_with_double_Digi" );
00160     sprintf (histo_t, "Wire_Number_with_double_Digi" );
00161     meWire_DoubleDigi_ = dbe_->book1D(histo_n, histo_t, 100,0.,100.);
00162 
00163     sprintf (histo_n, "Simhit_occupancy_MB1" );
00164     sprintf (histo_t, "Simhit_occupancy_MB1" );
00165     meMB1_sim_occup_ = dbe_->book1D(histo_n, histo_t, 55, 0., 55. );
00166 
00167     sprintf (histo_n, "Digi_occupancy_MB1" );
00168     sprintf (histo_t, "Digi_occupancy_MB1" );
00169     meMB1_digi_occup_ = dbe_->book1D(histo_n, histo_t, 55, 0., 55. );
00170 
00171     sprintf (histo_n, "Simhit_occupancy_MB2" );
00172     sprintf (histo_t, "Simhit_occupancy_MB2" );
00173     meMB2_sim_occup_ = dbe_->book1D(histo_n, histo_t, 63, 0., 63. );
00174 
00175     sprintf (histo_n, "Digi_occupancy_MB2" );
00176     sprintf (histo_t, "Digi_occupancy_MB2" );
00177     meMB2_digi_occup_ = dbe_->book1D(histo_n, histo_t, 63, 0., 63. );
00178 
00179     sprintf (histo_n, "Simhit_occupancy_MB3" );
00180     sprintf (histo_t, "Simhit_occupancy_MB3" );
00181     meMB3_sim_occup_ = dbe_->book1D(histo_n, histo_t, 75, 0., 75. );
00182 
00183     sprintf (histo_n, "Digi_occupancy_MB3" );
00184     sprintf (histo_t, "Digi_occupancy_MB3" );
00185     meMB3_digi_occup_ = dbe_->book1D(histo_n, histo_t, 75, 0., 75. );
00186 
00187     sprintf (histo_n, "Simhit_occupancy_MB4" );
00188     sprintf (histo_t, "Simhit_occupancy_MB4" );
00189     meMB4_sim_occup_ = dbe_->book1D(histo_n, histo_t, 99, 0., 99. );
00190 
00191     sprintf (histo_n, "Digi_occupancy_MB4" );
00192     sprintf (histo_t, "Digi_occupancy_MB4" );
00193     meMB4_digi_occup_ = dbe_->book1D(histo_n, histo_t, 99, 0., 99. );
00194 
00195 //    sprintf (histo_n, "" );
00196 //    sprintf (histo_t, "" );
00197 
00198 /*
00199 //  Other option
00200     string histoTag = "DigiTimeBox_slid_";
00201     for ( int wheel = -2; wheel <= +2; ++wheel ) { 
00202       for ( int station = 1; station <= 4; ++station )  {
00203         for ( int superLayer = 1; superLayer <= 3; ++superLayer ) {
00204           string histoName = histoTag 
00205                            + "_W" + wheel.str() 
00206                            + "_St" + station.str() 
00207                            + "_SL" + superLayer.str(); 
00208   // the booking is not yet done
00209         }
00210       }
00211     }
00212 */
00213   // Begona's option
00214     char stringcham[40];
00215       for ( int slnum = 1; slnum < 62; ++slnum ) {
00216         sprintf(stringcham, "DigiTimeBox_slid_%d", slnum) ;
00217         meDigiHisto_ =  dbe_->book1D(stringcham, stringcham, 100,0,1200);
00218         meDigiTimeBox_SL_.push_back(meDigiHisto_);
00219       }
00220   }
00221 
00222 }
00223 
00224 MuonDTDigis::~MuonDTDigis(){
00225 
00226 // Uncomment these next lines if you want additional plots in a second .root file
00227    
00228 //  file_more_plots->cd();
00229  
00230 // hDigis_global->Write();
00231 
00232 //  hDigis_W0->Write();
00233 //  hDigis_W1->Write();
00234 //  hDigis_W2->Write();
00235 //  hAllHits->Write();
00236 
00237 //  file_more_plots->Close();
00238 
00239 // End of comment.
00240 
00241   if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_); 
00242 
00243   if(verbose_)
00244     cout << "[MuonDTDigis] Destructor called" << endl;
00245 
00246 }
00247 
00248 //void  MuonDTDigis::endJob(void){
00249 
00250 //}
00251 
00252 void  MuonDTDigis::analyze(const Event & event, const EventSetup& eventSetup){
00253 
00254   if(verbose_)
00255     cout << "--- [MuonDTDigis] Analysing Event: #Run: " << event.id().run()
00256          << " #Event: " << event.id().event() << endl;
00257 
00258   // Get the DT Geometry 
00259   ESHandle<DTGeometry> muonGeom;
00260   eventSetup.get<MuonGeometryRecord>().get(muonGeom);
00261 
00262   // Get the Digi collection from the event
00263   Handle<DTDigiCollection> dtDigis;
00264   event.getByLabel(DigiLabel, dtDigis);
00265    
00266   // Get simhits
00267   Handle<PSimHitContainer> simHits; 
00268   event.getByLabel(SimHitLabel,"MuonDTHits",simHits);    
00269 
00270 //   For the PSimHit part generated by G4, for the 'simevent.root' type files
00271 //     event.getByLabel("SimG4Object","MuonDTHits",simHits);
00272 
00273 
00274   int num_mudigis;
00275   int num_musimhits;
00276   int num_digis;
00277   int num_digis_layer;
00278   int cham_num ;
00279   int wire_touched; 
00280   num_digis = 0;
00281   num_mudigis = 0;
00282   num_musimhits = 0;
00283   DTWireIdMap wireMap;     
00284  
00285   for(vector<PSimHit>::const_iterator hit = simHits->begin();
00286       hit != simHits->end(); hit++){    
00287     // Create the id of the wire, the simHits in the DT known also the wireId
00288      DTWireId wireId(hit->detUnitId());
00289  //   cout << " PSimHits wire id " << wireId << " part type " << hit->particleType() << endl;
00290 
00291     // Fill the map
00292     wireMap[wireId].push_back(&(*hit));
00293 
00294     LocalPoint entryP = hit->entryPoint();
00295     LocalPoint exitP = hit->exitPoint();
00296     int partType = hit->particleType();
00297     if ( abs(partType) == 13 ) num_musimhits++;    
00298   
00299     if ( wireId.station() == 1 && abs(partType) == 13 ) meMB1_sim_occup_->Fill(wireId.wire());
00300     if ( wireId.station() == 2 && abs(partType) == 13 ) meMB2_sim_occup_->Fill(wireId.wire());
00301     if ( wireId.station() == 3 && abs(partType) == 13 ) meMB3_sim_occup_->Fill(wireId.wire());
00302     if ( wireId.station() == 4 && abs(partType) == 13 ) meMB4_sim_occup_->Fill(wireId.wire());
00303 
00304 
00305     float path = (exitP-entryP).mag();
00306     float path_x = fabs((exitP-entryP).x());
00307 
00308     hAllHits->Fill(entryP.x(),exitP.x(),
00309                    entryP.y(),exitP.y(),
00310                    entryP.z(),exitP.z(),
00311                    path , path_x, 
00312                    partType, hit->processType(),
00313                   hit->pabs());
00314 
00315   }
00316    
00317  //  cout << "num muon simhits " << num_musimhits << endl;
00318  
00319   DTDigiCollection::DigiRangeIterator detUnitIt;
00320   for (detUnitIt=dtDigis->begin();
00321        detUnitIt!=dtDigis->end();
00322        ++detUnitIt){
00323     
00324     const DTLayerId& id = (*detUnitIt).first;
00325     const DTDigiCollection::Range& range = (*detUnitIt).second;
00326     
00327     num_digis_layer = 0 ;  
00328     cham_num = 0 ;
00329     wire_touched = 0;
00330 
00331    // Loop over the digis of this DetUnit
00332     for (DTDigiCollection::const_iterator digiIt = range.first;
00333          digiIt!=range.second;
00334          ++digiIt){
00335   //   cout<<" Wire: "<<(*digiIt).wire()<<endl
00336   //  <<" digi time (ns): "<<(*digiIt).time()<<endl;
00337       
00338       num_digis++;
00339       num_digis_layer++;
00340       if (num_digis_layer > 1 )
00341       {
00342        if ( (*digiIt).wire() == wire_touched )
00343         {
00344           meWire_DoubleDigi_->Fill((*digiIt).wire());
00345     //      cout << "old & new wire " << wire_touched << " " << (*digiIt).wire() << endl; 
00346         }
00347       }
00348       wire_touched = (*digiIt).wire();   
00349  
00350       meDigiTimeBox_->Fill((*digiIt).time());
00351       if (id.wheel() == -2 ) meDigiTimeBox_wheel2m_->Fill((*digiIt).time());      
00352       if (id.wheel() == -1 ) meDigiTimeBox_wheel1m_->Fill((*digiIt).time());
00353       if (id.wheel() == 0 )  meDigiTimeBox_wheel0_ ->Fill((*digiIt).time());
00354       if (id.wheel() == 1 )  meDigiTimeBox_wheel1p_->Fill((*digiIt).time());
00355       if (id.wheel() == 2 )  meDigiTimeBox_wheel2p_->Fill((*digiIt).time());
00356   
00357    //   Superlayer number and fill histo with digi timebox
00358  
00359       cham_num = (id.wheel() +2)*12 + (id.station() -1)*3 + id.superlayer();
00360    //   cout << " Histo number " << cham_num << endl;
00361 
00362       meDigiTimeBox_SL_[cham_num]->Fill((*digiIt).time());
00363 
00364  //    cout << " size de digis " << (*digiIt).size() << endl;
00365       
00366       DTWireId wireId(id,(*digiIt).wire());
00367       if (wireId.station() == 1 ) meMB1_digi_occup_->Fill((*digiIt).wire());
00368       if (wireId.station() == 2 ) meMB2_digi_occup_->Fill((*digiIt).wire());
00369       if (wireId.station() == 3 ) meMB3_digi_occup_->Fill((*digiIt).wire());
00370       if (wireId.station() == 4 ) meMB4_digi_occup_->Fill((*digiIt).wire());
00371 
00372       int mu=0;
00373       float theta = 0;
00374       
00375       for(vector<const PSimHit*>::iterator hit = wireMap[wireId].begin();
00376           hit != wireMap[wireId].end(); hit++)
00377         if( abs((*hit)->particleType()) == 13){
00378           theta = atan( (*hit)->momentumAtEntry().x()/ (-(*hit)->momentumAtEntry().z()) )*180/M_PI;
00379     //    cout<<"momentum x: "<<(*hit)->momentumAtEntry().x()<<endl
00380     //        <<"momentum z: "<<(*hit)->momentumAtEntry().z()<<endl
00381     //        <<"atan: "<<theta<<endl;
00382           mu++;
00383         }
00384      
00385      if( mu ) num_mudigis++;  
00386   
00387      if(mu && theta){
00388         hDigis_global->Fill((*digiIt).time(),theta,id.superlayer());
00389         //filling digi histos for wheel and for RZ and RPhi
00390         WheelHistos(id.wheel())->Fill((*digiIt).time(),theta,id.superlayer());
00391       }
00392           
00393     }// for digis in layer
00394 
00395     meDoubleDigi_->Fill( (float)num_digis_layer );
00396 
00397   }// for layers
00398 
00399  //cout << "num_digis " << num_digis << "mu digis " << num_mudigis << endl;
00400 
00401   if (num_musimhits != 0) {
00402    meDigiEfficiencyMu_->Fill( (float)num_mudigis/(float)num_musimhits );
00403    meDigiEfficiency_->Fill( (float)num_digis/(float)num_musimhits );
00404   }
00405   
00406   meSimvsDigi_->Fill( (float)num_musimhits, (float)num_digis ) ;
00407  //  cout<<"--------------"<<endl;
00408 
00409 }
00410 
00411 hDigis* MuonDTDigis::WheelHistos(int wheel){
00412   switch(abs(wheel)){
00413 
00414   case 0: return  hDigis_W0;
00415   
00416   case 1: return  hDigis_W1;
00417     
00418   case 2: return  hDigis_W2;
00419      
00420   default: return NULL;
00421   }
00422 }
00423 #include "FWCore/PluginManager/interface/ModuleDef.h"
00424 #include "FWCore/Framework/interface/MakerMacros.h"
00425 #include "DQMServices/Core/interface/DQMStore.h"
00426 
00427 DEFINE_FWK_MODULE(MuonDTDigis);