CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/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         if(statedirection.mag() != 0)     RecHitInfo<SiStripRecHit2D>(matchedhit->monoHit(),statedirection,trackref,es);
00487         //stereo side
00488         const GeomDetUnit * stereodet=gdet->stereoDet();
00489         statedirection=stereodet->toLocal(gtrkdirup);
00490         if(statedirection.mag() != 0)     RecHitInfo<SiStripRecHit2D>(matchedhit->stereoHit(),statedirection,trackref,es);
00491       }
00492       else if(phit){
00493         LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found"<< std::endl;
00494         type=Projected;
00495         GluedGeomDet * gdet=(GluedGeomDet *)tkgeom->idToDet(phit->geographicalId());
00496         
00497         GlobalVector gtrkdirup=gdet->toGlobal(updatedtsos.localMomentum());
00498         const SiStripRecHit2D&  originalhit=phit->originalHit();
00499         const GeomDetUnit * det;
00500         if(!StripSubdetector(originalhit.geographicalId().rawId()).stereo()){
00501           //mono side
00502           LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found  MONO"<< std::endl;
00503           det=gdet->monoDet();
00504           statedirection=det->toLocal(gtrkdirup);
00505           if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(&(phit->originalHit()),statedirection,trackref,es);
00506         }
00507         else{
00508           LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found STEREO"<< std::endl;
00509           //stereo side
00510           det=gdet->stereoDet();
00511           statedirection=det->toLocal(gtrkdirup);
00512           if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(&(phit->originalHit()),statedirection,trackref,es);
00513         }
00514       }else if (hit2D){
00515         statedirection=updatedtsos.localMomentum();
00516         if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(hit2D,statedirection,trackref,es);
00517       } else if (hit1D) {
00518         statedirection=updatedtsos.localMomentum();
00519         if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit1D>(hit1D,statedirection,trackref,es);
00520       } else {
00521         LogDebug ("SiStrioMonitorTrack") 
00522                  << " LocalMomentum: "<<statedirection
00523                  << "\nLocal x-z plane angle: "<<atan2(statedirection.x(),statedirection.z());
00524       }
00525     }
00526   }
00527 }
00528 
00529 template <class T> void SiStripMonitorTrack::RecHitInfo(const T* tkrecHit, LocalVector LV,reco::TrackRef track_ref, const edm::EventSetup& es){
00530     
00531     if(!tkrecHit->isValid()){
00532       LogTrace("SiStripMonitorTrack") <<"\t\t Invalid Hit " << std::endl;
00533       return;  
00534     }
00535     
00536     const uint32_t& detid = tkrecHit->geographicalId().rawId();
00537     if (find(ModulesToBeExcluded_.begin(),ModulesToBeExcluded_.end(),detid)!=ModulesToBeExcluded_.end()){
00538       LogTrace("SiStripMonitorTrack") << "Modules Excluded" << std::endl;
00539       return;
00540     }
00541     
00542     LogTrace("SiStripMonitorTrack")
00543       <<"\n\t\tRecHit on det "<<tkrecHit->geographicalId().rawId()
00544       <<"\n\t\tRecHit in LP "<<tkrecHit->localPosition()
00545       <<"\n\t\tRecHit in GP "<<tkgeom->idToDet(tkrecHit->geographicalId())->surface().toGlobal(tkrecHit->localPosition()) 
00546       <<"\n\t\tRecHit trackLocal vector "<<LV.x() << " " << LV.y() << " " << LV.z() <<std::endl; 
00547     
00548     //Get SiStripCluster from SiStripRecHit
00549     if ( tkrecHit != NULL ){
00550       const SiStripCluster* SiStripCluster_ = &*(tkrecHit->cluster());
00551       SiStripClusterInfo SiStripClusterInfo_(*SiStripCluster_,es);
00552             
00553       if ( clusterInfos(&SiStripClusterInfo_,detid,"OnTrack", LV ) ) {
00554         vPSiStripCluster.push_back(SiStripCluster_);
00555       }
00556     }else{
00557      edm::LogError("SiStripMonitorTrack") << "NULL hit" << std::endl;
00558     }     
00559   }
00560 
00561 //------------------------------------------------------------------------
00562 
00563 void SiStripMonitorTrack::AllClusters(const edm::Event& ev, const edm::EventSetup& es) 
00564 {
00565   edm::Handle< edmNew::DetSetVector<SiStripCluster> > siStripClusterHandle;
00566   ev.getByLabel( Cluster_src_, siStripClusterHandle); 
00567   if (!siStripClusterHandle.isValid()){
00568     edm::LogError("SiStripMonitorTrack")<< "ClusterCollection is not valid!!" << std::endl;
00569     return;
00570   }
00571   //Loop on Dets
00572   for ( edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter=siStripClusterHandle->begin(); DSViter!=siStripClusterHandle->end();DSViter++){
00573     uint32_t detid=DSViter->id();
00574     if (find(ModulesToBeExcluded_.begin(),ModulesToBeExcluded_.end(),detid)!=ModulesToBeExcluded_.end()) continue;
00575     //Loop on Clusters
00576     LogDebug("SiStripMonitorTrack") << "on detid "<< detid << " N Cluster= " << DSViter->size();
00577     edmNew::DetSet<SiStripCluster>::const_iterator ClusIter = DSViter->begin();
00578     for(; ClusIter!=DSViter->end(); ClusIter++) {
00579       if (std::find(vPSiStripCluster.begin(),vPSiStripCluster.end(),&*ClusIter) == vPSiStripCluster.end()){
00580         SiStripClusterInfo SiStripClusterInfo_(*ClusIter,es);
00581         clusterInfos(&SiStripClusterInfo_,detid,"OffTrack",LV);
00582       }
00583     }
00584   }
00585 }
00586 
00587 //------------------------------------------------------------------------
00588 bool SiStripMonitorTrack::clusterInfos(SiStripClusterInfo* cluster, const uint32_t& detid,std::string flag, const LocalVector LV)
00589 {
00590   SiStripFolderOrganizer folder_organizer;
00591   if (cluster==0) return false;
00592   // if one imposes a cut on the clusters, apply it
00593   if( (applyClusterQuality_) &&
00594       (cluster->signalOverNoise() < sToNLowerLimit_ ||
00595        cluster->signalOverNoise() > sToNUpperLimit_ ||
00596        cluster->width() < widthLowerLimit_ ||
00597        cluster->width() > widthUpperLimit_) ) return false;
00598   // start of the analysis
00599   
00600   std::pair<std::string,std::string> sdet_pair = folder_organizer.getSubDetFolderAndTag(detid);
00601   std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.find(sdet_pair.second);
00602   if(iSubdet != SubDetMEsMap.end()){ 
00603     if (flag=="OnTrack") iSubdet->second.totNClustersOnTrack++;
00604     else if (flag=="OffTrack") iSubdet->second.totNClustersOffTrack++;
00605   }
00606   
00607   float cosRZ = -2;
00608   LogDebug("SiStripMonitorTrack")<< "\n\tLV " << LV.x() << " " << LV.y() << " " << LV.z() << " " << LV.mag() << std::endl;
00609   if (LV.mag()!=0){
00610     cosRZ= fabs(LV.z())/LV.mag();
00611     LogDebug("SiStripMonitorTrack")<< "\n\t cosRZ " << cosRZ << std::endl;
00612   }
00613   std::string name;
00614   
00615   // Filling SubDet/Layer Plots (on Track + off Track)
00616   fillMEs(cluster,detid,cosRZ,flag);
00617   
00618   
00619   //******** TkHistoMaps
00620   if (TkHistoMap_On_) {
00621     uint32_t adet=cluster->detId();
00622     if(flag=="OnTrack"){
00623       tkhisto_NumOnTrack->add(adet,1.);
00624       tkhisto_StoNCorrOnTrack->fill(adet,cluster->signalOverNoise()*cosRZ);
00625     }
00626     else if(flag=="OffTrack"){
00627       tkhisto_NumOffTrack->add(adet,1.);
00628       if(cluster->charge() > 250){
00629         LogDebug("SiStripMonitorTrack") << "Module firing " << detid << " in Event " << eventNb << std::endl;
00630       }
00631     }
00632   }
00633 
00634   // Module plots filled only for onTrack Clusters
00635   if(Mod_On_){
00636     if(flag=="OnTrack"){
00637       SiStripHistoId hidmanager2;
00638       name =hidmanager2.createHistoId("","det",detid);
00639       fillModMEs(cluster,name,cosRZ); 
00640     }
00641   }
00642   return true;
00643 }
00644 
00645 //--------------------------------------------------------------------------------
00646 void SiStripMonitorTrack::fillModMEs(SiStripClusterInfo* cluster,std::string name,float cos)
00647 {
00648   std::map<std::string, ModMEs>::iterator iModME  = ModMEsMap.find(name);
00649   if(iModME!=ModMEsMap.end()){
00650 
00651     float    StoN     = cluster->signalOverNoise();
00652     uint16_t charge   = cluster->charge();
00653     uint16_t width    = cluster->width();
00654     float    position = cluster->baryStrip(); 
00655 
00656     fillME(iModME->second.ClusterStoNCorr ,StoN*cos);
00657     fillME(iModME->second.ClusterCharge,charge);
00658 
00659     fillME(iModME->second.ClusterChargeCorr,charge*cos);
00660 
00661     fillME(iModME->second.ClusterWidth ,width);
00662     fillME(iModME->second.ClusterPos   ,position);
00663     
00664     //fill the PGV histo
00665     float PGVmax = cluster->maxCharge();
00666     int PGVposCounter = cluster->maxIndex();
00667     for (int i= int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmin"));i<PGVposCounter;++i)
00668       fillME(iModME->second.ClusterPGV, i,0.);
00669     for (std::vector<uint8_t>::const_iterator it=cluster->stripCharges().begin();it<cluster->stripCharges().end();++it) {
00670       fillME(iModME->second.ClusterPGV, PGVposCounter++,(*it)/PGVmax);
00671     }
00672     for (int i= PGVposCounter;i<int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmax"));++i)
00673       fillME(iModME->second.ClusterPGV, i,0.);
00674     //end fill the PGV histo
00675   }
00676 }
00677 
00678 //------------------------------------------------------------------------
00679 void SiStripMonitorTrack::fillMEs(SiStripClusterInfo* cluster,uint32_t detid,float cos, std::string flag)
00680 { 
00681   SiStripFolderOrganizer folder_organizer;
00682   std::pair<std::string,int32_t> SubDetAndLayer = folder_organizer.GetSubDetAndLayer(detid,flag_ring);
00683   SiStripHistoId hidmanager1;
00684   std::string layer_id = hidmanager1.getSubdetid(detid,flag_ring); 
00685   
00686   std::pair<std::string,std::string> sdet_pair = folder_organizer.getSubDetFolderAndTag(detid);
00687   float    StoN     = cluster->signalOverNoise();
00688   float    noise    = cluster->noiseRescaledByGain();
00689   uint16_t charge   = cluster->charge();
00690   uint16_t width    = cluster->width();
00691   float    position = cluster->baryStrip(); 
00692    
00693   std::map<std::string, LayerMEs>::iterator iLayer  = LayerMEsMap.find(layer_id);
00694   if (iLayer != LayerMEsMap.end()) {
00695     if(flag=="OnTrack"){
00696       fillME(iLayer->second.ClusterStoNCorrOnTrack, StoN*cos);
00697       fillME(iLayer->second.ClusterChargeCorrOnTrack, charge*cos);
00698       fillME(iLayer->second.ClusterChargeOnTrack, charge);
00699       fillME(iLayer->second.ClusterNoiseOnTrack, noise);
00700       fillME(iLayer->second.ClusterWidthOnTrack, width);
00701       fillME(iLayer->second.ClusterPosOnTrack, position);
00702     } else {
00703       fillME(iLayer->second.ClusterChargeOffTrack, charge);
00704       fillME(iLayer->second.ClusterNoiseOffTrack, noise);
00705       fillME(iLayer->second.ClusterWidthOffTrack, width);
00706       fillME(iLayer->second.ClusterPosOffTrack, position);
00707     }
00708   }
00709   std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.find(sdet_pair.second);
00710   if(iSubdet != SubDetMEsMap.end() ){
00711     if(flag=="OnTrack"){
00712       fillME(iSubdet->second.ClusterStoNCorrOnTrack,StoN*cos);
00713     } else {
00714       fillME(iSubdet->second.ClusterChargeOffTrack,charge);
00715       fillME(iSubdet->second.ClusterStoNOffTrack,StoN);
00716     }
00717   }
00718 }
00719 //
00720 // -- Get Subdetector Tag from the Folder name
00721 //
00722 void SiStripMonitorTrack::getSubDetTag(std::string& folder_name, std::string& tag){
00723 
00724   tag =  folder_name.substr(folder_name.find("MechanicalView")+15);
00725   if (tag.find("side_") != std::string::npos) {
00726     tag.replace(tag.find_last_of("/"),1,"_");
00727   }
00728 }