CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTTrigCorrectionFirst.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author S. Maselli - INFN Torino
6  */
7 
9 
11 
17 
21 
22 #include <iostream>
23 #include <fstream>
24 
25 using namespace edm;
26 using namespace std;
27 
29 
30  debug = pset.getUntrackedParameter<bool>("debug",false);
31  ttrigMin = pset.getUntrackedParameter<double>("ttrigMin",0);
32  ttrigMax = pset.getUntrackedParameter<double>("ttrigMax",5000);
33  rmsLimit = pset.getUntrackedParameter<double>("rmsLimit",5.);
34 
35  dbLabel = pset.getUntrackedParameter<string>("dbLabel", "");
36 }
37 
39 
41  ESHandle<DTTtrig> tTrig;
42  setup.get<DTTtrigRcd>().get(dbLabel,tTrig);
43  tTrigMap = &*tTrig;
44  cout << "[DTTTrigCorrection]: TTrig version: " << tTrig->version() << endl;
45 
46  setup.get<MuonGeometryRecord>().get(muonGeom);
47 }
48 
50  // Create the object to be written to DB
51  DTTtrig* tTrigNewMap = new DTTtrig();
52  //Get the superlayers list
53  vector<const DTSuperLayer*> dtSupLylist = muonGeom->superLayers();
54 
55  //Loop on all superlayers to compute the mean
56  double average = 0.;
57  double average2 = 0.;
58  double rms = 0.;
59  double averageSigma = 0.;
60  double average2Sigma = 0.;
61  double rmsSigma = 0.;
62  double counter = 0.;
63  double averagekfactor = 0;
64  float kfactor = 0;
65 
66  for (auto sl = dtSupLylist.begin();
67  sl != dtSupLylist.end(); sl++) {
68  float ttrigMean = 0;
69  float ttrigSigma = 0;
70  tTrigMap->get((*sl)->id(),
71  ttrigMean,
72  ttrigSigma,
73  kfactor,
75  if( ttrigMean < ttrigMax && ttrigMean > ttrigMin ) {
76  average += ttrigMean;
77  averageSigma += ttrigSigma;
78  if(ttrigMean > 0)
79  counter += 1.;
80  }
81  }//End of loop on superlayers
82 
83  average = average/ counter;
84  averageSigma = averageSigma/counter;
85  averagekfactor = kfactor;
86 
87  // cout << " average counter "<< average << " "<< counter <<endl;
88 
89  for (auto sl = dtSupLylist.begin();
90  sl != dtSupLylist.end(); sl++) {
91  float ttrigMean = 0;
92  float ttrigSigma = 0;
93  float kfactor = 0;
94  tTrigMap->get((*sl)->id(),
95  ttrigMean,
96  ttrigSigma,
97  kfactor,
99  if( ttrigMean < ttrigMax && ttrigMean > ttrigMin ) {
100  average2 += (ttrigMean-average)*(ttrigMean-average);
101  average2Sigma += (ttrigSigma-averageSigma)*(ttrigSigma-averageSigma);
102  }
103  }//End of loop on superlayers
104 
105  rms = average2 /(counter-1);
106  rmsSigma = average2Sigma /(counter-1);
107  rms = sqrt(rms);
108  rmsSigma = sqrt(rmsSigma);
109  cout << "average averageSigma counter rms "<< average <<" " << averageSigma << " " << counter << " " << rms <<endl;
110 
111 
112  for (auto sl = dtSupLylist.begin();
113  sl != dtSupLylist.end(); sl++) {
114  //Compute new ttrig
115  double newTTrigMean = 0;
116  double newTTrigSigma = 0;
117  double newkfactor =0;
118  float tempttrigMean = 0;
119  float tempttrigSigma = 0;
120  float tempkfactor = 0;
121  float ttrigMean = 0;
122  float ttrigSigma = 0;
123  float kfactor = 0;
124  tTrigMap->get((*sl)->id(),
125  ttrigMean,
126  ttrigSigma,
127  kfactor,
129  int chamber = (*sl)->id().chamberId().station();
130 
131  //check if ttrigMean is similar to the mean
132  if (abs(ttrigMean - average) < rmsLimit*rms ){
133  newTTrigMean = ttrigMean;
134  newTTrigSigma = ttrigSigma;
135  newkfactor = kfactor;
136  } else {
137  // do not consider if ttrig == 0
138  if(ttrigMean > 0) {
139  //cout << "ttrig chamber " << ttrigMean <<" "<<chamber<<endl;
140  if(((*sl)->id().superlayer()) == 1){
141  //cout << " superlayer " << ((*sl)->id().superlayer()) <<endl;
142  DTSuperLayerId slId((*sl)->id().chamberId(),3);
143  tTrigMap->get(slId,
144  tempttrigMean,
145  tempttrigSigma,
146  tempkfactor,
148  if (abs(tempttrigMean - average) < rmsLimit*rms) {
149  newTTrigMean = tempttrigMean;
150  newTTrigSigma = tempttrigSigma;
151  newkfactor = tempkfactor;
152  cout <<"Chamber "<< chamber << " sl " << ((*sl)->id().superlayer()) << "has ttrig "<< ttrigMean
153  << " -> takes value of sl 3 " << newTTrigMean <<endl;
154  } else if(chamber == 4){
155  cout << "No correction possible within same chamber (sl1) " <<endl;
156  newTTrigMean = average;
157  newTTrigSigma = averageSigma;
158  newkfactor = averagekfactor;
159  cout<<"####### Bad SL: " << (*sl)->id() << " from "<< ttrigMean <<" to "<< newTTrigMean <<endl;
160  } else if(chamber != 4){
161  DTSuperLayerId slId((*sl)->id().chamberId(),2);
162  tTrigMap->get(slId,
163  tempttrigMean,
164  tempttrigSigma,
165  tempkfactor,
167  if (abs(tempttrigMean - average) < rmsLimit*rms) {
168  newTTrigMean = tempttrigMean;
169  newTTrigSigma = tempttrigSigma;
170  newkfactor = tempkfactor;
171  cout <<"Chamber "<< chamber << " sl " << ((*sl)->id().superlayer()) << "has ttrig "<< ttrigMean
172  <<" -> takes value of sl 2 " << newTTrigMean <<endl;
173  } else {
174  cout << "No correction possible within same chamber (sl1) " <<endl;
175  newTTrigMean = average;
176  newTTrigSigma = averageSigma;
177  newkfactor = averagekfactor;
178  cout<<"####### Bad SL: " << (*sl)->id() << " from "<< ttrigMean <<" to "<< newTTrigMean <<endl;
179  }
180  }
181  } else if (((*sl)->id().superlayer()) == 2) {
182  //cout << " superlayer " << ((*sl)->id().superlayer()) <<endl;
183  DTSuperLayerId slId((*sl)->id().chamberId(),1);
184  tTrigMap->get(slId,
185  tempttrigMean,
186  tempttrigSigma,
187  tempkfactor,
189  if (abs(tempttrigMean - average) < rmsLimit*rms) {
190  newTTrigMean = tempttrigMean;
191  newTTrigSigma = tempttrigSigma;
192  newkfactor = tempkfactor;
193  cout <<"Chamber "<< chamber << " sl " << ((*sl)->id().superlayer()) << "has ttrig "<< ttrigMean
194  << " -> takes value of sl 1 " << newTTrigMean <<endl;
195  } else {
196  DTSuperLayerId slId((*sl)->id().chamberId(),3);
197  tTrigMap->get(slId,
198  tempttrigMean,
199  tempttrigSigma,
200  tempkfactor,
202  if (abs(tempttrigMean - average) < rmsLimit*rms) {
203  newTTrigMean = tempttrigMean;
204  newTTrigSigma = tempttrigSigma;
205  newkfactor = tempkfactor;
206  cout <<"Chamber "<< chamber << " sl " << ((*sl)->id().superlayer()) << "has ttrig "<< ttrigMean
207  << "-> takes value of sl 3 " << newTTrigMean <<endl;
208  } else {
209  cout << "No correction possible within same chamber (sl2) " <<endl;
210  newTTrigMean = average;
211  newTTrigSigma = averageSigma;
212  newkfactor = averagekfactor;
213  cout<<"####### Bad SL: " << (*sl)->id() << " from "<< ttrigMean <<" to "<< newTTrigMean <<endl;
214  }
215  }
216 
217 
218  } else if (((*sl)->id().superlayer()) == 3) {
219  //cout << " superlayer " << ((*sl)->id().superlayer()) <<endl;
220  DTSuperLayerId slId((*sl)->id().chamberId(),1);
221  tTrigMap->get(slId,
222  tempttrigMean,
223  tempttrigSigma,
224  tempkfactor,
226  if (abs(tempttrigMean - average) < rmsLimit*rms) {
227  newTTrigMean = tempttrigMean;
228  newTTrigSigma = tempttrigSigma;
229  newkfactor = tempkfactor;
230  cout <<"Chamber "<< chamber << " sl " << ((*sl)->id().superlayer()) << "has ttrig "<< ttrigMean
231  << " -> takes value of sl 1 " << newTTrigMean <<endl;
232  } else if(chamber == 4) {
233  cout << "No correction possible within same chamber (sl3)" <<endl;
234  newTTrigMean = average;
235  newTTrigSigma = averageSigma;
236  newkfactor = averagekfactor;
237  cout<<"####### Bad SL: " << (*sl)->id() << " from "<< ttrigMean <<" to "<< newTTrigMean <<endl;
238  } else if(chamber != 4){
239  DTSuperLayerId slId((*sl)->id().chamberId(),2);
240  tTrigMap->get(slId,
241  tempttrigMean,
242  tempttrigSigma,
243  tempkfactor,
245  if (abs(tempttrigMean - average) < rmsLimit*rms) {
246  newTTrigMean = tempttrigMean;
247  newTTrigSigma = tempttrigSigma;
248  newkfactor = tempkfactor;
249  cout <<"Chamber "<< chamber << " sl " << ((*sl)->id().superlayer()) << "has ttrig "<< ttrigMean
250  << " -> takes value of sl 2 " << newTTrigMean <<endl;
251  } else {
252  cout << "No correction possible within same chamber (sl3) " <<endl;
253  newTTrigMean = average;
254  newTTrigSigma = averageSigma;
255  newkfactor = averagekfactor;
256  cout<<"####### Bad SL: " << (*sl)->id() << " from "<< ttrigMean <<" to "<< newTTrigMean <<endl;
257  }
258  }
259 
260  }
261  } else {
262  // cout << "SL not present " << ttrigMean << " " <<((*sl)->id().superlayer()) <<endl;
263  newTTrigMean = average;
264  newTTrigSigma = averageSigma;
265  newkfactor = averagekfactor;
266  cout<<"####### NotPresent SL: " << (*sl)->id() << " from "<< ttrigMean <<" to "<< newTTrigMean <<endl;
267  }
268  }
269 
270  //Store new ttrig in the new map
271  tTrigNewMap->set((*sl)->id(), newTTrigMean, newTTrigSigma, newkfactor, DTTimeUnits::ns);
272  if(debug){
273  cout<<"New tTrig: " << (*sl)->id()
274  << " from "<< ttrigMean <<" to "<< newTTrigMean <<endl;
275  cout<<"New tTrigSigma: " << (*sl)->id()
276  << " from "<<ttrigSigma <<" to "<< newTTrigSigma <<endl;
277 
278  }
279  }//End of loop on superlayers
280 
281 
282  //Write object to DB
283  cout << "[DTTTrigCorrection]: Writing ttrig object to DB!" << endl;
284  string record = "DTTtrigRcd";
285  DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigNewMap);
286 }
287 
288 
289 
T getUntrackedParameter(std::string const &, T const &) const
virtual void beginRun(const edm::Run &run, const edm::EventSetup &setup)
int set(int wheelId, int stationId, int sectorId, int slId, float tTrig, float tTrms, float kFact, DTTimeUnits::type unit)
Definition: DTTtrig.cc:248
JetCorrectorParameters::Record record
Definition: classes.h:7
T sqrt(T t)
Definition: SSEVec.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define debug
Definition: HDRShower.cc:19
const T & get() const
Definition: EventSetup.h:56
int average
Definition: PDRates.py:137
static std::atomic< unsigned int > counter
tuple cout
Definition: gather_cfg.py:121
virtual ~DTTTrigCorrectionFirst()
Destructor.
DTTTrigCorrectionFirst(const edm::ParameterSet &pset)
Constructor.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:43