CMS 3D CMS Logo

SiStripMonitorTrackEfficiency.cc

Go to the documentation of this file.
00001 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00002 
00003 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00004 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00005 
00006 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00007 #include "DataFormats/DetId/interface/DetId.h"
00008 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00009 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00010 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00011 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00012 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00013 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00014 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00015 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00016 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00017 
00018 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00019 
00020 #include "DQM/SiStripMonitorTrack/interface/SiStripMonitorTrackEfficiency.h"
00021 
00022 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00023 #include "TMath.h"
00024 
00025 static const uint16_t _NUM_SISTRIP_SUBDET_ = 4;
00026 static TString SubDet[_NUM_SISTRIP_SUBDET_]={"TIB","TID","TOB","TEC"};
00027 static std::string flags[2] = {"OnTrack","OffTrack"};
00028 
00029 SiStripMonitorTrackEfficiency::SiStripMonitorTrackEfficiency(const edm::ParameterSet& conf):
00030   dbe(edm::Service<DQMStore>().operator->()),
00031   conf_(conf),
00032   Cluster_src_( conf.getParameter<edm::InputTag>( "Cluster_src" ) ),
00033   Mod_On_(conf.getParameter<bool>("Mod_On")),
00034   OffHisto_On_(conf.getParameter<bool>("OffHisto_On")),
00035   folder_organizer(), tracksCollection_in_EventTree(true),
00036   firstEvent(-1),
00037   neighbourStripNumber(3)
00038 {
00039   for(int i=0;i<4;++i) for(int j=0;j<2;++j) NClus[i][j]=0;
00040   if(OffHisto_On_){
00041     off_Flag = 2;
00042   }else{
00043     off_Flag = 1;
00044   }
00045 }
00046 
00047 //------------------------------------------------------------------------
00048 SiStripMonitorTrackEfficiency::~SiStripMonitorTrackEfficiency() { }
00049 
00050 //------------------------------------------------------------------------
00051 void SiStripMonitorTrackEfficiency::beginRun(const edm::Run& run,const edm::EventSetup& es)
00052 {
00053   //get geom 
00054   es.get<TrackerDigiGeometryRecord>().get( tkgeom );
00055   edm::LogInfo("SiStripMonitorTrackEfficiency") << "[SiStripMonitorTrackEfficiency::beginRun] There are "<<tkgeom->detUnits().size() <<" detectors instantiated in the geometry" << std::endl;  
00056   es.get<SiStripDetCablingRcd>().get( SiStripDetCabling_ );
00057 
00058   book();
00059 
00060 }
00061 
00062 //------------------------------------------------------------------------
00063 void SiStripMonitorTrackEfficiency::endJob(void)
00064 {
00065   if(conf_.getParameter<bool>("OutputMEsInRootFile")){
00066     dbe->showDirStructure();
00067     dbe->save(conf_.getParameter<std::string>("OutputFileName"));
00068   }
00069 }
00070 
00071 // ------------ method called to produce the data  ------------
00072 void SiStripMonitorTrackEfficiency::analyze(const edm::Event& e, const edm::EventSetup& es)
00073 {
00074   tracksCollection_in_EventTree=true;
00075   trackAssociatorCollection_in_EventTree=true;
00076   
00077   //initialization of global quantities
00078   edm::LogInfo("SiStripMonitorTrackEfficiency") << "[SiStripMonitorTrackEfficiency::analyse]  " << "Run " << e.id().run() << " Event " << e.id().event() << std::endl;
00079   runNb   = e.id().run();
00080   eventNb = e.id().event();
00081   vPSiStripCluster.clear();
00082   countOn=0;
00083   countOff=0;
00084 
00085   e.getByLabel( Cluster_src_, dsv_SiStripCluster); 
00086 
00087   // track input  
00088   std::string TrackProducer = conf_.getParameter<std::string>("TrackProducer");
00089   std::string TrackLabel = conf_.getParameter<std::string>("TrackLabel");
00090   
00091   e.getByLabel(TrackProducer, TrackLabel, trackCollection);//takes the track collection
00092  
00093   if (trackCollection.isValid()){
00094   }else{
00095     LogDebug("SiStripMonitorTrackEfficiency")<<" Track Collection is not valid !!" <<std::endl;
00096     tracksCollection_in_EventTree=false;
00097   }
00098 
00099   // trajectory input
00100   e.getByLabel(TrackProducer, TrackLabel, TrajectoryCollection);
00101   e.getByLabel(TrackProducer, TrackLabel, TItkAssociatorCollection);
00102   if( TItkAssociatorCollection.isValid()){
00103   }else{
00104     LogDebug("SiStripMonitorTrackEfficiency")<<"Association not found "<<std::endl;
00105     trackAssociatorCollection_in_EventTree=false;
00106   }
00107   
00108   //Perform track study
00109   if (tracksCollection_in_EventTree && trackAssociatorCollection_in_EventTree) trackStudy(es);
00110   
00111   //Perform Cluster Study (irrespectively to tracks)
00112   if (dsv_SiStripCluster.isValid() && OffHisto_On_){
00113     AllClusters(es);//analyzes the off Track Clusters
00114   }else{
00115     LogDebug("SiStripMonitorTrackEfficiency")<< "ClusterCollection is not valid!!" << std::endl;
00116   }
00117 
00118   //Summary Counts of clusters
00119   std::map<TString, MonitorElement*>::iterator iME;
00120   std::map<TString, ModMEs>::iterator          iModME ;
00121 
00122   for (int j=0;j<off_Flag;++j){ // loop over ontrack, offtrack
00123     int nTot=0;
00124     for (int i=0;i<4;++i){ // loop over TIB, TID, TOB, TEC
00125       name=flags[j]+"_in_"+SubDet[i];      
00126       iModME = ModMEsMap.find(name);
00127       if(iModME!=ModMEsMap.end()) {
00128         fillME(   iModME->second.nClusters,      NClus[i][j]);
00129         fillTrend(iModME->second.nClustersTrend, NClus[i][j]);
00130       }
00131       nTot+=NClus[i][j];
00132       NClus[i][j]=0;
00133     }// loop over TIB, TID, TOB, TEC
00134   
00135     name=flags[j]+"_NumberOfClusters";
00136     iME = MEMap.find(name);
00137     if(iME!=MEMap.end()) iME->second->Fill(nTot);
00138     iME = MEMap.find(name+"Trend");
00139     if(iME!=MEMap.end()) fillTrend(iME->second,nTot);
00140 
00141  } // loop over ontrack, offtrack
00142   
00143 }
00144 
00145 //------------------------------------------------------------------------  
00146 void SiStripMonitorTrackEfficiency::book() 
00147 {
00148   
00149   std::vector<uint32_t> vdetId_;
00150   SiStripDetCabling_->addActiveDetectorsRawIds(vdetId_);
00151   //Histos for each detector, layer and module
00152   for (std::vector<uint32_t>::const_iterator detid_iter=vdetId_.begin();detid_iter!=vdetId_.end();detid_iter++){  //loop on all the active detid
00153     uint32_t detid = *detid_iter;
00154     
00155     if (detid < 1){
00156       edm::LogError("SiStripMonitorTrackEfficiency")<< "[" <<__PRETTY_FUNCTION__ << "] invalid detid " << detid<< std::endl;
00157       continue;
00158     }
00159     if (DetectedLayers.find(folder_organizer.GetSubDetAndLayer(detid)) == DetectedLayers.end()){
00160       
00161       DetectedLayers[folder_organizer.GetSubDetAndLayer(detid)]=true;
00162     }    
00163 
00164     // set the DQM directory
00165     std::string MEFolderName = conf_.getParameter<std::string>("FolderName");    
00166     dbe->setCurrentFolder(MEFolderName);
00167     
00168     for (int j=0;j<off_Flag;j++) { // Loop on onTrack, offTrack
00169       name=flags[j]+"_NumberOfClusters";
00170       if(MEMap.find(name)==MEMap.end()) {
00171         MEMap[name]=bookME1D("TH1nClusters", name.Data()); 
00172         name+="Trend";
00173         MEMap[name]=bookMETrend("TH1nClusters", name.Data());
00174       }
00175     }// End Loop on onTrack, offTrack
00176     
00177     //  LogTrace("SiStripMonitorTrackEfficiency") << " Detid " << *detid 
00178     //                                  << " SubDet " << GetSubDetAndLayer(*detid).first 
00179     //                                  << " Layer "  << GetSubDetAndLayer(*detid).second;
00180 
00181     // book Layer plots      
00182     for (int j=0;j<off_Flag;j++){ 
00183       folder_organizer.setLayerFolder(*detid_iter,folder_organizer.GetSubDetAndLayer(*detid_iter).second); 
00184       bookTrendMEs("layer",folder_organizer.GetSubDetAndLayer(*detid_iter).second,*detid_iter,flags[j]);
00185     }
00186   
00187     if(Mod_On_){
00188       //    book module plots
00189       folder_organizer.setDetectorFolder(*detid_iter);
00190       bookModMEs("det",*detid_iter);
00191     }
00192     DetectedLayers[folder_organizer.GetSubDetAndLayer(*detid_iter)] |= (DetectedLayers.find(folder_organizer.GetSubDetAndLayer(*detid_iter)) == DetectedLayers.end());
00193     //      }
00194   }//end loop on detector
00195   
00196   //  book SubDet plots
00197   for (std::map<std::pair<std::string,int32_t>,bool>::const_iterator iter=DetectedLayers.begin(); iter!=DetectedLayers.end();iter++){
00198     for (int j=0;j<off_Flag;j++){ // Loop on onTrack, offTrack
00199       folder_organizer.setDetectorFolder(0);
00200       dbe->cd("SiStrip/MechanicalView/"+iter->first.first);
00201       name=flags[j]+"_in_"+iter->first.first; 
00202       bookSubDetMEs(name,flags[j]); //for subdets
00203     }//end loop on onTrack,offTrack
00204   }  
00205 }
00206   
00207 //--------------------------------------------------------------------------------
00208 void SiStripMonitorTrackEfficiency::bookModMEs(TString name, uint32_t id)//Histograms at MODULE level
00209 {
00210   SiStripHistoId hidmanager;
00211   std::string hid = hidmanager.createHistoId("",name.Data(),id);
00212   std::map<TString, ModMEs>::iterator iModME  = ModMEsMap.find(TString(hid));
00213   if(iModME==ModMEsMap.end()){
00214     ModMEs theModMEs; 
00215     //Cluster Width
00216     theModMEs.ClusterWidth=bookME1D("TH1ClusterWidth", hidmanager.createHistoId("OnTrack_cWidth",name.Data(),id).c_str()); 
00217     dbe->tag(theModMEs.ClusterWidth,id); 
00218     //Cluster Charge
00219     theModMEs.ClusterCharge=bookME1D("TH1ClusterCharge", hidmanager.createHistoId("OnTrack_cCharge",name.Data(),id).c_str());
00220     dbe->tag(theModMEs.ClusterCharge,id); 
00221     //Cluster StoN
00222     theModMEs.ClusterStoN=bookME1D("TH1ClusterStoN", hidmanager.createHistoId("OnTrack_cStoN",name.Data(),id).c_str());
00223     dbe->tag(theModMEs.ClusterStoN,id); 
00224     //Cluster Charge Corrected
00225     theModMEs.ClusterChargeCorr=bookME1D("TH1ClusterChargeCorr", hidmanager.createHistoId("OnTrack_cChargeCorr",name.Data(),id).c_str());
00226     dbe->tag(theModMEs.ClusterChargeCorr,id); 
00227     //Cluster StoN Corrected
00228     theModMEs.ClusterStoNCorr=bookME1D("TH1ClusterStoNCorr", hidmanager.createHistoId("OnTrack_cStoNCorr",name.Data(),id).c_str());
00229     dbe->tag(theModMEs.ClusterStoNCorr,id); 
00230     //Cluster Position
00231     theModMEs.ClusterPos=bookME1D("TH1ClusterPos", hidmanager.createHistoId("OnTrack_cPos",name.Data(),id).c_str());  
00232     dbe->tag(theModMEs.ClusterPos,id); 
00233     //Cluster PGV
00234     theModMEs.ClusterPGV=bookMEProfile("TProfileClusterPGV", hidmanager.createHistoId("OnTrack_cPGV",name.Data(),id).c_str()); 
00235     dbe->tag(theModMEs.ClusterPGV,id); 
00236     //bookeeping
00237     ModMEsMap[hid]=theModMEs;
00238   }
00239 }
00240 
00241 void SiStripMonitorTrackEfficiency::bookTrendMEs(TString name,int32_t layer,uint32_t id,std::string flag)//Histograms and Trends at LAYER LEVEL
00242 {
00243   char rest[1024];
00244   int subdetid = ((id>>25)&0x7);
00245   if(       subdetid==3 ){
00246   // ---------------------------  TIB  --------------------------- //
00247     TIBDetId tib1 = TIBDetId(id);
00248     sprintf(rest,"TIB__layer__%d",tib1.layer());
00249   }else if( subdetid==4){
00250   // ---------------------------  TID  --------------------------- //
00251     TIDDetId tid1 = TIDDetId(id);
00252     sprintf(rest,"TID__side__%d__wheel__%d",tid1.side(),tid1.wheel());
00253   }else if( subdetid==5){
00254   // ---------------------------  TOB  --------------------------- //
00255     TOBDetId tob1 = TOBDetId(id);
00256     sprintf(rest,"TOB__layer__%d",tob1.layer());
00257   }else if( subdetid==6){
00258   // ---------------------------  TEC  --------------------------- //
00259     TECDetId tec1 = TECDetId(id);
00260     sprintf(rest,"TEC__side__%d__wheel__%d",tec1.side(),tec1.wheel());
00261   }else{
00262   // ---------------------------  ???  --------------------------- //
00263     edm::LogError("SiStripTkDQM|WrongInput")<<"no such subdetector type :"<<subdetid<<" no folder set!"<<std::endl;
00264     return;
00265   }
00266 
00267   SiStripHistoId hidmanager;
00268   std::string hid = hidmanager.createHistoLayer("",name.Data(),rest,flag);
00269   std::map<TString, ModMEs>::iterator iModME  = ModMEsMap.find(TString(hid));
00270   if(iModME==ModMEsMap.end()){
00271     ModMEs theModMEs; 
00272     //Cluster Width
00273     theModMEs.ClusterWidth=bookME1D("TH1ClusterWidth", hidmanager.createHistoLayer("Summary_cWidth",name.Data(),rest,flag).c_str()); 
00274     dbe->tag(theModMEs.ClusterWidth,layer); 
00275     theModMEs.ClusterWidthTrend=bookMETrend("TH1ClusterWidth", hidmanager.createHistoLayer("Trend_cWidth",name.Data(),rest,flag).c_str()); 
00276     dbe->tag(theModMEs.ClusterWidthTrend,layer); 
00277 
00278     //Cluster Noise
00279     theModMEs.ClusterNoise=bookME1D("TH1ClusterNoise", hidmanager.createHistoLayer("Summary_cNoise",name.Data(),rest,flag).c_str()); 
00280     dbe->tag(theModMEs.ClusterNoise,layer); 
00281     theModMEs.ClusterNoiseTrend=bookMETrend("TH1ClusterNoise", hidmanager.createHistoLayer("Trend_cNoise",name.Data(),rest,flag).c_str()); 
00282     dbe->tag(theModMEs.ClusterNoiseTrend,layer); 
00283     //Cluster Charge
00284     theModMEs.ClusterCharge=bookME1D("TH1ClusterCharge", hidmanager.createHistoLayer("Summary_cCharge",name.Data(),rest,flag).c_str());
00285     dbe->tag(theModMEs.ClusterCharge,layer);
00286     theModMEs.ClusterChargeTrend=bookMETrend("TH1ClusterCharge", hidmanager.createHistoLayer("Trend_cCharge",name.Data(),rest,flag).c_str());
00287     dbe->tag(theModMEs.ClusterChargeTrend,layer); 
00288     //Cluster StoN
00289     theModMEs.ClusterStoN=bookME1D("TH1ClusterStoN", hidmanager.createHistoLayer("Summary_cStoN",name.Data(),rest,flag).c_str());
00290     dbe->tag(theModMEs.ClusterStoN,layer); 
00291     theModMEs.ClusterStoNTrend=bookMETrend("TH1ClusterStoN", hidmanager.createHistoLayer("Trend_cStoN",name.Data(),rest,flag).c_str());
00292     dbe->tag(theModMEs.ClusterStoNTrend,layer); 
00293     if(flag=="OnTrack"){
00294       //Cluster Charge Corrected
00295       theModMEs.ClusterChargeCorr=bookME1D("TH1ClusterChargeCorr", hidmanager.createHistoLayer("Summary_cChargeCorr",name.Data(),rest,flag).c_str());
00296       dbe->tag(theModMEs.ClusterChargeCorr,layer); 
00297       theModMEs.ClusterChargeCorrTrend=bookMETrend("TH1ClusterChargeCorr", hidmanager.createHistoLayer("Trend_cChargeCorr",name.Data(),rest,flag).c_str());
00298       dbe->tag(theModMEs.ClusterChargeCorrTrend,layer); 
00299       //Cluster StoN Corrected
00300       theModMEs.ClusterStoNCorr=bookME1D("TH1ClusterStoNCorr", hidmanager.createHistoLayer("Summary_cStoNCorr",name.Data(),rest,flag).c_str());
00301       dbe->tag(theModMEs.ClusterStoNCorr,layer); 
00302       theModMEs.ClusterStoNCorrTrend=bookMETrend("TH1ClusterStoNCorr", hidmanager.createHistoLayer("Trend_cStoNCorr",name.Data(),rest,flag).c_str());
00303       //      dbe->tag(theModMEs.ClusterStoNCorrTrend,layer); 
00304     }
00305     //Cluster Position
00306     theModMEs.ClusterPos=bookME1D("TH1ClusterPos", hidmanager.createHistoLayer("Summary_cPos",name.Data(),rest,flag).c_str());  
00307     dbe->tag(theModMEs.ClusterPos,layer); 
00308     //bookeeping
00309     ModMEsMap[hid]=theModMEs;
00310   }
00311 
00312 }
00313 
00314 void SiStripMonitorTrackEfficiency::bookSubDetMEs(TString name,TString flag)//Histograms at SubDet level
00315 {
00316   std::map<TString, ModMEs>::iterator iModME  = ModMEsMap.find(name);
00317   char completeName[1024];
00318   if(iModME==ModMEsMap.end()){
00319     ModMEs theModMEs; 
00320     //Number of Cluster 
00321     sprintf(completeName,"Trend_NumberOfClusters_%s",name.Data());
00322     theModMEs.nClustersTrend=bookMETrend("TH1nClusters", completeName);
00323     sprintf(completeName,"Summary_NumberOfClusters_%s",name.Data());
00324     theModMEs.nClusters=bookME1D("TH1nClusters", completeName);
00325     //Cluster Width
00326     sprintf(completeName,"Trend_cWidth_%s",name.Data());
00327     theModMEs.ClusterWidthTrend=bookMETrend("TH1ClusterWidth", completeName);
00328     sprintf(completeName,"Summary_cWidth_%s",name.Data());
00329     theModMEs.ClusterWidth=bookME1D("TH1ClusterWidth", completeName);
00330     //Cluster Noise
00331     sprintf(completeName,"Trend_cNoise_%s",name.Data());
00332     theModMEs.ClusterNoiseTrend=bookMETrend("TH1ClusterNoise", completeName);
00333     sprintf(completeName,"Summary_cNoise_%s",name.Data());
00334     theModMEs.ClusterNoise=bookME1D("TH1ClusterNoise", completeName);
00335     //Cluster Charge
00336     sprintf(completeName,"Trend_cCharge_%s",name.Data());
00337     theModMEs.ClusterChargeTrend=bookMETrend("TH1ClusterCharge", completeName);
00338     sprintf(completeName,"Summary_cCharge_%s",name.Data());
00339     theModMEs.ClusterCharge=bookME1D("TH1ClusterCharge", completeName);
00340     //Cluster StoN
00341     sprintf(completeName,"Trend_cStoN_%s",name.Data());
00342     theModMEs.ClusterStoNTrend=bookMETrend("TH1ClusterStoN", completeName);
00343     sprintf(completeName,"Summary_cStoN_%s",name.Data());
00344     theModMEs.ClusterStoN=bookME1D("TH1ClusterStoN", completeName);
00345     if (flag=="OnTrack"){    //Cluster StoNCorr
00346       sprintf(completeName,"Trend_cStoNCorr_%s",name.Data());
00347       theModMEs.ClusterStoNCorrTrend=bookMETrend("TH1ClusterStoNCorr", completeName);
00348       sprintf(completeName,"Summary_cStoNCorr_%s",name.Data());
00349       theModMEs.ClusterStoNCorr=bookME1D("TH1ClusterStoNCorr", completeName);
00350       
00351       //Cluster ChargeCorr
00352       sprintf(completeName,"Trend_cChargeCorr_%s",name.Data());
00353       theModMEs.ClusterChargeCorrTrend=bookMETrend("TH1ClusterChargeCorr", completeName);
00354       sprintf(completeName,"Summary_cChargeCorr_%s",name.Data());
00355       theModMEs.ClusterChargeCorr=bookME1D("TH1ClusterChargeCorr", completeName);
00356 }
00357     //bookeeping
00358     ModMEsMap[name]=theModMEs;
00359   }
00360 }
00361 //--------------------------------------------------------------------------------
00362 
00363 MonitorElement* SiStripMonitorTrackEfficiency::bookME1D(const char* ParameterSetLabel, const char* HistoName)
00364 {
00365   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00366   return dbe->book1D(HistoName,HistoName,
00367                          Parameters.getParameter<int32_t>("Nbinx"),
00368                          Parameters.getParameter<double>("xmin"),
00369                          Parameters.getParameter<double>("xmax")
00370                     );
00371 }
00372 
00373 //--------------------------------------------------------------------------------
00374 MonitorElement* SiStripMonitorTrackEfficiency::bookME2D(const char* ParameterSetLabel, const char* HistoName)
00375 {
00376   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00377   return dbe->book2D(HistoName,HistoName,
00378                      Parameters.getParameter<int32_t>("Nbinx"),
00379                      Parameters.getParameter<double>("xmin"),
00380                      Parameters.getParameter<double>("xmax"),
00381                      Parameters.getParameter<int32_t>("Nbiny"),
00382                      Parameters.getParameter<double>("ymin"),
00383                      Parameters.getParameter<double>("ymax")
00384                      );
00385 }
00386 
00387 //--------------------------------------------------------------------------------
00388 MonitorElement* SiStripMonitorTrackEfficiency::bookME3D(const char* ParameterSetLabel, const char* HistoName)
00389 {
00390   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00391   return dbe->book3D(HistoName,HistoName,
00392                      Parameters.getParameter<int32_t>("Nbinx"),
00393                      Parameters.getParameter<double>("xmin"),
00394                      Parameters.getParameter<double>("xmax"),
00395                      Parameters.getParameter<int32_t>("Nbiny"),
00396                      Parameters.getParameter<double>("ymin"),
00397                      Parameters.getParameter<double>("ymax"),
00398                      Parameters.getParameter<int32_t>("Nbinz"),
00399                      Parameters.getParameter<double>("zmin"),
00400                      Parameters.getParameter<double>("zmax")
00401                      );
00402 }
00403 
00404 //--------------------------------------------------------------------------------
00405 MonitorElement* SiStripMonitorTrackEfficiency::bookMEProfile(const char* ParameterSetLabel, const char* HistoName)
00406 {
00407     Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00408     return dbe->bookProfile(HistoName,HistoName,
00409                             Parameters.getParameter<int32_t>("Nbinx"),
00410                             Parameters.getParameter<double>("xmin"),
00411                             Parameters.getParameter<double>("xmax"),
00412                             Parameters.getParameter<int32_t>("Nbiny"),
00413                             Parameters.getParameter<double>("ymin"),
00414                             Parameters.getParameter<double>("ymax"),
00415                             "" );
00416 }
00417 
00418 //--------------------------------------------------------------------------------
00419 MonitorElement* SiStripMonitorTrackEfficiency::bookMETrend(const char* ParameterSetLabel, const char* HistoName)
00420 {
00421   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00422   edm::ParameterSet ParametersTrend =  conf_.getParameter<edm::ParameterSet>("Trending");
00423   MonitorElement* me = dbe->bookProfile(HistoName,HistoName,
00424                                         ParametersTrend.getParameter<int32_t>("Nbins"),
00425                                         0,
00426                                         ParametersTrend.getParameter<int32_t>("Nbins"),
00427                                         100, //that parameter should not be there !?
00428                                         Parameters.getParameter<double>("xmin"),
00429                                         Parameters.getParameter<double>("xmax"),
00430                                         "" );
00431   if(!me) return me;
00432   char buffer[256];
00433   sprintf(buffer,"EventId/%d",ParametersTrend.getParameter<int32_t>("Steps"));
00434   me->setAxisTitle(std::string(buffer),1);
00435   return me;
00436 }
00437 
00438 //------------------------------------------------------------------------------------------
00439 void SiStripMonitorTrackEfficiency::trackStudy(const edm::EventSetup& es)
00440 {
00441 
00442   LogDebug("SiStripMonitorTrackEfficiency") << "inside trackstudy" << std::endl;
00443   const reco::TrackCollection tC = *(trackCollection.product());
00444   int i=0;
00445   std::vector<TrajectoryMeasurement> measurements;
00446   for(TrajTrackAssociationCollection::const_iterator it =  TItkAssociatorCollection->begin();it !=  TItkAssociatorCollection->end(); ++it){
00447     const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;  
00448     // Trajectory Map, extract Trajectory for this track
00449     reco::TrackRef trackref = it->val;
00450     LogTrace("SiStripMonitorTrackEfficiency")
00451       << "Track number "<< i+1 
00452       << "\n\tmomentum: " << trackref->momentum()
00453       << "\n\tPT: " << trackref->pt()
00454       << "\n\tvertex: " << trackref->vertex()
00455       << "\n\timpact parameter: " << trackref->d0()
00456       << "\n\tcharge: " << trackref->charge()
00457       << "\n\tnormalizedChi2: " << trackref->normalizedChi2() 
00458       <<"\n\tFrom EXTRA : "
00459       <<"\n\t\touter PT "<< trackref->outerPt()<<std::endl;
00460     i++;
00461 
00462     measurements =traj_iterator->measurements();
00463     std::vector<TrajectoryMeasurement>::iterator traj_mes_iterator;
00464     int nhit=0;
00465     for(traj_mes_iterator=measurements.begin();traj_mes_iterator!=measurements.end();traj_mes_iterator++){//loop on measurements
00466       //trajectory local direction and position on detector
00467       LocalPoint  stateposition;
00468       LocalVector statedirection;
00469       
00470       TrajectoryStateOnSurface  updatedtsos=traj_mes_iterator->updatedState();
00471       ConstRecHitPointer ttrh=traj_mes_iterator->recHit();
00472 
00473       TrajectoryStateCombiner tsoscomb;
00474       TrajectoryStateOnSurface tsos = tsoscomb( traj_mes_iterator->forwardPredictedState(), traj_mes_iterator->backwardPredictedState() );
00475       LogTrace("SiStripMonitorTrackEfficiency")<<"\n\n------------\nlocal position of tsos  " << updatedtsos.localPosition() << " " << tsos.localPosition()<< std::endl;
00476 
00477       if (!ttrh->isValid()) {
00478         LogTrace("SiStripMonitorTrackEfficiency")<<"\n\nthis is a nonValid hit " << " \n\n" ;
00479         continue;}
00480       
00481       std::stringstream ss;
00482       
00483       nhit++;
00484       
00485       const ProjectedSiStripRecHit2D* phit=dynamic_cast<const ProjectedSiStripRecHit2D*>( ttrh->hit() );
00486       const SiStripMatchedRecHit2D* matchedhit=dynamic_cast<const SiStripMatchedRecHit2D*>( ttrh->hit() );
00487       const SiStripRecHit2D* hit=dynamic_cast<const SiStripRecHit2D*>( ttrh->hit() );   
00488       
00489       RecHitType type=Single;
00490 
00491       if(matchedhit){
00492         LogTrace("SiStripMonitorTrackEfficiency")<<"\nMatched recHit found"<< std::endl;
00493         type=Matched;
00494         
00495         GluedGeomDet * gdet=(GluedGeomDet *)tkgeom->idToDet(matchedhit->geographicalId());
00496         GlobalVector gtrkdirup=gdet->toGlobal(updatedtsos.localMomentum());         
00497         //mono side
00498         const GeomDetUnit * monodet=gdet->monoDet();
00499         statedirection=monodet->toLocal(gtrkdirup);
00500         if(statedirection.mag() != 0)     RecHitInfo(matchedhit->monoHit(),statedirection,trackref,es);
00501         //stereo side
00502         const GeomDetUnit * stereodet=gdet->stereoDet();
00503         statedirection=stereodet->toLocal(gtrkdirup);
00504         if(statedirection.mag() != 0)     RecHitInfo(matchedhit->stereoHit(),statedirection,trackref,es);
00505         ss<<"\nLocalMomentum (stereo): " <<  statedirection;
00506       }
00507       else if(phit){
00508         LogTrace("SiStripMonitorTrackEfficiency")<<"\nProjected recHit found"<< std::endl;
00509         type=Projected;
00510         GluedGeomDet * gdet=(GluedGeomDet *)tkgeom->idToDet(phit->geographicalId());
00511         
00512         GlobalVector gtrkdirup=gdet->toGlobal(updatedtsos.localMomentum());
00513         const SiStripRecHit2D&  originalhit=phit->originalHit();
00514         const GeomDetUnit * det;
00515         if(!StripSubdetector(originalhit.geographicalId().rawId()).stereo()){
00516           //mono side
00517           LogTrace("SiStripMonitorTrackEfficiency")<<"\nProjected recHit found  MONO"<< std::endl;
00518           det=gdet->monoDet();
00519           statedirection=det->toLocal(gtrkdirup);
00520           if(statedirection.mag() != 0) RecHitInfo(&(phit->originalHit()),statedirection,trackref,es);
00521         }
00522         else{
00523           LogTrace("SiStripMonitorTrackEfficiency")<<"\nProjected recHit found STEREO"<< std::endl;
00524           //stereo side
00525           det=gdet->stereoDet();
00526           statedirection=det->toLocal(gtrkdirup);
00527           if(statedirection.mag() != 0) RecHitInfo(&(phit->originalHit()),statedirection,trackref,es);
00528         }
00529       }else {
00530         if(hit!=0){
00531           ss<<"\nSingle recHit found"<< std::endl;        
00532           statedirection=updatedtsos.localMomentum();
00533           if(statedirection.mag() != 0) RecHitInfo(hit,statedirection,trackref,es);
00534         }
00535       }
00536       ss <<"LocalMomentum: "<<statedirection
00537          << "\nLocal x-z plane angle: "<<atan2(statedirection.x(),statedirection.z());        
00538       LogTrace("SiStripMonitorTrackEfficiency") <<ss.str() << std::endl;
00539     }
00540     
00541   }
00542 }
00543 
00544   void SiStripMonitorTrackEfficiency::RecHitInfo(const SiStripRecHit2D* tkrecHit, LocalVector LV,reco::TrackRef track_ref, const edm::EventSetup& es){
00545     
00546     if(!tkrecHit->isValid()){
00547       LogTrace("SiStripMonitorTrackEfficiency") <<"\t\t Invalid Hit " << std::endl;
00548       return;  
00549     }
00550     
00551     const uint32_t& detid = tkrecHit->geographicalId().rawId();
00552     if (find(ModulesToBeExcluded_.begin(),ModulesToBeExcluded_.end(),detid)!=ModulesToBeExcluded_.end()){
00553       LogTrace("SiStripMonitorTrackEfficiency") << "Modules Excluded" << std::endl;
00554       return;
00555     }
00556     
00557     LogTrace("SiStripMonitorTrackEfficiency")
00558       <<"\n\t\tRecHit on det "<<tkrecHit->geographicalId().rawId()
00559       <<"\n\t\tRecHit in LP "<<tkrecHit->localPosition()
00560       <<"\n\t\tRecHit in GP "<<tkgeom->idToDet(tkrecHit->geographicalId())->surface().toGlobal(tkrecHit->localPosition()) 
00561       <<"\n\t\tRecHit trackLocal vector "<<LV.x() << " " << LV.y() << " " << LV.z() <<std::endl; 
00562     
00563     //Get SiStripCluster from SiStripRecHit
00564     if ( tkrecHit != NULL ){
00565       LogTrace("SiStripMonitorTrackEfficiency") << "GOOD hit" << std::endl;
00566       const SiStripCluster* SiStripCluster_ = &*(tkrecHit->cluster());
00567       SiStripClusterInfo* SiStripClusterInfo_ = new SiStripClusterInfo(detid,*SiStripCluster_,es);
00568             
00569       if ( clusterInfos(SiStripClusterInfo_,detid,"OnTrack", LV ) ) {
00570         vPSiStripCluster.push_back(SiStripCluster_);
00571         countOn++;
00572       }
00573       delete SiStripClusterInfo_; 
00574       //}
00575     }else{
00576       LogTrace("SiStripMonitorTrackEfficiency") << "NULL hit" << std::endl;
00577     }     
00578   }
00579 
00580 //------------------------------------------------------------------------
00581 
00582 void SiStripMonitorTrackEfficiency::AllClusters( const edm::EventSetup& es)
00583 {
00584 
00585   //Loop on Dets
00586   for ( edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter=dsv_SiStripCluster->begin(); DSViter!=dsv_SiStripCluster->end();DSViter++){
00587     uint32_t detid=DSViter->id();
00588     if (find(ModulesToBeExcluded_.begin(),ModulesToBeExcluded_.end(),detid)!=ModulesToBeExcluded_.end()) continue;
00589     //Loop on Clusters
00590     LogDebug("SiStripMonitorTrackEfficiency") << "on detid "<< detid << " N Cluster= " << DSViter->size();
00591     edmNew::DetSet<SiStripCluster>::const_iterator ClusIter = DSViter->begin();
00592     for(; ClusIter!=DSViter->end(); ClusIter++) {
00593       SiStripClusterInfo* SiStripClusterInfo_= new SiStripClusterInfo(detid,*ClusIter,es);
00594         LogDebug("SiStripMonitorTrackEfficiency") << "ClusIter " << &*ClusIter << "\t " 
00595                                         << std::find(vPSiStripCluster.begin(),vPSiStripCluster.end(),&*ClusIter)-vPSiStripCluster.begin();
00596         if (std::find(vPSiStripCluster.begin(),vPSiStripCluster.end(),&*ClusIter) == vPSiStripCluster.end()){
00597           if ( clusterInfos(SiStripClusterInfo_,detid,"OffTrack",LV) ) {
00598             countOff++;
00599           }
00600         }
00601         delete SiStripClusterInfo_; 
00602     }
00603   }
00604 }
00605 
00606 //------------------------------------------------------------------------
00607 bool SiStripMonitorTrackEfficiency::clusterInfos(SiStripClusterInfo* cluster, const uint32_t& detid,std::string flag, const LocalVector LV)
00608 {
00609   LogTrace("SiStripMonitorTrackEfficiency") << "\n["<<__PRETTY_FUNCTION__<<"]" << std::endl;
00610   //folder_organizer.setDetectorFolder(0);
00611   if (cluster==0) return false;
00612   // if one imposes a cut on the clusters, apply it
00613   const  edm::ParameterSet ps = conf_.getParameter<edm::ParameterSet>("ClusterConditions");
00614   if( ps.getParameter<bool>("On") &&
00615       (cluster->getCharge()/cluster->getNoise() < ps.getParameter<double>("minStoN") ||
00616        cluster->getCharge()/cluster->getNoise() > ps.getParameter<double>("maxStoN") ||
00617        cluster->getWidth() < ps.getParameter<double>("minWidth") ||
00618        cluster->getWidth() > ps.getParameter<double>("maxWidth")                    )) return false;
00619   // start of the analysis
00620   
00621   int SubDet_enum = StripSubdetector(detid).subdetId()-3;
00622   int iflag =0;
00623   if      (flag=="OnTrack")  iflag=0;
00624   else if (flag=="OffTrack") iflag=1;
00625   NClus[SubDet_enum][iflag]++;
00626   std::stringstream ss;
00627   //  const_cast<SiStripClusterInfo*>(cluster)->print(ss);
00628   LogTrace("SiStripMonitorTrackEfficiency") << "\n["<<__PRETTY_FUNCTION__<<"]\n" << ss.str() << std::endl;
00629   
00630   float cosRZ = -2;
00631   LogTrace("SiStripMonitorTrackEfficiency")<< "\n\tLV " << LV.x() << " " << LV.y() << " " << LV.z() << " " << LV.mag() << std::endl;
00632   if (LV.mag()!=0){
00633     cosRZ= fabs(LV.z())/LV.mag();
00634     LogTrace("SiStripMonitorTrackEfficiency")<< "\n\t cosRZ " << cosRZ << std::endl;
00635   }
00636   std::string name;
00637   
00638    //Filling SubDet Plots (on Track + off Track)
00639    std::pair<std::string,int32_t> SubDetAndLayer = folder_organizer.GetSubDetAndLayer(detid);
00640    name=flag+"_in_"+SubDetAndLayer.first;
00641    fillTrendMEs(cluster,name,cosRZ,flag);
00642 
00643    char rest[1024];
00644    int subdetid = ((detid>>25)&0x7);
00645    if(       subdetid==3 ){
00646      // ---------------------------  TIB  --------------------------- //
00647      TIBDetId tib1 = TIBDetId(detid);
00648      sprintf(rest,"TIB__layer__%d",tib1.layer());
00649    }else if( subdetid==4){
00650      // ---------------------------  TID  --------------------------- //
00651      TIDDetId tid1 = TIDDetId(detid);
00652      sprintf(rest,"TID__side__%d__wheel__%d",tid1.side(),tid1.wheel());
00653    }else if( subdetid==5){
00654      // ---------------------------  TOB  --------------------------- //
00655      TOBDetId tob1 = TOBDetId(detid);
00656      sprintf(rest,"TOB__layer__%d",tob1.layer());
00657    }else if( subdetid==6){
00658      // ---------------------------  TEC  --------------------------- //
00659      TECDetId tec1 = TECDetId(detid);
00660      sprintf(rest,"TEC__side__%d__wheel__%d",tec1.side(),tec1.wheel());
00661    }else{
00662      // ---------------------------  ???  --------------------------- //
00663      edm::LogError("SiStripTkDQM|WrongInput")<<"no such subdetector type :"<<subdetid<<" no folder set!"<<std::endl;
00664      return 0;
00665    }
00666    
00667    SiStripHistoId hidmanager1;
00668    
00669    //Filling Layer Plots
00670    name= hidmanager1.createHistoLayer("","layer",rest,flag);
00671    fillTrendMEs(cluster,name,cosRZ,flag);
00672    
00673    //Module plots filled only for onTrack Clusters
00674    if(Mod_On_){
00675      if(flag=="OnTrack"){
00676        SiStripHistoId hidmanager2;
00677        name =hidmanager2.createHistoId("","det",detid);
00678        fillModMEs(cluster,name,cosRZ); 
00679      }
00680    }
00681      return true;
00682    }
00683 
00684 //--------------------------------------------------------------------------------
00685 void SiStripMonitorTrackEfficiency::fillTrend(MonitorElement* me ,float value)
00686 {
00687   if(!me) return;
00688   //check the origin and check options
00689   int option = conf_.getParameter<edm::ParameterSet>("Trending").getParameter<int32_t>("UpdateMode");
00690   if(firstEvent==-1) firstEvent = eventNb;
00691   int CurrentStep = atoi(me->getAxisTitle(1).c_str()+8);
00692   int firstEventUsed = firstEvent;
00693   int presentOverflow = (int)me->getBinEntries(me->getNbinsX()+1);
00694   if(option==2) firstEventUsed += CurrentStep * int(me->getBinEntries(me->getNbinsX()+1));
00695   else if(option==3) firstEventUsed += CurrentStep * int(me->getBinEntries(me->getNbinsX()+1)) * me->getNbinsX();
00696   //fill
00697   me->Fill((eventNb-firstEventUsed)/CurrentStep,value);
00698   if(eventNb-firstEvent<1) return;
00699   // check if we reached the end
00700   if(presentOverflow == me->getBinEntries(me->getNbinsX()+1)) return;
00701   switch(option) {
00702   case 1:
00703     {
00704       // mode 1: rebin and change X scale
00705       int NbinsX = me->getNbinsX();
00706       float entries = 0.;
00707       float content = 0.;
00708       float error = 0.;
00709       int bin = 1;
00710       int totEntries = int(me->getEntries());
00711       for(;bin<=NbinsX/2;++bin) {
00712         content = (me->getBinContent(2*bin-1) + me->getBinContent(2*bin))/2.; 
00713         error   = pow((me->getBinError(2*bin-1)*me->getBinError(2*bin-1)) + (me->getBinError(2*bin)*me->getBinError(2*bin)),0.5)/2.; 
00714         entries = me->getBinEntries(2*bin-1) + me->getBinEntries(2*bin);
00715         me->setBinContent(bin,content*entries);
00716         me->setBinError(bin,error);
00717         me->setBinEntries(bin,entries);
00718       }
00719       for(;bin<=NbinsX+1;++bin) {
00720         me->setBinContent(bin,0);
00721         me->setBinError(bin,0);
00722         me->setBinEntries(bin,0); 
00723       }
00724       me->setEntries(totEntries);
00725       char buffer[256];
00726       sprintf(buffer,"EventId/%d",CurrentStep*2);
00727       me->setAxisTitle(std::string(buffer),1);
00728       break;
00729     }
00730   case 2:
00731     {
00732       // mode 2: slide
00733       int bin=1;
00734       int NbinsX = me->getNbinsX();
00735       for(;bin<=NbinsX;++bin) {
00736         me->setBinContent(bin,me->getBinContent(bin+1)*me->getBinEntries(bin+1));
00737         me->setBinError(bin,me->getBinError(bin+1));
00738         me->setBinEntries(bin,me->getBinEntries(bin+1));
00739       }
00740       break;
00741     }
00742   case 3:
00743     {
00744       // mode 3: reset
00745       int NbinsX = me->getNbinsX();
00746       for(int bin=0;bin<=NbinsX;++bin) {
00747         me->setBinContent(bin,0);
00748         me->setBinError(bin,0);
00749         me->setBinEntries(bin,0); 
00750       }
00751       break;
00752     }
00753   }
00754 }
00755 
00756 //--------------------------------------------------------------------------------
00757 void SiStripMonitorTrackEfficiency::fillModMEs(SiStripClusterInfo* cluster,TString name,float cos)
00758 {
00759   std::map<TString, ModMEs>::iterator iModME  = ModMEsMap.find(name);
00760   if(iModME!=ModMEsMap.end()){
00761     fillME(iModME->second.ClusterStoN  ,cluster->getCharge()/cluster->getNoise());
00762     fillME(iModME->second.ClusterStoNCorr ,cluster->getCharge()*cos/cluster->getNoise());
00763     fillME(iModME->second.ClusterCharge,cluster->getCharge());
00764     fillME(iModME->second.ClusterChargeCorr,cluster->getCharge()*cos);
00765     fillME(iModME->second.ClusterWidth ,cluster->getWidth());
00766     fillME(iModME->second.ClusterPos   ,cluster->getPosition());
00767 
00768     std::vector<float> amplitudesL, amplitudesR;
00769     //    amplitudesL = cluster->getRawDigiAmplitudesLR(neighbourStripNumber,*rawDigiHandle,dsv_SiStripCluster,theRawdigiLabel.label()).first;  
00770     //    amplitudesR = cluster->getRawDigiAmplitudesLR(neighbourStripNumber,*rawDigiHandle,dsv_SiStripCluster,theRawdigiLabel.label()).second;
00771 
00772     //fill the PGV histo
00773     float PGVmax = cluster->getMaxCharge();
00774     //    int PGVposCounter = cluster->getFirstStrip() - amplitudesL.size() - cluster->getMaxPosition();
00775     int PGVposCounter = cluster->getFirstStrip() - cluster->getMaxPosition();
00776     for (int i= int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmin"));i<PGVposCounter;++i)
00777       fillME(iModME->second.ClusterPGV, i,0.);
00778 //     for (std::vector<float>::const_iterator it=amplitudesL.begin();it<amplitudesL.end();++it) {
00779 //       fillME(iModME->second.ClusterPGV, PGVposCounter++,(*it)/PGVmax);
00780 //     }
00781     for (std::vector<uint8_t>::const_iterator it=cluster->getStripAmplitudes().begin();it<cluster->getStripAmplitudes().end();++it) {
00782       fillME(iModME->second.ClusterPGV, PGVposCounter++,(*it)/PGVmax);
00783     }
00784 //     for (std::vector<float>::const_iterator it=amplitudesR.begin();it<amplitudesR.end();++it) {
00785 //       fillME(iModME->second.ClusterPGV, PGVposCounter++,(*it)/PGVmax);
00786 //     }
00787     for (int i= PGVposCounter;i<int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmax"));++i)
00788       fillME(iModME->second.ClusterPGV, i,0.);
00789     //end fill the PGV histo
00790   }
00791 }
00792 
00793 void SiStripMonitorTrackEfficiency::fillTrendMEs(SiStripClusterInfo* cluster,std::string name,float cos, std::string flag)
00794 { 
00795   std::map<TString, ModMEs>::iterator iModME  = ModMEsMap.find(name);
00796   if(iModME!=ModMEsMap.end()){
00797     if(flag=="OnTrack"){
00798       fillME(iModME->second.ClusterStoNCorr,(cluster->getCharge()/cluster->getNoise())*cos);
00799       fillTrend(iModME->second.ClusterStoNCorrTrend,(cluster->getCharge()/cluster->getNoise())*cos);
00800       fillME(iModME->second.ClusterChargeCorr,cluster->getCharge()*cos);
00801       fillTrend(iModME->second.ClusterChargeCorrTrend,cluster->getCharge()*cos);
00802     }
00803     fillME(iModME->second.ClusterStoN  ,cluster->getCharge()/cluster->getNoise());
00804     fillTrend(iModME->second.ClusterStoNTrend,cluster->getCharge()/cluster->getNoise());
00805     fillME(iModME->second.ClusterCharge,cluster->getCharge());
00806     fillTrend(iModME->second.ClusterChargeTrend,cluster->getCharge());
00807     fillME(iModME->second.ClusterNoise ,cluster->getNoise());
00808     fillTrend(iModME->second.ClusterNoiseTrend,cluster->getNoise());
00809     fillME(iModME->second.ClusterWidth ,cluster->getWidth());
00810     fillTrend(iModME->second.ClusterWidthTrend,cluster->getWidth());
00811     fillME(iModME->second.ClusterPos   ,cluster->getPosition());
00812   }
00813 }
00814 

Generated on Tue Jun 9 17:33:41 2009 for CMSSW by  doxygen 1.5.4