ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/LinkSynchroAnalysis.cc
Revision: 1.3
Committed: Sun Jun 6 16:45:43 2010 UTC (14 years, 10 months ago) by konec
Content type: text/plain
Branch: MAIN
Changes since 1.2: +10 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 konec 1.1 #include "LinkSynchroAnalysis.h"
2    
3     #include "FWCore/MessageLogger/interface/MessageLogger.h"
4     #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
5     #include "CondFormats/RPCObjects/interface/LinkBoardSpec.h"
6    
7     #include "DataFormats/Common/interface/Handle.h"
8     #include "FWCore/Framework/interface/Event.h"
9     #include "FWCore/Framework/interface/ESTransientHandle.h"
10     #include "FWCore/Framework/interface/EventSetup.h"
11     #include "FWCore/Framework/interface/ESWatcher.h"
12     #include "CondFormats/RPCObjects/interface/RPCEMap.h"
13     #include "CondFormats/DataRecord/interface/RPCEMapRcd.h"
14    
15    
16     #include "DataFormats/MuonDetId/interface/RPCDetId.h"
17     #include "TFile.h"
18     #include "TH1F.h"
19     #include <map>
20    
21 konec 1.2 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
22     #include "DataFormats/GeometryVector/interface/GlobalVector.h"
23    
24     struct LessGP { bool operator () (const GlobalPoint & p1, const GlobalPoint & p2) const { return p1.perp() < p2.perp(); } };
25    
26 konec 1.1 LinkSynchroAnalysis::LinkSynchroAnalysis(const edm::ParameterSet& cfg)
27     : RPCMonitorLinkSynchro(cfg.getParameter<edm::ParameterSet>("linkMonitorPSet")), theAnaConfig(cfg),theCabling(0), theEventCounter(0) { }
28    
29     LinkSynchroAnalysis::~LinkSynchroAnalysis(){ delete theCabling;}
30    
31     void LinkSynchroAnalysis::beginJob()
32     {
33     RPCMonitorLinkSynchro::beginJob();
34     theHistos.SetOwner();
35     theHistos.Add(new TH1F("hBX","hBX",3564,0.,3564));
36     theHistos.Add(new TH1F("hDeltaPhi","hDeltaPhi",100, 0., 1.));
37     theHistos.Add(new TH1F("hDeltaEta","hDeltaEta",100, 0., 1.));
38     theHistos.Add(new TH1F("hDxy","hDxy",100.,0.,1.));
39     theHistos.Add(new TH1F("hNumTracks","hNumTracks",50,0.,250.));
40 konec 1.2 theHistos.Add(new TH1F("hDistB","hDistB",50,0.,200.));
41     theHistos.Add(new TH1F("hDistE","hDistE",50,0.,500.));
42     theHistos.Add(new TH1F("hPenetrationB","hPenetrationB",10,0.,10.));
43     theHistos.Add(new TH1F("hPenetrationE","hPenetrationE",10,0.,10.));
44 konec 1.3 theHistos.Add(new TH1F("hPullX","hPullX",100,-10.,10.));
45     theHistos.Add(new TH1F("hDistX","hDistX",100,-100.,100.));
46 konec 1.1
47     typedef std::vector<edm::ParameterSet> VPSet;
48     VPSet selectorConfigs = theAnaConfig.getParameter<VPSet>("ORedSynchroFilters");
49     for (VPSet::const_iterator it=selectorConfigs.begin(); it != selectorConfigs.end(); ++it) {
50     SynchroSelector f(*it);
51     if (it->getParameter<std::string>("collection") == "generalTracks") {
52     f.setHistoNum(static_cast<TH1F* >(theHistos.FindObject("hNumTracks")));
53     f.setHistoPhi(static_cast<TH1F* >(theHistos.FindObject("hDeltaPhi")));
54     f.setHistoEta(static_cast<TH1F* >(theHistos.FindObject("hDeltaEta")));
55     f.setHistoDxy(static_cast<TH1F* >(theHistos.FindObject("hDxy")));
56 konec 1.3 f.setHistoPullX(static_cast<TH1F* >(theHistos.FindObject("hPullX")));
57     f.setHistoDistX(static_cast<TH1F* >(theHistos.FindObject("hDistX")));
58     }
59     if (it->getParameter<std::string>("collection") == "globalMuons") {
60 konec 1.1 }
61     theSynchroFilters.push_back(f);
62     }
63     }
64    
65     void LinkSynchroAnalysis::endJob()
66     {
67     RPCMonitorLinkSynchro::endJob();
68     bool writeHistos = theAnaConfig.getUntrackedParameter<bool>("writeHistograms", false);
69     if (writeHistos) {
70     std::string histoFile = theAnaConfig.getUntrackedParameter<std::string>("histoFileName");
71     TFile f(histoFile.c_str(),"RECREATE");
72     theHistos.Write();
73     histos().Write();
74     edm::LogInfo(" END JOB, histos saved!");
75     edm::LogInfo("") <<"LINK SYNCHRO ANALYSIS number of events SELECTED: "<<theEventCounter;
76     f.Close();
77     }
78     }
79    
80     const RPCRawSynchro::ProdItem& LinkSynchroAnalysis::select(const RPCRawSynchro::ProdItem & vItem, const edm::Event &ev, const edm::EventSetup &es)
81     {
82     static RPCRawSynchro::ProdItem selected;
83     selected.clear();
84    
85     bool wasTakeIt = false;
86    
87     if (theMapWatcher.check(es)) {
88     delete theCabling;
89     edm::ESTransientHandle<RPCEMap> readoutMapping;
90     es.get<RPCEMapRcd>().get(readoutMapping);
91     theCabling = readoutMapping->convert();
92     LogTrace("") << "LinkSynchroAnalysis - record has CHANGED!!, read map, VERSION: " << theCabling->version();
93     }
94    
95 konec 1.2 theSynchroFilters[0].resetPos();
96 konec 1.1 for(RPCRawSynchro::ProdItem::const_iterator it = vItem.begin(); it != vItem.end(); ++it) {
97     const LinkBoardElectronicIndex & path = it->first;
98     const std::vector<FebConnectorSpec> & febs = theCabling->location(path)->febs();
99     std::map<uint32_t,bool> dets;
100     for (std::vector<FebConnectorSpec>::const_iterator iif = febs.begin(); iif != febs.end(); ++iif) dets[iif->rawId()] = true;
101    
102     bool takeIt = false;
103     for ( std::map<uint32_t,bool>::const_iterator im = dets.begin(); im != dets.end(); ++im) {
104     RPCDetId rpcDet(im->first);
105     for (std::vector<SynchroSelector>::iterator ix=theSynchroFilters.begin(); ix != theSynchroFilters.end(); ++ix) if(ix->takeIt(rpcDet,ev,es) ) takeIt = true;
106     }
107     if (takeIt) selected.push_back(*it);
108     if (takeIt) wasTakeIt = true;
109     }
110 konec 1.3
111     /*
112 konec 1.2 std::vector<GlobalPoint> pos = theSynchroFilters[0].positions();
113     std::sort(pos.begin(), pos.end(), LessGP());
114     GlobalPoint last(0.,0.,0.);
115     unsigned int points = 0;
116     bool barrel = false;
117     bool endcap = false;
118     for (std::vector<GlobalPoint>::const_iterator ip= pos.begin(); ip != pos.end(); ++ip) {
119     double dist = 0.;
120     if (fabs(ip->eta()) > 1.24 && fabs(ip->eta()) < 1.6 ) endcap = true;
121     if (fabs(ip->eta()) < 0.93) barrel= true;
122     if (barrel) dist = ((*ip)-last).perp();
123     if (endcap) dist = fabs(((*ip)-last).z());
124     if (barrel) static_cast<TH1F* >(theHistos.FindObject("hDistB"))->Fill(dist);
125     if (endcap) static_cast<TH1F* >(theHistos.FindObject("hDistE"))->Fill(dist);
126     if (endcap&& dist > 50.) points++;
127     if (barrel&& dist > 30.) points++;
128     last = *ip;
129     std::cout <<"HERE, barrel: " <<barrel<<" endcap:"<< endcap<<" dist: " << dist <<" points: "<<points<< *ip<<std::endl;
130     }
131     std::cout <<"POINTS: " << points << std::endl;
132     if (barrel && endcap) std::cout << "PROBLEM" << std::endl;
133     if (wasTakeIt && barrel ) static_cast<TH1F* >(theHistos.FindObject("hPenetrationB"))->Fill(points);
134     if (wasTakeIt && endcap) static_cast<TH1F* >(theHistos.FindObject("hPenetrationE"))->Fill(points);
135 konec 1.3
136     */
137 konec 1.1 if (wasTakeIt) static_cast<TH1*>(theHistos.FindObject("hBX"))->Fill( ev.bunchCrossing());
138     if (wasTakeIt) theEventCounter++;
139     return selected;
140     }
141