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