ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DTDPGAnalysis/src/CheckDeadChannels.cc
Revision: 1.1
Committed: Thu Jul 4 17:12:54 2013 UTC (11 years, 10 months ago) by marycruz
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
New code for check dead channels

File Contents

# User Rev Content
1 marycruz 1.1 /*
2     Compare dead channels found in this run with a reference one
3     Oct. 13, 2011
4     Francesca R. Cavallo
5     */
6    
7    
8     #include <UserCode/DTDPGAnalysis/src/CheckDeadChannels.h>
9    
10    
11    
12     #include "FWCore/MessageLogger/interface/MessageLogger.h"
13    
14     #include <iostream>
15     #include <fstream>
16     #include <stdio.h>
17     #include <string>
18     #include <sstream>
19     #include <math.h>
20    
21     #include "boost/filesystem.hpp"
22    
23     using namespace boost::filesystem;
24     using namespace edm;
25     using namespace std;
26    
27    
28     CheckDeadChannels::CheckDeadChannels(const edm::ParameterSet& ps){
29    
30     edm::LogVerbatim ("DTDPGSummary") << "[CheckDeadChannels]: Constructor";
31    
32     myParameters = ps;
33     myRunNumber = ps.getUntrackedParameter<int>("runNumber",0);
34     // 06-12-2011 take the reference run from the txt files mantained to this purpose in the /COMM_DT/OfflineCode/Scripts area
35     //ReferenceRun = ps.getUntrackedParameter<int>("referenceRun",0);
36    
37     }
38    
39     CheckDeadChannels::~CheckDeadChannels(){
40    
41     edm::LogVerbatim ("DTDPGSummary") << "[CheckDeadChannels]: Destructor called";
42    
43     char deadname[100]; string deadnameRef; char comparison[100]; string RefDir;
44    
45     ifstream refRun ("/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DT/OfflineCode/Scripts/referenceRun.txt");
46    
47     refRun>>ReferenceRun;
48     refRun>>RefDir;
49     refRun>>RefDir; //skipping unwanted string
50     refRun.close();
51    
52     sprintf (deadname, "Run%i/DeadChannelList_r%i.txt",myRunNumber,myRunNumber);
53    
54     // 06-12-2011 distinguish HeavyIons from Beam (pp) folders
55    
56    
57     char filen[100];
58     sprintf (filen, "DeadChannelList_r%i.txt",ReferenceRun);
59     deadnameRef = RefDir + filen;
60     sprintf (comparison, "Run%i/DeadChannelCheck_r%i_to_r%i.txt",myRunNumber, myRunNumber,ReferenceRun);
61    
62     ifstream DeadChannelList (deadname);
63     ifstream DeadChannelRef (deadnameRef.c_str());
64     cout<<" opened "<<deadname<<" and "<<deadnameRef<<endl;
65    
66     DeadComp = new ofstream(comparison);
67    
68     int wheel, station, sector, sl, lay, wire; float effi; float deffi;
69     int wheelref[200000], stationref[200000], sectorref[200000], slref[200000], layref[200000], wireref[200000]; float effiref; float deffiref;
70    
71     char printline[50];
72    
73     int nref=0;
74    
75     while (DeadChannelRef>>wheelref[nref]>>stationref[nref]>>sectorref[nref]>>slref[nref]>>layref[nref]>>wireref[nref]>>effiref>>deffiref) {
76     if (effiref>=0) nref++;
77     if (nref>199999) {
78     *DeadComp<<" WARNING !! more than 200000 dead channels in reference run! "<<endl<<endl;
79     break;
80     }
81     }
82    
83     cout<<nref<<" lines read in reference "<<endl;
84    
85     // search for "new" dead channels
86     *DeadComp<<" New dead channels (wheel, station, sector, superlayer, layer, wire, meas.efficiency, error)"<<endl<<endl;
87    
88     int ncheck=0; int nnew=0;
89     while (DeadChannelList>>wheel>>station>>sector>>sl>>lay>>wire>>effi>>deffi){
90     int ip=0;
91     while( effi>=0 &&
92     !(wheel==wheelref[ip] && station==stationref[ip] && sector==sectorref[ip] && sl==slref[ip] && lay==layref[ip] && wire==wireref[ip]) &&
93     wheel>=wheelref[ip] &&
94     ip<nref) ip++;
95     if (ip==nref || wheelref[ip]>wheel) {
96     nnew++;
97    
98     sprintf (printline,"%3i%3u%4u%3u%3u%4u%7.2f%7.2f",wheel,station,sector,sl,lay,wire,effi,deffi);
99     *DeadComp<<printline<<endl;
100     }
101     if (effi>=0) {ncheck++;
102     }
103     }
104     cout<<ncheck<<" lines read in this run from "<<deadname<<endl;
105     cout<<" ncheck "<<ncheck<<" nnew "<<nnew<<" nref "<<nref<<endl;
106    
107     if (ncheck < (nref+nnew)) { // resurrections?
108    
109     *DeadComp<<endl<<" Resurrected channels (wheel, station, sector, superlayer, layer, wire, previous.efficiency, error)"<<endl<<endl;
110    
111     DeadChannelList.close();
112     DeadChannelList.open(deadname);
113     DeadChannelRef.close();
114     DeadChannelRef.open(deadnameRef.c_str());
115     *DeadComp<<endl;
116     nref=0; int nres=0;
117    
118     while (DeadChannelList>>wheelref[nref]>>stationref[nref]>>sectorref[nref]>>slref[nref]>>layref[nref]>>wireref[nref]>>effiref>>deffiref) {
119     //if (effiref>=0) nref++; // effiref<0 --> undetermined
120     nref++;
121     if (nref>199999) {
122     *DeadComp<<" WARNING !! more than 200000 dead channels in this run! "<<endl<<endl;
123     break;
124     }
125     }
126    
127     while (DeadChannelRef>>wheel>>station>>sector>>sl>>lay>>wire>>effi>>deffi){
128    
129     int ip=0;
130     while( effi>=0 && // effi<0 --> undetermined
131     !(wheel==wheelref[ip] && station==stationref[ip] && sector==sectorref[ip] && sl==slref[ip] && lay==layref[ip] && wire==wireref[ip]) &&
132     wheel>=wheelref[ip] &&
133     ip<nref) ip++;
134     if (ip==nref || wheelref[ip]>wheel) {
135     nres++;
136     sprintf (printline,"%3i%3u%4u%3u%3u%4u%7.2f%7.2f",wheel,station,sector,sl,lay,wire,effi,deffi);
137     *DeadComp<<printline<<endl;
138     }
139     }
140    
141     // investigate on (groups of) cells without segments or zero efficiency
142    
143     *DeadComp<<endl<<" Rows of 4 or more channels with no segments or zero efficiency"<<endl
144     <<"(wheel, station, sector, superlayer, layer, group of wires)"<<endl<<endl;
145     DeadChannelList.close();
146     DeadChannelList.open(deadname);
147     int ndrow=0;
148     int curwh=0, curse=0, curst=0, cursl=0, curlay=0, curwi=0;
149    
150     while (DeadChannelList>>wheel>>station>>sector>>sl>>lay>>wire>>effi>>deffi){
151    
152     if (effi<-1 || (effi>=0.&&effi<0.01)) {
153     if (wheel==curwh && station==curst && sector==curse && sl==cursl && lay==curlay && wire==curwi+1){
154     ndrow++;
155     }
156     else { // new possible row of dead channels
157    
158     if (ndrow>=3) {
159     sprintf (printline,"%3i%3u%4u%3u%3u%4u - %4u",curwh,curst,curse,cursl,curlay,curwi-ndrow,curwi);
160     *DeadComp<<printline<<endl;
161     }
162     ndrow=0;
163     curwh=wheel;
164     curst=station;
165     curse=sector;
166     cursl=sl;
167     curlay=lay;
168     }
169     curwi=wire;
170     }
171     }
172    
173     if (ndrow>=3) { // last row
174     sprintf (printline,"%3i%3u%4u%3u%3u%4u - %4u",curwh,curst,curse,cursl,curlay,curwi-ndrow,curwi);
175     *DeadComp<<printline<<endl;
176     }
177    
178     }
179    
180     DeadComp->close();
181     }
182    
183    
184     void CheckDeadChannels::beginJob(){
185    
186     edm::LogVerbatim ("DTDPGSummary") << "[CheckDeadChannels]: beginJob";
187    
188     }
189    
190    
191     void CheckDeadChannels::beginRun(const edm::Run& run,const edm::EventSetup& context){
192    
193     edm::LogVerbatim ("DTDPGSummary") << "[CheckDeadChannels]: beginRun";
194    
195     }
196    
197     void CheckDeadChannels::analyze(const edm::Event& e, const edm::EventSetup& context){
198    
199     }
200    
201     void CheckDeadChannels::endJob(){
202    
203     edm::LogVerbatim ("DTDPGSummary") << "[CheckDeadChannels] endJob called!";
204    
205     }