CMS 3D CMS Logo

DTLocalTriggerTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file DTLocalTriggerTask.cc
00003  * 
00004  * $Date: 2008/11/18 17:45:31 $
00005  * $Revision: 1.31 $
00006  * \author M. Zanetti - INFN Padova
00007  *
00008 */
00009 
00010 #include "DQM/DTMonitorModule/interface/DTLocalTriggerTask.h"
00011 
00012 // Framework
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 
00015 // DT trigger
00016 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
00017 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h"
00018 #include "DataFormats/LTCDigi/interface/LTCDigi.h"
00019 
00020 // Geometry
00021 #include "DataFormats/GeometryVector/interface/Pi.h"
00022 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00023 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00024 #include "Geometry/DTGeometry/interface/DTLayer.h"
00025 #include "Geometry/DTGeometry/interface/DTTopology.h"
00026 
00027 //Root
00028 #include"TH1.h"
00029 #include"TAxis.h"
00030 
00031 #include <sstream>
00032 #include <iostream>
00033 #include <fstream>
00034 
00035 
00036 using namespace edm;
00037 using namespace std;
00038 
00039 DTLocalTriggerTask::DTLocalTriggerTask(const edm::ParameterSet& ps){
00040   
00041   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Constructor"<<endl;
00042 
00043   tpMode           = ps.getUntrackedParameter<bool>("testPulseMode", false);
00044   detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis", false);
00045   doDCCTheta       = ps.getUntrackedParameter<bool>("enableDCCTheta", false);
00046   
00047   if (tpMode) {
00048     baseFolder = "DT/11-LocalTriggerTP/";
00049   }
00050   else {
00051     baseFolder = "DT/03-LocalTrigger/";
00052   }
00053 
00054   parameters = ps;
00055   
00056   dbe = edm::Service<DQMStore>().operator->();
00057 
00058 }
00059 
00060 
00061 DTLocalTriggerTask::~DTLocalTriggerTask() {
00062 
00063   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: analyzed " << nevents << " events" << endl;
00064 
00065 }
00066 
00067 
00068 void DTLocalTriggerTask::beginJob(const edm::EventSetup& context){
00069 
00070  
00071   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: BeginJob" << endl;
00072 
00073   context.get<MuonGeometryRecord>().get(muonGeom);
00074   nevents = 0;
00075 
00076   if(parameters.getUntrackedParameter<bool>("staticBooking", true)) {  // Static histo booking
00077    
00078     vector<string> trigSources;
00079     if(parameters.getUntrackedParameter<bool>("localrun", true)) {
00080       trigSources.push_back("");
00081     }
00082     else {
00083       trigSources.push_back("_DTonly");
00084       trigSources.push_back("_NoDT");
00085       trigSources.push_back("_DTalso");
00086     }
00087     vector<string>::const_iterator trigSrcIt  = trigSources.begin();
00088     vector<string>::const_iterator trigSrcEnd = trigSources.end();
00089    
00090     if(parameters.getUntrackedParameter<bool>("process_dcc", true)) {
00091       bookCMSHistos("DCC_ErrorsChamberID");
00092     }
00093     
00094     if (tpMode) {
00095       for (int stat=1;stat<5;++stat){
00096         for (int wh=-2;wh<3;++wh){
00097           for (int sect=1;sect<13;++sect){
00098             DTChamberId dtChId(wh,stat,sect);
00099             
00100             if (parameters.getUntrackedParameter<bool>("process_dcc", true)){ // DCC data
00101               bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+(*trigSrcIt));
00102               bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+(*trigSrcIt));
00103             }
00104             
00105             if (parameters.getUntrackedParameter<bool>("process_ros", true)){ // DDU data             
00106               bookHistos(dtChId,"LocalTriggerPhi","DDU_BXvsQual"+(*trigSrcIt));
00107             }
00108             
00109           }
00110         }
00111       } // end of loop
00112     }
00113     else {
00114       for (;trigSrcIt!=trigSrcEnd;++trigSrcIt){
00115         for (int stat=1;stat<5;++stat){
00116           for (int wh=-2;wh<3;++wh){
00117             for (int sect=1;sect<13;++sect){
00118               DTChamberId dtChId(wh,stat,sect);
00119             
00120               if (parameters.getUntrackedParameter<bool>("process_dcc", true)){ // DCC data
00121               
00122                 bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+(*trigSrcIt));
00123                 if (detailedAnalysis) {
00124                   bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+(*trigSrcIt));
00125                   bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhibend"+(*trigSrcIt));
00126                 }
00127                 bookHistos(dtChId,"LocalTriggerPhi","DCC_Flag1stvsQual"+(*trigSrcIt));
00128                 bookHistos(dtChId,"LocalTriggerPhi","DCC_BestQual"+(*trigSrcIt));
00129                 if (stat!=4 && doDCCTheta){                                                   // theta view
00130                   if (detailedAnalysis) {
00131                     bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsBX"+(*trigSrcIt));
00132                     bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsQual"+(*trigSrcIt));
00133                   }
00134                   bookHistos(dtChId,"LocalTriggerTheta","DCC_ThetaBXvsQual"+(*trigSrcIt));
00135                   bookHistos(dtChId,"LocalTriggerTheta","DCC_ThetaBestQual"+(*trigSrcIt));
00136                 }
00137               
00138                 if (parameters.getUntrackedParameter<bool>("process_seg", true)){ // DCC + Segemnt
00139                   bookHistos(dtChId,"Segment","DCC_PhitkvsPhitrig"+(*trigSrcIt));
00140                   bookHistos(dtChId,"Segment","DCC_PhibtkvsPhibtrig"+(*trigSrcIt));
00141                   bookHistos(dtChId,"Segment","DCC_PhiResidual"+(*trigSrcIt));
00142                   bookHistos(dtChId,"Segment","DCC_PhibResidual"+(*trigSrcIt));
00143                   bookHistos(dtChId,"Segment","DCC_HitstkvsQualtrig"+(*trigSrcIt));
00144                   bookHistos(dtChId,"Segment","DCC_TrackPosvsAngle"+(*trigSrcIt));
00145                   bookHistos(dtChId,"Segment","DCC_TrackPosvsAngleandTrig"+(*trigSrcIt));
00146                   bookHistos(dtChId,"Segment","DCC_TrackPosvsAngleandTrigHHHL"+(*trigSrcIt));
00147                   if(stat!=4){
00148                     bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngle"+(*trigSrcIt)); // theta view
00149                     bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngleandTrig"+(*trigSrcIt));
00150                     bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngleandTrigH"+(*trigSrcIt));
00151                   }
00152                 }
00153               
00154               }
00155             
00156               if (parameters.getUntrackedParameter<bool>("process_ros", true)){ // DDU data
00157               
00158                 bookHistos(dtChId,"LocalTriggerPhi","DDU_BXvsQual"+(*trigSrcIt));
00159                 bookHistos(dtChId,"LocalTriggerPhi","DDU_Flag1stvsQual"+(*trigSrcIt));
00160                 bookHistos(dtChId,"LocalTriggerPhi","DDU_BestQual"+(*trigSrcIt));
00161                 if(stat!=4){                                                    // theta view
00162                   bookHistos(dtChId,"LocalTriggerTheta","DDU_ThetaBXvsQual"+(*trigSrcIt));
00163                   bookHistos(dtChId,"LocalTriggerTheta","DDU_ThetaBestQual"+(*trigSrcIt));
00164                 }
00165               
00166                 if (parameters.getUntrackedParameter<bool>("process_seg", true)){ // DDU + Segment
00167                   bookHistos(dtChId,"Segment","DDU_HitstkvsQualtrig"+(*trigSrcIt));
00168                   bookHistos(dtChId,"Segment","DDU_TrackPosvsAngle"+(*trigSrcIt));
00169                   bookHistos(dtChId,"Segment","DDU_TrackPosvsAngleandTrig"+(*trigSrcIt));
00170                   bookHistos(dtChId,"Segment","DDU_TrackPosvsAngleandTrigHHHL"+(*trigSrcIt));
00171                   if(stat!=4){
00172                     bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngle"+(*trigSrcIt)); // theta view
00173                     bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrig"+(*trigSrcIt));
00174                     bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrigH"+(*trigSrcIt));
00175                   }
00176                 }
00177               
00178               }
00179             
00180               if (parameters.getUntrackedParameter<bool>("process_dcc", true) &&
00181                   parameters.getUntrackedParameter<bool>("process_ros", true)){ // DCC+DDU data
00182                 bookHistos(dtChId,"LocalTriggerPhi","COM_QualDDUvsQualDCC"+(*trigSrcIt));
00183               }
00184             
00185             }
00186           }
00187         }
00188       }// end of loop
00189     }
00190     
00191   }
00192   
00193 }
00194 
00195 void DTLocalTriggerTask::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00196   
00197   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Begin of LS transition" << endl;
00198   
00199   if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
00200     for(map<uint32_t, map<string, MonitorElement*> > ::const_iterator histo = digiHistos.begin();
00201         histo != digiHistos.end();
00202         histo++) {
00203       for(map<string, MonitorElement*> ::const_iterator ht = (*histo).second.begin();
00204           ht != (*histo).second.end();
00205           ht++) {
00206         (*ht).second->Reset();
00207       }
00208     }
00209   }
00210   
00211 }
00212 
00213 
00214 void DTLocalTriggerTask::endJob(){
00215 
00216   LogVerbatim("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: analyzed " << nevents << " events" << endl;
00217   dbe->rmdir(topFolder());
00218 
00219 }
00220 
00221 
00222 void DTLocalTriggerTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00223   
00224   string dcc_label  = parameters.getUntrackedParameter<string>("dcc_label", "dttpgprod");
00225   string ros_label  = parameters.getUntrackedParameter<string>("ros_label", "dtunpacker");
00226   string seg_label  = parameters.getUntrackedParameter<string>("seg_label", "dt4DSegments");
00227 
00228   if (!nevents){
00229 
00230     edm::Handle<L1MuDTChambPhContainer> l1DTTPGPh;
00231     e.getByLabel(dcc_label, l1DTTPGPh);
00232     edm::Handle<L1MuDTChambThContainer> l1DTTPGTh;
00233     e.getByLabel(dcc_label, l1DTTPGTh);
00234     useDCC = (l1DTTPGPh.isValid() || l1DTTPGTh.isValid()) && parameters.getUntrackedParameter<bool>("process_dcc", true) ;
00235 
00236     Handle<DTLocalTriggerCollection> l1DDUTrigs;
00237     e.getByLabel(ros_label,l1DDUTrigs);
00238     useDDU = l1DDUTrigs.isValid() && parameters.getUntrackedParameter<bool>("process_ros", true) ;
00239 
00240     Handle<DTRecSegment4DCollection> all4DSegments;
00241     e.getByLabel(seg_label, all4DSegments);  
00242     useSEG = all4DSegments.isValid() && parameters.getUntrackedParameter<bool>("process_seg", true) ;
00243     
00244   }
00245 
00246   nevents++;
00247     
00248   triggerSource(e);  
00249 
00250   if ( useDCC ) {   
00251     edm::Handle<L1MuDTChambPhContainer> l1DTTPGPh;
00252     e.getByLabel(dcc_label,l1DTTPGPh);
00253     vector<L1MuDTChambPhDigi>*  l1PhTrig = l1DTTPGPh->getContainer();
00254 
00255     edm::Handle<L1MuDTChambThContainer> l1DTTPGTh;
00256     e.getByLabel(dcc_label,l1DTTPGTh);
00257     vector<L1MuDTChambThDigi>*  l1ThTrig = l1DTTPGTh->getContainer();
00258 
00259     runDCCAnalysis(l1PhTrig,l1ThTrig);
00260   }  
00261   if ( useDDU ) {
00262     Handle<DTLocalTriggerCollection> l1DDUTrigs;
00263     e.getByLabel(ros_label,l1DDUTrigs);
00264 
00265     runDDUAnalysis(l1DDUTrigs);
00266   }
00267   if ( !tpMode && useSEG ) {
00268     Handle<DTRecSegment4DCollection> segments4D;
00269     e.getByLabel(seg_label, segments4D);  
00270     
00271     runSegmentAnalysis(segments4D);
00272   } 
00273   if ( !tpMode && useDCC && useDDU ) {
00274     runDDUvsDCCAnalysis(trigsrc);
00275   }
00276 
00277 }
00278 
00279 
00280 void DTLocalTriggerTask::bookCMSHistos(string histoTag) {
00281 
00282   string hwFolder = histoTag.substr(0,3) == "DCC" ? "DCC/" : "";
00283   dbe->setCurrentFolder(topFolder()+hwFolder);
00284   if (histoTag == "DCC_ErrorsChamberID") {
00285     dcc_IDDataErrorPlot = dbe->book1D(histoTag.c_str(),"DCC Data ID Error",5,-2,3);
00286     dcc_IDDataErrorPlot->setAxisTitle("wheel",1);
00287   }
00288   
00289   return;
00290 
00291 }
00292 
00293 void DTLocalTriggerTask::bookHistos(const DTChamberId& dtCh, string folder, string histoTag) {
00294   
00295   int wh=dtCh.wheel();          
00296   int sc=dtCh.sector(); 
00297   stringstream wheel; wheel << wh;      
00298   stringstream station; station << dtCh.station();      
00299   stringstream sector; sector << sc;    
00300 
00301   double minBX=0;
00302   double maxBX=0;
00303   int  rangeBX=0;
00304 
00305   string histoType = histoTag.substr(4,histoTag.find("_",4)-4);
00306   string hwFolder = histoTag.substr(0,3) == "DCC" ? "DCC/" : ""; 
00307 
00308   dbe->setCurrentFolder(topFolder() + hwFolder + "Wheel" + wheel.str() +
00309                         "/Sector" + sector.str() +
00310                         "/Station" + station.str() + "/" + folder);
00311 
00312   string histoName = histoTag + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00313     
00314   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: booking " << topFolder() << hwFolder << "Wheel" << wheel.str()
00315                                                        << "/Sector" << sector.str()
00316                                                        << "/Station"<< station.str() << "/" << folder << "/" << histoName << endl;
00317     
00318   if (histoType.find("BX") != string::npos){
00319     if (histoTag.substr(0,3) == "DCC"){
00320       minBX= parameters.getUntrackedParameter<int>("minBXDCC",-2) - 0.5;
00321       maxBX= parameters.getUntrackedParameter<int>("maxBXDCC",2) + 0.5;
00322     }
00323     else {
00324       minBX= parameters.getUntrackedParameter<int>("minBXDDU",0) - 0.5;
00325       maxBX= parameters.getUntrackedParameter<int>("maxBXDDU",20) + 0.5;
00326     }
00327     rangeBX = (int)(maxBX-minBX);
00328   }
00329     
00330   if ( folder == "LocalTriggerPhi") {
00331       
00332     if( histoType == "BXvsQual" ){
00333       (digiHistos[dtCh.rawId()])[histoTag] = 
00334         dbe->book2D(histoName,"BX vs trigger quality",7,-0.5,6.5,rangeBX,minBX,maxBX);
00335       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00336       return ;
00337     }
00338     if( histoType == "BestQual" ){
00339       (digiHistos[dtCh.rawId()])[histoTag] = 
00340         dbe->book1D(histoName,"Trigger quality of best primitives",7,-0.5,6.5);
00341       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00342       return ;
00343     }
00344     if( histoType == "QualvsPhirad" ){
00345       (digiHistos[dtCh.rawId()])[histoTag] = 
00346         dbe->book2D(histoName,"Trigger quality vs local position",100,-500.,500.,7,-0.5,6.5);
00347       setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);
00348       return ;
00349     }
00350     if( histoType == "QualvsPhibend" ) { 
00351       (digiHistos[dtCh.rawId()])[histoTag] = 
00352         dbe->book2D(histoName,"Trigger quality vs local direction",200,-40.,40.,7,-0.5,6.5);
00353       setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);      
00354       return ;
00355     }
00356     if( histoType == "Flag1stvsQual" ) {
00357       (digiHistos[dtCh.rawId()])[histoTag] = 
00358         dbe->book2D(histoName,"1st/2nd trig flag vs quality",7,-0.5,6.5,2,-0.5,1.5);
00359       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00360       return ;
00361     }
00362     if( histoType == "QualDDUvsQualDCC" ){
00363       (digiHistos[dtCh.rawId()])[histoTag] = 
00364         dbe->book2D(histoName,"DDU quality vs DCC quality",8,-1.5,6.5,8,-1.5,6.5);
00365       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00366       setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);      
00367       return ;
00368     }    
00369       
00370   }
00371   else if ( folder == "LocalTriggerTheta")   {
00372       
00373     if( histoType == "PositionvsBX" ) {
00374       (digiHistos[dtCh.rawId()])[histoTag] = 
00375         dbe->book2D(histoName,"Theta trigger position vs BX",rangeBX,minBX,maxBX,7,-0.5,6.5);
00376       return ;
00377     }
00378     if( histoType == "PositionvsQual" ) {
00379       (digiHistos[dtCh.rawId()])[histoTag] = 
00380         dbe->book2D(histoName,"Theta trigger position vs quality",7,-0.5,6.5,7,-0.5,6.5);
00381       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00382       return ;
00383     }  
00384     if( histoType == "ThetaBXvsQual" ) {
00385       (digiHistos[dtCh.rawId()])[histoTag] = 
00386         dbe->book2D(histoName,"BX vs trigger quality",7,-0.5,6.5,rangeBX,minBX,maxBX);
00387       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00388     }
00389     if( histoType == "ThetaBestQual" ){
00390       (digiHistos[dtCh.rawId()])[histoTag] = 
00391         dbe->book1D(histoName,"Trigger quality of best primitives (theta)",7,-0.5,6.5);
00392       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00393       return ;
00394     }
00395 
00396   }
00397   else if ( folder == "Segment")   {
00398       
00399     if( histoType.find("TrackThetaPosvsAngle" ) == 0 ) {
00400 
00401       string histoLabel = "Position vs Angle (theta)";
00402       if (histoType.find("andTrigH") != string::npos) histoLabel += " for H triggers";
00403       else if (histoType.find("andTrig") != string::npos) histoLabel += " for triggers";
00404 
00405       (digiHistos[dtCh.rawId()])[histoTag] = 
00406         dbe->book2D(histoName,histoLabel,16,-40.,40.,20,-117.5,117.5);
00407       return ;
00408     }
00409     if( histoType.find("TrackPosvsAngle") == 0 ){
00410 
00411       pair<float,float> range = phiRange(dtCh);
00412       int nbins = int((range.second - range.first)/15);
00413 
00414       string histoLabel = "Position vs Angle (phi)";
00415       if (histoType.find("andTrigHHHL")  != string::npos) histoLabel += " for HH/HL triggers";
00416       else if (histoType.find("andTrig") != string::npos) histoLabel += " for triggers";
00417 
00418       (digiHistos[dtCh.rawId()])[histoTag] = 
00419         dbe->book2D(histoName,histoLabel,16,-40.,40.,nbins,range.first,range.second);
00420       return ;
00421     }
00422     if( histoType == "PhitkvsPhitrig" ){ 
00423       (digiHistos[dtCh.rawId()])[histoTag] = 
00424         dbe->book2D(histoName,"Local position: segment vs trigger",100,-500.,500.,100,-500.,500.);
00425       return ;
00426     }
00427     if( histoType == "PhibtkvsPhibtrig" ){ 
00428       (digiHistos[dtCh.rawId()])[histoTag] = 
00429         dbe->book2D(histoName,"Local direction : segment vs trigger",200,-40.,40.,200,-40.,40.);
00430       return ;
00431     }
00432     if( histoType == "PhiResidual" ){ 
00433       (digiHistos[dtCh.rawId()])[histoTag] = 
00434         dbe->book1D(histoName,"Trigger local position - Segment local position (correlated triggers)",400,-10.,10.);
00435       return ;
00436     }
00437     if( histoType == "PhibResidual" ){ 
00438       (digiHistos[dtCh.rawId()])[histoTag] = 
00439         dbe->book1D(histoName,"Trigger local direction - Segment local direction (correlated triggers)",500,-10.,10.);
00440       return ;
00441     }
00442     if( histoType == "HitstkvsQualtrig" ){ 
00443       (digiHistos[dtCh.rawId()])[histoTag] = 
00444         dbe->book2D(histoName,"Segment hits (phi) vs trigger quality",7,-0.5,6.5,10,0.5,10.5);
00445       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00446       return ;
00447     }
00448 
00449   }
00450 
00451 }
00452 
00453 void DTLocalTriggerTask::runDCCAnalysis( std::vector<L1MuDTChambPhDigi>* phTrigs, 
00454                                          std::vector<L1MuDTChambThDigi>* thTrigs ){
00455 
00456   string histoType ;
00457   string histoTag ;
00458 
00459   // define best quality trigger segment (phi and theta)  
00460   // in any station start from 1 and zero is kept empty
00461   for (int i=0;i<5;++i){
00462     for (int j=0;j<6;++j){
00463       for (int k=0;k<13;++k){
00464         phcode_best[j][i][k] = -1;
00465         thcode_best[j][i][k] = -1;
00466       }
00467     }
00468   }
00469 
00470   vector<L1MuDTChambPhDigi>::const_iterator iph  = phTrigs->begin();
00471   vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
00472   for(; iph !=iphe ; ++iph) {
00473 
00474     int phwheel = iph->whNum();
00475     int phsec   = iph->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
00476     int phst    = iph->stNum();
00477     int phbx    = iph->bxNum();
00478     int phcode  = iph->code();
00479     int phi1st  = iph->Ts2Tag();
00480     int phphi   = iph->phi();
00481     int phphiB  = iph->phiB();
00482 
00483     // FIXME: workaround for DCC data with station ID 
00484     if(phst == 0) {
00485       dcc_IDDataErrorPlot->Fill(phwheel);
00486       continue;
00487     }
00488 
00489     if(phcode>phcode_best[phwheel+3][phst][phsec] && phcode<7) {
00490       phcode_best[phwheel+3][phst][phsec]=phcode; 
00491       iphbest[phwheel+3][phst][phsec] = &(*iph);
00492     }
00493       
00494     DTChamberId dtChId(phwheel,phst,phsec);
00495       
00496     float x     = phi2Pos(dtChId,phphi);
00497     float angle = phib2Ang(dtChId,phphiB,phphi);
00498     uint32_t indexCh = dtChId.rawId();
00499     
00500     map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00501     if (innerME.find("DCC_BXvsQual"+trigsrc) == innerME.end()){
00502       if (tpMode) {
00503         bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+trigsrc);
00504         bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+trigsrc);
00505       }
00506       else {
00507         bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+trigsrc);
00508         bookHistos(dtChId,"LocalTriggerPhi","DCC_Flag1stvsQual"+trigsrc);
00509         if (detailedAnalysis) {
00510           bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+trigsrc);
00511           bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhibend"+trigsrc);
00512         }
00513       }
00514     }
00515 
00516     if (tpMode) {
00517       innerME.find("DCC_BXvsQual"+trigsrc)->second->Fill(phcode,phbx-phi1st);    // SM BX vs Qual Phi view (1st tracks) 
00518       innerME.find("DCC_QualvsPhirad"+trigsrc)->second->Fill(x,phcode);          // SM Qual vs radial angle Phi view
00519     }
00520     else {
00521       innerME.find("DCC_BXvsQual"+trigsrc)->second->Fill(phcode,phbx-phi1st);    // SM BX vs Qual Phi view (1st tracks) 
00522       innerME.find("DCC_Flag1stvsQual"+trigsrc)->second->Fill(phcode,phi1st);    // SM Qual 1st/2nd track flag Phi view
00523       if (detailedAnalysis) {
00524         innerME.find("DCC_QualvsPhirad"+trigsrc)->second->Fill(x,phcode);          // SM Qual vs radial angle Phi view
00525         innerME.find("DCC_QualvsPhibend"+trigsrc)->second->Fill(angle,phcode);     // SM Qual vs bending Phi view
00526       }
00527     }
00528       
00529   } 
00530 
00531   if (doDCCTheta) {
00532     int thcode[7];
00533     vector<L1MuDTChambThDigi>::const_iterator ith  = thTrigs->begin();
00534     vector<L1MuDTChambThDigi>::const_iterator ithe = thTrigs->end();
00535     for(; ith != ithe; ++ith) {
00536       int thwheel = ith->whNum();
00537       int thsec   = ith->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
00538       int thst    = ith->stNum();
00539       int thbx    = ith->bxNum();
00540       
00541       for (int pos=0; pos<7; pos++) {
00542         thcode[pos] = ith->code(pos);
00543 
00544         if(thcode[pos]>thcode_best[thwheel+3][thst][thsec] ) {
00545           thcode_best[thwheel+3][thst][thsec]=thcode[pos]; 
00546           ithbest[thwheel+3][thst][thsec] = &(*ith);
00547         }
00548       } 
00549       
00550       DTChamberId dtChId(thwheel,thst,thsec);
00551       uint32_t indexCh = dtChId.rawId();   
00552 
00553       map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00554       if (innerME.find("DCC_ThetaBXvsQual"+trigsrc) == innerME.end()){
00555         bookHistos(dtChId,"LocalTriggerTheta","DCC_ThetaBXvsQual"+trigsrc);
00556         if (detailedAnalysis) {
00557           bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsBX"+trigsrc);
00558           bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsQual"+trigsrc);
00559         }
00560       }
00561 
00562       for (int pos=0; pos<7; pos++) { //SM fill position for non zero position bit in theta view
00563         if(thcode[pos]>0){
00564           int thqual = (thcode[pos]/2)*2+1;
00565           innerME.find("DCC_ThetaBXvsQual"+trigsrc)->second->Fill(thqual,thbx);      // SM BX vs Code Theta view
00566           if (detailedAnalysis) {
00567             innerME.find("DCC_PositionvsBX"+trigsrc)->second->Fill(thbx,pos);          // SM BX vs Position Theta view
00568             innerME.find("DCC_PositionvsQual"+trigsrc)->second->Fill(thqual,pos);      // SM Code vs Position Theta view
00569           }
00570         }
00571       }
00572     }
00573   }
00574 
00575   
00576   // Fill Quality plots with best DCC triggers in phi & theta
00577   if (!tpMode) {
00578     for (int st=1;st<5;++st){
00579       for (int wh=-2;wh<3;++wh){
00580         for (int sc=1;sc<13;++sc){
00581           if (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7){
00582             DTChamberId id(wh,st,sc);
00583             uint32_t indexCh = id.rawId();
00584             map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00585             if (innerME.find("DCC_BestQual"+trigsrc) == innerME.end())
00586               bookHistos(id,"LocalTriggerPhi","DCC_BestQual"+trigsrc);
00587             innerME.find("DCC_BestQual"+trigsrc)->second->Fill(phcode_best[wh+3][st][sc]);  // CB Best Qual Trigger Phi view
00588           }
00589           if (thcode_best[wh+3][st][sc]>0){
00590             DTChamberId id(wh,st,sc);
00591             uint32_t indexCh = id.rawId();
00592             map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00593             if (innerME.find("DCC_ThetaBestQual"+trigsrc) == innerME.end())
00594               bookHistos(id,"LocalTriggerTheta","DCC_ThetaBestQual"+trigsrc);
00595             innerME.find("DCC_ThetaBestQual"+trigsrc)->second->Fill(thcode_best[wh+3][st][sc]); // CB Best Qual Trigger Theta view
00596           }
00597         }
00598       }
00599     }
00600   }
00601 
00602 }
00603 
00604 void DTLocalTriggerTask::runDDUAnalysis(Handle<DTLocalTriggerCollection>& trigsDDU){
00605     
00606   DTLocalTriggerCollection::DigiRangeIterator detUnitIt;
00607     
00608   for (int i=0;i<5;++i){
00609     for (int j=0;j<6;++j){
00610       for (int k=0;k<13;++k){
00611         dduphcode_best[j][i][k] = -1;
00612         dduthcode_best[j][i][k] = -1;
00613       }
00614     }
00615   }
00616 
00617   for (detUnitIt=trigsDDU->begin();
00618        detUnitIt!=trigsDDU->end();
00619        ++detUnitIt){
00620       
00621     const DTChamberId& id = (*detUnitIt).first;
00622     const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
00623     uint32_t indexCh = id.rawId();
00624     map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00625       
00626     int wh = id.wheel();
00627     int sec = id.sector();
00628     int st = id.station();
00629 
00630     for (DTLocalTriggerCollection::const_iterator trigIt = range.first;
00631          trigIt!=range.second;
00632          ++trigIt){
00633         
00634       int bx = trigIt->bx();
00635       int quality = trigIt->quality();
00636       int thqual = trigIt->trTheta();
00637       int flag1st = trigIt->secondTrack() ? 1 : 0;
00638 
00639       // check if SC data exist: fill for any trigger
00640       if( quality>-1 && quality<7 ) {     // it is a phi trigger
00641         
00642         if(quality>dduphcode_best[wh+3][st][sec]) {
00643           dduphcode_best[wh+3][st][sec]=quality;
00644           iphbestddu[wh+3][st][sec] = &(*trigIt);
00645         }
00646         
00647         if (innerME.find("DDU_BXvsQual"+trigsrc) == innerME.end()){
00648           bookHistos(id,"LocalTriggerPhi","DDU_BXvsQual"+trigsrc);
00649           bookHistos(id,"LocalTriggerPhi","DDU_Flag1stvsQual"+trigsrc);
00650         }
00651 
00652         if(tpMode) {      
00653           innerME.find("DDU_BXvsQual"+trigsrc)->second->Fill(quality,bx-flag1st);     // SM BX vs Qual Phi view 
00654         }
00655         else {
00656           innerME.find("DDU_BXvsQual"+trigsrc)->second->Fill(quality,bx-flag1st);     // SM BX vs Qual Phi view 
00657           innerME.find("DDU_Flag1stvsQual"+trigsrc)->second->Fill(quality,flag1st); // SM Quality vs 1st/2nd track flag Phi view
00658         }
00659       }
00660       if( thqual>0 && !tpMode ) {  // it is a theta trigger
00661         
00662         if(thqual>dduthcode_best[wh+3][st][sec] ) {
00663           dduthcode_best[wh+3][st][sec]=thqual; 
00664         }
00665         if (innerME.find("DDU_ThetaBXvsQual"+trigsrc) == innerME.end())
00666           bookHistos(id,"LocalTriggerTheta","DDU_ThetaBXvsQual"+trigsrc);
00667         innerME.find("DDU_ThetaBXvsQual"+trigsrc)->second->Fill(thqual,bx);     // SM BX vs Qual Theta view
00668         
00669       }
00670     }
00671     
00672     // Fill Quality plots with best ddu triggers in phi & theta
00673     if (!tpMode) {
00674       if (dduphcode_best[wh+3][st][sec]>-1 &&
00675           dduphcode_best[wh+3][st][sec]<7){
00676         if (innerME.find("DDU_BestQual"+trigsrc) == innerME.end())
00677           bookHistos(id,"LocalTriggerPhi","DDU_BestQual"+trigsrc);
00678         innerME.find("DDU_BestQual"+trigsrc)->second->Fill(dduphcode_best[wh+3][st][sec]);  // CB Best Qual Trigger Phi view
00679       }
00680       if (dduthcode_best[wh+3][st][sec]>0){
00681         if (innerME.find("DDU_ThetaBestQual"+trigsrc) == innerME.end())
00682           bookHistos(id,"LocalTriggerTheta","DDU_ThetaBestQual"+trigsrc);
00683         innerME.find("DDU_ThetaBestQual"+trigsrc)->second->Fill(dduthcode_best[wh+3][st][sec]); // CB Best Qual Trigger Theta view
00684       }  
00685     }
00686   }
00687   
00688 }
00689 
00690 
00691 void DTLocalTriggerTask::runSegmentAnalysis(Handle<DTRecSegment4DCollection>& segments4D){    
00692 
00693   DTRecSegment4DCollection::const_iterator track;
00694 
00695   // Find best tracks & good tracks
00696   memset(track_ok,false,450*sizeof(bool));
00697 
00698   DTRecSegment4DCollection::id_iterator chamberId;
00699   vector<const DTRecSegment4D*> best4DSegments;
00700 
00701   // Preliminary loop finds best 4D Segment and high quality ones
00702   for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
00703 
00704     DTRecSegment4DCollection::range  range = segments4D->get(*chamberId);
00705     const DTRecSegment4D* tmpBest=0;
00706     int tmpdof = 0;
00707     int dof = 0;
00708 
00709     for ( track = range.first; track != range.second; ++track){
00710 
00711       if( (*track).hasPhi() ) {
00712         
00713         dof = (*track).phiSegment()->degreesOfFreedom();
00714         if ( dof>tmpdof ){
00715           tmpBest = &(*track);
00716           tmpdof = dof;
00717         
00718           int wheel = (*track).chamberId().wheel();
00719           int sector = (*track).chamberId().sector();
00720           int station = (*track).chamberId().station();
00721           if (sector==13){
00722             sector=4;
00723           }
00724           else if (sector==14){
00725             sector=10;
00726           }
00727           track_ok[wheel+3][station][sector] = (!track_ok[wheel+3][station][sector] && dof>=2);
00728         }
00729 
00730       }
00731     }
00732     if (tmpBest) best4DSegments.push_back(tmpBest);
00733   }
00734     
00735   vector<const DTRecSegment4D*>::const_iterator btrack;
00736 
00737   for ( btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack ){
00738 
00739     if( (*btrack)->hasPhi() ) { // Phi component
00740         
00741       int wheel = (*btrack)->chamberId().wheel();
00742       int station = (*btrack)->chamberId().station();
00743       int scsector = 0;
00744       float x_track, y_track, x_angle, y_angle;
00745       computeCoordinates((*btrack),scsector,x_track,x_angle,y_track,y_angle);
00746       int nHitsPhi = (*btrack)->phiSegment()->degreesOfFreedom()+2;
00747         
00748       DTChamberId dtChId(wheel,station,scsector);  // get chamber for histograms
00749       uint32_t indexCh = dtChId.rawId(); 
00750       map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00751 
00752 
00753       if (useDDU && 
00754           dduphcode_best[wheel+3][station][scsector] > -1 && 
00755           dduphcode_best[wheel+3][station][scsector] < 7 ) {
00756 
00757         // SM hits of the track vs quality of the trigger
00758         if (innerME.find("DDU_HitstkvsQualtrig"+trigsrc) == innerME.end())
00759           bookHistos(dtChId,"Segment","DDU_HitstkvsQualtrig"+trigsrc);
00760         innerME.find("DDU_HitstkvsQualtrig"+trigsrc)->second->Fill(dduphcode_best[wheel+3][station][scsector],nHitsPhi);
00761 
00762       }
00763         
00764       if (useDCC &&
00765           phcode_best[wheel+3][station][scsector] > -1 && 
00766           phcode_best[wheel+3][station][scsector] < 7 ) {
00767             
00768         int phphi = iphbest[wheel+3][station][scsector]->phi();
00769         float x_trigger = phi2Pos(dtChId,phphi);
00770         float angle_trigger = phib2Ang(dtChId,iphbest[wheel+3][station][scsector]->phiB(),phphi);
00771             
00772         if (innerME.find("DCC_HitstkvsQualtrig"+trigsrc) == innerME.end()){
00773           bookHistos(dtChId,"Segment","DCC_PhiResidual"+trigsrc);
00774           bookHistos(dtChId,"Segment","DCC_PhibResidual"+trigsrc);
00775           bookHistos(dtChId,"Segment","DCC_PhitkvsPhitrig"+trigsrc);
00776           bookHistos(dtChId,"Segment","DCC_PhibtkvsPhibtrig"+trigsrc);
00777           bookHistos(dtChId,"Segment","DCC_HitstkvsQualtrig"+trigsrc);
00778         }
00779 
00780         innerME.find("DCC_PhitkvsPhitrig"+trigsrc)->second->Fill(x_trigger,x_track);
00781         innerME.find("DCC_PhibtkvsPhibtrig"+trigsrc)->second->Fill(angle_trigger,x_angle);
00782         
00783         if (phcode_best[wheel+3][station][scsector]> 3){
00784           innerME.find("DCC_PhiResidual"+trigsrc)->second->Fill(x_trigger-x_track);
00785           innerME.find("DCC_PhibResidual"+trigsrc)->second->Fill(angle_trigger-x_angle);
00786         }
00787 
00788         innerME.find("DCC_HitstkvsQualtrig"+trigsrc)->second->Fill(iphbest[wheel+3][station][scsector]->code(),nHitsPhi);
00789 
00790       }
00791 
00792       
00793       if (useDCC) {
00794           
00795         // check for triggers elsewhere in the sector
00796         bool trigFlagDCC =false;
00797         for (int ist=1; ist<5; ist++){
00798           if (ist!=station &&
00799               phcode_best[wheel+3][ist][scsector]>=2 && 
00800               phcode_best[wheel+3][ist][scsector]<7 &&
00801               track_ok[wheel+3][ist][scsector]==true){
00802             trigFlagDCC = true;
00803             break;
00804           }
00805         }
00806           
00807         if (trigFlagDCC && fabs(x_angle)<40. && nHitsPhi>=7){
00808 
00809           if (innerME.find("DCC_TrackPosvsAngle"+trigsrc) == innerME.end()){
00810             bookHistos(dtChId,"Segment","DCC_TrackPosvsAngle"+trigsrc);
00811             bookHistos(dtChId,"Segment","DCC_TrackPosvsAngleandTrig"+trigsrc);
00812             bookHistos(dtChId,"Segment","DCC_TrackPosvsAngleandTrigHHHL"+trigsrc);
00813           }
00814             
00815           // position vs angle of track for reconstruced tracks (denom. for trigger efficiency)
00816           innerME.find("DCC_TrackPosvsAngle"+trigsrc)->second->Fill(x_angle,x_track);     
00817           if (phcode_best[wheel+3][station][scsector] >= 2 && phcode_best[wheel+3][station][scsector] < 7) {
00818             innerME.find("DCC_TrackPosvsAngleandTrig"+trigsrc)->second->Fill(x_angle,x_track);    
00819             if (phcode_best[wheel+3][station][scsector] > 4){  //HH & HL Triggers
00820               innerME.find("DCC_TrackPosvsAngleandTrigHHHL"+trigsrc)->second->Fill(x_angle,x_track);      
00821             }         
00822           }
00823 
00824         }
00825           
00826         if ((*btrack)->hasZed() && trigFlagDCC && fabs(y_angle)<40. && (*btrack)->zSegment()->degreesOfFreedom()>=1){
00827 
00828           if (innerME.find("DCC_TrackThetaPosvsAngle"+trigsrc) == innerME.end()){
00829             bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngle"+trigsrc);
00830             bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngleandTrig"+trigsrc);
00831             bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngleandTrigH"+trigsrc);
00832           }
00833 
00834           // position va angle of track for reconstruced tracks (denom. for trigger efficiency) along theta direction
00835           innerME.find("DCC_TrackThetaPosvsAngle"+trigsrc)->second->Fill(y_angle,y_track);
00836           if (thcode_best[wheel+3][station][scsector] > 0) {            
00837             innerME.find("DCC_TrackThetaPosvsAngleandTrig"+trigsrc)->second->Fill(y_angle,y_track);
00838             if (thcode_best[wheel+3][station][scsector] == 3) {
00839               innerME.find("DCC_TrackThetaPosvsAngleH"+trigsrc)->second->Fill(y_angle,y_track);
00840             }            
00841           }
00842 
00843         }  
00844       }
00845 
00846       if (useDDU) {
00847           
00848         // check for triggers elsewhere in the sector
00849         bool trigFlagDDU =false;
00850         for (int ist=1; ist<5; ist++){
00851           if (ist!=station &&
00852               dduphcode_best[wheel+3][ist][scsector]>=2 && 
00853               dduphcode_best[wheel+3][ist][scsector]<7 &&
00854               track_ok[wheel+3][ist][scsector]==true){
00855             trigFlagDDU = true;
00856             break;
00857           }
00858         }
00859 
00860         if (trigFlagDDU && fabs(x_angle)<40. && nHitsPhi>=7){
00861 
00862           if (innerME.find("DDU_TrackPosvsAngle"+trigsrc) == innerME.end()){
00863             bookHistos(dtChId,"Segment","DDU_TrackPosvsAngle"+trigsrc);
00864             bookHistos(dtChId,"Segment","DDU_TrackPosvsAngleandTrig"+trigsrc);
00865             bookHistos(dtChId,"Segment","DDU_TrackPosvsAngleandTrigHHHL"+trigsrc);
00866           }
00867 
00868           // position vs angle of track for reconstruced tracks (denom. for trigger efficiency)
00869           innerME.find("DDU_TrackPosvsAngle"+trigsrc)->second->Fill(x_angle,x_track);
00870           if (dduphcode_best[wheel+3][station][scsector] >= 2 && dduphcode_best[wheel+3][station][scsector] < 7) {
00871           innerME.find("DDU_TrackPosvsAngleandTrig"+trigsrc)->second->Fill(x_angle,x_track);
00872             if (dduphcode_best[wheel+3][station][scsector] > 4){  //HH & HL Triggers
00873               innerME.find("DDU_TrackPosvsAngleandTrigHHHL"+trigsrc)->second->Fill(x_angle,x_track);      
00874             }         
00875           }
00876 
00877         }
00878           
00879         if ((*btrack)->hasZed() && trigFlagDDU && fabs(y_angle)<40. && (*btrack)->zSegment()->degreesOfFreedom()>=1){
00880 
00881           if (innerME.find("DDU_TrackThetaPosvsAngle"+trigsrc) == innerME.end()){
00882             bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngle"+trigsrc);
00883             bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrig"+trigsrc);
00884             bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrigH"+trigsrc);
00885           }
00886 
00887           // position va angle of track for reconstruced tracks (denom. for trigger efficiency) along theta direction
00888           innerME.find("DDU_TrackThetaPosvsAngle"+trigsrc)->second->Fill(y_angle,y_track);
00889           if (dduthcode_best[wheel+3][station][scsector] > 0) {         
00890             innerME.find("DDU_TrackThetaPosvsAngleandTrig"+trigsrc)->second->Fill(y_angle,y_track);
00891             if (dduthcode_best[wheel+3][station][scsector] == 3) {
00892               innerME.find("DDU_TrackThetaPosvsAngleandTrigH"+trigsrc)->second->Fill(y_angle,y_track);
00893             }            
00894           }
00895 
00896         }  
00897       }
00898     }
00899   } 
00900 
00901 }
00902 
00903 
00904 void DTLocalTriggerTask::runDDUvsDCCAnalysis(string& trigsrc){
00905 
00906   string histoType ;
00907   string histoTag ;
00908 
00909   for (int st=1;st<5;++st){
00910     for (int wh=-2;wh<3;++wh){
00911       for (int sc=1;sc<13;++sc){
00912         if ( (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7) ||
00913              (dduphcode_best[wh+3][st][sc]>-1 && dduphcode_best[wh+3][st][sc]<7) ){
00914           DTChamberId id(wh,st,sc);
00915           uint32_t indexCh = id.rawId();
00916           map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00917           if (innerME.find("COM_QualDDUvsQualDCC"+trigsrc) == innerME.end())
00918             bookHistos(id,"LocalTriggerPhi","COM_QualDDUvsQualDCC"+trigsrc);
00919           innerME.find("COM_QualDDUvsQualDCC"+trigsrc)->second->Fill(phcode_best[wh+3][st][sc],dduphcode_best[wh+3][st][sc]);
00920         }
00921       }
00922     }
00923   }
00924 
00925 }
00926 
00927 
00928 void DTLocalTriggerTask::computeCoordinates(const DTRecSegment4D* track, 
00929                                             int& scsector, 
00930                                             float& phpos, 
00931                                             float& phdir, 
00932                                             float& zpos, 
00933                                             float& zdir){
00934 
00935 
00936   float xcenter;        
00937   LocalPoint lpos;
00938   int wheel = track->chamberId().wheel();          
00939   int sector = track->chamberId().sector();
00940   int station = track->chamberId().station();
00941   const DTChamber* chamb;
00942   const DTChamber* scchamb;
00943   phdir = atan(track->localDirection().x()/ track->localDirection().z())/Geom::pi()*180.;
00944   zdir = atan(track->localDirection().y()/ track->localDirection().z())/Geom::pi()*180.;
00945 
00946 
00947   if (station == 4){
00948     switch (sector) {
00949     case 4:
00950       scsector = 4;
00951       chamb   = muonGeom->chamber(DTChamberId(wheel,station,13));
00952       scchamb = muonGeom->chamber(DTChamberId(wheel,station,4));
00953       xcenter = scchamb->toLocal(chamb->position()).x()*.5;
00954       phpos = track->localPosition().x()-xcenter;
00955       zpos  = track->localPosition().y();
00956       break;
00957     case 10:
00958       scsector = 10;
00959       chamb   = muonGeom->chamber(DTChamberId(wheel,station,14));
00960       scchamb = muonGeom->chamber(DTChamberId(wheel,station,10));
00961       xcenter = scchamb->toLocal(chamb->position()).x()*.5;
00962       phpos = track->localPosition().x()-xcenter;
00963       zpos = track->localPosition().y();
00964       break;
00965     case 13:
00966       scsector = 4;
00967       chamb   = muonGeom->chamber(DTChamberId(wheel,station,sector));
00968       scchamb = muonGeom->chamber(DTChamberId(wheel,station,scsector));
00969       lpos = scchamb->toLocal(chamb->toGlobal(track->localPosition()));
00970       xcenter = scchamb->toLocal(chamb->position()).x()*.5;
00971       phpos = lpos.x()-xcenter;
00972       zpos  = lpos.y();
00973       break;
00974     case 14:
00975       scsector = 10;
00976       chamb   = muonGeom->chamber(DTChamberId(wheel,station,sector));
00977       scchamb = muonGeom->chamber(DTChamberId(wheel,station,scsector));
00978       lpos = scchamb->toLocal(chamb->toGlobal(track->localPosition()));
00979       xcenter = scchamb->toLocal(chamb->position()).x()*.5;
00980       phpos = lpos.x()-xcenter;
00981       zpos  = lpos.y();
00982       break;
00983     default:
00984       scsector = sector;
00985       phpos = track->localPosition().x();
00986       zpos  = track->localPosition().y();
00987     }
00988   }
00989   else {
00990     scsector = sector;
00991     phpos = track->localPosition().x();
00992     zpos  = track->localPosition().y();
00993   }
00994 
00995 }
00996 
00997 
00998 pair<float,float> DTLocalTriggerTask::phiRange(const DTChamberId& id){
00999 
01000   float min,max;
01001   int station = id.station();
01002   int sector  = id.sector(); 
01003   int wheel   = id.wheel();
01004   
01005   const DTLayer  *layer = muonGeom->layer(DTLayerId(id,1,1));
01006   DTTopology topo = layer->specificTopology();
01007   min = topo.wirePosition(topo.firstChannel());
01008   max = topo.wirePosition(topo.lastChannel());
01009 
01010   if (station == 4){
01011     
01012     const DTLayer *layer2;
01013     float lposx;
01014     
01015     if (sector == 4){
01016       layer2  = muonGeom->layer(DTLayerId(wheel,station,13,1,1));
01017       lposx = layer->toLocal(layer2->position()).x();
01018     }
01019     else if (sector == 10){
01020       layer2 = muonGeom->layer(DTLayerId(wheel,station,14,1,1));
01021       lposx = layer->toLocal(layer2->position()).x();
01022     }
01023     else
01024       return make_pair(min,max);
01025     
01026     DTTopology topo2 = layer2->specificTopology();
01027 
01028     if (lposx>0){
01029       max =  lposx*.5 + topo2.wirePosition(topo2.lastChannel());
01030       min -= lposx*.5;
01031     }
01032     else{ 
01033       min =  lposx*.5 + topo2.wirePosition(topo2.firstChannel());
01034       max -= lposx*.5;
01035     }
01036   }
01037 
01038   return make_pair(min,max);
01039  
01040 }
01041 
01042 float DTLocalTriggerTask::phi2Pos(const DTChamberId & id, int phi){
01043 
01044   float phin = (id.sector()-1)*Geom::pi()/6;
01045   GlobalPoint gpos = muonGeom->chamber(id)->position();
01046   float deltaphi =  gpos.phi()-phin;
01047 
01048   if (id.station() == 4 && ( id.sector() == 4 || id.sector() == 10))
01049     deltaphi = 0;
01050 
01051   float x = (tan(phi/4096.)-tan(deltaphi))*gpos.perp()*cos(deltaphi);
01052   
01053   if (id.wheel()>0 || (id.wheel()==0 && id.sector()%4>1)) 
01054     x= -x;
01055 
01056   return x;
01057 
01058 }
01059 
01060 
01061 float DTLocalTriggerTask::phib2Ang(const DTChamberId & id, int phib, double phi){
01062   
01063   float fphi = phib/512.+phi/4096.;//+(id.sector()-4)*Geom::pi()/6.;
01064   fphi *= 180./Geom::pi();
01065 
01066   if (id.wheel()<0 || (id.wheel()==0 && id.sector()%4<=1)) 
01067     fphi = -fphi;
01068 
01069   return fphi;
01070 
01071 }
01072 
01073 void DTLocalTriggerTask::setQLabels(MonitorElement* me, short int iaxis){
01074 
01075   TH1* histo = me->getTH1();
01076   if (!histo) return;
01077   
01078   TAxis* axis=0;
01079   if (iaxis==1) {
01080     axis=histo->GetXaxis();
01081   }
01082   else if(iaxis==2) {
01083     axis=histo->GetYaxis();
01084   }
01085   if (!axis) return;
01086 
01087   char *labels[7] = {"LI","LO","HI","HO","LL","HL","HH"};
01088   int istart = axis->GetXmin()<-1 ? 2 : 1;
01089   for (int i=0;i<7;i++) {
01090     axis->SetBinLabel(i+istart,labels[i]);
01091   }
01092 
01093 }
01094 
01095 void DTLocalTriggerTask::triggerSource(const edm::Event& e) {
01096   
01097   
01098   if ( !parameters.getUntrackedParameter<bool>("localrun", true) ){
01099     
01100     Handle<LTCDigiCollection> ltcdigis;
01101     e.getByType(ltcdigis);
01102     
01103     for (std::vector<LTCDigi>::const_iterator ltc_it = ltcdigis->begin(); ltc_it != ltcdigis->end(); ltc_it++){
01104       
01105       int otherTriggerSum=0;
01106       for (int i = 1; i < 6; i++) {
01107         otherTriggerSum += int((*ltc_it).HasTriggered(i));
01108       }
01109       if ((*ltc_it).HasTriggered(0) && otherTriggerSum == 0) 
01110         trigsrc = "_DTonly";
01111       else if (!(*ltc_it).HasTriggered(0))
01112         trigsrc = "_NoDT";
01113       else if ((*ltc_it).HasTriggered(0) && otherTriggerSum > 0)
01114         trigsrc = "_DTalso";
01115       
01116     }
01117     return;
01118   }
01119 
01120   trigsrc = "";
01121   return;
01122 
01123 }

Generated on Tue Jun 9 17:32:40 2009 for CMSSW by  doxygen 1.5.4