CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/SiStripMonitorTrack/src/SiStripMonitorTrack.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/SiStripDetId/interface/SiStripSubStructure.h"
00008 #include "DataFormats/DetId/interface/DetId.h"
00009 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00010 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00011 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00012 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00013 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00014 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00015 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
00016 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00017 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00018 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00019 #include "CalibTracker/SiStripCommon/interface/SiStripDCSStatus.h"
00020 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
00021 
00022 #include "DQM/SiStripMonitorTrack/interface/SiStripMonitorTrack.h"
00023 
00024 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00025 #include "TMath.h"
00026 
00027 SiStripMonitorTrack::SiStripMonitorTrack(const edm::ParameterSet& conf): 
00028   dbe(edm::Service<DQMStore>().operator->()),
00029   conf_(conf),
00030   tracksCollection_in_EventTree(true),
00031   firstEvent(-1),
00032   genTriggerEventFlag_(new GenericTriggerEventFlag(conf))
00033 {
00034   Cluster_src_   = conf.getParameter<edm::InputTag>("Cluster_src");
00035   Mod_On_        = conf.getParameter<bool>("Mod_On");
00036   Trend_On_      = conf.getParameter<bool>("Trend_On");
00037   flag_ring      = conf.getParameter<bool>("RingFlag_On");
00038   TkHistoMap_On_ = conf.getParameter<bool>("TkHistoMap_On");
00039 
00040   TrackProducer_ = conf_.getParameter<std::string>("TrackProducer");
00041   TrackLabel_ = conf_.getParameter<std::string>("TrackLabel");
00042 
00043   // cluster quality conditions 
00044   edm::ParameterSet cluster_condition = conf_.getParameter<edm::ParameterSet>("ClusterConditions");
00045   applyClusterQuality_ = cluster_condition.getParameter<bool>("On");
00046   sToNLowerLimit_      = cluster_condition.getParameter<double>("minStoN");
00047   sToNUpperLimit_      = cluster_condition.getParameter<double>("maxStoN");
00048   widthLowerLimit_     = cluster_condition.getParameter<double>("minWidth"); 
00049   widthUpperLimit_     = cluster_condition.getParameter<double>("maxWidth"); 
00050 
00051 
00052   // Create DCS Status
00053   bool checkDCS    = conf_.getParameter<bool>("UseDCSFiltering");
00054   if (checkDCS) dcsStatus_ = new SiStripDCSStatus();
00055   else dcsStatus_ = 0; 
00056 }
00057 
00058 //------------------------------------------------------------------------
00059 SiStripMonitorTrack::~SiStripMonitorTrack() { 
00060   if (dcsStatus_) delete dcsStatus_;
00061   if (genTriggerEventFlag_) delete genTriggerEventFlag_;
00062 }
00063 
00064 //------------------------------------------------------------------------
00065 void SiStripMonitorTrack::beginRun(const edm::Run& run,const edm::EventSetup& es)
00066 {
00067   //get geom 
00068   es.get<TrackerDigiGeometryRecord>().get( tkgeom );
00069   LogDebug("SiStripMonitorTrack") << "[SiStripMonitorTrack::beginRun] There are "<<tkgeom->detUnits().size() <<" detectors instantiated in the geometry" << std::endl;  
00070   es.get<SiStripDetCablingRcd>().get( SiStripDetCabling_ );
00071 
00072   book();
00073 
00074   // Initialize the GenericTriggerEventFlag
00075   if ( genTriggerEventFlag_->on() )genTriggerEventFlag_->initRun( run, es );
00076 }
00077 
00078 //------------------------------------------------------------------------
00079 void SiStripMonitorTrack::endJob(void)
00080 {
00081   if(conf_.getParameter<bool>("OutputMEsInRootFile")){
00082     dbe->showDirStructure();
00083     dbe->save(conf_.getParameter<std::string>("OutputFileName"));
00084   }
00085 }
00086 
00087 // ------------ method called to produce the data  ------------
00088 void SiStripMonitorTrack::analyze(const edm::Event& e, const edm::EventSetup& es)
00089 {
00090   // Filter out events if DCS checking is requested
00091   if (dcsStatus_ && !dcsStatus_->getStatus(e,es)) return;
00092   
00093   // Filter out events if Trigger Filtering is requested
00094   if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( e, es) ) return;
00095   
00096   //initialization of global quantities
00097   LogDebug("SiStripMonitorTrack") << "[SiStripMonitorTrack::analyse]  " << "Run " << e.id().run() << " Event " << e.id().event() << std::endl;
00098   runNb   = e.id().run();
00099   eventNb = e.id().event();
00100   vPSiStripCluster.clear();
00101   
00102   iOrbitSec = e.orbitNumber()/11223.0;
00103 
00104   // initialise # of clusters
00105   for (std::map<std::string, SubDetMEs>::iterator iSubDet = SubDetMEsMap.begin();
00106        iSubDet != SubDetMEsMap.end(); iSubDet++) {
00107     iSubDet->second.totNClustersOnTrack = 0;
00108     iSubDet->second.totNClustersOffTrack = 0;
00109   }  
00110   
00111   //Perform track study
00112   trackStudy(e, es);
00113   
00114   //Perform Cluster Study (irrespectively to tracks)
00115 
00116    AllClusters(e, es); //analyzes the off Track Clusters
00117 
00118   //Summary Counts of clusters
00119   std::map<std::string, MonitorElement*>::iterator iME;
00120   std::map<std::string, LayerMEs>::iterator        iLayerME;
00121  
00122   for (std::map<std::string, SubDetMEs>::iterator iSubDet = SubDetMEsMap.begin();
00123        iSubDet != SubDetMEsMap.end(); iSubDet++) {
00124     SubDetMEs subdet_mes = iSubDet->second;
00125     if (subdet_mes.totNClustersOnTrack > 0) {
00126       fillME(subdet_mes.nClustersOnTrack, subdet_mes.totNClustersOnTrack);
00127     }
00128     fillME(subdet_mes.nClustersOffTrack, subdet_mes.totNClustersOffTrack);
00129     if (Trend_On_) {
00130       fillME(subdet_mes.nClustersTrendOnTrack,iOrbitSec,subdet_mes.totNClustersOnTrack);
00131       fillME(subdet_mes.nClustersTrendOffTrack,iOrbitSec,subdet_mes.totNClustersOffTrack);
00132     }
00133   }  
00134 }
00135 
00136 //------------------------------------------------------------------------  
00137 void SiStripMonitorTrack::book() 
00138 {
00139   
00140   SiStripFolderOrganizer folder_organizer;
00141   //******** TkHistoMaps
00142   if (TkHistoMap_On_) {
00143     tkhisto_StoNCorrOnTrack = new TkHistoMap("SiStrip/TkHisto" ,"TkHMap_StoNCorrOnTrack",0.0,1); 
00144     tkhisto_NumOnTrack  = new TkHistoMap("SiStrip/TkHisto", "TkHMap_NumberOfOnTrackCluster",0.0,1);
00145     tkhisto_NumOffTrack = new TkHistoMap("SiStrip/TkHisto", "TkHMap_NumberOfOfffTrackCluster",0.0,1);
00146   }
00147   //******** TkHistoMaps
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("SiStripMonitorTrack")<< "[" <<__PRETTY_FUNCTION__ << "] invalid detid " << detid<< std::endl;
00157       continue;
00158     }
00159 
00160     
00161     std::string name;    
00162     
00163     // book Layer and RING plots
00164     std::pair<std::string,int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid,flag_ring);
00165     
00166     SiStripHistoId hidmanager;
00167     std::string layer_id = hidmanager.getSubdetid(detid, flag_ring);
00168     std::map<std::string, LayerMEs>::iterator iLayerME  = LayerMEsMap.find(layer_id);
00169     if(iLayerME==LayerMEsMap.end()){
00170       folder_organizer.setLayerFolder(detid, det_layer_pair.second, flag_ring);
00171       bookLayerMEs(detid, layer_id);
00172     }
00173     // book sub-detector plots
00174     std::pair<std::string,std::string> sdet_pair = folder_organizer.getSubDetFolderAndTag(detid);
00175     if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()){
00176       dbe->setCurrentFolder(sdet_pair.first);
00177       bookSubDetMEs(sdet_pair.second);        
00178     }
00179     // book module plots
00180     if(Mod_On_) {
00181       folder_organizer.setDetectorFolder(detid);
00182       bookModMEs(*detid_iter);
00183     } 
00184   }//end loop on detectors detid
00185 }
00186   
00187 //--------------------------------------------------------------------------------
00188 void SiStripMonitorTrack::bookModMEs(const uint32_t & id)//Histograms at MODULE level
00189 {
00190   std::string name = "det";
00191   SiStripHistoId hidmanager;
00192   std::string hid = hidmanager.createHistoId("",name,id);
00193   std::map<std::string, ModMEs>::iterator iModME  = ModMEsMap.find(hid);
00194   if(iModME==ModMEsMap.end()){
00195     ModMEs theModMEs; 
00196     theModMEs.ClusterStoNCorr   = 0;
00197     theModMEs.ClusterCharge     = 0;
00198     theModMEs.ClusterChargeCorr = 0;
00199     theModMEs.ClusterWidth      = 0;
00200     theModMEs.ClusterPos        = 0;
00201     theModMEs.ClusterPGV        = 0;
00202 
00203     // Cluster Width
00204     theModMEs.ClusterWidth=bookME1D("TH1ClusterWidth", hidmanager.createHistoId("ClusterWidth_OnTrack",name,id).c_str()); 
00205     dbe->tag(theModMEs.ClusterWidth,id); 
00206     // Cluster Charge
00207     theModMEs.ClusterCharge=bookME1D("TH1ClusterCharge", hidmanager.createHistoId("ClusterCharge_OnTrack",name,id).c_str());
00208     dbe->tag(theModMEs.ClusterCharge,id); 
00209     // Cluster Charge Corrected
00210     theModMEs.ClusterChargeCorr=bookME1D("TH1ClusterChargeCorr", hidmanager.createHistoId("ClusterChargeCorr_OnTrack",name,id).c_str());
00211     dbe->tag(theModMEs.ClusterChargeCorr,id); 
00212     // Cluster StoN Corrected
00213     theModMEs.ClusterStoNCorr=bookME1D("TH1ClusterStoNCorrMod", hidmanager.createHistoId("ClusterStoNCorr_OnTrack",name,id).c_str());
00214     dbe->tag(theModMEs.ClusterStoNCorr,id); 
00215     // Cluster Position
00216     short total_nr_strips = SiStripDetCabling_->nApvPairs(id) * 2 * 128;
00217     theModMEs.ClusterPos=dbe->book1D(hidmanager.createHistoId("ClusterPosition_OnTrack",name,id).c_str(),hidmanager.createHistoId("ClusterPosition_OnTrack",name,id).c_str(),total_nr_strips,0.5,total_nr_strips+0.5);
00218     dbe->tag(theModMEs.ClusterPos,id); 
00219     // Cluster PGV
00220     theModMEs.ClusterPGV=bookMEProfile("TProfileClusterPGV", hidmanager.createHistoId("PGV_OnTrack",name,id).c_str()); 
00221     dbe->tag(theModMEs.ClusterPGV,id); 
00222 
00223     ModMEsMap[hid]=theModMEs;
00224   }
00225 }
00226 //
00227 // -- Book Layer Level Histograms and Trend plots
00228 //
00229 void SiStripMonitorTrack::bookLayerMEs(const uint32_t& mod_id, std::string& layer_id)
00230 {
00231   std::string name = "layer";  
00232   std::string hname;
00233   SiStripHistoId hidmanager;
00234 
00235   LayerMEs theLayerMEs; 
00236   theLayerMEs.ClusterStoNCorrOnTrack   = 0;
00237   theLayerMEs.ClusterChargeCorrOnTrack = 0;
00238   theLayerMEs.ClusterChargeOnTrack     = 0;
00239   theLayerMEs.ClusterChargeOffTrack    = 0;
00240   theLayerMEs.ClusterNoiseOnTrack      = 0;
00241   theLayerMEs.ClusterNoiseOffTrack     = 0;
00242   theLayerMEs.ClusterWidthOnTrack      = 0;
00243   theLayerMEs.ClusterWidthOffTrack     = 0;
00244   theLayerMEs.ClusterPosOnTrack        = 0;
00245   theLayerMEs.ClusterPosOffTrack       = 0;
00246   
00247   // Cluster StoN Corrected
00248   hname = hidmanager.createHistoLayer("Summary_ClusterStoNCorr",name,layer_id,"OnTrack");
00249   theLayerMEs.ClusterStoNCorrOnTrack = bookME1D("TH1ClusterStoNCorr", hname.c_str());
00250   
00251   // Cluster Charge Corrected
00252   hname = hidmanager.createHistoLayer("Summary_ClusterChargeCorr",name,layer_id,"OnTrack");
00253   theLayerMEs.ClusterChargeCorrOnTrack = bookME1D("TH1ClusterChargeCorr", hname.c_str());
00254   
00255   // Cluster Charge (On and Off Track)
00256   hname = hidmanager.createHistoLayer("Summary_ClusterCharge",name,layer_id,"OnTrack");
00257   theLayerMEs.ClusterChargeOnTrack = bookME1D("TH1ClusterCharge", hname.c_str());
00258   
00259   hname = hidmanager.createHistoLayer("Summary_ClusterCharge",name,layer_id,"OffTrack");
00260   theLayerMEs.ClusterChargeOffTrack = bookME1D("TH1ClusterCharge", hname.c_str());
00261   
00262   // Cluster Noise (On and Off Track)
00263   hname = hidmanager.createHistoLayer("Summary_ClusterNoise",name,layer_id,"OnTrack");
00264   theLayerMEs.ClusterNoiseOnTrack = bookME1D("TH1ClusterNoise", hname.c_str()); 
00265   
00266   hname = hidmanager.createHistoLayer("Summary_ClusterNoise",name,layer_id,"OffTrack");
00267   theLayerMEs.ClusterNoiseOffTrack = bookME1D("TH1ClusterNoise", hname.c_str()); 
00268   
00269   // Cluster Width (On and Off Track)
00270   hname = hidmanager.createHistoLayer("Summary_ClusterWidth",name,layer_id,"OnTrack");
00271   theLayerMEs.ClusterWidthOnTrack = bookME1D("TH1ClusterWidth", hname.c_str()); 
00272   
00273   hname = hidmanager.createHistoLayer("Summary_ClusterWidth",name,layer_id,"OffTrack");
00274   theLayerMEs.ClusterWidthOffTrack = bookME1D("TH1ClusterWidth", hname.c_str()); 
00275   
00276   //Cluster Position
00277   short total_nr_strips = SiStripDetCabling_->nApvPairs(mod_id) * 2 * 128; 
00278   if (layer_id.find("TEC") != std::string::npos && !flag_ring)  total_nr_strips = 3 * 2 * 128;
00279   
00280   hname = hidmanager.createHistoLayer("Summary_ClusterPosition",name,layer_id,"OnTrack");
00281   theLayerMEs.ClusterPosOnTrack = dbe->book1D(hname, hname, total_nr_strips, 0.5,total_nr_strips+0.5);
00282   
00283   hname = hidmanager.createHistoLayer("Summary_ClusterPosition",name,layer_id,"OffTrack");
00284   theLayerMEs.ClusterPosOffTrack = dbe->book1D(hname, hname, total_nr_strips, 0.5,total_nr_strips+0.5);
00285   
00286   //bookeeping
00287   LayerMEsMap[layer_id]=theLayerMEs;
00288 }
00289 //
00290 // -- Book Histograms at Sub-Detector Level
00291 //
00292 void SiStripMonitorTrack::bookSubDetMEs(std::string& name){
00293 
00294   std::string subdet_tag;
00295   subdet_tag = "__" + name;
00296   std::string completeName;
00297 
00298   SubDetMEs theSubDetMEs;
00299   theSubDetMEs.totNClustersOnTrack    = 0;
00300   theSubDetMEs.totNClustersOffTrack   = 0;
00301   theSubDetMEs.nClustersOnTrack       = 0;
00302   theSubDetMEs.nClustersTrendOnTrack  = 0;
00303   theSubDetMEs.nClustersOffTrack      = 0;
00304   theSubDetMEs.nClustersTrendOffTrack = 0;
00305   theSubDetMEs.ClusterStoNCorrOnTrack = 0;
00306   theSubDetMEs.ClusterChargeOffTrack  = 0;
00307   theSubDetMEs.ClusterStoNOffTrack    = 0;
00308 
00309   // TotalNumber of Cluster OnTrack
00310   completeName = "Summary_TotalNumberOfClusters_OnTrack" + subdet_tag;
00311   theSubDetMEs.nClustersOnTrack = bookME1D("TH1nClustersOn", completeName.c_str());
00312   theSubDetMEs.nClustersOnTrack->getTH1()->StatOverflows(kTRUE);
00313   
00314   // TotalNumber of Cluster OffTrack
00315   completeName = "Summary_TotalNumberOfClusters_OffTrack" + subdet_tag;
00316   theSubDetMEs.nClustersOffTrack = bookME1D("TH1nClustersOff", completeName.c_str());
00317   theSubDetMEs.nClustersOffTrack->getTH1()->StatOverflows(kTRUE);
00318   
00319   // Cluster StoN On Track
00320   completeName = "Summary_ClusterStoNCorr_OnTrack"  + subdet_tag;
00321   theSubDetMEs.ClusterStoNCorrOnTrack = bookME1D("TH1ClusterStoNCorr", completeName.c_str());
00322   
00323   // Cluster Charge Off Track
00324   completeName = "Summary_ClusterCharge_OffTrack" + subdet_tag;
00325   theSubDetMEs.ClusterChargeOffTrack=bookME1D("TH1ClusterCharge", completeName.c_str());
00326   
00327   // Cluster Charge StoN Off Track
00328   completeName = "Summary_ClusterStoN_OffTrack"  + subdet_tag;
00329   theSubDetMEs.ClusterStoNOffTrack = bookME1D("TH1ClusterStoN", completeName.c_str());
00330   
00331   if(Trend_On_){
00332     // TotalNumber of Cluster 
00333     completeName = "Trend_TotalNumberOfClusters_OnTrack"  + subdet_tag;
00334     theSubDetMEs.nClustersTrendOnTrack = bookMETrend("TH1nClustersOn", completeName.c_str());
00335     completeName = "Trend_TotalNumberOfClusters_OffTrack"  + subdet_tag;
00336     theSubDetMEs.nClustersTrendOffTrack = bookMETrend("TH1nClustersOff", completeName.c_str());
00337   }
00338   //bookeeping
00339   SubDetMEsMap[name]=theSubDetMEs;
00340 }
00341 //--------------------------------------------------------------------------------
00342 
00343 MonitorElement* SiStripMonitorTrack::bookME1D(const char* ParameterSetLabel, const char* HistoName)
00344 {
00345   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00346   return dbe->book1D(HistoName,HistoName,
00347                          Parameters.getParameter<int32_t>("Nbinx"),
00348                          Parameters.getParameter<double>("xmin"),
00349                          Parameters.getParameter<double>("xmax")
00350                     );
00351 }
00352 
00353 //--------------------------------------------------------------------------------
00354 MonitorElement* SiStripMonitorTrack::bookME2D(const char* ParameterSetLabel, const char* HistoName)
00355 {
00356   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00357   return dbe->book2D(HistoName,HistoName,
00358                      Parameters.getParameter<int32_t>("Nbinx"),
00359                      Parameters.getParameter<double>("xmin"),
00360                      Parameters.getParameter<double>("xmax"),
00361                      Parameters.getParameter<int32_t>("Nbiny"),
00362                      Parameters.getParameter<double>("ymin"),
00363                      Parameters.getParameter<double>("ymax")
00364                      );
00365 }
00366 
00367 //--------------------------------------------------------------------------------
00368 MonitorElement* SiStripMonitorTrack::bookME3D(const char* ParameterSetLabel, const char* HistoName)
00369 {
00370   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00371   return dbe->book3D(HistoName,HistoName,
00372                      Parameters.getParameter<int32_t>("Nbinx"),
00373                      Parameters.getParameter<double>("xmin"),
00374                      Parameters.getParameter<double>("xmax"),
00375                      Parameters.getParameter<int32_t>("Nbiny"),
00376                      Parameters.getParameter<double>("ymin"),
00377                      Parameters.getParameter<double>("ymax"),
00378                      Parameters.getParameter<int32_t>("Nbinz"),
00379                      Parameters.getParameter<double>("zmin"),
00380                      Parameters.getParameter<double>("zmax")
00381                      );
00382 }
00383 
00384 //--------------------------------------------------------------------------------
00385 MonitorElement* SiStripMonitorTrack::bookMEProfile(const char* ParameterSetLabel, const char* HistoName)
00386 {
00387     Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00388     return dbe->bookProfile(HistoName,HistoName,
00389                             Parameters.getParameter<int32_t>("Nbinx"),
00390                             Parameters.getParameter<double>("xmin"),
00391                             Parameters.getParameter<double>("xmax"),
00392                             Parameters.getParameter<int32_t>("Nbiny"),
00393                             Parameters.getParameter<double>("ymin"),
00394                             Parameters.getParameter<double>("ymax"),
00395                             "" );
00396 }
00397 
00398 //--------------------------------------------------------------------------------
00399 MonitorElement* SiStripMonitorTrack::bookMETrend(const char* ParameterSetLabel, const char* HistoName)
00400 {
00401   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00402   edm::ParameterSet ParametersTrend =  conf_.getParameter<edm::ParameterSet>("Trending");
00403   MonitorElement* me = dbe->bookProfile(HistoName,HistoName,
00404                                         ParametersTrend.getParameter<int32_t>("Nbins"),
00405                                         0,
00406                                         ParametersTrend.getParameter<int32_t>("Nbins"),
00407                                         100, //that parameter should not be there !?
00408                                         Parameters.getParameter<double>("xmin"),
00409                                         Parameters.getParameter<double>("xmax"),
00410                                         "" );
00411   if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) me->getTH1()->SetBit(TH1::kCanRebin);
00412 
00413   if(!me) return me;
00414   me->setAxisTitle("Event Time in Seconds",1);
00415   return me;
00416 }
00417 
00418 //------------------------------------------------------------------------------------------
00419  void SiStripMonitorTrack::trackStudy(const edm::Event& ev, const edm::EventSetup& es){
00420 
00421   // track input  
00422  
00423   edm::Handle<reco::TrackCollection > trackCollectionHandle;
00424   ev.getByLabel(TrackProducer_, TrackLabel_, trackCollectionHandle);//takes the track collection
00425   if (!trackCollectionHandle.isValid()){
00426     edm::LogError("SiStripMonitorTrack")<<" Track Collection is not valid !! " << TrackLabel_<<std::endl;
00427     return;
00428   }
00429   
00430   // trajectory input
00431   edm::Handle<TrajTrackAssociationCollection> TItkAssociatorCollection;
00432   ev.getByLabel(TrackProducer_, TrackLabel_, TItkAssociatorCollection);
00433   if( !TItkAssociatorCollection.isValid()){
00434     edm::LogError("SiStripMonitorTrack")<<"Association not found "<<std::endl;
00435     return;
00436   }
00437   
00438   //Perform track study
00439   int i=0;
00440   for(TrajTrackAssociationCollection::const_iterator it =  TItkAssociatorCollection->begin();it !=  TItkAssociatorCollection->end(); ++it){
00441     const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;  
00442     // Trajectory Map, extract Trajectory for this track
00443     reco::TrackRef trackref = it->val;
00444     LogDebug("SiStripMonitorTrack")
00445       << "Track number "<< i+1 
00446       << "\n\tmomentum: " << trackref->momentum()
00447       << "\n\tPT: " << trackref->pt()
00448       << "\n\tvertex: " << trackref->vertex()
00449       << "\n\timpact parameter: " << trackref->d0()
00450       << "\n\tcharge: " << trackref->charge()
00451       << "\n\tnormalizedChi2: " << trackref->normalizedChi2() 
00452       <<"\n\tFrom EXTRA : "
00453       <<"\n\t\touter PT "<< trackref->outerPt()<<std::endl;
00454     i++;
00455 
00456     const std::vector<TrajectoryMeasurement> & measurements = traj_iterator->measurements();
00457     std::vector<TrajectoryMeasurement>::const_iterator traj_mes_iterator;
00458     int nhit=0;
00459     for(std::vector<TrajectoryMeasurement>::const_iterator traj_mes_iterator= measurements.begin();traj_mes_iterator!=measurements.end();traj_mes_iterator++){//loop on measurements
00460       //trajectory local direction and position on detector
00461       LocalPoint  stateposition;
00462       LocalVector statedirection;
00463       
00464       TrajectoryStateOnSurface  updatedtsos=traj_mes_iterator->updatedState();
00465       ConstRecHitPointer ttrh=traj_mes_iterator->recHit();
00466       if (!ttrh->isValid()) {continue;}
00467       
00468       nhit++;
00469       
00470       const ProjectedSiStripRecHit2D* phit     = dynamic_cast<const ProjectedSiStripRecHit2D*>( ttrh->hit() );
00471       const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>( ttrh->hit() );
00472       const SiStripRecHit2D* hit2D             = dynamic_cast<const SiStripRecHit2D*>( ttrh->hit() );   
00473       const SiStripRecHit1D* hit1D             = dynamic_cast<const SiStripRecHit1D*>( ttrh->hit() );   
00474       
00475       //      RecHitType type=Single;
00476 
00477       if(matchedhit){
00478         LogTrace("SiStripMonitorTrack")<<"\nMatched recHit found"<< std::endl;
00479         //      type=Matched;
00480         
00481         GluedGeomDet * gdet=(GluedGeomDet *)tkgeom->idToDet(matchedhit->geographicalId());
00482         GlobalVector gtrkdirup=gdet->toGlobal(updatedtsos.localMomentum());         
00483         //mono side
00484         const GeomDetUnit * monodet=gdet->monoDet();
00485         statedirection=monodet->toLocal(gtrkdirup);
00486         SiStripRecHit2D m = matchedhit->monoHit();
00487         if(statedirection.mag() != 0)     RecHitInfo<SiStripRecHit2D>(&m,statedirection,trackref,es);
00488         //stereo side
00489         const GeomDetUnit * stereodet=gdet->stereoDet();
00490         statedirection=stereodet->toLocal(gtrkdirup);
00491         SiStripRecHit2D s = matchedhit->stereoHit();
00492         if(statedirection.mag() != 0)     RecHitInfo<SiStripRecHit2D>(&s,statedirection,trackref,es);
00493       }
00494       else if(phit){
00495         LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found"<< std::endl;
00496         //      type=Projected;
00497         GluedGeomDet * gdet=(GluedGeomDet *)tkgeom->idToDet(phit->geographicalId());
00498         
00499         GlobalVector gtrkdirup=gdet->toGlobal(updatedtsos.localMomentum());
00500         const SiStripRecHit2D&  originalhit=phit->originalHit();
00501         const GeomDetUnit * det;
00502         if(!StripSubdetector(originalhit.geographicalId().rawId()).stereo()){
00503           //mono side
00504           LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found  MONO"<< std::endl;
00505           det=gdet->monoDet();
00506           statedirection=det->toLocal(gtrkdirup);
00507           if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(&(phit->originalHit()),statedirection,trackref,es);
00508         }
00509         else{
00510           LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found STEREO"<< std::endl;
00511           //stereo side
00512           det=gdet->stereoDet();
00513           statedirection=det->toLocal(gtrkdirup);
00514           if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(&(phit->originalHit()),statedirection,trackref,es);
00515         }
00516       }else if (hit2D){
00517         statedirection=updatedtsos.localMomentum();
00518         if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(hit2D,statedirection,trackref,es);
00519       } else if (hit1D) {
00520         statedirection=updatedtsos.localMomentum();
00521         if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit1D>(hit1D,statedirection,trackref,es);
00522       } else {
00523         LogDebug ("SiStrioMonitorTrack") 
00524                  << " LocalMomentum: "<<statedirection
00525                  << "\nLocal x-z plane angle: "<<atan2(statedirection.x(),statedirection.z());
00526       }
00527     }
00528   }
00529 }
00530 
00531 template <class T> void SiStripMonitorTrack::RecHitInfo(const T* tkrecHit, LocalVector LV,reco::TrackRef track_ref, const edm::EventSetup& es){
00532     
00533     if(!tkrecHit->isValid()){
00534       LogTrace("SiStripMonitorTrack") <<"\t\t Invalid Hit " << std::endl;
00535       return;  
00536     }
00537     
00538     const uint32_t& detid = tkrecHit->geographicalId().rawId();
00539     if (find(ModulesToBeExcluded_.begin(),ModulesToBeExcluded_.end(),detid)!=ModulesToBeExcluded_.end()){
00540       LogTrace("SiStripMonitorTrack") << "Modules Excluded" << std::endl;
00541       return;
00542     }
00543     
00544     LogTrace("SiStripMonitorTrack")
00545       <<"\n\t\tRecHit on det "<<tkrecHit->geographicalId().rawId()
00546       <<"\n\t\tRecHit in LP "<<tkrecHit->localPosition()
00547       <<"\n\t\tRecHit in GP "<<tkgeom->idToDet(tkrecHit->geographicalId())->surface().toGlobal(tkrecHit->localPosition()) 
00548       <<"\n\t\tRecHit trackLocal vector "<<LV.x() << " " << LV.y() << " " << LV.z() <<std::endl; 
00549     
00550     //Get SiStripCluster from SiStripRecHit
00551     if ( tkrecHit != NULL ){
00552       const SiStripCluster* SiStripCluster_ = &*(tkrecHit->cluster());
00553       SiStripClusterInfo SiStripClusterInfo_(*SiStripCluster_,es,detid);
00554             
00555       if ( clusterInfos(&SiStripClusterInfo_,detid,OnTrack, LV ) ) {
00556         vPSiStripCluster.push_back(SiStripCluster_);
00557       }
00558     }else{
00559      edm::LogError("SiStripMonitorTrack") << "NULL hit" << std::endl;
00560     }     
00561   }
00562 
00563 //------------------------------------------------------------------------
00564 
00565 void SiStripMonitorTrack::AllClusters(const edm::Event& ev, const edm::EventSetup& es) 
00566 {
00567   edm::Handle< edmNew::DetSetVector<SiStripCluster> > siStripClusterHandle;
00568   ev.getByLabel( Cluster_src_, siStripClusterHandle); 
00569   if (!siStripClusterHandle.isValid()){
00570     edm::LogError("SiStripMonitorTrack")<< "ClusterCollection is not valid!!" << std::endl;
00571     return;
00572   }
00573   //Loop on Dets
00574   for ( edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter=siStripClusterHandle->begin(); DSViter!=siStripClusterHandle->end();DSViter++){
00575     uint32_t detid=DSViter->id();
00576     if (find(ModulesToBeExcluded_.begin(),ModulesToBeExcluded_.end(),detid)!=ModulesToBeExcluded_.end()) continue;
00577     //Loop on Clusters
00578     LogDebug("SiStripMonitorTrack") << "on detid "<< detid << " N Cluster= " << DSViter->size();
00579     edmNew::DetSet<SiStripCluster>::const_iterator ClusIter = DSViter->begin();
00580     for(; ClusIter!=DSViter->end(); ClusIter++) {
00581       if (std::find(vPSiStripCluster.begin(),vPSiStripCluster.end(),&*ClusIter) == vPSiStripCluster.end()){
00582         SiStripClusterInfo SiStripClusterInfo_(*ClusIter,es,detid);
00583         clusterInfos(&SiStripClusterInfo_,detid,OffTrack,LV);
00584       }
00585     }
00586   }
00587 }
00588 
00589 //------------------------------------------------------------------------
00590 bool SiStripMonitorTrack::clusterInfos(SiStripClusterInfo* cluster, const uint32_t& detid,enum ClusterFlags flag, const LocalVector LV)
00591 {
00592   if (cluster==0) return false;
00593   // if one imposes a cut on the clusters, apply it
00594   if( (applyClusterQuality_) &&
00595       (cluster->signalOverNoise() < sToNLowerLimit_ ||
00596        cluster->signalOverNoise() > sToNUpperLimit_ ||
00597        cluster->width() < widthLowerLimit_ ||
00598        cluster->width() > widthUpperLimit_) ) return false;
00599   // start of the analysis
00600   
00601   std::pair<std::string,std::string> sdet_pair = folderOrganizer_.getSubDetFolderAndTag(detid);
00602   std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.find(sdet_pair.second);
00603   if(iSubdet != SubDetMEsMap.end()){ 
00604     if (flag == OnTrack) iSubdet->second.totNClustersOnTrack++;
00605     else if (flag == OffTrack) iSubdet->second.totNClustersOffTrack++;
00606   }
00607   
00608   float cosRZ = -2;
00609   LogDebug("SiStripMonitorTrack")<< "\n\tLV " << LV.x() << " " << LV.y() << " " << LV.z() << " " << LV.mag() << std::endl;
00610   if (LV.mag()!=0){
00611     cosRZ= fabs(LV.z())/LV.mag();
00612     LogDebug("SiStripMonitorTrack")<< "\n\t cosRZ " << cosRZ << std::endl;
00613   }
00614   std::string name;
00615   
00616   // Filling SubDet/Layer Plots (on Track + off Track)
00617   fillMEs(cluster,detid,cosRZ,flag);
00618   
00619   
00620   //******** TkHistoMaps
00621   if (TkHistoMap_On_) {
00622     uint32_t adet=cluster->detId();
00623     float noise = cluster->noiseRescaledByGain();
00624     if(flag==OnTrack){
00625       tkhisto_NumOnTrack->add(adet,1.);
00626       if(noise > 0.0) tkhisto_StoNCorrOnTrack->fill(adet,cluster->signalOverNoise()*cosRZ);
00627       if(noise == 0.0) 
00628         LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise " << noise << std::endl;
00629     }
00630     else if(flag==OffTrack){
00631       tkhisto_NumOffTrack->add(adet,1.);
00632       if(cluster->charge() > 250){
00633         LogDebug("SiStripMonitorTrack") << "Module firing " << detid << " in Event " << eventNb << std::endl;
00634       }
00635     }
00636   }
00637 
00638   // Module plots filled only for onTrack Clusters
00639   if(Mod_On_){
00640     if(flag==OnTrack){
00641       SiStripHistoId hidmanager2;
00642       name =hidmanager2.createHistoId("","det",detid);
00643       fillModMEs(cluster,name,cosRZ); 
00644     }
00645   }
00646   return true;
00647 }
00648 
00649 //--------------------------------------------------------------------------------
00650 void SiStripMonitorTrack::fillModMEs(SiStripClusterInfo* cluster,std::string name,float cos)
00651 {
00652   std::map<std::string, ModMEs>::iterator iModME  = ModMEsMap.find(name);
00653   if(iModME!=ModMEsMap.end()){
00654 
00655     float    StoN     = cluster->signalOverNoise();
00656     uint16_t charge   = cluster->charge();
00657     uint16_t width    = cluster->width();
00658     float    position = cluster->baryStrip(); 
00659 
00660     float noise = cluster->noiseRescaledByGain();
00661     if(noise > 0.0) fillME(iModME->second.ClusterStoNCorr ,StoN*cos);
00662     if(noise == 0.0) LogDebug("SiStripMonitorTrack") << "Module " << name << " in Event " << eventNb << " noise " << noise << std::endl;
00663     fillME(iModME->second.ClusterCharge,charge);
00664 
00665     fillME(iModME->second.ClusterChargeCorr,charge*cos);
00666 
00667     fillME(iModME->second.ClusterWidth ,width);
00668     fillME(iModME->second.ClusterPos   ,position);
00669     
00670     //fill the PGV histo
00671     float PGVmax = cluster->maxCharge();
00672     int PGVposCounter = cluster->maxIndex();
00673     for (int i= int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmin"));i<PGVposCounter;++i)
00674       fillME(iModME->second.ClusterPGV, i,0.);
00675     for (std::vector<uint8_t>::const_iterator it=cluster->stripCharges().begin();it<cluster->stripCharges().end();++it) {
00676       fillME(iModME->second.ClusterPGV, PGVposCounter++,(*it)/PGVmax);
00677     }
00678     for (int i= PGVposCounter;i<int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmax"));++i)
00679       fillME(iModME->second.ClusterPGV, i,0.);
00680     //end fill the PGV histo
00681   }
00682 }
00683 
00684 //------------------------------------------------------------------------
00685 void SiStripMonitorTrack::fillMEs(SiStripClusterInfo* cluster,uint32_t detid,float cos, enum ClusterFlags flag)
00686 { 
00687   std::pair<std::string,int32_t> SubDetAndLayer = folderOrganizer_.GetSubDetAndLayer(detid,flag_ring);
00688   SiStripHistoId hidmanager1;
00689   std::string layer_id = hidmanager1.getSubdetid(detid,flag_ring); 
00690   
00691   std::pair<std::string,std::string> sdet_pair = folderOrganizer_.getSubDetFolderAndTag(detid);
00692   float    StoN     = cluster->signalOverNoise();
00693   float    noise    = cluster->noiseRescaledByGain();
00694   uint16_t charge   = cluster->charge();
00695   uint16_t width    = cluster->width();
00696   float    position = cluster->baryStrip(); 
00697    
00698   std::map<std::string, LayerMEs>::iterator iLayer  = LayerMEsMap.find(layer_id);
00699   if (iLayer != LayerMEsMap.end()) {
00700     if(flag==OnTrack){
00701       if(noise > 0.0) fillME(iLayer->second.ClusterStoNCorrOnTrack, StoN*cos);
00702       if(noise == 0.0) LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise " << cluster->noiseRescaledByGain() << std::endl;
00703       fillME(iLayer->second.ClusterChargeCorrOnTrack, charge*cos);
00704       fillME(iLayer->second.ClusterChargeOnTrack, charge);
00705       fillME(iLayer->second.ClusterNoiseOnTrack, noise);
00706       fillME(iLayer->second.ClusterWidthOnTrack, width);
00707       fillME(iLayer->second.ClusterPosOnTrack, position);
00708     } else {
00709       fillME(iLayer->second.ClusterChargeOffTrack, charge);
00710       fillME(iLayer->second.ClusterNoiseOffTrack, noise);
00711       fillME(iLayer->second.ClusterWidthOffTrack, width);
00712       fillME(iLayer->second.ClusterPosOffTrack, position);
00713     }
00714   }
00715   std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.find(sdet_pair.second);
00716   if(iSubdet != SubDetMEsMap.end() ){
00717     if(flag==OnTrack){
00718       if(noise > 0.0) fillME(iSubdet->second.ClusterStoNCorrOnTrack,StoN*cos);
00719     } else {
00720       fillME(iSubdet->second.ClusterChargeOffTrack,charge);
00721       if(noise > 0.0) fillME(iSubdet->second.ClusterStoNOffTrack,StoN);
00722     }
00723   }
00724 }
00725 //
00726 // -- Get Subdetector Tag from the Folder name
00727 //
00728 void SiStripMonitorTrack::getSubDetTag(std::string& folder_name, std::string& tag){
00729 
00730   tag =  folder_name.substr(folder_name.find("MechanicalView")+15);
00731   if (tag.find("side_") != std::string::npos) {
00732     tag.replace(tag.find_last_of("/"),1,"_");
00733   }
00734 }